Skip to contentSkip to conversation

Override arbitrary ACPI tables via initrd

PATCH New Thomas Renninger 1 participant 3 messages Nov 4, 2011

Subsystems (5)
Documentation x86 ACPI x86 MM +1 more subsystems
lore
Share & tools
lore
#0 lore raw

This patch is a resend with a tiny fix which came up in the last thread incorporated.

The first patch needs to go into ACPICA sources as well.

Both patches are in the latest SUSE factory kernel for a while and will show up in openSUSE 12.1.

It would be great to see these queued up for 3.2.

Thanks,

Thomas

#1 lore raw

PATCH 1/2 ACPICA: Introduce acpi_os_phys_table_override function V2

Currently it's only possible to feed acpica with virtual address for table overriding.
This patch introduces a function which allows the OS to pass physical addresses for table overriding.

This is necessary to allow early table overridings of arbitrary ACPI tables.

An extra flag like ACPI_TABLE_ORIGIN_OVERRIDE is not used, because physical address overriding is rather transparent (the same way acpica expects to get tables from reserved memory BIOS regions which is the normal way).

V2: Includes a fix from Michael Chang:
Fix wrongly mapped acpi table header when overriding via initrd

Signed-off-by Thomas Renninger <trenn(a)suse.de>
CC devel(a)acpica.org
CC lenb(a)kernel.org
CC VoJcEK <vojcek(a)tlen.pl>
CC Markus <dsdt(a)gaugusch.at>
CC eric(a)gaugusch.at
CC Michael Chang <mchang(a)suse.com>
CC ming.m.lin(a)intel.com
---
 drivers/acpi/acpica/tbinstal.c |   15 +++++++++++++++
 drivers/acpi/acpica/tbutils.c  |   18 +++++++++++++++++-
 drivers/acpi/osl.c             |   11 +++++++++++
 include/acpi/acpiosxf.h        |    4 ++++
 4 files changed, 47 insertions(+), 1 deletions(-)
drivers/acpi/acpica/tbinstal.c +15 -0
index 62365f6..b9b9d2a 100644
@@ -242,6 +242,21 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
 		table_desc->pointer = override_table;
 		table_desc->length = override_table->length;
 		table_desc->flags = ACPI_TABLE_ORIGIN_OVERRIDE;
+	} else {
+		acpi_physical_address address = 0;
+		u32 table_len = 0;
+		status = acpi_os_phys_table_override(table_desc->pointer,
+						     &address, &table_len);
+		if (ACPI_SUCCESS(status) && table_len && address) {
+			ACPI_INFO((AE_INFO, "%4.4s @ 0x%p "
+				   "Phys table override, replaced with:",
+				   table_desc->pointer->signature,
+				   ACPI_CAST_PTR(void, table_desc->address)));
+			table_desc->address = address;
+			table_desc->pointer = acpi_os_map_memory(address,
+								 table_len);
+			table_desc->length = table_len;
+		}
 	}
 
 	/* Add the table to the global root table list */
drivers/acpi/acpica/tbutils.c +17 -1
index 0f2d395..2e797d9 100644
@@ -499,8 +499,24 @@ acpi_tb_install_table(acpi_physical_address address,
 		table_to_install = override_table;
 		flags = ACPI_TABLE_ORIGIN_OVERRIDE;
 	} else {
-		table_to_install = mapped_table;
+		u32 table_len = 0;
+		acpi_physical_address tmp_addr = 0;
+
+		status = acpi_os_phys_table_override(mapped_table,
+						     &tmp_addr, &table_len);
+		if (ACPI_SUCCESS(status) && table_len && tmp_addr) {
+			ACPI_INFO((AE_INFO, "%4.4s @ 0x%p "
+				   "Phys table override, replaced with:",
+				   mapped_table->signature,
+				   ACPI_CAST_PTR(void, address)));
+			acpi_os_unmap_memory(mapped_table,
+					     sizeof(struct acpi_table_header));
+			address = tmp_addr;
+			mapped_table = acpi_os_map_memory(address,
+					  sizeof(struct acpi_table_header));
+		}
 		flags = ACPI_TABLE_ORIGIN_MAPPED;
+		table_to_install = mapped_table;
 	}
 
 	/* Initialize the table entry */
drivers/acpi/osl.c +11 -0
index f31c5c5..099a3a6 100644
@@ -523,6 +523,17 @@ acpi_os_table_override(struct acpi_table_header * existing_table,
 	return AE_OK;
 }
 
+acpi_status
+acpi_os_phys_table_override(struct acpi_table_header *existing_table,
+			    acpi_physical_address *address, u32 *table_length)
+{
+	if (!existing_table)
+		return AE_BAD_PARAMETER;
+
+	table_length = 0;
+	return AE_OK;
+}
+
 static irqreturn_t acpi_irq(int irq, void *dev_id)
 {
 	u32 handled;
include/acpi/acpiosxf.h +4 -0
index 83062ed..a56a811 100644
@@ -95,6 +95,10 @@ acpi_status
 acpi_os_table_override(struct acpi_table_header *existing_table,
 		       struct acpi_table_header **new_table);
 
+acpi_status
+acpi_os_phys_table_override(struct acpi_table_header *existing_table,
+			    acpi_physical_address *address, u32 *table_length);
+
 /*
  * Spinlock primitives
  */
Signature · 1 line
1.7.6.1
#2 lore raw

PATCH 2/2 ACPI: Implement overriding of arbitrary ACPI tables via initrd

In reply to Thomas Renninger

Details can be found in:
Documentation/acpi/initrd_table_override.txt

Additional dmesg output of a booted system with FACP (FADT), DSDT and SSDT (the 9th dynamically loaded one) tables overridden (with ### marked comments):

### ACPI tables found glued to initrd
DSDT ACPI table found in initrd - size: 16234
FACP ACPI table found in initrd - size: 116
SSDT ACPI table found in initrd - size: 334
### Re-printed e820 map via e820_update() with additionally created ### ACPI data section at 0xcff55000 where the ACPI tables passed via ### initrd where copied to
modified physical RAM map:
...
### New ACPI data section:
modified: 00000000cff55000 - 00000000cff5912c (ACPI data)
### BIOS e820 provided ACPI data section:
modified: 00000000cff60000 - 00000000cff69000 (ACPI data)
...
### Total size of all ACPI tables glued to initrd
### The address is initrd_start which gets updated to
### initrd_start = initrd_start + "size of all ACPI tables glued to initrd" Found acpi tables of size: 16684 at 0xffff8800374c4000

Disabling lock debugging due to kernel taint
### initrd provided FACP and DSDT tables are used instead of BIOS provided ones
ACPI: FACP @ 0x00000000cff68dd8 Phys table override, replaced with:
ACPI: FACP 00000000cff58f6a 00074 (v01 INTEL TUMWATER 06040000 PTL 00000003)
ACPI: DSDT @ 0x00000000cff649d4 Phys table override, replaced with:
ACPI: DSDT 00000000cff55000 04404 (v01 Intel BLAKFORD 06040000 MSFT 0100000E)
...
### Much later, the 9th (/sys/firmware/acpi/table/dynamic/SSDT9) dynamically ### loaded ACPI table matches and gets overridden:
ACPI: SSDT @ 0x00000000cff64824 Phys table override, replaced with:
ACPI: SSDT 00000000cff58fde 0014E (v01 PmRef Cpu7Ist 00003000 INTL 20110316)
ACPI: Dynamic OEM Table Load:
ACPI: SSDT (null) 0014E (v01 PmRef Cpu7Ist 00003000 INTL 20110316)
...

If the initrd does not start with a valid ACPI table signature or the ACPI table's checksum is wrong, there is no functional change.

Modified *.dat to *.aml in the documentation file as this is what iasl compiler produces -> suggested by Joey Lee.

---
 Documentation/acpi/initrd_table_override.txt |  121 +++++++++++++++++++++
 arch/x86/kernel/setup.c                      |   18 +++-
 arch/x86/mm/init.c                           |    6 +
 drivers/acpi/Kconfig                         |   10 ++
 drivers/acpi/osl.c                           |  150 +++++++++++++++++++++++++-
 include/linux/acpi.h                         |    4 +
 include/linux/initrd.h                       |    3 +
 7 files changed, 304 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/acpi/initrd_table_override.txt
Documentation/acpi/initrd_table_override.txt new file +121 -0
new file mode 100644
index 0000000..52118e9
@@ -0,0 +1,121 @@
+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.
+
+Up to 10 arbitrary ACPI tables can be passed.
+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:
+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 *.dsl
+# glue the modified and re-compiled tables together with the initrd.
+# ACPI tables go first, original initrd goes on top:
+cat TBL1.aml >>instrumented_initrd
+cat TBL2.aml >>instrumented_initrd
+cat TBL3.aml >>instrumented_initrd
+cat /boot/initrd >>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. FACS and RSDP tables are special and do not
+work. When the patches were added, these ACPI tables can be overridden
+(not all got tested):
+ASF , BERT, BOOT, CPEP, DBGP, DMAR, DSDT, ECDT, EINJ, ERST,
+FADT, HEST, HPET, IBFT, IVRS, MADT, MCFG, MCHI, MSCT, PSDT,
+RSDT, SBST, SLIT, SLIC, SRAT, SPCR, SPMI, SSDT, TCPA, UEFI,
+WAET, WDAT, WDDT, WDRT, XSDT
+
+
+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, ACPI tables can be retrieved via sysfs in latest kernels:
+/sys/firmware/acpi/tables
+
+For further questions ask on the [email protected] list
+
+Thomas Renninger <[email protected]> (SUSE Linux Product GmbH, 2011)
arch/x86/kernel/setup.c +13 -5
index afaf384..9fe9aa5 100644
@@ -411,12 +411,20 @@ static void __init reserve_initrd(void)
 		 */
 		initrd_start = ramdisk_image + PAGE_OFFSET;
 		initrd_end = initrd_start + ramdisk_size;
-		return;
+	} else {
+		relocate_initrd();
+		memblock_x86_free_range(ramdisk_image, ramdisk_end);
 	}
-
-	relocate_initrd();
-
-	memblock_x86_free_range(ramdisk_image, ramdisk_end);
+#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
+	acpi_initrd_offset = acpi_initrd_table_override((void *)initrd_start,
+							(void *)initrd_end);
+	if (!acpi_initrd_offset)
+		return;
+	printk(KERN_INFO "Found acpi tables of size: %lu at 0x%lx\n",
+	       acpi_initrd_offset, initrd_start);
+	initrd_start += acpi_initrd_offset;
+	return;
+#endif
 }
 #else
 static void __init reserve_initrd(void)
