diff options
author | Sean Christopherson <seanjc@google.com> | 2024-10-09 08:04:51 -0700 |
---|---|---|
committer | Sean Christopherson <seanjc@google.com> | 2024-12-16 14:37:30 -0800 |
commit | 0664dc74e9d004c36b4400081811df795169809a (patch) | |
tree | 7db1004362ed32908cb6d21fc312da1ea0370eb2 /tools/perf/scripts/python/export-to-postgresql.py | |
parent | 1e7381f3617d14b3c11da80ff5f8a93ab14cfc46 (diff) |
KVM: Verify there's at least one online vCPU when iterating over all vCPUs
Explicitly check that there is at least online vCPU before iterating over
all vCPUs. Because the max index is an unsigned long, passing "0 - 1" in
the online_vcpus==0 case results in xa_for_each_range() using an unlimited
max, i.e. allows it to access vCPU0 when it shouldn't. This will allow
KVM to safely _erase_ from vcpu_array if the last stages of vCPU creation
fail, i.e. without generating a use-after-free if a different task happens
to be concurrently iterating over all vCPUs.
Note, because xa_for_each_range() is a macro, kvm_for_each_vcpu() subtly
reloads online_vcpus after each iteration, i.e. adding an extra load
doesn't meaningfully impact the total cost of iterating over all vCPUs.
And because online_vcpus is never decremented, there is no risk of a
reload triggering a walk of the entire xarray.
Cc: Will Deacon <will@kernel.org>
Cc: Michal Luczaj <mhal@rbox.co>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20241009150455.1057573-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'tools/perf/scripts/python/export-to-postgresql.py')
0 files changed, 0 insertions, 0 deletions