Skip to contentSkip to conversation

cxl: Fix memory page not handled

PATCH Superseded Christophe Lombard 4 participants 6 messages Sep 25, 2017 – Sep 26, 2017 Char and misc drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cxl: Fix memory page not handled

The in-kernel 'library' API can be called by drivers to help interaction with an IBM XSL on a POWER9 system.

The cxllib_handle_fault() API is used to handle memory fault. All memory pages of the specified buffer have to be handled but under certain conditions,the last page may not be touched, and the address the adapter is trying to access is never sent to the kernel for resolution.

This patch reworks start address of the loop with an address aligned on the page size. In this context, the last page is not missed.

Fixes 3ced8d730063 ("cxl: Export library to support IBM XSL");

---
Changelog[v2]
- Rebase to latest upstream.
- Change the start address of the loop.
- Rewrite the commit message.

---
 drivers/misc/cxl/cxllib.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/misc/cxl/cxllib.c +11 -2
index 5dba23c..ff7492d 100644
@@ -219,8 +219,17 @@ int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
 
 	down_read(&mm->mmap_sem);
 
-	for (dar = addr; dar < addr + size; dar += page_size) {
-		if (!vma || dar < vma->vm_start || dar > vma->vm_end) {
+	vma = find_vma(mm, addr);
+	if (!vma) {
+		pr_err("Can't find vma for addr %016llx\n", addr);
+		rc = -EFAULT;
+		goto out;
+	}
+	/* get the size of the pages allocated */
+	page_size = vma_kernel_pagesize(vma);
+
+	for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
+		if (dar < vma->vm_start || dar > vma->vm_end) {
 			vma = find_vma(mm, addr);
 			if (!vma) {
 				pr_err("Can't find vma for addr %016llx\n", addr);
Signature · 1 line
2.7.4
Acked-by on v2 1/1
#1 lore raw

Le 25/09/2017 à 10:58, Christophe Lombard a écrit :

Quoted 8 lines

The in-kernel 'library' API can be called by drivers to help interaction with an IBM XSL on a POWER9 system.

The cxllib_handle_fault() API is used to handle memory fault. All memory pages of the specified buffer have to be handled but under certain conditions,the last page may not be touched, and the address the adapter is trying to access is never sent to the kernel for resolution.

Quoted 8 lines

This patch reworks start address of the loop with an address aligned on the page size. In this context, the last page is not missed.

Fixes 3ced8d730063 ("cxl: Export library to support IBM XSL");

---

Thanks,

Quoted 33 lines

Changelog[v2]
- Rebase to latest upstream.
- Change the start address of the loop.
- Rewrite the commit message.

---
  drivers/misc/cxl/cxllib.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
drivers/misc/cxl/cxllib.c +11 -2
index 5dba23c..ff7492d 100644
@@ -219,8 +219,17 @@ int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
 
  	down_read(&mm->mmap_sem);
 
-	for (dar = addr; dar < addr + size; dar += page_size) {
-		if (!vma || dar < vma->vm_start || dar > vma->vm_end) {
+	vma = find_vma(mm, addr);
+	if (!vma) {
+		pr_err("Can't find vma for addr %016llx\n", addr);
+		rc = -EFAULT;
+		goto out;
+	}
+	/* get the size of the pages allocated */
+	page_size = vma_kernel_pagesize(vma);
+
+	for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
+		if (dar < vma->vm_start || dar > vma->vm_end) {
  			vma = find_vma(mm, addr);
  			if (!vma) {
  				pr_err("Can't find vma for addr %016llx\n", addr);
Acked-by on v2 1/1
#2 lore raw
In reply to Christophe Lombard
Quoted 8 lines · Christophe Lombard

The in-kernel 'library' API can be called by drivers to help interaction with an IBM XSL on a POWER9 system.

The cxllib_handle_fault() API is used to handle memory fault. All memory pages of the specified buffer have to be handled but under certain conditions,the last page may not be touched, and the address the adapter is trying to access is never sent to the kernel for resolution.

Quoted 6 lines

This patch reworks start address of the loop with an address aligned on the page size. In this context, the last page is not missed.

Fixes 3ced8d730063 ("cxl: Export library to support IBM XSL");

The duplication of the find_vma() depresses me slightly but I suppose there's not much that can be done there :)

Quoted 35 lines

---
Changelog[v2]
- Rebase to latest upstream.
- Change the start address of the loop.
- Rewrite the commit message.

---
  drivers/misc/cxl/cxllib.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
drivers/misc/cxl/cxllib.c +11 -2
index 5dba23c..ff7492d 100644
@@ -219,8 +219,17 @@ int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags)
 
  	down_read(&mm->mmap_sem);
 
-	for (dar = addr; dar < addr + size; dar += page_size) {
-		if (!vma || dar < vma->vm_start || dar > vma->vm_end) {
+	vma = find_vma(mm, addr);
+	if (!vma) {
+		pr_err("Can't find vma for addr %016llx\n", addr);
+		rc = -EFAULT;
+		goto out;
+	}
+	/* get the size of the pages allocated */
+	page_size = vma_kernel_pagesize(vma);
+
+	for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
+		if (dar < vma->vm_start || dar > vma->vm_end) {
  			vma = find_vma(mm, addr);
  			if (!vma) {
  				pr_err("Can't find vma for addr %016llx\n", addr);
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]  IBM Australia Limited
#3 lore raw
In reply to Christophe Lombard

Hi Christophe,

A minor nitpick

drivers/misc/cxl/cxllib.c int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags) · line 232

Quoted 2 lines · Christophe Lombard
drivers/misc/cxl/cxllib.c +2 -0
+	for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
+		if (dar < vma->vm_start || dar > vma->vm_end) {

Code comment in mm_types.h for vm_end says it "The first byte after our end address within vm_mm". So this condition should be
(dar < vma->vm_start || dar >= vma->vm_end)

~ Vaibhav

#4 lore raw
Quoted 4 lines · Vaibhav Jain

Hi Christophe,

A minor nitpick

Quoted 8 lines

drivers/misc/cxl/cxllib.c int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags) · line 232

Quoted 2 lines · Christophe Lombard
drivers/misc/cxl/cxllib.c +2 -0
+	for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
+		if (dar < vma->vm_start || dar > vma->vm_end) {

Code comment in mm_types.h for vm_end says it "The first byte after our end address within vm_mm". So this condition should be
(dar < vma->vm_start || dar >= vma->vm_end)

Hmm, I *think* you're right... a quick grep through the tree seems to indicate that I'm not the only one to have made that mistake...

Christophe if you're happy to do a v3 with this fixed as well that would be great.

Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]  IBM Australia Limited
#5 lore raw
In reply to Vaibhav Jain

Le 26/09/2017 à 03:44, Vaibhav Jain a écrit :

Quoted 6 lines

Hi Christophe,

A minor nitpick

Christophe Lombard <[email protected]> writes:

Quoted 7 lines

drivers/misc/cxl/cxllib.c int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags) · line 232

Quoted 2 lines
drivers/misc/cxl/cxllib.c +2 -0
+	for (dar = (addr & ~(page_size - 1)); dar < (addr + size); dar += page_size) {
+		if (dar < vma->vm_start || dar > vma->vm_end) {

Code comment in mm_types.h for vm_end says it "The first byte after our end address within vm_mm". So this condition should be
(dar < vma->vm_start || dar >= vma->vm_end)

~ Vaibhav

You are right. Thanks for the review