linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations
@ 2025-05-22 11:44 Dev Jain
  2025-05-22 11:45 ` Dev Jain
  2025-05-22 14:41 ` Catalin Marinas
  0 siblings, 2 replies; 4+ messages in thread
From: Dev Jain @ 2025-05-22 11:44 UTC (permalink / raw)
  To: catalin.marinas, will
  Cc: linux-kernel, linux-arm-kernel, mark.rutland, anshuman.khandual,
	yang, wangkefeng.wang, yangyicong, baohua, pjaroszynski, ardb,
	david, Dev Jain

dsb(ishst) is used to ensure that prior pagetable updates are completed.
But, set_pmd/set_pud etc already issue a dsb-isb sequence for the exact
same purpose. Therefore, we can elide the dsb in kernel tlb invalidation.

There were no issues observed while running mm selftests, including
test_vmalloc.sh selftest to stress the vmalloc subsystem.

Signed-off-by: Dev Jain <dev.jain@arm.com>
---
 arch/arm64/include/asm/tlbflush.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
index eba1a98657f1..9b4adf1ee45e 100644
--- a/arch/arm64/include/asm/tlbflush.h
+++ b/arch/arm64/include/asm/tlbflush.h
@@ -508,7 +508,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end
 		return;
 	}
 
-	dsb(ishst);
+	/* dsb(ishst) not needed as callers (set_pxd) have that */
 	__flush_tlb_range_op(vaale1is, start, pages, stride, 0,
 			     TLBI_TTL_UNKNOWN, false, lpa2_is_enabled());
 	dsb(ish);
