2018-10-09 10:56:14

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v4 0/3] x86: make rsdp address accessible via boot params

In the non-EFI boot path the ACPI RSDP table is currently found via
either EBDA or by searching through low memory for the RSDP magic.
This requires the RSDP to be located in the first 1MB of physical
memory. Xen PVH guests, however, get the RSDP address via the start of
day information block.

In order to support an arbitrary RSDP address this patch series adds
the physical address of the RSDP to the boot params structure filled
by the boot loader.

Juergen Gross (3):
x86/xen: fix boot loader version reported for pvh guests
x86/boot: add acpi rsdp address to setup_header
x86/acpi: take rsdp address for boot params if available

Documentation/x86/boot.txt | 32 +++++++++++++++++++++++++++++++-
arch/x86/boot/header.S | 6 +++++-
arch/x86/include/asm/acpi.h | 2 ++
arch/x86/include/asm/x86_init.h | 2 ++
arch/x86/include/uapi/asm/bootparam.h | 4 ++++
arch/x86/kernel/acpi/boot.c | 6 ++++++
arch/x86/kernel/head32.c | 1 +
arch/x86/kernel/head64.c | 2 ++
arch/x86/kernel/setup.c | 17 +++++++++++++++++
arch/x86/kernel/x86_init.c | 3 +--
arch/x86/xen/enlighten_pvh.c | 2 +-
11 files changed, 72 insertions(+), 5 deletions(-)

--
2.16.4



2018-10-09 10:55:38

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v4 3/3] x86/acpi: take rsdp address for boot params if available

In case the rsdp address in struct boot_params is specified don't try
to find the table by searching, but take the address directly as set
by the boot loader.

Signed-off-by: Juergen Gross <[email protected]>
---
V3: use a generic retrieval function with a __weak annotated default
function (Ingo Molnar)

V4: check boot params version before using acpi_rsdp_addr
use x86_init structure instead of __weak
---
arch/x86/include/asm/acpi.h | 2 ++
arch/x86/kernel/acpi/boot.c | 6 ++++++
arch/x86/kernel/x86_init.c | 3 +--
3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/acpi.h b/arch/x86/include/asm/acpi.h
index a303d7b7d763..e9057ebff76c 100644
--- a/arch/x86/include/asm/acpi.h
+++ b/arch/x86/include/asm/acpi.h
@@ -142,6 +142,8 @@ static inline u64 acpi_arch_get_root_pointer(void)

void acpi_generic_reduced_hw_init(void);

+u64 x86_default_get_root_pointer(void);
+
#else /* !CONFIG_ACPI */

#define acpi_lapic 0
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 3b20607d581b..e8fea7ffa306 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -48,6 +48,7 @@
#include <asm/mpspec.h>
#include <asm/smp.h>
#include <asm/i8259.h>
+#include <asm/setup.h>

#include "sleep.h" /* To include x86_acpi_suspend_lowlevel */
static int __initdata acpi_force = 0;
@@ -1771,3 +1772,8 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
e820__range_add(addr, size, E820_TYPE_ACPI);
e820__update_table_print();
}
+
+u64 x86_default_get_root_pointer(void)
+{
+ return boot_params.hdr.acpi_rsdp_addr;
+}
diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
index 2792b5573818..50a2b492fdd6 100644
--- a/arch/x86/kernel/x86_init.c
+++ b/arch/x86/kernel/x86_init.c
@@ -31,7 +31,6 @@ static int __init iommu_init_noop(void) { return 0; }
static void iommu_shutdown_noop(void) { }
static bool __init bool_x86_init_noop(void) { return false; }
static void x86_op_int_noop(int cpu) { }
-static u64 u64_x86_init_noop(void) { return 0; }

