[IMPROVE] Modern kernels (> 3.16) support 93/64893/4
authorAlexander Aksenov <a.aksenov@samsung.com>
Wed, 28 Oct 2015 18:43:12 +0000 (21:43 +0300)
committerDmitry Kovalenko <d.kovalenko@samsung.com>
Wed, 6 Apr 2016 11:04:37 +0000 (14:04 +0300)
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 <a.aksenov@samsung.com>
23 files changed:
driver/device_driver.c
driver/driver_to_buffer.c
driver/us_interaction.c
driver/us_interaction.h
energy/energy.c
energy/lcd/lcd_base.c
fbiprobe/fbiprobe.c
kprobe/swap_kprobes.h
kprobe/swap_kprobes_deps.c
kprobe/swap_kprobes_deps.h
ks_features/file_ops.c
ks_features/file_ops.h
parser/usm_msg.c
preload/preload_control.c
preload/preload_handlers.c
preload/preload_module.c
preload/preload_pd.c
sampler/sampler_hrtimer.c
uprobe/swap_uprobes.c
us_manager/pf/proc_filters.c
us_manager/sspt/sspt_proc.c
webprobe/webprobe.c
writer/swap_msg.h

index 16a0085..f06b0f1 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/wait.h>
 #include <linux/workqueue.h>
 #include <linux/uaccess.h>
+#include <linux/version.h>
 
 #include <ksyms/ksyms.h>
 #include <master/swap_initializer.h>
@@ -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,
index 909b3b1..3ddd19c 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <linux/string.h>
 #include <linux/slab.h>
+#include <linux/fs.h>
 #include <linux/splice.h>
 #include <linux/uaccess.h>
 #include <linux/spinlock.h>
index b668f00..32f9bcb 100644 (file)
@@ -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);
index 9e9ec79..66f6343 100644 (file)
@@ -30,6 +30,8 @@
 #ifndef __US_INTERACTION_H__
 #define __US_INTERACTION_H__
 
+#include <linux/version.h>
+
 #ifdef CONFIG_CONNECTOR
 
 int us_interaction_create(void);
index 6eb863c..8dcaad9 100644 (file)
@@ -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);
 
index 627ccb2..018fe7b 100644 (file)
@@ -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;
 
index 535921c..ebb3e25 100644 (file)
@@ -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;
        }
index 303dfdb..973aa28 100644 (file)
 #include <swap-asm/swap_kprobes.h>
 
 
-#ifdef CONFIG_ARM
-
-#define regs_return_value(regs)     ((regs)->ARM_r0)
-
-#endif
-
-
 /* kprobe_status settings */
 /** Kprobe hit active */
 #define KPROBE_HIT_ACTIVE      0x00000001
index 7a8a008..7ef1056 100644 (file)
@@ -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;
                                }
index e555ecb..bfc58e4 100644 (file)
@@ -33,6 +33,7 @@
 #define _SWAP_KPROBES_DEPS_H
 
 #include <linux/version.h>     /* LINUX_VERSION_CODE, KERNEL_VERSION() */
+#include <linux/mm.h>
 #include <linux/hugetlb.h>
 #include <linux/mempolicy.h>
 #include <linux/highmem.h>
@@ -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 */
index 5769e3c..cf5a8a0 100644 (file)
@@ -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)
index 56e113d..8be3c19 100644 (file)
@@ -2,6 +2,7 @@
 #define __FILE_OPS__
 
 #include <linux/types.h>
+#include <kprobe/swap_kprobes_deps.h>
 
 bool file_ops_is_init(void);
 int file_ops_init(void);
index 6abcaa5..958ebef 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/sched.h>
 #include <linux/dcache.h>
 #include <linux/fdtable.h>
+#include <linux/version.h>
 #include <writer/swap_msg.h>
 #include <master/swap_deps.h>
 #include <us_manager/sspt/sspt.h>      /* ... 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);
index c4a07ef..79a45f0 100644 (file)
@@ -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:
 
index 578cebf..ac2a745 100644 (file)
@@ -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) &&
index 0071a7b..6b0cda9 100644 (file)
@@ -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;
 
index 17aa742..c358545 100644 (file)
@@ -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)
index c0e669e..b445212 100644 (file)
@@ -30,6 +30,8 @@
 
 
 #include <linux/types.h>
+#include <linux/version.h>
+#include <kprobe/swap_kprobes_deps.h>
 #include "sampler_timers.h"
 
 
index 6320e58..b7db15b 100644 (file)
@@ -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);
 
index ee9cf4c..241a216 100644 (file)
@@ -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;
        }
 
index 71d7f89..b0b0a86 100644 (file)
@@ -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) {
index 9f4e983..942754d 100644 (file)
@@ -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()) {
index 068885d..af1b42a 100644 (file)
 #ifndef _SWAP_MSG_H
 #define _SWAP_MSG_H
 
+#include <linux/version.h>
+#include <linux/types.h>
+
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0)
+
+#include <linux/ktime.h>       /* Needed by timekeeping.h */
+#include <linux/timekeeping.h> /* Now getnstimeofday() is here */
+
+#else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */
 
 #include <linux/time.h>
-#include <linux/types.h>
 
+#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */
 
 enum swap_msg_id {
        MSG_PROC_INFO                   = 0x0001,