From: Alexander Aksenov Date: Wed, 28 Oct 2015 18:43:12 +0000 (+0300) Subject: [IMPROVE] Modern kernels (> 3.16) support X-Git-Tag: submit/tizen/20161124.145503~49 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F64893%2F4;p=kernel%2Fswap-modules.git [IMPROVE] Modern kernels (> 3.16) support Issue: Great amount of changes in kernel interface, differences between arch-dependent symbols and definitions. Solutions: - Add necessary includes and definitions for getnstimeofday() (changed interface and declaration location); - Replace f_dentry with f_path.dentry (f_dentry definition was removed); - Replace instruction_pointer() definition with regs->pc for ARM64 (it is casted to unsinged long, so, is treated as simple number); - Replace hlist_add_after() by version-dependent definition (now it is hlist_add_behind() in kernel); - Replace dereference of task->real_start_time with definition (on recent kernels its type was changed); - Redefined __get_cpu_var() for modern kernels (it was removed from kernel); - Make kernel version-dependent .map/.unmap methods for pipe_buf_operations; - Add necessary include for using splice.h; - Replace strict_strtoul() with kstrtoul() (strict_strtoul() was removed); Change-Id: Id4d5ca4f809b6e13f18614bc0266d6f54d4c47fd Signed-off-by: Alexander Aksenov --- diff --git a/driver/device_driver.c b/driver/device_driver.c index 16a0085..f06b0f1 100644 --- a/driver/device_driver.c +++ b/driver/device_driver.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -394,8 +395,10 @@ static void swap_device_page_release(struct splice_pipe_desc *spd, static const struct pipe_buf_operations swap_device_pipe_buf_ops = { .can_merge = 0, +#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 14, 0) .map = generic_pipe_buf_map, .unmap = generic_pipe_buf_unmap, +#endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(3, 14, 0) */ .confirm = generic_pipe_buf_confirm, .release = swap_device_pipe_buf_release, .steal = generic_pipe_buf_steal, diff --git a/driver/driver_to_buffer.c b/driver/driver_to_buffer.c index 909b3b1..3ddd19c 100644 --- a/driver/driver_to_buffer.c +++ b/driver/driver_to_buffer.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include diff --git a/driver/us_interaction.c b/driver/us_interaction.c index b668f00..32f9bcb 100644 --- a/driver/us_interaction.c +++ b/driver/us_interaction.c @@ -70,7 +70,11 @@ int us_interaction_send_msg(const void *data, size_t size) msg->len = size; memcpy(msg->data, data, msg->len); +#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 14, 0) ret = cn_netlink_send(msg, CN_DAEMON_GROUP, GFP_ATOMIC); +#else /* LINUX_VERSION_CODE <= KERNEL_VERSION(3, 14, 0) */ + ret = cn_netlink_send(msg, 0, CN_DAEMON_GROUP, GFP_ATOMIC); +#endif /* LINUX_VERSION_CODE <= KERNEL_VERSION(3, 14, 0) */ if (ret < 0) goto fail_send; kfree(msg); diff --git a/driver/us_interaction.h b/driver/us_interaction.h index 9e9ec79..66f6343 100644 --- a/driver/us_interaction.h +++ b/driver/us_interaction.h @@ -30,6 +30,8 @@ #ifndef __US_INTERACTION_H__ #define __US_INTERACTION_H__ +#include + #ifdef CONFIG_CONNECTOR int us_interaction_create(void); diff --git a/energy/energy.c b/energy/energy.c index 6eb863c..8dcaad9 100644 --- a/energy/energy.c +++ b/energy/energy.c @@ -332,8 +332,8 @@ static int check_file(int fd) file = fget(fd); if (file) { int magic = 0; - if (file->f_dentry && file->f_dentry->d_sb) - magic = file->f_dentry->d_sb->s_magic; + if (file->f_path.dentry && file->f_path.dentry->d_sb) + magic = file->f_path.dentry->d_sb->s_magic; fput(file); diff --git a/energy/lcd/lcd_base.c b/energy/lcd/lcd_base.c index 627ccb2..018fe7b 100644 --- a/energy/lcd/lcd_base.c +++ b/energy/lcd/lcd_base.c @@ -60,7 +60,7 @@ int read_val(const char *path) buf[ret >= buf_len ? buf_len - 1 : ret] = '\0'; - ret = strict_strtoul(buf, 0, &val); + ret = kstrtoul(buf, 0, &val); if (ret) return ret; diff --git a/fbiprobe/fbiprobe.c b/fbiprobe/fbiprobe.c index 535921c..ebb3e25 100644 --- a/fbiprobe/fbiprobe.c +++ b/fbiprobe/fbiprobe.c @@ -204,7 +204,7 @@ static struct vm_area_struct *find_vma_exe_by_dentry(struct mm_struct *mm, /* TODO FILTER vma */ for (vma = mm->mmap; vma; vma = vma->vm_next) { if (vma->vm_file && - (vma->vm_file->f_dentry == dentry)) + (vma->vm_file->f_path.dentry == dentry)) /* found */ goto exit; } diff --git a/kprobe/swap_kprobes.h b/kprobe/swap_kprobes.h index 303dfdb..973aa28 100644 --- a/kprobe/swap_kprobes.h +++ b/kprobe/swap_kprobes.h @@ -46,13 +46,6 @@ #include -#ifdef CONFIG_ARM - -#define regs_return_value(regs) ((regs)->ARM_r0) - -#endif - - /* kprobe_status settings */ /** Kprobe hit active */ #define KPROBE_HIT_ACTIVE 0x00000001 diff --git a/kprobe/swap_kprobes_deps.c b/kprobe/swap_kprobes_deps.c index 7a8a008..7ef1056 100644 --- a/kprobe/swap_kprobes_deps.c +++ b/kprobe/swap_kprobes_deps.c @@ -607,7 +607,11 @@ long __get_user_pages_uprobe(struct task_struct *tsk, struct mm_struct *mm, unsigned int fault_flags = 0; /* For mlock, just skip the stack guard page. */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0) + if (foll_flags & FOLL_POPULATE) { +#else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0) */ if (foll_flags & FOLL_MLOCK) { +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0) */ if (stack_guard_page(vma, start)) goto next_page; } diff --git a/kprobe/swap_kprobes_deps.h b/kprobe/swap_kprobes_deps.h index e555ecb..bfc58e4 100644 --- a/kprobe/swap_kprobes_deps.h +++ b/kprobe/swap_kprobes_deps.h @@ -33,6 +33,7 @@ #define _SWAP_KPROBES_DEPS_H #include /* LINUX_VERSION_CODE, KERNEL_VERSION() */ +#include #include #include #include @@ -155,5 +156,14 @@ unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr, unsigned long flags, unsigned long pgoff); #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */ +#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) +#define swap_hlist_add_after(node, prev) hlist_add_behind(node, prev) +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */ +#define swap_hlist_add_after(node, prev) hlist_add_after(node, prev) +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */ + +#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 18, 0) +#define __get_cpu_var(var) (*this_cpu_ptr(&(var))) +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 18, 0) */ #endif /* _SWAP_KPROBES_DEPS_H */ diff --git a/ks_features/file_ops.c b/ks_features/file_ops.c index 5769e3c..cf5a8a0 100644 --- a/ks_features/file_ops.c +++ b/ks_features/file_ops.c @@ -331,7 +331,7 @@ static int fops_fcheck(struct task_struct *task, struct file *file) if (!task || !file) return -EINVAL; - dentry = file->f_dentry; + dentry = file->f_path.dentry; /* check if it is a regular file */ if (!S_ISREG(dentry->d_inode->i_mode)) @@ -379,7 +379,7 @@ static int generic_entry_handler(struct kretprobe_instance *ri, ksf_msg_file_entry(fd, fprobe->subtype, fops_fpath(file, buf, PATH_LEN)); - priv->dentry = file->f_dentry; + priv->dentry = file->f_path.dentry; } else { priv->dentry = NULL; } @@ -551,7 +551,7 @@ static int lock_entry_handler(struct kretprobe_instance *ri, ksf_msg_file_entry(fd, subtype, filepath); } - priv->dentry = file->f_dentry; + priv->dentry = file->f_path.dentry; priv->subtype = subtype; } else { priv->dentry = NULL; @@ -583,7 +583,7 @@ static int filp_close_entry_handler(struct kretprobe_instance *ri, struct file *file = fops_karg(struct file *, regs, 0); if (rp && file && file_count(file)) { - struct dentry *dentry = file->f_dentry; + struct dentry *dentry = file->f_path.dentry; /* release the file if it is going to be removed soon */ if (dentry && fops_dcount(dentry) == 2) diff --git a/ks_features/file_ops.h b/ks_features/file_ops.h index 56e113d..8be3c19 100644 --- a/ks_features/file_ops.h +++ b/ks_features/file_ops.h @@ -2,6 +2,7 @@ #define __FILE_OPS__ #include +#include bool file_ops_is_init(void); int file_ops_init(void); diff --git a/parser/usm_msg.c b/parser/usm_msg.c index 6abcaa5..958ebef 100644 --- a/parser/usm_msg.c +++ b/parser/usm_msg.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include /* ... check_vma() */ @@ -65,6 +66,16 @@ static void kmem_info_fill(struct kmem_info *info, struct mm_struct *mm) #endif /* CONFIG_arch */ } +static inline struct timespec get_task_start_time(struct task_struct *task) +{ +#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) + return ns_to_timespec(task->real_start_time); +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */ + return task->real_start_time; +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */ +} + + static int pack_path(void *data, size_t size, struct file *file) { @@ -217,7 +228,7 @@ static struct vm_area_struct *find_vma_exe_by_dentry(struct mm_struct *mm, for (vma = mm->mmap; vma; vma = vma->vm_next) { if (vma->vm_file && (vma->vm_flags & VM_EXEC) && - (vma->vm_file->f_dentry == dentry)) + (vma->vm_file->f_path.dentry == dentry)) goto out; } @@ -255,7 +266,7 @@ static int pack_proc_info_bottom(void *data, size_t size, return -ENOMEM; getboottime(&boot_time); - start_time = timespec_add(boot_time, task->real_start_time); + start_time = timespec_add(boot_time, get_task_start_time(task)); pib->ppid = task->real_parent->tgid; pib->start_time = swap_msg_spec2time(&start_time); diff --git a/preload/preload_control.c b/preload/preload_control.c index c4a07ef..79a45f0 100644 --- a/preload/preload_control.c +++ b/preload/preload_control.c @@ -147,7 +147,7 @@ static struct dentry *__get_caller_dentry(struct task_struct *task, if (unlikely(vma == NULL || vma->vm_file == NULL)) goto get_caller_dentry_fail; - return vma->vm_file->f_dentry; + return vma->vm_file->f_path.dentry; get_caller_dentry_fail: diff --git a/preload/preload_handlers.c b/preload/preload_handlers.c index 578cebf..ac2a745 100644 --- a/preload/preload_handlers.c +++ b/preload/preload_handlers.c @@ -137,9 +137,9 @@ static unsigned long __do_preload_entry(struct uretprobe_instance *ri, /* jump only if caller is instumented and it is not a system lib - * this leads to some errors */ if (cvma != NULL && cvma->vm_file != NULL && - cvma->vm_file->f_dentry != NULL) { + cvma->vm_file->f_path.dentry != NULL) { - struct dentry *dentry = cvma->vm_file->f_dentry; + struct dentry *dentry = cvma->vm_file->f_path.dentry; struct pd_t *pd = preload_pd_get_parent_pd(hd); if (!preload_control_check_dentry_is_ignored(dentry) && diff --git a/preload/preload_module.c b/preload/preload_module.c index 0071a7b..6b0cda9 100644 --- a/preload/preload_module.c +++ b/preload/preload_module.c @@ -220,7 +220,7 @@ static struct vm_area_struct *__get_linker_vma(struct task_struct *task) for (vma = task->mm->mmap; vma; vma = vma->vm_next) { if (vma->vm_file && vma->vm_flags & VM_EXEC - && vma->vm_file->f_dentry == ld_info->dentry) { + && vma->vm_file->f_path.dentry == ld_info->dentry) { preload_storage_put_linker_info(ld_info); return vma; } @@ -322,8 +322,7 @@ static int mmap_entry_handler(struct kretprobe_instance *ri, if (!file) return 0; - - dentry = file->f_dentry; + dentry = file->f_path.dentry; if (dentry == NULL) return 0; diff --git a/preload/preload_pd.c b/preload/preload_pd.c index 17aa742..c358545 100644 --- a/preload/preload_pd.c +++ b/preload/preload_pd.c @@ -36,7 +36,8 @@ static inline bool check_vma(struct vm_area_struct *vma, struct dentry *dentry) { struct file *file = vma->vm_file; - return (file && (vma->vm_flags & VM_EXEC) && (file->f_dentry == dentry)); + return (file && (vma->vm_flags & VM_EXEC) && + (file->f_path.dentry == dentry)); } static inline unsigned long __get_loader_base(struct pd_t *pd) diff --git a/sampler/sampler_hrtimer.c b/sampler/sampler_hrtimer.c index c0e669e..b445212 100644 --- a/sampler/sampler_hrtimer.c +++ b/sampler/sampler_hrtimer.c @@ -30,6 +30,8 @@ #include +#include +#include #include "sampler_timers.h" diff --git a/uprobe/swap_uprobes.c b/uprobe/swap_uprobes.c index 6320e58..b7db15b 100644 --- a/uprobe/swap_uprobes.c +++ b/uprobe/swap_uprobes.c @@ -1041,7 +1041,7 @@ void urinst_info_get_current_hlist(struct hlist_head *head, bool recycle) urinst = urinst_info_create(ri); if (urinst) { if (last) - hlist_add_after(last, &urinst->hlist); + swap_hlist_add_after(last, &urinst->hlist); else hlist_add_head(&urinst->hlist, head); diff --git a/us_manager/pf/proc_filters.c b/us_manager/pf/proc_filters.c index ee9cf4c..241a216 100644 --- a/us_manager/pf/proc_filters.c +++ b/us_manager/pf/proc_filters.c @@ -40,7 +40,7 @@ static int check_dentry(struct task_struct *task, struct dentry *dentry) return 0; for (vma = mm->mmap; vma; vma = vma->vm_next) { - if (check_vma(vma) && vma->vm_file->f_dentry == dentry) + if (check_vma(vma) && vma->vm_file->f_path.dentry == dentry) return 1; } diff --git a/us_manager/sspt/sspt_proc.c b/us_manager/sspt/sspt_proc.c index 71d7f89..b0b0a86 100644 --- a/us_manager/sspt/sspt_proc.c +++ b/us_manager/sspt/sspt_proc.c @@ -327,7 +327,7 @@ void sspt_proc_install_page(struct sspt_proc *proc, unsigned long page_addr) vma = find_vma_intersection(mm, page_addr, page_addr + 1); if (vma && check_vma(vma)) { - struct dentry *dentry = vma->vm_file->f_dentry; + struct dentry *dentry = vma->vm_file->f_path.dentry; struct sspt_file *file = sspt_proc_find_file(proc, dentry); if (file) { struct sspt_page *page; @@ -356,7 +356,7 @@ void sspt_proc_install(struct sspt_proc *proc) for (vma = mm->mmap; vma; vma = vma->vm_next) { if (check_vma(vma)) { - struct dentry *dentry = vma->vm_file->f_dentry; + struct dentry *dentry = vma->vm_file->f_path.dentry; struct sspt_file *file = sspt_proc_find_file(proc, dentry); if (file) { diff --git a/webprobe/webprobe.c b/webprobe/webprobe.c index 9f4e983..942754d 100644 --- a/webprobe/webprobe.c +++ b/webprobe/webprobe.c @@ -99,7 +99,7 @@ static int web_entry_handler(struct uretprobe_instance *ri, vma = find_vma_intersection(current->mm, page_vaddr, page_vaddr + 1); if (vma && check_vma(vma)) { unsigned long addr = vaddr - vma->vm_start; - struct dentry *d = vma->vm_file->f_dentry; + struct dentry *d = vma->vm_file->f_path.dentry; if (addr == web_prof_addr(WILL_EXECUTE) && d == web_prof_lib_dentry()) { @@ -133,7 +133,7 @@ static int web_ret_handler(struct uretprobe_instance *ri, struct pt_regs *regs) vma = find_vma_intersection(current->mm, page_vaddr, page_vaddr + 1); if (vma && check_vma(vma)) { unsigned long addr = vaddr - vma->vm_start; - struct dentry *d = vma->vm_file->f_dentry; + struct dentry *d = vma->vm_file->f_path.dentry; if (addr == web_prof_addr(INSPSERVER_START) && d == web_prof_lib_dentry()) { diff --git a/writer/swap_msg.h b/writer/swap_msg.h index 068885d..af1b42a 100644 --- a/writer/swap_msg.h +++ b/writer/swap_msg.h @@ -23,10 +23,20 @@ #ifndef _SWAP_MSG_H #define _SWAP_MSG_H +#include +#include + + +#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) + +#include /* Needed by timekeeping.h */ +#include /* Now getnstimeofday() is here */ + +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */ #include -#include +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */ enum swap_msg_id { MSG_PROC_INFO = 0x0001,