All of lore.kernel.org
 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 6/6] vt: keyboard: publish the shift_down[] counters with release semantics
Date: Tue, 22 Sep 2026 01:42:59 +0000	[thread overview]
Message-ID: <20260922014300.6CBA91F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260921-mb-keyboard-v1-6-d170228b80c0@vt.edu>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] tty: vt: unnecessary memory barriers on shift_down
--

commit 00b20e2546808f30870c343c8e766b47b9bd3b39
Author: Jaidev Shastri <jaidevshastri@vt.edu>

vt: keyboard: publish the shift_down[] counters with release semantics
    
The commit updates accesses to the shift_down[] array by adding
smp_store_release() and smp_load_acquire() semantics. This change was based on
a static analyzer report.

> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index 87970415a043c..e6112e0db1020 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -823,7 +823,8 @@ static void k_pad(struct vc_data *vc, unsigned char value, char up_flag)
>  		return;		/* no action, if this is a key release */
>  
>  	/* kludge... shift forces cursor/number keys */
> -	if (vc_kbd_mode(kbd, VC_APPLIC) && !shift_down[KG_SHIFT]) {
> +	/* Pairs with the smp_store_release() in k_shift(). */
> +	if (vc_kbd_mode(kbd, VC_APPLIC) && !smp_load_acquire(&shift_down[KG_SHIFT])) {

[Severity: Low]
Are these acquire semantics necessary?

A key press or release triggers kbd_event(), acquiring the kbd_event_lock
spinlock. This calls kbd_keycode() which invokes k_shift() and k_pad() via the
k_handler array.

All functions accessing shift_down[] (k_shift(), k_pad(), and
do_compute_shiftstate()) appear to be strictly executed under this spinlock,
meaning there are no lockless readers for shift_down[] in the kernel. Did
the static analyzer produce a false positive by failing to trace the
spinlock across the function pointer invocations in k_handler[]?

>  		applkey(vc, app_map[value], 1);
>  		return;
>  	}

[ ... ]

> @@ -890,15 +892,18 @@ static void k_shift(struct vc_data *vc, unsigned char value, char up_flag)
>  			clr_vc_kbd_led(kbd, VC_CAPSLOCK);
>  	}
>  
> +	cnt = shift_down[value];
>  	if (up_flag) {
>  		/*
>  		 * handle the case that two shift or control
>  		 * keys are depressed simultaneously
>  		 */
> -		if (shift_down[value])
> -			shift_down[value]--;
> +		if (cnt)
> +			cnt--;
>  	} else
> -		shift_down[value]++;
> +		cnt++;
> +	/* Pairs with the smp_load_acquire() in k_pad(). */
> +	smp_store_release(&shift_down[value], cnt);

[Severity: Low]
Are these release semantics necessary?

As mentioned above, since shift_down[] is already protected by the
kbd_event_lock spinlock, are there any lockless readers that require these
memory barriers? Also, as there are plain reads adjacent to the release
store (e.g. cnt = shift_down[value] just above), the implementation would
be flawed if lockless concurrency were actually present.

>  
>  	if (shift_down[value])
>  		state = shift_state | BIT(value);

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

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

Thread overview: 21+ 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
2026-09-22  1:28 ` Jaidev Shastri via B4 Relay
2026-09-22  1:28 ` [PATCH 1/6] vt: keyboard: publish shift_state with release semantics Jaidev Shastri
2026-09-22  1:28   ` 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
2026-09-22  1:28   ` 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
2026-09-22  1:28   ` Jaidev Shastri via B4 Relay
2026-09-22  1:39   ` sashiko-bot
2026-09-22  1:28 ` [PATCH 4/6] vt: keyboard: publish accent_table_size " Jaidev Shastri
2026-09-22  1:28   ` 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
2026-09-22  1:28   ` 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
2026-09-22  1:28   ` Jaidev Shastri via B4 Relay
2026-09-22  1:42   ` sashiko-bot [this message]

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=20260922014300.6CBA91F000FF@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.