Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yeoreum Yun" <yeoreum.yun@arm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH RFC v2 14/20] x86: mm: skip pud setup when using generic compile-time folded pagetable
Date: Wed, 22 Jul 2026 16:18:27 +0000	[thread overview]
Message-ID: <20260722161828.22F9F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722-dummy_ptxp3-v2-14-d9e4bad31e0a@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Incomplete `CONFIG_PGTABLE_LEVELS` check in `collapse_pud_page()` fails to skip x86 3-level PAE configurations, exposing them to latent compile-time errors and potential runtime hardware exceptions (RSVD #PF).

Pre-existing issues:
- [High] In `populate_pud()`, an error path during the 'trailing leftover' phase silently masks resource allocation failures, skipping necessary cleanup and causing a system crash (`BUG_ON`) instead of gracefully propagating the error.
--

--- Patch [14]: [PATCH RFC v2 14/20] x86: mm: skip pud setup when using generic compile-time folded pagetable ---
commit 163a3c6228e774c7dcf45c2630763c72ef0ffe3a
Author: Yeoreum Yun <yeoreum.yun@arm.com>

x86: mm: skip pud setup when using generic compile-time folded pagetable

We want to rework how set_pXd() behaves for generic compile-time folded
page tables by disallowing its use and triggering a compile-time error
when it is used improperly, ensuring that the actual first-level set_pXd()
function is used instead.

> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> index 078689aa7206f..91b33a265a431 100644
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@ -1346,7 +1346,7 @@ static int collapse_pud_page(pud_t *pud, unsigned long addr,
>  	pmd_t *pmd, first;
>  	int i;
>  
> -	if (!direct_gbpages)
> +	if (CONFIG_PGTABLE_LEVELS == 2 || !direct_gbpages)

[Severity: High]
Does this check skip 3-level PAE configurations correctly?

If a user boots a 32-bit PAE kernel on a CPU with 1GB page support and
gbpages is enabled, direct_gbpages becomes 1. collapse_pud_page() would then
execute on a folded PUD (PDPTE in PAE) and write a PDPTE entry with the
_PAGE_PSE (bit 7) flag copied from the PMD.

In PAE, bit 7 of the PDPTE is strictly reserved, and setting it causes a
hardware exception (kernel panic).

Should this condition be checking if CONFIG_PGTABLE_LEVELS <= 3 to match
the logic added to populate_pud() below?

>  		return 0;
>  
>  	addr &= PUD_MASK;

[ ... ]

> @@ -1730,7 +1730,8 @@ static int populate_pud(struct cpa_data *cpa, unsigned long start, p4d_t *p4d,
>  	/*
>  	 * Map everything starting from the Gb boundary, possibly with 1G pages
>  	 */
> -	while (boot_cpu_has(X86_FEATURE_GBPAGES) && end - start >= PUD_SIZE) {
> +	while (CONFIG_PGTABLE_LEVELS > 3 && boot_cpu_has(X86_FEATURE_GBPAGES) &&
> +	       end - start >= PUD_SIZE) {
>  		set_pud(pud, pud_mkhuge(pfn_pud(cpa->pfn,
>  				   canon_pgprot(pud_pgprot))));
>  

[Severity: High]
This is a pre-existing issue, but further down in populate_pud() under the
"Map trailing leftover" section, does the error handler silently mask
allocation failures?

arch/x86/mm/pat/set_memory.c:populate_pud() {
    ...
		tmp = populate_pmd(cpa, start, end, cpa->numpages - cur_pages,
				   pud, pgprot);
		if (tmp < 0)
			return cur_pages;
    ...
}

If populate_pmd() fails (e.g., due to OOM) while mapping trailing leftovers,
it returns a negative error code in tmp. Returning cur_pages (which can be 0)
instead of the error code causes populate_pgd() to assume success.

This skips unmap_pud_range() cleanup, and returns 0 to __change_page_attr().
The top-level __change_page_attr_set_clr() loop updates cpa->numpages = 0
and hits BUG_ON(!cpa->numpages), causing a kernel panic.

Should this return tmp instead to properly propagate the error code?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260722-dummy_ptxp3-v2-0-d9e4bad31e0a@arm.com?part=14

  reply	other threads:[~2026-07-22 16:18 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 15:30 [PATCH RFC v2 00/20] mm: optimize unnecessary loads due to ptep_get() and friends out Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 01/20] ARM: mm: make nommu pgd_t a scalar Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 02/20] ARM: mm: make 2-level " Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 03/20] ARM: mm: remove custom pgdp_get() Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 04/20] LoongArch: mm: define pud_leaf() only when PUD exists Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 05/20] MIPS: " Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 06/20] mm/pgtable: define (pgd|p4d|pud)_leaf() for folded page tables Yeoreum Yun
2026-07-22 15:51   ` sashiko-bot
2026-07-22 15:30 ` [PATCH RFC v2 07/20] mm/pgtable: define (pgd|p4d|pud)_offset_lockless() " Yeoreum Yun
2026-07-22 15:58   ` sashiko-bot
2026-07-22 15:30 ` [PATCH RFC v2 08/20] mm: vmscan: remove stack copy address of pud pass in wallk_pud_range() Yeoreum Yun
2026-07-22 15:56   ` sashiko-bot
2026-07-22 15:30 ` [PATCH RFC v2 09/20] loongarch: kvm: remove stack copy address of pXd in pXd_offset() Yeoreum Yun
2026-07-22 15:53   ` sashiko-bot
2026-07-22 15:30 ` [PATCH RFC v2 10/20] riscv: " Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 11/20] riscv: mm: use proper set_pXd() for generic compile-time folded patable in vmalloc_fault() Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 12/20] x86: mm: define pudp_set_access_flags() when CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD is enabled only Yeoreum Yun
2026-07-22 16:02   ` Dave Hansen
2026-07-22 17:27     ` Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 13/20] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() Yeoreum Yun
2026-07-22 16:07   ` sashiko-bot
2026-07-22 16:23     ` Yeoreum Yun
2026-07-22 16:11   ` Dave Hansen
2026-07-22 16:28     ` Yeoreum Yun
2026-07-22 17:37     ` Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 14/20] x86: mm: skip pud setup when using generic compile-time folded pagetable Yeoreum Yun
2026-07-22 16:18   ` sashiko-bot [this message]
2026-07-22 16:33   ` Dave Hansen
2026-07-22 17:18     ` Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 15/20] mm/pgtable: optimize pmdp_get() and friends for folded pagetable levels Yeoreum Yun
2026-07-22 16:15   ` sashiko-bot
2026-07-22 15:30 ` [PATCH RFC v2 16/20] mm/pgtable: catch abuse of folded dummy pgd_t/p4d_t/pud_t Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 17/20] mm/pgtable: disallow calling (pgd|p4d|pud)_page, pgd_page_vaddr() and (p4d|pud)_pgtable with dummy Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 18/20] mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud " Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 19/20] openrisc/pgtable: drop __pmd_offset() Yeoreum Yun
2026-07-22 15:30 ` [PATCH RFC v2 20/20] arm64: pgtable: convert pte_present() from macro to static inline Yeoreum Yun
2026-07-22 16:40 ` [PATCH RFC v2 00/20] mm: optimize unnecessary loads due to ptep_get() and friends out Dave Hansen
2026-07-22 17:30   ` Yeoreum Yun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260722161828.22F9F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yeoreum.yun@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox