Re: [PATCH 1/6] vt: keyboard: publish shift_state with release semantics

From: Greg Kroah-Hartman

Date: Wed Sep 23 2026 - 08:52:51 EST


On Mon, Sep 21, 2026 at 09:28:14PM -0400, Jaidev Shastri via B4 Relay wrote:
> From: Jaidev Shastri <jaidevshastri@xxxxxx>
>
> k_shift() updates shift_down[] and then shift_state under
> kbd_event_lock. vt_get_shift_state() reads shift_state without the lock
> for TIOCL_GETSHIFTSTATE, so the plain accesses leave the relation
> between the counters and the summary word unspecified.
>
> Store shift_state with smp_store_release() and read it with
> smp_load_acquire().
>
> Found with MBCheck, a static herd7-based memory consistency checker.
>
> Signed-off-by: Jaidev Shastri <jaidevshastri@xxxxxx>
> ---
> drivers/tty/vt/keyboard.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index c41d850b2..089f3b048 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -865,6 +865,7 @@ static void k_pad(struct vc_data *vc, unsigned char value, char up_flag)
> static void k_shift(struct vc_data *vc, unsigned char value, char up_flag)
> {
> int old_state = shift_state;
> + int state;
>
> if (rep)
> return;
> @@ -889,9 +890,11 @@ static void k_shift(struct vc_data *vc, unsigned char value, char up_flag)
> shift_down[value]++;
>
> if (shift_down[value])
> - shift_state |= BIT(value);
> + state = shift_state | BIT(value);
> else
> - shift_state &= ~BIT(value);
> + state = shift_state & ~BIT(value);
> + /* Pairs with the smp_load_acquire() in vt_get_shift_state(). */
> + smp_store_release(&shift_state, state);

Again, no.