linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()
@ 2018-09-18  9:26 Christophe Leroy
  2018-09-18  9:33 ` Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()) Christophe Leroy
  2018-10-22  9:37 ` powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() Michael Ellerman
  0 siblings, 2 replies; 9+ messages in thread
From: Christophe Leroy @ 2018-09-18  9:26 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
  Cc: linux-kernel, linuxppc-dev

Generic implementation fails to remove breakpoints after init
when CONFIG_STRICT_KERNEL_RWX is selected:

[   13.251285] KGDB: BP remove failed: c001c338
[   13.259587] kgdbts: ERROR PUT: end of test buffer on 'do_fork_test' line 8 expected OK got $E14#aa
[   13.268969] KGDB: re-enter exception: ALL breakpoints killed
[   13.275099] CPU: 0 PID: 1 Comm: init Not tainted 4.18.0-g82bbb913ffd8 #860
[   13.282836] Call Trace:
[   13.285313] [c60e1ba0] [c0080ef0] kgdb_handle_exception+0x6f4/0x720 (unreliable)
[   13.292618] [c60e1c30] [c000e97c] kgdb_handle_breakpoint+0x3c/0x98
[   13.298709] [c60e1c40] [c000af54] program_check_exception+0x104/0x700
[   13.305083] [c60e1c60] [c000e45c] ret_from_except_full+0x0/0x4
[   13.310845] [c60e1d20] [c02a22ac] run_simple_test+0x2b4/0x2d4
[   13.316532] [c60e1d30] [c0081698] put_packet+0xb8/0x158
[   13.321694] [c60e1d60] [c00820b4] gdb_serial_stub+0x230/0xc4c
[   13.327374] [c60e1dc0] [c0080af8] kgdb_handle_exception+0x2fc/0x720
[   13.333573] [c60e1e50] [c000e928] kgdb_singlestep+0xb4/0xcc
[   13.339068] [c60e1e70] [c000ae1c] single_step_exception+0x90/0xac
[   13.345100] [c60e1e80] [c000e45c] ret_from_except_full+0x0/0x4
[   13.350865] [c60e1f40] [c000e11c] ret_from_syscall+0x0/0x38
[   13.356346] Kernel panic - not syncing: Recursive entry to debugger

This patch creates powerpc specific version of
kgdb_arch_set_breakpoint() and kgdb_arch_remove_breakpoint()
using patch_instruction()

Fixes: 1e0fc9d1eb2b ("powerpc/Kconfig: Enable STRICT_KERNEL_RWX for some configs")
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/include/asm/kgdb.h |  5 ++++-
 arch/powerpc/kernel/kgdb.c      | 43 +++++++++++++++++++++++++++++++++--------
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/kgdb.h b/arch/powerpc/include/asm/kgdb.h
index 9db24e77b9f4..a9e098a3b881 100644
--- a/arch/powerpc/include/asm/kgdb.h
+++ b/arch/powerpc/include/asm/kgdb.h
@@ -26,9 +26,12 @@
 #define BREAK_INSTR_SIZE	4
 #define BUFMAX			((NUMREGBYTES * 2) + 512)
 #define OUTBUFMAX		((NUMREGBYTES * 2) + 512)
+
+#define BREAK_INSTR		0x7d821008	/* twge r2, r2 */
+
 static inline void arch_kgdb_breakpoint(void)
 {
-	asm(".long 0x7d821008"); /* twge r2, r2 */
+	asm(stringify_in_c(.long BREAK_INSTR));
 }
 #define CACHE_FLUSH_IS_SAFE	1
 #define DBG_MAX_REG_NUM     70
diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
index 35e240a0a408..59c578f865aa 100644
--- a/arch/powerpc/kernel/kgdb.c
+++ b/arch/powerpc/kernel/kgdb.c
@@ -24,6 +24,7 @@
 #include <asm/processor.h>
 #include <asm/machdep.h>
 #include <asm/debug.h>
