Skip to contentSkip to conversation

misc: ocxl: Change return type for fault handler

PATCH Applied Souptick Joarder 5 participants 7 messages Jun 11, 2018 – Jul 13, 2018

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: ocxl: Change return type for fault handler

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

---
 drivers/misc/ocxl/context.c | 22 +++++++++++-----------
 drivers/misc/ocxl/sysfs.c   |  5 ++---
 2 files changed, 13 insertions(+), 14 deletions(-)
drivers/misc/ocxl/context.c +11 -11
index 909e880..98daf91 100644
@@ -83,7 +83,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
 	return rc;
 }
 
-static int map_afu_irq(struct vm_area_struct *vma, unsigned long address,
+static vm_fault_t map_afu_irq(struct vm_area_struct *vma, unsigned long address,
 		u64 offset, struct ocxl_context *ctx)
 {
 	u64 trigger_addr;
@@ -92,15 +92,15 @@ static int map_afu_irq(struct vm_area_struct *vma, unsigned long address,
 	if (!trigger_addr)
 		return VM_FAULT_SIGBUS;
 
-	vm_insert_pfn(vma, address, trigger_addr >> PAGE_SHIFT);
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, address, trigger_addr >> PAGE_SHIFT);
 }
 
-static int map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
+static vm_fault_t map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
 		u64 offset, struct ocxl_context *ctx)
 {
 	u64 pp_mmio_addr;
 	int pasid_off;
+	vm_fault_t ret;
 
 	if (offset >= ctx->afu->config.pp_mmio_stride)
 		return VM_FAULT_SIGBUS;
@@ -118,27 +118,27 @@ static int map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
 		pasid_off * ctx->afu->config.pp_mmio_stride +
 		offset;
 
-	vm_insert_pfn(vma, address, pp_mmio_addr >> PAGE_SHIFT);
+	ret = vmf_insert_pfn(vma, address, pp_mmio_addr >> PAGE_SHIFT);
 	mutex_unlock(&ctx->status_mutex);
-	return VM_FAULT_NOPAGE;
+	return ret;
 }
 
-static int ocxl_mmap_fault(struct vm_fault *vmf)
+static vm_fault_t ocxl_mmap_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct ocxl_context *ctx = vma->vm_file->private_data;
 	u64 offset;
-	int rc;
+	vm_fault_t ret;
 
 	offset = vmf->pgoff << PAGE_SHIFT;
 	pr_debug("%s: pasid %d address 0x%lx offset 0x%llx\n", __func__,
 		ctx->pasid, vmf->address, offset);
 
 	if (offset < ctx->afu->irq_base_offset)
-		rc = map_pp_mmio(vma, vmf->address, offset, ctx);
+		ret = map_pp_mmio(vma, vmf->address, offset, ctx);
 	else
