* [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