reboot: allow to specify reboot mode via sysfs
PATCH v3 1/1 reboot: allow to specify reboot mode via sysfs
From: Matteo Croce <[email protected]>
The kernel cmdline reboot= option offers some sort of control on how the reboot is issued.
Add handles in sysfs to allow setting these reboot options, so they can be changed when the system is booted, other than at boot time.
The handlers are under <sysfs>/kernel/reboot, can be read to get the current configuration and written to alter it.
# cd /sys/kernel/reboot/
# grep . * cpu:0 force:0 mode:cold type:acpi
# echo 2 >cpu # echo yes >force # echo soft >mode # echo bios >type
# grep . * cpu:2 force:1 mode:soft type:bios
Before setting anything, check for CAP_SYS_BOOT capability, so it's possible to allow an unpriviledged process to change these settings simply by relaxing the handles permissions, without opening them to the world.
--- Documentation/ABI/testing/sysfs-kernel-reboot | 31 +++ kernel/reboot.c | 206 ++++++++++++++++++ 2 files changed, 237 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-kernel-reboot
Documentation/ABI/testing/sysfs-kernel-reboot new file +31 -0
@@ -0,0 +1,31 @@ +What: /sys/kernel/reboot +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Interface to set the kernel reboot mode, similarly to + what can be done via the reboot= cmdline option. + (see Documentation/admin-guide/kernel-parameters.txt) + +What: /sys/kernel/reboot/mode +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Reboot mode. Valid values are: cold warm hard soft gpio + +What: /sys/kernel/reboot/type +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Reboot type. Valid values are: bios acpi kbd triple efi pci + +What: /sys/kernel/reboot/cpu +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: CPU number to use to reboot. + +What: /sys/kernel/reboot/force +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Force an immediate reboot.
kernel/reboot.c +206 -0
209 lines not on this page · raw message
Signature · 1 line
2.28.0
Quoted 13 lines · Matteo Croce
From: Matteo Croce <[email protected]>
The kernel cmdline reboot= option offers some sort of control on how the reboot is issued.
Add handles in sysfs to allow setting these reboot options, so they can be changed when the system is booted, other than at boot time.The handlers are under <sysfs>/kernel/reboot, can be read to get the current configuration and written to alter it.
Documentation/ABI/testing/sysfs-kernel-reboot line 8
Quoted 8 lines
Documentation/ABI/testing/sysfs-kernel-reboot new file +8
-0@@ -0,0 +1,31 @@ +What: /sys/kernel/reboot +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Interface to set the kernel reboot mode, similarly to + what can be done via the reboot= cmdline option. + (see Documentation/admin-guide/kernel-parameters.txt) +
s/reboot mode/reboot behavior/
The reboot mode is only one of the modified parameters.
Quoted 13 lines
Documentation/ABI/testing/sysfs-kernel-reboot new file +13
-0+What: /sys/kernel/reboot/mode +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Reboot mode. Valid values are: cold warm hard soft gpio + +What: /sys/kernel/reboot/type +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Reboot type. Valid values are: bios acpi kbd triple efi pci + +What: /sys/kernel/reboot/cpu
Documentation/ABI/testing/sysfs-kernel-reboot line 31
Quoted 10 lines
Documentation/ABI/testing/sysfs-kernel-reboot new file +10
-0+Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: CPU number to use to reboot. + +What: /sys/kernel/reboot/force +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Force an immediate reboot.
This makes me feel like that the kernel will reboot immediately when you write "1". It would deserve a better explanation that would make it clear, something like:
Description: Use forced reboot that does not contact the init system.
Otherwise, it looks good to me. With the two above updates:
Best Regards,
Petr
Quoted 26 lines · Petr Mladek
Quoted 13 lines · Matteo Croce
From: Matteo Croce <[email protected]>
The kernel cmdline reboot= option offers some sort of control on how the reboot is issued.
Add handles in sysfs to allow setting these reboot options, so they can be changed when the system is booted, other than at boot time.The handlers are under <sysfs>/kernel/reboot, can be read to get the current configuration and written to alter it.
Documentation/ABI/testing/sysfs-kernel-reboot line 8
Quoted 8 lines
Documentation/ABI/testing/sysfs-kernel-reboot new file +8
-0@@ -0,0 +1,31 @@ +What: /sys/kernel/reboot +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Interface to set the kernel reboot mode, similarly to + what can be done via the reboot= cmdline option. + (see Documentation/admin-guide/kernel-parameters.txt) +s/reboot mode/reboot behavior/
Quoted 2 lines
The reboot mode is only one of the modified parameters.
Right
Quoted 29 lines
Quoted 14 lines
Documentation/ABI/testing/sysfs-kernel-reboot new file +13
-0+What: /sys/kernel/reboot/mode +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Reboot mode. Valid values are: cold warm hard soft gpio + +What: /sys/kernel/reboot/type +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Reboot type. Valid values are: bios acpi kbd triple efi pci + +What: /sys/kernel/reboot/cpuDocumentation/ABI/testing/sysfs-kernel-reboot line 31
Quoted 10 lines
Documentation/ABI/testing/sysfs-kernel-reboot new file +10
-0+Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: CPU number to use to reboot. + +What: /sys/kernel/reboot/force +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Force an immediate reboot.This makes me feel like that the kernel will reboot immediately when you write "1". It would deserve a better explanation that would make it clear, something like:
Quoted 2 lines
Description: Use forced reboot that does not contact the init system.
Description: Don't wait for any other CPUs on reboot and avoid anything that could hang.
Quoted 7 lines
Otherwise, it looks good to me. With the two above updates:
Reviewed-by Petr Mladek <[email protected]>Best Regards,
Petr
Thanks!
--
per aspera ad upstream
Quoted 13 lines · Matteo Croce
Quoted 12 lines · Petr Mladek
Documentation/ABI/testing/sysfs-kernel-reboot line 31
Quoted 6 lines · Matteo Croce
From: Matteo Croce <[email protected]>
Documentation/ABI/testing/sysfs-kernel-reboot new file +5
-0+What: /sys/kernel/reboot/force +Date: November 2020 +KernelVersion: 5.11 +Contact: Matteo Croce <[email protected]> +Description: Force an immediate reboot.This makes me feel like that the kernel will reboot immediately when you write "1". It would deserve a better explanation that would make it clear, something like:
Quoted 5 lines
Quoted 2 lines
Description: Use forced reboot that does not contact the init system.
Description: Don't wait for any other CPUs on reboot and avoid anything that could hang.
Sound good to me. I see that Andrew already queued the updated patch with my Reviewed-by so all is OK.
Best Regards,
Petr