Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: scsi_debug: Stop using READ/WRITE_ONCE() when accessing sdebug_defer.defer_t

Using READ/WRITE_ONCE() means that the read or write is not torn by the
compiler.

READ/WRITE_ONCE() is always used when accessing sdebug_defer.defer_t.

However, we also guard the access in a spinlock when accessing that
member, and spinlock already guarantees no tearing, so stop using
READ/WRITE_ONCE().

Signed-off-by: John Garry <john.g.garry@oracle.com>
Link: https://patch.msgid.link/20251113133645.2898748-3-john.g.garry@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

John Garry and committed by
Martin K. Petersen
559ae7a2 a743b120

+6 -6
+6 -6
drivers/scsi/scsi_debug.c
··· 6726 6726 { 6727 6727 struct sdebug_scsi_cmd *sdsc = scsi_cmd_priv(cmnd); 6728 6728 struct sdebug_defer *sd_dp = &sdsc->sd_dp; 6729 - enum sdeb_defer_type defer_t = READ_ONCE(sd_dp->defer_t); 6729 + enum sdeb_defer_type defer_t = sd_dp->defer_t; 6730 6730 6731 6731 lockdep_assert_held(&sdsc->lock); 6732 6732 ··· 7288 7288 if (polled) { 7289 7289 spin_lock_irqsave(&sdsc->lock, flags); 7290 7290 sd_dp->cmpl_ts = ktime_add(ns_to_ktime(ns_from_boot), kt); 7291 - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); 7291 + sd_dp->defer_t = SDEB_DEFER_POLL; 7292 7292 spin_unlock_irqrestore(&sdsc->lock, flags); 7293 7293 } else { 7294 7294 /* schedule the invocation of scsi_done() for a later time */ 7295 7295 spin_lock_irqsave(&sdsc->lock, flags); 7296 - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_HRT); 7296 + sd_dp->defer_t = SDEB_DEFER_HRT; 7297 7297 hrtimer_start(&sd_dp->hrt, kt, HRTIMER_MODE_REL_PINNED); 7298 7298 /* 7299 7299 * The completion handler will try to grab sqcp->lock, ··· 7317 7317 if (polled) { 7318 7318 spin_lock_irqsave(&sdsc->lock, flags); 7319 7319 sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot); 7320 - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_POLL); 7320 + sd_dp->defer_t = SDEB_DEFER_POLL; 7321 7321 spin_unlock_irqrestore(&sdsc->lock, flags); 7322 7322 } else { 7323 7323 spin_lock_irqsave(&sdsc->lock, flags); 7324 - WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_WQ); 7324 + sd_dp->defer_t = SDEB_DEFER_WQ; 7325 7325 schedule_work(&sd_dp->ew.work); 7326 7326 spin_unlock_irqrestore(&sdsc->lock, flags); 7327 7327 } ··· 9125 9125 9126 9126 spin_lock_irqsave(&sdsc->lock, flags); 9127 9127 sd_dp = &sdsc->sd_dp; 9128 - if (READ_ONCE(sd_dp->defer_t) != SDEB_DEFER_POLL) { 9128 + if (sd_dp->defer_t != SDEB_DEFER_POLL) { 9129 9129 spin_unlock_irqrestore(&sdsc->lock, flags); 9130 9130 return true; 9131 9131 }