From patchwork Sat Mar 17 00:09:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10290533 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 132A5601A0 for ; Sat, 17 Mar 2018 00:09:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0408829102 for ; Sat, 17 Mar 2018 00:09:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAAC829106; Sat, 17 Mar 2018 00:09:54 +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=ham 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 ABBC429102 for ; Sat, 17 Mar 2018 00:09:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B0A5A6E0DF; Sat, 17 Mar 2018 00:09:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0EF836EC1D; Sat, 17 Mar 2018 00:09:52 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Mar 2018 17:09:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,318,1517904000"; d="scan'208";a="39660148" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by orsmga001.jf.intel.com with ESMTP; 16 Mar 2018 17:09:51 -0700 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH v4 3/8] cgroup: Introduce cgroup_priv_get_current Date: Fri, 16 Mar 2018 17:09:00 -0700 Message-Id: <20180317000905.7091-4-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180317000905.7091-1-matthew.d.roper@intel.com> References: <20180317000905.7091-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 a5e2017c9a94..56ed910beb8a 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