mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] vt: Add VC_MUTE (v2)
@ 2012-12-10 16:04 Adam Jackson
  2012-12-11 10:53 ` Alan Cox
  2012-12-14 19:37 ` Arthur Taylor
  0 siblings, 2 replies; 3+ messages in thread
From: Adam Jackson @ 2012-12-10 16:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arthur Taylor, Greg Kroah-Hartman

The "don't enqueue stuff" semantics of K_OFF shouldn't be a function of
the keyboard map state; we should be able to switch among cooked/raw/
unicode without changing whether events are delivered.  Otherwise - if
changing to K_UNICODE undoes K_OFF - then suddenly Alt-F2 under
Gnome will switch VT instead of summoning the "run command" dialog.

Add a new KD[GS]KBMUTE ioctl pair that allows events to be muted
independently of map state.

v2: Leave K_OFF in place at Alan's suggestion.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=859485
Cc: Arthur Taylor <art@ified.ca>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Josh Boyer <jwboyer@redhat.com>
Signed-off-by: Adam Jackson <ajax@redhat.com>
---
 drivers/tty/vt/keyboard.c | 42 ++++++++++++++++++++++++++++++++++++++----
 drivers/tty/vt/vt_ioctl.c | 13 +++++++++++++
 include/linux/kbd_kern.h  |  3 ++-
 include/linux/vt_kern.h   |  2 ++
 include/uapi/linux/kd.h   |  4 ++++
 5 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 681765b..20ebdad 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -642,6 +642,11 @@ static void fn_null(struct vc_data *vc)
 	do_compute_shiftstate();
 }
 
+static bool kbd_is_muted(void)
+{
+    return (kbd->kbdmode == VC_OFF) || vc_kbd_mode(kbd, VC_MUTE);
+}
+
 /*
  * Special key handlers
  */
@@ -657,7 +662,7 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
 		return;
 	if ((kbd->kbdmode == VC_RAW ||
 	     kbd->kbdmode == VC_MEDIUMRAW ||
-	     kbd->kbdmode == VC_OFF) &&
+	     kbd_is_muted())
 	     value != KVAL(K_SAK))
 		return;		/* SAK is allowed even in raw mode */
 	fn_handler[value](vc);
@@ -1381,7 +1386,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
 	if (rc == NOTIFY_STOP)
 		return;
 
-	if ((raw_mode || kbd->kbdmode == VC_OFF) && type != KT_SPEC && type != KT_SHIFT)
+	if ((raw_mode || kbd_is_muted()) && type != KT_SPEC && type != KT_SHIFT)
 		return;
 
 	(*k_handler[type])(vc, keysym & 0xff, !down);
@@ -1742,6 +1747,30 @@ int vt_do_kdskbmode(int console, unsigned int arg)
 }
 
 /**
+ *	vt_do_kdskbmute		-	set keyboard event mute
+ *	@console: the console to use
+ *	@arg: the requested mode
+ *
+ *	Update the keyboard mute state while holding the correct locks.
+ *	Return 0 for success or an error code.
+ */
+int vt_do_kdskbmute(int console, unsigned int arg)
+{
+	struct kbd_struct * kbd = kbd_table + console;
+	int ret = 0;
+	unsigned long flags;
+
+	spin_lock_irqsave(&kbd_event_lock, flags);
+	if (arg)
+		set_vc_kbd_mode(kbd, VC_MUTE);
+	else
+		clr_vc_kbd_mode(kbd, VC_MUTE);
+	spin_unlock_irqrestore(&kbd_event_lock, flags);
+	return ret;
+}
+
+
+/**
  *	vt_do_kdskbmeta		-	set keyboard meta state
  *	@console: the console to use
  *	@arg: the requested meta state
@@ -2068,13 +2097,18 @@ int vt_do_kdgkbmode(int console)
 		return K_MEDIUMRAW;
 	case VC_UNICODE:
 		return K_UNICODE;
-	case VC_OFF:
-		return K_OFF;
 	default:
 		return K_XLATE;
 	}
 }
 
+int vt_do_kdgkbmute(int console)
+{
+	struct kbd_struct * kbd = kbd_table + console;
+	/* This is a spot read so needs no locking */
+	return vc_kbd_mode(kbd, VC_MUTE);
+}
+
 /**
  *	vt_do_kdgkbmeta		-	report meta status
  *	@console: console to report
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index b841f56..f0951e2 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -477,6 +477,19 @@ int vt_ioctl(struct tty_struct *tty,
 		ret = put_user(uival, (int __user *)arg);
 		break;
 
+	case KDSKBMUTE:
+		if (!perm)
+			return -EPERM;
+		ret = vt_do_kdskbmute(console, arg);
+		if (ret == 0)
+			tty_ldisc_flush(tty);
+		break;
+
+	case KDGKBMUTE:
+		uival = vt_do_kdgkbmute(console);
+		ret = put_user(uival, (int __user *)arg);
+		break;
+
 	/* this could be folded into KDSKBMODE, but for compatibility
 	   reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
 	case KDSKBMETA:
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index b7c8cdc..18c0a45 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -55,12 +55,13 @@ struct kbd_struct {
 #define VC_UNICODE	3	/* Unicode mode */
 #define VC_OFF		4	/* disabled mode */
 
-	unsigned char modeflags:5;
+	unsigned char modeflags:6;
 #define VC_APPLIC	0	/* application key mode */
 #define VC_CKMODE	1	/* cursor key mode */
 #define VC_REPEAT	2	/* keyboard repeat */
 #define VC_CRLF		3	/* 0 - enter sends CR, 1 - enter sends CRLF */
 #define VC_META		4	/* 0 - meta, 1 - meta=prefix with ESC */
