All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vt: Add virtual console keyboard mode OFF
@ 2011-01-30  8:36 Arthur Taylor
  2011-01-31  7:40 ` Pavel Machek
  2011-01-31 17:46 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Arthur Taylor @ 2011-01-30  8:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: gregkh, akpm, alan, Pavel Machek

Add a new mode for the virtual console keyboard OFF to compliment RAW
in which all key events are ignored. New mode prevents vt input
buffers from overflowing when a program opens but doesn't read from a
tty, like Xorg using only evdev for input.

The new mode is available by the ioctl KDSKBMODE with argument K_OFF
from linux/kd.h. Does not effect sysrq behaviour.

Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alan Cox <alan@redhat.com>
Signed-off-by: Arthur Taylor <art@ified.ca>
---
 drivers/tty/vt/keyboard.c |    5 +++--
 drivers/tty/vt/vt_ioctl.c |    3 +++
 include/linux/kbd_kern.h  |    3 ++-
 include/linux/kd.h        |    1 +
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index e95d787..6dd3c68 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -654,7 +654,8 @@ static void k_spec(struct vc_data *vc, unsigned
char value, char up_flag)
 	if (value >= ARRAY_SIZE(fn_handler))
 		return;
 	if ((kbd->kbdmode == VC_RAW ||
-	     kbd->kbdmode == VC_MEDIUMRAW) &&
+	     kbd->kbdmode == VC_MEDIUMRAW ||
+	     kbd->kbdmode == VC_OFF) &&
 	     value != KVAL(K_SAK))
 		return;		/* SAK is allowed even in raw mode */
 	fn_handler[value](vc);
@@ -1295,7 +1296,7 @@ static void kbd_keycode(unsigned int keycode,
int down, int hw_raw)
 	if (rc == NOTIFY_STOP)
 		return;

-	if (raw_mode && type != KT_SPEC && type != KT_SHIFT)
+	if ((raw_mode || kbd->kbdmode == VC_OFF) && type != KT_SPEC && type
!= KT_SHIFT)
 		return;

 	(*k_handler[type])(vc, keysym & 0xff, !down);
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 1235ebd..6bcf05b 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -688,6 +688,9 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
 			kbd->kbdmode = VC_UNICODE;
 			compute_shiftstate();
 			break;
+		  case K_OFF:
+			kbd->kbdmode = VC_OFF;
+			break;
 		  default:
 			ret = -EINVAL;
 			goto out;
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index 506ad20..4b0761c 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -50,11 +50,12 @@ struct kbd_struct {
 #define VC_CAPSLOCK	2	/* capslock mode */
 #define VC_KANALOCK	3	/* kanalock mode */

-	unsigned char kbdmode:2;	/* one 2-bit value */
+	unsigned char kbdmode:3;	/* one 3-bit value */
 #define VC_XLATE	0	/* translate keycodes using keymap */
 #define VC_MEDIUMRAW	1	/* medium raw (keycode) mode */
 #define VC_RAW		2	/* raw (scancode) mode */
 #define VC_UNICODE	3	/* Unicode mode */
+#define VC_OFF		4	/* disabled mode */

 	unsigned char modeflags:5;
 #define VC_APPLIC	0	/* application key mode */
diff --git a/include/linux/kd.h b/include/linux/kd.h
index 15f2853..c36d847 100644
--- a/include/linux/kd.h
+++ b/include/linux/kd.h
@@ -81,6 +81,7 @@ struct unimapinit {
 #define		K_XLATE		0x01
 #define		K_MEDIUMRAW	0x02
 #define		K_UNICODE	0x03
+#define		K_OFF		0x04
 #define KDGKBMODE	0x4B44	/* gets current keyboard mode */
 #define KDSKBMODE	0x4B45	/* sets current keyboard mode */

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

* Re: [PATCH] vt: Add virtual console keyboard mode OFF
  2011-01-30  8:36 [PATCH] vt: Add virtual console keyboard mode OFF Arthur Taylor
@ 2011-01-31  7:40 ` Pavel Machek
  2011-01-31 17:46 ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Pavel Machek @ 2011-01-31  7:40 UTC (permalink / raw)
  To: Arthur Taylor; +Cc: linux-kernel, gregkh, akpm, alan

