Subject: 4.9.186 patch
From: Ghislain Adnet <gadnet@aqueos.com>
Date: Fri, 26 Jul 2019 13:00:43 +0200
Fri, 26 Jul 2019 13:00:43 +0200
hi,

  just FYI i use this patch delta to be applied on top of patch-4.9.159-vs2.3.9.8.diff.

  It pass the testfs testme the sysinfo proc is virtualized, the uptime is virtualized
and it survive a stress-ng test 
of several hours in guest without crash.

   hope that helps some people, let me know.

regards,
Ghislain.



diff -urp ./linux-4.9.186/fs/proc/stat.c ./linux-4.9.186.ok/fs/proc/stat.c
--- ./linux-4.9.186/fs/proc/stat.c      2019-07-26 12:55:07.908792014 +0200
+++ ./linux-4.9.186.ok/fs/proc/stat.c   2019-07-25 16:25:04.700229480 +0200
@@ -96,8 +96,8 @@ static int show_stat(struct seq_file *p,
        guest = guest_nice = 0;
        getboottime64(&boottime);
 
-       if (vx_flags(VXF_VIRT_UPTIME, 0))
-               vx_vsi_boottime64(&boottime);
+//     if (vx_flags(VXF_VIRT_UPTIME, 0))
+//             vx_vsi_boottime64(&boottime);
 
        if (virt_cpu)
                cpuset_cpus_allowed(current, cpus_allowed);
diff -urp ./linux-4.9.186/include/linux/timekeeping.h ./linux-4.9.186.ok/include/linux/timekeeping.h
--- ./linux-4.9.186/include/linux/timekeeping.h 2019-07-21 09:06:09.000000000 +0200
+++ ./linux-4.9.186.ok/include/linux/timekeeping.h      2019-07-25 16:25:04.732230923
+0200
@@ -2,6 +2,7 @@
 #define _LINUX_TIMEKEEPING_H
 
 #include <linux/errno.h>
+#include <linux/time.h>
 
 /* Included from linux/ktime.h */
 
@@ -186,6 +187,7 @@ extern ktime_t ktime_get_with_offset(enu
 extern ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs);
 extern ktime_t ktime_get_raw(void);
 extern u32 ktime_get_resolution_ns(void);
+extern ktime_t ktime_get_boottime(void);
 
 /**
  * ktime_get_real - get the real (wall-) time in ktime_t format
@@ -196,17 +198,6 @@ static inline ktime_t ktime_get_real(voi
 }
 
 /**
- * ktime_get_boottime - Returns monotonic time since boot in ktime_t format
- *
- * This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
- * time spent in suspend.
- */
-static inline ktime_t ktime_get_boottime(void)
-{
-       return ktime_get_with_offset(TK_OFFS_BOOT);
-}
-
-/**
  * ktime_get_clocktai - Returns the TAI time of day in ktime_t format
  */
 static inline ktime_t ktime_get_clocktai(void)
diff -urp ./linux-4.9.186/kernel/ptrace.c ./linux-4.9.186.ok/kernel/ptrace.c
--- ./linux-4.9.186/kernel/ptrace.c     2019-07-26 12:55:07.924792734 +0200
+++ ./linux-4.9.186.ok/kernel/ptrace.c  2019-07-25 16:25:04.732230923 +0200
@@ -336,6 +336,11 @@ ok:
            ((get_dumpable(mm) != SUID_DUMP_USER) &&
             !ptrace_has_cap(mm->user_ns, mode)))
            return -EPERM;
+        if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
+               return -EPERM;
+        if (!vx_check(task->xid, VS_IDENT) &&
+               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
+               return -EACCES;

        if (mode & PTRACE_MODE_SCHED)
                return 0;
diff -urp ./linux-4.9.186/kernel/sys.c ./linux-4.9.186.ok/kernel/sys.c
--- ./linux-4.9.186/kernel/sys.c        2019-07-26 12:55:07.928792915 +0200
+++ ./linux-4.9.186.ok/kernel/sys.c     2019-07-25 16:25:04.732230923 +0200
@@ -2339,7 +2339,14 @@ static int do_sysinfo(struct sysinfo *in

        get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);

-       info->procs = nr_threads;
+//     info->procs = nr_threads;
+        // if in vserver guest virtualize the result
+        if (vx_check(0, VS_ADMIN|VS_WATCH)) {
+               info->procs = nr_threads;
+        } else {
+               struct vx_info *vxi = current_vx_info();
+                info->procs = atomic_read(&vxi->cvirt.nr_threads);
+        }

        si_meminfo(info);
        si_swapinfo(info);
diff -urp ./linux-4.9.186/kernel/time/timekeeping.c ./linux-4.9.186.ok/kernel/time/timekeeping.c
--- ./linux-4.9.186/kernel/time/timekeeping.c   2019-07-26 12:55:07.928792915 +0200
+++ ./linux-4.9.186.ok/kernel/time/timekeeping.c        2019-07-25 16:25:04.760232185
+0200
@@ -24,6 +24,9 @@
 #include <linux/pvclock_gtod.h>
 #include <linux/compiler.h>
 #include <linux/vs_time.h>
+#include <linux/vs_base.h>
+#include <linux/vs_cvirt.h>
+#include <linux/vserver/context.h>

 #include "tick-internal.h"
 #include "ntp_internal.h"
@@ -747,6 +750,26 @@ u32 ktime_get_resolution_ns(void)
 }
 EXPORT_SYMBOL_GPL(ktime_get_resolution_ns);

+/**
+* ktime_get_boottime - Returns monotonic time since boot in ktime_t format
+*
+* This is similar to CLOCK_MONTONIC/ktime_get, but also includes the
+* time spent in suspend.
+*/
+ktime_t ktime_get_boottime(void)
+{
+
+    ktime_t boottime = ktime_get_with_offset(TK_OFFS_BOOT);
+       if (vx_flags(VXF_VIRT_UPTIME, 0) && !vx_check(0, VS_ADMIN|VS_WATCH)  ) {
+               struct vx_info *vxi = current_vx_info();
+               ktime_t bias_uptime = timespec_to_ktime(vxi->cvirt.bias_uptime);
+               boottime = ktime_sub(boottime, bias_uptime);
+    }
+    return boottime;
+}
+EXPORT_SYMBOL_GPL(ktime_get_boottime);
+
+
 static ktime_t *offsets[TK_OFFS_MAX] = {
        [TK_OFFS_REAL]  = &tk_core.timekeeper.offs_real,
        [TK_OFFS_BOOT]  = &tk_core.timekeeper.offs_boot,
@@ -2165,6 +2188,8 @@ void getboottime64(struct timespec64 *ts
        ktime_t t = ktime_sub(tk->offs_real, tk->offs_boot);

        *ts = ktime_to_timespec64(t);
+       if (vx_flags(VXF_VIRT_UPTIME, 0))
+               vx_vsi_boottime64(ts);
 }
 EXPORT_SYMBOL_GPL(getboottime64);