* [PATCH -mm -v3] x86 boot : export boot_params via sysfs
@ 2007-12-14 8:16 Huang, Ying
2007-12-14 15:52 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Huang, Ying @ 2007-12-14 8:16 UTC (permalink / raw)
To: Greg KH, akpm, H. Peter Anvin, Thomas Gleixner, Ingo Molnar,
Andi Kleen, Eric W. Biederman
Cc: linux-kernel
This patch export the boot parameters via sysfs. This can be used for
debugging and kexec.
The files added are as follow:
/sys/kernel/boot_params/data : binary file for struct boot_params
/sys/kernel/boot_params/version : boot protocol version
This patch is based on 2.6.24-rc5-mm1 and has been tested on i386 and
x86_64 platoform.
This patch is based on the Peter Anvin's proposal.
v3:
- Use updated API: kobject_create_and_add.
v2:
- Add document in Document/ABI.
Signed-off-by: Huang Ying <ying.huang@intel.com>
---
Documentation/ABI/testing/sysfs-kernel-boot_params | 14 +++
arch/x86/kernel/Makefile_32 | 1
arch/x86/kernel/Makefile_64 | 1
arch/x86/kernel/ksysfs.c | 88 +++++++++++++++++++++
arch/x86/kernel/setup64.c | 2
arch/x86/kernel/setup_32.c | 2
6 files changed, 106 insertions(+), 2 deletions(-)
--- a/arch/x86/kernel/Makefile_64
+++ b/arch/x86/kernel/Makefile_64
@@ -40,6 +40,7 @@ obj-$(CONFIG_X86_VSMP) += vsmp_64.o
obj-$(CONFIG_K8_NB) += k8.o
obj-$(CONFIG_AUDIT) += audit_64.o
obj-$(CONFIG_EFI) += efi.o efi_64.o efi_stub_64.o
+obj-$(CONFIG_SYSFS) += ksysfs.o
obj-$(CONFIG_MODULES) += module_64.o
obj-$(CONFIG_PCI) += early-quirks.o
--- a/arch/x86/kernel/setup64.c
+++ b/arch/x86/kernel/setup64.c
@@ -24,7 +24,7 @@
#include <asm/sections.h>
#include <asm/setup.h>
-struct boot_params __initdata boot_params;
+struct boot_params boot_params;
cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
--- /dev/null
+++ b/arch/x86/kernel/ksysfs.c
@@ -0,0 +1,88 @@
+/*
+ * Architecture specific sysfs attributes in /sys/kernel
+ *
+ * Copyright (C) 2007, Intel Corp.
+ * Huang Ying <ying.huang@intel.com>
+ *
+ * This file is released under the GPLv2
+ */
+
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/init.h>
+#include <linux/stat.h>
+#include <linux/mm.h>
+
+#include <asm/setup.h>
+
+static ssize_t boot_params_version_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sprintf(buf, "0x%04x\n", boot_params.hdr.version);
+}
+
+static struct kobj_attribute boot_params_version_attr =
+ __ATTR(version, S_IRUGO, boot_params_version_show, NULL);
+
+static struct attribute *boot_params_attrs[] = {
+ &boot_params_version_attr.attr,
+ NULL
+};
+
+static struct attribute_group boot_params_attr_group = {
+ .attrs = boot_params_attrs,
+};
+
+static ssize_t boot_params_data_read(struct kobject *kobj,
+ struct bin_attribute *bin_attr,
+ char *buf, loff_t off, size_t count)
+{
+ memcpy(buf, (void *)&boot_params + off, count);
+ return count;
+}
+
+static struct bin_attribute boot_params_data_attr = {
+ .attr = {
+ .name = "data",
+ .mode = S_IRUGO,
+ },
+ .read = boot_params_data_read,
+ .size = sizeof(boot_params),
+};
+
+static int __init boot_params_ksysfs_init(void)
+{
+ int error;
+ struct kobject *boot_params_kobj;
+
+ boot_params_kobj = kobject_create_and_add("boot_params", kernel_kobj);
+ if (!boot_params_kobj) {
+ error = -ENOMEM;
+ goto err_return;
+ }
+ error = sysfs_create_group(boot_params_kobj,
+ &boot_params_attr_group);
+ if (error)
+ goto err_boot_params_subsys_unregister;
+ error = sysfs_create_bin_file(boot_params_kobj,
+ &boot_params_data_attr);
+ if (error)
+ goto err_boot_params_subsys_unregister;
+ return 0;
+err_boot_params_subsys_unregister:
+ kobject_unregister(boot_params_kobj);
+err_return:
+ return error;
+}
+
+static int __init arch_ksysfs_init(void)
+{
+ int error;
+
+ error = boot_params_ksysfs_init();
+
+ return error;
+}
+
+arch_initcall(arch_ksysfs_init);
--- a/arch/x86/kernel/Makefile_32
+++ b/arch/x86/kernel/Makefile_32
@@ -45,6 +45,7 @@ obj-$(CONFIG_EARLY_PRINTK) += early_prin
obj-$(CONFIG_HPET_TIMER) += hpet.o
obj-$(CONFIG_K8_NB) += k8.o
obj-$(CONFIG_MGEODE_LX) += geode_32.o mfgpt_32.o
+obj-$(CONFIG_SYSFS) += ksysfs.o
obj-$(CONFIG_VMI) += vmi_32.o vmiclock_32.o
obj-$(CONFIG_PARAVIRT) += paravirt_32.o
--- a/arch/x86/kernel/setup_32.c
+++ b/arch/x86/kernel/setup_32.c
@@ -194,7 +194,7 @@ unsigned long saved_videomode;
static char __initdata command_line[COMMAND_LINE_SIZE];
-struct boot_params __initdata boot_params;
+struct boot_params boot_params;
#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
struct edd edd;
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-boot_params
@@ -0,0 +1,14 @@
+What: /sys/kernel/boot_params
+Date: December 2007
+Contact: Huang Ying <ying.huang@intel.com>
+Description:
+ The /sys/kernel/boot_params directory contains two
+ files: "data" and "version". It is used to export the
+ kernel boot parameters of x86 platform to user space
+ for debugging and kexec. The "data" file is the binary
+ representation of struct boot_params. The "version"
+ file is the string representation of boot protocol
+ version.
+
+Users:
+ Kexec Mailing List <kexec@lists.infradead.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -mm -v3] x86 boot : export boot_params via sysfs
2007-12-14 8:16 [PATCH -mm -v3] x86 boot : export boot_params via sysfs Huang, Ying
@ 2007-12-14 15:52 ` Greg KH
2007-12-14 18:12 ` H. Peter Anvin
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2007-12-14 15:52 UTC (permalink / raw)
To: Huang, Ying
Cc: akpm, H. Peter Anvin, Thomas Gleixner, Ingo Molnar, Andi Kleen,
Eric W. Biederman, linux-kernel
On Fri, Dec 14, 2007 at 04:16:46PM +0800, Huang, Ying wrote:
> This patch export the boot parameters via sysfs. This can be used for
> debugging and kexec.
>
> The files added are as follow:
>
> /sys/kernel/boot_params/data : binary file for struct boot_params
> /sys/kernel/boot_params/version : boot protocol version
>
> This patch is based on 2.6.24-rc5-mm1 and has been tested on i386 and
> x86_64 platoform.
>
> This patch is based on the Peter Anvin's proposal.
But it ignored the fact that I said I didn't want this binary file in
sysfs :)
Please take Eric's suggestion and split it up into the different pieces.
Some of the fields can be binary files, as they come directly from the
firmware, but the others should be text.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -mm -v3] x86 boot : export boot_params via sysfs
2007-12-14 15:52 ` Greg KH
@ 2007-12-14 18:12 ` H. Peter Anvin
2007-12-14 19:00 ` H. Peter Anvin
0 siblings, 1 reply; 6+ messages in thread
From: H. Peter Anvin @ 2007-12-14 18:12 UTC (permalink / raw)
To: Greg KH
Cc: Huang, Ying, akpm, Thomas Gleixner, Ingo Molnar, Andi Kleen,
Eric W. Biederman, linux-kernel
Greg KH wrote:
>
> But it ignored the fact that I said I didn't want this binary file in
> sysfs :)
>
> Please take Eric's suggestion and split it up into the different pieces.
> Some of the fields can be binary files, as they come directly from the
> firmware, but the others should be text.
>
But PLEASE include the full structure as a ready-to-eat object. PLEASE.
-hpa
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -mm -v3] x86 boot : export boot_params via sysfs
2007-12-14 18:12 ` H. Peter Anvin
@ 2007-12-14 19:00 ` H. Peter Anvin
2007-12-18 4:34 ` Eric W. Biederman
0 siblings, 1 reply; 6+ messages in thread
From: H. Peter Anvin @ 2007-12-14 19:00 UTC (permalink / raw)
To: Greg KH
Cc: Huang, Ying, akpm, Thomas Gleixner, Ingo Molnar, Andi Kleen,
Eric W. Biederman, linux-kernel
H. Peter Anvin wrote:
> Greg KH wrote:
>>
>> But it ignored the fact that I said I didn't want this binary file in
>> sysfs :)
>>
>> Please take Eric's suggestion and split it up into the different pieces.
>> Some of the fields can be binary files, as they come directly from the
>> firmware, but the others should be text.
>>
>
> But PLEASE include the full structure as a ready-to-eat object. PLEASE.
>
I should clarify this.
By all means go ahead and provide broken-out fields where it makes
sense. However:
- this *IS* a structure defined by protocol, and which, for all users
except the 16-bit entry, comes from outside the kernel (bootloader or
firmware.)
- a newer kernel version can add fields to this structure, but can never
remove them. This would cause a potential information loss if the
current kernel doesn't have all fields available.
- the binary structure is the format that the majority of users will need.
This is directly analogous to how we treat identity information in IDE,
or PCI configuration space -- some fields are pre-digested, but the
entire raw information is also available.
-hpa
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -mm -v3] x86 boot : export boot_params via sysfs
2007-12-14 19:00 ` H. Peter Anvin
@ 2007-12-18 4:34 ` Eric W. Biederman
2007-12-18 7:29 ` Huang, Ying
0 siblings, 1 reply; 6+ messages in thread
From: Eric W. Biederman @ 2007-12-18 4:34 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Greg KH, Huang, Ying, akpm, Thomas Gleixner, Ingo Molnar,
Andi Kleen, linux-kernel
"H. Peter Anvin" <hpa@zytor.com> writes:
> This is directly analogous to how we treat identity information in IDE, or PCI
> configuration space -- some fields are pre-digested, but the entire raw
> information is also available.
Add to that a totally unchanged value can just be easier to get correct.
Still the kexec code as much as it can should not look there, as we may
get the same basic information in a couple of different ways.
EFI memmap vs. e820 for example. If/when that is the case /sbin/kexec
should get the information and spit it out into whatever format makes
sense for the destination kernel. My sense is just passing through
values is brittleness where we don't want it.
However I think being able to get at the raw boot information overall
sounds useful. I just don't know if it is generally useful or just
useful when debugging bootloaders though.
Eric
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -mm -v3] x86 boot : export boot_params via sysfs
2007-12-18 4:34 ` Eric W. Biederman
@ 2007-12-18 7:29 ` Huang, Ying
0 siblings, 0 replies; 6+ messages in thread
From: Huang, Ying @ 2007-12-18 7:29 UTC (permalink / raw)
To: Eric W. Biederman
Cc: H. Peter Anvin, Greg KH, akpm, Thomas Gleixner, Ingo Molnar,
Andi Kleen, linux-kernel
On Mon, 2007-12-17 at 21:34 -0700, Eric W. Biederman wrote:
> "H. Peter Anvin" <hpa@zytor.com> writes:
>
> > This is directly analogous to how we treat identity information in IDE, or PCI
> > configuration space -- some fields are pre-digested, but the entire raw
> > information is also available.
>
> Add to that a totally unchanged value can just be easier to get correct.
>
> Still the kexec code as much as it can should not look there, as we may
> get the same basic information in a couple of different ways.
>
> EFI memmap vs. e820 for example. If/when that is the case /sbin/kexec
> should get the information and spit it out into whatever format makes
> sense for the destination kernel. My sense is just passing through
> values is brittleness where we don't want it.
>
> However I think being able to get at the raw boot information overall
> sounds useful. I just don't know if it is generally useful or just
> useful when debugging bootloaders though.
If struct boot_params as a whole is useless for kexec, I can move it to
debugfs, because kexec is the only normal user now. Then which fields of
struct boot_params do you think is useful for kexec?
Refer to include/asm-x86/bootparam.h
edid_info?
e820_entries and e820_map? maybe useful for kdump
edd related fields (eddbuf, edd_mbr_sig_buffer, etc)? split fields until fundamental types?
Best Regards,
Huang Ying
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-12-18 7:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-14 8:16 [PATCH -mm -v3] x86 boot : export boot_params via sysfs Huang, Ying
2007-12-14 15:52 ` Greg KH
2007-12-14 18:12 ` H. Peter Anvin
2007-12-14 19:00 ` H. Peter Anvin
2007-12-18 4:34 ` Eric W. Biederman
2007-12-18 7:29 ` Huang, Ying
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox