Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jun 2017 10:12:24 +0800
From:      Jia-Ju Bai <baijiaju1990@163.com>
To:        freebsdraid@avagotech.com, megaraidfbsd@avagotech.com
Cc:        freebsd-drivers@freebsd.org, freebsd-bugs@freebsd.org, Jia-Ju Bai <baijiaju1990@163.com>
Subject:   [PATCH] mrsas: Fix possible sleep-under-mutex bugs
Message-ID:  <20170619021224.44042-1-baijiaju1990@163.com>

next in thread | raw e-mail | index | archive | help
The driver may sleep under a mutex, and the function call paths are:
mrsas_reset_ctrl [line 2959: acquire the mutex]
  mrsas_ioc_init [line 3050]
    mrsas_alloc_ioc_cmd [line 2450]
      bus_dma_tag_create(BUS_DMA_ALLOCNOW) --> may sleep
mrsas_reset_ctrl [line 2959: acquire the mutex]
  megasas_setup_jbod_map [line 3089]
    bus_dma_tag_create(BUS_DMA_ALLOCNOW) --> may sleep

The possible fix of these bugs is to add "BUS_DMA_NOWAIT" in bus_dma_tag_create.

These bugs are found by a static analysis tool written by myself, and it is
checked by my review of the FreeBSD code.

Signed-off-by: Jia-Ju Bai <baijiaju1990@163.com>
---
 sys/dev/mrsas/mrsas.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/dev/mrsas/mrsas.c b/sys/dev/mrsas/mrsas.c
index d5e83494284..06f26c95841 100644
--- a/sys/dev/mrsas/mrsas.c
+++ b/sys/dev/mrsas/mrsas.c
@@ -2087,7 +2087,7 @@ megasas_setup_jbod_map(struct mrsas_softc *sc)
 		    pd_seq_map_sz,
 		    1,
 		    pd_seq_map_sz,
-		    BUS_DMA_ALLOCNOW,
+		    BUS_DMA_ALLOCNOW | BUS_DMA_NOWAIT,
 		    NULL, NULL,
 		    &sc->jbodmap_tag[i])) {
 			device_printf(sc->mrsas_dev,
@@ -2391,7 +2391,7 @@ mrsas_alloc_ioc_cmd(struct mrsas_softc *sc)
 	    ioc_init_size,
 	    1,
 	    ioc_init_size,
-	    BUS_DMA_ALLOCNOW,
+	    BUS_DMA_ALLOCNOW | BUS_DMA_NOWAIT,
 	    NULL, NULL,
 	    &sc->ioc_init_tag)) {
 		device_printf(sc->mrsas_dev, "Cannot allocate ioc init tag\n");
-- 
2.13.0





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170619021224.44042-1-baijiaju1990>