aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2012-08-25 15:19:11 +0100
committerCatalin Marinas <catalin.marinas@arm.com>2012-09-07 15:54:39 +0100
commit6c875649e098d66589e658058109a9bcf688e0e3 (patch)
tree9e5f374c9b279a8224271075ff677eb910a4598a
parent206de37f316dbf133618f9fcf4eb728745ed44f9 (diff)
downloadlinux-aarch64-6c875649e098d66589e658058109a9bcf688e0e3.tar.gz
arm64: ptrace: use regsets for hardware debug registers
This patch rewrites the ptrace interface to hw_breakpoint so that it uses regsets rather than a homebrew virtual register file. Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
-rw-r--r--arch/arm64/include/asm/processor.h3
-rw-r--r--arch/arm64/include/asm/ptrace.h10
-rw-r--r--arch/arm64/kernel/ptrace.c640
-rw-r--r--include/linux/elf.h2
4 files changed, 465 insertions, 190 deletions
diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
index 4a6f73cb93f..39a208a392f 100644
--- a/arch/arm64/include/asm/processor.h
+++ b/arch/arm64/include/asm/processor.h
@@ -52,7 +52,8 @@ struct debug_info {
int bps_disabled;
int wps_disabled;
/* Hardware breakpoints pinned to this task. */
- struct perf_event *hbp[ARM_MAX_HBP_SLOTS];
+ struct perf_event *hbp_break[ARM_MAX_BRP];
+ struct perf_event *hbp_watch[ARM_MAX_WRP];
};
struct cpu_context {
diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
index f4e63d46620..b0a2e1f441f 100644
--- a/arch/arm64/include/asm/ptrace.h
+++ b/arch/arm64/include/asm/ptrace.h
@@ -86,7 +86,7 @@
#ifndef __ASSEMBLY__
/*
- * User structures for general purpose and floating point registers.
+ * User structures for general purpose, floating point and debug registers.
*/
struct user_pt_regs {
__u64 regs[31];
@@ -101,6 +101,14 @@ struct user_fpsimd_state {
__u32 fpcr;
};
+struct user_hwdebug_state {
+ __u32 dbg_info;
+ struct {
+ __u64 addr;
+ __u32 ctrl;
+ } dbg_regs[16];
+};
+
#ifdef __KERNEL__
/* sizeof(struct user) for AArch32 */
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 97932e8349f..9e1e2004d16 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -58,12 +58,12 @@ void ptrace_disable(struct task_struct *child)
*/
static int ptrace_break(struct pt_regs *regs)
{
- siginfo_t info;
-
- info.si_signo = SIGTRAP;
- info.si_errno = 0;
- info.si_code = TRAP_BRKPT;
- info.si_addr = (void __user *)instruction_pointer(regs);
+ siginfo_t info = {
+ .si_signo = SIGTRAP,
+ .si_errno = 0,
+ .si_code = TRAP_BRKPT,
+ .si_addr = (void __user *)instruction_pointer(regs),
+ };
force_sig_info(SIGTRAP, &info, current);
return 0;
@@ -77,31 +77,6 @@ static int arm64_break_trap(unsigned long addr, unsigned int esr,
#ifdef CONFIG_HAVE_HW_BREAKPOINT
/*
- * Convert a virtual register number into an index for a thread_info
- * breakpoint array. Breakpoints are identified using positive numbers
- * whilst watchpoints are negative. The registers are laid out as pairs
- * of (address, control), each pair mapping to a unique hw_breakpoint struct.
- * Register 0 is reserved for describing resource information.
- */
-static int ptrace_hbp_num_to_idx(long num)
-{
- if (num < 0)
- num = (ARM_MAX_BRP << 1) - num;
- return (num - 1) >> 1;
-}
-
-/*
- * Returns the virtual register number for the address of the
- * breakpoint at index idx.
- */
-static long ptrace_hbp_idx_to_num(int idx)
-{
- long mid = ARM_MAX_BRP << 1;
- long num = (idx << 1) + 1;
- return num > mid ? mid - num : num;
-}
-
-/*
* Handle hitting a HW-breakpoint.
*/
static void ptrace_hbptriggered(struct perf_event *bp,
@@ -109,21 +84,34 @@ static void ptrace_hbptriggered(struct perf_event *bp,
struct pt_regs *regs)
{
struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp);
- long num;
+ siginfo_t info = {
+ .si_signo = SIGTRAP,
+ .si_errno = 0,
+ .si_code = TRAP_HWBKPT,
+ .si_addr = (void __user *)(bkpt->trigger),
+ };
+
+#ifdef CONFIG_AARCH32_EMULATION
int i;
- siginfo_t info;
- for (i = 0; i < ARM_MAX_HBP_SLOTS; ++i)
- if (current->thread.debug.hbp[i] == bp)
- break;
-
- num = (i == ARM_MAX_HBP_SLOTS) ? 0 : ptrace_hbp_idx_to_num(i);
+ if (!is_compat_task())
+ goto send_sig;
- info.si_signo = SIGTRAP;
- info.si_errno = (int)num;
- info.si_code = TRAP_HWBKPT;
- info.si_addr = (void __user *)(bkpt->trigger);
+ for (i = 0; i < ARM_MAX_BRP; ++i) {
+ if (current->thread.debug.hbp_break[i] == bp) {
+ info.si_errno = (i << 1) + 1;
+ break;
+ }
+ }
+ for (i = ARM_MAX_BRP; i < ARM_MAX_HBP_SLOTS && !bp; ++i) {
+ if (current->thread.debug.hbp_watch[i] == bp) {
+ info.si_errno = -((i << 1) + 1);
+ break;
+ }
+ }
+send_sig:
+#endif
force_sig_info(SIGTRAP, &info, current);
}
@@ -136,43 +124,89 @@ void flush_ptrace_hw_breakpoint(struct task_struct *tsk)
int i;
struct thread_struct *t = &tsk->thread;
- for (i = 0; i < ARM_MAX_HBP_SLOTS; i++) {
- if (t->debug.hbp[i]) {
- unregister_hw_breakpoint(t->debug.hbp[i]);
- t->debug.hbp[i] = NULL;
+ for (i = 0; i < ARM_MAX_BRP; i++) {
+ if (t->debug.hbp_break[i]) {
+ unregister_hw_breakpoint(t->debug.hbp_break[i]);
+ t->debug.hbp_break[i] = NULL;
+ }
+ }
+
+ for (i = 0; i < ARM_MAX_WRP; i++) {
+ if (t->debug.hbp_watch[i]) {
+ unregister_hw_breakpoint(t->debug.hbp_watch[i]);
+ t->debug.hbp_watch[i] = NULL;
}
}
}
-void ptrace_hw_copy_thread(struct task_struct *task)
+void ptrace_hw_copy_thread(struct task_struct *tsk)
{
- memset(&task->thread.debug, 0, sizeof(struct debug_info));
+ memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
}
-static u32 ptrace_get_hbp_resource_info(void)
+static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx)
{
- u8 num_brps, num_wrps, debug_arch, wp_len;
- u32 reg = 0;
+ struct perf_event *bp = ERR_PTR(-EINVAL);
+
+ switch (note_type) {
+ case NT_ARM_HW_BREAK:
+ if (idx < ARM_MAX_BRP)
+ bp = tsk->thread.debug.hbp_break[idx];
+ break;
+ case NT_ARM_HW_WATCH:
+ if (idx < ARM_MAX_WRP)
+ bp = tsk->thread.debug.hbp_watch[idx];
+ break;
+ }
- num_brps = hw_breakpoint_slots(TYPE_INST);
- num_wrps = hw_breakpoint_slots(TYPE_DATA);
+ return bp;
+}
- debug_arch = debug_monitors_arch();
- wp_len = 8; /* Reserved on AArch64 */
- reg |= debug_arch;
- reg <<= 8;
- reg |= wp_len;
- reg <<= 8;
- reg |= num_wrps;
- reg <<= 8;
- reg |= num_brps;
+static int ptrace_hbp_set_event(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx,
+ struct perf_event *bp)
+{
+ int err = -EINVAL;
+
+ switch (note_type) {
+ case NT_ARM_HW_BREAK:
+ if (idx < ARM_MAX_BRP) {
+ tsk->thread.debug.hbp_break[idx] = bp;
+ err = 0;
+ }
+ break;
+ case NT_ARM_HW_WATCH:
+ if (idx < ARM_MAX_WRP) {
+ tsk->thread.debug.hbp_watch[idx] = bp;
+ err = 0;
+ }
+ break;
+ }
- return reg;
+ return err;
}
-static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type)
+static struct perf_event *ptrace_hbp_create(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx)
{
+ struct perf_event *bp;
struct perf_event_attr attr;
+ int err, type;
+
+ switch (note_type) {
+ case NT_ARM_HW_BREAK:
+ type = HW_BREAKPOINT_X;
+ break;
+ case NT_ARM_HW_WATCH:
+ type = HW_BREAKPOINT_RW;
+ break;
+ default:
+ return ERR_PTR(-EINVAL);
+ }
ptrace_breakpoint_init(&attr);
@@ -185,108 +219,245 @@ static struct perf_event *ptrace_hbp_create(struct task_struct *tsk, int type)
attr.bp_type = type;
attr.disabled = 1;
- return register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL,
- tsk);
+ bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk);
+ if (IS_ERR(bp))
+ return bp;
+
+ err = ptrace_hbp_set_event(note_type, tsk, idx, bp);
+ if (err)
+ return ERR_PTR(err);
+
+ return bp;
}
-static int ptrace_gethbpregs(struct task_struct *tsk, long num,
- unsigned long __user *data)
+static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type,
+ struct arch_hw_breakpoint_ctrl ctrl,
+ struct perf_event_attr *attr)
{
- u64 addr_reg;
- u32 ctrl_reg;
- int idx, ret = 0;
- struct perf_event *bp;
- struct arch_hw_breakpoint_ctrl arch_ctrl;
+ int err, len, type;
- if (num == 0) {
- ctrl_reg = ptrace_get_hbp_resource_info();
- if (put_user(ctrl_reg, (u32 __user *)data))
- ret = -EFAULT;
- } else {
- idx = ptrace_hbp_num_to_idx(num);
- if (idx < 0 || idx >= ARM_MAX_HBP_SLOTS)
+ err = arch_bp_generic_fields(ctrl, &len, &type);
+ if (err)
+ return err;
+
+ switch (note_type) {
+ case NT_ARM_HW_BREAK:
+ if ((type & HW_BREAKPOINT_X) != type)
+ return -EINVAL;
+ break;
+ case NT_ARM_HW_WATCH:
+ if ((type & HW_BREAKPOINT_RW) != type)
return -EINVAL;
+ break;
+ default:
+ return -EINVAL;
+ }
- bp = tsk->thread.debug.hbp[idx];
- arch_ctrl = counter_arch_bp(bp)->ctrl;
+ attr->bp_len = len;
+ attr->bp_type = type;
+ attr->disabled = !ctrl.enabled;
- if (is_compat_task()) {
- /*
- * Fix up the len because we may have adjusted
- * it to compensate for an unaligned address.
- */
- while (!(arch_ctrl.len & 0x1))
- arch_ctrl.len >>= 1;
- }
+ return 0;
+}
- if (num & 0x1) {
- addr_reg = bp ? bp->attr.bp_addr : 0;
- if (put_user(addr_reg, data))
- ret = -EFAULT;
- } else {
- ctrl_reg = bp ? encode_ctrl_reg(arch_ctrl) : 0;
- if (put_user(ctrl_reg, (u32 __user *)data))
- ret = -EFAULT;
- }
+static int ptrace_hbp_get_resource_info(unsigned int note_type, u32 *info)
+{
+ u8 num;
+ u32 reg = 0;
+
+ switch (note_type) {
+ case NT_ARM_HW_BREAK:
+ num = hw_breakpoint_slots(TYPE_INST);
+ break;
+ case NT_ARM_HW_WATCH:
+ num = hw_breakpoint_slots(TYPE_DATA);
+ break;
+ default:
+ return -EINVAL;
}
- return ret;
+ reg |= debug_monitors_arch();
+ reg <<= 8;
+ reg |= num;
+
+ *info = reg;
+ return 0;
}
-static int ptrace_sethbpregs(struct task_struct *tsk, long num,
- unsigned long __user *data)
+static int ptrace_hbp_get_ctrl(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx,
+ u32 *ctrl)
{
- int idx, gen_len, gen_type, implied_type, ret;
- u64 user_addr;
- u32 user_ctrl;
+ struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
+
+ if (IS_ERR(bp))
+ return PTR_ERR(bp);
+
+ *ctrl = bp ? encode_ctrl_reg(counter_arch_bp(bp)->ctrl) : 0;
+ return 0;
+}
+
+static int ptrace_hbp_get_addr(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx,
+ u64 *addr)
+{
+ struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
+
+ if (IS_ERR(bp))
+ return PTR_ERR(bp);
+
+ *addr = bp ? bp->attr.bp_addr : 0;
+ return 0;
+}
+
+static struct perf_event *ptrace_hbp_get_initialised_bp(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx)
+{
+ struct perf_event *bp = ptrace_hbp_get_event(note_type, tsk, idx);
+
+ if (!bp)
+ bp = ptrace_hbp_create(note_type, tsk, idx);
+
+ return bp;
+}
+
+static int ptrace_hbp_set_ctrl(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx,
+ u32 uctrl)
+{
+ int err;
struct perf_event *bp;
+ struct perf_event_attr attr;
struct arch_hw_breakpoint_ctrl ctrl;
+
+ bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
+ if (IS_ERR(bp)) {
+ err = PTR_ERR(bp);
+ return err;
+ }
+
+ attr = bp->attr;
+ decode_ctrl_reg(uctrl, &ctrl);
+ err = ptrace_hbp_fill_attr_ctrl(note_type, ctrl, &attr);
+ if (err)
+ return err;
+
+ return modify_user_hw_breakpoint(bp, &attr);
+}
+
+static int ptrace_hbp_set_addr(unsigned int note_type,
+ struct task_struct *tsk,
+ unsigned long idx,
+ u64 addr)
+{
+ int err;
+ struct perf_event *bp;
struct perf_event_attr attr;
- if (num == 0)
- return 0;
- else if (num < 0)
- implied_type = HW_BREAKPOINT_RW;
- else
- implied_type = HW_BREAKPOINT_X;
-
- idx = ptrace_hbp_num_to_idx(num);
- if (idx < 0 || idx >= ARM_MAX_HBP_SLOTS)
- return -EFAULT;
-
- bp = tsk->thread.debug.hbp[idx];
- if (!bp) {
- bp = ptrace_hbp_create(tsk, implied_type);
- if (IS_ERR(bp))
- return PTR_ERR(bp);
- tsk->thread.debug.hbp[idx] = bp;
+ bp = ptrace_hbp_get_initialised_bp(note_type, tsk, idx);
+ if (IS_ERR(bp)) {
+ err = PTR_ERR(bp);
+ return err;
}
attr = bp->attr;
+ attr.bp_addr = addr;
+ err = modify_user_hw_breakpoint(bp, &attr);
+ return err;
+}
- if (num & 0x1) {
- /* Address */
- if (get_user(user_addr, data))
- return -EFAULT;
- attr.bp_addr = user_addr;
- } else {
- /* Control */
- if (get_user(user_ctrl, (u32 __user *)data))
- return -EFAULT;
- decode_ctrl_reg(user_ctrl, &ctrl);
- ret = arch_bp_generic_fields(ctrl, &gen_len, &gen_type);
+#define PTRACE_HBP_ADDR_SZ sizeof(u64)
+#define PTRACE_HBP_CTRL_SZ sizeof(u32)
+#define PTRACE_HBP_REG_OFF sizeof(u32)
+
+static int hw_break_get(struct task_struct *target,
+ const struct user_regset *regset,
+ unsigned int pos, unsigned int count,
+ void *kbuf, void __user *ubuf)
+{
+ unsigned int note_type = regset->core_note_type;
+ int ret, idx = 0, offset = PTRACE_HBP_REG_OFF, limit;
+ u32 info, ctrl;
+ u64 addr;
+
+ /* Resource info */
+ ret = ptrace_hbp_get_resource_info(note_type, &info);
+ if (ret)
+ return ret;
+
+ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &info, 0, 4);
+ if (ret)
+ return ret;
+
+ /* (address, ctrl) registers */
+ limit = regset->n * regset->size;
+ while (count && offset < limit) {
+ ret = ptrace_hbp_get_addr(note_type, target, idx, &addr);
if (ret)
return ret;
+ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &addr,
+ offset, offset + PTRACE_HBP_ADDR_SZ);
+ if (ret)
+ return ret;
+ offset += PTRACE_HBP_ADDR_SZ;
- if ((gen_type & implied_type) != gen_type)
- return -EINVAL;
+ ret = ptrace_hbp_get_ctrl(note_type, target, idx, &ctrl);
+ if (ret)
+ return ret;
+ ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &ctrl,
+ offset, offset + PTRACE_HBP_CTRL_SZ);
+ if (ret)
+ return ret;
+ offset += PTRACE_HBP_CTRL_SZ;
+ idx++;
+ }
+
+ return 0;
+}
+
+static int hw_break_set(struct task_struct *target,
+ const struct user_regset *regset,
+ unsigned int pos, unsigned int count,
+ const void *kbuf, const void __user *ubuf)
+{
+ unsigned int note_type = regset->core_note_type;
+ int ret, idx = 0, offset = PTRACE_HBP_REG_OFF, limit;
+ u32 ctrl;
+ u64 addr;
+
+ /* Resource info */
+ ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, 0, 4);
+ if (ret)
+ return ret;
- attr.bp_len = gen_len;
- attr.bp_type = gen_type;
- attr.disabled = !ctrl.enabled;
+ /* (address, ctrl) registers */
+ limit = regset->n * regset->size;
+ while (count && offset < limit) {
+ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &addr,
+ offset, offset + PTRACE_HBP_ADDR_SZ);
+ if (ret)
+ return ret;
+ ret = ptrace_hbp_set_addr(note_type, target, idx, addr);
+ if (ret)
+ return ret;
+ offset += PTRACE_HBP_ADDR_SZ;
+
+ ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ctrl,
+ offset, offset + PTRACE_HBP_CTRL_SZ);
+ if (ret)
+ return ret;
+ ret = ptrace_hbp_set_ctrl(note_type, target, idx, ctrl);
+ if (ret)
+ return ret;
+ offset += PTRACE_HBP_CTRL_SZ;
+ idx++;
}
- return modify_user_hw_breakpoint(bp, &attr);
+ return 0;
}
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
@@ -354,7 +525,7 @@ static int tls_get(struct task_struct *target, const struct user_regset *regset,
static int tls_set(struct task_struct *target, const struct user_regset *regset,
unsigned int pos, unsigned int count,
- void *kbuf, void __user *ubuf)
+ const void *kbuf, const void __user *ubuf)
{
int ret;
unsigned long tls;
@@ -371,6 +542,10 @@ enum aarch64_regset {
REGSET_GPR,
REGSET_FPR,
REGSET_TLS,
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+ REGSET_HW_BREAK,
+ REGSET_HW_WATCH,
+#endif
};
static const struct user_regset aarch64_regsets[] = {
@@ -402,6 +577,24 @@ static const struct user_regset aarch64_regsets[] = {
.get = tls_get,
.set = tls_set,
},
+#ifdef CONFIG_HAVE_HW_BREAKPOINT
+ [REGSET_HW_BREAK] = {
+ .core_note_type = NT_ARM_HW_BREAK,
+ .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
+ .size = sizeof(u32),
+ .align = sizeof(u32),
+ .get = hw_break_get,
+ .set = hw_break_set,
+ },
+ [REGSET_HW_WATCH] = {
+ .core_note_type = NT_ARM_HW_WATCH,
+ .n = sizeof(struct user_hwdebug_state) / sizeof(u32),
+ .size = sizeof(u32),
+ .align = sizeof(u32),
+ .get = hw_break_get,
+ .set = hw_break_set,
+ },
+#endif
};
static const struct user_regset_view user_aarch64_view = {
@@ -410,6 +603,8 @@ static const struct user_regset_view user_aarch64_view = {
};
#ifdef CONFIG_COMPAT
+#include <linux/compat.h>
+
enum compat_regset {
REGSET_COMPAT_GPR,
REGSET_COMPAT_VFP,
@@ -592,45 +787,6 @@ static const struct user_regset_view user_aarch32_view = {
.name = "aarch32", .e_machine = EM_ARM,
.regsets = aarch32_regsets, .n = ARRAY_SIZE(aarch32_regsets)
};
-#endif /* CONFIG_COMPAT */
-
-const struct user_regset_view *task_user_regset_view(struct task_struct *task)
-{
-#ifdef CONFIG_COMPAT
- if (is_compat_thread(task_thread_info(task)))
- return &user_aarch32_view;
-#endif
- return &user_aarch64_view;
-}
-
-long arch_ptrace(struct task_struct *child, long request,
- unsigned long addr, unsigned long data)
-{
- int ret;
- unsigned long *datap = (unsigned long __user *)data;
-
- switch (request) {
-#ifdef CONFIG_HAVE_HW_BREAKPOINT
- case PTRACE_GETHBPREGS:
- ret = ptrace_gethbpregs(child, addr, datap);
- break;
-
- case PTRACE_SETHBPREGS:
- ret = ptrace_sethbpregs(child, addr, datap);
- break;
-#endif
-
- default:
- ret = ptrace_request(child, request, addr, data);
- break;
- }
-
- return ret;
-}
-
-#ifdef CONFIG_COMPAT
-
-#include <linux/compat.h>
int aarch32_break_trap(struct pt_regs *regs)
{
@@ -704,15 +860,101 @@ static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,
}
#ifdef CONFIG_HAVE_HW_BREAKPOINT
+
+/*
+ * Convert a virtual register number into an index for a thread_info
+ * breakpoint array. Breakpoints are identified using positive numbers
+ * whilst watchpoints are negative. The registers are laid out as pairs
+ * of (address, control), each pair mapping to a unique hw_breakpoint struct.
+ * Register 0 is reserved for describing resource information.
+ */
+static int compat_ptrace_hbp_num_to_idx(compat_long_t num)
+{
+ return (abs(num) - 1) >> 1;
+}
+
+static int compat_ptrace_hbp_get_resource_info(u32 *kdata)
+{
+ u8 num_brps, num_wrps, debug_arch, wp_len;
+ u32 reg = 0;
+
+ num_brps = hw_breakpoint_slots(TYPE_INST);
+ num_wrps = hw_breakpoint_slots(TYPE_DATA);
+
+ debug_arch = debug_monitors_arch();
+ wp_len = 8;
+ reg |= debug_arch;
+ reg <<= 8;
+ reg |= wp_len;
+ reg <<= 8;
+ reg |= num_wrps;
+ reg <<= 8;
+ reg |= num_brps;
+
+ *kdata = reg;
+ return 0;
+}
+
+static int compat_ptrace_hbp_get(unsigned int note_type,
+ struct task_struct *tsk,
+ compat_long_t num,
+ u32 *kdata)
+{
+ u64 addr = 0;
+ u32 ctrl = 0;
+
+ int err, idx = compat_ptrace_hbp_num_to_idx(num);;
+
+ if (num & 1) {
+ err = ptrace_hbp_get_addr(note_type, tsk, idx, &addr);
+ *kdata = (u32)addr;
+ } else {
+ err = ptrace_hbp_get_ctrl(note_type, tsk, idx, &ctrl);
+ *kdata = ctrl;
+ }
+
+ return err;
+}
+
+static int compat_ptrace_hbp_set(unsigned int note_type,
+ struct task_struct *tsk,
+ compat_long_t num,
+ u32 *kdata)
+{
+ u64 addr;
+ u32 ctrl;
+
+ int err, idx = compat_ptrace_hbp_num_to_idx(num);
+
+ if (num & 1) {
+ addr = *kdata;
+ err = ptrace_hbp_set_addr(note_type, tsk, idx, addr);
+ } else {
+ ctrl = *kdata;
+ err = ptrace_hbp_set_ctrl(note_type, tsk, idx, ctrl);
+ }
+
+ return err;
+}
+
static int compat_ptrace_gethbpregs(struct task_struct *tsk, compat_long_t num,
compat_ulong_t __user *data)
{
int ret;
- unsigned long kdata;
-
+ u32 kdata;
mm_segment_t old_fs = get_fs();
+
set_fs(KERNEL_DS);
- ret = ptrace_gethbpregs(tsk, (long)num, &kdata);
+ /* Watchpoint */
+ if (num < 0) {
+ ret = compat_ptrace_hbp_get(NT_ARM_HW_WATCH, tsk, num, &kdata);
+ /* Resource info */
+ } else if (num == 0) {
+ ret = compat_ptrace_hbp_get_resource_info(&kdata);
+ /* Breakpoint */
+ } else {
+ ret = compat_ptrace_hbp_get(NT_ARM_HW_BREAK, tsk, num, &kdata);
+ }
set_fs(old_fs);
if (!ret)
@@ -725,16 +967,22 @@ static int compat_ptrace_sethbpregs(struct task_struct *tsk, compat_long_t num,
compat_ulong_t __user *data)
{
int ret;
- unsigned long kdata = 0;
+ u32 kdata = 0;
mm_segment_t old_fs = get_fs();
+ if (num == 0)
+ return 0;
+
ret = get_user(kdata, data);
+ if (ret)
+ return ret;
- if (!ret) {
- set_fs(KERNEL_DS);
- ret = ptrace_sethbpregs(tsk, (long)num, &kdata);
- set_fs(old_fs);
- }
+ set_fs(KERNEL_DS);
+ if (num < 0)
+ ret = compat_ptrace_hbp_set(NT_ARM_HW_WATCH, tsk, num, &kdata);
+ else
+ ret = compat_ptrace_hbp_set(NT_ARM_HW_BREAK, tsk, num, &kdata);
+ set_fs(old_fs);
return ret;
}
@@ -819,6 +1067,22 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
}
#endif /* CONFIG_COMPAT */
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+#ifdef CONFIG_COMPAT
+ if (is_compat_thread(task_thread_info(task)))
+ return &user_aarch32_view;
+#endif
+ return &user_aarch64_view;
+}
+
+long arch_ptrace(struct task_struct *child, long request,
+ unsigned long addr, unsigned long data)
+{
+ return ptrace_request(child, request, addr, data);
+}
+
+
static int __init ptrace_break_init(void)
{
hook_debug_fault_code(DBG_ESR_EVT_BRK, arm64_break_trap, SIGTRAP,
diff --git a/include/linux/elf.h b/include/linux/elf.h
index aef297c4599..1e935e4c632 100644
--- a/include/linux/elf.h
+++ b/include/linux/elf.h
@@ -389,6 +389,8 @@ typedef struct elf64_shdr {
#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
#define NT_ARM_TLS 0x401 /* ARM TLS register */
+#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
+#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
/* Note header in a PT_NOTE section */