The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Jacques Nilo <jnilo@free.fr>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Jiri Slaby <jirislaby@kernel.org>,
	 linux-serial <linux-serial@vger.kernel.org>,
	 LKML <linux-kernel@vger.kernel.org>,
	Johan Hovold <johan@kernel.org>
Subject: Re: [PATCH 1/3] serial: core: introduce guard(uart_port_lock_sysrq_irqsave)
Date: Wed, 13 May 2026 15:01:44 +0300 (EEST)	[thread overview]
Message-ID: <3439217b-90b5-5d21-e777-d238b3ffc1a0@linux.intel.com> (raw)
In-Reply-To: <b65b5237542c1c1c694a20e9d8fd0e18434a82b9.1778592805.git.jnilo@free.fr>

On Tue, 12 May 2026, Jacques Nilo wrote:

> uart_handle_break() and uart_prepare_sysrq_char() (in
> include/linux/serial_core.h) capture a SysRq character into
> port->sysrq_ch while the port lock is held and rely on the unlock
> helper -- uart_unlock_and_check_sysrq_irqrestore() -- to dispatch the
> captured character to handle_sysrq() on scope exit.
> 
> The existing guard(uart_port_lock_irqsave) cannot be used by IRQ
> handlers that process RX, because its destructor calls plain
> uart_port_unlock_irqrestore() and silently drops port->sysrq_ch.
> 
> Add a dedicated guard variant whose destructor is the sysrq-aware

guard(...) (put the full form here already).

> unlock helper. Callers that may capture SysRq characters opt in by
> using guard(uart_port_lock_sysrq_irqsave); the existing

opt in by using -> must use

> uart_port_lock_irqsave guard keeps its current plain-unlock semantics

guard(uart_port_lock_irqsave)

> for the many callers that do not process RX.
> 
> The lock side is identical to uart_port_lock_irqsave -- only the
> unlock-time behaviour differs.

Move this to the previous paragraph after the first sentence.

> Naming mirrors
> uart_unlock_and_check_sysrq_irqrestore() (sysrq before irqsave/irqrestore).

I'd remove the sentence about the name, it's kind of obvious.

> The new macro is placed after the CONFIG_MAGIC_SYSRQ_SERIAL block so
> both definitions of uart_unlock_and_check_sysrq_irqrestore() (sysrq
> enabled and disabled) are visible at expansion time. When
> CONFIG_MAGIC_SYSRQ_SERIAL=n the destructor degenerates to plain
> uart_port_unlock_irqrestore(), so there is no overhead.
> 
> No functional change on its own; users are converted in the following
> patches.
> 

You should add Cc: stable here too as this is prerequisite for the other 
two patches (but no Fixes tag).

> Signed-off-by: Jacques Nilo <jnilo@free.fr>
> ---
>  include/linux/serial_core.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
> index 4f7bbdd90..4fa079dc9 100644
> --- a/include/linux/serial_core.h
> +++ b/include/linux/serial_core.h
> @@ -1286,6 +1286,19 @@ static inline void uart_unlock_and_check_sysrq_irqrestore(struct uart_port *port
>  }
>  #endif	/* CONFIG_MAGIC_SYSRQ_SERIAL */
>  
> +/*
> + * Variant of guard(uart_port_lock_irqsave) for IRQ handlers that may capture
> + * a SysRq character via uart_prepare_sysrq_char(). The destructor uses the
> + * sysrq-aware unlock helper so that a captured port->sysrq_ch is dispatched
> + * to handle_sysrq() on scope exit. The plain guard variant silently drops
> + * sysrq_ch and must not be used by callers that process RX.
> + */
> +DEFINE_LOCK_GUARD_1(uart_port_lock_sysrq_irqsave, struct uart_port,

I suppose the "check" in the name is kind of important detail so maybe it 
shouldn't be dropped from the guard name.

> +                    uart_port_lock_irqsave(_T->lock, &_T->flags),
> +                    uart_unlock_and_check_sysrq_irqrestore(_T->lock,
> +                                                           _T->flags),

This fits to one line.

> +                    unsigned long flags);
> +
>  /*
>   * We do the SysRQ and SAK checking like this...
>   */
> 

-- 
 i.


  reply	other threads:[~2026-05-13 12:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-12 12:38 [REPORT] serial: 8250: BREAK + SysRq dispatch silently broken since 8324a54f604d Jacques Nilo
2026-05-12 12:58 ` Ilpo Järvinen
2026-05-12 13:06   ` Jacques Nilo
2026-05-12 13:21     ` Ilpo Järvinen
2026-05-12 13:46 ` [PATCH 0/3] serial: 8250: fix BREAK+SysRq dispatch on guard()-locked IRQ handlers Jacques Nilo
2026-05-12 13:46   ` [PATCH 1/3] serial: core: introduce guard(uart_port_lock_sysrq_irqsave) Jacques Nilo
2026-05-13 12:01     ` Ilpo Järvinen [this message]
2026-05-13 12:10       ` Jacques Nilo
2026-05-13 12:21         ` Ilpo Järvinen
2026-05-12 13:46   ` [PATCH 2/3] serial: 8250: dispatch SysRq character in serial8250_handle_irq() Jacques Nilo
2026-05-13 11:49     ` Ilpo Järvinen
2026-05-12 13:46   ` [PATCH 3/3] serial: 8250_dw: dispatch SysRq character in dw8250_handle_irq() Jacques Nilo
2026-05-13 11:50     ` Ilpo Järvinen
2026-05-13 13:30   ` [PATCH v2 0/3] serial: 8250: fix BREAK+SysRq dispatch on guard()-locked IRQ handlers Jacques Nilo
2026-05-13 13:30     ` [PATCH v2 1/3] serial: core: introduce guard(uart_port_lock_check_sysrq_irqsave) Jacques Nilo
2026-05-13 13:35       ` Ilpo Järvinen
2026-05-13 13:30     ` [PATCH v2 2/3] serial: 8250: dispatch SysRq character in serial8250_handle_irq() Jacques Nilo
2026-05-13 13:30     ` [PATCH v2 3/3] serial: 8250_dw: dispatch SysRq character in dw8250_handle_irq() Jacques Nilo

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=3439217b-90b5-5d21-e777-d238b3ffc1a0@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=jnilo@free.fr \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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