kexec/arm64: Add support for ARMv8.2 (large space addressing) 52-bit VA extensions
Subsystems (2)
PATCH 1/1 kexec/arm64: Add support for ARMv8.2 (large space addressing) 52-bit VA extensions
This patch adds support for ARMv8.2 52-bit VA (large space addressing) extension in kexec-tools.
With ARMv8.2-LVA architecture extension availability, arm64 hardware which supports this extension can support upto 52-bit virtual addresses. It is specially useful for having a 52-bit user-space virtual address space while the kernel can still retain 48-bit/52-bit virtual addressing.
Since at the moment we enable the support of this extension in the kernel via a CONFIG flag (CONFIG_ARM64_VA_BITS_52), so there are no clear mechanisms in user-space to determine this CONFIG flag value and use it to determine the kernel-space VA address range values.
'kexec-tools' can instead use 'TCR_EL1.T1SZ' value from vmcoreinfo which indicates the size offset of the memory region addressed by TTBR1_EL1 (and hence can be used for determining the 'vabits_actual' value).
Using the vmcoreinfo variable exported by kernel commit
bbdbc11804ff ("arm64/crash_core: Export TCR_EL1.T1SZ in vmcoreinfo"),
the user-space can use the following computation for determining the 'vabits_actual' value:
if (TCR_EL1.T1SZ is available in vmcoreinfo)
vabits_actual = 64 - TCR_EL1.T1SZ;
else {
read_id_aa64mmfr2_el1();
if (hardware supports 52-bit addressing)
vabits_actual = 52;
else
vabits_actual = va_bits value calculated via _stext symbol;}
I have tested several combinations with both old and latest upstream kernels with different VA values (39, 42, 48 and 52-bits) on at-least 3 different boards, which include:
1. CPUs which don't support ARMv8.2 features, e.g. qualcomm-amberwing, ampere-osprey.
2. Prototype models which support ARMv8.2 extensions (e.g. ARMv8 FVP simulation model).
This patch is in accordance with ARMv8 Architecture Reference Manual.
--- kexec/arch/arm64/Makefile | 2 + kexec/arch/arm64/common-arm64.c | 332 +++++++++++++++++++++++++++++ kexec/arch/arm64/common-arm64.h | 8 + kexec/arch/arm64/crashdump-arm64.c | 29 +-- kexec/arch/arm64/kexec-arm64.c | 120 +---------- kexec/kexec.h | 10 + util_lib/elf_info.c | 35 +++ util_lib/include/elf_info.h | 2 + 8 files changed, 397 insertions(+), 141 deletions(-) create mode 100644 kexec/arch/arm64/common-arm64.c create mode 100644 kexec/arch/arm64/common-arm64.h
kexec/arch/arm64/Makefile +2 -0
@@ -11,6 +11,7 @@ arm64_MEM_REGIONS = kexec/mem_regions.c arm64_CPPFLAGS += -I $(srcdir)/kexec/ arm64_KEXEC_SRCS += \ + kexec/arch/arm64/common-arm64.c \ kexec/arch/arm64/crashdump-arm64.c \ kexec/arch/arm64/kexec-arm64.c \ kexec/arch/arm64/kexec-elf-arm64.c \
@@ -27,6 +28,7 @@ arm64_PHYS_TO_VIRT = dist += $(arm64_KEXEC_SRCS) \ kexec/arch/arm64/include/arch/options.h \ + kexec/arch/arm64/common-arm64.h \ kexec/arch/arm64/crashdump-arm64.h \ kexec/arch/arm64/image-header.h \ kexec/arch/arm64/iomem.h \
kexec/arch/arm64/common-arm64.c new file +332 -0
332 lines not on this page · raw message
kexec/arch/arm64/common-arm64.h new file +8 -0
@@ -0,0 +1,8 @@ +#if !defined(COMMON_ARM64_H ) +#define COMMON_ARM64_H + +int get_page_offset (unsigned long *page_offset); +int get_phys_offset_from_vmcoreinfo_pt_note (unsigned long *phys_offset); +int get_phys_base_from_pt_load (unsigned long *phys_offset); + +#endif
kexec/arch/arm64/crashdump-arm64.c +7 -22
@@ -16,6 +16,7 @@#include <linux/elf.h> #include "kexec.h" +#include "common-arm64.h" #include "crashdump.h" #include "crashdump-arm64.h" #include "iomem.h"
@@ -46,27 +47,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
@@ -169,6 +149,7 @@ int load_crashdump_segments(struct kexec_info *info) {unsigned long elfcorehdr;unsigned long bufsz; +unsigned long page_offset;void *buf;int err;
@@ -182,7 +163,11 @@ int load_crashdump_segments(struct kexec_info *info)if (err)return EFAILED ; - elf_info.page_offset =get_kernel_page_offset (); + err =get_page_offset (&page_offset); +if (err) +return EFAILED ; + + elf_info.page_offset = page_offset;dbgprintf ("%s: page_offset: %016llx\n" , __func__, elf_info.page_offset);
kexec/arch/arm64/kexec-arm64.c +1 -119
143 lines not on this page · raw message
kexec/kexec.h +10 -0
@@ -122,6 +122,16 @@ do { \fprintf (stderr, __VA_ARGS__); \ }while (0 ) +/* Indirect stringification. Doing two levels allows the parameter to be a +* macro itself. For example, compile with -DFOO=bar, __stringify(FOO) +* converts to "bar". +* +* Copied from linux source: 'include/linux/stringify.h' +*/ + +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) +struct kexec_segment {const void *buf;size_t bufsz;
util_lib/elf_info.c +35 -0
@@ -45,6 +45,7 @@ static uint16_t log_offset_len = UINT16_MAX;static uint16_t log_offset_text_len =UINT16_MAX ;static uint64_t phys_offset =UINT64_MAX ; +static uint64_t tcr_el1_t1sz =UINT64_MAX ;#if __BYTE_ORDER == __LITTLE_ENDIAN#define ELFDATANATIVE ELFDATA2LSB
@@ -411,6 +412,20 @@ void scan_vmcoreinfo(char *start, size_t size) } } +/* Check for TCR_EL1_T1SZ */ + str ="NUMBER(TCR_EL1_T1SZ)=" ; +if (memcmp (str, pos,strlen (str)) ==0 ) { + tcr_el1_t1sz =strtoul (pos +strlen (str), &endp, +10 ); +if (strlen (endp) !=0 ) + tcr_el1_t1sz =strtoul (pos +strlen (str), &endp,16 ); +if ((tcr_el1_t1sz ==LONG_MAX ) ||strlen (endp) !=0 ) { +fprintf (stderr,"Invalid data %s\n" , + pos); +break ; + } + } +if (last_line)break ; }
@@ -817,3 +832,23 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)return 2 ; } + +int read_tcr_el1_t1sz_elf_kcore (int fd,unsigned long *tcr_t1sz) +{ +int ret; + + *tcr_t1sz =UINT64_MAX ; + + ret =read_elf (fd); +if (!ret) { +/* If we have a valid 'tcr_el1_t1sz' by now, +* return it to the caller now. +*/ +if (tcr_el1_t1sz !=UINT64_MAX ) { + *tcr_t1sz = tcr_el1_t1sz; +return ret; + } + } + +return 2 ; +}
util_lib/include/elf_info.h +2 -0
@@ -29,6 +29,8 @@ int get_pt_load(int idx,unsigned long long *virt_start, unsigned long long *virt_end);int read_phys_offset_elf_kcore (int fd,unsigned long *phys_off); +int read_tcr_el1_t1sz_elf_kcore (int fd,unsigned long *tcr_t1sz); +int read_elf (int fd);void dump_dmesg (int fd,void (*handler)(char *,unsigned int ));
Signature · 7 lines
2.26.2 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hi Bhupesh,
thanks for your patch.
...
Quoted 9 lines
kexec/arch/arm64/common-arm64.c new file +9
-0+static int get_vabits_actual_from_id_aa64mmfr2_el1 (void ) +{ +int l_vabits_actual; +unsigned long val; + +/* Check if ID_AA64MMFR2_EL1 CPU-ID register indicates +* ARMv8.2/LVA support: +* VARange, bits [19:16] +* From ARMv8.2:
kexec/arch/arm64/common-arm64.c line 133
Quoted 10 lines
kexec/arch/arm64/common-arm64.c new file +10
-0+* Indicates support for a larger virtual address. +* Defined values are: +* 0b0000 VMSAv8-64 supports 48-bit VAs. +* 0b0001 VMSAv8-64 supports 52-bit VAs when using the 64KB +* page size. The other translation granules support +* 48-bit VAs. +* +* See ARMv8 ARM for more details. +*/ +if (!(getauxval (AT_HWCAP ) &HWCAP_CPUID )) {
Likely my build environment wants updating, but the above does not seem to build in my (aged) environment.
$ aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ aarch64-linux-gnu-gcc -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -I/home/horms/local/opt/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/include -I./include -I./util_lib/include -Iinclude/ -I ./kexec/ -I./kexec/libfdt -I./kexec/arch/arm64/include -c -MD -o kexec/arch/arm64/kexec-uImage-arm64.o kexec/arch/arm64/kexec-uImage-arm64.c
kexec/arch/arm64/common-arm64.c: In function ‘get_vabits_actual_from_id_aa64mmfr2_el1’:
kexec/arch/arm64/common-arm64.c:133:30: error: ‘HWCAP_CPUID’ undeclared (first use in this function); did you mean ‘HWCAP_CRC32’?
if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {...
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hello Simon,
Thanks for your review. Please see my comments in-line:
Quoted 36 lines · Simon Horman
Hi Bhupesh,
thanks for your patch.
...
Quoted 9 lines
kexec/arch/arm64/common-arm64.c new file +9
-0+static int get_vabits_actual_from_id_aa64mmfr2_el1 (void ) +{ +int l_vabits_actual; +unsigned long val; + +/* Check if ID_AA64MMFR2_EL1 CPU-ID register indicates +* ARMv8.2/LVA support: +* VARange, bits [19:16] +* From ARMv8.2: kexec/arch/arm64/common-arm64.c line 133
Quoted 10 lines
kexec/arch/arm64/common-arm64.c new file +10
-0+* Indicates support for a larger virtual address. +* Defined values are: +* 0b0000 VMSAv8-64 supports 48-bit VAs. +* 0b0001 VMSAv8-64 supports 52-bit VAs when using the 64KB +* page size. The other translation granules support +* 48-bit VAs. +* +* See ARMv8 ARM for more details. +*/ +if (!(getauxval (AT_HWCAP ) &HWCAP_CPUID )) {Likely my build environment wants updating, but the above does not seem to build in my (aged) environment.
$ aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Quoted 6 lines
$ aarch64-linux-gnu-gcc -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat -O2 -fomit-frame-pointer -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -I/home/horms/local/opt/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/include -I./include -I./util_lib/include -Iinclude/ -I ./kexec/ -I./kexec/libfdt -I./kexec/arch/arm64/include -c -MD -o kexec/arch/arm64/kexec-uImage-arm64.o kexec/arch/arm64/kexec-uImage-arm64.c kexec/arch/arm64/common-arm64.c: In function ‘get_vabits_actual_from_id_aa64mmfr2_el1’: kexec/arch/arm64/common-arm64.c:133:30: error: ‘HWCAP_CPUID’ undeclared (first use in this function); did you mean ‘HWCAP_CRC32’? if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {...
Ok, let me have a look at the compilation issue with aarch64-gcc-7 version. I will soon back with updates.
Thanks,
Bhupesh
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec