From patchwork Tue Aug 29 11:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13368862 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 190C3C6FA8F for ; Tue, 29 Aug 2023 11:01:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0889310E20E; Tue, 29 Aug 2023 11:01:22 +0000 (UTC) Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0732E10E201 for ; Tue, 29 Aug 2023 11:01:19 +0000 (UTC) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9a5be3166a2so200021666b.1 for ; Tue, 29 Aug 2023 04:01:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693306878; x=1693911678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=D2eRnoFZrUjASmOPG7eOs34IpVUTa8NA0xCYsyaGhog=; b=jPfJlTWJs9t2BSNDoY8NwY2CSvjxggDwJCMGZDomHVdC2tE8TfD1ZApA1jTtErIZXb F2+TLt0n52jvlzXsN48NznpfqfUbsbkfYH43brIIE2NQhEFgoXYgOy7LdH59GA7R8bNj tGxBTkiz5SABMiUWuNi6PKaJnXbyEDiZhxAHIO9PcRXcwEJb48myNpqOb9ZeSz94uaFg j9OuGFNf61GGMPujQKOnhAwL6d0PZ/ZlSjHEL2dtjp9Uh0DEQg5uEf44eSNzeiiVAUH4 2Kl/eXMe74lWI6bL9UKeVLQob4TInR8z+U1KCWgoux4agtq7WGndwZryt/6jZ9cyh7DD IjsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693306878; x=1693911678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D2eRnoFZrUjASmOPG7eOs34IpVUTa8NA0xCYsyaGhog=; b=Bn3k4/ZKvMLjaWTXCrSPSSuUEpBhSV3WF3Kt2PNkXEQ7SwNQFMeRiKgB6HTB+TSCrK hBYXX9+v1rkxIZ7ezdFmqVqy+ZQ7wFvgm/4pQKF2XRMkQr/gYGYS38g4yylOqzuZEN3i 3xFUt0FfasekRJ3TLHEyI7hyH55LjfN+LAky2eX3CPZxv4WDwIbg86mUIVBsEKuL7w2W DQvkMLGnoFvp+OC4MP2dNRrIxRzsG2ILDuCX3R8mR8hZ1MvtSbjsTEhvjJME+I2ldQET GlOJXt6HbKrDHwyaKjwdo1/j1FA479azbTkjo3QxdijQDZ0A9s9zbD8PBaWENaz0onew rYzg== X-Gm-Message-State: AOJu0Yw+abauduCc8fyySCSx+q2CcmWDlJaNg0bQJGXGPwkfJSqBNR42 6s9deUD9Ob0CBgcv2OrzWo0= X-Google-Smtp-Source: AGHT+IE7y1zGvm4etr5CvIZGfe3h8kp7DY7WBb5WivqpuFR1xl4HyEtpig2BtUKiKUShg3zZ6S6E7Q== X-Received: by 2002:a17:907:78d1:b0:9a5:d242:d9b3 with SMTP id kv17-20020a17090778d100b009a5d242d9b3mr736580ejc.21.1693306878307; Tue, 29 Aug 2023 04:01:18 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:158b:d500:cd84:8e32:621d:b36b]) by smtp.gmail.com with ESMTPSA id i27-20020a1709063c5b00b009928b4e3b9fsm5805885ejg.114.2023.08.29.04.01.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 04:01:18 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: ogabbay@kernel.org, ttayar@habana.ai, dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Date: Tue, 29 Aug 2023 13:01:11 +0200 Message-Id: <20230829110115.3442-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829110115.3442-1-christian.koenig@amd.com> References: <20230829110115.3442-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We want to remove per minor debugfs directories. Start by stopping drivers from adding anything inside of those in the mid layer callback. v2: drop it for the accel node as well Signed-off-by: Christian König Tested-by: Stanislaw Gruszka Reviewed-by: Andi Shyti Reviewed-by: Tomer Tayar Tested-by: Tomer Tayar --- drivers/accel/drm_accel.c | 3 --- drivers/gpu/drm/drm_debugfs.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 4a9baf02439e..01edf2c00b5a 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -99,9 +99,6 @@ void accel_debugfs_init(struct drm_minor *minor, int minor_id) drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES, minor->debugfs_root, minor); - - if (dev->driver->debugfs_init) - dev->driver->debugfs_init(minor); } /** diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 2de43ff3ce0a..d90d0827bfad 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -284,7 +284,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id, drm_client_debugfs_init(minor); } - if (dev->driver->debugfs_init) + if (dev->driver->debugfs_init && dev->render != minor) dev->driver->debugfs_init(minor); list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) { From patchwork Tue Aug 29 11:01:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13368863 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A218C6FA8F for ; Tue, 29 Aug 2023 11:01:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F0F5110E208; Tue, 29 Aug 2023 11:01:23 +0000 (UTC) Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1698910E208 for ; Tue, 29 Aug 2023 11:01:21 +0000 (UTC) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bcc14ea414so64689961fa.0 for ; Tue, 29 Aug 2023 04:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693306879; x=1693911679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zB8II6OIU0PeXoXNV+it2gU0mMIgzfk5ZSPUFJ1PZ78=; b=rVw7EMnFpEHIT5+yK4o7IzjStqA13ysUCTj6gwCwh4Hws/EX4wdm2prMV6xdh87KLi pU1nm4nz4NN1cpOqQOGRdPx030+PMWiwidWRKe+N+HsZxeKZ8VSeRELcywu7bvopflbf xnuXETGuAUjOagJlxILHmkyT2QlykoG+xculgilKCqkh6L2vgMQza9+G6WSl2aClvmnP 4R2qUYEKLydvReeWYFsDnvwm0WXCJIQqa835bu0aOFnzVJ8Yy4rrO4wVlApy8QishhNR iRSWoQ0pluD4gtm2PHlB1BZ3Z9CCrHTuC46P3r9eSeFkpJf5UDhf108p3VTn4cOqESFg /H6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693306879; x=1693911679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zB8II6OIU0PeXoXNV+it2gU0mMIgzfk5ZSPUFJ1PZ78=; b=kyZ2aGjaH1IBU5E4RfQUnX0XKPumFC6ohryFaxIvQYQ1RlerCooBLjzkFXcQtNzlB1 4lEYXRxzM6AiqSrfXJ52NKx0kW6cOawqJJzb+jTnhoI8bUwNRNY558+ZIqirLYCQkAxE qF7+lS5dsua6khC7lZ2e/SfbNbClCOZ0WSJwYSs5HNCazLRJ1jEnUIoZkGQAmtJ/Zdb4 KSy7Q3UKC8Ba95sl1ubZAUts2wcnPC8JRHn9QdoGyTl8YVIwf+7ztq4FiQqtaomyoPiD PNVQLuCxWDM1MWGl6XQGO9ZJgfewhfUPxrWhaW1yiUoRtlblWA92WNF0B238PFUkcONb oJ7g== X-Gm-Message-State: AOJu0YzZx4GYjJGh29GJZtFyOEH4Jvs9JLLEU5QSpFkKfHI9ip+zCjta QtPSM4qaE9kuJcMDthaE+P8= X-Google-Smtp-Source: AGHT+IHGWaXQVxGvQ0eK8y5FopNekOLCjSmaOSgLJRB9cYcD/3tYw4pI36oCUTK/bTcCectsPo23Ug== X-Received: by 2002:a2e:8210:0:b0:2bc:c21d:311f with SMTP id w16-20020a2e8210000000b002bcc21d311fmr16406280ljg.52.1693306878972; Tue, 29 Aug 2023 04:01:18 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:158b:d500:cd84:8e32:621d:b36b]) by smtp.gmail.com with ESMTPSA id i27-20020a1709063c5b00b009928b4e3b9fsm5805885ejg.114.2023.08.29.04.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 04:01:18 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: ogabbay@kernel.org, ttayar@habana.ai, dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Date: Tue, 29 Aug 2023 13:01:12 +0200 Message-Id: <20230829110115.3442-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829110115.3442-1-christian.koenig@amd.com> References: <20230829110115.3442-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" During device bringup it might be that we can't access the debugfs files. Return -ENODEV until the registration is completed on access. Signed-off-by: Christian König Reviewed-by: Andi Shyti --- drivers/gpu/drm/drm_debugfs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index d90d0827bfad..8a4c90fd9f02 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -150,6 +150,9 @@ static int drm_debugfs_open(struct inode *inode, struct file *file) { struct drm_info_node *node = inode->i_private; + if (!device_is_registered(node->minor->kdev)) + return -ENODEV; + return single_open(file, node->info_ent->show, node); } @@ -157,6 +160,10 @@ static int drm_debugfs_entry_open(struct inode *inode, struct file *file) { struct drm_debugfs_entry *entry = inode->i_private; struct drm_debugfs_info *node = &entry->file; + struct drm_minor *minor = entry->dev->primary ?: entry->dev->accel; + + if (!device_is_registered(minor->kdev)) + return -ENODEV; return single_open(file, node->show, entry); } From patchwork Tue Aug 29 11:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13368866 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD5C6C6FA8F for ; Tue, 29 Aug 2023 11:01:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0D95010E216; Tue, 29 Aug 2023 11:01:43 +0000 (UTC) Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by gabe.freedesktop.org (Postfix) with ESMTPS id C17BC10E208 for ; Tue, 29 Aug 2023 11:01:21 +0000 (UTC) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9a5be3166a2so200025366b.1 for ; Tue, 29 Aug 2023 04:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693306880; x=1693911680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=suOZxllMTpRMYzRS9FEvQDqhPgQr/NQzHfrT/kAGVs0=; b=dCRr8IOC2q2wcAzGTzB3ibFuJTJFKgyrPU3xztbX4eXaceP1pLzGMbt2CKlKXuTatI 4RLYx+H2xZmEf1n9C7uHCSntTyE9pv+Vpcn1ch+B4UVqJO5pnN/7EPWIir2U8BOFrfzn opLHQxMJVsTPenNVrJ43ZhZ6c+Cpx7N7YGOZ9oyBODoAXCLQ/WaBCcKvMo+OYQAkribN Ne9/l/rE48hIFzvq6sz8s3jTt5ACx/py0+vGw8yXcgIUzHPavoQ1hnerKccsoVSJ3NDa SnDOxJMv6pz3Dr3waJbcpiNpUWGBSyySsrjjCLNeLHkDXNtYwNRLq+iRG3CkSJhSI1pA p92g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693306880; x=1693911680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=suOZxllMTpRMYzRS9FEvQDqhPgQr/NQzHfrT/kAGVs0=; b=UAjlXA761rJtbjZKpfzgItO92TuhGLbV9jIBHeUrQYaQ6pWqxRV3yO6R9b9mdnWzRp 134lRm7DCtYUPsyZZTKBsOeXDxVxr7QsHksNNuCKKPvM3i+TCIUK6AOwea5xgXmUR6cV kZsKRHV+COp+5QL1zV2vmdIusFqvgQYOQS2/5v7VhAMMa0zXc21hvBtt8ohZouzCKGko BjYwsyJzAShd2y7tI7bYo90Wp7FhiWWrzphAMHqIwCbCcy5oSBKj4/Pr8dK3GryA4Zoo cOJGB0/yKkDIa0v2MBdgzY9lV1YMBFzpeq2Xr/S722ZWIrajNFOzzsYt/p7y0r74wVst QkwA== X-Gm-Message-State: AOJu0YwTOX29oO0fMcUhIZsSX+QS4f78czMQj9m09y1RUFuROj0P2aSJ LhLCRiqJFiUBZdmS3C4wt8A= X-Google-Smtp-Source: AGHT+IFnIbA9OKs3Tfq3siDO0IFw0TfnnKgqZRc0qYdlUPI01c094pln558F0Gi1v28MKXaWj+mlBA== X-Received: by 2002:a17:906:1444:b0:99b:c845:791d with SMTP id q4-20020a170906144400b0099bc845791dmr19757228ejc.76.1693306879826; Tue, 29 Aug 2023 04:01:19 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:158b:d500:cd84:8e32:621d:b36b]) by smtp.gmail.com with ESMTPSA id i27-20020a1709063c5b00b009928b4e3b9fsm5805885ejg.114.2023.08.29.04.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 04:01:19 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: ogabbay@kernel.org, ttayar@habana.ai, dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/debugfs: rework debugfs directory creation v5 Date: Tue, 29 Aug 2023 13:01:13 +0200 Message-Id: <20230829110115.3442-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829110115.3442-1-christian.koenig@amd.com> References: <20230829110115.3442-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Instead of the per minor directories only create a single debugfs directory for the whole device directly when the device is initialized. For DRM devices each minor gets a symlink to the per device directory for now until we can be sure that this isn't useful any more in any way. Accel devices create only the per device directory and also drops the mid layer callback to create driver specific files. v2: cleanup accel component as well v3: fix typo when debugfs is disabled v4: call drm_debugfs_dev_fini() during release as well, some kerneldoc typos fixed v5: rebased and one more kerneldoc fix Signed-off-by: Christian König Reviewed-by: Andi Shyti --- drivers/accel/drm_accel.c | 30 +++++++----- drivers/gpu/drm/drm_atomic.c | 4 +- drivers/gpu/drm/drm_bridge.c | 4 +- drivers/gpu/drm/drm_client.c | 4 +- drivers/gpu/drm/drm_crtc_internal.h | 2 +- drivers/gpu/drm/drm_debugfs.c | 76 ++++++++++++++++++++--------- drivers/gpu/drm/drm_drv.c | 21 ++++++-- drivers/gpu/drm/drm_framebuffer.c | 4 +- drivers/gpu/drm/drm_internal.h | 20 ++++++-- include/drm/drm_accel.h | 9 +++- include/drm/drm_bridge.h | 2 +- include/drm/drm_client.h | 2 +- include/drm/drm_device.h | 7 +++ include/drm/drm_drv.h | 8 +++ include/drm/drm_file.h | 1 + 15 files changed, 136 insertions(+), 58 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 01edf2c00b5a..8ba3db2ec5bb 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -79,26 +79,32 @@ static const struct drm_info_list accel_debugfs_list[] = { #define ACCEL_DEBUGFS_ENTRIES ARRAY_SIZE(accel_debugfs_list) /** - * accel_debugfs_init() - Initialize debugfs for accel minor - * @minor: Pointer to the drm_minor instance. - * @minor_id: The minor's id + * accel_debugfs_init() - Initialize debugfs for device + * @dev: Pointer to the device instance. * - * This function initializes the drm minor's debugfs members and creates - * a root directory for the minor in debugfs. It also creates common files - * for accelerators and calls the driver's debugfs init callback. + * This function creates a root directory for the device in debugfs. */ -void accel_debugfs_init(struct drm_minor *minor, int minor_id) +void accel_debugfs_init(struct drm_device *dev) { - struct drm_device *dev = minor->dev; - char name[64]; + drm_debugfs_dev_init(dev, accel_debugfs_root); +} + +/** + * accel_debugfs_register() - Register debugfs for device + * @dev: Pointer to the device instance. + * + * Creates common files for accelerators. + */ +void accel_debugfs_register(struct drm_device *dev) +{ + struct drm_minor *minor = dev->accel; INIT_LIST_HEAD(&minor->debugfs_list); mutex_init(&minor->debugfs_lock); - sprintf(name, "%d", minor_id); - minor->debugfs_root = debugfs_create_dir(name, accel_debugfs_root); + minor->debugfs_root = dev->debugfs_root; drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES, - minor->debugfs_root, minor); + dev->debugfs_root, minor); } /** diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 2c454568a607..affce6a8851f 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1832,9 +1832,9 @@ static const struct drm_debugfs_info drm_atomic_debugfs_list[] = { {"state", drm_state_info, 0}, }; -void drm_atomic_debugfs_init(struct drm_minor *minor) +void drm_atomic_debugfs_init(struct drm_device *dev) { - drm_debugfs_add_files(minor->dev, drm_atomic_debugfs_list, + drm_debugfs_add_files(dev, drm_atomic_debugfs_list, ARRAY_SIZE(drm_atomic_debugfs_list)); } #endif diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index 39e68e45bb12..30d66bee0ec6 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -1384,9 +1384,9 @@ static const struct drm_debugfs_info drm_bridge_debugfs_list[] = { { "bridge_chains", drm_bridge_chains_info, 0 }, }; -void drm_bridge_debugfs_init(struct drm_minor *minor) +void drm_bridge_debugfs_init(struct drm_device *dev) { - drm_debugfs_add_files(minor->dev, drm_bridge_debugfs_list, + drm_debugfs_add_files(dev, drm_bridge_debugfs_list, ARRAY_SIZE(drm_bridge_debugfs_list)); } #endif diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index 037e36f2049c..2762572f286e 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -535,9 +535,9 @@ static const struct drm_debugfs_info drm_client_debugfs_list[] = { { "internal_clients", drm_client_debugfs_internal_clients, 0 }, }; -void drm_client_debugfs_init(struct drm_minor *minor) +void drm_client_debugfs_init(struct drm_device *dev) { - drm_debugfs_add_files(minor->dev, drm_client_debugfs_list, + drm_debugfs_add_files(dev, drm_client_debugfs_list, ARRAY_SIZE(drm_client_debugfs_list)); } #endif diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h index 501a10edd0e1..8556c3b3ff88 100644 --- a/drivers/gpu/drm/drm_crtc_internal.h +++ b/drivers/gpu/drm/drm_crtc_internal.h @@ -232,7 +232,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev, /* drm_atomic.c */ #ifdef CONFIG_DEBUG_FS struct drm_minor; -void drm_atomic_debugfs_init(struct drm_minor *minor); +void drm_atomic_debugfs_init(struct drm_device *dev); #endif int __drm_atomic_helper_disable_plane(struct drm_plane *plane, diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 8a4c90fd9f02..5ec28c0e12d9 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -266,8 +266,46 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count, } EXPORT_SYMBOL(drm_debugfs_create_files); -int drm_debugfs_init(struct drm_minor *minor, int minor_id, - struct dentry *root) +/** + * drm_debugfs_dev_init - create debugfs directory for the device + * @dev: the device which we want to create the directory for + * @root: the parent directory depending on the device type + * + * Creates the debugfs directory for the device under the given root directory. + */ +void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) +{ + dev->debugfs_root = debugfs_create_dir(dev->unique, root); +} + +/** + * drm_debugfs_dev_fini - cleanup debugfs directory + * @dev: the device to cleanup the debugfs stuff + * + * Remove the debugfs directory, might be called multiple times. + */ +void drm_debugfs_dev_fini(struct drm_device *dev) +{ + debugfs_remove_recursive(dev->debugfs_root); + dev->debugfs_root = NULL; +} + +void drm_debugfs_dev_register(struct drm_device *dev) +{ + drm_debugfs_add_files(dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES); + + if (drm_core_check_feature(dev, DRIVER_MODESET)) { + drm_framebuffer_debugfs_init(dev); + drm_client_debugfs_init(dev); + } + if (drm_drv_uses_atomic_modeset(dev)) { + drm_atomic_debugfs_init(dev); + drm_bridge_debugfs_init(dev); + } +} + +int drm_debugfs_register(struct drm_minor *minor, int minor_id, + struct dentry *root) { struct drm_device *dev = minor->dev; struct drm_debugfs_entry *entry, *tmp; @@ -276,20 +314,11 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id, INIT_LIST_HEAD(&minor->debugfs_list); mutex_init(&minor->debugfs_lock); sprintf(name, "%d", minor_id); - minor->debugfs_root = debugfs_create_dir(name, root); - - drm_debugfs_add_files(minor->dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES); + minor->debugfs_symlink = debugfs_create_symlink(name, root, + dev->unique); - if (drm_drv_uses_atomic_modeset(dev)) { - drm_atomic_debugfs_init(minor); - drm_bridge_debugfs_init(minor); - } - - if (drm_core_check_feature(dev, DRIVER_MODESET)) { - drm_framebuffer_debugfs_init(minor); - - drm_client_debugfs_init(minor); - } + /* TODO: Only for compatibility with drivers */ + minor->debugfs_root = dev->debugfs_root; if (dev->driver->debugfs_init && dev->render != minor) dev->driver->debugfs_init(minor); @@ -356,13 +385,12 @@ static void drm_debugfs_remove_all_files(struct drm_minor *minor) void drm_debugfs_cleanup(struct drm_minor *minor) { - if (!minor->debugfs_root) + if (!minor->debugfs_symlink) return; drm_debugfs_remove_all_files(minor); - - debugfs_remove_recursive(minor->debugfs_root); - minor->debugfs_root = NULL; + debugfs_remove(minor->debugfs_symlink); + minor->debugfs_symlink = NULL; } /** @@ -547,13 +575,13 @@ static const struct file_operations drm_connector_fops = { void drm_debugfs_connector_add(struct drm_connector *connector) { - struct drm_minor *minor = connector->dev->primary; + struct drm_device *dev = connector->dev; struct dentry *root; - if (!minor->debugfs_root) + if (!dev->debugfs_root) return; - root = debugfs_create_dir(connector->name, minor->debugfs_root); + root = debugfs_create_dir(connector->name, dev->debugfs_root); connector->debugfs_entry = root; /* force */ @@ -588,7 +616,7 @@ void drm_debugfs_connector_remove(struct drm_connector *connector) void drm_debugfs_crtc_add(struct drm_crtc *crtc) { - struct drm_minor *minor = crtc->dev->primary; + struct drm_device *dev = crtc->dev; struct dentry *root; char *name; @@ -596,7 +624,7 @@ void drm_debugfs_crtc_add(struct drm_crtc *crtc) if (!name) return; - root = debugfs_create_dir(name, minor->debugfs_root); + root = debugfs_create_dir(name, dev->debugfs_root); kfree(name); crtc->debugfs_entry = root; diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 3eda026ffac6..d28f415cd733 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -172,10 +172,9 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) if (!minor) return 0; - if (minor->type == DRM_MINOR_ACCEL) { - accel_debugfs_init(minor, minor->index); - } else { - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); + if (minor->type != DRM_MINOR_ACCEL) { + ret = drm_debugfs_register(minor, minor->index, + drm_debugfs_root); if (ret) { DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); goto err_debugfs; @@ -697,6 +696,11 @@ static int drm_dev_init(struct drm_device *dev, goto err; } + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) + accel_debugfs_init(dev); + else + drm_debugfs_dev_init(dev, drm_debugfs_root); + return 0; err: @@ -786,6 +790,9 @@ static void drm_dev_release(struct kref *ref) { struct drm_device *dev = container_of(ref, struct drm_device, ref); + /* Just in case register/unregister was never called */ + drm_debugfs_dev_fini(dev); + if (dev->driver->release) dev->driver->release(dev); @@ -916,6 +923,11 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) if (drm_dev_needs_global_mutex(dev)) mutex_lock(&drm_global_mutex); + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) + accel_debugfs_register(dev); + else + drm_debugfs_dev_register(dev); + ret = drm_minor_register(dev, DRM_MINOR_RENDER); if (ret) goto err_minors; @@ -1001,6 +1013,7 @@ void drm_dev_unregister(struct drm_device *dev) drm_minor_unregister(dev, DRM_MINOR_ACCEL); drm_minor_unregister(dev, DRM_MINOR_PRIMARY); drm_minor_unregister(dev, DRM_MINOR_RENDER); + drm_debugfs_dev_fini(dev); } EXPORT_SYMBOL(drm_dev_unregister); diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index aff3746dedfb..ba51deb6d042 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -1222,9 +1222,9 @@ static const struct drm_debugfs_info drm_framebuffer_debugfs_list[] = { { "framebuffer", drm_framebuffer_info, 0 }, }; -void drm_framebuffer_debugfs_init(struct drm_minor *minor) +void drm_framebuffer_debugfs_init(struct drm_device *dev) { - drm_debugfs_add_files(minor->dev, drm_framebuffer_debugfs_list, + drm_debugfs_add_files(dev, drm_framebuffer_debugfs_list, ARRAY_SIZE(drm_framebuffer_debugfs_list)); } #endif diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index ba12acd55139..dee75a9cc59e 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -180,8 +180,10 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map); /* drm_debugfs.c drm_debugfs_crc.c */ #if defined(CONFIG_DEBUG_FS) -int drm_debugfs_init(struct drm_minor *minor, int minor_id, - struct dentry *root); +void drm_debugfs_dev_fini(struct drm_device *dev); +void drm_debugfs_dev_register(struct drm_device *dev); +int drm_debugfs_register(struct drm_minor *minor, int minor_id, + struct dentry *root); void drm_debugfs_cleanup(struct drm_minor *minor); void drm_debugfs_late_register(struct drm_device *dev); void drm_debugfs_connector_add(struct drm_connector *connector); @@ -190,8 +192,16 @@ void drm_debugfs_crtc_add(struct drm_crtc *crtc); void drm_debugfs_crtc_remove(struct drm_crtc *crtc); void drm_debugfs_crtc_crc_add(struct drm_crtc *crtc); #else -static inline int drm_debugfs_init(struct drm_minor *minor, int minor_id, - struct dentry *root) +static inline void drm_debugfs_dev_fini(struct drm_device *dev) +{ +} + +static inline void drm_debugfs_dev_register(struct drm_device *dev) +{ +} + +static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id, + struct dentry *root) { return 0; } @@ -259,4 +269,4 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, /* drm_framebuffer.c */ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent, const struct drm_framebuffer *fb); -void drm_framebuffer_debugfs_init(struct drm_minor *minor); +void drm_framebuffer_debugfs_init(struct drm_device *dev); diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h index d4955062c77e..f4d3784b1dce 100644 --- a/include/drm/drm_accel.h +++ b/include/drm/drm_accel.h @@ -58,7 +58,8 @@ int accel_minor_alloc(void); void accel_minor_replace(struct drm_minor *minor, int index); void accel_set_device_instance_params(struct device *kdev, int index); int accel_open(struct inode *inode, struct file *filp); -void accel_debugfs_init(struct drm_minor *minor, int minor_id); +void accel_debugfs_init(struct drm_device *dev); +void accel_debugfs_register(struct drm_device *dev); #else @@ -89,7 +90,11 @@ static inline void accel_set_device_instance_params(struct device *kdev, int ind { } -static inline void accel_debugfs_init(struct drm_minor *minor, int minor_id) +static inline void accel_debugfs_init(struct drm_device *dev) +{ +} + +static inline void accel_debugfs_register(struct drm_device *dev) { } diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index c339fc85fd07..2dd94224f17e 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -950,6 +950,6 @@ static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, } #endif -void drm_bridge_debugfs_init(struct drm_minor *minor); +void drm_bridge_debugfs_init(struct drm_device *dev); #endif diff --git a/include/drm/drm_client.h b/include/drm/drm_client.h index c0a14b40c039..d47458ecdac4 100644 --- a/include/drm/drm_client.h +++ b/include/drm/drm_client.h @@ -195,6 +195,6 @@ int drm_client_modeset_dpms(struct drm_client_dev *client, int mode); drm_for_each_connector_iter(connector, iter) \ if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) -void drm_client_debugfs_init(struct drm_minor *minor); +void drm_client_debugfs_init(struct drm_device *dev); #endif diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h index 7cf4afae2e79..3cf12b14232d 100644 --- a/include/drm/drm_device.h +++ b/include/drm/drm_device.h @@ -311,6 +311,13 @@ struct drm_device { */ struct drm_fb_helper *fb_helper; + /** + * @debugfs_root: + * + * Root directory for debugfs files. + */ + struct dentry *debugfs_root; + /** * @debugfs_mutex: * diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 9813fa759b75..9850fe73b739 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -581,4 +581,12 @@ static inline bool drm_firmware_drivers_only(void) return video_firmware_drivers_only(); } +#if defined(CONFIG_DEBUG_FS) +void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root); +#else +static void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root) +{ +} +#endif + #endif diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 010239392adf..12930a08368c 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -79,6 +79,7 @@ struct drm_minor { struct device *kdev; /* Linux device */ struct drm_device *dev; + struct dentry *debugfs_symlink; struct dentry *debugfs_root; struct list_head debugfs_list; From patchwork Tue Aug 29 11:01:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13368864 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AED4CC83F14 for ; Tue, 29 Aug 2023 11:01:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EFBD410E211; Tue, 29 Aug 2023 11:01:33 +0000 (UTC) Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by gabe.freedesktop.org (Postfix) with ESMTPS id 875A110E208 for ; Tue, 29 Aug 2023 11:01:22 +0000 (UTC) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2bd0d135ca3so32431401fa.3 for ; Tue, 29 Aug 2023 04:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693306880; x=1693911680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=uAhalCqAhdUzBu/ynF+9e8oMQrjjlxPT909+OFBIO3I=; b=T0GjU85QkrOT0IDuXFGZzTcej2utcbYrigVVIVE9Mx4n3uzjksr3PIgRltAIXeRY/x IpLWbrTKyPmO4JaoOLzdpgfY1OB8k030Jn5WjxPnDnRKIouA776E0Y/d4uyBrWVTupR8 dpXCUT3Gnd4444oWolxaSOZfdSNpAm2jPI8VxGXgaWWLiV+Ik12LuMuOXn8602QnKuNt rFeUBSsxKAbC0po4lO2kmx+youOJHt60s3P0Kb8R/3i9ccaBFmkq34moTd+JSwt6PeMQ EBM45NVlYv7LFxrN4tmj1aoIOWuBaBOZQ9uP8p0uMS0dyjL22U0rZ0hOpr308jBRGVZJ HISg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693306880; x=1693911680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uAhalCqAhdUzBu/ynF+9e8oMQrjjlxPT909+OFBIO3I=; b=RvwWs+F7yBdK2j/KRbBjD5S2HvPkXg0baXuQDMSRRI3RO09g+vPaMHZEBYw9qgC0/u BWuPnrSKft7FvWitgSxk30s0NcppFZFaZyHYDc4Oet3QBfXDTJPD8Z+rJ/xazpYH7fYS mS8LnjNmkrvz6UPFhlhox2Uw7kl9ZnY1kaj8nLhusWTdOfKdu6MWUOiAwHkxOcqCwit7 b9hpv4YMSdD19ASCJrBkL6ROfyuegfpaJID0u2JXkdK4sIN27TY8rh4CBDVTa2EKcnH8 ccTFJ3jrhxagVkh7xSjdOWWsDpviNMAXmyBgUvCreHfz3Zn7x1Kizh1Q321Ee/GFKzGK sEPA== X-Gm-Message-State: AOJu0YzD62XbeDJeGain8o0/NpBCeJFOJCZ+oKkYIum87BVn1EyPNvuk hAIGE4jODAM7XfkPDE4fBAE= X-Google-Smtp-Source: AGHT+IFNRdSF6LaAilKhiMST+7ASnJNz4jWFp86MZT2y/gNDsYmY8R8G83pg+4BPgcn+6AajWtM7sA== X-Received: by 2002:a2e:7810:0:b0:2bc:f1e2:9043 with SMTP id t16-20020a2e7810000000b002bcf1e29043mr8233384ljc.26.1693306880488; Tue, 29 Aug 2023 04:01:20 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:158b:d500:cd84:8e32:621d:b36b]) by smtp.gmail.com with ESMTPSA id i27-20020a1709063c5b00b009928b4e3b9fsm5805885ejg.114.2023.08.29.04.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 04:01:20 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: ogabbay@kernel.org, ttayar@habana.ai, dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Date: Tue, 29 Aug 2023 13:01:14 +0200 Message-Id: <20230829110115.3442-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829110115.3442-1-christian.koenig@amd.com> References: <20230829110115.3442-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The mutex was completely pointless in the first place since any parallel adding of files to this list would result in random behavior since the list is filled and consumed multiple times. Completely drop that approach and just create the files directly but return -ENODEV while opening the file when the minors are not registered yet. v2: rebase on debugfs directory rework, limit access before minors are registered. Signed-off-by: Christian König Reviewed-by: Andi Shyti --- drivers/gpu/drm/drm_debugfs.c | 27 ++------------------------- drivers/gpu/drm/drm_drv.c | 3 --- drivers/gpu/drm/drm_internal.h | 5 ----- drivers/gpu/drm/drm_mode_config.c | 2 -- include/drm/drm_device.h | 15 --------------- 5 files changed, 2 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 5ec28c0e12d9..d0c6492d5de1 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -308,7 +308,6 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id, struct dentry *root) { struct drm_device *dev = minor->dev; - struct drm_debugfs_entry *entry, *tmp; char name[64]; INIT_LIST_HEAD(&minor->debugfs_list); @@ -323,30 +322,9 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id, if (dev->driver->debugfs_init && dev->render != minor) dev->driver->debugfs_init(minor); - list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) { - debugfs_create_file(entry->file.name, 0444, - minor->debugfs_root, entry, &drm_debugfs_entry_fops); - list_del(&entry->list); - } - return 0; } -void drm_debugfs_late_register(struct drm_device *dev) -{ - struct drm_minor *minor = dev->primary; - struct drm_debugfs_entry *entry, *tmp; - - if (!minor) - return; - - list_for_each_entry_safe(entry, tmp, &dev->debugfs_list, list) { - debugfs_create_file(entry->file.name, 0444, - minor->debugfs_root, entry, &drm_debugfs_entry_fops); - list_del(&entry->list); - } -} - int drm_debugfs_remove_files(const struct drm_info_list *files, int count, struct drm_minor *minor) { @@ -416,9 +394,8 @@ void drm_debugfs_add_file(struct drm_device *dev, const char *name, entry->file.data = data; entry->dev = dev; - mutex_lock(&dev->debugfs_mutex); - list_add(&entry->list, &dev->debugfs_list); - mutex_unlock(&dev->debugfs_mutex); + debugfs_create_file(name, 0444, dev->debugfs_root, entry, + &drm_debugfs_entry_fops); } EXPORT_SYMBOL(drm_debugfs_add_file); diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index d28f415cd733..45053f3371ca 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -597,7 +597,6 @@ static void drm_dev_init_release(struct drm_device *dev, void *res) mutex_destroy(&dev->clientlist_mutex); mutex_destroy(&dev->filelist_mutex); mutex_destroy(&dev->struct_mutex); - mutex_destroy(&dev->debugfs_mutex); drm_legacy_destroy_members(dev); } @@ -638,14 +637,12 @@ static int drm_dev_init(struct drm_device *dev, INIT_LIST_HEAD(&dev->filelist_internal); INIT_LIST_HEAD(&dev->clientlist); INIT_LIST_HEAD(&dev->vblank_event_list); - INIT_LIST_HEAD(&dev->debugfs_list); spin_lock_init(&dev->event_lock); mutex_init(&dev->struct_mutex); mutex_init(&dev->filelist_mutex); mutex_init(&dev->clientlist_mutex); mutex_init(&dev->master_mutex); - mutex_init(&dev->debugfs_mutex); ret = drmm_add_action_or_reset(dev, drm_dev_init_release, NULL); if (ret) diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index dee75a9cc59e..ec8a1e9c19e8 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -185,7 +185,6 @@ void drm_debugfs_dev_register(struct drm_device *dev); int drm_debugfs_register(struct drm_minor *minor, int minor_id, struct dentry *root); void drm_debugfs_cleanup(struct drm_minor *minor); -void drm_debugfs_late_register(struct drm_device *dev); void drm_debugfs_connector_add(struct drm_connector *connector); void drm_debugfs_connector_remove(struct drm_connector *connector); void drm_debugfs_crtc_add(struct drm_crtc *crtc); @@ -210,10 +209,6 @@ static inline void drm_debugfs_cleanup(struct drm_minor *minor) { } -static inline void drm_debugfs_late_register(struct drm_device *dev) -{ -} - static inline void drm_debugfs_connector_add(struct drm_connector *connector) { } diff --git a/drivers/gpu/drm/drm_mode_config.c b/drivers/gpu/drm/drm_mode_config.c index 87eb591fe9b5..8525ef851540 100644 --- a/drivers/gpu/drm/drm_mode_config.c +++ b/drivers/gpu/drm/drm_mode_config.c @@ -54,8 +54,6 @@ int drm_modeset_register_all(struct drm_device *dev) if (ret) goto err_connector; - drm_debugfs_late_register(dev); - return 0; err_connector: diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h index 3cf12b14232d..c490977ee250 100644 --- a/include/drm/drm_device.h +++ b/include/drm/drm_device.h @@ -318,21 +318,6 @@ struct drm_device { */ struct dentry *debugfs_root; - /** - * @debugfs_mutex: - * - * Protects &debugfs_list access. - */ - struct mutex debugfs_mutex; - - /** - * @debugfs_list: - * - * List of debugfs files to be created by the DRM device. The files - * must be added during drm_dev_register(). - */ - struct list_head debugfs_list; - /* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED(CONFIG_DRM_LEGACY) From patchwork Tue Aug 29 11:01:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 13368865 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBC6EC6FA8F for ; Tue, 29 Aug 2023 11:01:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C7E210E213; Tue, 29 Aug 2023 11:01:35 +0000 (UTC) Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by gabe.freedesktop.org (Postfix) with ESMTPS id F1AC210E208 for ; Tue, 29 Aug 2023 11:01:22 +0000 (UTC) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bbbda48904so63925921fa.2 for ; Tue, 29 Aug 2023 04:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693306881; x=1693911681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=i1oK4e+U8y7KWzLi+wTdhv+UD/YbPDLmQluK2zJmg+o=; b=CzmFTSPTKEgQR72UulI0zPRQ5CTjE6tAqiVsAxZkXkhPvIU0HsHlMU3PXHAS93aKkW zQWFlDpLrutCoXlTtePURoavnbDnoy1wG/Kv/ghhYd7bNC7ZJbMfSArsH2cCt2MI/cW/ iKDAKnUkXrpDIrkNnHvvRRynd7SK2oIWhXSjKxQeya6uQIuUi/Jd5AJFVim1wXjdH0FZ XZ+h3eO9M2uxw34WxIOqCuQf6qp1P0GcRK0C2ZX4G199A8dtufwGK1PegUpHYCyCDjuB wgpZ7j/kSTQL8wgRDEUOuCQQHP0YVB2LLwSBBseG0189ZQ54+KQou3nIPgS+iBDi5Kuq PSgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693306881; x=1693911681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i1oK4e+U8y7KWzLi+wTdhv+UD/YbPDLmQluK2zJmg+o=; b=XAjub5QtTUhS3LgKwE6vShpKumRnvVlo9zoFNPwGqJ/aXx65tEcI+knY78PfleAwWN MJ/MdFXSoJsCsgVo9Skhaadp0su8YQXM92dPC6+MtloQy5ISwSGMDeJ3E/PxQCfXwdQL P3KURMql52SCKSY0D6oHZ/N4lrt/5WLJaZPXhdCQnV7Zg7QmnFzNtn0njkmuaShPGUD0 nklZx2FBudsplsi6MYNorlKhgJdwXLUsMm859lFzOXDAJwSKHBjSk0woztIalrJ7ghE9 Lm6wGh1MyeU9X22AxMYk53FyRrd78fFxNA9ZPD8pJw+tD8vBWta48pUq1m5HEPhom1Zk wfmQ== X-Gm-Message-State: AOJu0YzMuO6elounOnUXIhv9aCSDBmW6INiB5OWgKFGUIOoF2Spexo3V otKF1g2Z8yEdLaMhB8V5HPY= X-Google-Smtp-Source: AGHT+IFUTcAhUqDqmz8gA06zTcE670yyAUCS68KW2+YYD8ys2nrRcumJBgiPNZfeEtCh7MdmikO6nQ== X-Received: by 2002:a2e:b0d8:0:b0:2bc:f5a0:cc25 with SMTP id g24-20020a2eb0d8000000b002bcf5a0cc25mr8272961ljl.2.1693306881171; Tue, 29 Aug 2023 04:01:21 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:158b:d500:cd84:8e32:621d:b36b]) by smtp.gmail.com with ESMTPSA id i27-20020a1709063c5b00b009928b4e3b9fsm5805885ejg.114.2023.08.29.04.01.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 04:01:20 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: ogabbay@kernel.org, ttayar@habana.ai, dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation v2 Date: Tue, 29 Aug 2023 13:01:15 +0200 Message-Id: <20230829110115.3442-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829110115.3442-1-christian.koenig@amd.com> References: <20230829110115.3442-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use managed memory allocation for this. That allows us to not keep track of all the files any more. v2: keep drm_debugfs_cleanup(), but rename to drm_debugfs_unregister(), we still need to cleanup the symlink Signed-off-by: Christian König Reviewed-by: Andi Shyti --- drivers/accel/drm_accel.c | 2 - drivers/gpu/drm/drm_debugfs.c | 70 ++++++++++------------------------ drivers/gpu/drm/drm_drv.c | 4 +- drivers/gpu/drm/drm_internal.h | 4 +- drivers/gpu/drm/tegra/dc.c | 9 ++++- drivers/gpu/drm/tegra/dsi.c | 1 + drivers/gpu/drm/tegra/hdmi.c | 3 +- drivers/gpu/drm/tegra/sor.c | 1 + include/drm/drm_debugfs.h | 4 +- include/drm/drm_file.h | 3 -- 10 files changed, 39 insertions(+), 62 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 8ba3db2ec5bb..94b4ac12cf24 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -99,8 +99,6 @@ void accel_debugfs_register(struct drm_device *dev) { struct drm_minor *minor = dev->accel; - INIT_LIST_HEAD(&minor->debugfs_list); - mutex_init(&minor->debugfs_lock); minor->debugfs_root = dev->debugfs_root; drm_debugfs_create_files(accel_debugfs_list, ACCEL_DEBUGFS_ENTRIES, diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index d0c6492d5de1..34c7d1a580e3 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -234,7 +234,7 @@ EXPORT_SYMBOL(drm_debugfs_gpuva_info); * * Create a given set of debugfs files represented by an array of * &struct drm_info_list in the given root directory. These files will be removed - * automatically on drm_debugfs_cleanup(). + * automatically on drm_debugfs_dev_fini(). */ void drm_debugfs_create_files(const struct drm_info_list *files, int count, struct dentry *root, struct drm_minor *minor) @@ -249,7 +249,7 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count, if (features && !drm_core_check_all_features(dev, features)) continue; - tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL); + tmp = drmm_kzalloc(dev, sizeof(*tmp), GFP_KERNEL); if (tmp == NULL) continue; @@ -258,14 +258,28 @@ void drm_debugfs_create_files(const struct drm_info_list *files, int count, 0444, root, tmp, &drm_debugfs_fops); tmp->info_ent = &files[i]; - - mutex_lock(&minor->debugfs_lock); - list_add(&tmp->list, &minor->debugfs_list); - mutex_unlock(&minor->debugfs_lock); } } EXPORT_SYMBOL(drm_debugfs_create_files); +int drm_debugfs_remove_files(const struct drm_info_list *files, int count, + struct dentry *root, struct drm_minor *minor) +{ + int i; + + for (i = 0; i < count; i++) { + struct dentry *dent = debugfs_lookup(files[i].name, root); + + if (!dent) + continue; + + drmm_kfree(minor->dev, d_inode(dent)->i_private); + debugfs_remove(dent); + } + return 0; +} +EXPORT_SYMBOL(drm_debugfs_remove_files); + /** * drm_debugfs_dev_init - create debugfs directory for the device * @dev: the device which we want to create the directory for @@ -310,8 +324,6 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id, struct drm_device *dev = minor->dev; char name[64]; - INIT_LIST_HEAD(&minor->debugfs_list); - mutex_init(&minor->debugfs_lock); sprintf(name, "%d", minor_id); minor->debugfs_symlink = debugfs_create_symlink(name, root, dev->unique); @@ -325,48 +337,8 @@ int drm_debugfs_register(struct drm_minor *minor, int minor_id, return 0; } -int drm_debugfs_remove_files(const struct drm_info_list *files, int count, - struct drm_minor *minor) -{ - struct list_head *pos, *q; - struct drm_info_node *tmp; - int i; - - mutex_lock(&minor->debugfs_lock); - for (i = 0; i < count; i++) { - list_for_each_safe(pos, q, &minor->debugfs_list) { - tmp = list_entry(pos, struct drm_info_node, list); - if (tmp->info_ent == &files[i]) { - debugfs_remove(tmp->dent); - list_del(pos); - kfree(tmp); - } - } - } - mutex_unlock(&minor->debugfs_lock); - return 0; -} -EXPORT_SYMBOL(drm_debugfs_remove_files); - -static void drm_debugfs_remove_all_files(struct drm_minor *minor) -{ - struct drm_info_node *node, *tmp; - - mutex_lock(&minor->debugfs_lock); - list_for_each_entry_safe(node, tmp, &minor->debugfs_list, list) { - debugfs_remove(node->dent); - list_del(&node->list); - kfree(node); - } - mutex_unlock(&minor->debugfs_lock); -} - -void drm_debugfs_cleanup(struct drm_minor *minor) +void drm_debugfs_unregister(struct drm_minor *minor) { - if (!minor->debugfs_symlink) - return; - - drm_debugfs_remove_all_files(minor); debugfs_remove(minor->debugfs_symlink); minor->debugfs_symlink = NULL; } diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 45053f3371ca..535f16e7882e 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -198,7 +198,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) return 0; err_debugfs: - drm_debugfs_cleanup(minor); + drm_debugfs_unregister(minor); return ret; } @@ -222,7 +222,7 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ - drm_debugfs_cleanup(minor); + drm_debugfs_unregister(minor); } /* diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index ec8a1e9c19e8..ab9a472f4a47 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -184,7 +184,7 @@ void drm_debugfs_dev_fini(struct drm_device *dev); void drm_debugfs_dev_register(struct drm_device *dev); int drm_debugfs_register(struct drm_minor *minor, int minor_id, struct dentry *root); -void drm_debugfs_cleanup(struct drm_minor *minor); +void drm_debugfs_unregister(struct drm_minor *minor); void drm_debugfs_connector_add(struct drm_connector *connector); void drm_debugfs_connector_remove(struct drm_connector *connector); void drm_debugfs_crtc_add(struct drm_crtc *crtc); @@ -205,7 +205,7 @@ static inline int drm_debugfs_register(struct drm_minor *minor, int minor_id, return 0; } -static inline void drm_debugfs_cleanup(struct drm_minor *minor) +static inline void drm_debugfs_unregister(struct drm_minor *minor) { } diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 13b182ab905f..be61c9d1a4f0 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -1746,8 +1746,15 @@ static void tegra_dc_early_unregister(struct drm_crtc *crtc) unsigned int count = ARRAY_SIZE(debugfs_files); struct drm_minor *minor = crtc->dev->primary; struct tegra_dc *dc = to_tegra_dc(crtc); + struct dentry *root; + +#ifdef CONFIG_DEBUG_FS + root = crtc->debugfs_entry; +#else + root = NULL; +#endif - drm_debugfs_remove_files(dc->debugfs_files, count, minor); + drm_debugfs_remove_files(dc->debugfs_files, count, root, minor); kfree(dc->debugfs_files); dc->debugfs_files = NULL; } diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c index a9870c828374..fbfe92a816d4 100644 --- a/drivers/gpu/drm/tegra/dsi.c +++ b/drivers/gpu/drm/tegra/dsi.c @@ -256,6 +256,7 @@ static void tegra_dsi_early_unregister(struct drm_connector *connector) struct tegra_dsi *dsi = to_dsi(output); drm_debugfs_remove_files(dsi->debugfs_files, count, + connector->debugfs_entry, connector->dev->primary); kfree(dsi->debugfs_files); dsi->debugfs_files = NULL; diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c index 80c760986d9e..0ba3ca3ac509 100644 --- a/drivers/gpu/drm/tegra/hdmi.c +++ b/drivers/gpu/drm/tegra/hdmi.c @@ -1116,7 +1116,8 @@ static void tegra_hdmi_early_unregister(struct drm_connector *connector) unsigned int count = ARRAY_SIZE(debugfs_files); struct tegra_hdmi *hdmi = to_hdmi(output); - drm_debugfs_remove_files(hdmi->debugfs_files, count, minor); + drm_debugfs_remove_files(hdmi->debugfs_files, count, + connector->debugfs_entry, minor); kfree(hdmi->debugfs_files); hdmi->debugfs_files = NULL; } diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c index 61b437a84806..d5a3d3f4fece 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -1708,6 +1708,7 @@ static void tegra_sor_early_unregister(struct drm_connector *connector) struct tegra_sor *sor = to_sor(output); drm_debugfs_remove_files(sor->debugfs_files, count, + connector->debugfs_entry, connector->dev->primary); kfree(sor->debugfs_files); sor->debugfs_files = NULL; diff --git a/include/drm/drm_debugfs.h b/include/drm/drm_debugfs.h index cb2c1956a214..7213ce15e4ff 100644 --- a/include/drm/drm_debugfs.h +++ b/include/drm/drm_debugfs.h @@ -142,8 +142,8 @@ struct drm_debugfs_entry { void drm_debugfs_create_files(const struct drm_info_list *files, int count, struct dentry *root, struct drm_minor *minor); -int drm_debugfs_remove_files(const struct drm_info_list *files, - int count, struct drm_minor *minor); +int drm_debugfs_remove_files(const struct drm_info_list *files, int count, + struct dentry *root, struct drm_minor *minor); void drm_debugfs_add_file(struct drm_device *dev, const char *name, int (*show)(struct seq_file*, void*), void *data); diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 12930a08368c..489cc3758a82 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -81,9 +81,6 @@ struct drm_minor { struct dentry *debugfs_symlink; struct dentry *debugfs_root; - - struct list_head debugfs_list; - struct mutex debugfs_lock; /* Protects debugfs_list. */ }; /**