kvm: plumb in KVM_GET_EMULATED_CPUID

This plumbs in KVM_GET_EMULATED_CPUID to allow userspace to figure out
whether a certain feature(s) can be used or whether they are too
expensive.

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

Change-Id: I914415a311f40d079b1703efb5129fd91b0d24ad
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/933243
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Dmitry Torokhov 2018-02-22 15:37:49 -08:00 committed by chrome-bot
parent ae5878bef1
commit c73d390522

View file

@ -133,16 +133,15 @@ impl Kvm {
} }
} }
/// X86 specific call to get the system supported CPUID values
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn get_supported_cpuid(&self) -> Result<CpuId> { fn get_cpuid(&self, kind: u64) -> Result<CpuId> {
let mut cpuid = CpuId::new(MAX_KVM_CPUID_ENTRIES); let mut cpuid = CpuId::new(MAX_KVM_CPUID_ENTRIES);
let ret = unsafe { let ret = unsafe {
// ioctl is unsafe. The kernel is trusted not to write beyond the bounds of the memory // 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 // allocated for the struct. The limit is read from nent, which is set to the allocated
// size(MAX_KVM_CPUID_ENTRIES) above. // size(MAX_KVM_CPUID_ENTRIES) above.
ioctl_with_mut_ptr(self, KVM_GET_SUPPORTED_CPUID(), cpuid.as_mut_ptr()) ioctl_with_mut_ptr(self, kind, cpuid.as_mut_ptr())
}; };
if ret < 0 { if ret < 0 {
return errno_result(); return errno_result();
@ -150,6 +149,18 @@ impl Kvm {
Ok(cpuid) Ok(cpuid)
} }
/// X86 specific call to get the system supported CPUID values
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn get_supported_cpuid(&self) -> Result<CpuId> {
self.get_cpuid(KVM_GET_SUPPORTED_CPUID())
}
/// X86 specific call to get the system emulated CPUID values
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn get_emulated_cpuid(&self) -> Result<CpuId> {
self.get_cpuid(KVM_GET_EMULATED_CPUID())
}
} }
impl AsRawFd for Kvm { impl AsRawFd for Kvm {