From: Alexander Aksenov Date: Thu, 2 Mar 2017 09:24:07 +0000 (+0300) Subject: Make shared get/put dentry functions in SWAP dependencies X-Git-Tag: submit/tizen/20170815.123151~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8e1e8f3438070d6b83d95e6318f9372295f1fe9;p=platform%2Fkernel%2Fswap-modules.git Make shared get/put dentry functions in SWAP dependencies Change-Id: I0d15391cad845cad349675f5cfbeadc1e85ffd2d Signed-off-by: Alexander Aksenov --- diff --git a/got_patcher/gt_module.c b/got_patcher/gt_module.c index 40b8ea8..af6b233 100644 --- a/got_patcher/gt_module.c +++ b/got_patcher/gt_module.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "gt.h" @@ -104,24 +105,6 @@ static inline struct pd_t *_get_process_data(struct uretprobe *rp) return lpd_get(proc); } -static struct dentry *get_dentry(const char *filepath) -{ - struct path path; - struct dentry *dentry = NULL; - - if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) { - dentry = dget(path.dentry); - path_put(&path); - } - - return dentry; -} - -static void put_dentry(struct dentry *dentry) -{ - dput(dentry); -} - @@ -556,7 +539,7 @@ static void _destroy_linker_probe_el_no_lock(struct l_probe_el *l_probe) put_pf_group(l_probe->pfg); if (l_probe->task_id == GT_SET_BY_DENTRY && l_probe->dentry != NULL) - put_dentry(l_probe->dentry); + swap_put_dentry(l_probe->dentry); if (l_probe->task_id == GT_SET_BY_ID && l_probe->id != NULL) kfree(l_probe->id); @@ -736,7 +719,7 @@ int gtm_set_linker_path(char *path) { struct dentry *dentry; - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) return -EINVAL; @@ -744,9 +727,9 @@ int gtm_set_linker_path(char *path) if (_linker_fixup.dentry != NULL || _linker_reloc.dentry != NULL) { if (_linker_fixup.dentry != NULL) - put_dentry(_linker_fixup.dentry); + swap_put_dentry(_linker_fixup.dentry); else - put_dentry(_linker_reloc.dentry); + swap_put_dentry(_linker_reloc.dentry); } _linker_fixup.dentry = dentry; @@ -799,7 +782,7 @@ int gtm_add_by_path(char *path) struct l_probe_el *l_probe; int ret; - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) return -EINVAL; @@ -832,7 +815,7 @@ add_by_path_put_pfg: put_pf_group(pfg); add_by_path_put_dentry: - put_dentry(dentry); + swap_put_dentry(dentry); return ret; } @@ -926,7 +909,7 @@ int gtm_del_by_path(char *path) struct dentry *dentry; int ret = 0; - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) return -EINVAL; @@ -1011,16 +994,16 @@ int gtm_set_handler_path(char *path) int ret; /* We use get_dentry only once, so use put dentry also only once */ - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) return -EINVAL; if (_handler_fixup.dentry != NULL || _handler_reloc.dentry != NULL) { if (_handler_fixup.dentry != NULL) - put_dentry(_handler_fixup.dentry); + swap_put_dentry(_handler_fixup.dentry); else - put_dentry(_handler_reloc.dentry); + swap_put_dentry(_handler_reloc.dentry); } _handler_fixup.dentry = dentry; @@ -1053,12 +1036,12 @@ int gtm_set_pthread_path(char *path) { struct dentry *dentry; - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) return -EINVAL; if (_pthread_init.dentry != NULL) - put_dentry(_pthread_init.dentry); + swap_put_dentry(_pthread_init.dentry); _pthread_init.dentry = dentry; @@ -1103,9 +1086,9 @@ static void gtm_exit(void) if (_handler_fixup.dentry != NULL || _handler_reloc.dentry != NULL) { if (_handler_fixup.dentry != NULL) - put_dentry(_handler_fixup.dentry); + swap_put_dentry(_handler_fixup.dentry); else - put_dentry(_handler_reloc.dentry); + swap_put_dentry(_handler_reloc.dentry); } } diff --git a/loader/loader_debugfs.c b/loader/loader_debugfs.c index 95592fc..8611cbc 100644 --- a/loader/loader_debugfs.c +++ b/loader/loader_debugfs.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "loader_defs.h" #include "loader_debugfs.h" #include "loader_module.h" @@ -48,7 +49,7 @@ static void set_loader_file(char *path) { __loader_info.path = path; dentry_lock(); - __loader_info.dentry = get_dentry(__loader_info.path); + __loader_info.dentry = swap_get_dentry(__loader_info.path); dentry_unlock(); } @@ -77,7 +78,7 @@ static void clean_loader_info(void) dentry_lock(); if (__loader_info.dentry != NULL) - put_dentry(__loader_info.dentry); + swap_put_dentry(__loader_info.dentry); __loader_info.dentry = NULL; __loader_info.offset = 0; diff --git a/loader/loader_module.c b/loader/loader_module.c index 3bf56e0..6b832ed 100644 --- a/loader/loader_module.c +++ b/loader/loader_module.c @@ -41,13 +41,6 @@ static int __loader_cbs_start_h = -1; static int __loader_cbs_stop_h = -1; -static struct dentry *__get_dentry(struct dentry *dentry) -{ - atomic_inc(&dentry_balance); - return dget(dentry); -} - - bool loader_module_is_running(void) { @@ -88,25 +81,6 @@ void loader_module_set_not_ready(void) __loader_status = SWAP_LOADER_NOT_READY; } -struct dentry *get_dentry(const char *filepath) -{ - struct path path; - struct dentry *dentry = NULL; - - if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) { - dentry = __get_dentry(path.dentry); - path_put(&path); - } - - return dentry; -} - -void put_dentry(struct dentry *dentry) -{ - atomic_dec(&dentry_balance); - dput(dentry); -} - static inline void __prepare_ujump(struct uretprobe_instance *ri, struct pt_regs *regs, unsigned long vaddr) diff --git a/loader/loader_storage.c b/loader/loader_storage.c index de33076..a916833 100644 --- a/loader/loader_storage.c +++ b/loader/loader_storage.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "loader_defs.h" #include "loader_module.h" #include "loader_storage.h" @@ -36,7 +37,7 @@ static inline int __add_handler(char *path) struct bin_info_el *bin; int ret = 0; - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (!dentry) { ret = -ENOENT; goto add_handler_out; @@ -71,7 +72,7 @@ add_handler_fail_free_bin: kfree(bin); add_handler_fail_release_dentry: - put_dentry(dentry); + swap_put_dentry(dentry); add_handler_out: return ret; @@ -80,7 +81,7 @@ add_handler_out: static inline void __remove_handler(struct bin_info_el *bin) { list_del(&bin->list); - put_dentry(bin->dentry); + swap_put_dentry(bin->dentry); kfree(bin->path); kfree(bin); } @@ -116,7 +117,7 @@ static inline int __init_linker_info(char *path) goto init_linker_fail; } - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (!dentry) { ret = -ENOENT; goto init_linker_fail_free; @@ -142,7 +143,7 @@ static inline void __drop_linker_info(void) __linker_info.path = NULL; if (__linker_info.dentry) - put_dentry(__linker_info.dentry); + swap_put_dentry(__linker_info.dentry); __linker_info.dentry = NULL; } diff --git a/preload/preload_control.c b/preload/preload_control.c index 3ce44b3..019d8a1 100644 --- a/preload/preload_control.c +++ b/preload/preload_control.c @@ -4,6 +4,7 @@ #include #include +#include #include "preload.h" #include "preload_module.h" @@ -83,7 +84,7 @@ static void __free_binaries(struct list_desc *tl) list_for_each_entry_safe(p, n, &rm_head, list) { list_del(&p->list); - put_dentry(p->dentry); + swap_put_dentry(p->dentry); __free_binary(p); } } @@ -224,7 +225,7 @@ enum preload_call_type pc_call_type(struct sspt_ip *ip, void *caller) int pc_add_instrumented_binary(char *filename) { - struct dentry *dentry = get_dentry(filename); + struct dentry *dentry = swap_get_dentry(filename); int res = 0; if (dentry == NULL) @@ -232,7 +233,7 @@ int pc_add_instrumented_binary(char *filename) res = __add_binary(dentry, filename, &target); if (res != 0) - put_dentry(dentry); + swap_put_dentry(dentry); return res > 0 ? 0 : res; } @@ -246,7 +247,7 @@ int pc_clean_instrumented_bins(void) int pc_add_ignored_binary(char *filename) { - struct dentry *dentry = get_dentry(filename); + struct dentry *dentry = swap_get_dentry(filename); int res = 0; if (dentry == NULL) @@ -254,7 +255,7 @@ int pc_add_ignored_binary(char *filename) res = __add_binary(dentry, filename, &ignored); if (res != 0) - put_dentry(dentry); + swap_put_dentry(dentry); return res > 0 ? 0 : res; } diff --git a/preload/preload_module.c b/preload/preload_module.c index a58ffec..8c6f38d 100644 --- a/preload/preload_module.c +++ b/preload/preload_module.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include "preload.h" @@ -405,24 +406,6 @@ static int get_call_type_handler(struct uprobe *p, struct pt_regs *regs) -struct dentry *get_dentry(const char *filepath) -{ - struct path path; - struct dentry *dentry = NULL; - - if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) { - dentry = dget(path.dentry); - path_put(&path); - } - - return dentry; -} - -void put_dentry(struct dentry *dentry) -{ - dput(dentry); -} - int pm_get_caller_init(struct sspt_ip *ip) { struct uprobe *up = &ip->uprobe; @@ -468,9 +451,9 @@ int pm_set_handler(char *path) int ret; if (handler_dentry != NULL) - put_dentry(handler_dentry); + swap_put_dentry(handler_dentry); - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) { printk(KERN_WARNING PRELOAD_PREFIX "Error! Cannot get handler %s\n", @@ -548,7 +531,7 @@ static void pm_exit(void) pd_exit(); if (handler_dentry != NULL) - put_dentry(handler_dentry); + swap_put_dentry(handler_dentry); } SWAP_LIGHT_INIT_MODULE(NULL, pm_init, pm_exit, NULL, NULL); diff --git a/preload/preload_module.h b/preload/preload_module.h index b3f5c78..92e840f 100644 --- a/preload/preload_module.h +++ b/preload/preload_module.h @@ -15,7 +15,4 @@ int pm_write_msg_init(struct sspt_ip *ip); void pm_write_msg_exit(struct sspt_ip *ip); int pm_set_handler(char *path); -struct dentry *get_dentry(const char *filepath); -void put_dentry(struct dentry *dentry); - #endif /* __PRELOAD_MODULE_H__ */ diff --git a/uihv/uihv_module.c b/uihv/uihv_module.c index b4d51c7..eeb8ab3 100644 --- a/uihv/uihv_module.c +++ b/uihv/uihv_module.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -66,24 +67,6 @@ static int uihv_data_inst(void) return 0; } -struct dentry *get_dentry(const char *filepath) -{ - struct path path; - struct dentry *dentry = NULL; - - if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) { - dentry = dget(path.dentry); - path_put(&path); - } - - return dentry; -} - -void put_dentry(struct dentry *dentry) -{ - dput(dentry); -} - int uihv_data_set(const char *app_path, unsigned long main_addr) { struct dentry *dentry; @@ -110,9 +93,9 @@ int uihv_set_handler(char *path) int ret; if (uihv_dentry != NULL) - put_dentry(uihv_dentry); + swap_put_dentry(uihv_dentry); - dentry = get_dentry(path); + dentry = swap_get_dentry(path); if (dentry == NULL) { printk(KERN_WARNING UIHV_PREFIX "Error! Cannot get handler %s\n", path); @@ -235,7 +218,7 @@ static int uihv_init(void) static void uihv_exit(void) { if (uihv_dentry != NULL) - put_dentry(uihv_dentry); + swap_put_dentry(uihv_dentry); uihv_dfs_exit(); } diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index 892d4d8..a1adc1f 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -231,30 +232,6 @@ static void subsequent_install(struct task_struct *task, up_write(&task->mm->mmap_sem); } -struct dentry *dentry_get(const char *path) -{ - struct dentry *d; - struct path st_path; - - if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) { - pr_err("failed to lookup dentry for path %s!\n", path); - return NULL; - } - - d = st_path.dentry; - dget(d); - path_put(&st_path); - - return d; -} -EXPORT_SYMBOL_GPL(dentry_get); - -void dentry_put(struct dentry *d) -{ - dput(d); -} -EXPORT_SYMBOL_GPL(dentry_put); - /** * @brief Get dentry struct by path @@ -266,7 +243,7 @@ struct dentry *dentry_by_path(const char *path) { struct dentry *d; - d = dentry_get(path); + d = swap_get_dentry(path); if (d) dput(d); diff --git a/us_manager/pf/pf_group.h b/us_manager/pf/pf_group.h index 20da025..8bc4d55 100644 --- a/us_manager/pf/pf_group.h +++ b/us_manager/pf/pf_group.h @@ -42,10 +42,8 @@ struct pfg_msg_cb { }; -/* FIXME: create and use get_dentry() and put_dentry() */ +/* FIXME: use swap_get_dentry() and swap_put_dentry() */ struct dentry *dentry_by_path(const char *path); -struct dentry *dentry_get(const char *path); -void dentry_put(struct dentry *d); struct pf_group *get_pf_group_by_dentry(struct dentry *dentry, void *priv); struct pf_group *get_pf_group_by_tgid(pid_t tgid, void *priv); diff --git a/us_manager/us_common_file.h b/us_manager/us_common_file.h new file mode 100644 index 0000000..f18b6ce --- /dev/null +++ b/us_manager/us_common_file.h @@ -0,0 +1,49 @@ +/* + * SWAP uprobe manager + * modules/us_manager/us_manager_common_file.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Copyright (C) Samsung Electronics, 2017 + * + * 2017 Alexander Aksenov: SWAP us_manager implement + * + */ + +#ifndef __US_MANAGER_COMMON_FILE_H__ +#define __US_MANAGER_COMMON_FILE_H__ + +#include +#include + +static inline struct dentry *swap_get_dentry(const char *filepath) +{ + struct path path; + struct dentry *dentry = NULL; + + if (kern_path(filepath, LOOKUP_FOLLOW, &path) == 0) { + dentry = dget(path.dentry); + path_put(&path); + } + + return dentry; +} + +static inline void swap_put_dentry(struct dentry *dentry) +{ + dput(dentry); +} + +#endif /* __US_MANAGER_COMMON_FILE_H__ */