Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1512486imm; Fri, 14 Sep 2018 20:43:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbhivhjE1WjjDeDpT+6rJtu4P7M0iQ63sSQrbStFzWc9YXsOn6UuOZRnHvPi8fMeLx2PlU1 X-Received: by 2002:a17:902:a405:: with SMTP id p5-v6mr14775534plq.222.1536982998839; Fri, 14 Sep 2018 20:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536982998; cv=none; d=google.com; s=arc-20160816; b=yez22OwW98046gKu2RWy+uY+I+XOyL9wvT35IqTq+BIeoLxm9K8JyfCNAkcHcCGAJg kVM0uljEyW0XQq1+rih9CpDsicuEPey0efZWtQVh0AQlsXkWNrKjSlI5hhXyKZ4DYwAC n6lg8GjWo6CRj0Lqh7+t7PicbIawCoQ982hwG14AXBEvszyzp/60y/q5CigcINh+Xrub J8VSzeLHYrsmJjsGb/YMRBcrh7MBA+pBY8E3rkJG0rq0u+T3G/M8DLDhiSG9Fz5ajFcK SO60cB/Kb+v6o1Y/anDwHB8kSGSkzAGPTj+tTVzbjsGFpDpJoZYAPcwJdv0gOWZ0Nu2H HbWw== 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=UtezC0Jkv5pu9jw2uBFqaZbSmBAo1ptYXuNR2V30cIU=; b=tjcp3v9q96gG9qbVeGWX1yOB4FS0C9A8MnDYWDT2rRxil2jz4vVuuSol/UP7yqkkew /E00LeOQVBYoOaC9s0tt4M+1YS3ykLRJ/tzyjKaKUIbIpiMNnMMkvwLrJC7vvvvSyTLx 59GNEHcNFyQSsOAxHnW5OR2pQ6XKXCq4OfJTANlBnTZtxBFd+ZdHqq1DNETI8M6naZKV UqRLKuFSah9zOHUVmeQEtBCbtjxabN0J56GVvCZfkWhZ+0UlxpCPcEqSVpQtIPGz5pfV xInqKHHVRcW3/eGOcIV6TJjYnw8+OrtNOqPtwt5mY0T5CgAf32fbqLxqD0vxloD9gP0o mBLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="NCp/cYfn"; 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 z6-v6si8457473plo.503.2018.09.14.20.43.03; Fri, 14 Sep 2018 20:43:18 -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="NCp/cYfn"; 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 S1728076AbeIOI7c (ORCPT + 99 others); Sat, 15 Sep 2018 04:59:32 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42249 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725907AbeIOI7c (ORCPT ); Sat, 15 Sep 2018 04:59:32 -0400 Received: by mail-pg1-f194.google.com with SMTP id y4-v6so5229391pgp.9; Fri, 14 Sep 2018 20:42:06 -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=UtezC0Jkv5pu9jw2uBFqaZbSmBAo1ptYXuNR2V30cIU=; b=NCp/cYfnqj0Xtw8iyaQH/aC3D2tWF3e33lgovtam+CilidPkogfsgnLzDvNR+rvcaO ZYDjm9cwK3vOSR5nQLFD88sJQo/cEu1HLmxHOpm2tZP0dfV7AvebaN5ncq321pEDcLyr n0dVMe+Te5/P/qt9bdnLz6RKFgNvEgwlofsmDR9c2pbCjS/2aui7pie08qRN7n1Y9cSs J46khZJrj+g0dtb7PWWsKmyul6lXRvdLMbUBkj4bt5bmTaKCMkyjwIbriuWuuaSfYhqI fvrze+L8el8pkpI1OsN1laJ6a6R0oAKu8R/Q0gSXe7945WfZFq31BlFNPyA3ubCvg+W9 u0vQ== 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=UtezC0Jkv5pu9jw2uBFqaZbSmBAo1ptYXuNR2V30cIU=; b=Cr3cclb0N5HJFx0Bmoo4E6vsr2LTeJwq5epG2fCLdLl9+ZcWnQzZT98EHpzrPlpxVd kcOpwbSpUWAeJfLnHl+3Z982eCoF6dpyO7QT/Th62Fj+lQoTYpsGktn3OsPRvpUhs/nx z4LWasrDYEGzYkgBUF7uxIRXVjMFx9l6i+WtIP9XFp1TvBjITi7B/Cz0X2rwafsA7SUF lyS9LaYMsIioH5+ACXcCK/GUMHiI6UNA4AHvMa0pAcXYn/kQYcJDpYEeKaIbyhejyu1w HC4wytfkANLQAh6PzeyWjWxVqZX8aUKev/5XcCfui32qyqd+guRNAKcWU4avkYnHbXNO 9UVg== X-Gm-Message-State: APzg51BabjacRUHGTwZJOT4jyWtAdRj8B8BI5S5nE53ptyrm+VbJw4tv E25vsgCq4fsl3EYh66eYpSA= X-Received: by 2002:a63:b95e:: with SMTP id v30-v6mr14091596pgo.221.1536982926717; Fri, 14 Sep 2018 20:42:06 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:947c:62c0:a59c:7c99]) by smtp.gmail.com with ESMTPSA id j15-v6sm9935066pfn.52.2018.09.14.20.42.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 20:42:06 -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 a possible sleep-in-atomic-context bug in lpfc_mbuf_alloc() Date: Sat, 15 Sep 2018 11:42:00 +0800 Message-Id: <20180915034200.6706-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 path (from bottom to top) in Linux-4.17 is: [FUNC] dma_pool_alloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_mem.c, 400: dma_pool_alloc in lpfc_mbuf_alloc drivers/scsi/lpfc/lpfc_els.c, 228: lpfc_mbuf_alloc in lpfc_prep_els_iocb drivers/scsi/lpfc/lpfc_els.c, 2010: lpfc_prep_els_iocb in lpfc_issue_els_plogi drivers/scsi/lpfc/lpfc_els.c, 4914: lpfc_issue_els_plogi in lpfc_els_disc_plogi drivers/scsi/lpfc/lpfc_els.c, 1486: lpfc_els_disc_plogi in lpfc_more_plogi drivers/scsi/lpfc/lpfc_els.c, 3123: lpfc_more_plogi in lpfc_cancel_retry_delay_tmo drivers/scsi/lpfc/lpfc_nportdisc.c, 279: lpfc_cancel_retry_delay_tmo in lpfc_els_abort drivers/scsi/lpfc/lpfc_nportdisc.c, 236: spin_lock_irq in lpfc_els_abort To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC. This bug is found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/scsi/lpfc/lpfc_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c index 9c22a2c93462..7eae5508bfa3 100644 --- a/drivers/scsi/lpfc/lpfc_mem.c +++ b/drivers/scsi/lpfc/lpfc_mem.c @@ -398,7 +398,7 @@ lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle) unsigned long iflags; void *ret; - ret = dma_pool_alloc(phba->lpfc_mbuf_pool, GFP_KERNEL, handle); + ret = dma_pool_alloc(phba->lpfc_mbuf_pool, GFP_ATOMIC, handle); spin_lock_irqsave(&phba->hbalock, iflags); if (!ret && (mem_flags & MEM_PRI) && pool->current_count) { -- 2.17.0