All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/2] kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode
@ 2022-09-16  4:33 Kai-Heng Feng
  2022-09-16  4:33 ` [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot Kai-Heng Feng
  0 siblings, 1 reply; 5+ messages in thread
From: Kai-Heng Feng @ 2022-09-16  4:33 UTC (permalink / raw)
  To: rafael.j.wysocki, lenb
  Cc: Kai-Heng Feng, Dmitry Osipenko, Luis Chamberlain, tangmeng,
	Petr Mladek, YueHaibing, linux-kernel

Add SYS_OFF_MODE_RESTART_PREPARE callbacks can be invoked before system
restart.

This is a preparation for next patch.

Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v4:
 - Correct typo in comment.
v3:
 - New patch.

 include/linux/reboot.h |  8 ++++++++
 kernel/reboot.c        | 17 +++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index e5d9ef886179c..2b6bb593be5b6 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -105,6 +105,14 @@ enum sys_off_mode {
 	 */
 	SYS_OFF_MODE_POWER_OFF,
 
+	/**
+	 * @SYS_OFF_MODE_RESTART_PREPARE:
+	 *
+	 * Handlers prepare system to be restarted. Handlers are
+	 * allowed to sleep.
+	 */
+	SYS_OFF_MODE_RESTART_PREPARE,
+
 	/**
 	 * @SYS_OFF_MODE_RESTART:
 	 *
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 3c35445bf5ad3..3bba88c7ffc6b 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -243,6 +243,17 @@ void migrate_to_reboot_cpu(void)
 	set_cpus_allowed_ptr(current, cpumask_of(cpu));
 }
 
+/*
+ *	Notifier list for kernel code which wants to be called
+ *	to prepare system for restart.
+ */
+static BLOCKING_NOTIFIER_HEAD(restart_prep_handler_list);
+
+static void do_kernel_restart_prepare(void)
+{
+	blocking_notifier_call_chain(&restart_prep_handler_list, 0, NULL);
+}
+
 /**
  *	kernel_restart - reboot the system
  *	@cmd: pointer to buffer containing command to execute for restart
@@ -254,6 +265,7 @@ void migrate_to_reboot_cpu(void)
 void kernel_restart(char *cmd)
 {
 	kernel_restart_prepare(cmd);
+	do_kernel_restart_prepare();
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
 	if (!cmd)
@@ -396,6 +408,11 @@ register_sys_off_handler(enum sys_off_mode mode,
 		handler->list = &power_off_handler_list;
 		break;
 
+	case SYS_OFF_MODE_RESTART_PREPARE:
+		handler->list = &restart_prep_handler_list;
+		handler->blocking = true;
+		break;
+
 	case SYS_OFF_MODE_RESTART:
 		handler->list = &restart_handler_list;
 		break;
-- 
2.37.2


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

* [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot
  2022-09-16  4:33 [PATCH v4 1/2] kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode Kai-Heng Feng
@ 2022-09-16  4:33 ` Kai-Heng Feng
  2022-09-24 16:19   ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Kai-Heng Feng @ 2022-09-16  4:33 UTC (permalink / raw)
  To: rafael.j.wysocki, lenb
  Cc: Kai-Heng Feng, Josef Bacik, Dmitry Osipenko, Rafael J. Wysocki,
	linux-acpi, linux-kernel

Commit d60cd06331a3 ("PM: ACPI: reboot: Use S5 for reboot") caused Dell
PowerEdge r440 hangs at reboot.

The issue is fixed by commit 2ca1c94ce0b6 ("tg3: Disable tg3 device on
system reboot to avoid triggering AER"), so use the new sysoff API to
reinstate S5 for reboot on ACPI-based systems.

Using S5 for reboot is default behavior under Windows, "A full shutdown
(S5) occurs when a system restart is requested" [1].

[1] https://docs.microsoft.com/en-us/windows/win32/power/system-power-state

Cc: Josef Bacik <josef@toxicpanda.com>
Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v4:
 - Add comment and add more info to commit message.
v3:
 - Use new API to invoke ACPI S5.
v2:
 - Use do_kernel_power_off_prepare() instead.

 drivers/acpi/sleep.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index ad4b2987b3d6e..0b557c0d405ef 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -1088,6 +1088,14 @@ int __init acpi_sleep_init(void)
 		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
 					 SYS_OFF_PRIO_FIRMWARE,
 					 acpi_power_off, NULL);
