mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Petr Mladek" <pmladek@suse.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org, "Jiri Slaby" <jirislaby@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Tony Lindgren" <tony@atomide.com>,
	"Lukas Wunner" <lukas@wunner.de>,
	"Matthias Schiffer" <matthias.schiffer@ew.tq-group.com>,
	linux-serial@vger.kernel.org
Subject: [PATCH tty v1 5/8] serial: 8250: lock port for rx_dma() callback
Date: Thu, 25 May 2023 11:37:56 +0206	[thread overview]
Message-ID: <20230525093159.223817-6-john.ogness@linutronix.de> (raw)
In-Reply-To: <20230525093159.223817-1-john.ogness@linutronix.de>

The rx_dma() callback (omap_8250_rx_dma) accesses UART_IER. This
register is modified twice by each console write
(serial8250_console_write()) under the port lock. However, not
all calls to the rx_dma() callback are under the port lock.

Add the missing port locking around rx_dma() callback calls. Add
lockdep notation to the omap_8250_rx_dma().

Note that this is not fixing a real problem because:

1. Currently DMA is forced off for 8250_omap consoles.

2. The serial devices are resumed before console printing is enabled.

However, adding this locking allows for clean locking semantics
for the rx_dma() callback so that lockdep can be used to identify
possible problems in the future. It also simplifies synchronization
of UART_IER in general by not needing to rely on implementation
details such as 1 and 2.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/tty/serial/8250/8250_omap.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index c17d98161d5e..3cb9cfa62331 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -728,8 +728,11 @@ static int omap_8250_startup(struct uart_port *port)
 		priv->wer |= OMAP_UART_TX_WAKEUP_EN;
 	serial_out(up, UART_OMAP_WER, priv->wer);
 
-	if (up->dma && !(priv->habit & UART_HAS_EFR2))
+	if (up->dma && !(priv->habit & UART_HAS_EFR2)) {
+		spin_lock_irq(&port->lock);
 		up->dma->rx_dma(up);
+		spin_unlock_irq(&port->lock);
+	}
 
 	enable_irq(up->port.irq);
 
@@ -1003,6 +1006,9 @@ static int omap_8250_rx_dma(struct uart_8250_port *p)
 	unsigned long			flags;
 	u32				reg;
 
+	/* Port locked to synchronize UART_IER access against the console. */
+	lockdep_assert_held_once(&p->port.lock);
+
 	if (priv->rx_dma_broken)
 		return -EINVAL;
 
@@ -1736,8 +1742,11 @@ static int omap8250_runtime_resume(struct device *dev)
 	if (up && omap8250_lost_context(up))
 		omap8250_restore_regs(up);
 
-	if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2))
+	if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) {
+		spin_lock_irq(&up->port.lock);
 		omap_8250_rx_dma(up);
+		spin_unlock_irq(&up->port.lock);
+	}
 
 	priv->latency = priv->calc_latency;
 	schedule_work(&priv->qos_work);
-- 
2.30.2


  parent reply	other threads:[~2023-05-25  9:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-25  9:31 [PATCH tty v1 0/8] synchronize UART_IER access against console write John Ogness
2023-05-25  9:31 ` [PATCH tty v1 1/8] serial: 8250: lock port in startup() callbacks John Ogness
2023-05-25  9:31 ` [PATCH tty v1 2/8] serial: core: lock port for stop_rx() in uart_suspend_port() John Ogness
2023-05-25 17:47   ` Vijaya Krishna Nivarthi (Temp) (QUIC)
2023-05-25 20:37   ` Doug Anderson
2023-05-25  9:31 ` [PATCH tty v1 3/8] serial: 8250: lock port for stop_rx() in omap8250_irq() John Ogness
2023-05-26  9:00   ` Tony Lindgren
2023-05-25  9:31 ` [PATCH tty v1 4/8] serial: core: lock port for start_rx() in uart_resume_port() John Ogness
2023-05-25 16:07   ` Doug Anderson
2023-05-25 20:38     ` Doug Anderson
2023-05-26  8:09       ` John Ogness
2023-05-25  9:31 ` John Ogness [this message]
2023-05-25  9:31 ` [PATCH tty v1 6/8] serial: 8250: lock port for omap8250_restore_regs() John Ogness
2023-05-25  9:31 ` [PATCH tty v1 7/8] serial: 8250: lock port for UART_IER access in omap8250_irq() John Ogness
2023-05-26  9:01   ` Tony Lindgren
2023-05-25  9:31 ` [PATCH tty v1 8/8] serial: 8250: synchronize and annotate UART_IER access John Ogness

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=20230525093159.223817-6-john.ogness@linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=matthias.schiffer@ew.tq-group.com \
    --cc=pmladek@suse.com \
    --cc=tglx@linutronix.de \
    --cc=tony@atomide.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®