Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock
@ 2026-11-16  2:39 Changyul Lee
  2026-11-16  3:01 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Changyul Lee @ 2026-11-16  2:39 UTC (permalink / raw)
  To: Justin Tee, Paul Ely
  Cc: Martin K . Petersen, James E . J . Bottomley, Hannes Reinecke,
	Nigel Kirkland, linux-scsi, linux-kernel, Changyul Lee

lpfc_cmpl_ct_cmd_vmid() looks up the VMID entry for an RAPP_IDENT
response without vport->vmid_lock and takes the lock only after the
lookup. lpfc_vmid_get_appid() can meanwhile hash_del() another entry
from the same bucket under the lock. hash_del() clears the next pointer
of the removed node, so the walk stops early and misses the entry that
waits for the response. That entry keeps LPFC_VMID_REQ_REGISTER, and
the I/O of that VM is sent without a VMID tag from then on.

Take vmid_lock before the lookup, as lpfc_vmid_get_appid() does.

Fixes: 33c79741deaf ("scsi: lpfc: vmid: Introduce VMID in I/O path")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus SCSI_LPFC and W=1.

 drivers/scsi/lpfc/lpfc_ct.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index f709e5087577..af720ccdf1b6 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -3613,14 +3613,13 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 
 		hash = lpfc_vmid_hash_fn(app->obj.entity_id,
 					 app->obj.entity_id_len);
+		write_lock(&vport->vmid_lock);
 		vmp = lpfc_get_vmid_from_hashtable(vport, hash,
 						  app->obj.entity_id);
 		if (vmp) {
-			write_lock(&vport->vmid_lock);
 			vmp->un.app_id = be32_to_cpu(app->app_id);
 			vmp->flag |= LPFC_VMID_REGISTERED;
 			vmp->flag &= ~LPFC_VMID_REQ_REGISTER;
-			write_unlock(&vport->vmid_lock);
 			/* Set IN USE flag */
 			vport->vmid_flag |= LPFC_VMID_IN_USE;
 		} else {
@@ -3628,6 +3627,7 @@ lpfc_cmpl_ct_cmd_vmid(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
 					 "6901 No entry found %s hash %d\n",
 					 app->obj.entity_id, hash);
 		}
+		write_unlock(&vport->vmid_lock);
 		break;
 	case SLI_CTAS_DAPP_IDENT:
 		app = (struct app_id_object *)(DAPP_IDENT_OFFSET + data);

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16  3:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  2:39 [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock Changyul Lee
2026-11-16  3:01 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox