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 E3C2F2E06ED for ; Thu, 28 May 2026 21:10:57 +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=1780002658; cv=none; b=Uhbp1EKJ7JMI5qxkj57xNsHYOYY7jb4HgpJOCD5NVNMJ2hk3J9ta35wivezEomDE7MWpi6gGC37qsl3fb6Usz2vYMXicvTt9I4JpmOlLW8hw45zg7kEQLZyf6zUpR7FsmnmB0N17ZCIScwUlMz/qkkAr05nouZyTuXDqAPC99/4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780002658; c=relaxed/simple; bh=WM3ssIDYfGJXVg2yEBTtu7epcu2EJQnXnuzX6W+APUE=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=HFzI51RYe92NE53yZ5MYKfnp+45vXpMQDD2FzUVEmZmhZ9o/qkB7eDygt7iRwiuDNsgSKC1UqBTTi4nOoNXDXgPNdoNvkPh9VSYjJcCbjzHAG+6tWi08M931CiOgVqpCLZF2ucPWXtdsOoDIr2nAtIz9a8i2N4idQLHcxue91bg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=eXD4+/E6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="eXD4+/E6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4836A1F000E9; Thu, 28 May 2026 21:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1780002657; bh=TTskpAj6x+TMfI0RYGyLu0nkjbucB2TtboL3/uU4zEo=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=eXD4+/E6cwT8hDjY+RkhGaBEor5tVeNgfxZs2TU2lXABmJLkNPvToaJW/BEYuWT88 96ndewezliJP0A1E5TuHec4S3q8hS1Z+MoHeteTC/ZGG9O8PqojaYXY1fcIIRATgPT QlNRAaYq9J0lsGasowmboFFu6lDx9aH+UgbpuF1s= Date: Thu, 28 May 2026 14:10:56 -0700 From: Andrew Morton To: Kaitao Cheng Cc: dennis@kernel.org, tj@kernel.org, cl@gentwo.org, mhocko@suse.com, vbabka@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, muchun.song@linux.dev Subject: Re: [PATCH 0/2] mm/percpu: Fix possible NOFS/NOIO reclaim recursion Message-Id: <20260528141056.189d4c91756a974bfff20e9c@linux-foundation.org> In-Reply-To: <20260528132917.81123-1-kaitao.cheng@linux.dev> References: <20260528132917.81123-1-kaitao.cheng@linux.dev> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 28 May 2026 21:29:15 +0800 Kaitao Cheng wrote: > Commit 9a5b183941b5 ("mm, percpu: do not consider sleepable allocations > atomic") allowed GFP_NOFS and GFP_NOIO percpu allocations to use > pcpu_alloc_mutex and the chunk creation slow path. This restored the > allocation capability that was lost when those constrained allocations > were treated as atomic, but it also opens two possible reclaim recursion > problems. > > The first problem is that the create and populate slow paths do not fully > preserve the caller's allocation constraints. pcpu_alloc_noprof() derives > pcpu_gfp from the caller supplied GFP mask and passes it to the backing > page allocator. However, pcpu_create_chunk() calls pcpu_get_vm_areas(), > and population can allocate temporary metadata or page tables while mapping > backing pages. Those internal allocations can use GFP_KERNEL. A caller > using GFP_NOFS or GFP_NOIO can therefore still enter unconstrained FS or > IO reclaim while holding pcpu_alloc_mutex. This defeats the caller's > allocation context. > > The second problem is a possible pcpu_alloc_mutex recursion from reclaim. > If reclaim is entered while pcpu_alloc_mutex is already held, and reclaim > reaches a path which allocates percpu memory with GFP_NOFS or GFP_NOIO, > the nested allocation can now try to take pcpu_alloc_mutex again because > 9a5b183941b5 no longer treats those masks as atomic. > > Another possible way to avoid these issues is to revert 9a5b183941b5. > However, that would also bring back the premature allocation failures for > sleepable GFP_NOFS/GFP_NOIO percpu users that 9a5b183941b5 was intended > to fix. AI review might have found a couple of pre-existing issues: https://sashiko.dev/#/patchset/20260528132917.81123-1-kaitao.cheng@linux.dev