+#include <asm/code-patching.h>
 #include <linux/slab.h>
 
 /*
@@ -144,7 +145,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)
 	if (kgdb_handle_exception(1, SIGTRAP, 0, regs) != 0)
 		return 0;
 
-	if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
+	if (*(u32 *)regs->nip == BREAK_INSTR)
 		regs->nip += BREAK_INSTR_SIZE;
 
 	return 1;
@@ -441,16 +442,42 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
 	return -1;
 }
 
+int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
+{
+	int err;
+	unsigned int instr;
+	unsigned int *addr = (unsigned int *)bpt->bpt_addr;
+
+	err = probe_kernel_address(addr, instr);
+	if (err)
+		return err;
+
+	err = patch_instruction(addr, BREAK_INSTR);
+	if (err)
+		return -EFAULT;
+
+	*(unsigned int *)bpt->saved_instr = instr;
+
+	return 0;
+}
+
+int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
+{
+	int err;
+	unsigned int instr = *(unsigned int *)bpt->saved_instr;
+	unsigned int *addr = (unsigned int *)bpt->bpt_addr;
+
+	err = patch_instruction(addr, instr);
+	if (err)
+		return -EFAULT;
+
+	return 0;
+}
+
 /*
  * Global data
  */
-struct kgdb_arch arch_kgdb_ops = {
-#ifdef __LITTLE_ENDIAN__
-	.gdb_bpt_instr = {0x08, 0x10, 0x82, 0x7d},
-#else
-	.gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
-#endif
-};
+struct kgdb_arch arch_kgdb_ops;
 
 static int kgdb_not_implemented(struct pt_regs *regs)
 {
-- 
2.13.3


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

* Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-18  9:26 [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() Christophe Leroy
@ 2018-09-18  9:33 ` Christophe Leroy
  2018-09-20  3:02   ` Joe Perches
  2018-10-22  9:37 ` powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() Michael Ellerman
  1 sibling, 1 reply; 9+ messages in thread
From: Christophe Leroy @ 2018-09-18  9:33 UTC (permalink / raw)
  To: Joe Perches, Andy Whitcroft
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev, linux-kernel

On the below patch, checkpatch reports

WARNING: struct kgdb_arch should normally be const
#127: FILE: arch/powerpc/kernel/kgdb.c:480:
+struct kgdb_arch arch_kgdb_ops;

But when I add 'const', I get compilation failure

   CC      arch/powerpc/kernel/kgdb.o
arch/powerpc/kernel/kgdb.c:480:24: error: conflicting type qualifiers 
for ‘arch_kgdb_ops’
  const struct kgdb_arch arch_kgdb_ops;
                         ^
In file included from arch/powerpc/kernel/kgdb.c:18:0:
./include/linux/kgdb.h:284:26: note: previous declaration of 
‘arch_kgdb_ops’ was here
  extern struct kgdb_arch  arch_kgdb_ops;
                           ^
make[1]: *** [arch/powerpc/kernel/kgdb.o] Error 1

Christophe

On 09/18/2018 09:26 AM, Christophe Leroy wrote:
> Generic implementation fails to remove breakpoints after init
> when CONFIG_STRICT_KERNEL_RWX is selected:
> 
> [   13.251285] KGDB: BP remove failed: c001c338
> [   13.259587] kgdbts: ERROR PUT: end of test buffer on 'do_fork_test' line 8 expected OK got $E14#aa
> [   13.268969] KGDB: re-enter exception: ALL breakpoints killed
> [   13.275099] CPU: 0 PID: 1 Comm: init Not tainted 4.18.0-g82bbb913ffd8 #860
> [   13.282836] Call Trace:
> [   13.285313] [c60e1ba0] [c0080ef0] kgdb_handle_exception+0x6f4/0x720 (unreliable)
> [   13.292618] [c60e1c30] [c000e97c] kgdb_handle_breakpoint+0x3c/0x98
> [   13.298709] [c60e1c40] [c000af54] program_check_exception+0x104/0x700
> [   13.305083] [c60e1c60] [c000e45c] ret_from_except_full+0x0/0x4
> [   13.310845] [c60e1d20] [c02a22ac] run_simple_test+0x2b4/0x2d4
> [   13.316532] [c60e1d30] [c0081698] put_packet+0xb8/0x158
> [   13.321694] [c60e1d60] [c00820b4] gdb_serial_stub+0x230/0xc4c
> [   13.327374] [c60e1dc0] [c0080af8] kgdb_handle_exception+0x2fc/0x720
> [   13.333573] [c60e1e50] [c000e928] kgdb_singlestep+0xb4/0xcc
> [   13.339068] [c60e1e70] [c000ae1c] single_step_exception+0x90/0xac
> [   13.345100] [c60e1e80] [c000e45c] ret_from_except_full+0x0/0x4
> [   13.350865] [c60e1f40] [c000e11c] ret_from_syscall+0x0/0x38
> [   13.356346] Kernel panic - not syncing: Recursive entry to debugger
> 
> This patch creates powerpc specific version of
> kgdb_arch_set_breakpoint() and kgdb_arch_remove_breakpoint()
> using patch_instruction()
> 
> Fixes: 1e0fc9d1eb2b ("powerpc/Kconfig: Enable STRICT_KERNEL_RWX for some configs")
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
>   arch/powerpc/include/asm/kgdb.h |  5 ++++-
>   arch/powerpc/kernel/kgdb.c      | 43 +++++++++++++++++++++++++++++++++--------
>   2 files changed, 39 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kgdb.h b/arch/powerpc/include/asm/kgdb.h
> index 9db24e77b9f4..a9e098a3b881 100644
> --- a/arch/powerpc/include/asm/kgdb.h
> +++ b/arch/powerpc/include/asm/kgdb.h
> @@ -26,9 +26,12 @@
>   #define BREAK_INSTR_SIZE	4
>   #define BUFMAX			((NUMREGBYTES * 2) + 512)
>   #define OUTBUFMAX		((NUMREGBYTES * 2) + 512)
> +
> +#define BREAK_INSTR		0x7d821008	/* twge r2, r2 */
> +
>   static inline void arch_kgdb_breakpoint(void)
>   {
> -	asm(".long 0x7d821008"); /* twge r2, r2 */
> +	asm(stringify_in_c(.long BREAK_INSTR));
>   }
>   #define CACHE_FLUSH_IS_SAFE	1
>   #define DBG_MAX_REG_NUM     70
> diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
> index 35e240a0a408..59c578f865aa 100644
> --- a/arch/powerpc/kernel/kgdb.c
> +++ b/arch/powerpc/kernel/kgdb.c
> @@ -24,6 +24,7 @@
>   #include <asm/processor.h>
>   #include <asm/machdep.h>
>   #include <asm/debug.h>
> +#include <asm/code-patching.h>
>   #include <linux/slab.h>
>   
>   /*
> @@ -144,7 +145,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)
>   	if (kgdb_handle_exception(1, SIGTRAP, 0, regs) != 0)
>   		return 0;
>   
> -	if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
> +	if (*(u32 *)regs->nip == BREAK_INSTR)
>   		regs->nip += BREAK_INSTR_SIZE;
>   
>   	return 1;
> @@ -441,16 +442,42 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
>   	return -1;
>   }
>   
> +int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
> +{
> +	int err;
> +	unsigned int instr;
> +	unsigned int *addr = (unsigned int *)bpt->bpt_addr;
> +
> +	err = probe_kernel_address(addr, instr);
> +	if (err)
> +		return err;
> +
> +	err = patch_instruction(addr, BREAK_INSTR);
> +	if (err)
> +		return -EFAULT;
> +
> +	*(unsigned int *)bpt->saved_instr = instr;
> +
> +	return 0;
> +}
> +
> +int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
> +{
> +	int err;
> +	unsigned int instr = *(unsigned int *)bpt->saved_instr;
> +	unsigned int *addr = (unsigned int *)bpt->bpt_addr;
> +
> +	err = patch_instruction(addr, instr);
> +	if (err)
> +		return -EFAULT;
> +
> +	return 0;
> +}
> +
>   /*
>    * Global data
>    */
> -struct kgdb_arch arch_kgdb_ops = {
> -#ifdef __LITTLE_ENDIAN__
> -	.gdb_bpt_instr = {0x08, 0x10, 0x82, 0x7d},
> -#else
> -	.gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
> -#endif
> -};
> +struct kgdb_arch arch_kgdb_ops;
>   
>   static int kgdb_not_implemented(struct pt_regs *regs)
>   {
> 

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

* Re: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-20 13:19       ` Christophe LEROY
@ 2018-09-20  1:23         ` Christophe Leroy
  2018-09-20 20:36           ` Paul Burton
  2018-09-20 14:07         ` Christophe Leroy
  1 sibling, 1 reply; 9+ messages in thread
From: Christophe Leroy @ 2018-09-20  1:23 UTC (permalink / raw)
  To: Michael Ellerman, Joe Perches, Andy Whitcroft, paul.burton, ralf, jhogan
  Cc: Paul Mackerras, linuxppc-dev, linux-kernel, linux-mips

Adding MIPS arch in the loop

On 09/20/2018 01:19 PM, Christophe LEROY wrote:
> 
> 
> Le 20/09/2018 à 15:13, Michael Ellerman a écrit :
>> Joe Perches <joe@perches.com> writes:
>>
>>> On Tue, 2018-09-18 at 09:33 +0000, Christophe Leroy wrote:
>>>> On the below patch, checkpatch reports
>>>>
>>>> WARNING: struct kgdb_arch should normally be const
>>>> #127: FILE: arch/powerpc/kernel/kgdb.c:480:
>>>> +struct kgdb_arch arch_kgdb_ops;
>>>>
>>>> But when I add 'const', I get compilation failure
>>>
>>> So don't add const.
>>>
>>> checkpatch is stupid.  You are not.
>>>
>>> _Always_ take checkpatch bleats with very
>>> large grains of salt.
>>>
>>> Perhaps send a patch to remove kgbd_arch
>>> from scripts/const_structs.checkpatch as
>>> it seems not ever to be const.
>>
>> I think it could/should be const though, it just requires updating all
>> arches.
>>
> 
> Yes I was thinking about doing it, but first thing is to change the way 
> MIPS initialises it:
> 
> 
> struct kgdb_arch arch_kgdb_ops;
> 
> int kgdb_arch_init(void)
> {
>      union mips_instruction insn = {
>          .r_format = {
>              .opcode = spec_op,
>              .func    = break_op,
>          }
>      };
>      memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);
> 
> 
> Can this be done staticaly ?
> 
> Christophe

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

* Re: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-18  9:33 ` Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()) Christophe Leroy
@ 2018-09-20  3:02   ` Joe Perches
  2018-09-20 13:13     ` Michael Ellerman
  0 siblings, 1 reply; 9+ messages in thread
From: Joe Perches @ 2018-09-20  3:02 UTC (permalink / raw)
  To: Christophe Leroy, Andy Whitcroft
  Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev, linux-kernel

On Tue, 2018-09-18 at 09:33 +0000, Christophe Leroy wrote:
> On the below patch, checkpatch reports
> 
> WARNING: struct kgdb_arch should normally be const
> #127: FILE: arch/powerpc/kernel/kgdb.c:480:
> +struct kgdb_arch arch_kgdb_ops;
> 
> But when I add 'const', I get compilation failure

So don't add const.

checkpatch is stupid.  You are not.

_Always_ take checkpatch bleats with very
large grains of salt.

Perhaps send a patch to remove kgbd_arch
from scripts/const_structs.checkpatch as
it seems not ever to be const.


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

* Re: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-20  3:02   ` Joe Perches
@ 2018-09-20 13:13     ` Michael Ellerman
  2018-09-20 13:19       ` Christophe LEROY
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Ellerman @ 2018-09-20 13:13 UTC (permalink / raw)
  To: Joe Perches, Christophe Leroy, Andy Whitcroft
  Cc: Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev, linux-kernel

Joe Perches <joe@perches.com> writes:

> On Tue, 2018-09-18 at 09:33 +0000, Christophe Leroy wrote:
>> On the below patch, checkpatch reports
>> 
>> WARNING: struct kgdb_arch should normally be const
>> #127: FILE: arch/powerpc/kernel/kgdb.c:480:
>> +struct kgdb_arch arch_kgdb_ops;
>> 
>> But when I add 'const', I get compilation failure
>
> So don't add const.
>
> checkpatch is stupid.  You are not.
>
> _Always_ take checkpatch bleats with very
> large grains of salt.
>
> Perhaps send a patch to remove kgbd_arch
> from scripts/const_structs.checkpatch as
> it seems not ever to be const.

I think it could/should be const though, it just requires updating all
arches.

cheers

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

* Re: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-20 13:13     ` Michael Ellerman
@ 2018-09-20 13:19       ` Christophe LEROY
  2018-09-20  1:23         ` Christophe Leroy
  2018-09-20 14:07         ` Christophe Leroy
  0 siblings, 2 replies; 9+ messages in thread
From: Christophe LEROY @ 2018-09-20 13:19 UTC (permalink / raw)
  To: Michael Ellerman, Joe Perches, Andy Whitcroft
  Cc: Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev, linux-kernel



Le 20/09/2018 à 15:13, Michael Ellerman a écrit :
> Joe Perches <joe@perches.com> writes:
> 
>> On Tue, 2018-09-18 at 09:33 +0000, Christophe Leroy wrote:
>>> On the below patch, checkpatch reports
>>>
>>> WARNING: struct kgdb_arch should normally be const
>>> #127: FILE: arch/powerpc/kernel/kgdb.c:480:
>>> +struct kgdb_arch arch_kgdb_ops;
>>>
>>> But when I add 'const', I get compilation failure
>>
>> So don't add const.
>>
>> checkpatch is stupid.  You are not.
>>
>> _Always_ take checkpatch bleats with very
>> large grains of salt.
>>
>> Perhaps send a patch to remove kgbd_arch
>> from scripts/const_structs.checkpatch as
>> it seems not ever to be const.
> 
> I think it could/should be const though, it just requires updating all
> arches.
> 

Yes I was thinking about doing it, but first thing is to change the way 
MIPS initialises it:


struct kgdb_arch arch_kgdb_ops;

int kgdb_arch_init(void)
{
	union mips_instruction insn = {
		.r_format = {
			.opcode = spec_op,
			.func	= break_op,
		}
	};
	memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);


Can this be done staticaly ?

Christophe

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

* Re: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-20 13:19       ` Christophe LEROY
  2018-09-20  1:23         ` Christophe Leroy
@ 2018-09-20 14:07         ` Christophe Leroy
  1 sibling, 0 replies; 9+ messages in thread
From: Christophe Leroy @ 2018-09-20 14:07 UTC (permalink / raw)
  To: Michael Ellerman, Joe Perches, Andy Whitcroft, paul.burton, ralf, jhogan
  Cc: Paul Mackerras, linuxppc-dev, linux-kernel, linux-mips

Adding MIPS arch in the loop

On 09/20/2018 01:19 PM, Christophe LEROY wrote:
> 
> 
> Le 20/09/2018 à 15:13, Michael Ellerman a écrit :
>> Joe Perches <joe@perches.com> writes:
>>
>>> On Tue, 2018-09-18 at 09:33 +0000, Christophe Leroy wrote:
>>>> On the below patch, checkpatch reports
>>>>
>>>> WARNING: struct kgdb_arch should normally be const
>>>> #127: FILE: arch/powerpc/kernel/kgdb.c:480:
>>>> +struct kgdb_arch arch_kgdb_ops;
>>>>
>>>> But when I add 'const', I get compilation failure
>>>
>>> So don't add const.
>>>
>>> checkpatch is stupid.  You are not.
>>>
>>> _Always_ take checkpatch bleats with very
>>> large grains of salt.
>>>
>>> Perhaps send a patch to remove kgbd_arch
>>> from scripts/const_structs.checkpatch as
>>> it seems not ever to be const.
>>
>> I think it could/should be const though, it just requires updating all
>> arches.
>>
> 
> Yes I was thinking about doing it, but first thing is to change the way 
> MIPS initialises it:
> 
> 
> struct kgdb_arch arch_kgdb_ops;
> 
> int kgdb_arch_init(void)
> {
>      union mips_instruction insn = {
>          .r_format = {
>              .opcode = spec_op,
>              .func    = break_op,
>          }
>      };
>      memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);
> 
> 
> Can this be done staticaly ?
> 
> Christophe

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

* Re: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint())
  2018-09-20  1:23         ` Christophe Leroy
@ 2018-09-20 20:36           ` Paul Burton
  0 siblings, 0 replies; 9+ messages in thread
