mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-12-26 21:38:25 +00:00
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:
parent
ae5878bef1
commit
c73d390522
1 changed files with 14 additions and 3 deletions
|
@ -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"))]
|
||||
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 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_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 {
|
||||
return errno_result();
|
||||
|
@ -150,6 +149,18 @@ impl Kvm {
|
|||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue