From nobody Tue Apr 14 13:59:23 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.4]) (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 E022D1C01 for ; Tue, 14 Apr 2026 05:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776144004; cv=none; b=Tbt9+eHwBzMUgmZBJYbxymLN2YIW9IWMAjuFrjKZIi+8+mNC9sTMPmcByrIKh9q++FWqGXEfNYM5okEIRlcKNuMOBYA17x7HTisGIZ/pJuWqxiev5ezjCLM/qZ7bQRInx6H0vcDj+A72uY2k1HHoytg/3s59zfszKy+rQKGYWlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776144004; c=relaxed/simple; bh=O38tDJ+VXtAIcpztp0ZwV5dOZaGBdPnUCmHuciC4AwQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=BkO2zWaSuMqyub/77uyn8SAZvgJs0/a4fGrQC9URriLq8AKpKvh5P8uylLo1+n/6GLx5KDhAnCTsGHezDmvqx7KbGv33zh14KlYypkul42ZQRFNoWNNySH13VoFiWWyBL2I+EnBrb6wwQp6baATFNZByEXaEXADaGhi2ZsJirso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=F1gFYKm6; arc=none smtp.client-ip=117.135.210.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="F1gFYKm6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=Wo uCWQZQw2wWCXfxw9TY2LZlejrYTTJjmaYv9acBuZw=; b=F1gFYKm63ZQIZDYNl9 j9X7ip/O4JvHmcMbAf1dwvklOUcBaABPgmG9oXv5kvj6WpH+8m3vNAI/w2Ejxgkc 3y7tI6TFNFBEv5jqByyWdlYnNTK82Dtkw/FpdjVT4zp3XAtWx6nwK4Vy1OT28ldo EMZwqPJg++vcfcMImhQx6qXzg= Received: from localhost.localdomain (unknown []) by gzsmtp1 (Coremail) with SMTP id PCgvCgCnPNFDzt1pZ+E6VA--.2975S2; Tue, 14 Apr 2026 13:19:03 +0800 (CST) From: Cao Ruichuang To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Cao Ruichuang Subject: [PATCH] mm/pagewalk: honor action in pgd_entry and p4d_entry Date: Tue, 14 Apr 2026 13:18:54 +0800 Message-Id: <20260414051854.18487-1-create0818@163.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: PCgvCgCnPNFDzt1pZ+E6VA--.2975S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFy5uFW7KrWDuFWxuFW5GFg_yoW5AFyfpF W3Cw18ta1DJFZIyFn3Z3W09r1Fvws7WFW8Ja9rKryvkw1Sq3Zaqa4DXr1akF1UCrW8XrW8 Way7Kr95CF4xZw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pizuWJUUUUU= X-CM-SenderInfo: pfuht3jhqyimi6rwjhhfrp/xtbCvweWz2ndzkcmHgAA3k Content-Type: text/plain; charset="utf-8" walk_pud_range() and walk_pmd_range() reset walk->action to ACTION_SUBTREE = and honor ACTION_CONTINUE/ACTION_AGAIN after invoking their callbacks, but = walk_pgd_range() and walk_p4d_range() do not. That leaves the top levels with inconsistent callback semantics. In particu= lar, ptdump sets ACTION_CONTINUE from pgd_entry() and p4d_entry() for leaf = entries, but the generic walker still descends into lower levels instead of= skipping the subtree. Initialize walk->action before calling pgd_entry() and p4d_entry(), and han= dle ACTION_CONTINUE and ACTION_AGAIN afterwards just like the lower page-ta= ble levels do. Also update the action comment to reflect that it applies to= pgd_entry() and p4d_entry() as well. --- include/linux/pagewalk.h | 4 ++-- mm/pagewalk.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h index 88e18615dd7..d3f84781792 100644 --- a/include/linux/pagewalk.h +++ b/include/linux/pagewalk.h @@ -94,8 +94,8 @@ struct mm_walk_ops { }; =20 /* - * Action for pud_entry / pmd_entry callbacks. - * ACTION_SUBTREE is the default + * Action for pgd_entry / p4d_entry / pud_entry / pmd_entry callbacks. + * ACTION_SUBTREE is the default. */ enum page_walk_action { /* Descend to next level, splitting huge pages if needed and possible */ diff --git a/mm/pagewalk.c b/mm/pagewalk.c index 4e7bcd975c5..4268e08eabb 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -261,6 +261,7 @@ static int walk_p4d_range(pgd_t *pgd, unsigned long add= r, unsigned long end, =20 p4d =3D p4d_offset(pgd, addr); do { +again: next =3D p4d_addr_end(addr, end); if (p4d_none_or_clear_bad(p4d)) { if (has_install) @@ -272,11 +273,20 @@ static int walk_p4d_range(pgd_t *pgd, unsigned long a= ddr, unsigned long end, if (!has_install) continue; } + + walk->action =3D ACTION_SUBTREE; + if (ops->p4d_entry) { err =3D ops->p4d_entry(p4d, addr, next, walk); if (err) break; } + + if (walk->action =3D=3D ACTION_AGAIN) + goto again; + if (walk->action =3D=3D ACTION_CONTINUE) + continue; + if (has_handler || has_install) err =3D walk_pud_range(p4d, addr, next, walk); if (err) @@ -302,6 +312,7 @@ static int walk_pgd_range(unsigned long addr, unsigned = long end, else pgd =3D pgd_offset(walk->mm, addr); do { +again: next =3D pgd_addr_end(addr, end); if (pgd_none_or_clear_bad(pgd)) { if (has_install) @@ -313,11 +324,20 @@ static int walk_pgd_range(unsigned long addr, unsigne= d long end, if (!has_install) continue; } + + walk->action =3D ACTION_SUBTREE; + if (ops->pgd_entry) { err =3D ops->pgd_entry(pgd, addr, next, walk); if (err) break; } + + if (walk->action =3D=3D ACTION_AGAIN) + goto again; + if (walk->action =3D=3D ACTION_CONTINUE) + continue; + if (has_handler || has_install) err =3D walk_p4d_range(pgd, addr, next, walk); if (err) base-commit: e39f5a33eec1a4ea03358d82e861d6bb0a426b17 --=20 2.39.5 (Apple Git-154)