mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Javid Rzayev <javid.rzyv@gmail.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>,
	kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, Javid Rzayev <javid.rzyv@gmail.com>
Subject: [PATCH] KVM: selftests: Use __vmread() for the optional HOST_IA32_PERF_GLOBAL_CTRL field
Date: Mon, 23 Nov 2026 01:33:50 +0100	[thread overview]
Message-ID: <20261123003350.198278-1-javid.rzyv@gmail.com> (raw)

The HOST_IA32_PERF_GLOBAL_CTRL VMCS field exists only if the CPU supports
the "load IA32_PERF_GLOBAL_CTRL" VM-exit control, which is not always the
case.  E.g. when running on an Intel VM in Google Cloud with nested
virtualization enabled and no vPMU, VMREAD of this field fails.

init_vmcs_guest_state() copies the field into GUEST_IA32_PERF_GLOBAL_CTRL.
The write already uses __vmwrite() because the field is optional, but the
read uses vmread(), which asserts on failure since commit 4e824a04d4fa
("KVM: selftests: Always assert that vmreadz() succeeds").  As a result,
nested VMX tests (e.g. state_test, smm_test, nested_close_kvm_test) fail
with:

  vmread[0x2c04] hit VM-Fail

Read the field with __vmread() and copy it only if the read succeeds.

Fixes: 4e824a04d4fa ("KVM: selftests: Always assert that vmreadz() succeeds")
Signed-off-by: Javid Rzayev <javid.rzyv@gmail.com>
---
Tested on a Google Cloud n2-standard-128 VM (Intel, nested
virtualization enabled, no vPMU) running next-20261120:

  before: 15 nested VMX tests fail with "vmread[0x2c04] hit VM-Fail"
  after:  all of them pass

mmu_stress_test hits the 120s kselftest timeout both before and after
the patch; that is unrelated (the test scales with the host size).

 tools/testing/selftests/kvm/lib/x86/vmx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c b/tools/testing/selftests/kvm/lib/x86/vmx.c
index 5a06746eb..4b3e439ee 100644
--- a/tools/testing/selftests/kvm/lib/x86/vmx.c
+++ b/tools/testing/selftests/kvm/lib/x86/vmx.c
@@ -348,6 +348,8 @@ static inline void init_vmcs_host_state(void)
  */
 static inline void init_vmcs_guest_state(void *rip, void *rsp)
 {
+	u64 val;
+
 	vmwrite(GUEST_ES_SELECTOR, vmread(HOST_ES_SELECTOR));
 	vmwrite(GUEST_CS_SELECTOR, vmread(HOST_CS_SELECTOR));
 	vmwrite(GUEST_SS_SELECTOR, vmread(HOST_SS_SELECTOR));
@@ -363,8 +365,8 @@ static inline void init_vmcs_guest_state(void *rip, void *rsp)
 	vmwrite(GUEST_IA32_DEBUGCTL, 0);
 	__vmwrite(GUEST_IA32_PAT, vmread(HOST_IA32_PAT));
 	__vmwrite(GUEST_IA32_EFER, vmread(HOST_IA32_EFER));
-	__vmwrite(GUEST_IA32_PERF_GLOBAL_CTRL,
-		  vmread(HOST_IA32_PERF_GLOBAL_CTRL));
+	if (!__vmread(HOST_IA32_PERF_GLOBAL_CTRL, &val))
+		__vmwrite(GUEST_IA32_PERF_GLOBAL_CTRL, val);
 
 	vmwrite(GUEST_ES_LIMIT, -1);
 	vmwrite(GUEST_CS_LIMIT, -1);
-- 
2.47.3


                 reply	other threads:[~2026-11-23  0:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261123003350.198278-1-javid.rzyv@gmail.com \
    --to=javid.rzyv@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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

all inboxes | Powered by JetHome®