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: core: Fix the unit attention counter implementation

scsi_decide_disposition() may call scsi_check_sense().
scsi_decide_disposition() calls are not serialized. Hence, counter
updates by scsi_check_sense() must be serialized. Hence this patch that
makes the counters updated by scsi_check_sense() atomic.

Cc: Kai Mäkisara <Kai.Makisara@kolumbus.fi>
Fixes: a5d518cd4e3e ("scsi: core: Add counters for New Media and Power On/Reset UNIT ATTENTIONs")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Link: https://patch.msgid.link/20251014220244.3689508-1-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
d54c676d 35bc3c8e

+6 -8
+2 -2
drivers/scsi/scsi_error.c
··· 554 554 * happened, even if someone else gets the sense data. 555 555 */ 556 556 if (sshdr.asc == 0x28) 557 - scmd->device->ua_new_media_ctr++; 557 + atomic_inc(&sdev->ua_new_media_ctr); 558 558 else if (sshdr.asc == 0x29) 559 - scmd->device->ua_por_ctr++; 559 + atomic_inc(&sdev->ua_por_ctr); 560 560 } 561 561 562 562 if (scsi_sense_is_deferred(&sshdr))
+4 -6
include/scsi/scsi_device.h
··· 252 252 unsigned int queue_stopped; /* request queue is quiesced */ 253 253 bool offline_already; /* Device offline message logged */ 254 254 255 - unsigned int ua_new_media_ctr; /* Counter for New Media UNIT ATTENTIONs */ 256 - unsigned int ua_por_ctr; /* Counter for Power On / Reset UAs */ 255 + atomic_t ua_new_media_ctr; /* Counter for New Media UNIT ATTENTIONs */ 256 + atomic_t ua_por_ctr; /* Counter for Power On / Reset UAs */ 257 257 258 258 atomic_t disk_events_disable_depth; /* disable depth for disk events */ 259 259 ··· 693 693 } 694 694 695 695 /* Macros to access the UNIT ATTENTION counters */ 696 - #define scsi_get_ua_new_media_ctr(sdev) \ 697 - ((const unsigned int)(sdev->ua_new_media_ctr)) 698 - #define scsi_get_ua_por_ctr(sdev) \ 699 - ((const unsigned int)(sdev->ua_por_ctr)) 696 + #define scsi_get_ua_new_media_ctr(sdev) atomic_read(&sdev->ua_new_media_ctr) 697 + #define scsi_get_ua_por_ctr(sdev) atomic_read(&sdev->ua_por_ctr) 700 698 701 699 #define MODULE_ALIAS_SCSI_DEVICE(type) \ 702 700 MODULE_ALIAS("scsi:t-" __stringify(type) "*")