On Sun 2011-01-30 00:36:22, Arthur Taylor wrote:
> Add a new mode for the virtual console keyboard OFF to compliment RAW
> in which all key events are ignored. New mode prevents vt input
> buffers from overflowing when a program opens but doesn't read from a
> tty, like Xorg using only evdev for input.
> 
> The new mode is available by the ioctl KDSKBMODE with argument K_OFF
> from linux/kd.h. Does not effect sysrq behaviour.
> 
> Cc: Greg Kroah-Hartman <gregkh@suse.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Alan Cox <alan@redhat.com>
> Signed-off-by: Arthur Taylor <art@ified.ca>


ACK.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH] vt: Add virtual console keyboard mode OFF
  2011-01-30  8:36 [PATCH] vt: Add virtual console keyboard mode OFF Arthur Taylor
  2011-01-31  7:40 ` Pavel Machek
@ 2011-01-31 17:46 ` Greg KH
  2011-02-02  2:07   ` [PATCH] [resend] " Arthur Taylor
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2011-01-31 17:46 UTC (permalink / raw)
  To: Arthur Taylor; +Cc: linux-kernel, akpm, alan, Pavel Machek

On Sun, Jan 30, 2011 at 12:36:22AM -0800, Arthur Taylor wrote:
> Add a new mode for the virtual console keyboard OFF to compliment RAW
> in which all key events are ignored. New mode prevents vt input
> buffers from overflowing when a program opens but doesn't read from a
> tty, like Xorg using only evdev for input.
> 
> The new mode is available by the ioctl KDSKBMODE with argument K_OFF
> from linux/kd.h. Does not effect sysrq behaviour.

Care to document this somewhere (i.e. Documentation/ABI?)

> Cc: Greg Kroah-Hartman <gregkh@suse.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Alan Cox <alan@redhat.com>
> Signed-off-by: Arthur Taylor <art@ified.ca>
> ---
>  drivers/tty/vt/keyboard.c |    5 +++--
>  drivers/tty/vt/vt_ioctl.c |    3 +++
>  include/linux/kbd_kern.h  |    3 ++-
>  include/linux/kd.h        |    1 +
>  4 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index e95d787..6dd3c68 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -654,7 +654,8 @@ static void k_spec(struct vc_data *vc, unsigned
> char value, char up_flag)

Your patch is line-wrapped and can not be applied :(

> @@ -50,11 +50,12 @@ struct kbd_struct {
>  #define VC_CAPSLOCK	2	/* capslock mode */
>  #define VC_KANALOCK	3	/* kanalock mode */
> 
> -	unsigned char kbdmode:2;	/* one 2-bit value */
> +	unsigned char kbdmode:3;	/* one 3-bit value */

Are you sure you can change the size of this structure and no one is
going to have problems?

Also, what userspace code is going to use this new feature?  Has it been
tested to work properly?

thanks,

greg k-h

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

* [PATCH] [resend] vt: Add virtual console keyboard mode OFF
  2011-01-31 17:46 ` Greg KH
