arm64/debug: Fix registers on sleeping tasks
PATCH 1/1 arm64/debug: Fix registers on sleeping tasks
This is the equivalent of commit 001bf455d206 ("ARM: 8428/1: kgdb: Fix registers on sleeping tasks") but for arm64. Nuff said.
---
arch/arm64/kernel/kgdb.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
arch/arm64/kernel/kgdb.c +17 -5
@@ -138,14 +138,26 @@ int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)void sleeping_thread_to_gdb_regs (unsigned long *gdb_regs,struct task_struct *task) { -struct pt_regs *thread_regs; +struct thread_struct *thread = &task->thread; +struct cpu_context *cpu_context = &thread->cpu_context;/* Initialize to zero */ memset ((char *)gdb_regs,0 ,NUMREGBYTES ); - thread_regs =task_pt_regs (task); -memcpy ((void *)gdb_regs, (void *)thread_regs->regs,GP_REG_BYTES ); -/* Special case for PSTATE (check comments in asm/kgdb.h for details) */ -dbg_get_reg (33 , gdb_regs +GP_REG_BYTES , thread_regs); + + gdb_regs[19 ] = cpu_context->x19; + gdb_regs[20 ] = cpu_context->x20; + gdb_regs[21 ] = cpu_context->x21; + gdb_regs[22 ] = cpu_context->x22; + gdb_regs[23 ] = cpu_context->x23; + gdb_regs[24 ] = cpu_context->x24; + gdb_regs[25 ] = cpu_context->x25; + gdb_regs[26 ] = cpu_context->x26; + gdb_regs[27 ] = cpu_context->x27; + gdb_regs[28 ] = cpu_context->x28; + gdb_regs[29 ] = cpu_context->fp; + + gdb_regs[31 ] = cpu_context->sp; + gdb_regs[32 ] = cpu_context->pc; }void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc)
Signature · 1 line
2.16.2.395.g2e18187dfd-goog
Quoted 2 lines · Douglas Anderson
This is the equivalent of commit
001bf455d206("ARM: 8428/1: kgdb: Fix registers on sleeping tasks") but for arm64. Nuff said.
It's a pity that 001bf455d206 doesn't explain *why* past_pt_regs doesn't work.
Anyway, does this mean you're actually using kgdb on arm64? Does the rest of it appear to work?
Will
Quoted 39 lines
arch/arm64/kernel/kgdb.c +17
-5@@ -138,14 +138,26 @@ int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)void sleeping_thread_to_gdb_regs (unsigned long *gdb_regs,struct task_struct *task) { -struct pt_regs *thread_regs; +struct thread_struct *thread = &task->thread; +struct cpu_context *cpu_context = &thread->cpu_context;/* Initialize to zero */ memset ((char *)gdb_regs,0 ,NUMREGBYTES ); - thread_regs =task_pt_regs (task); -memcpy ((void *)gdb_regs, (void *)thread_regs->regs,GP_REG_BYTES ); -/* Special case for PSTATE (check comments in asm/kgdb.h for details) */ -dbg_get_reg (33 , gdb_regs +GP_REG_BYTES , thread_regs); + + gdb_regs[19 ] = cpu_context->x19; + gdb_regs[20 ] = cpu_context->x20; + gdb_regs[21 ] = cpu_context->x21; + gdb_regs[22 ] = cpu_context->x22; + gdb_regs[23 ] = cpu_context->x23; + gdb_regs[24 ] = cpu_context->x24; + gdb_regs[25 ] = cpu_context->x25; + gdb_regs[26 ] = cpu_context->x26; + gdb_regs[27 ] = cpu_context->x27; + gdb_regs[28 ] = cpu_context->x28; + gdb_regs[29 ] = cpu_context->fp; + + gdb_regs[31 ] = cpu_context->sp; + gdb_regs[32 ] = cpu_context->pc; }void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc)Signature · 1 line
2.16.2.395.g2e18187dfd-goog
Mark Rutland
reviewerQuoted 6 lines · Will Deacon
Quoted 2 lines · Douglas Anderson
This is the equivalent of commit
001bf455d206("ARM: 8428/1: kgdb: Fix registers on sleeping tasks") but for arm64. Nuff said.It's a pity that
001bf455d206doesn't explain *why*past_pt_regsdoesn't work.
The task_pt_regs are the userspace regs at the highest address on the kernel stack:
#define task_pt_regs(p) \ ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)
... for kernel tasks, that's meaningless, and for user tasks, that won't correspond to kernel state.
Quoted 11 lines
arch/arm64/kernel/kgdb.c int dbg_set_reg(int regno, void *mem, struct pt_regs *regs) · line 142
Quoted 11 lines
arch/arm64/kernel/kgdb.c +2
-1@@ -138,14 +138,26 @@ int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)void sleeping_thread_to_gdb_regs (unsigned long *gdb_regs,struct task_struct *task) { -struct pt_regs *thread_regs; +struct thread_struct *thread = &task->thread; +struct cpu_context *cpu_context = &thread->cpu_context;
We can do this in one go:
struct cpu_context *cpu_context = &task->thread.cpu_context;
... since we don't need the thread variable otherwise.
Quoted 14 lines
Quoted 14 lines
arch/arm64/kernel/kgdb.c +7
-4/* Initialize to zero */ memset ((char *)gdb_regs,0 ,NUMREGBYTES ); - thread_regs =task_pt_regs (task); -memcpy ((void *)gdb_regs, (void *)thread_regs->regs,GP_REG_BYTES ); -/* Special case for PSTATE (check comments in asm/kgdb.h for details) */ -dbg_get_reg (33 , gdb_regs +GP_REG_BYTES , thread_regs); + + gdb_regs[19 ] = cpu_context->x19; + gdb_regs[20 ] = cpu_context->x20; + gdb_regs[21 ] = cpu_context->x21; + gdb_regs[22 ] = cpu_context->x22; + gdb_regs[23 ] = cpu_context->x23; + gdb_regs[24 ] = cpu_context->x24;
Quoted 8 lines
arch/arm64/kernel/kgdb.c int dbg_set_reg(int regno, void *mem, struct pt_regs *regs) · line 160
Quoted 8 lines
arch/arm64/kernel/kgdb.c +8
-0+ gdb_regs[25 ] = cpu_context->x25; + gdb_regs[26 ] = cpu_context->x26; + gdb_regs[27 ] = cpu_context->x27; + gdb_regs[28 ] = cpu_context->x28; + gdb_regs[29 ] = cpu_context->fp; + + gdb_regs[31 ] = cpu_context->sp; + gdb_regs[32 ] = cpu_context->pc;
Are the other reg fields initialised elsewhere?
We might want to zero them here.
Thanks,
Mark.
Hi,
Quoted 31 lines · Mark Rutland
Quoted 6 lines · Will Deacon
Quoted 2 lines · Douglas Anderson
This is the equivalent of commit
001bf455d206("ARM: 8428/1: kgdb: Fix registers on sleeping tasks") but for arm64. Nuff said.It's a pity that
001bf455d206doesn't explain *why*past_pt_regsdoesn't work.The
task_pt_regsare the userspace regs at the highest address on the kernel stack:#define task_pt_regs(p) \ ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)... for kernel tasks, that's meaningless, and for user tasks, that won't correspond to kernel state.
Quoted 11 lines
arch/arm64/kernel/kgdb.c int dbg_set_reg(int regno, void *mem, struct pt_regs *regs) · line 142
Quoted 11 lines
arch/arm64/kernel/kgdb.c +2
-1@@ -138,14 +138,26 @@ int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)void sleeping_thread_to_gdb_regs (unsigned long *gdb_regs,struct task_struct *task) { -struct pt_regs *thread_regs; +struct thread_struct *thread = &task->thread; +struct cpu_context *cpu_context = &thread->cpu_context;We can do this in one go:
Quoted 3 lines
struct cpu_context *cpu_context = &task->thread.cpu_context;... since we don't need the thread variable otherwise.
Sure, I can spin it that way if it makes you happy.
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
arch/arm64/kernel/kgdb.c +7
-4/* Initialize to zero */ memset ((char *)gdb_regs,0 ,NUMREGBYTES ); - thread_regs =task_pt_regs (task); -memcpy ((void *)gdb_regs, (void *)thread_regs->regs,GP_REG_BYTES ); -/* Special case for PSTATE (check comments in asm/kgdb.h for details) */ -dbg_get_reg (33 , gdb_regs +GP_REG_BYTES , thread_regs); + + gdb_regs[19 ] = cpu_context->x19; + gdb_regs[20 ] = cpu_context->x20; + gdb_regs[21 ] = cpu_context->x21; + gdb_regs[22 ] = cpu_context->x22; + gdb_regs[23 ] = cpu_context->x23; + gdb_regs[24 ] = cpu_context->x24;Quoted 8 lines
arch/arm64/kernel/kgdb.c int dbg_set_reg(int regno, void *mem, struct pt_regs *regs) · line 160
Quoted 8 lines
arch/arm64/kernel/kgdb.c +8
-0+ gdb_regs[25 ] = cpu_context->x25; + gdb_regs[26 ] = cpu_context->x26; + gdb_regs[27 ] = cpu_context->x27; + gdb_regs[28 ] = cpu_context->x28; + gdb_regs[29 ] = cpu_context->fp; + + gdb_regs[31 ] = cpu_context->sp; + gdb_regs[32 ] = cpu_context->pc;Are the other reg fields initialised elsewhere?
Quoted 1 line
We might want to zero them here.
Isn't that covered by the the "/* Initialize to zero */" comment and and "memset((char *)gdb_regs, 0, NUMREGBYTES);"
...or are you thinking of initting something else to zero?
-Doug
Mark Rutland
reviewerQuoted 30 lines · Doug Anderson
Hi,
Quoted 27 lines · Mark Rutland
Quoted 15 lines · Will Deacon
Quoted 13 lines · Douglas Anderson
/* Initialize to zero */ memset((char *)gdb_regs, 0, NUMREGBYTES);arch/arm64/kernel/kgdb.c +7
-4- thread_regs =task_pt_regs (task); -memcpy ((void *)gdb_regs, (void *)thread_regs->regs,GP_REG_BYTES ); -/* Special case for PSTATE (check comments in asm/kgdb.h for details) */ -dbg_get_reg (33 , gdb_regs +GP_REG_BYTES , thread_regs); + + gdb_regs[19 ] = cpu_context->x19; + gdb_regs[20 ] = cpu_context->x20; + gdb_regs[21 ] = cpu_context->x21; + gdb_regs[22 ] = cpu_context->x22; + gdb_regs[23 ] = cpu_context->x23; + gdb_regs[24 ] = cpu_context->x24;Quoted 8 lines
arch/arm64/kernel/kgdb.c int dbg_set_reg(int regno, void *mem, struct pt_regs *regs) · line 160
Quoted 8 lines
arch/arm64/kernel/kgdb.c +8
-0+ gdb_regs[25 ] = cpu_context->x25; + gdb_regs[26 ] = cpu_context->x26; + gdb_regs[27 ] = cpu_context->x27; + gdb_regs[28 ] = cpu_context->x28; + gdb_regs[29 ] = cpu_context->fp; + + gdb_regs[31 ] = cpu_context->sp; + gdb_regs[32 ] = cpu_context->pc;Are the other reg fields initialised elsewhere?
Quoted 4 lines
Quoted 1 line
We might want to zero them here.
Isn't that covered by the the "/* Initialize to zero */" comment and and "
memset((char *)gdb_regs, 0, NUMREGBYTES);"
I'd misread the patch and thought that was part of the deleted lines.
That looks fine, then.
Mark.
Hi,
Quoted 6 lines · Will Deacon
Quoted 2 lines · Douglas Anderson
This is the equivalent of commit
001bf455d206("ARM: 8428/1: kgdb: Fix registers on sleeping tasks") but for arm64. Nuff said.It's a pity that
001bf455d206doesn't explain *why*past_pt_regsdoesn't work.
Ah, sorry. I can add that to the description but Mark Rutland also explained it. task_pt_regs are the userspace registers. That's not what kgdb needs.
Quoted 2 lines
Anyway, does this mean you're actually using kgdb on arm64? Does the rest of it appear to work?
Yeah, I've been using it for years. I had this patch on my list to upstream but it conflicted with commit 0d15ef677839 ("arm64: kgdb:
Match pstate size with gdbserver protocol") and I never had time to figure out if that mattered, so it's been sitting at
http://crosreview.com/371942 forever.
NOTE: in general I haven't been using single step and breakpoints since those have always been a bit iffy on serial kgdb and especially since we have read-only text on our system, but maybe I'll try that now that I'm running with a newer kernel.
-Doug