From patchwork Wed Mar 21 23:23:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10300667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55ABE60349 for ; Wed, 21 Mar 2018 23:25:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 479ED290D7 for ; Wed, 21 Mar 2018 23:25:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CA2C2990D; Wed, 21 Mar 2018 23:25:16 +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=-4.2 required=2.0 tests=BAYES_00, 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 9B8BF29889 for ; Wed, 21 Mar 2018 23:25:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2CC3B6EB3D; Wed, 21 Mar 2018 23:25:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id B64346EB3B; Wed, 21 Mar 2018 23:25:07 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Mar 2018 16:25:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,341,1517904000"; d="scan'208";a="210273055" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by orsmga005.jf.intel.com with ESMTP; 21 Mar 2018 16:25:07 -0700 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH v4.5 3/8] cgroup: Introduce cgroup_priv_get_current Date: Wed, 21 Mar 2018 16:23:39 -0700 Message-Id: <20180321232344.20727-4-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180321232344.20727-1-matthew.d.roper@intel.com> References: <20180321232344.20727-1-matthew.d.roper@intel.com> 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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Getting cgroup private data for the current process' cgroup is such a common pattern that we should add a convenience wrapper for it. Signed-off-by: Matt Roper --- include/linux/cgroup.h | 1 + kernel/cgroup/cgroup.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 74b435f913c1..64d3dc45efd0 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -867,6 +867,7 @@ int cgroup_priv_getkey(void (*free)(struct kref *)); void cgroup_priv_destroykey(int key); int cgroup_priv_install(struct cgroup *cgrp, int key, struct kref *ref); struct kref *cgroup_priv_get(struct cgroup *cgrp, int key); +struct kref *cgroup_priv_get_current(int key); void cgroup_priv_release(struct cgroup *cgrp, int key); #endif /* _LINUX_CGROUP_H */ diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 3268a21e8158..f1637d9c83d5 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6079,6 +6079,29 @@ cgroup_priv_get(struct cgroup *cgrp, int key) } EXPORT_SYMBOL_GPL(cgroup_priv_get); +/** + * cgroup_priv_get_current - looks up cgroup private data for current task + * @key: key uniquely identifying owner of private data to lookup + * + * Convenience function that performs cgroup_priv_get() on the cgroup that owns + * %current. + * + * Returns: + * A pointer to the private data's kref field, or NULL if no private data has + * been registered. + */ +struct kref * +cgroup_priv_get_current(int key) +{ + struct cgroup *cgrp = task_get_dfl_cgroup(current); + struct kref *ref = cgroup_priv_get(cgrp, key); + + cgroup_put(cgrp); + + return ref; +} +EXPORT_SYMBOL_GPL(cgroup_priv_get_current); + /** * cgroup_priv_free - free cgroup private data * @cgrp: cgroup to release private data for