Skip to contentSkip to conversation

nds32: remove dump_instr

PATCH In review Christoph Hellwig 3 participants 9 messages Jul 20, 2020 – Feb 24, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 nds32: remove dump_instr

dump_inst has a return before actually doing anything, so just drop the whole thing.

---
 arch/nds32/kernel/traps.c | 35 -----------------------------------
 1 file changed, 35 deletions(-)
arch/nds32/kernel/traps.c +0 -35
index 6a9772ba739276..b66f889bc6df9b 100644
@@ -62,40 +62,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 
 EXPORT_SYMBOL(dump_mem);
 
-static void dump_instr(struct pt_regs *regs)
-{
-	unsigned long addr = instruction_pointer(regs);
-	mm_segment_t fs;
-	char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
-	int i;
-
-	return;
-	/*
-	 * We need to switch to kernel mode so that we can use __get_user
-	 * to safely read from kernel space.  Note that we now dump the
-	 * code first, just in case the backtrace kills us.
-	 */
-	fs = get_fs();
-	set_fs(KERNEL_DS);
-
-	pr_emerg("Code: ");
-	for (i = -4; i < 1; i++) {
-		unsigned int val, bad;
-
-		bad = __get_user(val, &((u32 *) addr)[i]);
-
-		if (!bad) {
-			p += sprintf(p, i == 0 ? "(%08x) " : "%08x ", val);
-		} else {
-			p += sprintf(p, "bad PC value");
-			break;
-		}
-	}
-	pr_emerg("Code: %s\n", str);
-
-	set_fs(fs);
-}
-
 #define LOOP_TIMES (100)
 static void __dump(struct task_struct *tsk, unsigned long *base_reg,
 		   const char *loglvl)
@@ -179,7 +145,6 @@ void die(const char *str, struct pt_regs *regs, int err)
 
 	if (!user_mode(regs) || in_interrupt()) {
 		dump_mem("Stack: ", regs->sp, (regs->sp + PAGE_SIZE) & PAGE_MASK);
-		dump_instr(regs);
 		dump_stack();
 	}
 
Signature · 1 line
2.27.0
#1 lore raw

PATCH 2/2 nds32: use get_kernel_nofault in dump_mem

Use the proper get_kernel_nofault helper to access an unsafe kernel pointer without faulting instead of playing with set_fs and get_user.

---
 arch/nds32/kernel/traps.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
arch/nds32/kernel/traps.c +3 -12
index b66f889bc6df9b..ee0d9ae192a504 100644
@@ -25,17 +25,8 @@ extern void show_pte(struct mm_struct *mm, unsigned long addr);
 void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 {
 	unsigned long first;
-	mm_segment_t fs;
 	int i;
 
-	/*
-	 * We need to switch to kernel mode so that we can use __get_user
-	 * to safely read from kernel space.  Note that we now dump the
-	 * code first, just in case the backtrace kills us.
-	 */
-	fs = get_fs();
-	set_fs(KERNEL_DS);
-
 	pr_emerg("%s(0x%08lx to 0x%08lx)\n", lvl, bottom, top);
 
 	for (first = bottom & ~31; first < top; first += 32) {
@@ -48,7 +39,9 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 		for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
 			if (p >= bottom && p < top) {
 				unsigned long val;
-				if (__get_user(val, (unsigned long *)p) == 0)
+
+				if (get_kernel_nofault(val,
+						(unsigned long *)p) == 0)
 					sprintf(str + i * 9, " %08lx", val);
 				else
 					sprintf(str + i * 9, " ????????");
@@ -56,8 +49,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 		}
 		pr_emerg("%s%04lx:%s\n", lvl, first & 0xffff, str);
 	}
-
-	set_fs(fs);
 }
 
 EXPORT_SYMBOL(dump_mem);
Signature · 1 line
2.27.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem

Quoted 53 lines · Christoph Hellwig

Use the proper get_kernel_nofault helper to access an unsafe kernel pointer without faulting instead of playing with set_fs and get_user.

---
 arch/nds32/kernel/traps.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
