lkml.org 
[lkml]   [2009]   [Jul]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC][PATCH 3/5] hw-breakpoints: Make user breakpoints API truly generic
Date
Following the API changes on the kernel breakpoints API,
the user breakpoints registration now follows the same pattern.

The target, access length and type and now given as parameters
in the registration helpers to avoid per arch code in generic code.

However, to keep registering or modifying easily a user breakpoint
from arch code with a prefilled arch breakpoint structure, we provide
two new helpers:

- register_user_hw_breakpoint_filled(tsk, bp)
- modify_user_hw_breakpoint_filled(tsk, bp)

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
---
arch/x86/kernel/ptrace.c | 21 ++++++-----
include/asm-generic/hw_breakpoint.h | 12 +++++-
kernel/hw_breakpoint.c | 65 +++++++++++++++++++++++++++++-----
3 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index cabdabc..ef0eb10 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -525,17 +525,18 @@ restore:
if (!bp) {
rc = -ENOMEM;
bp = kzalloc(sizeof(struct hw_breakpoint), GFP_KERNEL);
- if (bp) {
- bp->info.address = thread->debugreg[i];
- bp->triggered = ptrace_triggered;
- bp->info.len = len;
- bp->info.type = type;
- rc = register_user_hw_breakpoint(tsk, bp);
- if (rc)
- kfree(bp);
- }
+ if (!bp)
+ break;
+
+ bp->info.address = thread->debugreg[i];
+ bp->triggered = ptrace_triggered;
+ bp->info.len = len;
+ bp->info.type = type;
+ rc = register_user_hw_breakpoint_filled(tsk, bp);
+ if (rc)
+ kfree(bp);
} else
- rc = modify_user_hw_breakpoint(tsk, bp);
+ rc = modify_user_hw_breakpoint_filled(tsk, bp);
if (rc)
break;
}
diff --git a/include/asm-generic/hw_breakpoint.h b/include/asm-generic/hw_breakpoint.h
index 300fe4c..598e3c4 100644
--- a/include/asm-generic/hw_breakpoint.h
+++ b/include/asm-generic/hw_breakpoint.h
@@ -83,10 +83,18 @@ struct hw_breakpoint {
* 1-, 2-, and 4-byte lengths may be unavailable.
*/

+extern int register_user_hw_breakpoint_filled(struct task_struct *tsk,
+ struct hw_breakpoint *bp);
extern int register_user_hw_breakpoint(struct task_struct *tsk,
- struct hw_breakpoint *bp);
+ struct hw_breakpoint *bp,
+ unsigned long addr, int len,
+ enum breakpoint_type type);
+extern int modify_user_hw_breakpoint_filled(struct task_struct *tsk,
+ struct hw_breakpoint *bp);
extern int modify_user_hw_breakpoint(struct task_struct *tsk,
- struct hw_breakpoint *bp);
+ struct hw_breakpoint *bp,
+ unsigned long addr,
+ int len, enum breakpoint_type type);
extern void unregister_user_hw_breakpoint(struct task_struct *tsk,
struct hw_breakpoint *bp);
/*
diff --git a/kernel/hw_breakpoint.c b/kernel/hw_breakpoint.c
index 0301245..f9e62e7 100644
--- a/kernel/hw_breakpoint.c
+++ b/kernel/hw_breakpoint.c
@@ -211,16 +211,14 @@ static void __unregister_user_hw_breakpoint(int pos, struct task_struct *tsk)
}

/**
- * register_user_hw_breakpoint - register a hardware breakpoint for user space
+ * register_user_hw_breakpoint_filled - register a filled hardware breakpoint
+ * for user space.
* @tsk: pointer to 'task_struct' of the process to which the address belongs
* @bp: the breakpoint structure to register
- *
- * @bp.info->name or @bp.info->address, @bp.info->len, @bp.info->type and
* @bp->triggered must be set properly before invocation
- *
*/
-int register_user_hw_breakpoint(struct task_struct *tsk,
- struct hw_breakpoint *bp)
+int register_user_hw_breakpoint_filled(struct task_struct *tsk,
+ struct hw_breakpoint *bp)
{
struct thread_struct *thread = &(tsk->thread);
int i, rc = -ENOSPC;
@@ -246,15 +244,40 @@ int register_user_hw_breakpoint(struct task_struct *tsk,
spin_unlock_bh(&hw_breakpoint_lock);
return rc;
}
+EXPORT_SYMBOL_GPL(register_user_hw_breakpoint_filled);
+
+/**
+ * register_user_hw_breakpoint - register a filled hardware breakpoint
+ * for user space.
+ * @tsk: pointer to 'task_struct' of the process to which the address belongs
+ * @bp: the breakpoint structure to register
+ * @addr: target of the breakpoint
+ * @len: length of the memory target access
+ * @type: type of the breakpoint (read-write/read/write/execute)
+ * @bp->triggered must be set properly before invocation
+ */
+int register_user_hw_breakpoint(struct task_struct *tsk,
+ struct hw_breakpoint *bp,
+ unsigned long addr,
+ int len, enum breakpoint_type type)
+{
+ int ret;
+
+ ret = arch_fill_hw_breakpoint(bp, addr, len, type);
+ if (ret)
+ return ret;
+
+ return register_user_hw_breakpoint_filled(tsk, bp);
+}
EXPORT_SYMBOL_GPL(register_user_hw_breakpoint);

/**
- * modify_user_hw_breakpoint - modify a user-space hardware breakpoint
+ * modify_user_hw_breakpoint_filled - modify a filled user-space hardware breakpoint
* @tsk: pointer to 'task_struct' of the process to which the address belongs
- * @bp: the breakpoint structure to unregister
- *
+ * @bp: the breakpoint structure to update
*/
-int modify_user_hw_breakpoint(struct task_struct *tsk, struct hw_breakpoint *bp)
+int modify_user_hw_breakpoint_filled(struct task_struct *tsk,
+ struct hw_breakpoint *bp)
{
struct thread_struct *thread = &(tsk->thread);
int i, ret = -ENOENT;
@@ -269,6 +292,28 @@ int modify_user_hw_breakpoint(struct task_struct *tsk, struct hw_breakpoint *bp)
spin_unlock_bh(&hw_breakpoint_lock);
return ret;
}
+EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint_filled);
+
+/**
+ * modify_user_hw_breakpoint - modify a user-space hardware breakpoint
+ * @tsk: pointer to 'task_struct' of the process to which the address belongs
+ * @bp: the breakpoint structure to update
+ * @addr: target of the breakpoint
+ * @len: length of the memory target access
+ * @type: type of the breakpoint (read-write/read/write/execute)
+ */
+int modify_user_hw_breakpoint(struct task_struct *tsk, struct hw_breakpoint *bp,
+ unsigned long addr, int len,
+ enum breakpoint_type type)
+{
+ int ret;
+
+ ret = arch_fill_hw_breakpoint(bp, addr, len, type);
+ if (ret)
+ return ret;
+
+ return register_user_hw_breakpoint_filled(tsk, bp);
+}
EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint);

/**
--
1.6.2.3


\
 
 \ /
  Last update: 2009-07-20 19:11    [W:0.164 / U:0.676 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site