From: Paul Burton @ 2018-09-20 20:36 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Michael Ellerman, Joe Perches, Andy Whitcroft, ralf, jhogan,
	Paul Mackerras, linuxppc-dev, linux-kernel, linux-mips

Hi Christophe,

On Thu, Sep 20, 2018 at 01:23:55AM +0000, Christophe Leroy wrote:
> On 09/20/2018 01:19 PM, Christophe LEROY wrote:
> > Le 20/09/2018 à 15:13, Michael Ellerman a écrit :
> > > Joe Perches <joe@perches.com> writes:
> > > > On Tue, 2018-09-18 at 09:33 +0000, Christophe Leroy wrote:
> > > > > On the below patch, checkpatch reports
> > > > > 
> > > > > WARNING: struct kgdb_arch should normally be const
> > > > > #127: FILE: arch/powerpc/kernel/kgdb.c:480:
> > > > > +struct kgdb_arch arch_kgdb_ops;
> > > > > 
> > > > > But when I add 'const', I get compilation failure
> > > > 
> > > > So don't add const.
> > > > 
> > > > checkpatch is stupid.  You are not.
> > > > 
> > > > _Always_ take checkpatch bleats with very
> > > > large grains of salt.
> > > > 
> > > > Perhaps send a patch to remove kgbd_arch
> > > > from scripts/const_structs.checkpatch as
> > > > it seems not ever to be const.
> > > 
> > > I think it could/should be const though, it just requires updating all
> > > arches.
> > > 
> > 
> > Yes I was thinking about doing it, but first thing is to change the way
> > MIPS initialises it:
> > 
> > struct kgdb_arch arch_kgdb_ops;
> > 
> > int kgdb_arch_init(void)
> > {
> >      union mips_instruction insn = {
> >          .r_format = {
> >              .opcode = spec_op,
> >              .func    = break_op,
> >          }
> >      };
> >      memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);
> > 
> > 
> > Can this be done staticaly ?

