public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] ipath/qib deadlock
@ 2013-10-04 13:29 Mike Marciniszyn
       [not found] ` <20131004132821.29162.46169.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Marciniszyn @ 2013-10-04 13:29 UTC (permalink / raw)
  To: roland-BHEL68pLQRGGvPXPguhicg; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Jan Kara

These two patches fix flaws that have been
observed in the wild with qib.

The issue has also been code inspected by
Jan Kara in his get_user_pages_unlocked()
patch series.

By using get_user_pages_fast() the dependency
on Jan's patch set has been removed. I can't
find any issue with losing the force in these
use cases.

Jan Kara (2):
      IB/ipath: Convert ipath_user_sdma_pin_pages() to use get_user_pages_fast()
      IB/qib: Convert qib_user_sdma_pin_pages() to use get_user_pages_fast()


 drivers/infiniband/hw/ipath/ipath_user_sdma.c |    7 +------
 drivers/infiniband/hw/qib/qib_user_sdma.c     |    6 +-----
 2 files changed, 2 insertions(+), 11 deletions(-)

-- 
Mike
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 1/2] IB/ipath: Convert ipath_user_sdma_pin_pages() to use get_user_pages_fast()
       [not found] ` <20131004132821.29162.46169.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
@ 2013-10-04 13:29   ` Mike Marciniszyn
       [not found]     ` <20131004132906.29162.1038.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
  2013-10-04 13:29   ` [PATCH 2/2] IB/qib: Convert qib_user_sdma_pin_pages() " Mike Marciniszyn
  1 sibling, 1 reply; 4+ messages in thread
From: Mike Marciniszyn @ 2013-10-04 13:29 UTC (permalink / raw)
  To: roland-BHEL68pLQRGGvPXPguhicg; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Jan Kara

From: Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>

Function ipath_user_sdma_queue_pkts() gets called with mmap_sem held for
writing. Except for get_user_pages() deep down in
ipath_user_sdma_pin_pages() we don't seem to need mmap_sem at all. Even
more interestingly the function ipath_user_sdma_queue_pkts() (and also
ipath_user_sdma_coalesce() called somewhat later) call copy_from_user()
which can hit a page fault and we deadlock on trying to get mmap_sem
when handling that fault. So just make ipath_user_sdma_pin_pages() use
get_user_pages_fast() and leave mmap_sem locking for mm.

This deadlock has actually been observed in the wild when the node
is under memory pressure.

Cc: Mike Marciniszyn <mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: Roland Dreier <roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Signed-off-by: Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>
---
 drivers/infiniband/hw/ipath/ipath_user_sdma.c |    7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/infiniband/hw/ipath/ipath_user_sdma.c b/drivers/infiniband/hw/ipath/ipath_user_sdma.c
index f5cb13b..06cbfd4 100644
--- a/drivers/infiniband/hw/ipath/ipath_user_sdma.c
+++ b/drivers/infiniband/hw/ipath/ipath_user_sdma.c
@@ -280,9 +280,7 @@ static int ipath_user_sdma_pin_pages(const struct ipath_devdata *dd,
 	int j;
 	int ret;
 
-	ret = get_user_pages(current, current->mm, addr,
-			     npages, 0, 1, pages, NULL);
-
+	ret = get_user_pages_fast(addr, j, 0, pages);
 	if (ret != npages) {
 		int i;
 
@@ -811,10 +809,7 @@ int ipath_user_sdma_writev(struct ipath_devdata *dd,
 	while (dim) {
 		const int mxp = 8;
 
-		down_write(&current->mm->mmap_sem);
 		ret = ipath_user_sdma_queue_pkts(dd, pq, &list, iov, dim, mxp);
-		up_write(&current->mm->mmap_sem);
-
 		if (ret <= 0)
 			goto done_unlock;
 		else {

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 2/2] IB/qib: Convert qib_user_sdma_pin_pages() to use get_user_pages_fast()
       [not found] ` <20131004132821.29162.46169.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
  2013-10-04 13:29   ` [PATCH 1/2] IB/ipath: Convert ipath_user_sdma_pin_pages() to use get_user_pages_fast() Mike Marciniszyn
@ 2013-10-04 13:29   ` Mike Marciniszyn
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Marciniszyn @ 2013-10-04 13:29 UTC (permalink / raw)
  To: roland-BHEL68pLQRGGvPXPguhicg; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Jan Kara

