platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work
@ 2022-07-08 13:14 Hans de Goede
  2022-07-08 13:14 ` [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again Hans de Goede
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Hans de Goede @ 2022-07-08 13:14 UTC (permalink / raw)
  To: Rafael J . Wysocki, Mika Westerberg, Dmitry Osipenko, Mark Gross,
	Andy Shevchenko, Ard Biesheuvel
  Cc: Hans de Goede, linux-acpi, linux-pm, platform-driver-x86, x86, linux-efi

Hi All,

I noticed that my Lenovo Yoga Tablet 2 1050L was hanging on power-off again
with 5.19, even though I had implemented a workaround for this in 5.17 .

I quickly realized that this was caused by the recent sys-off-handler work
and fixed this by switching the workaround over to register_sys_off_handler
with a priority of SYS_OFF_PRIO_FIRMWARE + 1, so that the workaround runs
before acpi_power_off() get a chance to run.

This made me realize that the efi_power_off handler which sometimes is
used in preference of acpi_power_off had the same problem, so the second
patch in this series fixes that.

I plan to include patch 1/2 in a fixes pull-req to Linus soon. Ard,
if I can get your Ack for 2/2 then I can include this in the pull-req
if you want; or you can send this to Linus yourself.

Regards,

Hans


Hans de Goede (2):
  platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050
    poweroff again
  efi: Fix efi_power_off() not being run before acpi_power_off() when
    necessary

 drivers/firmware/efi/reboot.c              | 21 +++++++++++----------
 drivers/platform/x86/x86-android-tablets.c | 17 +++++++++++++----
 2 files changed, 24 insertions(+), 14 deletions(-)

-- 
2.36.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again
  2022-07-08 13:14 [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Hans de Goede
@ 2022-07-08 13:14 ` Hans de Goede
  2022-07-08 13:36   ` Dmitry Osipenko
  2022-07-08 13:14 ` [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary Hans de Goede
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Hans de Goede @ 2022-07-08 13:14 UTC (permalink / raw)
  To: Rafael J . Wysocki, Mika Westerberg, Dmitry Osipenko, Mark Gross,
	Andy Shevchenko, Ard Biesheuvel
  Cc: Hans de Goede, linux-acpi, linux-pm, platform-driver-x86, x86, linux-efi

Commit 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
switched the ACPI sleep code from directly setting the old global
pm_power_off handler to using the new register_sys_off_handler()
mechanism with a priority of SYS_OFF_PRIO_FIRMWARE.

This is a problem in special cases where the old global pm_power_off
handler later gets overwritten, such as the Lenovo Tab2 poweroff bugfix
in x86-android-tablets. The old global pm_power_off handler gets run
with a priority of SYS_OFF_PRIO_DEFAULT which is lower then
SYS_OFF_PRIO_FIRMWARE, causing the troublesome ACPI poweroff (which
freezes the system) to run first.

Switch the registering of lenovo_yoga_tab2_830_1050_power_off over to
register_sys_off_handler() with a priority of SYS_OFF_PRIO_FIRMWARE + 1
so that it will run before acpi_power_off() to fix this.

Fixes: 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/x86-android-tablets.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
index f446be72e539..480375977435 100644
--- a/drivers/platform/x86/x86-android-tablets.c
+++ b/drivers/platform/x86/x86-android-tablets.c
@@ -27,8 +27,8 @@
 #include <linux/pinctrl/machine.h>
 #include <linux/platform_data/lp855x.h>
 #include <linux/platform_device.h>
-#include <linux/pm.h>
 #include <linux/power/bq24190_charger.h>
+#include <linux/reboot.h>
 #include <linux/rmi.h>
 #include <linux/serdev.h>
 #include <linux/spi/spi.h>
@@ -889,6 +889,7 @@ static const struct pinctrl_map lenovo_yoga_tab2_830_1050_codec_pinctrl_map =
 			  "INT33FC:02", "pmu_clk2_grp", "pmu_clk");
 
 static struct pinctrl *lenovo_yoga_tab2_830_1050_codec_pinctrl;
