From patchwork Wed Oct 23 07:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13846615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1144DD2E01E for ; Wed, 23 Oct 2024 07:53:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 945606B0082; Wed, 23 Oct 2024 03:53:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CE8B6B0083; Wed, 23 Oct 2024 03:53:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 748036B0085; Wed, 23 Oct 2024 03:53:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 515D06B0082 for ; Wed, 23 Oct 2024 03:53:07 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9F827C05D8 for ; Wed, 23 Oct 2024 07:52:48 +0000 (UTC) X-FDA: 82704100794.05.D84EE2D Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 0F1C9160014 for ; Wed, 23 Oct 2024 07:52:53 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf08.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729669862; a=rsa-sha256; cv=none; b=HCmiVzrsiSj+1REnjo1R3e7VdN2nSURwo1qi1u0jd2kpgBCDwYLTvn2tzgrOOF4vu/R5BP yDvfp1kfK1hsFaD6IrjZIsnUIR56ponNcn/46uhjrDnMs3n39GCxLFP+begoqKR69JRhqn AC2cV9GEnr67+kgHjNyGD/YJKX/Prl8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf08.hostedemail.com: domain of mlankhorst@mblankhorst.nl has no SPF policy when checking 141.105.120.124) smtp.mailfrom=mlankhorst@mblankhorst.nl ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729669862; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mMj4fisK6Cv90a37SqiKuP13+YHZVkmC64qpU/8DwVg=; b=8FDMJuX4p5wwCXfcM7eaRJXWn6vYZl/hW2jUh6U+q4T/9G9zZDbCNhCresyavlrERSoUFb 4ITKt1viCNXp19jf0dZMqnBwgXjQa07nEtoVVaWZVoEMiUZ1fPnYKQc96WVVmGCPgXtSan sZe04baw2hDkYZGcAH80vWn0QVFgM5M= From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Tejun Heo , Zefan Li , Johannes Weiner , Andrew Morton Cc: Friedrich Vock , cgroups@vger.kernel.org, linux-mm@kvack.org, Maxime Ripard , Maarten Lankhorst Subject: [PATCH 2/7] drm/drv: Add drmm cgroup registration for dev cgroups. Date: Wed, 23 Oct 2024 09:52:55 +0200 Message-ID: <20241023075302.27194-3-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241023075302.27194-1-maarten.lankhorst@linux.intel.com> References: <20241023075302.27194-1-maarten.lankh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QaK5tDQuMuzEL/B/3JcU40Y0yPa80wltGhD8X2kywc3DzCm6QYVqY/EuDsY IczOI6+s YyNPVF+YjQ0c8ku5h2BsslMcg2aBvgjBKfSsyVbTTyMqg3bAzQoA/DbEVTaBlhdDKTHkcz3tLWNQ/dRDj9I/M7oAbbkUIq8QmoHvPvm4kuVIHbJXAH1Fphm8/kb0lf54ZFLADWSHoxM2pCM0CpBUmjBetd+O/99ACCdlDp9jd48t1SGo6iQm6mTBpVO2SXzFTnSBl+m8qrwXS0mztaQjJFo3uU4+tSy2q8VqYidvY//LZ/BXvc7n0oVMoUpiqfwgv7Fht X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Maxime Ripard Drivers will need to register a cgroup device at probe time, so let's give them a drm-managed helper. Signed-off-by: Maxime Ripard Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/drm_drv.c | 21 +++++++++++++++++++++ include/drm/drm_drv.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index c2c172eb25df7..251d1d69b09c5 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -26,6 +26,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include #include #include #include @@ -820,6 +821,26 @@ void drm_dev_put(struct drm_device *dev) } EXPORT_SYMBOL(drm_dev_put); +static inline void drmm_cg_unregister_device(struct drm_device *dev, void *arg) +{ + dev_cgroup_unregister_device(arg); +} + +int drmm_cgroup_register_device(struct drm_device *dev, + struct dev_cgroup_device *cgdev) +{ + int ret; + char dev_name[32]; + + snprintf(dev_name, sizeof(dev_name), "drm/%s", dev->unique); + ret = dev_cgroup_register_device(cgdev, dev_name); + if (ret) + return ret; + + return drmm_add_action_or_reset(dev, drmm_cg_unregister_device, cgdev); +} +EXPORT_SYMBOL_GPL(drmm_cgroup_register_device); + static int create_compat_control_link(struct drm_device *dev) { struct drm_minor *minor; diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 1bbbcb8e2d231..3e83c7ce7f2d0 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -34,6 +34,7 @@ #include +struct dev_cgroup_device; struct drm_fb_helper; struct drm_fb_helper_surface_size; struct drm_file; @@ -438,6 +439,9 @@ void *__devm_drm_dev_alloc(struct device *parent, const struct drm_driver *driver, size_t size, size_t offset); +int drmm_cgroup_register_device(struct drm_device *dev, + struct dev_cgroup_device *cgdev); + /** * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance * @parent: Parent device object