/*
* The platform setup functions are preset with the default functions
@@ -96,7 +95,7 @@ struct x86_init_ops x86_init __initdata = {
},

.acpi = {
- .get_root_pointer = u64_x86_init_noop,
+ .get_root_pointer = x86_default_get_root_pointer,
.reduced_hw_early_init = acpi_generic_reduced_hw_init,
},
};
--
2.16.4


2018-10-09 10:55:39

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v4 2/3] x86/boot: add acpi rsdp address to setup_header

Xen PVH guests receive the address of the RSDP table from Xen. In order
to support booting a Xen PVH guest via Grub2 using the standard x86
boot entry we need a way for Grub2 to pass the RSDP address to the
kernel.

For this purpose expand the struct setup_header to hold the physical
address of the RSDP address. Being zero means it isn't specified and
has to be located the legacy way (searching through low memory or
EBDA).

While documenting the new setup_header layout and protocol version
2.14 add the missing documentation of protocol version 2.13.

There are grub2 versions in several distros with a downstream patch
violating the boot protocol by writing past the end of setup_header.
This requires another update of the boot protocol to enable the kernel
to distinguish between a specified RSDP address and one filled with
garbage by such a broken grub2.

From protocol 2.14 on grub2 will write the version it is supporting
(but never a higher value than found to be supported by the kernel)
ored with 0x8000 to the version field of setup_header. This enables
the kernel to know up to which field grub2 has written information
to. All fields after that are supposed to be clobbered.

Signed-off-by: Juergen Gross <[email protected]>
---
V3: fix commit message and some documentation bits (Ingo Molnar)

V4: add version feedback from bootloader
---
Documentation/x86/boot.txt | 32 +++++++++++++++++++++++++++++++-
arch/x86/boot/header.S | 6 +++++-
arch/x86/include/asm/x86_init.h | 2 ++
arch/x86/include/uapi/asm/bootparam.h | 4 ++++
arch/x86/kernel/head32.c | 1 +
arch/x86/kernel/head64.c | 2 ++
arch/x86/kernel/setup.c | 17 +++++++++++++++++
7 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt
index 5e9b826b5f62..c8f8d7e7a60c 100644
--- a/Documentation/x86/boot.txt
+++ b/Documentation/x86/boot.txt
@@ -61,6 +61,18 @@ Protocol 2.12: (Kernel 3.8) Added the xloadflags field and extension fields
to struct boot_params for loading bzImage and ramdisk
above 4G in 64bit.

+Protocol 2.13: (Kernel 3.14) Support 32- and 64-bit flags being set in
+ xloadflags to support booting a 64-bit kernel from 32-bit
+ EFI
+
+Protocol 2.14: (Kernel 4.20) Added acpi_rsdp_addr holding the physical
+ address of the ACPI RSDP table.
+ The bootloader updates version with:
+ 0x8000 | min(kernel-version, bootloader-version)
+ kernel-version being the protocol version supported by
+ the kernel and bootloader-version the protocol version
+ supported by the bootloader.
+
**** MEMORY LAYOUT

The traditional memory map for the kernel loader, used for Image or
@@ -197,6 +209,7 @@ Offset Proto Name Meaning
0258/8 2.10+ pref_address Preferred loading address
0260/4 2.10+ init_size Linear memory required during initialization
0264/4 2.11+ handover_offset Offset of handover entry point
+0268/8 2.14+ acpi_rsdp_addr Physical address of RSDP table

(1) For backwards compatibility, if the setup_sects field contains 0, the
real value is 4.
@@ -309,7 +322,7 @@ Protocol: 2.00+
Contains the magic number "HdrS" (0x53726448).

Field name: version
-Type: read
+Type: modify
Offset/size: 0x206/2
Protocol: 2.00+

@@ -317,6 +330,12 @@ Protocol: 2.00+
e.g. 0x0204 for version 2.04, and 0x0a11 for a hypothetical version
10.17.

+ Up to protocol version 2.13 this information is only read by the
+ bootloader. From protocol version 2.14 onwards the bootloader will
+ write the used protocol version ored with 0x8000 to the field. The
+ used protocol version will be the minimum of the supported protocol
+ versions of the bootloader and the kernel.
+
Field name: realmode_swtch
Type: modify (optional)
Offset/size: 0x208/4
@@ -744,6 +763,17 @@ Offset/size: 0x264/4

See EFI HANDOVER PROTOCOL below for more details.

+Field name: acpi_rsdp_addr
+Type: write
+Offset/size: 0x268/8
+Protocol: 2.14+
+
+ This field can be set by the boot loader to tell the kernel the
+ physical address of the ACPI RSDP table.
+
+ A value of 0 indicates the kernel should fall back to the standard
+ methods to locate the RSDP.
+

**** THE IMAGE CHECKSUM

diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index 850b8762e889..4c881c850125 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -300,7 +300,7 @@ _start:
# Part 2 of the header, from the old setup.S

.ascii "HdrS" # header signature
- .word 0x020d # header version number (>= 0x0105)
+ .word 0x020e # header version number (>= 0x0105)
# or else old loadlin-1.5 will fail)
.globl realmode_swtch
realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
@@ -558,6 +558,10 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
init_size: .long INIT_SIZE # kernel initialization size
handover_offset: .long 0 # Filled in by build.c

+acpi_rsdp_addr: .quad 0 # 64-bit physical pointer to the
+ # ACPI RSDP table, added with
+ # version 2.14
+
# End of setup header #####################################################

.section ".entrytext", "ax"
diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
index b85a7c54c6a1..0f842104862c 100644
--- a/arch/x86/include/asm/x86_init.h
+++ b/arch/x86/include/asm/x86_init.h
@@ -303,4 +303,6 @@ extern void x86_init_noop(void);
extern void x86_init_uint_noop(unsigned int unused);
extern bool x86_pnpbios_disabled(void);

+void x86_verify_bootdata_version(void);
+
#endif
diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h
index a06cbf019744..22f89d040ddd 100644
--- a/arch/x86/include/uapi/asm/bootparam.h
+++ b/arch/x86/include/uapi/asm/bootparam.h
@@ -16,6 +16,9 @@
#define RAMDISK_PROMPT_FLAG 0x8000
#define RAMDISK_LOAD_FLAG 0x4000

+/* version flags */
+#define VERSION_WRITTEN 0x8000
+
/* loadflags */
#define LOADED_HIGH (1<<0)
#define KASLR_FLAG (1<<1)
@@ -86,6 +89,7 @@ struct setup_header {
__u64 pref_address;
__u32 init_size;
__u32 handover_offset;
+ __u64 acpi_rsdp_addr;
} __attribute__((packed));

