linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] infiniband: hw: hns: Fix a sleep-in-atomic-context bug in hns_roce_set_hem()
@ 2018-09-01 11:39 Jia-Ju Bai
  2018-09-05 21:54 ` Jason Gunthorpe
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2018-09-01 11:39 UTC (permalink / raw)
  To: oulijun, xavier.huwei, dledford, jgg; +Cc: linux-rdma, linux-kernel, Jia-Ju Bai

The driver may sleep with holding a spinlock.

The function call paths (from bottom to top) in Linux-4.16 are:

drivers/infiniband/hw/hns/hns_roce_hem.c, 345: 
	msleep in hns_roce_set_hem
drivers/infiniband/hw/hns/hns_roce_hem.c, 330: 
	_raw_spin_lock_irqsave in hns_roce_set_hem

To fix this bug, msleep() is replaced with mdelay().

This bug is found by my static analysis tool DSAC.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/infiniband/hw/hns/hns_roce_hem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/hns/hns_roce_hem.c b/drivers/infiniband/hw/hns/hns_roce_hem.c
index 63b5b3edabcb..8c142676c589 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hem.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hem.c
@@ -342,7 +342,7 @@ static int hns_roce_set_hem(struct hns_roce_dev *hr_dev,
 			} else {
 				break;
 			}
-			msleep(HW_SYNC_SLEEP_TIME_INTERVAL);
+			mdelay(HW_SYNC_SLEEP_TIME_INTERVAL);
 		}
 
 		bt_cmd_l = (u32)bt_ba;
-- 
2.17.0


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

* Re: [PATCH] infiniband: hw: hns: Fix a sleep-in-atomic-context bug in hns_roce_set_hem()
  2018-09-01 11:39 [PATCH] infiniband: hw: hns: Fix a sleep-in-atomic-context bug in hns_roce_set_hem() Jia-Ju Bai
@ 2018-09-05 21:54 ` Jason Gunthorpe
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2018-09-05 21:54 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: oulijun, xavier.huwei, dledford, linux-rdma, linux-kernel

On Sat, Sep 01, 2018 at 07:39:48PM +0800, Jia-Ju Bai wrote:
> The driver may sleep with holding a spinlock.
> 
> The function call paths (from bottom to top) in Linux-4.16 are:
> 
> drivers/infiniband/hw/hns/hns_roce_hem.c, 345: 
> 	msleep in hns_roce_set_hem
> drivers/infiniband/hw/hns/hns_roce_hem.c, 330: 
> 	_raw_spin_lock_irqsave in hns_roce_set_hem
> 
> To fix this bug, msleep() is replaced with mdelay().
> 
> This bug is found by my static analysis tool DSAC.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/infiniband/hw/hns/hns_roce_hem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

This was already fixed here:

commit 73b4e1f4c04e76b19fca296d09b97555bfb35202
Author: Lijun Ou <oulijun@huawei.com>
Date:   Wed Jul 25 15:29:38 2018 +0800

    RDMA/hns: Use delay instead of usleep
    
    In order to avoid using usleep function in lock function, we use delay
    function instead of it.  Besides, it also use brackets for standardized
    the computed order.
    
    Signed-off-by: Lijun Ou <oulijun@huawei.com>
    Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

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

end of thread, other threads:[~2018-09-05 21:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-01 11:39 [PATCH] infiniband: hw: hns: Fix a sleep-in-atomic-context bug in hns_roce_set_hem() Jia-Ju Bai
2018-09-05 21:54 ` Jason Gunthorpe

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