Skip to contentSkip to conversation

2.6.36/2.6.37: broken compatibility with userspace input-utils ?

DISCUSSION Applied Mark Lord 6 participants 94 messages Jan 23, 2011 – Feb 2, 2011

Subsystems (2)
lore
Share & tools
lore

Mark Lord

author
#0 lore raw

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

At first glance, this looks like a visible regression. Is there a version of input-utils that works with both old and new kernels ?

Thanks

#1 lore raw

Hi Mark,

Quoted 9 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

At first glance, this looks like a visible regression. Is there a version of input-utils that works with both old and new kernels ?

The event protocol number was updated to reflect support of large scancodes, unfortunately some of the utilities expected exact version and refuse to work with updated one. Ubuntu's fix was simply recompile the code using the new define, this make it work on newer kernels but of course broke the old ones...

Signature · 1 line
Dmitry
author
#2 lore raw
Quoted 8 lines · Dmitry Torokhov

Hi Mark,

Quoted 5 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

Quoted 8 lines
Quoted 4 lines

At first glance, this looks like a visible regression. Is there a version of input-utils that works with both old and new kernels ?

The event protocol number was updated to reflect support of large scancodes, unfortunately some of the utilities expected exact version and refuse to work with updated one.

So is there a danger of memory corruption if running a binary that doesn't check the version number?

In other words, did the size and/or format of returned data change for an ioctl() or something here?

If so, then that is a user-visible regression, and shouldn't happen. One correct way to handle that, would be to create a new ioctl(), and mark the old one as deprecated, for removal a few years later perhaps.

???

Thanks

#3 lore raw
Quoted 14 lines · Mark Lord
Quoted 13 lines · Dmitry Torokhov

Hi Mark,

Quoted 9 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

At first glance, this looks like a visible regression. Is there a version of input-utils that works with both old and new kernels ?

Quoted 8 lines
Quoted 3 lines

The event protocol number was updated to reflect support of large scancodes, unfortunately some of the utilities expected exact version and refuse to work with updated one.

So is there a danger of memory corruption if running a binary that doesn't check the version number?

No, as far as I know we kept ABI intact.

Quoted 2 lines

In other words, did the size and/or format of returned data change for an ioctl() or something here?

Yes, we introduced new ioctls (keeping old ones and their ABI intact). The change is that EVIOCGVERSION ioctl now returns 0x10001 instead of 0x10000.

Quoted 6 lines

If so, then that is a user-visible regression, and shouldn't happen. One correct way to handle that, would be to create a new ioctl(), and mark the old one as deprecated, for removal a few years later perhaps.

???

Right.

However a few input utilities insist that they will only work with event protocol version 0x10000. It is purely their choice, however misguided it might be.

Signature · 1 line
Dmitry
author
#4 lore raw
Quoted 2 lines · Dmitry Torokhov

No, as far as I know we kept ABI intact.

Okay, I hacked lsinput and input-kbd to ignore the protocol number. input-kbd is still broken: it thinks my remote control (Hauppauge) has only ten buttons, and won't allow me to remap codes larger than 10.

I've now hacked around that too, but without determining exactly where the interface got broken.

Ugh.

Thanks.

#5 lore raw
Quoted 5 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

No, as far as I know we kept ABI intact.

Quoted 9 lines

Okay, I hacked lsinput and input-kbd to ignore the protocol number. input-kbd is still broken: it thinks my remote control (Hauppauge) has only ten buttons, and won't allow me to remap codes larger than 10.

I've now hacked around that too, but without determining exactly where the interface got broken.

Ugh.

Where are the sources? I can take a look...

Signature · 1 line
Dmitry
author
#6 lore raw
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

No, as far as I know we kept ABI intact.

Okay, I hacked lsinput and input-kbd to ignore the protocol number. input-kbd is still broken: it thinks my remote control (Hauppauge) has only ten buttons, and won't allow me to remap codes larger than 10.

Quoted 7 lines
Quoted 5 lines

I've now hacked around that too, but without determining exactly where the interface got broken.

Ugh.

Where are the sources? I can take a look...

I used "apt-get source input-utils" under Ubuntu-10.10. The problem seems to be here somewhere:

static struct kbd_map* kbd_map_read(int fd)

{
        struct kbd_entry entry;
        struct kbd_map *map;
        int rc;

        map = malloc(sizeof(*map));
        memset(map,0,sizeof(*map));
        for (map->size = 0; map->size < 65536; map->size++) {
                entry.scancode = map->size;
                entry.keycode  = KEY_RESERVED;
                rc = ioctl(fd, EVIOCGKEYCODE, &entry);
                if (rc < 0) {
                        break;
                }
                if (map->size >= map->alloc) {
                        map->alloc += 64;
                        map->map = realloc(map->map, map->alloc * sizeof(entry));
                }
                map->map[map->size] = entry;

                if (KEY_RESERVED != entry.keycode)
                        map->keys++;
        }
        if (map->keys) {
                printf("map: %d keys, size: %d/%d\n",
                        map->keys, map->size, map->alloc);
                return map;
        } else {
                free(map);
                return NULL;
        }
}

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

author
#7 lore raw
Quoted 36 lines · Mark Lord
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

No, as far as I know we kept ABI intact.

Okay, I hacked lsinput and input-kbd to ignore the protocol number. input-kbd is still broken: it thinks my remote control (Hauppauge) has only ten buttons, and won't allow me to remap codes larger than 10.

Quoted 7 lines
Quoted 5 lines

I've now hacked around that too, but without determining exactly where the interface got broken.

Ugh.

Where are the sources? I can take a look...

I used "apt-get source input-utils" under Ubuntu-10.10. The problem seems to be here somewhere:

static struct kbd_map* kbd_map_read(int fd)

{
        struct kbd_entry entry;
        struct kbd_map *map;
        int rc;

        map = malloc(sizeof(*map));
        memset(map,0,sizeof(*map));
        for (map->size = 0; map->size < 65536; map->size++) {
                entry.scancode = map->size;
                entry.keycode  = KEY_RESERVED;
                rc = ioctl(fd, EVIOCGKEYCODE, &entry);
                if (rc < 0) {
                        break;

...

Quoted 6 lines

}

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

I hacked input-kbd to ignore the map->size calculated above when writing a new map.. seems to work. Weird that the old method stopped working with 2.6.36, though.

I'm using this with ir-kbd-i2c.c as the hardware driver for the hauppauge R/C interface on a PVR-250 card.

Hey.. perhaps you may also know where in the code this thing is being forced to a repeat rate of about 4 times/sec max? I'd like the remote to be slightly faster that this, but my 2.5.35 (and earlier) hacks to ir-kbd-i2c now don't work for repeat intervals less than approx 220msecs.

Cheers!

#8 lore raw
In reply to Mark Lord
Quoted 56 lines · Mark Lord
Quoted 10 lines · Dmitry Torokhov
Quoted 9 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

No, as far as I know we kept ABI intact.

Okay, I hacked lsinput and input-kbd to ignore the protocol number. input-kbd is still broken: it thinks my remote control (Hauppauge) has only ten buttons, and won't allow me to remap codes larger than 10.

Quoted 7 lines
Quoted 5 lines

I've now hacked around that too, but without determining exactly where the interface got broken.

Ugh.

Where are the sources? I can take a look...

I used "apt-get source input-utils" under Ubuntu-10.10. The problem seems to be here somewhere:

static struct kbd_map* kbd_map_read(int fd)

{
        struct kbd_entry entry;
        struct kbd_map *map;
        int rc;

        map = malloc(sizeof(*map));
        memset(map,0,sizeof(*map));
        for (map->size = 0; map->size < 65536; map->size++) {
                entry.scancode = map->size;
                entry.keycode  = KEY_RESERVED;
                rc = ioctl(fd, EVIOCGKEYCODE, &entry);
                if (rc < 0) {
                        break;
                }
                if (map->size >= map->alloc) {
                        map->alloc += 64;
                        map->map = realloc(map->map, map->alloc * sizeof(entry));
                }
                map->map[map->size] = entry;

                if (KEY_RESERVED != entry.keycode)
                        map->keys++;
        }
        if (map->keys) {
                printf("map: %d keys, size: %d/%d\n",
                        map->keys, map->size, map->alloc);
                return map;
        } else {
                free(map);
                return NULL;
        }
}
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

Thanks.

Signature · 1 line
Dmitry
author
#9 lore raw
Quoted 1 line · Dmitry Torokhov

On Mon, Jan 24, 2011 at 11:37:06PM -0500, Mark Lord wrote:

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Thanks.

author
#10 lore raw
Quoted 24 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

On Mon, Jan 24, 2011 at 11:37:06PM -0500, Mark Lord wrote:

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

This is a BUG. Returning -EINVAL here is entirely wrong.

Cheers

author
#11 lore raw
Quoted 1 line · Mark Lord

On 11-01-25 12:04 AM, Mark Lord wrote:

..

Quoted 7 lines
Quoted 7 lines

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

Actually, what changed could be something different:
it's possible that this bug was always there, and older kernels had a more complete default keymap for the remote than that in 2.6.36+, thereby never triggering the bug. But I don't know that, and my best efforts to-date to locate any of this in the kernel have been futile. Oh well. :)

Quoted 13 lines
Quoted 3 lines

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

This is a BUG. Returning -EINVAL here is entirely wrong.

#12 lore raw
In reply to Mark Lord
Quoted 33 lines · Mark Lord
Quoted 24 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

On Mon, Jan 24, 2011 at 11:37:06PM -0500, Mark Lord wrote:

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Quoted 8 lines

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

Thanks.

Signature · 1 line
Dmitry
#13 lore raw
Quoted 39 lines · Dmitry Torokhov
Quoted 38 lines · Mark Lord
Quoted 24 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

On Mon, Jan 24, 2011 at 11:37:06PM -0500, Mark Lord wrote:

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

Quoted 9 lines
Quoted 3 lines

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

Thanks.

BTW, could you please try the following patch (it assumes that EVIOCGVERSION in input.c is alreday relaxed).

Thanks!

Signature · 1 line
Dmitry
Quoted 1 line

From c22c85c0b675422a23e3d853ed06fedc36805774 Mon Sep 17 00:00:00 2001

From: Dmitry Torokhov <[email protected]>
Date: Mon, 24 Jan 2011 22:49:59 -0800
Subject: [PATCH] input-kbd - switch to using EVIOCGKEYCODE2 when available

---
 input-kbd.c |  118 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 80 insertions(+), 38 deletions(-)
input-kbd.c +80 -38
index e94529d..5d93d54 100644
@@ -9,9 +9,27 @@
 
 #include "input.h"
 
+struct input_keymap_entry_v1 {
+	uint32_t scancode;
+	uint32_t keycode;
+};
+
+struct input_keymap_entry_v2 {
+#define KEYMAP_BY_INDEX	(1 << 0)
+	uint8_t  flags;
+	uint8_t  len;
+	uint16_t index;
+	uint32_t keycode;
+	uint8_t  scancode[32];
+};
+
+#ifndef EVIOCGKEYCODE2
+#define EVIOCGKEYCODE2 _IOR('E', 0x04, struct input_keymap_entry_v2)
+#endif
+
 struct kbd_entry {
-	int scancode;
-	int keycode;
+	unsigned int scancode;
+	unsigned int keycode;
 };
 