struct sys_desc_table {
diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
index ec6fefbfd3c0..76fa3b836598 100644
--- a/arch/x86/kernel/head32.c
+++ b/arch/x86/kernel/head32.c
@@ -37,6 +37,7 @@ asmlinkage __visible void __init i386_start_kernel(void)
cr4_init_shadow();

sanitize_boot_params(&boot_params);
+ x86_verify_bootdata_version();

x86_early_init_platform_quirks();

diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index ddee1f0870c4..5dc377dc9d7b 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -457,6 +457,8 @@ void __init x86_64_start_reservations(char *real_mode_data)
if (!boot_params.hdr.version)
copy_bootdata(__va(real_mode_data));

+ x86_verify_bootdata_version();
+
x86_early_init_platform_quirks();

switch (boot_params.hdr.hardware_subarch) {
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index b4866badb235..20321710efb4 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1281,6 +1281,23 @@ void __init setup_arch(char **cmdline_p)
unwind_init();
}

+/*
+ * From boot protocol 2.14 onwards we expect the bootloader to set the
+ * version to 0x8000 | <used version>. In case we find a version >= 2.14
+ * without the 0x8000 we assume the boot loader supports 2.13 only and
+ * reset the version accordingly. The 0x8000 flag is removed in any case.
+ */
+void __init x86_verify_bootdata_version(void)
+{
+ if (boot_params.hdr.version & VERSION_WRITTEN)
+ boot_params.hdr.version &= ~VERSION_WRITTEN;
+ else if (boot_params.hdr.version >= 0x020e)
+ boot_params.hdr.version = 0x020d;
+
+ if (boot_params.hdr.version < 0x020e)
+ boot_params.hdr.acpi_rsdp_addr = 0;
+}
+
#ifdef CONFIG_X86_32

static struct resource video_ram_resource = {
--
2.16.4


2018-10-09 10:56:26

by Jürgen Groß

[permalink] [raw]
Subject: [PATCH v4 1/3] x86/xen: fix boot loader version reported for pvh guests

The boot loader version reported via sysfs is wrong in case of the
kernel being booted via the Xen PVH boot entry. it should be 2.12
(0x020c), but it is reported to be 2.18 (0x0212).

As the current way to set the version is error prone use the more
readable variant (2 << 8) | 12.

Cc: <[email protected]> # 4.12
Signed-off-by: Juergen Gross <[email protected]>
---
arch/x86/xen/enlighten_pvh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/xen/enlighten_pvh.c b/arch/x86/xen/enlighten_pvh.c
index c85d1a88f476..f7f77023288a 100644
--- a/arch/x86/xen/enlighten_pvh.c
+++ b/arch/x86/xen/enlighten_pvh.c
@@ -75,7 +75,7 @@ static void __init init_pvh_bootparams(void)
* Version 2.12 supports Xen entry point but we will use default x86/PC
* environment (i.e. hardware_subarch 0).
*/
- pvh_bootparams.hdr.version = 0x212;
+ pvh_bootparams.hdr.version = (2 << 8) | 12;
pvh_bootparams.hdr.type_of_loader = (9 << 4) | 0; /* Xen loader */

x86_init.acpi.get_root_pointer = pvh_get_root_pointer;
--
2.16.4


2018-10-09 13:23:43

by Boris Ostrovsky

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] x86/acpi: take rsdp address for boot params if available

On 10/9/18 6:54 AM, Juergen Gross wrote:
> +
> +u64 x86_default_get_root_pointer(void)
> +{
> + return boot_params.hdr.acpi_rsdp_addr;
> +}


Should we then update init_pvh_bootparams() with

