Skip to contentSkip to conversation

powerpc/xmon: support dumping software pagetables

PATCH Superseded Balbir Singh 4 participants 6 messages Jul 21, 2017 – Jul 23, 2017 PowerPC

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 powerpc/xmon: support dumping software pagetables

It would be nice to be able to dump page tables in a particular context

Example use cases

Dumping PTE contents to see the keys (useful for debugging)

c0000000ba48c880 c0000000bab438b0 2677 2675 T 2 protection_keys
0:mon> ds c0000000ba48c880 0x7ffff7f70000 translating tsk c0000000ba48c880, addr 7ffff7f70000
G: 0xb95b6400 U: 0xb6334000 M: 0xb6543000 PA: 0x012c0000, PTE: 0xd4800000012c0504

Dumping vmalloc space

0:mon> ds 0 d000000000000000
translating tsk (null), addr d000000000000000
G: 0x3d450400 U: 0xbc184000 M: 0x3d460000 PA: 0x7e010000, PTE: 0xc08000007e01018e

I did not replicate the complex code of dump_pagetable and have no support for bolted linear mapping, thats why I've called it software pagetable dumping support. The format of the PTE can be expanded to add more useful information about the flags in the PTE if required.

---
 arch/powerpc/xmon/xmon.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
arch/powerpc/xmon/xmon.c +97 -0
index 08e367e..8aedfff 100644
@@ -126,6 +126,7 @@ static void byterev(unsigned char *, int);
 static void memex(void);
 static int bsesc(void);
 static void dump(void);
+static void show_pte(unsigned long);
 static void prdump(unsigned long, long);
 static int ppc_inst_dump(unsigned long, long, int);
 static void dump_log_buf(void);
@@ -233,6 +234,7 @@ Commands:\n\
 #endif
   "\
   dr	dump stream of raw bytes\n\
+  ds	dump software PTEs\n\
   dt	dump the tracing buffers (uses printk)\n\
 "
 #ifdef CONFIG_PPC_POWERNV
@@ -2528,6 +2530,9 @@ dump(void)
 	} else if (c == 't') {
 		ftrace_dump(DUMP_ALL);
 		tracing_on();
+	} else if (c == 's') {
+		/* dump software pte */
+		show_pte(adrs);
 	} else if (c == 'r') {
 		scanhex(&ndump);
 		if (ndump == 0)
@@ -2860,7 +2865,99 @@ static void show_task(struct task_struct *tsk)
 		state, task_thread_info(tsk)->cpu,
 		tsk->comm);
 }
+void format_pte(unsigned long pte)
+{
+	unsigned long pa = pte & PTE_RPN_MASK;
+
+	printf("PA: 0x%08lx, PTE: 0x%08lx\n", pa, pte);
+}
+
+static void show_pte(unsigned long tskv)
+{
+	unsigned long addr = 0;
+	struct task_struct *tsk = NULL;
+	struct mm_struct *mm;
+	pgd_t *pgdp;
+	pud_t *pudp;
+	pmd_t *pmdp;
+	pte_t *ptep;
+
+	tsk = (struct task_struct *)tskv;
+	if (tsk == NULL)
+		mm = &init_mm;
+	else
+		mm = tsk->active_mm;
+
+	if (mm == NULL)
+		mm = &init_mm;
+
+	if (!scanhex(&addr))
+		printf("need address to translate\n");
+
+	if (setjmp(bus_error_jmp) != 0) {
+		catch_memory_errors = 0;
+		printf("*** Error dumping pte for task %p\n", tsk);
+		return;
+	}
+
+	catch_memory_errors = 1;
+	sync();
+
+	if (mm == &init_mm)
+		pgdp = pgd_offset_k(addr);
+	else
+		pgdp = pgd_offset(mm, addr);
+
+	if (pgd_none(*pgdp)) {
+		printf("no linux page table for address\n");
+		return;
+	}
 
+	if (pgd_huge(*pgdp)) {
+		format_pte(pgd_val(*pgdp));
+		return;
+	}
+	printf("G: 0x%8lx\t", pgd_val(*pgdp));
+
+	pudp = pud_offset(pgdp, addr);
+
+	if (pud_none(*pudp)) {
+		printf("No valid PUD\n");
+		return;
+	}
+
+	if (pud_huge(*pudp)) {
+		format_pte(pud_val(*pudp));
+		return;
+	}
+	printf("U: 0x%8lx\t", pud_val(*pudp));
+
+	pmdp = pmd_offset(pudp, addr);
+
+	if (pmd_none(*pmdp)) {
+		printf("No valid PMD\n");
+		return;
+	}
+
+	if (pmd_huge(*pmdp)) {
+		format_pte(pmd_val(*pmdp));
+		return;
+	}
+	printf("M: 0x%8lx\t", pmd_val(*pmdp));
+
+	/* pte_offset_map is the same as pte_offset_kernel */
+	ptep = pte_offset_kernel(pmdp, addr);
+	if (pte_none(*ptep)) {
+		printf("no valid PTE\n");
+		return;
+	}
+
+	format_pte(pte_val(*ptep));
+
+	sync();
+	__delay(200);
+	catch_memory_errors = 0;
+}
 static void show_tasks(void)
 {
 	unsigned long tskv;
Signature · 1 line
2.9.4
#1 lore raw

PATCH 2/2 powerpc/xmon: revisit SPR support

This patch readjusts the SPR's adds support for IAMR/AMR UAMOR/AMOR based on their supported ISA revisions. The HDEC SPR is now printed with 16 hex digits instead of 8, so that we can see the expanded values on ISA 300. There is also support for printing the PIDR/TIDR for ISA 300 and PSSCR and PTCR in ISA 300 hypervisor mode.

---
 arch/powerpc/xmon/xmon.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
arch/powerpc/xmon/xmon.c +27 -1
index 8aedfff..e025a16 100644
@@ -1738,13 +1738,15 @@ static void dump_206_sprs(void)
 		mfspr(SPRN_SRR0), mfspr(SPRN_SRR1), mfspr(SPRN_DSISR));
 	printf("dscr   = %.16x  ppr   = %.16x pir    = %.8x\n",
 		mfspr(SPRN_DSCR), mfspr(SPRN_PPR), mfspr(SPRN_PIR));
+	printf("amr    = %.16x  uamor = %.16x\n",
+		mfspr(SPRN_AMR), mfspr(SPRN_UAMOR));
 
 	if (!(mfmsr() & MSR_HV))
 		return;
 
 	printf("sdr1   = %.16x  hdar  = %.16x hdsisr = %.8x\n",
 		mfspr(SPRN_SDR1), mfspr(SPRN_HDAR), mfspr(SPRN_HDSISR));
-	printf("hsrr0  = %.16x hsrr1  = %.16x hdec = %.8x\n",
+	printf("hsrr0  = %.16x hsrr1  = %.16x hdec = %.16x\n",
 		mfspr(SPRN_HSRR0), mfspr(SPRN_HSRR1), mfspr(SPRN_HDEC));
 	printf("lpcr   = %.16x  pcr   = %.16x lpidr = %.8x\n",
 		mfspr(SPRN_LPCR), mfspr(SPRN_PCR), mfspr(SPRN_LPID));
@@ -1788,6 +1790,7 @@ static void dump_207_sprs(void)
 		mfspr(SPRN_SDAR), mfspr(SPRN_SIER), mfspr(SPRN_PMC6));
 	printf("ebbhr  = %.16x  ebbrr = %.16x bescr  = %.16x\n",
 		mfspr(SPRN_EBBHR), mfspr(SPRN_EBBRR), mfspr(SPRN_BESCR));
+	printf("iamr   = %.16x\n", mfspr(SPRN_IAMR));
 
 	if (!(msr & MSR_HV))
 		return;
@@ -1796,6 +1799,28 @@ static void dump_207_sprs(void)
 		mfspr(SPRN_HFSCR), mfspr(SPRN_DHDES), mfspr(SPRN_RPR));
 	printf("dawr   = %.16x  dawrx = %.16x ciabr  = %.16x\n",
 		mfspr(SPRN_DAWR), mfspr(SPRN_DAWRX), mfspr(SPRN_CIABR));
+	printf("amor   = %.16x\n", mfspr(SPRN_AMOR));
+#endif
+}
+
+static void dump_300_sprs(void)
+{
+#ifdef CONFIG_PPC64
+	unsigned long msr;
+
+	if (!cpu_has_feature(CPU_FTR_ARCH_300))
+		return;
+
+	printf("pidr   = %.16x  tidr  = %.16x asdr   = %.16x\n",
+		mfspr(SPRN_PID), mfspr(SPRN_TIDR), mfspr(SPRN_ASDR));
+
+	msr = mfmsr();
+
+	if (!(msr & MSR_HV))
+		return;
+
+	printf("ptcr   = %.16x  psscr = %.16x\n",
+		mfspr(SPRN_PTCR), mfspr(SPRN_PSSCR));
 #endif
 }
 
@@ -1852,6 +1877,7 @@ static void super_regs(void)
 
 		dump_206_sprs();
 		dump_207_sprs();
+		dump_300_sprs();
 
 		return;
 	}
Signature · 1 line
2.9.4
#2 lore raw
In reply to Balbir Singh

Nice !

Quoted 8 lines · Balbir Singh

It would be nice to be able to dump page tables in a particular context

Example use cases

Dumping PTE contents to see the keys (useful for debugging)

c0000000ba48c880 c0000000bab438b0 2677 2675 T 2 protection_keys

What is that ^ ?

Quoted 3 lines

0:mon> ds c0000000ba48c880 0x7ffff7f70000 translating tsk c0000000ba48c880, addr 7ffff7f70000
G: 0xb95b6400 U: 0xb6334000 M: 0xb6543000 PA: 0x012c0000, PTE: 0xd4800000012c0504

Without reading the code I don't grok what G/U/M mean.

Feel free to use more than one line of output :)

Quoted 3 lines

Dumping vmalloc space

0:mon> ds 0 d000000000000000

I suspect we will want to do that a lot. So I'd rather the arguments were reversed, and the second (task) can be omitted.

So:
0:mon> ds x == translate x via init_mm
0:mon> ds x y == translate x via &y->mm

I guess it's easier for folks to find a task rather than an mm directly? Otherwise it could take an mm not a task.

Quoted 1 line

translating tsk (null), addr d000000000000000

We should special case that to say "using kernel page tables" or similar.

Quoted 5 lines

G: 0x3d450400 U: 0xbc184000 M: 0x3d460000 PA: 0x7e010000, PTE: 0xc08000007e01018e

I did not replicate the complex code of dump_pagetable and have no support for bolted linear mapping, thats why I've called it software pagetable dumping support.

Not sure about that naming. On hash it makes sense, but not on radix or on other platforms.

Maybe 'dv' for dump Virtual address ?

It doesn't dump a PTE, it tries to translate an address into a PTE.

cheers

#3 lore raw
Quoted 7 lines · Michael Ellerman

Nice !

Quoted 3 lines · Balbir Singh

It would be nice to be able to dump page tables in a particular context

Quoted 7 lines
Quoted 5 lines

Example use cases

Dumping PTE contents to see the keys (useful for debugging)

c0000000ba48c880 c0000000bab438b0 2677 2675 T 2 protection_keys

What is that ^ ?

Thats extra, the output of P (print all tasks, I've used that task selection)

Quoted 6 lines
Quoted 4 lines

0:mon> ds c0000000ba48c880 0x7ffff7f70000 translating tsk c0000000ba48c880, addr 7ffff7f70000
G: 0xb95b6400 U: 0xb6334000 M: 0xb6543000 PA: 0x012c0000, PTE: 0xd4800000012c0504

Without reading the code I don't grok what G/U/M mean.

PGD, PUD and PMD, I'll expand on them.

Quoted 9 lines

Feel free to use more than one line of output :)

Quoted 3 lines

Dumping vmalloc space

0:mon> ds 0 d000000000000000

I suspect we will want to do that a lot. So I'd rather the arguments were reversed, and the second (task) can be omitted.

I considered that as well, can do

Quoted 8 lines

So:
0:mon> ds x == translate x via init_mm
0:mon> ds x y == translate x via &y->mm

I guess it's easier for folks to find a task rather than an mm directly? Otherwise it could take an mm not a task.

we already have commands for task, via (P), which is why I thought task makes sense.

Quoted 9 lines
Quoted 1 line

translating tsk (null), addr d000000000000000

We should special case that to say "using kernel page tables" or similar.

Quoted 4 lines

G: 0x3d450400 U: 0xbc184000 M: 0x3d460000 PA: 0x7e010000, PTE: 0xc08000007e01018e
I did not replicate the complex code of dump_pagetable and have no support for bolted linear mapping, thats why I've called it software pagetable dumping support.

Quoted 7 lines

Not sure about that naming. On hash it makes sense, but not on radix or on other platforms.

Maybe 'dv' for dump Virtual address ?

It doesn't dump a PTE, it tries to translate an address into a PTE.

Done, will do a v2

Thanks for the review!
Balbir Singh.

#4 lore raw
In reply to Balbir Singh
Quoted 14 lines · Balbir Singh

It would be nice to be able to dump page tables in a particular context

Example use cases

Dumping PTE contents to see the keys (useful for debugging)

c0000000ba48c880 c0000000bab438b0 2677 2675 T 2 protection_keys
0:mon> ds c0000000ba48c880 0x7ffff7f70000 translating tsk c0000000ba48c880, addr 7ffff7f70000
G: 0xb95b6400 U: 0xb6334000 M: 0xb6543000 PA: 0x012c0000, PTE: 0xd4800000012c0504

Dumping vmalloc space

Quoted 8 lines

0:mon> ds 0 d000000000000000
translating tsk (null), addr d000000000000000
G: 0x3d450400 U: 0xbc184000 M: 0x3d460000 PA: 0x7e010000, PTE: 0xc08000007e01018e

I did not replicate the complex code of dump_pagetable and have no support for bolted linear mapping, thats why I've called it software pagetable dumping support. The format of the PTE can be expanded to add more useful information about the flags in the PTE if required.

yes. a nice way of dumping all the flags in the PTE will be handy. especially; my favorite, protection key values.

Quoted 119 lines
---
 arch/powerpc/xmon/xmon.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
arch/powerpc/xmon/xmon.c +83 -0
index 08e367e..8aedfff 100644
@@ -126,6 +126,7 @@ static void byterev(unsigned char *, int);
 static void memex(void);
 static int bsesc(void);
 static void dump(void);
+static void show_pte(unsigned long);
 static void prdump(unsigned long, long);
 static int ppc_inst_dump(unsigned long, long, int);
 static void dump_log_buf(void);
@@ -233,6 +234,7 @@ Commands:\n\
 #endif
   "\
   dr	dump stream of raw bytes\n\
+  ds	dump software PTEs\n\
   dt	dump the tracing buffers (uses printk)\n\
 "
 #ifdef CONFIG_PPC_POWERNV
@@ -2528,6 +2530,9 @@ dump(void)
 	} else if (c == 't') {
 		ftrace_dump(DUMP_ALL);
 		tracing_on();
+	} else if (c == 's') {
+		/* dump software pte */
+		show_pte(adrs);
 	} else if (c == 'r') {
 		scanhex(&ndump);
 		if (ndump == 0)
@@ -2860,7 +2865,99 @@ static void show_task(struct task_struct *tsk)
 		state, task_thread_info(tsk)->cpu,
 		tsk->comm);
 }
+void format_pte(unsigned long pte)
+{
+	unsigned long pa = pte & PTE_RPN_MASK;
+
+	printf("PA: 0x%08lx, PTE: 0x%08lx\n", pa, pte);
+}
+
+static void show_pte(unsigned long tskv)
+{
+	unsigned long addr = 0;
+	struct task_struct *tsk = NULL;
+	struct mm_struct *mm;
+	pgd_t *pgdp;
+	pud_t *pudp;
+	pmd_t *pmdp;
+	pte_t *ptep;
+
+	tsk = (struct task_struct *)tskv;
+	if (tsk == NULL)
+		mm = &init_mm;
+	else
+		mm = tsk->active_mm;
+
+	if (mm == NULL)
+		mm = &init_mm;
+
+	if (!scanhex(&addr))
+		printf("need address to translate\n");
+
+	if (setjmp(bus_error_jmp) != 0) {
+		catch_memory_errors = 0;
+		printf("*** Error dumping pte for task %p\n", tsk);
+		return;
+	}
+
+	catch_memory_errors = 1;
+	sync();
+
+	if (mm == &init_mm)
+		pgdp = pgd_offset_k(addr);
+	else
+		pgdp = pgd_offset(mm, addr);
+
+	if (pgd_none(*pgdp)) {
+		printf("no linux page table for address\n");
+		return;
+	}
 
+	if (pgd_huge(*pgdp)) {
+		format_pte(pgd_val(*pgdp));
+		return;
+	}
+	printf("G: 0x%8lx\t", pgd_val(*pgdp));
+
+	pudp = pud_offset(pgdp, addr);
+
+	if (pud_none(*pudp)) {
+		printf("No valid PUD\n");
+		return;
+	}
+
+	if (pud_huge(*pudp)) {
+		format_pte(pud_val(*pudp));
+		return;
+	}
+	printf("U: 0x%8lx\t", pud_val(*pudp));
+
+	pmdp = pmd_offset(pudp, addr);
+
+	if (pmd_none(*pmdp)) {
+		printf("No valid PMD\n");
+		return;
+	}
+
+	if (pmd_huge(*pmdp)) {
+		format_pte(pmd_val(*pmdp));
+		return;
+	}
+	printf("M: 0x%8lx\t", pmd_val(*pmdp));

arch/powerpc/xmon/xmon.c static void show_task(struct task_struct *tsk) · line 2956

Quoted 10 lines
arch/powerpc/xmon/xmon.c +10 -0
+
+	/* pte_offset_map is the same as pte_offset_kernel */
+	ptep = pte_offset_kernel(pmdp, addr);
+	if (pte_none(*ptep)) {
+		printf("no valid PTE\n");
+		return;
+	}
+
+	format_pte(pte_val(*ptep));
+

These two lines below always go togather. A nice macro #define sync_delay() { sync(); __delay(200); } can help.

Quoted 13 lines
arch/powerpc/xmon/xmon.c +4 -0
+	sync();
+	__delay(200);
 
 
+	catch_memory_errors = 0;
 
 
+}
 static void show_tasks(void)
 {
 	unsigned long tskv;
Signature · 1 line
2.9.4
Signature · 1 line
Ram Pai
#5 lore raw
In reply to Balbir Singh
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Balbir,

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.13-rc1 next-20170721]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Balbir-Singh/powerpc-xmon-support-dumping-software-pagetables/20170723-002848
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-akebono_defconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc

All errors (new ones prefixed by >>):

arch/powerpc/xmon/xmon.c: In function 'show_pte':