Something like this ought to do the trick:

diff --git a/arch/mips/kernel/kgdb.c b/arch/mips/kernel/kgdb.c
index eb6c0d582626..31eff1bec577 100644
--- a/arch/mips/kernel/kgdb.c
+++ b/arch/mips/kernel/kgdb.c
@@ -394,18 +394,16 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
 	return -1;
 }
 
-struct kgdb_arch arch_kgdb_ops;
+struct kgdb_arch arch_kgdb_ops = {
+#ifdef CONFIG_CPU_BIG_ENDIAN
+	.gdb_bpt_instr = { spec_op << 2, 0x00, 0x00, break_op },
+#else
+	.gdb_bpt_instr = { break_op, 0x00, 0x00, spec_op << 2 },
+#endif
+};
 
 int kgdb_arch_init(void)
 {
-	union mips_instruction insn = {
-		.r_format = {
-			.opcode = spec_op,
-			.func	= break_op,
-		}
-	};
-	memcpy(arch_kgdb_ops.gdb_bpt_instr, insn.byte, BREAK_INSTR_SIZE);
-
 	register_die_notifier(&kgdb_notifier);
 
 	return 0;

Thanks,
    Paul

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

* Re: powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()
  2018-09-18  9:26 [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() Christophe Leroy
  2018-09-18  9:33 ` Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()) Christophe Leroy
@ 2018-10-22  9:37 ` Michael Ellerman
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2018-10-22  9:37 UTC (permalink / raw)
  To: Christophe Leroy, Benjamin Herrenschmidt, Paul Mackerras
  Cc: linuxppc-dev, linux-kernel

On Tue, 2018-09-18 at 09:26:03 UTC, Christophe Leroy wrote:
> Generic implementation fails to remove breakpoints after init
> when CONFIG_STRICT_KERNEL_RWX is selected:
> 
> [   13.251285] KGDB: BP remove failed: c001c338
> [   13.259587] kgdbts: ERROR PUT: end of test buffer on 'do_fork_test' line 8 expected OK got $E14#aa
> [   13.268969] KGDB: re-enter exception: ALL breakpoints killed
> [   13.275099] CPU: 0 PID: 1 Comm: init Not tainted 4.18.0-g82bbb913ffd8 #860
> [   13.282836] Call Trace:
> [   13.285313] [c60e1ba0] [c0080ef0] kgdb_handle_exception+0x6f4/0x720 (unreliable)
> [   13.292618] [c60e1c30] [c000e97c] kgdb_handle_breakpoint+0x3c/0x98
> [   13.298709] [c60e1c40] [c000af54] program_check_exception+0x104/0x700
> [   13.305083] [c60e1c60] [c000e45c] ret_from_except_full+0x0/0x4
> [   13.310845] [c60e1d20] [c02a22ac] run_simple_test+0x2b4/0x2d4
> [   13.316532] [c60e1d30] [c0081698] put_packet+0xb8/0x158
> [   13.321694] [c60e1d60] [c00820b4] gdb_serial_stub+0x230/0xc4c
> [   13.327374] [c60e1dc0] [c0080af8] kgdb_handle_exception+0x2fc/0x720
> [   13.333573] [c60e1e50] [c000e928] kgdb_singlestep+0xb4/0xcc
> [   13.339068] [c60e1e70] [c000ae1c] single_step_exception+0x90/0xac
> [   13.345100] [c60e1e80] [c000e45c] ret_from_except_full+0x0/0x4
> [   13.350865] [c60e1f40] [c000e11c] ret_from_syscall+0x0/0x38
> [   13.356346] Kernel panic - not syncing: Recursive entry to debugger
> 
> This patch creates powerpc specific version of
> kgdb_arch_set_breakpoint() and kgdb_arch_remove_breakpoint()
> using patch_instruction()
> 
> Fixes: 1e0fc9d1eb2b ("powerpc/Kconfig: Enable STRICT_KERNEL_RWX for some configs")
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/fb978ca207743badfe7efd9eebe68b

cheers

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

end of thread, other threads:[~2018-10-22  9:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-18  9:26 [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() Christophe Leroy
2018-09-18  9:33 ` Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()) Christophe Leroy
2018-09-20  3:02   ` Joe Perches
2018-09-20 13:13     ` Michael Ellerman
2018-09-20 13:19       ` Christophe LEROY
2018-09-20  1:23         ` Christophe Leroy
2018-09-20 20:36           ` Paul Burton
2018-09-20 14:07         ` Christophe Leroy
2018-10-22  9:37 ` powerpc/kgdb: add kgdb_arch_set/remove_breakpoint() Michael Ellerman

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).