Message ID | 20220506105758.283887-5-bigeasy@linutronix.de (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | scsi: PREEMPT_RT related fixes. | expand |
On Fri, 06 May 2022, Sebastian Andrzej Siewior wrote: >Using get_cpu() leads to disabling preemption and in this context it is >not possible to acquire the following spinlock_t on PREEMPT_RT because >it becomes a sleeping lock. > >Commit > 0ea5c27583e1c ("[SCSI] bnx2fc: common free list for cleanup commands") > >says that it is using get_cpu() as a fix in case the CPU is preempted. >While this might be true, the important part is that it is now using the >same CPU for locking and unlocking while previously it always relied on >smp_processor_id(). >The date structure itself is protected with a lock so it does not rely >on CPU-local access. > >Replace get_cpu() with raw_smp_processor_id() to obtain the current CPU >number which is used as an index for the per-CPU resource. > >Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c index 6a1fc35b832ae..b42a9accb8320 100644 --- a/drivers/scsi/bnx2fc/bnx2fc_io.c +++ b/drivers/scsi/bnx2fc/bnx2fc_io.c @@ -472,7 +472,7 @@ struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt) u32 free_sqes; u32 max_sqes; u16 xid; - int index = get_cpu(); + int index = raw_smp_processor_id(); max_sqes = BNX2FC_SCSI_MAX_SQES; /* @@ -485,7 +485,6 @@ struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt) (tgt->num_active_ios.counter >= max_sqes) || (free_sqes + max_sqes <= BNX2FC_SQ_WQES_MAX)) { spin_unlock_bh(&cmd_mgr->free_list_lock[index]); - put_cpu(); return NULL; } @@ -498,7 +497,6 @@ struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt) atomic_inc(&tgt->num_active_ios); atomic_dec(&tgt->free_sqes); spin_unlock_bh(&cmd_mgr->free_list_lock[index]); - put_cpu(); INIT_LIST_HEAD(&io_req->link);
Using get_cpu() leads to disabling preemption and in this context it is not possible to acquire the following spinlock_t on PREEMPT_RT because it becomes a sleeping lock. Commit 0ea5c27583e1c ("[SCSI] bnx2fc: common free list for cleanup commands") says that it is using get_cpu() as a fix in case the CPU is preempted. While this might be true, the important part is that it is now using the same CPU for locking and unlocking while previously it always relied on smp_processor_id(). The date structure itself is protected with a lock so it does not rely on CPU-local access. Replace get_cpu() with raw_smp_processor_id() to obtain the current CPU number which is used as an index for the per-CPU resource. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- drivers/scsi/bnx2fc/bnx2fc_io.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)