From: sashiko-bot@kernel.org
To: "Changyul Lee" <lcy8047@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: lpfc: Look up the VMID entry under vmid_lock
Date: Mon, 16 Nov 2026 03:01:02 +0000 [thread overview]
Message-ID: <sashiko-outbox-216096@kernel.org> (raw)
In-Reply-To: <20261116023939.588838-1-lcy8047@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] scsi: lpfc: inaccurate Fixes trailer for lpfc_cmpl_ct_cmd_vmid()
lock fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] scsi: lpfc: data race and list corruption in
lpfc_cmpl_ct_cmd_vmid() [1]
--
commit ace8e21fd4e560f69d845916087ba204329824c3
Author: Changyul Lee <lcy8047@gmail.com>
> scsi: lpfc: Look up the VMID entry under vmid_lock
>
> 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>
[Severity: Low]
33c79741deaf ("scsi: lpfc: vmid: Introduce VMID in I/O path") only touched
drivers/scsi/lpfc/lpfc_scsi.c. The unlocked lpfc_get_vmid_from_hashtable()
call in lpfc_cmpl_ct_cmd_vmid() was added by 742b0cf87a8f ("scsi: lpfc:
vmid: Implement CT commands for appid"), so should the Fixes tag be:
Fixes: 742b0cf87a8f ("scsi: lpfc: vmid: Implement CT commands for appid")
> diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
> index f709e50875770..af720ccdf1b6f 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);
[Severity: High]
This problem wasn't introduced by this patch, but the SLI_CTAS_DALLAPP_ID
branch right below in lpfc_cmpl_ct_cmd_vmid() causes a NULL pointer
dereference, list corruption, and a memory leak [1]:
drivers/scsi/lpfc/lpfc_ct.c:lpfc_cmpl_ct_cmd_vmid() {
...
case SLI_CTAS_DALLAPP_ID:
...
read_lock(&vport->vmid_lock);
for (i = 0; i < phba->cfg_max_vmid; i++) {
vmp = &vport->vmid[i];
if (vmp->flag != LPFC_VMID_SLOT_FREE)
memset(vmp, 0, sizeof(struct lpfc_vmid));
}
read_unlock(&vport->vmid_lock);
/* for all elements in the hash table */
if (!hash_empty(vport->hash_table))
hash_for_each(vport->hash_table, bucket, cur, hnode)
hash_del(&cur->hnode);
...
}
Can this crash when deregistering all app IDs? Zeroing vmp with memset()
while its hnode is still linked in vport->hash_table clears hnode.next and
hnode.pprev, so the subsequent hash_del(&cur->hnode) dereferences a NULL
pprev pointer. In addition, the loop mutates vport->vmid under read_lock()
instead of write_lock(), overwrites vmp->last_io_time without calling
free_percpu(), and walks vport->hash_table without holding vport->vmid_lock
or using hash_for_each_safe().
[1] https://sashiko.dev/#/bug/linux-b856b4ae-5c8f-4fb3-812c-1d152bd8d42f
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116023939.588838-1-lcy8047@gmail.com?part=1
prev parent reply other threads:[~2026-11-16 3:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=sashiko-outbox-216096@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lcy8047@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox