diff mbox series

[v4,34/66] cxl: Remove vma linked list walk

Message ID 20211201142918.921493-35-Liam.Howlett@oracle.com (mailing list archive)
State New
Headers show
Series Introducing the Maple Tree | expand

Commit Message

Liam R. Howlett Dec. 1, 2021, 2:30 p.m. UTC
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>

Use the VMA iterator instead.  This requires a little restructuring
of the surrounding code to hoist the mm to the caller.  That turns
cxl_prefault_one() into a trivial function, so call cxl_fault_segment()
directly.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 drivers/misc/cxl/fault.c | 43 +++++++++++++---------------------------
 1 file changed, 14 insertions(+), 29 deletions(-)

Comments

Vlastimil Babka Jan. 18, 2022, 12:37 p.m. UTC | #1
On 12/1/21 15:30, Liam Howlett wrote:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> 
> Use the VMA iterator instead.  This requires a little restructuring
> of the surrounding code to hoist the mm to the caller.  That turns
> cxl_prefault_one() into a trivial function, so call cxl_fault_segment()
> directly.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> ---
>  drivers/misc/cxl/fault.c | 43 +++++++++++++---------------------------
>  1 file changed, 14 insertions(+), 29 deletions(-)
> 
> diff --git a/drivers/misc/cxl/fault.c b/drivers/misc/cxl/fault.c
> index 60c829113299..504522a126b5 100644
> --- a/drivers/misc/cxl/fault.c
> +++ b/drivers/misc/cxl/fault.c
> @@ -280,22 +280,6 @@ void cxl_handle_fault(struct work_struct *fault_work)
>  		mmput(mm);
>  }
>  
> -static void cxl_prefault_one(struct cxl_context *ctx, u64 ea)
> -{
> -	struct mm_struct *mm;
> -
> -	mm = get_mem_context(ctx);
> -	if (mm == NULL) {
> -		pr_devel("cxl_prefault_one unable to get mm %i\n",
> -			 pid_nr(ctx->pid));
> -		return;
> -	}
> -
> -	cxl_fault_segment(ctx, mm, ea);
> -
> -	mmput(mm);
> -}
> -
>  static u64 next_segment(u64 ea, u64 vsid)
>  {
>  	if (vsid & SLB_VSID_B_1T)
> @@ -306,23 +290,16 @@ static u64 next_segment(u64 ea, u64 vsid)
>  	return ea + 1;
>  }
>  
> -static void cxl_prefault_vma(struct cxl_context *ctx)
> +static void cxl_prefault_vma(struct cxl_context *ctx, struct mm_struct *mm)
>  {
>  	u64 ea, last_esid = 0;
>  	struct copro_slb slb;
> +	VMA_ITERATOR(vmi, mm, 0);
>  	struct vm_area_struct *vma;
>  	int rc;
> -	struct mm_struct *mm;
> -
> -	mm = get_mem_context(ctx);
> -	if (mm == NULL) {
> -		pr_devel("cxl_prefault_vm unable to get mm %i\n",
> -			 pid_nr(ctx->pid));
> -		return;
> -	}
>  
>  	mmap_read_lock(mm);
> -	for (vma = mm->mmap; vma; vma = vma->vm_next) {
> +	for_each_vma(vmi, vma) {
>  		for (ea = vma->vm_start; ea < vma->vm_end;
>  				ea = next_segment(ea, slb.vsid)) {
>  			rc = copro_calculate_slb(mm, ea, &slb);
> @@ -337,15 +314,21 @@ static void cxl_prefault_vma(struct cxl_context *ctx)
>  		}
>  	}
>  	mmap_read_unlock(mm);
> -
> -	mmput(mm);
>  }
>  
>  void cxl_prefault(struct cxl_context *ctx, u64 wed)
>  {
> +	struct mm_struct *mm = get_mem_context(ctx);
> +
> +	if (mm == NULL) {
> +		pr_devel("cxl_prefault unable to get mm %i\n",
> +			 pid_nr(ctx->pid));
> +		return;
> +	}
> +
>  	switch (ctx->afu->prefault_mode) {
>  	case CXL_PREFAULT_WED:
> -		cxl_prefault_one(ctx, wed);
> +		cxl_fault_segment(ctx, mm, wed);
>  		break;
>  	case CXL_PREFAULT_ALL:
>  		cxl_prefault_vma(ctx);

Need to pass mm here, compile tested much? :)

After fixup
Acked-by: Vlastimil Babka <vbabka@suse.cz>

> @@ -353,4 +336,6 @@ void cxl_prefault(struct cxl_context *ctx, u64 wed)
>  	default:
>  		break;
>  	}
> +
> +	mmput(mm);
>  }
Liam R. Howlett Jan. 25, 2022, 4:32 p.m. UTC | #2
* Vlastimil Babka <vbabka@suse.cz> [220118 07:37]:
> On 12/1/21 15:30, Liam Howlett wrote:
> > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> > 
> > Use the VMA iterator instead.  This requires a little restructuring
> > of the surrounding code to hoist the mm to the caller.  That turns
> > cxl_prefault_one() into a trivial function, so call cxl_fault_segment()
> > directly.
> > 
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> > ---
> >  drivers/misc/cxl/fault.c | 43 +++++++++++++---------------------------
> >  1 file changed, 14 insertions(+), 29 deletions(-)
> > 
> > diff --git a/drivers/misc/cxl/fault.c b/drivers/misc/cxl/fault.c
> > index 60c829113299..504522a126b5 100644
> > --- a/drivers/misc/cxl/fault.c
> > +++ b/drivers/misc/cxl/fault.c
> > @@ -280,22 +280,6 @@ void cxl_handle_fault(struct work_struct *fault_work)
> >  		mmput(mm);
> >  }
> >  
> > -static void cxl_prefault_one(struct cxl_context *ctx, u64 ea)
> > -{
> > -	struct mm_struct *mm;
> > -
> > -	mm = get_mem_context(ctx);
> > -	if (mm == NULL) {
> > -		pr_devel("cxl_prefault_one unable to get mm %i\n",
> > -			 pid_nr(ctx->pid));
> > -		return;
> > -	}
> > -
> > -	cxl_fault_segment(ctx, mm, ea);
> > -
> > -	mmput(mm);
> > -}
> > -
> >  static u64 next_segment(u64 ea, u64 vsid)
> >  {
> >  	if (vsid & SLB_VSID_B_1T)
> > @@ -306,23 +290,16 @@ static u64 next_segment(u64 ea, u64 vsid)
> >  	return ea + 1;
> >  }
> >  
> > -static void cxl_prefault_vma(struct cxl_context *ctx)
> > +static void cxl_prefault_vma(struct cxl_context *ctx, struct mm_struct *mm)
> >  {
> >  	u64 ea, last_esid = 0;
> >  	struct copro_slb slb;
> > +	VMA_ITERATOR(vmi, mm, 0);
> >  	struct vm_area_struct *vma;
> >  	int rc;
> > -	struct mm_struct *mm;
> > -
> > -	mm = get_mem_context(ctx);
> > -	if (mm == NULL) {
> > -		pr_devel("cxl_prefault_vm unable to get mm %i\n",
> > -			 pid_nr(ctx->pid));
> > -		return;
> > -	}
> >  
> >  	mmap_read_lock(mm);
> > -	for (vma = mm->mmap; vma; vma = vma->vm_next) {
> > +	for_each_vma(vmi, vma) {
> >  		for (ea = vma->vm_start; ea < vma->vm_end;
> >  				ea = next_segment(ea, slb.vsid)) {
> >  			rc = copro_calculate_slb(mm, ea, &slb);
> > @@ -337,15 +314,21 @@ static void cxl_prefault_vma(struct cxl_context *ctx)
> >  		}
> >  	}
> >  	mmap_read_unlock(mm);
> > -
> > -	mmput(mm);
> >  }
> >  
> >  void cxl_prefault(struct cxl_context *ctx, u64 wed)
> >  {
> > +	struct mm_struct *mm = get_mem_context(ctx);
> > +
> > +	if (mm == NULL) {
> > +		pr_devel("cxl_prefault unable to get mm %i\n",
> > +			 pid_nr(ctx->pid));
> > +		return;
> > +	}
> > +
> >  	switch (ctx->afu->prefault_mode) {
> >  	case CXL_PREFAULT_WED:
> > -		cxl_prefault_one(ctx, wed);
> > +		cxl_fault_segment(ctx, mm, wed);
> >  		break;
> >  	case CXL_PREFAULT_ALL:
> >  		cxl_prefault_vma(ctx);
> 
> Need to pass mm here, compile tested much? :)

ack.

> 
> After fixup
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
> 
> > @@ -353,4 +336,6 @@ void cxl_prefault(struct cxl_context *ctx, u64 wed)
> >  	default:
> >  		break;
> >  	}
> > +
> > +	mmput(mm);
> >  }
>
diff mbox series

Patch

diff --git a/drivers/misc/cxl/fault.c b/drivers/misc/cxl/fault.c
index 60c829113299..504522a126b5 100644
--- a/drivers/misc/cxl/fault.c
+++ b/drivers/misc/cxl/fault.c
@@ -280,22 +280,6 @@  void cxl_handle_fault(struct work_struct *fault_work)
 		mmput(mm);
 }
 
-static void cxl_prefault_one(struct cxl_context *ctx, u64 ea)
-{
-	struct mm_struct *mm;
-
-	mm = get_mem_context(ctx);
-	if (mm == NULL) {
-		pr_devel("cxl_prefault_one unable to get mm %i\n",
-			 pid_nr(ctx->pid));
-		return;
-	}
-
-	cxl_fault_segment(ctx, mm, ea);
-
-	mmput(mm);
-}
-
 static u64 next_segment(u64 ea, u64 vsid)
 {
 	if (vsid & SLB_VSID_B_1T)
@@ -306,23 +290,16 @@  static u64 next_segment(u64 ea, u64 vsid)
 	return ea + 1;
 }
 
-static void cxl_prefault_vma(struct cxl_context *ctx)
+static void cxl_prefault_vma(struct cxl_context *ctx, struct mm_struct *mm)
 {
 	u64 ea, last_esid = 0;
 	struct copro_slb slb;
+	VMA_ITERATOR(vmi, mm, 0);
 	struct vm_area_struct *vma;
 	int rc;
-	struct mm_struct *mm;
-
-	mm = get_mem_context(ctx);
-	if (mm == NULL) {
-		pr_devel("cxl_prefault_vm unable to get mm %i\n",
-			 pid_nr(ctx->pid));
-		return;
-	}
 
 	mmap_read_lock(mm);
-	for (vma = mm->mmap; vma; vma = vma->vm_next) {
+	for_each_vma(vmi, vma) {
 		for (ea = vma->vm_start; ea < vma->vm_end;
 				ea = next_segment(ea, slb.vsid)) {
 			rc = copro_calculate_slb(mm, ea, &slb);
@@ -337,15 +314,21 @@  static void cxl_prefault_vma(struct cxl_context *ctx)
 		}
 	}
 	mmap_read_unlock(mm);
-
-	mmput(mm);
 }
 
 void cxl_prefault(struct cxl_context *ctx, u64 wed)
 {
+	struct mm_struct *mm = get_mem_context(ctx);
+
+	if (mm == NULL) {
+		pr_devel("cxl_prefault unable to get mm %i\n",
+			 pid_nr(ctx->pid));
+		return;
+	}
+
 	switch (ctx->afu->prefault_mode) {
 	case CXL_PREFAULT_WED:
-		cxl_prefault_one(ctx, wed);
+		cxl_fault_segment(ctx, mm, wed);
 		break;
 	case CXL_PREFAULT_ALL:
 		cxl_prefault_vma(ctx);
@@ -353,4 +336,6 @@  void cxl_prefault(struct cxl_context *ctx, u64 wed)
 	default:
 		break;
 	}
+
+	mmput(mm);
 }