From: Eric Piel <eric.piel@tremplin-utc.net>
To: Philippe Coval <rzr@users.sf.net>
Cc: Len Brown <lenb@kernel.org>,
trenn@suse.de, Andrew Morton <akpm@linux-foundation.org>,
linux-acpi@vger.kernel.org, dsdt <dsdt@gaugusch.at>
Subject: Re: [PATCH] Override DSDT and SSDTs via initramfs
Date: Sat, 19 Apr 2008 01:25:50 +0200 [thread overview]
Message-ID: <48092DFE.70101@tremplin-utc.net> (raw)
In-Reply-To: <48091B8A.3000800@users.sf.net>
[-- Attachment #1: Type: text/plain, Size: 2417 bytes --]
Philippe Coval wrote:
> Hi,
:
> You may be aware of that yet, but It seems that the patch was rejected
> for 2.6.25
>
>
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=9a9e0d685553af76cb6ae2af93cca4913e7fcd47
>
> Quoting linus : "the relevant ACPI code should either run much later,"
Hi,
Yes, I'm aware of it. The problem was that the code was using fake
userspace commands to access the filesystem (it's was not really wrong
but it always warm the blood of people) _and_ it was reordering the
initialisation code in a rather incompatible way with the some of the
part of the kernel (which is indeed a good reason to reject a patch!).
> So was next then ? how can we help to fix this recurrent issue ?
Now that 2.6.26-rc is open, I can try to summarize all the discussions
that have been about this patch during previous cycle. There are
basically three solutions:
* Make the ACPI layer able to update the DSDT (or other table) at any
time. This was proposed by Linus, and sounds the most beautiful
approach... until you realize that it will lead to lots of limitations
on what update can be done on the DSDT and that it requires basically a
full rewrite of the ACPI layer (and some other parts of the kernel).
* Leverage the kexec infrastructure: instead of inserting the DSDT in
the initramfs, you first boot calmly, read the DSDT from userspace as
you feel like, reboot with kexec to the same kernel while passing this
DSDT to the next kernel instance, which will then use it. It seems quite
a reasonable approach. So far the only problem I have is that I don't
know how to reliably pass the DSDT as argument to the second kernel
(mainly due to lack of time to look for).
* Add 20 lines to the initramfs parser so that it can also just read
one file and copy it to memory without populating the rootfs. This
permits an approach very similar to the previous one but without fake
userspace commands and without reordering the initialisation. Attached
is a patch doing this.
Actually, I'd be interested to know how likely this last approach would
be acceptable for the kernel. Andrew, would you accept the patch in your
tree, for testing?
> Anyway I'd like to thank you all for all time spent on this job,
> and I am happy with the patch as it is...
One small thing to do to help is to test this patch and report success
or failure :-)
See you,
Eric
[-- Attachment #2: acpi-dsdt-initrd-v0.9-2.6.25.patch --]
[-- Type: text/plain, Size: 9675 bytes --]
From de31945e20bc0bd255d0264c5d97a6b24906b30a Mon Sep 17 00:00:00 2001
From: Eric Piel <piel@localhost.(none)>
Date: Wed, 19 Mar 2008 23:00:04 +0100
Subject: [PATCH 1/1] ACPI: initramfs DSDT override support
Permits to load of DSDT (the main ACPI table) from initramfs. In case this
option is selected, the initramfs is parsed at ACPI initialization (very early
boot time) to look for a file DSDT.aml . This aims at allowing users to
override the DSDT without recompiling the kernel
This is derived from the patch from http://gaugusch.at/kernel.shtml but with
some clean-up's in the documentation, default set to No, a kernel paramater to
disable it at runtime, and most important, a different approach for reading the
initramfs which avoids using the filesystem infrastructure.
Signed-off-by: Eric Piel <eric.piel@tremplin-utc.net>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Len Brown <len.brown@intel.com>
---
Documentation/acpi/dsdt-override.txt | 12 ++++-
Documentation/acpi/initramfs-add-dsdt.sh | 43 +++++++++++++++++
Documentation/kernel-parameters.txt | 3 +
drivers/acpi/Kconfig | 11 ++++
drivers/acpi/osl.c | 24 ++++++++++
init/initramfs.c | 74 ++++++++++++++++++++++++++++++
6 files changed, 165 insertions(+), 2 deletions(-)
create mode 100644 Documentation/acpi/initramfs-add-dsdt.sh
diff --git a/Documentation/acpi/dsdt-override.txt b/Documentation/acpi/dsdt-override.txt
index febbb1b..5008f25 100644
--- a/Documentation/acpi/dsdt-override.txt
+++ b/Documentation/acpi/dsdt-override.txt
@@ -1,7 +1,15 @@
-Linux supports a method of overriding the BIOS DSDT:
+Linux supports two methods of overriding the BIOS DSDT:
CONFIG_ACPI_CUSTOM_DSDT builds the image into the kernel.
-When to use this method is described in detail on the
+CONFIG_ACPI_CUSTOM_DSDT_INITRD adds the image to the initrd.
+
+When to use these methods is described in detail on the
Linux/ACPI home page:
http://www.lesswatts.org/projects/acpi/overridingDSDT.php
+
+Note that if both options are used, the DSDT supplied
+by the INITRD method takes precedence.
+
+Documentation/initramfs-add-dsdt.sh is provided for convenience
+for use with the CONFIG_ACPI_CUSTOM_DSDT_INITRD method.
diff --git a/Documentation/acpi/initramfs-add-dsdt.sh b/Documentation/acpi/initramfs-add-dsdt.sh
new file mode 100644
index 0000000..17ef6e8
--- /dev/null
+++ b/Documentation/acpi/initramfs-add-dsdt.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+# Adds a DSDT file to the initrd (if it's an initramfs)
+# first argument is the name of archive
+# second argument is the name of the file to add
+# The file will be copied as /DSDT.aml
+
+# 20060126: fix "Premature end of file" with some old cpio (Roland Robic)
+# 20060205: this time it should really work
+
+# check the arguments
+if [ $# -ne 2 ]; then
+ program_name=$(basename $0)
+ echo "\
+$program_name: too few arguments
+Usage: $program_name initrd-name.img DSDT-to-add.aml
+Adds a DSDT file to an initrd (in initramfs format)
+
+ initrd-name.img: filename of the initrd in initramfs format
+ DSDT-to-add.aml: filename of the DSDT file to add
+ " 1>&2
+ exit 1
+fi
+
+# we should check it's an initramfs
+
+tempcpio=$(mktemp -d)
+# cleanup on exit, hangup, interrupt, quit, termination
+trap 'rm -rf $tempcpio' 0 1 2 3 15
+
+# extract the archive
+gunzip -c "$1" > "$tempcpio"/initramfs.cpio || exit 1
+
+# copy the DSDT file at the root of the directory so that we can call it "/DSDT.aml"
+cp -f "$2" "$tempcpio"/DSDT.aml
+
+# add the file
+cd "$tempcpio"
+(echo DSDT.aml | cpio --quiet -H newc -o -A -O "$tempcpio"/initramfs.cpio) || exit 1
+cd "$OLDPWD"
+
+# re-compress the archive
+gzip -c "$tempcpio"/initramfs.cpio > "$1"
+
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 622f784..49318b9 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -177,6 +177,9 @@ and is between 256 and 4096 characters. It is defined in the file
acpi_no_auto_ssdt [HW,ACPI] Disable automatic loading of SSDT
+ acpi_no_initrd_override [KNL,ACPI]
+ Disable loading custom ACPI tables from the initramfs
+
acpi_os_name= [HW,ACPI] Tell ACPI BIOS the name of the OS
Format: To spoof as Windows 98: ="Microsoft Windows"
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index b4f5e85..fbcaa06 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -300,6 +300,17 @@ config ACPI_CUSTOM_DSDT
bool
default ACPI_CUSTOM_DSDT_FILE != ""
+config ACPI_CUSTOM_DSDT_INITRD
+ bool "Read Custom DSDT from initramfs"
+ depends on BLK_DEV_INITRD
+ default n
+ help
+ This option supports a custom DSDT by optionally loading it from initrd.
+ See Documentation/acpi/dsdt-override.txt
+
+ If you are not using this feature now, but may use it later,
+ it is safe to say Y here.
+
config ACPI_BLACKLIST_YEAR
int "Disable ACPI for systems before Jan 1st this year" if X86_32
default 0
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index a697fb6..8fa630f 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -91,6 +91,11 @@ static DEFINE_SPINLOCK(acpi_res_lock);
#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
static char osi_additional_string[OSI_STRING_LENGTH_MAX];
+#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
+static int acpi_no_initrd_override;
+extern struct acpi_table_header *acpi_find_dsdt_initrd(void);
+#endif
+
/*
* "Ode to _OSI(Linux)"
*
@@ -333,6 +338,16 @@ acpi_os_table_override(struct acpi_table_header * existing_table,
if (strncmp(existing_table->signature, "DSDT", 4) == 0)
*new_table = (struct acpi_table_header *)AmlCode;
#endif
+#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
+ if ((strncmp(existing_table->signature, "DSDT", 4) == 0) &&
+ !acpi_no_initrd_override) {
+ struct acpi_table_header *initrd_table;
+
+ initrd_table = acpi_find_dsdt_initrd();
+ if (initrd_table)
+ *new_table = initrd_table;
+ }
+#endif
if (*new_table != NULL) {
printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
"this is unsafe: tainting kernel\n",
@@ -343,6 +358,15 @@ acpi_os_table_override(struct acpi_table_header * existing_table,
return AE_OK;
}
+#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
+static int __init acpi_no_initrd_override_setup(char *s)
+{
+ acpi_no_initrd_override = 1;
+ return 1;
+}
+__setup("acpi_no_initrd_override", acpi_no_initrd_override_setup);
+#endif
+
static irqreturn_t acpi_irq(int irq, void *dev_id)
{
u32 handled;
diff --git a/init/initramfs.c b/init/initramfs.c
index d53fee8..495380c 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -6,6 +6,7 @@
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/syscalls.h>
+#include <acpi/acpi.h>
static __initdata char *message;
static void __init error(char *x)
@@ -90,6 +91,12 @@ static __initdata unsigned long body_len, name_len;
static __initdata uid_t uid;
static __initdata gid_t gid;
static __initdata unsigned rdev;
+#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
+static __initdata char *file_looked_for;
+static __initdata struct acpi_table_header *file_mem;
+#else
+const char *file_looked_for = NULL;
+#endif
static void __init parse_header(char *s)
{
@@ -123,6 +130,7 @@ static __initdata enum state {
SkipIt,
GotName,
CopyFile,
+ CopyFileMem,
GotSymlink,
Reset
} state, next_state;
@@ -267,6 +275,9 @@ static int __init do_name(void)
free_hash();
return 0;
}
+ if (file_looked_for && S_ISREG(mode) &&
+ (strcmp(collected, file_looked_for) == 0))
+ state = CopyFileMem;
if (dry_run)
return 0;
clean_path(collected, mode);
@@ -299,6 +310,40 @@ static int __init do_name(void)
return 0;
}
+#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
+static int __init do_copy_mem(void)
+{
+ static void *file_current; /* current position in the memory */
+ if (file_mem == NULL) {
+ if (body_len < 4) { /* check especially against empty files */
+ error("file is less than 4 bytes");
+ return 1;
+ }
+ file_mem = kmalloc(body_len, GFP_ATOMIC);
+ if (!file_mem) {
+ error("failed to allocate enough memory");
+ return 1;
+ }
+ file_current = file_mem;
+ }
+ if (count >= body_len) {
+ memcpy(file_current, victim, body_len);
+ eat(body_len);
+ file_looked_for = NULL; /* don't find files with same name */
+ state = SkipIt;
+ return 0;
+ } else {
+ memcpy(file_current, victim, count);
+ file_current += count;
+ body_len -= count;
+ eat(count);
+ return 1;
+ }
+}
+#else
+#define do_copy_mem NULL
+#endif
+
static int __init do_copy(void)
{
if (count >= body_len) {
@@ -333,6 +378,7 @@ static __initdata int (*actions[])(void) = {
[SkipIt] = do_skip,
[GotName] = do_name,
[CopyFile] = do_copy,
+ [CopyFileMem] = do_copy_mem,
[GotSymlink] = do_symlink,
[Reset] = do_reset,
};
@@ -578,3 +624,31 @@ static int __init populate_rootfs(void)
return 0;
}
rootfs_initcall(populate_rootfs);
+
+#ifdef CONFIG_ACPI_CUSTOM_DSDT_INITRD
+struct acpi_table_header *acpi_find_dsdt_initrd(void)
+{
+ char *err, *ramfs_dsdt_name = "DSDT.aml";
+
+ printk(KERN_INFO "ACPI: Checking initramfs for custom DSDT\n");
+ file_mem = NULL;
+ file_looked_for = ramfs_dsdt_name;
+ err = unpack_to_rootfs((char *)initrd_start,
+ initrd_end - initrd_start, 1);
+ file_looked_for = NULL;
+
+ if (err) {
+ /*
+ * Even if reading the DSDT file was successful,
+ * we give up if the initramfs cannot be entirely read.
+ */
+ kfree(file_mem);
+ printk(KERN_ERR "ACPI: Aborded because %s.\n", err);
+ return NULL;
+ }
+ if (file_mem)
+ printk(KERN_INFO "ACPI: Found DSDT in %s.\n", ramfs_dsdt_name);
+
+ return file_mem;
+}
+#endif
--
1.5.4.3
next prev parent reply other threads:[~2008-04-18 23:26 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4798E2A5.6020804@users.sf.net>
[not found] ` <20080125063328.4e3b4752.akpm@linux-foundation.org>
2008-01-26 4:39 ` initrd DSDT override (Re: Feedback about your talk in Rennes France (20080124) : Evolution of the Linux kernel & virtualization technologies) Len Brown
2008-01-30 17:27 ` [PATCH] Override DSDT and SSDTs via initramfs Thomas Renninger
2008-01-30 22:36 ` Éric Piel
2008-01-31 19:17 ` Len Brown
2008-02-01 9:53 ` Thomas Renninger
2008-02-01 11:07 ` Alexey Starikovskiy
2008-02-01 11:29 ` Thomas Renninger
2008-02-02 4:36 ` Len Brown
2008-02-03 17:28 ` [PATCH 0/3] Override DSDT " Éric Piel
2008-02-04 17:53 ` Thomas Renninger
2008-02-04 22:57 ` Éric Piel
2008-02-07 0:15 ` Len Brown
2008-02-07 0:23 ` Éric Piel
2008-02-07 1:07 ` Len Brown
2008-02-07 1:12 ` initrd DSDT override patch series Len Brown
2008-02-07 1:12 ` [PATCH] ACPI: basic initramfs DSDT override support Len Brown
2008-02-07 1:12 ` [PATCH] ACPI: Taint kernel on ACPI table override (format corrected) Len Brown
2008-02-07 1:12 ` [PATCH] ACPI: Add "acpi_no_initrd_override" kernel parameter Len Brown
2008-02-07 1:12 ` [PATCH] ACPI: update DSDT override documentation Len Brown
2008-02-07 1:12 ` [PATCH] ACPI: update intrd DSDT override console messages Len Brown
2008-02-03 17:28 ` [PATCH 1/3] The basics of DSDT from initramfs Éric Piel
2008-02-03 17:39 ` Markus Gaugusch
2008-02-03 17:55 ` Éric Piel
2008-02-04 23:04 ` [PATCH 1/3] The basics of DSDT from initramfs (format corrected) Éric Piel
2008-02-06 23:54 ` Len Brown
2008-02-05 14:43 ` [PATCH 1/3] The basics of DSDT from initramfs Thomas Renninger
2008-02-05 14:56 ` Carlos Corbacho
2008-02-03 17:29 ` [PATCH 2/3] Taint kernel on ACPI table override Éric Piel
2008-02-04 23:04 ` [PATCH 2/3] Taint kernel on ACPI table override (format corrected) Éric Piel
2008-02-03 17:29 ` [PATCH 3/3] Add acpi_no_initrd_override kernel parameter Éric Piel
2008-02-04 23:04 ` [PATCH 3/3] Add acpi_no_initrd_override kernel parameter (format corrected) Éric Piel
2008-02-01 10:21 ` [PATCH] Override DSDT and SSDTs via initramfs Thomas Renninger
2008-02-01 10:38 ` Eric Piel
2008-02-07 2:51 ` Len Brown
2008-02-07 7:57 ` Éric Piel
2008-04-18 22:07 ` Philippe Coval
2008-04-18 23:25 ` Eric Piel [this message]
2008-02-07 2:49 ` Len Brown
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=48092DFE.70101@tremplin-utc.net \
--to=eric.piel@tremplin-utc.net \
--cc=akpm@linux-foundation.org \
--cc=dsdt@gaugusch.at \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=rzr@users.sf.net \
--cc=trenn@suse.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.