mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Artem Dinaburg <artem@trailofbits.com>
To: Justin Tee <justin.tee@broadcom.com>, Paul Ely <paul.ely@broadcom.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	James Smart <James.Smart@Emulex.Com>,
	James Bottomley <James.Bottomley@SteelEye.com>,
	"Martin K . Petersen" <mkp@kernel.org>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Artem Dinaburg <artem@trailofbits.com>
Subject: [RFC PATCH 0/3] scsi: lpfc: Fix mailbox timeout ownership races
Date: Sat,  3 Oct 2026 23:41:08 -0400	[thread overview]
Message-ID: <cover.1790968549.git.artem@trailofbits.com> (raw)

Hi Justin and Paul,

While preparing a 6.6.y backport of
commit ede596b1434b ("scsi: lpfc: Handle mailbox timeouts in
lpfc_get_sfp_info"), I may have found two ownership problems in the
synchronous mailbox timeout handoff. I am attaching patches just in
case; I do not have the correct hardware (nor can I emulate it 
in QEMU) to validate the issue is actually reachable.

These patches were developed with AI assistance, and each carries the
required attribution trailer.

Patch 1 fixes lpfc_get_sfp_info_wait(). After MBX_TIMEOUT it no longer
reads the mailbox, which the late completion may already have freed, and
it cleans up after any other failed issue instead of leaking the mailbox
or reporting a zeroed A2 page as success. It is correct on its own with
the current wait/wake code.

Patch 2 fixes the generic wait/wake handoff. A completion that loaded the
wake callback before the waiter timed out finds no waiter and leaks the
mailbox. Because the wake flag is set before hbalock is taken, a waiter
that times out in that window can also return success and free the
mailbox before the callback reads it. The wake callback now decides
ownership under hbalock and runs the default completion itself when the
waiter is gone.

Patch 3 adds a hardware-independent KUnit suite for the wait/wake paths
and for lpfc_get_sfp_info_wait() itself. The issue failure cases fail
without patch 1 and the stale-callback cases fail without patch 2. The
tests check mailbox ownership only, not an SFP transaction or a timeout
on an adapter.

I built lpfc from x86_64 allmodconfig with CONFIG_SCSI_LPFC=m and
CONFIG_WERROR=y after each patch, and ran the KUnit suite in x86_64 QEMU
with and without KASAN. KASAN only covers the paths the suite runs. I do
not have LPFC hardware, so I have not exercised the SFP transaction on an
adapter.

Patch 2 changes the completion path for every lpfc_sli_issue_mbox_wait()
caller. I am not sure if this is the correct approach or if there should
be a different fix.

Thanks,
Artem Dinaburg

Artem Dinaburg (3):
  scsi: lpfc: Do not touch the SFP mailbox after a wait timeout
  scsi: lpfc: Resolve synchronous mailbox wait ownership under hbalock
  scsi: lpfc: Add KUnit tests for mailbox wait ownership

 drivers/scsi/Kconfig                 |  16 ++
 drivers/scsi/lpfc/.kunitconfig       |   9 +
 drivers/scsi/lpfc/Makefile           |   2 +
 drivers/scsi/lpfc/lpfc_els.c         |  12 +-
 drivers/scsi/lpfc/lpfc_sli.c         |  29 +--
 drivers/scsi/lpfc/tests/mbox_kunit.c | 362 +++++++++++++++++++++++++++
 6 files changed, 410 insertions(+), 20 deletions(-)
 create mode 100644 drivers/scsi/lpfc/.kunitconfig
 create mode 100644 drivers/scsi/lpfc/tests/mbox_kunit.c


base-commit: 5e0f8396d4805a3e7f753fa58c8c55f1f3cc2160
-- 
2.43.0

             reply	other threads:[~2026-10-04  3:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04  3:41 Artem Dinaburg [this message]
2026-10-04  3:41 ` [RFC PATCH 1/3] scsi: lpfc: Do not touch the SFP mailbox after a wait timeout Artem Dinaburg
2026-10-04  3:41 ` [RFC PATCH 2/3] scsi: lpfc: Resolve synchronous mailbox wait ownership under hbalock Artem Dinaburg
2026-10-04  3:41 ` [RFC PATCH 3/3] scsi: lpfc: Add KUnit tests for mailbox wait ownership Artem Dinaburg

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=cover.1790968549.git.artem@trailofbits.com \
    --to=artem@trailofbits.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=James.Bottomley@SteelEye.com \
    --cc=James.Smart@Emulex.Com \
    --cc=justin.tee@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=paul.ely@broadcom.com \
    /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

all inboxes | Powered by JetHome®