summary refs log tree commit diff
path: root/kvm
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@chromium.org>2018-02-22 15:26:18 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-27 17:33:20 -0800
commitcda18d757b0f9bb67af649bca9c9f13b73e56afc (patch)
tree6ba744fc05c2c5810e7b8466764d98acd0a7f350 /kvm
parent4567a281a5c28e49479f916a057ee7b1f221925b (diff)
downloadcrosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.tar
crosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.tar.gz
crosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.tar.bz2
crosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.tar.lz
crosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.tar.xz
crosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.tar.zst
crosvm-cda18d757b0f9bb67af649bca9c9f13b73e56afc.zip
kvm: do not pass max number of cpuid entries in get_supported_cpuid()
It does not make sense to have users of the API limit number of cpuid
entries retrieved. Just have KVM select reasonable upper limit and
return the true number.

TEST=cargo test --features plugin; cargo test -p kvm
BUG=chromium:800626

Change-Id: I8ab7e8d901bc408d17c23bfe798d89f921488673
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933242
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'kvm')
-rw-r--r--kvm/src/lib.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs
index d1488d6..d87bc76 100644
--- a/kvm/src/lib.rs
+++ b/kvm/src/lib.rs
@@ -31,6 +31,8 @@ use sys_util::{ioctl, ioctl_with_val, ioctl_with_ref, ioctl_with_mut_ref, ioctl_
 
 pub use cap::*;
 
+const MAX_KVM_CPUID_ENTRIES: usize = 256;
+
 fn errno_result<T>() -> Result<T> {
     Err(Error::last())
 }
@@ -132,18 +134,14 @@ impl Kvm {
     }
 
     /// X86 specific call to get the system supported CPUID values
-    ///
-    /// # Arguments
-    ///
-    /// * `max_cpus` - Maximum number of cpuid entries to return.
     #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
-    pub fn get_supported_cpuid(&self, max_cpus: usize) -> Result<CpuId> {
-        let mut cpuid = CpuId::new(max_cpus);
+    pub fn get_supported_cpuid(&self) -> Result<CpuId> {
+        let mut cpuid = CpuId::new(MAX_KVM_CPUID_ENTRIES);
 
         let ret = unsafe {
             // ioctl is unsafe. The kernel is trusted not to write beyond the bounds of the memory
             // allocated for the struct. The limit is read from nent, which is set to the allocated
-            // size(max_cpus) above.
+            // size(MAX_KVM_CPUID_ENTRIES) above.
             ioctl_with_mut_ptr(self, KVM_GET_SUPPORTED_CPUID(), cpuid.as_mut_ptr())
         };
         if ret < 0 {