Netdev List
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Shubham Antil <shubham@octane.security>
Cc: netdev@vger.kernel.org, oe-linux-nfc@lists.linux.dev,
	david@ixit.cz, gio@octane.security
Subject: Re: [PATCH net v8 3/4] nfc: nci: uart: quiesce callbacks during teardown
Date: Thu, 26 Nov 2026 12:40:26 +0000	[thread overview]
Message-ID: <20261126124026.GZ31322@horms.kernel.org> (raw)
In-Reply-To: <20261119040253.15986-4-shubham@octane.security>

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.


  reply	other threads:[~2026-11-26 12:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  4:02 [PATCH net v8 0/4] nfc: order NCI UART and firmware teardown Shubham Antil
2026-11-19  4:02 ` [PATCH net v8 1/4] nfc: nci: uart: serialize driver selection Shubham Antil
2026-11-19  4:02 ` [PATCH net v8 2/4] nfc: reject overlapping firmware downloads Shubham Antil
2026-11-19  4:02 ` [PATCH net v8 3/4] nfc: nci: uart: quiesce callbacks during teardown Shubham Antil
2026-11-26 12:40   ` Simon Horman [this message]
2026-11-19  4:02 ` [PATCH net v8 4/4] nfc: nfcmrvl: stop firmware work before unregistering Shubham Antil

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=20261126124026.GZ31322@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=david@ixit.cz \
    --cc=gio@octane.security \
    --cc=netdev@vger.kernel.org \
    --cc=oe-linux-nfc@lists.linux.dev \
    --cc=shubham@octane.security \
    /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