@@ -2818,7 +2818,7 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx)
2818
2818
vmx -> nested .nested_vmx_secondary_ctls_high );
2819
2819
vmx -> nested .nested_vmx_secondary_ctls_low = 0 ;
2820
2820
vmx -> nested .nested_vmx_secondary_ctls_high &=
2821
- SECONDARY_EXEC_RDRAND | SECONDARY_EXEC_RDSEED |
2821
+ SECONDARY_EXEC_RDSEED |
2822
2822
SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
2823
2823
SECONDARY_EXEC_DESC |
2824
2824
SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE |
@@ -3671,6 +3671,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
3671
3671
SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
3672
3672
SECONDARY_EXEC_SHADOW_VMCS |
3673
3673
SECONDARY_EXEC_XSAVES |
3674
+ SECONDARY_EXEC_RDRAND |
3674
3675
SECONDARY_EXEC_ENABLE_PML |
3675
3676
SECONDARY_EXEC_TSC_SCALING |
3676
3677
SECONDARY_EXEC_ENABLE_VMFUNC ;
@@ -5273,6 +5274,12 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx)
5273
5274
return exec_control ;
5274
5275
}
5275
5276
5277
+ static bool vmx_rdrand_supported (void )
5278
+ {
5279
+ return vmcs_config .cpu_based_2nd_exec_ctrl &
5280
+ SECONDARY_EXEC_RDRAND ;
5281
+ }
5282
+
5276
5283
static void vmx_compute_secondary_exec_control (struct vcpu_vmx * vmx )
5277
5284
{
5278
5285
struct kvm_vcpu * vcpu = & vmx -> vcpu ;
@@ -5342,6 +5349,21 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)
5342
5349
}
5343
5350
}
5344
5351
5352
+ if (vmx_rdrand_supported ()) {
5353
+ bool rdrand_enabled = guest_cpuid_has (vcpu , X86_FEATURE_RDRAND );
5354
+ if (rdrand_enabled )
5355
+ exec_control &= ~SECONDARY_EXEC_RDRAND ;
5356
+
5357
+ if (nested ) {
5358
+ if (rdrand_enabled )
5359
+ vmx -> nested .nested_vmx_secondary_ctls_high |=
5360
+ SECONDARY_EXEC_RDRAND ;
5361
+ else
5362
+ vmx -> nested .nested_vmx_secondary_ctls_high &=
5363
+ ~SECONDARY_EXEC_RDRAND ;
5364
+ }
5365
+ }
5366
+
5345
5367
vmx -> secondary_exec_control = exec_control ;
5346
5368
}
5347
5369
@@ -6847,6 +6869,12 @@ static int handle_mwait(struct kvm_vcpu *vcpu)
6847
6869
return handle_nop (vcpu );
6848
6870
}
6849
6871
6872
+ static int handle_invalid_op (struct kvm_vcpu * vcpu )
6873
+ {
6874
+ kvm_queue_exception (vcpu , UD_VECTOR );
6875
+ return 1 ;
6876
+ }
6877
+
6850
6878
static int handle_monitor_trap (struct kvm_vcpu * vcpu )
6851
6879
{
6852
6880
return 1 ;
@@ -8090,6 +8118,7 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
8090
8118
[EXIT_REASON_MONITOR_INSTRUCTION ] = handle_monitor ,
8091
8119
[EXIT_REASON_INVEPT ] = handle_invept ,
8092
8120
[EXIT_REASON_INVVPID ] = handle_invvpid ,
8121
+ [EXIT_REASON_RDRAND ] = handle_invalid_op ,
8093
8122
[EXIT_REASON_XSAVES ] = handle_xsaves ,
8094
8123
[EXIT_REASON_XRSTORS ] = handle_xrstors ,
8095
8124
[EXIT_REASON_PML_FULL ] = handle_pml_full ,
0 commit comments