arm64:kexec: Memstart should not be before the kernel start address
Subsystems (2)
PATCH v2 1/1 arm64:kexec: Memstart should not be before the kernel start address
Starting 4.6 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved meory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.
---
This change should be applied on top of geoff kexec-tools v3 branch from arm64[1] + bugfix[2]
[1] http://lists.infradead.org/pipermail/kexec/2016-August/016768.html
[2] http://lists.infradead.org/pipermail/kexec/2016-July/016664.html
kexec/arch/arm64/kexec-arm64.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
kexec/arch/arm64/kexec-arm64.c +34 -1
@@ -25,6 +25,11 @@/* Global varables the core kexec routines expect. */ +#define SZ_2M 0x200000 +#define __round_mask (x, y) ((__typeof__(x))((y)-1)) +#define round_up (x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_down (x, y) ((x) & ~__round_mask(x, y)) +unsigned char reuse_initrd;off_t initrd_base;
@@ -448,6 +453,27 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,add_segment_phys_virt (info, buf, bufsz, base, memsz,1 ); } +static int get_memory_ranges_iomem_kc_cb (void *data,int nr,char *str, +unsigned long long base,unsigned long long length) +{ +struct memory_range *r; + +if (nr >=KEXEC_SEGMENT_MAX ) +return -1 ; + + r = (struct memory_range *)data + nr; + r->type =RANGE_RAM ; + r->start = base; + r->end = base + length -1 ; + +set_phys_offset (round_down (r->start,SZ_2M )); + +dbgprintf ("%s: %016llx - %016llx : %s" , __func__, r->start, + r->end, str); + +return 0 ; +} +/** * get_memory_ranges_iomem_cb - Helper for get_memory_ranges_iomem. */
@@ -465,7 +491,6 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, r->start = base; r->end = base + length -1 ; -set_phys_offset (r->start);dbgprintf ("%s: %016llx - %016llx : %s" , __func__, r->start, r->end, str);
@@ -480,6 +505,14 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str,static int get_memory_ranges_iomem (struct memory_range *array,unsigned int *count) { + *count =kexec_iomem_for_each_line ("Kernel code\n" , + get_memory_ranges_iomem_kc_cb, array); + +if (!*count) { +dbgprintf ("%s: failed: No code segment found.\n" , __func__); +return -EFAILED ; + } + *count =kexec_iomem_for_each_line ("System RAM\n" , get_memory_ranges_iomem_cb, array);
Signature · 7 lines
Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Sameer,
Quoted 62 lines · Sameer Goel
Starting 4.6 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved meory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.Signed-off-by Sameer Goel <[email protected]>---
This change should be applied on top of geoff kexec-tools v3 branch from arm64[1] + bugfix[2][1] http://lists.infradead.org/pipermail/kexec/2016-August/016768.html
[2] http://lists.infradead.org/pipermail/kexec/2016-July/016664.htmlkexec/arch/arm64/kexec-arm64.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)kexec/arch/arm64/kexec-arm64.c +26
-0@@ -25,6 +25,11 @@/* Global varables the core kexec routines expect. */ +#define SZ_2M 0x200000 +#define __round_mask (x, y) ((__typeof__(x))((y)-1)) +#define round_up (x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_down (x, y) ((x) & ~__round_mask(x, y)) +unsigned char reuse_initrd;off_t initrd_base;@@ -448,6 +453,27 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,add_segment_phys_virt (info, buf, bufsz, base, memsz,1 ); } +static int get_memory_ranges_iomem_kc_cb (void *data,int nr,char *str, +unsigned long long base,unsigned long long length) +{ +struct memory_range *r; + +if (nr >=KEXEC_SEGMENT_MAX ) +return -1 ; + + r = (struct memory_range *)data + nr; + r->type =RANGE_RAM ; + r->start = base; + r->end = base + length -1 ; + +set_phys_offset (round_down (r->start,SZ_2M )); + +dbgprintf ("%s: %016llx - %016llx : %s" , __func__, r->start, + r->end, str); + +return 0 ; +} +/** * get_memory_ranges_iomem_cb - Helper for get_memory_ranges_iomem. */
kexec/arch/arm64/kexec-arm64.c static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, · line 468
Quoted 4 lines
kexec/arch/arm64/kexec-arm64.c +0
-1@@ -465,7 +491,6 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, r->start = base; r->end = base + length -1 ; -set_phys_offset (r->start);
I think phys_offset definition was already closer with the kernel definition. phys_offset has been defined in kernel as start of DRAM rounded down to section size alignment.
Now, with this patch physical offset will be start of Kernel Code rounded to the 2M alignment, which might not be matching to the physical offset from kernel.
kexec/arch/arm64/kexec-arm64.c static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, · line 509
Quoted 9 lines
kexec/arch/arm64/kexec-arm64.c +2
-0dbgprintf ("%s: %016llx - %016llx : %s" , __func__, r->start, r->end, str);@@ -480,6 +505,14 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str,static int get_memory_ranges_iomem (struct memory_range *array,unsigned int *count) { + *count =kexec_iomem_for_each_line ("Kernel code\n" , + get_memory_ranges_iomem_kc_cb, array);
May be I am missing someting...
IIUC, then the whole purpose of doing the above hunk is to get a physical offset value which allows you to pick the correct kernel start address, right? If yes, then IMHO we should correct page_offset definition rather than physical offset.
kexec/arch/arm64/kexec-arm64.c static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, · line 518
Quoted 9 lines
kexec/arch/arm64/kexec-arm64.c +6
-0+ +if (!*count) { +dbgprintf ("%s: failed: No code segment found.\n" , __func__); +return -EFAILED ; + } + *count =kexec_iomem_for_each_line ("System RAM\n" , get_memory_ranges_iomem_cb, array);
~Pratyush
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Sameer,
Quoted 2 lines · Sameer Goel
Starting 4.6 the kernel memblock start is rounded down to a desirable alignment.
Please mention here the kernel commit that made this change, maybe 'kernel commit a7f8de168ace ("arm64: allow kernel Image to be loaded anywhere in physical memory")'?
Quoted 4 lines
So, the kernel can see reserved meory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.
Please run kexec with the --debug option and post the get_memory_ranges output to the ML or send me directly if you consider it sensitive.
-Geoff
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec