Skip to contentSkip to conversation

RDMA/umem: minor bug fix in error handling path

PATCH Superseded [email protected] 5 participants 8 messages Mar 4, 2019 – Mar 5, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover RDMA/umem: minor bug fix in error handling path

From: John Hubbard <[email protected]>

Hi,

Ira Weiny alerted me to a couple of places where I'd missed a change from put_page() to put_user_page(), in my pending patchsets. But when I attempted to dive more deeply into that code, I ran into a bug in the cleanup code. Leon Romanovsky has confirmed that and requested this simplified patch to fix it, so here it is.

Changes since v2:

1) Removed the part of the patch that tried to delete "dead code", because that code was dealing with huge pages.

2) Reverted the pr_*() line shortening, so as to keep this to only the minimal bug fix required.

3) Rebased to today's linux.git.

Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>

John Hubbard (1):
RDMA/umem: minor bug fix in error handling path

 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v3 1/1 RDMA/umem: minor bug fix in error handling path

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>
---
 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/infiniband/core/umem_odp.c +6 -3
index acb882f279cb..d45735b02e07 100644
@@ -40,6 +40,7 @@
 #include <linux/vmalloc.h>
 #include <linux/hugetlb.h>
 #include <linux/interval_tree_generic.h>
+#include <linux/pagemap.h>
 
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_umem.h>
@@ -684,9 +685,11 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt,
 		mutex_unlock(&umem_odp->umem_mutex);
 
 		if (ret < 0) {
-			/* Release left over pages when handling errors. */
-			for (++j; j < npages; ++j)
-				put_page(local_page_list[j]);
+			/*
+			 * Release pages, starting at the the first page
+			 * that experienced an error.
+			 */
+			release_pages(&local_page_list[j], npages - j);
 			break;
 		}
 	}
Signature · 1 line
2.21.0
#2 lore raw
Quoted 9 lines · On Mon, Mar 04, 2019 at 11:46:45AM -0800, [email protected] wrote:

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Quoted 8 lines
Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>
Quoted 34 lines
---
 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/infiniband/core/umem_odp.c +6 -3
index acb882f279cb..d45735b02e07 100644
@@ -40,6 +40,7 @@
 #include <linux/vmalloc.h>
 #include <linux/hugetlb.h>
 #include <linux/interval_tree_generic.h>
+#include <linux/pagemap.h>
 
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_umem.h>
@@ -684,9 +685,11 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt,
 		mutex_unlock(&umem_odp->umem_mutex);
 
 		if (ret < 0) {
-			/* Release left over pages when handling errors. */
-			for (++j; j < npages; ++j)
-				put_page(local_page_list[j]);
+			/*
+			 * Release pages, starting at the the first page
+			 * that experienced an error.
+			 */
+			release_pages(&local_page_list[j], npages - j);
 			break;
 		}
 	}
Signature · 1 line
2.21.0
Reviewed-by on v3 1/1
#3 lore raw
In reply to [email protected]
Quoted 9 lines · On Mon, Mar 04, 2019 at 11:46:45AM -0800, [email protected] wrote:

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Quoted 8 lines
Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>

I meant...

<sigh> just a bit too quick on the keyboard before lunch... ;-)

Ira

Quoted 34 lines
---
 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/infiniband/core/umem_odp.c +6 -3
index acb882f279cb..d45735b02e07 100644
@@ -40,6 +40,7 @@
 #include <linux/vmalloc.h>
 #include <linux/hugetlb.h>
 #include <linux/interval_tree_generic.h>
+#include <linux/pagemap.h>
 
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_umem.h>
@@ -684,9 +685,11 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt,
 		mutex_unlock(&umem_odp->umem_mutex);
 
 		if (ret < 0) {
-			/* Release left over pages when handling errors. */
-			for (++j; j < npages; ++j)
-				put_page(local_page_list[j]);
+			/*
+			 * Release pages, starting at the the first page
+			 * that experienced an error.
+			 */
+			release_pages(&local_page_list[j], npages - j);
 			break;
 		}
 	}
Signature · 1 line
2.21.0
#4 lore raw
Quoted 19 lines · Ira Weiny
Quoted 9 lines · On Mon, Mar 04, 2019 at 11:46:45AM -0800, [email protected] wrote:

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Quoted 8 lines
Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>
Quoted 7 lines

I meant...

<sigh> just a bit too quick on the keyboard before lunch... ;-)

Ira

I have this mapping in vimrc so i just have to do shift+!

map ! o Reviewed-by: Yuval Shaia <[email protected]> 

Quoted 36 lines
Quoted 36 lines

---
 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/infiniband/core/umem_odp.c +6 -3
index acb882f279cb..d45735b02e07 100644
@@ -40,6 +40,7 @@
 #include <linux/vmalloc.h>
 #include <linux/hugetlb.h>
 #include <linux/interval_tree_generic.h>
+#include <linux/pagemap.h>
 
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_umem.h>
@@ -684,9 +685,11 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt,
 		mutex_unlock(&umem_odp->umem_mutex);
 
 		if (ret < 0) {
-			/* Release left over pages when handling errors. */
-			for (++j; j < npages; ++j)
-				put_page(local_page_list[j]);
+			/*
+			 * Release pages, starting at the the first page
+			 * that experienced an error.
+			 */
+			release_pages(&local_page_list[j], npages - j);
 			break;
 		}
 	}
Signature · 1 line
2.21.0
#5 lore raw
Quoted 24 lines · Yuval Shaia
Quoted 23 lines · Ira Weiny
Quoted 9 lines · On Mon, Mar 04, 2019 at 11:46:45AM -0800, [email protected] wrote:

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Quoted 8 lines
Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>

I meant...

Quoted 7 lines
Quoted 3 lines

<sigh> just a bit too quick on the keyboard before lunch... ;-)

Ira

I have this mapping in vimrc so i just have to do shift+!

map ! o Reviewed-by: Yuval Shaia <[email protected]> 

I have something similar, but limited to responses through mail client only and mapped to "rt" key combination.

in my .vimrc:

augroup filetypedetect

	" Mail
	autocmd BufRead,BufNewFile *mutt-* setfiletype mail
	 " Add Reviewed-by tag and delete rest of the email
	function! RBtag()
		r~/.vim/mutt/rb-tag.txt
	endfunction
	nmap rt :call RBtag()<CR>2j<CR>dG<CR>

augroup END

Thanks

Acked-by on v3 1/1
#6 lore raw
In reply to [email protected]
Quoted 17 lines · On Mon, Mar 04, 2019 at 11:46:45AM -0800, [email protected] wrote:

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Cc Leon Romanovsky <[email protected]>
Cc Ira Weiny <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Doug Ledford <[email protected]>
Quoted 4 lines
---
 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Thanks,

#7 lore raw
In reply to [email protected]
Quoted 20 lines · On Mon, Mar 04, 2019 at 11:46:45AM -0800, [email protected] wrote:

From: John Hubbard <[email protected]>

1. Bug fix: fix an off by one error in the code that cleans up if it fails to dma-map a page, after having done a get_user_pages_remote() on a range of pages.

2. Refinement: for that same cleanup code, release_pages() is better than put_page() in a loop.

Quoted 3 lines
---
 drivers/infiniband/core/umem_odp.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Applied to for-next, thanks

Jason