Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4547822imm; Tue, 11 Sep 2018 13:44:31 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdas4STv+Jb+ad9lohXgFSmd9kqxkVU84KvmQwm7szU9ymUGo7Axmr888K3ZpKO+O04fwH1g X-Received: by 2002:a65:5286:: with SMTP id y6-v6mr29138025pgp.65.1536698671714; Tue, 11 Sep 2018 13:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536698671; cv=none; d=google.com; s=arc-20160816; b=yQzs9V+mn8aa93ptI3FMHDSt7+/GRQnvcgiJo8MxhtxUrXTCztRI5/OgJTGOopqFXd fh2j5+Ws4POXHcK7XrU3trJqon/3AjL0908TldS0pG3UFPEApwklwVnQ4u9skW7yH7K5 DqP8/TbjzMPMOyMamDdj6ReqIwBMCr1+sA+2WI791wNYPWXP2ViZFifyLLDb/N3u5tUl Ie85VuT/YH0/UM/Eqj7vGzhwiEoKrrwcNxP+uungY3EcOXTil0tth2FaW9Di9xNUYcSx R2e0njN14BcYWhp9J61wnXhm4lZ1fHO2maAHWg1mUSu4NnBgXW59JQ+JDa7W259MNdv/ oOIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=zjLKvfcW+HWu9QXWzdhOMc6w1isQUiWqZfugYRvoU0c=; b=OyLa6tHNtr8QpUjAsredcClr4SYsEFFOFF9XaSL+mO/3f0samXYjK+Z/MW78sWD0Wf tASrG820839rODKBKJNLGh2n9iHMDQWNgPOacARj8OAmt6fzr2NB9jXN6Sqr65EWQuft 95BpYeeZBiXrjO5lnP/RXZ12O0iFFkUiEd28u8VwyDL/PV2S5dE8ucqpw+J2AzFPG1L2 8KKCsuPpbGLlToDZhSMwrylPwI8o3xu1EAwvKzqUYXuWuOyOlV7douEVfuZH9NvNiRw7 Hr1Oa+MowvMCPX2wByESeAHS0iakxelzJ08CbIbIoDSuW1bQCtgMLgTbQzy8PdgvvZ5i mUBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d2-v6si22638407pgu.106.2018.09.11.13.44.16; Tue, 11 Sep 2018 13:44:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727781AbeILBpH (ORCPT + 99 others); Tue, 11 Sep 2018 21:45:07 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:42400 "EHLO mslow2.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726829AbeILBpG (ORCPT ); Tue, 11 Sep 2018 21:45:06 -0400 Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 9F75B3A19E1 for ; Tue, 11 Sep 2018 22:18:28 +0200 (CEST) X-Originating-IP: 88.190.179.123 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id E40E7240009; Tue, 11 Sep 2018 20:18:26 +0000 (UTC) From: Remi Pommarel To: Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org Cc: Alexander Viro , Kees Cook , Elie Roudninski , Remi Pommarel Subject: [PATCH 3/4] drivers/tty/vt/keyboard.c: Make key_down[] bitmap input dependent Date: Tue, 11 Sep 2018 22:23:58 +0200 Message-Id: <45a4a8e3123730bf900ea921baf153ff0c899dd5.1536695071.git.repk@triplefau.lt> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A kbd_handle input can have a specific keyboard config that makes keycode to keysym mapping array different from another one. Because key_down[] bitmap stores currently pressed key as keycode, it should be associated with an input keymap in order to retrieve the associated keysym. Allocating this array in each input allows to retrieve its associated keymap. Signed-off-by: Remi Pommarel Tested-by: Elie Roudninski --- drivers/tty/vt/keyboard.c | 46 +++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 4f09331ad5c3..7272e1828838 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -122,6 +122,7 @@ struct kbd_handle { struct kref ref; struct kbd_conf *conf; struct input_handle handle; + unsigned long key_down[BITS_TO_LONGS(KEY_CNT)];/* keyboard key bitmap */ }; #define hdl_to_kbd_handle(h) (container_of(h, struct kbd_handle, handle)) @@ -140,7 +141,6 @@ static const int NR_TYPES = ARRAY_SIZE(max_vals); static struct input_handler kbd_handler; static DEFINE_SPINLOCK(kbd_event_lock); static DEFINE_SPINLOCK(led_lock); -static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ static bool dead_key_next; static int npadch = -1; /* -1 or number assembled on pad */ @@ -378,20 +378,18 @@ static void to_utf8(struct vc_data *vc, uint c) /* * Called after returning from RAW mode or when changing consoles - recompute - * shift_down[] and shift_state from key_down[] maybe called when keymap is - * undefined, so that shiftkey release is seen. The caller must hold the - * kbd_event_lock. + * shift_down[] and shift_state from each input's key_down[] maybe called when + * keymap is undefined, so that shiftkey release is seen. The caller must hold + * the kbd_event_lock. */ -static void do_compute_shiftstate(void) +static int do_compute_input_shiftstate(struct input_handle *handle, void *data) { + struct kbd_handle *kh = hdl_to_kbd_handle(handle); unsigned int k, sym, val; - shift_state = 0; - memset(shift_down, 0, sizeof(shift_down)); - - for_each_set_bit(k, key_down, min(NR_KEYS, KEY_CNT)) { - sym = U(key_maps[0][k]); + for_each_set_bit(k, kh->key_down, min(NR_KEYS, KEY_CNT)) { + sym = U(kh->conf->maps[0][k]); if (KTYP(sym) != KT_SHIFT && KTYP(sym) != KT_SLOCK) continue; @@ -402,6 +400,15 @@ static void do_compute_shiftstate(void) shift_down[val]++; shift_state |= BIT(val); } + return 0; +} + +static void do_compute_shiftstate(void) +{ + shift_state = 0; + memset(shift_down, 0, sizeof(shift_down)); + input_handler_for_each_handle(&kbd_handler, NULL, + do_compute_input_shiftstate); } /* We still have to export this method to vt.c */ @@ -1278,6 +1285,17 @@ static int sparc_l1_a_state; extern void sun_do_break(void); #endif +static int is_alt_down(struct input_handle *handle, void *data) +{ + struct kbd_handle *kh = hdl_to_kbd_handle(handle); + + if (test_bit(KEY_LEFTALT, kh->key_down) || + test_bit(KEY_RIGHTALT, kh->key_down)) + return 1; + + return 0; +} + static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char up_flag) { @@ -1308,8 +1326,8 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode, * pressing PrtSc/SysRq alone, but simply 0x54 * when pressing Alt+PrtSc/SysRq. */ - if (test_bit(KEY_LEFTALT, key_down) || - test_bit(KEY_RIGHTALT, key_down)) { + if (input_handler_for_each_handle(&kbd_handler, NULL, + is_alt_down)) { put_queue(vc, 0x54 | up_flag); } else { put_queue(vc, 0xe0); @@ -1424,9 +1442,9 @@ static void kbd_keycode(struct kbd_handle *kh, unsigned int keycode, int down, } if (down) - set_bit(keycode, key_down); + set_bit(keycode, kh->key_down); else - clear_bit(keycode, key_down); + clear_bit(keycode, kh->key_down); if (rep && (!vc_kbd_mode(kbd, VC_REPEAT) || -- 2.18.0