[PATCH v4 4/4] scsi: arcmsr: serialise the type B completion ring
From: Yehyeong Lee
Date: Fri Nov 13 2026 - 22:39:14 EST
Type B keeps its completion ring in shared memory and consumes it from
arcmsr_hbaB_postqueue_isr(), from arcmsr_hbaB_polling_ccbdone() by way of
arcmsr_abort(), and from arcmsr_done4abort_postqueue(). None takes
acb->doneq_lock, and all three read reg->doneq_index and
reg->done_qbuffer[] with no other synchronisation, so two can fetch the
same entry. arcmsr_abort() masks the outbound interrupts first, but that
only stops the next one; a handler already running on another CPU keeps
going and nothing waits for it. The interrupt side clears the slot and
advances the index only after arcmsr_drain_donequeue() has run, so a
polling loop inside that window reads the same index and the same entry,
and the startdone test both consult is a plain read: both can reach
arcmsr_ccb_complete(), which means two scsi_dma_unmap() calls, two
scsi_done() calls and the command on ccb_free_list twice. It needs no
misbehaving adapter, only a command timing out as it is completed.
A harness that plants one entry and runs the two consumers over it, on a
KASAN and lockdep kernel, has both take it in 5 of 5 runs and none in 5
runs with this patch. I have no arcmsr hardware.
Take acb->doneq_lock in all three, as types D, E and F already do:
across the drain in the interrupt handler and in the reset sweep, and
across the index-and-entry step only in the polling loop, which must not
hold it while it completes a command. Types A and C read completions
from a hardware queue port where each read pops a different entry, so
they are left alone.
Fixes: 1a4f550a09f8 ("[SCSI] arcmsr: 1.20.00.15: add SATA RAID plus other fixes")
Signed-off-by: Yehyeong Lee <yhlee@xxxxxxxxxxxxxxxxxx>
---
This touches the two lines patch 3 touches.
drivers/scsi/arcmsr/arcmsr_hba.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index d13bd0febb81ac..9b2a7053f1823f 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1552,8 +1552,11 @@ static void arcmsr_done4abort_postqueue(struct AdapterControlBlock *acb)
case ACB_ADAPTER_TYPE_B: {
struct MessageUnit_B *reg = acb->pmuB;
+ unsigned long flags;
+
/*clear all outbound posted Q*/
writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN, reg->iop2drv_doorbell); /* clear doorbell interrupt */
+ spin_lock_irqsave(&acb->doneq_lock, flags);
for (i = 0; i < ARCMSR_MAX_HBB_POSTQUEUE; i++) {
flag_ccb = reg->done_qbuffer[i];
if (flag_ccb != 0) {
@@ -1570,6 +1573,7 @@ static void arcmsr_done4abort_postqueue(struct AdapterControlBlock *acb)
}
reg->doneq_index = 0;
reg->postq_index = 0;
+ spin_unlock_irqrestore(&acb->doneq_lock, flags);
}
break;
case ACB_ADAPTER_TYPE_C: {
@@ -2566,8 +2570,9 @@ static void arcmsr_hbaB_postqueue_isr(struct AdapterControlBlock *acb)
struct ARCMSR_CDB *pARCMSR_CDB;
struct CommandControlBlock *pCCB;
bool error;
- unsigned long cdb_phy_addr;
+ unsigned long cdb_phy_addr, flags;
+ spin_lock_irqsave(&acb->doneq_lock, flags);
index = reg->doneq_index % ARCMSR_MAX_HBB_POSTQUEUE;
while ((flag_ccb = reg->done_qbuffer[index]) != 0) {
cdb_phy_addr = (flag_ccb << 5) & 0xffffffff;
@@ -2582,6 +2587,7 @@ static void arcmsr_hbaB_postqueue_isr(struct AdapterControlBlock *acb)
index %= ARCMSR_MAX_HBB_POSTQUEUE;
reg->doneq_index = index;
}
+ spin_unlock_irqrestore(&acb->doneq_lock, flags);
}
static void arcmsr_hbaC_postqueue_isr(struct AdapterControlBlock *acb)
@@ -3664,16 +3670,18 @@ static int arcmsr_hbaB_polling_ccbdone(struct AdapterControlBlock *acb,
uint32_t flag_ccb, poll_ccb_done = 0, poll_count = 0;
int index, rtn;
bool error;
- unsigned long ccb_cdb_phy;
+ unsigned long ccb_cdb_phy, flags;
polling_hbb_ccb_retry:
poll_count++;
/* clear doorbell interrupt */
writel(ARCMSR_DOORBELL_INT_CLEAR_PATTERN, reg->iop2drv_doorbell);
while(1){
+ spin_lock_irqsave(&acb->doneq_lock, flags);
index = reg->doneq_index % ARCMSR_MAX_HBB_POSTQUEUE;
flag_ccb = reg->done_qbuffer[index];
if (flag_ccb == 0) {
+ spin_unlock_irqrestore(&acb->doneq_lock, flags);
if (poll_ccb_done){
rtn = SUCCESS;
break;
@@ -3691,6 +3699,7 @@ static int arcmsr_hbaB_polling_ccbdone(struct AdapterControlBlock *acb,
/*if last index number set it to 0 */
index %= ARCMSR_MAX_HBB_POSTQUEUE;
reg->doneq_index = index;
+ spin_unlock_irqrestore(&acb->doneq_lock, flags);
/* check if command done with no error*/
ccb_cdb_phy = (flag_ccb << 5) & 0xffffffff;
if (acb->cdb_phyadd_hipart)
--
2.43.0