mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: seanjc@google.com, jmattson@google.com
Cc: pbonzini@redhat.com, kvm@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org, zhao1.liu@intel.com,
	chang.seok.bae@intel.com, Chao Gao <chao.gao@intel.com>
Subject: [PATCH v9 10/20] KVM: nVMX: Propagate extended instruction information
Date: Tue, 17 Nov 2026 18:03:00 +0000	[thread overview]
Message-ID: <20261117180310.921701-11-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20261117180310.921701-1-chang.seok.bae@intel.com>

Define the new extended_instruction_info field in struct vmcs12 and
propagate it to nested VMX. Gate the propagation on the guest APX
enumeration, which aligns with bare metal behavior. Thus, define the
CPUID bit here too.

Suggested-by: Chao Gao <chao.gao@intel.com>
Tested-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Link: https://lore.kernel.org/aRvOSnaUt1E+%2FpkC@intel.com
---
V8 -> V9: Extend cpu_has_vmcs12_field() (Jim Mattson)
---
 arch/x86/kvm/reverse_cpuid.h | 2 ++
 arch/x86/kvm/vmx/nested.c    | 3 +++
 arch/x86/kvm/vmx/vmcs12.c    | 4 ++++
 arch/x86/kvm/vmx/vmcs12.h    | 3 ++-
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h
index 89345af0f7ad..1ff87fe63c3c 100644
--- a/arch/x86/kvm/reverse_cpuid.h
+++ b/arch/x86/kvm/reverse_cpuid.h
@@ -37,6 +37,7 @@
 #define X86_FEATURE_AVX_VNNI_INT16      KVM_X86_FEATURE(CPUID_7_1_EDX, 10)
 #define X86_FEATURE_PREFETCHITI         KVM_X86_FEATURE(CPUID_7_1_EDX, 14)
 #define X86_FEATURE_AVX10               KVM_X86_FEATURE(CPUID_7_1_EDX, 19)
+#define KVM_X86_FEATURE_APX             KVM_X86_FEATURE(CPUID_7_1_EDX, 21)
 
 /* Intel-defined sub-features, CPUID level 0x00000007:2 (EDX) */
 #define X86_FEATURE_INTEL_PSFD		KVM_X86_FEATURE(CPUID_7_2_EDX, 0)
@@ -146,6 +147,7 @@ static __always_inline u32 __feature_translate(int x86_feature)
 	KVM_X86_TRANSLATE_FEATURE(SGX1);
 	KVM_X86_TRANSLATE_FEATURE(SGX2);
 	KVM_X86_TRANSLATE_FEATURE(SGX_EDECCSSA);
+	KVM_X86_TRANSLATE_FEATURE(APX);
 	KVM_X86_TRANSLATE_FEATURE(CONSTANT_TSC);
 	KVM_X86_TRANSLATE_FEATURE(PERFMON_V2);
 	KVM_X86_TRANSLATE_FEATURE(RRSBA_CTRL);
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index aebdad142d67..3899d50b3e64 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -4751,6 +4751,9 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
 		vmcs12->vm_exit_intr_info = exit_intr_info;
 		vmcs12->vm_exit_instruction_len = exit_insn_len;
 		vmcs12->vmx_instruction_info = vmcs_read32(VMX_INSTRUCTION_INFO);
+		/* The extended field exists whenever APX is enumerated. */
+		if (guest_cpu_cap_has(vcpu, X86_FEATURE_APX))
+			vmcs12->extended_instruction_info = vmcs_read64(EXTENDED_INSTRUCTION_INFO);
 
 		/*
 		 * According to spec, there's no need to store the guest's
diff --git a/arch/x86/kvm/vmx/vmcs12.c b/arch/x86/kvm/vmx/vmcs12.c
index 1ebe67c384ad..dc6a22db7388 100644
--- a/arch/x86/kvm/vmx/vmcs12.c
+++ b/arch/x86/kvm/vmx/vmcs12.c
@@ -2,6 +2,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include "vmcs12.h"
+#include "vmx_ops.h"
 
 #define VMCS12_OFFSET(x) offsetof(struct vmcs12, x)
 #define FIELD(number, name)	[ENC_TO_VMCS12_IDX(number)] = VMCS12_OFFSET(name)
@@ -53,6 +54,7 @@ static const u16 kvm_supported_vmcs12_field_offsets[] __initconst = {
 	FIELD64(XSS_EXIT_BITMAP, xss_exit_bitmap),
 	FIELD64(ENCLS_EXITING_BITMAP, encls_exiting_bitmap),
 	FIELD64(GUEST_PHYSICAL_ADDRESS, guest_physical_address),
+	FIELD64(EXTENDED_INSTRUCTION_INFO, extended_instruction_info),
 	FIELD64(VMCS_LINK_POINTER, vmcs_link_pointer),
 	FIELD64(GUEST_IA32_DEBUGCTL, guest_ia32_debugctl),
 	FIELD64(GUEST_IA32_PAT, guest_ia32_pat),
@@ -203,6 +205,8 @@ static __init bool cpu_has_vmcs12_field(unsigned int idx)
 	case HOST_SSP:
 	case HOST_INTR_SSP_TABLE:
 		return cpu_has_load_cet_ctrl();
+	VMCS12_CASE64(EXTENDED_INSTRUCTION_INFO):
+		return vmx_instr_info_extended();
 
 	/* KVM always emulates PML and the VMX preemption timer in software. */
 	case GUEST_PML_INDEX:
