From: Vyacheslav Cherkashin Date: Wed, 8 May 2013 13:34:55 +0000 (+0400) Subject: [REFACTOR] move and redesign install_proc_probes() X-Git-Tag: Tizen_SDK_2.3~504 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bbf1ec1f802a067ec2e492f0545e8d9d5c7f00e3;p=kernel%2Fswap-modules.git [REFACTOR] move and redesign install_proc_probes() refactoring: install_proc_probes() --> sspt_procs_install() move: from src/modules/driver/us_proc_inst.c to src/modules/driver/sspt/sspt_procs.c install_page_probes() --> sspt_procs_install_page() move: from src/modules/driver/us_proc_inst.c to src/modules/driver/sspt/sspt_procs.c mm_read_lock() and mm_read_unlock() move: from src/modules/driver/us_proc_inst.c to src/modules/driver/sspt/sspt_procs.c set_mapping_file() --> sspt_file_set_mapping() move: from src/modules/driver/us_proc_inst.c to src/modules/driver/sspt/sspt_file.c --- diff --git a/driver/helper.c b/driver/helper.c index 7bf8cec..02d5f7d 100644 --- a/driver/helper.c +++ b/driver/helper.c @@ -71,7 +71,7 @@ static int ret_handler_pf(struct kretprobe_instance *ri, struct pt_regs *regs) procs = sspt_procs_get_by_task_or_new(task); /* install probes in already mapped memory */ - install_proc_probes(task, procs); + sspt_procs_install(procs); } } @@ -82,7 +82,7 @@ static int ret_handler_pf(struct kretprobe_instance *ri, struct pt_regs *regs) if (procs) { unsigned long page = addr & PAGE_MASK; - install_page_probes(page, task, procs); + sspt_procs_install_page(procs, page); } out: diff --git a/driver/sspt/sspt_file.c b/driver/sspt/sspt_file.c index 49d92a9..0bb3139 100644 --- a/driver/sspt/sspt_file.c +++ b/driver/sspt/sspt_file.c @@ -24,9 +24,12 @@ #include "sspt_file.h" #include "sspt_page.h" +#include "sspt_procs.h" +#include #include #include #include +#include #include static int calculation_hash_bits(int cnt) @@ -239,3 +242,16 @@ void sspt_file_install(struct sspt_file *file) } } } + +void sspt_file_set_mapping(struct sspt_file *file, struct vm_area_struct *vma) +{ + struct task_struct *task = file->procs->task; + int app_flag = (vma->vm_file->f_dentry == file->procs->dentry); + + file->vm_start = vma->vm_start; + file->vm_end = vma->vm_end; + + pack_event_info(DYN_LIB_PROBE_ID, RECORD_ENTRY, "dspdd", + task->tgid, file->name, vma->vm_start, + vma->vm_end - vma->vm_start, app_flag); +} diff --git a/driver/sspt/sspt_file.h b/driver/sspt/sspt_file.h index 14e8b4f..1a33698 100644 --- a/driver/sspt/sspt_file.h +++ b/driver/sspt/sspt_file.h @@ -28,6 +28,7 @@ #include "ip.h" #include +struct vm_area_struct; struct sspt_file { struct list_head list; // for proc_probes @@ -55,5 +56,6 @@ void sspt_put_page(struct sspt_page *page); int sspt_file_check_install_pages(struct sspt_file *file); void sspt_file_install(struct sspt_file *file); +void sspt_file_set_mapping(struct sspt_file *file, struct vm_area_struct *vma); #endif /* __SSPT_FILE__ */ diff --git a/driver/sspt/sspt_procs.c b/driver/sspt/sspt_procs.c index 46ca2c2..a77112f 100644 --- a/driver/sspt/sspt_procs.c +++ b/driver/sspt/sspt_procs.c @@ -23,9 +23,34 @@ */ #include "sspt_procs.h" +#include "sspt_page.h" #include #include #include +#include + +#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); \ + } static LIST_HEAD(proc_probes_list); @@ -158,3 +183,62 @@ struct sspt_file *sspt_procs_find_file(struct sspt_procs *procs, struct dentry * return NULL; } + +void sspt_procs_install_page(struct sspt_procs *procs, unsigned long page_addr) +{ + int lock, atomic; + struct mm_struct *mm; + struct vm_area_struct *vma; + struct task_struct *task = procs->task; + + atomic = in_atomic(); + mm_read_lock(task, mm, atomic, lock); + + vma = find_vma(mm, page_addr); + if (vma && check_vma(vma)) { + struct dentry *dentry = vma->vm_file->f_dentry; + struct sspt_file *file = sspt_procs_find_file(procs, dentry); + if (file) { + struct sspt_page *page; + if (!file->loaded) { + sspt_file_set_mapping(file, vma); + file->loaded = 1; + } + + page = sspt_find_page_mapped(file, page_addr); + if (page) { + sspt_register_page(page, file); + } + } + } + + mm_read_unlock(mm, atomic, lock); +} + +void sspt_procs_install(struct sspt_procs *procs) +{ + int lock, atomic; + struct vm_area_struct *vma; + struct task_struct *task = procs->task; + struct mm_struct *mm; + + 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; + struct sspt_file *file = sspt_procs_find_file(procs, dentry); + if (file) { + if (!file->loaded) { + sspt_file_set_mapping(file, vma); + file->loaded = 1; + } + + sspt_file_install(file); + } + } + } + + mm_read_unlock(mm, atomic, lock); +} diff --git a/driver/sspt/sspt_procs.h b/driver/sspt/sspt_procs.h index 1099107..40aef01 100644 --- a/driver/sspt/sspt_procs.h +++ b/driver/sspt/sspt_procs.h @@ -55,4 +55,7 @@ struct sspt_file *sspt_procs_find_file(struct sspt_procs *procs, struct dentry * struct sspt_file *sspt_procs_find_file_or_new(struct sspt_procs *procs, struct dentry *dentry, char *name); +void sspt_procs_install_page(struct sspt_procs *procs, unsigned long page_addr); +void sspt_procs_install(struct sspt_procs *procs); + #endif /* __SSPT_PROC__ */ diff --git a/driver/us_proc_inst.c b/driver/us_proc_inst.c index 57f966c..a01565d 100644 --- a/driver/us_proc_inst.c +++ b/driver/us_proc_inst.c @@ -25,29 +25,6 @@ #include "helper.h" #include "us_slot_manager.h" -#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); \ - } - unsigned long ujprobe_event_pre_handler (struct us_ip *ip, struct pt_regs *regs); void ujprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6); int uretprobe_event_handler(struct uretprobe_instance *probe, struct pt_regs *regs, struct us_ip *ip); @@ -162,11 +139,6 @@ static int find_task_by_path (const char *path, struct task_struct **p_task, str return 0; } -static void set_mapping_file(struct sspt_file *file, - const struct sspt_procs *procs, - const struct task_struct *task, - const struct vm_area_struct *vma); - int install_otg_ip(unsigned long addr, kprobe_pre_entry_handler_t pre_handler, unsigned long jp_handler, @@ -197,7 +169,7 @@ int install_otg_ip(unsigned long addr, struct us_ip *ip = sspt_find_ip(page, offset_addr & ~PAGE_MASK); if (!file->loaded) { - set_mapping_file(file, procs, task, vma); + sspt_file_set_mapping(file, vma); file->loaded = 1; } @@ -301,7 +273,7 @@ int inst_usr_space_proc (void) procs = sspt_procs_get_by_task_or_new(task); DPRINTF("trying process"); - install_proc_probes(task, procs); + sspt_procs_install(procs); //put_task_struct (task); } } @@ -314,7 +286,7 @@ int inst_usr_space_proc (void) procs = sspt_procs_get_by_task_or_new(task); us_proc_info.tgid = task->pid; - install_proc_probes(task, procs); + sspt_procs_install(procs); put_task_struct(task); } } @@ -322,80 +294,8 @@ int inst_usr_space_proc (void) return 0; } -static void set_mapping_file(struct sspt_file *file, - const struct sspt_procs *procs, - const struct task_struct *task, - const struct vm_area_struct *vma) -{ - int app_flag = (vma->vm_file->f_dentry == procs->dentry); - - file->vm_start = vma->vm_start; - file->vm_end = vma->vm_end; - - pack_event_info(DYN_LIB_PROBE_ID, RECORD_ENTRY, "dspdd", - task->tgid, file->name, vma->vm_start, - vma->vm_end - vma->vm_start, app_flag); -} - void print_vma(struct mm_struct *mm); -void install_page_probes(unsigned long page_addr, struct task_struct *task, struct sspt_procs *procs) -{ - int lock, atomic; - struct mm_struct *mm; - struct vm_area_struct *vma; - - atomic = in_atomic(); - mm_read_lock(task, mm, atomic, lock); - - vma = find_vma(mm, page_addr); - if (vma && check_vma(vma)) { - struct dentry *dentry = vma->vm_file->f_dentry; - struct sspt_file *file = sspt_procs_find_file(procs, dentry); - if (file) { - struct sspt_page *page; - if (!file->loaded) { - set_mapping_file(file, procs, task, vma); - file->loaded = 1; - } - - page = sspt_find_page_mapped(file, page_addr); - if (page) { - sspt_register_page(page, file); - } - } - } - - mm_read_unlock(mm, atomic, lock); -} - -void install_proc_probes(struct task_struct *task, struct sspt_procs *procs) -{ - int lock, atomic; - struct vm_area_struct *vma; - struct mm_struct *mm; - - 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; - struct sspt_file *file = sspt_procs_find_file(procs, dentry); - if (file) { - if (!file->loaded) { - set_mapping_file(file, procs, task, vma); - file->loaded = 1; - } - - sspt_file_install(file); - } - } - } - - mm_read_unlock(mm, atomic, lock); -} - int unregister_us_file_probes(struct task_struct *task, struct sspt_file *file, enum US_FLAGS flag) { int i, err = 0; diff --git a/driver/us_proc_inst.h b/driver/us_proc_inst.h index c9b7ab8..fc26121 100644 --- a/driver/us_proc_inst.h +++ b/driver/us_proc_inst.h @@ -52,9 +52,7 @@ int install_otg_ip(unsigned long addr, unsigned long jp_handler, uretprobe_handler_t rp_handler); -void install_proc_probes(struct task_struct *task, struct sspt_procs *procs); int check_dentry(struct task_struct *task, struct dentry *dentry); -void install_page_probes(unsigned long page_addr, struct task_struct *task, struct sspt_procs *procs); int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs *procs, enum US_FLAGS flag); int check_vma(struct vm_area_struct *vma); int unregister_us_file_probes(struct task_struct *task, struct sspt_file *file, enum US_FLAGS flag);