Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1511990imm; Fri, 14 Sep 2018 20:42:31 -0700 (PDT) X-Google-Smtp-Source: ANB0VdacDCmlwvwzZoBHGWo3Po6DB6mxrjDJPI8a48i2IC8pMNHojHutP2J9RWX0Jmx4dAEfj0dA X-Received: by 2002:a63:7a0f:: with SMTP id v15-v6mr14537713pgc.127.1536982951813; Fri, 14 Sep 2018 20:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536982951; cv=none; d=google.com; s=arc-20160816; b=aX5cSBck27VIrAyLkjdXNv+YP8LbCK+ilcIPSikF8Td+MBAAHIPgNZFQklrp9wlfWF ZlglIyUWSfRrZtb3gipW/5wzkj/KzFoKfJ9JTAm1HsJRftj3ki68q3L6do3CiN1J+y9G N7MDYr7DY6iWNeP1b3YLJKBIjrpDMpqsYexApaCkGl0eyY8Xd4T1PL22kxhPjzlIjT90 hhjC18cKwQYnFkoNUcT/hl1YqniRu6C5FQJ8wqPLRSNPhp9dusn0USkaqbj4TJR2EyaQ t/t2tEaneen6Xsm6KZGz2X8aSbqn5jNH+QN+RCxgmhzvqSRWUXofHnKEkk7vrrelrW+4 7ttQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=PG75NBZAQXGS57U08M9CJ+QkfhHgTs56HWq6D4D4LPc=; b=B8Z9xc6hNZNds51W8L2n821i5BXP1K3vPCYUhjsnVCLgcu8zmu+vzANEFf7oLphgR7 sYMByzk6IIE7JOdce7Ta3wwW0hB0fi9QXFTcq/+J/bWUispVSX0nNX6VLrFpw+stl0h1 pxYJHfUQ7/ldAKs3Qu4p0Xw74CasK/AQzoDrCRjGubjK9IR1CQjZS5HwD5OAkp0D8n8g 41w5URtBB39atlmYG6VyJ+y3FcAwuPOHW7RUKKE/Y4GHbymxzZf6QydfM+WgIhBSMQ/3 HUHGI6rk7Z64Q88PdfzVLRoRDSPrAKo7bTF/B4f+m5qKh4XUnc6UGxEGTOitwV8nrf9D fyWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BxHughbX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14-v6si9045062pgg.67.2018.09.14.20.41.45; Fri, 14 Sep 2018 20:42:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BxHughbX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727110AbeIOI6u (ORCPT + 99 others); Sat, 15 Sep 2018 04:58:50 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:41020 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726295AbeIOI6t (ORCPT ); Sat, 15 Sep 2018 04:58:49 -0400 Received: by mail-pl1-f193.google.com with SMTP id b12-v6so5012239plr.8; Fri, 14 Sep 2018 20:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=PG75NBZAQXGS57U08M9CJ+QkfhHgTs56HWq6D4D4LPc=; b=BxHughbXL95eAczzkLTIcO9wzR1muAkVmo0FYrnK20TOy/K+kXlLpZMRdAufU1JSIM 8QDCUB5DpxAjI4XtlTzoDoea4MsADud/zVNbYR+02jjgomHrup3Xt1z8H9PfTFzhwt0D tHOl4Ij7YJ+SyPwpx/N5NMQUEsHnstuuAYOT1xcreTjz7Epmuk6RXUo//OdnFu3BTQ5m 6Kr7zdVCSW8xKF/02odEf6WvUZzssASJbMzZzSNGPHDlZeosUhs0eJE79kuExCyEDzQM 1uIy3rrEwW2EkGOaw4k+bScMqyDxAvfa/nxR1H4aK+QmOX679bH07+NJxsFMULZzAF+h e36A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=PG75NBZAQXGS57U08M9CJ+QkfhHgTs56HWq6D4D4LPc=; b=HMvwMoOoO2dZkhGLaHdR05JypOPXQp5i9IbEzitLJjV/f2j/t7y1Xo+EQuK2dGhgNV ky09N+s/10MauqP/ZxAieWqMGJ33GtXYxfp4LOP9uBGWqDTj/x6St4h63C8Lr6HZ1pmR vMAcvDI6gjacWw1jNzdiEwu9McSzAu04jpDeMPQFj35bFW+HCBJcsno9aI029TVKLeTv D/qpmjuXNoPTR+MNqlmK8BbxvxgMdu3f91YZeld/6jaZTSBOHWZbFJFxzA6PVFGxhVER SzcepAA0lqN4IJiHgfqpjqPX7xQtFMkeNKoS5lnyDGZiMwzetggUbj6KO29l7GpCgIlV kP4g== X-Gm-Message-State: APzg51BpnBTr8bVvfWhiOAUbO8S+GpUXuGRRFx4AjgJA0MVqgLdOWuCW SrQ6qc1FbhX6WnvtztArMhY= X-Received: by 2002:a17:902:900a:: with SMTP id a10-v6mr14801298plp.143.1536982884556; Fri, 14 Sep 2018 20:41:24 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:947c:62c0:a59c:7c99]) by smtp.gmail.com with ESMTPSA id c8-v6sm10255767pfb.147.2018.09.14.20.41.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 20:41:23 -0700 (PDT) From: Jia-Ju Bai To: james.smart@broadcom.com, dick.kennedy@broadcom.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] scsi: lpfc: Fix three sleep-in-atomic-context bugs in lpfc_sli4_nvmet_alloc() Date: Sat, 15 Sep 2018 11:41:15 +0800 Message-Id: <20180915034115.6543-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver may sleep with holding a spinlock. The function call paths (from bottom to top) in Linux-4.17 are: [FUNC] kzalloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_mem.c, 633: kzalloc in lpfc_sli4_nvmet_alloc drivers/scsi/lpfc/lpfc_sli.c, 6729: [FUNC_PTR]lpfc_sli4_nvmet_alloc in lpfc_post_rq_buffer drivers/scsi/lpfc/lpfc_sli.c, 6723: _raw_spin_lock_irqsave in lpfc_post_rq_buffer [FUNC] dma_pool_alloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_mem.c, 637: dma_pool_alloc in lpfc_sli4_nvmet_alloc drivers/scsi/lpfc/lpfc_sli.c, 6729: [FUNC_PTR]lpfc_sli4_nvmet_alloc in lpfc_post_rq_buffer drivers/scsi/lpfc/lpfc_sli.c, 6723: _raw_spin_lock_irqsave in lpfc_post_rq_buffer [FUNC] dma_pool_alloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_mem.c, 643: dma_pool_alloc in lpfc_sli4_nvmet_alloc drivers/scsi/lpfc/lpfc_sli.c, 6729: [FUNC_PTR]lpfc_sli4_nvmet_alloc in lpfc_post_rq_buffer drivers/scsi/lpfc/lpfc_sli.c, 6723: _raw_spin_lock_irqsave in lpfc_post_rq_buffer Note that [FUNC_PTR] means a function pointer call is used. To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC. These bugs are found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/scsi/lpfc/lpfc_mem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c index 9c22a2c93462..20359e5d0016 100644 --- a/drivers/scsi/lpfc/lpfc_mem.c +++ b/drivers/scsi/lpfc/lpfc_mem.c @@ -631,18 +631,18 @@ lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba) { struct rqb_dmabuf *dma_buf; - dma_buf = kzalloc(sizeof(struct rqb_dmabuf), GFP_KERNEL); + dma_buf = kzalloc(sizeof(struct rqb_dmabuf), GFP_ATOMIC); if (!dma_buf) return NULL; - dma_buf->hbuf.virt = dma_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL, + dma_buf->hbuf.virt = dma_pool_alloc(phba->lpfc_hrb_pool, GFP_ATOMIC, &dma_buf->hbuf.phys); if (!dma_buf->hbuf.virt) { kfree(dma_buf); return NULL; } dma_buf->dbuf.virt = dma_pool_alloc(phba->lpfc_nvmet_drb_pool, - GFP_KERNEL, &dma_buf->dbuf.phys); + GFP_ATOMIC, &dma_buf->dbuf.phys); if (!dma_buf->dbuf.virt) { dma_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt, dma_buf->hbuf.phys); -- 2.17.0