All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hyperv: check cpu mask after interrupt has been disabled
@ 2021-01-05 17:50 Wei Liu
  2021-01-05 18:20 ` Michael Kelley
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Liu @ 2021-01-05 17:50 UTC (permalink / raw)
  To: Linux on Hyper-V List
  Cc: Michael Kelley, Wei Liu, stable, K. Y. Srinivasan, Haiyang Zhang,
	Stephen Hemminger, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

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.

Signed-off-by: Wei Liu <wei.liu@kernel.org>
Cc: stable@kernel.org
---
 arch/x86/hyperv/mmu.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
index 5208ba49c89a..2c87350c1fb0 100644
--- a/arch/x86/hyperv/mmu.c
+++ b/arch/x86/hyperv/mmu.c
@@ -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);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] x86/hyperv: check cpu mask after interrupt has been disabled
  2021-01-05 17:50 [PATCH] x86/hyperv: check cpu mask after interrupt has been disabled Wei Liu
@ 2021-01-05 18:20 ` Michael Kelley
  2021-01-06 11:04   ` Wei Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Kelley @ 2021-01-05 18:20 UTC (permalink / raw)
  To: Wei Liu, Linux on Hyper-V List
  Cc: stable, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

From: Wei Liu <wei.liu@kernel.org> Sent: Tuesday, January 5, 2021 9:51 AM
> 
> 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.
> 
> Signed-off-by: Wei Liu <wei.liu@kernel.org>
> Cc: stable@kernel.org
> ---
>  arch/x86/hyperv/mmu.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
> index 5208ba49c89a..2c87350c1fb0 100644
> --- a/arch/x86/hyperv/mmu.c
> +++ b/arch/x86/hyperv/mmu.c
> @@ -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);
> 
> --
> 2.20.1

Reviewed-by:  Michael Kelley <mikelley@microsoft.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/hyperv: check cpu mask after interrupt has been disabled
  2021-01-05 18:20 ` Michael Kelley
@ 2021-01-06 11:04   ` Wei Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Liu @ 2021-01-06 11:04 UTC (permalink / raw)
  To: Michael Kelley
  Cc: Wei Liu, Linux on Hyper-V List, stable, KY Srinivasan,
	Haiyang Zhang, Stephen Hemminger, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

On Tue, Jan 05, 2021 at 06:20:05PM +0000, Michael Kelley wrote:
> From: Wei Liu <wei.liu@kernel.org> Sent: Tuesday, January 5, 2021 9:51 AM
> > 
> > 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.
> > 
> > Signed-off-by: Wei Liu <wei.liu@kernel.org>
> > Cc: stable@kernel.org
> > ---
> >  arch/x86/hyperv/mmu.c | 12 +++++++++---
> >  1 file changed, 9 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c
> > index 5208ba49c89a..2c87350c1fb0 100644
> > --- a/arch/x86/hyperv/mmu.c
> > +++ b/arch/x86/hyperv/mmu.c
> > @@ -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);
> > 
> > --
> > 2.20.1
> 
> Reviewed-by:  Michael Kelley <mikelley@microsoft.com>
> 

Applied to hyperv-fixes.

Wei.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-06 11:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 17:50 [PATCH] x86/hyperv: check cpu mask after interrupt has been disabled Wei Liu
2021-01-05 18:20 ` Michael Kelley
2021-01-06 11:04   ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.