From: dave.long@linaro.org (David Long)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 1/7] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature
Date: Mon, 29 Jun 2015 14:36:45 -0400 [thread overview]
Message-ID: <5591903D.7090108@linaro.org> (raw)
In-Reply-To: <CAPvkgC37gFJjU__jubnJ1xJA_9ktCgBJ3wzWMAZN=93rvu3+Ew@mail.gmail.com>
On 06/29/15 13:23, Steve Capper wrote:
> On 15 June 2015 at 20:07, David Long <dave.long@linaro.org> wrote:
>> From: "David A. Long" <dave.long@linaro.org>
>>
>> Add HAVE_REGS_AND_STACK_ACCESS_API feature for arm64.
>>
>> Signed-off-by: David A. Long <dave.long@linaro.org>
>> ---
>> arch/arm64/Kconfig | 1 +
>> arch/arm64/include/asm/ptrace.h | 25 +++++++++++++
>> arch/arm64/kernel/ptrace.c | 77 +++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 103 insertions(+)
>>
>> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
>> index 7796af4..966091f 100644
>> --- a/arch/arm64/Kconfig
>> +++ b/arch/arm64/Kconfig
>> @@ -68,6 +68,7 @@ config ARM64
>> select HAVE_PERF_EVENTS
>> select HAVE_PERF_REGS
>> select HAVE_PERF_USER_STACK_DUMP
>> + select HAVE_REGS_AND_STACK_ACCESS_API
>> select HAVE_RCU_TABLE_FREE
>> select HAVE_SYSCALL_TRACEPOINTS
>> select IRQ_DOMAIN
>> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
>> index d6dd9fd..8f440e9 100644
>> --- a/arch/arm64/include/asm/ptrace.h
>> +++ b/arch/arm64/include/asm/ptrace.h
>> @@ -118,6 +118,8 @@ struct pt_regs {
>> u64 syscallno;
>> };
>>
>> +#define MAX_REG_OFFSET (sizeof(struct user_pt_regs) - sizeof(u64))
>> +
>> #define arch_has_single_step() (1)
>>
>> #ifdef CONFIG_COMPAT
>> @@ -146,6 +148,29 @@ struct pt_regs {
>> #define user_stack_pointer(regs) \
>> (!compat_user_mode(regs) ? (regs)->sp : (regs)->compat_sp)
>>
>> +/**
>> + * regs_get_register() - get register value from its offset
>> + * @regs: pt_regs from which register value is gotten
>> + * @offset: offset number of the register.
>> + *
>> + * regs_get_register returns the value of a register whose offset from @regs.
>> + * The @offset is the offset of the register in struct pt_regs.
>> + * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
>> + */
>> +static inline u64 regs_get_register(struct pt_regs *regs,
>> + unsigned int offset)
>> +{
>> + if (unlikely(offset > MAX_REG_OFFSET))
>> + return 0;
>> + return *(u64 *)((u64)regs + offset);
>
> Why not:
> return regs->regs[offset];
>
This would not be correct. The offset is a byte offset and your code
would index eight times that amount into the structure. The offset
needs to remain a byte offset so architecture-independent code does not
need to know the architecture-specific layout of the structure.
>> +}
>> +
>> +/* Valid only for Kernel mode traps. */
>> +static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
>> +{
>> + return regs->sp;
>> +}
>> +
>> static inline unsigned long regs_return_value(struct pt_regs *regs)
>> {
>> return regs->regs[0];
>> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
>> index d882b83..f6199a5 100644
>> --- a/arch/arm64/kernel/ptrace.c
>> +++ b/arch/arm64/kernel/ptrace.c
>> @@ -48,6 +48,83 @@
>> #define CREATE_TRACE_POINTS
>> #include <trace/events/syscalls.h>
>>
>> +#define ARM_pstate pstate
>> +#define ARM_pc pc
>> +#define ARM_sp sp
>> +#define ARM_x30 regs[30]
>> +#define ARM_x29 regs[29]
>> +#define ARM_x28 regs[28]
>> +#define ARM_x27 regs[27]
>> +#define ARM_x26 regs[26]
>> +#define ARM_x25 regs[25]
>> +#define ARM_x24 regs[24]
>> +#define ARM_x23 regs[23]
>> +#define ARM_x22 regs[22]
>> +#define ARM_x21 regs[21]
>> +#define ARM_x20 regs[20]
>> +#define ARM_x19 regs[19]
>> +#define ARM_x18 regs[18]
>> +#define ARM_x17 regs[17]
>> +#define ARM_x16 regs[16]
>> +#define ARM_x15 regs[15]
>> +#define ARM_x14 regs[14]
>> +#define ARM_x13 regs[13]
>> +#define ARM_x12 regs[12]
>> +#define ARM_x11 regs[11]
>> +#define ARM_x10 regs[10]
>> +#define ARM_x9 regs[9]
>> +#define ARM_x8 regs[8]
>> +#define ARM_x7 regs[7]
>> +#define ARM_x6 regs[6]
>> +#define ARM_x5 regs[5]
>> +#define ARM_x4 regs[4]
>> +#define ARM_x3 regs[3]
>> +#define ARM_x2 regs[2]
>> +#define ARM_x1 regs[1]
>> +#define ARM_x0 regs[0]
>> +
>> +#define REG_OFFSET_NAME(r) \
>> + {.name = #r, .offset = offsetof(struct pt_regs, ARM_##r)}
>> +#define REG_OFFSET_END {.name = NULL, .offset = 0}
>> +
>> +const struct pt_regs_offset regs_offset_table[] = {
>> + REG_OFFSET_NAME(x0),
>> + REG_OFFSET_NAME(x1),
>> + REG_OFFSET_NAME(x2),
>> + REG_OFFSET_NAME(x3),
>> + REG_OFFSET_NAME(x4),
>> + REG_OFFSET_NAME(x5),
>> + REG_OFFSET_NAME(x6),
>> + REG_OFFSET_NAME(x7),
>> + REG_OFFSET_NAME(x8),
>> + REG_OFFSET_NAME(x9),
>> + REG_OFFSET_NAME(x10),
>> + REG_OFFSET_NAME(x11),
>> + REG_OFFSET_NAME(x12),
>> + REG_OFFSET_NAME(x13),
>> + REG_OFFSET_NAME(x14),
>> + REG_OFFSET_NAME(x15),
>> + REG_OFFSET_NAME(x16),
>> + REG_OFFSET_NAME(x17),
>> + REG_OFFSET_NAME(x18),
>> + REG_OFFSET_NAME(x19),
>> + REG_OFFSET_NAME(x20),
>> + REG_OFFSET_NAME(x21),
>> + REG_OFFSET_NAME(x22),
>> + REG_OFFSET_NAME(x23),
>> + REG_OFFSET_NAME(x24),
>> + REG_OFFSET_NAME(x25),
>> + REG_OFFSET_NAME(x26),
>> + REG_OFFSET_NAME(x27),
>> + REG_OFFSET_NAME(x28),
>> + REG_OFFSET_NAME(x29),
>> + REG_OFFSET_NAME(x30),
>> + REG_OFFSET_NAME(sp),
>> + REG_OFFSET_NAME(pc),
>> + REG_OFFSET_NAME(pstate),
>> + REG_OFFSET_END,
>> +};
>> +
>> /*
>> * TODO: does not yet catch signals sent when the child dies.
>> * in exit.c or in signal.c.
>> --
>> 1.8.1.2
>>
Thanks,
-dl
next prev parent reply other threads:[~2015-06-29 18:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-15 19:07 [PATCH v7 0/7] arm64: Add kernel probes (kprobes) support David Long
2015-06-15 19:07 ` [PATCH v7 1/7] arm64: Add HAVE_REGS_AND_STACK_ACCESS_API feature David Long
2015-06-29 17:23 ` Steve Capper
2015-06-29 18:36 ` David Long [this message]
2015-06-30 10:51 ` Steve Capper
2015-06-15 19:07 ` [PATCH v7 2/7] arm64: Add more test functions to insn.c David Long
2015-06-29 17:23 ` Steve Capper
2015-06-30 0:06 ` David Long
2015-06-15 19:07 ` [PATCH v7 3/7] arm64: Kprobes with single stepping support David Long
2015-06-29 17:24 ` Steve Capper
2015-07-02 22:36 ` David Long
2015-06-15 19:07 ` [PATCH v7 4/7] arm64: kprobes instruction simulation support David Long
2015-06-29 17:25 ` Steve Capper
2015-06-15 19:07 ` [PATCH v7 5/7] arm64: Add trampoline code for kretprobes David Long
2015-06-16 15:09 ` William Cohen
2015-06-17 18:37 ` David Long
2015-06-29 17:25 ` Steve Capper
2015-06-29 18:16 ` William Cohen
2015-06-30 11:04 ` Steve Capper
2015-06-30 13:41 ` William Cohen
2015-07-31 14:15 ` Catalin Marinas
2015-06-15 19:07 ` [PATCH v7 6/7] arm64: Add kernel return probes support (kretprobes) David Long
2015-06-15 19:07 ` [PATCH v7 7/7] kprobes: Add arm64 case in kprobe example module David Long
2015-06-17 14:18 ` [PATCH v7 0/7] arm64: Add kernel probes (kprobes) support Masami Hiramatsu
2015-06-17 18:51 ` David Long
2015-06-29 17:23 ` Steve Capper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5591903D.7090108@linaro.org \
--to=dave.long@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).