linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] reboot: sysfs improvements
@ 2020-11-30 17:37 Matteo Croce
  2020-11-30 17:37 ` [PATCH 1/2] reboot: allow to override reboot type if quirks are found Matteo Croce
  2020-11-30 17:37 ` [PATCH 2/2] reboot: hide from sysfs not applicable settings Matteo Croce
  0 siblings, 2 replies; 5+ messages in thread
From: Matteo Croce @ 2020-11-30 17:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: Petr Mladek, Andrew Morton

From: Matteo Croce <mcroce@microsoft.com>

Some improvements to the sysfs reboot interface: hide not
working settings and support machines with known reboot quirks.

Matteo Croce (2):
  reboot: allow to override reboot type if quirks are found
  reboot: hide from sysfs not applicable settings

 kernel/reboot.c | 58 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 22 deletions(-)

-- 
2.28.0


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

* [PATCH 1/2] reboot: allow to override reboot type if quirks are found
  2020-11-30 17:37 [PATCH 0/2] reboot: sysfs improvements Matteo Croce
@ 2020-11-30 17:37 ` Matteo Croce
  2020-12-01 10:46   ` Petr Mladek
  2020-11-30 17:37 ` [PATCH 2/2] reboot: hide from sysfs not applicable settings Matteo Croce
  1 sibling, 1 reply; 5+ messages in thread
From: Matteo Croce @ 2020-11-30 17:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: Petr Mladek, Andrew Morton

From: Matteo Croce <mcroce@microsoft.com>

On some machines a quirk can force a specific reboot type.
Quirks are found during a DMI scan, the list of machines which need
special reboot handling is defined in reboot_dmi_table.

The kernel command line reboot= option overrides this via a global
variable `reboot_default`, so that the reboot type requested in
the command line is really performed.

This was not true when setting the reboot type via the new sysfs
interface. Fix this by setting reboot_default upon the first change,
like reboot_setup() does for the command line.

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 kernel/reboot.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index ea6347b99b14..d80e3d64fe23 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -656,6 +656,8 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,
 	else
 		return -EINVAL;
 
+	reboot_default = 0;
+
 	return count;
 }
 static struct kobj_attribute reboot_mode_attr = __ATTR_RW(mode);
@@ -710,6 +712,8 @@ static ssize_t type_store(struct kobject *kobj, struct kobj_attribute *attr,
 	else
 		return -EINVAL;
 
+	reboot_default = 0;
+
 	return count;
 }
 static struct kobj_attribute reboot_type_attr = __ATTR_RW(type);
@@ -735,6 +739,7 @@ static ssize_t cpu_store(struct kobject *kobj, struct kobj_attribute *attr,
 	if (cpunum >= num_possible_cpus())
 		return -ERANGE;
 
+	reboot_default = 0;
 	reboot_cpu = cpunum;
 
 	return count;
@@ -756,6 +761,7 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
 	if (kstrtobool(buf, &res))
 		return -EINVAL;
 
+	reboot_default = 0;
 	reboot_force = res;
 
 	return count;
-- 
2.28.0


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

* [PATCH 2/2] reboot: hide from sysfs not applicable settings
  2020-11-30 17:37 [PATCH 0/2] reboot: sysfs improvements Matteo Croce
  2020-11-30 17:37 ` [PATCH 1/2] reboot: allow to override reboot type if quirks are found Matteo Croce
@ 2020-11-30 17:37 ` Matteo Croce
  2020-12-01 10:52   ` Petr Mladek
  1 sibling, 1 reply; 5+ messages in thread
From: Matteo Croce @ 2020-11-30 17:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: Petr Mladek, Andrew Morton

From: Matteo Croce <mcroce@microsoft.com>

Not all the reboot settings from both the kernel command line or sysfs
interface are available to all platforms.

Filter out reboot_type and reboot_force which are x86 only, and also
remove reboot_cpu on kernels without SMP support.

This saves some space, and avoid confusing the user with settings which
will have no effect.

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
---
 kernel/reboot.c | 54 ++++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/kernel/reboot.c b/kernel/reboot.c
index d80e3d64fe23..f9c192bb49d0 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -662,6 +662,29 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,
 }
 static struct kobj_attribute reboot_mode_attr = __ATTR_RW(mode);
 
