mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>,
	"Peter Ujfalusi" <peter.ujfalusi@ti.com>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Patrice Chotard" <patrice.chotard@foss.st.com>,
	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 v12 5/8] serial: core: allow drivers to reserve flushed transmit storage
Date: Thu, 12 Nov 2026 18:13:49 +0200	[thread overview]
Message-ID: <avXlve7ROG9jb6AH@ashevche-desk.local> (raw)
In-Reply-To: <20261111-submit-serial-8250-dma-cancel-v1-v12-5-9e3456bc2555@gmail.com>

On Wed, Nov 11, 2026 at 03:16:30PM -0700, James Hilliard wrote:
> uart_flush_buffer() resets the transmit FIFO before calling the driver's
> flush callback. An asynchronous DMA transfer can still access that storage
> after the callback returns, while a new write can immediately reuse it.
> 
> Add uart_xmit_block() and uart_xmit_unblock() so a driver can reserve the
> flushed storage until its transfer and completion callbacks have retired.
> Serialize the reservation with FIFO producers using the port lock.
> 
> While the storage is reserved, write_room() reports no space and write()
> and put_char() accept no data. Defer write-ready notifications until the
> reservation is released, preserving one-shot TTY wakeups. Keep the flush's
> write-ready notification under the port lock so it cannot race another
> reservation.
> 
> Wake tty->write_wait after flushing even when writes remain blocked.
> tty_wait_until_sent() waits for the logical FIFO to empty, independently
> of whether its storage can be reused. Notify these drain waiters without
> invoking the line discipline's write_wakeup() callback, so a reservation
> does not prevent a completed logical flush from waking a drain waiter or
> consume a one-shot write-ready notification prematurely.
> 
> Suppress ordinary TX starts while the FIFO storage is blocked. Preserve
> high-priority flow-control characters, which use separate storage.
> Releasing the reservation wakes writers through the existing TTY wakeup
> path. This preserves immediate logical flushing while applying write
> backpressure until the storage is reusable.
> 
> Track port readiness separately from DMA ownership. Retirement releases the
> reservation even during startup or shutdown, while writes and wakeups stay
> gated until successful startup or resume. Reopening or restarting a port
> wakes deferred writers with either a new or retained FIFO. Restart queued
> output when reusing a FIFO after suspension. Keep its write-ready
> notification pending until the retained output drains below the normal
> wakeup threshold. Share that threshold check with generic 8250 and OMAP
> TX DMA completion through uart_write_wakeup_if_needed().
> 
> Publish resume readiness under the same port lock as the TX restart,
> without clearing any reservation. A concurrent flush can then reserve a
> new transfer without resume releasing its storage prematurely.
> 
> Assert the port-lock requirement at uart_write_wakeup(), alongside the
> reservation helpers, so callers cannot inspect readiness or release a
> one-shot notification concurrently with a reservation change.

...

>  void uart_write_wakeup(struct uart_port *port);

> +void uart_xmit_block(struct uart_port *port);
> +void uart_xmit_unblock(struct uart_port *port);

These are not used in the below helper, so, move them after it, with that
the uart_xmit_*() and uart_write_*() will be grouped.

> +/**
> + * uart_write_wakeup_if_needed - notify writers when queued output is low
> + * @port: port to be processed
> + *
> + * Keep one-shot write-wakeup notifications pending until fewer than
> + * %WAKEUP_CHARS remain in the transmit FIFO. This also applies to output
> + * retained across suspend and resume.
> + *
> + * Context: @port->lock held.
> + */
> +static inline void uart_write_wakeup_if_needed(struct uart_port *port)
> +{
> +	if (kfifo_len(&port->state->port.xmit_fifo) < WAKEUP_CHARS)
> +		uart_write_wakeup(port);
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-11-12 16:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 22:16 [PATCH v12 0/8] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-11-11 22:16 ` [PATCH v12 1/8] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-11-11 22:16 ` [PATCH v12 2/8] serial: serialize asynchronous write wakeups with the port lock James Hilliard
2026-11-12 16:11   ` Andy Shevchenko
2026-11-11 22:16 ` [PATCH v12 3/8] serial: 8250_omap: serialize RX DMA completion and flushing James Hilliard
2026-11-11 22:16 ` [PATCH v12 4/8] serial: 8250_omap: quiesce DMA IRQ handling before shutdown James Hilliard
2026-11-11 22:16 ` [PATCH v12 5/8] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-11-12 16:13   ` Andy Shevchenko [this message]
2026-11-11 22:16 ` [PATCH v12 6/8] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-11-11 22:16 ` [PATCH v12 7/8] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-11-12 16:25   ` Andy Shevchenko
2026-11-11 22:16 ` [PATCH v12 8/8] serial: 8250: retain DMA resources when termination fails James Hilliard
2026-11-12 16:28   ` Andy Shevchenko

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=avXlve7ROG9jb6AH@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=patrice.chotard@foss.st.com \
    --cc=peter.ujfalusi@ti.com \
    --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=vigneshr@ti.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

all inboxes | Powered by JetHome®