Skip to contentSkip to conversation

reboot: sysfs improvements

PATCH Applied Matteo Croce 2 participants 5 messages Nov 30, 2020 – Dec 1, 2020

lore
Share & tools
lore
#0 lore raw

cover reboot: sysfs improvements

From: Matteo Croce <[email protected]>

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(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/2 reboot: allow to override reboot type if quirks are found

From: Matteo Croce <[email protected]>

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.

---
 kernel/reboot.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/reboot.c +6 -0
index ea6347b99b14..d80e3d64fe23 100644
@@ -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;
Signature · 1 line
2.28.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] reboot: allow to override reboot type if quirks are found

Quoted 6 lines · Matteo Croce

From: Matteo Croce <[email protected]>

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.

Quoted 7 lines

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.

Best Regards,
Petr

#3 lore raw

PATCH 2/2 reboot: hide from sysfs not applicable settings

In reply to Matteo Croce

From: Matteo Croce <[email protected]>

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.

---
 kernel/reboot.c | 54 ++++++++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 23 deletions(-)
kernel/reboot.c +31 -23
index d80e3d64fe23..f9c192bb49d0 100644
@@ -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,
 };
 
Signature · 1 line
2.28.0
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] reboot: hide from sysfs not applicable settings

Quoted 5 lines · Matteo Croce

From: Matteo Croce <[email protected]>

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

Quoted 7 lines

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.

Looks good to be.

Best Regards,
Petr