vmm: cleanup &Mutex parameters

In [0] we refactored some Arc<Mutex<T>> parameters to &Mutex<T>> to
satisfy clippy's needless_pass_by_value lint. Nevertheless, this is also
not so idiomatic, so as a follow-up, we put the responsibility to lock
objects to the caller side (only where this is not strictly needed by
the callee).

While on it, I also tried to pass vm_config directly into
pre_create_console_devices() which would clean up some code, but then
we have interleaving mutable and immutable borrows of the Vmm, which
are denied by the borrow checker.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-12-10 06:48:50 +01:00
committed by Rob Bradford
parent 4592f37bcf
commit 6bda6541be
4 changed files with 24 additions and 25 deletions

View File

@@ -922,11 +922,9 @@ impl CpuManager {
pub fn configure_vcpu(
&self,
vcpu: &Mutex<Vcpu>,
vcpu: &mut Vcpu,
boot_setup: Option<(EntryPoint, &GuestMemoryAtomic<GuestMemoryMmap>)>,
) -> Result<()> {
let mut vcpu = vcpu.lock().unwrap();
#[cfg(feature = "sev_snp")]
if self.sev_snp_enabled {
if let Some((kernel_entry_point, _)) = boot_setup {
@@ -1406,7 +1404,8 @@ impl CpuManager {
cmp::Ordering::Greater => {
let vcpus = self.create_vcpus(desired_vcpus, None)?;
for vcpu in vcpus {
self.configure_vcpu(&vcpu, None)?;
let mut vcpu = vcpu.lock().unwrap();
self.configure_vcpu(&mut vcpu, None)?;
}
self.activate_vcpus(desired_vcpus, true, None)?;
Ok(true)