@@ -523,7 +523,7 @@ static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)
 {
 	unsigned long addr = __TLBI_VADDR(kaddr, 0);
 
-	dsb(ishst);
+	/* dsb(ishst) not needed as callers (set_pxd) have that */
 	__tlbi(vaae1is, addr);
 	dsb(ish);
 	isb();
-- 
2.30.2



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

* Re: [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations
  2025-05-22 11:44 [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations Dev Jain
@ 2025-05-22 11:45 ` Dev Jain
  2025-05-22 14:41 ` Catalin Marinas
  1 sibling, 0 replies; 4+ messages in thread
From: Dev Jain @ 2025-05-22 11:45 UTC (permalink / raw)
  To: catalin.marinas, will
  Cc: linux-kernel, linux-arm-kernel, mark.rutland, anshuman.khandual,
	yang, wangkefeng.wang, yangyicong, baohua, pjaroszynski, ardb,
	david, Ryan Roberts

Forgot to add Ryan.

On 22/05/25 5:14 pm, Dev Jain wrote:
> dsb(ishst) is used to ensure that prior pagetable updates are completed.
> But, set_pmd/set_pud etc already issue a dsb-isb sequence for the exact
> same purpose. Therefore, we can elide the dsb in kernel tlb invalidation.
>
> There were no issues observed while running mm selftests, including
> test_vmalloc.sh selftest to stress the vmalloc subsystem.
>
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>   arch/arm64/include/asm/tlbflush.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
> index eba1a98657f1..9b4adf1ee45e 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -508,7 +508,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end
>   		return;
>   	}
>   
> -	dsb(ishst);
> +	/* dsb(ishst) not needed as callers (set_pxd) have that */
>   	__flush_tlb_range_op(vaale1is, start, pages, stride, 0,
>   			     TLBI_TTL_UNKNOWN, false, lpa2_is_enabled());
>   	dsb(ish);
> @@ -523,7 +523,7 @@ static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)
>   {
>   	unsigned long addr = __TLBI_VADDR(kaddr, 0);
>   
> -	dsb(ishst);
> +	/* dsb(ishst) not needed as callers (set_pxd) have that */
>   	__tlbi(vaae1is, addr);
>   	dsb(ish);
>   	isb();


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

* Re: [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations
  2025-05-22 11:44 [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations Dev Jain
  2025-05-22 11:45 ` Dev Jain
@ 2025-05-22 14:41 ` Catalin Marinas
  2025-05-26  4:04   ` Dev Jain
  1 sibling, 1 reply; 4+ messages in thread
From: Catalin Marinas @ 2025-05-22 14:41 UTC (permalink / raw)
  To: Dev Jain
  Cc: will, linux-kernel, linux-arm-kernel, mark.rutland,
	anshuman.khandual, yang, wangkefeng.wang, yangyicong, baohua,
	pjaroszynski, ardb, david, Ryan Roberts

On Thu, May 22, 2025 at 05:14:14PM +0530, Dev Jain wrote:
> dsb(ishst) is used to ensure that prior pagetable updates are completed.
> But, set_pmd/set_pud etc already issue a dsb-isb sequence for the exact
> same purpose. Therefore, we can elide the dsb in kernel tlb invalidation.
> 
> There were no issues observed while running mm selftests, including
> test_vmalloc.sh selftest to stress the vmalloc subsystem.
> 
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
>  arch/arm64/include/asm/tlbflush.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
> index eba1a98657f1..9b4adf1ee45e 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -508,7 +508,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end
>  		return;
>  	}
>  
> -	dsb(ishst);
> +	/* dsb(ishst) not needed as callers (set_pxd) have that */
>  	__flush_tlb_range_op(vaale1is, start, pages, stride, 0,
>  			     TLBI_TTL_UNKNOWN, false, lpa2_is_enabled());
>  	dsb(ish);
> @@ -523,7 +523,7 @@ static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)
>  {
>  	unsigned long addr = __TLBI_VADDR(kaddr, 0);
>  
> -	dsb(ishst);
> +	/* dsb(ishst) not needed as callers (set_pxd) have that */
>  	__tlbi(vaae1is, addr);
>  	dsb(ish);
>  	isb();

What about __set_pte()? We only issue (or rather queue) a barrier if we
set a valid kernel pte. I recall we added them for the case where a TLBI
won't happen, see commit 7f0b1bf04511 ("arm64: Fix barriers used for
page table modifications"). When we clear a PTE, we rely on the TLB
maintenance to issue barriers.

Maybe something that can be optimised following Ryan's reworking but I
don't think it is safe to remove them now, given that
__set_pte_complete() skips the barriers for invalid ptes. Possibly the
__flush_tlb_kernel_pgtable() is alright but not the
flush_tlb_kernel_range() one.

-- 
Catalin


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

* Re: [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations
  2025-05-22 14:41 ` Catalin Marinas
@ 2025-05-26  4:04   ` Dev Jain
  0 siblings, 0 replies; 4+ messages in thread
From: Dev Jain @ 2025-05-26  4:04 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: will, linux-kernel, linux-arm-kernel, mark.rutland,
	anshuman.khandual, yang, wangkefeng.wang, yangyicong, baohua,
	pjaroszynski, ardb, david, Ryan Roberts


On 22/05/25 8:11 pm, Catalin Marinas wrote:
> On Thu, May 22, 2025 at 05:14:14PM +0530, Dev Jain wrote:
>> dsb(ishst) is used to ensure that prior pagetable updates are completed.
>> But, set_pmd/set_pud etc already issue a dsb-isb sequence for the exact
>> same purpose. Therefore, we can elide the dsb in kernel tlb invalidation.
>>
>> There were no issues observed while running mm selftests, including
>> test_vmalloc.sh selftest to stress the vmalloc subsystem.
>>
>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>> ---
>>   arch/arm64/include/asm/tlbflush.h | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h
>> index eba1a98657f1..9b4adf1ee45e 100644
>> --- a/arch/arm64/include/asm/tlbflush.h
>> +++ b/arch/arm64/include/asm/tlbflush.h
>> @@ -508,7 +508,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end
>>   		return;
>>   	}
>>   
>> -	dsb(ishst);
>> +	/* dsb(ishst) not needed as callers (set_pxd) have that */
>>   	__flush_tlb_range_op(vaale1is, start, pages, stride, 0,
>>   			     TLBI_TTL_UNKNOWN, false, lpa2_is_enabled());
>>   	dsb(ish);
>> @@ -523,7 +523,7 @@ static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)
>>   {
>>   	unsigned long addr = __TLBI_VADDR(kaddr, 0);
>>   
>> -	dsb(ishst);
>> +	/* dsb(ishst) not needed as callers (set_pxd) have that */
>>   	__tlbi(vaae1is, addr);
>>   	dsb(ish);
>>   	isb();
> What about __set_pte()? We only issue (or rather queue) a barrier if we
> set a valid kernel pte. I recall we added them for the case where a TLBI
> won't happen, see commit 7f0b1bf04511 ("arm64: Fix barriers used for
> page table modifications"). When we clear a PTE, we rely on the TLB
> maintenance to issue barriers.


I see, so I think one example also can be __set_fixmap -> __pte_clear -> 
__set_pte.

My original motivation was that it would be good to identify all the callers

instead of unconditionally issuing it for every tlb flush.


>
> Maybe something that can be optimised following Ryan's reworking but I
> don't think it is safe to remove them now, given that
> __set_pte_complete() skips the barriers for invalid ptes. Possibly the
> __flush_tlb_kernel_pgtable() is alright but not the
> flush_tlb_kernel_range() one.


Sure, I think Ryan's optimizations haven't landed yet? I'll take a look 
after that.




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

end of thread, other threads:[~2025-05-26  4:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22 11:44 [RFC PATCH] arm64: Elide dsb in kernel TLB invalidations Dev Jain
2025-05-22 11:45 ` Dev Jain
2025-05-22 14:41 ` Catalin Marinas
2025-05-26  4:04   ` Dev Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).