-		rc = map_afu_irq(vma, vmf->address, offset, ctx);
-	return rc;
+		ret = map_afu_irq(vma, vmf->address, offset, ctx);
+	return ret;
 }
 
 static const struct vm_operations_struct ocxl_vmops = {
drivers/misc/ocxl/sysfs.c +2 -3
index d9753a1..0ab1fd1 100644
@@ -64,7 +64,7 @@ static ssize_t global_mmio_read(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static int global_mmio_fault(struct vm_fault *vmf)
+static vm_fault_t global_mmio_fault(struct vm_fault *vmf)
 {
 	struct vm_area_struct *vma = vmf->vma;
 	struct ocxl_afu *afu = vma->vm_private_data;
@@ -75,8 +75,7 @@ static int global_mmio_fault(struct vm_fault *vmf)
 
 	offset = vmf->pgoff;
 	offset += (afu->global_mmio_start >> PAGE_SHIFT);
-	vm_insert_pfn(vma, vmf->address, offset);
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, vmf->address, offset);
 }
 
 static const struct vm_operations_struct global_mmio_vmops = {
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Souptick Joarder

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Quoted 8 lines

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

Looks okay to me

Quoted 96 lines
---
  drivers/misc/ocxl/context.c | 22 +++++++++++-----------
  drivers/misc/ocxl/sysfs.c   |  5 ++---
  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/misc/ocxl/context.c +11 -11
index 909e880..98daf91 100644
@@ -83,7 +83,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
  	return rc;
  }
 
-static int map_afu_irq(struct vm_area_struct *vma, unsigned long address,
+static vm_fault_t map_afu_irq(struct vm_area_struct *vma, unsigned long address,
  		u64 offset, struct ocxl_context *ctx)
  {
  	u64 trigger_addr;
@@ -92,15 +92,15 @@ static int map_afu_irq(struct vm_area_struct *vma, unsigned long address,
  	if (!trigger_addr)
  		return VM_FAULT_SIGBUS;
 
-	vm_insert_pfn(vma, address, trigger_addr >> PAGE_SHIFT);
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, address, trigger_addr >> PAGE_SHIFT);
  }
 
-static int map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
+static vm_fault_t map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
  		u64 offset, struct ocxl_context *ctx)
  {
  	u64 pp_mmio_addr;
  	int pasid_off;
+	vm_fault_t ret;
 
  	if (offset >= ctx->afu->config.pp_mmio_stride)
  		return VM_FAULT_SIGBUS;
@@ -118,27 +118,27 @@ static int map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
  		pasid_off * ctx->afu->config.pp_mmio_stride +
  		offset;
 
-	vm_insert_pfn(vma, address, pp_mmio_addr >> PAGE_SHIFT);
+	ret = vmf_insert_pfn(vma, address, pp_mmio_addr >> PAGE_SHIFT);
  	mutex_unlock(&ctx->status_mutex);
-	return VM_FAULT_NOPAGE;
+	return ret;
  }
 
-static int ocxl_mmap_fault(struct vm_fault *vmf)
+static vm_fault_t ocxl_mmap_fault(struct vm_fault *vmf)
  {
  	struct vm_area_struct *vma = vmf->vma;
  	struct ocxl_context *ctx = vma->vm_file->private_data;
  	u64 offset;
-	int rc;
+	vm_fault_t ret;
 
  	offset = vmf->pgoff << PAGE_SHIFT;
  	pr_debug("%s: pasid %d address 0x%lx offset 0x%llx\n", __func__,
  		ctx->pasid, vmf->address, offset);
 
  	if (offset < ctx->afu->irq_base_offset)
-		rc = map_pp_mmio(vma, vmf->address, offset, ctx);
+		ret = map_pp_mmio(vma, vmf->address, offset, ctx);
  	else
-		rc = map_afu_irq(vma, vmf->address, offset, ctx);
-	return rc;
+		ret = map_afu_irq(vma, vmf->address, offset, ctx);
+	return ret;
  }
 
  static const struct vm_operations_struct ocxl_vmops = {
drivers/misc/ocxl/sysfs.c +2 -3
index d9753a1..0ab1fd1 100644
@@ -64,7 +64,7 @@ static ssize_t global_mmio_read(struct file *filp, struct kobject *kobj,
  	return count;
  }
 
-static int global_mmio_fault(struct vm_fault *vmf)
+static vm_fault_t global_mmio_fault(struct vm_fault *vmf)
  {
  	struct vm_area_struct *vma = vmf->vma;
  	struct ocxl_afu *afu = vma->vm_private_data;
@@ -75,8 +75,7 @@ static int global_mmio_fault(struct vm_fault *vmf)
 
  	offset = vmf->pgoff;
  	offset += (afu->global_mmio_start >> PAGE_SHIFT);
-	vm_insert_pfn(vma, vmf->address, offset);
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, vmf->address, offset);
  }
 
  static const struct vm_operations_struct global_mmio_vmops = {
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]  IBM Australia Limited
Acked-by on v1 1/1
#2 lore raw
In reply to Souptick Joarder

Le 11/06/2018 à 22:29, Souptick Joarder a écrit :

Quoted 7 lines

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Quoted 7 lines

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

---

Thanks!

Tested and

Quoted 95 lines
  drivers/misc/ocxl/context.c | 22 +++++++++++-----------
  drivers/misc/ocxl/sysfs.c   |  5 ++---
  2 files changed, 13 insertions(+), 14 deletions(-)
drivers/misc/ocxl/context.c +11 -11
index 909e880..98daf91 100644
@@ -83,7 +83,7 @@ int ocxl_context_attach(struct ocxl_context *ctx, u64 amr)
  	return rc;
  }
 
