x86: Move is_ia32_task to asm/thread_info.h from asm/compat.h
Subsystems (7)
PATCH 1/2 x86: Move is_ia32_task to asm/thread_info.h from asm/compat.h
From: Srikar Dronamraju <[email protected]>
is_ia32_task is useful even in !CONFIG_COMPAT cases. Hence move it to a more generic file asm/thread_info.h
Also now is_ia32_task returns true if CONFIG_X86_32 is defined.
--- arch/x86/include/asm/compat.h | 9 --------- arch/x86/include/asm/thread_info.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-)
arch/x86/include/asm/compat.h +0 -9
@@ -235,15 +235,6 @@ static inline void __user *arch_compat_alloc_user_space(long len)return (void __user *)round_down (sp - len,16 ); } -static inline bool is_ia32_task (void ) -{ -#ifdef CONFIG_IA32_EMULATION -if (current_thread_info ()->status &TS_COMPAT ) -return true; -#endif -return false; -} -static inline bool is_x32_task (void ) {#ifdef CONFIG_X86_X32_ABI
arch/x86/include/asm/thread_info.h +12 -0
@@ -266,6 +266,18 @@ static inline void set_restore_sigmask(void) ti->status |=TS_RESTORE_SIGMASK ; set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); } + +static inline bool is_ia32_task (void ) +{ +#ifdef CONFIG_X86_32 +return true; +#endif +#if definedCONFIG_X86_64 && definedCONFIG_IA32_EMULATION +if (current_thread_info ()->status &TS_COMPAT ) +return true; +#endif +return false; +}#endif /* !__ASSEMBLY__ */ #ifndef __ASSEMBLY__
PATCH 2/2 uprobes/core: Handle breakpoint and singlestep exception.
From: Srikar Dronamraju <[email protected]>
Uprobes uses exception notifiers to get to know if a thread hit a breakpoint or singlestep exception.
When a thread hits a uprobe or is singlestepping post a uprobe hit, the uprobe exception notifier sets its TIF_UPROBE bit, which will then be checked on its return to userspace path (do_notify_resume() ->uprobe_notify_resume()), where the consumers handlers are run (in task context) based on the defined filters.
Uprobe hits are thread specific and hence we need to maintain information about if a task hit a uprobe, what uprobe was hit, the slot where the original instruction was copied for xol so that it can be singlestepped with appropriate fixups.
In some cases, special care is needed for instructions that are executed out of line (xol). These are architecture specific artefacts, such as handling RIP relative instructions on x86_64.
Since the instruction at which the uprobe was inserted is executed out of line, architecture specific fixups are added so that the thread continues normal execution in the presence of a uprobe.
Postpone the signals until we execute the probed insn. post_xol() path does a recalc_sigpending() before return to user-mode, this ensures the signal can't be lost.
Uprobes relies on DIE_DEBUG notification to notify if a singlestep is complete.
Adds x86 specific uprobe exception notifiers and appropriate hooks needed to determine a uprobe hit and subsequent post processing.
Add requisite x86 fixups for xol for uprobes. Specific cases needing fixups include relative jumps (x86_64), calls, etc.
Where possible, we check and skip singlestepping the breakpointed instructions. For now we skip single byte as well as few multibyte nop instructions. However this can be extended to other instructions too.
Credits to Oleg Nesterov for suggestions/patches related to signal, breakpoint, singlestep handling code.
---
Changelog
(v10):
- Resolve comments suggested by Ingo Molnar.
- arch specific functions start with arch_uprobe_
- factor out few cleanup into separate patches
(v9):
- Use instruction_pointer_set instead of set_instruction_pointer.
- Changed can_skip_xol to uprobe_skip_sstep as suggested by Ananth
(v7):
- Resolve comments from Dan Carpenter.
- add_utask returns NULL on error.
- Handles architecture agnostic parts of a uprobe breakpoint hit and subsequent xol singlestepping.
(v6)
- added x86 specific hook for aborting xol.
(v5)
- Use srcu_raw instead of synchronize_sched
- Introduce per task srcu_id to store the srcu_id
- Modified comments.
- No more do a i386 specific enable interrupts. (Its not part of another patch posted separately)
arch/x86/include/asm/thread_info.h | 2 arch/x86/include/asm/uprobes.h | 16 ++ arch/x86/kernel/signal.c | 6 + arch/x86/kernel/uprobes.c | 261 ++++++++++++++++++++++++++++++ include/linux/sched.h | 4 include/linux/uprobes.h | 44 +++++ kernel/events/uprobes.c | 310 ++++++++++++++++++++++++++++++++++++ kernel/fork.c | 7 + kernel/signal.c | 4 9 files changed, 645 insertions(+), 9 deletions(-)
arch/x86/include/asm/thread_info.h +2 -0
@@ -85,6 +85,7 @@ struct thread_info {#define TIF_SECCOMP 8/* secure computing */ #define TIF_MCE_NOTIFY 10/* notify userspace of an MCE */ #define TIF_USER_RETURN_NOTIFY 11/* notify kernel of userspace return */ +#define TIF_UPROBE 12/* breakpointed or singlestepping */ #define TIF_NOTSC 16/* TSC is not accessible in userland */ #define TIF_IA32 17/* IA32 compatibility process */ #define TIF_FORK 18/* ret_from_fork */
@@ -109,6 +110,7 @@ struct thread_info {#define _TIF_SECCOMP (1 << TIF_SECCOMP)#define _TIF_MCE_NOTIFY (1 << TIF_MCE_NOTIFY)#define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY) +#define _TIF_UPROBE (1 << TIF_UPROBE)#define _TIF_NOTSC (1 << TIF_NOTSC)#define _TIF_IA32 (1 << TIF_IA32)#define _TIF_FORK (1 << TIF_FORK)
arch/x86/include/asm/uprobes.h +15 -1
@@ -23,6 +23,8 @@* Jim Keniston */ +#include <linux/notifier.h> +typedef u8 uprobe_opcode_t ;#define MAX_UINSN_BYTES 16
@@ -39,5 +41,17 @@ struct arch_uprobe { #endif }; -extern int arch_uprobes_analyze_insn (struct arch_uprobe *aup,struct mm_struct *mm); +struct arch_uprobe_task { +unsigned long saved_trap_nr; +#ifdef CONFIG_X86_64 +unsigned long saved_scratch_register; +#endif +}; + +extern int arch_uprobe_analyze_insn (struct arch_uprobe *aup,struct mm_struct *mm); +extern int arch_uprobe_pre_xol (struct arch_uprobe *aup,struct pt_regs *regs); +extern int arch_uprobe_post_xol (struct arch_uprobe *aup,struct pt_regs *regs); +extern bool arch_uprobe_xol_was_trapped (struct task_struct *tsk); +extern int arch_uprobe_exception_notify (struct notifier_block *self,unsigned long val,void *data); +extern void arch_uprobe_abort_xol (struct arch_uprobe *aup,struct pt_regs *regs);#endif /* _ASM_UPROBES_H */
arch/x86/kernel/signal.c +6 -0
@@ -18,6 +18,7 @@#include <linux/personality.h> #include <linux/uaccess.h> #include <linux/user-return-notifier.h> +#include <linux/uprobes.h> #include <asm/processor.h> #include <asm/ucontext.h>
@@ -824,6 +825,11 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)mce_notify_process ();#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ +if (thread_info_flags & _TIF_UPROBE) { +clear_thread_flag (TIF_UPROBE ); +uprobe_notify_resume (regs); + } +/* deal with pending signal delivery */ if (thread_info_flags & _TIF_SIGPENDING)do_signal (regs);
arch/x86/kernel/uprobes.c +255 -6
294 lines not on this page · raw message
include/linux/sched.h +4 -0
@@ -1606,6 +1606,10 @@ struct task_struct {#ifdef CONFIG_HAVE_HW_BREAKPOINT atomic_t ptrace_bp_refcnt;#endif +#ifdef CONFIG_UPROBES +struct uprobe_task *utask; +int uprobe_srcu_id; +#endif };/* Future-safe accessor for struct task_struct's cpus_allowed. */
include/linux/uprobes.h +44 -0
67 lines not on this page · raw message
kernel/events/uprobes.c +308 -2
359 lines not on this page · raw message
kernel/fork.c +7 -0
@@ -67,6 +67,7 @@#include <linux/oom.h> #include <linux/khugepaged.h> #include <linux/signalfd.h> +#include <linux/uprobes.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -731,6 +732,8 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)exit_pi_state_list (tsk);#endif +uprobe_free_utask (tsk); +/* Get rid of any cached register state */ deactivate_mm (tsk, mm);
@@ -1322,6 +1325,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,INIT_LIST_HEAD (&p->pi_state_list); p->pi_state_cache =NULL ;#endif +#ifdef CONFIG_UPROBES + p->utask =NULL ; + p->uprobe_srcu_id =-1 ; +#endif /* * sigaltstack should be cleared when sharing the same VM */
kernel/signal.c +4 -0
@@ -29,6 +29,7 @@#include <linux/pid_namespace.h> #include <linux/nsproxy.h> #include <linux/user_namespace.h> +#include <linux/uprobes.h> #define CREATE_TRACE_POINTS #include <trace/events/signal.h>
@@ -2192,6 +2193,9 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,struct signal_struct *signal = current->signal;int signr; +if (unlikely (uprobe_deny_signal ())) +return 0 ; + relock:/* * We'll jump back here after any time we were stopped in TASK_STOPPED.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] uprobes/core: Handle breakpoint and singlestep exception.
Quoted 22 lines · Srikar Dronamraju
kernel/fork.c +3
-0@@ -67,6 +67,7 @@#include <linux/oom.h> #include <linux/khugepaged.h> #include <linux/signalfd.h> +#include <linux/uprobes.h> #include <asm/pgtable.h> #include <asm/pgalloc.h> @@ -731,6 +732,8 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)exit_pi_state_list (tsk);#endif +uprobe_free_utask (tsk); +/* Get rid of any cached register state */ deactivate_mm (tsk, mm);
kernel/fork.c static struct task_struct *copy_process(unsigned long clone_flags, · line 1334
Quoted 10 lines
kernel/fork.c +4
-0@@ -1322,6 +1325,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,INIT_LIST_HEAD (&p->pi_state_list); p->pi_state_cache =NULL ;#endif +#ifdef CONFIG_UPROBES + p->utask =NULL ; + p->uprobe_srcu_id =-1 ; +#endif /* * sigaltstack should be cleared when sharing the same VM */
Hm, I suspect by looking at the first two hunks you can guess how the third hunk should be done more cleanly?
Thanks,
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/2] uprobes/core: Handle breakpoint and singlestep exception.
Quoted 22 lines
Quoted 22 lines
kernel/fork.c +3
-0@@ -67,6 +67,7 @@#include <linux/oom.h> #include <linux/khugepaged.h> #include <linux/signalfd.h> +#include <linux/uprobes.h> #include <asm/pgtable.h> #include <asm/pgalloc.h> @@ -731,6 +732,8 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm)exit_pi_state_list (tsk);#endif +uprobe_free_utask (tsk); +/* Get rid of any cached register state */ deactivate_mm (tsk, mm);
Quoted 15 lines
kernel/fork.c static struct task_struct *copy_process(unsigned long clone_flags, · line 1334
Quoted 11 lines
kernel/fork.c +4
-0@@ -1322,6 +1325,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,INIT_LIST_HEAD (&p->pi_state_list); p->pi_state_cache =NULL ;#endif +#ifdef CONFIG_UPROBES + p->utask =NULL ; + p->uprobe_srcu_id =-1 ; +#endif /* * sigaltstack should be cleared when sharing the same VM */ Hm, I suspect by looking at the first two hunks you can guess how the third hunk should be done more cleanly?
Resent just this patch after addressing this comment.
Signature · 2 lines
thanks and regards Srikar
[tip:perf/uprobes] x86: Move is_ia32_task to asm/thread_info. h from asm/compat.h
In reply to Srikar DronamrajuCommit-ID: ef334a20d84f52407a8a2afd02ddeaecbef0ad3d Gitweb: http://git.kernel.org/tip/ef334a20d84f52407a8a2afd02ddeaecbef0ad3d Author: Srikar Dronamraju <[email protected]> AuthorDate: Tue, 13 Mar 2012 19:33:03 +0530 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 13 Mar 2012 16:31:09 +0100
x86: Move is_ia32_task to asm/thread_info.h from asm/compat.h
is_ia32_task() is useful even in !CONFIG_COMPAT cases - utrace will use it for example. Hence move it to a more generic file: asm/thread_info.h
Also now is_ia32_task() returns true if CONFIG_X86_32 is defined.
--- arch/x86/include/asm/compat.h | 9 --------- arch/x86/include/asm/thread_info.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-)
arch/x86/include/asm/compat.h +0 -9
@@ -235,15 +235,6 @@ static inline void __user *arch_compat_alloc_user_space(long len)return (void __user *)round_down (sp - len,16 ); } -static inline bool is_ia32_task (void ) -{ -#ifdef CONFIG_IA32_EMULATION -if (current_thread_info ()->status &TS_COMPAT ) -return true; -#endif -return false; -} -static inline bool is_x32_task (void ) {#ifdef CONFIG_X86_X32_ABI
arch/x86/include/asm/thread_info.h +12 -0
@@ -266,6 +266,18 @@ static inline void set_restore_sigmask(void) ti->status |=TS_RESTORE_SIGMASK ; set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); } + +static inline bool is_ia32_task (void ) +{ +#ifdef CONFIG_X86_32 +return true; +#endif +#ifdef CONFIG_IA32_EMULATION +if (current_thread_info ()->status &TS_COMPAT ) +return true; +#endif +return false; +}#endif /* !__ASSEMBLY__ */ #ifndef __ASSEMBLY__
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>