From: Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>

Function qib_user_sdma_queue_pkts() gets called with mmap_sem held for
writing. Except for get_user_pages() deep down in
qib_user_sdma_pin_pages() we don't seem to need mmap_sem at all.  Even
more interestingly the function qib_user_sdma_queue_pkts() (and also
qib_user_sdma_coalesce() called somewhat later) call copy_from_user()
which can hit a page fault and we deadlock on trying to get mmap_sem
when handling that fault. So just make qib_user_sdma_pin_pages() use
get_user_pages_fast() and leave mmap_sem locking for mm.

This deadlock has actually been observed in the wild when the node
is under memory pressure.

Cc: Roland Dreier <roland-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>
---
 drivers/infiniband/hw/qib/qib_user_sdma.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/infiniband/hw/qib/qib_user_sdma.c b/drivers/infiniband/hw/qib/qib_user_sdma.c
index d0a0ea0..165aee2 100644
--- a/drivers/infiniband/hw/qib/qib_user_sdma.c
+++ b/drivers/infiniband/hw/qib/qib_user_sdma.c
@@ -594,8 +594,7 @@ static int qib_user_sdma_pin_pages(const struct qib_devdata *dd,
 		else
 			j = npages;
 
-		ret = get_user_pages(current, current->mm, addr,
-			     j, 0, 1, pages, NULL);
+		ret = get_user_pages_fast(addr, j, 0, pages);
 		if (ret != j) {
 			i = 0;
 			j = ret;
@@ -1294,11 +1293,8 @@ int qib_user_sdma_writev(struct qib_ctxtdata *rcd,
 		int mxp = 8;
 		int ndesc = 0;
 
-		down_write(&current->mm->mmap_sem);
 		ret = qib_user_sdma_queue_pkts(dd, ppd, pq,
 				iov, dim, &list, &mxp, &ndesc);
-		up_write(&current->mm->mmap_sem);
-
 		if (ret < 0)
 			goto done_unlock;
 		else {

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [PATCH 1/2] IB/ipath: Convert ipath_user_sdma_pin_pages() to use get_user_pages_fast()
       [not found]     ` <20131004132906.29162.1038.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
@ 2013-10-04 13:45       ` Marciniszyn, Mike
  0 siblings, 0 replies; 4+ messages in thread
From: Marciniszyn, Mike @ 2013-10-04 13:45 UTC (permalink / raw)
  To: Marciniszyn, Mike, roland-BHEL68pLQRGGvPXPguhicg@public.gmane.org
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jan Kara

> Even more interestingly the function ipath_user_sdma_queue_pkts() (and
> also
> ipath_user_sdma_coalesce() called somewhat later) call copy_from_user()
> which can hit a page fault and we deadlock on trying to get mmap_sem
> when handling that fault. So just make ipath_user_sdma_pin_pages() use
> get_user_pages_fast() and leave mmap_sem locking for mm.
> 
> This deadlock has actually been observed in the wild when the node is under
> memory pressure.

This patch has been re-submited in http://marc.info/?l=linux-rdma&m=138089335106353&w=2.

Mike

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

end of thread, other threads:[~2013-10-04 13:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-04 13:29 [PATCH 0/2] ipath/qib deadlock Mike Marciniszyn
     [not found] ` <20131004132821.29162.46169.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
2013-10-04 13:29   ` [PATCH 1/2] IB/ipath: Convert ipath_user_sdma_pin_pages() to use get_user_pages_fast() Mike Marciniszyn
     [not found]     ` <20131004132906.29162.1038.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
2013-10-04 13:45       ` Marciniszyn, Mike
2013-10-04 13:29   ` [PATCH 2/2] IB/qib: Convert qib_user_sdma_pin_pages() " Mike Marciniszyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox