linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cxl: Fix memory page not handled
@ 2017-09-22 13:08 Christophe Lombard
  2017-09-22 16:39 ` Frederic Barrat
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe Lombard @ 2017-09-22 13:08 UTC (permalink / raw)
  To: linuxppc-dev, fbarrat, vaibhav, andrew.donnellan

The a 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 the last page is
never touched, and the address the adapter is trying to access is never
sent to the kernel for resolution.

This patch updates the loop on the memory pages to be handled.

Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>

Fixes: 3ced8d730063 ("cxl: Export library to support IBM XSL");
---
 drivers/misc/cxl/cxllib.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
index 5dba23c..0c1eaf0 100644
--- a/drivers/misc/cxl/cxllib.c
+++ b/drivers/misc/cxl/cxllib.c
@@ -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);
-- 
2.7.4

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

* Re: [PATCH] cxl: Fix memory page not handled
  2017-09-22 13:08 [PATCH] cxl: Fix memory page not handled Christophe Lombard
@ 2017-09-22 16:39 ` Frederic Barrat
  0 siblings, 0 replies; 2+ messages in thread
From: Frederic Barrat @ 2017-09-22 16:39 UTC (permalink / raw)
  To: Christophe Lombard, linuxppc-dev, vaibhav, andrew.donnellan
  Cc: John W Walthour



Le 22/09/2017 à 15:08, Christophe Lombard a écrit :
> The a in-kernel 'library' API can be called by drivers to help


"the in-kernel library"



> 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 the last page is
> never touched, and the address the adapter is trying to access is never

nitpick: "never touched"? I thought it could be. It all depends on the 
input parameter. But it doesn't really matter, there's a bug.


> sent to the kernel for resolution.
> 
> This patch updates the loop on the memory pages to be handled.
> 
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> 
> Fixes: 3ced8d730063 ("cxl: Export library to support IBM XSL");
> ---
>   drivers/misc/cxl/cxllib.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
> index 5dba23c..0c1eaf0 100644
> --- a/drivers/misc/cxl/cxllib.c
> +++ b/drivers/misc/cxl/cxllib.c
> @@ -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) {


The end boundary should be 'dar < (addr + size)', or we may hit an extra 
page, which could fail (and cause the call to return an error). Thanks 
to John for spotting it!

   Fred


> +		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);
> 

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

end of thread, other threads:[~2017-09-22 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-22 13:08 [PATCH] cxl: Fix memory page not handled Christophe Lombard
2017-09-22 16:39 ` Frederic Barrat

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).