Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Paolo Bonzini" <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 6.1.y 03/24] KVM: x86/mmu: Move round_gfn_for_level() helper into mmu_internal.h
Date: Fri, 04 Dec 2026 18:22:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-250411@kernel.org> (raw)
In-Reply-To: <20261204180423.2168641-4-pbonzini@redhat.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] kvm/x86: kvm_tdp_page_fault() reads zero-initialized fault->gfn
- [High] kvm: kvm_tdp_page_fault() reads zeroed fault->gfn before it is
  set
--

commit 73752e956b3b2e05f08dc7c1a2dd6aeb316925fe
Author: Hou Wenlong <houwenlong.hwl@antgroup.com>

KVM: x86/mmu: Move round_gfn_for_level() helper into mmu_internal.h

This commit moves round_gfn_for_level() from tdp_iter.c to mmu_internal.h
as gfn_round_for_level() and converts other call sites to use it.

Link: https://lore.kernel.org/r/415c64782f27444898db650e21cf28eeb6441dfa.1665214747.git.houwenlong.hwl@antgroup.com

> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 0a1318eee1ef8..72a61480890e6 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c

[ ... ]

> @@ -4375,7 +4375,8 @@ int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
>  	if (shadow_memtype_mask && kvm_arch_has_noncoherent_dma(vcpu->kvm)) {
>  		for ( ; fault->max_level > PG_LEVEL_4K; --fault->max_level) {
>  			int page_num = KVM_PAGES_PER_HPAGE(fault->max_level);
> -			gfn_t base = (fault->addr >> PAGE_SHIFT) & ~(page_num - 1);
> +			gfn_t base = gfn_round_for_level(fault->gfn,
> +							 fault->max_level);
>  
>  			if (kvm_mtrr_check_gfn_range_consistency(vcpu, base, page_num))
>  				break;

[Severity: High]
Is fault->gfn initialized yet when kvm_tdp_page_fault() runs?

In this tree, kvm_mmu_do_page_fault() leaves fault.gfn zero-initialized
and direct_page_fault() only sets it later from fault->addr.  As a result,
base is always 0 and kvm_mtrr_check_gfn_range_consistency() always checks
guest MTRRs at GFN 0 instead of the faulting GPA.

On Intel EPT VMs with non-coherent DMA, if guest low memory has uniform
MTRRs while a faulting hugepage spans mixed memory types, KVM fails to
restrict fault->max_level and maps the range as a single hugepage, risking
DMA cache-coherency corruption.

Conversely, when legacy fixed MTRRs in the first 1 MiB are mixed, every
TDP fault across the guest is demoted to 4 KiB pages.

Passing fault->addr >> PAGE_SHIFT to gfn_round_for_level() here (or
backporting the commit that initializes fault.gfn in
kvm_mmu_do_page_fault()) would avoid this regression.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204180423.2168641-1-pbonzini@redhat.com?part=3

  reply	other threads:[~2026-12-04 18:22 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:03 [PATCH 6.1.y 00/24] Fixes for various (mostly x86) KVM vulnerabilities Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 01/24] ptrace: Convert ptrace_attach() to use lock guards Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 02/24] KVM: x86: Grab lapic_timer in a local variable to cleanup periodic code Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 03/24] KVM: x86/mmu: Move round_gfn_for_level() helper into mmu_internal.h Paolo Bonzini
2026-12-04 18:22   ` sashiko-bot [this message]
2026-12-04 18:04 ` [PATCH 6.1.y 04/24] KVM: x86/mmu: Fix wrong gfn range of tlb flushing in kvm_set_pte_rmapp() Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 05/24] KVM: x86/mmu: Fix wrong start gfn of tlb flushing with range Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 06/24] KVM: x86/mmu: Flush TLBs if child SPTE is zapped when splitting a huge SPTE Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 07/24] KVM: x86/mmu: Propagate the return from kvm_zap_all_rmap_sptes() out of __rmap_add() Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 08/24] KVM: x86: Disable hypervisor (VMX Preemption) timer if TSC deadline wraps Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 09/24] KVM: x86: Reset local APIC timer metadata on RESET, INIT, and KVM_SET_LAPIC Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 10/24] KVM: x86/mmu: Flush all TLB entries, not a precise range, when yielding Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 11/24] KVM: VMX: Retry APIC-access page reload if invalidation is in-progress Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 12/24] KVM: x86: Use standard mmu_notifier invalidate hooks for APIC access page Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 13/24] KVM: x86/mmu: Flush TLBs in kvm_unmap_gfn_range() if the unmap may block/yield Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 14/24] KVM: x86/xen: Pin kvm->mm prior to borrowing mm when setting event channel Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 15/24] KVM: Fold kvm_flush_shadow_all() into kvm_mmu_notifier_release() Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 16/24] KVM: WARN if there are dangling MMU invalidations at VM destruction Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 17/24] KVM: WARN if there are in-flight memslot updates when a VM's process exits Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 18/24] KVM: Fix comments that refer to the non-existent install_new_memslots() Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 19/24] KVM: Set mn_active_invalidate_count when the VM's mm is released Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 20/24] KVM: Invalidate all GFN=>PFN caches when VM and/or its process is dying Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 21/24] x86/fpu: Bail early from guest XFD update if XFD isn't supported Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 22/24] x86/fpu: Clear XSTATE_BV[i] in guest XSAVE state if guest FPU isn't in-use Paolo Bonzini
2026-12-04 18:04 ` [PATCH 6.1.y 23/24] x86/fpu: Ensure guest FPU is resident in hardware when updating actual XFD MSR Paolo Bonzini
2026-12-04 19:15   ` sashiko-bot
2026-12-04 18:04 ` [PATCH 6.1.y 24/24] KVM: VMX: Ensure pCPU is valid before sending IPI to deliver posted IRQ Paolo Bonzini
2026-12-04 19:18   ` sashiko-bot
2026-12-04 20:29 ` [PATCH 6.1.y 00/24] Fixes for various (mostly x86) KVM vulnerabilities Paolo Bonzini

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=sashiko-outbox-250411@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox