Skip to contentSkip to conversation

x86/hyperv: check cpu mask after interrupt has been disabled

PATCH In review Wei Liu 2 participants 3 messages Jan 5, 2021 – Jan 6, 2021

Subsystems (3)
lore
Share & tools
lore

Wei Liu

author maintainer
#0 lore raw

PATCH 1/1 x86/hyperv: check cpu mask after interrupt has been disabled

We've observed crashes due to an empty cpu mask in hyperv_flush_tlb_others. Obviously the cpu mask in question is changed between the cpumask_empty call at the beginning of the function and when it is actually used later.

One theory is that an interrupt comes in between and a code path ends up changing the mask. Move the check after interrupt has been disabled to see if it fixes the issue.

---
 arch/x86/hyperv/mmu.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/x86/hyperv/mmu.c +9 -3
index 5208ba49c89a..2c87350c1fb0 100644
@@ -66,11 +66,17 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus,
 	if (!hv_hypercall_pg)
 		goto do_native;
 
-	if (cpumask_empty(cpus))
-		return;
-
 	local_irq_save(flags);
 
+	/*
+	 * Only check the mask _after_ interrupt has been disabled to avoid the
+	 * mask changing under our feet.
+	 */
+	if (cpumask_empty(cpus)) {
+		local_irq_restore(flags);
+		return;
+	}
+
 	flush_pcpu = (struct hv_tlb_flush **)
 		     this_cpu_ptr(hyperv_pcpu_input_arg);
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

From: Wei Liu <[email protected]> Sent: Tuesday, January 5, 2021 9:51 AM

Quoted 42 lines

We've observed crashes due to an empty cpu mask in hyperv_flush_tlb_others. Obviously the cpu mask in question is changed between the cpumask_empty call at the beginning of the function and when it is actually used later.

One theory is that an interrupt comes in between and a code path ends up changing the mask. Move the check after interrupt has been disabled to see if it fixes the issue.

---
 arch/x86/hyperv/mmu.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/x86/hyperv/mmu.c +9 -4
index 5208ba49c89a..2c87350c1fb0 100644
@@ -66,11 +66,17 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus,
 	if (!hv_hypercall_pg)
 		goto do_native;
 
-	if (cpumask_empty(cpus))
-		return;
-
 	local_irq_save(flags);
 
+	/*
+	 * Only check the mask _after_ interrupt has been disabled to avoid the
+	 * mask changing under our feet.
+	 */
+	if (cpumask_empty(cpus)) {
+		local_irq_restore(flags);
+		return;
+	}
+
 	flush_pcpu = (struct hv_tlb_flush **)
 		     this_cpu_ptr(hyperv_pcpu_input_arg);
 
--
Quoted 1 line

2.20.1

author maintainer Applied
#2 lore raw
Quoted 42 lines · Michael Kelley

From: Wei Liu <[email protected]> Sent: Tuesday, January 5, 2021 9:51 AM

Quoted 41 lines

We've observed crashes due to an empty cpu mask in hyperv_flush_tlb_others. Obviously the cpu mask in question is changed between the cpumask_empty call at the beginning of the function and when it is actually used later.

One theory is that an interrupt comes in between and a code path ends up changing the mask. Move the check after interrupt has been disabled to see if it fixes the issue.

---
 arch/x86/hyperv/mmu.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/x86/hyperv/mmu.c +9 -3
index 5208ba49c89a..2c87350c1fb0 100644
@@ -66,11 +66,17 @@ static void hyperv_flush_tlb_others(const struct cpumask *cpus,
 	if (!hv_hypercall_pg)
 		goto do_native;
 
-	if (cpumask_empty(cpus))
-		return;
-
 	local_irq_save(flags);
 
+	/*
+	 * Only check the mask _after_ interrupt has been disabled to avoid the
+	 * mask changing under our feet.
+	 */
+	if (cpumask_empty(cpus)) {
+		local_irq_restore(flags);
+		return;
+	}
+
 	flush_pcpu = (struct hv_tlb_flush **)
 		     this_cpu_ptr(hyperv_pcpu_input_arg);
 
Quoted 5 lines
Quoted 2 lines

--
2.20.1

Applied to hyperv-fixes.

Wei.