Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9281663pxu; Mon, 28 Dec 2020 11:17:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwq/G11sFT3unK7uai586pC5bIdXnX3bbttWGzHh32wcLC/ER0D5HlWGb1oSAhUNjuAOw2b X-Received: by 2002:a17:906:65a:: with SMTP id t26mr36115774ejb.394.1609183037132; Mon, 28 Dec 2020 11:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609183037; cv=none; d=google.com; s=arc-20160816; b=egbCmkDQ7MghwasEGbJiKTE4dZVrBVXcFUp23Ee+VtjLo6+9pJsCEXH5I2+LqmcqjC XVkUYljXjVGeFP6VPl0kLoc7oHai4GgdstgZ9scIKc4WgLmTpjK+opU1hvHpoeHDL9hc dcd5+QkfkEWGiuP+NGK78ZbtDpZniQ90mi/gcaFXrlBaQWA4q5hHrT9gI/ejQdbtFUOc 9QALOAfsvAl40dV8zUbgQYZ1MS9qtIgXuLkpuRQbBZNq+tSrBEOcGAaHe8ya8KjgVC6E asmnz16rCf6Nv0xmWh16pj+lSfKavrFN0hHjlPCm4t4m8WotpP6pImvQBH05eUAxmHXv ApGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rY/wRBVYbyz9JfxyXfLqP/yBDBpnSMoWNARJOi54+Vw=; b=iAEK1F9Vpdnsr7L5m7d4R9nDzsQmAhG9gvAm+H3TwXsP2afWQkb4NjTYfWymnC5J3Z Kj9ha1K7+E3WyIjONOFVerqAiD5M4lJQpXH7LthLso/Y9usxLah7iN04HNmqqOZX3Fv9 yukwbjcvycC20NVNGUgqArPt+5/hY1Jppd2N/BgL6Ga5Y+ZN6gbd+9nj3ShyMNsuibHb pxiHaNiDwKdVHsRT8XMKQiviN/2ktn1u+i4opsHuvnug6rZp08VnUrlZP4YmCkZYw/jN UQDzLA+IZmSdNemXcclP22XcILEXGyNUBDiuMxAQikOxjhPluozLw/5WjQoAnvx833Ry IjrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P9LvWyJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si20363398eja.450.2020.12.28.11.16.55; Mon, 28 Dec 2020 11:17:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P9LvWyJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405189AbgL1N5y (ORCPT + 99 others); Mon, 28 Dec 2020 08:57:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:59576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407413AbgL1N5w (ORCPT ); Mon, 28 Dec 2020 08:57:52 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8514420782; Mon, 28 Dec 2020 13:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609163832; bh=moODPkrfC++ildKLR07t2aUiMPnatOOn4vrPfX9GpZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9LvWyJnyaDmcGVIV2rWMwNQ2fF7RP0U9hJuM3j+aKV1eneh5BTTUvfjev6S25tSm teJCHFAJZPlG57HP2YZ06r1VZNokyxgHyLcTUT/zzGIB4A6aENhGfK8P0Zvxh6Vol/ Z4hNMLDa5R3v1TzIlkRLE4Dtwlkmkz5YDpzZRwO0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dick Kennedy , James Smart , "Martin K. Petersen" Subject: [PATCH 5.4 423/453] scsi: lpfc: Fix invalid sleeping context in lpfc_sli4_nvmet_alloc() Date: Mon, 28 Dec 2020 13:50:59 +0100 Message-Id: <20201228124957.575665697@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124937.240114599@linuxfoundation.org> References: <20201228124937.240114599@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Smart commit 62e3a931db60daf94fdb3159d685a5bc6ad4d0cf upstream. The following calltrace was seen: BUG: sleeping function called from invalid context at mm/slab.h:494 ... Call Trace: dump_stack+0x9a/0xf0 ___might_sleep.cold.63+0x13d/0x178 slab_pre_alloc_hook+0x6a/0x90 kmem_cache_alloc_trace+0x3a/0x2d0 lpfc_sli4_nvmet_alloc+0x4c/0x280 [lpfc] lpfc_post_rq_buffer+0x2e7/0xa60 [lpfc] lpfc_sli4_hba_setup+0x6b4c/0xa4b0 [lpfc] lpfc_pci_probe_one_s4.isra.15+0x14f8/0x2280 [lpfc] lpfc_pci_probe_one+0x260/0x2880 [lpfc] local_pci_probe+0xd4/0x180 work_for_cpu_fn+0x51/0xa0 process_one_work+0x8f0/0x17b0 worker_thread+0x536/0xb50 kthread+0x30c/0x3d0 ret_from_fork+0x3a/0x50 A prior patch introduced a spin_lock_irqsave(hbalock) in the lpfc_post_rq_buffer() routine. Call trace is seen as the hbalock is held with interrupts disabled during a GFP_KERNEL allocation in lpfc_sli4_nvmet_alloc(). Fix by reordering locking so that hbalock not held when calling sli4_nvmet_alloc() (aka rqb_buf_list()). Link: https://lore.kernel.org/r/20201020202719.54726-2-james.smart@broadcom.com Fixes: 411de511c694 ("scsi: lpfc: Fix RQ empty firmware trap") Cc: # v4.17+ Co-developed-by: Dick Kennedy Signed-off-by: Dick Kennedy Signed-off-by: James Smart Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/lpfc/lpfc_mem.c | 4 +--- drivers/scsi/lpfc/lpfc_sli.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) --- a/drivers/scsi/lpfc/lpfc_mem.c +++ b/drivers/scsi/lpfc/lpfc_mem.c @@ -593,8 +593,6 @@ lpfc_sli4_rb_free(struct lpfc_hba *phba, * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI * pool along a non-DMA-mapped container for it. * - * Notes: Not interrupt-safe. Must be called with no locks held. - * * Returns: * pointer to HBQ on success * NULL on failure @@ -604,7 +602,7 @@ lpfc_sli4_nvmet_alloc(struct lpfc_hba *p { struct rqb_dmabuf *dma_buf; - dma_buf = kzalloc(sizeof(struct rqb_dmabuf), GFP_KERNEL); + dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL); if (!dma_buf) return NULL; --- a/drivers/scsi/lpfc/lpfc_sli.c +++ b/drivers/scsi/lpfc/lpfc_sli.c @@ -7102,12 +7102,16 @@ lpfc_post_rq_buffer(struct lpfc_hba *phb struct rqb_dmabuf *rqb_buffer; LIST_HEAD(rqb_buf_list); - spin_lock_irqsave(&phba->hbalock, flags); rqbp = hrq->rqbp; for (i = 0; i < count; i++) { + spin_lock_irqsave(&phba->hbalock, flags); /* IF RQ is already full, don't bother */ - if (rqbp->buffer_count + i >= rqbp->entry_count - 1) + if (rqbp->buffer_count + i >= rqbp->entry_count - 1) { + spin_unlock_irqrestore(&phba->hbalock, flags); break; + } + spin_unlock_irqrestore(&phba->hbalock, flags); + rqb_buffer = rqbp->rqb_alloc_buffer(phba); if (!rqb_buffer) break; @@ -7116,6 +7120,8 @@ lpfc_post_rq_buffer(struct lpfc_hba *phb rqb_buffer->idx = idx; list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); } + + spin_lock_irqsave(&phba->hbalock, flags); while (!list_empty(&rqb_buf_list)) { list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, hbuf.list);