[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 03/10] kvm: dirty-ring: Fix race with vcpu creation
From: |
huangy81 |
Subject: |
[PATCH v3 03/10] kvm: dirty-ring: Fix race with vcpu creation |
Date: |
Sun, 4 Dec 2022 00:38:48 +0800 |
From: Peter Xu <peterx@redhat.com>
It's possible that we want to reap a dirty ring on a vcpu that is during
creation, because the vcpu is put onto list (CPU_FOREACH visible) before
initialization of the structures. In this case:
qemu_init_vcpu
x86_cpu_realizefn
cpu_exec_realizefn
cpu_list_add <---- can be probed by CPU_FOREACH
qemu_init_vcpu
cpus_accel->create_vcpu_thread(cpu);
kvm_init_vcpu
map kvm_dirty_gfns <--- kvm_dirty_gfns valid
Don't try to reap dirty ring on vcpus during creation or it'll crash.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2124756
Reported-by: Xiaohui Li <xiaohli@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
accel/kvm/kvm-all.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index f99b0be..ff26b07 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -683,6 +683,15 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s,
CPUState *cpu)
uint32_t ring_size = s->kvm_dirty_ring_size;
uint32_t count = 0, fetch = cpu->kvm_fetch_index;
+ /*
+ * It's possible that we race with vcpu creation code where the vcpu is
+ * put onto the vcpus list but not yet initialized the dirty ring
+ * structures. If so, skip it.
+ */
+ if (!cpu->created) {
+ return 0;
+ }
+
assert(dirty_gfns && ring_size);
trace_kvm_dirty_ring_reap_vcpu(cpu->cpu_index);
--
1.8.3.1
- [PATCH v3 00/10] migration: introduce dirtylimit capabilit, huangy81, 2022/12/03
- [PATCH v3 03/10] kvm: dirty-ring: Fix race with vcpu creation,
huangy81 <=
- [PATCH v3 02/10] softmmu/dirtylimit: Add parameter check for hmp "set_vcpu_dirty_limit", huangy81, 2022/12/03
- [PATCH v3 01/10] dirtylimit: Fix overflow when computing MB, huangy81, 2022/12/03
- [PATCH v3 05/10] qapi/migration: Introduce vcpu-dirty-limit parameters, huangy81, 2022/12/03
- [PATCH v3 07/10] migration: Refactor auto-converge capability logic, huangy81, 2022/12/03
- [PATCH v3 06/10] migration: Introduce dirty-limit capability, huangy81, 2022/12/03
- [PATCH v3 04/10] qapi/migration: Introduce x-vcpu-dirty-limit-period parameter, huangy81, 2022/12/03
- [PATCH v3 08/10] migration: Implement dirty-limit convergence algo, huangy81, 2022/12/03
- [PATCH v3 09/10] migration: Export dirty-limit time info for observation, huangy81, 2022/12/03
- [PATCH v3 10/10] tests: Add migration dirty-limit capability test, huangy81, 2022/12/03