@@ -10,7 +10,6 @@ use serde::{Deserialize, Serialize};
1010#[ cfg( target_arch = "x86_64" ) ]
1111use crate :: arch:: x86_64:: xstate:: { XstateError , request_dynamic_xstate_features} ;
1212use crate :: cpu_config:: templates:: KvmCapability ;
13- use crate :: vstate:: memory:: { GuestMemory , GuestMemoryMmap } ;
1413
1514/// Errors associated with the wrappers over KVM ioctls.
1615/// Needs `rustfmt::skip` to make multiline comments work
@@ -27,8 +26,6 @@ pub enum KvmError {
2726 #[ cfg( target_arch = "x86_64" ) ]
2827 /// Failed to get supported cpuid: {0}
2928 GetSupportedCpuId ( kvm_ioctls:: Error ) ,
30- /// The number of configured slots is bigger than the maximum reported by KVM
31- NotEnoughMemorySlots ,
3229 #[ cfg( target_arch = "x86_64" ) ]
3330 /// Failed to request permission for dynamic XSTATE features: {0}
3431 XstateFeatures ( XstateError ) ,
@@ -39,8 +36,6 @@ pub enum KvmError {
3936pub struct Kvm {
4037 /// KVM fd.
4138 pub fd : KvmFd ,
42- /// Maximum number of memory slots allowed by KVM.
43- pub max_memslots : usize ,
4439 /// Additional capabilities that were specified in cpu template.
4540 pub kvm_cap_modifiers : Vec < KvmCapability > ,
4641
@@ -65,13 +60,10 @@ impl Kvm {
6560 // Check that all desired capabilities are supported.
6661 Self :: check_capabilities ( & kvm_fd, & total_caps) . map_err ( KvmError :: Capabilities ) ?;
6762
68- let max_memslots = kvm_fd. get_nr_memslots ( ) ;
69-
7063 #[ cfg( target_arch = "aarch64" ) ]
7164 {
7265 Ok ( Self {
7366 fd : kvm_fd,
74- max_memslots,
7567 kvm_cap_modifiers,
7668 } )
7769 }
@@ -86,7 +78,6 @@ impl Kvm {
8678
8779 Ok ( Kvm {
8880 fd : kvm_fd,
89- max_memslots,
9081 kvm_cap_modifiers,
9182 supported_cpuid,
9283 } )
@@ -99,15 +90,6 @@ impl Kvm {
9990 crate :: arch:: x86_64:: msr:: get_msrs_to_save ( & self . fd )
10091 }
10192
102- /// Check guest memory does not have more regions than kvm allows.
103- pub fn check_memory ( & self , guest_mem : & GuestMemoryMmap ) -> Result < ( ) , KvmError > {
104- if guest_mem. num_regions ( ) > self . max_memslots {
105- Err ( KvmError :: NotEnoughMemorySlots )
106- } else {
107- Ok ( ( ) )
108- }
109- }
110-
11193 fn combine_capabilities ( kvm_cap_modifiers : & [ KvmCapability ] ) -> Vec < u32 > {
11294 let mut total_caps = Self :: DEFAULT_CAPABILITIES . to_vec ( ) ;
11395 for modifier in kvm_cap_modifiers. iter ( ) {
@@ -143,6 +125,11 @@ impl Kvm {
143125 kvm_cap_modifiers : self . kvm_cap_modifiers . clone ( ) ,
144126 }
145127 }
128+
129+ /// Returns the maximal number of memslots allowed in a [`Vm`]
130+ pub fn max_nr_memslots ( & self ) -> usize {
131+ self . fd . get_nr_memslots ( )
132+ }
146133}
147134#[ cfg( target_arch = "aarch64" ) ]
148135/// Optional capabilities.
0 commit comments