From 823167ff5296299a977b4378cca82759b51580a4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Mon, 27 Apr 2015 12:50:46 +0300 Subject: [PATCH] [FIX] partial revert revert commit 898e1e017764c13d0dda84a1a96bee687743ee70. Change-Id: I3ce70e137d603a8bc4a132041fe75c10288e8bc7 Signed-off-by: Vyacheslav Cherkashin --- us_manager/helper.c | 37 ++++++++++++++------------------- us_manager/pf/pf_group.c | 15 +------------- us_manager/sspt/sspt_proc.c | 50 ++------------------------------------------- 3 files changed, 18 insertions(+), 84 deletions(-) diff --git a/us_manager/helper.c b/us_manager/helper.c index 4cbdcec..ec9c1a6 100644 --- a/us_manager/helper.c +++ b/us_manager/helper.c @@ -49,20 +49,21 @@ struct pf_data { unsigned long addr; }; -static int entry_handler_mf(struct kretprobe_instance *ri, struct pt_regs *regs) +static int entry_handler_pf(struct kretprobe_instance *ri, struct pt_regs *regs) { struct pf_data *data = (struct pf_data *)ri->data; -#ifdef CONFIG_ARM +#if defined(CONFIG_ARM) data->addr = swap_get_karg(regs, 0); -#else /* CONFIG_ARM */ - data->addr = swap_get_karg(regs, 2); -#endif /* CONFIG_ARM */ +#elif defined(CONFIG_X86_32) + data->addr = read_cr2(); +#else + #error "this architecture is not supported" +#endif /* CONFIG_arch */ return 0; } -#ifdef CONFIG_ARM static unsigned long cb_pf(void *data) { unsigned long page_addr = *(unsigned long *)data; @@ -71,34 +72,31 @@ static unsigned long cb_pf(void *data) return 0; } -#endif /* CONFIG_ARM */ /* Detects when IPs are really loaded into phy mem and installs probes. */ -static int ret_handler_mf(struct kretprobe_instance *ri, struct pt_regs *regs) +static int ret_handler_pf(struct kretprobe_instance *ri, struct pt_regs *regs) { struct task_struct *task = current; unsigned long page_addr; + int ret; if (is_kthread(task)) return 0; /* TODO: check return value */ page_addr = ((struct pf_data *)ri->data)->addr & PAGE_MASK; + ret = set_jump_cb((unsigned long)ri->ret_addr, regs, cb_pf, + &page_addr, sizeof(page_addr)); -#ifdef CONFIG_ARM - set_jump_cb((unsigned long)ri->ret_addr, regs, cb_pf, - &page_addr, sizeof(page_addr)); - ri->ret_addr = (unsigned long *)get_jump_addr(); -#else /* CONFIG_ARM */ - call_page_fault(task, page_addr); -#endif /* CONFIG_ARM */ + if (ret == 0) + ri->ret_addr = (unsigned long *)get_jump_addr(); return 0; } static struct kretprobe mf_kretprobe = { - .entry_handler = entry_handler_mf, - .handler = ret_handler_mf, + .entry_handler = entry_handler_pf, + .handler = ret_handler_pf, .data_size = sizeof(struct pf_data) }; @@ -656,11 +654,7 @@ int once_helper(void) { const char *sym; -#ifdef CONFIG_ARM sym = "do_page_fault"; -#else /* CONFIG_ARM */ - sym = "handle_mm_fault"; -#endif /* CONFIG_ARM */ mf_kretprobe.kp.addr = (kprobe_opcode_t *)swap_ksyms(sym); if (mf_kretprobe.kp.addr == NULL) goto not_found; @@ -670,7 +664,6 @@ int once_helper(void) if (cp_kretprobe.kp.addr == NULL) goto not_found; - sym = "mm_release"; mr_kprobe.addr = (kprobe_opcode_t *)swap_ksyms(sym); if (mr_kprobe.addr == NULL) diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index e5667b0..d967d6b 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -190,31 +190,18 @@ static void first_install(struct task_struct *task, struct sspt_proc *proc, NULL; } - down_read(&task->mm->mmap_sem); - proc_info_msg(task, dentry); - up_read(&task->mm->mmap_sem); - -#ifdef CONFIG_ARM down_write(&task->mm->mmap_sem); + proc_info_msg(task, dentry); sspt_proc_install(proc); up_write(&task->mm->mmap_sem); -#else /* CONFIG_ARM */ - sspt_proc_install(proc); -#endif /* CONFIG_ARM */ } static void subsequent_install(struct task_struct *task, struct sspt_proc *proc, unsigned long page_addr) { - if (!page_addr) - return; -#ifdef CONFIG_ARM down_write(&task->mm->mmap_sem); sspt_proc_install_page(proc, page_addr); up_write(&task->mm->mmap_sem); -#else /* CONFIG_ARM */ - sspt_proc_install_page(proc, page_addr); -#endif /* CONFIG_ARM */ } /** diff --git a/us_manager/sspt/sspt_proc.c b/us_manager/sspt/sspt_proc.c index b76b136..baa0968 100644 --- a/us_manager/sspt/sspt_proc.c +++ b/us_manager/sspt/sspt_proc.c @@ -34,38 +34,6 @@ #include -#ifdef CONFIG_ARM -#define mm_read_lock(task, mm, atomic, lock) \ - mm = task->mm; \ - lock = 0 - -#define mm_read_unlock(mm, atomic, lock) -#else /* CONFIG_ARM */ -#define mm_read_lock(task, mm, atomic, lock) \ - mm = atomic ? task->active_mm : get_task_mm(task); \ - if (mm == NULL) { \ - /* FIXME: */ \ - panic("ERRR mm_read_lock: mm == NULL\n"); \ - } \ - \ - if (atomic) { \ - lock = down_read_trylock(&mm->mmap_sem); \ - } else { \ - lock = 1; \ - down_read(&mm->mmap_sem); \ - } - -#define mm_read_unlock(mm, atomic, lock) \ - if (lock) { \ - up_read(&mm->mmap_sem); \ - } \ - \ - if (!atomic) { \ - mmput(mm); \ - } -#endif /* CONFIG_ARM */ - - static LIST_HEAD(proc_probes_list); static DEFINE_RWLOCK(sspt_proc_rwlock); @@ -311,13 +279,8 @@ struct sspt_file *sspt_proc_find_file(struct sspt_proc *proc, struct dentry *den */ void sspt_proc_install_page(struct sspt_proc *proc, unsigned long page_addr) { - int lock, atomic; - struct mm_struct *mm; + struct mm_struct *mm = proc->task->mm; struct vm_area_struct *vma; - struct task_struct *task = proc->task; - - atomic = in_atomic(); - mm_read_lock(task, mm, atomic, lock); vma = find_vma_intersection(mm, page_addr, page_addr + 1); if (vma && check_vma(vma)) { @@ -336,8 +299,6 @@ void sspt_proc_install_page(struct sspt_proc *proc, unsigned long page_addr) } } } - - mm_read_unlock(mm, atomic, lock); } /** @@ -348,16 +309,11 @@ void sspt_proc_install_page(struct sspt_proc *proc, unsigned long page_addr) */ void sspt_proc_install(struct sspt_proc *proc) { - int lock, atomic; struct vm_area_struct *vma; - struct task_struct *task = proc->task; - struct mm_struct *mm; + struct mm_struct *mm = proc->task->mm; proc->first_install = 1; - atomic = in_atomic(); - mm_read_lock(task, mm, atomic, lock); - for (vma = mm->mmap; vma; vma = vma->vm_next) { if (check_vma(vma)) { struct dentry *dentry = vma->vm_file->f_dentry; @@ -372,8 +328,6 @@ void sspt_proc_install(struct sspt_proc *proc) } } } - - mm_read_unlock(mm, atomic, lock); } /** -- 2.7.4