Repository navigation
IPTS sleep improvements - #188
Open
jaydenmilne wants to merge 6 commits into
Open
jaydenmilne wants to merge 6 commits into
jaydenmilne wants to merge 6 commits into
Conversation
ipts_mei_send() calls mei_cldev_send() again for as long as it returns -EINTR. mei_cldev_send() queues the message and then waits interruptibly for the transfer to complete, returning -EINTR if a signal is pending. Since the signal stays pending until the task returns to userspace, every retry fails immediately, and the loop never terminates. The task spins in the kernel, cannot be killed, and blocks the freezer. Every retry also queues the message again. On EDS v1 devices, iptsd switches the device to multitouch mode on startup, which restarts the device from iptsd's process context. If iptsd is stopped during that restart (e.g. by a system-sleep hook at the intermediate wakeup of suspend-then-hibernate), it gets stuck, and the system fails to hibernate: Freezing user space processes failed after 20.006 seconds (1 tasks refusing to freeze, wq_busy=0): task:iptsd state:R running task ... __mei_cl_send_timeout+0x197/0x360 [mei] ipts_mei_send+0x46/0x90 [ipts] ipts_cmd_send+0x8c/0xf0 [ipts] ipts_control_get_device_info+0x49/0xec [ipts] ipts_control_start.cold+0x24/0x271 [ipts] ipts_control_restart+0x2f/0x40 [ipts] Return the error instead of retrying. Signed-off-by: Jayden Milne <linux-surface@jayd.ml> Patchset: ipts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ipts_thread_stop() waits for the completion that the thread signals right before returning, and only then calls kthread_stop(). By that time the thread may have fully exited, and since nothing holds a reference to its task_struct, kthread_stop() operates on freed memory: refcount_t: addition on 0; use-after-free. WARNING: lib/refcount.c:25 at refcount_warn_saturate+0x6a/0x90 Call Trace: kthread_stop+0x16c/0x180 ipts_thread_stop+0x32/0x60 [ipts] ipts_receiver_stop+0x22/0x40 [ipts] _ipts_control_stop.part.0+0x29/0x50 [ipts] ipts_control_restart+0x21/0x40 [ipts] Take a reference when starting the thread, and drop it with kthread_stop_put(). Signed-off-by: Jayden Milne <linux-surface@jayd.ml> Patchset: ipts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iled The receiver thread returns an error if the sensor does not shut down cleanly (e.g. "READY_FOR_DATA: cmd failed: 5"). The thread has exited at that point, but _ipts_control_stop() returns early and leaves the buffers allocated, and ipts_control_stop() skips freeing the HID device. MEI removes and probes the device again on every suspend and hibernation. Since the old HID device is never destroyed, it keeps its hidraw node, the new one gets a different node, and iptsd is left talking to the wrong device, breaking touch until the next reboot: READY_FOR_DATA: cmd failed: 5 Failed to wait for data: -53 Failed to stop receiver loop: -53 Failed to stop receiver: -53 Failed to stop IPTS: -53 hid-generic 0000:1B96:005E.0163: input,hidraw3: ... Log the error and finish tearing down the device. Signed-off-by: Jayden Milne <linux-surface@jayd.ml> Patchset: ipts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When sending a command is interrupted, or waiting for its response times out, the ME may still answer later. That response stays in the list of received messages until the device is removed, where it can be mistaken for the response to a later command with the same code. This is not just a leak. After a restart, a stale READY_FOR_DATA response makes the event mode receiver process a buffer that has no data, and if its status is an error, the next shutdown of the receiver fails: IPTS running in event mode Failed to process buffer: -19 FEEDBACK: recv failed: -11 Failed to send feedback: -11 Stopping IPTS READY_FOR_DATA: cmd failed: 5 Failed to wait for data: -53 Drop all unconsumed responses when starting the device, before sending the first command. Signed-off-by: Jayden Milne <linux-surface@jayd.ml> Patchset: ipts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On EDS v1 devices, switching modes restarts the device. If the restart fails (e.g. because the calling task has a signal pending), the device stays stopped and the HID device inactive. Since ipts_hid_raw_request() rejects requests while the HID device is inactive, userspace cannot retry, and touch input stays broken until the module is reloaded or the MEI client device is probed again. When the restart fails, restore the previous mode and restart the device from a work item instead, retrying a few times. Restoring the previous mode means that the device comes back in the mode that works without iptsd, and that iptsd can switch modes again once it is restarted. Serialize restarts with a mutex, and make sure that no restart is queued or running when the device is removed. Signed-off-by: Jayden Milne <linux-surface@jayd.ml> Patchset: ipts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…itch After a command times out, the ME client can get stuck one response behind: each response is delivered only when the next command is sent. Every later command then times out as well. The restart attempts cycle between failing on GET_DEVICE_INFO and failing on SET_MODE until they give up, and the device stays stopped. Waiting does not clear this, but reloading the module does. Disconnect from the ME client and connect again before each restart attempt, like a re-probe does. The cause of the stuck response is not known. Signed-off-by: Jayden Milne <linux-surface@jayd.ml> Patchset: ipts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Sorry - realized there are some competing PRs here. I'll dig into it |
|
@jaydenmilne your three commits are in #196, rebased onto #187 with your authorship and sign-off kept; each has a |
Author
|
Sweet - I'll build your PR and then run the soak test tonight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've had issues with IPTS blocking sleep and hibernations, resulting in a hot, dead laptop in my bag. I sent Claude after the issues then ran some soak tests, and it seems to have resolved the problem.
I had it run 339 suspend then hibernate cycles over 10 hours (most with the hibernate step simulated). None failed to freeze, there were no kernel warnings, no cases of the driver giving up, and 0 leaked HID devices. All of these issues were observed in kernel logs beforehand.
I also let it hibernate several times the past week. Every time the driver came back and it slept correctly.