+#define VC_MUTE		5	/* don't generate events */
 };
 
 extern int kbd_init(void);
diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h
index 50ae7d0..a886915 100644
--- a/include/linux/vt_kern.h
+++ b/include/linux/vt_kern.h
@@ -168,6 +168,7 @@ extern void hide_boot_cursor(bool hide);
 
 /* keyboard  provided interfaces */
 extern int vt_do_diacrit(unsigned int cmd, void __user *up, int eperm);
+extern int vt_do_kdskbmute(int console, unsigned int arg);
 extern int vt_do_kdskbmode(int console, unsigned int arg);
 extern int vt_do_kdskbmeta(int console, unsigned int arg);
 extern int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc,
@@ -177,6 +178,7 @@ extern int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe,
 extern int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb,
                                         int perm);
 extern int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm);
+extern int vt_do_kdgkbmute(int console);
 extern int vt_do_kdgkbmode(int console);
 extern int vt_do_kdgkbmeta(int console);
 extern void vt_reset_unicode(int console);
diff --git a/include/uapi/linux/kd.h b/include/uapi/linux/kd.h
index 87b7cc4..ce08f6a 100644
--- a/include/uapi/linux/kd.h
+++ b/include/uapi/linux/kd.h
@@ -150,6 +150,10 @@ struct kbd_repeat {
 			/* earlier this field was misnamed "rate" */
 };
 
+/* get/set event mute */
+#define KDGKBMUTE	0x4B50
+#define KDSKBMUTE	0x4B51
+
 #define KDKBDREP        0x4B52  /* set keyboard delay/repeat rate;
 				 * actually used values are returned */
 
-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vt: Add VC_MUTE (v2)
  2012-12-10 16:04 [PATCH] vt: Add VC_MUTE (v2) Adam Jackson
@ 2012-12-11 10:53 ` Alan Cox
  2012-12-14 19:37 ` Arthur Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Cox @ 2012-12-11 10:53 UTC (permalink / raw)
  To: Adam Jackson; +Cc: linux-kernel, Arthur Taylor, Greg Kroah-Hartman

> @@ -2068,13 +2097,18 @@ int vt_do_kdgkbmode(int console)
>  		return K_MEDIUMRAW;
>  	case VC_UNICODE:
>  		return K_UNICODE;
> -	case VC_OFF:
> -		return K_OFF;

Trying to work out why this change is made ?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vt: Add VC_MUTE (v2)
  2012-12-10 16:04 [PATCH] vt: Add VC_MUTE (v2) Adam Jackson
  2012-12-11 10:53 ` Alan Cox
@ 2012-12-14 19:37 ` Arthur Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Arthur Taylor @ 2012-12-14 19:37 UTC (permalink / raw)
  To: Adam Jackson; +Cc: linux-kernel, Greg Kroah-Hartman

> The "don't enqueue stuff" semantics of K_OFF shouldn't be a function of
> the keyboard map state; we should be able to switch among cooked/raw/
> unicode without changing whether events are delivered.  Otherwise - if
> changing to K_UNICODE undoes K_OFF - then suddenly Alt-F2 under
> Gnome will switch VT instead of summoning the "run command" dialog.

A patch to disable the muting should be added to the SysRq handler for
the "unRaw" action.

I do not think that KBMODE is only about the keyboard map. The
behaviours that KBMODE influences are:
-Whether input is generated.
-Whether input is buffered by line.
-Whether key events are put through the keymap and translated by
modifiers or sent as raw keyup/down events.
-Whether the keymap is unicode.
-Whether special keys are interpreted by the kernel.

The meaning of KBMODE is a bit overloaded It does make sense to split
the generate / don't generate input into its own ioctl. However, IMO
this change is part of an incomplete fix to a user space problem.

The issue creating a need for moving the generate / don't generate
input to its own ioctl was that through some plumbing, when changing
the keymap setting in an X graphical environment session systemd is
told to switch the console keymap. As part of switching the keymap, if
unicode is selected, systemd blindly calls KDSKBMODE with K_UNICODE.
This currently messes up X, which this change attempts to address.

I'm not sure if letting systemd freely meddle with KBMODE and moving
the important-for-X behaviour to another ioctl is such a wise idea.
systemd already changes the kernel default KBMODE to/from unicode by a
module parameter. Further, this will only work with newer or patched X
servers.

Depending on the input configuration and drivers used by X, either the
input system is used directly and the virtual console keyboard is
ignored, or X uses the virtual console keyboard for input and switches
it into RAW mode.

In both modes X does not want the kernel to interpret special keys. In
the former mode X doesn't want the kernel to generate input (as
otherwise it needs to periodically flush a buffer it never reads to
stop it from overflowing and causing a kworker to go nuts), in the
later mode X wants raw key up/down events which are not line buffered.

Setting the console to K_UNICODE is none of these things and causes
one of many possible problems.

KBMODE (like the console keymap) is a virtual console setting which is
stored in the virtual terminal and saved/restored from the console
upon a VT switch.

X is usually run on a VT it allocates and then closes on exit, but you
can also specify a VT for X to run on which could already have been
open by another process (say getty.) In either case, X saves the
KBMODE of the VT during initialization and restores it upon exit.

systemd calling KDSKBMODE on a VT which X is running either has no
affect or a negative affect on X. In the rare case that X is started
on a VT with another text mode cooked input process, KBMODE is
unaffected after X exits.

-Art

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-14 19:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-10 16:04 [PATCH] vt: Add VC_MUTE (v2) Adam Jackson
2012-12-11 10:53 ` Alan Cox
2012-12-14 19:37 ` Arthur Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®