All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Saiz <benj.saiz@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: mkp@kernel.org, James.Bottomley@HansenPartnership.com,
	Sagar.Biradar@microchip.com, bvanassche@acm.org,
	thenzl@redhat.com, aacraid@microsemi.com,
	sashiko-reviews@lists.linux.dev
Subject: Re: [PATCH RFC] scsi: aacraid: free aborted management FIBs on late completion
Date: Tue, 24 Nov 2026 12:47:58 +0000	[thread overview]
Message-ID: <20261124124758.3485-1-benj.saiz@gmail.com> (raw)
In-Reply-To: <sashiko-outbox-231035@kernel.org>

Thanks for the review. Both findings are correct, so please do not
apply this RFC as is.

Before a v2, I would like to agree on the direction, because the fix
touches the ownership of abandoned FIBs in several callers and I can
only test one of them. The question is at the end; the findings
behind it come first.

I had the RFC and the surrounding code reviewed again, and checked
each item below against the v7.4-rc4 sources (file:line refer to
drivers/scsi/aacraid/ in v7.4-rc4).

Made worse by the RFC on controllers handled by aac_intr_normal()
(a second free, or a write to a FIB the interrupt handler may already
have freed and handed out again):

 1. aac_hba_send(): done = 2 is written outside event_lock
    (commsup.c:761-762), and done is never reset before delivery
    (only aac_fib_send() does it, commsup.c:561). This is the pattern
    commit cacb6dc3d7fe ("[SCSI] aacraid: fix File System going into
    read-only mode") removed from aac_fib_send(); commit 423400e64d37
    ("scsi: aacraid: Include HBA direct interface") reintroduced it.
    Dan Carpenter flagged this block in 2017:
    https://lore.kernel.org/all/20170213184101.GA4762@mwanda/
    Without the RFC, a stale done == 1 already leaks the FIB when the
    reply arrives before the unlocked write, as the review notes.

 2. aac_send_safw_bmic_cmd(): completes and frees the FIB
    unconditionally after -ERESTARTSYS (aachba.c:1736-1753). This was
    harmless while done == 2 turned both calls into no-ops. Commit
    8fb391827f57 ("scsi: aacraid: Create bmic submission function
    from bmic identify") added the -ERESTARTSYS to -ERESTART
    conversion, and commit 5480aa18375e ("scsi: aacraid: Change phy
    luns function to use common bmic function") dropped the
    -ERESTARTSYS check its old caller had.

 3. ioctl_send_fib() with a replaced hw_fib (size > max_fib_size):
    on -ERESTARTSYS the cleanup frees the coherent buffer and restores
    hw_fib_va/hw_fib_pa (commctrl.c:80-102 and 146-155). With the RFC
    that FIB may already be back on the free list.

 4. aac_get_adapter_info(): if both DMA mask settings fail, rcode =
    -ENOMEM overwrites the -ERESTARTSYS of GetBusInfo before the final
    cleanup, which then frees the FIB (aachba.c:2238-2248, 2306-2312).
    This needs both dma_set_mask() calls to fail, so it is unlikely.

Controllers whose replies go through aac_response_normal() (rx.c,
sa.c) already free abandoned FIBs unconditionally today
(dpcsup.c:126-132), so items 3 and 4 already apply there.

Pre-existing, independent of the RFC:

 5. fibptr->event_wait is initialised once (commsup.c:169) and never
    re-initialised. If the reply posts complete() while the waiter is
    leaving on a signal (done already 1), that completion is never
    consumed and may wake the next user of the FIB early. The same
    applies to the polled and sync_mode paths.

 6. Block layer tagged FIBs reach aac_fib_free() on error paths (for
    example aachba.c:2490-2507, 2598-2599, 2686-2687, and
    dpcsup.c:346-349), so the management free list does not only hold
    the 8 pool FIBs. My changelog was wrong on that point, and also
    in saying that cacb6dc3d7fe introduced done = 2: it moved the
    abort marking under event_lock.

 7. Buffers released while the controller may still use them: the
    BMIC buffer (dma_unmap_single(), aachba.c:1749, then freed by the
    callers), the wellness buffer (dma_free_coherent() right after
    the send, commsup.c:2207), and the replaced ioctl hw_fib (item 3).
    Raw SRB instead strands its SG buffers and leaves its DMA mappings
    unmapped (bugzilla 220504).

 8. Polled sends (wait < 0) that time out or see the adapter offline
    (commsup.c:640-662), and sync_mode on a signal
    (commsup.c:604-610), return after delivery without marking the
    FIB as abandoned, and their callers free it.

I see two directions:

 (a) An explicit, scoped ownership handover, for controllers handled
     by aac_intr_normal(). ioctl_send_fib(), on its plain path only
     (no replaced hw_fib), marks the FIB before delivery as handed
     over on abort, in a dedicated field rather than in fib->flags,
     which is updated outside the lock. aac_fib_alloc() clears the
     mark, and so does aac_fib_alloc_tag(), since tagged FIBs reach
     the free list (item 6). On a late reply, aac_intr_normal()
     decides under event_lock whether done == 2 and the FIB is
     marked, then completes and frees it once. The completion is
     re-initialised before each synchronous send. This fixes the leak
     I observed (plain FSACTL_SEND_FIB on a Series 6). Every other
     path keeps its current behaviour on these controllers: it leaks
     an abandoned FIB but never frees it twice. A FIB whose reply
     never arrives stays lost until an adapter reset, as today.

 (b) A series that first fixes each path above (aac_hba_send()
     locking and done reset; ownership in BMIC, GetBusInfo and the
     replaced ioctl hw_fib; buffer lifetime; items 5 and 8), then
     frees abandoned FIBs for every caller, in aac_intr_normal() as
     aac_response_normal() already does.

For reference, the Microchip out-of-tree driver 1.2.1-60001 frees the
FIB in both done == 2 branches of aac_intr_normal() and only returns
pool FIBs to the free list. It marks done = 2 under the lock when a
polled send times out. But it keeps the same aac_hba_send() and BMIC
patterns as mainline, and an unlocked done = 2 in aac_fib_send() too.

Testing: my only affected controller is an Adaptec 6805 in production.
I can observe the driver there with kprobes, but I cannot load a
modified driver on it. I have no hardware for the native HBA or SA
firmware paths.

Which direction would you accept? Sagar, could Microchip test the
native HBA and SA paths on Series 7/8 hardware if we go for (b)?

Unless someone prefers (b), I plan to send (a) as v2 in a week or
two, with the remaining items listed in the cover letter.

This analysis was done with the help of AI coding assistants (Claude,
and Codex for an independent review). I checked each item against the
v7.4-rc4 sources.

Benjamin

      reply	other threads:[~2026-11-24 12:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 11:04 [PATCH RFC] scsi: aacraid: free aborted management FIBs on late completion Benjamin Saiz
2026-11-24 11:18 ` sashiko-bot
2026-11-24 12:47   ` Benjamin Saiz [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=20261124124758.3485-1-benj.saiz@gmail.com \
    --to=benj.saiz@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=Sagar.Biradar@microchip.com \
    --cc=aacraid@microsemi.com \
    --cc=bvanassche@acm.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=thenzl@redhat.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 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.