Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Jaidev Shastri via B4 Relay <devnull+jaidevshastri.vt.edu@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Jiri Slaby <jirislaby@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	 Jaidev Shastri <jaidevshastri@vt.edu>
Subject: [PATCH 4/6] vt: keyboard: publish accent_table_size with release semantics
Date: Mon, 21 Sep 2026 21:28:17 -0400	[thread overview]
Message-ID: <20260921-mb-keyboard-v1-4-d170228b80c0@vt.edu> (raw)
In-Reply-To: <20260921-mb-keyboard-v1-0-d170228b80c0@vt.edu>

From: Jaidev Shastri <jaidevshastri@vt.edu>

vt_do_kdskbdiacr() and vt_do_kdskbdiacruc() rewrite accent_table[] and
accent_table_size. handle_diacr() reads the size and then walks the
table.

vt_do_kdskbdiacr() sets the size before it converts the entries, so the
size covers entries that have not been written yet. Set it after the
loop in both paths and publish it with smp_store_release(); read it once
with smp_load_acquire() before the walk.

Found with MBCheck, a static herd7-based memory consistency checker.

Signed-off-by: Jaidev Shastri <jaidevshastri@vt.edu>
---
 drivers/tty/vt/keyboard.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index d7db5e226..c2fd92e2b 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -447,7 +447,7 @@ void vt_set_leds_compute_shiftstate(void)
 static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
 {
 	unsigned int d = diacr;
-	unsigned int i;
+	unsigned int i, n;
 
 	diacr = 0;
 
@@ -455,7 +455,9 @@ static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
 		if ((ch & ~0xff) == BRL_UC_ROW)
 			return d | ch;
 	} else {
-		for (i = 0; i < accent_table_size; i++)
+		/* Pairs with the smp_store_release() in vt_do_diacrit(). */
+		n = smp_load_acquire(&accent_table_size);
+		for (i = 0; i < n; i++)
 			if (accent_table[i].diacr == d && accent_table[i].base == ch)
 				return accent_table[i].result;
 	}
@@ -1810,7 +1812,6 @@ static int vt_do_kdskbdiacr(void __user *udp, int perm)
 	}
 
 	guard(spinlock_irqsave)(&kbd_event_lock);
-	accent_table_size = ct;
 	for (i = 0; i < ct; i++) {
 		accent_table[i].diacr =
 				conv_8bit_to_uni(dia[i].diacr);
@@ -1819,6 +1820,8 @@ static int vt_do_kdskbdiacr(void __user *udp, int perm)
 		accent_table[i].result =
 				conv_8bit_to_uni(dia[i].result);
 	}
+	/* Pairs with the smp_load_acquire() in handle_diacr(). */
+	smp_store_release(&accent_table_size, ct);
 
 	return 0;
 }
@@ -1848,7 +1851,8 @@ static int vt_do_kdskbdiacruc(void __user *udp, int perm)
 	if (ct)
 		memcpy(accent_table, buf,
 				ct * sizeof(struct kbdiacruc));
-	accent_table_size = ct;
+	/* Pairs with the smp_load_acquire() in handle_diacr(). */
+	smp_store_release(&accent_table_size, ct);
 	return 0;
 }
 

-- 
2.43.0



  parent reply	other threads:[~2026-09-22  1:28 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
2026-09-22  1:28 ` Jaidev Shastri via B4 Relay [this message]
2026-09-22  1:36   ` [PATCH 4/6] vt: keyboard: publish accent_table_size " 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=20260921-mb-keyboard-v1-4-d170228b80c0@vt.edu \
    --to=devnull+jaidevshastri.vt.edu@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jaidevshastri@vt.edu \
    --cc=jirislaby@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