From patchwork Tue Mar 14 14:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 69664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1792360wrd; Tue, 14 Mar 2023 07:30:38 -0700 (PDT) X-Google-Smtp-Source: AK7set8OhwhbSjufp/iCtYsTA2C+k5h/T93eHrD0jEF4SFE9+crvrKpaglysJnenzO4XCSIwPrUG X-Received: by 2002:a17:902:d4cf:b0:19e:500b:517a with SMTP id o15-20020a170902d4cf00b0019e500b517amr45032949plg.69.1678804237922; Tue, 14 Mar 2023 07:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678804237; cv=none; d=google.com; s=arc-20160816; b=NZH5zkpyexqx+TAXWkkjZBEWv3ktZ+4941pv8DNu9EgyHkRXVJWLAlLPsvZu/r9hs4 DUSNiQwoPkY0wPBt1gNEU8j+M8mzjA9hVbLnY1ZTFzQdYzJnPBDWyN3OtDSVsuXpLnSV vf8UrR2ij85CW1tex4WlANR1HbddFissWt48KHTi7kOU+kSlS9oF/W7mqcMsYJajIwA1 fL/aQ+1+cemqrVy3ODMTivvygREPsK2cS6GOkyoEEaGSINPo4lmusKvcZAnXTdG66PZt stFYGY6pahslKVuStXc2pxWwHglGr5yckz/yDQS6B6tBIVZWyk2L75hFMFQnyvw+nDlf /1Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=btXpTJl1iqvurW7rBR2LY69qiRSL4AGqCC+N87jIbRI=; b=gjO4+o4wonab+UxGGRaLXPqIQR4nxffHhM/nf8xmLgGUlUtzgFneCQKkQD14Eu1fsC VOqlrHJZ/P6VFqPPMOrCh0jJAHdsErZ/ANv31i8cvVHhjaVEPy6H8DEhze433ur8RKFA DiUBWb6eEa3qcQtTGl7Yyf/8/aW27yqIKZD8ESGd5sgYGI4RN32mymtkVZMqOX1ZRMz4 SV1PHut1NZd4Gneboswv57IknMZMXKG5NTAlVqpBV86Fjcrn2P5haFfKDGlDeyKfUp4X BHRkyyj9zki5oNg1Bo6KPCRBfLe50U/g+eLfmJ2/IwyyM7ef39F0OLTckgLaSEUYFLPW +dpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="LwKf/Ibg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902ebc100b001a043389a7asi2616965plg.310.2023.03.14.07.30.23; Tue, 14 Mar 2023 07:30:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="LwKf/Ibg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229960AbjCNOUY (ORCPT + 99 others); Tue, 14 Mar 2023 10:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230043AbjCNOTo (ORCPT ); Tue, 14 Mar 2023 10:19:44 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67B36A1892; Tue, 14 Mar 2023 07:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678803570; x=1710339570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=33+0P00oKCPT59EPr+zGQB3p4qKmhGdsGjDhazkuHW8=; b=LwKf/IbgSxTXkut+aJmrJGKpc8OC2wv83+Gu7i1SNCvFo1yoQSWcgDpN 8Y1/TdmzLbR6mDJ79DUhPm7GLTum4+VaZp3p47ey4LO1gI+lkV0woj7ec bkxdo4j/tuuKIB7Av7VgGA8FU/E/PsoErt4uo1qEMBW6hIEmEnBksLFWe XBL1FbiGj9fFQcbI/hZ++avjXj4ZqDFfT5e2hZf3eC1hhkP/v/brRXr+z bg5pZgWDwAdFsJTXnhAZbNQEO8SfPTkGfhO+PAz4JJbH3VzJ5D3Fm2FcA 9BuSeIbqXq80e2xKqIatLdiVrULsX68mx7zeI8iZ46m/YN/Mxf01MWGav A==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="321284719" X-IronPort-AV: E=Sophos;i="5.98,260,1673942400"; d="scan'208";a="321284719" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2023 07:19:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="656363227" X-IronPort-AV: E=Sophos;i="5.98,260,1673942400"; d="scan'208";a="656363227" Received: from mjtillin-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.213.236.227]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2023 07:19:25 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Tejun Heo , Johannes Weiner , Zefan Li , Dave Airlie , Daniel Vetter , Rob Clark , =?utf-8?q?St=C3=A9phane_Marchesin?= , "T . J . Mercier" , Kenny.Ho@amd.com, =?utf-8?q?Chris?= =?utf-8?q?tian_K=C3=B6nig?= , Brian Welty , Tvrtko Ursulin Subject: [RFC 03/10] cgroup: Add the DRM cgroup controller Date: Tue, 14 Mar 2023 14:18:57 +0000 Message-Id: <20230314141904.1210824-4-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230314141904.1210824-1-tvrtko.ursulin@linux.intel.com> References: <20230314141904.1210824-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HK_RANDOM_ENVFROM,HK_RANDOM_FROM, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760353832722279812?= X-GMAIL-MSGID: =?utf-8?q?1760353832722279812?= From: Tvrtko Ursulin Skeleton controller without any functionality. Signed-off-by: Tvrtko Ursulin --- include/linux/cgroup_drm.h | 9 ++++++ include/linux/cgroup_subsys.h | 4 +++ init/Kconfig | 7 ++++ kernel/cgroup/Makefile | 1 + kernel/cgroup/drm.c | 60 +++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 include/linux/cgroup_drm.h create mode 100644 kernel/cgroup/drm.c diff --git a/include/linux/cgroup_drm.h b/include/linux/cgroup_drm.h new file mode 100644 index 000000000000..8ef66a47619f --- /dev/null +++ b/include/linux/cgroup_drm.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2023 Intel Corporation + */ + +#ifndef _CGROUP_DRM_H +#define _CGROUP_DRM_H + +#endif /* _CGROUP_DRM_H */ diff --git a/include/linux/cgroup_subsys.h b/include/linux/cgroup_subsys.h index 445235487230..49460494a010 100644 --- a/include/linux/cgroup_subsys.h +++ b/include/linux/cgroup_subsys.h @@ -65,6 +65,10 @@ SUBSYS(rdma) SUBSYS(misc) #endif +#if IS_ENABLED(CONFIG_CGROUP_DRM) +SUBSYS(drm) +#endif + /* * The following subsystems are not supported on the default hierarchy. */ diff --git a/init/Kconfig b/init/Kconfig index 1fb5f313d18f..1679229143c0 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1093,6 +1093,13 @@ config CGROUP_RDMA Attaching processes with active RDMA resources to the cgroup hierarchy is allowed even if can cross the hierarchy's limit. +config CGROUP_DRM + bool "DRM controller" + help + Provides the DRM subsystem controller. + + ... + config CGROUP_FREEZER bool "Freezer controller" help diff --git a/kernel/cgroup/Makefile b/kernel/cgroup/Makefile index 12f8457ad1f9..849bd2917477 100644 --- a/kernel/cgroup/Makefile +++ b/kernel/cgroup/Makefile @@ -6,4 +6,5 @@ obj-$(CONFIG_CGROUP_PIDS) += pids.o obj-$(CONFIG_CGROUP_RDMA) += rdma.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_CGROUP_MISC) += misc.o +obj-$(CONFIG_CGROUP_DRM) += drm.o obj-$(CONFIG_CGROUP_DEBUG) += debug.o diff --git a/kernel/cgroup/drm.c b/kernel/cgroup/drm.c new file mode 100644 index 000000000000..02c8eaa633d3 --- /dev/null +++ b/kernel/cgroup/drm.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2023 Intel Corporation + */ + +#include +#include +#include + +struct drm_cgroup_state { + struct cgroup_subsys_state css; +}; + +struct drm_root_cgroup_state { + struct drm_cgroup_state drmcs; +}; + +static struct drm_root_cgroup_state root_drmcs; + +static inline struct drm_cgroup_state * +css_to_drmcs(struct cgroup_subsys_state *css) +{ + return container_of(css, struct drm_cgroup_state, css); +} + +static void drmcs_free(struct cgroup_subsys_state *css) +{ + struct drm_cgroup_state *drmcs = css_to_drmcs(css); + + if (drmcs != &root_drmcs.drmcs) + kfree(drmcs); +} + +static struct cgroup_subsys_state * +drmcs_alloc(struct cgroup_subsys_state *parent_css) +{ + struct drm_cgroup_state *drmcs; + + if (!parent_css) { + drmcs = &root_drmcs.drmcs; + } else { + drmcs = kzalloc(sizeof(*drmcs), GFP_KERNEL); + if (!drmcs) + return ERR_PTR(-ENOMEM); + } + + return &drmcs->css; +} + +struct cftype files[] = { + { } /* Zero entry terminates. */ +}; + +struct cgroup_subsys drm_cgrp_subsys = { + .css_alloc = drmcs_alloc, + .css_free = drmcs_free, + .early_init = false, + .legacy_cftypes = files, + .dfl_cftypes = files, +};