@@ -111,6 +111,8 @@ pub struct HostContext {
111111 pub vpci_supported : bool ,
112112 /// Hypervisor backend that OpenVMM will select on this host.
113113 pub openvmm_hypervisor : Option < OpenVmmHypervisor > ,
114+ /// Whether KVM supports nested-state ioctls, required for nested reset.
115+ pub kvm_nested_state_supported : bool ,
114116 /// Whether MSHV implements partition scrub, required for nested reset.
115117 pub mshv_partition_scrub_supported : bool ,
116118}
@@ -167,6 +169,13 @@ impl HostContext {
167169 None
168170 } ;
169171
172+ let kvm_nested_state_supported = if openvmm_hypervisor == Some ( OpenVmmHypervisor :: Kvm ) {
173+ openvmm_hypervisors:: kvm_nested_state_available ( )
174+ . expect ( "failed to probe KVM nested-state support" )
175+ } else {
176+ false
177+ } ;
178+
170179 let mshv_partition_scrub_supported = if openvmm_hypervisor == Some ( OpenVmmHypervisor :: Mshv )
171180 {
172181 openvmm_hypervisors:: mshv_partition_scrub_available ( )
@@ -213,6 +222,7 @@ impl HostContext {
213222 } ,
214223 vpci_supported,
215224 openvmm_hypervisor,
225+ kvm_nested_state_supported,
216226 mshv_partition_scrub_supported,
217227 }
218228 }
@@ -357,7 +367,8 @@ fn available_capabilities(context: &HostContext, vmm: VmmType) -> BTreeSet<&'sta
357367 }
358368
359369 if vmm == VmmType :: OpenVmm
360- && ( context. openvmm_hypervisor == Some ( OpenVmmHypervisor :: Kvm )
370+ && ( ( context. openvmm_hypervisor == Some ( OpenVmmHypervisor :: Kvm )
371+ && context. kvm_nested_state_supported )
361372 || ( context. openvmm_hypervisor == Some ( OpenVmmHypervisor :: Mshv )
362373 && context. mshv_partition_scrub_supported ) )
363374 {
@@ -419,6 +430,7 @@ mod tests {
419430 execution_environment : ExecutionEnvironment :: Baremetal ,
420431 vpci_supported : false ,
421432 openvmm_hypervisor : Some ( openvmm_hypervisor) ,
433+ kvm_nested_state_supported : false ,
422434 mshv_partition_scrub_supported : false ,
423435 }
424436 }
@@ -458,7 +470,6 @@ mod tests {
458470 mshv. mshv_partition_scrub_supported = true ;
459471 assert ! ( requirement. is_satisfied( & mshv) ) ;
460472
461- assert ! ( requirement. is_satisfied( & host_context( OpenVmmHypervisor :: Kvm ) ) ) ;
462473 assert ! ( !requirement. is_satisfied( & host_context( OpenVmmHypervisor :: Whp ) ) ) ;
463474 assert ! ( !requirement. is_satisfied( & host_context( OpenVmmHypervisor :: Hvf ) ) ) ;
464475 mshv. openvmm_hypervisor = None ;
@@ -472,6 +483,29 @@ mod tests {
472483 ) ;
473484 }
474485
486+ #[ test]
487+ fn nested_reset_requires_kvm_nested_state ( ) {
488+ let requirement = TestRequirement :: RequiresCapability {
489+ name : capabilities:: NESTED_RESET ,
490+ vmm : VmmType :: OpenVmm ,
491+ } ;
492+ let mut kvm = host_context ( OpenVmmHypervisor :: Kvm ) ;
493+ assert ! (
494+ TestRequirement :: RequiresCapability {
495+ name: capabilities:: NESTED_VIRT ,
496+ vmm: VmmType :: OpenVmm ,
497+ }
498+ . is_satisfied( & kvm)
499+ ) ;
500+ assert ! ( !requirement. is_satisfied( & kvm) ) ;
501+ kvm. kvm_nested_state_supported = true ;
502+ assert ! ( requirement. is_satisfied( & kvm) ) ;
503+ kvm. openvmm_hypervisor = Some ( OpenVmmHypervisor :: Mshv ) ;
504+ assert ! ( !requirement. is_satisfied( & kvm) ) ;
505+ kvm. openvmm_hypervisor = None ;
506+ assert ! ( !requirement. is_satisfied( & kvm) ) ;
507+ }
508+
475509 #[ test]
476510 fn openvmm_hypervisor_requirement_matches_the_selected_backend ( ) {
477511 let requirement = TestRequirement :: OpenVmmHypervisor ( OpenVmmHypervisor :: Mshv ) ;
0 commit comments