All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 06/16] KVM: selftests: Introduce struct kvm_mmu
Date: Tue, 23 Dec 2025 14:29:23 -0800	[thread overview]
Message-ID: <aUsXw9m4g-Pn7LtO@google.com> (raw)
In-Reply-To: <20251127013440.3324671-7-yosry.ahmed@linux.dev>

On Thu, Nov 27, 2025, Yosry Ahmed wrote:
> In preparation for generalizing the virt mapping functions to work with
> TDP page tables, introduce struct kvm_mmu. This struct currently only
> holds the root GPA and number of page table levels. Parameterize virt
> mapping functions by the kvm_mmu, and use the root GPA and page table
> levels instead of hardcoding vm->pgd and vm->pgtable_levels.
> 
> There's a subtle change here, instead of checking that the parent
> pointer is the address of the vm->pgd, check if the value pointed at by
> the parent pointer is the root GPA (i.e. the value of vm->pgd in this
> case). No change in behavior expected.
> 
> Opportunistically, switch the ordering of the checks in the assertion in
> virt_get_pte(), as it makes more sense to check if the parent PTE is the
> root (in which case, not a PTE) before checking the present flag.
> 
> vm->arch.mmu is dynamically allocated to avoid a circular dependency
> chain if kvm_util_arch.h includes processor.h for the struct definition:
> kvm_util_arch.h -> processor.h -> kvm_util.h -> kvm_util_arch.h
> 
> No functional change intended.
> 
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
> ---
>  .../selftests/kvm/include/x86/kvm_util_arch.h |  4 ++
>  .../selftests/kvm/include/x86/processor.h     |  8 ++-
>  .../testing/selftests/kvm/lib/x86/processor.c | 61 +++++++++++++------
>  3 files changed, 53 insertions(+), 20 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h b/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h
> index 972bb1c4ab4c..d8808fa33faa 100644
> --- a/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h
> +++ b/tools/testing/selftests/kvm/include/x86/kvm_util_arch.h
> @@ -10,6 +10,8 @@
>  
>  extern bool is_forced_emulation_enabled;
>  
> +struct kvm_mmu;
> +
>  struct kvm_vm_arch {
>  	vm_vaddr_t gdt;
>  	vm_vaddr_t tss;
> @@ -19,6 +21,8 @@ struct kvm_vm_arch {
>  	uint64_t s_bit;
>  	int sev_fd;
>  	bool is_pt_protected;
> +
> +	struct kvm_mmu *mmu;

No, put kvm_mmu in common code and create kvm_vm.mmu.  This makes the "mmu" object
a weird copy of state that's already in kvm_vm (pgd, pgd_created, and pgtable_levels),
and more importantly makes it _way_ to easy to botch the x86 MMU code (speaking
from first hand experience), e.g. due to grabbing vm->pgtable_levels instead of
the mmu's version.  I don't see an easy way to _completely_ guard against goofs
like that, but it's easy-ish to audit code the code for instance of "vm->mmu.",
and adding a common kvm_mmu avoids the weird duplicate code.


  reply	other threads:[~2025-12-23 22:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27  1:34 [PATCH v3 00/16] Add Nested NPT support in selftests Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 01/16] KVM: selftests: Make __vm_get_page_table_entry() static Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 02/16] KVM: selftests: Stop passing a memslot to nested_map_memslot() Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 03/16] KVM: selftests: Rename nested TDP mapping functions Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 04/16] KVM: selftests: Kill eptPageTablePointer Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 05/16] KVM: selftests: Stop setting AD bits on nested EPTs on creation Yosry Ahmed
2025-12-23 22:26   ` Sean Christopherson
2025-12-23 23:35     ` Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 06/16] KVM: selftests: Introduce struct kvm_mmu Yosry Ahmed
2025-12-23 22:29   ` Sean Christopherson [this message]
2025-12-23 23:38     ` Yosry Ahmed
2025-12-29 15:24       ` Sean Christopherson
2025-11-27  1:34 ` [PATCH v3 07/16] KVM: selftests: Move PTE bitmasks to kvm_mmu Yosry Ahmed
2025-12-23 22:31   ` Sean Christopherson
2025-12-23 23:40     ` Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 08/16] KVM: selftests: Use a nested MMU to share nested EPTs between vCPUs Yosry Ahmed
2025-12-23 23:16   ` Sean Christopherson
2025-11-27  1:34 ` [PATCH v3 09/16] KVM: selftests: Stop passing VMX metadata to TDP mapping functions Yosry Ahmed
2025-12-15 18:38   ` Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 10/16] KVM: selftests: Reuse virt mapping functions for nested EPTs Yosry Ahmed
2025-12-23 23:12   ` Sean Christopherson
2025-12-23 23:45     ` Yosry Ahmed
2025-12-30  0:08       ` Sean Christopherson
2025-12-30  4:03         ` Yosry Ahmed
2025-12-30 15:43           ` Sean Christopherson
2025-12-23 23:14   ` Sean Christopherson
2025-12-23 23:47     ` Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 11/16] KVM: selftests: Move TDP mapping functions outside of vmx.c Yosry Ahmed
2025-12-23 23:13   ` Sean Christopherson
2025-11-27  1:34 ` [PATCH v3 12/16] KVM: selftests: Allow kvm_cpu_has_ept() to be called on AMD CPUs Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 13/16] KVM: selftests: Add support for nested NPTs Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 14/16] KVM: selftests: Set the user bit on nested NPT PTEs Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 15/16] KVM: selftests: Extend vmx_dirty_log_test to cover SVM Yosry Ahmed
2025-11-27  1:34 ` [PATCH v3 16/16] KVM: selftests: Extend memstress to run on nested SVM Yosry Ahmed
2025-12-23 22:01 ` [PATCH v3 00/16] Add Nested NPT support in selftests Sean Christopherson
2025-12-23 23:48   ` Yosry Ahmed

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=aUsXw9m4g-Pn7LtO@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=yosry.ahmed@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.