Repository: firecracker-microvm/firecracker
File: src/vmm/src/builder.rs (Rust)

Code before:
    )?;
    attach_net_devices(
        &mut vmm,
        &mut boot_cmdline,
        vm_resources.net_builder.iter(),
        event_manager,
    )?;

    if let Some(unix_vsock) = vm_resources.vsock.get() {
        attach_unixsock_vsock_device(&mut vmm, &mut boot_cmdline, unix_vsock, event_manager)?;
    }

    if let Some(entropy) = vm_resources.entropy.get() {
        attach_entropy_device(&mut vmm, &mut boot_cmdline, entropy, event_manager)?;
    }

    #[cfg(target_arch = "aarch64")]
    attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline)?;

    attach_vmgenid_device(&mut vmm)?;

    // Attempt to setup PVTime, continue if not supported
    #[cfg(target_arch = "aarch64")]
    if let Err(e) = setup_pv_time(&mut vmm, vcpus.as_mut()) {
        match e {
            StartMicrovmError::PVTimeNotSupported(e) => {
                warn!("PVTime not supported: {}", e);
            }
            other => return Err(other),
        }
    }

    configure_system_for_boot(
        &mut vmm,
        vcpus.as_mut(),
        &vm_resources.machine_config,
        &cpu_template,
        entry_point,
        &initrd,
        boot_cmdline,
    )?;

    let vmm = Arc::new(Mutex::new(vmm));

    #[cfg(feature = "gdb")]
    if let Some(gdb_socket_path) = &vm_resources.machine_config.gdb_socket_path {
        gdb::gdb_thread(
            vmm.clone(),
            vcpu_fds,
            gdb_rx,
            entry_point.entry_addr,

Review comment (suggestion):
With the changes proposed below, this would become
```
#[cfg(target_arch = "aarch64")]
vmm.pvtime = if PVTime::is_supported(&vcpus[0].kvm_vcpu.fd) {
        Some(setup_pv_time(&mut vmm, vcpus.as_mut())?)
    } else {
        warn!("PVTime is not supported by KVM. Steal time will not be reported to the guest.");
        None
};
```

Code after:
        &mut vmm,
        &mut boot_cmdline,
        vm_resources.net_builder.iter(),
        event_manager,
    )?;

    if let Some(unix_vsock) = vm_resources.vsock.get() {
        attach_unixsock_vsock_device(&mut vmm, &mut boot_cmdline, unix_vsock, event_manager)?;
    }

    if let Some(entropy) = vm_resources.entropy.get() {
        attach_entropy_device(&mut vmm, &mut boot_cmdline, entropy, event_manager)?;
    }

    #[cfg(target_arch = "aarch64")]
    attach_legacy_devices_aarch64(event_manager, &mut vmm, &mut boot_cmdline)?;

    attach_vmgenid_device(&mut vmm)?;

    #[cfg(target_arch = "aarch64")]
    if vcpus[0].kvm_vcpu.supports_pvtime() {
        setup_pvtime(&mut vmm, &mut vcpus)?;
    } else {
        log::warn!("Vcpus do not support pvtime, steal time will not be reported to guest");
    }

    configure_system_for_boot(
        &mut vmm,
        vcpus.as_mut(),
        &vm_resources.machine_config,
        &cpu_template,
        entry_point,
        &initrd,
        boot_cmdline,
    )?;

    let vmm = Arc::new(Mutex::new(vmm));

    #[cfg(feature = "gdb")]
    if let Some(gdb_socket_path) = &vm_resources.machine_config.gdb_socket_path {
        gdb::gdb_thread(
            vmm.clone(),
            vcpu_fds,
            gdb_rx,
            entry_point.entry_addr,
            gdb_socket_path,
        )
        .map_err(GdbServer)?;
    } else {
        debug!("No GDB socket provided not starting gdb server.");
    }