clippy: Fix kvm(_sys)

This adds a blanket allow to the top of the bindings file. The bindings
will need to be regenerated in a separate CL.

BUG=b:192373803
TEST=./tools/presubmit

Change-Id: I6554d17fffde2089e29bf2e7c184b8cac937db6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3439049
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2022-02-07 11:00:04 -08:00 committed by Commit Bot
parent f881af3c1f
commit 53fccea4e7
5 changed files with 38 additions and 39 deletions

View file

@ -1735,7 +1735,7 @@ mod tests {
#[test] #[test]
fn create_vm() { fn create_vm() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x1000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x1000)]).unwrap();
Vm::new(&kvm, gm).unwrap(); Vm::new(&kvm, gm).unwrap();
} }
@ -1750,7 +1750,7 @@ mod tests {
#[test] #[test]
fn check_vm_extension() { fn check_vm_extension() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x1000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x1000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
assert!(vm.check_extension(Cap::UserMemory)); assert!(vm.check_extension(Cap::UserMemory));
// I assume nobody is testing this on s390 // I assume nobody is testing this on s390
@ -1784,11 +1784,8 @@ mod tests {
#[test] #[test]
fn add_memory() { fn add_memory() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![ let gm =
(GuestAddress(0), 0x1000), GuestMemory::new(&[(GuestAddress(0), 0x1000), (GuestAddress(0x5000), 0x5000)]).unwrap();
(GuestAddress(0x5000), 0x5000),
])
.unwrap();
let mut vm = Vm::new(&kvm, gm).unwrap(); let mut vm = Vm::new(&kvm, gm).unwrap();
let mem_size = 0x1000; let mem_size = 0x1000;
let mem = MemoryMappingBuilder::new(mem_size).build().unwrap(); let mem = MemoryMappingBuilder::new(mem_size).build().unwrap();
@ -1802,7 +1799,7 @@ mod tests {
#[test] #[test]
fn add_memory_ro() { fn add_memory_ro() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x1000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x1000)]).unwrap();
let mut vm = Vm::new(&kvm, gm).unwrap(); let mut vm = Vm::new(&kvm, gm).unwrap();
let mem_size = 0x1000; let mem_size = 0x1000;
let mem = MemoryMappingBuilder::new(mem_size).build().unwrap(); let mem = MemoryMappingBuilder::new(mem_size).build().unwrap();
@ -1813,7 +1810,7 @@ mod tests {
#[test] #[test]
fn remove_memory_region() { fn remove_memory_region() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x1000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x1000)]).unwrap();
let mut vm = Vm::new(&kvm, gm).unwrap(); let mut vm = Vm::new(&kvm, gm).unwrap();
let mem_size = 0x1000; let mem_size = 0x1000;
let mem = MemoryMappingBuilder::new(mem_size).build().unwrap(); let mem = MemoryMappingBuilder::new(mem_size).build().unwrap();
@ -1829,7 +1826,7 @@ mod tests {
#[test] #[test]
fn remove_invalid_memory() { fn remove_invalid_memory() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x1000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x1000)]).unwrap();
let mut vm = Vm::new(&kvm, gm).unwrap(); let mut vm = Vm::new(&kvm, gm).unwrap();
assert!(vm.remove_memory_region(0).is_err()); assert!(vm.remove_memory_region(0).is_err());
} }
@ -1837,7 +1834,7 @@ mod tests {
#[test] #[test]
fn overlap_memory() { fn overlap_memory() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let mut vm = Vm::new(&kvm, gm).unwrap(); let mut vm = Vm::new(&kvm, gm).unwrap();
let mem_size = 0x2000; let mem_size = 0x2000;
let mem = MemoryMappingBuilder::new(mem_size).build().unwrap(); let mem = MemoryMappingBuilder::new(mem_size).build().unwrap();
@ -1849,7 +1846,7 @@ mod tests {
#[test] #[test]
fn get_memory() { fn get_memory() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x1000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x1000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let obj_addr = GuestAddress(0xf0); let obj_addr = GuestAddress(0xf0);
vm.get_memory().write_obj_at_addr(67u8, obj_addr).unwrap(); vm.get_memory().write_obj_at_addr(67u8, obj_addr).unwrap();
@ -1861,7 +1858,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn clock_handling() { fn clock_handling() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let mut clock_data = vm.get_clock().unwrap(); let mut clock_data = vm.get_clock().unwrap();
clock_data.clock += 1000; clock_data.clock += 1000;
@ -1872,7 +1869,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn pic_handling() { fn pic_handling() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.create_irq_chip().unwrap(); vm.create_irq_chip().unwrap();
let pic_state = vm.get_pic_state(PicId::Secondary).unwrap(); let pic_state = vm.get_pic_state(PicId::Secondary).unwrap();
@ -1883,7 +1880,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn ioapic_handling() { fn ioapic_handling() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.create_irq_chip().unwrap(); vm.create_irq_chip().unwrap();
let ioapic_state = vm.get_ioapic_state().unwrap(); let ioapic_state = vm.get_ioapic_state().unwrap();
@ -1894,7 +1891,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn pit_handling() { fn pit_handling() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.create_irq_chip().unwrap(); vm.create_irq_chip().unwrap();
vm.create_pit().unwrap(); vm.create_pit().unwrap();
@ -1905,7 +1902,7 @@ mod tests {
#[test] #[test]
fn register_ioevent() { fn register_ioevent() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let evtfd = Event::new().unwrap(); let evtfd = Event::new().unwrap();
vm.register_ioevent(&evtfd, IoeventAddress::Pio(0xf4), Datamatch::AnyLength) vm.register_ioevent(&evtfd, IoeventAddress::Pio(0xf4), Datamatch::AnyLength)
@ -1941,7 +1938,7 @@ mod tests {
#[test] #[test]
fn unregister_ioevent() { fn unregister_ioevent() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let evtfd = Event::new().unwrap(); let evtfd = Event::new().unwrap();
vm.register_ioevent(&evtfd, IoeventAddress::Pio(0xf4), Datamatch::AnyLength) vm.register_ioevent(&evtfd, IoeventAddress::Pio(0xf4), Datamatch::AnyLength)
@ -1969,7 +1966,7 @@ mod tests {
#[test] #[test]
fn irqfd_resample() { fn irqfd_resample() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let evtfd1 = Event::new().unwrap(); let evtfd1 = Event::new().unwrap();
let evtfd2 = Event::new().unwrap(); let evtfd2 = Event::new().unwrap();
@ -1985,7 +1982,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn set_gsi_routing() { fn set_gsi_routing() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.create_irq_chip().unwrap(); vm.create_irq_chip().unwrap();
vm.set_gsi_routing(&[]).unwrap(); vm.set_gsi_routing(&[]).unwrap();
@ -2027,7 +2024,7 @@ mod tests {
#[test] #[test]
fn create_vcpu() { fn create_vcpu() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
Vcpu::new(0, &kvm, &vm).unwrap(); Vcpu::new(0, &kvm, &vm).unwrap();
} }
@ -2036,7 +2033,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn debugregs() { fn debugregs() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
let mut dregs = vcpu.get_debugregs().unwrap(); let mut dregs = vcpu.get_debugregs().unwrap();
@ -2054,7 +2051,7 @@ mod tests {
return; return;
} }
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
let mut xcrs = vcpu.get_xcrs().unwrap(); let mut xcrs = vcpu.get_xcrs().unwrap();
@ -2068,7 +2065,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn get_msrs() { fn get_msrs() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
let mut msrs = vec![ let mut msrs = vec![
@ -2091,7 +2088,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn get_hyperv_cpuid() { fn get_hyperv_cpuid() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
let cpuid = vcpu.get_hyperv_cpuid(); let cpuid = vcpu.get_hyperv_cpuid();
@ -2108,12 +2105,14 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn enable_feature() { fn enable_feature() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.create_irq_chip().unwrap(); vm.create_irq_chip().unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
let mut cap: kvm_enable_cap = Default::default(); let cap: kvm_enable_cap = kvm_sys::kvm_enable_cap {
cap.cap = kvm_sys::KVM_CAP_HYPERV_SYNIC; cap: kvm_sys::KVM_CAP_HYPERV_SYNIC,
..Default::default()
};
unsafe { vcpu.kvm_enable_cap(&cap) }.unwrap(); unsafe { vcpu.kvm_enable_cap(&cap) }.unwrap();
} }
@ -2121,7 +2120,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn mp_state() { fn mp_state() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.create_irq_chip().unwrap(); vm.create_irq_chip().unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
@ -2132,7 +2131,7 @@ mod tests {
#[test] #[test]
fn set_signal_mask() { fn set_signal_mask() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
let vcpu = Vcpu::new(0, &kvm, &vm).unwrap(); let vcpu = Vcpu::new(0, &kvm, &vm).unwrap();
vcpu.set_signal_mask(&[base::SIGRTMIN() + 0]).unwrap(); vcpu.set_signal_mask(&[base::SIGRTMIN() + 0]).unwrap();
@ -2151,7 +2150,7 @@ mod tests {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn set_identity_map_addr() { fn set_identity_map_addr() {
let kvm = Kvm::new().unwrap(); let kvm = Kvm::new().unwrap();
let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); let gm = GuestMemory::new(&[(GuestAddress(0), 0x10000)]).unwrap();
let vm = Vm::new(&kvm, gm).unwrap(); let vm = Vm::new(&kvm, gm).unwrap();
vm.set_identity_map_addr(GuestAddress(0x20000)).unwrap(); vm.set_identity_map_addr(GuestAddress(0x20000)).unwrap();
} }

View file

@ -14,17 +14,17 @@ fn test_run() {
let code = [ let code = [
0xba, 0xf8, 0x03, /* mov $0x3f8, %dx */ 0xba, 0xf8, 0x03, /* mov $0x3f8, %dx */
0x00, 0xd8, /* add %bl, %al */ 0x00, 0xd8, /* add %bl, %al */
0x04, '0' as u8, /* add $'0', %al */ 0x04, b'0', /* add $'0', %al */
0xee, /* out %al, (%dx) */ 0xee, /* out %al, (%dx) */
0xb0, '\n' as u8, /* mov $'\n', %al */ 0xb0, b'\n', /* mov $'\n', %al */
0xee, /* out %al, (%dx) */ 0xee, /* out %al, (%dx) */
0x2e, 0xc6, 0x06, 0xf1, 0x10, 0x13, /* movb $0x13, %cs:0xf1 */ 0x2e, 0xc6, 0x06, 0xf1, 0x10, 0x13, /* movb $0x13, %cs:0xf1 */
0xf4, /* hlt */ 0xf4, /* hlt */
]; ];
let mem_size = 0x1000; let mem_size = 0x1000;
let load_addr = GuestAddress(0x1000); let load_addr = GuestAddress(0x1000);
let mem = GuestMemory::new(&vec![(load_addr, mem_size)]).unwrap(); let mem = GuestMemory::new(&[(load_addr, mem_size)]).unwrap();
let kvm = Kvm::new().expect("new kvm failed"); let kvm = Kvm::new().expect("new kvm failed");
let vm = Vm::new(&kvm, mem).expect("new vm failed"); let vm = Vm::new(&kvm, mem).expect("new vm failed");

View file

@ -11,6 +11,8 @@
* $ bindgen --with-derive-default -o bindings.rs include/linux/kvm.h -- -Iinclude * $ bindgen --with-derive-default -o bindings.rs include/linux/kvm.h -- -Iinclude
*/ */
#![allow(warnings)]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage, Align> pub struct __BindgenBitfieldUnit<Storage, Align>

View file

@ -8,7 +8,7 @@ use libc::{c_char, ioctl, open, O_RDWR};
use kvm_sys::*; use kvm_sys::*;
const KVM_PATH: &'static str = "/dev/kvm\0"; const KVM_PATH: &str = "/dev/kvm\0";
#[test] #[test]
fn get_version() { fn get_version() {

View file

@ -14,8 +14,6 @@ cd "$(dirname $0)/.."
# TODO(b/192373803): Clean up clippy error is the following crates # TODO(b/192373803): Clean up clippy error is the following crates
EXCLUDE=( EXCLUDE=(
kvm # 641 errors
kvm_sys # 613 errors
libvda # 79 errors libvda # 79 errors
net_sys # 3 errors net_sys # 3 errors
virtio_sys # 9 errors virtio_sys # 9 errors