 struct kbd_map {
@@ -23,7 +41,7 @@ struct kbd_map {
 
 /* ------------------------------------------------------------------ */
 
-static struct kbd_map* kbd_map_read(int fd)
+static struct kbd_map* kbd_map_read(int fd, unsigned int version)
 {
 	struct kbd_entry entry;
 	struct kbd_map *map;
@@ -32,16 +50,37 @@ static struct kbd_map* kbd_map_read(int fd)
 	map = malloc(sizeof(*map));
 	memset(map,0,sizeof(*map));
 	for (map->size = 0; map->size < 65536; map->size++) {
-		entry.scancode = map->size;
-		entry.keycode  = KEY_RESERVED;
-		rc = ioctl(fd, EVIOCGKEYCODE, &entry);
-		if (rc < 0) {
-			break;
+		if (version < 0x10001) {
+			struct input_keymap_entry_v1 ke = {
+				.scancode = map->size,
+				.keycode = KEY_RESERVED,
+			};
+
+			rc = ioctl(fd, EVIOCGKEYCODE, &ke);
+			if (rc < 0)
+				break;
+		} else {
+			struct input_keymap_entry_v2 ke = {
+				.index = map->size,
+				.flags = KEYMAP_BY_INDEX,
+				.len = sizeof(uint32_t),
+				.keycode = KEY_RESERVED,
+			};
+
+			rc = ioctl(fd, EVIOCGKEYCODE2, &ke);
+			if (rc < 0)
+				break;
+
+			memcpy(&entry.scancode, ke.scancode,
+				sizeof(entry.scancode));
+			entry.keycode = ke.keycode;
 		}
+
 		if (map->size >= map->alloc) {
 			map->alloc += 64;
 			map->map = realloc(map->map, map->alloc * sizeof(entry));
 		}
+
 		map->map[map->size] = entry;
 
 		if (KEY_RESERVED != entry.keycode)
@@ -155,40 +194,27 @@ static void kbd_print_bits(int fd)
 	}
 }
 
-static void show_kbd(int nr)
+static void show_kbd(int fd, unsigned int protocol_version)
 {
 	struct kbd_map *map;
-	int fd;
 
-	fd = device_open(nr,1);
-	if (-1 == fd)
-		return;
 	device_info(fd);
 
-	map = kbd_map_read(fd);
-	if (NULL != map) {
-		kbd_map_print(stdout,map,0);
-	} else {
+	map = kbd_map_read(fd, protocol_version);
+	if (map)
+		kbd_map_print(stdout, map, 0);
+	else
 		kbd_print_bits(fd);
-	}
-
-	close(fd);
 }
 
-static int set_kbd(int nr, char *mapfile)
+static int set_kbd(int fd, unsigned int protocol_version, char *mapfile)
 {
 	struct kbd_map *map;
 	FILE *fp;
-	int fd;
-
-	fd = device_open(nr,1);
-	if (-1 == fd)
-		return -1;
 
-	map = kbd_map_read(fd);
+	map = kbd_map_read(fd, protocol_version);
 	if (NULL == map) {
 		printf("device has no map\n");
-		close(fd);
 		return -1;
 	}
 
@@ -198,18 +224,15 @@ static int set_kbd(int nr, char *mapfile)
 		fp = fopen(mapfile,"r");
 		if (NULL == fp) {
 			printf("open %s: %s\n",mapfile,strerror(errno));
-			close(fd);
 			return -1;
 		}
 	}
-	
+
 	if (0 != kbd_map_parse(fp,map) ||
 	    0 != kbd_map_write(fd,map)) {
-		close(fd);
 		return -1;
 	}
 
-	close(fd);
 	return 0;
 }
 
@@ -223,8 +246,10 @@ static int usage(char *prog, int error)
 
 int main(int argc, char *argv[])
 {
-	int c,devnr;
+	int c, devnr, fd;
 	char *mapfile = NULL;
+	unsigned int protocol_version;
+	int rc = EXIT_FAILURE;
 
 	for (;;) {
 		if (-1 == (c = getopt(argc, argv, "hf:")))
@@ -244,12 +269,29 @@ int main(int argc, char *argv[])
 		usage(argv[0],1);
 
 	devnr = atoi(argv[optind]);
-	if (mapfile) {
-		set_kbd(devnr,mapfile);
-	} else {
-		show_kbd(devnr);
+
+	fd = device_open(devnr, 1);
+	if (fd < 0)
+		goto out;
+
+	if (ioctl(fd, EVIOCGVERSION, &protocol_version) < 0) {
+		fprintf(stderr,
+			"Unable to query evdev protocol version: %s\n",
+			strerror(errno));
+		goto out_close;
 	}
-	return 0;
+
+	if (mapfile)
+		set_kbd(fd, protocol_version, mapfile);
+	else
+		show_kbd(fd, protocol_version);
+
+	rc = EXIT_SUCCESS;
+
+out_close:
+	close(fd);
+out:
+	return rc;
 }
 
 /* ---------------------------------------------------------------------
Signature · 1 line
1.7.3.4
#14 lore raw

Extending rc-core/userspace to handle bigger scancodes - Was: Re: 2.6.36/2.6.37: broken compatibility with userspace input-utils ?

Em 25-01-2011 04:52, Dmitry Torokhov escreveu:

Quoted 44 lines · Dmitry Torokhov
Quoted 43 lines · Mark Lord
Quoted 41 lines · Mark Lord
Quoted 24 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

Quoted 8 lines
Quoted 5 lines

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

Thanks.

BTW, could you please try the following patch (it assumes that EVIOCGVERSION in input.c is alreday relaxed).

Dmitry,

Thanks for your patch. I used part of his logic to improve the ir-keytable tool at v4l-utils:
http://git.linuxtv.org/v4l-utils.git

The ir-keytable is a tool that just handles Remote Controller input devices, and do it well, allowing all sorts of operations related to it, and using the sysfs /sys/class/rc stuff to help its operation. Without any arguments, it lists the existing RC devices. Arguments are there to allow enabling/disabling RC protocols, reading/writing/cleaning keycode tables and to test if the remote is generating events (EV_MSC/EV_KEY/EV_REP/EV_SYN).

Now, it will be using V2 for reads and keycode cleanups, but will still use V1 for writes, as, currently with 32 bits scancodes, there's no gain to use V2 for it. Also, changing the tool to use more bits will require to rewrite part of the code.

Also, writing a rc-core code that can work with an arbitrary large scancode is still on our TODO list.

I'm not entirely sure how to extend the scancode size, as there are a few options:
1) Core would always work internally with 32 bytes (1024 bits). Some
logic will be required to accept entries with .len < 32;
2) Drivers will define the code lengtht, and core will use it,
returning -EINVAL if userspace uses a len grater than used internally by the core. In this case, we'll need a sysfs node to tell userspace what's the maximum allowed size;
3) Drivers will define the max number of bits, and core will use it,
truncating the number to the max size if userspace tries to write more bits than the internal representation;
4) Drivers will define the max number of bits, and core will use it,
returning an error if the number is bigger than the max scancode that can be represented internally.

I think that (2) is the best way for doing it, but I'm not yet entirely sure. So, it is good to hear some comments about that.

Cheers,
Mauro

#15 lore raw

Re: Extending rc-core/userspace to handle bigger scancodes - Was: Re: 2.6.36/2.6.37: broken compatibility with userspace input-utils ?

Quoted 90 lines · Mauro Carvalho Chehab

Em 25-01-2011 04:52, Dmitry Torokhov escreveu:

Quoted 44 lines · Dmitry Torokhov
Quoted 43 lines · Mark Lord
Quoted 41 lines · Mark Lord
Quoted 24 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

Quoted 8 lines
Quoted 5 lines

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

Thanks.

BTW, could you please try the following patch (it assumes that EVIOCGVERSION in input.c is alreday relaxed).

Dmitry,

Thanks for your patch. I used part of his logic to improve the ir-keytable tool at v4l-utils:
http://git.linuxtv.org/v4l-utils.git

The ir-keytable is a tool that just handles Remote Controller input devices, and do it well, allowing all sorts of operations related to it, and using the sysfs /sys/class/rc stuff to help its operation. Without any arguments, it lists the existing RC devices. Arguments are there to allow enabling/disabling RC protocols, reading/writing/cleaning keycode tables and to test if the remote is generating events (EV_MSC/EV_KEY/EV_REP/EV_SYN).

Now, it will be using V2 for reads and keycode cleanups, but will still use V1 for writes, as, currently with 32 bits scancodes, there's no gain to use V2 for it. Also, changing the tool to use more bits will require to rewrite part of the code.

Also, writing a rc-core code that can work with an arbitrary large scancode is still on our TODO list.

I'm not entirely sure how to extend the scancode size, as there are a few options:
1) Core would always work internally with 32 bytes (1024 bits). Some
logic will be required to accept entries with .len < 32;
2) Drivers will define the code lengtht, and core will use it,
returning -EINVAL if userspace uses a len grater than used internally by the core. In this case, we'll need a sysfs node to tell userspace what's the maximum allowed size;
3) Drivers will define the max number of bits, and core will use it,
truncating the number to the max size if userspace tries to write more bits than the internal representation;
4) Drivers will define the max number of bits, and core will use it,
returning an error if the number is bigger than the max scancode that can be represented internally.

Quoted 2 lines

I think that (2) is the best way for doing it, but I'm not yet entirely sure. So, it is good to hear some comments about that.

I'd say 4 and userspace utility should normalize scancodes packing them into the least number of bits possible. Since keymap should be device specific data in the keymap will not exceed what the driver expects, right?

Signature · 1 line
Dmitry
#16 lore raw

Re: Extending rc-core/userspace to handle bigger scancodes - Was: Re: 2.6.36/2.6.37: broken compatibility with userspace input-utils ?

Em 25-01-2011 14:55, Dmitry Torokhov escreveu:

Quoted 91 lines · Mauro Carvalho Chehab
Quoted 90 lines

Em 25-01-2011 04:52, Dmitry Torokhov escreveu:

Quoted 44 lines · Dmitry Torokhov
Quoted 43 lines · Mark Lord
Quoted 41 lines · Mark Lord
Quoted 24 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

Quoted 8 lines
Quoted 5 lines

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

Thanks.

BTW, could you please try the following patch (it assumes that EVIOCGVERSION in input.c is alreday relaxed).

Dmitry,

Thanks for your patch. I used part of his logic to improve the ir-keytable tool at v4l-utils:
http://git.linuxtv.org/v4l-utils.git

The ir-keytable is a tool that just handles Remote Controller input devices, and do it well, allowing all sorts of operations related to it, and using the sysfs /sys/class/rc stuff to help its operation. Without any arguments, it lists the existing RC devices. Arguments are there to allow enabling/disabling RC protocols, reading/writing/cleaning keycode tables and to test if the remote is generating events (EV_MSC/EV_KEY/EV_REP/EV_SYN).

Now, it will be using V2 for reads and keycode cleanups, but will still use V1 for writes, as, currently with 32 bits scancodes, there's no gain to use V2 for it. Also, changing the tool to use more bits will require to rewrite part of the code.

Also, writing a rc-core code that can work with an arbitrary large scancode is still on our TODO list.

I'm not entirely sure how to extend the scancode size, as there are a few options:
1) Core would always work internally with 32 bytes (1024 bits). Some
logic will be required to accept entries with .len < 32;
2) Drivers will define the code lengtht, and core will use it,
returning -EINVAL if userspace uses a len grater than used internally by the core. In this case, we'll need a sysfs node to tell userspace what's the maximum allowed size;
3) Drivers will define the max number of bits, and core will use it,
truncating the number to the max size if userspace tries to write more bits than the internal representation;
4) Drivers will define the max number of bits, and core will use it,
returning an error if the number is bigger than the max scancode that can be represented internally.

Quoted 6 lines
Quoted 2 lines

I think that (2) is the best way for doing it, but I'm not yet entirely sure. So, it is good to hear some comments about that.

I'd say 4 and userspace utility should normalize scancodes packing them into the least number of bits possible. Since keymap should be device specific data in the keymap will not exceed what the driver expects, right?

Well, it depends on what you name "device" ;) If you call it the Linux device that will handle the Remote Controller, then, the keymap is not driver-specific data.

They will follow one of the protocol standards, like RC-5 (14 bits), NEC (16 bits), NEC EXTENDED (24 bits), some NEC variants with 32 bits, RC6 (there are several modes, and the key length depends on what mode is used, ranging from 16 to 64 bits).

The problem is that some drivers support the NEC protocol, with 16 bits, plus 16 bits of checksum, but doesn't support the variants that (ab)use the checksum bits to extend it to 24 or 32 bits. So, if we do (4), the userspace program will clean the keytable but will fail on the new keytable programming.

Currently, the driver exports the supported protocols, but it doesn't export the protocol variants. Maybe the better would be to also export the supported protocol variants via sysfs.

Cheers,
Mauro

#17 lore raw
In reply to Dmitry Torokhov

Em 25-01-2011 03:31, Dmitry Torokhov escreveu:

Quoted 39 lines · Mark Lord
Quoted 38 lines · Mark Lord
Quoted 24 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

Quoted 6 lines
Quoted 3 lines

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

I lost part of the thread, but a quick search via the Internet showed that you're using the input tools to work with a Remote Controller, right? Are you using a vanilla kernel, or are you using the media_build backports? There are some distros that are using those backports also like Fedora 14.

In the latter case, I found the reason why the backports were not working and I fixed it a couple days ago:

	http://git.linuxtv.org/media_build.git?a=commit;h=b83dc3e49d90527d8e1016d09e06f4842a6a847a

The issue is simple, and it is related on how the input.c used to handle EVIOSGKEYCODE. Basically, before allowing you to change a key, it used to call EVIOCGKEYCODE to check it that key exists. However, when you're creating a new association, the key didn't exist, and, to be strict with input rules, EVIOCGKEYCODE should return -EINVAL. To circumvent that behaviour, old versions were returning 0, and associating unmapped scancodes to KEY_RESERVED. We used this workaround for a few kernel versions, while we were discussing the improvements so support larger scancodes.

Yet, on all vanilla kernels, changing the keycode association works fine.

However, the backport patch at media_build were not taking this workaround into account, and were just returning -EINVAL. So, the backported media drivers stopped allowing some keytable changes. The patch above fixes it.

Cheers,
Mauro

author
#18 lore raw
Quoted 5 lines · Mauro Carvalho Chehab

I lost part of the thread, but a quick search via the Internet showed that you're using the input tools to work with a Remote Controller, right? Are you using a vanilla kernel, or are you using the media_build backports? There are some distros that are using those backports also like Fedora 14.

I use kernel.org kernels exclusively.

Quoted 4 lines

The issue is simple, and it is related on how the input.c used to handle EVIOSGKEYCODE. Basically, before allowing you to change a key, it used to call EVIOCGKEYCODE to check it that key exists. However, when you're creating a new association, the key didn't exist, and, to be strict with input rules, EVIOCGKEYCODE should return -EINVAL.

No, if the parameters are a valid key, then -EINVAL is never the correct thing for a kernel to return. -EINVAL means "bad parameters", and that's not an accurate description of a valid yet unmapped key.

Quoted 3 lines

To circumvent that behaviour, old versions were returning 0, and associating unmapped scancodes to KEY_RESERVED. We used this workaround for a few kernel versions, while we were discussing the improvements so support larger scancodes.

And now we're stuck with it. If that is how it works, and userspace depends upon it (it does), then consider it cast in stone. Immutable by Linus's Law: don't break userspace.

Create a new ioctl() number for the new behaviour, but preserve the old behaviour in exact form for a suitable (multi-year) overlap period.

Cheers

#19 lore raw
In reply to Mauro Carvalho Chehab
Quoted 52 lines · Mauro Carvalho Chehab

Em 25-01-2011 03:31, Dmitry Torokhov escreveu:

Quoted 39 lines · Mark Lord
Quoted 38 lines · Mark Lord
Quoted 24 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

..

Quoted 6 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

Quoted 8 lines

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

Quoted 7 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Note that this device DOES have "flat scancode space", and the kernel is now incorrectly signalling an error (-EINVAL) in response to a perfectly valid query of a VALID (and mappable) keycode on the remote control

Quoted 6 lines
Quoted 3 lines

The code really is a valid button, it just doesn't have a default mapping set by the kernel (I can set a mapping for that code from userspace and it works).

OK, in this case let's ping Mauro - I think he done the adjustments to IR keymap hanlding.

I lost part of the thread, but a quick search via the Internet showed that you're using the input tools to work with a Remote Controller, right? Are you using a vanilla kernel, or are you using the media_build backports? There are some distros that are using those backports also like Fedora 14.

Quoted 8 lines

In the latter case, I found the reason why the backports were not working and I fixed it a couple days ago:

	http://git.linuxtv.org/media_build.git?a=commit;h=b83dc3e49d90527d8e1016d09e06f4842a6a847a

The issue is simple, and it is related on how the input.c used to handle EVIOSGKEYCODE. Basically, before allowing you to change a key, it used to call EVIOCGKEYCODE to check it that key exists. However, when you're creating a new association, the key didn't exist, and, to be strict with input rules, EVIOCGKEYCODE should return -EINVAL.

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

Signature · 1 line
Dmitry
#20 lore raw
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change and the buggy EINVAL return both.

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

Linus

#21 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Quoted 1 line

and the buggy EINVAL return both.

I believe that -EINVAL thing only affects RC devices that Mauro switched to the new rc-core; input core in itself should be ABI compatible. Thus I'll leave the decision to him whether he wants to revert or fix compatibility issue.

Quoted 4 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 6 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

Signature · 1 line
Dmitry
#22 lore raw
Quoted 36 lines · Dmitry Torokhov
Quoted 10 lines · Linus Torvalds
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Quoted 1 line

and the buggy EINVAL return both.

I believe that -EINVAL thing only affects RC devices that Mauro switched to the new rc-core; input core in itself should be ABI compatible. Thus I'll leave the decision to him whether he wants to revert or fix compatibility issue.

Quoted 4 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

BTW, another issue is that evdev's ioctl returns -EINVAL for unknown ioctls so applications would have hard time figuring out whether error returned because of kernel being too old or because they are trying to retrieve/establish invalid mapping if they had to go only by the error code.

As far as I can see EINVAL is a proper error for unknown ioctls:

[dtor@hammer work]$ man 2 ioctl | grep EINVAL
EINVAL Request or argp is not valid.
[dtor@hammer work]$

Signature · 1 line
Dmitry
#23 lore raw
Quoted 6 lines · Dmitry Torokhov

BTW, another issue is that evdev's ioctl returns -EINVAL for unknown ioctls so applications would have hard time figuring out whether error returned because of kernel being too old or because they are trying to retrieve/establish invalid mapping if they had to go only by the error code.

So that's just another evdev interface bug.

Quoted 4 lines

As far as I can see EINVAL is a proper error for unknown ioctls:

[dtor@hammer work]$ man 2 ioctl | grep EINVAL
      EINVAL Request or argp is not valid.

Yeah, there's some confusion there.

The "unknown ioctl" error code is (for traditional reasons) ENOTTY, but yes, the EINVAL thing admittedly has a lot of legacy use too.

Inside the kernel, the preferred way to say "I don't recognize that ioctl number" is actually ENOIOCTLCMD. That's exactly so that various nested ioctl handlers can then tell the difference between "I didn't recognize that ioctl" and "I understand what you asked me to do, but your arguments were crap".

vfs_ioctl() will then turn ENOIOCTLCMD to EINVAL to return to user space.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#24 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 6 lines · Dmitry Torokhov

BTW, another issue is that evdev's ioctl returns -EINVAL for unknown ioctls so applications would have hard time figuring out whether error returned because of kernel being too old or because they are trying to retrieve/establish invalid mapping if they had to go only by the error code.

So that's just another evdev interface bug.

Huh? I do not have lot of options here as far as error codes go. Invalid request, invalid data in request - all goes to EINVAL.

Quoted 11 lines
Quoted 5 lines

As far as I can see EINVAL is a proper error for unknown ioctls:

[dtor@hammer work]$ man 2 ioctl | grep EINVAL
      EINVAL Request or argp is not valid.

Yeah, there's some confusion there.

The "unknown ioctl" error code is (for traditional reasons) ENOTTY, but yes, the EINVAL thing admittedly has a lot of legacy use too.

Quoted 7 lines

Inside the kernel, the preferred way to say "I don't recognize that ioctl number" is actually ENOIOCTLCMD. That's exactly so that various nested ioctl handlers can then tell the difference between "I didn't recognize that ioctl" and "I understand what you asked me to do, but your arguments were crap".

vfs_ioctl() will then turn ENOIOCTLCMD to EINVAL to return to user space.

OK, so I can change evdev to employ ENOIOCTLCMD where needed, bit that will not change older kernels where such distinction is needed (as never kernels do support newer ioctl). And even if I could go back it would not help since userspace still sees EINVAL only.

Signature · 1 line
Dmitry
#25 lore raw
In reply to Dmitry Torokhov

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

Quoted 11 lines · Linus Torvalds
Quoted 10 lines
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Reverting the version increment is a bad thing. I agree with Dmitry that an application that fails just because the API version were incremented is buggy.

Quoted 3 lines

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Reverting it will also break the ir-keytable userspace program that it is meant to be used by the Remote Controller devices, and uses it to adjust its behaviour to support RC's with more than 16 bits of scancodes.

I agree that it is bad that the ABI broke, but reverting it will cause even more damage.

Quoted 6 lines
Quoted 1 line

and the buggy EINVAL return both.

I believe that -EINVAL thing only affects RC devices that Mauro switched to the new rc-core; input core in itself should be ABI compatible. Thus I'll leave the decision to him whether he wants to revert or fix compatibility issue.

The Remote Controller keycode tables are very sparse. In general, they contain up to 100 entries, and the scan codes typically have 16 bits. Some newer devices have 24 or 32 bits. With version 1, as the table index is the scancode, in order to read all keytables with EVIOCGKEYCODE, the userspace needs to do 2^16 reads (or 2^32 for RC-6 remotes). I don't need to say that this is highly ineffective. So, using V1 doesn't work fine anyway for Remote Controllers.

Btw, ir-keycodestool don't work with V1 and more than 16 bits, because it doesn't scale. I didn't actually checked, but based on Dmitry's patch for input-kbd, it is clear to me that the old version only supports 16 bits scancodes:

Em 25-01-2011 04:52, Dmitry Torokhov escreveu:

Quoted 14 lines

From c22c85c0b675422a23e3d853ed06fedc36805774 Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <[email protected]>
Date: Mon, 24 Jan 2011 22:49:59 -0800
Subject: [PATCH] input-kbd - switch to using EVIOCGKEYCODE2 when available

---
 input-kbd.c |  118 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 80 insertions(+), 38 deletions(-)
input-kbd.c +0 -0
index e94529d..5d93d54 100644

<snip>

input-kbd.c static struct kbd_map* kbd_map_read(int fd) · line 52

Quoted 13 lines
input-kbd.c +1 -1
@@ -23,7 +41,7 @@ struct kbd_map {
 
 /* ------------------------------------------------------------------ */
 
-static struct kbd_map* kbd_map_read(int fd)
+static struct kbd_map* kbd_map_read(int fd, unsigned int version)
 {
 	struct kbd_entry entry;
 	struct kbd_map *map;
@@ -32,16 +50,37 @@ static struct kbd_map* kbd_map_read(int fd)
 	map = malloc(sizeof(*map));
 	memset(map,0,sizeof(*map));
 	for (map->size = 0; map->size < 65536; map->size++) {

See, it will only look into the 16-bits scancode space. There are several remote controllers with 24 bits and 32 bits, so the tool is already broken anyway.

On the tests I did here with an ir-keytable version made before such change, with a Fedora rawhide kernel (2.6.37), I didn't notice any breakage at EVIOCGKEYCODE. I'll do more tests tomorrow with a vanilla Kernel. I'll compile a vanilla 2.6.37 kernel tomorrow and, if needed, write a patch.

Quoted 9 lines
Quoted 5 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

Not arguing in favor of the version numbering, but it is easy to read the version increment at the beginning of the application, and adjust if the code will use EVIOCGKEYCODE or EVIOCGKEYCODE_V2 of the ioctl's, depending on what kernel provides.

Ok, we might be just calling the new ioctl and check for -ENOSYS at the beginning, using some fake arguments.

Quoted 4 lines

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

Regards,
Mauro.

author
#26 lore raw
Quoted 21 lines · Mauro Carvalho Chehab

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

Quoted 11 lines · Linus Torvalds
Quoted 10 lines
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Reverting the version increment is a bad thing. I agree with Dmitry that an application that fails just because the API version were incremented is buggy.

Quoted 3 lines

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Quoted 6 lines

Reverting it will also break the ir-keytable userspace program that it is meant to be used by the Remote Controller devices, and uses it to adjust its behaviour to support RC's with more than 16 bits of scancodes.

I agree that it is bad that the ABI broke, but reverting it will cause even more damage.

There we disagree. Sure it's a very poorly thought out interface, but the way to fix it is to put a new one along side the old, and put the old back the way it was before it got broken.

I'm not making a fuss here for myself -- I'm more than capable of working around new kernel bugs like these, but for every person like me there are likely hundreds of others who simply get frustrated and give up.

If you're worried about Ubuntu's adaptation to the buggy regression, then email their developers (kernel and input-utils packagers) explaining the revert, and they can coordination their kernel and input-utils updates to do the Right Thing.

But for all of the rest of us, our systems are broken by this change.

...

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

Quoted 19 lines

Not arguing in favor of the version numbering, but it is easy to read the version increment at the beginning of the application, and adjust if the code will use EVIOCGKEYCODE or EVIOCGKEYCODE_V2 of the ioctl's, depending on what kernel provides.

Ok, we might be just calling the new ioctl and check for -ENOSYS at the beginning, using some fake arguments.

Quoted 11 lines

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 6 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

#27 lore raw
Quoted 73 lines · Mark Lord
Quoted 21 lines · Mauro Carvalho Chehab

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

Quoted 11 lines · Linus Torvalds
Quoted 10 lines
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Reverting the version increment is a bad thing. I agree with Dmitry that an application that fails just because the API version were incremented is buggy.

Quoted 3 lines

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Quoted 6 lines

Reverting it will also break the ir-keytable userspace program that it is meant to be used by the Remote Controller devices, and uses it to adjust its behaviour to support RC's with more than 16 bits of scancodes.

I agree that it is bad that the ABI broke, but reverting it will cause even more damage.

There we disagree. Sure it's a very poorly thought out interface, but the way to fix it is to put a new one along side the old, and put the old back the way it was before it got broken.

I'm not making a fuss here for myself -- I'm more than capable of working around new kernel bugs like these, but for every person like me there are likely hundreds of others who simply get frustrated and give up.

If you're worried about Ubuntu's adaptation to the buggy regression, then email their developers (kernel and input-utils packagers) explaining the revert, and they can coordination their kernel and input-utils updates to do the Right Thing.

But for all of the rest of us, our systems are broken by this change.

...

Quoted 26 lines
Quoted 7 lines
Quoted 3 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

Not arguing in favor of the version numbering, but it is easy to read the version increment at the beginning of the application, and adjust if the code will use EVIOCGKEYCODE or EVIOCGKEYCODE_V2 of the ioctl's, depending on what kernel provides.

Ok, we might be just calling the new ioctl and check for -ENOSYS at the beginning, using some fake arguments.

Quoted 10 lines

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 6 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

Quoted 6 lines
Quoted 1 line
Quoted 1 line

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

Please calm down. This, in fact, is not new vs old ioctl problem but rather particular driver (or rather set of drivers) implementation issue. Even if we drop the new ioctls and convert the RC code to use the old ones you'd be observing the same breakage as RC code responds with -EINVAL to not-yet-established mappings.

I'll see what can be done for these drivers; I guess we could supply a fake KEY_RESERVED entry for not mapped scancodes if there are mapped scancodes "above" current one. That should result in the same behavior for RCs as before.

Signature · 1 line
Dmitry
#28 lore raw
Quoted 87 lines · Dmitry Torokhov
Quoted 73 lines · Mark Lord
Quoted 21 lines · Mauro Carvalho Chehab

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

Quoted 11 lines · Linus Torvalds
Quoted 10 lines
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Reverting the version increment is a bad thing. I agree with Dmitry that an application that fails just because the API version were incremented is buggy.

Quoted 3 lines

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Quoted 6 lines

Reverting it will also break the ir-keytable userspace program that it is meant to be used by the Remote Controller devices, and uses it to adjust its behaviour to support RC's with more than 16 bits of scancodes.

I agree that it is bad that the ABI broke, but reverting it will cause even more damage.

There we disagree. Sure it's a very poorly thought out interface, but the way to fix it is to put a new one along side the old, and put the old back the way it was before it got broken.

I'm not making a fuss here for myself -- I'm more than capable of working around new kernel bugs like these, but for every person like me there are likely hundreds of others who simply get frustrated and give up.

If you're worried about Ubuntu's adaptation to the buggy regression, then email their developers (kernel and input-utils packagers) explaining the revert, and they can coordination their kernel and input-utils updates to do the Right Thing.

But for all of the rest of us, our systems are broken by this change.

...

Quoted 26 lines
Quoted 7 lines
Quoted 3 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

Not arguing in favor of the version numbering, but it is easy to read the version increment at the beginning of the application, and adjust if the code will use EVIOCGKEYCODE or EVIOCGKEYCODE_V2 of the ioctl's, depending on what kernel provides.

Ok, we might be just calling the new ioctl and check for -ENOSYS at the beginning, using some fake arguments.

Quoted 10 lines

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 6 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

Quoted 6 lines
Quoted 1 line
Quoted 1 line

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

Please calm down. This, in fact, is not new vs old ioctl problem but rather particular driver (or rather set of drivers) implementation issue. Even if we drop the new ioctls and convert the RC code to use the old ones you'd be observing the same breakage as RC code responds with -EINVAL to not-yet-established mappings.

Quoted 5 lines

I'll see what can be done for these drivers; I guess we could supply a fake KEY_RESERVED entry for not mapped scancodes if there are mapped scancodes "above" current one. That should result in the same behavior for RCs as before.

I wonder if the patch below is all that is needed...

Thanks!

Signature · 16 lines
Dmitry


Input: ir-keymap - return KEY_RESERVED for unknown mappings

Do not respond with -EINVAL to EVIOCGKEYCODE for not-yet-mapped scancodes,
but rather return KEY_RESERVED.

This fixes breakage with Ubuntu's input-kbd utility that stopped returning
full keymaps for remote controls.

Signed-off-by: Dmitry Torokhov <[email protected]>
---

 drivers/media/IR/ir-keytable.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)
drivers/media/IR/ir-keytable.c +17 -11
index f60107c..c4645d7 100644
@@ -374,21 +374,27 @@ static int ir_getkeycode(struct input_dev *dev,
 		index = ir_lookup_by_scancode(rc_tab, scancode);
 	}
 
-	if (index >= rc_tab->len) {
-		if (!(ke->flags & INPUT_KEYMAP_BY_INDEX))
-			IR_dprintk(1, "unknown key for scancode 0x%04x\n",
-				   scancode);
+	if (index < rc_tab->len) {
+		entry = &rc_tab->scan[index];
+
+		ke->index = index;
+		ke->keycode = entry->keycode;
+		ke->len = sizeof(entry->scancode);
+		memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
+
+	} else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) {
+		/*
+		 * We do not really know the valid range of scancodes
+		 * so let's respond with KEY_RESERVED to anything we
+		 * do not have mapping for [yet].
+		 */
+		ke->index = index;
+		ke->keycode = KEY_RESERVED;
+	} else {
 		retval = -EINVAL;
 		goto out;
 	}
 
-	entry = &rc_tab->scan[index];
-
-	ke->index = index;
-	ke->keycode = entry->keycode;
-	ke->len = sizeof(entry->scancode);
-	memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
-
 	retval = 0;
 
 out:
#29 lore raw

Hi Dmitry,

Em 26-01-2011 00:00, Dmitry Torokhov escreveu:

Quoted 98 lines · Dmitry Torokhov
Quoted 87 lines · Mark Lord
Quoted 73 lines · Mauro Carvalho Chehab
Quoted 21 lines

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

Quoted 11 lines · Linus Torvalds
Quoted 10 lines
Quoted 6 lines · Dmitry Torokhov

We should be able to handle the case where scancode is valid even though it might be unmapped yet. This is regardless of what version of EVIOCGKEYCODE we use, 1 or 2, and whether it is sparse keymap or not.

Is it possible to validate the scancode by driver?

More appropriately, why not just revert the thing? The version change

Reverting the version increment is a bad thing. I agree with Dmitry that an application that fails just because the API version were incremented is buggy.

Quoted 3 lines

Well, then we'll break Ubuntu again as they recompiled their input-utils package (without fixing the check). And the rest of distros do not seem to be using that package...

Quoted 6 lines

Reverting it will also break the ir-keytable userspace program that it is meant to be used by the Remote Controller devices, and uses it to adjust its behaviour to support RC's with more than 16 bits of scancodes.

I agree that it is bad that the ABI broke, but reverting it will cause even more damage.

There we disagree. Sure it's a very poorly thought out interface, but the way to fix it is to put a new one along side the old, and put the old back the way it was before it got broken.

I'm not making a fuss here for myself -- I'm more than capable of working around new kernel bugs like these, but for every person like me there are likely hundreds of others who simply get frustrated and give up.

If you're worried about Ubuntu's adaptation to the buggy regression, then email their developers (kernel and input-utils packagers) explaining the revert, and they can coordination their kernel and input-utils updates to do the Right Thing.

But for all of the rest of us, our systems are broken by this change.

...

Quoted 26 lines
Quoted 7 lines
Quoted 3 lines

As Mark said, breaking user space simply isn't acceptable. And since breaking user space isn't acceptable, then incrementing the version is stupid too.

It might not have been the best idea to increment, however I maintain that if there exists version is can be changed. Otherwise there is no point in having version at all.

Not arguing in favor of the version numbering, but it is easy to read the version increment at the beginning of the application, and adjust if the code will use EVIOCGKEYCODE or EVIOCGKEYCODE_V2 of the ioctl's, depending on what kernel provides.

Ok, we might be just calling the new ioctl and check for -ENOSYS at the beginning, using some fake arguments.

Quoted 10 lines

As I said, reverting the version bump will cause yet another wave of breakages so I propose leaving version as is.

Quoted 6 lines

The way we add new ioctl's is not by incrementing some "ABI version" crap. It's by adding new ioctl's or system calls or whatever that simply used to return -ENOSYS or other error before, while preserving the old ABI. That way old binaries don't break (for _ANY_ reason), and new binaries can see "oh, this doesn't support the new thing".

Quoted 6 lines
Quoted 1 line
Quoted 1 line

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

Please calm down. This, in fact, is not new vs old ioctl problem but rather particular driver (or rather set of drivers) implementation issue. Even if we drop the new ioctls and convert the RC code to use the old ones you'd be observing the same breakage as RC code responds with -EINVAL to not-yet-established mappings.

Quoted 5 lines

I'll see what can be done for these drivers; I guess we could supply a fake KEY_RESERVED entry for not mapped scancodes if there are mapped scancodes "above" current one. That should result in the same behavior for RCs as before.

I wonder if the patch below is all that is needed...

Input: ir-keymap - return KEY_RESERVED for unknown mappings

Quoted 7 lines

Do not respond with -EINVAL to EVIOCGKEYCODE for not-yet-mapped scancodes, but rather return KEY_RESERVED.

This fixes breakage with Ubuntu's input-kbd utility that stopped returning full keymaps for remote controls.

I tested your patch with both ir-keytable and the input-kbd (with the version check fixed) on the top of a vanilla 2.6.37 kernel. It works with both tools.

Feel free to add:

-

Btw, I took some time to take analyse the input-kbd stuff. As said at the README:

This is a small collection of input layer utilities. I wrote them mainly for testing and debugging, but maybe others find them useful too :-)
...
Gerd Knorr <[email protected]> [SUSE Labs]

This is an old testing tool written by Gerd Hoffmann probably used for him to test the V4L early Remote Controller implementations. I think he never meant to use it for anything else. So that's probably the reason why he added a check for a specific input version.

The last "official" version seems to be this one:

	http://dl.bytesex.org/cvs-snapshots/input-20081014-101501.tar.gz

I don't think that Gerd is still maintaining it. On a quick search, it seems that most distros don't ship it (Debian being an exception).

Gerd, if you're still maintaining it, it is a good idea to apply Dmitry's patch:

	http://www.spinics.net/lists/linux-input/msg13728.html

Otherwise, the tool won't work for NEC-extended and RC-6 tables.

Most of the tools found on Gerd's input package can be replaced with gains by ir-keytable [1][2].
[1] http://git.linuxtv.org/v4l-utils.git
[2] http://linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.2.tar.bz2

The output format for input-kbd is compatible with the input format of ir-keytable.

So, people that are using input-kbd to work with a remote controller at /dev/input/event2 can read the existent RC tables with:

	# input-kbd 2 >input_kbd_rc_map
or:
	# ir-keytable -r >ir_keytable_rc_map

In order to replace the table, people can use:

	# input-kbd -f some_rc_map 2
or:
	# ir-keytable -cw input_kbd_rc_map
	# ir-keytable -cw ir_keytable_rc_map

To list Remote Controller input devices:

	$ ir-keytable
		(somewhat similar to what lsinput does)

To test input events:

	# input-events 2
	# ir-keytable -t

However, as said previously in this thread, input-kbd won't work with any RC table that uses NEC extended (and there are several devices on the current Kernels with those tables), since it only reads up to 16 bits.

ir-keytable works with all RC tables, if you use a kernel equal or upper to 2.6.36, due to the usage of the new ioctl's.

ir-keytable also gets some additional data from the remote controllers, available via sysfs (/sys/class/rc).

Thanks,
Mauro

#30 lore raw

Hi,

Quoted 11 lines

Btw, I took some time to take analyse the input-kbd stuff. As said at the README:

This is a small collection of input layer utilities. I wrote them mainly for testing and debugging, but maybe others find them useful too :-)
...
Gerd Knorr<[email protected]> [SUSE Labs]

This is an old testing tool written by Gerd Hoffmann probably used for him to test the V4L early Remote Controller implementations.

Indeed.

Quoted 2 lines

The last "official" version seems to be this one:

	http://dl.bytesex.org/cvs-snapshots/input-20081014-101501.tar.gz

Just moved the bits to git a few days ago.
http://bigendian.kraxel.org/cgit/input/

Code is unchanged since 2008 though.

Quoted 3 lines

Gerd, if you're still maintaining it, it is a good idea to apply Dmitry's patch:

	http://www.spinics.net/lists/linux-input/msg13728.html

Hmm, doesn't apply cleanly ...

cheers,
Gerd

#31 lore raw

Em 26-01-2011 11:08, Gerd Hoffmann escreveu:

Quoted 22 lines

Hi,

Quoted 11 lines

Btw, I took some time to take analyse the input-kbd stuff. As said at the README:

This is a small collection of input layer utilities. I wrote them mainly for testing and debugging, but maybe others find them useful too :-)
...
Gerd Knorr<[email protected]> [SUSE Labs]

This is an old testing tool written by Gerd Hoffmann probably used for him to test the V4L early Remote Controller implementations.

Indeed.

Quoted 2 lines

The last "official" version seems to be this one:

    http://dl.bytesex.org/cvs-snapshots/input-20081014-101501.tar.gz

Just moved the bits to git a few days ago.
http://bigendian.kraxel.org/cgit/input/

Quoted 7 lines

Code is unchanged since 2008 though.

Quoted 3 lines

Gerd, if you're still maintaining it, it is a good idea to apply Dmitry's patch:

    http://www.spinics.net/lists/linux-input/msg13728.html

Hmm, doesn't apply cleanly ...

I suspect that Dmitry did the patch against the Debian package, based on a 2007 version of it, as it seems that Debian is using an older version of the package.

Anyway, I've ported his patch to be applied over your -git tree, and tested on it, with vanilla 2.6.37.

That's the incorrect output result of the old version, with an existing NEC extended map:

$ sudo /tmp/input/input-kbd 2
/dev/input/event2
   bustype : BUS_I2C
   vendor  : 0x0
   product : 0x0
   version : 0
   name    : "i2c IR (i2c IR (EM2820 Winfast "
   phys    : "i2c-0/0-0030/ir0"
   bits ev : EV_SYN EV_KEY EV_MSC EV_REP

bits: KEY_1
bits: KEY_2
bits: KEY_3
bits: KEY_4
...

And that's the output after applying the patch:

$ sudo ./input-kbd 2
/dev/input/event2
   bustype : BUS_I2C
   vendor  : 0x0
   product : 0x0
   version : 0
   name    : "i2c IR (i2c IR (EM2820 Winfast "
   phys    : "i2c-0/0-0030/ir0"
   bits ev : EV_SYN EV_KEY EV_MSC EV_REP

map: 31 keys, size: 31/64

0x866b00 = 393  # KEY_VIDEO
0x866b01 =   2  # KEY_1
0x866b02 =  11  # KEY_0
0x866b03 = 386  # KEY_TUNER

-

[PATCH] input-kbd - switch to using EVIOCGKEYCODE2 when available

From: Dmitry Torokhov <[email protected]>

[[email protected]: Ported it to the -git version]

input-kbd.c +73 -37
index c432d0d..aaf23b9 100644
@@ -9,9 +9,22 @@
 
 #include "input.h"
 
+struct input_keymap_entry_v2 {
+#define KEYMAP_BY_INDEX	(1 << 0)
+	uint8_t  flags;
+	uint8_t  len;
+	uint16_t index;
+	uint32_t keycode;
+	uint8_t  scancode[32];
+};
+
+#ifndef EVIOCGKEYCODE_V2
+#define EVIOCGKEYCODE_V2 _IOR('E', 0x04, struct input_keymap_entry_v2)
+#endif
+
 struct kbd_entry {
-	int scancode;
-	int keycode;
+	unsigned int scancode;
+	unsigned int keycode;
 };
 
 struct kbd_map {
@@ -23,7 +36,7 @@ struct kbd_map {
 
 /* ------------------------------------------------------------------ */
 
-static struct kbd_map* kbd_map_read(int fd)
+static struct kbd_map* kbd_map_read(int fd, unsigned int version)
 {
 	struct kbd_entry entry;
 	struct kbd_map *map;
@@ -32,17 +45,35 @@ static struct kbd_map* kbd_map_read(int fd)
 	map = malloc(sizeof(*map));
 	memset(map,0,sizeof(*map));
 	for (map->size = 0; map->size < 65536; map->size++) {
-		entry.scancode = map->size;
-		entry.keycode  = KEY_RESERVED;
-		rc = ioctl(fd, EVIOCGKEYCODE, &entry);
-		if (rc < 0) {
-			map->size--;
-			break;
+		if (version < 0x10001) {
+			entry.scancode = map->size;
+			entry.keycode  = KEY_RESERVED;
+			rc = ioctl(fd, EVIOCGKEYCODE, &entry);
+			if (rc < 0) {
+				map->size--;
+				break;
+			}
+		} else {
+			struct input_keymap_entry_v2 ke = {
+				.index = map->size,
+				.flags = KEYMAP_BY_INDEX,
+				.len = sizeof(uint32_t),
+				.keycode = KEY_RESERVED,
+			};
+
+			rc = ioctl(fd, EVIOCGKEYCODE_V2, &ke);
+			if (rc < 0)
+				break;
+			memcpy(&entry.scancode, ke.scancode,
+				sizeof(entry.scancode));
+			entry.keycode = ke.keycode;
 		}
+
 		if (map->size >= map->alloc) {
 			map->alloc += 64;
 			map->map = realloc(map->map, map->alloc * sizeof(entry));
 		}
+
 		map->map[map->size] = entry;
 
 		if (KEY_RESERVED != entry.keycode)
@@ -156,37 +187,25 @@ static void kbd_print_bits(int fd)
 	}
 }
 
-static void show_kbd(int nr)
+static void show_kbd(int fd, unsigned int protocol_version)
 {
 	struct kbd_map *map;
-	int fd;
 
-	fd = device_open(nr,1);
-	if (-1 == fd)
-		return;
 	device_info(fd);
 
-	map = kbd_map_read(fd);
-	if (NULL != map) {
-		kbd_map_print(stdout,map,0);
-	} else {
+	map = kbd_map_read(fd, protocol_version);
+	if (map)
+		kbd_map_print(stdout, map, 0);
+	else
 		kbd_print_bits(fd);
-	}
-
-	close(fd);
 }
 
-static int set_kbd(int nr, char *mapfile)
+static int set_kbd(int fd, unsigned int protocol_version, char *mapfile)
 {
 	struct kbd_map *map;
 	FILE *fp;
-	int fd;
 
-	fd = device_open(nr,1);
-	if (-1 == fd)
-		return -1;
-
-	map = kbd_map_read(fd);
+	map = kbd_map_read(fd, protocol_version);
 	if (NULL == map) {
 		fprintf(stderr,"device has no map\n");
 		close(fd);
@@ -203,14 +222,12 @@ static int set_kbd(int nr, char *mapfile)
 			return -1;
 		}
 	}
-	
+
 	if (0 != kbd_map_parse(fp,map) ||
 	    0 != kbd_map_write(fd,map)) {
-		close(fd);
 		return -1;
 	}
 
-	close(fd);
 	return 0;
 }
 
@@ -224,8 +241,10 @@ static int usage(char *prog, int error)
 
 int main(int argc, char *argv[])
 {
-	int c,devnr;
+	int c, devnr, fd;
 	char *mapfile = NULL;
+	unsigned int protocol_version;
+	int rc = EXIT_FAILURE;
 
 	for (;;) {
 		if (-1 == (c = getopt(argc, argv, "hf:")))
@@ -245,12 +264,29 @@ int main(int argc, char *argv[])
 		usage(argv[0],1);
 
 	devnr = atoi(argv[optind]);
-	if (mapfile) {
-		set_kbd(devnr,mapfile);
-	} else {
-		show_kbd(devnr);
+
+	fd = device_open(devnr, 1);
+	if (fd < 0)
+		goto out;
+
+	if (ioctl(fd, EVIOCGVERSION, &protocol_version) < 0) {
+		fprintf(stderr,
+			"Unable to query evdev protocol version: %s\n",
+			strerror(errno));
+		goto out_close;
 	}
-	return 0;
+
+	if (mapfile)
+		set_kbd(fd, protocol_version, mapfile);
+	else
+		show_kbd(fd, protocol_version);
+
+	rc = EXIT_SUCCESS;
+
+out_close:
+	close(fd);
+out:
+	return rc;
 }
 
 /* ---------------------------------------------------------------------
input.c +2 -2
index d57a31e..a9bd5e8 100644
@@ -101,8 +101,8 @@ int device_open(int nr, int verbose)
 		close(fd);
 		return -1;
 	}
-	if (EV_VERSION != version) {
-		fprintf(stderr, "protocol version mismatch (expected %d, got %d)\n",
+	if (EV_VERSION > version) {
+		fprintf(stderr, "protocol version mismatch (expected >= %d, got %d)\n",
 			EV_VERSION, version);
 		close(fd);
 		return -1;
#32 lore raw

Hi,

Quoted 4 lines
Quoted 1 line

Hmm, doesn't apply cleanly ...

I suspect that Dmitry did the patch against the Debian package, based on a 2007 version of it, as it seems that Debian is using an older version of the package.

Applied, thanks.

cheers,
Gerd

#33 lore raw
In reply to Mauro Carvalho Chehab
Quoted 25 lines · Mauro Carvalho Chehab

Em 26-01-2011 11:08, Gerd Hoffmann escreveu:

Quoted 24 lines

Hi,

Quoted 11 lines

Btw, I took some time to take analyse the input-kbd stuff. As said at the README:

This is a small collection of input layer utilities. I wrote them mainly for testing and debugging, but maybe others find them useful too :-)
...
Gerd Knorr<[email protected]> [SUSE Labs]

This is an old testing tool written by Gerd Hoffmann probably used for him to test the V4L early Remote Controller implementations.

Indeed.

Quoted 2 lines

The last "official" version seems to be this one:

    http://dl.bytesex.org/cvs-snapshots/input-20081014-101501.tar.gz

Just moved the bits to git a few days ago.
http://bigendian.kraxel.org/cgit/input/

Code is unchanged since 2008 though.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Gerd, if you're still maintaining it, it is a good idea to apply Dmitry's patch:

    http://www.spinics.net/lists/linux-input/msg13728.html

Hmm, doesn't apply cleanly ...

I suspect that Dmitry did the patch against the Debian package, based on a 2007 version of it, as it seems that Debian is using an older version of the package.

Actually it was from Ubuntu, so it is based on 2008 checkout, but they also have more patches, take a peek here:

https://launchpad.net/ubuntu/+archive/primary/+files/input-utils_0.0.20081014-1.debian.tar.gz

Thanks.

Signature · 1 line
Dmitry
#34 lore raw
In reply to Mauro Carvalho Chehab

input.c int device_open(int nr, int verbose) · line 106

Quoted 13 lines · Mauro Carvalho Chehab
input.c +2 -2
index d57a31e..a9bd5e8 100644
@@ -101,8 +101,8 @@ int device_open(int nr, int verbose)
 		close(fd);
 		return -1;
 	}
-	if (EV_VERSION != version) {
-		fprintf(stderr, "protocol version mismatch (expected %d, got %d)\n",
+	if (EV_VERSION > version) {
+		fprintf(stderr, "protocol version mismatch (expected >= %d, got %d)\n",
 			EV_VERSION, version);

Please do not do this. It causes check to "float" depending on the version of kernel headers it was compiled against.

The check should be against concrete version (0x10000 in this case).

Thanks.

Signature · 1 line
Dmitry
#35 lore raw

Em 26-01-2011 14:51, Dmitry Torokhov escreveu:

Quoted 18 lines · Mauro Carvalho Chehab

input.c int device_open(int nr, int verbose) · line 106

Quoted 13 lines
input.c +2 -2
index d57a31e..a9bd5e8 100644
@@ -101,8 +101,8 @@ int device_open(int nr, int verbose)
 		close(fd);
 		return -1;
 	}
-	if (EV_VERSION != version) {
-		fprintf(stderr, "protocol version mismatch (expected %d, got %d)\n",
+	if (EV_VERSION > version) {
+		fprintf(stderr, "protocol version mismatch (expected >= %d, got %d)\n",
 			EV_VERSION, version);

Please do not do this. It causes check to "float" depending on the version of kernel headers it was compiled against.

Quoted 1 line

The check should be against concrete version (0x10000 in this case).

The idea here is to not prevent it to load if version is 0x10001. This is actually the only change that it is really needed (after applying your KEY_RESERVED patch to 2.6.37) for the tool to work. Reverting it causes the error:

$ sudo ./input-kbd 2
/dev/input/event2
protocol version mismatch (expected >= 65536, got 65537)

Just applying this diff to the previous version:

$ git diff 442bc4e7697a3f20ce9a24df630324d94cd22ba6
input.c +2 -2
index d57a31e..a9bd5e8 100644
@@ -101,8 +101,8 @@ int device_open(int nr, int verbose)
                close(fd);
                return -1;
        }
-       if (EV_VERSION != version) {
-               fprintf(stderr, "protocol version mismatch (expected %d, got %d)
+       if (EV_VERSION > version) {
+               fprintf(stderr, "protocol version mismatch (expected >= %d, got 
                        EV_VERSION, version);
                close(fd);
                return -1;

And, with your KEY_RESERVED patch applied to 2.6.37, the tool works fine, with 16-bits keytables:

$ sudo ./input-kbd 2
/dev/input/event2
   bustype : BUS_I2C
   vendor  : 0x0
   product : 0x0
   version : 0
   name    : "i2c IR (i2c IR (EM2820 Winfast "
   phys    : "i2c-0/0-0030/ir0"
   bits ev : EV_SYN EV_KEY EV_MSC EV_REP

map: 28 keys, size: 65536/65536

0x0021 = 363  # KEY_CHANNEL
0x0031 =  52  # KEY_DOT
0x0035 = 359  # KEY_TIME
0x0037 = 167  # KEY_RECORD
0x0038 = 212  # KEY_CAMERA
0x0039 = 154  # KEY_CYCLEWINDOWS
0x003a = 181  # KEY_NEW
0x0060 = 403  # KEY_CHANNELDOWN
0x0061 = 405  # KEY_LAST
0x0062 =  11  # KEY_0
0x0063 =  28  # KEY_ENTER
0x0064 = 113  # KEY_MIN_INTERESTING
0x0066 = 358  # KEY_INFO
0x0070 = 356  # KEY_POWER2
0x0072 = 393  # KEY_VIDEO
0x0073 = 372  # KEY_ZOOM
0x0074 = 115  # KEY_VOLUMEUP
0x0075 =   2  # KEY_1
0x0076 =   3  # KEY_2
0x0077 =   4  # KEY_3
0x0078 = 114  # KEY_VOLUMEDOWN
0x0079 =   5  # KEY_4
0x007a =   6  # KEY_5
0x007b =   7  # KEY_6
0x007c = 402  # KEY_CHANNELUP
0x007d =   8  # KEY_7
0x007e =   9  # KEY_8
0x007f =  10  # KEY_9

(this is the original RC-5 table for the IR that comes with this device)

It will fail, however, it the keytable has 24 bits keycode:

$ sudo ir-keytable -cw /etc/rc_keymaps/pixelview_mk12 

(loads a 24 bits NEC-extended keycode, found on Pixelview MK12 remote control)

$ sudo ./input-kbd 2
/dev/input/event2
   bustype : BUS_I2C
   vendor  : 0x0
   product : 0x0
   version : 0
   name    : "i2c IR (i2c IR (EM2820 Winfast "
   phys    : "i2c-0/0-0030/ir0"
   bits ev : EV_SYN EV_KEY EV_MSC EV_REP

bits: KEY_1
bits: KEY_2
bits: KEY_3
bits: KEY_4
bits: KEY_5
bits: KEY_6
bits: KEY_7
bits: KEY_8
bits: KEY_9
bits: KEY_0
bits: KEY_MIN_INTERESTING
bits: KEY_VOLUMEDOWN
bits: KEY_VOLUMEUP
bits: KEY_PAUSE
bits: KEY_STOP
bits: KEY_AGAIN
bits: KEY_FORWARD
bits: KEY_RECORD
bits: KEY_REWIND
bits: KEY_PLAY
bits: KEY_CAMERA
bits: KEY_SEARCH
bits: KEY_POWER2
bits: KEY_ZOOM
bits: KEY_TV
bits: KEY_RADIO
bits: KEY_TUNER
bits: KEY_VIDEO
bits: KEY_CHANNELUP
bits: KEY_CHANNELDOWN
bits: KEY_DIGITS

Instead of showing the scancode/keycode table, it shows the mapped keys as if they were some event bits.

The current kraxel tree at http://bigendian.kraxel.org/cgit/input/
with your userspace input patch, plus my backports for upstream work fine also with the 24-bits keycode table:

$ git reset --hard && make
[mchehab@nehalem input]$ git reset --hard && make
HEAD is now at 52f533a input-kbd - switch to using EVIOCGKEYCODE2 when available
  CC	  input-kbd.o
  LD	  input-kbd
$ sudo ./input-kbd 2
/dev/input/event2
   bustype : BUS_I2C
   vendor  : 0x0
   product : 0x0
   version : 0
   name    : "i2c IR (i2c IR (EM2820 Winfast "
   phys    : "i2c-0/0-0030/ir0"
   bits ev : EV_SYN EV_KEY EV_MSC EV_REP

map: 31 keys, size: 31/64

0x866b00 = 393  # KEY_VIDEO
0x866b01 =   2  # KEY_1
0x866b02 =  11  # KEY_0
0x866b03 = 386  # KEY_TUNER
0x866b04 = 168  # KEY_REWIND
0x866b05 =   5  # KEY_4
0x866b06 =   8  # KEY_7
0x866b07 = 385  # KEY_RADIO
0x866b08 = 207  # KEY_PLAY
0x866b09 =   6  # KEY_5
0x866b0a =   9  # KEY_8
0x866b0b =   3  # KEY_2
0x866b0c = 159  # KEY_FORWARD
0x866b0d = 377  # KEY_TV
0x866b0e = 167  # KEY_RECORD
0x866b0f = 119  # KEY_PAUSE
0x866b10 = 413  # KEY_DIGITS
0x866b12 =  10  # KEY_9
0x866b13 = 129  # KEY_AGAIN
0x866b14 = 403  # KEY_CHANNELDOWN
0x866b15 =   7  # KEY_6
0x866b16 = 402  # KEY_CHANNELUP
0x866b17 = 114  # KEY_VOLUMEDOWN
0x866b18 = 113  # KEY_MIN_INTERESTING
0x866b19 = 212  # KEY_CAMERA
0x866b1a = 217  # KEY_SEARCH
0x866b1b =   4  # KEY_3
0x866b1c = 372  # KEY_ZOOM
0x866b1d = 128  # KEY_STOP
0x866b1e = 356  # KEY_POWER2
0x866b1f = 115  # KEY_VOLUMEUP

Cheers,
Mauro

#36 lore raw
Quoted 19 lines · Mauro Carvalho Chehab

Em 26-01-2011 14:51, Dmitry Torokhov escreveu:

Quoted 18 lines · Mauro Carvalho Chehab

input.c int device_open(int nr, int verbose) · line 106

Quoted 13 lines
input.c +2 -2
index d57a31e..a9bd5e8 100644
@@ -101,8 +101,8 @@ int device_open(int nr, int verbose)
 		close(fd);
 		return -1;
 	}
-	if (EV_VERSION != version) {
-		fprintf(stderr, "protocol version mismatch (expected %d, got %d)\n",
+	if (EV_VERSION > version) {
+		fprintf(stderr, "protocol version mismatch (expected >= %d, got %d)\n",
 			EV_VERSION, version);

Please do not do this. It causes check to "float" depending on the version of kernel headers it was compiled against.

Quoted 6 lines
Quoted 1 line

The check should be against concrete version (0x10000 in this case).

The idea here is to not prevent it to load if version is 0x10001. This is actually the only change that it is really needed (after applying your KEY_RESERVED patch to 2.6.37) for the tool to work. Reverting it causes the error:

You did not understand. When comparing against EV_VERSION, if you compile on 2.6.32 you are comparing with 0x10000. If you are compiling on 2.6.37 you are comparing with 0x10001 as EV_VERSION value changes (not the value returned by EVIOCGVERSION, the value of the _define_ itself).

The proper check is:

#define EVDEV_MIN_VERSION 0x10000
	if (version < EVDEV_MIN_VERSION) {
		fprintf(stderr,
			"protocol version mismatch (need at least %d, got %d)\n",
			EVDEV_MIN_VERSION, version);
		...
	}
Signature · 1 line
Dmitry
#37 lore raw

Hi,

Quoted 1 line
Quoted 1 line
Quoted 1 line

The check should be against concrete version (0x10000 in this case).

Stepping back: what does the version mean?

0x10000 == 1.0 ?
0x10001 == 1.1 ?

Can I expect the interface stay backward compatible if only the minor revision changes, i.e. makes it sense to accept 1.x?

Will the major revision ever change? Does it make sense to check the version at all?

thanks,
Gerd

author
#38 lore raw
Quoted 6 lines · Gerd Hoffmann

Hi,

Quoted 1 line
Quoted 1 line
Quoted 1 line

The check should be against concrete version (0x10000 in this case).

Stepping back: what does the version mean?

Quoted 8 lines

0x10000 == 1.0 ?
0x10001 == 1.1 ?

Can I expect the interface stay backward compatible if only the minor revision changes, i.e. makes it sense to accept 1.x?

Will the major revision ever change? Does it make sense to check the version at all?

As already established earlier in this thread,
by Linus Torvalds as well as by myself,
NO!

That whole "version" concept is broken and inappropriate. Userspace should simply ignore it completely.

Cheers

#39 lore raw

Hi,

Quoted 6 lines
Quoted 2 lines

Will the major revision ever change? Does it make sense to check the version at all?

As already established earlier in this thread,
by Linus Torvalds as well as by myself,
NO!

Check removed.

thanks,
Gerd

#40 lore raw
In reply to Gerd Hoffmann

Em 26-01-2011 17:16, Gerd Hoffmann escreveu:

Quoted 3 lines

Hi,

Quoted 1 line
Quoted 1 line
Quoted 1 line

The check should be against concrete version (0x10000 in this case).

Dmitry,

Ok, now I see what you're meaning. Yeah, an absolute version check like what you've proposed is better than a relative version check.

Quoted 9 lines

Stepping back: what does the version mean?

0x10000 == 1.0 ?
0x10001 == 1.1 ?

Can I expect the interface stay backward compatible if only the minor revision changes, i.e. makes it sense to accept 1.x?

Will the major revision ever change? Does it make sense to check the version at all?

Gerd,

Dmitry will likely have a better answer for me, but I think you should just remove the test. By principle, the interface should always be backward compatible (if it isn't, then we have a regression to fix). You may expect newer features on newer versions, so I understand that the version check is there to just allow userspace to enable new code for newer evdev protocol revisions.

Thanks,
Mauro

#41 lore raw
In reply to Gerd Hoffmann

On Wed, Jan 26, 2011 at 08:16:09PM +0100, Gerd Hoffmann wrote: > Hi,

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The check should be against concrete version (0x10000 in this case).

Stepping back: what does the version mean?

Nothing, it is just a number.

Quoted 2 lines

0x10000 == 1.0 ?
0x10001 == 1.1 ?

No, not really.

Quoted 3 lines

Can I expect the interface stay backward compatible if only the minor revision changes, i.e. makes it sense to accept 1.x?

I am not planning on breaking backward compatibility.

Quoted 3 lines

Will the major revision ever change? Does it make sense to check the version at all?

It depends. We do not have a clear way to see if new ioctls are supported (and I do not consider "try new ioctl and see if data sticks" being a good way) so that facilitated protocol version rev-up. So keymap manipulating tools might be forced to check protocol version. For the rest I think doing EVIOCGVERSION just to check that ioctl is supported is an OK way to validate that we are dealing with an event device, but that's it.

BTW, maybe we should move lsinput and input-kbd into linuxconsole package, together with evtest, fftest, etc?

Signature · 1 line
Dmitry
#42 lore raw

Hi,

Quoted 3 lines

It depends. We do not have a clear way to see if new ioctls are supported (and I do not consider "try new ioctl and see if data sticks" being a good way) so that facilitated protocol version rev-up.

Yea, EVIOCGKEYCODE_V2 on a old kernel returns EINVAL. Not good. There is another one which should have been used to signal "unknown ioctl", ENOTTY IIRC (a bit silly for historical reasons), so you can figure whenever your input data is invalid or whenever the ioctl isn't supported in the first place (in which case you could just fallback to the old version).

Quoted 2 lines

So keymap
manipulating tools might be forced to check protocol version.

Guess that is the best way indeed.

cheers,
Gerd.

author
#43 lore raw
In reply to Dmitry Torokhov
Quoted 35 lines · Dmitry Torokhov
Quoted 19 lines · Mauro Carvalho Chehab

Em 26-01-2011 14:51, Dmitry Torokhov escreveu:

Quoted 18 lines · Mauro Carvalho Chehab

input.c int device_open(int nr, int verbose) · line 106

Quoted 13 lines
input.c +2 -2
index d57a31e..a9bd5e8 100644
@@ -101,8 +101,8 @@ int device_open(int nr, int verbose)
 		close(fd);
 		return -1;
 	}
-	if (EV_VERSION != version) {
-		fprintf(stderr, "protocol version mismatch (expected %d, got %d)\n",
+	if (EV_VERSION > version) {
+		fprintf(stderr, "protocol version mismatch (expected >= %d, got %d)\n",
 			EV_VERSION, version);

Please do not do this. It causes check to "float" depending on the version of kernel headers it was compiled against.

Quoted 6 lines
Quoted 1 line

The check should be against concrete version (0x10000 in this case).

The idea here is to not prevent it to load if version is 0x10001. This is actually the only change that it is really needed (after applying your KEY_RESERVED patch to 2.6.37) for the tool to work. Reverting it causes the error:

You did not understand. When comparing against EV_VERSION, if you compile on 2.6.32 you are comparing with 0x10000. If you are compiling on 2.6.37 you are comparing with 0x10001 as EV_VERSION value changes (not the value returned by EVIOCGVERSION, the value of the _define_ itself).

The proper check is:

Quoted 7 lines
#define EVDEV_MIN_VERSION 0x10000
	if (version < EVDEV_MIN_VERSION) {
		fprintf(stderr,
			"protocol version mismatch (need at least %d, got %d)\n",
			EVDEV_MIN_VERSION, version);
		...
	}

Guys, NO!

The proper check is actually to remove all of that silly VERSION testing from the userspace binary. And then have it try EVIOCGKEYCODE_V2 first. If EVIOCGKEYCODE_V2 fails (-ENOTTY, -EINVAL, or -ENOSYS), then have it fall back to trying to use EVIOCGKEYCODE.

Of course this does assume that the new EVIOCGKEYCODE_V2 interface uses correct ioctl return values..

Cheers

author
#44 lore raw
In reply to Mauro Carvalho Chehab

On 11-01-26 06:26 AM, Mauro Carvalho Chehab wrote:
..

Quoted 6 lines

However, as said previously in this thread, input-kbd won't work with any RC table that uses NEC extended (and there are several devices on the current Kernels with those tables), since it only reads up to 16 bits.

ir-keytable works with all RC tables, if you use a kernel equal or upper to 2.6.36, due to the usage of the new ioctl's.

Is there a way to control the key repeat rate for a device controlled by ir-kbd-i2c ?

It appears to be limited to a max of between 4 and 5 repeats/sec somewhere, and I'd like to fix that.

???

#45 lore raw

Em 26-01-2011 12:58, Mark Lord escreveu:

Quoted 6 lines · Mauro Carvalho Chehab

..

Quoted 4 lines

However, as said previously in this thread, input-kbd won't work with any RC table that uses NEC extended (and there are several devices on the current Kernels with those tables), since it only reads up to 16 bits.

Quoted 8 lines
Quoted 2 lines

ir-keytable works with all RC tables, if you use a kernel equal or upper to 2.6.36, due to the usage of the new ioctl's.

Is there a way to control the key repeat rate for a device controlled by ir-kbd-i2c ?

It appears to be limited to a max of between 4 and 5 repeats/sec somewhere, and I'd like to fix that.

It depends on what device do you have. Several I2C chips have the repeat logic inside the I2C microcontroller PROM firmware. or at the remote controller itself. So, there's nothing we can do to change it.

I have even one device here (I think it is a saa7134-based Kworld device) that doesn't send any repeat event at all for most keys (I think it only sends repeat events for volume - Can't remember the specific details anymore - too many devices!).

The devices that produce repeat events can be adjusted via the normal input layer tools like kbdrate.

Thanks,
Mauro

#46 lore raw
Quoted 20 lines · Mauro Carvalho Chehab

Em 26-01-2011 12:58, Mark Lord escreveu:

Quoted 6 lines · Mauro Carvalho Chehab

..

Quoted 4 lines

However, as said previously in this thread, input-kbd won't work with any RC table that uses NEC extended (and there are several devices on the current Kernels with those tables), since it only reads up to 16 bits.

Quoted 8 lines
Quoted 2 lines

ir-keytable works with all RC tables, if you use a kernel equal or upper to 2.6.36, due to the usage of the new ioctl's.

Is there a way to control the key repeat rate for a device controlled by ir-kbd-i2c ?

It appears to be limited to a max of between 4 and 5 repeats/sec somewhere, and I'd like to fix that.

It depends on what device do you have. Several I2C chips have the repeat logic inside the I2C microcontroller PROM firmware. or at the remote controller itself. So, there's nothing we can do to change it.

Quoted 8 lines

I have even one device here (I think it is a saa7134-based Kworld device) that doesn't send any repeat event at all for most keys (I think it only sends repeat events for volume - Can't remember the specific details anymore - too many devices!).

The devices that produce repeat events can be adjusted via the normal input layer tools like kbdrate.

Unfortunately kbdrate affects all connected devices and I am not sure if there is a utility allowing to set rate on individual devices. But here is the main part:

static int input_set_rate(int fd,
unsigned int delay, unsigned int period)

{
	unsigned int rep[2] = { delay, period };

	if (ioctl(fd, EVIOCSREP, rep) < 0) {
		perror("evdev ioctl");
		return -1;
	}
	return 0;
}
Signature · 1 line
Dmitry
author
#47 lore raw
Quoted 36 lines · Dmitry Torokhov
Quoted 20 lines · Mauro Carvalho Chehab

Em 26-01-2011 12:58, Mark Lord escreveu:

Quoted 6 lines · Mauro Carvalho Chehab

..

Quoted 4 lines

However, as said previously in this thread, input-kbd won't work with any RC table that uses NEC extended (and there are several devices on the current Kernels with those tables), since it only reads up to 16 bits.

Quoted 8 lines
Quoted 2 lines

ir-keytable works with all RC tables, if you use a kernel equal or upper to 2.6.36, due to the usage of the new ioctl's.

Is there a way to control the key repeat rate for a device controlled by ir-kbd-i2c ?

It appears to be limited to a max of between 4 and 5 repeats/sec somewhere, and I'd like to fix that.

It depends on what device do you have. Several I2C chips have the repeat logic inside the I2C microcontroller PROM firmware. or at the remote controller itself. So, there's nothing we can do to change it.

Quoted 8 lines

I have even one device here (I think it is a saa7134-based Kworld device) that doesn't send any repeat event at all for most keys (I think it only sends repeat events for volume - Can't remember the specific details anymore - too many devices!).

The devices that produce repeat events can be adjusted via the normal input layer tools like kbdrate.

Unfortunately kbdrate affects all connected devices and I am not sure if there is a utility allowing to set rate on individual devices. But here is the main part:

static int input_set_rate(int fd,
unsigned int delay, unsigned int period)

Quoted 10 lines
{
	unsigned int rep[2] = { delay, period };

	if (ioctl(fd, EVIOCSREP, rep) < 0) {
		perror("evdev ioctl");
		return -1;
	}
	return 0;
}

Okay, if that's still a global in this day and age, then I suppose I'll just have to special-case it here in my copy.

The hardware itself is capable of much faster repeat rates, and prior to 2.6.36 I used to patch it for intelligent ramp-up on repeats inside ir-kbd-i2c.

As of 2.6.36 that stopped working, and is now limited somewhere to no more than one repeat every 210msecs.

Cheers

author
#48 lore raw
In reply to Dmitry Torokhov
Quoted 4 lines · Dmitry Torokhov
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Mark Lord
Quoted 1 line · Mauro Carvalho Chehab

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

..

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

Please calm down. This, in fact, is not new vs old ioctl problem but rather particular driver (or rather set of drivers) implementation issue. Even if we drop the new ioctls and convert the RC code to use the old ones you'd be observing the same breakage as RC code responds with -EINVAL to not-yet-established mappings.

Quoted 7 lines
Quoted 5 lines

I'll see what can be done for these drivers; I guess we could supply a fake KEY_RESERVED entry for not mapped scancodes if there are mapped scancodes "above" current one. That should result in the same behavior for RCs as before.

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)
Quoted 58 lines

Input: ir-keymap - return KEY_RESERVED for unknown mappings

Do not respond with -EINVAL to EVIOCGKEYCODE for not-yet-mapped scancodes, but rather return KEY_RESERVED.

This fixes breakage with Ubuntu's input-kbd utility that stopped returning full keymaps for remote controls.

---

drivers/media/IR/ir-keytable.c | 28 +++++++++++++++++-----------

1 files changed, 17 insertions(+), 11 deletions(-)
drivers/media/IR/ir-keytable.c +17 -11
index f60107c..c4645d7 100644
@@ -374,21 +374,27 @@ static int ir_getkeycode(struct input_dev *dev,
 		index = ir_lookup_by_scancode(rc_tab, scancode);
 	}
 
-	if (index >= rc_tab->len) {
-		if (!(ke->flags & INPUT_KEYMAP_BY_INDEX))
-			IR_dprintk(1, "unknown key for scancode 0x%04x\n",
-				   scancode);
+	if (index < rc_tab->len) {
+		entry = &rc_tab->scan[index];
+
+		ke->index = index;
+		ke->keycode = entry->keycode;
+		ke->len = sizeof(entry->scancode);
+		memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
+
+	} else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) {
+		/*
+		 * We do not really know the valid range of scancodes
+		 * so let's respond with KEY_RESERVED to anything we
+		 * do not have mapping for [yet].
+		 */
+		ke->index = index;
+		ke->keycode = KEY_RESERVED;
+	} else {
 		retval = -EINVAL;
 		goto out;
 	}
 
-	entry = &rc_tab->scan[index];
-
-	ke->index = index;
-	ke->keycode = entry->keycode;
-	ke->len = sizeof(entry->scancode);
-	memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
-
 	retval = 0;
 

out:

#49 lore raw
Quoted 25 lines · Mark Lord
Quoted 4 lines · Dmitry Torokhov
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Mark Lord
Quoted 1 line · Mauro Carvalho Chehab

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

..

Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

Please calm down. This, in fact, is not new vs old ioctl problem but rather particular driver (or rather set of drivers) implementation issue. Even if we drop the new ioctls and convert the RC code to use the old ones you'd be observing the same breakage as RC code responds with -EINVAL to not-yet-established mappings.

I'll see what can be done for these drivers; I guess we could supply a fake KEY_RESERVED entry for not mapped scancodes if there are mapped scancodes "above" current one. That should result in the same behavior for RCs as before.

Quoted 8 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

It would be much more helpful if you tried to test what has been fixed (hint: version change wasn't it).

Signature · 1 line
Dmitry
author
#50 lore raw
Quoted 1 line · Dmitry Torokhov

On Wed, Jan 26, 2011 at 10:05:57AM -0500, Mark Lord wrote:

..

Quoted 8 lines
Quoted 5 lines

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

It would be much more helpful if you tried to test what has been fixed (hint: version change wasn't it).

It would be much more helpful if you would revert that which was broken in 2.6.36. (hint: version was part of it).

The other part does indeed appear to work with the old binary for input-kbd, but the binary for lsinput still fails as above.

Cheers

#51 lore raw
Quoted 9 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

On Wed, Jan 26, 2011 at 10:05:57AM -0500, Mark Lord wrote:

..

Quoted 6 lines
Quoted 5 lines

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)
Quoted 6 lines
Quoted 2 lines

It would be much more helpful if you tried to test what has been fixed (hint: version change wasn't it).

It would be much more helpful if you would revert that which was broken in 2.6.36. (hint: version was part of it).

No, version change will not be reverted as we do not have a way to validate whether new ioctls are supported. The older kernels are returning -EINVAL for unknown evdev ioctls so userspace can't know if ioctl failed because it is unsupported or because arguments are wrong/not applicable for the underlying device.

Quoted 3 lines

The other part does indeed appear to work with the old binary for input-kbd, but the binary for lsinput still fails as above.

Great, then I'' include the fix for RC keytables in my next pull request. I guess it should go to stable as well.

Thanks.

Signature · 1 line
Dmitry
#52 lore raw
In reply to Mark Lord

Em 26-01-2011 13:05, Mark Lord escreveu:

Quoted 25 lines · Dmitry Torokhov
Quoted 4 lines · Dmitry Torokhov
Quoted 3 lines · Mark Lord
Quoted 2 lines · Mauro Carvalho Chehab
Quoted 1 line

Em 25-01-2011 18:54, Dmitry Torokhov escreveu:

..

Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

That has been done as well; we have 2 new ioctls and kept 2 old ioctls.

That's the problem: you did NOT keep the two old ioctls(). Those got changed too.. so now we have four NEW ioctls(), none of which backward compatible with userspace.

Please calm down. This, in fact, is not new vs old ioctl problem but rather particular driver (or rather set of drivers) implementation issue. Even if we drop the new ioctls and convert the RC code to use the old ones you'd be observing the same breakage as RC code responds with -EINVAL to not-yet-established mappings.

I'll see what can be done for these drivers; I guess we could supply a fake KEY_RESERVED entry for not mapped scancodes if there are mapped scancodes "above" current one. That should result in the same behavior for RCs as before.

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

You need to relax the version test at the tree. As I said before, this is a development tool from the early RC days, bound to work with one specific version of the API, and programmed by purpose to fail if there would by any updates at the Input layer.

Cheers,
Mauro.

author
#53 lore raw
Quoted 1 line · Mauro Carvalho Chehab

Em 26-01-2011 13:05, Mark Lord escreveu:

..

Quoted 9 lines
Quoted 4 lines

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

You need to relax the version test at the tree. As I said before, this is a development tool from the early RC days, bound to work with one specific version of the API, and programmed by purpose to fail if there would by any updates at the Input layer.

..

As I said before, I personally have done that on my copy here. But that's not what this thread is about.

This thread is about broken userspace courtesy of these changes. So I am testing with the original userspace binary here,
and it still fails. And will continue to fail until that regression is fixed.

Cheers

#54 lore raw
Quoted 12 lines · Mark Lord
Quoted 1 line · Mauro Carvalho Chehab

Em 26-01-2011 13:05, Mark Lord escreveu:

..

Quoted 9 lines
Quoted 4 lines

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

You need to relax the version test at the tree. As I said before, this is a development tool from the early RC days, bound to work with one specific version of the API, and programmed by purpose to fail if there would by any updates at the Input layer.

Quoted 8 lines

..

As I said before, I personally have done that on my copy here. But that's not what this thread is about.

This thread is about broken userspace courtesy of these changes. So I am testing with the original userspace binary here,
and it still fails. And will continue to fail until that regression is fixed.

I do not consider lsinput refusing to work a regression. The tool claims to work with particular protocol version and it is tool's choice.

Shall I write a utility that checks kernel version and only works with 2.6.37 and yell when we release 2.6.38?

Signature · 1 line
Dmitry
author
#55 lore raw
Quoted 2 lines · Dmitry Torokhov

I do not consider lsinput refusing to work a regression.

Obviously, since you don't use that tool.
Those of us who do use it see this as broken userspace compatibility.

Who the hell reviews this crap, anyway?
Code like that should never have made it upstream in the first place.

Cheers

#56 lore raw
Quoted 10 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

I do not consider lsinput refusing to work a regression.

Obviously, since you don't use that tool.
Those of us who do use it see this as broken userspace compatibility.

Who the hell reviews this crap, anyway?
Code like that should never have made it upstream in the first place.

You are more than welcome spend more time on reviews.

Thanks.

Signature · 1 line
Dmitry
author
#57 lore raw
Quoted 5 lines · Dmitry Torokhov
Quoted 4 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

I do not consider lsinput refusing to work a regression.

Quoted 8 lines
Quoted 6 lines

Obviously, since you don't use that tool.
Those of us who do use it see this as broken userspace compatibility.

Who the hell reviews this crap, anyway?
Code like that should never have made it upstream in the first place.

You are more than welcome spend more time on reviews.

Somehow I detect a totally lack of sincerity there.

But thanks for fixing the worst of this regression, at least.

Perhaps you might think about eventually fixing the bad use of -EINVAL in future revisions. One way perhaps to approach that, would be to begin fixing it internally, but still returning the same things from the actual f_ops->ioctl() routine.

Then eventually provide new ioctl numbers which return the correct -ENOTTY (or whatever is best there), rather than converting to -EVINAL at the interface. Then a nice multi-year overlap, with a scheduled removal of the old codes some day.

Then the input subsystem would work more like most other subsystems, and make userspace programming simpler and easier to "get correct".

Cheers

author
#58 lore raw

Or perhaps get rid of that unworkable "version number" thing (just freeze it in time with the 2.6.35 value returned),
and implement a "get_feature_flags" ioctl or something for going forward. Then you can just turn on new bits in the flags as new features are added.

It's a kludge (to get around the poor use of -EINVAL everywhere), but at least it's a design that's workable.

Cheers

#59 lore raw
Quoted 5 lines · Mark Lord

Or perhaps get rid of that unworkable "version number" thing (just freeze it in time with the 2.6.35 value returned),
and implement a "get_feature_flags" ioctl or something for going forward. Then you can just turn on new bits in the flags as new features are added.

That could be done but I do not expect retire features so far so version is about the same. Plus, what guarantees that someone in the future won't write a utility that compares exact capability bitmap and refuse to work when new ones will be added?

Signature · 1 line
Dmitry
#60 lore raw
In reply to Mark Lord
Quoted 9 lines · Mark Lord
Quoted 8 lines · Dmitry Torokhov
Quoted 7 lines · Mark Lord
Quoted 2 lines · Dmitry Torokhov

I do not consider lsinput refusing to work a regression.

Obviously, since you don't use that tool.
Those of us who do use it see this as broken userspace compatibility.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Who the hell reviews this crap, anyway?
Code like that should never have made it upstream in the first place.

You are more than welcome spend more time on reviews.

Somehow I detect a totally lack of sincerity there.

No, not really. If we known about Ubuntu's employ of such utility before we'd try to come up with workaround or updated the utility proactively so user-visible changes would be limited.

Quoted 6 lines

But thanks for fixing the worst of this regression, at least.

Perhaps you might think about eventually fixing the bad use of -EINVAL in future revisions. One way perhaps to approach that, would be to begin fixing it internally,

Yes, that is on my lest (unless somebody beats me to it). Won't help with the older kernels though, unfortunately.

Quoted 2 lines

but still returning the same things from the actual f_ops->ioctl() routine.

Not sure if this is needed.

Quoted 7 lines

Then eventually provide new ioctl numbers which return the correct -ENOTTY (or whatever is best there), rather than converting to -EVINAL at the interface. Then a nice multi-year overlap, with a scheduled removal of the old codes some day.

Then the input subsystem would work more like most other subsystems, and make userspace programming simpler and easier to "get correct".

I do not believe that such characterization is called for. We did fix the breakage that was ABI breakage. The version issue is different. If we go by what you say _none_ of the versions anywhere can be changed ever because there might be a program that does not expect new version.

Signature · 1 line
Dmitry
author
#61 lore raw
In reply to Mark Lord
Quoted 1 line · Mark Lord

On 11-01-25 09:00 PM, Dmitry Torokhov wrote:

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

That behaviour is new, with the proposed "fix" patch from this thread. So the "fix" itself appears to also break userspace.

The ir-keyboard program reports: IR keytable control version 0.8.2

Cheers

author
#62 lore raw
Quoted 22 lines · Mark Lord
Quoted 1 line · Mark Lord

On 11-01-25 09:00 PM, Dmitry Torokhov wrote:

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

Quoted 2 lines

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

Note: I tried to capture an strace of ir-keyboard segfaulting during boot (as above), but doing so kills the system (hangs on boot).

The command from udev was: /usr/bin/ir-keytable -a /etc/rc_maps.cfg -s rc0

#63 lore raw
Quoted 23 lines · Mark Lord
Quoted 22 lines · Mark Lord
Quoted 1 line · Mark Lord

On 11-01-25 09:00 PM, Dmitry Torokhov wrote:

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

Quoted 7 lines
Quoted 2 lines

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

Note: I tried to capture an strace of ir-keyboard segfaulting during boot (as above), but doing so kills the system (hangs on boot).

The command from udev was: /usr/bin/ir-keytable -a /etc/rc_maps.cfg -s rc0

Does it die when you try to invoke the command by hand? Can you see where?

Signature · 1 line
Dmitry
author
#64 lore raw
Quoted 27 lines · Dmitry Torokhov
Quoted 26 lines · Mark Lord
Quoted 24 lines · Mark Lord
Quoted 1 line · Mark Lord

On 11-01-25 09:00 PM, Dmitry Torokhov wrote:

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

Quoted 6 lines
Quoted 4 lines

Note: I tried to capture an strace of ir-keyboard segfaulting during boot (as above), but doing so kills the system (hangs on boot).

The command from udev was: /usr/bin/ir-keytable -a /etc/rc_maps.cfg -s rc0

Does it die when you try to invoke the command by hand? Can you see where?

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

It does NOT segfault on the stock 2.6.37 kernel, without the patch.

-ml

#65 lore raw
Quoted 36 lines · Mark Lord
Quoted 27 lines · Dmitry Torokhov
Quoted 26 lines · Mark Lord
Quoted 24 lines · Mark Lord
Quoted 1 line · Mark Lord

On 11-01-25 09:00 PM, Dmitry Torokhov wrote:

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

Quoted 6 lines
Quoted 4 lines

Note: I tried to capture an strace of ir-keyboard segfaulting during boot (as above), but doing so kills the system (hangs on boot).

The command from udev was: /usr/bin/ir-keytable -a /etc/rc_maps.cfg -s rc0

Does it die when you try to invoke the command by hand? Can you see where?

Quoted 6 lines

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

It does NOT segfault on the stock 2.6.37 kernel, without the patch.

I must admit I am baffled. The patch in question only affects the EVIOCGKEYCODE path whereas '-a' means "automatically load appropriate keymap" and as far as I can see it does not call EVIOCGKEYCODE, only EVIOCSKEYCODE...

Mauro, any ideas?

BTW, I wonder what package ir-keytable is coming from? Ubuntu seems to have v4l-utils at 0.8.1-2 and you say yours is 0.8.2...

Thanks.

Signature · 1 line
Dmitry
#66 lore raw

Em 27-01-2011 04:38, Dmitry Torokhov escreveu:

Quoted 49 lines · Mark Lord
Quoted 36 lines · Dmitry Torokhov
Quoted 27 lines · Mark Lord
Quoted 26 lines · Mark Lord
Quoted 24 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

Quoted 6 lines
Quoted 4 lines

Note: I tried to capture an strace of ir-keyboard segfaulting during boot (as above), but doing so kills the system (hangs on boot).

The command from udev was: /usr/bin/ir-keytable -a /etc/rc_maps.cfg -s rc0

Does it die when you try to invoke the command by hand? Can you see where?

Quoted 6 lines

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

It does NOT segfault on the stock 2.6.37 kernel, without the patch.

I must admit I am baffled. The patch in question only affects the EVIOCGKEYCODE path whereas '-a' means "automatically load appropriate keymap" and as far as I can see it does not call EVIOCGKEYCODE, only EVIOCSKEYCODE...

Quoted 4 lines

Mauro, any ideas?

BTW, I wonder what package ir-keytable is coming from? Ubuntu seems to have v4l-utils at 0.8.1-2 and you say yours is 0.8.2...

0.8.2 is the new version that was released in Jan, 25. One of the major differences is that it now installs the udev rules, with make install.

This is there in order to prepare to the removal of all those in-kernel Remote Controller tables.

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

I suspect that Mark may be experiencing a similar issue.

I don't think that most of the c/c will be able to help with this issue. So, I think that the better is if Mark could either open a Buzgilla or send me and linux-media the dmesg logs and other information that he may have about what's happening. It would be interesting if he can remove the udev rule, boot it and run the udev command manually, to see if this is really a race condition or something else. If it fails manually, the better is to activate ftrace logs for rc-core and for the driver functions and send us the trace logs.

Thanks,
Mauro

author
#67 lore raw

On 11-01-27 05:30 AM, Mauro Carvalho Chehab wrote:
..

Quoted 2 lines

0.8.2 is the new version that was released in Jan, 25. One of the major differences is that it now installs the udev rules, with make install.

Oh, and there's no "make uninstall" option in the Makefile, either. Where does it put those tentacles, so that I can delete them again ?

Quoted 3 lines

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

Well, all I know is that it does NOT segfault without the patch, and now it does. At this point I should refer you back to Linus's posts earlier in this thread for the definition of "breaks userspace".

Quoted 7 lines

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

I suspect that Mark may be experiencing a similar issue.

Could be. I really don't know.
Again, I could not care less about ir-keyboard,
as I don't use it here at all.

But also again, this thread isn't about what I need fixed, but rather about broken userspace from 2.6.36 onward. And the patch to "fix" it seems to possibly cause more breakage.

Cheers

#68 lore raw
In reply to Mauro Carvalho Chehab
Quoted 10 lines · Mauro Carvalho Chehab

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

Well, this is quite possible. The usev ruls in the v4l-utils reads:

ACTION=="add", SUBSYSTEM=="rc", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $name"

So we act when we add RC device to the system. The corresponding input device has not been registered yet (and will not be for some time because before creating input ddevice we invoke request_module() to load initial rc map module) so the tool runs simultaneously with kernel registering input device and it could very well be it can't find something it really wants.

This would explain why Mark sees the segfault only when invoked via udev but not when ran manually.

However I still do not understand why Mark does not see the same issue without the patch. Like I said, maybe if Mark could recompile with debug data and us a core we'd see what is going on.

BTW, that means that we need to redo udev rules. Maybe we should split the utility into 2 parts - one dealing with rcX device and for keymap setting reuse udev's existing utility that adjusts maps on ann input devices, not for RCs only.

Signature · 1 line
Dmitry
#69 lore raw

Em 27-01-2011 15:21, Dmitry Torokhov escreveu:

Quoted 23 lines · Mauro Carvalho Chehab
Quoted 10 lines

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

Well, this is quite possible. The usev ruls in the v4l-utils reads:

ACTION=="add", SUBSYSTEM=="rc", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $name"

So we act when we add RC device to the system. The corresponding input device has not been registered yet (and will not be for some time because before creating input ddevice we invoke request_module() to load initial rc map module) so the tool runs simultaneously with kernel registering input device and it could very well be it can't find something it really wants.

Quoted 6 lines

This would explain why Mark sees the segfault only when invoked via udev but not when ran manually.

However I still do not understand why Mark does not see the same issue without the patch. Like I said, maybe if Mark could recompile with debug data and us a core we'd see what is going on.

Race conditions are hard to track... probably the new code added some delay, and this allowed the request_module() to finish his job.

Quoted 1 line

BTW, that means that we need to redo udev rules.

If there's a race condition, then the proper fix is to lock the driver until it is ready to receive a fops. Maybe we'll need a mutex to preventing opening the device until it is completely initialized.

It is hard to tell, as Mark didn't provide us yet the dmesg info (at least on the emails I was c/c), so I don't even know what device he has, and what drivers are used.

Quoted 4 lines

Maybe we should split
the utility into 2 parts - one dealing with rcX device and for keymap setting reuse udev's existing utility that adjusts maps on ann input devices, not for RCs only.

It could be done, but then we'll need to pollute the existing input tools with RC-specific stuff. For IR, there are some additional steps, like the need to select the IR protocol, otherwise the keytable is useless. Also, the keytable and persistent info is provided via /sys/class/rc/rc?/uevent. So, the tool need to first read the RC class, check what keytable should be associated with that device (based on a custom file), and load the proper table.

Also, I'm currently working on a way to map media keys for remote controllers into X11 (basically, mapping them into the keyspace between 8-255, passing through Xorg evdev.c, and then mapping back into some X11 symbols). This way, we don't need to violate the X11 protocol. (Yeah, I know this is hacky, but while X11 cannot pass the full evdev keycode, at least the Remote Controllers will work). This probably means that we may need to add some DBus logic inside ir-keytable, when called via udev, to allow it to announce to X11.

Regards,
Mauro

#70 lore raw
Quoted 31 lines · Mauro Carvalho Chehab

Em 27-01-2011 15:21, Dmitry Torokhov escreveu:

Quoted 23 lines · Mauro Carvalho Chehab
Quoted 10 lines

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

Well, this is quite possible. The usev ruls in the v4l-utils reads:

ACTION=="add", SUBSYSTEM=="rc", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $name"

So we act when we add RC device to the system. The corresponding input device has not been registered yet (and will not be for some time because before creating input ddevice we invoke request_module() to load initial rc map module) so the tool runs simultaneously with kernel registering input device and it could very well be it can't find something it really wants.

Quoted 6 lines

This would explain why Mark sees the segfault only when invoked via udev but not when ran manually.

However I still do not understand why Mark does not see the same issue without the patch. Like I said, maybe if Mark could recompile with debug data and us a core we'd see what is going on.

Quoted 8 lines

Race conditions are hard to track... probably the new code added some delay, and this allowed the request_module() to finish his job.

Quoted 1 line

BTW, that means that we need to redo udev rules.

If there's a race condition, then the proper fix is to lock the driver until it is ready to receive a fops. Maybe we'll need a mutex to preventing opening the device until it is completely initialized.

No, not at all. The devices are ready to handle everything when they are created, it's just some devices are not there yet. What you do with current udev rule is similar to trying to mount filesystem as soon as you discover a PCI SCSI card. The controller is there but disks have not been discovered, block devices have not been created, and so on.

Quoted 4 lines

It is hard to tell, as Mark didn't provide us yet the dmesg info (at least on the emails I was c/c), so I don't even know what device he has, and what drivers are used.

I belie you have been copied on the mail that had the following snippet:

Quoted 8 lines

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

Quoted 8 lines
Quoted 4 lines

Maybe we should split
the utility into 2 parts - one dealing with rcX device and for keymap setting reuse udev's existing utility that adjusts maps on ann input devices, not for RCs only.

It could be done, but then we'll need to pollute the existing input tools with RC-specific stuff. For IR, there are some additional steps, like the need to select the IR protocol, otherwise the keytable is useless.

That should be done by the separate utility that fires up when udev gets event for /sys/class/rc/rcX device.

Quoted 4 lines

Also, the keytable and persistent info is provided via /sys/class/rc/rc?/uevent. So, the tool need to first read the RC class, check what keytable should be associated with that device (based on a custom file), and load the proper table.

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Quoted 8 lines

Also, I'm currently working on a way to map media keys for remote controllers into X11 (basically, mapping them into the keyspace between 8-255, passing through Xorg evdev.c, and then mapping back into some X11 symbols). This way, we don't need to violate the X11 protocol. (Yeah, I know this is hacky, but while X11 cannot pass the full evdev keycode, at least the Remote Controllers will work). This probably means that we may need to add some DBus logic inside ir-keytable, when called via udev, to allow it to announce to X11.

The same issue is present with other types of input devices (multimedia keyboards emitting codes that X can't consume) and so it again would make sense to enhance udev's utility instead of confining it all to ir-keytable.

Thanks.

Signature · 1 line
Dmitry
#71 lore raw

Em 28-01-2011 07:39, Dmitry Torokhov escreveu:

Quoted 41 lines · Mauro Carvalho Chehab
Quoted 31 lines

Em 27-01-2011 15:21, Dmitry Torokhov escreveu:

Quoted 23 lines · Mauro Carvalho Chehab
Quoted 10 lines

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

Well, this is quite possible. The usev ruls in the v4l-utils reads:

ACTION=="add", SUBSYSTEM=="rc", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $name"

So we act when we add RC device to the system. The corresponding input device has not been registered yet (and will not be for some time because before creating input ddevice we invoke request_module() to load initial rc map module) so the tool runs simultaneously with kernel registering input device and it could very well be it can't find something it really wants.

Quoted 6 lines

This would explain why Mark sees the segfault only when invoked via udev but not when ran manually.

However I still do not understand why Mark does not see the same issue without the patch. Like I said, maybe if Mark could recompile with debug data and us a core we'd see what is going on.

Quoted 8 lines

Race conditions are hard to track... probably the new code added some delay, and this allowed the request_module() to finish his job.

Quoted 1 line

BTW, that means that we need to redo udev rules.

If there's a race condition, then the proper fix is to lock the driver until it is ready to receive a fops. Maybe we'll need a mutex to preventing opening the device until it is completely initialized.

Quoted 5 lines

No, not at all. The devices are ready to handle everything when they are created, it's just some devices are not there yet. What you do with current udev rule is similar to trying to mount filesystem as soon as you discover a PCI SCSI card. The controller is there but disks have not been discovered, block devices have not been created, and so on.

The rc-core register (and the corresponding input register) is done when the device detected a remote controller, so, it should be safe to register on that point. If not, IMHO, there's a bug somewhere.

Yet, I agree that udev tries to set devices too fast. It would be better if it would wait for a few milisseconds, to reduce the risk of race conditions.

Quoted 4 lines
Quoted 3 lines

It is hard to tell, as Mark didn't provide us yet the dmesg info (at least on the emails I was c/c), so I don't even know what device he has, and what drivers are used.

Quoted 8 lines

I belie you have been copied on the mail that had the following snippet:

Quoted 6 lines

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

Ok, the last line says it is a ivtv board, using IR. However, it doesn't show the I2C detection of other devices that might be racing to gain access to the I2C bus, nor if some OOPS were hit by kernel.

I don't have any ivtv boards handy, but there are some developers at linux-media ML that may help with this.

Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

Maybe we should split
the utility into 2 parts - one dealing with rcX device and for keymap setting reuse udev's existing utility that adjusts maps on ann input devices, not for RCs only.

It could be done, but then we'll need to pollute the existing input tools with RC-specific stuff. For IR, there are some additional steps, like the need to select the IR protocol, otherwise the keytable is useless.

That should be done by the separate utility that fires up when udev gets event for /sys/class/rc/rcX device.

Quoted 7 lines
Quoted 4 lines

Also, the keytable and persistent info is provided via /sys/class/rc/rc?/uevent. So, the tool need to first read the RC class, check what keytable should be associated with that device (based on a custom file), and load the proper table.

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Yes, it can, if you add the IR protocol selection on that tool. A remote controller keycode table has both the protocol and the keycodes. This basically means to merge 99% of the logic inside ir-keytable into the evdev generic tool.

I'm not against it, although I prefer a specialized tool for RC.

Quoted 8 lines
Quoted 7 lines

Also, I'm currently working on a way to map media keys for remote controllers into X11 (basically, mapping them into the keyspace between 8-255, passing through Xorg evdev.c, and then mapping back into some X11 symbols). This way, we don't need to violate the X11 protocol. (Yeah, I know this is hacky, but while X11 cannot pass the full evdev keycode, at least the Remote Controllers will work). This probably means that we may need to add some DBus logic inside ir-keytable, when called via udev, to allow it to announce to X11.

Quoted 4 lines

The same issue is present with other types of input devices (multimedia keyboards emitting codes that X can't consume) and so it again would make sense to enhance udev's utility instead of confining it all to ir-keytable.

I agree with you, but I'm not sure if we can find a solution that will work for both RC and media keyboards, as X11 evdev just maps keyboards on the 8-255 range. I was thinking to add a detection there for RC, and use a separate map for them, as RC don't need most of the normal keyboard keys.

Cheers,
Mauro

#72 lore raw
Quoted 48 lines · Mauro Carvalho Chehab

Em 28-01-2011 07:39, Dmitry Torokhov escreveu:

Quoted 41 lines · Mauro Carvalho Chehab
Quoted 31 lines

Em 27-01-2011 15:21, Dmitry Torokhov escreveu:

Quoted 23 lines · Mauro Carvalho Chehab
Quoted 10 lines

On my tests here, this is working fine, with Fedora and RHEL 6, on my usual test devices, so I don't believe that the tool itself is broken, nor I think that the issue is due to the fix patch.

I remember that when Kay added a persistence utility tool that opens a V4L device in order to read some capabilities, this caused a race condition into a number of drivers that use to register the video device too early. The result is that udev were opening the device before the end of the register process, causing OOPS and other problems.

Well, this is quite possible. The usev ruls in the v4l-utils reads:

ACTION=="add", SUBSYSTEM=="rc", RUN+="/usr/bin/ir-keytable -a /etc/rc_maps.cfg -s $name"

So we act when we add RC device to the system. The corresponding input device has not been registered yet (and will not be for some time because before creating input ddevice we invoke request_module() to load initial rc map module) so the tool runs simultaneously with kernel registering input device and it could very well be it can't find something it really wants.

Quoted 6 lines

This would explain why Mark sees the segfault only when invoked via udev but not when ran manually.

However I still do not understand why Mark does not see the same issue without the patch. Like I said, maybe if Mark could recompile with debug data and us a core we'd see what is going on.

Quoted 8 lines

Race conditions are hard to track... probably the new code added some delay, and this allowed the request_module() to finish his job.

Quoted 1 line

BTW, that means that we need to redo udev rules.

If there's a race condition, then the proper fix is to lock the driver until it is ready to receive a fops. Maybe we'll need a mutex to preventing opening the device until it is completely initialized.

Quoted 5 lines

No, not at all. The devices are ready to handle everything when they are created, it's just some devices are not there yet. What you do with current udev rule is similar to trying to mount filesystem as soon as you discover a PCI SCSI card. The controller is there but disks have not been discovered, block devices have not been created, and so on.

Quoted 3 lines

The rc-core register (and the corresponding input register) is done when the device detected a remote controller, so, it should be safe to register on that point. If not, IMHO, there's a bug somewhere.

It is not a matter of safe or unsafe registration. Registration is fine. The problem is that with the current set up is that utility is fired when trunk of [sub]tree is created, but the utility wants to operate on leaves which may not be there yet.

Quoted 2 lines

Yet, I agree that udev tries to set devices too fast.

It tries to set devices exacty when you tell it to do so. It's not like it goes trolling for random devices is sysfs.

Quoted 2 lines

It would be better if
it would wait for a few milisseconds, to reduce the risk of race conditions.

Gah, I really prefer using properly engineered solutions instead of adding crutches.

Quoted 38 lines
Quoted 13 lines
Quoted 4 lines

It is hard to tell, as Mark didn't provide us yet the dmesg info (at least on the emails I was c/c), so I don't even know what device he has, and what drivers are used.

I belie you have been copied on the mail that had the following snippet:

Quoted 6 lines

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

Ok, the last line says it is a ivtv board, using IR. However, it doesn't show the I2C detection of other devices that might be racing to gain access to the I2C bus, nor if some OOPS were hit by kernel.

I don't have any ivtv boards handy, but there are some developers at linux-media ML that may help with this.

Quoted 17 lines
Quoted 8 lines
Quoted 4 lines

Maybe we should split
the utility into 2 parts - one dealing with rcX device and for keymap setting reuse udev's existing utility that adjusts maps on ann input devices, not for RCs only.

It could be done, but then we'll need to pollute the existing input tools with RC-specific stuff. For IR, there are some additional steps, like the need to select the IR protocol, otherwise the keytable is useless.

That should be done by the separate utility that fires up when udev gets event for /sys/class/rc/rcX device.

Quoted 4 lines

Also, the keytable and persistent info is provided via /sys/class/rc/rc?/uevent. So, the tool need to first read the RC class, check what keytable should be associated with that device (based on a custom file), and load the proper table.

Quoted 7 lines
Quoted 2 lines

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Yes, it can, if you add the IR protocol selection on that tool. A remote controller keycode table has both the protocol and the keycodes. This basically means to merge 99% of the logic inside ir-keytable into the evdev generic tool.

Or just have an utility producing keymap name and feed it as input to the generic tools. The way most of utilities work...

Quoted 16 lines

I'm not against it, although I prefer a specialized tool for RC.

Quoted 8 lines
Quoted 7 lines

Also, I'm currently working on a way to map media keys for remote controllers into X11 (basically, mapping them into the keyspace between 8-255, passing through Xorg evdev.c, and then mapping back into some X11 symbols). This way, we don't need to violate the X11 protocol. (Yeah, I know this is hacky, but while X11 cannot pass the full evdev keycode, at least the Remote Controllers will work). This probably means that we may need to add some DBus logic inside ir-keytable, when called via udev, to allow it to announce to X11.

Quoted 4 lines

The same issue is present with other types of input devices (multimedia keyboards emitting codes that X can't consume) and so it again would make sense to enhance udev's utility instead of confining it all to ir-keytable.

Quoted 5 lines

I agree with you, but I'm not sure if we can find a solution that will work for both RC and media keyboards, as X11 evdev just maps keyboards on the 8-255 range. I was thinking to add a detection there for RC, and use a separate map for them, as RC don't need most of the normal keyboard keys.

Well, there will always be clashes - there is reason why evdev goes beyond 255 keycodes...

Thanks.

Signature · 1 line
Dmitry
#73 lore raw

Em 28-01-2011 14:40, Dmitry Torokhov escreveu:

Quoted 10 lines · Mauro Carvalho Chehab
Quoted 4 lines

The rc-core register (and the corresponding input register) is done when the device detected a remote controller, so, it should be safe to register on that point. If not, IMHO, there's a bug somewhere.

It is not a matter of safe or unsafe registration. Registration is fine. The problem is that with the current set up is that utility is fired when trunk of [sub]tree is created, but the utility wants to operate on leaves which may not be there yet.

I'm not an udev expert. Is there a udev event that hits only after having the driver completely loaded? Starting an udev rule while modprobe is still running is asking for race conditions.

I'm not entirely convinced that this is the bug that Mark is hitting, as rc-core does all needed setups before registering the evdev device. We need the core and the dmesg to be sure about what's happening there.

Quoted 10 lines
Quoted 1 line

Yet, I agree that udev tries to set devices too fast.

It tries to set devices exacty when you tell it to do so. It's not like it goes trolling for random devices is sysfs.

Quoted 2 lines

It would be better if
it would wait for a few milisseconds, to reduce the risk of race conditions.

Gah, I really prefer using properly engineered solutions instead of adding crutches.

I agree.

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Yes, it can, if you add the IR protocol selection on that tool. A remote controller keycode table has both the protocol and the keycodes. This basically means to merge 99% of the logic inside ir-keytable into the evdev generic tool.

Or just have an utility producing keymap name and feed it as input to the generic tools. The way most of utilities work...

I don't like the idea of running a some logic at udev that would generate such keymap in runtime just before calling the generic tool. The other alternative (e. g.) to maintain the RC-protocol dependent keytables separate from the RC protocol used by each table will be a maintenance nightmare.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 7 lines

Also, I'm currently working on a way to map media keys for remote controllers into X11 (basically, mapping them into the keyspace between 8-255, passing through Xorg evdev.c, and then mapping back into some X11 symbols). This way, we don't need to violate the X11 protocol. (Yeah, I know this is hacky, but while X11 cannot pass the full evdev keycode, at least the Remote Controllers will work). This probably means that we may need to add some DBus logic inside ir-keytable, when called via udev, to allow it to announce to X11.

The same issue is present with other types of input devices (multimedia keyboards emitting codes that X can't consume) and so it again would make sense to enhance udev's utility instead of confining it all to ir-keytable.

Quoted 8 lines
Quoted 5 lines

I agree with you, but I'm not sure if we can find a solution that will work for both RC and media keyboards, as X11 evdev just maps keyboards on the 8-255 range. I was thinking to add a detection there for RC, and use a separate map for them, as RC don't need most of the normal keyboard keys.

Well, there will always be clashes - there is reason why evdev goes beyond 255 keycodes...

Yeah. The most appropriate fix would be for X to just use the full evdev keycode range. However, I'm not seeing any indication that such change will happen soon. Not sure if there are some news about it at LCA, as there were one speech about this subject there.

Cheers,
Mauro

#74 lore raw
Quoted 7 lines · Mauro Carvalho Chehab

Em 28-01-2011 14:40, Dmitry Torokhov escreveu:

Quoted 6 lines · Mauro Carvalho Chehab
Quoted 4 lines

The rc-core register (and the corresponding input register) is done when the device detected a remote controller, so, it should be safe to register on that point. If not, IMHO, there's a bug somewhere.

Quoted 7 lines
Quoted 4 lines

It is not a matter of safe or unsafe registration. Registration is fine. The problem is that with the current set up is that utility is fired when trunk of [sub]tree is created, but the utility wants to operate on leaves which may not be there yet.

I'm not an udev expert. Is there a udev event that hits only after having the driver completely loaded?

Define completely loaded? For a PCI SCSI controller does fully loaded mean all attached devices are discovered and registered with block layer? For a wireless NIC does it mean that it assocuated with an AP? What if you have more than one device that driver serves?

So teh answer is no and there should not be.

Quoted 3 lines

Starting an udev rule while modprobe is
still running is asking for race conditions.

Not if we write stuff properly.

Quoted 2 lines

I'm not entirely convinced that this is the bug that Mark is hitting, as

I do not know yet.

Quoted 2 lines

rc-core does all needed setups before registering the evdev device. We need the core and the dmesg to be sure about what's happening there.

I will say it again. Your udev rule triggers when you create rcX device. eventX device may apeear 2 hours after that (I could have evdev as a module and blacklisted and load it later manually).

You need to split it into 2 separate steps:

1. Triggers when rcX appears, accesses only rcX and it's parents and does rcX related stuff.

2. Triggers when eventX appears and loads keymap and what not. Because it is a child of rcX (in specific case of remotes) it may examine rcX attributes as well.

Quoted 22 lines
Quoted 11 lines
Quoted 2 lines

Yet, I agree that udev tries to set devices too fast.

It tries to set devices exacty when you tell it to do so. It's not like it goes trolling for random devices is sysfs.

Quoted 2 lines

It would be better if
it would wait for a few milisseconds, to reduce the risk of race conditions.

Gah, I really prefer using properly engineered solutions instead of adding crutches.

I agree.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Yes, it can, if you add the IR protocol selection on that tool. A remote controller keycode table has both the protocol and the keycodes. This basically means to merge 99% of the logic inside ir-keytable into the evdev generic tool.

Quoted 5 lines
Quoted 2 lines

Or just have an utility producing keymap name and feed it as input to the generic tools. The way most of utilities work...

I don't like the idea of running a some logic at udev that would generate such keymap in runtime just before calling the generic tool. The other

Why? You'd just call something like:

keymap $name rc-keymap-name -d $name

where 'keymap' is udev's utility and 'rc-keymap-name' is new utility that incorporates map selection logic currently found in rc-keytable.

It looks like format of the keymaps is compatible between 'keymap' and 'ir-keytable' and metadata that is present in your keymaps will not confuse 'keymap' utility.

Quoted 2 lines

alternative (e. g.) to maintain the RC-protocol dependent keytables separate from the RC protocol used by each table will be a maintenance nightmare.

I do not propose splitting keytables, I propose splittign utilities. ir-keytable is a kitchen sink now. It implements 'keymap', 'evtest' and bucnch of other stuff and would be much cleaner if split apart.

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 9 lines
Quoted 8 lines

Also, I'm currently working on a way to map media keys for remote controllers into X11 (basically, mapping them into the keyspace between 8-255, passing through Xorg evdev.c, and then mapping back into some X11 symbols). This way, we don't need to violate the X11 protocol. (Yeah, I know this is hacky, but while X11 cannot pass the full evdev keycode, at least the Remote Controllers will work). This probably means that we may need to add some DBus logic inside ir-keytable, when called via udev, to allow it to announce to X11.

Quoted 4 lines

The same issue is present with other types of input devices (multimedia keyboards emitting codes that X can't consume) and so it again would make sense to enhance udev's utility instead of confining it all to ir-keytable.

I agree with you, but I'm not sure if we can find a solution that will work for both RC and media keyboards, as X11 evdev just maps keyboards on the 8-255 range. I was thinking to add a detection there for RC, and use a separate map for them, as RC don't need most of the normal keyboard keys.

Quoted 8 lines
Quoted 2 lines

Well, there will always be clashes - there is reason why evdev goes beyond 255 keycodes...

Yeah. The most appropriate fix would be for X to just use the full evdev keycode range. However, I'm not seeing any indication that such change will happen soon. Not sure if there are some news about it at LCA, as there were one speech about this subject there.

Would be nice...

Thanks.

Signature · 1 line
Dmitry
#75 lore raw

Em 28-01-2011 15:33, Dmitry Torokhov escreveu:

Quoted 32 lines · Mauro Carvalho Chehab
Quoted 7 lines

Em 28-01-2011 14:40, Dmitry Torokhov escreveu:

Quoted 6 lines · Mauro Carvalho Chehab
Quoted 4 lines

The rc-core register (and the corresponding input register) is done when the device detected a remote controller, so, it should be safe to register on that point. If not, IMHO, there's a bug somewhere.

Quoted 7 lines
Quoted 4 lines

It is not a matter of safe or unsafe registration. Registration is fine. The problem is that with the current set up is that utility is fired when trunk of [sub]tree is created, but the utility wants to operate on leaves which may not be there yet.

I'm not an udev expert. Is there a udev event that hits only after having the driver completely loaded?

Define completely loaded? For a PCI SCSI controller does fully loaded mean all attached devices are discovered and registered with block layer? For a wireless NIC does it mean that it assocuated with an AP? What if you have more than one device that driver serves?

So teh answer is no and there should not be.

Quoted 3 lines

Starting an udev rule while modprobe is
still running is asking for race conditions.

Not if we write stuff properly.

Quoted 2 lines

I'm not entirely convinced that this is the bug that Mark is hitting, as

Quoted 8 lines

I do not know yet.

Quoted 2 lines

rc-core does all needed setups before registering the evdev device. We need the core and the dmesg to be sure about what's happening there.

I will say it again. Your udev rule triggers when you create rcX device. eventX device may apeear 2 hours after that (I could have evdev as a module and blacklisted and load it later manually).

Blacklisting it won't (or shouldn't work).

Quoted 1 line

From rc-main, the registering sequence is:

	dev_set_name(&dev->dev, "rc%ld", dev->devno);
	dev_set_drvdata(&dev->dev, dev);
	rc = device_add(&dev->dev);
	if (rc)
		return rc;

	rc = ir_setkeytable(dev, rc_map);
	if (rc)
		goto out_dev;

	dev->input_dev->dev.parent = &dev->dev;
	memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id));
	dev->input_dev->phys = dev->input_phys;
	dev->input_dev->name = dev->input_name;
	rc = input_register_device(dev->input_dev);
	if (rc)
		goto out_table;

rc-main will wait for input_register_device() to finish, so even if you blacklist it, rc-core will load it, in order to solve the symbol dependency.

Btw, there's really a race issue there: device_add is happening before input_register_device(), so the udev rule will cause troubles.

Quoted 8 lines

You need to split it into 2 separate steps:

1. Triggers when rcX appears, accesses only rcX and it's parents and does rcX related stuff.

2. Triggers when eventX appears and loads keymap and what not. Because it is a child of rcX (in specific case of remotes) it may examine rcX attributes as well.

The fix is probably simpler: we need to change the udev rules to work at evdev registration and only if the device is a remote controller. This should solve the current issue.

Quoted 29 lines
Quoted 21 lines
Quoted 10 lines
Quoted 1 line

Yet, I agree that udev tries to set devices too fast.

It tries to set devices exacty when you tell it to do so. It's not like it goes trolling for random devices is sysfs.

Quoted 2 lines

It would be better if
it would wait for a few milisseconds, to reduce the risk of race conditions.

Gah, I really prefer using properly engineered solutions instead of adding crutches.

I agree.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Yes, it can, if you add the IR protocol selection on that tool. A remote controller keycode table has both the protocol and the keycodes. This basically means to merge 99% of the logic inside ir-keytable into the evdev generic tool.

Quoted 5 lines
Quoted 2 lines

Or just have an utility producing keymap name and feed it as input to the generic tools. The way most of utilities work...

I don't like the idea of running a some logic at udev that would generate such keymap in runtime just before calling the generic tool. The other

Why? You'd just call something like:

Quoted 8 lines

keymap $name rc-keymap-name -d $name

where 'keymap' is udev's utility and 'rc-keymap-name' is new utility that incorporates map selection logic currently found in rc-keytable.

It looks like format of the keymaps is compatible between 'keymap' and 'ir-keytable' and metadata that is present in your keymaps will not confuse 'keymap' utility.

The format is, currently compatible. However, we'll likely need to change it (or to allow the tool to handle also a different format), due to some reasons:
1) Protocol and the device name where it is found by default is currently a comment;
2) We'll need to add a field there specifying the number of the bits to be used by the keymap table, in order to use the proper length with _V2 ioctls;
3) There are hundreds of keymaps already created for lircd. It would be nice to support lircd format, in order to make life easier for those that use lirc.

If you want to add these to the generic tool, that's fine for me, but, IMO, this doesn't sound a good idea. There are already specialized tools for other kinds of input devices (mouse: gpm; joystick: jstest; etc). It seems a bad idea to merge them into the generic tools.

I think it is better to have a tool that just handle one kind of device, but does it well, than trying to extend a generic tool to cover all possible devices, and adding lots of caveats there for it to handle all the specifics.

Quoted 6 lines
Quoted 2 lines

alternative (e. g.) to maintain the RC-protocol dependent keytables separate from the RC protocol used by each table will be a maintenance nightmare.

I do not propose splitting keytables, I propose splittign utilities. ir-keytable is a kitchen sink now. It implements 'keymap', 'evtest' and bucnch of other stuff and would be much cleaner if split apart.

It may be broken into a few utilities, by creating a library with the common code. I'll think about that when I have some spare time for it.

Cheers,
Mauro.

#76 lore raw
Quoted 64 lines · Mauro Carvalho Chehab

Em 28-01-2011 15:33, Dmitry Torokhov escreveu:

Quoted 32 lines · Mauro Carvalho Chehab
Quoted 7 lines

Em 28-01-2011 14:40, Dmitry Torokhov escreveu:

Quoted 6 lines · Mauro Carvalho Chehab
Quoted 4 lines

The rc-core register (and the corresponding input register) is done when the device detected a remote controller, so, it should be safe to register on that point. If not, IMHO, there's a bug somewhere.

Quoted 7 lines
Quoted 4 lines

It is not a matter of safe or unsafe registration. Registration is fine. The problem is that with the current set up is that utility is fired when trunk of [sub]tree is created, but the utility wants to operate on leaves which may not be there yet.

I'm not an udev expert. Is there a udev event that hits only after having the driver completely loaded?

Define completely loaded? For a PCI SCSI controller does fully loaded mean all attached devices are discovered and registered with block layer? For a wireless NIC does it mean that it assocuated with an AP? What if you have more than one device that driver serves?

So teh answer is no and there should not be.

Quoted 3 lines

Starting an udev rule while modprobe is
still running is asking for race conditions.

Not if we write stuff properly.

Quoted 2 lines

I'm not entirely convinced that this is the bug that Mark is hitting, as

Quoted 8 lines

I do not know yet.

Quoted 2 lines

rc-core does all needed setups before registering the evdev device. We need the core and the dmesg to be sure about what's happening there.

I will say it again. Your udev rule triggers when you create rcX device. eventX device may apeear 2 hours after that (I could have evdev as a module and blacklisted and load it later manually).

Blacklisting it won't (or shouldn't work).

From rc-main, the registering sequence is:

	dev_set_name(&dev->dev, "rc%ld", dev->devno);
	dev_set_drvdata(&dev->dev, dev);
	rc = device_add(&dev->dev);
	if (rc)
		return rc;

	rc = ir_setkeytable(dev, rc_map);
	if (rc)
		goto out_dev;

	dev->input_dev->dev.parent = &dev->dev;
	memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id));
	dev->input_dev->phys = dev->input_phys;
	dev->input_dev->name = dev->input_name;
	rc = input_register_device(dev->input_dev);
	if (rc)
		goto out_table;
Quoted 2 lines

rc-main will wait for input_register_device() to finish, so even if you blacklist it, rc-core will load it, in order to solve the symbol dependency.

No, input_register_device() and input core itself does not have symbol dependency on evdev (which provides /dev/input/eventX), which is just an input handler. A very important, but still an optional, handler.

Quoted 2 lines

Btw, there's really a race issue there: device_add is happening before input_register_device(), so the udev rule will cause troubles.

That's what I have been saying in the last 3+ emails, yes.

Quoted 6 lines
Quoted 6 lines

You need to split it into 2 separate steps:

1. Triggers when rcX appears, accesses only rcX and it's parents and does rcX related stuff.

Quoted 7 lines
Quoted 3 lines

2. Triggers when eventX appears and loads keymap and what not. Because it is a child of rcX (in specific case of remotes) it may examine rcX attributes as well.

The fix is probably simpler: we need to change the udev rules to work at evdev registration and only if the device is a remote controller. This should solve the current issue.

The problem I have with it is that it violates layering. You affect different subsystems/layers, why do you insist on jamming them togetehr? Don't do the kitchen sink style, pretty please.

Quoted 35 lines
Quoted 35 lines
Quoted 22 lines
Quoted 11 lines
Quoted 2 lines

Yet, I agree that udev tries to set devices too fast.

It tries to set devices exacty when you tell it to do so. It's not like it goes trolling for random devices is sysfs.

Quoted 2 lines

It would be better if
it would wait for a few milisseconds, to reduce the risk of race conditions.

Gah, I really prefer using properly engineered solutions instead of adding crutches.

I agree.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

And this could be easily added to the udev's keymap utility that is fired up when we discover evdevX devices.

Yes, it can, if you add the IR protocol selection on that tool. A remote controller keycode table has both the protocol and the keycodes. This basically means to merge 99% of the logic inside ir-keytable into the evdev generic tool.

Quoted 5 lines
Quoted 2 lines

Or just have an utility producing keymap name and feed it as input to the generic tools. The way most of utilities work...

I don't like the idea of running a some logic at udev that would generate such keymap in runtime just before calling the generic tool. The other

Why? You'd just call something like:

keymap $name rc-keymap-name -d $name

where 'keymap' is udev's utility and 'rc-keymap-name' is new utility that incorporates map selection logic currently found in rc-keytable.

Quoted 8 lines
Quoted 3 lines

It looks like format of the keymaps is compatible between 'keymap' and 'ir-keytable' and metadata that is present in your keymaps will not confuse 'keymap' utility.

The format is, currently compatible. However, we'll likely need to change it (or to allow the tool to handle also a different format), due to some reasons:

	1) Protocol and the device name where it is found by default is
	   currently a comment;

So? Keep it there, it does not hurt anything.

Quoted 3 lines

2) We'll need to add a field there specifying the number of the bits to be used by the keymap table, in order to use the proper length with _V2 ioctls;

You can't calculate this automatically given the length of the "scancode"? I mean if you have keymap file with

0x12345678936 KEY_COFFEE

that means that scancode is at least 36 bit.

Quoted 3 lines

3) There are hundreds of keymaps already created for lircd. It would be nice to support lircd format, in order to make life easier for those that use lirc.

or write a script to convert and be done with it?

Quoted 5 lines

If you want to add these to the generic tool, that's fine for me, but, IMO, this doesn't sound a good idea. There are already specialized tools for other kinds of input devices (mouse: gpm; joystick: jstest; etc). It seems a bad idea to merge them into the generic tools.

gpm is different and more akin to X itself and is not limited to mice; jstest uses differnt interface (jsX, not eventX) so you are right, we should not mix them into utilities working with event interface.

keymap/ir-keytable both work with event interface.

Quoted 8 lines

I think it is better to have a tool that just handle one kind of device, but does it well, than trying to extend a generic tool to cover all possible devices, and adding lots of caveats there for it to handle all the specifics.

Quoted 3 lines
Quoted 2 lines

alternative (e. g.) to maintain the RC-protocol dependent keytables separate from the RC protocol used by each table will be a maintenance nightmare.

Quoted 7 lines
Quoted 3 lines

I do not propose splitting keytables, I propose splittign utilities. ir-keytable is a kitchen sink now. It implements 'keymap', 'evtest' and bucnch of other stuff and would be much cleaner if split apart.

It may be broken into a few utilities, by creating a library with the common code. I'll think about that when I have some spare time for it.

Thanks.

Signature · 1 line
Dmitry
author
#77 lore raw

Dmitry / Mauro,

I'm encouraged by all of the good dialog happening here, and regret that I am unable to poke any further at the issue with ir-keytable for now.

The system in question is now getting rebuilt with new/modern userspace, and I expect the original issue to "vanish" as a result. If I do see ir-keytable acting up again afterward,
I'll let you know.

But it will be whatever version Ubuntu 10.10 installs, not the newer one I used earlier in this thread.

Cheers!
-Mark

author
#78 lore raw
In reply to Dmitry Torokhov

On 11-01-27 01:38 AM, Dmitry Torokhov wrote:
..

Quoted 2 lines

BTW, I wonder what package ir-keytable is coming from? Ubuntu seems to have v4l-utils at 0.8.1-2 and you say yours is 0.8.2...

..

I downloaded/built/installed it from the link you gave earlier in this thread.

Cheers

#79 lore raw
In reply to Mark Lord
Quoted 33 lines · Mark Lord
Quoted 32 lines · Dmitry Torokhov
Quoted 30 lines · Mark Lord
Quoted 22 lines · Mark Lord
Quoted 1 line · Mark Lord

On 11-01-25 09:00 PM, Dmitry Torokhov wrote:

..

Quoted 7 lines
Quoted 1 line

I wonder if the patch below is all that is needed...

Nope. Does not work here:

$ lsinput
protocol version mismatch (expected 65536, got 65537)

Heh.. I just noticed something *new* in the bootlogs on my system:

kernel: Registered IR keymap rc-rc5-tv
udevd-event[6438]: run_program: '/usr/bin/ir-keytable' abnormal exit
kernel: input: i2c IR (Hauppauge) as /devices/virtual/rc/rc0/input7
kernel: ir-keytable[6439]: segfault at 8 ip 00000000004012d2 sp 00007fff6d43ca60 error 4 in ir-keytable[400000+7000]
kernel: rc0: i2c IR (Hauppauge) as /devices/virtual/rc/rc0
kernel: ir-kbd-i2c: i2c IR (Hauppauge) detected at i2c-0/0-0018/ir0 [ivtv i2c driver #0]

Quoted 2 lines

That's udev invoking ir-keyboard when the ir-kbd-i2c kernel module is loaded, and that is also ir-keyboard (userspace) segfaulting when run.

Note: I tried to capture an strace of ir-keyboard segfaulting during boot (as above), but doing so kills the system (hangs on boot).

The command from udev was: /usr/bin/ir-keytable -a /etc/rc_maps.cfg -s rc0

Quoted 8 lines
Quoted 1 line

Does it die when you try to invoke the command by hand? Can you see where?

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

Hmm, what about compiling with debug and getting a core then?

Signature · 1 line
Dmitry
author
#80 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 5 lines · Mark Lord

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

Hmm, what about compiling with debug and getting a core then?

Sure. debug is easy, -g, but you'll have to tell me how to get it do produce a core dump.

Cheers

#81 lore raw
Quoted 8 lines · Mark Lord
Quoted 7 lines · Dmitry Torokhov
Quoted 5 lines · Mark Lord

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

Quoted 5 lines
Quoted 1 line

Hmm, what about compiling with debug and getting a core then?

Sure. debug is easy, -g, but you'll have to tell me how to get it do produce a core dump.

See if adjusting /etc/security/limits.conf will enable it to dump core. Otherwise you'll have to stick 'ulimit -c unlimited' somewhere...

Signature · 1 line
Dmitry
#82 lore raw
Quoted 9 lines · Dmitry Torokhov
Quoted 8 lines · Mark Lord
Quoted 7 lines · Dmitry Torokhov
Quoted 5 lines · Mark Lord

No, it does not seem to segfault when I unload/reload ir-kbd-i2c and then invoke it by hand with the same parameters. Quite possibly the environment is different when udev invokes it, and my strace attempt with udev killed the system, so no info there.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Hmm, what about compiling with debug and getting a core then?

Sure. debug is easy, -g, but you'll have to tell me how to get it do produce a core dump.

See if adjusting /etc/security/limits.conf will enable it to dump core. Otherwise you'll have to stick 'ulimit -c unlimited' somewhere...

Mark,

Any luck with getting the core? I'd really like to resolve this issue.

Thanks.

Signature · 1 line
Dmitry
author
#83 lore raw
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

On 11-01-27 11:39 AM, Dmitry Torokhov wrote:

..

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Hmm, what about compiling with debug and getting a core then?

Sure. debug is easy, -g, but you'll have to tell me how to get it do produce a core dump.

See if adjusting /etc/security/limits.conf will enable it to dump core. Otherwise you'll have to stick 'ulimit -c unlimited' somewhere...

..

Quoted 1 line

Any luck with getting the core? I'd really like to resolve this issue.

..

I'm upgrading the box to new userspace now.
But I still have the old installation drive,
so perhaps I'll go there now and try this.

My plan is to replace /usr/bin/ir-keytable with a script that issues the 'ulimit -c unlimited' command and then invokes the original /usr/bin/ir-keytable binary.

Should take half an hour or so before I get back here again.

-ml

author
#84 lore raw
Quoted 21 lines · Mark Lord
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

On 11-01-27 11:39 AM, Dmitry Torokhov wrote:

..

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Hmm, what about compiling with debug and getting a core then?

Sure. debug is easy, -g, but you'll have to tell me how to get it do produce a core dump.

See if adjusting /etc/security/limits.conf will enable it to dump core. Otherwise you'll have to stick 'ulimit -c unlimited' somewhere...

..

Quoted 1 line

Any luck with getting the core? I'd really like to resolve this issue.

..

I'm upgrading the box to new userspace now.
But I still have the old installation drive,
so perhaps I'll go there now and try this.

Quoted 5 lines

My plan is to replace /usr/bin/ir-keytable with a script that issues the 'ulimit -c unlimited' command and then invokes the original /usr/bin/ir-keytable binary.

Should take half an hour or so before I get back here again.

No-go. According to the syslog, the segfault has not happened since I reconfigured the kernel and startup sequence two days ago to resolve an XFS mount issue.

Something in there changed the init timing just enough to make it go away, I believe.

Now I'm blowing it all away in favour of fresh userspace, with a whole new set of issues to resolve. :)

Off-Topic:
Ubuntu (Mythbuntu) really has a ton of timing issues with this upstart thing at startup and shutdown.. running from an SSD really exposes the flaws.

Cheers

#85 lore raw
Quoted 26 lines · Mark Lord
Quoted 25 lines · Mark Lord
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Dmitry Torokhov
Quoted 1 line · Mark Lord

On 11-01-27 11:39 AM, Dmitry Torokhov wrote:

..

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Hmm, what about compiling with debug and getting a core then?

Sure. debug is easy, -g, but you'll have to tell me how to get it do produce a core dump.

See if adjusting /etc/security/limits.conf will enable it to dump core. Otherwise you'll have to stick 'ulimit -c unlimited' somewhere...

..

Quoted 1 line

Any luck with getting the core? I'd really like to resolve this issue.

..

I'm upgrading the box to new userspace now.
But I still have the old installation drive,
so perhaps I'll go there now and try this.

My plan is to replace /usr/bin/ir-keytable with a script that issues the 'ulimit -c unlimited' command and then invokes the original /usr/bin/ir-keytable binary.

Quoted 8 lines
Quoted 1 line

Should take half an hour or so before I get back here again.

No-go. According to the syslog, the segfault has not happened since I reconfigured the kernel and startup sequence two days ago to resolve an XFS mount issue.

Something in there changed the init timing just enough to make it go away, I believe.

OK, this reinforces my suspicion that the cause of segfault is the race we were discussing with Mauro, not the keymap retrieval fix.

I shall be sending the patch to Linus/stable in the next pull then.

Thank you for your help.

Signature · 1 line
Dmitry
#86 lore raw
In reply to Mauro Carvalho Chehab
Quoted 3 lines · Mauro Carvalho Chehab

See, it will only look into the 16-bits scancode space. There are several remote controllers with 24 bits and 32 bits, so the tool is already broken anyway.

Mauro, stop blathering.

The problem is that the tool used to work with OLD DEVICES AND SETUPS that used to work. That broke. It needs to get fixed.

We do not change user-land ABI. Not now, not ever. And no, "the tool is broken" is NOT an excuse. Bringing it up as one is unacceptable. The fact that there are devices that didn't use to be supported at all that don't work with the old tool has absolutely ZERO relevance, because that's not a regression.

No regressions. No excuses. No "user-land is broken", however much you disagree with it.

Linus

#87 lore raw
In reply to Mark Lord
Quoted 15 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

On Mon, Jan 24, 2011 at 11:37:06PM -0500, Mark Lord wrote:

..

Quoted 12 lines
Quoted 5 lines

This results in (map->size==10) for 2.6.36+ (wrong), and a much larger map->size for 2.6.35 and earlier.

So perhaps EVIOCGKEYCODE has changed?

So the utility expects that all devices have flat scancode space and driver might have changed so it does not recognize scancode 10 as valid scancode anymore.

The options are:

Quoted 8 lines
Quoted 2 lines

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

You are inventing rules. You are requesting a scancode->keycode mapping. If scancode is unknown/invalid for the device ioctl returns -EINVAL.

Quoted 4 lines

That's how it worked in all kernels prior to 2.6.36,
and now it is broken. It now returns -EINVAL for any unmapped keycode, even though keycodes higher than that still have mappings.

For unmapped - yes, either KEY_RESERVED or KEY_UNKNOWN should be returned. For invalid scancodes -EINVAL shoudl be returned. Scancodes are not guaranteed to be continuous (and never have been for all devices although there are still plenty of devices with continuous scancodes, like atkbd).

Quoted 5 lines

This is a bug, a regression, and breaks userspace.
I haven't identified *where* in the kernel the breakage happened, though.. that code confuses me. :)

Signature · 1 line
Dmitry
author
#88 lore raw
Quoted 3 lines · Dmitry Torokhov
Quoted 2 lines · Mark Lord
Quoted 1 line · Dmitry Torokhov

On Mon, Jan 24, 2011 at 11:37:06PM -0500, Mark Lord wrote:

..

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

The options are:

1. Convert to EVIOCGKEYCODE2
2. Ignore errors from EVIOCGKEYCODE and go through all 65536 iterations.

or 3. Revert/fix the in-kernel regression.

Quoted 7 lines
Quoted 3 lines

The EVIOCGKEYCODE ioctl is supposed to return KEY_RESERVED for unmapped (but value) keycodes, and only return -EINVAL when the keycode itself is out of range.

You are inventing rules. You are requesting a scancode->keycode mapping. If scancode is unknown/invalid for the device ioctl returns -EINVAL.

-EINVAL signals bad/invalid parameters.
That's NOT what is happening here.

Quoted 2 lines

For unmapped - yes, either KEY_RESERVED or KEY_UNKNOWN should be returned. For invalid scancodes -EINVAL shoudl be returned.

Exactly my point. The scancode in question is 100% valid and mapable, yet the kernel is rejecting it as -EINVAL. Incorrect.

BUG. Regression. Breaks userspace. Must get fixed.

Cheers

#89 lore raw
In reply to Mark Lord
Quoted 4 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

I planned on taking another look at this before we release Ubuntu 11.04 at the end of April. That doesn't prevent someone else from helping out :), but I'll make sure the utility is working again if not.

At this point it sounds like we should switch over to Gerd's new repo of sources. Gerd, will you be making any kind of official release?

Thanks,

-- Chase

#90 lore raw
Quoted 10 lines · Chase Douglas
Quoted 4 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

I planned on taking another look at this before we release Ubuntu 11.04 at the end of April. That doesn't prevent someone else from helping out :), but I'll make sure the utility is working again if not.

Here you go:

Quoted 1 line

From dbe48c8044987da6e64036fa3f36d7b2826994d5 Mon Sep 17 00:00:00 2001

From: Dmitry Torokhov <[email protected]>
Date: Mon, 24 Jan 2011 22:06:10 -0800
Subject: [PATCH 1/2] Do not require exact version of EVDEV protocol, we can work with
other versions too.

---
 input.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
input.c +5 -3
index 73d5df1..08f4046 100644
@@ -101,9 +101,11 @@ int device_open(int nr, int verbose)
 		close(fd);
 		return -1;
 	}
-	if (EV_VERSION != version) {
-		fprintf(stderr, "protocol version mismatch (expected %d, got %d)\n",
-			EV_VERSION, version);
+
+#define EVDEV_MIN_VERSION 0x10000
+	if (version < EVDEV_MIN_VERSION) {
+		fprintf(stderr, "protocol version mismatch (need at least %d, got %d)\n",
+			EVDEV_MIN_VERSION, version);
 		close(fd);
 		return -1;
 	}
Signature · 1 line
Dmitry
#91 lore raw
Quoted 14 lines · Dmitry Torokhov
Quoted 10 lines · Chase Douglas
Quoted 4 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

I planned on taking another look at this before we release Ubuntu 11.04 at the end of April. That doesn't prevent someone else from helping out :), but I'll make sure the utility is working again if not.

Here you go:

Quoted 7 lines

From dbe48c8044987da6e64036fa3f36d7b2826994d5 Mon Sep 17 00:00:00 2001
From: Dmitry Torokhov <[email protected]>
Date: Mon, 24 Jan 2011 22:06:10 -0800
Subject: [PATCH 1/2] Do not require exact version of EVDEV protocol, we can work with
other versions too.

Yeah that's the easy part :). I need to find time to go through the packaging and bug handling churn...

Thanks,

-- Chase

author
#92 lore raw
Quoted 8 lines · Chase Douglas
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines · Chase Douglas
Quoted 4 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

I planned on taking another look at this before we release Ubuntu 11.04 at the end of April. That doesn't prevent someone else from helping out :), but I'll make sure the utility is working again if not.

Here you go:

That patch was not enough for me to get input-kbd working here on Ubuntu-10.10. It would still only let me map 10 keys of my 56(?) button remote.

I also had to hack it to ignore the read-in map->size value when writing-out the new keymap.

Cheers

#93 lore raw
Quoted 14 lines · Mark Lord
Quoted 13 lines · Chase Douglas
Quoted 12 lines · Dmitry Torokhov
Quoted 10 lines · Chase Douglas
Quoted 4 lines · Mark Lord

As of the 2.6.36 kernel, the userspace commands lsinput and input-kbd no longer work. And if I grab newer/patched versions of those from the latest Ubuntu 10.10, then those newer/patched versions do not work with kernels *before* 2.6.36.

I planned on taking another look at this before we release Ubuntu 11.04 at the end of April. That doesn't prevent someone else from helping out :), but I'll make sure the utility is working again if not.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Here you go:

That patch was not enough for me to get input-kbd working here on Ubuntu-10.10. It would still only let me map 10 keys of my 56(?) button remote.

I also had to hack it to ignore the read-in map->size value when writing-out the new keymap.

I assumed that the fix to make RCs compatible with the pre-v2 getkeycode will trickle into Ubuntu through staging (I will be sending a patch to the stable team today now that it is in mainline). But if Chase wants to also add V2 keycode hdling then here's another patch.

Thanks.

Signature · 1 line
Dmitry
Quoted 1 line

From cf5954a4db2d0e411bd6f717fb50bcdf37e80c9b Mon Sep 17 00:00:00 2001

From: Dmitry Torokhov <[email protected]>
Date: Mon, 24 Jan 2011 22:49:59 -0800
Subject: [PATCH 2/2] input-kbd - switch to using EVIOCGKEYCODE2 when available

---
 input-kbd.c |  118 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 80 insertions(+), 38 deletions(-)
input-kbd.c +80 -38
index e94529d..5d93d54 100644
@@ -9,9 +9,27 @@
 
 #include "input.h"
 
+struct input_keymap_entry_v1 {
+	uint32_t scancode;
+	uint32_t keycode;
+};
+
+struct input_keymap_entry_v2 {
+#define KEYMAP_BY_INDEX	(1 << 0)
+	uint8_t  flags;
+	uint8_t  len;
+	uint16_t index;
+	uint32_t keycode;
+	uint8_t  scancode[32];
+};
+
+#ifndef EVIOCGKEYCODE2
+#define EVIOCGKEYCODE2 _IOR('E', 0x04, struct input_keymap_entry_v2)
+#endif
+
 struct kbd_entry {
-	int scancode;
-	int keycode;
+	unsigned int scancode;
+	unsigned int keycode;
 };
 
 struct kbd_map {
@@ -23,7 +41,7 @@ struct kbd_map {
 
 /* ------------------------------------------------------------------ */
 
-static struct kbd_map* kbd_map_read(int fd)
+static struct kbd_map* kbd_map_read(int fd, unsigned int version)
 {
 	struct kbd_entry entry;
 	struct kbd_map *map;
@@ -32,16 +50,37 @@ static struct kbd_map* kbd_map_read(int fd)
 	map = malloc(sizeof(*map));
 	memset(map,0,sizeof(*map));
 	for (map->size = 0; map->size < 65536; map->size++) {
-		entry.scancode = map->size;
-		entry.keycode  = KEY_RESERVED;
-		rc = ioctl(fd, EVIOCGKEYCODE, &entry);
-		if (rc < 0) {
-			break;
+		if (version < 0x10001) {
+			struct input_keymap_entry_v1 ke = {
+				.scancode = map->size,
+				.keycode = KEY_RESERVED,
+			};
+
+			rc = ioctl(fd, EVIOCGKEYCODE, &ke);
+			if (rc < 0)
+				break;
+		} else {
+			struct input_keymap_entry_v2 ke = {
+				.index = map->size,
+				.flags = KEYMAP_BY_INDEX,
+				.len = sizeof(uint32_t),
+				.keycode = KEY_RESERVED,
+			};
+
+			rc = ioctl(fd, EVIOCGKEYCODE2, &ke);
+			if (rc < 0)
+				break;
+
+			memcpy(&entry.scancode, ke.scancode,
+				sizeof(entry.scancode));
+			entry.keycode = ke.keycode;
 		}
+
 		if (map->size >= map->alloc) {
 			map->alloc += 64;
 			map->map = realloc(map->map, map->alloc * sizeof(entry));
 		}
+
 		map->map[map->size] = entry;
 
 		if (KEY_RESERVED != entry.keycode)
@@ -155,40 +194,27 @@ static void kbd_print_bits(int fd)
 	}
 }
 
-static void show_kbd(int nr)
+static void show_kbd(int fd, unsigned int protocol_version)
 {
 	struct kbd_map *map;
-	int fd;
 
-	fd = device_open(nr,1);
-	if (-1 == fd)
-		return;
 	device_info(fd);
 
-	map = kbd_map_read(fd);
-	if (NULL != map) {
-		kbd_map_print(stdout,map,0);
-	} else {
+	map = kbd_map_read(fd, protocol_version);
+	if (map)
+		kbd_map_print(stdout, map, 0);
+	else
 		kbd_print_bits(fd);
-	}
-
-	close(fd);
 }
 
-static int set_kbd(int nr, char *mapfile)
+static int set_kbd(int fd, unsigned int protocol_version, char *mapfile)
 {
 	struct kbd_map *map;
 	FILE *fp;
-	int fd;
-
-	fd = device_open(nr,1);
-	if (-1 == fd)
-		return -1;
 
-	map = kbd_map_read(fd);
+	map = kbd_map_read(fd, protocol_version);
 	if (NULL == map) {
 		printf("device has no map\n");
-		close(fd);
 		return -1;
 	}
 
@@ -198,18 +224,15 @@ static int set_kbd(int nr, char *mapfile)
 		fp = fopen(mapfile,"r");
 		if (NULL == fp) {
 			printf("open %s: %s\n",mapfile,strerror(errno));
-			close(fd);
 			return -1;
 		}
 	}
-	
+
 	if (0 != kbd_map_parse(fp,map) ||
 	    0 != kbd_map_write(fd,map)) {
-		close(fd);
 		return -1;
 	}
 
-	close(fd);
 	return 0;
 }
 
@@ -223,8 +246,10 @@ static int usage(char *prog, int error)
 
 int main(int argc, char *argv[])
 {
-	int c,devnr;
+	int c, devnr, fd;
 	char *mapfile = NULL;
+	unsigned int protocol_version;
+	int rc = EXIT_FAILURE;
 
 	for (;;) {
 		if (-1 == (c = getopt(argc, argv, "hf:")))
@@ -244,12 +269,29 @@ int main(int argc, char *argv[])
 		usage(argv[0],1);
 
 	devnr = atoi(argv[optind]);
-	if (mapfile) {
-		set_kbd(devnr,mapfile);
-	} else {
-		show_kbd(devnr);
+
+	fd = device_open(devnr, 1);
+	if (fd < 0)
+		goto out;
+
+	if (ioctl(fd, EVIOCGVERSION, &protocol_version) < 0) {
+		fprintf(stderr,
+			"Unable to query evdev protocol version: %s\n",
+			strerror(errno));
+		goto out_close;
 	}
-	return 0;
+
+	if (mapfile)
+		set_kbd(fd, protocol_version, mapfile);
+	else
+		show_kbd(fd, protocol_version);
+
+	rc = EXIT_SUCCESS;
+
+out_close:
+	close(fd);
+out:
+	return rc;
 }
 
 /* ---------------------------------------------------------------------
Signature · 1 line
1.7.3.5