@ 2011-02-02  2:07   ` Arthur Taylor
  2011-02-03 18:48     ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Arthur Taylor @ 2011-02-02  2:07 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, akpm, Pavel Machek

On Mon, 2011-01-31 at 09:46 -0800, Greg KH wrote:
> Care to document this somewhere (i.e. Documentation/ABI?)
Sure. Can it wait for a future patch though as currently all VT IOCTLs
aren't documented in the source tree. I'm willing to write said
documentation.

> Your patch is line-wrapped and can not be applied :(
Fixed in this mail (hopefully).

> Are you sure you can change the size of this structure and no one is
> going to have problems?
>From what I can tell, no. kbd_struct and it's members are defined in the
non-exported kbd_kern.h, and it is never packed into weird places. Is
that sufficient? What else should be checked?

> Also, what userspace code is going to use this new feature?  Has it been
> tested to work properly?
Xorg is the intended user. In short, reasons for the feature are:
      * Removes having to flush unnecessary duplicate data.
      * Fixes an Xorg corner case.
      * Less code run in both kernel and userspace per key event (I know
        kinda meh, but hey, it's a plus.)

Since the switch to evdev and automatic input device detection, Xorg
sets the console to RAW to disable kernel special key handling and
flushes the console input buffer per key event.

If Xorg is configured with static input device definitions, it can't
flush the input in case the older kbd driver is in use, leading to the
buffer filling. If the console input buffer fills, bad things happen
(which I'm currently looking into as well.)

I modified my xserver to use this feature. I tested Xorg with the
input-evdev and input-kbd drivers for keyboard events. Since input-kbd
sets the keyboard back to RAW when needed, everything is fine. If
input-kbd isn't in use, the keyboard stays in OFF and he input buffer is
always kept empty, things always work. Shift key states are maintained,
and SysRq's unRaw function is still works as expected.

To: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Arthur Taylor <art@ified.ca>
---
 drivers/tty/vt/keyboard.c |    5 +++--
 drivers/tty/vt/vt_ioctl.c |    3 +++
 include/linux/kbd_kern.h  |    3 ++-
 include/linux/kd.h        |    1 +
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index e95d787..6dd3c68 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -654,7 +654,8 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
 	if (value >= ARRAY_SIZE(fn_handler))
 		return;
 	if ((kbd->kbdmode == VC_RAW ||
-	     kbd->kbdmode == VC_MEDIUMRAW) &&
+	     kbd->kbdmode == VC_MEDIUMRAW ||
+	     kbd->kbdmode == VC_OFF) &&
 	     value != KVAL(K_SAK))
 		return;		/* SAK is allowed even in raw mode */
 	fn_handler[value](vc);
@@ -1295,7 +1296,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
 	if (rc == NOTIFY_STOP)
 		return;
 
-	if (raw_mode && type != KT_SPEC && type != KT_SHIFT)
+	if ((raw_mode || kbd->kbdmode == VC_OFF) && type != KT_SPEC && type != KT_SHIFT)
 		return;
 
 	(*k_handler[type])(vc, keysym & 0xff, !down);
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 1235ebd..6bcf05b 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -688,6 +688,9 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
 			kbd->kbdmode = VC_UNICODE;
 			compute_shiftstate();
 			break;
+		  case K_OFF:
+			kbd->kbdmode = VC_OFF;
+			break;
 		  default:
 			ret = -EINVAL;
 			goto out;
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index 506ad20..4b0761c 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -50,11 +50,12 @@ struct kbd_struct {
 #define VC_CAPSLOCK	2	/* capslock mode */
 #define VC_KANALOCK	3	/* kanalock mode */
 
-	unsigned char kbdmode:2;	/* one 2-bit value */
+	unsigned char kbdmode:3;	/* one 3-bit value */
 #define VC_XLATE	0	/* translate keycodes using keymap */
 #define VC_MEDIUMRAW	1	/* medium raw (keycode) mode */
 #define VC_RAW		2	/* raw (scancode) mode */
 #define VC_UNICODE	3	/* Unicode mode */
+#define VC_OFF		4	/* disabled mode */
 
 	unsigned char modeflags:5;
 #define VC_APPLIC	0	/* application key mode */
diff --git a/include/linux/kd.h b/include/linux/kd.h
index 15f2853..c36d847 100644
--- a/include/linux/kd.h
+++ b/include/linux/kd.h
@@ -81,6 +81,7 @@ struct unimapinit {
 #define		K_XLATE		0x01
 #define		K_MEDIUMRAW	0x02
 #define		K_UNICODE	0x03
+#define		K_OFF		0x04
 #define KDGKBMODE	0x4B44	/* gets current keyboard mode */
 #define KDSKBMODE	0x4B45	/* sets current keyboard mode */
 


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

* Re: [PATCH] [resend] vt: Add virtual console keyboard mode OFF
  2011-02-02  2:07   ` [PATCH] [resend] " Arthur Taylor