+static struct sys_off_handler *lenovo_yoga_tab2_830_1050_sys_off_handler;
 
 static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
 {
@@ -933,9 +934,11 @@ static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
  * followed by a normal 3 second press to recover. Avoid this by doing an EFI
  * poweroff instead.
  */
-static void lenovo_yoga_tab2_830_1050_power_off(void)
+static int lenovo_yoga_tab2_830_1050_power_off(struct sys_off_data *data)
 {
 	efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
+
+	return NOTIFY_DONE;
 }
 
 static int __init lenovo_yoga_tab2_830_1050_init(void)
@@ -950,13 +953,19 @@ static int __init lenovo_yoga_tab2_830_1050_init(void)
 	if (ret)
 		return ret;
 
-	pm_power_off = lenovo_yoga_tab2_830_1050_power_off;
+	/* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
+	lenovo_yoga_tab2_830_1050_sys_off_handler =
+		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
+					 lenovo_yoga_tab2_830_1050_power_off, NULL);
+	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
+		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
+
 	return 0;
 }
 
 static void lenovo_yoga_tab2_830_1050_exit(void)
 {
-	pm_power_off = NULL; /* Just turn poweroff into halt on module unload */
+	unregister_sys_off_handler(lenovo_yoga_tab2_830_1050_sys_off_handler);
 
 	if (lenovo_yoga_tab2_830_1050_codec_pinctrl) {
 		pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary
  2022-07-08 13:14 [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Hans de Goede
  2022-07-08 13:14 ` [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again Hans de Goede
@ 2022-07-08 13:14 ` Hans de Goede
  2022-07-08 16:37   ` Ard Biesheuvel
  2022-07-08 13:29 ` [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Dmitry Osipenko
  2022-07-10 15:27 ` Hans de Goede
  3 siblings, 1 reply; 8+ messages in thread
From: Hans de Goede @ 2022-07-08 13:14 UTC (permalink / raw)
  To: Rafael J . Wysocki, Mika Westerberg, Dmitry Osipenko, Mark Gross,
	Andy Shevchenko, Ard Biesheuvel
  Cc: Hans de Goede, linux-acpi, linux-pm, platform-driver-x86, x86, linux-efi

Commit 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
switched the ACPI sleep code from directly setting the old global
pm_power_off handler to using the new register_sys_off_handler()
mechanism with a priority of SYS_OFF_PRIO_FIRMWARE.

This is a problem when the old global pm_power_off handler would later
be overwritten, such as done by the late_initcall(efi_shutdown_init):

	if (efi_poweroff_required())
		pm_power_off = efi_power_off;

The old global pm_power_off handler gets run with a priority of
SYS_OFF_PRIO_DEFAULT which is lower then SYS_OFF_PRIO_FIRMWARE, causing
acpi_power_off() to run first, changing the behavior from before
the ACPI sleep code switched to the new register_sys_off_handler().

Switch the registering of efi_power_off over to register_sys_off_handler()
with a priority of SYS_OFF_PRIO_FIRMWARE + 1 so that it will run before
acpi_power_off() as before.

Note since the new sys-off-handler code will try all handlers in
priority order, there is no more need for the EFI code to store and
call the original pm_power_off handler.

Fixes: 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/firmware/efi/reboot.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/efi/reboot.c b/drivers/firmware/efi/reboot.c
index 73089a24f04b..ceae84c19d22 100644
--- a/drivers/firmware/efi/reboot.c
+++ b/drivers/firmware/efi/reboot.c
@@ -6,7 +6,7 @@
 #include <linux/efi.h>
 #include <linux/reboot.h>
 
-static void (*orig_pm_power_off)(void);
+static struct sys_off_handler *efi_sys_off_handler;
 
 int efi_reboot_quirk_mode = -1;
 
@@ -51,15 +51,11 @@ bool __weak efi_poweroff_required(void)
 	return false;
 }
 
-static void efi_power_off(void)
+static int efi_power_off(struct sys_off_data *data)
 {
 	efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
-	/*
-	 * The above call should not return, if it does fall back to
-	 * the original power off method (typically ACPI poweroff).
-	 */
-	if (orig_pm_power_off)
-		orig_pm_power_off();
+
+	return NOTIFY_DONE;
 }
 
 static int __init efi_shutdown_init(void)
@@ -68,8 +64,13 @@ static int __init efi_shutdown_init(void)
 		return -ENODEV;
 
 	if (efi_poweroff_required()) {
-		orig_pm_power_off = pm_power_off;
-		pm_power_off = efi_power_off;
+		/* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
+		efi_sys_off_handler =
+			register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
+						 SYS_OFF_PRIO_FIRMWARE + 1,
+						 efi_power_off, NULL);
+		if (IS_ERR(efi_sys_off_handler))
+			return PTR_ERR(efi_sys_off_handler);
 	}
 
 	return 0;
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work
  2022-07-08 13:14 [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Hans de Goede
  2022-07-08 13:14 ` [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again Hans de Goede
  2022-07-08 13:14 ` [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary Hans de Goede
@ 2022-07-08 13:29 ` Dmitry Osipenko
  2022-07-10 15:27 ` Hans de Goede
  3 siblings, 0 replies; 8+ messages in thread
From: Dmitry Osipenko @ 2022-07-08 13:29 UTC (permalink / raw)
  To: Hans de Goede, Rafael J . Wysocki, Mika Westerberg, Mark Gross,
	Andy Shevchenko, Ard Biesheuvel
  Cc: linux-acpi, linux-pm, platform-driver-x86, x86, linux-efi

On 7/8/22 16:14, Hans de Goede wrote:
> Hi All,
> 
> I noticed that my Lenovo Yoga Tablet 2 1050L was hanging on power-off again
> with 5.19, even though I had implemented a workaround for this in 5.17 .
> 
> I quickly realized that this was caused by the recent sys-off-handler work
> and fixed this by switching the workaround over to register_sys_off_handler
> with a priority of SYS_OFF_PRIO_FIRMWARE + 1, so that the workaround runs
> before acpi_power_off() get a chance to run.
> 
> This made me realize that the efi_power_off handler which sometimes is
> used in preference of acpi_power_off had the same problem, so the second
> patch in this series fixes that.
> 
> I plan to include patch 1/2 in a fixes pull-req to Linus soon. Ard,
> if I can get your Ack for 2/2 then I can include this in the pull-req
> if you want; or you can send this to Linus yourself.
> 
> Regards,
> 
> Hans
> 
> 
> Hans de Goede (2):
>   platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050
>     poweroff again
>   efi: Fix efi_power_off() not being run before acpi_power_off() when
>     necessary
> 
>  drivers/firmware/efi/reboot.c              | 21 +++++++++++----------
>  drivers/platform/x86/x86-android-tablets.c | 17 +++++++++++++----
>  2 files changed, 24 insertions(+), 14 deletions(-)
> 

Thank you for the fixes. It's great that the RC is getting more testing
since I couldn't test everything and we don't have CI for the power-off
testing.

-- 
Best regards,
Dmitry

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again
  2022-07-08 13:14 ` [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again Hans de Goede
@ 2022-07-08 13:36   ` Dmitry Osipenko
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Osipenko @ 2022-07-08 13:36 UTC (permalink / raw)
  To: Hans de Goede, Rafael J . Wysocki, Mika Westerberg, Mark Gross,
	Andy Shevchenko, Ard Biesheuvel
  Cc: linux-acpi, linux-pm, platform-driver-x86, x86, linux-efi

On 7/8/22 16:14, Hans de Goede wrote:
> @@ -950,13 +953,19 @@ static int __init lenovo_yoga_tab2_830_1050_init(void)
>  	if (ret)
>  		return ret;
>  
> -	pm_power_off = lenovo_yoga_tab2_830_1050_power_off;
> +	/* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
> +	lenovo_yoga_tab2_830_1050_sys_off_handler =
> +		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
> +					 lenovo_yoga_tab2_830_1050_power_off, NULL);
> +	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
> +		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);

Please note that technically we could ignore the registration error
(maybe print error message) and allow the rest of the module to work
without the power-off.

The unregister_sys_off_handler() will skip the ERR_PTR handler.

-- 
Best regards,
Dmitry

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary
  2022-07-08 13:14 ` [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary Hans de Goede
@ 2022-07-08 16:37   ` Ard Biesheuvel
  2022-07-10 15:24     ` Hans de Goede
  0 siblings, 1 reply; 8+ messages in thread
From: Ard Biesheuvel @ 2022-07-08 16:37 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Rafael J . Wysocki, Mika Westerberg, Dmitry Osipenko, Mark Gross,
	Andy Shevchenko, ACPI Devel Maling List, Linux PM,
	platform-driver-x86, X86 ML, linux-efi

On Fri, 8 Jul 2022 at 15:14, Hans de Goede <hdegoede@redhat.com> wrote:
>
> Commit 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
> switched the ACPI sleep code from directly setting the old global
> pm_power_off handler to using the new register_sys_off_handler()
> mechanism with a priority of SYS_OFF_PRIO_FIRMWARE.
>
> This is a problem when the old global pm_power_off handler would later
> be overwritten, such as done by the late_initcall(efi_shutdown_init):
>
>         if (efi_poweroff_required())
>                 pm_power_off = efi_power_off;
>
> The old global pm_power_off handler gets run with a priority of
> SYS_OFF_PRIO_DEFAULT which is lower then SYS_OFF_PRIO_FIRMWARE, causing
> acpi_power_off() to run first, changing the behavior from before
> the ACPI sleep code switched to the new register_sys_off_handler().
>
> Switch the registering of efi_power_off over to register_sys_off_handler()
> with a priority of SYS_OFF_PRIO_FIRMWARE + 1 so that it will run before
> acpi_power_off() as before.
>
> Note since the new sys-off-handler code will try all handlers in
> priority order, there is no more need for the EFI code to store and
> call the original pm_power_off handler.
>
> Fixes: 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
> Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

Note that, as far as I know, this should only affect x86 even though
this is generic EFI code, and arm64 also supports ACPI boot, but it
doesn't use ACPI for poweroff/reboot etc

> ---
>  drivers/firmware/efi/reboot.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/firmware/efi/reboot.c b/drivers/firmware/efi/reboot.c
> index 73089a24f04b..ceae84c19d22 100644
> --- a/drivers/firmware/efi/reboot.c
> +++ b/drivers/firmware/efi/reboot.c
> @@ -6,7 +6,7 @@
>  #include <linux/efi.h>
>  #include <linux/reboot.h>
>
> -static void (*orig_pm_power_off)(void);
> +static struct sys_off_handler *efi_sys_off_handler;
>
>  int efi_reboot_quirk_mode = -1;
>
> @@ -51,15 +51,11 @@ bool __weak efi_poweroff_required(void)
>         return false;
>  }
>
> -static void efi_power_off(void)
> +static int efi_power_off(struct sys_off_data *data)
>  {
>         efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
> -       /*
> -        * The above call should not return, if it does fall back to
> -        * the original power off method (typically ACPI poweroff).
> -        */
> -       if (orig_pm_power_off)
> -               orig_pm_power_off();
> +
> +       return NOTIFY_DONE;
>  }
>
>  static int __init efi_shutdown_init(void)
> @@ -68,8 +64,13 @@ static int __init efi_shutdown_init(void)
>                 return -ENODEV;
>
>         if (efi_poweroff_required()) {
> -               orig_pm_power_off = pm_power_off;
> -               pm_power_off = efi_power_off;
> +               /* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
> +               efi_sys_off_handler =
> +                       register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
> +                                                SYS_OFF_PRIO_FIRMWARE + 1,
> +                                                efi_power_off, NULL);
> +               if (IS_ERR(efi_sys_off_handler))
> +                       return PTR_ERR(efi_sys_off_handler);
>         }
>
>         return 0;
> --
> 2.36.0
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary
  2022-07-08 16:37   ` Ard Biesheuvel
@ 2022-07-10 15:24     ` Hans de Goede
  0 siblings, 0 replies; 8+ messages in thread
From: Hans de Goede @ 2022-07-10 15:24 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Rafael J . Wysocki, Mika Westerberg, Dmitry Osipenko, Mark Gross,
	Andy Shevchenko, ACPI Devel Maling List, Linux PM,
	platform-driver-x86, X86 ML, linux-efi

Hi,

On 7/8/22 18:37, Ard Biesheuvel wrote:
> On Fri, 8 Jul 2022 at 15:14, Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Commit 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
>> switched the ACPI sleep code from directly setting the old global
>> pm_power_off handler to using the new register_sys_off_handler()
>> mechanism with a priority of SYS_OFF_PRIO_FIRMWARE.
>>
>> This is a problem when the old global pm_power_off handler would later
>> be overwritten, such as done by the late_initcall(efi_shutdown_init):
>>
>>         if (efi_poweroff_required())
>>                 pm_power_off = efi_power_off;
>>
>> The old global pm_power_off handler gets run with a priority of
>> SYS_OFF_PRIO_DEFAULT which is lower then SYS_OFF_PRIO_FIRMWARE, causing
>> acpi_power_off() to run first, changing the behavior from before
>> the ACPI sleep code switched to the new register_sys_off_handler().
>>
>> Switch the registering of efi_power_off over to register_sys_off_handler()
>> with a priority of SYS_OFF_PRIO_FIRMWARE + 1 so that it will run before
>> acpi_power_off() as before.
>>
>> Note since the new sys-off-handler code will try all handlers in
>> priority order, there is no more need for the EFI code to store and
>> call the original pm_power_off handler.
>>
>> Fixes: 98f30d0ecf79 ("ACPI: power: Switch to sys-off handler API")
>> Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> 
> Acked-by: Ard Biesheuvel <ardb@kernel.org>

Thanks, I'll include this in my next fixes pull-req for 5.19.

Regards,

Hans


> 
> Note that, as far as I know, this should only affect x86 even though
> this is generic EFI code, and arm64 also supports ACPI boot, but it
> doesn't use ACPI for poweroff/reboot etc
> 
>> ---
>>  drivers/firmware/efi/reboot.c | 21 +++++++++++----------
>>  1 file changed, 11 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/firmware/efi/reboot.c b/drivers/firmware/efi/reboot.c
>> index 73089a24f04b..ceae84c19d22 100644
>> --- a/drivers/firmware/efi/reboot.c
>> +++ b/drivers/firmware/efi/reboot.c
>> @@ -6,7 +6,7 @@
>>  #include <linux/efi.h>
>>  #include <linux/reboot.h>
>>
>> -static void (*orig_pm_power_off)(void);
>> +static struct sys_off_handler *efi_sys_off_handler;
>>
>>  int efi_reboot_quirk_mode = -1;
>>
>> @@ -51,15 +51,11 @@ bool __weak efi_poweroff_required(void)
>>         return false;
>>  }
>>
>> -static void efi_power_off(void)
>> +static int efi_power_off(struct sys_off_data *data)
>>  {
>>         efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
>> -       /*
>> -        * The above call should not return, if it does fall back to
>> -        * the original power off method (typically ACPI poweroff).
>> -        */
>> -       if (orig_pm_power_off)
>> -               orig_pm_power_off();
>> +
>> +       return NOTIFY_DONE;
>>  }
>>
>>  static int __init efi_shutdown_init(void)
>> @@ -68,8 +64,13 @@ static int __init efi_shutdown_init(void)
>>                 return -ENODEV;
>>
>>         if (efi_poweroff_required()) {
>> -               orig_pm_power_off = pm_power_off;
>> -               pm_power_off = efi_power_off;
>> +               /* SYS_OFF_PRIO_FIRMWARE + 1 so that it runs before acpi_power_off */
>> +               efi_sys_off_handler =
>> +                       register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
>> +                                                SYS_OFF_PRIO_FIRMWARE + 1,
>> +                                                efi_power_off, NULL);
>> +               if (IS_ERR(efi_sys_off_handler))
>> +                       return PTR_ERR(efi_sys_off_handler);
>>         }
>>
>>         return 0;
>> --
>> 2.36.0
>>
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work
  2022-07-08 13:14 [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Hans de Goede
                   ` (2 preceding siblings ...)
  2022-07-08 13:29 ` [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Dmitry Osipenko
@ 2022-07-10 15:27 ` Hans de Goede
  3 siblings, 0 replies; 8+ messages in thread
From: Hans de Goede @ 2022-07-10 15:27 UTC (permalink / raw)
  To: Rafael J . Wysocki, Mika Westerberg, Dmitry Osipenko, Mark Gross,
	Andy Shevchenko, Ard Biesheuvel
  Cc: linux-acpi, linux-pm, platform-driver-x86, x86, linux-efi

Hi,

On 7/8/22 15:14, Hans de Goede wrote:
> Hi All,
> 
> I noticed that my Lenovo Yoga Tablet 2 1050L was hanging on power-off again
> with 5.19, even though I had implemented a workaround for this in 5.17 .
> 
> I quickly realized that this was caused by the recent sys-off-handler work
> and fixed this by switching the workaround over to register_sys_off_handler
> with a priority of SYS_OFF_PRIO_FIRMWARE + 1, so that the workaround runs
> before acpi_power_off() get a chance to run.
> 
> This made me realize that the efi_power_off handler which sometimes is
> used in preference of acpi_power_off had the same problem, so the second
> patch in this series fixes that.
> 
> I plan to include patch 1/2 in a fixes pull-req to Linus soon. Ard,
> if I can get your Ack for 2/2 then I can include this in the pull-req
> if you want; or you can send this to Linus yourself.

I've added these to my review-hans (soon to be for-next) branch now
and I'll include them in my upcoming 5.19 fixes pull-req.

Regards,

Hans

> 
> Regards,
> 
> Hans
> 
> 
> Hans de Goede (2):
>   platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050
>     poweroff again
>   efi: Fix efi_power_off() not being run before acpi_power_off() when
>     necessary
> 
>  drivers/firmware/efi/reboot.c              | 21 +++++++++++----------
>  drivers/platform/x86/x86-android-tablets.c | 17 +++++++++++++----
>  2 files changed, 24 insertions(+), 14 deletions(-)
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-10 15:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 13:14 [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Hans de Goede
2022-07-08 13:14 ` [PATCH 1/2] platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again Hans de Goede
2022-07-08 13:36   ` Dmitry Osipenko
2022-07-08 13:14 ` [PATCH 2/2] efi: Fix efi_power_off() not being run before acpi_power_off() when necessary Hans de Goede
2022-07-08 16:37   ` Ard Biesheuvel
2022-07-10 15:24     ` Hans de Goede
2022-07-08 13:29 ` [PATCH 0/2] Fix 2 5.19 power-off regressions caused by sys-off-handler work Dmitry Osipenko
2022-07-10 15:27 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).