* [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking
@ 2026-11-25 23:11 Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
` (7 more replies)
0 siblings, 8 replies; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
This series fixes a kthread lifecycle bug and cleans up hotkey NVRAM
polling setup and locking in thinkpad_acpi:
- Remove the unsafe early return on TPACPI_LIFE_EXITING in
hotkey_kthread() so kthread_stop() never races with kthread exit.
- Drop the dead -ENXIO check on hotkey_mask_set() in hotkey_init().
- Drop obsolete tpacpi_lifecycle checks from hotkey_inputdev_open() and
hotkey_inputdev_close(), fold hotkey_poll_setup() calls into existing
hotkey_mutex critical sections, and remove hotkey_poll_setup_safe().
- Call hotkey_poll_setup() in hotkey_user_mask_set() so that runtime
hotkey mask updates via /proc/acpi/ibm/hotkey also start or stop the
NVRAM polling thread.
- Replace the HOTKEY_CONFIG_CRITICAL_START/END macros and manual
hotkey_thread_data_mutex lock/unlock calls with scoped_guard().
- Convert hotkey_thread_data_mutex to a spinlock.
- Remove the unused hotkey_poll_active bitfield from tp_features.
- Drop the redundant tpacpi_inputdev->dev.parent assignment in
tpacpi_pdriver_probe().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
Dmitry Torokhov (8):
platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread()
platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init()
platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup
platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set()
platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking
platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock
platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag
platform/x86: thinkpad_acpi: drop redundant input device parent assignment
drivers/platform/x86/lenovo/thinkpad_acpi.c | 148 ++++++++++------------------
1 file changed, 52 insertions(+), 96 deletions(-)
---
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
change-id: 20260930-thinkpad-acpi-hotkey-poll-6c5e037cbf3c
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread()
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 2:43 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init() Dmitry Torokhov
` (6 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
hotkey_kthread() starts with an early return when tpacpi_lifecycle is
TPACPI_LIFE_EXITING. A kthread started with kthread_run() and stopped
via kthread_stop() must not exit before kthread_should_stop() returns
true, otherwise its task_struct can be freed before
hotkey_poll_stop_sync() calls kthread_stop().
Remove the early return so hotkey_kthread() always waits for
kthread_stop().
Fixes: 01e88f25985d ("ACPI: thinkpad-acpi: add CMOS NVRAM polling for hot keys (v9)")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 1bccc21ee29b..a586113ab1a7 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -2451,9 +2451,6 @@ static int hotkey_kthread(void *data)
unsigned int poll_freq;
bool was_frozen;
- if (tpacpi_lifecycle == TPACPI_LIFE_EXITING)
- return 0;
-
set_freezable();
so = 0;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init()
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 2:46 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup Dmitry Torokhov
` (5 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
hotkey_mask_set() only ever returns 0 or -EIO, never -ENXIO. Simplify
the error check on its return value in hotkey_init() accordingly.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index a586113ab1a7..659a2c5d1982 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -3572,7 +3572,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
| hotkey_driver_mask)
& ~hotkey_source_mask);
}
- if (res < 0 && res != -ENXIO) {
+ if (res) {
hotkey_exit();
return res;
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init() Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 3:28 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set() Dmitry Torokhov
` (4 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
Since commit 38b9ab80db31 ("platform/x86: thinkpad_acpi: Move subdriver
initialization to tpacpi_pdriver's probe."), tpacpi_subdrivers_release()
is registered via devm_add_action_or_reset() before tpacpi_inputdev is
registered. Because devres resources are unwound in reverse order,
tpacpi_inputdev is always unregistered (closing any open handles and
preventing new opens) before hotkey_exit() is called. Combined with
hotkey_kthread() no longer exiting early on TPACPI_LIFE_EXITING, the
lifecycle guards in the input callbacks are unnecessary.
Drop the obsolete tpacpi_lifecycle checks and BUG() from
hotkey_inputdev_open() and hotkey_inputdev_close(), as well as the
redundant driver mask check in hotkey_inputdev_close() (which
hotkey_poll_setup() already evaluates).
Also call hotkey_poll_setup() directly inside the existing hotkey_mutex
critical sections in hotkey_init() and hotkey_resume(), and remove the
now-unused hotkey_poll_setup_safe() wrapper.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 52 +++++++++--------------------
1 file changed, 15 insertions(+), 37 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 659a2c5d1982..e5f78107bd1a 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -2546,12 +2546,6 @@ static void hotkey_poll_setup(const bool may_warn)
}
}
-static void hotkey_poll_setup_safe(const bool may_warn)
-{
- guard(mutex)(&hotkey_mutex);
- hotkey_poll_setup(may_warn);
-}
-
static void hotkey_poll_set_freq(unsigned int freq)
{
lockdep_assert_held(&hotkey_mutex);
@@ -2568,10 +2562,6 @@ static void hotkey_poll_setup(const bool __unused)
{
}
-static void hotkey_poll_setup_safe(const bool __unused)
-{
-}
-
static void hotkey_poll_stop_sync(void)
{
}
@@ -2579,21 +2569,12 @@ static void hotkey_poll_stop_sync(void)
static int hotkey_inputdev_open(struct input_dev *dev)
{
- switch (tpacpi_lifecycle) {
- case TPACPI_LIFE_INIT:
- case TPACPI_LIFE_RUNNING:
- scoped_guard(mutex, &hotkey_mutex) {
- hotkey_input_enabled = true;
- hotkey_poll_setup(false);
- }
- return 0;
- case TPACPI_LIFE_EXITING:
- return -EBUSY;
- }
+ guard(mutex)(&hotkey_mutex);
+
+ hotkey_input_enabled = true;
+ hotkey_poll_setup(false);
- /* Should only happen if tpacpi_lifecycle is corrupt */
- BUG();
- return -EBUSY;
+ return 0;
}
static void hotkey_inputdev_close(struct input_dev *dev)
@@ -2601,11 +2582,7 @@ static void hotkey_inputdev_close(struct input_dev *dev)
guard(mutex)(&hotkey_mutex);
hotkey_input_enabled = false;
-
- /* disable hotkey polling when possible */
- if (tpacpi_lifecycle != TPACPI_LIFE_EXITING &&
- !(hotkey_source_mask & hotkey_driver_mask))
- hotkey_poll_setup(false);
+ hotkey_poll_setup(false);
}
/* sysfs hotkey enable ------------------------------------------------- */
@@ -3571,22 +3548,23 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask)
| hotkey_driver_mask)
& ~hotkey_source_mask);
+ if (!res) {
+ hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
+ & ~hotkey_reserved_mask;
+ vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
+ "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
+ hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
+ hotkey_poll_setup(true);
+ }
}
if (res) {
hotkey_exit();
return res;
}
- hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
- & ~hotkey_reserved_mask;
- vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
- "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
- hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
tpacpi_inputdev->open = &hotkey_inputdev_open;
tpacpi_inputdev->close = &hotkey_inputdev_close;
- hotkey_poll_setup_safe(true);
-
/* Enable TrackPoint doubletap event reporting by default. */
tp_features.trackpoint_doubletap_enable = 1;
@@ -4024,6 +4002,7 @@ static void hotkey_resume(void)
if (hotkey_status_set(true) < 0 ||
hotkey_mask_set(hotkey_acpi_mask) < 0)
pr_err("error while attempting to reset the event firmware interface\n");
+ hotkey_poll_setup(false);
}
tpacpi_send_radiosw_update();
@@ -4033,7 +4012,6 @@ static void hotkey_resume(void)
keyboard_attached_on_screen_notify_change();
hotkey_wakeup_reason_notify_change();
hotkey_wakeup_hotunplug_complete_notify_change();
- hotkey_poll_setup_safe(false);
/* restore previous mode of adaptive keyboard of X1 Carbon */
if (tp_features.has_adaptive_kbd) {
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set()
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
` (2 preceding siblings ...)
2026-11-25 23:11 ` [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 2:57 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking Dmitry Torokhov
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
hotkey_user_mask_set() is called from both hotkey_mask_store() (sysfs)
and hotkey_write() (/proc/acpi/ibm/hotkey), but only hotkey_mask_store()
called hotkey_poll_setup(true) afterwards. As a result, updating the
hotkey mask through /proc/acpi/ibm/hotkey did not start or stop the
NVRAM polling thread to match the new mask.
Move the hotkey_poll_setup(true) call into hotkey_user_mask_set(),
matching tpacpi_hotkey_driver_mask_set(), and drop the redundant #ifdef
guard from hotkey_mask_store().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index e5f78107bd1a..7a82a9014a3e 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -2137,6 +2137,8 @@ static int hotkey_user_mask_set(const u32 mask)
/* Enable the available bits in hotkey_user_mask */
hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask);
+ hotkey_poll_setup(true);
+
return rc;
}
@@ -2647,10 +2649,6 @@ static ssize_t hotkey_mask_store(struct device *dev,
res = hotkey_user_mask_set(t);
-#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
- hotkey_poll_setup(true);
-#endif
-
tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t);
return (res) ? res : count;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
` (3 preceding siblings ...)
2026-11-25 23:11 ` [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set() Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 3:01 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock Dmitry Torokhov
` (2 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
Replace the HOTKEY_CONFIG_CRITICAL_START and HOTKEY_CONFIG_CRITICAL_END
macros and manual hotkey_thread_data_mutex lock/unlock calls with
scoped_guard(mutex, &hotkey_thread_data_mutex).
Keep the hotkey_driver_mask assignment inside the guard in
tpacpi_hotkey_driver_mask_set() when polling is enabled so updates to
hotkey_driver_mask, hotkey_source_mask, and hotkey_config_change remain
atomic with respect to hotkey_kthread().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 74 ++++++++++++-----------------
1 file changed, 31 insertions(+), 43 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 7a82a9014a3e..58500b72d9d2 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -1819,8 +1819,6 @@ static struct task_struct *tpacpi_hotkey_task;
*
* Increment hotkey_config_change when changing them if you
* want the kthread to forget old state.
- *
- * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
*/
static struct mutex hotkey_thread_data_mutex;
static unsigned int hotkey_config_change;
@@ -1828,29 +1826,14 @@ static unsigned int hotkey_config_change;
/*
* hotkey poller control variables
*
- * Must be atomic or readers will also need to acquire mutex
- *
- * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
- * should be used only when the changes need to be taken as
- * a block, OR when one needs to force the kthread to forget
- * old state.
+ * Must be atomic or readers will also need to acquire mutex.
*/
static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
static unsigned int hotkey_poll_freq = 10; /* Hz */
-#define HOTKEY_CONFIG_CRITICAL_START \
- do { \
- mutex_lock(&hotkey_thread_data_mutex); \
- hotkey_config_change++; \
- } while (0);
-#define HOTKEY_CONFIG_CRITICAL_END \
- mutex_unlock(&hotkey_thread_data_mutex);
-
#else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
#define hotkey_source_mask 0U
-#define HOTKEY_CONFIG_CRITICAL_START
-#define HOTKEY_CONFIG_CRITICAL_END
#endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
@@ -2159,12 +2142,15 @@ static int tpacpi_hotkey_driver_mask_set(const u32 mask)
guard(mutex)(&hotkey_mutex);
- HOTKEY_CONFIG_CRITICAL_START
- hotkey_driver_mask = mask;
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
- hotkey_source_mask |= (mask & ~hotkey_all_mask);
+ scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ hotkey_driver_mask = mask;
+ hotkey_source_mask |= (mask & ~hotkey_all_mask);
+ hotkey_config_change++;
+ }
+#else
+ hotkey_driver_mask = mask;
#endif
- HOTKEY_CONFIG_CRITICAL_END
rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) &
~hotkey_source_mask);
@@ -2460,13 +2446,13 @@ static int hotkey_kthread(void *data)
t = 0;
/* Initial state for compares */
- mutex_lock(&hotkey_thread_data_mutex);
- change_detector = hotkey_config_change;
- poll_mask = hotkey_source_mask;
- event_mask = hotkey_source_mask &
- (hotkey_driver_mask | hotkey_user_mask);
- poll_freq = hotkey_poll_freq;
- mutex_unlock(&hotkey_thread_data_mutex);
+ scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ change_detector = hotkey_config_change;
+ poll_mask = hotkey_source_mask;
+ event_mask = hotkey_source_mask &
+ (hotkey_driver_mask | hotkey_user_mask);
+ poll_freq = hotkey_poll_freq;
+ }
hotkey_read_nvram(&s[so], poll_mask);
while (!kthread_should_stop()) {
@@ -2483,18 +2469,19 @@ static int hotkey_kthread(void *data)
if (t > 0 && !was_frozen)
continue;
- mutex_lock(&hotkey_thread_data_mutex);
- if (was_frozen || hotkey_config_change != change_detector) {
- /* forget old state on thaw or config change */
- si = so;
- t = 0;
- change_detector = hotkey_config_change;
+ scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ if (was_frozen ||
+ hotkey_config_change != change_detector) {
+ /* forget old state on thaw or config change */
+ si = so;
+ t = 0;
+ change_detector = hotkey_config_change;
+ }
+ poll_mask = hotkey_source_mask;
+ event_mask = hotkey_source_mask &
+ (hotkey_driver_mask | hotkey_user_mask);
+ poll_freq = hotkey_poll_freq;
}
- poll_mask = hotkey_source_mask;
- event_mask = hotkey_source_mask &
- (hotkey_driver_mask | hotkey_user_mask);
- poll_freq = hotkey_poll_freq;
- mutex_unlock(&hotkey_thread_data_mutex);
if (likely(poll_mask)) {
hotkey_read_nvram(&s[si], poll_mask);
@@ -2739,9 +2726,10 @@ static ssize_t hotkey_source_mask_store(struct device *dev,
if (rc)
return rc;
- HOTKEY_CONFIG_CRITICAL_START
- hotkey_source_mask = t;
- HOTKEY_CONFIG_CRITICAL_END
+ scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ hotkey_source_mask = t;
+ hotkey_config_change++;
+ }
rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) &
~hotkey_source_mask);
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
` (4 preceding siblings ...)
2026-11-25 23:11 ` [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 3:35 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment Dmitry Torokhov
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
hotkey_thread_data_mutex only protects a few in-memory integer reads
and updates across hotkey_kthread(), tpacpi_hotkey_driver_mask_set(),
and hotkey_source_mask_store(), with no sleeping calls inside any of
its critical sections.
Convert it to a statically initialized spinlock_t
(hotkey_thread_data_lock), which also allows dropping the conditional
mutex_init() call from hotkey_init().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 58500b72d9d2..0ebaea0ab96b 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -67,6 +67,7 @@
#include <linux/sched/signal.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
+#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/string_choices.h>
#include <linux/string_helpers.h>
@@ -1814,19 +1815,19 @@ struct tp_nvram_state {
static struct task_struct *tpacpi_hotkey_task;
/*
- * Acquire mutex to write poller control variables as an
+ * Acquire spinlock to write poller control variables as an
* atomic block.
*
* Increment hotkey_config_change when changing them if you
* want the kthread to forget old state.
*/
-static struct mutex hotkey_thread_data_mutex;
+static DEFINE_SPINLOCK(hotkey_thread_data_lock);
static unsigned int hotkey_config_change;
/*
* hotkey poller control variables
*
- * Must be atomic or readers will also need to acquire mutex.
+ * Must be atomic or readers will also need to acquire spinlock.
*/
static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
static unsigned int hotkey_poll_freq = 10; /* Hz */
@@ -2143,7 +2144,7 @@ static int tpacpi_hotkey_driver_mask_set(const u32 mask)
guard(mutex)(&hotkey_mutex);
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
hotkey_driver_mask = mask;
hotkey_source_mask |= (mask & ~hotkey_all_mask);
hotkey_config_change++;
@@ -2446,7 +2447,7 @@ static int hotkey_kthread(void *data)
t = 0;
/* Initial state for compares */
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
change_detector = hotkey_config_change;
poll_mask = hotkey_source_mask;
event_mask = hotkey_source_mask &
@@ -2469,7 +2470,7 @@ static int hotkey_kthread(void *data)
if (t > 0 && !was_frozen)
continue;
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
if (was_frozen ||
hotkey_config_change != change_detector) {
/* forget old state on thaw or config change */
@@ -2726,7 +2727,7 @@ static ssize_t hotkey_source_mask_store(struct device *dev,
if (rc)
return rc;
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
hotkey_source_mask = t;
hotkey_config_change++;
}
@@ -3329,10 +3330,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
TPACPI_ACPIHANDLE_INIT(hkey);
mutex_init(&hotkey_mutex);
-#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
- mutex_init(&hotkey_thread_data_mutex);
-#endif
-
/* hotkey not supported on 570 */
tp_features.hotkey = hkey_handle != NULL;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
` (5 preceding siblings ...)
2026-11-25 23:11 ` [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 3:02 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment Dmitry Torokhov
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
Drop the unused hotkey_poll_active bitfield from tp_features, which has
never been referenced since it was introduced.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 0ebaea0ab96b..898d919d697a 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -377,7 +377,6 @@ static struct {
u32 mixer_no_level_control:1;
u32 battery_force_primary:1;
u32 platform_drv_registered:1;
- u32 hotkey_poll_active:1;
u32 has_adaptive_kbd:1;
u32 kbd_lang:1;
u32 trackpoint_doubletap_enable:1;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
` (6 preceding siblings ...)
2026-11-25 23:11 ` [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag Dmitry Torokhov
@ 2026-11-25 23:11 ` Dmitry Torokhov
2026-11-27 3:05 ` Mark Pearson
7 siblings, 1 reply; 17+ messages in thread
From: Dmitry Torokhov @ 2026-11-25 23:11 UTC (permalink / raw)
To: Henrique de Moraes Holschuh, Mark Pearson, Derek J. Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
Drop the manual tpacpi_inputdev->dev.parent assignment in
tpacpi_pdriver_probe(), as devm_input_allocate_device(&pdev->dev)
already sets the parent device.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 898d919d697a..e809ed417e0c 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -12245,7 +12245,6 @@ static int __init tpacpi_pdriver_probe(struct platform_device *pdev)
tpacpi_inputdev->id.vendor = thinkpad_id.vendor;
tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
- tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev;
/* Init subdriver dependencies */
tpacpi_detect_brightness_capabilities();
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread()
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
@ 2026-11-27 2:43 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 2:43 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> hotkey_kthread() starts with an early return when tpacpi_lifecycle is
> TPACPI_LIFE_EXITING. A kthread started with kthread_run() and stopped
> via kthread_stop() must not exit before kthread_should_stop() returns
> true, otherwise its task_struct can be freed before
> hotkey_poll_stop_sync() calls kthread_stop().
>
> Remove the early return so hotkey_kthread() always waits for
> kthread_stop().
>
> Fixes: 01e88f25985d ("ACPI: thinkpad-acpi: add CMOS NVRAM polling for
> hot keys (v9)")
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 1bccc21ee29b..a586113ab1a7 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -2451,9 +2451,6 @@ static int hotkey_kthread(void *data)
> unsigned int poll_freq;
> bool was_frozen;
>
> - if (tpacpi_lifecycle == TPACPI_LIFE_EXITING)
> - return 0;
> -
> set_freezable();
>
> so = 0;
>
> --
> 2.56.1.839.g22a8290db9-goog
This was implemented quite a long time ago :)
Change looks good to me
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init()
2026-11-25 23:11 ` [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init() Dmitry Torokhov
@ 2026-11-27 2:46 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 2:46 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> hotkey_mask_set() only ever returns 0 or -EIO, never -ENXIO. Simplify
> the error check on its return value in hotkey_init() accordingly.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index a586113ab1a7..659a2c5d1982 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -3572,7 +3572,7 @@ static int __init hotkey_init(struct
> ibm_init_struct *iibm)
> | hotkey_driver_mask)
> & ~hotkey_source_mask);
> }
> - if (res < 0 && res != -ENXIO) {
> + if (res) {
> hotkey_exit();
> return res;
> }
>
> --
> 2.56.1.839.g22a8290db9-goog
Looks good to me.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set()
2026-11-25 23:11 ` [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set() Dmitry Torokhov
@ 2026-11-27 2:57 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 2:57 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> hotkey_user_mask_set() is called from both hotkey_mask_store() (sysfs)
> and hotkey_write() (/proc/acpi/ibm/hotkey), but only hotkey_mask_store()
> called hotkey_poll_setup(true) afterwards. As a result, updating the
> hotkey mask through /proc/acpi/ibm/hotkey did not start or stop the
> NVRAM polling thread to match the new mask.
>
> Move the hotkey_poll_setup(true) call into hotkey_user_mask_set(),
> matching tpacpi_hotkey_driver_mask_set(), and drop the redundant #ifdef
> guard from hotkey_mask_store().
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index e5f78107bd1a..7a82a9014a3e 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -2137,6 +2137,8 @@ static int hotkey_user_mask_set(const u32 mask)
> /* Enable the available bits in hotkey_user_mask */
> hotkey_user_mask = mask & (hotkey_acpi_mask | hotkey_source_mask);
>
> + hotkey_poll_setup(true);
> +
> return rc;
> }
>
> @@ -2647,10 +2649,6 @@ static ssize_t hotkey_mask_store(struct device *dev,
>
> res = hotkey_user_mask_set(t);
>
> -#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
> - hotkey_poll_setup(true);
> -#endif
> -
> tpacpi_disclose_usertask("hotkey_mask", "set to 0x%08lx\n", t);
>
> return (res) ? res : count;
>
> --
> 2.56.1.839.g22a8290db9-goog
Looks good to me.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking
2026-11-25 23:11 ` [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking Dmitry Torokhov
@ 2026-11-27 3:01 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 3:01 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> Replace the HOTKEY_CONFIG_CRITICAL_START and HOTKEY_CONFIG_CRITICAL_END
> macros and manual hotkey_thread_data_mutex lock/unlock calls with
> scoped_guard(mutex, &hotkey_thread_data_mutex).
>
> Keep the hotkey_driver_mask assignment inside the guard in
> tpacpi_hotkey_driver_mask_set() when polling is enabled so updates to
> hotkey_driver_mask, hotkey_source_mask, and hotkey_config_change remain
> atomic with respect to hotkey_kthread().
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 74 ++++++++++++-----------------
> 1 file changed, 31 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 7a82a9014a3e..58500b72d9d2 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -1819,8 +1819,6 @@ static struct task_struct *tpacpi_hotkey_task;
> *
> * Increment hotkey_config_change when changing them if you
> * want the kthread to forget old state.
> - *
> - * See HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
> */
> static struct mutex hotkey_thread_data_mutex;
> static unsigned int hotkey_config_change;
> @@ -1828,29 +1826,14 @@ static unsigned int hotkey_config_change;
> /*
> * hotkey poller control variables
> *
> - * Must be atomic or readers will also need to acquire mutex
> - *
> - * HOTKEY_CONFIG_CRITICAL_START/HOTKEY_CONFIG_CRITICAL_END
> - * should be used only when the changes need to be taken as
> - * a block, OR when one needs to force the kthread to forget
> - * old state.
> + * Must be atomic or readers will also need to acquire mutex.
> */
> static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
> static unsigned int hotkey_poll_freq = 10; /* Hz */
>
> -#define HOTKEY_CONFIG_CRITICAL_START \
> - do { \
> - mutex_lock(&hotkey_thread_data_mutex); \
> - hotkey_config_change++; \
> - } while (0);
> -#define HOTKEY_CONFIG_CRITICAL_END \
> - mutex_unlock(&hotkey_thread_data_mutex);
> -
> #else /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
>
> #define hotkey_source_mask 0U
> -#define HOTKEY_CONFIG_CRITICAL_START
> -#define HOTKEY_CONFIG_CRITICAL_END
>
> #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
>
> @@ -2159,12 +2142,15 @@ static int tpacpi_hotkey_driver_mask_set(const u32 mask)
>
> guard(mutex)(&hotkey_mutex);
>
> - HOTKEY_CONFIG_CRITICAL_START
> - hotkey_driver_mask = mask;
> #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
> - hotkey_source_mask |= (mask & ~hotkey_all_mask);
> + scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + hotkey_driver_mask = mask;
> + hotkey_source_mask |= (mask & ~hotkey_all_mask);
> + hotkey_config_change++;
> + }
> +#else
> + hotkey_driver_mask = mask;
> #endif
> - HOTKEY_CONFIG_CRITICAL_END
>
> rc = hotkey_mask_set((hotkey_acpi_mask | hotkey_driver_mask) &
> ~hotkey_source_mask);
> @@ -2460,13 +2446,13 @@ static int hotkey_kthread(void *data)
> t = 0;
>
> /* Initial state for compares */
> - mutex_lock(&hotkey_thread_data_mutex);
> - change_detector = hotkey_config_change;
> - poll_mask = hotkey_source_mask;
> - event_mask = hotkey_source_mask &
> - (hotkey_driver_mask | hotkey_user_mask);
> - poll_freq = hotkey_poll_freq;
> - mutex_unlock(&hotkey_thread_data_mutex);
> + scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + change_detector = hotkey_config_change;
> + poll_mask = hotkey_source_mask;
> + event_mask = hotkey_source_mask &
> + (hotkey_driver_mask | hotkey_user_mask);
> + poll_freq = hotkey_poll_freq;
> + }
> hotkey_read_nvram(&s[so], poll_mask);
>
> while (!kthread_should_stop()) {
> @@ -2483,18 +2469,19 @@ static int hotkey_kthread(void *data)
> if (t > 0 && !was_frozen)
> continue;
>
> - mutex_lock(&hotkey_thread_data_mutex);
> - if (was_frozen || hotkey_config_change != change_detector) {
> - /* forget old state on thaw or config change */
> - si = so;
> - t = 0;
> - change_detector = hotkey_config_change;
> + scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + if (was_frozen ||
> + hotkey_config_change != change_detector) {
> + /* forget old state on thaw or config change */
> + si = so;
> + t = 0;
> + change_detector = hotkey_config_change;
> + }
> + poll_mask = hotkey_source_mask;
> + event_mask = hotkey_source_mask &
> + (hotkey_driver_mask | hotkey_user_mask);
> + poll_freq = hotkey_poll_freq;
> }
> - poll_mask = hotkey_source_mask;
> - event_mask = hotkey_source_mask &
> - (hotkey_driver_mask | hotkey_user_mask);
> - poll_freq = hotkey_poll_freq;
> - mutex_unlock(&hotkey_thread_data_mutex);
>
> if (likely(poll_mask)) {
> hotkey_read_nvram(&s[si], poll_mask);
> @@ -2739,9 +2726,10 @@ static ssize_t hotkey_source_mask_store(struct
> device *dev,
> if (rc)
> return rc;
>
> - HOTKEY_CONFIG_CRITICAL_START
> - hotkey_source_mask = t;
> - HOTKEY_CONFIG_CRITICAL_END
> + scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + hotkey_source_mask = t;
> + hotkey_config_change++;
> + }
>
> rc = hotkey_mask_set((hotkey_user_mask | hotkey_driver_mask) &
> ~hotkey_source_mask);
>
> --
> 2.56.1.839.g22a8290db9-goog
Looks good to me.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag
2026-11-25 23:11 ` [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag Dmitry Torokhov
@ 2026-11-27 3:02 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 3:02 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> Drop the unused hotkey_poll_active bitfield from tp_features, which has
> never been referenced since it was introduced.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 0ebaea0ab96b..898d919d697a 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -377,7 +377,6 @@ static struct {
> u32 mixer_no_level_control:1;
> u32 battery_force_primary:1;
> u32 platform_drv_registered:1;
> - u32 hotkey_poll_active:1;
> u32 has_adaptive_kbd:1;
> u32 kbd_lang:1;
> u32 trackpoint_doubletap_enable:1;
>
> --
> 2.56.1.839.g22a8290db9-goog
Looks good.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment
2026-11-25 23:11 ` [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment Dmitry Torokhov
@ 2026-11-27 3:05 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 3:05 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> Drop the manual tpacpi_inputdev->dev.parent assignment in
> tpacpi_pdriver_probe(), as devm_input_allocate_device(&pdev->dev)
> already sets the parent device.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 898d919d697a..e809ed417e0c 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -12245,7 +12245,6 @@ static int __init tpacpi_pdriver_probe(struct
> platform_device *pdev)
> tpacpi_inputdev->id.vendor = thinkpad_id.vendor;
> tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
> tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
> - tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev;
>
> /* Init subdriver dependencies */
> tpacpi_detect_brightness_capabilities();
>
> --
> 2.56.1.839.g22a8290db9-goog
Looks good.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup
2026-11-25 23:11 ` [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup Dmitry Torokhov
@ 2026-11-27 3:28 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 3:28 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> Since commit 38b9ab80db31 ("platform/x86: thinkpad_acpi: Move subdriver
> initialization to tpacpi_pdriver's probe."), tpacpi_subdrivers_release()
> is registered via devm_add_action_or_reset() before tpacpi_inputdev is
> registered. Because devres resources are unwound in reverse order,
> tpacpi_inputdev is always unregistered (closing any open handles and
> preventing new opens) before hotkey_exit() is called. Combined with
> hotkey_kthread() no longer exiting early on TPACPI_LIFE_EXITING, the
> lifecycle guards in the input callbacks are unnecessary.
>
> Drop the obsolete tpacpi_lifecycle checks and BUG() from
> hotkey_inputdev_open() and hotkey_inputdev_close(), as well as the
> redundant driver mask check in hotkey_inputdev_close() (which
> hotkey_poll_setup() already evaluates).
>
> Also call hotkey_poll_setup() directly inside the existing hotkey_mutex
> critical sections in hotkey_init() and hotkey_resume(), and remove the
> now-unused hotkey_poll_setup_safe() wrapper.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 52 +++++++++--------------------
> 1 file changed, 15 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 659a2c5d1982..e5f78107bd1a 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -2546,12 +2546,6 @@ static void hotkey_poll_setup(const bool
> may_warn)
> }
> }
>
> -static void hotkey_poll_setup_safe(const bool may_warn)
> -{
> - guard(mutex)(&hotkey_mutex);
> - hotkey_poll_setup(may_warn);
> -}
> -
> static void hotkey_poll_set_freq(unsigned int freq)
> {
> lockdep_assert_held(&hotkey_mutex);
> @@ -2568,10 +2562,6 @@ static void hotkey_poll_setup(const bool __unused)
> {
> }
>
> -static void hotkey_poll_setup_safe(const bool __unused)
> -{
> -}
> -
> static void hotkey_poll_stop_sync(void)
> {
> }
> @@ -2579,21 +2569,12 @@ static void hotkey_poll_stop_sync(void)
>
> static int hotkey_inputdev_open(struct input_dev *dev)
> {
> - switch (tpacpi_lifecycle) {
> - case TPACPI_LIFE_INIT:
> - case TPACPI_LIFE_RUNNING:
> - scoped_guard(mutex, &hotkey_mutex) {
> - hotkey_input_enabled = true;
> - hotkey_poll_setup(false);
> - }
> - return 0;
> - case TPACPI_LIFE_EXITING:
> - return -EBUSY;
> - }
> + guard(mutex)(&hotkey_mutex);
> +
> + hotkey_input_enabled = true;
> + hotkey_poll_setup(false);
>
> - /* Should only happen if tpacpi_lifecycle is corrupt */
> - BUG();
> - return -EBUSY;
> + return 0;
> }
>
> static void hotkey_inputdev_close(struct input_dev *dev)
> @@ -2601,11 +2582,7 @@ static void hotkey_inputdev_close(struct input_dev *dev)
> guard(mutex)(&hotkey_mutex);
>
> hotkey_input_enabled = false;
> -
> - /* disable hotkey polling when possible */
> - if (tpacpi_lifecycle != TPACPI_LIFE_EXITING &&
> - !(hotkey_source_mask & hotkey_driver_mask))
> - hotkey_poll_setup(false);
> + hotkey_poll_setup(false);
> }
>
> /* sysfs hotkey enable
> ------------------------------------------------- */
> @@ -3571,22 +3548,23 @@ static int __init hotkey_init(struct
> ibm_init_struct *iibm)
> res = hotkey_mask_set(((hotkey_all_mask & ~hotkey_reserved_mask)
> | hotkey_driver_mask)
> & ~hotkey_source_mask);
> + if (!res) {
> + hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
> + & ~hotkey_reserved_mask;
> + vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> + "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
> + hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
> + hotkey_poll_setup(true);
> + }
> }
> if (res) {
> hotkey_exit();
> return res;
> }
> - hotkey_user_mask = (hotkey_acpi_mask | hotkey_source_mask)
> - & ~hotkey_reserved_mask;
> - vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
> - "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n",
> - hotkey_user_mask, hotkey_acpi_mask, hotkey_source_mask);
>
> tpacpi_inputdev->open = &hotkey_inputdev_open;
> tpacpi_inputdev->close = &hotkey_inputdev_close;
>
> - hotkey_poll_setup_safe(true);
> -
> /* Enable TrackPoint doubletap event reporting by default. */
> tp_features.trackpoint_doubletap_enable = 1;
>
> @@ -4024,6 +4002,7 @@ static void hotkey_resume(void)
> if (hotkey_status_set(true) < 0 ||
> hotkey_mask_set(hotkey_acpi_mask) < 0)
> pr_err("error while attempting to reset the event firmware interface\n");
> + hotkey_poll_setup(false);
> }
>
> tpacpi_send_radiosw_update();
> @@ -4033,7 +4012,6 @@ static void hotkey_resume(void)
> keyboard_attached_on_screen_notify_change();
> hotkey_wakeup_reason_notify_change();
> hotkey_wakeup_hotunplug_complete_notify_change();
> - hotkey_poll_setup_safe(false);
>
> /* restore previous mode of adaptive keyboard of X1 Carbon */
> if (tp_features.has_adaptive_kbd) {
>
> --
> 2.56.1.839.g22a8290db9-goog
I think this is all good.
Just to check - how much testing have you done? I'll see if I can put the series through a few platforms just in case (but I can't see any issues with the code)
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock
2026-11-25 23:11 ` [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock Dmitry Torokhov
@ 2026-11-27 3:35 ` Mark Pearson
0 siblings, 0 replies; 17+ messages in thread
From: Mark Pearson @ 2026-11-27 3:35 UTC (permalink / raw)
To: Dmitry Torokhov, Henrique de Moraes Holschuh, Derek J . Clark,
Rong Zhang, Hans de Goede, Ilpo Järvinen
Cc: platform-driver-x86, ibm-acpi-devel, linux-kernel
On Wed, Nov 25, 2026, at 6:11 PM, Dmitry Torokhov wrote:
> hotkey_thread_data_mutex only protects a few in-memory integer reads
> and updates across hotkey_kthread(), tpacpi_hotkey_driver_mask_set(),
> and hotkey_source_mask_store(), with no sleeping calls inside any of
> its critical sections.
>
> Convert it to a statically initialized spinlock_t
> (hotkey_thread_data_lock), which also allows dropping the conditional
> mutex_init() call from hotkey_init().
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 58500b72d9d2..0ebaea0ab96b 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -67,6 +67,7 @@
> #include <linux/sched/signal.h>
> #include <linux/seq_file.h>
> #include <linux/slab.h>
> +#include <linux/spinlock.h>
> #include <linux/string.h>
> #include <linux/string_choices.h>
> #include <linux/string_helpers.h>
> @@ -1814,19 +1815,19 @@ struct tp_nvram_state {
> static struct task_struct *tpacpi_hotkey_task;
>
> /*
> - * Acquire mutex to write poller control variables as an
> + * Acquire spinlock to write poller control variables as an
> * atomic block.
> *
> * Increment hotkey_config_change when changing them if you
> * want the kthread to forget old state.
> */
> -static struct mutex hotkey_thread_data_mutex;
> +static DEFINE_SPINLOCK(hotkey_thread_data_lock);
> static unsigned int hotkey_config_change;
>
> /*
> * hotkey poller control variables
> *
> - * Must be atomic or readers will also need to acquire mutex.
> + * Must be atomic or readers will also need to acquire spinlock.
> */
> static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
> static unsigned int hotkey_poll_freq = 10; /* Hz */
> @@ -2143,7 +2144,7 @@ static int tpacpi_hotkey_driver_mask_set(const u32 mask)
> guard(mutex)(&hotkey_mutex);
>
> #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
> - scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + scoped_guard(spinlock, &hotkey_thread_data_lock) {
> hotkey_driver_mask = mask;
> hotkey_source_mask |= (mask & ~hotkey_all_mask);
> hotkey_config_change++;
> @@ -2446,7 +2447,7 @@ static int hotkey_kthread(void *data)
> t = 0;
>
> /* Initial state for compares */
> - scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + scoped_guard(spinlock, &hotkey_thread_data_lock) {
> change_detector = hotkey_config_change;
> poll_mask = hotkey_source_mask;
> event_mask = hotkey_source_mask &
> @@ -2469,7 +2470,7 @@ static int hotkey_kthread(void *data)
> if (t > 0 && !was_frozen)
> continue;
>
> - scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + scoped_guard(spinlock, &hotkey_thread_data_lock) {
> if (was_frozen ||
> hotkey_config_change != change_detector) {
> /* forget old state on thaw or config change */
> @@ -2726,7 +2727,7 @@ static ssize_t hotkey_source_mask_store(struct
> device *dev,
> if (rc)
> return rc;
>
> - scoped_guard(mutex, &hotkey_thread_data_mutex) {
> + scoped_guard(spinlock, &hotkey_thread_data_lock) {
> hotkey_source_mask = t;
> hotkey_config_change++;
> }
> @@ -3329,10 +3330,6 @@ static int __init hotkey_init(struct
> ibm_init_struct *iibm)
> TPACPI_ACPIHANDLE_INIT(hkey);
> mutex_init(&hotkey_mutex);
>
> -#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
> - mutex_init(&hotkey_thread_data_mutex);
> -#endif
> -
> /* hotkey not supported on 570 */
> tp_features.hotkey = hkey_handle != NULL;
>
>
> --
> 2.56.1.839.g22a8290db9-goog
I think this is all fine and a good change. Hopefully some more experienced eyes confirm there aren't any issues that I'm not thinking of.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
mark
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-11-27 3:35 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
2026-11-27 2:43 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init() Dmitry Torokhov
2026-11-27 2:46 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup Dmitry Torokhov
2026-11-27 3:28 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set() Dmitry Torokhov
2026-11-27 2:57 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking Dmitry Torokhov
2026-11-27 3:01 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock Dmitry Torokhov
2026-11-27 3:35 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag Dmitry Torokhov
2026-11-27 3:02 ` Mark Pearson
2026-11-25 23:11 ` [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment Dmitry Torokhov
2026-11-27 3:05 ` Mark Pearson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®