From patchwork Sat Jan 20 01:51:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10176193 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 2728160386 for ; Sat, 20 Jan 2018 01:52:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1946328762 for ; Sat, 20 Jan 2018 01:52:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E14D2880C; Sat, 20 Jan 2018 01:52:03 +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 C4C3428762 for ; Sat, 20 Jan 2018 01:52:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F75F6EBC0; Sat, 20 Jan 2018 01:52:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7643C6EBBF; Sat, 20 Jan 2018 01:51:59 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jan 2018 17:51:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,383,1511856000"; d="scan'208";a="23895479" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by fmsmga001.fm.intel.com with ESMTP; 19 Jan 2018 17:51:58 -0800 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH RFC 2/9] cgroup: Add notifier call chain for cgroup destruction Date: Fri, 19 Jan 2018 17:51:34 -0800 Message-Id: <20180120015141.10118-3-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180120015141.10118-1-matthew.d.roper@intel.com> References: <20180120015141.10118-1-matthew.d.roper@intel.com> Cc: Tejun Heo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 Drivers or other kernel subsystems may allow subsystem-specific policy and configuration to be applied to cgroups. If these subsystems track private data on a per-cgroup basis, they need a way to be notified about cgroup destruction so that they can clean up their own internal data for that cgroup. Let's add a blocking_notifier that will be called whenever a cgroup in the v2 hierarchy is destroyed to allow this cleanup. I'm arbitrarily restricting this behavior to the default (cgroup-v2) hierarchy for now since I don't anticipate it being terribly useful on the legacy hierarchies. We can certainly relax that restriction if someone comes up with a use case that needs this on the v1 hierarchies. Cc: Tejun Heo Cc: cgroups@vger.kernel.org Signed-off-by: Matt Roper --- include/linux/cgroup.h | 3 +++ kernel/cgroup/cgroup.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 473e0c0abb86..c9896027ed99 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -43,6 +43,9 @@ /* walk all threaded css_sets in the domain */ #define CSS_TASK_ITER_THREADED (1U << 1) +/* Driver-registered callbacks for cgroup destruction */ +extern struct blocking_notifier_head cgroup_destroy_notifier_list; + /* a css_task_iter should be treated as an opaque object */ struct css_task_iter { struct cgroup_subsys *ss; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 2cf06c274e4c..f12c32c6ec7f 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -75,6 +75,15 @@ DEFINE_MUTEX(cgroup_mutex); DEFINE_SPINLOCK(css_set_lock); +/* + * Driver-registered callbacks for cgroup destruction. Drivers may wish to + * track their own per-cgroup data. Registering a callback on this list will + * allow them to detect cgroup destruction and perform any appropriate cleanup + * of that data when the cgroup is destroyed. + */ +BLOCKING_NOTIFIER_HEAD(cgroup_destroy_notifier_list); +EXPORT_SYMBOL_GPL(cgroup_destroy_notifier_list); + #ifdef CONFIG_PROVE_RCU EXPORT_SYMBOL_GPL(cgroup_mutex); EXPORT_SYMBOL_GPL(css_set_lock); @@ -5086,6 +5095,15 @@ static int cgroup_destroy_locked(struct cgroup *cgrp) for_each_css(css, ssid, cgrp) kill_css(css); + /* + * Notify listeners of cgroup destruction on the default hierarchy. + * Drivers that store per-cgroup data may register for callback to know + * when it's safe to reap that data. + */ + if (cgroup_on_dfl(cgrp)) + blocking_notifier_call_chain(&cgroup_destroy_notifier_list, + 0, cgrp); + /* * Remove @cgrp directory along with the base files. @cgrp has an * extra ref on its kn.