From nobody Fri Nov 18 23:56:11 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NDYZz3VyVz4hl2V; Fri, 18 Nov 2022 23:56:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NDYZz2xjrz3FBY; Fri, 18 Nov 2022 23:56:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668815771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KhePE2nTnE/g2MTcG6hqjRFopv19Q4uhKsM18oWRLYk=; b=NVj454F72u39jm13bIvQZZg9WSoAnDXIFr2Y+4Z59wZ7EhV6DI6TUIunfT7gTpJhiMTd63 59C3N1AlARNXRtyBTkgOHrl+/GZKPKpJ0+JYMAyCPU8l3h9Xwh98iLijD60acOtnNho+Xd dwwZBbfYLI8DmmFCBFQJuUzsq1UmD1d9R50vcfwsn2wSjmMmXhmwVBKtYPkZ4TYPi1r1ZZ z92C1MhyMFObfU3egM8X8Ba8qLLi5O7xNL0P0tPr+BJPcIjvPsSLzys6KKbCfgkfuCy87O 8UBpzOZYEq5nEMRK2SZSs0wgS487o+CG5cGQrf7go990v5hv4oIlwpZuncSioQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668815771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KhePE2nTnE/g2MTcG6hqjRFopv19Q4uhKsM18oWRLYk=; b=Cll2Tj96USBXiTnqFITWlz3wIdFdHuyRmonQmsT0YOqCRXIcPnJKAWpakIRkcnJzz1pS0h 0K4+8wGp5i1LMhE+8yq86Cic0iOUVfn3n+esPRpPQoegtZG4Y26AL6HiKK4pQfc63MwGrP Xd99q07afd1SB89sgmnan2ShUrNLWmyfDtKIqlYgQ0N3fdtyOTTYDoHtopp8MnVDItj4Zj oxPdDZhePsQ2RrzaEw9IVmLxN6UddxKaBgnMnc1YnR3nps5QVpv0ASVwU1Cpk004o+t2pF XvpsWzS3e3rHX+ERhabf9acfwVnhqpgKcgFKDJE9hqNi8SKZifd8QMKYcEOh0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668815771; a=rsa-sha256; cv=none; b=AxlWLqvkjdgnVj1cjgDNKhSROj7UauRA4MddkLo/sY93+lP8Xkn5zFGmXoNOSoZHIVy+ic eWvBZBBNnTnPsE2YzOsEWntzSNlHB9DTm5vqJDDSQffgmRv6SMOMe5KCYsgf82LCfe1JbB KIsveQmL/z9x+wc2YDPcoZ4qq4EL5RdZvp5fM0gEY/Ma+OJwz6cloRhuVtOTb27vn1UF+4 MbKCoB4AldF+jaaXhNzeH8eyMPavm4VuvGYKLUUHQzfVI2i6SDmCnlKvgRSHk20diLsVk5 WckmorLmRr1CbycuvWNitiSLV5R5IPIinRJUTk6zsSase+iCxsNkLYM5TEuTcQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NDYZz211tzPyX; Fri, 18 Nov 2022 23:56:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2AINuBgQ098210; Fri, 18 Nov 2022 23:56:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AINuBUX098209; Fri, 18 Nov 2022 23:56:11 GMT (envelope-from git) Date: Fri, 18 Nov 2022 23:56:11 GMT Message-Id: <202211182356.2AINuBUX098209@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 183088934a6c - main - evdev: Extend EVIOCGRAB ioctl scope to cover kbd interface List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 183088934a6c4384e45ac6d01c04754e0d7a991c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=183088934a6c4384e45ac6d01c04754e0d7a991c commit 183088934a6c4384e45ac6d01c04754e0d7a991c Author: Vladimir Kondratyev AuthorDate: 2022-11-18 23:54:46 +0000 Commit: Vladimir Kondratyev CommitDate: 2022-11-18 23:54:46 +0000 evdev: Extend EVIOCGRAB ioctl scope to cover kbd interface of various keyboard drivers. EVIOCGRAB ioctl execution on /dev/input/event# device node gains exclusive access to this device to caller. It is used mostly for development purposes and remote control software. See e.g. https://reviews.freebsd.org/D30020 which is the reason of creation of this change. Keyboard grabbing is disabled in KDB and during panics. MFC with: 4a0db5e2920c Tested by: corvink Differential revision: https://reviews.freebsd.org/D30542 --- sys/dev/atkbdc/atkbd.c | 3 +++ sys/dev/evdev/evdev.c | 2 ++ sys/dev/gpio/gpiokeys.c | 4 ++++ sys/dev/hid/hkbd.c | 4 ++++ sys/dev/hyperv/input/hv_kbd.c | 2 ++ sys/dev/kbdmux/kbdmux.c | 3 +++ sys/dev/usb/input/ukbd.c | 4 ++++ 7 files changed, 22 insertions(+) diff --git a/sys/dev/atkbdc/atkbd.c b/sys/dev/atkbdc/atkbd.c index 3e261115527b..eb76882bf9f7 100644 --- a/sys/dev/atkbdc/atkbd.c +++ b/sys/dev/atkbdc/atkbd.c @@ -703,6 +703,9 @@ next_code: evdev_sync(state->ks_evdev); } } + + if (state->ks_evdev != NULL && evdev_is_grabbed(state->ks_evdev)) + return (NOKEY); #endif /* return the byte as is for the K_RAW mode */ diff --git a/sys/dev/evdev/evdev.c b/sys/dev/evdev/evdev.c index a0a039f0b691..2bb365125b5a 100644 --- a/sys/dev/evdev/evdev.c +++ b/sys/dev/evdev/evdev.c @@ -1097,6 +1097,8 @@ evdev_release_client(struct evdev_dev *evdev, struct evdev_client *client) bool evdev_is_grabbed(struct evdev_dev *evdev) { + if (kdb_active || SCHEDULER_STOPPED()) + return (false); /* * The function is intended to be called from evdev-unrelated parts of * code like syscons-compatible parts of mouse and keyboard drivers. diff --git a/sys/dev/gpio/gpiokeys.c b/sys/dev/gpio/gpiokeys.c index bea5844bad5e..36746923f01b 100644 --- a/sys/dev/gpio/gpiokeys.c +++ b/sys/dev/gpio/gpiokeys.c @@ -194,6 +194,10 @@ gpiokeys_key_event(struct gpiokeys_softc *sc, struct gpiokey *key, int pressed) evdev_push_key(sc->sc_evdev, key->evcode, pressed); evdev_sync(sc->sc_evdev); } + if (evdev_is_grabbed(sc->sc_evdev)) { + GPIOKEYS_UNLOCK(sc); + return; + } #endif if (key->keycode != GPIOKEY_NONE) { code = key->keycode & SCAN_KEYCODE_MASK; diff --git a/sys/dev/hid/hkbd.c b/sys/dev/hid/hkbd.c index 6fee3b0094a5..09339a762679 100644 --- a/sys/dev/hid/hkbd.c +++ b/sys/dev/hid/hkbd.c @@ -391,6 +391,8 @@ hkbd_put_key(struct hkbd_softc *sc, uint32_t key) if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) evdev_push_event(sc->sc_evdev, EV_KEY, evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE)); + if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev)) + return; #endif tail = (sc->sc_inputtail + 1) % HKBD_IN_BUF_SIZE; @@ -541,6 +543,8 @@ hkbd_interrupt(struct hkbd_softc *sc) #ifdef EVDEV_SUPPORT if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) evdev_sync(sc->sc_evdev); + if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev)) + return; #endif /* wakeup keyboard system */ diff --git a/sys/dev/hyperv/input/hv_kbd.c b/sys/dev/hyperv/input/hv_kbd.c index 53aacda7fbcb..ea1a8b883fbb 100644 --- a/sys/dev/hyperv/input/hv_kbd.c +++ b/sys/dev/hyperv/input/hv_kbd.c @@ -340,6 +340,8 @@ next_code: evdev_sync(sc->ks_evdev); } } + if (sc->ks_evdev != NULL && evdev_is_grabbed(sc->ks_evdev)) + return (NOKEY); #endif ++kbd->kb_count; DEBUG_HVKBD(kbd, "read scan: 0x%x\n", scancode); diff --git a/sys/dev/kbdmux/kbdmux.c b/sys/dev/kbdmux/kbdmux.c index 3bbdc78b7c1a..b70e956830e5 100644 --- a/sys/dev/kbdmux/kbdmux.c +++ b/sys/dev/kbdmux/kbdmux.c @@ -715,6 +715,9 @@ next_code: evdev_sync(state->ks_evdev); } } + + if (state->ks_evdev != NULL && evdev_is_grabbed(state->ks_evdev)) + return (NOKEY); #endif /* return the byte as is for the K_RAW mode */ diff --git a/sys/dev/usb/input/ukbd.c b/sys/dev/usb/input/ukbd.c index 4353888505da..c8658f9b62da 100644 --- a/sys/dev/usb/input/ukbd.c +++ b/sys/dev/usb/input/ukbd.c @@ -394,6 +394,8 @@ ukbd_put_key(struct ukbd_softc *sc, uint32_t key) if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) evdev_push_event(sc->sc_evdev, EV_KEY, evdev_hid2key(KEY_INDEX(key)), !(key & KEY_RELEASE)); + if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev)) + return; #endif if (sc->sc_inputs < UKBD_IN_BUF_SIZE) { @@ -562,6 +564,8 @@ ukbd_interrupt(struct ukbd_softc *sc) #ifdef EVDEV_SUPPORT if (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD && sc->sc_evdev != NULL) evdev_sync(sc->sc_evdev); + if (sc->sc_evdev != NULL && evdev_is_grabbed(sc->sc_evdev)) + return; #endif /* wakeup keyboard system */