Skip to contentSkip to conversation

usb: kbd: destroy device after console is stopped

PATCH New Andy Shevchenko 4 participants 15 messages Jan 28, 2021 – Feb 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

 common/usb_kbd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
common/usb_kbd.c +6 -6
index b316807844b1..e09d9f7794c8 100644
@@ -617,12 +617,12 @@ int usb_kbd_deregister(int force)
 	if (dev) {
 		usb_kbd_dev = (struct usb_device *)dev->priv;
 		data = usb_kbd_dev->privptr;
-		if (stdio_deregister_dev(dev, force) != 0)
-			return 1;
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
 		if (iomux_doenv(stdin, env_get("stdin")) != 0)
 			return 1;
 #endif
+		if (stdio_deregister_dev(dev, force) != 0)
+			return 1;
 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
 		destroy_int_queue(usb_kbd_dev, data->intq);
 #endif
@@ -660,16 +660,16 @@ static int usb_kbd_remove(struct udevice *dev)
 		goto err;
 	}
 	data = udev->privptr;
-	if (stdio_deregister_dev(sdev, true)) {
-		ret = -EPERM;
-		goto err;
-	}
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
 	if (iomux_doenv(stdin, env_get("stdin"))) {
 		ret = -ENOLINK;
 		goto err;
 	}
 #endif
+	if (stdio_deregister_dev(sdev, true)) {
+		ret = -EPERM;
+		goto err;
+	}
 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
 	destroy_int_queue(udev, data->intq);
 #endif
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Regards,
Nicolas

Quoted 40 lines

?common/usb_kbd.c | 12 ++++++------
?1 file changed, 6 insertions(+), 6 deletions(-)

common/usb_kbd.c +0 -2
index b316807844b1..e09d9f7794c8 100644
@@ -617,12 +617,12 @@ int usb_kbd_deregister(int force)
 ?	if (dev) {
 ?		usb_kbd_dev = (struct usb_device *)dev->priv;
 ?		data = usb_kbd_dev->privptr;
-		if (stdio_deregister_dev(dev, force) != 0)
-			return 1;
 ?#if CONFIG_IS_ENABLED(CONSOLE_MUX)
 ?		if (iomux_doenv(stdin, env_get("stdin")) != 0)
 ?			return 1;

?#endif

common/usb_kbd.c +2 -0
+		if (stdio_deregister_dev(dev, force) != 0)
+			return 1;

?#ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
? destroy_int_queue(usb_kbd_dev, data->intq);
?#endif

common/usb_kbd.c +0 -4
@@ -660,16 +660,16 @@ static int usb_kbd_remove(struct udevice *dev)
 ?		goto err;
 ?	}
 ?	data = udev->privptr;
-	if (stdio_deregister_dev(sdev, true)) {
-		ret = -EPERM;
-		goto err;
-	}
 ?#if CONFIG_IS_ENABLED(CONSOLE_MUX)
 ?	if (iomux_doenv(stdin, env_get("stdin"))) {
 ?		ret = -ENOLINK;
 ?		goto err;
 ?	}

?#endif

common/usb_kbd.c +4 -0
+	if (stdio_deregister_dev(sdev, true)) {
+		ret = -EPERM;
+		goto err;
+	}
Quoted 3 lines

?#ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
? destroy_int_queue(udev, data->intq);
?#endif

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210128/829347a0/attachment.sig>

#2 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Thanks for trying.

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 24 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Quoted 7 lines

Thanks for trying.

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Seems test cases are broken in U-Boot.
I'm not sure how you were able to run them.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 27 lines · Andy Shevchenko
Quoted 26 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Thanks for trying.

Quoted 8 lines
Quoted 5 lines

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Seems test cases are broken in U-Boot.
I'm not sure how you were able to run them.

This is I guess what Heinrich was posting a patch for earlier today. The supported way to run the tests (so that they're the same for everyone) is to use "pip" and "pip install -r test/py/requirements.txt".

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210128/a72b26a6/attachment.sig>
#8 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

In reply to Andy Shevchenko
Quoted 27 lines · Andy Shevchenko
Quoted 26 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Thanks for trying.

Quoted 8 lines
Quoted 5 lines

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Seems test cases are broken in U-Boot.
I'm not sure how you were able to run them.

Tom, any insights? Seems your patch changed the way how test.py works and something wrong happened meanwhile.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

In reply to Tom Rini
Quoted 34 lines · Tom Rini
Quoted 33 lines · Andy Shevchenko
Quoted 31 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Thanks for trying.

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Quoted 6 lines
Quoted 2 lines

Seems test cases are broken in U-Boot.
I'm not sure how you were able to run them.

This is I guess what Heinrich was posting a patch for earlier today. The supported way to run the tests (so that they're the same for everyone) is to use "pip" and "pip install -r test/py/requirements.txt".

My Gosh! It is full of package == version, which is simply awful. Can it be more flexible?

I hate this Python hell.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 38 lines · Andy Shevchenko
Quoted 37 lines · Tom Rini
Quoted 35 lines · Andy Shevchenko
Quoted 24 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Quoted 7 lines

Thanks for trying.

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Seems test cases are broken in U-Boot.
I'm not sure how you were able to run them.

Quoted 8 lines
Quoted 3 lines

This is I guess what Heinrich was posting a patch for earlier today. The supported way to run the tests (so that they're the same for everyone) is to use "pip" and "pip install -r test/py/requirements.txt".

My Gosh! It is full of package == version, which is simply awful. Can it be more flexible?

I hate this Python hell.

It's intentional to follow the best practices of using python packages as best I can tell. CI doesn't mean so much if it's not repeatable and non-versioned packages mean that you can't be sure that running a test 6 months from now gives you what you get today on the same code base.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210128/68c65697/attachment.sig>
#7 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 5 lines · Tom Rini
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Tom Rini
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Andy Shevchenko

On Thu, Jan 28, 2021 at 06:19:56PM +0100, Nicolas Saenz Julienne wrote:

...

Quoted 16 lines
Quoted 16 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Unfortunately I have unrelated bug somewhere:
Traceback (most recent call last):
File "/home/andy/prj/u-boot/./test/py/test.py", line 20, in <module>

    sys.exit(load_entry_point('pytest', 'console_scripts', 'pytest')(args))

TypeError: console_main() takes 0 positional arguments but 1 was given

Quoted 6 lines
Quoted 2 lines

Seems test cases are broken in U-Boot.
I'm not sure how you were able to run them.

This is I guess what Heinrich was posting a patch for earlier today. The supported way to run the tests (so that they're the same for everyone) is to use "pip" and "pip install -r test/py/requirements.txt".

My Gosh! It is full of package == version, which is simply awful. Can it be more flexible?

Quoted 6 lines
Quoted 1 line

I hate this Python hell.

It's intentional to follow the best practices of using python packages as best I can tell. CI doesn't mean so much if it's not repeatable and non-versioned packages mean that you can't be sure that running a test 6 months from now gives you what you get today on the same code base.

I agree on CI point, I disagree on end user's point of view.
I have a distribution that has provided all required packages. Moreover, I have another (locally installed) packages that may require something else. The Py virtual environment maybe a way to solve this, but it's like an exploitation of the hi-tech laboratory to chop a firewood.

And as I told, it's not your fault, it's "best practices of using Py packages".

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

In reply to Nicolas Saenz Julienne
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 9 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Quoted 6 lines
Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Now I'm able to run test cases. I see some of them failing even without my patch, but few definitely related. Can you give a list of failed ones on your side? I can compare that we are on the same page here.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 20 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 15 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 7 lines
Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Now I'm able to run test cases. I see some of them failing even without my patch, but few definitely related. Can you give a list of failed ones on your side? I can compare that we are on the same page here.

Running this here on sandbox I get:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_bootcount] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_video_ansi] - OSError: [Errno 5] Input/output...

and those 4 are segfaults of sandbox.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210128/e08d487d/attachment.sig>
#11 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 3 lines · Tom Rini
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Nicolas Saenz Julienne

On Thu, 2021-01-28 at 18:55 +0200, Andy Shevchenko wrote:

...

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Now I'm able to run test cases. I see some of them failing even without my patch, but few definitely related. Can you give a list of failed ones on your side? I can compare that we are on the same page here.

Quoted 7 lines

Running this here on sandbox I get:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_bootcount] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_video_ansi] - OSError: [Errno 5] Input/output...

