2020-07-20 11:46:10

by Christoph Hellwig

[permalink] [raw]
Subject: [PATCH 1/2] nds32: remove dump_instr

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

Signed-off-by: Christoph Hellwig <[email protected]>
---
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


2020-07-20 11:47:47

by Christoph Hellwig

[permalink] [raw]
Subject: [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.

Signed-off-by: Christoph Hellwig <[email protected]>
---
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

2020-07-21 11:20:13

by Nick Hu

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

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 <[email protected]>
> ---
> 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 <[email protected]>

2020-07-21 11:20:17

by Nick Hu

[permalink] [raw]
Subject: Re: [PATCH 1/2] nds32: remove dump_instr

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 <[email protected]>
> ---
> 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 <[email protected]>

2020-07-21 11:28:38

by Christoph Hellwig

[permalink] [raw]
Subject: 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.

2021-01-28 10:19:52

by Christoph Hellwig

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

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/

2021-02-24 12:58:08

by Christoph Hellwig

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

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?

2021-02-24 13:06:15

by Christoph Hellwig

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

On Wed, Feb 24, 2021 at 04:59:37PM +0800, Greentime Hu wrote:
> Christoph Hellwig <[email protected]> 於 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 <[email protected]>

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

2021-02-24 13:06:33

by Greentime Hu

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

Christoph Hellwig <[email protected]> 於 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 <[email protected]>