Skip to content

Commit 53cddc3

Browse files
authored
Merge branch 'main' into fix-vmclock-sigsegv
2 parents 60d258b + ef2c268 commit 53cddc3

38 files changed

Lines changed: 936 additions & 637 deletions

File tree

resources/guest_configs/debug.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ CONFIG_FRAME_POINTER=y
33
# CONFIG_KGDB_SERIAL_CONSOLE=y
44
CONFIG_DEBUG_INFO=y
55
CONFIG_DEBUG_INFO_DWARF4=y
6+
CONFIG_DEBUG_INFO_BTF=y

src/clippy-tracing/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ macro_rules! create_check_visitor_function {
128128
($func_name:ident, $item:ident) => {
129129
fn $func_name(&mut self, i: &syn::$item) {
130130
let attr = check_attributes(&i.attrs);
131-
if !attr.instrumented && !attr.test && i.sig.constness.is_none() {
131+
if !attr.instrumented && !attr.test && i.sig.constness.is_none() && i.sig.abi.is_none()
132+
{
132133
self.0 = Some(i.span());
133134
} else {
134135
self.visit_block(&i.block);
@@ -162,7 +163,8 @@ macro_rules! create_fix_visitor_function {
162163
fn $func_name(&mut self, i: &syn::$item) {
163164
let attr = check_attributes(&i.attrs);
164165

165-
if !attr.instrumented && !attr.test && i.sig.constness.is_none() {
166+
if !attr.instrumented && !attr.test && i.sig.constness.is_none() && i.sig.abi.is_none()
167+
{
166168
let line = i.span().start().line;
167169

168170
let attr_string = instrument(&i.sig, self.suffix, self.cfg_attr);

src/clippy-tracing/tests/integration_tests.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,36 @@ mod tests {
407407
check_file(GIVEN, &path);
408408
}
409409

410+
#[test]
411+
fn fix_skips_extern_c_fn() {
412+
const GIVEN: &str = "extern \"C\" fn handle_signal() {}\nfn normal() {}";
413+
const EXPECTED: &str =
414+
"extern \"C\" fn handle_signal() {}\n#[log_instrument::instrument]\nfn normal() {}";
415+
fix(GIVEN, EXPECTED, None);
416+
}
417+
418+
#[test]
419+
fn check_skips_extern_c_fn() {
420+
const GIVEN: &str = "extern \"C\" fn handle_signal() {}";
421+
let path = setup(GIVEN);
422+
let output = Command::new(BINARY)
423+
.args(["--action", "check", "--path", &path])
424+
.output()
425+
.unwrap();
426+
assert_eq!(output.status.code(), Some(0));
427+
assert_eq!(output.stdout, []);
428+
assert_eq!(output.stderr, []);
429+
remove_file(path).unwrap();
430+
}
431+
432+
#[test]
433+
fn fix_skips_extern_c_fn_in_impl() {
434+
const GIVEN: &str =
435+
"struct S;\nimpl S {\n extern \"C\" fn callback() {}\n fn normal() {}\n}";
436+
const EXPECTED: &str = "struct S;\nimpl S {\n extern \"C\" fn callback() {}\n #[log_instrument::instrument]\n fn normal() {}\n}";
437+
fix(GIVEN, EXPECTED, None);
438+
}
439+
410440
#[test]
411441
fn readme_custom_suffix() {
412442
const GIVEN: &str = r#"fn main() {

src/vmm/src/acpi/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ mod tests {
247247
// A mocke Vmm object with 128MBs of memory
248248
let vmm = default_vmm();
249249
let mut writer = AcpiTableWriter {
250-
mem: vmm.vm.guest_memory(),
250+
mem: vmm.vm.as_kvm().unwrap().guest_memory(),
251251
};
252-
let mut resource_allocator = vmm.vm.resource_allocator();
252+
let mut resource_allocator = vmm.vm.as_kvm().unwrap().resource_allocator();
253253

254254
// This should succeed
255255
let mut sdt = MockSdt(vec![0; 4096]);
@@ -309,7 +309,7 @@ mod tests {
309309
// change in the future.
310310
#[test]
311311
fn test_write_acpi_table_small_memory() {
312-
let (_, vm) = setup_vm_with_memory(u64_to_usize(SYSTEM_MEM_START + SYSTEM_MEM_SIZE - 4096));
312+
let vm = setup_vm_with_memory(u64_to_usize(SYSTEM_MEM_START + SYSTEM_MEM_SIZE - 4096));
313313
let mut writer = AcpiTableWriter {
314314
mem: vm.guest_memory(),
315315
};

src/vmm/src/arch/aarch64/fdt.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ mod tests {
564564
use crate::device_manager::tests::default_device_manager;
565565
use crate::test_utils::arch_mem;
566566
use crate::vstate::memory::GuestAddress;
567-
use crate::{EventManager, Kvm, Vm};
567+
use crate::vstate::vm::KvmVm;
568+
use crate::{EventManager, Kvm};
568569

569570
// The `load` function from the `device_tree` will mistakenly check the actual size
570571
// of the buffer with the allocated size. This works around that.
@@ -581,7 +582,7 @@ mod tests {
581582
let mut event_manager = EventManager::new().unwrap();
582583
let mut device_manager = default_device_manager();
583584
let kvm = Kvm::new(vec![]).unwrap();
584-
let vm = Vm::new(&kvm).unwrap();
585+
let vm = KvmVm::new(kvm).unwrap();
585586
let gic = create_gic(vm.fd(), 1, None).unwrap();
586587
let mut cmdline = kernel_cmdline::Cmdline::new(4096).unwrap();
587588
cmdline.insert("console", "/dev/tty0").unwrap();
@@ -618,7 +619,7 @@ mod tests {
618619
let mem = arch_mem(layout::FDT_MAX_SIZE + 0x1000);
619620
let device_manager = default_device_manager();
620621
let kvm = Kvm::new(vec![]).unwrap();
621-
let vm = Vm::new(&kvm).unwrap();
622+
let vm = KvmVm::new(kvm).unwrap();
622623
let gic = create_gic(vm.fd(), 1, None).unwrap();
623624

624625
let saved_dtb_bytes = match gic.fdt_compatibility() {
@@ -675,7 +676,7 @@ mod tests {
675676
let mem = arch_mem(layout::FDT_MAX_SIZE + 0x1000);
676677
let device_manager = default_device_manager();
677678
let kvm = Kvm::new(vec![]).unwrap();
678-
let vm = Vm::new(&kvm).unwrap();
679+
let vm = KvmVm::new(kvm).unwrap();
679680
let gic = create_gic(vm.fd(), 1, None).unwrap();
680681

681682
let saved_dtb_bytes = match gic.fdt_compatibility() {

src/vmm/src/arch/aarch64/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ use crate::vstate::memory::{
3737
Address, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap, GuestRegionType,
3838
};
3939
use crate::vstate::vcpu::KvmVcpuError;
40-
use crate::{DeviceManager, Kvm, Vcpu, VcpuConfig, Vm, logger};
40+
use crate::vstate::vm::KvmVm;
41+
use crate::{DeviceManager, Kvm, Vcpu, VcpuConfig, logger};
4142

4243
/// Errors thrown while configuring aarch64 system.
4344
#[derive(Debug, thiserror::Error, displaydoc::Display)]
@@ -92,7 +93,7 @@ pub fn arch_memory_regions(size: usize) -> Vec<(GuestAddress, usize)> {
9293
#[allow(clippy::too_many_arguments)]
9394
pub fn configure_system_for_boot(
9495
kvm: &Kvm,
95-
vm: &Vm,
96+
vm: &KvmVm,
9697
device_manager: &mut DeviceManager,
9798
vcpus: &mut [Vcpu],
9899
machine_config: &MachineConfig,

src/vmm/src/arch/aarch64/vcpu.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::vcpu::{VcpuConfig, VcpuError};
2626
use crate::vstate::bus::Bus;
2727
use crate::vstate::memory::{Address, GuestMemoryMmap};
2828
use crate::vstate::vcpu::VcpuEmulation;
29-
use crate::vstate::vm::Vm;
29+
use crate::vstate::vm::KvmVm;
3030

3131
/// Errors thrown while setting aarch64 registers.
3232
#[derive(Debug, PartialEq, Eq, thiserror::Error, displaydoc::Display)]
@@ -133,7 +133,7 @@ impl KvmVcpu {
133133
///
134134
/// * `index` - Represents the 0-based CPU index between [0, max vcpus).
135135
/// * `vm` - The vm to which this vcpu will get attached.
136-
pub fn new(index: u8, vm: &Vm) -> Result<Self, KvmVcpuError> {
136+
pub fn new(index: u8, vm: &KvmVm) -> Result<Self, KvmVcpuError> {
137137
let kvm_vcpu = vm
138138
.fd()
139139
.create_vcpu(index.into())
@@ -561,27 +561,25 @@ mod tests {
561561
use crate::cpu_config::templates::RegisterValueFilter;
562562
use crate::test_utils::arch_mem;
563563
use crate::vcpu::VcpuConfig;
564-
use crate::vstate::kvm::Kvm;
565-
use crate::vstate::vm::Vm;
566564
use crate::vstate::vm::tests::setup_vm_with_memory;
567565

568-
fn setup_vcpu(mem_size: usize) -> (Kvm, Vm, KvmVcpu) {
569-
let (kvm, mut vm, mut vcpu) = setup_vcpu_no_init(mem_size);
566+
fn setup_vcpu(mem_size: usize) -> (KvmVm, KvmVcpu) {
567+
let (mut vm, mut vcpu) = setup_vcpu_no_init(mem_size);
570568
vcpu.init(&[]).unwrap();
571569
vm.setup_irqchip(1).unwrap();
572-
(kvm, vm, vcpu)
570+
(vm, vcpu)
573571
}
574572

575-
fn setup_vcpu_no_init(mem_size: usize) -> (Kvm, Vm, KvmVcpu) {
576-
let (kvm, vm) = setup_vm_with_memory(mem_size);
573+
fn setup_vcpu_no_init(mem_size: usize) -> (KvmVm, KvmVcpu) {
574+
let vm = setup_vm_with_memory(mem_size);
577575
let vcpu = KvmVcpu::new(0, &vm).unwrap();
578576

579-
(kvm, vm, vcpu)
577+
(vm, vcpu)
580578
}
581579

582580
#[test]
583581
fn test_create_vcpu() {
584-
let (_, vm) = setup_vm_with_memory(0x1000);
582+
let vm = setup_vm_with_memory(0x1000);
585583

586584
unsafe { libc::close(vm.fd().as_raw_fd()) };
587585

@@ -600,8 +598,8 @@ mod tests {
600598

601599
#[test]
602600
fn test_configure_vcpu() {
603-
let (kvm, vm, mut vcpu) = setup_vcpu(0x10000);
604-
let optional_capabilities = kvm.optional_capabilities();
601+
let (vm, mut vcpu) = setup_vcpu(0x10000);
602+
let optional_capabilities = vm.kvm().optional_capabilities();
605603

606604
let vcpu_config = VcpuConfig {
607605
vcpu_count: 1,
@@ -649,7 +647,7 @@ mod tests {
649647

650648
#[test]
651649
fn test_init_vcpu() {
652-
let (_, mut vm) = setup_vm_with_memory(0x1000);
650+
let mut vm = setup_vm_with_memory(0x1000);
653651
let mut vcpu = KvmVcpu::new(0, &vm).unwrap();
654652
vm.setup_irqchip(1).unwrap();
655653

@@ -668,7 +666,7 @@ mod tests {
668666

669667
#[test]
670668
fn test_pmu_v3_feature_invalid() {
671-
let (_, mut vm) = setup_vm_with_memory(0x1000);
669+
let mut vm = setup_vm_with_memory(0x1000);
672670
let mut vcpu = KvmVcpu::new(0, &vm).unwrap();
673671
vm.setup_irqchip(1).unwrap();
674672

@@ -688,7 +686,7 @@ mod tests {
688686

689687
#[test]
690688
fn test_vcpu_save_restore_state() {
691-
let (_, mut vm) = setup_vm_with_memory(0x1000);
689+
let mut vm = setup_vm_with_memory(0x1000);
692690
let mut vcpu = KvmVcpu::new(0, &vm).unwrap();
693691
vm.setup_irqchip(1).unwrap();
694692

@@ -732,7 +730,7 @@ mod tests {
732730
//
733731
// This should fail with ENOEXEC.
734732
// https://elixir.bootlin.com/linux/v5.10.176/source/arch/arm64/kvm/arm.c#L1165
735-
let (_, mut vm) = setup_vm_with_memory(0x1000);
733+
let mut vm = setup_vm_with_memory(0x1000);
736734
let vcpu = KvmVcpu::new(0, &vm).unwrap();
737735
vm.setup_irqchip(1).unwrap();
738736

@@ -742,7 +740,7 @@ mod tests {
742740
#[test]
743741
fn test_dump_cpu_config_after_init() {
744742
// Test `dump_cpu_config()` after `KVM_VCPU_INIT`.
745-
let (_, mut vm) = setup_vm_with_memory(0x1000);
743+
let mut vm = setup_vm_with_memory(0x1000);
746744
let mut vcpu = KvmVcpu::new(0, &vm).unwrap();
747745
vm.setup_irqchip(1).unwrap();
748746
vcpu.init(&[]).unwrap();
@@ -752,7 +750,7 @@ mod tests {
752750

753751
#[test]
754752
fn test_setup_non_boot_vcpu() {
755-
let (_, vm) = setup_vm_with_memory(0x1000);
753+
let vm = setup_vm_with_memory(0x1000);
756754
let mut vcpu1 = KvmVcpu::new(0, &vm).unwrap();
757755
vcpu1.init(&[]).unwrap();
758756
let mut vcpu2 = KvmVcpu::new(1, &vm).unwrap();
@@ -764,24 +762,24 @@ mod tests {
764762
// Test `get_regs()` with valid register IDs.
765763
// - X0: 0x6030 0000 0010 0000
766764
// - X1: 0x6030 0000 0010 0002
767-
let (_, _, vcpu) = setup_vcpu(0x10000);
765+
let (_, vcpu) = setup_vcpu(0x10000);
768766
let reg_list = Vec::<u64>::from([0x6030000000100000, 0x6030000000100002]);
769767
get_registers(&vcpu.fd, &reg_list, &mut Aarch64RegisterVec::default()).unwrap();
770768
}
771769

772770
#[test]
773771
fn test_get_invalid_regs() {
774772
// Test `get_regs()` with invalid register IDs.
775-
let (_, _, vcpu) = setup_vcpu(0x10000);
773+
let (_, vcpu) = setup_vcpu(0x10000);
776774
let reg_list = Vec::<u64>::from([0x6030000000100001, 0x6030000000100003]);
777775
get_registers(&vcpu.fd, &reg_list, &mut Aarch64RegisterVec::default()).unwrap_err();
778776
}
779777

780778
#[test]
781779
fn test_setup_regs() {
782-
let (kvm, _, vcpu) = setup_vcpu_no_init(0x10000);
780+
let (vm, vcpu) = setup_vcpu_no_init(0x10000);
783781
let mem = arch_mem(layout::FDT_MAX_SIZE + 0x1000);
784-
let optional_capabilities = kvm.optional_capabilities();
782+
let optional_capabilities = vm.kvm().optional_capabilities();
785783

786784
let res = vcpu.setup_boot_regs(0x0, &mem, &optional_capabilities);
787785
assert!(matches!(
@@ -816,7 +814,7 @@ mod tests {
816814

817815
#[test]
818816
fn test_read_mpidr() {
819-
let (_, _, vcpu) = setup_vcpu_no_init(0x10000);
817+
let (_, vcpu) = setup_vcpu_no_init(0x10000);
820818

821819
// Must fail when vcpu is not initialized yet.
822820
let res = vcpu.get_mpidr();
@@ -831,7 +829,7 @@ mod tests {
831829

832830
#[test]
833831
fn test_get_set_regs() {
834-
let (_, _, vcpu) = setup_vcpu_no_init(0x10000);
832+
let (_, vcpu) = setup_vcpu_no_init(0x10000);
835833

836834
// Must fail when vcpu is not initialized yet.
837835
let mut regs = Aarch64RegisterVec::default();
@@ -849,7 +847,7 @@ mod tests {
849847
fn test_mpstate() {
850848
use std::os::unix::io::AsRawFd;
851849

852-
let (_, _, vcpu) = setup_vcpu(0x10000);
850+
let (_, vcpu) = setup_vcpu(0x10000);
853851

854852
let res = vcpu.get_mpstate();
855853
vcpu.set_mpstate(res.unwrap()).unwrap();

0 commit comments

Comments
 (0)