Skip to content

Commit 970dee0

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Disable preemption in kvm_arch_hardware_enable()
Since 0bf5049 ("KVM: Drop kvm_count_lock and instead protect kvm_usage_count with kvm_lock"), hotplugging back a CPU whilst a guest is running results in a number of ugly splats as most of this code expects to run with preemption disabled, which isn't the case anymore. While the context is preemptable, it isn't migratable, which should be enough. But we have plenty of preemptible() checks all over the place, and our per-CPU accessors also disable preemption. Since this affects released versions, let's do the easy fix first, disabling preemption in kvm_arch_hardware_enable(). We can always revisit this with a more invasive fix in the future. Fixes: 0bf5049 ("KVM: Drop kvm_count_lock and instead protect kvm_usage_count with kvm_lock") Reported-by: Kristina Martsenko <[email protected]> Tested-by: Kristina Martsenko <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] # v6.3, v6.4 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent fa729bc commit 970dee0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

arch/arm64/kvm/arm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,15 +1872,26 @@ static void _kvm_arch_hardware_enable(void *discard)
18721872

18731873
int kvm_arch_hardware_enable(void)
18741874
{
1875-
int was_enabled = __this_cpu_read(kvm_arm_hardware_enabled);
1875+
int was_enabled;
18761876

1877+
/*
1878+
* Most calls to this function are made with migration
1879+
* disabled, but not with preemption disabled. The former is
1880+
* enough to ensure correctness, but most of the helpers
1881+
* expect the later and will throw a tantrum otherwise.
1882+
*/
1883+
preempt_disable();
1884+
1885+
was_enabled = __this_cpu_read(kvm_arm_hardware_enabled);
18771886
_kvm_arch_hardware_enable(NULL);
18781887

18791888
if (!was_enabled) {
18801889
kvm_vgic_cpu_up();
18811890
kvm_timer_cpu_up();
18821891
}
18831892

1893+
preempt_enable();
1894+
18841895
return 0;
18851896
}
18861897

0 commit comments

Comments
 (0)