-static int map_afu_irq(struct vm_area_struct *vma, unsigned long address,
+static vm_fault_t map_afu_irq(struct vm_area_struct *vma, unsigned long address,
  		u64 offset, struct ocxl_context *ctx)
  {
  	u64 trigger_addr;
@@ -92,15 +92,15 @@ static int map_afu_irq(struct vm_area_struct *vma, unsigned long address,
  	if (!trigger_addr)
  		return VM_FAULT_SIGBUS;
 
-	vm_insert_pfn(vma, address, trigger_addr >> PAGE_SHIFT);
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, address, trigger_addr >> PAGE_SHIFT);
  }
 
-static int map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
+static vm_fault_t map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
  		u64 offset, struct ocxl_context *ctx)
  {
  	u64 pp_mmio_addr;
  	int pasid_off;
+	vm_fault_t ret;
 
  	if (offset >= ctx->afu->config.pp_mmio_stride)
  		return VM_FAULT_SIGBUS;
@@ -118,27 +118,27 @@ static int map_pp_mmio(struct vm_area_struct *vma, unsigned long address,
  		pasid_off * ctx->afu->config.pp_mmio_stride +
  		offset;
 
-	vm_insert_pfn(vma, address, pp_mmio_addr >> PAGE_SHIFT);
+	ret = vmf_insert_pfn(vma, address, pp_mmio_addr >> PAGE_SHIFT);
  	mutex_unlock(&ctx->status_mutex);
-	return VM_FAULT_NOPAGE;
+	return ret;
  }
 
-static int ocxl_mmap_fault(struct vm_fault *vmf)
+static vm_fault_t ocxl_mmap_fault(struct vm_fault *vmf)
  {
  	struct vm_area_struct *vma = vmf->vma;
  	struct ocxl_context *ctx = vma->vm_file->private_data;
  	u64 offset;
-	int rc;
+	vm_fault_t ret;
 
  	offset = vmf->pgoff << PAGE_SHIFT;
  	pr_debug("%s: pasid %d address 0x%lx offset 0x%llx\n", __func__,
  		ctx->pasid, vmf->address, offset);
 
  	if (offset < ctx->afu->irq_base_offset)
-		rc = map_pp_mmio(vma, vmf->address, offset, ctx);
+		ret = map_pp_mmio(vma, vmf->address, offset, ctx);
  	else
-		rc = map_afu_irq(vma, vmf->address, offset, ctx);
-	return rc;
+		ret = map_afu_irq(vma, vmf->address, offset, ctx);
+	return ret;
  }
 
  static const struct vm_operations_struct ocxl_vmops = {
drivers/misc/ocxl/sysfs.c +2 -3
index d9753a1..0ab1fd1 100644
@@ -64,7 +64,7 @@ static ssize_t global_mmio_read(struct file *filp, struct kobject *kobj,
  	return count;
  }
 
-static int global_mmio_fault(struct vm_fault *vmf)
+static vm_fault_t global_mmio_fault(struct vm_fault *vmf)
  {
  	struct vm_area_struct *vma = vmf->vma;
  	struct ocxl_afu *afu = vma->vm_private_data;
@@ -75,8 +75,7 @@ static int global_mmio_fault(struct vm_fault *vmf)
 
  	offset = vmf->pgoff;
  	offset += (afu->global_mmio_start >> PAGE_SHIFT);
-	vm_insert_pfn(vma, vmf->address, offset);
-	return VM_FAULT_NOPAGE;
+	return vmf_insert_pfn(vma, vmf->address, offset);
  }
 
  static const struct vm_operations_struct global_mmio_vmops = {
#3 lore raw

On Thu, Jun 14, 2018 at 9:36 PM, Frederic Barrat <[email protected]> wr= ote:

Quoted 16 lines

Le 11/06/2018 =C3=A0 22:29, Souptick Joarder a =C3=A9crit :

Quoted 13 lines

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

Quoted 10 lines
Quoted 2 lines

---

Thanks!

Tested and

Frederic, is this patch queued for 4.19 ?

#4 lore raw
Quoted 1 line · Souptick Joarder

On Thu, Jun 14, 2018 at 9:36 PM, Frederic Barrat <[email protected]> =

Quoted 18 lines · wrote:
Quoted 18 lines

Le 11/06/2018 =C3=A0 22:29, Souptick Joarder a =C3=A9crit :

Quoted 15 lines

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

---

Quoted 6 lines
Quoted 4 lines

Thanks!

Tested and

Frederic, is this patch queued for 4.19 ?

Not yet, you're a bit early. 4.18-rc1 only came out the other day :)

Your patches are tracked here:

http://patchwork.ozlabs.org/project/linuxppc-dev/list/?submitter=3D67924

They should appear in 4.19 unless something conflicts with them.

cheers

#5 lore raw
In reply to Souptick Joarder
Quoted 7 lines · Souptick Joarder

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Quoted 8 lines

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/a545cf032d11437ed86e62f00d4991

cheers

#6 lore raw
Quoted 17 lines · Michael Ellerman
Quoted 7 lines · Souptick Joarder

Use new return type vm_fault_t for fault handler. For now, this is just documenting that the function returns a VM_FAULT value rather than an errno. Once all instances are converted, vm_fault_t will become a distinct type.

Ref-> commit 1c8f422059ae ("mm: change return type to vm_fault_t")

Quoted 8 lines

There is an existing bug when vm_insert_pfn() can return ENOMEM which was ignored and VM_FAULT_NOPAGE returned as default. The new inline vmf_insert_pfn() has removed this inefficiency by returning correct vm_fault_ type.

Quoted 5 lines

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/a545cf032d11437ed86e62f00d4991

cheers

Thanks :)