From patchwork Wed Dec 4 13:44:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13893795 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 6E9CAE77173 for ; Wed, 4 Dec 2024 13:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E5C06B008A; Wed, 4 Dec 2024 08:44:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 36EA86B008C; Wed, 4 Dec 2024 08:44:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 234BF6B0092; Wed, 4 Dec 2024 08:44:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 02FED6B008C for ; Wed, 4 Dec 2024 08:44:21 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B29A2141002 for ; Wed, 4 Dec 2024 13:44:21 +0000 (UTC) X-FDA: 82857395376.06.000C076 Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 9E3D31C0012 for ; Wed, 4 Dec 2024 13:43:52 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=none; spf=none (imf21.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=1733319849; 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=VdZp7H4YeZ4QSE2p7BmX8sYf3UoctR+j+KvVz+vtXdQ=; b=NE++q6Hm6TP0M7qoFVqxJ+jMxTKuUxU9rJ6prig9fKe7d3HnpS8ewJyzICjoL8Ryqa/OnN 479r+Bulqopt6KaPr0gB4xAgIqZmFQK1YMXL4LiRXcV7XnCIIWDSk4kGNgdIbPNKXrTm91 x6V/IUSlZjWFbD2MFz7+AmIxj9egTDs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=none; spf=none (imf21.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=1733319849; a=rsa-sha256; cv=none; b=WzHc50MAy1aiYOqrCfoVnnPANnYa79wkzuhMdu2oAo7g+EMhksuoMDziFe2Y6PArj2R02o go0mH7eLBeFhNh8avDlAG7AFx/pzROolX8lpTJvQGew4HaPdjd6QwDU/H6eT/66u8FQvtj ONvJ3bfYOA+7VtrMcM3IdqAxftvffkQ= From: Maarten Lankhorst To: linux-kernel@vger.kernel.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Tejun Heo , Zefan Li , Johannes Weiner , Andrew Morton , Friedrich Vock , Maxime Ripard Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Maarten Lankhorst , Maarten Lankhorst Subject: [PATCH v2 2/7] drm/drv: Add drmm managed registration helper for dmem cgroups. Date: Wed, 4 Dec 2024 14:44:02 +0100 Message-ID: <20241204134410.1161769-3-dev@lankhorst.se> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204134410.1161769-1-dev@lankhorst.se> References: <20241204134410.1161769-1-dev@lankhorst.se> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9E3D31C0012 X-Rspamd-Server: rsp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QXxkanqEUFZbg5hKXMGinP9fNRR8SDok4NOQsdpn0T+9Z7emNgWM/yI1mvuOsftB8LByo/Z/bQaICKVmdiaasdHiGZCHCOWR++q930LQN7DKxWI/D4bAUTKe5jOyHg2aExvRf5ZNSG6ngBtrUNHqyiBW+NkQWzknEtqpNqTyNdf 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 dmem regions 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 | 32 ++++++++++++++++++++++++++++++++ include/drm/drm_drv.h | 5 +++++ 2 files changed, 37 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index c2c172eb25df7..3cf440eee8a2a 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,37 @@ void drm_dev_put(struct drm_device *dev) } EXPORT_SYMBOL(drm_dev_put); +static void drmm_cg_unregister_region(struct drm_device *dev, void *arg) +{ + dmem_cgroup_unregister_region(arg); +} + +/** + * drmm_cgroup_register_region - Register a region of a DRM device to cgroups + * @dev: device for region + * @region_name: Region name for registering + * @size: Size of region in bytes + * + * This decreases the ref-count of @dev by one. The device is destroyed if the + * ref-count drops to zero. + */ +struct dmem_cgroup_region *drmm_cgroup_register_region(struct drm_device *dev, const char *region_name, u64 size) +{ + struct dmem_cgroup_region *region; + int ret; + + region = dmem_cgroup_register_region(size, "drm/%s/%s", dev->unique, region_name); + if (IS_ERR_OR_NULL(region)) + return region; + + ret = drmm_add_action_or_reset(dev, drmm_cg_unregister_region, region); + if (ret) + return ERR_PTR(ret); + + return region; +} +EXPORT_SYMBOL_GPL(drmm_cgroup_register_region); + 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..7dd49d9ab5058 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -34,6 +34,7 @@ #include +struct dmem_cgroup_region; struct drm_fb_helper; struct drm_fb_helper_surface_size; struct drm_file; @@ -438,6 +439,10 @@ void *__devm_drm_dev_alloc(struct device *parent, const struct drm_driver *driver, size_t size, size_t offset); +struct dmem_cgroup_region * +drmm_cgroup_register_region(struct drm_device *dev, + const char *region_name, u64 size); + /** * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance * @parent: Parent device object