Skip to contentSkip to conversation

vs. latest linuxppc_2_4_devel and linuxppc_2_4 for xmon

PATCH In review Cort Dougan 2 participants 2 messages Feb 12, 2003 – Feb 13, 2003

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vs. latest linuxppc_2_4_devel and linuxppc_2_4 for xmon

Allows printing of pgtables in xmon. Mighty useful in both trees.

arch/ppc/xmon/xmon.c +76 -0
diff -Nru a/arch/ppc/xmon/xmon.c b/arch/ppc/xmon/xmon.c
@@ -138,6 +138,7 @@
   ms	set a block of memory\n\
   md	compare two blocks of memory\n\
   M	print System.map\n\
+  p	print page tables for current\n\
   r	print registers\n\
   S	print special registers\n\
   t	print backtrace\n\
@@ -432,6 +433,9 @@
 		case 'M':
 			print_sysmap();
 			break;
+		case 'p':
+			print_pgtables();
+			break;
 		case 'S':
 			super_regs();
 			break;
@@ -689,6 +693,78 @@
 	}
 }
 
+
+/*
+ * Lookup page mappings for the current task and for the
+ * kernel and print them all.  -- Cort <[email protected]>
+ */
+static void
+print_pgtables(void)
+{
+	int i = 0;/* j = 0;*/
+	pgd_t *pgd;
+	pmd_t *pmd;
+	/*pte_t *pte;*/
+	struct mm_struct *mm = current->mm;
+
+	if (!mm) {
+		printf("!current->mm, using init_task\n");
+		mm = &init_mm;
+	}
+
+	printf("current %08x %s/%d\n", current, current->comm,
+	       current->pid);
+
+	printf("User mappings: ");
+again:
+	printf("->mm %08x ->context %08x\n",
+	       (ulong)mm, (ulong)mm->context);
+
+	if ( !mm->pgd ) {
+		printf("!mm->pgd\n");
+		return;
+	}
+
+	pgd = mm->pgd;
+
+	printf("PGD/PMD table spans %08x -> %08x\n",
+	       (ulong)mm->pgd,
+	       (ulong)mm->pgd+(PTRS_PER_PGD*sizeof(pgd_t)));
+
+
+	for ( i = 0 ; i < PTRS_PER_PGD; i++, pgd++ ) {
+		/* pmd is the same as the PGD on PPC -- Cort */
+		pmd = pmd_offset(pgd,0);
+
+		/* if there is a valid PMD (table of 1024 PTE's) */
+		if ( !pmd_none(*pmd) ) {
+			printf(" PMD %08x maps %08x,%08x (pmd_val %08x)\n",
+			       pgd, i*PGDIR_SIZE,
+			       (i*PGDIR_SIZE)+(PGDIR_SIZE-1),
+			       pmd_val(*pmd));
+#if 0
+			pte = (pte_t *)pmd_page(*pmd);
+
+			for ( j = 0; j < PTRS_PER_PTE; j++,pte++ )
+			{
+				if ( !pte || !pte_none(*pte) )
+					continue;
+				printf("   PTE %08x maps %08x,%08x\n",
+				       pte, (i*PGDIR_SIZE) + (j*PAGE_SIZE),
+				       (i*PGDIR_SIZE) + (j*PAGE_SIZE) + (PAGE_SIZE-1));
+			}
+#endif
+		}
+	}
+
+	/* do the swapper_pg_dir */
+	if ( mm != &init_mm ) {
+		printf("Kernel mappings: ");
+		mm = &init_mm;
+		goto again;
+	}
+}
+
 static void
 backtrace(struct pt_regs *excp)
 {

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 1 line · Cort Dougan

Allows printing of pgtables in xmon. Mighty useful in both trees.

Nice idea. :)

The main problem I have with the patch is that it doesn't check the pointers in the page table tree, so if the page tables are corrupted then xmon itself will get a DSI. Yes, if that is the case then your system is pretty badly hosed, but it is in those sorts of situations that you most need xmon to work. We should also be using mread() to read the pagetables safely.

The other problem is that it could print thousands or millions of lines of output. It would be nice to be able to specify an address or a range of addresses to look up rather than printing them all.

BTW, we have other points where we need to use mread() - for example I noticed that the top-level xmon() function calls smp_processor_id(), which is current->processor, which will break badly if r2 is bad.

Regards,
Paul.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/