Files
linux/drivers/gpu/drm/drm_client_sysrq.c
Thomas Zimmermann 6915190a50 drm/client: Support emergency restore via sysrq for all clients
Move the sysrq functionality from DRM fbdev helpers to the DRM device
and in-kernel clients, so that it becomes available on all clients.

DRM fbdev helpers support emergency restoration of the console output
via a special key combination. Press SysRq+v to replace the current
compositor with the kernel's output on the framebuffer console. This
allows users to see the log messages during system emergencies.

By moving the functionality from fbdev helpers to the DRM device, any
in-kernel client can serve as emergency output. This can be used to
bring up drm_log, for example.

Each DRM device registers itself to the list of possible sysrq handlers.
On receiving SysRq+v, the DRM core goes over all registered devices and
restores an in-kernel DRM client for each of them.

See Documentation/admin-guide/sysrq.rst on how to invoke SysRq. Switch
VTs to bring back the user-space compositor.

v2:
- declare placeholders as 'static inline' (kernel test robot)
- fix grammar in commit description

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patch.msgid.link/20251110154616.539328-3-tzimmermann@suse.de
2025-11-25 08:43:47 +01:00

66 lines
1.7 KiB
C

// SPDX-License-Identifier: GPL-2.0 or MIT
#include <linux/sysrq.h>
#include <drm/drm_client_event.h>
#include <drm/drm_device.h>
#include <drm/drm_print.h>
#include "drm_internal.h"
#ifdef CONFIG_MAGIC_SYSRQ
static LIST_HEAD(drm_client_sysrq_dev_list);
static DEFINE_MUTEX(drm_client_sysrq_dev_lock);
/* emergency restore, don't bother with error reporting */
static void drm_client_sysrq_restore_work_fn(struct work_struct *ignored)
{
struct drm_device *dev;
guard(mutex)(&drm_client_sysrq_dev_lock);
list_for_each_entry(dev, &drm_client_sysrq_dev_list, client_sysrq_list) {
if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
continue;
drm_client_dev_restore(dev, true);
}
}
static DECLARE_WORK(drm_client_sysrq_restore_work, drm_client_sysrq_restore_work_fn);
static void drm_client_sysrq_restore_handler(u8 ignored)
{
schedule_work(&drm_client_sysrq_restore_work);
}
static const struct sysrq_key_op drm_client_sysrq_restore_op = {
.handler = drm_client_sysrq_restore_handler,
.help_msg = "force-fb(v)",
.action_msg = "Restore framebuffer console",
};
void drm_client_sysrq_register(struct drm_device *dev)
{
guard(mutex)(&drm_client_sysrq_dev_lock);
if (list_empty(&drm_client_sysrq_dev_list))
register_sysrq_key('v', &drm_client_sysrq_restore_op);
list_add(&dev->client_sysrq_list, &drm_client_sysrq_dev_list);
}
void drm_client_sysrq_unregister(struct drm_device *dev)
{
guard(mutex)(&drm_client_sysrq_dev_lock);
/* remove device from global restore list */
if (!drm_WARN_ON(dev, list_empty(&dev->client_sysrq_list)))
list_del(&dev->client_sysrq_list);
/* no devices left; unregister key */
if (list_empty(&drm_client_sysrq_dev_list))
unregister_sysrq_key('v', &drm_client_sysrq_restore_op);
}
#endif