]> xenbits.xensource.com Git - xen.git/commit
x86/vpmu: Fix race-condition in vpmu_load
authorTamas K Lengyel <tamas.lengyel@intel.com>
Tue, 11 Oct 2022 13:17:42 +0000 (15:17 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 11 Oct 2022 13:17:42 +0000 (15:17 +0200)
commit9690bb261d5fa09cb281e1fa124d93db7b84fda5
tree5b3882b7f3279f438b777181fe3584acbab1ccb7
parent62e534d17cdd838828bfd75d3d845e31524dd336
x86/vpmu: Fix race-condition in vpmu_load

The vPMU code-bases attempts to perform an optimization on saving/reloading the
PMU context by keeping track of what vCPU ran on each pCPU. When a pCPU is
getting scheduled, checks if the previous vCPU isn't the current one. If so,
attempts a call to vpmu_save_force. Unfortunately if the previous vCPU is
already getting scheduled to run on another pCPU its state will be already
runnable, which results in an ASSERT failure.

Fix this by always performing a pmu context save in vpmu_save when called from
vpmu_switch_from, and do a vpmu_load when called from vpmu_switch_to.

While this presents a minimal overhead in case the same vCPU is getting
rescheduled on the same pCPU, the ASSERT failure is avoided and the code is a
lot easier to reason about.

Signed-off-by: Tamas K Lengyel <tamas.lengyel@intel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
master commit: defa4e51d20a143bdd4395a075bf0933bb38a9a4
master date: 2022-09-30 09:53:49 +0200
xen/arch/x86/cpu/vpmu.c