Skip to content

Commit 75f4fc8

Browse files
jsmattsonjrbonzini
authored andcommitted
kvm: vmx: Raise #UD on unsupported RDSEED
A guest may not be configured to support RDSEED, even when the host does. If the guest does not support RDSEED, intercept the instruction and synthesize #UD. Also clear the "allowed-1" bit for RDSEED exiting in the IA32_VMX_PROCBASED_CTLS2 MSR. Signed-off-by: Jim Mattson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 45ec368 commit 75f4fc8

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

arch/x86/kvm/vmx.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,6 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
28182818
vmx->nested.nested_vmx_secondary_ctls_high);
28192819
vmx->nested.nested_vmx_secondary_ctls_low = 0;
28202820
vmx->nested.nested_vmx_secondary_ctls_high &=
2821-
SECONDARY_EXEC_RDSEED |
28222821
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
28232822
SECONDARY_EXEC_DESC |
28242823
SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
@@ -3671,6 +3670,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
36713670
SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
36723671
SECONDARY_EXEC_SHADOW_VMCS |
36733672
SECONDARY_EXEC_XSAVES |
3673+
SECONDARY_EXEC_RDSEED |
36743674
SECONDARY_EXEC_RDRAND |
36753675
SECONDARY_EXEC_ENABLE_PML |
36763676
SECONDARY_EXEC_TSC_SCALING |
@@ -5280,6 +5280,12 @@ static bool vmx_rdrand_supported(void)
52805280
SECONDARY_EXEC_RDRAND;
52815281
}
52825282

5283+
static bool vmx_rdseed_supported(void)
5284+
{
5285+
return vmcs_config.cpu_based_2nd_exec_ctrl &
5286+
SECONDARY_EXEC_RDSEED;
5287+
}
5288+
52835289
static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)
52845290
{
52855291
struct kvm_vcpu *vcpu = &vmx->vcpu;
@@ -5364,6 +5370,21 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)
53645370
}
53655371
}
53665372

5373+
if (vmx_rdseed_supported()) {
5374+
bool rdseed_enabled = guest_cpuid_has(vcpu, X86_FEATURE_RDSEED);
5375+
if (rdseed_enabled)
5376+
exec_control &= ~SECONDARY_EXEC_RDSEED;
5377+
5378+
if (nested) {
5379+
if (rdseed_enabled)
5380+
vmx->nested.nested_vmx_secondary_ctls_high |=
5381+
SECONDARY_EXEC_RDSEED;
5382+
else
5383+
vmx->nested.nested_vmx_secondary_ctls_high &=
5384+
~SECONDARY_EXEC_RDSEED;
5385+
}
5386+
}
5387+
53675388
vmx->secondary_exec_control = exec_control;
53685389
}
53695390

@@ -8119,6 +8140,7 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
81198140
[EXIT_REASON_INVEPT] = handle_invept,
81208141
[EXIT_REASON_INVVPID] = handle_invvpid,
81218142
[EXIT_REASON_RDRAND] = handle_invalid_op,
8143+
[EXIT_REASON_RDSEED] = handle_invalid_op,
81228144
[EXIT_REASON_XSAVES] = handle_xsaves,
81238145
[EXIT_REASON_XRSTORS] = handle_xrstors,
81248146
[EXIT_REASON_PML_FULL] = handle_pml_full,

0 commit comments

Comments
 (0)