From patchwork Tue Mar 1 11:30:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12764648 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E59F1C433EF for ; Tue, 1 Mar 2022 11:30:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232382AbiCALa7 (ORCPT ); Tue, 1 Mar 2022 06:30:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbiCALa4 (ORCPT ); Tue, 1 Mar 2022 06:30:56 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEA9546652 for ; Tue, 1 Mar 2022 03:30:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1646134216; x=1677670216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VtTuSOPkcV5UWYKU8irJVaL8BUf1V1/zpRv7QYQhw40=; b=io1rHvtxz7ILFi9NwRbSU0xN5CjKUuGKmzybL0hcDTIK9KQrfknZ6zOc xJsBcVAZvuhDU+VM7HpUq+iMYewzOBZhSPXZ/N136EKPVk/B7XOUaBikn kzeqIIwoVwzzC2Iq5d9wgDmEVnw/jqPn0wHnZXXQpptxYuxT+0syHljSD upoqdf30aWsxtKh/cRBXxPKgRtTbDdS4GnaPtPsmBQmp9EtZpCU7iiuSO 7+xVLNmWK3MyEDpzFVDXEtmArGYGBsLR/rrKz/erUst+7G0hgSpib3IqV OEgCXwf+Pq6SDZMAz25bHcohTq/G0BLMvIuGJaVl1chIFY9LWDK7PbIkJ g==; X-IronPort-AV: E=Sophos;i="5.90,145,1643644800"; d="scan'208";a="195162728" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Mar 2022 19:30:15 +0800 IronPort-SDR: DRbGksK7NZdXd+2ttLiU/XSEA3Nralizgr70egSWiTfyadY4VaQBrJSHPlpwib/q7O+grcIs/l OotUhZqbvSnSPKxSl+JSpcti5m8skvAwWdthaewvzS5j+/Og5aglXC5Lof/IjGoz+Zwe6HTbZu qzEAyhGVGo0rLRZeW5cJyS2yk54UDmFUPrswpKUQiqDQ4WU0YG16vE6shQWbLDwUYX7uq7Hl10 ou7KyvkpetNzremu5iW/vRtTarORetAHX7j7tij2nB2MnYRNo4udM41CwcB/mp6iGHyFtTv7a0 MlMNaHtJiKjfsKCHqdt5TR/c Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 03:02:42 -0800 IronPort-SDR: AzCfl2bCSSJj2/t2lRRz5doALSR6cKB3ImtXcTuY8+1ape1dEEzIypn5ElvAmPkbSYEYfC+74M qU4BJTqy1HovRsnECqmGfyIngRrtSXHeOUf2jStnYQXC3bTT7psA3JjNEFvOgILOONhwuwTgMk Lc3GvvwFxh6JZtr1BPq4cLmqZ99mR+FqQKc4J+81wMOgf/tbo3SMY7x/9YRRfkzQsYd7gLwKH7 jebMRBcjlHzTV8SJjZBHWmQZkMjqYN4PthwhxUdO0rHPQXC2pPgWdVjQvsc+YiAb1R60ApLb2M YX4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 03:30:15 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4K7FRB5Yr8z1SVnx for ; Tue, 1 Mar 2022 03:30:14 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1646134214; x=1648726215; bh=VtTuSOPkcV5UWYKU8i rJVaL8BUf1V1/zpRv7QYQhw40=; b=PwUURhTs+mad2nsn405f4e7TerkA4SCJbT 5YGbI7O/INnrCJ6w4IL7GFUTlMi4YnF1/7qUO+gTxcHiJxCioYwCVwh423knHVv1 tQerfPMx69HfeSBXsKXMkdfJeTazLUNoafhDeHWmzhxn2Qjmo1NtpZy74/I34sl+ mC2rtdDbqxshzo+erM/Ogjl2xLBH+jmDkmUVKS/okh7jy1XSQQmjcjUJL4aDVsKh 6m6alWPPysIbN81gXji+m9qrUGZWB0VmfCxY8cj8G41vMwF1ZT+UIZ3SYVDjSq+G FEJYhJ2hmOUbuUnukJI0hMBaRVaRy3qJvaTzuG13nN369GV6YCZg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 0E9nKTtqgh28 for ; Tue, 1 Mar 2022 03:30:14 -0800 (PST) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4K7FR965HTz1Rwrw; Tue, 1 Mar 2022 03:30:13 -0800 (PST) From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: Douglas Gilbert Subject: [PATCH v2 1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings Date: Tue, 1 Mar 2022 20:30:08 +0900 Message-Id: <20220301113009.595857-2-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220301113009.595857-1-damien.lemoal@opensource.wdc.com> References: <20220301113009.595857-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The return statement inside the sdeb_read_lock(), sdeb_read_unlock(), sdeb_write_lock() and sdeb_write_unlock() confuse sparse, leading to many warnings about unexpected unlocks in the resp_xxx() functions. Modify the lock/unlock functions using the __acquire() and __release() inline annotations for the sdebug_no_rwlock == true case to avoid these warnings. Signed-off-by: Damien Le Moal Acked-by: Douglas Gilbert --- drivers/scsi/scsi_debug.c | 68 +++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 0d25b30922ef..f4e97f2224b2 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3167,45 +3167,65 @@ static int prot_verify_read(struct scsi_cmnd *scp, sector_t start_sec, static inline void sdeb_read_lock(struct sdeb_store_info *sip) { - if (sdebug_no_rwlock) - return; - if (sip) - read_lock(&sip->macc_lck); - else - read_lock(&sdeb_fake_rw_lck); + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + read_lock(&sip->macc_lck); + else + read_lock(&sdeb_fake_rw_lck); + } } static inline void sdeb_read_unlock(struct sdeb_store_info *sip) { - if (sdebug_no_rwlock) - return; - if (sip) - read_unlock(&sip->macc_lck); - else - read_unlock(&sdeb_fake_rw_lck); + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + read_unlock(&sip->macc_lck); + else + read_unlock(&sdeb_fake_rw_lck); + } } static inline void sdeb_write_lock(struct sdeb_store_info *sip) { - if (sdebug_no_rwlock) - return; - if (sip) - write_lock(&sip->macc_lck); - else - write_lock(&sdeb_fake_rw_lck); + if (sdebug_no_rwlock) { + if (sip) + __acquire(&sip->macc_lck); + else + __acquire(&sdeb_fake_rw_lck); + } else { + if (sip) + write_lock(&sip->macc_lck); + else + write_lock(&sdeb_fake_rw_lck); + } } static inline void sdeb_write_unlock(struct sdeb_store_info *sip) { - if (sdebug_no_rwlock) - return; - if (sip) - write_unlock(&sip->macc_lck); - else - write_unlock(&sdeb_fake_rw_lck); + if (sdebug_no_rwlock) { + if (sip) + __release(&sip->macc_lck); + else + __release(&sdeb_fake_rw_lck); + } else { + if (sip) + write_unlock(&sip->macc_lck); + else + write_unlock(&sdeb_fake_rw_lck); + } } static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) From patchwork Tue Mar 1 11:30:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12764649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B00CDC433EF for ; Tue, 1 Mar 2022 11:30:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234517AbiCALbC (ORCPT ); Tue, 1 Mar 2022 06:31:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbiCALa5 (ORCPT ); Tue, 1 Mar 2022 06:30:57 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F02FD4617C for ; Tue, 1 Mar 2022 03:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1646134217; x=1677670217; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HQTJ3hFf5JF9NvHGCqug7VPmGgRxRZtmNGm+PZyOjyM=; b=RApAdM0ueDGrnCeX4aKCDWbmhiPJBpwJrGamUXCNQK0cWqm8h+owqJko eKXvrNTB0PayVON6G++emTBlJb9Rk4DcZ10pdXcUDHcgw/UrYpE5TeP33 gKdqEDTaQwhdxR/F+lbn4wWvlXBM5PU4CujdTawas3tlODPk7hJcGpxgW mh9JCSM4h3VUpElItYCnYbi7GWmmBIpjQ/pjh8PLJSA2yA7JHHnyXr3ti 3wa0nynC0PxjVdR9KjPzfWEpEYDrx83eqk7Mh/hg749leunDRQwoqlb5B CIBXTzIDNQefIWbmv+3uBb0op3H425/NQUCBXJmd942QVq1LVxS1fd/zJ A==; X-IronPort-AV: E=Sophos;i="5.90,145,1643644800"; d="scan'208";a="195162732" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Mar 2022 19:30:16 +0800 IronPort-SDR: 0n0rPiefaEcvh8x3x3X1JY6tHXqw32usNgdEEEyUOKHZFeCuy2lSZVq+RxkygJgdbWM5FtCbzK A8i0keAanDOxfMbcFz2InfeENm+ETecyxXQzVi6erATmeReFF8veclwmRzmfWj2YFiuLXw62qb rY870fhY43GnEQsnPZoG81F1OfXsO+i38qp3XkLT+LBjJRfSCYwCjajnTh9eURLHl9hMHeprME kwzXImyvFh4RTPtPguOoCe1daQ9yRdy4pkcdpIhfjsSFVg/sSw18SSMwGAIQhwDDAo1wRgd2lV GzVwsGFWS4c483//IWgY31cB Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 03:02:43 -0800 IronPort-SDR: TAxgC6ipGs+rUcM0fWLLmpZVzB4tZ/oHqohKaImvu4nvFnra2qcIfmFgcDrvvUYZkNCM57aLUo qHovw7qzL/YHQsH1y3ib+qdyU88F0nTwdwJoTW5Rc6oBT+FrNErqgv28xpKcjwKksXsrS0xbp3 EQwQiOBeH7KV1VbrG63UZVy7Eq4EJrIHeWdXdkaGVHZCCeNlZ1sS4S11Msw9zWKFxMKcW9TLAd dmA9k2He9FqR9AyZJs95+3mnq11VsJrXfUvQSbJqQ6xg382VLRjvJxDGx3HTff2tfQswdEfa2m b5w= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 03:30:16 -0800 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4K7FRC3tDrz1Rwrw for ; Tue, 1 Mar 2022 03:30:15 -0800 (PST) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1646134215; x=1648726216; bh=HQTJ3hFf5JF9NvHGCq ug7VPmGgRxRZtmNGm+PZyOjyM=; b=ggIC6GRIzVvr5Oy82an5EGgtgniZ4bxSX1 kRTVTDXYcptMtZO22LPJmr9li8ZBC3Se9bVUyQ3BdNO3K369KnA+GqASt9yDuxR/ /Jgb3n3Io3666GCzFYf5ByhFMsyAwWgLrs18TpdBRfrHZl/jkW1asTJNTVKV/o+j l86EZJcHl+kqXAR2U8UUvu9MlS7jJ7tBuNhx6dWB/yfGsnnH99eFCvzk1fuoVHcH cD8eIhXfDiBpLtJBplkDabn+xEr+4R1vzmnlkRj2x5P+owEH+w4YgE1zIVsgj0CS JRRRfGKGJuTol0KwLDqpRCbaR5zoU7r0qReEztqYskak0ppEvVcQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id wRAHQfWguUfd for ; Tue, 1 Mar 2022 03:30:15 -0800 (PST) Received: from washi.fujisawa.hgst.com (washi.fujisawa.hgst.com [10.149.53.254]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4K7FRB4nqnz1Rvlx; Tue, 1 Mar 2022 03:30:14 -0800 (PST) From: Damien Le Moal To: linux-scsi@vger.kernel.org, "Martin K . Petersen" Cc: Douglas Gilbert Subject: [PATCH v2 2/2] scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll() Date: Tue, 1 Mar 2022 20:30:09 +0900 Message-Id: <20220301113009.595857-3-damien.lemoal@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220301113009.595857-1-damien.lemoal@opensource.wdc.com> References: <20220301113009.595857-1-damien.lemoal@opensource.wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The use of the locked boolean variable to control locking and unlocking of the qc_lock spinlock of struct sdebug_queue confuses sparse, leading to a warning about an unexpected unlock. Simplify the qc_lock lock/unlock handling code of this function to avoid this warning by removing the locked boolean variable. This change also fixes unlocked access to the in_use_bm bitmap with the find_first_bit() function. Fixes: b05d4e481eff ("scsi: scsi_debug: Refine sdebug_blk_mq_poll()") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal --- drivers/scsi/scsi_debug.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index f4e97f2224b2..25fa8e93f5a8 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7509,7 +7509,6 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) { bool first; bool retiring = false; - bool locked = false; int num_entries = 0; unsigned int qc_idx = 0; unsigned long iflags; @@ -7525,11 +7524,9 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) if (qc_idx >= sdebug_max_queue) return 0; + spin_lock_irqsave(&sqp->qc_lock, iflags); + for (first = true; first || qc_idx + 1 < sdebug_max_queue; ) { - if (!locked) { - spin_lock_irqsave(&sqp->qc_lock, iflags); - locked = true; - } if (first) { first = false; if (!test_bit(qc_idx, sqp->in_use_bm)) @@ -7586,14 +7583,15 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) } WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE); spin_unlock_irqrestore(&sqp->qc_lock, iflags); - locked = false; scsi_done(scp); /* callback to mid level */ num_entries++; + spin_lock_irqsave(&sqp->qc_lock, iflags); if (find_first_bit(sqp->in_use_bm, sdebug_max_queue) >= sdebug_max_queue) - break; /* if no more then exit without retaking spinlock */ + break; } - if (locked) - spin_unlock_irqrestore(&sqp->qc_lock, iflags); + + spin_unlock_irqrestore(&sqp->qc_lock, iflags); + if (num_entries > 0) atomic_add(num_entries, &sdeb_mq_poll_count); return num_entries;