All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] cxl: Fix memory page not handled
@ 2017-09-25  8:58 Christophe Lombard
  2017-09-25 12:24 ` Frederic Barrat
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe Lombard @ 2017-09-25  8:58 UTC (permalink / raw)
  To: linuxppc-dev, fbarrat, vaibhav, andrew.donnellan

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.

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

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

diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
index 5dba23c..ff7492d 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] 6+ messages in thread

* Re: [PATCH V2] cxl: Fix memory page not handled
  2017-09-25  8:58 [PATCH V2] cxl: Fix memory page not handled Christophe Lombard
@ 2017-09-25 12:24 ` Frederic Barrat
  2017-09-26  1:20 ` Andrew Donnellan
  2017-09-26  1:44 ` Vaibhav Jain
  2 siblings, 0 replies; 6+ messages in thread
From: Frederic Barrat @ 2017-09-25 12:24 UTC (permalink / raw)
  To: Christophe Lombard, linuxppc-dev, vaibhav, andrew.donnellan



Le 25/09/2017 à 10:58, Christophe Lombard a écrit :
> 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.
> 
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> 
> Fixes: 3ced8d730063 ("cxl: Export library to support IBM XSL");
> 
> ---

Thanks,

Acked-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>



> 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(-)
> 
> diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
> index 5dba23c..ff7492d 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);
> 

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

* Re: [PATCH V2] cxl: Fix memory page not handled
  2017-09-25  8:58 [PATCH V2] cxl: Fix memory page not handled Christophe Lombard
  2017-09-25 12:24 ` Frederic Barrat
@ 2017-09-26  1:20 ` Andrew Donnellan
  2017-09-26  1:44 ` Vaibhav Jain
  2 siblings, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2017-09-26  1:20 UTC (permalink / raw)
  To: Christophe Lombard, linuxppc-dev, fbarrat, vaibhav

On 25/09/17 18:58, Christophe Lombard wrote:
> 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.
> 
> Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
> 
> 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 :)

Acked-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

> 
> ---
> 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(-)
> 
> diff --git a/drivers/misc/cxl/cxllib.c b/drivers/misc/cxl/cxllib.c
> index 5dba23c..ff7492d 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);
> 

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

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

* Re: [PATCH V2] cxl: Fix memory page not handled
  2017-09-25  8:58 [PATCH V2] cxl: Fix memory page not handled Christophe Lombard
  2017-09-25 12:24 ` Frederic Barrat
  2017-09-26  1:20 ` Andrew Donnellan
@ 2017-09-26  1:44 ` Vaibhav Jain
  2017-09-26  2:00   ` Andrew Donnellan
  2017-09-26  8:15   ` christophe lombard
  2 siblings, 2 replies; 6+ messages in thread
From: Vaibhav Jain @ 2017-09-26  1:44 UTC (permalink / raw)
  To: Christophe Lombard, linuxppc-dev, fbarrat, andrew.donnellan

Hi Christophe,

A minor nitpick

Christophe Lombard <clombard@linux.vnet.ibm.com> writes:

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

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

* Re: [PATCH V2] cxl: Fix memory page not handled
  2017-09-26  1:44 ` Vaibhav Jain
@ 2017-09-26  2:00   ` Andrew Donnellan
  2017-09-26  8:15   ` christophe lombard
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Donnellan @ 2017-09-26  2:00 UTC (permalink / raw)
  To: Vaibhav Jain, Christophe Lombard, linuxppc-dev, fbarrat

On 26/09/17 11:44, Vaibhav Jain wrote:
> Hi Christophe,
> 
> A minor nitpick
> 
> Christophe Lombard <clombard@linux.vnet.ibm.com> writes:
> 
>> +	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.

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited

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

* Re: [PATCH V2] cxl: Fix memory page not handled
  2017-09-26  1:44 ` Vaibhav Jain
  2017-09-26  2:00   ` Andrew Donnellan
@ 2017-09-26  8:15   ` christophe lombard
  1 sibling, 0 replies; 6+ messages in thread
From: christophe lombard @ 2017-09-26  8:15 UTC (permalink / raw)
  To: Vaibhav Jain, linuxppc-dev, fbarrat, andrew.donnellan

Le 26/09/2017 à 03:44, Vaibhav Jain a écrit :
> Hi Christophe,
>
> A minor nitpick
>
> Christophe Lombard <clombard@linux.vnet.ibm.com> writes:
>
>> +	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

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-25  8:58 [PATCH V2] cxl: Fix memory page not handled Christophe Lombard
2017-09-25 12:24 ` Frederic Barrat
2017-09-26  1:20 ` Andrew Donnellan
2017-09-26  1:44 ` Vaibhav Jain
2017-09-26  2:00   ` Andrew Donnellan
2017-09-26  8:15   ` christophe lombard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.