Skip to contentSkip to conversation

kvm: preemption must be disabled when calling smp_call_function_many

PATCH In review Salah Triki 3 participants 3 messages Jun 7, 2025 – Jun 9, 2025 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: preemption must be disabled when calling smp_call_function_many

{Disable, Enable} preemption {before, after} calling smp_call_function_many().

---
 virt/kvm/kvm_main.c | 3 +++
 1 file changed, 3 insertions(+)
virt/kvm/kvm_main.c +3 -0
index eec82775c5bf..ab9593943846 100644
@@ -209,7 +209,10 @@ static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait)
 	if (cpumask_empty(cpus))
 		return false;
 
+	preempt_disable();
 	smp_call_function_many(cpus, ack_kick, NULL, wait);
+	preempt_enable();
+
 	return true;
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Salah Triki

{Disable, Enable} preemption {before, after} calling smp_call_function_many().

---
 virt/kvm/kvm_main.c | 3 +++
 1 file changed, 3 insertions(+)
virt/kvm/kvm_main.c +0 -0
index eec82775c5bf..ab9593943846 100644

virt/kvm/kvm_main.c static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait) · line 218

Quoted 10 lines
virt/kvm/kvm_main.c +3 -0
@@ -209,7 +209,10 @@ static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait)
 	if (cpumask_empty(cpus))
 		return false;
 
+	preempt_disable();
 	smp_call_function_many(cpus, ack_kick, NULL, wait);
+	preempt_enable();
+
 	return true;
 }
 
#2 lore raw
In reply to Salah Triki
Quoted 13 lines · Salah Triki

{Disable, Enable} preemption {before, after} calling smp_call_function_many().

---
 virt/kvm/kvm_main.c | 3 +++
 1 file changed, 3 insertions(+)
virt/kvm/kvm_main.c +0 -0
index eec82775c5bf..ab9593943846 100644

virt/kvm/kvm_main.c static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait) · line 218

Quoted 10 lines
virt/kvm/kvm_main.c +3 -0
@@ -209,7 +209,10 @@ static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait)
 	if (cpumask_empty(cpus))
 		return false;
 
+	preempt_disable();
 	smp_call_function_many(cpus, ack_kick, NULL, wait);
+	preempt_enable();
+
 	return true;
 }
 

Hi Salah,

I noticed that kvm_kick_many_cpus() is only invoked from two locations (from kvm_make_vcpus_request_mask() and kvm_make_all_cpus_request(), and in both cases, get_cpu() is called prior to kvm_kick_many_cpus(), with a corresponding put_cpu() afterward. Since get_cpu() disables preemption and put_cpu() re-enables it, preemption is already disabled during the execution of kvm_kick_many_cpus().

Given that, could you clarify the motivation behind explicitly adding preempt_disable() and preempt_enable() within kvm_kick_many_cpus()?

-Manali