and those 4 are segfaults of sandbox.

Right, I have got the same. Thanks.

Actually it's a can of worms I have opened. I already see a mess with the console assignment between devices.
I will check later how possibly to fix this (to some extent), today is almost midnight here...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

In reply to Tom Rini
Quoted 4 lines · Tom Rini

On Thu, Jan 28, 2021 at 10:35:37PM +0200, Andy Shevchenko wrote:

Running this here on sandbox I get:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_bootcount] - OSError: [Errno 5] Input/output ...

Btw this is the wrong test case name printed. The real one which crashed is blk_usb (previous one to above mentioned). And it's failing only when you run either blk_usb or acpi_basic before (I haven't checked other permutations). Consider this as a bug report against tests.

Quoted 5 lines

FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_video_ansi] - OSError: [Errno 5] Input/output...

and those 4 are segfaults of sandbox.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

In reply to Tom Rini

Andy, Tony,
Sorry for my late reply, but I got a bad cold.

Quoted 29 lines · Tom Rini
Quoted 20 lines · Andy Shevchenko
Quoted 19 lines · Nicolas Saenz Julienne

Hi Andy,

Quoted 15 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 7 lines
Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Now I'm able to run test cases. I see some of them failing even without my patch, but few definitely related. Can you give a list of failed ones on your side? I can compare that we are on the same page here.

Quoted 5 lines

Running this here on sandbox I get:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_bootcount] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_video_ansi] - OSError: [Errno 5] Input/output...

This is what I'm seeing too.

Regards,
Nicolas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210203/eb8c59b3/attachment.sig>

#14 lore raw

PATCH 1/1 usb: kbd: destroy device after console is stopped

Quoted 2 lines · Nicolas Saenz Julienne

Andy, Tony,
Sorry for my late reply, but I got a bad cold.

I hope you are doing well.

Unfortunately I haven't heard from you lately, so I have decided to send out whatever I have as a patch series. You are Cc'ed on the last patch (it has prerequisites, so better to apply entire series for easy going).

That said, I have dropped the 'iomux' branch from my public tree.

Quoted 37 lines · Tom Rini
Quoted 29 lines · Andy Shevchenko
Quoted 20 lines · Nicolas Saenz Julienne
Quoted 19 lines

Hi Andy,

Quoted 15 lines · Andy Shevchenko

In case of IOMUX enabled it assumes that console devices in the list are available to get them stopped properly via ->stop() callback. However, the USB keyboard driver violates this assumption and tries to play tricks so the device get destroyed while being listed as an active console.

Swap the order of device deregistration and IOMUX update to avoid the use-after-free.

Fixes 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")

---
v2: Nicolas, can you test this one instead of yours?

Quoted 7 lines
Quoted 3 lines

Sadly this doesn't seem to work, and breaks a bunch of other tests in the process. You can try it yourself by running: './test/py/test.py --bd sandbox --build'

Now I'm able to run test cases. I see some of them failing even without my patch, but few definitely related. Can you give a list of failed ones on your side? I can compare that we are on the same page here.

Quoted 5 lines

Running this here on sandbox I get:
FAILED test/py/tests/test_ut.py::test_ut[ut_dm_bootcount] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] - OSError: [Errno 5] Input/output ... FAILED test/py/tests/test_ut.py::test_ut[ut_dm_video_ansi] - OSError: [Errno 5] Input/output...

This is what I'm seeing too.

Signature · 2 lines
With Best Regards,
Andy Shevchenko