From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Raul E Rangel" <rrangel@chromium.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Tony Lindgren" <tony@atomide.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Richard Genoud" <richard.genoud@bootlin.com>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Jacky Huang" <ychuang3@nuvoton.com>,
"Shan-Chun Hung" <schung@nuvoton.com>,
"Pali Rohár" <pali@kernel.org>, "Frank Li" <Frank.Li@nxp.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"Maciej W. Rozycki" <macro@orcam.me.uk>,
"Timur Tabi" <timur@kernel.org>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v6 2/5] serial: serialize asynchronous write wakeups with the port lock
Date: Sun, 25 Oct 2026 17:14:06 +0200 [thread overview]
Message-ID: <at4cvnsjHndzY5o3@ashevche-desk.local> (raw)
In-Reply-To: <20261024-submit-serial-8250-dma-cancel-v1-v6-2-6f366591f566@gmail.com>
On Sat, Oct 24, 2026 at 02:52:27PM -0600, James Hilliard wrote:
> uart_write_wakeup() expects the UART port lock to be held. Several worker,
> DMA completion and interrupt paths call it without that lock, including
> indirect calls from uart_handle_cts_change() and the transmit helpers.
>
> Take the port lock around these notifications or their transmit helper.
> Keep sleeping SPI and regmap accesses outside the locked region, and keep
> the FSL LPUART completion lock held through its wakeup. Acquire the port
> lock after releasing private channel locks to preserve the ordering used
> by UART callbacks. In the MUX timer, publish available FIFO space under
> the port lock and keep the hardware FIFO-drain wait outside it.
>
> Use IRQ-safe locking in the Atmel RX and TX tasklets and SB1250 termios
> path, since their interrupt handlers now acquire the same port lock.
> Preserve the caller's interrupt state when releasing those locks.
>
> Serialize CLPS711x TX servicing and its interrupt-enable state with the
> port lock. Disable TX interrupts without waiting in stop_tx(), since a
> threaded handler may need that same lock. Have an already queued handler
> leave stopped output untouched, and drain it outside the lock during
> shutdown before the transmit FIFO can be released.
>
> SCCNXP handles interrupts under a controller lock which its UART callbacks
> acquire with the port lock already held. Collect the ports needing wakeups
> while servicing the controller, then release that lock before taking each
> port lock and rechecking the wakeup threshold. Removal drains the IRQ or
> timer before unregistering the ports.
>
> This serializes write notifications with port-locked serial-core state
> changes, allowing readiness and transmit-storage reservations to gate the
> notification without a check-versus-shutdown race.
...
> -static void sccnxp_handle_events(struct sccnxp_port *s)
> +static unsigned int sccnxp_handle_events(struct sccnxp_port *s)
> {
> + unsigned int wakeup = 0;
unsigned long
> int i;
> u8 isr;
> @@ -491,20 +491,43 @@ static void sccnxp_handle_events(struct sccnxp_port *s)
> for (i = 0; i < s->uart.nr; i++) {
> if (s->opened[i] && (isr & ISR_RXRDY(i)))
> sccnxp_handle_rx(&s->port[i]);
> - if (s->opened[i] && (isr & ISR_TXRDY(i)))
> - sccnxp_handle_tx(&s->port[i]);
> + if (s->opened[i] && (isr & ISR_TXRDY(i)) &&
> + sccnxp_handle_tx(&s->port[i]))
> + wakeup |= BIT(i);
> }
> } while (1);
> +
> + return wakeup;
> +}
> +
> +static void sccnxp_write_wakeup(struct sccnxp_port *s, unsigned int wakeup)
unsigned long
> +{
> + int i;
Why is 'i' signed?
> + /* UART callbacks take s->lock with the port lock already held. */
> + for (i = 0; i < s->uart.nr; i++) {
> + struct uart_port *port = &s->port[i];
> +
> + if (!(wakeup & BIT(i)))
> + continue;
NIH [1] for_each_set_bit()
> + scoped_guard(uart_port_lock_irqsave, port) {
> + if (kfifo_len(&port->state->port.xmit_fifo) < WAKEUP_CHARS)
> + uart_write_wakeup(port);
> + }
> + }
> }
NIH syndrome is one of the weakest points of AI, please, read and study
the code you are changing.
[1]: https://en.wikipedia.org/wiki/Not_invented_here
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-10-25 15:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 20:52 [PATCH v6 0/5] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-10-24 20:52 ` [PATCH v6 1/5] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-10-24 20:52 ` [PATCH v6 2/5] serial: serialize asynchronous write wakeups with the port lock James Hilliard
2026-10-25 15:14 ` Andy Shevchenko [this message]
2026-10-24 20:52 ` [PATCH v6 3/5] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-10-24 20:52 ` [PATCH v6 4/5] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-10-24 20:52 ` [PATCH v6 5/5] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-10-26 11:15 ` [PATCH v6 0/5] serial: 8250: serialize DMA cancellation with buffer reuse Ilpo Järvinen
[not found] ` <CAHQZ30AfcwMTXPpCgiWkhz1OFoxHJOqcVmur8Buz72M45Acuag@mail.gmail.com>
2026-10-26 17:10 ` James Hilliard
2026-10-26 18:05 ` Ilpo Järvinen
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=at4cvnsjHndzY5o3@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=Frank.Li@nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=bigeasy@linutronix.de \
--cc=claudiu.beznea@tuxon.dev \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=imx@lists.linux.dev \
--cc=james.hilliard1@gmail.com \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=macro@orcam.me.uk \
--cc=nicolas.ferre@microchip.com \
--cc=pali@kernel.org \
--cc=richard.genoud@bootlin.com \
--cc=rrangel@chromium.org \
--cc=s.hauer@pengutronix.de \
--cc=schung@nuvoton.com \
--cc=timur@kernel.org \
--cc=tony@atomide.com \
--cc=ychuang3@nuvoton.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