Skip to content

Commit c91e140

Browse files
Ranjan Kumarmartinkpetersen
authored andcommitted
scsi: mpi3mr: Serialize admin queue BAR writes on 32-bit systems
On 32-bit systems, 64-bit BAR writes to admin queue registers are performed as two 32-bit writes. Without locking, this can cause partial writes when accessed concurrently. Updated per-queue spinlocks is used to serialize these writes and prevent race conditions. Fixes: 824a156 ("scsi: mpi3mr: Base driver code") Cc: [email protected] Signed-off-by: Ranjan Kumar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 6853885 commit c91e140

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

drivers/scsi/mpi3mr/mpi3mr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,8 @@ struct scmd_priv {
11371137
* @logdata_buf: Circular buffer to store log data entries
11381138
* @logdata_buf_idx: Index of entry in buffer to store
11391139
* @logdata_entry_sz: log data entry size
1140+
* @adm_req_q_bar_writeq_lock: Admin request queue lock
1141+
* @adm_reply_q_bar_writeq_lock: Admin reply queue lock
11401142
* @pend_large_data_sz: Counter to track pending large data
11411143
* @io_throttle_data_length: I/O size to track in 512b blocks
11421144
* @io_throttle_high: I/O size to start throttle in 512b blocks
@@ -1339,6 +1341,8 @@ struct mpi3mr_ioc {
13391341
u8 *logdata_buf;
13401342
u16 logdata_buf_idx;
13411343
u16 logdata_entry_sz;
1344+
spinlock_t adm_req_q_bar_writeq_lock;
1345+
spinlock_t adm_reply_q_bar_writeq_lock;
13421346

13431347
atomic_t pend_large_data_sz;
13441348
u32 io_throttle_data_length;

drivers/scsi/mpi3mr/mpi3mr_fw.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ module_param(poll_queues, int, 0444);
2323
MODULE_PARM_DESC(poll_queues, "Number of queues for io_uring poll mode. (Range 1 - 126)");
2424

2525
#if defined(writeq) && defined(CONFIG_64BIT)
26-
static inline void mpi3mr_writeq(__u64 b, void __iomem *addr)
26+
static inline void mpi3mr_writeq(__u64 b, void __iomem *addr,
27+
spinlock_t *write_queue_lock)
2728
{
2829
writeq(b, addr);
2930
}
3031
#else
31-
static inline void mpi3mr_writeq(__u64 b, void __iomem *addr)
32+
static inline void mpi3mr_writeq(__u64 b, void __iomem *addr,
33+
spinlock_t *write_queue_lock)
3234
{
3335
__u64 data_out = b;
36+
unsigned long flags;
3437

38+
spin_lock_irqsave(write_queue_lock, flags);
3539
writel((u32)(data_out), addr);
3640
writel((u32)(data_out >> 32), (addr + 4));
41+
spin_unlock_irqrestore(write_queue_lock, flags);
3742
}
3843
#endif
3944

@@ -2954,9 +2959,11 @@ static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
29542959
(mrioc->num_admin_req);
29552960
writel(num_admin_entries, &mrioc->sysif_regs->admin_queue_num_entries);
29562961
mpi3mr_writeq(mrioc->admin_req_dma,
2957-
&mrioc->sysif_regs->admin_request_queue_address);
2962+
&mrioc->sysif_regs->admin_request_queue_address,
2963+
&mrioc->adm_req_q_bar_writeq_lock);
29582964
mpi3mr_writeq(mrioc->admin_reply_dma,
2959-
&mrioc->sysif_regs->admin_reply_queue_address);
2965+
&mrioc->sysif_regs->admin_reply_queue_address,
2966+
&mrioc->adm_reply_q_bar_writeq_lock);
29602967
writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
29612968
writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
29622969
return retval;

drivers/scsi/mpi3mr/mpi3mr_os.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,6 +5365,8 @@ mpi3mr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
53655365
spin_lock_init(&mrioc->tgtdev_lock);
53665366
spin_lock_init(&mrioc->watchdog_lock);
53675367
spin_lock_init(&mrioc->chain_buf_lock);
5368+
spin_lock_init(&mrioc->adm_req_q_bar_writeq_lock);
5369+
spin_lock_init(&mrioc->adm_reply_q_bar_writeq_lock);
53685370
spin_lock_init(&mrioc->sas_node_lock);
53695371
spin_lock_init(&mrioc->trigger_lock);
53705372

0 commit comments

Comments
 (0)