Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jaidev Shastri" <jaidevshastri@vt.edu>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH 3/6] vt: keyboard: publish dead_key_next with release semantics
Date: Tue, 22 Sep 2026 01:39:22 +0000	[thread overview]
Message-ID: <20260922013922.B26191F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260921-mb-keyboard-v1-3-d170228b80c0@vt.edu>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] tty: vt: bogus memory barriers for dead_key_next under spinlock
- [Medium] tty: vt: flawed acquire semantics in k_unicode lockless logic
--

commit 8306184a36f96d0dec76dd629c6b568b695fecc2
Author: Jaidev Shastri <jaidevshastri@vt.edu>

vt: keyboard: publish dead_key_next with release semantics

fn_compose() arms the dead-key state in dead_key_next and k_unicode()
consumes it together with diacr.

> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index 6f3472cd4f24d..d7db5e226d7dc 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -618,7 +618,8 @@ static void fn_boot_it(struct vc_data *vc)
>  
>  static void fn_compose(struct vc_data *vc)
>  {
> -	dead_key_next = true;
> +	/* Pairs with the smp_load_acquire() in k_unicode(). */
> +	smp_store_release(&dead_key_next, true);
>  }

[Severity: Medium]
Are these memory barriers redundant here?

The dead_key_next flag is only accessed within fn_compose() and k_unicode().
Both of these functions are exclusively invoked as part of the keyboard event
handling path originating from kbd_keycode().

kbd_keycode() is called by kbd_event(), which wraps the entire execution block
with scoped_guard(spinlock, &kbd_event_lock). Since all accesses to
dead_key_next are strictly serialized by this spinlock, no concurrent access
across cores can occur, making the lockless memory barriers useless.

[ ... ]

> @@ -672,7 +673,8 @@ static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag)
>  	if (diacr)
>  		value = handle_diacr(vc, value);
>  
> -	if (dead_key_next) {
> +	/* Pairs with the smp_store_release() in fn_compose(). */
> +	if (smp_load_acquire(&dead_key_next)) {
>  		dead_key_next = false;
>  		diacr = value;
>  		return;

[Severity: Medium]
If this were truly a lockless environment, does reading diacr before the
acquire barrier defeat the intended synchronization?

The payload diacr is read prior to the smp_load_acquire(&dead_key_next)
barrier, meaning it is fetched outside the intended synchronization domain,
which could allow stale reads.

Additionally, dead_key_next is reset to false using a plain store inside the
block. In a concurrent setting, consuming a shared flag requires an atomic
operation (like xchg()) to avoid a read-modify-write data race where multiple
threads could read true and simultaneously clobber diacr.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921-mb-keyboard-v1-0-d170228b80c0@vt.edu?part=3

  reply	other threads:[~2026-09-22  1:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  1:28 [PATCH 0/6] vt: keyboard: make the kbd_event_lock ordering explicit Jaidev Shastri via B4 Relay
2026-09-22  1:28 ` [PATCH 1/6] vt: keyboard: publish shift_state with release semantics Jaidev Shastri via B4 Relay
2026-09-22  1:38   ` sashiko-bot
2026-09-23 12:51   ` Greg Kroah-Hartman
2026-09-22  1:28 ` [PATCH 2/6] vt: keyboard: publish npadch_value " Jaidev Shastri via B4 Relay
2026-09-22  1:39   ` sashiko-bot
2026-09-22  1:28 ` [PATCH 3/6] vt: keyboard: publish dead_key_next " Jaidev Shastri via B4 Relay
2026-09-22  1:39   ` sashiko-bot [this message]
2026-09-22  1:28 ` [PATCH 4/6] vt: keyboard: publish accent_table_size " Jaidev Shastri via B4 Relay
2026-09-22  1:36   ` sashiko-bot
2026-09-22  1:28 ` [PATCH 5/6] vt: keyboard: recompute the shift state into locals before publishing it Jaidev Shastri via B4 Relay
2026-09-22  1:34   ` sashiko-bot
2026-09-22  1:28 ` [PATCH 6/6] vt: keyboard: publish the shift_down[] counters with release semantics Jaidev Shastri via B4 Relay
2026-09-22  1:42   ` sashiko-bot

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=20260922013922.B26191F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jaidevshastri@vt.edu \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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