lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 15 Sep 2023 08:56:49 +0200
From:   Neil Armstrong <neil.armstrong@...aro.org>
To:     John Ogness <john.ogness@...utronix.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc:     Jiri Slaby <jirislaby@...nel.org>, linux-serial@...r.kernel.org,
        Petr Mladek <pmladek@...e.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org, Kevin Hilman <khilman@...libre.com>,
        Jerome Brunet <jbrunet@...libre.com>,
        Martin Blumenstingl <martin.blumenstingl@...glemail.com>,
        Dmitry Rokosov <ddrokosov@...rdevices.ru>,
        Lucas Tanure <tanure@...ux.com>,
        Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
        linux-arm-kernel@...ts.infradead.org,
        linux-amlogic@...ts.infradead.org
Subject: Re: [PATCH tty v1 37/74] serial: meson: Use port lock wrappers

On 14/09/2023 20:37, John Ogness wrote:
> From: Thomas Gleixner <tglx@...utronix.de>
> 
> When a serial port is used for kernel console output, then all
> modifications to the UART registers which are done from other contexts,
> e.g. getty, termios, are interference points for the kernel console.
> 
> So far this has been ignored and the printk output is based on the
> principle of hope. The rework of the console infrastructure which aims to
> support threaded and atomic consoles, requires to mark sections which
> modify the UART registers as unsafe. This allows the atomic write function
> to make informed decisions and eventually to restore operational state. It
> also allows to prevent the regular UART code from modifying UART registers
> while printk output is in progress.
> 
> All modifications of UART registers are guarded by the UART port lock,
> which provides an obvious synchronization point with the console
> infrastructure.
> 
> To avoid adding this functionality to all UART drivers, wrap the
> spin_[un]lock*() invocations for uart_port::lock into helper functions
> which just contain the spin_[un]lock*() invocations for now. In a
> subsequent step these helpers will gain the console synchronization
> mechanisms.
> 
> Converted with coccinelle. No functional change.
> 
> Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
> ---
>   drivers/tty/serial/meson_uart.c | 30 +++++++++++++++---------------
>   1 file changed, 15 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
> index 790d910dafa5..45cc23e9e399 100644
> --- a/drivers/tty/serial/meson_uart.c
> +++ b/drivers/tty/serial/meson_uart.c
> @@ -129,14 +129,14 @@ static void meson_uart_shutdown(struct uart_port *port)
>   
>   	free_irq(port->irq, port);
>   
> -	spin_lock_irqsave(&port->lock, flags);
> +	uart_port_lock_irqsave(port, &flags);
>   
>   	val = readl(port->membase + AML_UART_CONTROL);
>   	val &= ~AML_UART_RX_EN;
>   	val &= ~(AML_UART_RX_INT_EN | AML_UART_TX_INT_EN);
>   	writel(val, port->membase + AML_UART_CONTROL);
>   
> -	spin_unlock_irqrestore(&port->lock, flags);
> +	uart_port_unlock_irqrestore(port, flags);
>   }
>   
>   static void meson_uart_start_tx(struct uart_port *port)
> @@ -238,7 +238,7 @@ static irqreturn_t meson_uart_interrupt(int irq, void *dev_id)
>   {
>   	struct uart_port *port = (struct uart_port *)dev_id;
>   
> -	spin_lock(&port->lock);
> +	uart_port_lock(port);
>   
>   	if (!(readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY))
>   		meson_receive_chars(port);
> @@ -248,7 +248,7 @@ static irqreturn_t meson_uart_interrupt(int irq, void *dev_id)
>   			meson_uart_start_tx(port);
>   	}
>   
> -	spin_unlock(&port->lock);
> +	uart_port_unlock(port);
>   
>   	return IRQ_HANDLED;
>   }
> @@ -284,7 +284,7 @@ static int meson_uart_startup(struct uart_port *port)
>   	u32 val;
>   	int ret = 0;
>   
> -	spin_lock_irqsave(&port->lock, flags);
> +	uart_port_lock_irqsave(port, &flags);
>   
>   	val = readl(port->membase + AML_UART_CONTROL);
>   	val |= AML_UART_CLEAR_ERR;
> @@ -301,7 +301,7 @@ static int meson_uart_startup(struct uart_port *port)
>   	val = (AML_UART_RECV_IRQ(1) | AML_UART_XMIT_IRQ(port->fifosize / 2));
>   	writel(val, port->membase + AML_UART_MISC);
>   
> -	spin_unlock_irqrestore(&port->lock, flags);
> +	uart_port_unlock_irqrestore(port, flags);
>   
>   	ret = request_irq(port->irq, meson_uart_interrupt, 0,
>   			  port->name, port);
> @@ -341,7 +341,7 @@ static void meson_uart_set_termios(struct uart_port *port,
>   	unsigned long flags;
>   	u32 val;
>   
> -	spin_lock_irqsave(&port->lock, flags);
> +	uart_port_lock_irqsave(port, &flags);
>   
>   	cflags = termios->c_cflag;
>   	iflags = termios->c_iflag;
> @@ -401,7 +401,7 @@ static void meson_uart_set_termios(struct uart_port *port,
>   					    AML_UART_FRAME_ERR;
>   
>   	uart_update_timeout(port, termios->c_cflag, baud);
> -	spin_unlock_irqrestore(&port->lock, flags);
> +	uart_port_unlock_irqrestore(port, flags);
>   }
>   
>   static int meson_uart_verify_port(struct uart_port *port,
> @@ -460,14 +460,14 @@ static int meson_uart_poll_get_char(struct uart_port *port)
>   	u32 c;
>   	unsigned long flags;
>   
> -	spin_lock_irqsave(&port->lock, flags);
> +	uart_port_lock_irqsave(port, &flags);
>   
>   	if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)
>   		c = NO_POLL_CHAR;
>   	else
>   		c = readl(port->membase + AML_UART_RFIFO);
>   
> -	spin_unlock_irqrestore(&port->lock, flags);
> +	uart_port_unlock_irqrestore(port, flags);
>   
>   	return c;
>   }
> @@ -478,7 +478,7 @@ static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c)
>   	u32 reg;
>   	int ret;
>   
> -	spin_lock_irqsave(&port->lock, flags);
> +	uart_port_lock_irqsave(port, &flags);
>   
>   	/* Wait until FIFO is empty or timeout */
>   	ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg,
> @@ -502,7 +502,7 @@ static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c)
>   		dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n");
>   
>   out:
> -	spin_unlock_irqrestore(&port->lock, flags);
> +	uart_port_unlock_irqrestore(port, flags);
>   }
>   
>   #endif /* CONFIG_CONSOLE_POLL */
> @@ -559,9 +559,9 @@ static void meson_serial_port_write(struct uart_port *port, const char *s,
>   	if (port->sysrq) {
>   		locked = 0;
>   	} else if (oops_in_progress) {
> -		locked = spin_trylock(&port->lock);
> +		locked = uart_port_trylock(port);
>   	} else {
> -		spin_lock(&port->lock);
> +		uart_port_lock(port);
>   		locked = 1;
>   	}
>   
> @@ -573,7 +573,7 @@ static void meson_serial_port_write(struct uart_port *port, const char *s,
>   	writel(val, port->membase + AML_UART_CONTROL);
>   
>   	if (locked)
> -		spin_unlock(&port->lock);
> +		uart_port_unlock(port);
>   	local_irq_restore(flags);
>   }
>   

Acked-by: Neil Armstrong <neil.armstrong@...aro.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