consolidate "System RAM" resources setup
Subsystems (6)
Mike Rapoport
maintainercover consolidate "System RAM" resources setup
From: Mike Rapoport <[email protected]>
Hi,
There are several architectures that use very similar code for setup if "System RAM" resources under iomem_resource tree and requesting memory resources corresponding to the kernel code, data etc.
The flow for resources setup iterates over memory regions registered in memblock, adds a resource for each region as "System RAM" and than registers the areas used by the kernel image and, optionally, the crash kernel area, as children of the "System RAM" resources.
The notable differences are:
* arm/arm64 use [__text, __init_begin] range for kernel code resource and [_sdata, _end] range for kernel data, while most other architectures use more fine grained ranges.
* arm has "System RAM (boot alias)" that do not seem useful for any other architecture
* arm64 has special treatment for NOMAP areas and all the areas reserved in memblock
* s390 has crashk_res in parallel with the "System RAM" resource, but it seems it was required some time ago but no longer actually needed.
These patches use s390 implementation of the resource setup as the basis and then switch MIPS, arm and arm64 to use it with modifications required to support each architecture.
The generic code loops over all memblock.memory regions, adds the NOMAP regions as "reserved" iomem resources and "normal" regions as "System RAM" iomem resrouces, reserves the areas occupied by the kernel code, rodata, data and bss, if there is crash kernel resource it is also reserved.
In addition, if an architectures selects CONFIG_ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS (bad name, but I could not find a better one) the memblock.reserved regions are registered as "reserved" resources in iomem_resource.
It would be also possible to convert other architectures (e.g, RISC-V and sh) to use the common infrastructure.
Mike Rapoport (5):
s390: make crashk_res resource a child of "System RAM"
memblock: introduce generic memblock_setup_resources()
arm: switch to generic memblock_setup_resources()
MIPS: switch to generic memblock_setup_resources
arm64: switch to generic memblock_setup_resources()
arch/Kconfig | 7 ++ arch/arm/kernel/setup.c | 37 +---------- arch/arm64/Kconfig | 1 + arch/arm64/kernel/setup.c | 101 +---------------------------- arch/mips/kernel/setup.c | 78 ++-------------------- arch/s390/kernel/setup.c | 86 +------------------------ include/linux/memblock.h | 2 + mm/memblock.c | 132 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 151 insertions(+), 293 deletions(-)
base-commit: c4681547bcce777daf576925a966ffa824edd09d
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 1/5 s390: make crashk_res resource a child of "System RAM"
From: Mike Rapoport <[email protected]>
Commit 4e042af463f8 ("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that.
Keeping crashk_res inline with other resources makes code simpler and cleaner, and allows future consolidation of the resources setup across several architectures.
--- arch/s390/kernel/setup.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
arch/s390/kernel/setup.c +5 -16
@@ -500,6 +500,9 @@ static struct resource __initdata *standard_resources[] = { &code_resource, &data_resource, &bss_resource, +#ifdef CONFIG_CRASH_DUMP + &crashk_res, +#endif };static void __init setup_resources (void )
@@ -535,7 +538,7 @@ static void __init setup_resources(void)for (j =0 ; j <ARRAY_SIZE (standard_resources); j++) { std_res = standard_resources[j]; -if (std_res->start < res->start || +if (!std_res->end || std_res->start < res->start || std_res->start > res->end)continue ;if (std_res->end > res->end) {
@@ -552,20 +555,6 @@ static void __init setup_resources(void) } } } -#ifdef CONFIG_CRASH_DUMP -/* -* Re-add removed crash kernel memory as reserved memory. This makes -* sure it will be mapped with the identity mapping and struct pages -* will be created, so it can be resized later on. -* However add it later since the crash kernel resource should not be -* part of the System RAM resource. -*/ -if (crashk_res.end) { -memblock_add_node (crashk_res.start,resource_size (&crashk_res),0 ); -memblock_reserve (crashk_res.start,resource_size (&crashk_res)); -insert_resource (&iomem_resource, &crashk_res); - } -#endif }static void __init setup_ident_map_size (void )
@@ -733,7 +722,7 @@ static void __init reserve_crashkernel(void)diag10_range (PFN_DOWN (crash_base),PFN_DOWN (crash_size)); crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; -memblock_remove (crash_base, crash_size); +memblock_reserve (crash_base, crash_size); pr_info("Reserving %lluMB of memory at %lluMB " "for crashkernel (System RAM: %luMB)\n", crash_size >> 20, crash_base >> 20,
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 2/5 memblock: introduce generic memblock_setup_resources()
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
Several architecture have very similar implementation of the setup of the resource tree. The implementations loop over memory ranges registered in memblock, request a "System RAM" resource for each range and then reserve resource rages corresponding to various sections of the kernel image. If kexec/crash dump are enable the crashk_res region is also reserved.
Move the implementation of resource tree setup from s390 to memblock. It will be then used by several other architectures as well.
--- arch/s390/kernel/setup.c | 73 +-------------------------------- include/linux/memblock.h | 2 + mm/memblock.c | 87 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 72 deletions(-)
arch/s390/kernel/setup.c +1 -72
@@ -481,80 +481,9 @@ static void __init setup_lowcore_dat_on(void)__ctl_set_bit (0 ,28 ); } -static struct resource code_resource = { - .name ="Kernel code" , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , -}; - -static struct resource data_resource = { - .name ="Kernel data" , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , -}; - -static struct resource bss_resource = { - .name ="Kernel bss" , - .flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM , -}; - -static struct resource __initdata *standard_resources[] = { - &code_resource, - &data_resource, - &bss_resource, -#ifdef CONFIG_CRASH_DUMP - &crashk_res, -#endif -}; -static void __init setup_resources (void ) { -struct resource *res, *std_res, *sub_res; -phys_addr_t start, end; -int j; -u64 i; - - code_resource.start = (unsigned long ) _text; - code_resource.end = (unsigned long ) _etext -1 ; - data_resource.start = (unsigned long ) _etext; - data_resource.end = (unsigned long ) _edata -1 ; - bss_resource.start = (unsigned long ) __bss_start; - bss_resource.end = (unsigned long ) __bss_stop -1 ; - -for_each_mem_range (i, &start, &end) { - res =memblock_alloc (sizeof (*res),8 ); -if (!res) -panic ("%s: Failed to allocate %zu bytes align=0x%x\n" , - __func__,sizeof (*res),8 ); - res->flags =IORESOURCE_BUSY |IORESOURCE_SYSTEM_RAM ; - - res->name ="System RAM" ; - res->start = start; -/* -* In memblock, end points to the first byte after the -* range while in resourses, end points to the last byte in -* the range. -*/ - res->end = end -1 ; -request_resource (&iomem_resource, res); - -for (j =0 ; j <ARRAY_SIZE (standard_resources); j++) { - std_res = standard_resources[j]; -if (!std_res->end || std_res->start < res->start || - std_res->start > res->end) -continue ; -if (std_res->end > res->end) { - sub_res =memblock_alloc (sizeof (*sub_res),8 ); -if (!sub_res) -panic ("%s: Failed to allocate %zu bytes align=0x%x\n" , - __func__,sizeof (*sub_res),8 ); - *sub_res = *std_res; - sub_res->end = res->end; - std_res->start = res->end +1 ; -request_resource (res, sub_res); - }else { -request_resource (res, std_res); - } - } - } +memblock_setup_resources (); }static void __init setup_ident_map_size (void )
include/linux/memblock.h +2 -0
@@ -121,6 +121,8 @@ void memblock_free_all(void);void reset_node_managed_pages (pg_data_t *pgdat);void reset_all_zones_managed_pages (void ); +void memblock_setup_resources (void ); +/* Low level functions */ void __next_mem_range(u64 *idx, int nid, enum memblock_flags flags, struct memblock_type *type_a,
mm/memblock.c +87 -0
99 lines not on this page · raw message
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 3/5 arm: switch to generic memblock_setup_resources()
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
The registration of "System RAM" resources on arm is very similar to the generic version.
The major differences are the registration of "System RAM (boot alias)" areas and minor differences in the way kernel image resources are reserved.
Replace the open coded registration of the "System RAM" resource and the requests for kernel image and data areas in the resource tree with the generic implementation.
--- arch/arm/kernel/setup.c | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-)
arch/arm/kernel/setup.c +1 -36
@@ -174,23 +174,9 @@ static struct resource mem_res[] = { .end = 0, .flags =IORESOURCE_MEM }, - { - .name = "Kernel code", - .start = 0, - .end = 0, - .flags =IORESOURCE_SYSTEM_RAM - }, - { - .name = "Kernel data", - .start = 0, - .end = 0, - .flags = IORESOURCE_SYSTEM_RAM - } };#define video_ram mem_res[0] -#define kernel_code mem_res[1] -#define kernel_data mem_res[2]static struct resource io_res[] = { {
@@ -849,10 +835,7 @@ static void __init request_standard_resources(const struct machine_desc *mdesc)struct resource *res;u64 i; - kernel_code.start =virt_to_phys (_text); - kernel_code.end =virt_to_phys (__init_begin -1 ); - kernel_data.start =virt_to_phys (_sdata); - kernel_data.end =virt_to_phys (_end -1 ); +memblock_setup_resources ();for_each_mem_range (i, &start, &end) {unsigned long boot_alias_start;
@@ -881,24 +864,6 @@ static void __init request_standard_resources(const struct machine_desc *mdesc) res->flags =IORESOURCE_MEM |IORESOURCE_BUSY ;request_resource (&iomem_resource, res); } - - res =memblock_alloc (sizeof (*res),SMP_CACHE_BYTES ); -if (!res) -panic ("%s: Failed to allocate %zu bytes\n" , __func__, -sizeof (*res)); - res->name ="System RAM" ; - res->start = start; - res->end = res_end; - res->flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - -request_resource (&iomem_resource, res); - -if (kernel_code.start >= res->start && - kernel_code.end <= res->end) -request_resource (res, &kernel_code); -if (kernel_data.start >= res->start && - kernel_data.end <= res->end) -request_resource (res, &kernel_data); }if (mdesc->video_start) {
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 4/5 MIPS: switch to generic memblock_setup_resources
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
MIPS version of resource setup is very similar to the generic one. The only difference is the reservation of the crash kernel area that is spread among several functions.
Switch MIPS to use the generic version.
--- arch/mips/kernel/setup.c | 78 +++------------------------------------- 1 file changed, 5 insertions(+), 73 deletions(-)
arch/mips/kernel/setup.c +5 -73
@@ -79,10 +79,6 @@ static const char builtin_cmdline[] __initconst = "";unsigned long mips_io_port_base =-1 ;EXPORT_SYMBOL (mips_io_port_base); -static struct resource code_resource = { .name ="Kernel code" , }; -static struct resource data_resource = { .name ="Kernel data" , }; -static struct resource bss_resource = { .name ="Kernel bss" , }; -unsigned long __kaslr_offset__ro_after_init ;EXPORT_SYMBOL (__kaslr_offset);
@@ -469,31 +465,18 @@ static void __init mips_parse_crashkernel(void) } } +memblock_reserve (crashk_res.start,resource_size (&crashk_res)); + crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; -} - -static void __init request_crashkernel (struct resource *res) -{ -int ret; - -if (crashk_res.start == crashk_res.end) -return ; - ret =request_resource (res, &crashk_res); -if (!ret) -pr_info ("Reserving %ldMB of memory at %ldMB for crashkernel\n" , - (unsigned long )(resource_size (&crashk_res) >>20 ), - (unsigned long )(crashk_res.start >>20 )); +pr_info ("Reserving %lldMB of memory at %lldMB for crashkernel\n" , + crash_base >>20 , crash_size); }#else /* !defined(CONFIG_KEXEC) */ static void __init mips_parse_crashkernel (void ) { } - -static void __init request_crashkernel (struct resource *res) -{ -}#endif /* !defined(CONFIG_KEXEC) */ static void __init check_kernel_sections_mem (void )
@@ -656,10 +639,6 @@ static void __init arch_mem_init(char **cmdline_p)mips_reserve_vmcore ();mips_parse_crashkernel (); -#ifdef CONFIG_KEXEC -if (crashk_res.start != crashk_res.end) -memblock_reserve (crashk_res.start,resource_size (&crashk_res)); -#endif device_tree_init ();/*
@@ -683,53 +662,6 @@ static void __init arch_mem_init(char **cmdline_p)early_memtest (PFN_PHYS (ARCH_PFN_OFFSET ),PFN_PHYS (max_low_pfn)); } -static void __init resource_init (void ) -{ -phys_addr_t start, end; -u64 i; - -if (UNCAC_BASE !=IO_BASE ) -return ; - - code_resource.start =__pa_symbol (&_text); - code_resource.end =__pa_symbol (&_etext) -1 ; - data_resource.start =__pa_symbol (&_etext); - data_resource.end =__pa_symbol (&_edata) -1 ; - bss_resource.start =__pa_symbol (&__bss_start); - bss_resource.end =__pa_symbol (&__bss_stop) -1 ; - -for_each_mem_range (i, &start, &end) { -struct resource *res; - - res =memblock_alloc (sizeof (struct resource ),SMP_CACHE_BYTES ); -if (!res) -panic ("%s: Failed to allocate %zu bytes\n" , __func__, -sizeof (struct resource )); - - res->start = start; -/* -* In memblock, end points to the first byte after the -* range while in resourses, end points to the last byte in -* the range. -*/ - res->end = end -1 ; - res->flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ; - res->name ="System RAM" ; - -request_resource (&iomem_resource, res); - -/* -* We don't know which RAM region contains kernel data, -* so we try it repeatedly and let the resource manager -* test it. -*/ -request_resource (res, &code_resource); -request_resource (res, &data_resource); -request_resource (res, &bss_resource); -request_crashkernel (res); - } -} -#ifdef CONFIG_SMP static void __init prefill_possible_map (void ) {
@@ -771,7 +703,7 @@ void __init setup_arch(char **cmdline_p)arch_mem_init (cmdline_p);dmi_setup (); -resource_init (); +memblock_setup_resources ();plat_smp_setup ();prefill_possible_map ();
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 5/5 arm64: switch to generic memblock_setup_resources()
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
The implementation of resource setup on arm64 takes into account NOMAP regions and registers them as "Reserved" rather than as "System RAM". In addition, there is an extra pass that adds regions that were reserved in memblock to the resource tree as well.
Update the generic version of memblock_setup_resources() to take into the account NOMAP regions and move the registration of the reserved regions to memblock to have all the "System RAM" related resource data structures and code close to each other.
Only enable requests for the reserved resources if an architecture selects CONFIG_ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS.
--- arch/Kconfig | 7 +++ arch/arm64/Kconfig | 1 + arch/arm64/kernel/setup.c | 101 +------------------------------------- mm/memblock.c | 73 +++++++++++++++++++++------ 4 files changed, 68 insertions(+), 114 deletions(-)
arch/Kconfig +7 -0
@@ -1275,6 +1275,13 @@ config ARCH_SPLIT_ARG64 config ARCH_HAS_ELFCORE_COMPAT bool +config ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS + bool + help + If an architecture requires that memory regions reserved in + memblock will appear as "Reserved" in the resource tree, select + this option. + source "kernel/gcov/Kconfig" source "scripts/gcc-plugins/Kconfig"
arch/arm64/Kconfig +1 -0
@@ -93,6 +93,7 @@ config ARM64 select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS select ARCH_HAS_UBSAN_SANITIZE_ALL select ARM_AMBA select ARM_ARCH_TIMER
arch/arm64/kernel/setup.c +1 -100
121 lines not on this page · raw message
mm/memblock.c +59 -14
106 lines not on this page · raw message
Signature · 1 line
2.28.0
Re: [RFC/RFT PATCH 1/5] s390: make crashk_res resource a child of "System RAM"
In reply to Mike RapoportQuoted 6 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
Commit
4e042af463f8("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that.
Are you sure?
Looking at kexec-tools: kexec/arch/s390/kexec-s390.c
get_memory_ranges_s390() wants "System RAM" and Crash kernel only with "with_crashk=1". Your patch would change that. "Crash kernel" would always be included if you make it a child of "System RAM".
Further, get_memory_ranges() and is_crashkernel_mem_reserved() look out for "Crash kernel\n" via parse_iomem_single().
However, parse_iomem_single() does not care about ranges that start with spaces IIRC via
sscanf(line, "%llx-%llx : %n" ...
So once you make "Crash kernel" a child of "System RAM", kexec-tools would break if I'm not completely wrong.
Signature · 3 lines
Thanks, David / dhildenb
Re: [RFC/RFT PATCH 1/5] s390: make crashk_res resource a child of "System RAM"
Quoted 16 lines · David Hildenbrand
Quoted 6 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
Commit
4e042af463f8("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that.Are you sure?
Looking at kexec-tools:
kexec/arch/s390/kexec-s390.c
get_memory_ranges_s390()wants "System RAM" and Crash kernel only with "with_crashk=1". Your patch would change that. "Crash kernel" would always be included if you make it a child of "System RAM".
Quoted 6 lines
Further,
get_memory_ranges()andis_crashkernel_mem_reserved()look out for "Crash kernel\n" viaparse_iomem_single().However,
parse_iomem_single()does not care about ranges that start with spaces IIRC viasscanf(line, "%llx-%llx : %n" ...
I think I'm wrong about that one because I read
"Input white-space characters (as specified by the isspace function) are skipped, unless the specification includes a [ , c , or n specifier"
So having it as a child won't affect parse_iomem_single().
Signature · 3 lines
Thanks, David / dhildenb
Re: [RFC/RFT PATCH 1/5] s390: make crashk_res resource a child of "System RAM"
In reply to Mike RapoportQuoted 6 lines · On Mon, 31 May 2021 15:29:55 +0300 Mike Rapoport <[email protected]> wrote:
From: Mike Rapoport <[email protected]>
Commit
4e042af463f8("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that.
Still testing, but so far everything works fine.
Quoted 25 lines
Keeping
crashk_resinline with other resources makes code simpler and cleaner, and allows future consolidation of the resources setup across several architectures.Signed-off-by Mike Rapoport <[email protected]>--- arch/s390/kernel/setup.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)arch/s390/kernel/setup.c +3
-0@@ -500,6 +500,9 @@ static struct resource __initdata *standard_resources[] = { &code_resource, &data_resource, &bss_resource, +#ifdef CONFIG_CRASH_DUMP + &crashk_res, +#endif };static void __init setup_resources (void )
arch/s390/kernel/setup.c static void __init setup_resources(void) · line 544
Quoted 8 lines
arch/s390/kernel/setup.c +1
-1@@ -535,7 +538,7 @@ static void __init setup_resources(void)for (j =0 ; j <ARRAY_SIZE (standard_resources); j++) { std_res = standard_resources[j]; -if (std_res->start < res->start || +if (!std_res->end || std_res->start < res->start || std_res->start > res->end)continue ;if (std_res->end > res->end) {
Why is this extra check for !std_res->end added here? I assume it might be needed later, after you moved this to common code, but I cannot see how any of the other patches in this series would require that.
Quoted 22 lines
arch/s390/kernel/setup.c +0
-14@@ -552,20 +555,6 @@ static void __init setup_resources(void) } } } -#ifdef CONFIG_CRASH_DUMP -/* -* Re-add removed crash kernel memory as reserved memory. This makes -* sure it will be mapped with the identity mapping and struct pages -* will be created, so it can be resized later on. -* However add it later since the crash kernel resource should not be -* part of the System RAM resource. -*/ -if (crashk_res.end) { -memblock_add_node (crashk_res.start,resource_size (&crashk_res),0 ); -memblock_reserve (crashk_res.start,resource_size (&crashk_res)); -insert_resource (&iomem_resource, &crashk_res); - } -#endif }static void __init setup_ident_map_size (void )
arch/s390/kernel/setup.c static void __init reserve_crashkernel(void) · line 728
Quoted 8 lines
arch/s390/kernel/setup.c +1
-1@@ -733,7 +722,7 @@ static void __init reserve_crashkernel(void)diag10_range (PFN_DOWN (crash_base),PFN_DOWN (crash_size)); crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; -memblock_remove (crash_base, crash_size); +memblock_reserve (crash_base, crash_size); pr_info("Reserving %lluMB of memory at %lluMB " "for crashkernel (System RAM: %luMB)\n", crash_size >> 20, crash_base >> 20,
Other architectures check the return value of memblock_reserve() at this point, and exit crashkernel reservation if it fails. IIUC, the only reason why memblock_reserve() could fail would be the same reason why also memblock_remove() could fail, i.e. that memblock_double_array() would fail. And since we also do not check that at the moment, your patch would probably not (additionally) break anything.
Still, this might be something for an add-on patch (for us). Do you happen to know how likely it would be that memblock_remove/reserve() could fail at this point?
Russell King (Oracle)
maintainerQuoted 2 lines · Mike Rapoport
* arm has "System RAM (boot alias)" that do not seem useful for any other architecture
This is VERY important for kexec and must _not_ be removed, since you will be causing a userspace regression by doing so.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Russell King (Oracle)
maintainerRe: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
In reply to Mike Rapoportmm/memblock.c void __init memblock_free_all(void) · line 2111
Quoted 8 lines · Mike Rapoport
mm/memblock.c +8
-0+ code_resource.start =__pa_symbol (_text); + code_resource.end =__pa_symbol (_etext)-1 ; + rodata_resource.start =__pa_symbol (__start_rodata); + rodata_resource.end =__pa_symbol (__end_rodata)-1 ; + data_resource.start =__pa_symbol (_sdata); + data_resource.end =__pa_symbol (_edata)-1 ; + bss_resource.start =__pa_symbol (__bss_start); + bss_resource.end =__pa_symbol (__bss_stop)-1 ;
This falls short on 32-bit ARM. The old code was:
- kernel_code.start = virt_to_phys(_text); - kernel_code.end = virt_to_phys(__init_begin - 1); - kernel_data.start = virt_to_phys(_sdata); - kernel_data.end = virt_to_phys(_end - 1);
If I look at one of my kernels:
c0008000 T _textc0b5b000 R __end_rodata
... exception and unwind tables live here ...c0c00000 T __init_beginc0e00000 D _sdatac0e68870 D _edatac0e68870 B __bss_startc0e995d4 B __bss_stopc0e995d4 B _end
So the original covers _text..__init_begin-1 which includes the exception and unwind tables. Your version above omits these, which leaves them exposed.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Re: [RFC/RFT PATCH 1/5] s390: make crashk_res resource a child of "System RAM"
In reply to David HildenbrandQuoted 24 lines · David Hildenbrand
Quoted 16 lines · David Hildenbrand
Quoted 6 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
Commit
4e042af463f8("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that.Are you sure?
Looking at kexec-tools:
kexec/arch/s390/kexec-s390.c
get_memory_ranges_s390()wants "System RAM" and Crash kernel only with "with_crashk=1". Your patch would change that. "Crash kernel" would always be included if you make it a child of "System RAM".Quoted 6 lines
Further,
get_memory_ranges()andis_crashkernel_mem_reserved()look out for "Crash kernel\n" viaparse_iomem_single().However,
parse_iomem_single()does not care about ranges that start with spaces IIRC viasscanf(line, "%llx-%llx : %n" ...
Quoted 6 lines
I think I'm wrong about that one because I read
"Input white-space characters (as specified by the isspace function) are skipped, unless the specification includes a [ , c , or n specifier"
So having it as a child won't affect
parse_iomem_single().
Yes, this was my understanding as well.
Signature · 2 lines
Sincerely yours, Mike.
Re: [RFC/RFT PATCH 1/5] s390: make crashk_res resource a child of "System RAM"
In reply to Gerald SchaeferQuoted 38 lines · Gerald Schaefer
Quoted 6 lines · On Mon, 31 May 2021 15:29:55 +0300 Mike Rapoport <[email protected]> wrote:
From: Mike Rapoport <[email protected]>
Commit
4e042af463f8("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that.Still testing, but so far everything works fine.
Quoted 26 lines
Keeping
crashk_resinline with other resources makes code simpler and cleaner, and allows future consolidation of the resources setup across several architectures.Signed-off-by Mike Rapoport <[email protected]>--- arch/s390/kernel/setup.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)arch/s390/kernel/setup.c +3
-0@@ -500,6 +500,9 @@ static struct resource __initdata *standard_resources[] = { &code_resource, &data_resource, &bss_resource, +#ifdef CONFIG_CRASH_DUMP + &crashk_res, +#endif };static void __init setup_resources (void )@@ -535,7 +538,7 @@ static void __init setup_resources(void)
Quoted 12 lines
arch/s390/kernel/setup.c static void __init setup_resources(void) · line 544
Quoted 7 lines
arch/s390/kernel/setup.c +1
-1for (j =0 ; j <ARRAY_SIZE (standard_resources); j++) { std_res = standard_resources[j]; -if (std_res->start < res->start || +if (!std_res->end || std_res->start < res->start || std_res->start > res->end)continue ;if (std_res->end > res->end) {Why is this extra check for !std_res->end added here? I assume it might be needed later, after you moved this to common code, but I cannot see how any of the other patches in this series would require that.
This is needed to avoid requesting empty crash_res.
Quoted 29 lines
Quoted 29 lines
arch/s390/kernel/setup.c +1
-15@@ -552,20 +555,6 @@ static void __init setup_resources(void) } } } -#ifdef CONFIG_CRASH_DUMP -/* -* Re-add removed crash kernel memory as reserved memory. This makes -* sure it will be mapped with the identity mapping and struct pages -* will be created, so it can be resized later on. -* However add it later since the crash kernel resource should not be -* part of the System RAM resource. -*/ -if (crashk_res.end) { -memblock_add_node (crashk_res.start,resource_size (&crashk_res),0 ); -memblock_reserve (crashk_res.start,resource_size (&crashk_res)); -insert_resource (&iomem_resource, &crashk_res); - } -#endif }static void __init setup_ident_map_size (void )@@ -733,7 +722,7 @@ static void __init reserve_crashkernel(void)diag10_range (PFN_DOWN (crash_base),PFN_DOWN (crash_size)); crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size -1 ; -memblock_remove (crash_base, crash_size); +memblock_reserve (crash_base, crash_size); pr_info("Reserving %lluMB of memory at %lluMB " "for crashkernel (System RAM: %luMB)\n",
Quoted 8 lines
arch/s390/kernel/setup.c static void __init reserve_crashkernel(void) · line 728
Quoted 1 line
arch/s390/kernel/setup.c +0
-0crash_size >> 20, crash_base >> 20,Other architectures check the return value of
memblock_reserve()at this point, and exit crashkernel reservation if it fails. IIUC, the only reason whymemblock_reserve()could fail would be the same reason why alsomemblock_remove()could fail, i.e. thatmemblock_double_array()would fail. And since we also do not check that at the moment, your patch would probably not (additionally) break anything.
We don't check the return value of memblock_reserve() (or memblock_remove() for that matter) in vast majority of cases all over the place, but it is very much unlikely it will fail because there is not enough memory.
Quoted 3 lines
Still, this might be something for an add-on patch (for us). Do you happen to know how likely it would be that memblock_remove/reserve() could fail at this point?
Generally, the worst case scenario is that memblock_remove/reserve() will need to double one of the memblock arrays. This will require to allocate several kilobytes of memory, but since the memory this early is mostly free it should not be a problem.
Looking particularly at s390 case, there are handful of reservations before setup_resouces(), so we can accommodate more than 100 calls to memblock_reserve() before we'll need to increase memblock.reserved array.
Signature · 2 lines
Sincerely yours, Mike.
Quoted 6 lines · Russell King (Oracle)
Quoted 2 lines · Mike Rapoport
* arm has "System RAM (boot alias)" that do not seem useful for any other architecture
This is VERY important for kexec and must _not_ be removed, since you will be causing a userspace regression by doing so.
I didn't remove these. I'll update the changelog and the cover letter to make it clear.
Signature · 2 lines
Sincerely yours, Mike.
Re: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
In reply to Russell King (Oracle)Quoted 29 lines · Russell King (Oracle)
mm/memblock.c void __init memblock_free_all(void) · line 2111
Quoted 8 lines · Mike Rapoport
mm/memblock.c +8
-0+ code_resource.start =__pa_symbol (_text); + code_resource.end =__pa_symbol (_etext)-1 ; + rodata_resource.start =__pa_symbol (__start_rodata); + rodata_resource.end =__pa_symbol (__end_rodata)-1 ; + data_resource.start =__pa_symbol (_sdata); + data_resource.end =__pa_symbol (_edata)-1 ; + bss_resource.start =__pa_symbol (__bss_start); + bss_resource.end =__pa_symbol (__bss_stop)-1 ;This falls short on 32-bit ARM. The old code was:
(quoted diff) +0
-4- kernel_code.start = virt_to_phys(_text); - kernel_code.end = virt_to_phys(__init_begin - 1); - kernel_data.start = virt_to_phys(_sdata); - kernel_data.end = virt_to_phys(_end - 1);If I look at one of my kernels:
c0008000T_textc0b5b000R__end_rodata
... exception and unwind tables live here ...c0c00000T__init_beginc0e00000D_sdatac0e68870D_edatac0e68870B__bss_startc0e995d4B__bss_stopc0e995d4B_end
Quoted 3 lines
So the original covers _text..__init_begin-1 which includes the exception and unwind tables. Your version above omits these, which leaves them exposed.
Right, this needs to be fixed. Is there any reason the exception and unwind tables cannot be placed between _sdata and _edata?
It seems to me that they were left outside for purely historical reasons. Commit ee951c630c5c ("ARM: 7568/1: Sort exception table at compile time") moved the exception tables out of .data section before _sdata existed. Commit 14c4a533e099 ("ARM: 8583/1: mm: fix location of _etext") moved _etext before the unwind tables and didn't bother to put them into data or rodata areas.
Signature · 2 lines
Sincerely yours, Mike.
Russell King (Oracle)
maintainerRe: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
Quoted 37 lines · Mike Rapoport
Quoted 29 lines · Russell King (Oracle)
mm/memblock.c void __init memblock_free_all(void) · line 2111
Quoted 8 lines · Mike Rapoport
mm/memblock.c +8
-0+ code_resource.start =__pa_symbol (_text); + code_resource.end =__pa_symbol (_etext)-1 ; + rodata_resource.start =__pa_symbol (__start_rodata); + rodata_resource.end =__pa_symbol (__end_rodata)-1 ; + data_resource.start =__pa_symbol (_sdata); + data_resource.end =__pa_symbol (_edata)-1 ; + bss_resource.start =__pa_symbol (__bss_start); + bss_resource.end =__pa_symbol (__bss_stop)-1 ;This falls short on 32-bit ARM. The old code was:
(quoted diff) +0
-4- kernel_code.start = virt_to_phys(_text); - kernel_code.end = virt_to_phys(__init_begin - 1); - kernel_data.start = virt_to_phys(_sdata); - kernel_data.end = virt_to_phys(_end - 1);If I look at one of my kernels:
c0008000T_textc0b5b000R__end_rodata
... exception and unwind tables live here ...c0c00000T__init_beginc0e00000D_sdatac0e68870D_edatac0e68870B__bss_startc0e995d4B__bss_stopc0e995d4B_endQuoted 3 lines
So the original covers _text..__init_begin-1 which includes the exception and unwind tables. Your version above omits these, which leaves them exposed.
Right, this needs to be fixed. Is there any reason the exception and unwind tables cannot be placed between
_sdataand_edata?
Quoted 6 lines
It seems to me that they were left outside for purely historical reasons. Commit
ee951c630c5c("ARM: 7568/1: Sort exception table at compile time") moved the exception tables out of .data section before_sdataexisted. Commit14c4a533e099("ARM: 8583/1: mm: fix location of_etext") moved_etextbefore the unwind tables and didn't bother to put them into data or rodata areas.
You can not assume that all sections will be between these symbols. This isn't specific to 32-bit ARM. If you look at x86's vmlinux.lds.in, you will see that BUG_TABLE and ORC_UNWIND_TABLE are after _edata, along with many other undiscarded sections before __bss_start. So it seems your assumptions in trying to clean this up are somewhat false.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Re: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
Quoted 45 lines · Russell King (Oracle)
Quoted 37 lines · Mike Rapoport
Quoted 29 lines · Russell King (Oracle)
mm/memblock.c void __init memblock_free_all(void) · line 2111
Quoted 8 lines · Mike Rapoport
mm/memblock.c +8
-0+ code_resource.start =__pa_symbol (_text); + code_resource.end =__pa_symbol (_etext)-1 ; + rodata_resource.start =__pa_symbol (__start_rodata); + rodata_resource.end =__pa_symbol (__end_rodata)-1 ; + data_resource.start =__pa_symbol (_sdata); + data_resource.end =__pa_symbol (_edata)-1 ; + bss_resource.start =__pa_symbol (__bss_start); + bss_resource.end =__pa_symbol (__bss_stop)-1 ;This falls short on 32-bit ARM. The old code was:
(quoted diff) +0
-4- kernel_code.start = virt_to_phys(_text); - kernel_code.end = virt_to_phys(__init_begin - 1); - kernel_data.start = virt_to_phys(_sdata); - kernel_data.end = virt_to_phys(_end - 1);If I look at one of my kernels:
c0008000T_textc0b5b000R__end_rodata
... exception and unwind tables live here ...c0c00000T__init_beginc0e00000D_sdatac0e68870D_edatac0e68870B__bss_startc0e995d4B__bss_stopc0e995d4B_endQuoted 3 lines
So the original covers _text..__init_begin-1 which includes the exception and unwind tables. Your version above omits these, which leaves them exposed.
Right, this needs to be fixed. Is there any reason the exception and unwind tables cannot be placed between
_sdataand_edata?Quoted 6 lines
It seems to me that they were left outside for purely historical reasons. Commit
ee951c630c5c("ARM: 7568/1: Sort exception table at compile time") moved the exception tables out of .data section before_sdataexisted. Commit14c4a533e099("ARM: 8583/1: mm: fix location of_etext") moved_etextbefore the unwind tables and didn't bother to put them into data or rodata areas.
Quoted 4 lines
You can not assume that all sections will be between these symbols. This isn't specific to 32-bit ARM. If you look at x86's vmlinux.lds.in, you will see that
BUG_TABLEandORC_UNWIND_TABLEare after_edata, along with many other undiscarded sections before__bss_start.
But if you look at x86's setup_arch() all these never make it to the resource tree. So there are holes in /proc/iomem between the kernel resources.
Quoted 2 lines
So it seems your assumptions in trying to clean this up are somewhat false.
My assumption was that there is complete lack of consistency between what is reserved memory and how it is reported in /proc/iomem or /sys/firmware/memmap for that matter. I'm not trying to clean this up, I'm trying to make different views of the physical memory consistent. Consolidating several similar per-arch implementations is the first step in this direction.
Signature · 2 lines
Sincerely yours, Mike.
Russell King (Oracle)
maintainerRe: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
Quoted 29 lines · Mike Rapoport
Quoted 28 lines · Russell King (Oracle)
Quoted 26 lines · Mike Rapoport
Quoted 12 lines · Russell King (Oracle)
If I look at one of my kernels:
c0008000T_textc0b5b000R__end_rodata
... exception and unwind tables live here ...c0c00000T__init_beginc0e00000D_sdatac0e68870D_edatac0e68870B__bss_startc0e995d4B__bss_stopc0e995d4B_endQuoted 3 lines
So the original covers _text..__init_begin-1 which includes the exception and unwind tables. Your version above omits these, which leaves them exposed.
Right, this needs to be fixed. Is there any reason the exception and unwind tables cannot be placed between
_sdataand_edata?It seems to me that they were left outside for purely historical reasons. Commit
ee951c630c5c("ARM: 7568/1: Sort exception table at compile time") moved the exception tables out of .data section before_sdataexisted. Commit14c4a533e099("ARM: 8583/1: mm: fix location of_etext") moved_etextbefore the unwind tables and didn't bother to put them into data or rodata areas.
Quoted 8 lines
Quoted 4 lines
You can not assume that all sections will be between these symbols. This isn't specific to 32-bit ARM. If you look at x86's vmlinux.lds.in, you will see that
BUG_TABLEandORC_UNWIND_TABLEare after_edata, along with many other undiscarded sections before__bss_start.But if you look at x86's
setup_arch()all these never make it to the resource tree. So there are holes in/proc/iomembetween the kernel resources.
Also true. However, my point was to counter your claim that these sections should be part of the .text/.data/.rodata etc sections in the output vmlinux.
There is, however, a more important point. The __ex_table section must exist and be separate from the .text/.data/.rodata sections in the output ELF file, as sorttable (the exception table sorter) relies on this to be able to find the table and sort it.
So, it isn't entirely "for historical reasons" as you said two messages ago.
Quoted 9 lines
Quoted 2 lines
So it seems your assumptions in trying to clean this up are somewhat false.
My assumption was that there is complete lack of consistency between what is reserved memory and how it is reported in
/proc/iomemor/sys/firmware/memmapfor that matter. I'm not trying to clean this up, I'm trying to make different views of the physical memory consistent. Consolidating several similar per-arch implementations is the first step in this direction.
It looks to me that there is quite a number of things that need fixing. One glaring thing is the kernel's init memory - should that be counted as reserved memory? It's marked as such in memblock and /proc/iomem, yet we free these pages into the page allocator after boot meaning they are just like any other page in the memory allocator - they are most certainly not "reserved" at that point.
So, what is reported as reserved in firmware maps will be different from memblock. Memblock includes kernel boot-time allocations, which count as "reserved" but are not part of the firmware maps - these will be for things like early page tables and the struct page array. So, you're never going to get consistency between memblock and firmware.
Memblock and /proc/iomem should be fairly consistent - areas marked as reserved in memblock seem to be propagated into /proc/iomem, including areas around the kernel image (the resources that you're changing in your patch.) Here's an example:
/sys/kernel/debug/memblock/reserved:
1: 0x0000000081210000..0x0000000082d6efff
2: 0x0000000082d71000..0x0000000082d7ffff
81210000-821cffff : Kernel code
821d0000-8246ffff : reserved
82470000-82d7ffff : Kernel data
This is aarch64, which isn't as accurate as 32-bit ARM in /proc/iomem:
/sys/kernel/debug/memblock/reserved:
1: 0x0000000040200000..0x0000000040ea1c17
/proc/iomem:
40008000-40bfffff : Kernel code
40e00000-40ea1c17 : Kernel data
32-bit ARM doesn't forward the memblock reserved areas into /proc/iomem because they are kernel allocations. In the example I show above for 32-bit ARM, there are no firmware reserved regions, yet there are 19 memblock "reserved" regions.
I think part of the problem here is understanding what "reserved" means in these cases. For something passed to the kernel from firmware, it's an area that firmware doesn't want the OS to use. For memblock, it is those areas plus allocations made early on during kernel boot before the page allocator is up and running, and includes areas of memory that these allocations must avoid (e.g. due to initramfs or device tree temporarily residing there.) Then there's differences in what should be placed in /proc/iomem.
Now, bear in mind that /proc/iomem is a user API, one which userspace depends on. If we start going around making /proc/iomem report stuff like kernel boot time reservations as "reserved" memory, we will end up breaking the kexec tooling on some platforms. For example, kexec tooling for 32-bit ARM parses /proc/iomem, looking for "System RAM", "System RAM (boot alias)" and "reserved" regions.
So, I think changes to make this "more consistent" come with high risk.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Mike Rapoport
maintainerRe: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
Quoted 43 lines · Russell King (Oracle)
Quoted 29 lines · Mike Rapoport
Quoted 28 lines · Russell King (Oracle)
Quoted 26 lines · Mike Rapoport
Quoted 12 lines · Russell King (Oracle)
If I look at one of my kernels:
c0008000T_textc0b5b000R__end_rodata
... exception and unwind tables live here ...c0c00000T__init_beginc0e00000D_sdatac0e68870D_edatac0e68870B__bss_startc0e995d4B__bss_stopc0e995d4B_endQuoted 3 lines
So the original covers _text..__init_begin-1 which includes the exception and unwind tables. Your version above omits these, which leaves them exposed.
Right, this needs to be fixed. Is there any reason the exception and unwind tables cannot be placed between
_sdataand_edata?It seems to me that they were left outside for purely historical reasons. Commit
ee951c630c5c("ARM: 7568/1: Sort exception table at compile time") moved the exception tables out of .data section before_sdataexisted. Commit14c4a533e099("ARM: 8583/1: mm: fix location of_etext") moved_etextbefore the unwind tables and didn't bother to put them into data or rodata areas.Quoted 8 lines
Quoted 4 lines
You can not assume that all sections will be between these symbols. This isn't specific to 32-bit ARM. If you look at x86's vmlinux.lds.in, you will see that
BUG_TABLEandORC_UNWIND_TABLEare after_edata, along with many other undiscarded sections before__bss_start.But if you look at x86's
setup_arch()all these never make it to the resource tree. So there are holes in/proc/iomembetween the kernel resources.Also true. However, my point was to counter your claim that these sections should be part of the .text/.data/.rodata etc sections in the output vmlinux.
Quoted 7 lines
There is, however, a more important point. The
__ex_tablesection must exist and be separate from the .text/.data/.rodata sections in the output ELF file, as sorttable (the exception table sorter) relies on this to be able to find the table and sort it.So, it isn't entirely "for historical reasons" as you said two messages ago.
Back then when __ex_table was moved from .data section, _sdata and _edata were part of the .data section. Today they are not. So something like the patch below will ensure for instance that __ex_table would be a part of "Kernel data" in /proc/iomem without moving it to the .data section:
arch/arm/kernel/vmlinux.lds.S +8 -7
@@ -72,13 +72,6 @@ SECTIONS RO_DATA(PAGE_SIZE) - . = ALIGN(4); - __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { - __start___ex_table = .; - ARM_MMU_KEEP(*(__ex_table)) - __stop___ex_table = .; - } - #ifdef CONFIG_ARM_UNWIND ARM_UNWIND_SECTIONS #endif
@@ -143,6 +136,14 @@ SECTIONS __init_end = .; _sdata = .; + + . = ALIGN(4); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + ARM_MMU_KEEP(*(__ex_table)) + __stop___ex_table = .; + } + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) _edata = .;
Quoted 9 lines
Now, bear in mind that
/proc/iomemis a user API, one which userspace depends on. If we start going around making/proc/iomemreport stuff like kernel boot time reservations as "reserved" memory, we will end up breaking the kexec tooling on some platforms. For example, kexec tooling for 32-bit ARM parses/proc/iomem, looking for "System RAM", "System RAM (boot alias)" and "reserved" regions.So, I think changes to make this "more consistent" come with high risk.
I agree there is a risk but I don't think it's high. It does not look like the minor changes in "reserved" reporting in /proc/iomem will break kexec tooling. Anyway the amount of reserved and free memory depends on a particular system, kernel version, configuration and command line. I have no intention to report kernel boot time reservations
to /proc/iomem on architectures that do not report them there today, although this also does not seem like a significant factor.
On the other hand, making /proc/iomem reporting consistent among architectures will allow to reduce complexity of both the kernel and kexec tools in the long run.
Signature · 2 lines
Sincerely yours, Mike.
Russell King (Oracle)
maintainerRe: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
Quoted 27 lines · Mike Rapoport
Back then when
__ex_tablewas moved from .data section,_sdataand_edatawere part of the .data section. Today they are not. So something like the patch below will ensure for instance that__ex_tablewould be a part of "Kernel data" in/proc/iomemwithout moving it to the .data section:arch/arm/kernel/vmlinux.lds.S +0
-7@@ -72,13 +72,6 @@ SECTIONS RO_DATA(PAGE_SIZE) - . = ALIGN(4); - __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { - __start___ex_table = .; - ARM_MMU_KEEP(*(__ex_table)) - __stop___ex_table = .; - } - #ifdef CONFIG_ARM_UNWIND ARM_UNWIND_SECTIONS #endif@@ -143,6 +136,14 @@ SECTIONS __init_end = .; _sdata = .;
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 148
Quoted 10 lines
arch/arm/kernel/vmlinux.lds.S +8
-0+ + . = ALIGN(4); + __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { + __start___ex_table = .; + ARM_MMU_KEEP(*(__ex_table)) + __stop___ex_table = .; + } + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) _edata = .;
This example has undesirable security implications. It moves the exception table out of the read-only mappings into the read-write mappings, thereby providing a way for an attacker to bypass the read-only protection on the kernel and manipulate code pointers at potentially known addresses for distro built kernels.
Quoted 3 lines
I agree there is a risk but I don't think it's high. It does not look like the minor changes in "reserved" reporting in
/proc/iomemwill break kexec tooling.
What makes you come to that conclusion? The kexec tools architecture backends get to decide what they do when parsing /proc/iomem. Currently, only firmware areas are marked reserved in /proc/iomem on 32-bit ARM.
This is read by kexec, and entered into its memory_range[] table as either RAM, or RESERVED.
kexec uses this to search for a suitable hole in the memory map to place the kernel in physical memory. The addition of what I will call ficticious "reserved" areas by the host kernel because the host kernel happened to use them _will_ have an impact on this.
They _are_ ficticious, because they are purely an artifact of the host kernel being run, and are of no consequence to tooling such as kexec. What such tooling is interested in is which areas it needs to avoid because of firmware.
I think what isn't helping here is that you haven't adequately described what your overall objective actually is. Framing it in terms of wanting the reserved memory to be consistent between the various kernel "interfaces" such as /proc/iomem, the memblock debugfs and firmware is very ambiguous and open to different interpretations, whcih I think is what the problem is here.
Quoted 5 lines
Anyway the amount of reserved and free memory depends on a particular system, kernel version, configuration and command line. I have no intention to report kernel boot time reservations to
/proc/iomemon architectures that do not report them there today, although this also does not seem like a significant factor.
You seem to be missing the point I've tried to make. The areas in memblock that are marked "reserved" are the areas of reserved memory from the firmware _plus_ the areas that the kernel has made during boot which are of no consequence to userspace.
Wanting /proc/iomem, memblock and firmware to all agree on the values that they mark as "reserved" is IMHO unrealistic.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Mike Rapoport
maintainerRe: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources()
Quoted 11 lines · Russell King (Oracle)
Quoted 5 lines · Mike Rapoport
Back then when
__ex_tablewas moved from .data section,_sdataand_edatawere part of the .data section. Today they are not. So something like the patch below will ensure for instance that__ex_tablewould be a part of "Kernel data" in/proc/iomemwithout moving it to the .data section:This example has undesirable security implications. It moves the exception table out of the read-only mappings into the read-write mappings, thereby providing a way for an attacker to bypass the read-only protection on the kernel and manipulate code pointers at potentially known addresses for distro built kernels.
My point was that __ex_table can be in "Kernel data" or "Kernel rodata" without loosing the ability to sort it.
Quoted 4 lines
You seem to be missing the point I've tried to make. The areas in memblock that are marked "reserved" are the areas of reserved memory from the firmware _plus_ the areas that the kernel has made during boot which are of no consequence to userspace.
I know what areas are marked "reserved" in memblock.
I never suggested to report "ficticious" reserved areas in /proc/iomem unless an architecture already reports them there, like arm64 for example.
You are right I should have described better the overall objective, but sill I feel that we keep missing each other points.
I'll update the descriptions for the next repost, hopefully it'll help.
Signature · 2 lines
Sincerely yours, Mike.