+
+		/*
+		 * Windows uses S5 for reboot, so some BIOSes depend on it to
+		 * perform proper reboot.
+		 */
+		register_sys_off_handler(SYS_OFF_MODE_RESTART_PREPARE,
+					 SYS_OFF_PRIO_FIRMWARE,
+					 acpi_power_off_prepare, NULL);
 	} else {
 		acpi_no_s5 = true;
 	}
-- 
2.37.2


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

* Re: [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot
  2022-09-16  4:33 ` [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot Kai-Heng Feng
@ 2022-09-24 16:19   ` Rafael J. Wysocki
  2022-09-25 15:50     ` Rafael J. Wysocki
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2022-09-24 16:19 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: Rafael Wysocki, Len Brown, Josef Bacik, Dmitry Osipenko,
	Rafael J. Wysocki, ACPI Devel Maling List,
	Linux Kernel Mailing List

On Fri, Sep 16, 2022 at 6:33 AM Kai-Heng Feng
<kai.heng.feng@canonical.com> wrote:
>
> Commit d60cd06331a3 ("PM: ACPI: reboot: Use S5 for reboot") caused Dell
> PowerEdge r440 hangs at reboot.
>
> The issue is fixed by commit 2ca1c94ce0b6 ("tg3: Disable tg3 device on
> system reboot to avoid triggering AER"), so use the new sysoff API to
> reinstate S5 for reboot on ACPI-based systems.
>
> Using S5 for reboot is default behavior under Windows, "A full shutdown
> (S5) occurs when a system restart is requested" [1].
>
> [1] https://docs.microsoft.com/en-us/windows/win32/power/system-power-state
>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v4:
>  - Add comment and add more info to commit message.
> v3:
>  - Use new API to invoke ACPI S5.
> v2:
>  - Use do_kernel_power_off_prepare() instead.
>
>  drivers/acpi/sleep.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
> index ad4b2987b3d6e..0b557c0d405ef 100644
> --- a/drivers/acpi/sleep.c
> +++ b/drivers/acpi/sleep.c
> @@ -1088,6 +1088,14 @@ int __init acpi_sleep_init(void)
>                 register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
>                                          SYS_OFF_PRIO_FIRMWARE,
>                                          acpi_power_off, NULL);
> +
> +               /*
> +                * Windows uses S5 for reboot, so some BIOSes depend on it to
> +                * perform proper reboot.
> +                */
> +               register_sys_off_handler(SYS_OFF_MODE_RESTART_PREPARE,
> +                                        SYS_OFF_PRIO_FIRMWARE,
> +                                        acpi_power_off_prepare, NULL);
>         } else {
>                 acpi_no_s5 = true;
>         }
> --

Applied as 6.1 material with some edits in the changelog, thanks!

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

* Re: [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot
  2022-09-24 16:19   ` Rafael J. Wysocki
@ 2022-09-25 15:50     ` Rafael J. Wysocki
  2022-09-29  6:03       ` Kai-Heng Feng
  0 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2022-09-25 15:50 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: Rafael Wysocki, Len Brown, Josef Bacik, Dmitry Osipenko,
	Rafael J. Wysocki, ACPI Devel Maling List,
	Linux Kernel Mailing List

On Sat, Sep 24, 2022 at 6:19 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Fri, Sep 16, 2022 at 6:33 AM Kai-Heng Feng
> <kai.heng.feng@canonical.com> wrote:
> >
> > Commit d60cd06331a3 ("PM: ACPI: reboot: Use S5 for reboot") caused Dell
> > PowerEdge r440 hangs at reboot.
> >
> > The issue is fixed by commit 2ca1c94ce0b6 ("tg3: Disable tg3 device on
> > system reboot to avoid triggering AER"), so use the new sysoff API to
> > reinstate S5 for reboot on ACPI-based systems.
> >
> > Using S5 for reboot is default behavior under Windows, "A full shutdown
> > (S5) occurs when a system restart is requested" [1].
> >
> > [1] https://docs.microsoft.com/en-us/windows/win32/power/system-power-state
> >
> > Cc: Josef Bacik <josef@toxicpanda.com>
> > Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> > ---
> > v4:
> >  - Add comment and add more info to commit message.
> > v3:
> >  - Use new API to invoke ACPI S5.
> > v2:
> >  - Use do_kernel_power_off_prepare() instead.
> >
> >  drivers/acpi/sleep.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
> > index ad4b2987b3d6e..0b557c0d405ef 100644
> > --- a/drivers/acpi/sleep.c
> > +++ b/drivers/acpi/sleep.c
> > @@ -1088,6 +1088,14 @@ int __init acpi_sleep_init(void)
> >                 register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
> >                                          SYS_OFF_PRIO_FIRMWARE,
> >                                          acpi_power_off, NULL);
> > +
> > +               /*
> > +                * Windows uses S5 for reboot, so some BIOSes depend on it to
> > +                * perform proper reboot.
> > +                */
> > +               register_sys_off_handler(SYS_OFF_MODE_RESTART_PREPARE,
> > +                                        SYS_OFF_PRIO_FIRMWARE,
> > +                                        acpi_power_off_prepare, NULL);
> >         } else {
> >                 acpi_no_s5 = true;
> >         }
> > --
>
> Applied as 6.1 material with some edits in the changelog, thanks!

And dropped due to a build failure.

It looks like it depends on patch [1/2], but I haven't seen that one.

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

* Re: [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot
  2022-09-25 15:50     ` Rafael J. Wysocki
@ 2022-09-29  6:03       ` Kai-Heng Feng
  0 siblings, 0 replies; 5+ messages in thread
From: Kai-Heng Feng @ 2022-09-29  6:03 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Rafael Wysocki, Len Brown, Josef Bacik, Dmitry Osipenko,
	ACPI Devel Maling List, Linux Kernel Mailing List

On Sun, Sep 25, 2022 at 11:50 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Sat, Sep 24, 2022 at 6:19 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Fri, Sep 16, 2022 at 6:33 AM Kai-Heng Feng
> > <kai.heng.feng@canonical.com> wrote:
> > >
> > > Commit d60cd06331a3 ("PM: ACPI: reboot: Use S5 for reboot") caused Dell
> > > PowerEdge r440 hangs at reboot.
> > >
> > > The issue is fixed by commit 2ca1c94ce0b6 ("tg3: Disable tg3 device on
> > > system reboot to avoid triggering AER"), so use the new sysoff API to
> > > reinstate S5 for reboot on ACPI-based systems.
> > >
> > > Using S5 for reboot is default behavior under Windows, "A full shutdown
> > > (S5) occurs when a system restart is requested" [1].
> > >
> > > [1] https://docs.microsoft.com/en-us/windows/win32/power/system-power-state
> > >
> > > Cc: Josef Bacik <josef@toxicpanda.com>
> > > Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> > > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> > > ---
> > > v4:
> > >  - Add comment and add more info to commit message.
> > > v3:
> > >  - Use new API to invoke ACPI S5.
> > > v2:
> > >  - Use do_kernel_power_off_prepare() instead.
> > >
> > >  drivers/acpi/sleep.c | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > >
> > > diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
> > > index ad4b2987b3d6e..0b557c0d405ef 100644
> > > --- a/drivers/acpi/sleep.c
> > > +++ b/drivers/acpi/sleep.c
> > > @@ -1088,6 +1088,14 @@ int __init acpi_sleep_init(void)
> > >                 register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
> > >                                          SYS_OFF_PRIO_FIRMWARE,
> > >                                          acpi_power_off, NULL);
> > > +
> > > +               /*
> > > +                * Windows uses S5 for reboot, so some BIOSes depend on it to
> > > +                * perform proper reboot.
> > > +                */
> > > +               register_sys_off_handler(SYS_OFF_MODE_RESTART_PREPARE,
> > > +                                        SYS_OFF_PRIO_FIRMWARE,
> > > +                                        acpi_power_off_prepare, NULL);
> > >         } else {
> > >                 acpi_no_s5 = true;
> > >         }
> > > --
> >
> > Applied as 6.1 material with some edits in the changelog, thanks!
>
> And dropped due to a build failure.
>
> It looks like it depends on patch [1/2], but I haven't seen that one.

Sorry about that, let me resend it to linux-pm too.

Kai-Heng

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

end of thread, other threads:[~2022-09-29  6:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16  4:33 [PATCH v4 1/2] kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode Kai-Heng Feng
2022-09-16  4:33 ` [PATCH v4 2/2] PM: ACPI: reboot: Reinstate S5 for reboot Kai-Heng Feng
2022-09-24 16:19   ` Rafael J. Wysocki
2022-09-25 15:50     ` Rafael J. Wysocki
2022-09-29  6:03       ` Kai-Heng Feng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.