makedumpfile: arm64: Fix page table walk of 1GB section
Subsystems (2)
PATCH 1/1 makedumpfile: arm64: Fix page table walk of 1GB section
Using an arm64 board, 2GB of memory, makedumpfile 1.6.2, and the v4.11 kernel, I ran into an issue where the dumpfile was not excluding any pages thus creating a huge vmcore.
I found that my board had a 1GB mapping in the PGD of 0xffffffc040000000. This isn't my area of expertise but I think I've pieced together how the kernel handles page tables.
cat /proc/kallsyms |grep swapper_pgffffff8008a66000 B swapper_pg_dir
00a66800: 7fff9003 // pgd for virtual addr 0xffffffc000000000 00a66804: 0000000000a66808: 40000711 // pgd for virtual addr 0xffffffc040000000 00a6680c: 00e80000
If I understand everything correctly then the pgd at 0xa66808 is a section and not a pointer to a PMD, thus it should have been handled as a section instead of trying to drill down to a PTE by the code in arch/arm64.c
Please find debug below and a proposed (probably not optimal) fix attached.
Thank you.
/usr/sbin/makedumpfile -F -c -d 31 --message-level=31 /proc/vmcore > /dev/null
sadump: unsupported architecture
LOAD (0)phys_start : 80000phys_end : a58000virt_start : ffffff8008080000virt_end : ffffff8008a58000
LOAD (1)phys_start : 0phys_end : 6000000virt_start : ffffffc000000000virt_end : ffffffc006000000
LOAD (2)phys_start : 6800000phys_end : 8000000virt_start : ffffffc006800000virt_end : ffffffc008000000
LOAD (3)phys_start : a000000phys_end : 80000000virt_start : ffffffc00a000000virt_end : ffffffc080000000
Linux kdumppage_size : 4096phys_base : 0
max_mapnr : 80000
There is enough free memory to be done in one cycle.
Buffer size for the cyclic mode: 131072kimage_voffset : ffffff8008000000max_physmem_bits : 30section_size_bits: 1epage_offset : ffffffc000000000
num of NODEs : 1
Memory type : SPARSEMEM_EX
readmem: Can't convert a virtual address(ffffffc07fff6000) to physical address.
readmem: type_addr: 0, addr:ffffffc07fff6000, size:16section_mem_map_addr: Can't get a struct mem_section(ffffffc07fff6000). mem_map (0)mem_map : 0pfn_start : 0pfn_end : 40000
readmem: Can't convert a virtual address(ffffffc07fff6010) to physical address.
readmem: type_addr: 0, addr:ffffffc07fff6010, size:16section_mem_map_addr: Can't get a struct mem_section(ffffffc07fff6010). mem_map (1)mem_map : 0pfn_start : 40000pfn_end : 80000mmap() is available on the kernel.
Checking for memory holes : [100.0 %] | STEP [Checking for memory holes ] :
0.017147 seconds
Excluding unnecessary pages : [100.0 %] \ STEP [Excluding unnecessary pages] :
0.000034 seconds
Bradley Bolen (1):
makedumpfile: arm64: Fix page table walk of 1GB section
arch/arm64.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Signature · 7 lines
1.9.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH 1/1 makedumpfile: arm64: Fix page table walk of 1GB section
makedumpfile was generating large (> 500MB) vmcore files for an arm64 board with 2GB of DRAM. It was not excluding any pages because the mem_map address was not being converted correctly.
readmem: Can't convert a virtual address(ffffffc07fff6000) to physical address.
readmem: type_addr: 0, addr:ffffffc07fff6000, size:16section_mem_map_addr: Can't get a struct mem_section(ffffffc07fff6000). mem_map (0)mem_map : 0
makedumpfile was not handling 1GB sections in the PGD and was trying to drill down to a PTE in which it was trying to dereference invalid memory. This patch adds code to check the PGD for a section type and handle it instead of treating it as a table entry.
--- arch/arm64.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64.c +13 -0
@@ -57,6 +57,8 @@ static unsigned long kimage_voffset;#define PGDIR_SHIFT ((PAGESHIFT() - 3) * pgtable_level + 3)#define PTRS_PER_PGD (1 << (va_bits - PGDIR_SHIFT))#define PUD_SHIFT get_pud_shift_arm64() +#define PUD_SIZE (1UL << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE - 1))#define PTRS_PER_PTE (1 << (PAGESHIFT() - 3))#define PTRS_PER_PUD PTRS_PER_PTE#define PMD_SHIFT ((PAGESHIFT() - 3) * 2 + 3)
@@ -79,6 +81,10 @@ static unsigned long kimage_voffset;#define PMD_TYPE_SECT 1#define PMD_TYPE_TABLE 3 +#define PUD_TYPE_MASK 3 +#define PUD_TYPE_SECT 1 +#define PUD_TYPE_TABLE 3 +#define pgd_index (vaddr) (((vaddr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))#define pgd_offset (pgdir, vaddr) ((pgd_t *)(pgdir) + pgd_index(vaddr))
@@ -253,6 +259,13 @@ vaddr_to_paddr_arm64(unsigned long vaddr)return NOT_PADDR ; } +if ((pud_val (pudv) &PUD_TYPE_MASK ) ==PUD_TYPE_SECT ) { +/* 1GB section */ + paddr = (pud_val (pudv) & (PUD_MASK &PMD_SECTION_MASK )) + + (vaddr & (PUD_SIZE -1 )); +return paddr; + } + pmda =pmd_offset (puda, &pudv, vaddr);if (!readmem (PADDR , (unsigned long long )pmda, &pmdv,sizeof (pmdv))) {ERRMSG ("Can't read pmd\n" );
Signature · 7 lines
1.9.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Hello Bradley,
Sorry for my late reply, I'll merge this patch into v1.6.3. Thanks for your work.
Regards,
Atsushi Kumagai
Quoted 63 lines
makedumpfile was generating large (> 500MB) vmcore files for an arm64 board with 2GB of DRAM. It was not excluding any pages because the
mem_mapaddress was not being converted correctly.readmem: Can't convert a virtual address(ffffffc07fff6000) to physical address.
readmem:type_addr: 0, addr:ffffffc07fff6000, size:16section_mem_map_addr: Can't get a structmem_section(ffffffc07fff6000).mem_map(0)mem_map: 0makedumpfile was not handling 1GB sections in the PGD and was trying to drill down to a PTE in which it was trying to dereference invalid memory. This patch adds code to check the PGD for a section type and handle it instead of treating it as a table entry.
Signed-off-by Bradley Bolen <[email protected]>---
arch/arm64.c| 13 +++++++++++++1 file changed, 13 insertions(+)arch/arm64.c +13
-1@@ -57,6 +57,8 @@ static unsigned long kimage_voffset;#define PGDIR_SHIFT ((PAGESHIFT() - 3) * pgtable_level + 3)#define PTRS_PER_PGD (1 << (va_bits - PGDIR_SHIFT))#define PUD_SHIFT get_pud_shift_arm64() +#define PUD_SIZE (1UL << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE - 1))#define PTRS_PER_PTE (1 << (PAGESHIFT() - 3))#define PTRS_PER_PUD PTRS_PER_PTE#define PMD_SHIFT ((PAGESHIFT() - 3) * 2 + 3)@@ -79,6 +81,10 @@ static unsigned long kimage_voffset;#define PMD_TYPE_SECT 1#define PMD_TYPE_TABLE 3 +#define PUD_TYPE_MASK 3 +#define PUD_TYPE_SECT 1 +#define PUD_TYPE_TABLE 3 +#define pgd_index (vaddr) (((vaddr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))#define pgd_offset (pgdir, vaddr) ((pgd_t *)(pgdir) + pgd_index(vaddr))@@ -253,6 +259,13 @@ vaddr_to_paddr_arm64(unsigned long vaddr)return NOT_PADDR ; } +if ((pud_val (pudv) &PUD_TYPE_MASK ) ==PUD_TYPE_SECT ) { +/* 1GB section */ + paddr = (pud_val (pudv) & (PUD_MASK &PMD_SECTION_MASK )) + + (vaddr & (PUD_SIZE -1 )); +return paddr; + } + pmda =pmd_offset (puda, &pudv, vaddr);if (!readmem (PADDR , (unsigned long long )pmda, &pmdv,sizeof (pmdv))) {ERRMSG ("Can't read pmd\n" ); --1.9.3
Quoted 4 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines · Atsushi Kumagai
Hello Bradley,
Sorry for my late reply, I'll merge this patch into v1.6.3.
Sorry, I missed it as well. Patch looks fine to me.However, I think /* 1GB Section*/ comment can be improved. Infact, other existing /* 1GB Section*/ comment for PMD type is wrong.
Quoted 50 lines
Thanks for your work.
Regards,
Atsushi KumagaiQuoted 45 lines
makedumpfile was generating large (> 500MB) vmcore files for an arm64 board with 2GB of DRAM. It was not excluding any pages because the
mem_mapaddress was not being converted correctly.readmem: Can't convert a virtual address(ffffffc07fff6000) to physical address.
readmem:type_addr: 0, addr:ffffffc07fff6000, size:16section_mem_map_addr: Can't get a structmem_section(ffffffc07fff6000).mem_map(0)mem_map: 0makedumpfile was not handling 1GB sections in the PGD and was trying to drill down to a PTE in which it was trying to dereference invalid memory. This patch adds code to check the PGD for a section type and handle it instead of treating it as a table entry.
Signed-off-by Bradley Bolen <[email protected]>---
arch/arm64.c| 13 +++++++++++++1 file changed, 13 insertions(+)arch/arm64.c +6
-0@@ -57,6 +57,8 @@ static unsigned long kimage_voffset;#define PGDIR_SHIFT ((PAGESHIFT() - 3) * pgtable_level + 3)#define PTRS_PER_PGD (1 << (va_bits - PGDIR_SHIFT))#define PUD_SHIFT get_pud_shift_arm64() +#define PUD_SIZE (1UL << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE - 1))#define PTRS_PER_PTE (1 << (PAGESHIFT() - 3))#define PTRS_PER_PUD PTRS_PER_PTE#define PMD_SHIFT ((PAGESHIFT() - 3) * 2 + 3)@@ -79,6 +81,10 @@ static unsigned long kimage_voffset;#define PMD_TYPE_SECT 1#define PMD_TYPE_TABLE 3 +#define PUD_TYPE_MASK 3 +#define PUD_TYPE_SECT 1 +#define PUD_TYPE_TABLE 3 +#define pgd_index (vaddr) (((vaddr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))#define pgd_offset (pgdir, vaddr) ((pgd_t *)(pgdir) + pgd_index(vaddr))
Quoted 6 lines
arch/arm64.c vaddr_to_paddr_arm64(unsigned long vaddr) · line 263
Quoted 6 lines
arch/arm64.c +2
-0@@ -253,6 +259,13 @@ vaddr_to_paddr_arm64(unsigned long vaddr)return NOT_PADDR ; } +if ((pud_val (pudv) &PUD_TYPE_MASK ) ==PUD_TYPE_SECT ) { +/* 1GB section */
May be we can write above comment like:
/* 1GB section for Page Table level = 4 and Page Size = 4KB*/
I think the other existing /* 1GB section */ comment for PMD_TYPE should be /* 512MB section for Page Table level = 3 and Page Size = 64KB*/
Quoted 18 lines
Quoted 16 lines
arch/arm64.c +5
-1+ paddr = (pud_val (pudv) & (PUD_MASK &PMD_SECTION_MASK )) + + (vaddr & (PUD_SIZE -1 )); +return paddr; + } + pmda =pmd_offset (puda, &pudv, vaddr);if (!readmem (PADDR , (unsigned long long )pmda, &pmdv,sizeof (pmdv))) {ERRMSG ("Can't read pmd\n" ); --1.9.3
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Signature · 7 lines
Regards Pratyush _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec