Merge branch 'work.openat2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-2.6-microblaze.git] / fs / proc / base.c
index ee97dd3..c7c6427 100644 (file)
@@ -94,6 +94,8 @@
 #include <linux/sched/debug.h>
 #include <linux/sched/stat.h>
 #include <linux/posix-timers.h>
+#include <linux/time_namespace.h>
+#include <linux/resctrl.h>
 #include <trace/events/oom.h>
 #include "internal.h"
 #include "fd.h"
@@ -1533,6 +1535,96 @@ static const struct file_operations proc_pid_sched_autogroup_operations = {
 
 #endif /* CONFIG_SCHED_AUTOGROUP */
 
+#ifdef CONFIG_TIME_NS
+static int timens_offsets_show(struct seq_file *m, void *v)
+{
+       struct task_struct *p;
+
+       p = get_proc_task(file_inode(m->file));
+       if (!p)
+               return -ESRCH;
+       proc_timens_show_offsets(p, m);
+
+       put_task_struct(p);
+
+       return 0;
+}
+
+static ssize_t timens_offsets_write(struct file *file, const char __user *buf,
+                                   size_t count, loff_t *ppos)
+{
+       struct inode *inode = file_inode(file);
+       struct proc_timens_offset offsets[2];
+       char *kbuf = NULL, *pos, *next_line;
+       struct task_struct *p;
+       int ret, noffsets;
+
+       /* Only allow < page size writes at the beginning of the file */
+       if ((*ppos != 0) || (count >= PAGE_SIZE))
+               return -EINVAL;
+
+       /* Slurp in the user data */
+       kbuf = memdup_user_nul(buf, count);
+       if (IS_ERR(kbuf))
+               return PTR_ERR(kbuf);
+
+       /* Parse the user data */
+       ret = -EINVAL;
+       noffsets = 0;
+       for (pos = kbuf; pos; pos = next_line) {
+               struct proc_timens_offset *off = &offsets[noffsets];
+               int err;
+
+               /* Find the end of line and ensure we don't look past it */
+               next_line = strchr(pos, '\n');
+               if (next_line) {
+                       *next_line = '\0';
+                       next_line++;
+                       if (*next_line == '\0')
+                               next_line = NULL;
+               }
+
+               err = sscanf(pos, "%u %lld %lu", &off->clockid,
+                               &off->val.tv_sec, &off->val.tv_nsec);
+               if (err != 3 || off->val.tv_nsec >= NSEC_PER_SEC)
+                       goto out;
+               noffsets++;
+               if (noffsets == ARRAY_SIZE(offsets)) {
+                       if (next_line)
+                               count = next_line - kbuf;
+                       break;
+               }
+       }
+
+       ret = -ESRCH;
+       p = get_proc_task(inode);
+       if (!p)
+               goto out;
+       ret = proc_timens_set_offset(file, p, offsets, noffsets);
+       put_task_struct(p);
+       if (ret)
+               goto out;
+
+       ret = count;
+out:
+       kfree(kbuf);
+       return ret;
+}
+
+static int timens_offsets_open(struct inode *inode, struct file *filp)
+{
+       return single_open(filp, timens_offsets_show, inode);
+}
+
+static const struct file_operations proc_timens_offsets_operations = {
+       .open           = timens_offsets_open,
+       .read           = seq_read,
+       .write          = timens_offsets_write,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+#endif /* CONFIG_TIME_NS */
+
 static ssize_t comm_write(struct file *file, const char __user *buf,
                                size_t count, loff_t *offset)
 {
@@ -3014,6 +3106,9 @@ static const struct pid_entry tgid_base_stuff[] = {
 #endif
 #ifdef CONFIG_SCHED_AUTOGROUP
        REG("autogroup",  S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
+#endif
+#ifdef CONFIG_TIME_NS
+       REG("timens_offsets",  S_IRUGO|S_IWUSR, proc_timens_offsets_operations),
 #endif
        REG("comm",      S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
 #ifdef CONFIG_HAVE_ARCH_TRACEHOOK
@@ -3059,6 +3154,9 @@ static const struct pid_entry tgid_base_stuff[] = {
 #endif
 #ifdef CONFIG_CGROUPS
        ONE("cgroup",  S_IRUGO, proc_cgroup_show),
+#endif
+#ifdef CONFIG_PROC_CPU_RESCTRL
+       ONE("cpu_resctrl_groups", S_IRUGO, proc_resctrl_show),
 #endif
        ONE("oom_score",  S_IRUGO, proc_oom_score),
        REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
@@ -3459,6 +3557,9 @@ static const struct pid_entry tid_base_stuff[] = {
 #endif
 #ifdef CONFIG_CGROUPS
        ONE("cgroup",  S_IRUGO, proc_cgroup_show),
+#endif
+#ifdef CONFIG_PROC_CPU_RESCTRL
+       ONE("cpu_resctrl_groups", S_IRUGO, proc_resctrl_show),
 #endif
        ONE("oom_score", S_IRUGO, proc_oom_score),
        REG("oom_adj",   S_IRUGO|S_IWUSR, proc_oom_adj_operations),