public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jim Mattson <jmattson@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>,  Bibo Mao <maobibo@loongson.cn>,
	Huacai Chen <chenhuacai@kernel.org>,
	 Andrew Jones <ajones@ventanamicro.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	 "Pratik R. Sampat" <prsampat@amd.com>,
	Kai Huang <kai.huang@intel.com>,
	 Eric Auger <eric.auger@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	 linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 3/4] KVM: selftests: Add VM_MODE_PXXV57_4K VM mode
Date: Wed, 15 Oct 2025 17:40:11 -0700	[thread overview]
Message-ID: <aPA-60vV0WQUCmc2@google.com> (raw)
In-Reply-To: <aPAnWWmo555uB0-H@google.com>

On Wed, Oct 15, 2025, Sean Christopherson wrote:
> On Wed, Sep 17, 2025, Jim Mattson wrote:
> > Add a new VM mode, VM_MODE_PXXV57_4K, to support tests that require
> > 5-level paging on x86. This mode sets up a 57-bit virtual address
> > space and sets CR4.LA57 in the guest.

Thinking about this more, unless it's _really_ painful, e.g. because tests assume
4-level paging or 48-bit non-canonical address, I would rather turn VM_MODE_PXXV48_4K
into VM_MODE_PXXVXX_4K and have ____vm_create() create the "maximal" VM.  That
way tests don't need to go out of their way just to use 5-level paging, e.g. a
"TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_LA57))" is all that is needed.  It will also
gives quite a bit of coverage for free, e.g. that save/restore works with and
without 5-level paging (contrived example, but you get the point).

The NONCANONICAL #define works for LA57, so hopefully making tests play nice with
LA57 is straightforward?

> > @@ -358,6 +360,25 @@ struct kvm_vm *____vm_create(struct vm_shape shape)
> >  		vm->va_bits = 48;
> >  #else
> >  		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
> > +#endif
> > +		break;
> > +	case VM_MODE_PXXV57_4K:
> > +#ifdef __x86_64__
> > +		kvm_get_cpu_address_width(&vm->pa_bits, &vm->va_bits);
> > +		kvm_init_vm_address_properties(vm);
> > +		/*
> > +		 * For 5-level paging, KVM requires LA57 to be enabled, which
> > +		 * requires a 57-bit virtual address space.
> > +		 */
> > +		TEST_ASSERT(vm->va_bits == 57,
> > +			    "Linear address width (%d bits) not supported for VM_MODE_PXXV57_4K",
> > +			    vm->va_bits);
> > +		pr_debug("Guest physical address width detected: %d\n",
> > +			 vm->pa_bits);
> > +		vm->pgtable_levels = 5;
> > +		vm->va_bits = 57;
> > +#else
> > +		TEST_FAIL("VM_MODE_PXXV57_4K not supported on non-x86 platforms");
> >  #endif
> 
> That's a lot of copy+paste, especially given the #ifdefs.  How about this (untested)?
> 
> 	case VM_MODE_PXXV48_4K:
> 	case VM_MODE_PXXV57_4K:
> #ifdef __x86_64__
> 		kvm_get_cpu_address_width(&vm->pa_bits, &vm->va_bits);
> 		kvm_init_vm_address_properties(vm);
> 
> 		/*
> 		 * Ignore KVM support for 5-level paging (vm->va_bits == 57) if
> 		 * the target mode is 4-level paging (48-bit virtual address
> 		 * space), as 5-level paging only takes effect if CR4.LA57=1.
> 		 */
> 		TEST_ASSERT(vm->va_bits == 57 ||
> 			    (vm->va_bits == 48 && vm->mode == VM_MODE_PXXV48_4K),
> 			    "Linear address width (%d bits) not supported",
> 			    vm->va_bits);
> 		pr_debug("Guest physical address width detected: %d\n",
> 			 vm->pa_bits);
> 		if (vm->mode == VM_MODE_PXXV48_4K) {
> 			vm->pgtable_levels = 4;
> 			vm->va_bits = 48;
> 		} else {
> 			vm->pgtable_levels = 5;
> 			vm->va_bits = 57;
> 		}
> #else
> 		TEST_FAIL("VM_MODE_PXXV{48,57}_4K not supported on non-x86 platforms");
> #endif
> 		break;

  reply	other threads:[~2025-10-16  0:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17 21:48 [PATCH 0/4] KVM: selftests: Add test of SET_NESTED_STATE with 48-bit L2 on 57-bit L1 Jim Mattson
2025-09-17 21:48 ` [PATCH 1/4] KVM: selftests: Use a loop to create guest page tables Jim Mattson
2025-10-20 17:10   ` Yosry Ahmed
2025-09-17 21:48 ` [PATCH 2/4] KVM: selftests: Use a loop to walk " Jim Mattson
2025-10-20 17:21   ` Yosry Ahmed
2025-10-21 22:11     ` Jim Mattson
2025-10-21 22:24       ` Yosry Ahmed
2025-09-17 21:48 ` [PATCH 3/4] KVM: selftests: Add VM_MODE_PXXV57_4K VM mode Jim Mattson
2025-10-15 21:23   ` Yosry Ahmed
2025-10-21 22:34     ` Jim Mattson
2025-10-21 22:56       ` Yosry Ahmed
2025-10-15 21:25   ` Yosry Ahmed
2025-10-15 22:58     ` Sean Christopherson
2025-10-15 22:59   ` Sean Christopherson
2025-10-16  0:40     ` Sean Christopherson [this message]
2025-10-21 22:37       ` Jim Mattson
2025-09-17 21:48 ` [PATCH 4/4] KVM: selftests: Add a VMX test for LA57 nested state Jim Mattson
2025-10-20 17:26   ` Yosry Ahmed
2025-10-21 23:40     ` Jim Mattson
2025-10-22 18:07       ` 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=aPA-60vV0WQUCmc2@google.com \
    --to=seanjc@google.com \
    --cc=ajones@ventanamicro.com \
    --cc=chenhuacai@kernel.org \
    --cc=eric.auger@redhat.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=jmattson@google.com \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=maobibo@loongson.cn \
    --cc=pbonzini@redhat.com \
    --cc=prsampat@amd.com \
    --cc=shuah@kernel.org \
    /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