Re: [PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #12]

2018-12-06 Thread Andrei Vagin
On Sun, Nov 18, 2018 at 08:23:42PM -0800, Andrei Vagin wrote:
> On Fri, Sep 21, 2018 at 05:33:01PM +0100, David Howells wrote:
> > @@ -1993,57 +2009,53 @@ int cgroup_setup_root(struct cgroup_root *root, u16 
> > ss_mask, int ref_flags)
> > return ret;
> >  }
> >  
> > -struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
> > -  struct cgroup_root *root, unsigned long magic,
> > -  struct cgroup_namespace *ns)
> > +int cgroup_do_get_tree(struct fs_context *fc)
> >  {
> > -   struct dentry *dentry;
> > -   bool new_sb;
> > +   struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
> > +   int ret;
> >  
> > -   dentry = kernfs_mount(fs_type, flags, root->kf_root, magic, _sb);
> > +   ctx->kfc.root = ctx->root->kf_root;
> > +
> > +   ret = kernfs_get_tree(fc);
> > +   if (ret < 0)
> > +   goto out_cgrp;
> >  
> > /*
> >  * In non-init cgroup namespace, instead of root cgroup's dentry,
> >  * we return the dentry corresponding to the cgroupns->root_cgrp.
> >  */
> > -   if (!IS_ERR(dentry) && ns != _cgroup_ns) {
> > +   if (ctx->ns != _cgroup_ns) {
> > struct dentry *nsdentry;
> > struct cgroup *cgrp;
> >  
> > mutex_lock(_mutex);
> > spin_lock_irq(_set_lock);
> >  
> > -   cgrp = cset_cgroup_from_root(ns->root_cset, root);
> > +   cgrp = cset_cgroup_from_root(ctx->ns->root_cset, ctx->root);
> >  
> > spin_unlock_irq(_set_lock);
> > mutex_unlock(_mutex);
> >  
> > -   nsdentry = kernfs_node_dentry(cgrp->kn, dentry->d_sb);
> > -   dput(dentry);
> > -   dentry = nsdentry;
> > +   nsdentry = kernfs_node_dentry(cgrp->kn, fc->root->d_sb);
> > +   if (IS_ERR(nsdentry))
> > +   return PTR_ERR(nsdentry);
> > +   dput(fc->root);
> > +   fc->root = nsdentry;
> > }
> >  
> > -   if (IS_ERR(dentry) || !new_sb)
> > -   cgroup_put(>cgrp);
> 
> I don't see where this cgroup_put() has been moved.

David, have you looked at this problem? It isn't fixed in linux-next
yet.

https://travis-ci.org/avagin/linux/jobs/463960763

Thanks,
Andrei

> 
> With this patch, the next script works only once, on the second attempt
> it hangs up on mounting a cgroup file system.
> 
> This is the only suspicious place in this patch what I have found.
> 
> [root@fc24 ~]# cat fs-vs-cg 
> d=$(mktemp -d /tmp/cg.XX)
> mkdir $d/a
> mkdir $d/b
> mount -t cgroup -o none,name= xxx $d/a
> mount -t cgroup -o none,name= xxx $d/b
> umount $d/a
> umount $d/b
> 
> [root@fc24 ~]# unshare -m --propagation private bash -x fs-vs-cg
> ++ mktemp -d /tmp/cg.XX
> + d=/tmp/cg.yUfagS
> + mkdir /tmp/cg.yUfagS/a
> + mkdir /tmp/cg.yUfagS/b
> + mount -t cgroup -o none,name= xxx /tmp/cg.yUfagS/a
> + mount -t cgroup -o none,name= xxx /tmp/cg.yUfagS/b
> + umount /tmp/cg.yUfagS/a
> + umount /tmp/cg.yUfagS/b
> [root@fc24 ~]# unshare -m --propagation private bash -x fs-vs-cg
> ++ mktemp -d /tmp/cg.XX
> + d=/tmp/cg.ippWUn
> + mkdir /tmp/cg.ippWUn/a
> + mkdir /tmp/cg.ippWUn/b
> + mount -t cgroup -o none,name= xxx /tmp/cg.ippWUn/a
> ^Z
> [1]+  Stopped unshare -m --propagation private bash -x 
> fs-vs-cg
> 
> [root@fc24 ~]# ps
>   PID TTY  TIME CMD
>   556 pts/000:00:00 bash
>   591 pts/000:00:00 bash
>   595 pts/000:00:00 mount
>   596 pts/000:00:00 ps
> 
> [root@fc24 ~]# bg
> [1]+ unshare -m --propagation private bash -x fs-vs-cg &
> 
> [root@fc24 ~]# cat /proc/595/stack 
> [<0>] msleep+0x38/0x40
> [<0>] cgroup1_get_tree+0x4e1/0x72c
> [<0>] vfs_get_tree+0x5e/0x140
> [<0>] do_mount+0x326/0xc70
> [<0>] ksys_mount+0xba/0xd0
> [<0>] __x64_sys_mount+0x21/0x30
> [<0>] do_syscall_64+0x60/0x210
> [<0>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
> [<0>] 0x
> 


Re: [PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #12]

2018-12-06 Thread Andrei Vagin
On Sun, Nov 18, 2018 at 08:23:42PM -0800, Andrei Vagin wrote:
> On Fri, Sep 21, 2018 at 05:33:01PM +0100, David Howells wrote:
> > @@ -1993,57 +2009,53 @@ int cgroup_setup_root(struct cgroup_root *root, u16 
> > ss_mask, int ref_flags)
> > return ret;
> >  }
> >  
> > -struct dentry *cgroup_do_mount(struct file_system_type *fs_type, int flags,
> > -  struct cgroup_root *root, unsigned long magic,
> > -  struct cgroup_namespace *ns)
> > +int cgroup_do_get_tree(struct fs_context *fc)
> >  {
> > -   struct dentry *dentry;
> > -   bool new_sb;
> > +   struct cgroup_fs_context *ctx = cgroup_fc2context(fc);
> > +   int ret;
> >  
> > -   dentry = kernfs_mount(fs_type, flags, root->kf_root, magic, _sb);
> > +   ctx->kfc.root = ctx->root->kf_root;
> > +
> > +   ret = kernfs_get_tree(fc);
> > +   if (ret < 0)
> > +   goto out_cgrp;
> >  
> > /*
> >  * In non-init cgroup namespace, instead of root cgroup's dentry,
> >  * we return the dentry corresponding to the cgroupns->root_cgrp.
> >  */
> > -   if (!IS_ERR(dentry) && ns != _cgroup_ns) {
> > +   if (ctx->ns != _cgroup_ns) {
> > struct dentry *nsdentry;
> > struct cgroup *cgrp;
> >  
> > mutex_lock(_mutex);
> > spin_lock_irq(_set_lock);
> >  
> > -   cgrp = cset_cgroup_from_root(ns->root_cset, root);
> > +   cgrp = cset_cgroup_from_root(ctx->ns->root_cset, ctx->root);
> >  
> > spin_unlock_irq(_set_lock);
> > mutex_unlock(_mutex);
> >  
> > -   nsdentry = kernfs_node_dentry(cgrp->kn, dentry->d_sb);
> > -   dput(dentry);
> > -   dentry = nsdentry;
> > +   nsdentry = kernfs_node_dentry(cgrp->kn, fc->root->d_sb);
> > +   if (IS_ERR(nsdentry))
> > +   return PTR_ERR(nsdentry);
> > +   dput(fc->root);
> > +   fc->root = nsdentry;
> > }
> >  
> > -   if (IS_ERR(dentry) || !new_sb)
> > -   cgroup_put(>cgrp);
> 
> I don't see where this cgroup_put() has been moved.

David, have you looked at this problem? It isn't fixed in linux-next
yet.

https://travis-ci.org/avagin/linux/jobs/463960763

Thanks,
Andrei

> 
> With this patch, the next script works only once, on the second attempt
> it hangs up on mounting a cgroup file system.
> 
> This is the only suspicious place in this patch what I have found.
> 
> [root@fc24 ~]# cat fs-vs-cg 
> d=$(mktemp -d /tmp/cg.XX)
> mkdir $d/a
> mkdir $d/b
> mount -t cgroup -o none,name= xxx $d/a
> mount -t cgroup -o none,name= xxx $d/b
> umount $d/a
> umount $d/b
> 
> [root@fc24 ~]# unshare -m --propagation private bash -x fs-vs-cg
> ++ mktemp -d /tmp/cg.XX
> + d=/tmp/cg.yUfagS
> + mkdir /tmp/cg.yUfagS/a
> + mkdir /tmp/cg.yUfagS/b
> + mount -t cgroup -o none,name= xxx /tmp/cg.yUfagS/a
> + mount -t cgroup -o none,name= xxx /tmp/cg.yUfagS/b
> + umount /tmp/cg.yUfagS/a
> + umount /tmp/cg.yUfagS/b
> [root@fc24 ~]# unshare -m --propagation private bash -x fs-vs-cg
> ++ mktemp -d /tmp/cg.XX
> + d=/tmp/cg.ippWUn
> + mkdir /tmp/cg.ippWUn/a
> + mkdir /tmp/cg.ippWUn/b
> + mount -t cgroup -o none,name= xxx /tmp/cg.ippWUn/a
> ^Z
> [1]+  Stopped unshare -m --propagation private bash -x 
> fs-vs-cg
> 
> [root@fc24 ~]# ps
>   PID TTY  TIME CMD
>   556 pts/000:00:00 bash
>   591 pts/000:00:00 bash
>   595 pts/000:00:00 mount
>   596 pts/000:00:00 ps
> 
> [root@fc24 ~]# bg
> [1]+ unshare -m --propagation private bash -x fs-vs-cg &
> 
> [root@fc24 ~]# cat /proc/595/stack 
> [<0>] msleep+0x38/0x40
> [<0>] cgroup1_get_tree+0x4e1/0x72c
> [<0>] vfs_get_tree+0x5e/0x140
> [<0>] do_mount+0x326/0xc70
> [<0>] ksys_mount+0xba/0xd0
> [<0>] __x64_sys_mount+0x21/0x30
> [<0>] do_syscall_64+0x60/0x210
> [<0>] entry_SYSCALL_64_after_hwframe+0x49/0xbe
> [<0>] 0x
> 


Re: [PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #12]

2018-11-18 Thread Andrei Vagin
On Fri, Sep 21, 2018 at 05:33:01PM +0100, David Howells wrote:
> Make kernfs support superblock creation/mount/remount with fs_context.
> 
> This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
> be made to support fs_context also.
> 
> Notes:
> 
>  (1) A kernfs_fs_context struct is created to wrap fs_context and the
>  kernfs mount parameters are moved in here (or are in fs_context).
> 
>  (2) kernfs_mount{,_ns}() are made into kernfs_get_tree().  The extra
>  namespace tag parameter is passed in the context if desired
> 
>  (3) kernfs_free_fs_context() is provided as a destructor for the
>  kernfs_fs_context struct, but for the moment it does nothing except
>  get called in the right places.
> 
>  (4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
>  pass, but possibly this should be done anyway in case someone wants to
>  add a parameter in future.
> 
>  (5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
>  the cgroup v1 and v2 mount parameters are all moved there.
> 
>  (6) cgroup1 parameter parsing error messages are now handled by invalf(),
>  which allows userspace to collect them directly.
> 
>  (7) cgroup1 parameter cleanup is now done in the context destructor rather
>  than in the mount/get_tree and remount functions.
> 
> Weirdies:
> 
>  (*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
>  but then uses the resulting pointer after dropping the locks.  I'm
>  told this is okay and needs commenting.
> 
>  (*) The cgroup refcount web.  This really needs documenting.
> 
>  (*) cgroup2 only has one root?
> 
> Add a suggestion from Thomas Gleixner in which the RDT enablement code is
> placed into its own function.
> 
> Signed-off-by: David Howells 
> cc: Greg Kroah-Hartman 
> cc: Tejun Heo 
> cc: Li Zefan 
> cc: Johannes Weiner 
> cc: cgro...@vger.kernel.org
> cc: fenghua...@intel.com
> ---
> 
>  arch/x86/kernel/cpu/intel_rdt.h  |   15 +
>  arch/x86/kernel/cpu/intel_rdt_rdtgroup.c |  183 ++--
>  fs/kernfs/mount.c|   88 
>  fs/sysfs/mount.c |   67 --
>  include/linux/cgroup.h   |3 
>  include/linux/kernfs.h   |   39 ++-
>  kernel/cgroup/cgroup-internal.h  |   50 +++-
>  kernel/cgroup/cgroup-v1.c|  345 
> --
>  kernel/cgroup/cgroup.c   |  264 +++
>  kernel/cgroup/cpuset.c   |4 
>  10 files changed, 640 insertions(+), 418 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
> index 4e588f36228f..1461adc2c5e8 100644
> --- a/arch/x86/kernel/cpu/intel_rdt.h
> +++ b/arch/x86/kernel/cpu/intel_rdt.h
> @@ -33,6 +33,21 @@
>  #define RMID_VAL_ERROR   BIT_ULL(63)
>  #define RMID_VAL_UNAVAIL BIT_ULL(62)
>  
> +
> +struct rdt_fs_context {
> + struct kernfs_fs_contextkfc;
> + boolenable_cdpl2;
> + boolenable_cdpl3;
> + boolenable_mba_mbps;
> +};
> +
> +static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
> +{
> + struct kernfs_fs_context *kfc = fc->fs_private;
> +
> + return container_of(kfc, struct rdt_fs_context, kfc);
> +}
> +
>  DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
>  
>  /**
> diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c 
> b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
> index d6cb04c3a28b..34733a221669 100644
> --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
> +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -1707,43 +1708,6 @@ static void cdp_disable_all(void)
>   cdpl2_disable();
>  }
>  
> -static int parse_rdtgroupfs_options(char *data)
> -{
> - char *token, *o = data;
> - int ret = 0;
> -
> - while ((token = strsep(, ",")) != NULL) {
> - if (!*token) {
> - ret = -EINVAL;
> - goto out;
> - }
> -
> - if (!strcmp(token, "cdp")) {
> - ret = cdpl3_enable();
> - if (ret)
> - goto out;
> - } else if (!strcmp(token, "cdpl2")) {
> - ret = cdpl2_enable();
> - if (ret)
> - goto out;
> - } else if (!strcmp(token, "mba_MBps")) {
> - ret = set_mba_sc(true);
> - if (ret)
> - goto out;
> - } else {
> - ret = -EINVAL;
> - goto out;
> - }
> - }
> -
> - return 0;
> -
> -out:
> - pr_err("Invalid mount option \"%s\"\n", token);
> -
> - return ret;

Re: [PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #12]

2018-11-18 Thread Andrei Vagin
On Fri, Sep 21, 2018 at 05:33:01PM +0100, David Howells wrote:
> Make kernfs support superblock creation/mount/remount with fs_context.
> 
> This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
> be made to support fs_context also.
> 
> Notes:
> 
>  (1) A kernfs_fs_context struct is created to wrap fs_context and the
>  kernfs mount parameters are moved in here (or are in fs_context).
> 
>  (2) kernfs_mount{,_ns}() are made into kernfs_get_tree().  The extra
>  namespace tag parameter is passed in the context if desired
> 
>  (3) kernfs_free_fs_context() is provided as a destructor for the
>  kernfs_fs_context struct, but for the moment it does nothing except
>  get called in the right places.
> 
>  (4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
>  pass, but possibly this should be done anyway in case someone wants to
>  add a parameter in future.
> 
>  (5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
>  the cgroup v1 and v2 mount parameters are all moved there.
> 
>  (6) cgroup1 parameter parsing error messages are now handled by invalf(),
>  which allows userspace to collect them directly.
> 
>  (7) cgroup1 parameter cleanup is now done in the context destructor rather
>  than in the mount/get_tree and remount functions.
> 
> Weirdies:
> 
>  (*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
>  but then uses the resulting pointer after dropping the locks.  I'm
>  told this is okay and needs commenting.
> 
>  (*) The cgroup refcount web.  This really needs documenting.
> 
>  (*) cgroup2 only has one root?
> 
> Add a suggestion from Thomas Gleixner in which the RDT enablement code is
> placed into its own function.
> 
> Signed-off-by: David Howells 
> cc: Greg Kroah-Hartman 
> cc: Tejun Heo 
> cc: Li Zefan 
> cc: Johannes Weiner 
> cc: cgro...@vger.kernel.org
> cc: fenghua...@intel.com
> ---
> 
>  arch/x86/kernel/cpu/intel_rdt.h  |   15 +
>  arch/x86/kernel/cpu/intel_rdt_rdtgroup.c |  183 ++--
>  fs/kernfs/mount.c|   88 
>  fs/sysfs/mount.c |   67 --
>  include/linux/cgroup.h   |3 
>  include/linux/kernfs.h   |   39 ++-
>  kernel/cgroup/cgroup-internal.h  |   50 +++-
>  kernel/cgroup/cgroup-v1.c|  345 
> --
>  kernel/cgroup/cgroup.c   |  264 +++
>  kernel/cgroup/cpuset.c   |4 
>  10 files changed, 640 insertions(+), 418 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
> index 4e588f36228f..1461adc2c5e8 100644
> --- a/arch/x86/kernel/cpu/intel_rdt.h
> +++ b/arch/x86/kernel/cpu/intel_rdt.h
> @@ -33,6 +33,21 @@
>  #define RMID_VAL_ERROR   BIT_ULL(63)
>  #define RMID_VAL_UNAVAIL BIT_ULL(62)
>  
> +
> +struct rdt_fs_context {
> + struct kernfs_fs_contextkfc;
> + boolenable_cdpl2;
> + boolenable_cdpl3;
> + boolenable_mba_mbps;
> +};
> +
> +static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
> +{
> + struct kernfs_fs_context *kfc = fc->fs_private;
> +
> + return container_of(kfc, struct rdt_fs_context, kfc);
> +}
> +
>  DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
>  
>  /**
> diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c 
> b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
> index d6cb04c3a28b..34733a221669 100644
> --- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
> +++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -1707,43 +1708,6 @@ static void cdp_disable_all(void)
>   cdpl2_disable();
>  }
>  
> -static int parse_rdtgroupfs_options(char *data)
> -{
> - char *token, *o = data;
> - int ret = 0;
> -
> - while ((token = strsep(, ",")) != NULL) {
> - if (!*token) {
> - ret = -EINVAL;
> - goto out;
> - }
> -
> - if (!strcmp(token, "cdp")) {
> - ret = cdpl3_enable();
> - if (ret)
> - goto out;
> - } else if (!strcmp(token, "cdpl2")) {
> - ret = cdpl2_enable();
> - if (ret)
> - goto out;
> - } else if (!strcmp(token, "mba_MBps")) {
> - ret = set_mba_sc(true);
> - if (ret)
> - goto out;
> - } else {
> - ret = -EINVAL;
> - goto out;
> - }
> - }
> -
> - return 0;
> -
> -out:
> - pr_err("Invalid mount option \"%s\"\n", token);
> -
> - return ret;

[PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #12]

2018-09-21 Thread David Howells
Make kernfs support superblock creation/mount/remount with fs_context.

This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.

Notes:

 (1) A kernfs_fs_context struct is created to wrap fs_context and the
 kernfs mount parameters are moved in here (or are in fs_context).

 (2) kernfs_mount{,_ns}() are made into kernfs_get_tree().  The extra
 namespace tag parameter is passed in the context if desired

 (3) kernfs_free_fs_context() is provided as a destructor for the
 kernfs_fs_context struct, but for the moment it does nothing except
 get called in the right places.

 (4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
 pass, but possibly this should be done anyway in case someone wants to
 add a parameter in future.

 (5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
 the cgroup v1 and v2 mount parameters are all moved there.

 (6) cgroup1 parameter parsing error messages are now handled by invalf(),
 which allows userspace to collect them directly.

 (7) cgroup1 parameter cleanup is now done in the context destructor rather
 than in the mount/get_tree and remount functions.

Weirdies:

 (*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
 but then uses the resulting pointer after dropping the locks.  I'm
 told this is okay and needs commenting.

 (*) The cgroup refcount web.  This really needs documenting.

 (*) cgroup2 only has one root?

Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.

Signed-off-by: David Howells 
cc: Greg Kroah-Hartman 
cc: Tejun Heo 
cc: Li Zefan 
cc: Johannes Weiner 
cc: cgro...@vger.kernel.org
cc: fenghua...@intel.com
---

 arch/x86/kernel/cpu/intel_rdt.h  |   15 +
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c |  183 ++--
 fs/kernfs/mount.c|   88 
 fs/sysfs/mount.c |   67 --
 include/linux/cgroup.h   |3 
 include/linux/kernfs.h   |   39 ++-
 kernel/cgroup/cgroup-internal.h  |   50 +++-
 kernel/cgroup/cgroup-v1.c|  345 --
 kernel/cgroup/cgroup.c   |  264 +++
 kernel/cgroup/cpuset.c   |4 
 10 files changed, 640 insertions(+), 418 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
index 4e588f36228f..1461adc2c5e8 100644
--- a/arch/x86/kernel/cpu/intel_rdt.h
+++ b/arch/x86/kernel/cpu/intel_rdt.h
@@ -33,6 +33,21 @@
 #define RMID_VAL_ERROR BIT_ULL(63)
 #define RMID_VAL_UNAVAIL   BIT_ULL(62)
 
+
+struct rdt_fs_context {
+   struct kernfs_fs_contextkfc;
+   boolenable_cdpl2;
+   boolenable_cdpl3;
+   boolenable_mba_mbps;
+};
+
+static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
+{
+   struct kernfs_fs_context *kfc = fc->fs_private;
+
+   return container_of(kfc, struct rdt_fs_context, kfc);
+}
+
 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
 
 /**
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c 
b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index d6cb04c3a28b..34733a221669 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1707,43 +1708,6 @@ static void cdp_disable_all(void)
cdpl2_disable();
 }
 
-static int parse_rdtgroupfs_options(char *data)
-{
-   char *token, *o = data;
-   int ret = 0;
-
-   while ((token = strsep(, ",")) != NULL) {
-   if (!*token) {
-   ret = -EINVAL;
-   goto out;
-   }
-
-   if (!strcmp(token, "cdp")) {
-   ret = cdpl3_enable();
-   if (ret)
-   goto out;
-   } else if (!strcmp(token, "cdpl2")) {
-   ret = cdpl2_enable();
-   if (ret)
-   goto out;
-   } else if (!strcmp(token, "mba_MBps")) {
-   ret = set_mba_sc(true);
-   if (ret)
-   goto out;
-   } else {
-   ret = -EINVAL;
-   goto out;
-   }
-   }
-
-   return 0;
-
-out:
-   pr_err("Invalid mount option \"%s\"\n", token);
-
-   return ret;
-}
-
 /*
  * We don't allow rdtgroup directories to be created anywhere
  * except the root directory. Thus when looking for the rdtgroup
@@ -1815,13 +1779,27 @@ static int mkdir_mondata_all(struct kernfs_node 
*parent_kn,
 struct rdtgroup *prgrp,
  

[PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #12]

2018-09-21 Thread David Howells
Make kernfs support superblock creation/mount/remount with fs_context.

This requires that sysfs, cgroup and intel_rdt, which are built on kernfs,
be made to support fs_context also.

Notes:

 (1) A kernfs_fs_context struct is created to wrap fs_context and the
 kernfs mount parameters are moved in here (or are in fs_context).

 (2) kernfs_mount{,_ns}() are made into kernfs_get_tree().  The extra
 namespace tag parameter is passed in the context if desired

 (3) kernfs_free_fs_context() is provided as a destructor for the
 kernfs_fs_context struct, but for the moment it does nothing except
 get called in the right places.

 (4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to
 pass, but possibly this should be done anyway in case someone wants to
 add a parameter in future.

 (5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and
 the cgroup v1 and v2 mount parameters are all moved there.

 (6) cgroup1 parameter parsing error messages are now handled by invalf(),
 which allows userspace to collect them directly.

 (7) cgroup1 parameter cleanup is now done in the context destructor rather
 than in the mount/get_tree and remount functions.

Weirdies:

 (*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
 but then uses the resulting pointer after dropping the locks.  I'm
 told this is okay and needs commenting.

 (*) The cgroup refcount web.  This really needs documenting.

 (*) cgroup2 only has one root?

Add a suggestion from Thomas Gleixner in which the RDT enablement code is
placed into its own function.

Signed-off-by: David Howells 
cc: Greg Kroah-Hartman 
cc: Tejun Heo 
cc: Li Zefan 
cc: Johannes Weiner 
cc: cgro...@vger.kernel.org
cc: fenghua...@intel.com
---

 arch/x86/kernel/cpu/intel_rdt.h  |   15 +
 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c |  183 ++--
 fs/kernfs/mount.c|   88 
 fs/sysfs/mount.c |   67 --
 include/linux/cgroup.h   |3 
 include/linux/kernfs.h   |   39 ++-
 kernel/cgroup/cgroup-internal.h  |   50 +++-
 kernel/cgroup/cgroup-v1.c|  345 --
 kernel/cgroup/cgroup.c   |  264 +++
 kernel/cgroup/cpuset.c   |4 
 10 files changed, 640 insertions(+), 418 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_rdt.h b/arch/x86/kernel/cpu/intel_rdt.h
index 4e588f36228f..1461adc2c5e8 100644
--- a/arch/x86/kernel/cpu/intel_rdt.h
+++ b/arch/x86/kernel/cpu/intel_rdt.h
@@ -33,6 +33,21 @@
 #define RMID_VAL_ERROR BIT_ULL(63)
 #define RMID_VAL_UNAVAIL   BIT_ULL(62)
 
+
+struct rdt_fs_context {
+   struct kernfs_fs_contextkfc;
+   boolenable_cdpl2;
+   boolenable_cdpl3;
+   boolenable_mba_mbps;
+};
+
+static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
+{
+   struct kernfs_fs_context *kfc = fc->fs_private;
+
+   return container_of(kfc, struct rdt_fs_context, kfc);
+}
+
 DECLARE_STATIC_KEY_FALSE(rdt_enable_key);
 
 /**
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c 
b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index d6cb04c3a28b..34733a221669 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1707,43 +1708,6 @@ static void cdp_disable_all(void)
cdpl2_disable();
 }
 
-static int parse_rdtgroupfs_options(char *data)
-{
-   char *token, *o = data;
-   int ret = 0;
-
-   while ((token = strsep(, ",")) != NULL) {
-   if (!*token) {
-   ret = -EINVAL;
-   goto out;
-   }
-
-   if (!strcmp(token, "cdp")) {
-   ret = cdpl3_enable();
-   if (ret)
-   goto out;
-   } else if (!strcmp(token, "cdpl2")) {
-   ret = cdpl2_enable();
-   if (ret)
-   goto out;
-   } else if (!strcmp(token, "mba_MBps")) {
-   ret = set_mba_sc(true);
-   if (ret)
-   goto out;
-   } else {
-   ret = -EINVAL;
-   goto out;
-   }
-   }
-
-   return 0;
-
-out:
-   pr_err("Invalid mount option \"%s\"\n", token);
-
-   return ret;
-}
-
 /*
  * We don't allow rdtgroup directories to be created anywhere
  * except the root directory. Thus when looking for the rdtgroup
@@ -1815,13 +1779,27 @@ static int mkdir_mondata_all(struct kernfs_node 
*parent_kn,
 struct rdtgroup *prgrp,