From patchwork Wed May 31 01:19:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 9755663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7A634603F7 for ; Wed, 31 May 2017 01:17:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FCC4283F5 for ; Wed, 31 May 2017 01:17:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 649C52847A; Wed, 31 May 2017 01:17:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA63428474 for ; Wed, 31 May 2017 01:17:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751141AbdEaBRi (ORCPT ); Tue, 30 May 2017 21:17:38 -0400 Received: from m12-13.163.com ([220.181.12.13]:37161 "EHLO m12-13.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751109AbdEaBRh (ORCPT ); Tue, 30 May 2017 21:17:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=BujwCmWHiMDnf7sGCX aLPZhhjngdf/24spHij2E/VCY=; b=PpSY43rHSGwlLQugzsZH0hHNBf47vFUZKr 8LkrmtGwSNNidiF6nMwvoSqEI47psNW5ktPdatVTLnxHM4N8npoVLSb4bE7Wzjwu rEWPR4Ih9YvFuFB7ePaae+tTi4vy2fYWM8SUG4GCnXBnuYATVFrkjCEw92dbSrtC TZA+j0i28= Received: from bai-oslab.tsinghua.edu.cn (unknown [166.111.70.19]) by smtp9 (Coremail) with SMTP id DcCowAB3f0ufGS5ZMqdsHA--.15549S2; Wed, 31 May 2017 09:17:23 +0800 (CST) From: Jia-Ju Bai To: QLogic-Storage-Upstream@qlogic.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] [PATCH] qla4xxx: Fix a sleep-in-atomic bug Date: Wed, 31 May 2017 09:19:31 +0800 Message-Id: <1496193571-31682-1-git-send-email-baijiaju1990@163.com> X-Mailer: git-send-email 1.7.9.5 X-CM-TRANSID: DcCowAB3f0ufGS5ZMqdsHA--.15549S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ury7KF1fZr15KFyrZw1DKFg_yoW8Zry8pF WFq3s8Cr4UZryjgryDWF18ur13ua1jgrWUCw47G34DuFn8Aa42grnYyFy3CFWqgrZ2yFZ7 XFWkJFy3uFsrA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07Ub6pQUUUUU= X-Originating-IP: [166.111.70.19] X-CM-SenderInfo: xedlyx5dmximizq6il2tof0z/1tbiHgPoelSIVUze0wAAsH Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver may sleep under a write spin lock, the function call path is: qla4_82xx_wr_32 (acquire the lock) qla4_82xx_crb_win_lock schedule or cpu_relax To fixed it, the lock is released before "schedule" and "cpu_relax", and the lock is acquired again after "schedule" and "cpu_relax". Signed-off-by: Jia-Ju Bai --- drivers/scsi/qla4xxx/ql4_nx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c index e91abb3..1cf5f4a 100644 --- a/drivers/scsi/qla4xxx/ql4_nx.c +++ b/drivers/scsi/qla4xxx/ql4_nx.c @@ -386,7 +386,7 @@ if (rv == 1) { write_lock_irqsave(&ha->hw_lock, flags); - qla4_82xx_crb_win_lock(ha); + qla4_82xx_crb_win_lock(ha, flags); qla4_82xx_pci_set_crbwindow_2M(ha, &off); } @@ -410,7 +410,7 @@ uint32_t qla4_82xx_rd_32(struct scsi_qla_host *ha, ulong off) if (rv == 1) { write_lock_irqsave(&ha->hw_lock, flags); - qla4_82xx_crb_win_lock(ha); + qla4_82xx_crb_win_lock(ha, flags); qla4_82xx_pci_set_crbwindow_2M(ha, &off); } data = readl((void __iomem *)off); @@ -476,7 +476,7 @@ int qla4_82xx_md_wr_32(struct scsi_qla_host *ha, uint32_t off, uint32_t data) #define CRB_WIN_LOCK_TIMEOUT 100000000 -int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha) +int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha, unsigned long flags) { int i; int done = 0, timeout = 0; @@ -491,6 +491,7 @@ int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha) timeout++; + write_unlock_irqrestore(&ha->hw_lock, flags); /* Yield CPU */ if (!in_interrupt()) schedule(); @@ -498,6 +499,7 @@ int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha) for (i = 0; i < 20; i++) cpu_relax(); /*This a nop instr on i386*/ } + write_lock_irqsave(&ha->hw_lock, flags); } qla4_82xx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->func_num); return 0;