From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7897C3B7744 for ; Wed, 17 Jun 2026 06:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781679185; cv=none; b=bEOR+E5KKGJLVTEIYQ3yGwVxi4qMwpAD1Jzm1VmvQMRp0Yh3Avrx4CRumor4RImT9vzY5s3fxdHYTN5ujVEBmjA5G4v1/cXmThtuyT0jdpNX+TzoB4504gEw5JKqGc22/I+eBq0lWzX83EUYQbqg+JvhX4KufSjI7QuEtrqgVLM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781679185; c=relaxed/simple; bh=hFTV9DA6QHfTxNAiAubAHN9f4Kmv902qiqMwDaXo1lo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lul9EOJN+5xcGeiNpMv2KvWQ5u/K1ncwYhIkMq6zbtNwXrxx0sXEj9si8Ee8ozFq5peTFQzptl/HpNKETEq9xbkddig2JveB2eTHt1trFbswi+QQL+nT14j7TvrTbuYg9zLBoYKqMOxtTWKoyJ31lR+dYmm+nOXRk1TzxBba1qI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NklfJCj5; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NklfJCj5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4CFD1F000E9; Wed, 17 Jun 2026 06:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781679183; bh=bM4VGvKJIagGPyGZhns/SGKBdrac6vGwNBZ/hApzcjg=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=NklfJCj5xkDpZWlzAQO9begPqSpvXD3y+bWn3EmLpAZw3Od+Ta/ohvgj/YwmUNnCV MyaSkl3B0vpJaYbIrRnHXgXLtuZxO/qq9e0tKnpOAgzTIU5WQlSX6uJrTfi5nVu55a G4JMRRrFJwnCkh34lGLxqtZKT1PYyjIA+metdq1Dtw1SSbTQP8DZIrvvvCBbJxTDk/ B40UxgaImUHHy4Yys2EBGS/Yk81801tcXBmewRSG7KMFU2n6utoWbmYNnyncB9UtrV UYDZFCQltHPA+imjbgtsdtOfRHmrpFVg7e6eW8iC5b2rAKUDLsxuP+M12K67ZUdees 2P1gy/j/FVyQA== Date: Tue, 16 Jun 2026 23:53:01 -0700 From: Dennis Zhou To: Kaitao Cheng Cc: Andrew Morton , Uladzislau Rezki , Tejun Heo , Christoph Lameter , Vlastimil Babka , Michal Hocko , muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng Subject: Re: [PATCH v3 3/3] mm/percpu: Avoid IO/FS reclaim in backing allocations Message-ID: References: <20260612022648.13008-1-kaitao.cheng@linux.dev> <20260612022648.13008-4-kaitao.cheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260612022648.13008-4-kaitao.cheng@linux.dev> On Fri, Jun 12, 2026 at 10:26:48AM +0800, Kaitao Cheng wrote: > From: Kaitao Cheng > > Commit 9a5b183941b5 ("mm, percpu: do not consider sleepable > allocations atomic") allows sleepable GFP_NOIO and GFP_NOFS percpu > allocations to take pcpu_alloc_mutex. This avoids premature allocation > failures, but it also makes the mutex visible to callers from constrained > IO/FS contexts. > > Thread A calls pcpu_alloc_noprof() with GFP_KERNEL and takes > pcpu_alloc_mutex. Since the internal allocation is not constrained by > NOFS, it may enter FS reclaim while still holding pcpu_alloc_mutex, > creating a dependency like: pcpu_alloc_mutex -> fs_reclaim -> FS lock > > At the same time, Thread B may already hold an FS lock and then call > pcpu_alloc_noprof() with GFP_NOFS. It will try to acquire > pcpu_alloc_mutex and block, creating the reverse dependency: > FS lock -> pcpu_alloc_mutex > > This can still form a potential deadlock cycle. > > Avoid the dependency by restricting percpu backing allocations to GFP_NOIO. > The public allocation still uses the caller's GFP context to decide whether > it may block, but the internal memory allocations performed while > pcpu_alloc_mutex is held cannot recurse into IO or FS reclaim. > > Fixes: 9a5b183941b5 ("mm, percpu: do not consider sleepable allocations atomic") > Signed-off-by: Kaitao Cheng > --- > mm/percpu.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 4d89965cba16..47824061a701 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1726,9 +1726,9 @@ static void pcpu_alloc_tag_free_hook(struct pcpu_chunk *chunk, int off, size_t s > * @gfp: allocation flags > * > * Allocate percpu area of @size bytes aligned at @align. If @gfp doesn't > - * contain %GFP_KERNEL, the allocation is atomic. If @gfp has __GFP_NOWARN > - * then no warning will be triggered on invalid or failed allocation > - * requests. > + * allow blocking, the allocation is atomic. If @gfp has __GFP_NOFAIL, backing > + * allocation failures are retried. If @gfp has __GFP_NOWARN then no warning > + * will be triggered on invalid or failed allocation requests. > * > * RETURNS: > * Percpu pointer to the allocated area on success, NULL on failure. > @@ -1749,8 +1749,14 @@ void __percpu *pcpu_alloc_noprof(size_t size, size_t align, bool reserved, > size_t bits, bit_align; > > gfp = current_gfp_context(gfp); > - /* whitelisted flags that can be passed to the backing allocators */ > - pcpu_gfp = gfp & (GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); > + /* > + * Allowlisted flags that can be passed to the backing allocators. > + * Backing allocations under pcpu_alloc_mutex must not recurse into > + * IO/FS reclaim. Otherwise a GFP_KERNEL caller holding the mutex can > + * block on reclaim while a GFP_NOIO/NOFS caller holding an IO/FS lock > + * waits for the same mutex. > + */ > + pcpu_gfp = gfp & (GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOFAIL); > is_atomic = !gfpflags_allow_blocking(gfp); > do_warn = !(gfp & __GFP_NOWARN); > I think GFP_KERNEL -> GFP_NOIO makes sense. It breaks the cycle. For __GFP_NOFAIL, I think my concern is that a chunk can be quite large and might need numerous pages. If we allow __GFP_NOFAIL, then we could potentially churn and stall out other allocations for quite some time while GFP_NOIO tries to reclaim without access to fs or io paths. Thanks, Dennis