[-fixes] riscv: Fix arch_tlbbatch_flush() by clearing the batch cpumask

Message ID 20240130115508.105386-1-alexghiti@rivosinc.com
State New
Headers
Series [-fixes] riscv: Fix arch_tlbbatch_flush() by clearing the batch cpumask |

Commit Message

Alexandre Ghiti Jan. 30, 2024, 11:55 a.m. UTC
  We must clear the cpumask once we have flushed the batch, otherwise cpus
get accumulated and we end sending IPIs to more cpus than needed.

Fixes: 54d7431af73e ("riscv: Add support for BATCHED_UNMAP_TLB_FLUSH")
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
 arch/riscv/mm/tlbflush.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Charlie Jenkins Feb. 6, 2024, 12:26 a.m. UTC | #1
On Tue, Jan 30, 2024 at 12:55:08PM +0100, Alexandre Ghiti wrote:
> We must clear the cpumask once we have flushed the batch, otherwise cpus
> get accumulated and we end sending IPIs to more cpus than needed.
> 
> Fixes: 54d7431af73e ("riscv: Add support for BATCHED_UNMAP_TLB_FLUSH")
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/mm/tlbflush.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> index 99c3e037f127..c8efc3f87a0f 100644
> --- a/arch/riscv/mm/tlbflush.c
> +++ b/arch/riscv/mm/tlbflush.c
> @@ -240,4 +240,5 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
>  {
>  	__flush_tlb_range(NULL, &batch->cpumask,
>  			  0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE);
> +	cpumask_clear(&batch->cpumask);
>  }
> -- 
> 2.39.2
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
  
Jisheng Zhang Feb. 6, 2024, 10:15 a.m. UTC | #2
On Mon, Feb 05, 2024 at 04:26:55PM -0800, Charlie Jenkins wrote:
> On Tue, Jan 30, 2024 at 12:55:08PM +0100, Alexandre Ghiti wrote:
> > We must clear the cpumask once we have flushed the batch, otherwise cpus
> > get accumulated and we end sending IPIs to more cpus than needed.
> > 
> > Fixes: 54d7431af73e ("riscv: Add support for BATCHED_UNMAP_TLB_FLUSH")
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Reviewed-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> >  arch/riscv/mm/tlbflush.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> > index 99c3e037f127..c8efc3f87a0f 100644
> > --- a/arch/riscv/mm/tlbflush.c
> > +++ b/arch/riscv/mm/tlbflush.c
> > @@ -240,4 +240,5 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
> >  {
> >  	__flush_tlb_range(NULL, &batch->cpumask,
> >  			  0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE);
> > +	cpumask_clear(&batch->cpumask);
> >  }
> > -- 
> > 2.39.2
> > 
> > 
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
> 
> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
>
  
Samuel Holland Feb. 7, 2024, 7:23 p.m. UTC | #3
Hi Alex,

On 2024-01-30 5:55 AM, Alexandre Ghiti wrote:
> We must clear the cpumask once we have flushed the batch, otherwise cpus
> get accumulated and we end sending IPIs to more cpus than needed.
> 
> Fixes: 54d7431af73e ("riscv: Add support for BATCHED_UNMAP_TLB_FLUSH")
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/mm/tlbflush.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
> index 99c3e037f127..c8efc3f87a0f 100644
> --- a/arch/riscv/mm/tlbflush.c
> +++ b/arch/riscv/mm/tlbflush.c
> @@ -240,4 +240,5 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
>  {
>  	__flush_tlb_range(NULL, &batch->cpumask,
>  			  0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE);
> +	cpumask_clear(&batch->cpumask);
>  }

This patch doesn't apply to fixes -- it looks like it was based on "riscv: Call
secondary mmu notifier when flushing the tlb"[1], which has not been merged and
would go in for-next anyway. Otherwise:

Reviewed-by: Samuel Holland <samuel.holland@sifive.com>

[1]: https://lore.kernel.org/all/20240124080325.2324462-1-alexghiti@rivosinc.com/
  
Palmer Dabbelt Feb. 7, 2024, 7:35 p.m. UTC | #4
On Wed, 07 Feb 2024 11:23:55 PST (-0800), samuel.holland@sifive.com wrote:
> Hi Alex,
>
> On 2024-01-30 5:55 AM, Alexandre Ghiti wrote:
>> We must clear the cpumask once we have flushed the batch, otherwise cpus
>> get accumulated and we end sending IPIs to more cpus than needed.
>>
>> Fixes: 54d7431af73e ("riscv: Add support for BATCHED_UNMAP_TLB_FLUSH")
>> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
>> ---
>>  arch/riscv/mm/tlbflush.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
>> index 99c3e037f127..c8efc3f87a0f 100644
>> --- a/arch/riscv/mm/tlbflush.c
>> +++ b/arch/riscv/mm/tlbflush.c
>> @@ -240,4 +240,5 @@ void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
>>  {
>>  	__flush_tlb_range(NULL, &batch->cpumask,
>>  			  0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE);
>> +	cpumask_clear(&batch->cpumask);
>>  }
>
> This patch doesn't apply to fixes -- it looks like it was based on "riscv: Call
> secondary mmu notifier when flushing the tlb"[1], which has not been merged and
> would go in for-next anyway. Otherwise:
>
> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
>
> [1]: https://lore.kernel.org/all/20240124080325.2324462-1-alexghiti@rivosinc.com/

Ya and for some reason it trips up "patch -p1", which applies it to some 
other function.  I just merged it manually a few minutes ago and it's in 
the tester...
  
patchwork-bot+linux-riscv@kernel.org Feb. 8, 2024, 1:30 a.m. UTC | #5
Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Tue, 30 Jan 2024 12:55:08 +0100 you wrote:
> We must clear the cpumask once we have flushed the batch, otherwise cpus
> get accumulated and we end sending IPIs to more cpus than needed.
> 
> Fixes: 54d7431af73e ("riscv: Add support for BATCHED_UNMAP_TLB_FLUSH")
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/mm/tlbflush.c | 1 +
>  1 file changed, 1 insertion(+)

Here is the summary with links:
  - [-fixes] riscv: Fix arch_tlbbatch_flush() by clearing the batch cpumask
    https://git.kernel.org/riscv/c/3951f6add519

You are awesome, thank you!
  

Patch

diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c
index 99c3e037f127..c8efc3f87a0f 100644
--- a/arch/riscv/mm/tlbflush.c
+++ b/arch/riscv/mm/tlbflush.c
@@ -240,4 +240,5 @@  void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
 {
 	__flush_tlb_range(NULL, &batch->cpumask,
 			  0, FLUSH_TLB_MAX_SIZE, PAGE_SIZE);
+	cpumask_clear(&batch->cpumask);
 }