diff --git a/arch/x86/kvm/vmx/vmcs12.h b/arch/x86/kvm/vmx/vmcs12.h
index 21cd1b75e4fd..25e9a41c248f 100644
--- a/arch/x86/kvm/vmx/vmcs12.h
+++ b/arch/x86/kvm/vmx/vmcs12.h
@@ -71,7 +71,7 @@ struct __packed vmcs12 {
 	u64 pml_address;
 	u64 encls_exiting_bitmap;
 	u64 tsc_multiplier;
-	u64 padding64[1]; /* room for future expansion */
+	u64 extended_instruction_info;
 	/*
 	 * To allow migration of L1 (complete with its L2 guests) between
 	 * machines of different natural widths (32 or 64 bit), we cannot have
@@ -261,6 +261,7 @@ static inline void vmx_check_vmcs12_offsets(void)
 	CHECK_OFFSET(pml_address, 312);
 	CHECK_OFFSET(encls_exiting_bitmap, 320);
 	CHECK_OFFSET(tsc_multiplier, 328);
+	CHECK_OFFSET(extended_instruction_info, 336);
 	CHECK_OFFSET(cr0_guest_host_mask, 344);
 	CHECK_OFFSET(cr4_guest_host_mask, 352);
 	CHECK_OFFSET(cr0_read_shadow, 360);
-- 
2.53.0


  parent reply	other threads:[~2026-11-17 18:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 18:02 [PATCH v9 00/20] KVM: x86: Enable APX for guest Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 01/20] KVM: x86: Extend VCPU registers for EGPRs Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 02/20] KVM: VMX: Save guest EGPRs in VCPU cache Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 03/20] KVM: x86: Support EGPRs on VCPU RESET/INIT events Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 04/20] KVM: x86: Support APX state for XSAVE ABI Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 05/20] KVM: VMX: Refactor VMX instruction information access Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 06/20] KVM: VMX: Refactor instruction information decoding Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 07/20] KVM: VMX: Remove unused control-register access defines Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 08/20] KVM: VMX: Refactor register index retrieval from exit qualification Chang S. Bae
2026-11-17 18:02 ` [PATCH v9 09/20] KVM: VMX: Support instruction information extension Chang S. Bae
2026-11-17 18:03 ` Chang S. Bae [this message]
2026-11-17 18:03 ` [PATCH v9 11/20] KVM: x86: Support EGPR accessing and tracking for emulator Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 12/20] KVM: x86: Handle EGPR index and REX2-incompatible opcodes Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 13/20] KVM: x86: Support REX2-prefixed opcode decode Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 14/20] KVM: x86: Document EVEX-prefix not implemented Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 15/20] KVM: x86: Move KVM_SUPPORTED_{XCR0,XSS} into kvm_x86_vendor_init() Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 16/20] KVM: x86: Guard valid XCR0.APX settings Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 17/20] KVM: x86: Add APX to supported XCR0 Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 18/20] KVM: x86: Expose APX feature to userspace Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 19/20] KVM: selftests: Add APX state and ABI test Chang S. Bae
2026-11-17 18:03 ` [PATCH v9 20/20] KVM: selftests: Add APX state handling and XCR0 sanity checks Chang S. Bae

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=20261117180310.921701-11-chang.seok.bae@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=chao.gao@intel.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=x86@kernel.org \
    --cc=zhao1.liu@intel.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 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®