tools: Mark ACPI SDTs as NVS in the PVH build path
PATCH v2 1/1 tools: Mark ACPI SDTs as NVS in the PVH build path
Commit cefeffc7e583 marked ACPI tables as NVS in the hvmloader path because SeaBIOS may otherwise just mark it as RAM. There is, however, yet another reason to do it even in the PVH path. Xen's incarnation of AML relies on having access to some ACPI tables (e.g: _STA of Processor objects relies on reading the processor online bit in its MADT entry)
This is problematic if the OS tries to reclaim ACPI memory for page tables as it's needed for runtime and can't be reclaimed after the OSPM is up and running.
---v1->v2:
* Copy explanatory comment in hvmloader/e820.c to its libxl_x86.c counterpart
--- tools/firmware/hvmloader/e820.c | 4 ++++ tools/libs/light/libxl_x86.c | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
tools/firmware/hvmloader/e820.c +4 -0
@@ -210,6 +210,10 @@ int build_e820_table(struct e820entry *e820,* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. * before an ACPI OS takes control. This is possible due to the fact that * ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. */ if ( acpi_enabled )
tools/libs/light/libxl_x86.c +16 -1
@@ -737,12 +737,27 @@ static int domain_construct_memmap(libxl__gc *gc, nr++; } +/* +* Mark populated reserved memory that contains ACPI tables as ACPI NVS. +* That should help the guest to treat it correctly later: e.g. pass to +* the next kernel on kexec. +* +* Using NVS type instead of a regular one helps to prevent potential +* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. +* before an ACPI OS takes control. This is possible due to the fact that +* ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. +*/ +for (i =0 ; i <MAX_ACPI_MODULES ; i++) {if (dom->acpi_modules[i].length) { e820[nr].addr = dom->acpi_modules[i].guest_addr_out & ~(page_size -1 ); e820[nr].size = dom->acpi_modules[i].length + (dom->acpi_modules[i].guest_addr_out & (page_size -1 )); - e820[nr].type =E820_ACPI ; + e820[nr].type =E820_NVS ; nr++; } }
Signature · 1 line
2.48.1
Quoted 48 lines · Alejandro Vallejo
Commit
cefeffc7e583marked ACPI tables as NVS in the hvmloader path because SeaBIOS may otherwise just mark it as RAM. There is, however, yet another reason to do it even in the PVH path. Xen's incarnation of AML relies on having access to some ACPI tables (e.g:_STAof Processor objects relies on reading the processor online bit in its MADT entry)This is problematic if the OS tries to reclaim ACPI memory for page tables as it's needed for runtime and can't be reclaimed after the OSPM is up and running.
Fixes de6d188a519f("hvmloader: flip "ACPI data" to "ACPI NVS" type for ACPI table region)"Signed-off-by Alejandro Vallejo <[email protected]>---
v1->v2:
* Copy explanatory comment inhvmloader/e820.cto itslibxl_x86.ccounterpart--- tools/firmware/hvmloader/e820.c | 4 ++++ tools/libs/light/libxl_x86.c | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)tools/firmware/hvmloader/e820.c +4
-0@@ -210,6 +210,10 @@ int build_e820_table(struct e820entry *e820,* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. * before an ACPI OS takes control. This is possible due to the fact that * ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. */ if ( acpi_enabled )tools/libs/light/libxl_x86.c +4
-0@@ -737,12 +737,27 @@ static int domain_construct_memmap(libxl__gc *gc, nr++; } +/* +* Mark populated reserved memory that contains ACPI tables as ACPI NVS. +* That should help the guest to treat it correctly later: e.g. pass to +* the next kernel on kexec.
tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 753
Quoted 10 lines
tools/libs/light/libxl_x86.c +10
-0+* +* Using NVS type instead of a regular one helps to prevent potential +* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. +* before an ACPI OS takes control. This is possible due to the fact that +* ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. +*/
When asking for a comment here I really only was after what the last paragraph says. Especially the middle paragraph seems questionable to me: It would not only be ACPI- unawareness, but also E820-unawareness, for the range to be prematurely re-used. And buggy bootloaders really would need fixing, I think - they'd put OSes into trouble on real hardware as well.
In short - I'd like to ask that the middle paragraph be dropped from here (which surely could be done while committing).
However, there's a second concern: You say "PVH" in the title, yet this function is in use also for HVM, and ...
tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 763
Quoted 10 lines
tools/libs/light/libxl_x86.c +1
-1for (i =0 ; i <MAX_ACPI_MODULES ; i++) {if (dom->acpi_modules[i].length) { e820[nr].addr = dom->acpi_modules[i].guest_addr_out & ~(page_size -1 ); e820[nr].size = dom->acpi_modules[i].length + (dom->acpi_modules[i].guest_addr_out & (page_size -1 )); - e820[nr].type =E820_ACPI ; + e820[nr].type =E820_NVS ; nr++; } }
... this code is outside of any conditionals. This imo needs sorting one way or another.
Jan
Quoted 66 lines · Jan Beulich
Quoted 48 lines · Alejandro Vallejo
Commit
cefeffc7e583marked ACPI tables as NVS in the hvmloader path because SeaBIOS may otherwise just mark it as RAM. There is, however, yet another reason to do it even in the PVH path. Xen's incarnation of AML relies on having access to some ACPI tables (e.g:_STAof Processor objects relies on reading the processor online bit in its MADT entry)This is problematic if the OS tries to reclaim ACPI memory for page tables as it's needed for runtime and can't be reclaimed after the OSPM is up and running.
Fixes de6d188a519f("hvmloader: flip "ACPI data" to "ACPI NVS" type for ACPI table region)"Signed-off-by Alejandro Vallejo <[email protected]>---
v1->v2:
* Copy explanatory comment inhvmloader/e820.cto itslibxl_x86.ccounterpart--- tools/firmware/hvmloader/e820.c | 4 ++++ tools/libs/light/libxl_x86.c | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)tools/firmware/hvmloader/e820.c +4
-0@@ -210,6 +210,10 @@ int build_e820_table(struct e820entry *e820,* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. * before an ACPI OS takes control. This is possible due to the fact that * ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. */ if ( acpi_enabled )tools/libs/light/libxl_x86.c +4
-0@@ -737,12 +737,27 @@ static int domain_construct_memmap(libxl__gc *gc, nr++; } +/* +* Mark populated reserved memory that contains ACPI tables as ACPI NVS. +* That should help the guest to treat it correctly later: e.g. pass to +* the next kernel on kexec. tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 753
Quoted 10 lines
tools/libs/light/libxl_x86.c +10
-0+* +* Using NVS type instead of a regular one helps to prevent potential +* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. +* before an ACPI OS takes control. This is possible due to the fact that +* ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. +*/ When asking for a comment here I really only was after what the last paragraph says. Especially the middle paragraph seems questionable to me: It would not only be ACPI- unawareness, but also E820-unawareness, for the range to be prematurely re-used. And buggy bootloaders really would need fixing, I think - they'd put OSes into trouble on real hardware as well.
Quoted 2 lines
In short - I'd like to ask that the middle paragraph be dropped from here (which surely could be done while committing).
I feel the rationale is the same on both paths, so the comment blocks ought to be aligned (whichever way). But I have no strong motivations and would be fine dropping the middle paragraph here.
If that's your only remark, I'm happy for it to be dropped on commit.
Quoted 15 lines
However, there's a second concern: You say "PVH" in the title, yet this function is in use also for HVM, and ...
tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 763
Quoted 10 lines
tools/libs/light/libxl_x86.c +1
-1for (i =0 ; i <MAX_ACPI_MODULES ; i++) {if (dom->acpi_modules[i].length) { e820[nr].addr = dom->acpi_modules[i].guest_addr_out & ~(page_size -1 ); e820[nr].size = dom->acpi_modules[i].length + (dom->acpi_modules[i].guest_addr_out & (page_size -1 )); - e820[nr].type =E820_ACPI ; + e820[nr].type =E820_NVS ; nr++; } }
Quoted 4 lines
... this code is outside of any conditionals. This imo needs sorting one way or another.
Jan
ACPI tables are populated by hvmloader, while libxl generates those of PVH.
dom->acpi_modules are populated by libxl__dom_load_acpi(), which is gated on the type being PVH (see the caller of this function). So this loop should be effectively skipped.
I called it the PVH path because it happens to be at the moment. Nothing prevents this path from being the HVM path too, but that involves rewiring hvmloader.
Cheers,
Alejandro
Quoted 96 lines · Alejandro Vallejo
Quoted 66 lines · Jan Beulich
Quoted 48 lines · Alejandro Vallejo
Commit
cefeffc7e583marked ACPI tables as NVS in the hvmloader path because SeaBIOS may otherwise just mark it as RAM. There is, however, yet another reason to do it even in the PVH path. Xen's incarnation of AML relies on having access to some ACPI tables (e.g:_STAof Processor objects relies on reading the processor online bit in its MADT entry)This is problematic if the OS tries to reclaim ACPI memory for page tables as it's needed for runtime and can't be reclaimed after the OSPM is up and running.
Fixes de6d188a519f("hvmloader: flip "ACPI data" to "ACPI NVS" type for ACPI table region)"Signed-off-by Alejandro Vallejo <[email protected]>---
v1->v2:
* Copy explanatory comment inhvmloader/e820.cto itslibxl_x86.ccounterpart--- tools/firmware/hvmloader/e820.c | 4 ++++ tools/libs/light/libxl_x86.c | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)tools/firmware/hvmloader/e820.c +4
-0@@ -210,6 +210,10 @@ int build_e820_table(struct e820entry *e820,* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. * before an ACPI OS takes control. This is possible due to the fact that * ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. */ if ( acpi_enabled )tools/libs/light/libxl_x86.c +4
-0@@ -737,12 +737,27 @@ static int domain_construct_memmap(libxl__gc *gc, nr++; } +/* +* Mark populated reserved memory that contains ACPI tables as ACPI NVS. +* That should help the guest to treat it correctly later: e.g. pass to +* the next kernel on kexec. tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 753
Quoted 10 lines
tools/libs/light/libxl_x86.c +10
-0+* +* Using NVS type instead of a regular one helps to prevent potential +* space reuse by an ACPI unaware / buggy bootloader, option ROM, etc. +* before an ACPI OS takes control. This is possible due to the fact that +* ACPI NVS memory is explicitly described as non-reclaimable in ACPI spec. +* +* Furthermore, Xen relies on accessing ACPI tables from within the AML +* code exposed to guests. So Xen's ACPI tables are not, in general, +* reclaimable. +*/ When asking for a comment here I really only was after what the last paragraph says. Especially the middle paragraph seems questionable to me: It would not only be ACPI- unawareness, but also E820-unawareness, for the range to be prematurely re-used. And buggy bootloaders really would need fixing, I think - they'd put OSes into trouble on real hardware as well.
Quoted 2 lines
In short - I'd like to ask that the middle paragraph be dropped from here (which surely could be done while committing).
I feel the rationale is the same on both paths, so the comment blocks ought to be aligned (whichever way). But I have no strong motivations and would be fine dropping the middle paragraph here.
If that's your only remark, I'm happy for it to be dropped on commit.
Quoted 15 lines
However, there's a second concern: You say "PVH" in the title, yet this function is in use also for HVM, and ...
tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 763
Quoted 10 lines
tools/libs/light/libxl_x86.c +1
-1for (i =0 ; i <MAX_ACPI_MODULES ; i++) {if (dom->acpi_modules[i].length) { e820[nr].addr = dom->acpi_modules[i].guest_addr_out & ~(page_size -1 ); e820[nr].size = dom->acpi_modules[i].length + (dom->acpi_modules[i].guest_addr_out & (page_size -1 )); - e820[nr].type =E820_ACPI ; + e820[nr].type =E820_NVS ; nr++; } }Quoted 2 lines
... this code is outside of any conditionals. This imo needs sorting one way or another.
ACPI tables are populated by hvmloader, while libxl generates those of PVH.
Quoted 7 lines
dom->acpi_modulesare populated bylibxl__dom_load_acpi(), which is gated on the type being PVH (see the caller of this function). So this loop should be effectively skipped.I called it the PVH path because it happens to be at the moment. Nothing prevents this path from being the HVM path too, but that involves rewiring hvmloader.
Oh, okay - what I was missing then is that ->acpi_modules[] is populated by libxl__dom_load_acpi(), and that bails early for non-PVH. So the loop here will have only no-op iterations for HVM.
Jan