Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1654751 > unrolled thread
| Started by | Jia-Ju Bai <baijiaju1990@163.com> |
|---|---|
| First post | 2017-06-01 03:50 +0200 |
| Last post | 2017-06-01 07:20 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH] rxe: Fix a sleep-in-atomic bug in post_one_send Jia-Ju Bai <baijiaju1990@163.com> - 2017-06-01 03:50 +0200
Re: [PATCH] rxe: Fix a sleep-in-atomic bug in post_one_send Leon Romanovsky <leon@kernel.org> - 2017-06-01 07:20 +0200
| From | Jia-Ju Bai <baijiaju1990@163.com> |
|---|---|
| Date | 2017-06-01 03:50 +0200 |
| Subject | [PATCH] rxe: Fix a sleep-in-atomic bug in post_one_send |
| Message-ID | <tNnpn-4r2-3@gated-at.bofh.it> |
The driver may sleep under a spin lock, and the function call path is:
post_one_send (acquire the lock by spin_lock_irqsave)
init_send_wqe
copy_from_user --> may sleep
To fix it, the lock is released before copy_from_user, and the lock is
acquired again after this function.
Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
drivers/infiniband/sw/rxe/rxe_verbs.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index 83d709e..6fb7e1a 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -725,7 +725,7 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
{
int num_sge = ibwr->num_sge;
struct ib_sge *sge;
- int i;
+ int i, err;
u8 *p;
init_send_wr(qp, &wqe->wr, ibwr);
@@ -740,8 +740,11 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
sge = ibwr->sg_list;
for (i = 0; i < num_sge; i++, sge++) {
- if (qp->is_user && copy_from_user(p, (__user void *)
- (uintptr_t)sge->addr, sge->length))
+ spin_unlock_irq(&qp->sq.sq_lock);
+ err = copy_from_user(p, (__user void *)
+ (uintptr_t)sge->addr, sge->length);
+ spin_lock_irq(&qp->sq.sq_lock);
+ if (qp->is_user && err)
return -EFAULT;
else if (!qp->is_user)
--
1.7.9.5
[toc] | [next] | [standalone]
| From | Leon Romanovsky <leon@kernel.org> |
|---|---|
| Date | 2017-06-01 07:20 +0200 |
| Message-ID | <tNqGB-6KR-5@gated-at.bofh.it> |
| In reply to | #1654751 |
[Multipart message — attachments visible in raw view] — view raw
On Thu, Jun 01, 2017 at 09:48:34AM +0800, Jia-Ju Bai wrote:
> The driver may sleep under a spin lock, and the function call path is:
> post_one_send (acquire the lock by spin_lock_irqsave)
> init_send_wqe
> copy_from_user --> may sleep
>
> To fix it, the lock is released before copy_from_user, and the lock is
> acquired again after this function.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
> ---
> drivers/infiniband/sw/rxe/rxe_verbs.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
> index 83d709e..6fb7e1a 100644
> --- a/drivers/infiniband/sw/rxe/rxe_verbs.c
> +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
> @@ -725,7 +725,7 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
> {
> int num_sge = ibwr->num_sge;
> struct ib_sge *sge;
> - int i;
> + int i, err;
> u8 *p;
>
> init_send_wr(qp, &wqe->wr, ibwr);
> @@ -740,8 +740,11 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
>
> sge = ibwr->sg_list;
> for (i = 0; i < num_sge; i++, sge++) {
> - if (qp->is_user && copy_from_user(p, (__user void *)
> - (uintptr_t)sge->addr, sge->length))
> + spin_unlock_irq(&qp->sq.sq_lock);
In original spin_lock, the flags of irq were saved, hence it should be
restored here too, but it is unclear to me if spin_lock is needed here
and it can't be converted to mutex_lock.
> + err = copy_from_user(p, (__user void *)
> + (uintptr_t)sge->addr, sge->length);
> + spin_lock_irq(&qp->sq.sq_lock);
> + if (qp->is_user && err)
> return -EFAULT;
>
> else if (!qp->is_user)
> --
> 1.7.9.5
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web