arm64: make phys_to_virt() correct
Subsystems (2)
cover arm64: make phys_to_virt() correct
Currently phys_to_virt() does not work well on 52-bits VA arm64 kernel. One issue is contributed by phys_offset not signed.
The other is contributed by wrong page_offset.
This series fixes them so vmcore-dmesg can work on 52-bits VA kernel
Pingfan Liu (3):
arm64: make phys_offset signed arm64/crashdump: unify routine to get page_offset
arm64: read VA_BITS from kcore for 52-bits VA kernel
kexec/arch/arm64/crashdump-arm64.c | 23 +--------------- kexec/arch/arm64/kexec-arm64.c | 43 +++++++++++++++++++++++------- kexec/arch/arm64/kexec-arm64.h | 4 ++- util_lib/elf_info.c | 7 ++++- util_lib/include/elf_info.h | 2 +- 5 files changed, 44 insertions(+), 35 deletions(-)
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/3 arm64: make phys_offset signed
After kernel commit 7bc1a0f9e176 ("arm64: mm: use single quantity to represent the PA to VA translation"), phys_offset can be negative if running 52-bits kernel on 48-bits hardware.
So changing phys_offset from unsigned to signed.
--- kexec/arch/arm64/kexec-arm64.c | 8 ++++---- kexec/arch/arm64/kexec-arm64.h | 2 +- util_lib/elf_info.c | 2 +- util_lib/include/elf_info.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
kexec/arch/arm64/kexec-arm64.c +4 -4
@@ -859,7 +859,7 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,add_segment_phys_virt (info, buf, bufsz, base, memsz,1 ); } -static inline void set_phys_offset (uint64_t v,char *set_method) +static inline void set_phys_offset (long v,char *set_method) {if (arm64_mem.phys_offset == arm64_mem_ngv || v < arm64_mem.phys_offset) {
@@ -928,7 +928,7 @@ static int get_page_offset(void)* from VMCOREINFO note inside 'kcore'. */ -static int get_phys_offset_from_vmcoreinfo_pt_note (unsigned long *phys_offset) +static int get_phys_offset_from_vmcoreinfo_pt_note (long *phys_offset) {int fd, ret =0 ;
@@ -948,7 +948,7 @@ static int get_phys_offset_from_vmcoreinfo_pt_note(unsigned long *phys_offset)* from PT_LOADs inside 'kcore'. */ -int get_phys_base_from_pt_load (unsigned long *phys_offset) +int get_phys_base_from_pt_load (long *phys_offset) {int i, fd, ret;unsigned long long phys_start;
@@ -997,7 +997,7 @@ static bool to_be_excluded(char *str)int get_memory_ranges (struct memory_range **range,int *ranges,unsigned long kexec_flags) { -unsigned long phys_offset =UINT64_MAX ; +long phys_offset = (long )UINT64_MAX ;FILE *fp;const char *iomem =proc_iomem ();char line[MAX_LINE ], *str;
kexec/arch/arm64/kexec-arm64.h +1 -1
@@ -58,7 +58,7 @@ extern off_t initrd_size;*/ struct arm64_mem { -uint64_t phys_offset; +long phys_offset;uint64_t text_offset;uint64_t image_size;uint64_t vp_offset;
util_lib/elf_info.c +1 -1
@@ -1236,7 +1236,7 @@ int read_elf(int fd)return 0 ; } -int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off) +int read_phys_offset_elf_kcore (int fd,long *phys_off) {int ret;
util_lib/include/elf_info.h +1 -1
@@ -28,7 +28,7 @@ int get_pt_load(int idx,unsigned long long *phys_end, unsigned long long *virt_start, unsigned long long *virt_end); -int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off); +int read_phys_offset_elf_kcore (int fd,long *phys_off);int read_elf (int fd);void dump_dmesg (int fd,void (*handler)(char *,unsigned int ));
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 2/3 arm64/crashdump: unify routine to get page_offset
In reply to Pingfan LiuThere are two funcs to get page_offset:
get_kernel_page_offset()
get_page_offset()
Since get_kernel_page_offset() does not observe the kernel formula, and remove it. Unify them in order to introduce 52-bits VA kernel more easily in the coming patch.
--- kexec/arch/arm64/crashdump-arm64.c | 23 +---------------------- kexec/arch/arm64/kexec-arm64.c | 4 ++-- kexec/arch/arm64/kexec-arm64.h | 1 + 3 files changed, 4 insertions(+), 24 deletions(-)
kexec/arch/arm64/crashdump-arm64.c +1 -22
@@ -46,27 +46,6 @@ static struct crash_elf_info elf_info = { .machine = EM_AARCH64, }; -/* -* Note: The returned value is correct only if !CONFIG_RANDOMIZE_BASE. -*/ -static uint64_t get_kernel_page_offset (void ) -{ -int i; - -if (elf_info.kern_vaddr_start ==UINT64_MAX ) -return UINT64_MAX ; - -/* Current max virtual memory range is 48-bits. */ -for (i =48 ; i >0 ; i--) -if (!(elf_info.kern_vaddr_start & (1UL << i))) -break ; - -if (i <=0 ) -return UINT64_MAX ; -else -return UINT64_MAX << i; -} -/* * iomem_range_callback() - callback called for each iomem region * @data: not used
@@ -198,7 +177,7 @@ int load_crashdump_segments(struct kexec_info *info)if (err)return EFAILED ; - elf_info.page_offset =get_kernel_page_offset (); +get_page_offset (&elf_info.page_offset);dbgprintf ("%s: page_offset: %016llx\n" , __func__, elf_info.page_offset);
kexec/arch/arm64/kexec-arm64.c +2 -2
@@ -909,7 +909,7 @@ static int get_va_bits(void)* get_page_offset - Helper for getting PAGE_OFFSET */ -static int get_page_offset (void ) +int get_page_offset (unsigned long *page_offset) {int ret;
@@ -954,7 +954,7 @@ int get_phys_base_from_pt_load(long *phys_offset)unsigned long long phys_start;unsigned long long virt_start; - ret =get_page_offset (); + ret =get_page_offset (&page_offset);if (ret <0 )return ret;
kexec/arch/arm64/kexec-arm64.h +1 -0
@@ -69,6 +69,7 @@ extern struct arm64_mem arm64_mem;uint64_t get_phys_offset (void );uint64_t get_vp_offset (void ); +int get_page_offset (unsigned long *offset);static inline void reset_vp_offset (void ) {
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/3] arm64/crashdump: unify routine to get page_offset
Hi Pinfang,
Quoted 19 lines · On Fri, 10 Dec 2021 11:07:34 +0800 Pingfan Liu <[email protected]> wrote:
There are two funcs to get
page_offset:
get_kernel_page_offset()
get_page_offset()Since
get_kernel_page_offset()does not observe the kernel formula, and remove it. Unify them in order to introduce 52-bits VA kernel more easily in the coming patch.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/crashdump-arm64.c | 23 +---------------------- kexec/arch/arm64/kexec-arm64.c | 4 ++-- kexec/arch/arm64/kexec-arm64.h | 1 + 3 files changed, 4 insertions(+), 24 deletions(-)kexec/arch/arm64/crashdump-arm64.c +0
-0
[...]
kexec/arch/arm64/kexec-arm64.c static int get_va_bits(void) · line 915
Quoted 13 lines
kexec/arch/arm64/kexec-arm64.c +1
-1@@ -909,7 +909,7 @@ static int get_va_bits(void)* get_page_offset - Helper for getting PAGE_OFFSET */ -static int get_page_offset (void ) +int get_page_offset (unsigned long *page_offset) {int ret;
The new page_offset is never used in this patch. There's still the line left with the global page_offset but that will cause a type miss-match (unsigend long vs unsigned log *). In the next patch you do the update (page_offset -> *page_offset) but in the meantime the code is broken.
Thanks
Philipp
Quoted 14 lines
kexec/arch/arm64/kexec-arm64.c +1
-1@@ -954,7 +954,7 @@ int get_phys_base_from_pt_load(long *phys_offset)unsigned long long phys_start;unsigned long long virt_start; - ret =get_page_offset (); + ret =get_page_offset (&page_offset);if (ret <0 )return ret;kexec/arch/arm64/kexec-arm64.h +0
-0
kexec/arch/arm64/kexec-arm64.h extern struct arm64_mem arm64_mem; · line 75
Quoted 7 lines
kexec/arch/arm64/kexec-arm64.h +1
-0@@ -69,6 +69,7 @@ extern struct arm64_mem arm64_mem;uint64_t get_phys_offset (void );uint64_t get_vp_offset (void ); +int get_page_offset (unsigned long *offset);static inline void reset_vp_offset (void ) {
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/3] arm64/crashdump: unify routine to get page_offset
Quoted 36 lines · Philipp Rudo
Hi Pinfang,
Quoted 19 lines · On Fri, 10 Dec 2021 11:07:34 +0800 Pingfan Liu <[email protected]> wrote:
There are two funcs to get
page_offset:
get_kernel_page_offset()
get_page_offset()Since
get_kernel_page_offset()does not observe the kernel formula, and remove it. Unify them in order to introduce 52-bits VA kernel more easily in the coming patch.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/crashdump-arm64.c | 23 +---------------------- kexec/arch/arm64/kexec-arm64.c | 4 ++-- kexec/arch/arm64/kexec-arm64.h | 1 + 3 files changed, 4 insertions(+), 24 deletions(-)kexec/arch/arm64/crashdump-arm64.c +0
-0[...]
Quoted 8 lines
kexec/arch/arm64/kexec-arm64.c +0
-0@@ -909,7 +909,7 @@ static int get_va_bits(void)* get_page_offset - Helper for getting PAGE_OFFSET */
Quoted 11 lines
kexec/arch/arm64/kexec-arm64.c static int get_va_bits(void) · line 915
Quoted 5 lines
kexec/arch/arm64/kexec-arm64.c +1
-1-static int get_page_offset (void ) +int get_page_offset (unsigned long *page_offset) {int ret;The new
page_offsetis never used in this patch. There's still the line left with the globalpage_offsetbut that will cause a type miss-match (unsigend long vs unsigned log *). In the next patch you do the update (page_offset->*page_offset) but in the meantime the code is broken.
I will fix it in V2.
Thanks,
Pingfan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH 3/3 arm64: read VA_BITS from kcore for 52-bits VA kernel
In reply to Pingfan Liuphys_to_virt() calculates virtual address. As a important factor, page_offset is excepted to be accurate.
Since arm64 kernel exposes va_bits through vmcore, using it.
--- kexec/arch/arm64/kexec-arm64.c | 31 +++++++++++++++++++++++++++---- kexec/arch/arm64/kexec-arm64.h | 1 + util_lib/elf_info.c | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-)
kexec/arch/arm64/kexec-arm64.c +27 -4
@@ -54,7 +54,7 @@static bool try_read_phys_offset_from_kcore = false;/* Machine specific details. */ -static int va_bits; +static int va_bits =-1 ;static unsigned long page_offset;/* Global varables the core kexec routines expect. */
@@ -876,7 +876,15 @@ static inline void set_phys_offset(long v, char *set_method)static int get_va_bits (void ) { -unsigned long long stext_sym_addr =get_kernel_sym ("_stext" ); +unsigned long long stext_sym_addr; + +/* +* if already got from kcore +*/ +if (va_bits !=-1 ) + goto out; + + stext_sym_addr =get_kernel_sym ("_stext" );if (stext_sym_addr ==0 ) {fprintf (stderr,"Can't get the symbol of _stext.\n" );
@@ -900,6 +908,7 @@ static int get_va_bits(void)return -1 ; } +out:dbgprintf ("va_bits : %d\n" , va_bits);return 0 ;
@@ -917,14 +926,27 @@ int get_page_offset(unsigned long *page_offset)if (ret <0 )return ret; - page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +if (va_bits <52 ) + *page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +else + *page_offset = (0xffffffffffffffffUL ) << va_bits; +dbgprintf ("page_offset : %lx\n" , page_offset);return 0 ; } +static void arm64_scan_vmcoreinfo (char *pos) +{ +const char *str; + + str ="NUMBER(VA_BITS)=" ; +if (memcmp (str, pos,strlen (str)) ==0 ) + va_bits =strtoul (pos +strlen (str),NULL ,10 ); +} +/** -* get_phys_offset_from_vmcoreinfo_pt_note - Helper for getting PHYS_OFFSET +* get_phys_offset_from_vmcoreinfo_pt_note - Helper for getting PHYS_OFFSET (and va_bits) * from VMCOREINFO note inside 'kcore'. */
@@ -937,6 +959,7 @@ static int get_phys_offset_from_vmcoreinfo_pt_note(long *phys_offset)return EFAILED ; } + arch_scan_vmcoreinfo = arm64_scan_vmcoreinfo; ret =read_phys_offset_elf_kcore (fd, phys_offset);close (fd);
kexec/arch/arm64/kexec-arm64.h +1 -0
@@ -66,6 +66,7 @@ struct arm64_mem {#define arm64_mem_ngv UINT64_MAXextern struct arm64_mem arm64_mem; +extern void (*arch_scan_vmcoreinfo)(char *pos);uint64_t get_phys_offset (void );uint64_t get_vp_offset (void );
util_lib/elf_info.c +5 -0
@@ -310,6 +310,8 @@ int get_pt_load(int idx,#define NOT_FOUND_LONG_VALUE (-1) +void (*arch_scan_vmcoreinfo)(char *pos); +void scan_vmcoreinfo (char *start,size_t size) {char *last = start + size -1 ;
@@ -551,6 +553,9 @@ void scan_vmcoreinfo(char *start, size_t size) } } +if (arch_scan_vmcoreinfo !=NULL ) + (*arch_scan_vmcoreinfo)(pos); +if (last_line)break ; }
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] arm64: read VA_BITS from kcore for 52-bits VA kernel
Hi Pingfang,
Quoted 51 lines · On Fri, 10 Dec 2021 11:07:35 +0800 Pingfan Liu <[email protected]> wrote:
phys_to_virt()calculates virtual address. As a important factor,page_offsetis excepted to be accurate.Since arm64 kernel exposes
va_bitsthrough vmcore, using it.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/kexec-arm64.c | 31 +++++++++++++++++++++++++++---- kexec/arch/arm64/kexec-arm64.h | 1 + util_lib/elf_info.c | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-)kexec/arch/arm64/kexec-arm64.c +11
-2@@ -54,7 +54,7 @@static bool try_read_phys_offset_from_kcore = false;/* Machine specific details. */ -static int va_bits; +static int va_bits =-1 ;static unsigned long page_offset;/* Global varables the core kexec routines expect. */ @@ -876,7 +876,15 @@ static inline void set_phys_offset(long v, char *set_method)static int get_va_bits (void ) { -unsigned long long stext_sym_addr =get_kernel_sym ("_stext" ); +unsigned long long stext_sym_addr; + +/* +* if already got from kcore +*/ +if (va_bits !=-1 ) + goto out; + + stext_sym_addr =get_kernel_sym ("_stext" );if (stext_sym_addr ==0 ) {fprintf (stderr,"Can't get the symbol of _stext.\n" );@@ -900,6 +908,7 @@ static int get_va_bits(void)return -1 ; } +out:dbgprintf ("va_bits : %d\n" , va_bits);return 0 ;
kexec/arch/arm64/kexec-arm64.c int get_page_offset(unsigned long *page_offset) · line 932
Quoted 8 lines
kexec/arch/arm64/kexec-arm64.c +4
-1@@ -917,14 +926,27 @@ int get_page_offset(unsigned long *page_offset)if (ret <0 )return ret; - page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +if (va_bits <52 ) + *page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +else + *page_offset = (0xffffffffffffffffUL ) << va_bits;
wouldn't it make sense to use ULONG_MAX here? At least for me it would be much better readable.
Quoted 33 lines
kexec/arch/arm64/kexec-arm64.c +11
-1dbgprintf ("page_offset : %lx\n" , page_offset);return 0 ; } +static void arm64_scan_vmcoreinfo (char *pos) +{ +const char *str; + + str ="NUMBER(VA_BITS)=" ; +if (memcmp (str, pos,strlen (str)) ==0 ) + va_bits =strtoul (pos +strlen (str),NULL ,10 ); +} +/** -* get_phys_offset_from_vmcoreinfo_pt_note - Helper for getting PHYS_OFFSET +* get_phys_offset_from_vmcoreinfo_pt_note - Helper for getting PHYS_OFFSET (and va_bits) * from VMCOREINFO note inside 'kcore'. */ @@ -937,6 +959,7 @@ static int get_phys_offset_from_vmcoreinfo_pt_note(long *phys_offset)return EFAILED ; } + arch_scan_vmcoreinfo = arm64_scan_vmcoreinfo; ret =read_phys_offset_elf_kcore (fd, phys_offset);close (fd);kexec/arch/arm64/kexec-arm64.h +0
-0
kexec/arch/arm64/kexec-arm64.h struct arm64_mem { · line 69
Quoted 4 lines
kexec/arch/arm64/kexec-arm64.h +1
-0@@ -66,6 +66,7 @@ struct arm64_mem {#define arm64_mem_ngv UINT64_MAXextern struct arm64_mem arm64_mem; +extern void (*arch_scan_vmcoreinfo)(char *pos);
This definition isn't arm64 specific. I think this should go to util_lib/include/elf_info.h.
Thanks
Philipp
Quoted 17 lines
kexec/arch/arm64/kexec-arm64.h +0
-0uint64_t get_phys_offset (void );uint64_t get_vp_offset (void );util_lib/elf_info.c +2
-0@@ -310,6 +310,8 @@ int get_pt_load(int idx,#define NOT_FOUND_LONG_VALUE (-1) +void (*arch_scan_vmcoreinfo)(char *pos); +void scan_vmcoreinfo (char *start,size_t size) {char *last = start + size -1 ;
util_lib/elf_info.c void scan_vmcoreinfo(char *start, size_t size) · line 561
Quoted 9 lines
util_lib/elf_info.c +3
-0@@ -551,6 +553,9 @@ void scan_vmcoreinfo(char *start, size_t size) } } +if (arch_scan_vmcoreinfo !=NULL ) + (*arch_scan_vmcoreinfo)(pos); +if (last_line)break ; }
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] arm64: read VA_BITS from kcore for 52-bits VA kernel
Quoted 60 lines · Philipp Rudo
Hi Pingfang,
Quoted 54 lines · On Fri, 10 Dec 2021 11:07:35 +0800 Pingfan Liu <[email protected]> wrote:
phys_to_virt()calculates virtual address. As a important factor,page_offsetis excepted to be accurate.Since arm64 kernel exposes
va_bitsthrough vmcore, using it.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/kexec-arm64.c | 31 +++++++++++++++++++++++++++---- kexec/arch/arm64/kexec-arm64.h | 1 + util_lib/elf_info.c | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-)kexec/arch/arm64/kexec-arm64.c +11
-2@@ -54,7 +54,7 @@static bool try_read_phys_offset_from_kcore = false;/* Machine specific details. */ -static int va_bits; +static int va_bits =-1 ;static unsigned long page_offset;/* Global varables the core kexec routines expect. */ @@ -876,7 +876,15 @@ static inline void set_phys_offset(long v, char *set_method)static int get_va_bits (void ) { -unsigned long long stext_sym_addr =get_kernel_sym ("_stext" ); +unsigned long long stext_sym_addr; + +/* +* if already got from kcore +*/ +if (va_bits !=-1 ) + goto out; + + stext_sym_addr =get_kernel_sym ("_stext" );if (stext_sym_addr ==0 ) {fprintf (stderr,"Can't get the symbol of _stext.\n" );@@ -900,6 +908,7 @@ static int get_va_bits(void)return -1 ; } +out:dbgprintf ("va_bits : %d\n" , va_bits);return 0 ;@@ -917,14 +926,27 @@ int get_page_offset(unsigned long *page_offset)if (ret <0 )return ret;
Quoted 9 lines
kexec/arch/arm64/kexec-arm64.c int get_page_offset(unsigned long *page_offset) · line 932
Quoted 5 lines
kexec/arch/arm64/kexec-arm64.c +4
-1- page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +if (va_bits <52 ) + *page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +else + *page_offset = (0xffffffffffffffffUL ) << va_bits;wouldn't it make sense to use
ULONG_MAXhere? At least for me it would be much better readable.
Yes, I tend to agree and will update it in V2 (if there is no need to compile it on 32-bits machine, which I consider as a rare case nowadays.)
Quoted 34 lines
Quoted 34 lines
kexec/arch/arm64/kexec-arm64.c +11
-1dbgprintf ("page_offset : %lx\n" , page_offset);return 0 ; } +static void arm64_scan_vmcoreinfo (char *pos) +{ +const char *str; + + str ="NUMBER(VA_BITS)=" ; +if (memcmp (str, pos,strlen (str)) ==0 ) + va_bits =strtoul (pos +strlen (str),NULL ,10 ); +} +/** -* get_phys_offset_from_vmcoreinfo_pt_note - Helper for getting PHYS_OFFSET +* get_phys_offset_from_vmcoreinfo_pt_note - Helper for getting PHYS_OFFSET (and va_bits) * from VMCOREINFO note inside 'kcore'. */ @@ -937,6 +959,7 @@ static int get_phys_offset_from_vmcoreinfo_pt_note(long *phys_offset)return EFAILED ; } + arch_scan_vmcoreinfo = arm64_scan_vmcoreinfo; ret =read_phys_offset_elf_kcore (fd, phys_offset);close (fd);kexec/arch/arm64/kexec-arm64.h +0
-0@@ -66,6 +66,7 @@ struct arm64_mem {
Quoted 7 lines
kexec/arch/arm64/kexec-arm64.h struct arm64_mem { · line 69
Quoted 3 lines
kexec/arch/arm64/kexec-arm64.h +1
-0#define arm64_mem_ngv UINT64_MAXextern struct arm64_mem arm64_mem; +extern void (*arch_scan_vmcoreinfo)(char *pos);This definition isn't arm64 specific. I think this should go to
util_lib/include/elf_info.h.
Good suggestion and update it in V2.
Thanks,
Pingfan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] arm64: read VA_BITS from kcore for 52-bits VA kernel
Quoted 72 lines · Pingfan Liu
Quoted 60 lines · Philipp Rudo
Hi Pingfang,
Quoted 54 lines · On Fri, 10 Dec 2021 11:07:35 +0800 Pingfan Liu <[email protected]> wrote:
phys_to_virt()calculates virtual address. As a important factor,page_offsetis excepted to be accurate.Since arm64 kernel exposes
va_bitsthrough vmcore, using it.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/kexec-arm64.c | 31 +++++++++++++++++++++++++++---- kexec/arch/arm64/kexec-arm64.h | 1 + util_lib/elf_info.c | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-)kexec/arch/arm64/kexec-arm64.c +11
-2@@ -54,7 +54,7 @@static bool try_read_phys_offset_from_kcore = false;/* Machine specific details. */ -static int va_bits; +static int va_bits =-1 ;static unsigned long page_offset;/* Global varables the core kexec routines expect. */ @@ -876,7 +876,15 @@ static inline void set_phys_offset(long v, char *set_method)static int get_va_bits (void ) { -unsigned long long stext_sym_addr =get_kernel_sym ("_stext" ); +unsigned long long stext_sym_addr; + +/* +* if already got from kcore +*/ +if (va_bits !=-1 ) + goto out; + + stext_sym_addr =get_kernel_sym ("_stext" );if (stext_sym_addr ==0 ) {fprintf (stderr,"Can't get the symbol of _stext.\n" );@@ -900,6 +908,7 @@ static int get_va_bits(void)return -1 ; } +out:dbgprintf ("va_bits : %d\n" , va_bits);return 0 ;@@ -917,14 +926,27 @@ int get_page_offset(unsigned long *page_offset)if (ret <0 )return ret;Quoted 9 lines
kexec/arch/arm64/kexec-arm64.c int get_page_offset(unsigned long *page_offset) · line 932
Quoted 5 lines
kexec/arch/arm64/kexec-arm64.c +4
-1- page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +if (va_bits <52 ) + *page_offset = (0xffffffffffffffffUL ) << (va_bits -1 ); +else + *page_offset = (0xffffffffffffffffUL ) << va_bits;wouldn't it make sense to use
ULONG_MAXhere? At least for me it would be much better readable.
Quoted 4 lines
Yes, I tend to agree and will update it in V2 (if there is no need to compile it on 32-bits machine, which I consider as a rare case nowadays.)
I think UINT64_MAX can free of this issue
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] arm64: read VA_BITS from kcore for 52-bits VA kernel
Quoted 29 lines · On Wed, Dec 15, 2021 at 9:06 PM [email protected]:Simon Horman…
Quoted 27 lines · Pingfan Liu
phys_to_virt()calculates virtual address. As a important factor,page_offsetis excepted to be accurate.Since arm64 kernel exposes
va_bitsthrough vmcore, using it.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/kexec-arm64.c | 31 +++++++++++++++++++++++++++---- kexec/arch/arm64/kexec-arm64.h | 1 + util_lib/elf_info.c | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-)kexec/arch/arm64/kexec-arm64.c +1
-1@@ -54,7 +54,7 @@static bool try_read_phys_offset_from_kcore = false;/* Machine specific details. */ -static int va_bits; +static int va_bits =-1 ;static unsigned long page_offset;/* Global varables the core kexec routines expect. */ @@ -876,7 +876,15 @@ static inline void set_phys_offset(long v, char *set_method)
Quoted 15 lines
kexec/arch/arm64/kexec-arm64.c static inline void set_phys_offset(long v, char *set_method) · line 885
Quoted 10 lines
kexec/arch/arm64/kexec-arm64.c +7
-1static int get_va_bits (void ) { -unsigned long long stext_sym_addr =get_kernel_sym ("_stext" ); +unsigned long long stext_sym_addr; + +/* +* if already got from kcore +*/ +if (va_bits !=-1 ) + goto out;If
va_bitsis exposed by the kernel then it will be used. Else we continue here. Are there actually cases (old kernels) where we expect to continue. Or could we get rid of the fallback code here?
va_bits is exposed by kernel commit 84c57dbd3c48 ("arm64: kernel:arch_crash_save_vmcoreinfo() should depend on CONFIG_CRASH_CORE") And the first kernel which contains VA_BITS is v4.19.
I have no idea about the need for old kernels. Maybe just keep the compatible code and throw a warning to remind users?
Quoted 12 lines
Quoted 12 lines
kexec/arch/arm64/kexec-arm64.c +3
-0+ + stext_sym_addr =get_kernel_sym ("_stext" );if (stext_sym_addr ==0 ) {fprintf (stderr,"Can't get the symbol of _stext.\n" );@@ -900,6 +908,7 @@ static int get_va_bits(void)return -1 ; } +out:dbgprintf ("va_bits : %d\n" , va_bits);
Quoted 9 lines
kexec/arch/arm64/kexec-arm64.c int get_page_offset(unsigned long *page_offset) · line 928
Quoted 5 lines
kexec/arch/arm64/kexec-arm64.c +0
-0return 0 ;@@ -917,14 +926,27 @@ int get_page_offset(unsigned long *page_offset)if (ret <0 )return ret;I'm confused about why there is both a (
va_bits- 1) andva_bitscase here.
It originates from the changes of memory layout on arm64. And mostly it is contributed by kernel commit 14c127c957c1 ("arm64:
mm: Flip kernel VA space"),
where sees the changes:
-#define PAGE_OFFSET (UL(0xffffffffffffffff) - \
(UL(1) << (VA_BITS - 1)) + 1)+#define PAGE_OFFSET (UL(0xffffffffffffffff) - \
+ (UL(1) << VA_BITS) + 1)
Thanks,
Pingfan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 3/3] arm64: read VA_BITS from kcore for 52-bits VA kernel
Quoted 47 lines · Pingfan Liu
Quoted 29 lines · On Wed, Dec 15, 2021 at 9:06 PM [email protected]:Simon Horman…
Quoted 27 lines · Pingfan Liu
phys_to_virt()calculates virtual address. As a important factor,page_offsetis excepted to be accurate.Since arm64 kernel exposes
va_bitsthrough vmcore, using it.Signed-off-by Pingfan Liu <[email protected]>--- kexec/arch/arm64/kexec-arm64.c | 31 +++++++++++++++++++++++++++---- kexec/arch/arm64/kexec-arm64.h | 1 + util_lib/elf_info.c | 5 +++++ 3 files changed, 33 insertions(+), 4 deletions(-)kexec/arch/arm64/kexec-arm64.c +1
-1@@ -54,7 +54,7 @@static bool try_read_phys_offset_from_kcore = false;/* Machine specific details. */ -static int va_bits; +static int va_bits =-1 ;static unsigned long page_offset;/* Global varables the core kexec routines expect. */ @@ -876,7 +876,15 @@ static inline void set_phys_offset(long v, char *set_method)Quoted 15 lines
kexec/arch/arm64/kexec-arm64.c static inline void set_phys_offset(long v, char *set_method) · line 885
Quoted 10 lines
kexec/arch/arm64/kexec-arm64.c +7
-1static int get_va_bits (void ) { -unsigned long long stext_sym_addr =get_kernel_sym ("_stext" ); +unsigned long long stext_sym_addr; + +/* +* if already got from kcore +*/ +if (va_bits !=-1 ) + goto out;If
va_bitsis exposed by the kernel then it will be used. Else we continue here. Are there actually cases (old kernels) where we expect to continue. Or could we get rid of the fallback code here?
Quoted 5 lines
va_bitsis exposed by kernel commit84c57dbd3c48("arm64: kernel:arch_crash_save_vmcoreinfo()should depend onCONFIG_CRASH_CORE") And the first kernel which containsVA_BITSis v4.19.
I have no idea about the need for old kernels. Maybe just keep the compatible code and throw a warning to remind users?
I suspect that kexec for ARM64 was present in v4.19, so we should leave this part as-is.
Quoted 32 lines
Quoted 12 lines
Quoted 12 lines
kexec/arch/arm64/kexec-arm64.c +3
-0+ + stext_sym_addr =get_kernel_sym ("_stext" );if (stext_sym_addr ==0 ) {fprintf (stderr,"Can't get the symbol of _stext.\n" );@@ -900,6 +908,7 @@ static int get_va_bits(void)return -1 ; } +out:dbgprintf ("va_bits : %d\n" , va_bits);Quoted 9 lines
kexec/arch/arm64/kexec-arm64.c int get_page_offset(unsigned long *page_offset) · line 928
Quoted 5 lines
kexec/arch/arm64/kexec-arm64.c +0
-0return 0 ;@@ -917,14 +926,27 @@ int get_page_offset(unsigned long *page_offset)if (ret <0 )return ret;I'm confused about why there is both a (
va_bits- 1) andva_bitscase here.It originates from the changes of memory layout on arm64. And mostly it is contributed by kernel commit
14c127c957c1("arm64:
mm: Flip kernel VA space"),
where sees the changes:(quoted diff) +2
-1-#define PAGE_OFFSET (UL(0xffffffffffffffff) - \ (UL(1) << (VA_BITS - 1)) + 1) +#define PAGE_OFFSET (UL(0xffffffffffffffff) - \ + (UL(1) << VA_BITS) + 1)
Quoted 4 lines
Thanks,
Pingfan
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
+ AKASHI Takahiro
+ Simon Horman
Thank you guys for any suggestions.
And vmcore-dmesg just can not work for 52-bits VA arm64 now.
Thanks,
Pingfan
Quoted 19 lines · Pingfan Liu
Currently
phys_to_virt()does not work well on 52-bits VA arm64 kernel. One issue is contributed byphys_offsetnot signed.
The other is contributed by wrongpage_offset.This series fixes them so vmcore-dmesg can work on 52-bits VA kernel
Pingfan Liu (3):
arm64: makephys_offsetsigned arm64/crashdump: unify routine to getpage_offset
arm64: readVA_BITSfrom kcore for 52-bits VA kernelkexec/arch/arm64/crashdump-arm64.c | 23 +--------------- kexec/arch/arm64/kexec-arm64.c | 43 +++++++++++++++++++++++------- kexec/arch/arm64/kexec-arm64.h | 4 ++- util_lib/elf_info.c | 7 ++++- util_lib/include/elf_info.h | 2 +- 5 files changed, 44 insertions(+), 35 deletions(-)
Quoted 3 lines
--
2.31.1
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec