Skip to contentSkip to conversation

ppc64: fix vtop translation when a page table spans multiple pages

PATCH New Jyoti Gupta 1 participant 1 message Dec 1

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 ppc64: fix vtop translation when a page table spans multiple pages

ppc64_vtop_level4() reads the page containing the start of each page table (PGD/PUD/PMD/PTE) into info->page_buf and then indexes into it using PAGEOFFSET() of the entry address. This is only correct when the whole table fits within a single page. For a larger table, an entry beyond the first page is read from the wrong place, giving a bad translation.

This happens at the PGD level on ppc64 with the Radix MMU and 4K pages, where the PGD has 8192 entries * 8 bytes = 64KB (16 pages). For the vmemmap address 0xc00c000018000000:

PGD index = (vaddr >> 39) & 0x1fff = 6144
Entry offset = 6144 * 8 = 49152 (13th 4KB page of the PGD)

makedumpfile reads only the first 4KB page, which holds entries 0-511, and indexes it with PAGEOFFSET() = 0, so it picks up entry 0 instead of entry 6144. With 64K pages the PGD is exactly one page, so the bug is not seen, though it could be if the kernel increases the number of PGD entries.

Fix this by reading the page that actually contains the entry being looked up, rather than the page at the start of the table.

With the current index sizes the PUD, PMD and PTE tables always fit in one page, so the problem cannot be triggered at those levels. They are changed as well to keep all levels consistent and robust against future changes in table sizes or page-size configurations; there is no change in behavior at those levels today.

Before the fix (Radix MMU, 4K pages):

  # ./makedumpfile -c -d 31 /proc/vmcore /tmp/vmcore
  The kernel version is not supported.
  The makedumpfile operation may be incomplete.
  Checking for memory holes                         : [100.0 %] |
  WARNING: Invalid free page order: pfn=234383, order=2305843009213693953, max order=12
  WARNING: Invalid free page order: pfn=3c0c5b, order=3319433498405634048, max order=12
  WARNING: Invalid free page order: pfn=5b0950, order=3319433532765372416, max order=12
  readpage_elf: Attempt to read non-existent page at 0x18000000.
  readmem: type_addr: 0, addr:c00c000018000000, size:32768
  __exclude_unnecessary_pages: Can't read the buffer of struct page.
  create_2nd_bitmap: Can't exclude unnecessary pages.

makedumpfile Failed.

After the fix:

  # ./makedumpfile -c -d 31 /proc/vmcore /tmp/vmcore
  The kernel version is not supported.
  The makedumpfile operation may be incomplete.
  Copying data : [100.0 %] / eta: 0s

The dumpfile is saved to /tmp/vmcore.

makedumpfile Completed.

---
Changelog:
v3->v4:
- Update Closes: tag to point to the lore.kernel.org thread.

v2->v3:
- Add before/after makedumpfile output (Radix MMU, 4K pages).
- Add Suggested-by tag.

v1->v2:
- Expand the commit message: explain the Radix MMU 4K-page PGD case with the vmemmap address example.
- Explain that PUD/PMD/PTE are changed only for consistency, with no behavior change today.
- Add Reported-by: and Closes: tags.

Testing:
-Tested on both 4K and 64K page size configurations.

---
 arch/ppc64.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/ppc64.c +8 -8
index 8ad9d6e..53b0004 100644
@@ -397,8 +397,8 @@ ppc64_vtop_level4(unsigned long vaddr)
 
 	level4 = (ulong *)info->kernel_pgd;
 	pgdir = (ulong *)((ulong *)level4 + PGD_OFFSET_L4(vaddr));
-	if (!readmem(VADDR, PAGEBASE(level4), info->page_buf, PAGESIZE())) {
-		ERRMSG("Can't read PGD page: 0x%llx\n", PAGEBASE(level4));
+	if (!readmem(VADDR, PAGEBASE(pgdir), info->page_buf, PAGESIZE())) {
+		ERRMSG("Can't read PGD page: 0x%llx\n", PAGEBASE(pgdir));
 		return NOT_PADDR;
 	}
 	pgd_pte = swap64(ULONG((info->page_buf + PAGEOFFSET(pgdir))), swap);
@@ -418,8 +418,8 @@ ppc64_vtop_level4(unsigned long vaddr)
 	if (info->l3_index_size != 0) {
 		pgd_pte = pgd_page_vaddr_l4(pgd_pte);
 		page_upper = (ulong *)((ulong *)pgd_pte + PUD_OFFSET_L4(vaddr));
-		if (!readmem(VADDR, PAGEBASE(pgd_pte), info->page_buf, PAGESIZE())) {
-			ERRMSG("Can't read PUD page: 0x%llx\n", PAGEBASE(pgd_pte));
+		if (!readmem(VADDR, PAGEBASE(page_upper), info->page_buf, PAGESIZE())) {
+			ERRMSG("Can't read PUD page: 0x%llx\n", PAGEBASE(page_upper));
 			return NOT_PADDR;
 		}
 		pud_pte = swap64(ULONG((info->page_buf + PAGEOFFSET(page_upper))), swap);
@@ -438,8 +438,8 @@ ppc64_vtop_level4(unsigned long vaddr)
 
 	pud_pte = pud_page_vaddr_l4(pud_pte);
 	page_middle = (ulong *)((ulong *)pud_pte + PMD_OFFSET_L4(vaddr));
-	if (!readmem(VADDR, PAGEBASE(pud_pte), info->page_buf, PAGESIZE())) {
-		ERRMSG("Can't read PMD page: 0x%llx\n", PAGEBASE(pud_pte));
+	if (!readmem(VADDR, PAGEBASE(page_middle), info->page_buf, PAGESIZE())) {
+		ERRMSG("Can't read PMD page: 0x%llx\n", PAGEBASE(page_middle));
 		return NOT_PADDR;
 	}
 	pmd_pte = swap64(ULONG((info->page_buf + PAGEOFFSET(page_middle))), swap);
@@ -456,8 +456,8 @@ ppc64_vtop_level4(unsigned long vaddr)
 	pmd_pte = pmd_page_vaddr_l4(pmd_pte);
 	page_table = (ulong *)(pmd_pte)
 			+ (BTOP(vaddr) & (info->ptrs_per_l1 - 1));
-	if (!readmem(VADDR, PAGEBASE(pmd_pte), info->page_buf, PAGESIZE())) {
-		ERRMSG("Can't read page table: 0x%llx\n", PAGEBASE(pmd_pte));
+	if (!readmem(VADDR, PAGEBASE(page_table), info->page_buf, PAGESIZE())) {
+		ERRMSG("Can't read page table: 0x%llx\n", PAGEBASE(page_table));
 		return NOT_PADDR;
 	}
 	pte = swap64(ULONG((info->page_buf + PAGEOFFSET(page_table))), swap);
Signature · 1 line
2.55.0