arch/nds32/kernel/traps.c +3 -12
index b66f889bc6df9b..ee0d9ae192a504 100644
@@ -25,17 +25,8 @@ extern void show_pte(struct mm_struct *mm, unsigned long addr);
 void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 {
 	unsigned long first;
-	mm_segment_t fs;
 	int i;
 
-	/*
-	 * We need to switch to kernel mode so that we can use __get_user
-	 * to safely read from kernel space.  Note that we now dump the
-	 * code first, just in case the backtrace kills us.
-	 */
-	fs = get_fs();
-	set_fs(KERNEL_DS);
-
 	pr_emerg("%s(0x%08lx to 0x%08lx)\n", lvl, bottom, top);
 
 	for (first = bottom & ~31; first < top; first += 32) {
@@ -48,7 +39,9 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 		for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
 			if (p >= bottom && p < top) {
 				unsigned long val;
-				if (__get_user(val, (unsigned long *)p) == 0)
+
+				if (get_kernel_nofault(val,
+						(unsigned long *)p) == 0)
 					sprintf(str + i * 9, " %08lx", val);
 				else
 					sprintf(str + i * 9, " ????????");
@@ -56,8 +49,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 		}
 		pr_emerg("%s%04lx:%s\n", lvl, first & 0xffff, str);
 	}
-
-	set_fs(fs);
 }
 
 EXPORT_SYMBOL(dump_mem);
Signature · 1 line
2.27.0

Hi Christoph,

Thank you!

#3 lore raw

Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem

Can you pich the patches up in the nds32 tree for Linus? There are not short-term dependencies on them.

#4 lore raw

Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem

Quoted 2 lines · Christoph Hellwig

Can you pich the patches up in the nds32 tree for Linus? There are not short-term dependencies on them.

It seems like these patches are still sitting in linux-next and never made it to Linus/

#5 lore raw

Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem

Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

Can you pich the patches up in the nds32 tree for Linus? There are not short-term dependencies on them.

It seems like these patches are still sitting in linux-next and never made it to Linus/

ping?

Acked-by
#6 lore raw

Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem

Christoph Hellwig <[email protected]> 於 2021年2月24日 週三 下午3:47寫道:

Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines

Can you pich the patches up in the nds32 tree for Linus? There are not short-term dependencies on them.

It seems like these patches are still sitting in linux-next and never made it to Linus/

ping?

Sorry for late.

#7 lore raw

Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem

Quoted 7 lines · Greentime Hu

Christoph Hellwig <[email protected]> 於 2021年2月24日 週三 下午3:47寫道:

Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines

Can you pich the patches up in the nds32 tree for Linus? There are not short-term dependencies on them.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It seems like these patches are still sitting in linux-next and never made it to Linus/

ping?

Sorry for late.

Well, I'm mostly interested in eventually getting it sent to Linus given that it has been in linux-next for months.

Acked-by on v1 1/2
#8 lore raw
In reply to Christoph Hellwig
Quoted 64 lines · Christoph Hellwig

dump_inst has a return before actually doing anything, so just drop the whole thing.

---
 arch/nds32/kernel/traps.c | 35 -----------------------------------
 1 file changed, 35 deletions(-)
arch/nds32/kernel/traps.c +0 -35
index 6a9772ba739276..b66f889bc6df9b 100644
@@ -62,40 +62,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 
 EXPORT_SYMBOL(dump_mem);
 
-static void dump_instr(struct pt_regs *regs)
-{
-	unsigned long addr = instruction_pointer(regs);
-	mm_segment_t fs;
-	char str[sizeof("00000000 ") * 5 + 2 + 1], *p = str;
-	int i;
-
-	return;
-	/*
-	 * We need to switch to kernel mode so that we can use __get_user
-	 * to safely read from kernel space.  Note that we now dump the
-	 * code first, just in case the backtrace kills us.
-	 */
-	fs = get_fs();
-	set_fs(KERNEL_DS);
-
-	pr_emerg("Code: ");
-	for (i = -4; i < 1; i++) {
-		unsigned int val, bad;
-
-		bad = __get_user(val, &((u32 *) addr)[i]);
-
-		if (!bad) {
-			p += sprintf(p, i == 0 ? "(%08x) " : "%08x ", val);
-		} else {
-			p += sprintf(p, "bad PC value");
-			break;
-		}
-	}
-	pr_emerg("Code: %s\n", str);
-
-	set_fs(fs);
-}
-
 #define LOOP_TIMES (100)
 static void __dump(struct task_struct *tsk, unsigned long *base_reg,
 		   const char *loglvl)
@@ -179,7 +145,6 @@ void die(const char *str, struct pt_regs *regs, int err)
 
 	if (!user_mode(regs) || in_interrupt()) {
 		dump_mem("Stack: ", regs->sp, (regs->sp + PAGE_SIZE) & PAGE_MASK);
-		dump_instr(regs);
 		dump_stack();
 	}
 
Signature · 1 line
2.27.0