mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-03 17:15:54 +00:00
crovm/plugin: fix PerVcpuState to be per vcpu
Because resize was used to grow a vec, each Arc<Mutex<PerVcpuState>> was cloned from the original Default, merely increasing the ref count on the same default data. This change manually pushes a unique set of data per vcpu. BUG=chromium:835916 TEST=None Change-Id: I7116c764effd0f33f706f912bcf4d5d28ba1e08e Reviewed-on: https://chromium-review.googlesource.com/1024504 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Aleksandr Kartashov <regmka@gmail.com> Reviewed-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
This commit is contained in:
parent
a894f53439
commit
da3f64c8fe
1 changed files with 9 additions and 2 deletions
|
@ -144,8 +144,15 @@ impl Process {
|
|||
for _ in 0..cpu_count {
|
||||
vcpu_sockets.push(new_seqpacket_pair().map_err(Error::CreateVcpuSocket)?);
|
||||
}
|
||||
let mut per_vcpu_states: Vec<Arc<Mutex<PerVcpuState>>> = Vec::new();
|
||||
per_vcpu_states.resize(cpu_count as usize, Default::default());
|
||||
let mut per_vcpu_states: Vec<Arc<Mutex<PerVcpuState>>> = Vec::with_capacity(cpu_count as
|
||||
usize);
|
||||
// TODO(zachr): replace with `resize_default` when that stabilizes. Using a plain `resize`
|
||||
// is incorrect because each element in the `Vec` will contain a shared reference to the
|
||||
// same `PerVcpuState` instance. This happens because `resize` fills new slots using clones
|
||||
// of the instance given to `resize`.
|
||||
for _ in 0..cpu_count {
|
||||
per_vcpu_states.push(Default::default());
|
||||
}
|
||||
|
||||
let plugin_pid = match jail {
|
||||
Some(jail) => {
|
||||
|
|
Loading…
Reference in a new issue