arch/x86/mm/init.c +6 -0
index 87488b9..4a42745 100644
@@ -389,6 +389,12 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 	 *   - relocate_initrd()
 	 * So here We can do PAGE_ALIGN() safely to get partial page to be freed
 	 */
+#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
+	if (acpi_initrd_offset)
+		free_init_pages("initrd memory", start - acpi_initrd_offset,
+				PAGE_ALIGN(end));
+	else
+#endif
 	free_init_pages("initrd memory", start, PAGE_ALIGN(end));
 }
 #endif
drivers/acpi/Kconfig +10 -0
index de0e3df..3e0ee1a 100644
@@ -261,6 +261,16 @@ config ACPI_CUSTOM_DSDT
 	bool
 	default ACPI_CUSTOM_DSDT_FILE != ""
 
+config ACPI_INITRD_TABLE_OVERRIDE
+	bool
+	depends on X86
+	default y
+	help
+	  This option provides functionality to override arbitrary ACPI tables
+	  via initrd. No functional change if no ACPI tables are glued to the
+	  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 +147 -3

170 lines not on this page · raw message

include/linux/acpi.h +4 -0
index 6001b4da..adc87ec 100644
@@ -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
+int __init acpi_initrd_table_override(void *start_addr, void *end_addr);
+#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);
include/linux/initrd.h +3 -0
index 55289d2..c7694d9 100644
@@ -16,5 +16,8 @@ extern int initrd_below_start_ok;
 /* free_initrd_mem always gets called with the next two as arguments.. */
 extern unsigned long initrd_start, initrd_end;
 extern void free_initrd_mem(unsigned long, unsigned long);
+#ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
+extern unsigned long acpi_initrd_offset;
+#endif
 
 extern unsigned int real_root_dev;
Signature · 1 line
1.7.6.1