From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 862F43F0AAD for ; Thu, 28 May 2026 13:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779975023; cv=none; b=sYVZQtAUv3CWcbvL9pE7IxSnIdIMVBhvTRaNd3GMUkGXo9aHncyZ2zjNLOb2einsVn62vIGOitEgDyTc7iziKMQyH0pgi5HyG+w+Fmxzp1yfWuc4vDAP+bjArGlVtk4Cx+nbW7nFMvKHm4BpzTXVBklaWLTw1XGqSH7qHBeDpgM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779975023; c=relaxed/simple; bh=B+aJ2l2iUz2ofQXWnF0Gq5o9iHq7wP+zMEmUO2Or7L8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=X6ld9BDj5xj6qcFTAIZuQrZLd8tSjyAHmfZyAeG+3B7Vemu7M7KPUAFo25PuFyXXTIFrhHy9e6th/OUThWbepvF0dkRaW903x1BoUpkK6F4rS1dKRYIIATAZvdIs51UYfS6fHEDNfcdErtkd4seXC9tC2pB4V9hXPojJCan8Av4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=OqumLFAc; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="OqumLFAc" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1779975020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KhpTO4hFo9OC+mrEE7JFS6Q7sHMI0fS8gBIMk6Qxzhc=; b=OqumLFAcBtN5y4Aq9/aw82ZzRXDsV2lcJGVGQ20Nay8gah8vA4dNdFwYqyvjtI9ttavFN/ 889fLDus8fccZ7Gw/ux/E2Euq6yGMrc+wOdaB218uJgH05cuwVW92VuoiQusyZi2CqnME4 zOOn9zvKFh7N/Hm96E8W5+4iA5aXsCQ= From: Kaitao Cheng To: dennis@kernel.org, tj@kernel.org, cl@gentwo.org, akpm@linux-foundation.org Cc: mhocko@suse.com, vbabka@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, muchun.song@linux.dev, Kaitao Cheng Subject: [PATCH 0/2] mm/percpu: Fix possible NOFS/NOIO reclaim recursion Date: Thu, 28 May 2026 21:29:15 +0800 Message-ID: <20260528132917.81123-1-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-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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. Kaitao Cheng (2): mm/percpu: Preserve NOFS/NOIO scope during chunk create and populate mm/percpu: Avoid pcpu_alloc_mutex recursion from reclaim mm/percpu.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) -- 2.50.1 (Apple Git-155)