+#ifdef CONFIG_X86
+static ssize_t force_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%d\n", reboot_force);
+}
+static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
+			  const char *buf, size_t count)
+{
+	bool res;
+
+	if (!capable(CAP_SYS_BOOT))
+		return -EPERM;
+
+	if (kstrtobool(buf, &res))
+		return -EINVAL;
+
+	reboot_default = 0;
+	reboot_force = res;
+
+	return count;
+}
+static struct kobj_attribute reboot_force_attr = __ATTR_RW(force);
+
 static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
 {
 	const char *val;
@@ -717,7 +740,9 @@ static ssize_t type_store(struct kobject *kobj, struct kobj_attribute *attr,
 	return count;
 }
 static struct kobj_attribute reboot_type_attr = __ATTR_RW(type);
+#endif
 
+#ifdef CONFIG_SMP
 static ssize_t cpu_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
 {
 	return sprintf(buf, "%d\n", reboot_cpu);
@@ -745,34 +770,17 @@ static ssize_t cpu_store(struct kobject *kobj, struct kobj_attribute *attr,
 	return count;
 }
 static struct kobj_attribute reboot_cpu_attr = __ATTR_RW(cpu);
-
-static ssize_t force_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
-{
-	return sprintf(buf, "%d\n", reboot_force);
-}
-static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,
-			  const char *buf, size_t count)
-{
-	bool res;
-
-	if (!capable(CAP_SYS_BOOT))
-		return -EPERM;
-
-	if (kstrtobool(buf, &res))
-		return -EINVAL;
-
-	reboot_default = 0;
-	reboot_force = res;
-
-	return count;
-}
-static struct kobj_attribute reboot_force_attr = __ATTR_RW(force);
+#endif
 
 static struct attribute *reboot_attrs[] = {
 	&reboot_mode_attr.attr,
+#ifdef CONFIG_X86
+	&reboot_force_attr.attr,
 	&reboot_type_attr.attr,
+#endif
+#ifdef CONFIG_SMP
 	&reboot_cpu_attr.attr,
-	&reboot_force_attr.attr,
+#endif
 	NULL,
 };
 
-- 
2.28.0


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

* Re: [PATCH 1/2] reboot: allow to override reboot type if quirks are found
  2020-11-30 17:37 ` [PATCH 1/2] reboot: allow to override reboot type if quirks are found Matteo Croce
@ 2020-12-01 10:46   ` Petr Mladek
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Mladek @ 2020-12-01 10:46 UTC (permalink / raw)
  To: Matteo Croce; +Cc: linux-kernel, Andrew Morton

On Mon 2020-11-30 18:37:16, Matteo Croce wrote:
> From: Matteo Croce <mcroce@microsoft.com>
> 
> On some machines a quirk can force a specific reboot type.
> Quirks are found during a DMI scan, the list of machines which need
> special reboot handling is defined in reboot_dmi_table.
> 
> The kernel command line reboot= option overrides this via a global
> variable `reboot_default`, so that the reboot type requested in
> the command line is really performed.
> 
> This was not true when setting the reboot type via the new sysfs
> interface. Fix this by setting reboot_default upon the first change,
> like reboot_setup() does for the command line.

Strictly speaking this is not necessary. The quirks are proceed
in core_initcall() while the sysfs interface is created in
late_initcall(). By other words, the quirks are uses before
the default can be modified by the sysfs interface.

On the other hand, it does not harm. Better be on the safe
side for eventual future changes.

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

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

* Re: [PATCH 2/2] reboot: hide from sysfs not applicable settings
  2020-11-30 17:37 ` [PATCH 2/2] reboot: hide from sysfs not applicable settings Matteo Croce
@ 2020-12-01 10:52   ` Petr Mladek
  0 siblings, 0 replies; 5+ messages in thread
From: Petr Mladek @ 2020-12-01 10:52 UTC (permalink / raw)
  To: Matteo Croce; +Cc: linux-kernel, Andrew Morton

On Mon 2020-11-30 18:37:17, Matteo Croce wrote:
> From: Matteo Croce <mcroce@microsoft.com>
> 
> Not all the reboot settings from both the kernel command line or sysfs
> interface are available to all platforms.
> 
> Filter out reboot_type and reboot_force which are x86 only, and also
> remove reboot_cpu on kernels without SMP support.
> 
> This saves some space, and avoid confusing the user with settings which
> will have no effect.
> 
> Signed-off-by: Matteo Croce <mcroce@microsoft.com>

Looks good to be.

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr

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

end of thread, other threads:[~2020-12-01 10:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 17:37 [PATCH 0/2] reboot: sysfs improvements Matteo Croce
2020-11-30 17:37 ` [PATCH 1/2] reboot: allow to override reboot type if quirks are found Matteo Croce
2020-12-01 10:46   ` Petr Mladek
2020-11-30 17:37 ` [PATCH 2/2] reboot: hide from sysfs not applicable settings Matteo Croce
2020-12-01 10:52   ` Petr Mladek

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).