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

Code before:
        GuestMemoryMmap::from_raw_regions(
            &regions,
            track_dirty_pages,
            vm_resources.vm_config.huge_pages,
        )
        .map_err(StartMicrovmError::GuestMemory)?
    };

    let entry_addr = load_kernel(boot_config, &guest_memory)?;
    let initrd = load_initrd_from_config(boot_config, &guest_memory)?;
    // Clone the command-line so that a failed boot doesn't pollute the original.
    #[allow(unused_mut)]
    let mut boot_cmdline = boot_config.cmdline.clone();

    let cpu_template = vm_resources.vm_config.cpu_template.get_cpu_template()?;

    let (mut vmm, mut vcpus) = create_vmm_and_vcpus(
        instance_info,
        event_manager,
        guest_memory,
        None,
        track_dirty_pages,
        vm_resources.vm_config.vcpu_count,
        seccomp_filters.clone(),
        cpu_template.kvm_capabilities.clone(),
    )?;

    // The boot timer device needs to be the first device attached in order
    // to maintain the same MMIO address referenced in the documentation
    // and tests.
    if vm_resources.boot_timer {
        attach_boot_timer_device(&mut vmm, request_ts)?;
    }

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

    attach_block_devices(
        &mut vmm,
        &mut boot_cmdline,
        vm_resources.block.devices.iter(),
        event_manager,
    )?;
    attach_net_devices(
        &mut vmm,
        &mut boot_cmdline,
        vm_resources.net_builder.iter(),
        event_manager,
    )?;


Review comment (suggestion):
I would check the reason why `seccomp_filters` is passed here by reference. Most likely it can be passed by value, so you don't need to clone the thing.

Code after:
        let regions = crate::arch::arch_memory_regions(vm_resources.vm_config.mem_size_mib << 20);
        GuestMemoryMmap::from_raw_regions(
            &regions,
            track_dirty_pages,
            vm_resources.vm_config.huge_pages,
        )
        .map_err(StartMicrovmError::GuestMemory)?
    };

    let entry_addr = load_kernel(boot_config, &guest_memory)?;
    let initrd = load_initrd_from_config(boot_config, &guest_memory)?;
    // Clone the command-line so that a failed boot doesn't pollute the original.
    #[allow(unused_mut)]
    let mut boot_cmdline = boot_config.cmdline.clone();

    let cpu_template = vm_resources.vm_config.cpu_template.get_cpu_template()?;

    let (mut vmm, mut vcpus) = create_vmm_and_vcpus(
        instance_info,
        event_manager,
        guest_memory,
        None,
        track_dirty_pages,
        vm_resources.vm_config.vcpu_count,
        #[cfg(target_arch = "x86_64")]
        seccomp_filters.clone(),
        cpu_template.kvm_capabilities.clone(),
    )?;

    // The boot timer device needs to be the first device attached in order
    // to maintain the same MMIO address referenced in the documentation
    // and tests.
    if vm_resources.boot_timer {
        attach_boot_timer_device(&mut vmm, request_ts)?;
    }

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

    attach_block_devices(
        &mut vmm,
        &mut boot_cmdline,
        vm_resources.block.devices.iter(),
        event_manager,
    )?;
    attach_net_devices(
        &mut vmm,
        &mut boot_cmdline,
        vm_resources.net_builder.iter(),
        event_manager,