All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kenta Akagi" <k@mgml.me>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 5.15.y v3 3/7] KVM: x86/mmu: Derive shadow MMU page role from parent
Date: Sun, 13 Sep 2026 16:56:15 +0000	[thread overview]
Message-ID: <20260913165616.09F7F1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260913155523.7423-4-k@mgml.me>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Direct shadow pages erroneously inherit `gpte_is_8_bytes = 0` and are incorrectly assigned quadrants.
--

commit 6bad5f356476627b0df5994e2be62a19a71f499f
Author: Paolo Bonzini <pbonzini@redhat.com>

KVM: x86/mmu: Derive shadow MMU page role from parent

This patch modifies the shadow MMU page role calculation to derive most
information from the parent shadow page rather than computing it from scratch.
It preemptively splits the role calculation into a separate function to reduce
dependencies on the vCPU root role when allocating shadow page tables.

> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 9f193b1620a95..b0504d40ac8c6 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
[ ... ]
> @@ -2176,6 +2158,54 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
>  	return sp;
>  }
>  
> +static union kvm_mmu_page_role kvm_mmu_child_role(u64 *sptep, bool direct, unsigned int access)
> +{
> +	struct kvm_mmu_page *parent_sp = sptep_to_sp(sptep);
> +	union kvm_mmu_page_role role;
> +
> +	role = parent_sp->role;
> +	role.level--;
> +	role.access = access;
> +	role.direct = direct;
> +
> +	/*
> +	 * If the guest has 4-byte PTEs then that means it's using 32-bit,
> +	 * 2-level, non-PAE paging. KVM shadows such guests with PAE paging
> +	 * (i.e. 8-byte PTEs). The difference in PTE size means that KVM must
> +	 * shadow each guest page table with multiple shadow page tables, which
> +	 * requires extra bookkeeping in the role.
> +	 *
> +	 * Specifically, to shadow the guest's page directory (which covers a
> +	 * 4GiB address space), KVM uses 4 PAE page directories, each mapping
> +	 * 1GiB of the address space. @role.quadrant encodes which quarter of
> +	 * the address space each maps.
> +	 *
> +	 * To shadow the guest's page tables (which each map a 4MiB region), KVM
> +	 * uses 2 PAE page tables, each mapping a 2MiB region. For these,
> +	 * @role.quadrant encodes which half of the region they map.
> +	 *
> +	 * Note, the 4 PAE page directories are pre-allocated and the quadrant
> +	 * assigned in mmu_alloc_root(). So only page tables need to be handled
> +	 * here.
> +	 */
> +	if (!role.gpte_is_8_bytes) {
> +		WARN_ON_ONCE(role.level != PG_LEVEL_4K);
> +		role.quadrant = (sptep - parent_sp->spt) % 2;
> +	}
> +
> +	return role;
> +}

[Severity: High]
Because this patch removes the earlier enforcement of gpte_is_8_bytes being
true for direct pages, will direct child pages (like NX huge page workaround
pages shadowed from a 32-bit parent) inherit gpte_is_8_bytes = 0 from the
parent here?

If so, doesn't this incorrectly assign a quadrant to these direct pages,
violating the KVM invariant that quadrants are never used for direct pages?
This broken invariant appears to cause the WARN_ON_ONCE(role.direct &&
!role.gpte_is_8_bytes) check to trigger when introduced in later patches,
which creates a potential host-side denial of service if panic_on_warn is
enabled.

[ ... ]
> @@ -3438,13 +3467,18 @@ static int mmu_check_root(struct kvm_vcpu *vcpu, gfn_t root_gfn)
>  	return ret;
>  }
>  
> -static hpa_t mmu_alloc_root(struct kvm_vcpu *vcpu, gfn_t gfn, gva_t gva,
> +static hpa_t mmu_alloc_root(struct kvm_vcpu *vcpu, gfn_t gfn, int quadrant,
>  			    u8 level)
>  {
> -	bool direct = vcpu->arch.mmu->mmu_role.base.direct;
> +	union kvm_mmu_page_role role = vcpu->arch.mmu->mmu_role.base;
>  	struct kvm_mmu_page *sp;
>  
> -	sp = kvm_mmu_get_page(vcpu, gfn, gva, level, direct, ACC_ALL);
> +	role.level = level;
> +
> +	if (!role.gpte_is_8_bytes)
> +		role.quadrant = quadrant;
> +
> +	sp = kvm_mmu_get_page(vcpu, gfn, role);
>  	++sp->root_count;
>  
>  	return __pa(sp->spt);

[Severity: High]
When a guest runs in non-paging mode (CR0.PG=0), mmu_role.base has
gpte_is_8_bytes set to 0. Since the code no longer forces gpte_is_8_bytes to
true for direct pages, will this block erroneously assign a quadrant to the
direct root?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260913155523.7423-1-k@mgml.me?part=3

  reply	other threads:[~2026-09-13 16:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13 15:55 [PATCH 5.15.y v3 0/7] KVM: fixes for CVE-2026-46113 and related issues Kenta Akagi
2026-09-13 15:55 ` [PATCH 5.15.y v3 1/7] KVM: x86/mmu: Use a bool for direct Kenta Akagi
2026-09-13 15:55 ` [PATCH 5.15.y v3 2/7] KVM: x86/mmu: Stop passing "direct" to mmu_alloc_root() Kenta Akagi
2026-09-13 15:55 ` [PATCH 5.15.y v3 3/7] KVM: x86/mmu: Derive shadow MMU page role from parent Kenta Akagi
2026-09-13 16:56   ` sashiko-bot [this message]
2026-09-13 15:55 ` [PATCH 5.15.y v3 4/7] KVM: x86/mmu: Always pass 0 for @quadrant when gptes are 8 bytes Kenta Akagi
2026-09-13 16:49   ` sashiko-bot
2026-09-13 15:55 ` [PATCH 5.15.y v3 5/7] KVM: x86/mmu: pull call to drop_large_spte() into __link_shadow_page() Kenta Akagi
2026-09-13 16:51   ` sashiko-bot
2026-09-13 15:55 ` [PATCH 5.15.y v3 6/7] KVM: x86: Fix shadow paging use-after-free due to unexpected GFN Kenta Akagi
2026-09-13 15:55 ` [PATCH 5.15.y v3 7/7] KVM: x86: Fix shadow paging use-after-free due to unexpected role Kenta Akagi

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=20260913165616.09F7F1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=k@mgml.me \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.