linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] nds32: remove dump_instr
@ 2020-07-20 11:44 Christoph Hellwig
  2020-07-20 11:44 ` [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem Christoph Hellwig
  2020-07-21 11:08 ` [PATCH 1/2] nds32: remove dump_instr Nick Hu
  0 siblings, 2 replies; 9+ messages in thread
From: Christoph Hellwig @ 2020-07-20 11:44 UTC (permalink / raw)
  To: nickhu, green.hu, deanbo422; +Cc: linux-kernel

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

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/nds32/kernel/traps.c | 35 -----------------------------------
 1 file changed, 35 deletions(-)

diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c
index 6a9772ba739276..b66f889bc6df9b 100644
--- a/arch/nds32/kernel/traps.c
+++ b/arch/nds32/kernel/traps.c
@@ -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();
 	}
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2020-07-20 11:44 [PATCH 1/2] nds32: remove dump_instr Christoph Hellwig
@ 2020-07-20 11:44 ` Christoph Hellwig
  2020-07-21 11:07   ` Nick Hu
  2020-07-21 11:08 ` [PATCH 1/2] nds32: remove dump_instr Nick Hu
  1 sibling, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-07-20 11:44 UTC (permalink / raw)
  To: nickhu, green.hu, deanbo422; +Cc: linux-kernel

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

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/nds32/kernel/traps.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c
index b66f889bc6df9b..ee0d9ae192a504 100644
--- a/arch/nds32/kernel/traps.c
+++ b/arch/nds32/kernel/traps.c
@@ -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);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2020-07-20 11:44 ` [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem Christoph Hellwig
@ 2020-07-21 11:07   ` Nick Hu
  2020-07-21 11:28     ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Hu @ 2020-07-21 11:07 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: green.hu, deanbo422, linux-kernel

On Mon, Jul 20, 2020 at 01:44:48PM +0200, Christoph Hellwig wrote:
> Use the proper get_kernel_nofault helper to access an unsafe kernel
> pointer without faulting instead of playing with set_fs and get_user.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/nds32/kernel/traps.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c
> index b66f889bc6df9b..ee0d9ae192a504 100644
> --- a/arch/nds32/kernel/traps.c
> +++ b/arch/nds32/kernel/traps.c
> @@ -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);
> -- 
> 2.27.0
>
Hi Christoph,

Thank you!
Acked-by: Nick Hu <nickhu@andestech.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] nds32: remove dump_instr
  2020-07-20 11:44 [PATCH 1/2] nds32: remove dump_instr Christoph Hellwig
  2020-07-20 11:44 ` [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem Christoph Hellwig
@ 2020-07-21 11:08 ` Nick Hu
  1 sibling, 0 replies; 9+ messages in thread
From: Nick Hu @ 2020-07-21 11:08 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: green.hu, deanbo422, linux-kernel

On Mon, Jul 20, 2020 at 01:44:47PM +0200, Christoph Hellwig wrote:
> dump_inst has a return before actually doing anything, so just drop the
> whole thing.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  arch/nds32/kernel/traps.c | 35 -----------------------------------
>  1 file changed, 35 deletions(-)
> 
> diff --git a/arch/nds32/kernel/traps.c b/arch/nds32/kernel/traps.c
> index 6a9772ba739276..b66f889bc6df9b 100644
> --- a/arch/nds32/kernel/traps.c
> +++ b/arch/nds32/kernel/traps.c
> @@ -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();
>  	}
>  
> -- 
> 2.27.0
>

Acked-by: Nick Hu <nickhu@andestech.com> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2020-07-21 11:07   ` Nick Hu
@ 2020-07-21 11:28     ` Christoph Hellwig
  2021-01-28 10:16       ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-07-21 11:28 UTC (permalink / raw)
  To: Nick Hu; +Cc: Christoph Hellwig, green.hu, deanbo422, linux-kernel

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2020-07-21 11:28     ` Christoph Hellwig
@ 2021-01-28 10:16       ` Christoph Hellwig
  2021-02-24  7:47         ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2021-01-28 10:16 UTC (permalink / raw)
  To: Nick Hu; +Cc: Christoph Hellwig, green.hu, deanbo422, linux-kernel

On Tue, Jul 21, 2020 at 01:28:00PM +0200, Christoph Hellwig wrote:
> 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/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2021-01-28 10:16       ` Christoph Hellwig
@ 2021-02-24  7:47         ` Christoph Hellwig
  2021-02-24  8:59           ` Greentime Hu
  0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2021-02-24  7:47 UTC (permalink / raw)
  To: Nick Hu; +Cc: Christoph Hellwig, green.hu, deanbo422, linux-kernel

On Thu, Jan 28, 2021 at 11:16:33AM +0100, Christoph Hellwig wrote:
> On Tue, Jul 21, 2020 at 01:28:00PM +0200, Christoph Hellwig wrote:
> > 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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2021-02-24  7:47         ` Christoph Hellwig
@ 2021-02-24  8:59           ` Greentime Hu
  2021-02-24  9:02             ` Christoph Hellwig
  0 siblings, 1 reply; 9+ messages in thread
From: Greentime Hu @ 2021-02-24  8:59 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Nick Hu, Vincent Chen, Linux Kernel Mailing List

Christoph Hellwig <hch@lst.de> 於 2021年2月24日 週三 下午3:47寫道:
>
> On Thu, Jan 28, 2021 at 11:16:33AM +0100, Christoph Hellwig wrote:
> > On Tue, Jul 21, 2020 at 01:28:00PM +0200, Christoph Hellwig wrote:
> > > 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.
Acked-by: Greentime Hu <green.hu@gmail.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem
  2021-02-24  8:59           ` Greentime Hu
@ 2021-02-24  9:02             ` Christoph Hellwig
  0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-02-24  9:02 UTC (permalink / raw)
  To: Greentime Hu
  Cc: Christoph Hellwig, Nick Hu, Vincent Chen, Linux Kernel Mailing List

On Wed, Feb 24, 2021 at 04:59:37PM +0800, Greentime Hu wrote:
> Christoph Hellwig <hch@lst.de> 於 2021年2月24日 週三 下午3:47寫道:
> >
> > On Thu, Jan 28, 2021 at 11:16:33AM +0100, Christoph Hellwig wrote:
> > > On Tue, Jul 21, 2020 at 01:28:00PM +0200, Christoph Hellwig wrote:
> > > > 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.
> Acked-by: Greentime Hu <green.hu@gmail.com>

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-02-24  9:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20 11:44 [PATCH 1/2] nds32: remove dump_instr Christoph Hellwig
2020-07-20 11:44 ` [PATCH 2/2] nds32: use get_kernel_nofault in dump_mem Christoph Hellwig
2020-07-21 11:07   ` Nick Hu
2020-07-21 11:28     ` Christoph Hellwig
2021-01-28 10:16       ` Christoph Hellwig
2021-02-24  7:47         ` Christoph Hellwig
2021-02-24  8:59           ` Greentime Hu
2021-02-24  9:02             ` Christoph Hellwig
2020-07-21 11:08 ` [PATCH 1/2] nds32: remove dump_instr Nick Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).