HID: sony: fix sleeping in atomic context in RB3 Pro raw event handler
Subsystems (2)
PATCH 1/1 HID: sony: fix sleeping in atomic context in RB3 Pro raw event handler
Rock Band 3 Pro instruments only send navigation reports until they receive a magic SET_REPORT feature request. When such a report is seen, rb3_pro_instrument_raw_event() sends that request directly through rb3_pro_instrument_enable_full_report(), which does a GFP_KERNEL allocation and a synchronous hid_hw_raw_request().
The raw event handler is called from the URB completion handler in softirq context, and on USB hid_hw_raw_request() ends up in usb_control_msg(), which sleeps. Plugging in an RB3 Pro instrument therefore triggers:
BUG: scheduling while atomic ... softirq: huh, entered softirq 0 HI ... preempt_count 101, exited with 0
This was reported on a Mustang guitar (12ba:2430).
Move the request to process context by registering rb3_pro_instrument_enable_full_report() as the send_output_report callback of the existing state worker. The raw event handler now only schedules the work, keeping the 8 second rate limit. The state worker is already cancelled by sony_cleanup() on remove and on probe failure, and sony_schedule_work() is a no-op once cancellation has started, so no new teardown is needed.
---
Notes:
Reproduced and tested with a Santroller device emulating a 12ba:2430
guitar: without the fix, 'BUG: scheduling while atomic' is logged every 8 seconds; with the fix no more warnings are logged.
The fix and changelog were written with the help of an AI coding assistant (Claude Opus 5.5).
drivers/hid/hid-sony.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/hid/hid-sony.c +7 -6
@@ -630,7 +630,7 @@ static int ghl_init_urb(struct sony_sc *sc, struct usb_device *usbdev,* Sending HID_REQ_SET_REPORT enables the full report. Without this * Rock Band 3 Pro instruments only report navigation events */ -static int rb3_pro_instrument_enable_full_report (struct sony_sc *sc) +static void rb3_pro_instrument_enable_full_report (struct sony_sc *sc) {struct hid_device *hdev = sc->hdev;static const u8 report[] = {0x00 ,0xE9 ,0x00 ,0x89 ,0x1B ,
@@ -647,14 +647,14 @@ static int rb3_pro_instrument_enable_full_report(struct sony_sc *sc) buf =kmemdup (report,sizeof (report),GFP_KERNEL );if (!buf) -return -ENOMEM ; +return ; ret =hid_hw_raw_request (hdev, buf[0 ], buf,sizeof (report),HID_FEATURE_REPORT ,HID_REQ_SET_REPORT ); +if (ret <0 ) +hid_dbg (hdev,"failed to enable full report: %d\n" , ret);kfree (buf); - -return ret; } static int djh_turntable_mapping(struct hid_device *hdev, struct hid_input *hi,
@@ -1098,10 +1098,10 @@ static int rb3_pro_instrument_raw_event(struct sony_sc *sc, u8 *rd, int size)if (size <25 || rd[24 ] !=0x02 )return 0 ; -/* Only attempt to enable full report every 8 seconds */ +/* Only attempt to enable full report every 8 seconds, from the worker */ if (time_after (jiffies, sc->rb3_pro_poke_jiffies)) { sc->rb3_pro_poke_jiffies = jiffies +secs_to_jiffies (8 ); -rb3_pro_instrument_enable_full_report (sc); +sony_schedule_work (sc); }return 0 ;
@@ -2217,6 +2217,7 @@ static int sony_input_configured(struct hid_device *hdev, hdev->quirks |=HID_QUIRK_SKIP_OUTPUT_REPORT_ID ;sony_init_raw_event_handler (sc, rb3_pro_instrument_raw_event); +sony_init_output_report (sc, rb3_pro_instrument_enable_full_report); }else if (sc->quirks &SIXAXIS_CONTROLLER_USB ) {/* * The Sony Sixaxis does not handle HID Output Reports on the
Signature · 1 line
2.56.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Medium] HID: sony: incorrect jiffies…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Medium] HID: sony: incorrect jiffies initialization in sony_probe()
[1]
--
commit b4e6f33044b15e23503ab50df025ce6ffced3a7d
Author: Sanjay Govind <[email protected]>
HID: sony: fix sleeping in atomic context in RB3 Pro raw event handler
This commit defers rb3_pro_instrument_enable_full_report() from the raw event handler to the sony state worker so that the GFP_KERNEL allocation and synchronous HID feature report request run in process context.
Quoted 4 lines
drivers/hid/hid-sony.c +0
-0
[ ... ]
drivers/hid/hid-sony.c static int rb3_pro_instrument_raw_event(struct sony_sc *sc, u8 *rd, int size) · line 1105
Quoted 11 lines
drivers/hid/hid-sony.c +2
-2@@ -1098,10 +1098,10 @@ static int rb3_pro_instrument_raw_event(struct sony_sc *sc, u8 *rd, int size)if (size <25 || rd[24 ] !=0x02 )return 0 ; -/* Only attempt to enable full report every 8 seconds */ +/* Only attempt to enable full report every 8 seconds, from the worker */ if (time_after (jiffies, sc->rb3_pro_poke_jiffies)) { sc->rb3_pro_poke_jiffies = jiffies +secs_to_jiffies (8 ); -rb3_pro_instrument_enable_full_report (sc); +sony_schedule_work (sc); }
[Severity: Medium]
This problem wasn't introduced by this patch, but can time_after(jiffies, sc->rb3_pro_poke_jiffies) [1] stay false for the first 5 minutes after boot?
sony_probe() leaves sc->rb3_pro_poke_jiffies at 0, while jiffies starts at INITIAL_JIFFIES (-300 * HZ). Until jiffies wraps past 0, time_after(jiffies,
0) evaluates to false and full reporting mode is never enabled on the instrument.
[1] https://sashiko.dev/#/bug/linux-bbf93673-dc17-4826-b162-980cf3f12da0
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Gentle ping on this one. Without it, connecting any Rock Band 3 Pro instrument handled by hid-sony (Mustang or Squier guitar, keyboard, or the MIDI Pro Adapter) can panic the machine: the full report request sleeps in the URB completion softirq, and when that happens on top of the idle task, the control transfer's completion later tries to wake the idle task:
RIP: 0010:0x0 enqueue_task+0x84/0x180 ttwu_do_activate+0x6e/0x180 try_to_wake_up+0x294/0x820 complete+0x49/0x80 __usb_hcd_giveback_urb+0xa0/0x120 usb_giveback_urb_bh+0xc0/0x140 ... Kernel panic - not syncing: Fatal exception in interrupt
I reproduced the panic on 7.2.11, and with this patch applied I can no longer reproduce it. A user on Fedora's 7.2.13 has also hit "BUG:
scheduling while atomic" followed by "bad: scheduling from the idle thread!" and lost all USB and Bluetooth until a hard reboot. As it's a fix tagged for stable, could it go in as a 7.4 fix?
As for the issue Sashiko raised, I submitted the fix for that as its own patch because it was unrelated to this change.
Quoted 97 lines · Sanjay Govind
Rock Band 3 Pro instruments only send navigation reports until they receive a magic
SET_REPORTfeature request. When such a report is seen,rb3_pro_instrument_raw_event()sends that request directly throughrb3_pro_instrument_enable_full_report(), which does aGFP_KERNELallocation and a synchronoushid_hw_raw_request().The raw event handler is called from the URB completion handler in softirq context, and on USB
hid_hw_raw_request()ends up inusb_control_msg(), which sleeps. Plugging in an RB3 Pro instrument therefore triggers:BUG: scheduling while atomic ... softirq: huh, entered softirq 0 HI ... preempt_count 101, exited with 0This was reported on a Mustang guitar (12ba:2430).
Move the request to process context by registering
rb3_pro_instrument_enable_full_report()as thesend_output_reportcallback of the existing state worker. The raw event handler now only schedules the work, keeping the 8 second rate limit. The state worker is already cancelled bysony_cleanup()on remove and on probe failure, andsony_schedule_work()is a no-op once cancellation has started, so no new teardown is needed.Fixes 7245b0017d12 ("HID: sony: add support for more instruments")Signed-off-by Sanjay Govind <[email protected]>---
Notes:
Reproduced and tested with a Santroller device emulating a 12ba:2430
guitar: without the fix, 'BUG: scheduling while atomic' is logged every 8 seconds; with the fix no more warnings are logged.The fix and changelog were written with the help of an AI coding assistant (Claude Opus 5.5).
drivers/hid/hid-sony.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/hid/hid-sony.c +7
-7@@ -630,7 +630,7 @@ static int ghl_init_urb(struct sony_sc *sc, struct usb_device *usbdev,* Sending HID_REQ_SET_REPORT enables the full report. Without this * Rock Band 3 Pro instruments only report navigation events */ -static int rb3_pro_instrument_enable_full_report (struct sony_sc *sc) +static void rb3_pro_instrument_enable_full_report (struct sony_sc *sc) {struct hid_device *hdev = sc->hdev;static const u8 report[] = {0x00 ,0xE9 ,0x00 ,0x89 ,0x1B ,@@ -647,14 +647,14 @@ static int rb3_pro_instrument_enable_full_report(struct sony_sc *sc) buf =kmemdup (report,sizeof (report),GFP_KERNEL );if (!buf) -return -ENOMEM ; +return ; ret =hid_hw_raw_request (hdev, buf[0 ], buf,sizeof (report),HID_FEATURE_REPORT ,HID_REQ_SET_REPORT ); +if (ret <0 ) +hid_dbg (hdev,"failed to enable full report: %d\n" , ret);kfree (buf); - -return ret; } static int djh_turntable_mapping(struct hid_device *hdev, struct hid_input *hi,@@ -1098,10 +1098,10 @@ static int rb3_pro_instrument_raw_event(struct sony_sc *sc, u8 *rd, int size)if (size <25 || rd[24 ] !=0x02 )return 0 ; -/* Only attempt to enable full report every 8 seconds */ +/* Only attempt to enable full report every 8 seconds, from the worker */ if (time_after (jiffies, sc->rb3_pro_poke_jiffies)) { sc->rb3_pro_poke_jiffies = jiffies +secs_to_jiffies (8 ); -rb3_pro_instrument_enable_full_report (sc); +sony_schedule_work (sc); }return 0 ;@@ -2217,6 +2217,7 @@ static int sony_input_configured(struct hid_device *hdev, hdev->quirks |=HID_QUIRK_SKIP_OUTPUT_REPORT_ID ;sony_init_raw_event_handler (sc, rb3_pro_instrument_raw_event); +sony_init_output_report (sc, rb3_pro_instrument_enable_full_report); }else if (sc->quirks &SIXAXIS_CONTROLLER_USB ) {/* * The Sony Sixaxis does not handle HID Output Reports on the -- 2.56.0
Quoted 25 lines · Sanjay Govind
Rock Band 3 Pro instruments only send navigation reports until they receive a magic
SET_REPORTfeature request. When such a report is seen,rb3_pro_instrument_raw_event()sends that request directly throughrb3_pro_instrument_enable_full_report(), which does aGFP_KERNELallocation and a synchronoushid_hw_raw_request().The raw event handler is called from the URB completion handler in softirq context, and on USB
hid_hw_raw_request()ends up inusb_control_msg(), which sleeps. Plugging in an RB3 Pro instrument therefore triggers:BUG: scheduling while atomic ... softirq: huh, entered softirq 0 HI ... preempt_count 101, exited with 0This was reported on a Mustang guitar (12ba:2430).
Move the request to process context by registering
rb3_pro_instrument_enable_full_report()as thesend_output_reportcallback of the existing state worker. The raw event handler now only schedules the work, keeping the 8 second rate limit. The state worker is already cancelled bysony_cleanup()on remove and on probe failure, andsony_schedule_work()is a no-op once cancellation has started, so no new teardown is needed.
Quoted 3 lines
Fixes 7245b0017d12 ("HID: sony: add support for more instruments")Signed-off-by Sanjay Govind <[email protected]>
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs