* [PATCH v3] drm/appletbdrm: Add suspend and resume support
@ 2026-10-15 21:47 ` Vasilij Markin
0 siblings, 0 replies; 4+ messages in thread
From: Vasilij Markin via B4 Relay @ 2026-10-15 21:47 UTC (permalink / raw)
To: Aun-Ali Zaidi, Aditya Garg, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Lukas Wunner, dri-devel, linux-kernel, Kerem Karabay,
Atharva Tiwari, Atharva Tiwari, Vasilij Markin
From: Vasilij Markin <vasilij.kernel@tototo.si>
The driver has no USB power management callbacks, so the USB core
unbinds it before system suspend and binds it again on resume. The DRM
device is unregistered and registered again on every suspend and resume
cycle, userspace driving the Touch Bar through it (such as tiny-dfr)
loses its device, and the Touch Bar stays dark after resume.
Implement suspend and resume with drm_mode_config_helper_suspend() and
drm_mode_config_helper_resume(), so the device stays registered and the
last committed state is restored on resume. If the device was reset
while suspended, repeat the probe-time handshake first.
Fixes: 0670c2f56e45 ("drm/tiny: add driver for Apple Touch Bars in x86 Macs")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Vasilij Markin <vasilij.kernel@tototo.si>
---
Tested on a MacBookPro16,2 with this change backported to the t2linux
7.2.11 kernel, deep (S3) suspend by closing the lid, tiny-dfr 0.3.7, 7
suspend/resume cycles. On this kernel the Touch Bar display is reset on
every resume ("usb 5-6: reset high-speed USB device number 7 using
t2bce_core"), so reset_resume runs each time: the driver is not probed
again, tiny-dfr keeps running and the Touch Bar shows its content right
after resume. Without reset_resume (v2) the same reset makes the USB core
unbind and probe the driver again, and the Touch Bar stays dark. The error
path in reset_resume is untested: the handshake never failed.
Kernels before commit 3d95f93b30b8 ("drm/appletbdrm: Convert to atomic_create_state")
also need the plane reset hook to free the existing state, otherwise
drm_mode_config_reset() on resume hits WARN_ON(plane->state) in
appletbdrm_primary_plane_reset() and leaks the old state. 7.2.y is such a
kernel; the tested backport carries that change as a separate patch.
Built on drm-misc-next (1c01801c3) with W=1 without warnings.
---
Changes in v3:
- Bring back reset_resume: v2 dropped it because the device was not reset
on resume, but with the t2bce driver of the t2linux 7.2.11 kernel it is
reset on every resume, and without reset_resume the driver is probed
again (Sashiko review of v2).
- In reset_resume, call drm_mode_config_helper_resume() even if the probe
handshake fails, so that the state saved on suspend is released
(Sashiko review of v1).
- Rebase on current drm-misc-next.
- Link to v2: https://lore.kernel.org/all/586d0b39-40c8-4f3d-a786-c1085f87b858@linux.dev/
Changes in v2 (sent by Aditya Garg):
- Remove reset_resume.
- Link to v1: https://lore.kernel.org/r/20260924-appletbdrm-pm-v1-1-0e5432132161@tototo.si
---
drivers/gpu/drm/tiny/appletbdrm.c | 46 +++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/drivers/gpu/drm/tiny/appletbdrm.c b/drivers/gpu/drm/tiny/appletbdrm.c
index 4297d9c11..350dc598c 100644
--- a/drivers/gpu/drm/tiny/appletbdrm.c
+++ b/drivers/gpu/drm/tiny/appletbdrm.c
@@ -30,6 +30,7 @@
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_modeset_helper.h>
#include <drm/drm_plane.h>
#include <drm/drm_print.h>
#include <drm/drm_probe_helper.h>
@@ -821,6 +822,48 @@ static void appletbdrm_shutdown(struct usb_interface *intf)
drm_atomic_helper_shutdown(&adev->drm);
}
+static int appletbdrm_suspend(struct usb_interface *intf, pm_message_t message)
+{
+ struct appletbdrm_device *adev = usb_get_intfdata(intf);
+
+ return drm_mode_config_helper_suspend(&adev->drm);
+}
+
+static int appletbdrm_resume(struct usb_interface *intf)
+{
+ struct appletbdrm_device *adev = usb_get_intfdata(intf);
+
+ return drm_mode_config_helper_resume(&adev->drm);
+}
+
+static int appletbdrm_reset_resume(struct usb_interface *intf)
+{
+ struct appletbdrm_device *adev = usb_get_intfdata(intf);
+ struct drm_device *drm = &adev->drm;
+ int ret, resume_ret;
+
+ /*
+ * A reset puts the device back into its initial state, where it
+ * expects the same handshake as during probe. Resume the DRM side
+ * even if the handshake fails, so that the state saved on suspend
+ * is released.
+ */
+ ret = appletbdrm_get_information(adev);
+ if (ret) {
+ drm_err(drm, "Failed to get display information\n");
+ goto resume;
+ }
+
+ ret = appletbdrm_signal_readiness(adev);
+ if (ret)
+ drm_err(drm, "Failed to signal readiness\n");
+
+resume:
+ resume_ret = drm_mode_config_helper_resume(drm);
+
+ return ret ? ret : resume_ret;
+}
+
static const struct usb_device_id appletbdrm_usb_id_table[] = {
{ USB_DEVICE_INTERFACE_CLASS(0x05ac, 0x8302, USB_CLASS_AUDIO_VIDEO) },
{}
@@ -832,6 +875,9 @@ static struct usb_driver appletbdrm_usb_driver = {
.probe = appletbdrm_probe,
.disconnect = appletbdrm_disconnect,
.shutdown = appletbdrm_shutdown,
+ .suspend = appletbdrm_suspend,
+ .resume = appletbdrm_resume,
+ .reset_resume = appletbdrm_reset_resume,
.id_table = appletbdrm_usb_id_table,
};
module_usb_driver(appletbdrm_usb_driver);
---
base-commit: 1c01801c393ef934286e19f03374999c858e6a20
change-id: 20260924-appletbdrm-pm-6bd220385beb
Best regards,
--
Vasilij Markin <vasilij.kernel@tototo.si>
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v3] drm/appletbdrm: Add suspend and resume support
@ 2026-10-15 21:47 ` Vasilij Markin
0 siblings, 0 replies; 4+ messages in thread
From: Vasilij Markin @ 2026-10-15 21:47 UTC (permalink / raw)
To: Aun-Ali Zaidi, Aditya Garg, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Lukas Wunner, dri-devel, linux-kernel, Kerem Karabay,
Atharva Tiwari, Atharva Tiwari, Vasilij Markin
The driver has no USB power management callbacks, so the USB core
unbinds it before system suspend and binds it again on resume. The DRM
device is unregistered and registered again on every suspend and resume
cycle, userspace driving the Touch Bar through it (such as tiny-dfr)
loses its device, and the Touch Bar stays dark after resume.
Implement suspend and resume with drm_mode_config_helper_suspend() and
drm_mode_config_helper_resume(), so the device stays registered and the
last committed state is restored on resume. If the device was reset
while suspended, repeat the probe-time handshake first.
Fixes: 0670c2f56e45 ("drm/tiny: add driver for Apple Touch Bars in x86 Macs")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Vasilij Markin <vasilij.kernel@tototo.si>
---
Tested on a MacBookPro16,2 with this change backported to the t2linux
7.2.11 kernel, deep (S3) suspend by closing the lid, tiny-dfr 0.3.7, 7
suspend/resume cycles. On this kernel the Touch Bar display is reset on
every resume ("usb 5-6: reset high-speed USB device number 7 using
t2bce_core"), so reset_resume runs each time: the driver is not probed
again, tiny-dfr keeps running and the Touch Bar shows its content right
after resume. Without reset_resume (v2) the same reset makes the USB core
unbind and probe the driver again, and the Touch Bar stays dark. The error
path in reset_resume is untested: the handshake never failed.
Kernels before commit 3d95f93b30b8 ("drm/appletbdrm: Convert to atomic_create_state")
also need the plane reset hook to free the existing state, otherwise
drm_mode_config_reset() on resume hits WARN_ON(plane->state) in
appletbdrm_primary_plane_reset() and leaks the old state. 7.2.y is such a
kernel; the tested backport carries that change as a separate patch.
Built on drm-misc-next (1c01801c3) with W=1 without warnings.
---
Changes in v3:
- Bring back reset_resume: v2 dropped it because the device was not reset
on resume, but with the t2bce driver of the t2linux 7.2.11 kernel it is
reset on every resume, and without reset_resume the driver is probed
again (Sashiko review of v2).
- In reset_resume, call drm_mode_config_helper_resume() even if the probe
handshake fails, so that the state saved on suspend is released
(Sashiko review of v1).
- Rebase on current drm-misc-next.
- Link to v2: https://lore.kernel.org/all/586d0b39-40c8-4f3d-a786-c1085f87b858@linux.dev/
Changes in v2 (sent by Aditya Garg):
- Remove reset_resume.
- Link to v1: https://lore.kernel.org/r/20260924-appletbdrm-pm-v1-1-0e5432132161@tototo.si
---
drivers/gpu/drm/tiny/appletbdrm.c | 46 +++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/drivers/gpu/drm/tiny/appletbdrm.c b/drivers/gpu/drm/tiny/appletbdrm.c
index 4297d9c11..350dc598c 100644
--- a/drivers/gpu/drm/tiny/appletbdrm.c
+++ b/drivers/gpu/drm/tiny/appletbdrm.c
@@ -30,6 +30,7 @@
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_modeset_helper.h>
#include <drm/drm_plane.h>
#include <drm/drm_print.h>
#include <drm/drm_probe_helper.h>
@@ -821,6 +822,48 @@ static void appletbdrm_shutdown(struct usb_interface *intf)
drm_atomic_helper_shutdown(&adev->drm);
}
+static int appletbdrm_suspend(struct usb_interface *intf, pm_message_t message)
+{
+ struct appletbdrm_device *adev = usb_get_intfdata(intf);
+
+ return drm_mode_config_helper_suspend(&adev->drm);
+}
+
+static int appletbdrm_resume(struct usb_interface *intf)
+{
+ struct appletbdrm_device *adev = usb_get_intfdata(intf);
+
+ return drm_mode_config_helper_resume(&adev->drm);
+}
+
+static int appletbdrm_reset_resume(struct usb_interface *intf)
+{
+ struct appletbdrm_device *adev = usb_get_intfdata(intf);
+ struct drm_device *drm = &adev->drm;
+ int ret, resume_ret;
+
+ /*
+ * A reset puts the device back into its initial state, where it
+ * expects the same handshake as during probe. Resume the DRM side
+ * even if the handshake fails, so that the state saved on suspend
+ * is released.
+ */
+ ret = appletbdrm_get_information(adev);
+ if (ret) {
+ drm_err(drm, "Failed to get display information\n");
+ goto resume;
+ }
+
+ ret = appletbdrm_signal_readiness(adev);
+ if (ret)
+ drm_err(drm, "Failed to signal readiness\n");
+
+resume:
+ resume_ret = drm_mode_config_helper_resume(drm);
+
+ return ret ? ret : resume_ret;
+}
+
static const struct usb_device_id appletbdrm_usb_id_table[] = {
{ USB_DEVICE_INTERFACE_CLASS(0x05ac, 0x8302, USB_CLASS_AUDIO_VIDEO) },
{}
@@ -832,6 +875,9 @@ static struct usb_driver appletbdrm_usb_driver = {
.probe = appletbdrm_probe,
.disconnect = appletbdrm_disconnect,
.shutdown = appletbdrm_shutdown,
+ .suspend = appletbdrm_suspend,
+ .resume = appletbdrm_resume,
+ .reset_resume = appletbdrm_reset_resume,
.id_table = appletbdrm_usb_id_table,
};
module_usb_driver(appletbdrm_usb_driver);
---
base-commit: 1c01801c393ef934286e19f03374999c858e6a20
change-id: 20260924-appletbdrm-pm-6bd220385beb
Best regards,
--
Vasilij Markin <vasilij.kernel@tototo.si>
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v3] drm/appletbdrm: Add suspend and resume support
2026-10-15 21:47 ` Vasilij Markin
(?)
@ 2026-10-15 21:57 ` sashiko-bot
-1 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-10-15 21:57 UTC (permalink / raw)
To: Vasilij Markin; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] drm/tiny/appletbdrm: memory leak of info buffer on appletbdrm_send_msg error
- [Medium] drm/appletbdrm: coordinate underflow on resume if device dimensions shrink
--
commit e4d6246ec3eb92963562077b451503c3ef907475
Author: Vasilij Markin <vasilij.kernel@tototo.si>
Subject: drm/appletbdrm: Add suspend and resume support
The driver has no USB power management callbacks, so the USB core unbinds
it before system suspend and binds it again on resume. This commit
implements suspend and resume with drm_mode_config_helper_suspend() and
drm_mode_config_helper_resume() so the device stays registered and the
last committed state is restored on resume.
> diff --git a/drivers/gpu/drm/tiny/appletbdrm.c b/drivers/gpu/drm/tiny/appletbdrm.c
> index 4297d9c1125e4..350dc598c9e7c 100644
> --- a/drivers/gpu/drm/tiny/appletbdrm.c
> +++ b/drivers/gpu/drm/tiny/appletbdrm.c
[ ... ]
> @@ -821,6 +822,48 @@ static void appletbdrm_shutdown(struct usb_interface *intf)
> drm_atomic_helper_shutdown(&adev->drm);
> }
>
[ ... ]
> +static int appletbdrm_reset_resume(struct usb_interface *intf)
> +{
> + struct appletbdrm_device *adev = usb_get_intfdata(intf);
> + struct drm_device *drm = &adev->drm;
> + int ret, resume_ret;
> +
> + /*
> + * A reset puts the device back into its initial state, where it
> + * expects the same handshake as during probe. Resume the DRM side
> + * even if the handshake fails, so that the state saved on suspend
> + * is released.
> + */
> + ret = appletbdrm_get_information(adev);
[Severity: Medium]
This problem wasn't introduced by this patch, but calling
appletbdrm_get_information() here on every system resume can trigger a memory
leak if the USB device fails to handshake correctly:
drivers/gpu/drm/tiny/appletbdrm.c:appletbdrm_get_information() {
...
info = kzalloc_obj(*info);
if (!info)
return -ENOMEM;
ret = appletbdrm_send_msg(adev, APPLETBDRM_MSG_GET_INFORMATION);
if (ret)
return ret; /* Leaks info */
...
}
Can this cause repeated memory leaks if the device frequently fails to wake?
[Severity: Medium]
If a buggy or malicious USB device returns smaller display dimensions during
this handshake, appletbdrm_get_information() updates the device dimensions:
drivers/gpu/drm/tiny/appletbdrm.c:appletbdrm_get_information() {
...
adev->width = get_unaligned_le32(&info->width);
adev->height = get_unaligned_le32(&info->height);
...
}
When the DRM core subsequently commits the suspended atomic state, it uses the
old damage rectangles which are clamped to the pre-suspend mode bounds. This
can cause an integer underflow in appletbdrm_flush_damage():
drivers/gpu/drm/tiny/appletbdrm.c:appletbdrm_flush_damage() {
...
frame->begin_y = cpu_to_le16(adev->height - damage.x2);
...
}
Because damage.x2 can now be larger than the newly updated adev->height, this
could underflow and send huge out-of-bounds coordinates to the USB device.
Should the new dimensions be validated against the existing mode bounds before
applying them?
> + if (ret) {
> + drm_err(drm, "Failed to get display information\n");
> + goto resume;
> + }
> +
> + ret = appletbdrm_signal_readiness(adev);
> + if (ret)
> + drm_err(drm, "Failed to signal readiness\n");
> +
> +resume:
> + resume_ret = drm_mode_config_helper_resume(drm);
> +
> + return ret ? ret : resume_ret;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-appletbdrm-pm-v3-1-47377176619a@tototo.si?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v3] drm/appletbdrm: Add suspend and resume support
2026-10-15 21:47 ` Vasilij Markin
(?)
(?)
@ 2026-10-16 8:05 ` Lukas Wunner
-1 siblings, 0 replies; 4+ messages in thread
From: Lukas Wunner @ 2026-10-16 8:05 UTC (permalink / raw)
To: vasilij.kernel
Cc: Aun-Ali Zaidi, Aditya Garg, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, dri-devel,
linux-kernel, Kerem Karabay, Atharva Tiwari, Atharva Tiwari
On Thu, Oct 15, 2026 at 11:47:36PM +0200, Vasilij Markin via B4 Relay wrote:
> The driver has no USB power management callbacks, so the USB core
> unbinds it before system suspend and binds it again on resume. The DRM
> device is unregistered and registered again on every suspend and resume
> cycle, userspace driving the Touch Bar through it (such as tiny-dfr)
> loses its device, and the Touch Bar stays dark after resume.
>
> Implement suspend and resume with drm_mode_config_helper_suspend() and
> drm_mode_config_helper_resume(), so the device stays registered and the
> last committed state is restored on resume. If the device was reset
> while suspended, repeat the probe-time handshake first.
>
> Fixes: 0670c2f56e45 ("drm/tiny: add driver for Apple Touch Bars in x86 Macs")
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Vasilij Markin <vasilij.kernel@tototo.si>
Applied to drm-misc-next, thanks. Note that we're at the tail end
of the cyce and the drm subsystem has an rc6 cut-off. So this is
v7.5 material.
The Fixes tag could be argued against because this isn't really a fix,
it's more like a missing feature. But I can see how this is useful for
people on older LTS kernels, so I let it slide.
Thanks,
Lukas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-16 8:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15 21:47 [PATCH v3] drm/appletbdrm: Add suspend and resume support Vasilij Markin via B4 Relay
2026-10-15 21:47 ` Vasilij Markin
2026-10-15 21:57 ` sashiko-bot
2026-10-16 8:05 ` Lukas Wunner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.