arm64: kexec_file_load vs memory reservations
Subsystems (4)
cover arm64: kexec_file_load vs memory reservations
It recently became apparent that using kexec with kexec_file_load() on arm64 is pretty similar to playing Russian roulette.
Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec: /proc/iomem for the userspace implementation, and memblock.reserved for kexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.
On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
This small series aims at triggering a discussion on what are the expectations for kexec_file, and whether we should unify the two reservation mechanisms.
And in the meantime, it gets things going...
Marc Zyngier (2):
firmware/efi: Tell memblock about EFI reservations
ACPI: arm64: Reserve the ACPI tables in memblock
arch/arm64/kernel/acpi.c | 1 + drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)
Signature · 7 lines
2.29.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/2 firmware/efi: Tell memblock about EFI reservations
kexec_load_file() relies on the memblock infrastructure to avoid stamping over regions of memory that are essential to the survival of the system.
However, nobody seems to agree how to flag these regions as reserved, and (for example) EFI only publishes its reservations in /proc/iomem for the benefit of the traditional, userspace based kexec tool.
On arm64 platforms with GICv3, this can result in the payload being placed at the location of the LPI tables. Shock, horror!
Let's augment the EFI reservation code with a memblock_reserve() call, protecting our dear tables from the secondary kernel invasion.
At some point, someone will have to go and figure out a way to unify these multiple reservation trees, because sprinkling random reservation calls is only a temporary workaround.
--- drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +22 -1
@@ -896,11 +896,25 @@ static int __init efi_memreserve_map_root(void)static int efi_mem_reserve_iomem (phys_addr_t addr,u64 size) {struct resource *res, *parent; +int ret; res =kzalloc (sizeof (struct resource ),GFP_ATOMIC );if (!res)return -ENOMEM ; +/* +* Given that efi_mem_reserve_iomem() can be called at any +* time, only call memblock_reserve() if the architecture +* keeps the infrastructure around. +*/ +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { + ret =memblock_reserve (addr, size); +if (ret) { +kfree (res); +return ret; + } + } + res->name ="reserved" ; res->flags =IORESOURCE_MEM ; res->start = addr;
@@ -908,7 +922,14 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size)/* we expect a conflict with a 'System RAM' region */ parent =request_resource_conflict (&iomem_resource, res); -return parent ?request_resource (parent, res) :0 ; + ret = parent ?request_resource (parent, res) :0 ; +if (ret) { +kfree (res); +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) +memblock_free (addr, size); + } + +return ret; }int __ref efi_mem_reserve_persistent (phys_addr_t addr,u64 size)
Signature · 7 lines
2.29.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] firmware/efi: Tell memblock about EFI reservations
Marc,
Quoted 11 lines · Marc Zyngier
kexec_load_file()relies on the memblock infrastructure to avoid stamping over regions of memory that are essential to the survival of the system.However, nobody seems to agree how to flag these regions as reserved, and (for example) EFI only publishes its reservations in
/proc/iomemfor the benefit of the traditional, userspace based kexec tool.On arm64 platforms with GICv3, this can result in the payload being placed at the location of the LPI tables. Shock, horror!
Quoted 7 lines
Let's augment the EFI reservation code with a
memblock_reserve()call, protecting our dear tables from the secondary kernel invasion.At some point, someone will have to go and figure out a way to unify these multiple reservation trees, because sprinkling random reservation calls is only a temporary workaround.
Feel free to add (and/or):
Quoted 59 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/firmware/efi/efi.c +22
-1@@ -896,11 +896,25 @@ static int __init efi_memreserve_map_root(void)static int efi_mem_reserve_iomem (phys_addr_t addr,u64 size) {struct resource *res, *parent; +int ret; res =kzalloc (sizeof (struct resource ),GFP_ATOMIC );if (!res)return -ENOMEM ; +/* +* Given that efi_mem_reserve_iomem() can be called at any +* time, only call memblock_reserve() if the architecture +* keeps the infrastructure around. +*/ +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { + ret =memblock_reserve (addr, size); +if (ret) { +kfree (res); +return ret; + } + } + res->name ="reserved" ; res->flags =IORESOURCE_MEM ; res->start = addr;@@ -908,7 +922,14 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size)/* we expect a conflict with a 'System RAM' region */ parent =request_resource_conflict (&iomem_resource, res); -return parent ?request_resource (parent, res) :0 ; + ret = parent ?request_resource (parent, res) :0 ; +if (ret) { +kfree (res); +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) +memblock_free (addr, size); + } + +return ret; }int __ref efi_mem_reserve_persistent (phys_addr_t addr,u64 size)Signature · 7 lines
2.29.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thanks,
Moritz
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] firmware/efi: Tell memblock about EFI reservations
Quoted 45 lines · Moritz Fischer
Marc,
Quoted 11 lines · Marc Zyngier
kexec_load_file()relies on the memblock infrastructure to avoid stamping over regions of memory that are essential to the survival of the system.However, nobody seems to agree how to flag these regions as reserved, and (for example) EFI only publishes its reservations in
/proc/iomemfor the benefit of the traditional, userspace based kexec tool.On arm64 platforms with GICv3, this can result in the payload being placed at the location of the LPI tables. Shock, horror!
Quoted 7 lines
Let's augment the EFI reservation code with a
memblock_reserve()call, protecting our dear tables from the secondary kernel invasion.At some point, someone will have to go and figure out a way to unify these multiple reservation trees, because sprinkling random reservation calls is only a temporary workaround.
Feel free to add (and/or):
Reported-by Moritz Fischer <[email protected]>Tested-by Moritz Fischer <[email protected]>Quoted 19 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/firmware/efi/efi.c +1
-0@@ -896,11 +896,25 @@ static int __init efi_memreserve_map_root(void)static int efi_mem_reserve_iomem (phys_addr_t addr,u64 size) {struct resource *res, *parent; +int ret; res =kzalloc (sizeof (struct resource ),GFP_ATOMIC );if (!res)return -ENOMEM ;
Quoted 13 lines
drivers/firmware/efi/efi.c static int __init efi_memreserve_map_root(void) · line 917
Quoted 13 lines
drivers/firmware/efi/efi.c +13
-0+/* +* Given that efi_mem_reserve_iomem() can be called at any +* time, only call memblock_reserve() if the architecture +* keeps the infrastructure around. +*/ +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { + ret =memblock_reserve (addr, size); +if (ret) { +kfree (res); +return ret; + } + } +
If you go with memblock, it would be better to handle it separately from the iomem?
Quoted 5 lines
Quoted 5 lines
drivers/firmware/efi/efi.c +0
-0res->name ="reserved" ; res->flags =IORESOURCE_MEM ; res->start = addr;@@ -908,7 +922,14 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size)
Quoted 11 lines
drivers/firmware/efi/efi.c static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size) · line 932
Quoted 11 lines
drivers/firmware/efi/efi.c +8
-1/* we expect a conflict with a 'System RAM' region */ parent =request_resource_conflict (&iomem_resource, res); -return parent ?request_resource (parent, res) :0 ; + ret = parent ?request_resource (parent, res) :0 ; +if (ret) { +kfree (res); +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) +memblock_free (addr, size); + } + +return ret;
It looks odd to free memblock when reqeust resource fails, they are not relavant?
Quoted 12 lines
Quoted 11 lines
drivers/firmware/efi/efi.c +0
-0}int __ref efi_mem_reserve_persistent (phys_addr_t addr,u64 size)Signature · 7 lines
2.29.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 9 lines
Thanks,
Moritz_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/2] firmware/efi: Tell memblock about EFI reservations
Quoted 47 lines · Dave Young
Quoted 45 lines · Moritz Fischer
Marc,
Quoted 11 lines · Marc Zyngier
kexec_load_file()relies on the memblock infrastructure to avoid stamping over regions of memory that are essential to the survival of the system.However, nobody seems to agree how to flag these regions as reserved, and (for example) EFI only publishes its reservations in
/proc/iomemfor the benefit of the traditional, userspace based kexec tool.On arm64 platforms with GICv3, this can result in the payload being placed at the location of the LPI tables. Shock, horror!
Quoted 7 lines
Let's augment the EFI reservation code with a
memblock_reserve()call, protecting our dear tables from the secondary kernel invasion.At some point, someone will have to go and figure out a way to unify these multiple reservation trees, because sprinkling random reservation calls is only a temporary workaround.
Feel free to add (and/or):
Reported-by Moritz Fischer <[email protected]>Tested-by Moritz Fischer <[email protected]>Quoted 19 lines
Signed-off-by Marc Zyngier <[email protected]>--- drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/firmware/efi/efi.c +1
-0@@ -896,11 +896,25 @@ static int __init efi_memreserve_map_root(void)static int efi_mem_reserve_iomem (phys_addr_t addr,u64 size) {struct resource *res, *parent; +int ret; res =kzalloc (sizeof (struct resource ),GFP_ATOMIC );if (!res)return -ENOMEM ;
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
drivers/firmware/efi/efi.c +5
-0+/* +* Given that efi_mem_reserve_iomem() can be called at any +* time, only call memblock_reserve() if the architecture +* keeps the infrastructure around. +*/ Quoted 8 lines
drivers/firmware/efi/efi.c static int __init efi_memreserve_map_root(void) · line 917
Quoted 8 lines
drivers/firmware/efi/efi.c +8
-0+if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { + ret =memblock_reserve (addr, size); +if (ret) { +kfree (res); +return ret; + } + } +If you go with memblock, it would be better to handle it separately from the iomem?
Do you mean having a separate helper from efi_mem_reserve_iomem()? Sure, can do.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/firmware/efi/efi.c +0
-0res->name ="reserved" ; res->flags =IORESOURCE_MEM ; res->start = addr;@@ -908,7 +922,14 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size)
Quoted 14 lines
Quoted 11 lines
drivers/firmware/efi/efi.c static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size) · line 932
Quoted 11 lines
drivers/firmware/efi/efi.c +8
-1/* we expect a conflict with a 'System RAM' region */ parent =request_resource_conflict (&iomem_resource, res); -return parent ?request_resource (parent, res) :0 ; + ret = parent ?request_resource (parent, res) :0 ; +if (ret) { +kfree (res); +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) +memblock_free (addr, size); + } + +return ret;It looks odd to free memblock when reqeust resource fails, they are not relavant?
I'm trying to keep the two trees in sync so that when the caller finds out that the reservation has failed, we're not in a half-baked state.
But maybe it doesn't really matter, and if a reservation fails, we're already screwed.
Ard, what do you think?
M.
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/2 ACPI: arm64: Reserve the ACPI tables in memblock
In reply to Marc ZyngierJust like the EFI reservations, ACPI tables can be stamped over by kexec_file_load(), and the secondary kernel will be unable to recover from such corruption.
It looks like our x86 friends have been there before, and have recently added some infratructure that does what we need since 1a1c130ab757 ("ACPI: tables: x86: Reserve memory occupied by ACPI tables"), though it appears to exist for different reasons.
Let's call into acpi_reserve_initial_tables() early so that our tables are protected from the big bad kexec.
--- arch/arm64/kernel/acpi.c | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kernel/acpi.c +1 -0
@@ -233,6 +233,7 @@ void __init acpi_boot_table_init(void)if (earlycon_acpi_spcr_enable)early_init_dt_scan_chosen_stdout (); }else { +acpi_reserve_initial_tables ();acpi_parse_spcr (earlycon_acpi_spcr_enable, true);if (IS_ENABLED (CONFIG_ACPI_BGRT ))acpi_table_parse (ACPI_SIG_BGRT , acpi_parse_bgrt);
Signature · 7 lines
2.29.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/2] ACPI: arm64: Reserve the ACPI tables in memblock
Marc,
Quoted 4 lines · Marc Zyngier
Just like the EFI reservations, ACPI tables can be stamped over by
kexec_file_load(), and the secondary kernel will be unable to recover from such corruption.
Quoted 8 lines
It looks like our x86 friends have been there before, and have recently added some infratructure that does what we need since
1a1c130ab757("ACPI: tables: x86: Reserve memory occupied by ACPI tables"), though it appears to exist for different reasons.Let's call into
acpi_reserve_initial_tables()early so that our tables are protected from the big bad kexec.
Feel free to add (and/or):
Quoted 25 lines
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kernel/acpi.c | 1 + 1 file changed, 1 insertion(+)arch/arm64/kernel/acpi.c +1
-0@@ -233,6 +233,7 @@ void __init acpi_boot_table_init(void)if (earlycon_acpi_spcr_enable)early_init_dt_scan_chosen_stdout (); }else { +acpi_reserve_initial_tables ();acpi_parse_spcr (earlycon_acpi_spcr_enable, true);if (IS_ENABLED (CONFIG_ACPI_BGRT ))acpi_table_parse (ACPI_SIG_BGRT , acpi_parse_bgrt);Signature · 7 lines
2.29.2 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Thanks,
Moritz
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
+ Dave Young, which I accidentally missed in my initial post
Quoted 27 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
This small series aims at triggering a discussion on what are the expectations for
kexec_file, and whether we should unify the two reservation mechanisms.And in the meantime, it gets things going...
Quoted 7 lines
Marc Zyngier (2):
firmware/efi: Tell memblock about EFI reservations
ACPI: arm64: Reserve the ACPI tables in memblockarch/arm64/kernel/acpi.c | 1 + drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)
Any comment on this?
I've separately started working on using the resource tree to slice and dice the memblocks that are candidate for kexec_file_load(), but I'd like some consensus on whether this is the right way to address the issue.
Without something like this, kexec_file_load() is not usable on arm64, so I'm pretty eager to see the back of this bug.
Thanks,
M.
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Marc,
Quoted 41 lines · Marc Zyngier
+ Dave Young, which I accidentally missed in my initial post
Quoted 27 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
This small series aims at triggering a discussion on what are the expectations for
kexec_file, and whether we should unify the two reservation mechanisms.And in the meantime, it gets things going...
Quoted 7 lines
Marc Zyngier (2):
firmware/efi: Tell memblock about EFI reservations
ACPI: arm64: Reserve the ACPI tables in memblockarch/arm64/kernel/acpi.c | 1 + drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)Any comment on this?
Quoted 7 lines
I've separately started working on using the resource tree to slice and dice the memblocks that are candidate for
kexec_file_load(), but I'd like some consensus on whether this is the right way to address the issue.Without something like this,
kexec_file_load()is not usable on arm64, so I'm pretty eager to see the back of this bug.
The arm64 memory reservation is tricky, I do not think I understand it correctly. Previously there were a lot discussion, Ard and AKASHI should know more about it, see if they can provide comments.
About the problem you see, another way is to just add an arch weak function like powerpc: arch_kexec_locate_mem_hole, and walking resource tree for kexec_file_load as well. But I might be wrong since I did not follow up the arm64 specific history.
Quoted 8 lines
Thanks,
M.Signature · 1 line
Without deviation from the norm, progress is not possible.
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
[- Bhupesh, as his RH address now bounces]
Quoted 49 lines · Dave Young
Hi Marc,
Quoted 46 lines · Marc Zyngier
+ Dave Young, which I accidentally missed in my initial post
Quoted 27 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
This small series aims at triggering a discussion on what are the expectations for
kexec_file, and whether we should unify the two reservation mechanisms.And in the meantime, it gets things going...
Quoted 7 lines
Marc Zyngier (2):
firmware/efi: Tell memblock about EFI reservations
ACPI: arm64: Reserve the ACPI tables in memblockarch/arm64/kernel/acpi.c | 1 + drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)Any comment on this?
I've separately started working on using the resource tree to slice and dice the memblocks that are candidate for
kexec_file_load(), but I'd like some consensus on whether this is the right way to address the issue.
Quoted 6 lines
Quoted 2 lines
Without something like this,
kexec_file_load()is not usable on arm64, so I'm pretty eager to see the back of this bug.The arm64 memory reservation is tricky, I do not think I understand it correctly. Previously there were a lot discussion, Ard and AKASHI should know more about it, see if they can provide comments.
I'll let them chime in. It looks like most of the discussions were around kdump, which doesn't suffer from this issue (the memory is reserved upfront).
Quoted 4 lines
About the problem you see, another way is to just add an arch weak function like powerpc:
arch_kexec_locate_mem_hole, and walking resource tree forkexec_file_loadas well. But I might be wrong since I did not follow up the arm64 specific history.
Right, this would avoid messing with the core code. However, the problem remains in the sense that there is no clear definition of what "reserved memory" is in general, and where it is described. For example, x86 places the ACPI tables in reserved memblocks, while arm64 doesn't (unless we use my second patch).
To reliably use the resource tree, we need to ensure that it contains all the reservations that appeared in memblock too. And if we can't have a single reference, then we have to consider the union of the two trees.
Thoughts?
M.
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Will Deacon
maintainer[Fixing Bhupesh's email address]
Quoted 15 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.
Quoted 8 lines
On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
This small series aims at triggering a discussion on what are the expectations for
kexec_file, and whether we should unify the two reservation mechanisms.
Bhupesh, since you've been involved with kexec file on arm64 before, please could you take a look at these patches?
Thanks,
Will
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Will,
Quoted 24 lines · Will Deacon
[Fixing Bhupesh's email address]
Quoted 20 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
Quoted 6 lines
Quoted 3 lines
This small series aims at triggering a discussion on what are the expectations for
kexec_file, and whether we should unify the two reservation mechanisms.Bhupesh, since you've been involved with kexec file on arm64 before, please could you take a look at these patches?
Thanks for adding me in Cc.
Yes, I will look and test these patches asap.
Regards,
Bhupesh
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Catalin Marinas
maintainerQuoted 8 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
Quoted 6 lines
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.
So which one of these (/proc/iomem and memblock.reserved) would be the correct option? If none of them, is their intersection any better? Looking at the default kexec_locate_mem_hole(), it uses the resources tree if !CONFIG_ARCH_KEEP_MEMBLOCK, otherwise memblock.
PowerPC implements its own arch_kexec_locate_mem_hole() to skip specific arch regions. We could do something similar for arm64 if the arch code knows where the LPI reservation is or the ACPI tables.
If we conclude that we need some intersection of resource reservations and memblock, maybe we should change the default kexec_locate_mem_hole() implementation to check for both (e.g. start with the resource tree and only consider a range valid if not in memblock.reserved).
Signature · 6 lines
Catalin _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 17 lines · Catalin Marinas
Quoted 8 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
Quoted 6 lines
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file. And of course, our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping. Similar things could happen with ACPI tables as well.
Quoted 2 lines
So which one of these (
/proc/iomemand memblock.reserved) would be the correct option? If none of them, is their intersection any better?
/proc/iomem is what we use for userspace, so you'd expect this to be the right thing to use.
Quoted 2 lines
Looking at the default
kexec_locate_mem_hole(), it uses the resources tree if !CONFIG_ARCH_KEEP_MEMBLOCK, otherwise memblock.
Yup, and funnily enough, forcing a fallback to the resources tree doesn't help either, because the logic used here isn't much better (it takes the RAM areas at face value, without excluding any of the reserved regions that are children of the "System RAM" regions).
It's not funny anymore.
Quoted 3 lines
PowerPC implements its own
arch_kexec_locate_mem_hole()to skip specific arch regions. We could do something similar for arm64 if the arch code knows where the LPI reservation is or the ACPI tables.
It feels like a bit of a failure to duplicate all that code. I'd consider that the last possible outcome.
Quoted 4 lines
If we conclude that we need some intersection of resource reservations and memblock, maybe we should change the default
kexec_locate_mem_hole()implementation to check for both (e.g. start with the resource tree and only consider a range valid if not in memblock.reserved).
I am more angling towards this. But my worry is that different architectures have already different ways to reserve memory (PPC seems to do their own stuff on top of memblock, x86 I assumes uses the resource tree in a different way than arm64).
Anyway, I'll keep digging.
M.
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Marc,
Quoted 11 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file.
One is spilled into the other by request_standard_resources()...
Quoted 3 lines
And of course,
our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping.
Presumably well after efi_init() has run...
Quoted 1 line
Similar things could happen with ACPI tables as well.
efi_init() calls reserve_regions(), which has:
| /* keep ACPI reclaim memory intact for kexec etc. */ | if (md->type == EFI_ACPI_RECLAIM_MEMORY) | memblock_reserve(paddr, size);
This is also what stops mm from allocating them, as memblock-reserved gets copied into the PG_Reserved flag by free_low_memory_core_early()'s calls to reserve_bootmem_region().
Is your machines firmware putting them in a region with a different type?
(The UEFI spec has something to say: see 2.3.6 "AArch64 Platforms":
| ACPI Tables loaded at boot time can be contained in memory of type EfiACPIReclaimMemory | (recommended) or EfiACPIMemoryNVS
NVS would fail the is_usable_memory() check earlier, so gets treated as nomap)
Thanks,
James
Quoted 11 lines
On my 24xA53 system artificially limited to 256MB of RAM (yes, it boots with that little memory), trying to kexec a secondary kernel failed every times. I can only presume that this was mostly tested using kdump, which preserves the entire kernel memory range.
This small series aims at triggering a discussion on what are the expectations for
kexec_file, and whether we should unify the two reservation mechanisms.And in the meantime, it gets things going...
Quoted 8 lines
Marc Zyngier (2):
firmware/efi: Tell memblock about EFI reservations
ACPI: arm64: Reserve the ACPI tables in memblockarch/arm64/kernel/acpi.c | 1 + drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-)
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi James,
Quoted 16 lines · James Morse
Hi Marc,
Quoted 11 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file.
Quoted 8 lines
One is spilled into the other by
request_standard_resources()...Quoted 3 lines
And of course,
our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping.Presumably well after
efi_init()has run...
Yup, much later. And we can keep on reserving memory as long as we boot new CPUs. Having it as a one-off sync doesn't really help here.
Quoted 8 lines
Quoted 2 lines
Similar things could happen with ACPI tables as well.
efi_init()callsreserve_regions(), which has:| /* keep ACPI reclaim memory intact for kexec etc. */ | if (md->type == EFI_ACPI_RECLAIM_MEMORY) | memblock_reserve(paddr, size);
Quoted 5 lines
This is also what stops mm from allocating them, as memblock-reserved gets copied into the
PG_Reservedflag by free_low_memory_core_early()'s calls toreserve_bootmem_region().Is your machines firmware putting them in a region with a different type?
Good question. Moritz (cc'd) saw the tables being overwritten on his system (which I don't have access to), so I guess this is not entirely clear cut how this happens.
My SQ box reports the ACPI region as "ACPI Reclaim", so I guess it works as expected here.
Quoted 6 lines
(The UEFI spec has something to say: see 2.3.6 "AArch64 Platforms":
| ACPI Tables loaded at boot time can be contained in memory of type EfiACPIReclaimMemory | (recommended) or EfiACPIMemoryNVSNVS would fail the
is_usable_memory()check earlier, so gets treated as nomap)
Note that I've since changed tactics and proposed that we fully rely on the resource tree instead[1].
Thanks,
M.
[1] https://lore.kernel.org/r/[email protected]
Signature · 6 lines
Without deviation from the norm, progress is not possible. _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Marc,
Quoted 18 lines · Marc Zyngier
Quoted 16 lines · James Morse
Quoted 11 lines · Marc Zyngier
It recently became apparent that using kexec with
kexec_file_load()on arm64 is pretty similar to playing Russian roulette.Depending on the amount of memory, the HW supported and the firmware interface used, your secondary kernel may overwrite critical memory regions without which the secondary kernel cannot boot (the GICv3 LPI tables being a prime example of such reserved regions).
It turns out that there is at least two ways for reserved memory regions to be described to kexec:
/proc/iomemfor the userspace implementation, and memblock.reserved forkexec_file.One is spilled into the other by
request_standard_resources()...
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
And of course,
our LPI tables are only reserved using the resource tree, leading to the aforementioned stamping.Presumably well after
efi_init()has run...Yup, much later. And we can keep on reserving memory as long as we boot new CPUs. Having it as a one-off sync doesn't really help here.
It might need doing for all possible CPUs up-front... otherwise someone loads a kexec kernel and correctly picks a safe location ... then a CPU comes online and reserves a hole in the middle of it: kexec isn't using the selected location until you reboot(). (memory hotplug has some 'fun' in this area, which can only be fixed by using memblock, which ought to know about removable memory ranges ... but doesn't)
There does need to be a point where the list of reserved memory stops changing.
Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Similar things could happen with ACPI tables as well.
efi_init()callsreserve_regions(), which has:| /* keep ACPI reclaim memory intact for kexec etc. */ | if (md->type == EFI_ACPI_RECLAIM_MEMORY) | memblock_reserve(paddr, size);This is also what stops mm from allocating them, as memblock-reserved gets copied into the
PG_Reservedflag by free_low_memory_core_early()'s calls toreserve_bootmem_region().
Quoted 5 lines
Quoted 1 line
Is your machines firmware putting them in a region with a different type?
Good question. Moritz (cc'd) saw the tables being overwritten on his system (which I don't have access to), so I guess this is not entirely clear cut how this happens.
If we have systems that store the tables in 'conventional memory' we have bigger problems!
Quoted 7 lines
My SQ box reports the ACPI region as "ACPI Reclaim", so I guess it works as expected here.
Quoted 4 lines
(The UEFI spec has something to say: see 2.3.6 "AArch64 Platforms":
| ACPI Tables loaded at boot time can be contained in memory of type EfiACPIReclaimMemory | (recommended) or EfiACPIMemoryNVS
Quoted 5 lines
Quoted 2 lines
NVS would fail the
is_usable_memory()check earlier, so gets treated as nomap)Note that I've since changed tactics and proposed that we fully rely on the resource tree instead[1].
Yup - I came back here to work out why you gave up on memblock:reserving the reserved regions...
Thanks,
James
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec