From: "Huang, Ying" <ying.huang@intel.com>
To: Greg KH <greg@kroah.com>,
akpm@linux-foundation.org, "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Andi Kleen <ak@suse.de>,
"Eric W. Biederman" <ebiederm@xmission.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH -mm -v2] x86 boot : export boot_params via sysfs
Date: Wed, 12 Dec 2007 16:59:51 +0800 [thread overview]
Message-ID: <1197449991.14443.88.camel@caritas-dev.intel.com> (raw)
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-rc4-mm1 and has been tested on i386 and
x86_64 platoform.
This patch is based on the Peter Anvin's proposal.
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 | 89 +++++++++++++++++++++
arch/x86/kernel/setup64.c | 2
arch/x86/kernel/setup_32.c | 2
6 files changed, 107 insertions(+), 2 deletions(-)
--- a/arch/x86/kernel/Makefile_64
+++ b/arch/x86/kernel/Makefile_64
@@ -39,6 +39,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,89 @@
+/*
+ * 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_register("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
@@ -44,6 +44,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>
next reply other threads:[~2007-12-12 9:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-12 8:59 Huang, Ying [this message]
2007-12-12 17:46 ` [PATCH -mm -v2] x86 boot : export boot_params via sysfs Greg KH
2007-12-12 17:54 ` H. Peter Anvin
2007-12-12 18:59 ` Greg KH
2007-12-12 19:05 ` H. Peter Anvin
2007-12-12 22:21 ` Greg KH
2007-12-12 22:37 ` H. Peter Anvin
2007-12-12 22:43 ` Randy Dunlap
2007-12-12 23:08 ` Eric W. Biederman
2007-12-12 22:52 ` Eric W. Biederman
2007-12-12 22:52 ` Eric W. Biederman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1197449991.14443.88.camel@caritas-dev.intel.com \
--to=ying.huang@intel.com \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=greg@kroah.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.