[Fault-injection-developer] Updated: fi_dbp
Status: Alpha
Brought to you by:
rustyl
From: Wang, S. <sta...@in...> - 2003-01-07 08:54:53
|
I rewrited part of fi_dbp. We get the "mod->module_core" through "/proc/modules" now. Here is the patch: # This is a BitKeeper generated patch for the following project: # Project Name: Linux kernel tree # This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas: # ChangeSet 1.972 -> 1.972.2.3 # kernel/module.c 1.39 -> 1.40 # drivers/fi/interceptors/dbp/fi_dbp.c 1.9 -> 1.11 # include/linux/module.h 1.38 -> 1.39 # # The following is the BitKeeper ChangeSet Log # -------------------------------------------- # 03/01/07 lo...@ha... 1.973 # make fi_core moduleable # -------------------------------------------- # 03/01/07 ke...@ke... 1.972.1.1 # fi_core.c: # Remove codesegment before detach trigger issue # -------------------------------------------- # 03/01/07 st...@ma... 1.972.2.1 # Rewrite fi_dbp. # We get module->module_core from /proc/modules now. # -------------------------------------------- # 03/01/07 lo...@ha... 1.974 # Merge bk://fau...@fa.../linux-2.5 # into hawk.sh.intel.com:/home/work/2.5-fi # -------------------------------------------- # 03/01/07 lo...@ha... 1.975 # Add missed license # -------------------------------------------- # 03/01/07 st...@ma... 1.972.2.3 # Clean up code and fix bug for fi_dbp. # Can't clear bug fixed. # -------------------------------------------- # diff -Nru a/drivers/fi/interceptors/dbp/fi_dbp.c b/drivers/fi/interceptors/dbp/fi_dbp.c --- a/drivers/fi/interceptors/dbp/fi_dbp.c Tue Jan 7 16:43:10 2003 +++ b/drivers/fi/interceptors/dbp/fi_dbp.c Tue Jan 7 16:43:10 2003 @@ -47,12 +47,12 @@ #include <asm/uaccess.h> #include <linux/smp.h> #include <asm/processor.h> +#include <linux/list.h> #include <linux/kprobes.h> #include <linux/fi.h> #define MAX_WP 32 -#define MAX_MOD 16 /*define reason of entering do_debug*/ #define REASON_NOTME 0 @@ -73,11 +73,10 @@ unsigned long mask; }; -struct inst_rec_header { - char modname[256]; - int counter; - struct kprobe *kprobes; -}inst_tab[MAX_MOD] = {[0 ... MAX_MOD-1] = {"",0,NULL}}; +struct inst_rec { + struct list_head list; + struct kprobe kprobe; +}; struct { struct watchpoint wp; @@ -95,9 +94,7 @@ }which_inst[NR_CPUS] = {[0 ... NR_CPUS-1] = {-1, -1, 0, 0, NULL, {0, 0, 0, 0}}}; static DECLARE_MUTEX(dbp_sem); -static int in_used; -static int mod_index; -static int ins_index; +static LIST_HEAD(inst_rec_head); static struct interceptor dbp_interceptor; static int dbp_arm(struct trigger *t); @@ -105,9 +102,7 @@ void dbp_corrupt(__u32 dirty, void *data); int get_IO_opcode(struct opcode *op, struct pt_regs *regs); -int attach_module(const char *page); -int detach_module(const char *page); -void add_ins(const char *page); +int add_ins(const char *page); void post_probe_handler(struct kprobe *, struct pt_regs *, unsigned long); void pre_probe_handler(struct kprobe *, struct pt_regs *); @@ -446,133 +441,44 @@ return ; } -int attach_module(const char *page) -{ - int num=0; - int i=0; - char tmp[16]; - - for(i=0;i<MAX_MOD;i++){ - if(inst_tab[i].counter <= 0) { - break; - } - } - if(i > MAX_MOD) { - return -EINVAL; - } - - num = sscanf(page, "%15s %s %d", tmp, inst_tab[i].modname, &inst_tab[i].counter); - if (num != 3) { - err("Invalid command format, translated no commands\n"); - goto err; - } - - if (inst_tab[i].counter == 0) { - err("Needn't to attach %s\n", inst_tab[i].modname); - goto err; - } - - inst_tab[i].kprobes = (struct kprobe*)kmalloc(inst_tab[i].counter*(sizeof(struct kprobe)), GFP_KERNEL); - if(inst_tab[i].kprobes == NULL) { - err("No memory @ %s\n", __FUNCTION__); - goto err; - } - - mod_index = i; - ins_index = 0; - return 0; -err: - inst_tab[i].modname[0] = '\0'; - inst_tab[i].counter = 0; - return -EINVAL; -} - -void add_ins(const char *page) +int add_ins(const char *page) { + struct inst_rec *inst; char tmp[16]; int num=0; unsigned long addr=0; - struct module *mod; num = sscanf(page, "%15s %lu", tmp, &addr); if (num != 2) { err("Invalid command format, translated no commands\n"); - return; - } - if (ins_index > inst_tab[mod_index].counter - 1) { - err("Exceed address table!\n"); - return; - } - mod = get_module((const char *)(inst_tab[mod_index].modname)); - if (!mod) { - err("Can not get module, not be loaded?\n"); - return; - } - dbg("module_core:%#lx\toff_set:%ld\n",(unsigned long)mod->module_core, addr); - inst_tab[mod_index].kprobes[ins_index].addr = (kprobe_opcode_t *)(addr + mod->module_core); - inst_tab[mod_index].kprobes[ins_index].pre_handler = pre_probe_handler; - inst_tab[mod_index].kprobes[ins_index].post_handler = post_probe_handler; - inst_tab[mod_index].kprobes[ins_index].fault_handler = NULL; - if ( register_kprobe(&(inst_tab[mod_index].kprobes[ins_index])) < 0 ) - { - err("register_kprobe failed @ %s\n", __FUNCTION__); - return; - } - ins_index++; - return; -} -int detach_module(const char *page) -{ - int num=0; - int i=0; - int j=0; - char tmp[16]; - char modname[256]; - - num = sscanf(page, "%15s %s", tmp, modname); - if (num != 2) { - err("Invalid command format, translated no commands\n"); - return 0; + return -EINVAL; } - for(i=0;i<MAX_MOD;i++){ - if(!strcmp(inst_tab[i].modname, modname)) { - break; - } - } - if(i > MAX_MOD) { - return -EINVAL; + inst=(struct inst_rec *)kmalloc(sizeof(struct inst_rec), GFP_KERNEL); + if (!inst) { + err("Allocate memory failed.\n"); + return -ENOMEM; } - - for(j=0;j<inst_tab[i].counter;j++) { - unregister_kprobe(&(inst_tab[i].kprobes[j])); - } - inst_tab[i].counter = 0; - inst_tab[i].modname[0] = '\0'; - if (inst_tab[i].kprobes) + + inst->kprobe.addr = (kprobe_opcode_t *)addr; + inst->kprobe.pre_handler = pre_probe_handler; + inst->kprobe.post_handler = post_probe_handler; + inst->kprobe.fault_handler = NULL; + if ( register_kprobe(&(inst->kprobe)) < 0 ) { - kfree(inst_tab[i].kprobes); + kfree(inst); + err("register_kprobe failed @ %s\n", __FUNCTION__); + return -EINVAL; } + + list_add(&inst->list, &inst_rec_head); return 0; } static ssize_t ctl_show(struct interceptor * p, char * page, size_t count, loff_t off) { - int i=0; - int n=0; - int j; - if (off) - return 0; - n += sprintf (page, "Module\tInstructions\n"); - while (inst_tab[i].modname[0]!='\0' && i < MAX_MOD) { - n += sprintf (page+n, "%s\t%d\n", inst_tab[i].modname, inst_tab[i].counter); - for(j=0;j<inst_tab[i].counter;j++){ - n += sprintf (page+n, "addr:\t%#lx\n", (unsigned long)inst_tab[i].kprobes[j].addr); - } - i++; - } - return n; + return 0; } static ssize_t ctl_store(struct interceptor * p, const char * page, @@ -580,66 +486,46 @@ { char ctl[16]; int num; + int error=0; if (off) return 0; + down(&dbp_sem); num = sscanf(page, "%15s", ctl); if (!num) { err("Invalid command format, translated no commands\n"); - return count; + error = -EINVAL; + goto err; } if (!strncmp(ctl, "add", 3)) { - down(&dbp_sem); - if (!in_used) { + error = add_ins(page); + if(error==0){ up(&dbp_sem); - err("Use attach first.\n"); return count; + } else { + goto err; } - add_ins(page); - up(&dbp_sem); - return count; } - if (!strncmp(ctl, "attach", 6)) { - down(&dbp_sem); - if (in_used) { - up(&dbp_sem); - err("FI_DBP is busy.(Attaching %s)\n", inst_tab[mod_index].modname); - return count; - } - if(attach_module(page)==0) - in_used++; - up(&dbp_sem); - return count; - } + if (!strncmp(ctl, "clear", 5)) { + struct inst_rec *inst; - if (!strncmp(ctl, "end", 3)) { - down(&dbp_sem); - if (!in_used) { - up(&dbp_sem); - err("No attaching action to be ended.\n"); - return count; + while (!list_empty(&inst_rec_head)) { + inst=list_entry(inst_rec_head.next, struct inst_rec, list); + list_del(&inst->list); + unregister_kprobe(&inst->kprobe); + kfree(inst); } - in_used--; - up(&dbp_sem); - return count; - } - - if (!strncmp(ctl, "detach", 6)) { - down(&dbp_sem); - if (in_used) { - up(&dbp_sem); - err("FI_DBP is busy.(Attaching %s)\n", inst_tab[mod_index].modname); + up(&dbp_sem); return count; - } - detach_module(page); - up(&dbp_sem); - return count; } err("Unknow command %s\n", page); - return count; + error = -EINVAL; +err: + up(&dbp_sem); + return error; } static struct interceptor_attribute attr_ctl = { @@ -657,8 +543,6 @@ static int __init dbp_start(void) { - int i; - if (fi_register_interceptor(&dbp_interceptor)) { dbg("Failed to register DBP Interceptor"); return -EINVAL; @@ -666,31 +550,21 @@ sysfs_create_file(&dbp_interceptor.kobj, &attr_ctl.attr); - for (i=0;i<MAX_MOD;i++) { - inst_tab[i].modname[0]='\0'; - } - EXPORT_NO_SYMBOLS; return 0; } static void __exit dbp_stop(void) { - int i; - int j; + struct inst_rec *inst; - for(i=0;i<MAX_MOD;i++) - { - for(j=0;j<inst_tab[i].counter;j++) { - unregister_kprobe(&(inst_tab[i].kprobes[j])); - } - inst_tab[i].counter = 0; - inst_tab[i].modname[0] = '\0'; - if (inst_tab[i].kprobes) - { - kfree(inst_tab[i].kprobes); - } + if (!list_empty(&inst_rec_head)) { + inst=list_entry(inst_rec_head.next, struct inst_rec, list); + list_del(&inst->list); + unregister_kprobe(&inst->kprobe); + kfree(inst); } + sysfs_remove_file(&dbp_interceptor.kobj, &attr_ctl.attr); fi_unregister_interceptor(&dbp_interceptor); return; diff -Nru a/include/linux/module.h b/include/linux/module.h --- a/include/linux/module.h Tue Jan 7 16:43:10 2003 +++ b/include/linux/module.h Tue Jan 7 16:43:10 2003 @@ -315,7 +315,6 @@ /* For extable.c to search modules' exception tables. */ const struct exception_table_entry *search_module_extables(unsigned long addr); -extern struct module *get_module(const char *modname); #else /* !CONFIG_MODULES... */ #define EXPORT_SYMBOL(sym) #define EXPORT_SYMBOL_GPL(sym) @@ -360,8 +359,6 @@ { return NULL; } - -static inline struct module *get_module(const char *modname){ return NULL; } #endif /* CONFIG_MODULES */ #ifdef MODULE diff -Nru a/kernel/module.c b/kernel/module.c --- a/kernel/module.c Tue Jan 7 16:43:10 2003 +++ b/kernel/module.c Tue Jan 7 16:43:10 2003 @@ -128,16 +128,6 @@ return NULL; } -struct module *get_module(const char *name) -{ - struct module *mod; - down(&module_mutex); - mod = find_module(name); - up(&module_mutex); - return mod; -} -EXPORT_SYMBOL_GPL(get_module); - #ifdef CONFIG_MODULE_UNLOAD /* Init the unload section of the module. */ static void module_unload_init(struct module *mod) @@ -1432,6 +1422,7 @@ seq_printf(m, "%s %lu", mod->name, mod->init_size + mod->core_size); print_unload_info(m, mod); + seq_printf(m, " %p", mod->module_core); seq_printf(m, "\n"); return 0; } Your Sincerely, Stanley Wang SW Engineer, Intel Corporation. Intel China Software Lab. Tel: 021-52574545 ext. 1171 iNet: 8-752-1171 Opinions expressed are those of the author and do not represent Intel Corporation |