[PATCH v7 078/120] KVM: x86: Use parsed CPUID(0x12)
From: Ahmed S. Darwish
Date: Thu May 28 2026 - 12:24:45 EST
For KVM's SGX ECREATE intercept logic, use parsed CPUID(0x12).0 and
CPUID(0x12).1 instead of issuing direct CPUID queries.
This centralizes CPUID parsing and cached access across the kernel.
Signed-off-by: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
---
arch/x86/kvm/vmx/sgx.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c
index 29a1f8e3be60..3f381f0f2395 100644
--- a/arch/x86/kvm/vmx/sgx.c
+++ b/arch/x86/kvm/vmx/sgx.c
@@ -440,8 +440,12 @@ void vcpu_setup_sgx_lepubkeyhash(struct kvm_vcpu *vcpu)
*/
static bool sgx_intercept_encls_ecreate(struct kvm_vcpu *vcpu)
{
+ const struct cpuid_regs *sl0 = cpuid_subleaf_raw(&boot_cpu_data, 0x12, 0);
+ const struct cpuid_regs *sl1 = cpuid_subleaf_raw(&boot_cpu_data, 0x12, 1);
struct kvm_cpuid_entry2 *guest_cpuid;
- u32 eax, ebx, ecx, edx;
+
+ if (!sl0 || !sl1)
+ return true;
if (!vcpu->kvm->arch.sgx_provisioning_allowed)
return true;
@@ -450,17 +454,15 @@ static bool sgx_intercept_encls_ecreate(struct kvm_vcpu *vcpu)
if (!guest_cpuid)
return true;
- cpuid_count(0x12, 0, &eax, &ebx, &ecx, &edx);
- if (guest_cpuid->ebx != ebx || guest_cpuid->edx != edx)
+ if (guest_cpuid->ebx != sl0->ebx || guest_cpuid->edx != sl0->edx)
return true;
guest_cpuid = kvm_find_cpuid_entry_index(vcpu, 0x12, 1);
if (!guest_cpuid)
return true;
- cpuid_count(0x12, 1, &eax, &ebx, &ecx, &edx);
- if (guest_cpuid->eax != eax || guest_cpuid->ebx != ebx ||
- guest_cpuid->ecx != ecx || guest_cpuid->edx != edx)
+ if (guest_cpuid->eax != sl1->eax || guest_cpuid->ebx != sl1->ebx ||
+ guest_cpuid->ecx != sl1->ecx || guest_cpuid->edx != sl1->edx)
return true;
return false;
--
2.54.0