    pvh_bootparams.hdr.acpi_rsdp_addr = pvh_start_info.rsdp_paddr;

(and drop x86_init.acpi.get_root_pointer = pvh_get_root_pointer;) ?

-boris

> diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
> index 2792b5573818..50a2b492fdd6 100644
> --- a/arch/x86/kernel/x86_init.c
> +++ b/arch/x86/kernel/x86_init.c
> @@ -31,7 +31,6 @@ static int __init iommu_init_noop(void) { return 0; }
> static void iommu_shutdown_noop(void) { }
> static bool __init bool_x86_init_noop(void) { return false; }
> static void x86_op_int_noop(int cpu) { }
> -static u64 u64_x86_init_noop(void) { return 0; }
>
> /*
> * The platform setup functions are preset with the default functions
> @@ -96,7 +95,7 @@ struct x86_init_ops x86_init __initdata = {
> },
>
> .acpi = {
> - .get_root_pointer = u64_x86_init_noop,
> + .get_root_pointer = x86_default_get_root_pointer,
> .reduced_hw_early_init = acpi_generic_reduced_hw_init,
> },
> };


2018-10-09 13:30:28

by Jürgen Groß

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] x86/acpi: take rsdp address for boot params if available

On 09/10/2018 15:22, Boris Ostrovsky wrote:
> On 10/9/18 6:54 AM, Juergen Gross wrote:
>> +
>> +u64 x86_default_get_root_pointer(void)
>> +{
>> + return boot_params.hdr.acpi_rsdp_addr;
>> +}
>
>
> Should we then update init_pvh_bootparams() with
>
>     pvh_bootparams.hdr.acpi_rsdp_addr = pvh_start_info.rsdp_paddr;
>
> (and drop x86_init.acpi.get_root_pointer = pvh_get_root_pointer;) ?

I was planning to do this as a follow on patch.


Juergen

>
> -boris
>
>> diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
>> index 2792b5573818..50a2b492fdd6 100644
>> --- a/arch/x86/kernel/x86_init.c
>> +++ b/arch/x86/kernel/x86_init.c
>> @@ -31,7 +31,6 @@ static int __init iommu_init_noop(void) { return 0; }
>> static void iommu_shutdown_noop(void) { }
>> static bool __init bool_x86_init_noop(void) { return false; }
>> static void x86_op_int_noop(int cpu) { }
>> -static u64 u64_x86_init_noop(void) { return 0; }
>>
>> /*
>> * The platform setup functions are preset with the default functions
>> @@ -96,7 +95,7 @@ struct x86_init_ops x86_init __initdata = {
>> },
>>
>> .acpi = {
>> - .get_root_pointer = u64_x86_init_noop,
>> + .get_root_pointer = x86_default_get_root_pointer,
>> .reduced_hw_early_init = acpi_generic_reduced_hw_init,
>> },
>> };
>
>


2018-10-10 04:12:24

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v4 3/3] x86/acpi: take rsdp address for boot params if available

Hi Juergen,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on v4.19-rc7 next-20181009]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Juergen-Gross/x86-make-rsdp-address-accessible-via-boot-params/20181010-065806
config: i386-allnoconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386

All errors (new ones prefixed by >>):

>> arch/x86/kernel/x86_init.c:98:23: error: 'x86_default_get_root_pointer' undeclared here (not in a function); did you mean 'x86_default_pci_init_irq'?
.get_root_pointer = x86_default_get_root_pointer,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
x86_default_pci_init_irq

vim +98 arch/x86/kernel/x86_init.c

40
41 .resources = {
42 .probe_roms = probe_roms,
43 .reserve_resources = reserve_standard_io_resources,
44 .memory_setup = e820__memory_setup_default,
45 },
46
47 .mpparse = {
48 .mpc_record = x86_init_uint_noop,
49 .setup_ioapic_ids = x86_init_noop,
50 .mpc_apic_id = default_mpc_apic_id,
51 .smp_read_mpc_oem = default_smp_read_mpc_oem,
52 .mpc_oem_bus_info = default_mpc_oem_bus_info,
53 .find_smp_config = default_find_smp_config,
54 .get_smp_config = default_get_smp_config,
55 },
56
57 .irqs = {
58 .pre_vector_init = init_ISA_irqs,
59 .intr_init = native_init_IRQ,
60 .trap_init = x86_init_noop,
61 .intr_mode_init = apic_intr_mode_init
62 },
63
64 .oem = {
65 .arch_setup = x86_init_noop,
66 .banner = default_banner,
67 },
68
69 .paging = {
70 .pagetable_init = native_pagetable_init,
71 },
72
73 .timers = {
74 .setup_percpu_clockev = setup_boot_APIC_clock,
75 .timer_init = hpet_time_init,
76 .wallclock_init = x86_init_noop,
77 },
78
79 .iommu = {
80 .iommu_init = iommu_init_noop,
81 },
82
83 .pci = {
84 .init = x86_default_pci_init,
85 .init_irq = x86_default_pci_init_irq,
86 .fixup_irqs = x86_default_pci_fixup_irqs,
87 },
88
89 .hyper = {
90 .init_platform = x86_init_noop,
91 .guest_late_init = x86_init_noop,
92 .x2apic_available = bool_x86_init_noop,
93 .init_mem_mapping = x86_init_noop,
94 .init_after_bootmem = x86_init_noop,
95 },
96
97 .acpi = {
> 98 .get_root_pointer = x86_default_get_root_pointer,
99 .reduced_hw_early_init = acpi_generic_reduced_hw_init,
100 },
101 };
102

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation


Attachments:
(No filename) (2.99 kB)
.config.gz (6.42 kB)
Download all attachments