-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oops / NULL pointer dereference when using libcomposite/HID OTG device #3870
Comments
+1 |
Could it be related with #3151? |
Have you tried applying the patch in #3151 to see if it solves the problem? |
I'm just about to do it. The fact is that I found the patch and the problem after I created this Issue. |
@pelwell I just tested it.
But this does NOT fix the problem described in this issue. The kernel still does oops :( It seems to be an independent issue. |
@pelwell I spent a few hours and found a synthetic pattern that completely reproduces the problem on the Raspberry Pi 4. The problem persists regardless of whether the patch #3151 is present. I tried default kernel 5.4.51 and patched 5.4.68 from git. To reproduce the problem, you need to configure the system as I described in the first post and have the attached scripts otg.sh and spam.py. Since the test requires reconnecting the USB OTG cable, I used this circuit to power the RPi. No underpower detected btw. I think the powering via GPIO pins will work fine either. Also I used my linux laptop as USB host. So, the steps:
I found two patterns. Sometimes the first one is triggered immediately, if it didn't work, you need to continue the first one with the second one, and repeat this until the crash occurs. This is usually 1-2 times. The first pattern:
If not, continue with this:
Each time, it's the same NULL dereference failure inside This problem exists on Zero with the same stacktrace, although locally I could not reproduce it on this Board with this pattern. Maybe it's just a single processor core or something. However, I received several stacktraces from my users who used Zero. The content is exactly the same as attached to issue: NULL and I'm sorry if I'm too intrusive. How can I help to resolve this bug? It's just really urgent for me and my users who use Raspberry to manage their servers. |
From your log, the driver is in
because Adding a simple |
Note that I've been trying on the Zero - I'll have to locate a different power supply to try the 4B. |
Okay, here what I did (the patch that fixes the states is also applied): --- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -364,6 +364,14 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
count = min_t(unsigned, count, hidg->report_length);
spin_unlock_irqrestore(&hidg->write_spinlock, flags);
+
+ if (!req) {
+ ERROR(hidg->func.config->cdev,
+ "+++++++++++++++++++++++++ copy_from_user error: req->buf is NULL\n");
+ status = -EINVAL;
+ goto release_write_pending;
+ }
+
status = copy_from_user(req->buf, buffer, count);
if (status != 0) { I am confused by the fact that such a check is ALREADY in the kernel, but it seems that it is implemented incorrectly: here. That is, I tried testing this patch and it seems it helped. Oops disappeared, but a couple of times I was able to catch another error:
UPD: req->buf is NULL should be read as req is NULL, just a typo in my patch. |
With a suitably-powered 4B I was able to reproduce the bug just before the end of the day, so expect progress tomorrow. |
Oh, that's great news! Thank you. I hope there's something I can do to help. By the way, line 398 leads to spam in dmesg:
In fact, the kernel reports every EAGAIN from the user software. I think it must be ignored for the -11 code. The same applies to my patch, logging is not necessary here at all, I think. Or at least it should be at the debug level. |
Another similar catch:
UPD: |
Can you try with these patches? diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index f3816a5c861e..7c0341a139e7 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -344,6 +344,11 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
spin_lock_irqsave(&hidg->write_spinlock, flags);
+ if (!hidg->req) {
+ spin_unlock_irqrestore(&hidg->write_spinlock, flags);
+ return -ESHUTDOWN;
+ }
+
#define WRITE_COND (!hidg->write_pending)
try_again:
/* write queue */
@@ -364,7 +369,13 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
count = min_t(unsigned, count, hidg->report_length);
spin_unlock_irqrestore(&hidg->write_spinlock, flags);
- status = copy_from_user(req->buf, buffer, count);
+ if (req)
+ status = copy_from_user(req->buf, buffer, count);
+ else {
+ pr_err("hidg->req is NULL\n");
+ status = -ESHUTDOWN;
+ goto release_write_pending;
+ }
if (status != 0) {
ERROR(hidg->func.config->cdev,
@@ -393,10 +404,14 @@ static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
spin_unlock_irqrestore(&hidg->write_spinlock, flags);
+ if (!hidg->in_ep->enabled) {
+ pr_err("enabled %d, req %px, hidg->req %px\n",
+ hidg->in_ep->enabled, req, hidg->req);
+ status = -ESHUTDOWN;
+ goto release_write_pending;
+ }
status = usb_ep_queue(hidg->in_ep, req, GFP_ATOMIC);
if (status < 0) {
- ERROR(hidg->func.config->cdev,
- "usb_ep_queue error on int endpoint %zd\n", status);
goto release_write_pending;
} else {
status = count; I usually see messages like these:
|
@pelwell It looks like it will work (but I had to fix the indetion in the patch :). Now I see this:
And sometimes If I disconnect the cable while the script is running, I get an endpoint error. But I didn't see any stacktraces:
|
Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. Try to fix or minimise both. See: #3870 Signed-off-by: Phil Elwell <[email protected]>
Thanks - I've tidied up that patch and pushed it, along with #3151. |
I think it might be - the timing relationship between the write call and the disable call is unclear and possibly unsynchronized, in which case being outside the spin lock means anything is possible. |
But if this is the case, there is another potential NULL dereference here: linux/drivers/usb/gadget/u_f.h Line 78 in 65caf60
static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req)
{
WARN_ON(req->buf == NULL);
kfree(req->buf);
req->buf = NULL;
usb_ep_free_request(ep, req);
} If I'm right, then call |
It's no longer crashing, and I don't want to spend any longer on what appears to be a generic problem in the HID gadget - there's nothing Pi-specific about this issue. |
Okay, anyway thank you. |
I read this code carefully again and it looks like I'm really wrong. I'm sorry to bother you with this. I really appreciate you fixing this bug, even though it's not directly related to Pi. |
kernel: overlays: Update display GPIO declarations kernel: Update hy28b-overlay.dts See: raspberrypi/linux#3880 kernel: net: bcmgenet: Reset RBUF on first open See: raspberrypi/linux#3850 kernel: ASoC: cs42xx8: Only define cs42xx8_of_match once See: raspberrypi/linux#3873 kernel: bcm2835-codec fixes See: raspberrypi/linux#3877 kernel: usb/dwc2: Set correct state on gadget disconnect kernel: USB: gadget: f_hid: avoid crashes and log spam See: raspberrypi/linux#3870 firmware: arm_loader: enable simple_fb iff there is a display See: raspberrypi/linux#3878 firmware: arm_loader: Mark V3D early boost as for the ARM See: #1469
kernel: overlays: Update display GPIO declarations kernel: Update hy28b-overlay.dts See: raspberrypi/linux#3880 kernel: net: bcmgenet: Reset RBUF on first open See: raspberrypi/linux#3850 kernel: ASoC: cs42xx8: Only define cs42xx8_of_match once See: raspberrypi/linux#3873 kernel: bcm2835-codec fixes See: raspberrypi/linux#3877 kernel: usb/dwc2: Set correct state on gadget disconnect kernel: USB: gadget: f_hid: avoid crashes and log spam See: raspberrypi/linux#3870 firmware: arm_loader: enable simple_fb iff there is a display See: raspberrypi/linux#3878 firmware: arm_loader: Mark V3D early boost as for the ARM See: raspberrypi/firmware#1469
This fix is in latest rpi-update kernel. |
Thanks. Just tested on Raspbian and Arch. No crash anymore, but the spam with |
For all boards: - raspberrypi/linux#3870 - raspberrypi/linux#3151 For zero: - raspberrypi/linux#3602
Tidying up the previous patch to this file dropped the deletion of a particularly noisy error message. Restore its removal. See: #3870 Signed-off-by: Phil Elwell <[email protected]>
You're right - in dropping some of the unwanted changes for this commit I also dropped this wanted one. It's there now as 6e776e6. |
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
BugLink: https://bugs.launchpad.net/bugs/1942123 commit 2867652 upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
BugLink: https://bugs.launchpad.net/bugs/1941798 commit 2867652 upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Kelsey Skunberg <[email protected]>
Source: Kernel.org MR: 113035 Type: Integration Disposition: Backport from git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable linux5.4.y ChangeID: 02f336cee5898142f31ce4f8649098dd4e863a9f Description: commit 2867652 upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Armin Kuster <[email protected]>
commit 2867652 upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 9d25976d99a0dae8d32ac7685a34def12671c9d2)
stable inclusion from stable-5.10.58 commit 825ac3f0bc3516a3a93f48c573f7cb8f4f0d86fe bugzilla: 176984 https://gitee.com/openeuler/kernel/issues/I4E2P4 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=825ac3f0bc3516a3a93f48c573f7cb8f4f0d86fe -------------------------------- commit 2867652 upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Chen Jun <[email protected]> Acked-by: Weilong Chen <[email protected]> Signed-off-by: Chen Jun <[email protected]> Signed-off-by: Zheng Zengkai <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652 upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit 2867652e4766360adf14dfda3832455e04964f2a upstream. Disconnecting and reconnecting the USB cable can lead to crashes and a variety of kernel log spam. The problem was found and reproduced on the Raspberry Pi [1] and the original fix was created in Raspberry's own fork [2]. Link: raspberrypi/linux#3870 [1] Link: raspberrypi/linux@a6e47d5 [2] Signed-off-by: Maxim Devaev <[email protected]> Signed-off-by: Phil Elwell <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
Describe the bug
When emulating an OTG HID Keyboard on a Raspberry Pi 4 or ZeroW, there is a chance of getting kernel oops when the USB is hot-disconnected/plugged in. This requires that the device /dev/hidg0 constantly performs a write operation while switching the connector. This happens when the /dev/hidg0 is constantly being written (spammed).
Apparently, the problem lies in f_hidg_write() which uses
hidg->write_spinlock
. When the device is disconnected (presumably), this variable becomes NULL, which causes oops. There's probably a race going on somewhere.To reproduce
/etc/modules
:/boot/config.txt
:configfs-gadget gadget: usb_ep_queue error on int endpoint -11
appears in dmesg of the Pi. the probability of oops will be high. Sometimes it can be 1:5, sometimes 1:20.Expected behaviour
No oops. Linux must correctly initialize the device each time after reconnecting, so that the user space can continue working with it.
Actual behaviour
Oops. Sometimes Linux is not able to correctly handle the fact of reconnection/disconnection.
System
/etc/rpi-issue
:vcgencmd version
:Linux raspberrypi 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l GNU/Linux
Logs
Full dmesg with crashes: biglog.txt
When testing on Arch Linux ARM I got a slightly more detailed error location (
f_hidg_write
,_raw_spin_unlock_irqrestore
). This applies to mouse emulation, but it was exactly the same for the keyboard:Additional context
The problem was detected when using an OTG keyboard to control a computer that was rebooted. To get into the BIOS, the user sent an event to /dev/hidg0 that was responsible for the F12 key. During boot, the USB is reinitialized several times so that the Pi is perceived as enabling and disabling the OTG host. The same thing happens if you just pull out and insert the USB cable.
The text was updated successfully, but these errors were encountered: