* [PATCH v2 0/2] Fix sparse warnings in scsi_debug
@ 2022-03-01 11:30 Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings Damien Le Moal
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Damien Le Moal @ 2022-03-01 11:30 UTC (permalink / raw)
To: linux-scsi, Martin K . Petersen; +Cc: Douglas Gilbert
A couple of patches to suppress sparse warnings in scsi_debug. No
functional changes.
Changes from v1:
* Added Acked-by tag to patch 1
* Fixed patch 2 (find_next_bit() call and break comment)
Damien Le Moal (2):
scsi: scsi_debug: silence sparse unexpected unlock warnings
scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll()
drivers/scsi/scsi_debug.c | 84 ++++++++++++++++++++++++---------------
1 file changed, 51 insertions(+), 33 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings
2022-03-01 11:30 [PATCH v2 0/2] Fix sparse warnings in scsi_debug Damien Le Moal
@ 2022-03-01 11:30 ` Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 2/2] scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll() Damien Le Moal
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2022-03-01 11:30 UTC (permalink / raw)
To: linux-scsi, Martin K . Petersen; +Cc: Douglas Gilbert
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 <damien.lemoal@opensource.wdc.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
---
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)
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll()
2022-03-01 11:30 [PATCH v2 0/2] Fix sparse warnings in scsi_debug Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings Damien Le Moal
@ 2022-03-01 11:30 ` Damien Le Moal
2022-03-09 3:31 ` [PATCH v2 0/2] Fix sparse warnings in scsi_debug Martin K. Petersen
2022-03-15 5:02 ` Martin K. Petersen
3 siblings, 0 replies; 5+ messages in thread
From: Damien Le Moal @ 2022-03-01 11:30 UTC (permalink / raw)
To: linux-scsi, Martin K . Petersen; +Cc: Douglas Gilbert
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 <damien.lemoal@opensource.wdc.com>
---
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;
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] Fix sparse warnings in scsi_debug
2022-03-01 11:30 [PATCH v2 0/2] Fix sparse warnings in scsi_debug Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 2/2] scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll() Damien Le Moal
@ 2022-03-09 3:31 ` Martin K. Petersen
2022-03-15 5:02 ` Martin K. Petersen
3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2022-03-09 3:31 UTC (permalink / raw)
To: Damien Le Moal; +Cc: linux-scsi, Martin K . Petersen, Douglas Gilbert
Damien,
> A couple of patches to suppress sparse warnings in scsi_debug. No
> functional changes.
Applied to 5.18/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/2] Fix sparse warnings in scsi_debug
2022-03-01 11:30 [PATCH v2 0/2] Fix sparse warnings in scsi_debug Damien Le Moal
` (2 preceding siblings ...)
2022-03-09 3:31 ` [PATCH v2 0/2] Fix sparse warnings in scsi_debug Martin K. Petersen
@ 2022-03-15 5:02 ` Martin K. Petersen
3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2022-03-15 5:02 UTC (permalink / raw)
To: Damien Le Moal, linux-scsi; +Cc: Martin K . Petersen, Douglas Gilbert
On Tue, 1 Mar 2022 20:30:07 +0900, Damien Le Moal wrote:
> A couple of patches to suppress sparse warnings in scsi_debug. No
> functional changes.
>
> Changes from v1:
> * Added Acked-by tag to patch 1
> * Fixed patch 2 (find_next_bit() call and break comment)
>
> [...]
Applied to 5.18/scsi-queue, thanks!
[1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings
https://git.kernel.org/mkp/scsi/c/e9c478014b60
[2/2] scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll()
https://git.kernel.org/mkp/scsi/c/3fd07aecb750
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-15 5:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-01 11:30 [PATCH v2 0/2] Fix sparse warnings in scsi_debug Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 1/2] scsi: scsi_debug: silence sparse unexpected unlock warnings Damien Le Moal
2022-03-01 11:30 ` [PATCH v2 2/2] scsi: scsi_debug: fix qc_lock use in sdebug_blk_mq_poll() Damien Le Moal
2022-03-09 3:31 ` [PATCH v2 0/2] Fix sparse warnings in scsi_debug Martin K. Petersen
2022-03-15 5:02 ` Martin K. Petersen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.