From patchwork Wed May 1 14:04:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Welty, Brian" X-Patchwork-Id: 10925109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05CA91390 for ; Wed, 1 May 2019 14:03:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8C4828C58 for ; Wed, 1 May 2019 14:03:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCADB28D34; Wed, 1 May 2019 14:03:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 69AE328CFE for ; Wed, 1 May 2019 14:03:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0376B89363; Wed, 1 May 2019 14:03:05 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 394568938C; Wed, 1 May 2019 14:03:03 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 May 2019 07:03:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,417,1549958400"; d="scan'208";a="145141398" Received: from nperf12.hd.intel.com ([10.127.88.161]) by fmsmga008.fm.intel.com with ESMTP; 01 May 2019 07:03:01 -0700 From: Brian Welty To: cgroups@vger.kernel.org, Tejun Heo , Li Zefan , Johannes Weiner , linux-mm@kvack.org, Michal Hocko , Vladimir Davydov , dri-devel@lists.freedesktop.org, David Airlie , Daniel Vetter , intel-gfx@lists.freedesktop.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , =?utf-8?q?Christian_K=C3=B6nig?= , Alex Deucher , ChunMing Zhou , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= Subject: [RFC PATCH 2/5] cgroup: Change kernfs_node for directories to store cgroup_subsys_state Date: Wed, 1 May 2019 10:04:35 -0400 Message-Id: <20190501140438.9506-3-brian.welty@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190501140438.9506-1-brian.welty@intel.com> References: <20190501140438.9506-1-brian.welty@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change the kernfs_node.priv to store the cgroup_subsys_state (CSS) pointer for directories, instead of storing cgroup pointer. This is done in order to support files within the cgroup associated with devices. We require of_css() to return the device-specific CSS pointer for these files. Cc: cgroups@vger.kernel.org Signed-off-by: Brian Welty --- kernel/cgroup/cgroup-v1.c | 10 ++++---- kernel/cgroup/cgroup.c | 48 +++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index c126b34fd4ff..4fa56cc2b99c 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -723,6 +723,7 @@ int proc_cgroupstats_show(struct seq_file *m, void *v) int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) { struct kernfs_node *kn = kernfs_node_from_dentry(dentry); + struct cgroup_subsys_state *css; struct cgroup *cgrp; struct css_task_iter it; struct task_struct *tsk; @@ -740,12 +741,13 @@ int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry) * @kn->priv is RCU safe. Let's do the RCU dancing. */ rcu_read_lock(); - cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv); - if (!cgrp || cgroup_is_dead(cgrp)) { + css = rcu_dereference(*(void __rcu __force **)&kn->priv); + if (!css || cgroup_is_dead(css->cgroup)) { rcu_read_unlock(); mutex_unlock(&cgroup_mutex); return -ENOENT; } + cgrp = css->cgroup; rcu_read_unlock(); css_task_iter_start(&cgrp->self, 0, &it); @@ -851,7 +853,7 @@ void cgroup1_release_agent(struct work_struct *work) static int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent, const char *new_name_str) { - struct cgroup *cgrp = kn->priv; + struct cgroup_subsys_state *css = kn->priv; int ret; if (kernfs_type(kn) != KERNFS_DIR) @@ -871,7 +873,7 @@ static int cgroup1_rename(struct kernfs_node *kn, struct kernfs_node *new_parent ret = kernfs_rename(kn, new_parent, new_name_str); if (!ret) - TRACE_CGROUP_PATH(rename, cgrp); + TRACE_CGROUP_PATH(rename, css->cgroup); mutex_unlock(&cgroup_mutex); diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 9b035e728941..1fe4fee502ea 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -595,12 +595,13 @@ static void cgroup_get_live(struct cgroup *cgrp) struct cgroup_subsys_state *of_css(struct kernfs_open_file *of) { - struct cgroup *cgrp = of->kn->parent->priv; + struct cgroup_subsys_state *css = of->kn->parent->priv; struct cftype *cft = of_cft(of); - /* FIXME this needs updating to lookup device-specific CSS */ - /* + * If the cft specifies a subsys and this is not a device file, + * then lookup the css, otherwise it is already correct. + * * This is open and unprotected implementation of cgroup_css(). * seq_css() is only called from a kernfs file operation which has * an active reference on the file. Because all the subsystem @@ -608,10 +609,9 @@ struct cgroup_subsys_state *of_css(struct kernfs_open_file *of) * the matching css from the cgroup's subsys table is guaranteed to * be and stay valid until the enclosing operation is complete. */ - if (cft->ss) - return rcu_dereference_raw(cgrp->subsys[cft->ss->id]); - else - return &cgrp->self; + if (cft->ss && !css->device) + css = rcu_dereference_raw(css->cgroup->subsys[cft->ss->id]); + return css; } EXPORT_SYMBOL_GPL(of_css); @@ -1524,12 +1524,14 @@ static u16 cgroup_calc_subtree_ss_mask(u16 subtree_control, u16 this_ss_mask) */ void cgroup_kn_unlock(struct kernfs_node *kn) { + struct cgroup_subsys_state *css; struct cgroup *cgrp; if (kernfs_type(kn) == KERNFS_DIR) - cgrp = kn->priv; + css = kn->priv; else - cgrp = kn->parent->priv; + css = kn->parent->priv; + cgrp = css->cgroup; mutex_unlock(&cgroup_mutex); @@ -1556,12 +1558,14 @@ void cgroup_kn_unlock(struct kernfs_node *kn) */ struct cgroup *cgroup_kn_lock_live(struct kernfs_node *kn, bool drain_offline) { + struct cgroup_subsys_state *css; struct cgroup *cgrp; if (kernfs_type(kn) == KERNFS_DIR) - cgrp = kn->priv; + css = kn->priv; else - cgrp = kn->parent->priv; + css = kn->parent->priv; + cgrp = css->cgroup; /* * We're gonna grab cgroup_mutex which nests outside kernfs @@ -1652,7 +1656,7 @@ static int cgroup_device_mkdir(struct cgroup_subsys_state *css) if (WARN_ON_ONCE(ret >= CGROUP_FILE_NAME_MAX)) return 0; - kn = kernfs_create_dir(cgrp->kn, name, cgrp->kn->mode, cgrp); + kn = kernfs_create_dir(cgrp->kn, name, cgrp->kn->mode, css); if (IS_ERR(kn)) return PTR_ERR(kn); css->device_kn = kn; @@ -1662,7 +1666,7 @@ static int cgroup_device_mkdir(struct cgroup_subsys_state *css) /* FIXME: prefix dev_name with bus_name for uniqueness? */ kn = kernfs_create_dir(css->device_kn, dev_name(device_css->device), - cgrp->kn->mode, cgrp); + cgrp->kn->mode, device_css); if (IS_ERR(kn)) return PTR_ERR(kn); /* FIXME: kernfs_get needed here? */ @@ -2025,7 +2029,7 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) root->kf_root = kernfs_create_root(kf_sops, KERNFS_ROOT_CREATE_DEACTIVATED | KERNFS_ROOT_SUPPORT_EXPORTOP, - root_cgrp); + &root_cgrp->self); if (IS_ERR(root->kf_root)) { ret = PTR_ERR(root->kf_root); goto exit_root_id; @@ -3579,9 +3583,9 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, size_t nbytes, loff_t off) { struct cgroup_namespace *ns = current->nsproxy->cgroup_ns; - struct cgroup *cgrp = of->kn->parent->priv; + struct cgroup_subsys_state *css = of_css(of); struct cftype *cft = of->kn->priv; - struct cgroup_subsys_state *css; + struct cgroup *cgrp = css->cgroup; int ret; /* @@ -3598,16 +3602,6 @@ static ssize_t cgroup_file_write(struct kernfs_open_file *of, char *buf, if (cft->write) return cft->write(of, buf, nbytes, off); - /* - * kernfs guarantees that a file isn't deleted with operations in - * flight, which means that the matching css is and stays alive and - * doesn't need to be pinned. The RCU locking is not necessary - * either. It's just for the convenience of using cgroup_css(). - */ - rcu_read_lock(); - css = cgroup_css(cgrp, cft->ss); - rcu_read_unlock(); - if (cft->write_u64) { unsigned long long v; ret = kstrtoull(buf, 0, &v); @@ -5262,7 +5256,7 @@ int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, umode_t mode) } /* create the directory */ - kn = kernfs_create_dir(parent->kn, name, mode, cgrp); + kn = kernfs_create_dir(parent->kn, name, mode, &cgrp->self); if (IS_ERR(kn)) { ret = PTR_ERR(kn); goto out_destroy;