Article View: linux.kernel.netdev
Article #23067Re: [PATCH net v8 3/4] nfc: nci: uart: quiesce callbacks during teardown
From: Simon Horman
Date: Thu, 26 Nov 2026 12:40
Date: Thu, 26 Nov 2026 12:40
103 lines
13201 bytes
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.
Technical Details
Message-ID:
<20261126124026.GZ31322@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372101-linux-kernel-netdev=dewy.ruReferences:
<20261119040253.15986-1-shubham@octane.security> <20261119040253.15986-4-shubham@octane.security>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372101-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v8 3/4] nfc: nci: uart: quiesce callbacks during teardown Date: Thu, 26 Nov 2026 12:40:26 +0000 Organization: Usenet Network Message-ID: <20261126124026.GZ31322@horms.kernel.org> References: <20261119040253.15986-1-shubham@octane.security> <20261119040253.15986-4-shubham@octane.security> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="465845"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:N6399VyPQ380r85EBlEwxh2iTck= sha256:j8Ip/apPchrb5TeR1EVBfLOELu5IsUu46ugTvJ404oc= sha1:dQcdgpzq/dNaX9oMq8sKfMAASTs= sha256:4ywIlBFH3aTJVuQcoLO0cYlOprbG5gEJqH+0DHNO08I= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id ED27A125EDA; Thu, 26 Nov 2026 15:40:51 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id loMjXLAD0uz8; Thu, 26 Nov 2026 15:40:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372101-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 88992125ED9; Thu, 26 Nov 2026 15:40:33 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id DEE513C28D; Thu, 26 Nov 2026 12:40:30 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795696830; b=0yC5U6fHbj0HV/WYzftPvxwUCEzoWIEFcM8V0RDspgj1fS9K7goTojppdmj1byqYAi9/ A/TZtLWhKinzuJUnKUeVQ5mZ8O79+Mv+yxTZwiKQUNCptWLBIa6rPFQsMqyDC5rUpez/5 0L59Svmog0IKY+eZkMws9fNRU5JnH6GNcq4CFlYAoDv6u8fVYA9YKw2gI6NZq6uRJKIaf UqtT+EEDLCDYbSXJHW06Vr8AODKfuHsmTRPTNhMZvReq90djpj19Uucr99pTcddfbqsbw k76/8PRDR5OF3VQ6MkxC5onKGAUf1XynvR2KhyMnuRovBlm9WWJPXf4AYDIlU42p05g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795696830; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=vB1GV/8tGNyQg/NxcqXtlLxd+LWTEmgxjMt7djdRTys=; b=v/FDf96PSXffoqEbJ5wp2esSyOO2PvibfQ0nz1iLOqzZ1SAcnHk2vNQOmMITeUWvPAbl zvkFN2J/2qTgnvA8qJ5gJvKIm2SDube69lTcJ9ORGrJ0nIjKInRU+skXcrC8Jfv06Hqp/ CgbDbnlnLa3iM5Yn45A91rJNqyMqsRL2Q9qWbTJaSruIMV2Crp83dec0ITbwD1MpViUan 5i7RTjy9n3klevEySU06C/AJaz5GGOHIf9vjxiHGbG31ceEz6+M3D66+d6Xi+hIEAXGqJ W62jRfmW8dckNktm/kCAUaaQXdcyH3v4Ro4DJ/xjst3rMPZxzIQMrueTC3Jrty2XHGA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U5cV6LKW; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B23DA606A330; Thu, 26 Nov 2026 12:40:30 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U5cV6LKW X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795696829; b=JQMvI6IrP+ucZfbLwCGStD2RK5+ECRdA3jklao+OauI5YjClHVPL8mw9lgSoYlTqpdK2 imQBs1vRQQu4An5QDs9wtSIguziYu0sDWAozqC9cHuV+uXG+fagQ+m8d9pGsmIu38mDd3 Mdlzvt2ZGq7oew0gxuvQnCIOug+FTXwax3s6Sw5mM5pByZqcMQc8H4w1jqOadFV0bwqHD 9w1gWl8z3QAuz8K1YoeXCKIXtJ9MEAi12fIisoJhIAz5dTlTOoyg81y2tuXD2EjF/d1/L z4ZLehsC1R6XKyXkrJe9wmJgBCP37yhOJsdqhPPdtTWIInBuy0lPqdfP9ck+14txbOw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795696829; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=vB1GV/8tGNyQg/NxcqXtlLxd+LWTEmgxjMt7djdRTys=; b=WOvveCLVB9V1wwNpYy/J4744oeqtlzv1LhZ212PDHr+dwaH9CPFUTv3Nh7/5e3LTTETM /LQ91iM8S++p9PLGQZxNtYoYrxhJF2nvQcN8QPl3dJOge0ogI6AxvjODVBVk8wChzhiou hsrVDx4uTYKSSZXEbXk8H4ZVZX9eE2Q6AdEABpFeSTLDp+IKt+hGXZDIIJUoTO6zPHxlu oTnD9fwTuPsFRkxpYbSOt7OsvCw1m6U29pe1gKjn7RkScudsOVSV4r4v/3hF8+EvbVY21 Z0RKVtrbzMEcaYbYw1plF1Z7HCmZJMP6WIKXCA336JI9+KfKmAPl+oSljpVEemoK2wA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U5cV6LKW; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3286606A31C; Thu, 26 Nov 2026 12:40:29 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4B151F000CA; Thu, 26 Nov 2026 12:40:28 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795696829; bh=vB1GV/8tGNyQg/NxcqXtlLxd+LWTEmgxjMt7djdRTys=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=U5cV6LKWcgZlxvIWRzedSIIMtpX0UPX8eo4cNa89pDcm+O+6+1z2904/FUVvaqKE/ dZUteQCpLUaoUAtxqC2G6ChYnzw54gY08cay27S4RD/l3uKhRUOzrcfOv9WYqC7gTG YWc+9O22Q1LGJyChT/IJ4Ve9KIkUnH4anl71ra5UEz6xaUVTvL9UkjlUibn3jI+WV/ UloQlyivqpW5v/ZOhRBJfehAm9cJlLr/q7vk0BooCSfDcy3fnTfTMl7H+z5j5g+LtP +R4nx4FJz79Xok/PFcBo6f4kGIxXutJCeYmw/IKAEgvYRHws8UwXDXbTCxRX6i0++3 olCdJN/SIXHPw== X-Cc: netdev@vger.kernel.org, oe-linux-nfc@lists.linux.dev, david@ixit.cz, gio@octane.security X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261119040253.15986-4-shubham@octane.security>