@ 2011-02-03 18:48     ` Greg KH
  2011-02-04 21:55       ` Arthur Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2011-02-03 18:48 UTC (permalink / raw)
  To: Arthur Taylor; +Cc: Greg KH, linux-kernel, akpm, Pavel Machek

On Tue, Feb 01, 2011 at 06:07:32PM -0800, Arthur Taylor wrote:
> On Mon, 2011-01-31 at 09:46 -0800, Greg KH wrote:
> > Care to document this somewhere (i.e. Documentation/ABI?)
> Sure. Can it wait for a future patch though as currently all VT IOCTLs
> aren't documented in the source tree. I'm willing to write said
> documentation.

Ok, that is fine, but care to do it as part of the requirements to get
this patch in?  Yeah, it's not fair, but it ensures that the
documentation gets written :)

> > Your patch is line-wrapped and can not be applied :(
> Fixed in this mail (hopefully).

Yes, looks good.

> > Are you sure you can change the size of this structure and no one is
> > going to have problems?
> >From what I can tell, no. kbd_struct and it's members are defined in the
> non-exported kbd_kern.h, and it is never packed into weird places. Is
> that sufficient? What else should be checked?

No, you are correct.

> 
> > Also, what userspace code is going to use this new feature?  Has it been
> > tested to work properly?
> Xorg is the intended user. In short, reasons for the feature are:
>       * Removes having to flush unnecessary duplicate data.
>       * Fixes an Xorg corner case.
>       * Less code run in both kernel and userspace per key event (I know
>         kinda meh, but hey, it's a plus.)
> 
> Since the switch to evdev and automatic input device detection, Xorg
> sets the console to RAW to disable kernel special key handling and
> flushes the console input buffer per key event.
> 
> If Xorg is configured with static input device definitions, it can't
> flush the input in case the older kbd driver is in use, leading to the
> buffer filling. If the console input buffer fills, bad things happen
> (which I'm currently looking into as well.)
> 
> I modified my xserver to use this feature. I tested Xorg with the
> input-evdev and input-kbd drivers for keyboard events. Since input-kbd
> sets the keyboard back to RAW when needed, everything is fine. If
> input-kbd isn't in use, the keyboard stays in OFF and he input buffer is
> always kept empty, things always work. Shift key states are maintained,
> and SysRq's unRaw function is still works as expected.

Are the xorg patches upstream and accepted or are they waiting for this
change?  Will they work properly with the BSDs as well?

> To: Greg Kroah-Hartman <gregkh@suse.de>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Arthur Taylor <art@ified.ca>

Thanks for the information, but we also need the original changelog
comment here for me to be able to apply it.

Care to resend with all of the text correct?

thanks,

greg k-h

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

* Re: [PATCH] [resend] vt: Add virtual console keyboard mode OFF
  2011-02-03 18:48     ` Greg KH
@ 2011-02-04 21:55       ` Arthur Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Arthur Taylor @ 2011-02-04 21:55 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, akpm, Pavel Machek

On Thu, 2011-02-03 at 10:48 -0800, Greg KH wrote:
> Are the xorg patches upstream and accepted or are they waiting for this
> change?  Will they work properly with the BSDs as well?

The Xorg patches requires this change to exist first to make sense,
hence is not upstream. The Xorg code which requires changing is in the
platform specific support code for linux
(xserver/hw/xfree86/os-support/linux/lnx_init.c) so I don't think the
BSDs even had the problem to begin with.

> Thanks for the information, but we also need the original changelog
> comment here for me to be able to apply it.
> 
> Care to resend with all of the text correct?

Hopefully this is correct. Thanks for the help, this is my first time
using the lkml.
---
commit ee6be802d3cfaba8e1693ec7ad266077bb89ccd6
Author: Arthur Taylor <art@ified.ca>
Date:   Sun Jan 30 00:13:03 2011 -0800

    virtual console: add keyboard mode OFF
    
    Add a new mode for the virtual console keyboard OFF in which all input
    other than shift keys is ignored. Prevents vt input buffers from
    overflowing when a program opens but doesn't read from a tty, like X11
    using evdev for input.
    
    Signed-off-by: Arthur Taylor <art@ified.ca>
---
 drivers/tty/vt/keyboard.c |    5 +++--
 drivers/tty/vt/vt_ioctl.c |    3 +++
 include/linux/kbd_kern.h  |    3 ++-
 include/linux/kd.h        |    1 +
 4 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index e95d787..6dd3c68 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -654,7 +654,8 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
 	if (value >= ARRAY_SIZE(fn_handler))
 		return;
 	if ((kbd->kbdmode == VC_RAW ||
-	     kbd->kbdmode == VC_MEDIUMRAW) &&
+	     kbd->kbdmode == VC_MEDIUMRAW ||
+	     kbd->kbdmode == VC_OFF) &&
 	     value != KVAL(K_SAK))
 		return;		/* SAK is allowed even in raw mode */
 	fn_handler[value](vc);
@@ -1295,7 +1296,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
 	if (rc == NOTIFY_STOP)
 		return;
 
-	if (raw_mode && type != KT_SPEC && type != KT_SHIFT)
+	if ((raw_mode || kbd->kbdmode == VC_OFF) && type != KT_SPEC && type != KT_SHIFT)
 		return;
 
 	(*k_handler[type])(vc, keysym & 0xff, !down);
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
index 1235ebd..6bcf05b 100644
--- a/drivers/tty/vt/vt_ioctl.c
+++ b/drivers/tty/vt/vt_ioctl.c
@@ -688,6 +688,9 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
 			kbd->kbdmode = VC_UNICODE;
 			compute_shiftstate();
 			break;
+		  case K_OFF:
+			kbd->kbdmode = VC_OFF;
+			break;
 		  default:
 			ret = -EINVAL;
 			goto out;
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index 506ad20..4b0761c 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -50,11 +50,12 @@ struct kbd_struct {
 #define VC_CAPSLOCK	2	/* capslock mode */
 #define VC_KANALOCK	3	/* kanalock mode */
 
-	unsigned char kbdmode:2;	/* one 2-bit value */
+	unsigned char kbdmode:3;	/* one 3-bit value */
 #define VC_XLATE	0	/* translate keycodes using keymap */
 #define VC_MEDIUMRAW	1	/* medium raw (keycode) mode */
 #define VC_RAW		2	/* raw (scancode) mode */
 #define VC_UNICODE	3	/* Unicode mode */
+#define VC_OFF		4	/* disabled mode */
 
 	unsigned char modeflags:5;
 #define VC_APPLIC	0	/* application key mode */
diff --git a/include/linux/kd.h b/include/linux/kd.h
index 15f2853..c36d847 100644
--- a/include/linux/kd.h
+++ b/include/linux/kd.h
@@ -81,6 +81,7 @@ struct unimapinit {
 #define		K_XLATE		0x01
 #define		K_MEDIUMRAW	0x02
 #define		K_UNICODE	0x03
+#define		K_OFF		0x04
 #define KDGKBMODE	0x4B44	/* gets current keyboard mode */
 #define KDSKBMODE	0x4B45	/* sets current keyboard mode */
 


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

end of thread, other threads:[~2011-02-04 21:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-30  8:36 [PATCH] vt: Add virtual console keyboard mode OFF Arthur Taylor
2011-01-31  7:40 ` Pavel Machek
2011-01-31 17:46 ` Greg KH
2011-02-02  2:07   ` [PATCH] [resend] " Arthur Taylor
2011-02-03 18:48     ` Greg KH
2011-02-04 21:55       ` Arthur Taylor

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.