From patchwork Sun Apr 23 08:36:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 9694603 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 3095C601AE for ; Sun, 23 Apr 2017 08:40:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22FEB26E75 for ; Sun, 23 Apr 2017 08:40:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 172CF27E5A; Sun, 23 Apr 2017 08:40:52 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham 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 7B83626E75 for ; Sun, 23 Apr 2017 08:40:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1428006AbdDWIgx (ORCPT ); Sun, 23 Apr 2017 04:36:53 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:59388 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1427801AbdDWIgi (ORCPT ); Sun, 23 Apr 2017 04:36:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=nTL5tlPduJdc4sC1WbeIsJwbdt+vM3+9bmH8lFThkoc=; b=Tvk0YAeIGRJXEXS/UFW7HF9p0 Xkceua37Wj/ScNs4c5Pn10wqYpaYdCfsgcf7bmNRwDxbksccJe2+aHbXX0+jQPxs8ymV2AxKwoAhT rL5VOMjYbca3Oa6oITcivSfJyL6FOkOiLVQUHHBpDoin2QqIeuv12fRJOrfwpAk8snPly/uhwlBEk OozK8bUh1PW2v7xdwSAeHiuHC5KxDFNNzVkRGvSdl0/J3o1Zcl/aIbuRX8qZ4fvw+9bg5ist7zwIB 6Em/FVpvJx7tTuL7ddwTG3GwHFs7xH6S0SfJ8/VO6DZKu09zf+F4W8+hHbt05W0gWe5idUegMbXgS d3OmbhgOg==; Received: from hch by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1d2D0V-0002ZI-NF; Sun, 23 Apr 2017 08:36:35 +0000 Date: Sun, 23 Apr 2017 01:36:35 -0700 From: Christoph Hellwig To: Arnd Bergmann Cc: "James E.J. Bottomley" , "Martin K. Petersen" , stable@vger.kernel.org, Johannes Berg , Quentin Lambert , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] scsi: pmcraid: fix lock imbalance in pmcraid_reset_reload() Message-ID: <20170423083635.GB30869@infradead.org> References: <20170420175549.3435196-1-arnd@arndb.de> <20170420175549.3435196-2-arnd@arndb.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170420175549.3435196-2-arnd@arndb.de> User-Agent: Mutt/1.8.0 (2017-02-23) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 On Thu, Apr 20, 2017 at 07:54:46PM +0200, Arnd Bergmann wrote: > sparse found a bug that has always been present since the driver > was merged: > > drivers/scsi/pmcraid.c:2353:12: warning: context imbalance in 'pmcraid_reset_reload' - different lock contexts for basic block > > This adds the missing unlock at the end of the function. I could > not figure out if this will happen in practice, but I could not > prove that it doesn't happen, so to be on the safe side, let's > backport this fix. > > Cc: stable@vger.kernel.org > Fixes: 89a368104150 ("[SCSI] pmcraid: PMC-Sierra MaxRAID driver to support 6Gb/s SAS RAID controller") > Signed-off-by: Arnd Bergmann > --- > drivers/scsi/pmcraid.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c > index 096c704ca39a..35087e94c2ad 100644 > --- a/drivers/scsi/pmcraid.c > +++ b/drivers/scsi/pmcraid.c > @@ -2411,8 +2411,11 @@ static int pmcraid_reset_reload( > scsi_unblock_requests(pinstance->host); > if (pinstance->ioa_state == target_state) > reset = 0; > + spin_lock_irqsave(pinstance->host->host_lock, lock_flags); > } > > + spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); > + This looks weird. Using a proper goto label to unwind seem like the best way to go, e.g. this patch: --- From 8c58854f345bd87789b68eba2b2f72d0cac952fa Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Sun, 23 Apr 2017 10:33:23 +0200 Subject: pmcraid: fix lock imbalance in pmcraid_reset_reload() sparse found a bug that has always been present since the driver was merged: drivers/scsi/pmcraid.c:2353:12: warning: context imbalance in 'pmcraid_reset_reload' - different lock contexts for basic block Fix this by using a common unlock goto label, and also reduce the indentation level in the function. Signed-off-by: Christoph Hellwig Reported-by: Arnd Bergmann --- drivers/scsi/pmcraid.c | 59 ++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c index 49e70a383afa..3cc858f45838 100644 --- a/drivers/scsi/pmcraid.c +++ b/drivers/scsi/pmcraid.c @@ -2373,46 +2373,43 @@ static int pmcraid_reset_reload( spin_lock_irqsave(pinstance->host->host_lock, lock_flags); if (pinstance->ioa_state == IOA_STATE_DEAD) { - spin_unlock_irqrestore(pinstance->host->host_lock, - lock_flags); pmcraid_info("reset_reload: IOA is dead\n"); - return reset; - } else if (pinstance->ioa_state == target_state) { + goto out_unlock; + } + + if (pinstance->ioa_state == target_state) { reset = 0; + goto out_unlock; } } - if (reset) { - pmcraid_info("reset_reload: proceeding with reset\n"); - scsi_block_requests(pinstance->host); - reset_cmd = pmcraid_get_free_cmd(pinstance); - - if (reset_cmd == NULL) { - pmcraid_err("no free cmnd for reset_reload\n"); - spin_unlock_irqrestore(pinstance->host->host_lock, - lock_flags); - return reset; - } + pmcraid_info("reset_reload: proceeding with reset\n"); + scsi_block_requests(pinstance->host); + reset_cmd = pmcraid_get_free_cmd(pinstance); + if (reset_cmd == NULL) { + pmcraid_err("no free cmnd for reset_reload\n"); + goto out_unlock; + } - if (shutdown_type == SHUTDOWN_NORMAL) - pinstance->ioa_bringdown = 1; + if (shutdown_type == SHUTDOWN_NORMAL) + pinstance->ioa_bringdown = 1; - pinstance->ioa_shutdown_type = shutdown_type; - pinstance->reset_cmd = reset_cmd; - pinstance->force_ioa_reset = reset; - pmcraid_info("reset_reload: initiating reset\n"); - pmcraid_ioa_reset(reset_cmd); - spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); - pmcraid_info("reset_reload: waiting for reset to complete\n"); - wait_event(pinstance->reset_wait_q, - !pinstance->ioa_reset_in_progress); + pinstance->ioa_shutdown_type = shutdown_type; + pinstance->reset_cmd = reset_cmd; + pinstance->force_ioa_reset = reset; + pmcraid_info("reset_reload: initiating reset\n"); + pmcraid_ioa_reset(reset_cmd); + spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); + pmcraid_info("reset_reload: waiting for reset to complete\n"); + wait_event(pinstance->reset_wait_q, + !pinstance->ioa_reset_in_progress); - pmcraid_info("reset_reload: reset is complete !!\n"); - scsi_unblock_requests(pinstance->host); - if (pinstance->ioa_state == target_state) - reset = 0; - } + pmcraid_info("reset_reload: reset is complete !!\n"); + scsi_unblock_requests(pinstance->host); + return pinstance->ioa_state != target_state; +out_unlock: + spin_unlock_irqrestore(pinstance->host->host_lock, lock_flags); return reset; }