>> arch/powerpc/xmon/xmon.c:2929:6: error: implicit declaration of function 'pud_huge' [-Werror=implicit-function-declaration]
     if (pud_huge(*pudp)) {
         ^~~~~~~~
>> arch/powerpc/xmon/xmon.c:2942:6: error: implicit declaration of function 'pmd_huge' [-Werror=implicit-function-declaration]
     if (pmd_huge(*pmdp)) {
         ^~~~~~~~

cc1: all warnings being treated as errors

vim +/pud_huge +2929 arch/powerpc/xmon/xmon.c

2874
2875 static void show_pte(unsigned long tskv)
2876 {
2877 unsigned long addr = 0;
2878 struct task_struct *tsk = NULL;
2879 struct mm_struct *mm;
2880 pgd_t *pgdp;
2881 pud_t *pudp;
2882 pmd_t *pmdp;
2883 pte_t *ptep;
2884
2885 tsk = (struct task_struct *)tskv;
2886 if (tsk == NULL)
2887 mm = &init_mm;
2888 else
2889 mm = tsk->active_mm;
2890
2891 if (mm == NULL)
2892 mm = &init_mm;
2893
2894 if (!scanhex(&addr))
2895 printf("need address to translate\n");
2896
2897 if (setjmp(bus_error_jmp) != 0) {
2898 catch_memory_errors = 0;
2899 printf("*** Error dumping pte for task %p\n", tsk);
2900 return;
2901 }
2902
2903 catch_memory_errors = 1;
2904 sync();
2905
2906 if (mm == &init_mm)
2907 pgdp = pgd_offset_k(addr);
2908 else
2909 pgdp = pgd_offset(mm, addr);
2910
2911 if (pgd_none(*pgdp)) {
2912 printf("no linux page table for address\n");
2913 return;
2914 }
2915
2916 if (pgd_huge(*pgdp)) {
2917 format_pte(pgd_val(*pgdp));
2918 return;
2919 }
2920 printf("G: 0x%8lx\t", pgd_val(*pgdp));
2921
2922 pudp = pud_offset(pgdp, addr);
2923
2924 if (pud_none(*pudp)) {
2925 printf("No valid PUD\n");
2926 return;
2927 }
2928

> 2929		if (pud_huge(*pudp)) {
  2930			format_pte(pud_val(*pudp));
  2931			return;
  2932		}
  2933		printf("U: 0x%8lx\t", pud_val(*pudp));
  2934	
  2935		pmdp = pmd_offset(pudp, addr);
  2936	
  2937		if (pmd_none(*pmdp)) {
  2938			printf("No valid PMD\n");
  2939			return;
  2940		}
  2941	
> 2942		if (pmd_huge(*pmdp)) {

2943 format_pte(pmd_val(*pmdp));
2944 return;
2945 }
2946 printf("M: 0x%8lx\t", pmd_val(*pmdp));
2947
2948 /* pte_offset_map is the same as pte_offset_kernel */
2949 ptep = pte_offset_kernel(pmdp, addr);
2950 if (pte_none(*ptep)) {
2951 printf("no valid PTE\n");
2952 return;
2953 }
2954
2955 format_pte(pte_val(*ptep));
2956
2957 sync();
2958 __delay(200);
2959 catch_memory_errors = 0;
2960 }
2961 static void show_tasks(void)
2962 {
2963 unsigned long tskv;
2964 struct task_struct *tsk = NULL;
2965
2966 printf(" task_struct ->thread.ksp PID PPID S P CMD\n");
2967
2968 if (scanhex(&tskv))
2969 tsk = (struct task_struct *)tskv;
2970
2971 if (setjmp(bus_error_jmp) != 0) {
2972 catch_memory_errors = 0;
2973 printf("*** Error dumping task %p\n", tsk);
2974 return;
2975 }
2976
2977 catch_memory_errors = 1;
2978 sync();
2979
2980 if (tsk)
2981 show_task(tsk);
2982 else
2983 for_each_process(tsk)
2984 show_task(tsk);
2985
2986 sync();
2987 __delay(200);
2988 catch_memory_errors = 0;
2989 }
2990

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation