All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-scsi@vger.kernel.org
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	GR-QLogic-Storage-Upstream@marvell.com,
	Hannes Reinecke <hare@suse.de>, Javed Hasan <jhasan@marvell.com>,
	Saurav Kashyap <skashyap@marvell.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Davidlohr Bueso <dbueso@suse.de>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 4/4] scsi: bnx2fc: Avoid using get_cpu() in bnx2fc_cmd_alloc().
Date: Fri,  6 May 2022 12:57:58 +0200	[thread overview]
Message-ID: <20220506105758.283887-5-bigeasy@linutronix.de> (raw)
In-Reply-To: <20220506105758.283887-1-bigeasy@linutronix.de>

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(-)

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);
 
-- 
2.36.0


  parent reply	other threads:[~2022-05-06 10:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06 10:57 [PATCH 0/4] scsi: PREEMPT_RT related fixes Sebastian Andrzej Siewior
2022-05-06 10:57 ` [PATCH 1/4] scsi: fcoe: Add a local_lock to fcoe_percpu Sebastian Andrzej Siewior
2022-05-06 10:57 ` [PATCH 2/4] scsi: fcoe: Use per-CPU API to update per-CPU statistics Sebastian Andrzej Siewior
2022-05-10  0:48   ` Davidlohr Bueso
2022-05-06 10:57 ` [PATCH 3/4] scsi: libfc: Remove get_cpu() semantics in fc_exch_em_alloc() Sebastian Andrzej Siewior
2022-05-06 10:57 ` Sebastian Andrzej Siewior [this message]
2022-05-07  4:46   ` [PATCH 4/4] scsi: bnx2fc: Avoid using get_cpu() in bnx2fc_cmd_alloc() Davidlohr Bueso
2022-05-17  1:28 ` [PATCH 0/4] scsi: PREEMPT_RT related fixes Martin K. Petersen
2022-05-17  6:11   ` Sebastian Andrzej Siewior
2022-05-20  1:09 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220506105758.283887-5-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=dbueso@suse.de \
    --cc=hare@suse.de \
    --cc=jejb@linux.ibm.com \
    --cc=jhasan@marvell.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=skashyap@marvell.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.