🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Simon Horman Thu, 26 Nov 2026 12:40
Re: [PATCH net v8 3/4] nfc: nci: uart: quiesce callbacks during teardown
#23067
Author: Simon Horman
Date: Thu, 26 Nov 2026 12:40
103 lines
13201 bytes
On Thu, Nov 19, 2026 at 09:32:52AM +0530, Shubham Antil wrote:
> The UART write worker can miss a wakeup while handing SENDING back to a
> producer.  Teardown also has no state which prevents a new wakeup from
> queuing work after the close path starts cancelling it.
> 
> The Marvell open path has a related publication window.  It registers the
> NCI device before publishing the UART back-pointers, so an early open can
> use unset transport state or lose the controller response.
> 
> Serialize transmit scheduling and the worker's final state transition.
> When a transmit burst is active, record a wakeup before consulting the
> shared queue.  A partial skb can temporarily be owned only by the worker,
> and an empty-queue test in that window would otherwise discard the sole tty
> wakeup.  Once quiescing starts, block new work and cancel the worker
> synchronously.  Track an active transmit burst across partial writes and
> worker restarts so each tx_start() has exactly one tx_done(), including
> when close interrupts the burst.  Protect tx_skb with the same lock as the
> transmit state.
> 
> Publish the Marvell UART back-pointers before NCI registration, but keep
> UART callbacks gated until nci_register_device() has initialized the core
> queues.  Add a core ready callback immediately before public registration
> so transport state is visible before an early device-open can submit its
> first reset.  Keep the generic ready publication after transport open as an
> idempotent fallback.  Gate receive parsing on an active firmware download,
> NCI_UP, or NCI_INIT.  Bytes rejected outside those states discard any
> partial parser state and still unthrottle the tty, so a later reset
> response cannot be spliced into an old frame and a throttled peer cannot
> remain asleep.
> 
> Before the close-time reset, close command admission and drain a response
> already owned by the NCI receive worker before cancelling command work.
> Make the response and command workers honor that closing gate, then reopen
> it only for the reset exchange and a driver's final close command.  Cancel
> commands after both synchronous stages so a signal cannot leave its skb for
> the next open.  This also preserves close callbacks which legitimately
> submit a final proprietary command.  A late response therefore cannot make
> an old command runnable after cancellation.
> 
> Ask the transport to finish complete queued frames and wait for both the
> UART queue and tty driver buffer with a bounded timeout.  Keep a partial
> frame intact while a reset exchange remains possible.  If framing cannot
> be preserved, skip the reset, stop the writer, flush the tty driver's
> output, and release the unsent data.  Leave that line-discipline instance
> poisoned so a later NCI open cannot append bytes; recovery requires closing
> and selecting the line discipline again.  Clear receive parser state after
> the transport flush and immediately before reset admission opens.  Retry a
> partial write from the bounded flush itself, so line-discipline close does
> not depend on a write-wakeup callback which its write lock prevents.
> 
> Keep tty->disc_data and receive admission valid while the transport close
> performs its reset exchange.  Stop generic callbacks afterward, halt the
> controller while its device-managed reset GPIO is still valid, and withdraw
> the UART back-pointers before releasing private state.  Apply the same
> barriers to the failed-open path and document the sleep, lifetime, and
> queue-ownership contracts of the lifecycle helpers.
> 
> Discovered during an AI-assisted source audit using OpenAI Codex,
> gpt-5.6-sol.  Patch development and test planning used the same assistant.
> Confirmed with repeated NCI UART registration, device-open, and hangup
> cycles using an unmodified kernel and a pty-backed user-space controller;
> no error injection was used.
> 
> With the fix applied, the final v8 registration/publication reproducer
> passed 5 cycles under KASAN, UBSAN, and lockdep, and 5 cycles under
> strict-mode KCSAN.  Lifecycle testing observed all four expected CORE_RESET
> commands in each of 5 cycles under both configurations.  No physical
> Marvell controller was available, and no in-tree selftest covers this UART
> path.
> 
> Fixes: 9961127d4bce ("NFC: nci: add generic uart support")
> Fixes: e097dc624f78 ("NFC: nfcmrvl: add UART driver")
> Signed-off-by: Shubham Antil <shubham@octane.security>
> ---
>  drivers/nfc/nfcmrvl/main.c    |  40 +++-
>  drivers/nfc/nfcmrvl/nfcmrvl.h |   4 +
>  drivers/nfc/nfcmrvl/uart.c    |  60 +++++-
>  include/net/nfc/nci_core.h    |  20 ++
>  net/nfc/core.c                |   7 +-
>  net/nfc/nci/core.c            |  73 +++++--
>  net/nfc/nci/rsp.c             |   3 +
>  net/nfc/nci/uart.c            | 347 +++++++++++++++++++++++++++++++---
>  8 files changed, 496 insertions(+), 58 deletions(-)

Hi Shubham,

This patch is large and complex.
It adds both core changes and a driver implementation of them.
Please consider splitting this up into smaller steps.

I have similar concerns about the complexity of patches 1/4 and 4/4.

And, less critically, patch 2/4 could be split into a patch
that adds READ/WRITE_ONCE annotations, followed by one that fixes
the bug described there.

Given the overall complexity here, you may wish to consider multiple
patch-sets; the bugs described seem independent of each other.

I suggest splitting things up because smaller patch-sets are easier to
advance than larger ones. And the current series seems too large to me,
even if split into smaller patches.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads