All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Chenyi Qiang <chenyi.qiang@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Maxim Levitsky <mlevitsk@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] nVMX: Fix testing failure for canonical checks when forced emulation is not available
Date: Tue, 3 Jun 2025 16:20:22 -0700	[thread overview]
Message-ID: <aD-DNn6ZnAAK4TmH@google.com> (raw)
In-Reply-To: <20250523090848.16133-1-chenyi.qiang@intel.com>

On Fri, May 23, 2025, Chenyi Qiang wrote:
> Use the _safe() variant instead of _fep_safe() to avoid failure if the
> forced emulated is not available.
> 
> Fixes: 05fbb364b5b2 ("nVMX: add a test for canonical checks of various host state vmcs12 fields")
> Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
> ---
>  x86/vmx_tests.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
> index 2f178227..01a15b7c 100644
> --- a/x86/vmx_tests.c
> +++ b/x86/vmx_tests.c
> @@ -10881,12 +10881,11 @@ static int set_host_value(u64 vmcs_field, u64 value)
>  	case HOST_BASE_GDTR:
>  		sgdt(&dt_ptr);
>  		dt_ptr.base = value;
> -		lgdt(&dt_ptr);
> -		return lgdt_fep_safe(&dt_ptr);
> +		return lgdt_safe(&dt_ptr);
>  	case HOST_BASE_IDTR:
>  		sidt(&dt_ptr);
>  		dt_ptr.base = value;
> -		return lidt_fep_safe(&dt_ptr);
> +		return lidt_safe(&dt_ptr);

Hmm, the main purpose of this particular test is to verify KVM's emulation of the
canonical checks, so it probably makes sense to force emulation when possible.

It's not the most performant approach, but how about this?

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 2f178227..fe53e989 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -10881,12 +10881,13 @@ static int set_host_value(u64 vmcs_field, u64 value)
        case HOST_BASE_GDTR:
                sgdt(&dt_ptr);
                dt_ptr.base = value;
-               lgdt(&dt_ptr);
-               return lgdt_fep_safe(&dt_ptr);
+               return is_fep_available() ? lgdt_fep_safe(&dt_ptr) :
+                                           lgdt_safe(&dt_ptr);
        case HOST_BASE_IDTR:
                sidt(&dt_ptr);
                dt_ptr.base = value;
-               return lidt_fep_safe(&dt_ptr);
+               return is_fep_available() ? lidt_fep_safe(&dt_ptr) :
+                                           lidt_safe(&dt_ptr);
        case HOST_BASE_TR:
                /* Set the base and clear the busy bit */
                set_gdt_entry(FIRST_SPARE_SEL, value, 0x200, 0x89, 0);

  reply	other threads:[~2025-06-03 23:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-23  9:08 [kvm-unit-tests PATCH] nVMX: Fix testing failure for canonical checks when forced emulation is not available Chenyi Qiang
2025-06-03 23:20 ` Sean Christopherson [this message]
2025-06-04  2:15   ` Chenyi Qiang
2025-06-04 19:41     ` Sean Christopherson
2025-06-05  1:16       ` Chenyi Qiang

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=aD-DNn6ZnAAK4TmH@google.com \
    --to=seanjc@google.com \
    --cc=chenyi.qiang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.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 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.