Skip to content

Commit d6477ee

Browse files
Francisco Gutierrezmartinkpetersen
authored andcommitted
scsi: pm80xx: Fix race condition caused by static variables
Eliminate the use of static variables within the log pull implementation to resolve a race condition and prevent data gaps when pulling logs from multiple controllers in parallel, ensuring each operation is properly isolated. Signed-off-by: Francisco Gutierrez <frankramirez@google.com> Link: https://lore.kernel.org/r/20250723183543.1443301-1-frankramirez@google.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent e5e11f6 commit d6477ee

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

drivers/scsi/pm8001/pm8001_ctl.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,23 +534,25 @@ static ssize_t pm8001_ctl_iop_log_show(struct device *cdev,
534534
char *str = buf;
535535
u32 read_size =
536536
pm8001_ha->main_cfg_tbl.pm80xx_tbl.event_log_size / 1024;
537-
static u32 start, end, count;
538537
u32 max_read_times = 32;
539538
u32 max_count = (read_size * 1024) / (max_read_times * 4);
540539
u32 *temp = (u32 *)pm8001_ha->memoryMap.region[IOP].virt_ptr;
541540

542-
if ((count % max_count) == 0) {
543-
start = 0;
544-
end = max_read_times;
545-
count = 0;
541+
mutex_lock(&pm8001_ha->iop_log_lock);
542+
543+
if ((pm8001_ha->iop_log_count % max_count) == 0) {
544+
pm8001_ha->iop_log_start = 0;
545+
pm8001_ha->iop_log_end = max_read_times;
546+
pm8001_ha->iop_log_count = 0;
546547
} else {
547-
start = end;
548-
end = end + max_read_times;
548+
pm8001_ha->iop_log_start = pm8001_ha->iop_log_end;
549+
pm8001_ha->iop_log_end = pm8001_ha->iop_log_end + max_read_times;
549550
}
550551

551-
for (; start < end; start++)
552-
str += sprintf(str, "%08x ", *(temp+start));
553-
count++;
552+
for (; pm8001_ha->iop_log_start < pm8001_ha->iop_log_end; pm8001_ha->iop_log_start++)
553+
str += sprintf(str, "%08x ", *(temp+pm8001_ha->iop_log_start));
554+
pm8001_ha->iop_log_count++;
555+
mutex_unlock(&pm8001_ha->iop_log_lock);
554556
return str - buf;
555557
}
556558
static DEVICE_ATTR(iop_log, S_IRUGO, pm8001_ctl_iop_log_show, NULL);

drivers/scsi/pm8001/pm8001_init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ static struct pm8001_hba_info *pm8001_pci_alloc(struct pci_dev *pdev,
552552
pm8001_ha->id = pm8001_id++;
553553
pm8001_ha->logging_level = logging_level;
554554
pm8001_ha->non_fatal_count = 0;
555+
mutex_init(&pm8001_ha->iop_log_lock);
555556
if (link_rate >= 1 && link_rate <= 15)
556557
pm8001_ha->link_rate = (link_rate << 8);
557558
else {

drivers/scsi/pm8001/pm8001_sas.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ struct pm8001_hba_info {
547547
u32 ci_offset;
548548
u32 pi_offset;
549549
u32 max_memcnt;
550+
u32 iop_log_start;
551+
u32 iop_log_end;
552+
u32 iop_log_count;
553+
struct mutex iop_log_lock;
550554
};
551555

552556
struct pm8001_work {

0 commit comments

Comments
 (0)