[PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES

Gavin Shan posted 3 patches 1 year, 10 months ago
[PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES
Posted by Gavin Shan 1 year, 10 months ago
MAX_TLBI_RANGE_PAGES pages is covered by SCALE#3 and NUM#31 and it's
supported now. Allow TLBI RANGE operation when the number of pages is
equal to MAX_TLBI_RANGE_PAGES in __flush_tlb_range_nosync().

Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Gavin Shan <gshan@redhat.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 243d71f7bc1f..95fbc8c05607 100644
--- a/arch/arm64/include/asm/tlbflush.h
+++ b/arch/arm64/include/asm/tlbflush.h
@@ -446,11 +446,11 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma,
 	 * When not uses TLB range ops, we can handle up to
 	 * (MAX_DVM_OPS - 1) pages;
 	 * When uses TLB range ops, we can handle up to
-	 * (MAX_TLBI_RANGE_PAGES - 1) pages.
+	 * MAX_TLBI_RANGE_PAGES pages.
 	 */
 	if ((!system_supports_tlb_range() &&
 	     (end - start) >= (MAX_DVM_OPS * stride)) ||
-	    pages >= MAX_TLBI_RANGE_PAGES) {
+	    pages > MAX_TLBI_RANGE_PAGES) {
 		flush_tlb_mm(vma->vm_mm);
 		return;
 	}
-- 
2.44.0
Re: [PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES
Posted by Anshuman Khandual 1 year, 10 months ago
On 4/5/24 09:28, Gavin Shan wrote:
> MAX_TLBI_RANGE_PAGES pages is covered by SCALE#3 and NUM#31 and it's
> supported now. Allow TLBI RANGE operation when the number of pages is
> equal to MAX_TLBI_RANGE_PAGES in __flush_tlb_range_nosync().
> 
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Gavin Shan <gshan@redhat.com>

Reviewed-by: Anshuman Khandual <anshuman.khandual@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 243d71f7bc1f..95fbc8c05607 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -446,11 +446,11 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma,
>  	 * When not uses TLB range ops, we can handle up to
>  	 * (MAX_DVM_OPS - 1) pages;
>  	 * When uses TLB range ops, we can handle up to
> -	 * (MAX_TLBI_RANGE_PAGES - 1) pages.
> +	 * MAX_TLBI_RANGE_PAGES pages.
>  	 */
>  	if ((!system_supports_tlb_range() &&
>  	     (end - start) >= (MAX_DVM_OPS * stride)) ||
> -	    pages >= MAX_TLBI_RANGE_PAGES) {
> +	    pages > MAX_TLBI_RANGE_PAGES) {
>  		flush_tlb_mm(vma->vm_mm);
>  		return;
>  	}
Re: [PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES
Posted by Ryan Roberts 1 year, 10 months ago
On 05/04/2024 04:58, Gavin Shan wrote:
> MAX_TLBI_RANGE_PAGES pages is covered by SCALE#3 and NUM#31 and it's
> supported now. Allow TLBI RANGE operation when the number of pages is
> equal to MAX_TLBI_RANGE_PAGES in __flush_tlb_range_nosync().
> 
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Gavin Shan <gshan@redhat.com>

Reviewed-by: Ryan Roberts <ryan.roberts@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 243d71f7bc1f..95fbc8c05607 100644
> --- a/arch/arm64/include/asm/tlbflush.h
> +++ b/arch/arm64/include/asm/tlbflush.h
> @@ -446,11 +446,11 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma,
>  	 * When not uses TLB range ops, we can handle up to
>  	 * (MAX_DVM_OPS - 1) pages;
>  	 * When uses TLB range ops, we can handle up to
> -	 * (MAX_TLBI_RANGE_PAGES - 1) pages.
> +	 * MAX_TLBI_RANGE_PAGES pages.
>  	 */
>  	if ((!system_supports_tlb_range() &&
>  	     (end - start) >= (MAX_DVM_OPS * stride)) ||
> -	    pages >= MAX_TLBI_RANGE_PAGES) {
> +	    pages > MAX_TLBI_RANGE_PAGES) {

As a further enhancement, I wonder if it might be better to test:

	pages * 4 / MAX_TLBI_RANGE_PAGES > MAX_DVM_OPS

Then add an extra loop over __flush_tlb_range_op(), like KVM does.

The math is trying to express that there are a maximum of 4 tlbi range
instructions for MAX_TLBI_RANGE_PAGES pages (1 per scale) and we only need to
fall back to flushing the whole mm if it could generate more than MAX_DVM_OPS ops.

>  		flush_tlb_mm(vma->vm_mm);
>  		return;
>  	}
Re: [PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES
Posted by Marc Zyngier 1 year, 10 months ago
On Mon, 08 Apr 2024 09:43:44 +0100,
Ryan Roberts <ryan.roberts@arm.com> wrote:
> 
> On 05/04/2024 04:58, Gavin Shan wrote:
> > MAX_TLBI_RANGE_PAGES pages is covered by SCALE#3 and NUM#31 and it's
> > supported now. Allow TLBI RANGE operation when the number of pages is
> > equal to MAX_TLBI_RANGE_PAGES in __flush_tlb_range_nosync().
> > 
> > Suggested-by: Marc Zyngier <maz@kernel.org>
> > Signed-off-by: Gavin Shan <gshan@redhat.com>
> 
> Reviewed-by: Ryan Roberts <ryan.roberts@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 243d71f7bc1f..95fbc8c05607 100644
> > --- a/arch/arm64/include/asm/tlbflush.h
> > +++ b/arch/arm64/include/asm/tlbflush.h
> > @@ -446,11 +446,11 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma,
> >  	 * When not uses TLB range ops, we can handle up to
> >  	 * (MAX_DVM_OPS - 1) pages;
> >  	 * When uses TLB range ops, we can handle up to
> > -	 * (MAX_TLBI_RANGE_PAGES - 1) pages.
> > +	 * MAX_TLBI_RANGE_PAGES pages.
> >  	 */
> >  	if ((!system_supports_tlb_range() &&
> >  	     (end - start) >= (MAX_DVM_OPS * stride)) ||
> > -	    pages >= MAX_TLBI_RANGE_PAGES) {
> > +	    pages > MAX_TLBI_RANGE_PAGES) {
> 
> As a further enhancement, I wonder if it might be better to test:
> 
> 	pages * 4 / MAX_TLBI_RANGE_PAGES > MAX_DVM_OPS
> 
> Then add an extra loop over __flush_tlb_range_op(), like KVM does.
> 
> The math is trying to express that there are a maximum of 4 tlbi range
> instructions for MAX_TLBI_RANGE_PAGES pages (1 per scale) and we only need to
> fall back to flushing the whole mm if it could generate more than MAX_DVM_OPS ops.

That'd be a good enhancement indeed, although I wonder if that occurs
as often as we see it on the KVM side. But in any case, adding
consistency amongst the users of __flush_tlb_range_op() can only be
beneficial.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.
Re: [PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES
Posted by Will Deacon 1 year, 10 months ago
On Wed, Apr 10, 2024 at 09:50:20AM +0100, Marc Zyngier wrote:
> On Mon, 08 Apr 2024 09:43:44 +0100,
> Ryan Roberts <ryan.roberts@arm.com> wrote:
> > 
> > On 05/04/2024 04:58, Gavin Shan wrote:
> > > MAX_TLBI_RANGE_PAGES pages is covered by SCALE#3 and NUM#31 and it's
> > > supported now. Allow TLBI RANGE operation when the number of pages is
> > > equal to MAX_TLBI_RANGE_PAGES in __flush_tlb_range_nosync().
> > > 
> > > Suggested-by: Marc Zyngier <maz@kernel.org>
> > > Signed-off-by: Gavin Shan <gshan@redhat.com>
> > 
> > Reviewed-by: Ryan Roberts <ryan.roberts@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 243d71f7bc1f..95fbc8c05607 100644
> > > --- a/arch/arm64/include/asm/tlbflush.h
> > > +++ b/arch/arm64/include/asm/tlbflush.h
> > > @@ -446,11 +446,11 @@ static inline void __flush_tlb_range_nosync(struct vm_area_struct *vma,
> > >  	 * When not uses TLB range ops, we can handle up to
> > >  	 * (MAX_DVM_OPS - 1) pages;
> > >  	 * When uses TLB range ops, we can handle up to
> > > -	 * (MAX_TLBI_RANGE_PAGES - 1) pages.
> > > +	 * MAX_TLBI_RANGE_PAGES pages.
> > >  	 */
> > >  	if ((!system_supports_tlb_range() &&
> > >  	     (end - start) >= (MAX_DVM_OPS * stride)) ||
> > > -	    pages >= MAX_TLBI_RANGE_PAGES) {
> > > +	    pages > MAX_TLBI_RANGE_PAGES) {
> > 
> > As a further enhancement, I wonder if it might be better to test:
> > 
> > 	pages * 4 / MAX_TLBI_RANGE_PAGES > MAX_DVM_OPS
> > 
> > Then add an extra loop over __flush_tlb_range_op(), like KVM does.
> > 
> > The math is trying to express that there are a maximum of 4 tlbi range
> > instructions for MAX_TLBI_RANGE_PAGES pages (1 per scale) and we only need to
> > fall back to flushing the whole mm if it could generate more than MAX_DVM_OPS ops.
> 
> That'd be a good enhancement indeed, although I wonder if that occurs
> as often as we see it on the KVM side. But in any case, adding
> consistency amongst the users of __flush_tlb_range_op() can only be
> beneficial.

I'll pick patches 2 & 3 up for 6.10, but feel free to send stuff on top
if you want to tweak this.

Will
Re: [PATCH v3 3/3] arm64: tlb: Allow range operation for MAX_TLBI_RANGE_PAGES
Posted by Catalin Marinas 1 year, 10 months ago
On Fri, Apr 05, 2024 at 01:58:52PM +1000, Gavin Shan wrote:
> MAX_TLBI_RANGE_PAGES pages is covered by SCALE#3 and NUM#31 and it's
> supported now. Allow TLBI RANGE operation when the number of pages is
> equal to MAX_TLBI_RANGE_PAGES in __flush_tlb_range_nosync().
> 
> Suggested-by: Marc Zyngier <maz@kernel.org>
> Signed-off-by: Gavin Shan <gshan@redhat.com>

Verified this case as well, so:

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>