thermal: core: battery data corrupted after resume on ThinkPad P1 Gen2 since d33e89d12295
Subsystems (3)
On my ThinkPad P1 Gen2 with Fedora 44 I've noticed that the battery percentage started showing garbage values, mainly showing less, while the battery was fully charged.
I enlisted the help of Claude to help me debug this so I am providing the results here. All the testing was done on my laptop and no vanilla kernel was installed. Started with Fedora's build of 7.1.6 and currently I'm on 7.2.8 with the same results.
Since v7.1, _BIX and _BST data read after resume from S3 on my Lenovo ThinkPad P1 Gen2 (latest BIOS 1.57) is often garbage, energy_full 327.97 Wh (design 78 Wh), voltage_min_design 32.8 V, serial changes, or energy_now ~328 Wh giving 424%, reported percentage wrong until the next re-read. Same symptom as https://bugzilla.kernel.org/show_bug.cgi?id=218881, fixed in 494c7d055081 ("thermal: core: Change PM notifier priority to the minimum").
#regzbot introduced: d33e89d12295
#regzbot link: https://bugzilla.kernel.org/show_bug.cgi?id=218881
Out of the suspend/resume cycles I logged on this machine, the battery data came back corrupted in 0 of 39 on 7.0.11-7.0.14, 14 of 22 on 7.1.6-7.1.13 and 5 of 12 on 7.2.5. 7.2.8 and mainline still carry the same code.
d33e89d12295 dropped the INT_MIN-priority PM notifier and starts thermal zone resume from dpm_complete(), so INT3403 _TMP now runs concurrently with the ACPI battery driver's _BIX refresh in battery_notify().
Claude provided this explanation for the "firmware confusion" left unexplained in 494c7d055081:
the DSDT method \GTST, called by every INT3403 _TMP, writes the EC page selector (HIID = 0x60) without taking the BATM mutex that the battery methods hold while paging through the same EC window. EC register trace (ec.c dyndbg) at resume:
WR 81=02 <- GBIX (_BIX) selects battery page 2 WR 81=60 <- GTST from a concurrent _TMP RD a2->3a a3->80 <- _BIX reads "design voltage" = 0x803A
Test: 3 suspend/resume cycles (rtcwake + systemctl suspend), checking /sys/class/power_supply/BAT0/{energy_full,voltage_min_design,serial_number} after each. int3403_thermal loaded: 3/3 corrupted. Unloaded: 3/3 correct.
I did not bisect though, the analysis of the responsible commit was performed statically, happy to test patches, and can provide the DSDT/SSDT dump and full EC trace.
This issue seems also similar to https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2070441
Regards,
Charalampos Stratakis
PATCH 1/1 ACPI: battery: Re-read battery information in the complete callback
Since commit d33e89d12295 ("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed from dpm_complete(), before the PM_POST_SUSPEND notifier that re-reads _BIX and _BST. On ThinkPad P1 Gen2 and P53, INT3403 _TMP calls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accesses so the two methods interleave and _BIX often returns temperature page data after resume.
Evaluate _BIX and _BST in the complete callback, which runs before dpm_complete() resumes thermal zones and leave only the sysfs re-registration to the notifier.
---
Ran into this (report) while reading the EC firmware of my T490. The P1 Gen2 EC has the same single page selector.
Tested on 7.3-rc7 with an SSDT that makes a thermal zone keep calling a copy of the P1 Gen2 \GTST after resume. _BIX was broken after 5 of 5 resumes without the patch and 0 of 5 with it.
Doing it in the resume callback also works but _BIX takes about 75 ms there right after resume against about 35 ms here (and by the complete callback all operation region providers have resumed too).
drivers/acpi/battery.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 20 deletions(-)
drivers/acpi/battery.c +42 -20
@@ -107,6 +107,7 @@ struct acpi_battery {struct notifier_block pm_nb;struct list_head list;unsigned long flags; +bool resume_reregister;struct mutex property_lock;/* Protects properties below. */ unsigned long update_time;
@@ -1209,29 +1210,15 @@ static int battery_notify(struct notifier_block *nb,if (mode ==PM_POST_SUSPEND || mode ==PM_POST_HIBERNATION ) {guard (mutex)(&battery->update_lock); -if (!acpi_battery_present (battery)) +if (!battery->resume_reregister)return 0 ; -if (battery->bat) { -acpi_battery_refresh (battery); - }else { -int result; - - scoped_guard(mutex, &battery->property_lock) { - result =acpi_battery_get_info (battery); -if (result) -return result; - } + battery->resume_reregister = false; - result =sysfs_add_battery (battery); -if (result) -return result; - } +if (battery->bat) +sysfs_remove_battery (battery); - scoped_guard(mutex, &battery->property_lock) { -acpi_battery_init_alarm (battery); -acpi_battery_get_state (battery); - } +return sysfs_add_battery (battery); }return 0 ;
@@ -1450,7 +1437,42 @@ static int acpi_battery_resume(struct device *dev)return 0 ; } -static DEFINE_SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume); +static void acpi_battery_complete (struct device *dev) +{ +struct acpi_battery *battery =dev_get_drvdata (dev); + +if (!battery) +return ; + +guard (mutex)(&battery->update_lock); + +if (!acpi_battery_present (battery)) +return ; + +/* +* Evaluate _BIX and _BST here before thermal zones are resumed, as +* some firmware shares the EC window with _TMP without locking. +*/ +guard (mutex)(&battery->property_lock); + +if (battery->bat) { +int power_unit = battery->power_unit; + +acpi_battery_get_info (battery); +if (power_unit != battery->power_unit) + battery->resume_reregister = true; + }else if (!acpi_battery_get_info (battery)) { + battery->resume_reregister = true; + } + +acpi_battery_init_alarm (battery); +acpi_battery_get_state (battery); +} + +static const struct dev_pm_ops acpi_battery_pm = { +SYSTEM_SLEEP_PM_OPS (NULL , acpi_battery_resume) + .complete =pm_sleep_ptr (acpi_battery_complete), +};static struct platform_driver acpi_battery_driver = { .probe = acpi_battery_probe,
Signature · 1 line
2.55.0
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Hi Charis, could you test this on the P1 Gen2?
(Resending with the lists in Cc, the first one only went to you.)
Charis Stratakis
Tested-byRe: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 2 lines · Ali Ahmet Memiş
Hi Charis, could you test this on the P1 Gen2?
I've rebuilt the Fedora 7.2.10 kernel with the patch for F44 to test it, the hunks are identical to 7.3-rc7. As before, no vanilla kernel was installed, all testing on my laptop, with Claude's help.
The test is cycles of "rtcwake -m no -s 25; systemctl suspend", checking energy_full, voltage_min_design and serial_number after each resume, with int3403_thermal loaded throughout. I ran it as ABA so that nothing else could drift:
7.2.8-200.fc44, stock 10 of 10 resumes corrupted
7.2.10 + this patch 0 of 20 resumes corrupted
7.2.8-200.fc44, stock again 8 of 10 resumes corrupted
18 of 20 on stock against 0 of 20 patched.
Here is what Claude reports, hope it makes sense as I don't have much knowledge of the kernel's workings:
Both flavours from my report show up: energy_full = 328.1x Wh, which makes capacity read ~20%, together with voltage_min_design = 32.81x V, and one cycle with energy_now = 328960000, i.e. 424%, with energy_full intact. One bad cycle is worth singling out because it supports the \GTST explanation, it returned voltage_min_design correctly as 15360000 while energy_full was 328160000. So the page selector flips in the middle of _BIX and which fields come back wrong depends on where in the read the _TMP burst lands, rather than the whole structure being read from page 0x60.
I also traced the EC (ec.c dyndbg) on the patched kernel for one resume, which shows the ordering the patch relies on:
.223100 WR 81=01, 00, 02, 06, 04, 05 with the 0xA0-0xAF reads, i.e.
_BIX and _BST from the complete callback
.236664 last battery page selection .239670 WR 81=60, first \GTST .270916 last of 13 consecutive \GTST bursts
Nothing from the battery is interleaved among those bursts, and the next battery access is 5.7s later from userspace polling. Worth noting that "Restarting tasks: Done" (.240802) and "PM: suspend exit" (.251365) both fall inside the \GTST burst, so PM_POST_SUSPEND, where the refresh used to happen, is right in the middle of it.
The firmware bug itself is of course untouched, so a _BST that races a _TMP at runtime can still return garbage. Those were the transient 424% readings and they self-heal on the next read because of the 1s cache. Would a plausibility check in acpi_battery_get_state() be welcome for that, re- evaluating _BST once and warning FW_BUG when capacity_now exceeds design_capacity by a wide margin? It would sit next to the existing workarounds there. I realise it only catches the obviously absurd values and not wrong ones that look plausible, so I am not sure it is worth it.
Regards,
Charalampos Stratakis
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 3 lines · Charis Stratakis
18 of 20 on stock against 0 of 20 patched.
Thanks for testing.
[...]
Quoted 3 lines
Would a plausibility check in
acpi_battery_get_state()be welcome for that, re- evaluating_BSTonce and warningFW_BUGwhencapacity_nowexceedsdesign_capacityby a wide margin?
I'd rather not. It only hides the absurd values and the plausible wrong ones still get through. If the runtime race turns out to matter, taking BATM around the INT3403 _TMP on these two models would fix it where it happens.
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
In reply to Ali Ahmet MemişHi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accesses
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here. Recently I've learned / heard from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
And even go futher and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
Another example of multi-threaded ACPI calls causing problems is:
https://bugzilla.kernel.org/show_bug.cgi?id=221065
Regards,
Hans
Quoted 118 lines
so the
two methods interleave and_BIXoften returns temperature page data after resume.Quoted 1 line
Evaluate
_BIXand_BSTin the complete callback, which runs before
dpm_complete()resumes thermal zones and leave only the sysfs re-registration to the notifier.Fixes d33e89d12295 ("thermal: core: Suspend thermal zones later and resume them earlier")Reported-by Charis Stratakis <[email protected]>Closes https://lore.kernel.org/all/37N_jFulf7n-Z55NfKfE71C_wVPxYvZ0xD_iRUg2fXu7TypDiF5PStQ6siSfVBih6fThg5WoPes8U5ZQpfVm_teMFcUGXFxz2DdMbfSWuws=@proton.me/ open hereSigned-off-by Ali Ahmet Memiş <[email protected]>---
Ran into this (report) while reading the EC firmware of my T490. The P1 Gen2 EC has the same single page selector.Tested on 7.3-rc7 with an SSDT that makes a thermal zone keep calling a copy of the P1 Gen2 \GTST after resume.
_BIXwas broken after 5 of 5 resumes without the patch and 0 of 5 with it.Doing it in the resume callback also works but
_BIXtakes about 75 ms there right after resume against about 35 ms here (and by the complete callback all operation region providers have resumed too).drivers/acpi/battery.c | 62 ++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 20 deletions(-)drivers/acpi/battery.c +42
-20@@ -107,6 +107,7 @@ struct acpi_battery {struct notifier_block pm_nb;struct list_head list;unsigned long flags; +bool resume_reregister;struct mutex property_lock;/* Protects properties below. */ unsigned long update_time;@@ -1209,29 +1210,15 @@ static int battery_notify(struct notifier_block *nb,if (mode ==PM_POST_SUSPEND || mode ==PM_POST_HIBERNATION ) {guard (mutex)(&battery->update_lock); -if (!acpi_battery_present (battery)) +if (!battery->resume_reregister)return 0 ; -if (battery->bat) { -acpi_battery_refresh (battery); - }else { -int result; - - scoped_guard(mutex, &battery->property_lock) { - result =acpi_battery_get_info (battery); -if (result) -return result; - } + battery->resume_reregister = false; - result =sysfs_add_battery (battery); -if (result) -return result; - } +if (battery->bat) +sysfs_remove_battery (battery); - scoped_guard(mutex, &battery->property_lock) { -acpi_battery_init_alarm (battery); -acpi_battery_get_state (battery); - } +return sysfs_add_battery (battery); }return 0 ;@@ -1450,7 +1437,42 @@ static int acpi_battery_resume(struct device *dev)return 0 ; } -static DEFINE_SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume); +static void acpi_battery_complete (struct device *dev) +{ +struct acpi_battery *battery =dev_get_drvdata (dev); + +if (!battery) +return ; + +guard (mutex)(&battery->update_lock); + +if (!acpi_battery_present (battery)) +return ; + +/* +* Evaluate _BIX and _BST here before thermal zones are resumed, as +* some firmware shares the EC window with _TMP without locking. +*/ +guard (mutex)(&battery->property_lock); + +if (battery->bat) { +int power_unit = battery->power_unit; + +acpi_battery_get_info (battery); +if (power_unit != battery->power_unit) + battery->resume_reregister = true; + }else if (!acpi_battery_get_info (battery)) { + battery->resume_reregister = true; + } + +acpi_battery_init_alarm (battery); +acpi_battery_get_state (battery); +} + +static const struct dev_pm_ops acpi_battery_pm = { +SYSTEM_SLEEP_PM_OPS (NULL , acpi_battery_resume) + .complete =pm_sleep_ptr (acpi_battery_complete), +};static struct platform_driver acpi_battery_driver = { .probe = acpi_battery_probe,
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 11 lines · On Tue, Oct 13, 2026 at 11:33 AM <[email protected]> wrote:
Hi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accesses
Quoted 2 lines
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here.
Yes, it most likely is.
What actually happens is that ACPICA drops the interpreter lock and the namespace lock in several cases listed in the acpi_ex_exit_interpreter() documentation comment, the majority of which involve having to wait.
The bottom line though is that the interpreter and namespace locks cannot be expected to be held throughout AML evaluation because it is not known in advance if any of the cases in question will appear.
Quoted 6 lines
Recently I've learned / heard
from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.
This is also my conclusion, at least to some extent.
The problem with it though is that in some cases parallel evaluation of AML is actually useful. For example, say two PCI devices are powered up at the same time and AML waits for each of them. The async suspend/resume aligns those waits to take place simultaneously instead of serializing them which allows some time to be saved.
Quoted 2 lines
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
The problem here is that it is hard to say in advance whether or not _BIX or _BST will access the EC and whether or not that will clash with _TMP evaluation for a seemingly unrelated thermal zone.
Quoted 4 lines
And even go further and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
I would be inclined to do so except for device power management methods, that is _ON, _OFF, and _PSx, that are not the problematic ones, at least as far as I know.
Quoted 3 lines
Another example of multi-threaded ACPI calls causing problems is:
Right.
So I guess the idea would be to add locking to acpi_evaluate_object()?
An alternative might be to introduce an "exclusive" variant of acpi_evaluate_object() with built-in locking and use it in the cases that are known-problematic.
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 3 lines · Rafael J. Wysocki (Intel)
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.
An exclusive variant would have to be used on both sides here, for _BIX/_BST and for the INT3403 _TMP, since it is \GTST in _TMP that switches the page. I can do that and test it the same way.
Should this patch still go in for the regression meanwhile?
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 9 lines · Ali Ahmet Memiş
Quoted 3 lines · Rafael J. Wysocki (Intel)
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.An exclusive variant would have to be used on both sides here, for _BIX/_BST and for the INT3403
_TMP, since it is \GTST in_TMPthat switches the page. I can do that and test it the same way.
Sounds good.
Quoted 1 line
Should this patch still go in for the regression meanwhile?
No, it only addresses system resume while the same race may occur if user space reads the thermal zone temperature during a battery notification, for example. All of that needs to be addressed.
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
In reply to Rafael J. Wysocki (Intel)Hi Rafael,
Quoted 48 lines · Rafael J. Wysocki (Intel)
Quoted 11 lines · On Tue, Oct 13, 2026 at 11:33 AM <[email protected]> wrote:
Hi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accessesQuoted 2 lines
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here.
Yes, it most likely is.
What actually happens is that ACPICA drops the interpreter lock and the namespace lock in several cases listed in the
acpi_ex_exit_interpreter()documentation comment, the majority of which involve having to wait.The bottom line though is that the interpreter and namespace locks cannot be expected to be held throughout AML evaluation because it is not known in advance if any of the cases in question will appear.
Quoted 6 lines
Recently I've learned / heard
from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.This is also my conclusion, at least to some extent.
The problem with it though is that in some cases parallel evaluation of AML is actually useful. For example, say two PCI devices are powered up at the same time and AML waits for each of them. The async suspend/resume aligns those waits to take place simultaneously instead of serializing them which allows some time to be saved.
Quoted 2 lines
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
The problem here is that it is hard to say in advance whether or not
_BIXor_BSTwill access the EC and whether or not that will clash with_TMPevaluation for a seemingly unrelated thermal zone.
Quoted 8 lines
Quoted 4 lines
And even go further and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
I would be inclined to do so except for device power management methods, that is
_ON,_OFF, and_PSx, that are not the problematic ones, at least as far as I know.
That sounds like a reasonable compromise which should fix both this case as well as help with bko221065 .
Quoted 7 lines
Quoted 3 lines
Another example of multi-threaded ACPI calls causing problems is:
Right.
So I guess the idea would be to add locking to
acpi_evaluate_object()?
Yes that seems like a nice single point of entry to do this where all the various helpers eventually end up.
Quoted 3 lines
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.
So here we have _TMP and _BIX / _BST and in bko221065 we have a bunch of again batteyr methods + UCSI racing. I'm afraid if we add something like acpi_evaluate_object_exclusive() we'll end up eventually using that almost everywhere.
Maybe do things the other way around and serializing all the calls by default and adding an acpi_evaluate_object_unlocked() to be used in cases where we want the speedup of multi-threading like the _ON, _OFF and _PSx you mentioned above ?
Regards,
Hans
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Hi Hans,
Quoted 66 lines · On Tue, Oct 13, 2026 at 3:36 PM <[email protected]> wrote:
Hi Rafael,
Quoted 48 lines · Rafael J. Wysocki (Intel)
Quoted 11 lines · On Tue, Oct 13, 2026 at 11:33 AM <[email protected]> wrote:
Hi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accessesQuoted 2 lines
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here.
Yes, it most likely is.
What actually happens is that ACPICA drops the interpreter lock and the namespace lock in several cases listed in the
acpi_ex_exit_interpreter()documentation comment, the majority of which involve having to wait.The bottom line though is that the interpreter and namespace locks cannot be expected to be held throughout AML evaluation because it is not known in advance if any of the cases in question will appear.
Quoted 6 lines
Recently I've learned / heard
from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.This is also my conclusion, at least to some extent.
The problem with it though is that in some cases parallel evaluation of AML is actually useful. For example, say two PCI devices are powered up at the same time and AML waits for each of them. The async suspend/resume aligns those waits to take place simultaneously instead of serializing them which allows some time to be saved.
Quoted 2 lines
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
The problem here is that it is hard to say in advance whether or not
_BIXor_BSTwill access the EC and whether or not that will clash with_TMPevaluation for a seemingly unrelated thermal zone.Quoted 8 lines
Quoted 4 lines
And even go further and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
I would be inclined to do so except for device power management methods, that is
_ON,_OFF, and_PSx, that are not the problematic ones, at least as far as I know.That sounds like a reasonable compromise which should fix both this case as well as help with bko221065 .
Quoted 2 lines
Quoted 2 lines
Another example of multi-threaded ACPI calls causing problems is:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Right.
So I guess the idea would be to add locking to
acpi_evaluate_object()?Yes that seems like a nice single point of entry to do this where all the various helpers eventually end up.
That, of course, would require updating ACPICA code and I'm not sure if doing it upstream is useful. For example, if some hosts already use locking around acpi_evaluate_object(), this modification won't help them and it will certainly be a change in behavior.
This means that we'll likely end up with a Linux-specific divergence from the upstream which can be lived with, but it won't be nice.
Quoted 8 lines
Quoted 3 lines
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.So here we have
_TMPand_BIX/_BSTand in bko221065 we have a bunch of again batteyr methods + UCSI racing. I'm afraid if we add something likeacpi_evaluate_object_exclusive()we'll end up eventually using that almost everywhere.
While I think that your concern is valid, this can be done without touching the ACPICA code at all.
Also, we don't actually know how many "bad" cases there are and so far we have identified a few. If they are not too widespread, changing behavior everywhere for everyone may not be adequate.
Quoted 4 lines
Maybe do things the other way around and serializing all the calls by default and adding an
acpi_evaluate_object_unlocked()to be used in cases where we want the speedup of multi-threading like the_ON,_OFFand_PSxyou mentioned above ?
Yes, depending on which way is more practical, that can be done.
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 2 lines · Rafael J. Wysocki (Intel)
Also, we don't actually know how many "bad" cases there are and so far we have identified a few.
I wrote a script that extracts the ACPI tables from all 208 BIOS packages in Lenovo's ThinkPad catalog (370 models) and flags methods that switch the EC page selector (HIID) without BATM while other methods use it under BATM, and checked the flagged ones by hand. Two BIOSes do it both with \GTST from _TMP: P1 Gen2 / X1 Extreme Gen2 and P53 / P73. Apart from those, NVPS on T450 / T450s does it from the NVIDIA GPS _DSM, which only the out-of-tree NVIDIA driver evaluates. This doesn't cover races like the UCSI one in bko221065.
FWIW, the exclusive variant is done. With it the emulated \GTST breaks neither _BIX after resume nor _BST at run time (0 of 5 and 0 of 1074), and with only the _TMP side converted both still break (5 of 5 and 421 of 424).
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Hi,
Quoted 13 lines · Ali Ahmet Memiş
Quoted 2 lines · Rafael J. Wysocki (Intel)
Also, we don't actually know how many "bad" cases there are and so far we have identified a few.
I wrote a script that extracts the ACPI tables from all 208 BIOS packages in Lenovo's ThinkPad catalog (370 models) and flags methods that switch the EC page selector (HIID) without BATM while other methods use it under BATM, and checked the flagged ones by hand. Two BIOSes do it both with \GTST from
_TMP: P1 Gen2 / X1 Extreme Gen2 and P53 / P73. Apart from those, NVPS on T450 / T450s does it from the NVIDIA GPS_DSM, which only the out-of-tree NVIDIA driver evaluates. This doesn't cover races like the UCSI one in bko221065.
Quoted 4 lines
FWIW, the exclusive variant is done. With it the emulated \GTST breaks neither
_BIXafter resume nor_BSTat run time (0 of 5 and 0 of 1074), and with only the_TMPside converted both still break (5 of 5 and 421 of 424).
As I just agreed in my reply to Rafael, it looks like we want to go with the exclusive variant for now.
Can you post a patch series for the code you've for this now ?
Note I guess you're using LLM to help you with this, that is fine, but can you please manually shorten the commit messages of the patches a bit if they were written by LLM? OR instruct it to write "short and concise" commit messages?
LLM's tend to write overly verbose commit messages. Note a good commit message is important, but lets try to keep them compact.
And the same for the cover-letter.
Regards,
Hans
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Quoted 1 line · On Wed, Oct 14, 2026 at 12:01:55PM +0200, [email protected] wrote:
Can you post a patch series for the code you've for this now ?
Posted: https://lore.kernel.org/all/[email protected]/
Quoted 3 lines
Note I guess you're using LLM to help you with this, that is fine, but can you please manually shorten the commit messages of the patches a bit if they were written by LLM?
No LLM used here, I just thought the race needed some explanation. I kept the series short.
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Hi,
Quoted 10 lines · Ali Ahmet Memiş
Quoted 1 line · On Wed, Oct 14, 2026 at 12:01:55PM +0200, [email protected] wrote:
Can you post a patch series for the code you've for this now ?
Posted: https://lore.kernel.org/all/[email protected]/
Quoted 3 lines
Note I guess you're using LLM to help you with this, that is fine, but can you please manually shorten the commit messages of the patches a bit if they were written by LLM?
No LLM used here, I just thought the race needed some explanation.
That is fair, sometimes it can be hard to find the balance between including enough information and keeping things short and sweet.
Quoted 1 line
I kept the series short.
Much appreciated, thx.
Regards,
Hans
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
In reply to Rafael J. Wysocki (Intel)Hi Rafael,
Quoted 78 lines · Rafael J. Wysocki (Intel)
Hi Hans,
Quoted 66 lines · On Tue, Oct 13, 2026 at 3:36 PM <[email protected]> wrote:
Hi Rafael,
Quoted 48 lines · Rafael J. Wysocki (Intel)
Quoted 11 lines · On Tue, Oct 13, 2026 at 11:33 AM <[email protected]> wrote:
Hi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accessesQuoted 2 lines
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here.
Yes, it most likely is.
What actually happens is that ACPICA drops the interpreter lock and the namespace lock in several cases listed in the
acpi_ex_exit_interpreter()documentation comment, the majority of which involve having to wait.The bottom line though is that the interpreter and namespace locks cannot be expected to be held throughout AML evaluation because it is not known in advance if any of the cases in question will appear.
Quoted 6 lines
Recently I've learned / heard
from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.This is also my conclusion, at least to some extent.
The problem with it though is that in some cases parallel evaluation of AML is actually useful. For example, say two PCI devices are powered up at the same time and AML waits for each of them. The async suspend/resume aligns those waits to take place simultaneously instead of serializing them which allows some time to be saved.
Quoted 2 lines
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
The problem here is that it is hard to say in advance whether or not
_BIXor_BSTwill access the EC and whether or not that will clash with_TMPevaluation for a seemingly unrelated thermal zone.Quoted 8 lines
Quoted 4 lines
And even go further and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
I would be inclined to do so except for device power management methods, that is
_ON,_OFF, and_PSx, that are not the problematic ones, at least as far as I know.That sounds like a reasonable compromise which should fix both this case as well as help with bko221065 .
Quoted 2 lines
Quoted 2 lines
Another example of multi-threaded ACPI calls causing problems is:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Right.
So I guess the idea would be to add locking to
acpi_evaluate_object()?Yes that seems like a nice single point of entry to do this where all the various helpers eventually end up.
Quoted 7 lines
That, of course, would require updating ACPICA code and I'm not sure if doing it upstream is useful. For example, if some hosts already use locking around
acpi_evaluate_object(), this modification won't help them and it will certainly be a change in behavior.This means that we'll likely end up with a Linux-specific divergence from the upstream which can be lived with, but it won't be nice.
Ah, I see.
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.So here we have
_TMPand_BIX/_BSTand in bko221065 we have a bunch of again batteyr methods + UCSI racing. I'm afraid if we add something likeacpi_evaluate_object_exclusive()we'll end up eventually using that almost everywhere.While I think that your concern is valid, this can be done without touching the ACPICA code at all.
Not needing to touch ACPICA is a valid concern. So I agree lets go with a wrapper for paths which we know need to be serialized for now.
And then add that around the battery methods + _TMP + UCSI methods for starters I guess ?
###
Should we also stop releasing the interpreter lock in the EC code?
All these things (battery, _TMP, UCSI) seem to have in common that they might talk to the EC in some cases?
Where as e.g. your powering-up of PCI slots example is unlikely to talk to the EC ?
Regards,
Hans
Rafael J. Wysocki (Intel)
maintainerRe: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Hi Hans,
Quoted 101 lines · On Wed, Oct 14, 2026 at 11:58 AM <[email protected]> wrote:
Hi Rafael,
Quoted 78 lines · Rafael J. Wysocki (Intel)
Hi Hans,
Quoted 66 lines · On Tue, Oct 13, 2026 at 3:36 PM <[email protected]> wrote:
Hi Rafael,
Quoted 48 lines · Rafael J. Wysocki (Intel)
Quoted 11 lines · On Tue, Oct 13, 2026 at 11:33 AM <[email protected]> wrote:
Hi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accessesQuoted 2 lines
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here.
Yes, it most likely is.
What actually happens is that ACPICA drops the interpreter lock and the namespace lock in several cases listed in the
acpi_ex_exit_interpreter()documentation comment, the majority of which involve having to wait.The bottom line though is that the interpreter and namespace locks cannot be expected to be held throughout AML evaluation because it is not known in advance if any of the cases in question will appear.
Quoted 6 lines
Recently I've learned / heard
from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.This is also my conclusion, at least to some extent.
The problem with it though is that in some cases parallel evaluation of AML is actually useful. For example, say two PCI devices are powered up at the same time and AML waits for each of them. The async suspend/resume aligns those waits to take place simultaneously instead of serializing them which allows some time to be saved.
Quoted 2 lines
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
The problem here is that it is hard to say in advance whether or not
_BIXor_BSTwill access the EC and whether or not that will clash with_TMPevaluation for a seemingly unrelated thermal zone.Quoted 8 lines
Quoted 4 lines
And even go further and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
I would be inclined to do so except for device power management methods, that is
_ON,_OFF, and_PSx, that are not the problematic ones, at least as far as I know.That sounds like a reasonable compromise which should fix both this case as well as help with bko221065 .
Quoted 2 lines
Quoted 2 lines
Another example of multi-threaded ACPI calls causing problems is:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Right.
So I guess the idea would be to add locking to
acpi_evaluate_object()?Yes that seems like a nice single point of entry to do this where all the various helpers eventually end up.
Quoted 7 lines
That, of course, would require updating ACPICA code and I'm not sure if doing it upstream is useful. For example, if some hosts already use locking around
acpi_evaluate_object(), this modification won't help them and it will certainly be a change in behavior.This means that we'll likely end up with a Linux-specific divergence from the upstream which can be lived with, but it won't be nice.
Ah, I see.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.So here we have
_TMPand_BIX/_BSTand in bko221065 we have a bunch of again batteyr methods + UCSI racing. I'm afraid if we add something likeacpi_evaluate_object_exclusive()we'll end up eventually using that almost everywhere.
Quoted 8 lines
Quoted 2 lines
While I think that your concern is valid, this can be done without touching the ACPICA code at all.
Not needing to touch ACPICA is a valid concern. So I agree lets go with a wrapper for paths which we know need to be serialized for now.
And then add that around the battery methods +
_TMP+ UCSI methods for starters I guess ?
Yes.
Quoted 3 lines
###
Should we also stop releasing the interpreter lock in the EC code?
Which EC code do you mean in particular?
Quoted 2 lines
All these things (battery,
_TMP, UCSI) seem to have in common that they might talk to the EC in some cases?
Yes, they are EC-based in many cases.
Quoted 2 lines
Where as e.g. your powering-up of PCI slots example is unlikely to talk to the EC ?
Yup.
Re: [PATCH] ACPI: battery: Re-read battery information in the complete callback
Hi,
Quoted 113 lines · Rafael J. Wysocki (Intel)
Hi Hans,
Quoted 101 lines · On Wed, Oct 14, 2026 at 11:58 AM <[email protected]> wrote:
Hi Rafael,
Quoted 78 lines · Rafael J. Wysocki (Intel)
Hi Hans,
Quoted 66 lines · On Tue, Oct 13, 2026 at 3:36 PM <[email protected]> wrote:
Hi Rafael,
Quoted 48 lines · Rafael J. Wysocki (Intel)
Quoted 11 lines · On Tue, Oct 13, 2026 at 11:33 AM <[email protected]> wrote:
Hi,
Quoted 6 lines · Ali Ahmet Memiş
Since commit
d33e89d12295("thermal: core: Suspend thermal zones later and resume them earlier"), thermal zones are resumed fromdpm_complete(), before thePM_POST_SUSPENDnotifier that re-reads_BIXand_BST. On ThinkPad P1 Gen2 and P53, INT3403_TMPcalls \GTST which switches the EC page selector (HIID) without taking the BATM mutex used by the battery methods. ACPICA releases the interpreter lock around EC accessesQuoted 2 lines
I'm wondering if this "ACPICA releases the interpreter lock around EC accesses" is not the real problem here.
Yes, it most likely is.
What actually happens is that ACPICA drops the interpreter lock and the namespace lock in several cases listed in the
acpi_ex_exit_interpreter()documentation comment, the majority of which involve having to wait.The bottom line though is that the interpreter and namespace locks cannot be expected to be held throughout AML evaluation because it is not known in advance if any of the cases in question will appear.
Quoted 6 lines
Recently I've learned / heard
from a trusted source that Windows ACPI subsystem is very much single threaded. So it is nice that ACPI has these mutexes and other stuff to support multi-threading but as long as Windows ACPI interpreter is not multi-threaded I think we may need to consider to copy Windows behavior.This is also my conclusion, at least to some extent.
The problem with it though is that in some cases parallel evaluation of AML is actually useful. For example, say two PCI devices are powered up at the same time and AML waits for each of them. The async suspend/resume aligns those waits to take place simultaneously instead of serializing them which allows some time to be saved.
Quoted 2 lines
So maybe the EC accesses should keep the interpreter lock locked during EC accesses.
The problem here is that it is hard to say in advance whether or not
_BIXor_BSTwill access the EC and whether or not that will clash with_TMPevaluation for a seemingly unrelated thermal zone.Quoted 8 lines
Quoted 4 lines
And even go further and maybe we need to introduce a big-acpi-lock, which I guess the interpreter lock more or less is? And just serialize all ACPI accesses since most ACPI tables clearly do not handle multi-threaded access to ACPI methods well ?
I would be inclined to do so except for device power management methods, that is
_ON,_OFF, and_PSx, that are not the problematic ones, at least as far as I know.That sounds like a reasonable compromise which should fix both this case as well as help with bko221065 .
Quoted 2 lines
Quoted 2 lines
Another example of multi-threaded ACPI calls causing problems is:
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Right.
So I guess the idea would be to add locking to
acpi_evaluate_object()?Yes that seems like a nice single point of entry to do this where all the various helpers eventually end up.
Quoted 7 lines
That, of course, would require updating ACPICA code and I'm not sure if doing it upstream is useful. For example, if some hosts already use locking around
acpi_evaluate_object(), this modification won't help them and it will certainly be a change in behavior.This means that we'll likely end up with a Linux-specific divergence from the upstream which can be lived with, but it won't be nice.
Ah, I see.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
An alternative might be to introduce an "exclusive" variant of
acpi_evaluate_object()with built-in locking and use it in the cases that are known-problematic.So here we have
_TMPand_BIX/_BSTand in bko221065 we have a bunch of again batteyr methods + UCSI racing. I'm afraid if we add something likeacpi_evaluate_object_exclusive()we'll end up eventually using that almost everywhere.Quoted 8 lines
Quoted 2 lines
While I think that your concern is valid, this can be done without touching the ACPICA code at all.
Not needing to touch ACPICA is a valid concern. So I agree lets go with a wrapper for paths which we know need to be serialized for now.
And then add that around the battery methods +
_TMP+ UCSI methods for starters I guess ?
Quoted 7 lines
Yes.
Quoted 3 lines
###
Should we also stop releasing the interpreter lock in the EC code?
Which EC code do you mean in particular?
I meant the event-handling code, but I forgot the unlock is actually in the ACPICA core, not in the Linux code.
Anyways I think this is nicely covered by Ali's latest series:
https://lore.kernel.org/all/[email protected]/
Regards,
Hans