summaryrefslogtreecommitdiff
path: root/tools/perf/scripts/python/flamegraph.py
diff options
context:
space:
mode:
authorJinmo Yang <jinmo44.yang@gmail.com>2026-09-28 00:30:14 +0900
committerJiri Kosina <jkosina@suse.com>2026-11-20 14:59:24 +0100
commit7e1b58bd6d36aa76f920da72ae114574b21d5283 (patch)
treeb5146115fa7a9a21ec14d5a29566a5d85f70df7a /tools/perf/scripts/python/flamegraph.py
parentebe5e010199517103271033b435fb5b0f8213c68 (diff)
HID: wiimote: initialise rumble_worker once per device
wdata->rumble_worker is a single work_struct in struct wiimote_data, but two different modules called INIT_WORK() on it: wiimod_rumble_probe() devtype module, once per device wiimod_pro_probe() extension module, once per extension hotplug These have independent lifetimes. The devtype module is loaded once by wiimote_modules_load() and stays until wiimote_destroy(), while the extension module is loaded and unloaded any number of times by wiimote_ext_load() / wiimote_ext_unload(). wiimote_ext_load() calls the extension probe with no lock and no cancel_work_sync(), and for the common EXT_NONE -> EXT_PRO_CONTROLLER transition the preceding wiimote_ext_unload() is a no-op because wiimod_ext_table[] maps both EXT_NONE and EXT_UNKNOWN to wiimod_dummy, which has no .remove. So nothing stops the force-feedback path, which is still live in the base module, from having queued the work already: /* wiimod_rumble_play() */ wdata->state.cache_rumble = value; schedule_work(&wdata->rumble_worker); INIT_WORK() on a queued work item is memory corruption. __INIT_WORK() does (_work)->data = (atomic_long_t) WORK_DATA_INIT(); INIT_LIST_HEAD(&(_work)->entry); which clears the pool reference and the PENDING bit, and re-points ->entry at itself while the item is still linked into the worker pool list, leaving its neighbours pointing at a node that has left the list. Note that CONFIG_DEBUG_OBJECTS_WORK hides the impact rather than just reporting it: work_fixup_init() calls cancel_work_sync() for the caller, so a debug kernel prints a warning and then repairs the state. That is the kernel stating what the driver should have done. Production kernels have no such repair. Initialise the work once in wiimote_create(), which is where the object that contains it is created and which already initialises wdata->queue.worker, wdata->init_worker and wdata->timer, and drop both module-level INIT_WORK() calls. wiimote_create() runs as the first statement of wiimote_hid_probe(), before hid_parse() and hid_hw_start(), so it strictly precedes the existence of any input device and therefore of any path that could queue the work. This does not affect the deadlock fix in commit f50f9aabf32d ("HID: wiimote: fix FF deadlock"). That fix is the offload itself - caching the value and deferring to a worker instead of taking state.lock inside the FF callback - and this patch leaves wiimod_rumble_play(), wiimod_rumble_worker() and state.cache_rumble untouched. Only the placement of the initialisation changes. The two halves come from different actors, and both are available on a stock Android phone without root. The extension hotplug half needs only /dev/uhid, which is group 3011 and held by the shell. The shell cannot write to an evdev node - SELinux grants it read access only - so the force-feedback half comes from an ordinary app calling InputDevice.getVibrator().vibrate(), which reaches EVIOCSFF through system_server; VIBRATE is a normal permission and is granted automatically. A paired Bluetooth HID device can supply the hotplug half instead of /dev/uhid. The ordering matters: the device has to be created without an extension so that the devtype resolves to a GEN10/GEN20 that includes WIIMOD_RUMBLE, because WIIMOTE_DEV_PRO_CONTROLLER does not, and the extension has to be plugged afterwards. Measured before the change: Pixel 11, stock Android 17 user build, SELinux enforcing, no KASAN and no DEBUG_OBJECTS at runtime, kernel 6.12.81: reboots with ro.boot.bootreason=kernel_panic one to two seconds after the two paths start overlapping. Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 CPU: 5 Comm: kworker/5:4 Workqueue: wiimod_rumble_worker (events) pc : process_scheduled_works+0xd4/0x810 Kernel panic - not syncing: Oops: Fatal exception The empty workqueue name in that line is itself the corruption: print_worker_info() reads wq->name with copy_from_kernel_nofault() and it failed, while another CPU in the same dump shows the normal form, "Workqueue: events wiimote_init_worker" - the task that called wiimod_pro_probe(). x86_64 with CONFIG_KASAN_GENERIC and CONFIG_DEBUG_OBJECTS_WORK both enabled, 15 s in: KASAN says nothing, because INIT_WORK() writes to a valid field of a live object, and DEBUG_OBJECTS_WORK reports ODEBUG: init active (active state 0) object type: work_struct hint: wiimod_rumble_worker+0x0/0x70 WARNING: lib/debugobjects.c:629 at debug_print_object Workqueue: events wiimote_init_worker __debug_object_init+0x1ff/0x3b0 __init_work+0x51/0x60 wiimod_pro_probe+0x28/0xba0 wiimote_init_worker.cold+0xb6a/0xe88 After the change the same reproducer drives 36774 extension hotplugs and 612156 force-feedback plays in 60 s on that x86_64 kernel with no ODEBUG, WARNING or KASAN output, and the rumble reports still arrive, so the force-feedback path is unaffected. Fixes: f50f9aabf32d ("HID: wiimote: fix FF deadlock") Cc: stable@vger.kernel.org Signed-off-by: Jinmo Yang <jinmo44.yang@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com>
Diffstat (limited to 'tools/perf/scripts/python/flamegraph.py')
0 files changed, 0 insertions, 0 deletions