Early cpio decoder and ACPI table override via initrd making use of it
Subsystems (4)
This is based on the early cpio decoder from hpa.
The first patch is exactly the patch (41750d31fc9599fd81763e685) from git repo:kernel/git/hpa/linux-earlyinitramfs. Ony the Makefile was slightly adjusted to latest Linus kernel (3.6.0-rc3).
Because of the special requirements hpa mentioned, I gave up the cleaner callback approach. It may make sense to revive it if there are potential more users and let the very early code call the cpio decoder directly and let others use the callback interface I had made up.
Anyway, it would be great to see these two patches showing up in a mainline branch and linux-next asap, so that they can slip in with the next (3.7) merge window.
Working on ACPI features or debugging ACPI problems is a nightmare on Linux currently. ACPI table overrding via initrd makes working on such problems a lot easier.
Thomas
PATCH 1/2 lib: Add early cpio decoder
From: "H. Peter Anvin" <[email protected]>
Add a simple cpio decoder without library dependencies for the purpose of extracting components from the initramfs blob for early kernel uses. Intended consumers so far are microcode and ACPI override.
--- include/linux/earlycpio.h | 13 ++++ lib/Makefile | 2 +- lib/earlycpio.c | 173 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+), 1 deletions(-) create mode 100644 include/linux/earlycpio.h create mode 100644 lib/earlycpio.c
include/linux/earlycpio.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef _LINUX_EARLYCPIO_H +#define _LINUX_EARLYCPIO_H + +#include <linux/types.h> + +struct cpio_data { +void *data; +size_t size; +}; + +struct cpio_data find_cpio_data (const char *name,const void *data,size_t len); + +#endif /* _LINUX_EARLYCPIO_H */
lib/Makefile +1 -1
@@ -12,7 +12,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ idr.o int_sqrt.o extable.o prio_tree.o \ sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \ proportions.o flex_proportions.o prio_heap.o ratelimit.o show_mem.o \ - is_single_threaded.o plist.o decompress.o + is_single_threaded.o plist.o decompress.o earlycpio.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.o
lib/earlycpio.c new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
1.7.6.1
PATCH 2/2 ACPI: Override arbitrary ACPI tables via initrd for debugging
In reply to Thomas RenningerDetails can be found in:Documentation/acpi/initrd_table_override.txt
--- Documentation/acpi/initrd_table_override.txt | 122 ++++++++++++++++ arch/x86/kernel/setup.c | 4 + drivers/acpi/Kconfig | 9 ++ drivers/acpi/osl.c | 200 ++++++++++++++++++++++++-- include/linux/acpi.h | 4 + 5 files changed, 328 insertions(+), 11 deletions(-) create mode 100644 Documentation/acpi/initrd_table_override.txt
Documentation/acpi/initrd_table_override.txt new file +122 -0
@@ -0,0 +1,122 @@ +Overriding ACPI tables via initrd +================================= + +1) Introduction (What is this about) +2) What is this for +3) How does it work +4) References (Where to retrieve userspace tools) + +1) What is this about +--------------------- + +If ACPI_INITRD_TABLE_OVERRIDE compile option is true, it is possible to +override nearly any ACPI table provided by the BIOS with an instrumented, +modified one. + +For a full list of ACPI tables that can be overridden, take a look at +the char *table_sigs[MAX_ACPI_SIGNATURE]; definition in drivers/acpi/osl.c +All ACPI tables iasl (Intel's ACPI compiler and disassembler) knows should +be overridable, except: + - ACPI_SIG_RSDP (has a signature of 6 bytes) + - ACPI_SIG_FACS (does not have an ordinary ACPI table header) +Both could get implemented as well. + + +2) What is this for +------------------- + +Please keep in mind that this is a debug option. +ACPI tables should not get overridden for productive use. +If BIOS ACPI tables are overridden the kernel will get tainted with the +TAINT_OVERRIDDEN_ACPI_TABLE flag. +Complain to your platform/BIOS vendor if you find a bug which is that sever +that a workaround is not accepted in the Linus kernel. + +Still, it can and should be enabled in any kernel, because: + - There is no functional change with not instrumented initrds + - It provides a powerful feature to easily debug and test ACPI BIOS table + compatibility with the Linux kernel. + +Until now it was only possible to override the DSDT by compiling it into +the kernel. This is a nightmare when trying to work on ACPI related bugs +and a lot bugs got stuck because of that. +Even for people with enough kernel knowledge, building a kernel to try out +things is very time consuming. Also people may have to browse and modify the +ACPI interpreter code to find a possible BIOS bug. With this feature, people +can correct the ACPI tables and try out quickly whether this is the root cause +that needs to get addressed in the kernel. + +This could even ease up testing for BIOS providers who could flush their BIOS +to test, but overriding table via initrd is much easier and quicker. +For example one could prepare different initrds overriding NUMA tables with +different affinity settings. Set up a script, let the machine reboot and +run tests over night and one can get a picture how these settings influence +the Linux kernel and which values are best. + +People can instrument the dynamic ACPI (ASL) code (for example with debug +statements showing up in syslog when the ACPI code is processed, etc.), +to better understand BIOS to OS interfaces, to hunt down ACPI BIOS code related +bugs quickly or to easier develop ACPI based drivers. + +Intstrumenting ACPI code in SSDTs is now much easier. Before, one had to copy +all SSDTs into the DSDT to compile it into the kernel for testing +(because only DSDT could get overridden). That's what the acpi_no_auto_ssdt +boot param is for: the BIOS provided SSDTs are ignored and all have to get +copied into the DSDT, complicated and time consuming. + +Much more use cases, depending on which ACPI parts you are working on... + + +3) How does it work +------------------- + +# Extract the machine's ACPI tables: +cd /tmp +acpidump >acpidump +acpixtract -a acpidump +# Disassemble, modify and recompile them: +iasl -d *.dat +# For example add this statement into a _PRT (PCI Routing Table) function +# of the DSDT: +Store("HELLO WORLD", debug) +iasl -sa DSDT.dsl +# Add the raw ACPI tables to an uncompressed cpio archive. +# They must be put into /kernel/firmware/acpi/table[0-9].dat files inside the +# cpio archive. Starting with table0.dat +# The one uncompressed cpio archive and it must be the first. +# Other, typically compressed cpio archives, must be +# concatenated on top of the uncompressed one. +mkdir -p kernel/firmware/acpi +cp DSDT.aml kernel/firmware/acpi/table0.dat +# Add other ACPI tables, the filename's number must increase in order +# A maximum of ten tables (table9.dat) are allowed: +iasl -sa FACP.dsl +iasl -sa SSDT1.dsl +cp FACP.aml kernel/firmware/acpi/table1.dat +cp SSDT1.aml kernel/firmware/acpi/table2.dat +# Create the uncompressed cpio archive and concatenate the orginal initrd +# on top: +find kernel | cpio -H newc --create > /boot/instrumented_initrd +cat /boot/initrd >>/boot/instrumented_initrd +# reboot with increased acpi debug level, e.g. boot params: +acpi.debug_level=0x2 acpi.debug_layer=0xFFFFFFFF +# and check your syslog: +[ 1.268089] ACPI: PCI Interrupt Routing Table [\_SB_.PCI0._PRT] +[ 1.272091] [ACPI Debug] String [0x0B] "HELLO WORLD" + +iasl is able to disassemble and recompile quite a lot different, +also static ACPI tables. + +4) Where to retrieve userspace tools +------------------------------------ + +iasl and acpixtract are part of Intel's ACPICA project: +http://acpica.org/ +and should be packaged by distributions (for example in the acpica package +on SUSE). + +acpidump can be found in Len Browns pmtools: +ftp://kernel.org/pub/linux/kernel/people/lenb/acpi/utils/pmtools/acpidump +This tool is also part of the acpica package on SUSE. +Alternatively, used ACPI tables can be retrieved via sysfs in latest kernels: +/sys/firmware/acpi/tables
arch/x86/kernel/setup.c +4 -0
@@ -941,6 +941,10 @@ void __init setup_arch(char **cmdline_p)reserve_initrd (); +#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE +acpi_initrd_override ((void *)initrd_start, initrd_end - initrd_start); +#endif +reserve_crashkernel ();vsmp_init ();
drivers/acpi/Kconfig +9 -0
@@ -261,6 +261,15 @@ config ACPI_CUSTOM_DSDT bool default ACPI_CUSTOM_DSDT_FILE != "" +config ACPI_INITRD_TABLE_OVERRIDE + bool + default y + help + This option provides functionality to override arbitrary ACPI tables + via initrd. No functional change if no ACPI tables are passed via + initrd, therefore it's safe to say Y. + See Documentation/acpi/initrd_table_override.txt for details + config ACPI_BLACKLIST_YEAR int "Disable ACPI for systems before Jan 1st this year" if X86_32 default 0
drivers/acpi/osl.c +189 -11
219 lines not on this page · raw message
include/linux/acpi.h +4 -0
@@ -76,6 +76,10 @@ typedef int (*acpi_table_handler) (struct acpi_table_header *table);typedef int (*acpi_table_entry_handler ) (struct acpi_subtable_header *header,const unsigned long end); +#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE +void __init acpi_initrd_override (void *data,size_t size); +#endif +char *__acpi_map_table (unsigned long phys_addr,unsigned long size);void __acpi_unmap_table (char *map,unsigned long size);int early_acpi_boot_init (void );
Signature · 1 line
1.7.6.1
Re: [PATCH 2/2] ACPI: Override arbitrary ACPI tables via initrd for debugging
Quoted 7 lines · Thomas Renninger
Details can be found in:
Documentation/acpi/initrd_table_override.txtSigned-off-by Thomas Renninger <[email protected]>CC vojcek-wYtBgQxc//[email protected]CC Lin Ming <[email protected]>
Lin Ming's address is not valid anymore?:
<[email protected]>: host mga01.intel.com[192.55.52.88] said: 550 #5.1.0
Address rejected. (in reply to RCPT TO command)
Please remove it from CC list if you reply on one of these.
Would be great if it can get removed from CC list in the patch without the need of resending (if the patches are fine).
Thanks,
Thomas
H. Peter Anvin
reviewerRe: [PATCH 1/2] lib: Add early cpio decoder
In reply to Thomas RenningerQuoted 10 lines · Thomas Renninger
From: "H. Peter Anvin" <hpa-VuQAYsv1563Yd54FQh9/[email protected]>
Add a simple cpio decoder without library dependencies for the purpose of extracting components from the initramfs blob for early kernel uses. Intended consumers so far are microcode and ACPI override.
CC Thomas Renninger <[email protected]>Signed-off-by Thomas Renninger <[email protected]>
I was trying to figure out if there is a way to do what you want (support for multiple files) without the problems of the callback interface. I think it is actually fairly straightforward; we need a prefix iterator (so you can give it a string like "kernel/acpi/" rather than a full filename) and it needs to be able to accept a "last" pointer so it can resume scanning at the point it last left off. That should be a pretty trivial change.
The other thing we presumably want to do -- and this is generic -- is to be able to handle multiple sources for the initramfs; at the very least there is built in vs provided from the boot loader. I had originally intended to just handle that by calling the earlycpio function once per block, but the "last left off" bit makes that a little harder. Need to think about that a little bit.
I am guessing that this may not need to be something we need from the very beginning, or am I wrong?
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH 1/2] lib: Add early cpio decoder
Quoted 12 lines · H. Peter Anvin
Quoted 10 lines · Thomas Renninger
From: "H. Peter Anvin" <[email protected]>
Add a simple cpio decoder without library dependencies for the purpose of extracting components from the initramfs blob for early kernel uses. Intended consumers so far are microcode and ACPI override.
Signed-off-by H. Peter Anvin <[email protected]>CC Thomas Renninger <[email protected]>Signed-off-by Thomas Renninger <[email protected]>
Quoted 7 lines
I was trying to figure out if there is a way to do what you want (support for multiple files) without the problems of the callback interface. I think it is actually fairly straightforward; we need a prefix iterator (so you can give it a string like "
kernel/acpi/" rather than a full filename) and it needs to be able to accept a "last" pointer so it can resume scanning at the point it last left off. That should be a pretty trivial change.
Yep, this is a good idea.
Quoted 6 lines
The other thing we presumably want to do -- and this is generic -- is to be able to handle multiple sources for the initramfs; at the very least there is built in vs provided from the boot loader. I had originally intended to just handle that by calling the earlycpio function once per block, but the "last left off" bit makes that a little harder. Need to think about that a little bit.
I guess I understand the first part, not sure about the "last left off" bit.
"Multiple sources" means bootloader already points to multiple sources, right?
This is somewhat out of scope as this would need both, bootloader and kernel adjustings.
This is about "built in" which means multiple cpios concatenated together and passed via bootloader as one "file" (initrd).
At least I understand it that way.
The only disadvantage I run into is that once the cpios are concatenated, I couldn't figure out an easy way how to slice them into separate cpio/zip archives again.
Quoted 2 lines
I am guessing that this may not need to be something we need from the very beginning, or am I wrong?
I have re-worked the patches:
- added an offset argument to be able to iterate over files inside a directory as suggested
- removed the strlen and memcmp function duplication in earlycpio.c This is not needed for this patchset and would be confusing. This can easily be added in the context of the patches which need it
I'll re-submit.
Thanks,
Thomas
Re: [PATCH 1/2] lib: Add early cpio decoder
Quoted 4 lines · Thomas Renninger
I guess I understand the first part, not sure about the "last left off" bit.
"Multiple sources" means bootloader already points to multiple sources, right?
Quoted 8 lines
This is somewhat out of scope as this would need both, bootloader and kernel adjustings.
This is about "built in" which means multiple cpios concatenated together and passed via bootloader as one "file" (initrd).
At least I understand it that way.
The only disadvantage I run into is that once the cpios are concatenated, I couldn't figure out an easy way how to slice them into separate cpio/zip archives again.
No, that's not the issue.
The issue is that there isn't just one initramfs blob, there are (currently) *TWO*... one loaded by the bootloader and one compiled into the kernel.
-hpa