From patchwork Mon Apr 24 12:30:24 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: 13222085 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 3E65EC7618E for ; Mon, 24 Apr 2023 12:30:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F66510E4D9; Mon, 24 Apr 2023 12:30:34 +0000 (UTC) Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by gabe.freedesktop.org (Postfix) with ESMTPS id 87B1E10E4D4 for ; Mon, 24 Apr 2023 12:30:32 +0000 (UTC) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-959a626b622so145385166b.0 for ; Mon, 24 Apr 2023 05:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339430; x=1684931430; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zQmjReLMkxtS3Ylf9Gai6KIzJluY9/zyQyab67UImSw=; b=RvL4Wg7DTMmhUx+Ixuj6uUuOvRuSlXaAetqVK0NYggnzCU6ishQuvPfI/1mWi0NuEf +DHkenLS0Ag+kq4tesHSCeq+wduu6xsRbx9ZCW1f9CLTEwG7+cU9pCC6j0bqbGSaCK17 1xkKPwFLLWqwpeAmy86FxZZ7NTkLI7J7ovGxWGYPxN0Kb7ynK9NZCwBwJWyaSyykkUNt flGuaKyJAC+xbzT0xN8CdrfLSnpaOvazlstw6gwaUEkCZT0pyjDV907gmB+235Xj4OZP 47jC8vyc9HkMMFZCFhPG2M+2IUfEv3fbry1+67QOWFfFfqWX7uklcrkC2JYij+8or9c1 rAbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339430; x=1684931430; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zQmjReLMkxtS3Ylf9Gai6KIzJluY9/zyQyab67UImSw=; b=E6KE/3NQN8rT5NOTzAD3qdeNUpphs2/fDukdVtXty1cf1UajW0TGCdhHU3XskEeb6C rcaJ5VtNUxKVKiUcQOPZdC/uyM4FxPGPJytEiVl5r/vbWeoPTE2ZGQUQM+5HB0T4VxNx 2NDbMpm/Tb5yk3Fwb7qetwraW1JEyq2+Cd30qlpt69J/aUNIwTvktOtCCD3I+wr7QjEe qYLFahDHZwRdNnQJxhv16QNWHZEo/X5dvC52wY/lSDBF2aZHsD8RQjVEbzypjiqaYbak V+mbBrjuJY/Dszjz6GB2b3AhgdIIOqcTvqgdwy4+JtRVXKYLj5JVa0ndw2ViR6owIgiN rL8Q== X-Gm-Message-State: AAQBX9cFkUrr0CUHFf2+dnj6crk1H9RAyxveZVvO8ZTNnDjA8iBkds+s PmQSRUpEnPN7w/XQtdWUjhISYKnUvlb0zw== X-Google-Smtp-Source: AKy350asOvRRpjEPfAgWDVNGbm71Rs/paoYPnEm5MbgIhCgjG/J+yYx8xHEg+hfAqtECCvHfLpO5WA== X-Received: by 2002:a17:906:14e:b0:94f:8605:3f31 with SMTP id 14-20020a170906014e00b0094f86053f31mr10376608ejh.42.1682339430347; Mon, 24 Apr 2023 05:30:30 -0700 (PDT) Received: from able.fritz.box (p4fc2092b.dip0.t-ipconnect.de. [79.194.9.43]) by smtp.gmail.com with ESMTPSA id wv14-20020a170907080e00b009598cbe55c2sm1608146ejb.28.2023.04.24.05.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 05:30:29 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Date: Mon, 24 Apr 2023 14:30:24 +0200 Message-Id: <20230424123028.25986-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 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 --- 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 1b69824286fd..d473388ee807 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 4855230ba2c6..54376e2400bb 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -242,7 +242,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 Mon Apr 24 12:30:25 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: 13222089 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 81570C7618E for ; Mon, 24 Apr 2023 12:30:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A46D10E4E4; Mon, 24 Apr 2023 12:30:54 +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 EAAB810E4D4 for ; Mon, 24 Apr 2023 12:30:32 +0000 (UTC) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-94f0dd117dcso610387566b.3 for ; Mon, 24 Apr 2023 05:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339431; x=1684931431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N9Uuouz6BCzdOfJmpXCASsGruHU4kdCFVbUUrlmsthg=; b=Ry9iK7sbT0TECKzVjDSCpDSl3yTofrBBVKHs/8TVP9JstWw9y9UpWq9wvdI0hOn7Zj ztDUM/FAeMcJqyxK9VOvJ6yrh2ZFFZqnwSGWxLHsN3U5OSPPA9qBjctRo98KGe/7hifH rk9EUSv7jz+PJyfziclwj6IHZlviWOKJJBdSrdbqVzApj7aA39ZNWCkZwJvaoDhL8+UP rfBEJv3rCHDnbHkieiUqr5o8bD6lpwrPwpHO5mwUvjme5RDRBngXRI/3E3hs9v3E+v22 Mkdoztv7bWiZSk02LxhuKNjsbLevVKxobx4+V9VbsnsZ9PhcugAtg4sGgpGGkYDZZv93 8cZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339431; x=1684931431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N9Uuouz6BCzdOfJmpXCASsGruHU4kdCFVbUUrlmsthg=; b=DdGNyqkpItWL6Hx1oz6o4+a3gz9veFi8zLnHuJYSzkPIdPb9dHw+Zx4UGz/yhoXprH 8bM/LP0e9QnaJsDOCsJCFGNxSLgT5yr/GqJD7EkFAnE5l7BTh00cg03+6xYIPjIsgHNG abQzk9odK1VlhDfxx5uoyPwS1DCV1Ul1cZVPRnWKf93Tz8WxN4HtxZfzcrFqmHj9scJ6 gj88W8x3AhmpMR2YtgM54rpp2Zsc9LqwfhNx/OfUO7VNSgiuQR+zrNVvkl7SD5IaOwN7 gDDDy8lCnKM0J+F9tmYtyR8UXP1GIjeodPrgjpedaUnlAIbqu4bEReb/ATUnqn5BL1kR 1zBg== X-Gm-Message-State: AAQBX9dkqJO1OZFP/Nn6LEcFM/lapIHOBkenSRXUMbSpoGQLUhyrqzgJ nRKcbCwvOizM9pvgkB7fKFD6jwKk8cr0mg== X-Google-Smtp-Source: AKy350bho1B1w700yDHgPFECkLGUJWHjR88gdV4FxIBSGpOvCxld8CNBmLAHYuU78eZYCRSidfC9rQ== X-Received: by 2002:a17:906:ecb7:b0:933:3a22:8513 with SMTP id qh23-20020a170906ecb700b009333a228513mr10168645ejb.53.1682339431155; Mon, 24 Apr 2023 05:30:31 -0700 (PDT) Received: from able.fritz.box (p4fc2092b.dip0.t-ipconnect.de. [79.194.9.43]) by smtp.gmail.com with ESMTPSA id wv14-20020a170907080e00b009598cbe55c2sm1608146ejb.28.2023.04.24.05.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 05:30:30 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Date: Mon, 24 Apr 2023 14:30:25 +0200 Message-Id: <20230424123028.25986-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424123028.25986-1-christian.koenig@amd.com> References: <20230424123028.25986-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 --- 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 54376e2400bb..796cda62ad12 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -148,6 +148,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); } @@ -155,6 +158,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 Mon Apr 24 12:30:26 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: 13222088 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 9BE22C77B61 for ; Mon, 24 Apr 2023 12:30:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6D1A310E4E1; Mon, 24 Apr 2023 12:30:54 +0000 (UTC) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by gabe.freedesktop.org (Postfix) with ESMTPS id 92CF810E4D4 for ; Mon, 24 Apr 2023 12:30:34 +0000 (UTC) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-94ef8b88a5bso630011966b.2 for ; Mon, 24 Apr 2023 05:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339432; x=1684931432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pnrZ62SgBhyflUFr2SdQjAavFXZxyFlW317Noj6bG1A=; b=Iw+6kXWsVdgCmSmzFAlfsn4/3ibTLSOjt4AFI/SpBeUBiaxXQsyrAauccj2zO/MyLX 2fqk+6QHeyFHWpgA2omQy7XNaDaaB2CTtaMsrHHzufJGpAFAEl8H7ZjpdZmZ+Gj5fqmL z/OPLYsA1JhfVzmI+0f5/EoyqInsiQv2KqS54/STjvpSlx8BOFYduKMNvfigKlPuEHU0 /HQw8ImLCksBKeZjLpa/+3lc10x7gW+gLfclCrS/LuoP0LWKl+eOgHD1p+EGKU+hN+bn 0BnQM/i2lDm/P49f0Q8I3JIJfmJSG+ptJooRVw+8yjK3ay6L6KR72UjRkyzOV9GadJug pIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339432; x=1684931432; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pnrZ62SgBhyflUFr2SdQjAavFXZxyFlW317Noj6bG1A=; b=B1skaY1ZrQwawHFi7LKIZndbiCV6BDwi5jxjbtgsCKWoi84hgRbeNTW7vP93I28ymm zNHT7xh/wHSIeJDoZ+cbmCE9LVbtP8g5dB+crPPOlbOxqu06dts/Vo7Q9QCVgcrcxq9f LMI90qJY/kWVLjp4C1j52NXCPIzgqrYG9mLH6nP4/gz3PQ9jiF85pam1uxiPYMpA7cIP vmhX3fYZZhBfNMA4wmo8BcJ5Cu6ZlX9sT/6GOmXqR5drFp43VurW6d/dqpFVxULZZgen NFGdqU7kau9nT6fdhb4XuSgO/eK0OlxjYWfJSuxd7h38q+HPzCHcoSr8J1qJeI6iLddw C2BQ== X-Gm-Message-State: AAQBX9fFmpgebF1xp49TweNmGPlA6yDCFIKQEo5SLyE3mOKXhXUTTFjE qjY77vy/YPYB7aTOjsnVEOYdRubXNN3p0Q== X-Google-Smtp-Source: AKy350avlIbTbjPLK1WY3cX+eg3GzcSkLKrLgl61yjmC4aC5uDcaL9AcNEcclYy4IAE5S8oDQQZenw== X-Received: by 2002:a17:906:7113:b0:94e:f969:fb3e with SMTP id x19-20020a170906711300b0094ef969fb3emr9993229ejj.43.1682339432178; Mon, 24 Apr 2023 05:30:32 -0700 (PDT) Received: from able.fritz.box (p4fc2092b.dip0.t-ipconnect.de. [79.194.9.43]) by smtp.gmail.com with ESMTPSA id wv14-20020a170907080e00b009598cbe55c2sm1608146ejb.28.2023.04.24.05.30.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 05:30:31 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/debugfs: rework debugfs directory creation v4 Date: Mon, 24 Apr 2023 14:30:26 +0200 Message-Id: <20230424123028.25986-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424123028.25986-1-christian.koenig@amd.com> References: <20230424123028.25986-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 Signed-off-by: Christian König --- drivers/accel/drm_accel.c | 27 +++++++---- drivers/gpu/drm/drm_atomic.c | 4 +- drivers/gpu/drm/drm_client.c | 4 +- drivers/gpu/drm/drm_crtc_internal.h | 2 +- drivers/gpu/drm/drm_debugfs.c | 73 ++++++++++++++++++++--------- 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_client.h | 2 +- include/drm/drm_device.h | 7 +++ include/drm/drm_drv.h | 8 ++++ include/drm/drm_file.h | 1 + 13 files changed, 130 insertions(+), 52 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index d473388ee807..34fda8a9b829 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -79,26 +79,33 @@ 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 + * accel_debugfs_init() - Initialize debugfs for device + * @dev: Pointer to the device instance. + * + * This function creates a root directory for the device in debugfs. + */ +void accel_debugfs_init(struct drm_device *dev) +{ + drm_debugfs_dev_init(dev, accel_debugfs_root); +} + +/** + * accel_debugfs_register() - Register debugfs for device * @minor: Pointer to the drm_minor instance. * @minor_id: The minor's id * - * 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. + * Creates common files for accelerators. */ -void accel_debugfs_init(struct drm_minor *minor, int minor_id) +void accel_debugfs_register(struct drm_device *dev) { - struct drm_device *dev = minor->dev; - char name[64]; + 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 b4c6ffc438da..87d0269f063a 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1831,9 +1831,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_client.c b/drivers/gpu/drm/drm_client.c index f6292ba0e6fc..a91132276f21 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -514,9 +514,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 796cda62ad12..65b6e0aae96e 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -225,8 +225,44 @@ 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); +} + +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; @@ -235,19 +271,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); - } - - 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); @@ -314,13 +342,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; } /** @@ -505,13 +532,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 */ @@ -546,7 +573,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; @@ -554,7 +581,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 cee0cc522ed9..9505c4c3f10e 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, unsigned int 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; @@ -999,6 +1011,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 d7e023bbb0d5..bf4a4f24bd4c 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; } @@ -257,4 +267,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_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 b419c59c4bef..14d5337f4297 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -590,4 +590,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 ecffe24e2b1b..1fe08fcaa149 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -78,6 +78,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 Mon Apr 24 12:30:27 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: 13222086 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 E3E7DC77B61 for ; Mon, 24 Apr 2023 12:30:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3761F10E4D4; Mon, 24 Apr 2023 12:30:43 +0000 (UTC) Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0159110E4DC for ; Mon, 24 Apr 2023 12:30:34 +0000 (UTC) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-94eff00bcdaso779087266b.1 for ; Mon, 24 Apr 2023 05:30:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339433; x=1684931433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WKE5VoOQt5+1XYsrNpE7PvF9VrsUn5BcNG9FesGbJyc=; b=T0it76fWPtAt0WrzMceuks5dAtssuuw/h3Elh5fAxeT1F5qYum51CBKqu81+Fwt8b+ aHezSK/d6VTNtluU1h+KgRqsDHULylyrpp+gkYV543N0gyEsito3yzZlTvcZcgcsgNpg T15AF8xt4ec7iIPK2B5vkA6TgJmDYvSE1ApVzOb4q5FpR3GWMGoP8/hc39j3VtQAWkcZ uQz9wQ3T9JYDXoVuQu8aA6gFJAIAdjap/FcuT8Paid8rNmYVSMRWC7d6k4oLp1LBVGgi PkYSD7AS8WUdOuHe8eVFE4C4iPrjh7mF5ugLFb3SCD9xqYlvyCsmoI3LgGZQyNGmGXFy SGyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339433; x=1684931433; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WKE5VoOQt5+1XYsrNpE7PvF9VrsUn5BcNG9FesGbJyc=; b=BpdSnjDx0q/NR8IqcwiNh2qLXvz1DWj7CIxfvTCT+9xSEI6rHqRxZt9mvti70Y7zGo +q3rPIRssV1XPWfDoMoiq5jDJK8yrKyb1enQb/amIghZ/NYeiV6z7hRgCEqsL9lIifrz CyGmLltrzzc023es34p20IdsrkOcy4uqyxGJra7uiq/KfDWdEkOEK52ZZpd8B67NFoeI c0VhUR20fqnE39EMEBoMnOWqp/hjuropZMAM1ys/4COMY5NphL8CSLFkA2e1Roa5OB4Y d0t8jIZLrtqyCgre1jxatb+p3/o/HXuekL+0vuPEva5+0jjehSwyVEhT33IhzmxoCr+P Ik5Q== X-Gm-Message-State: AAQBX9dbAQCQ4rg65TFI1N+i343x7pY4PMK9jw2nV4NWBai3LFAc1z+m Wb5U3mqWCxwNLg6Cf3NOMCgFgpQhi6vaAg== X-Google-Smtp-Source: AKy350YcBpvxKSEplokNyGOrEnTonuN2hE5Gb+G64AhaaEI8dJimrLliugfhAZWx0vcNCfTNzHjFVA== X-Received: by 2002:a17:906:16d8:b0:94f:29f0:edc0 with SMTP id t24-20020a17090616d800b0094f29f0edc0mr9696166ejd.44.1682339433017; Mon, 24 Apr 2023 05:30:33 -0700 (PDT) Received: from able.fritz.box (p4fc2092b.dip0.t-ipconnect.de. [79.194.9.43]) by smtp.gmail.com with ESMTPSA id wv14-20020a170907080e00b009598cbe55c2sm1608146ejb.28.2023.04.24.05.30.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 05:30:32 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Date: Mon, 24 Apr 2023 14:30:27 +0200 Message-Id: <20230424123028.25986-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424123028.25986-1-christian.koenig@amd.com> References: <20230424123028.25986-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 --- 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 65b6e0aae96e..d723143852e3 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -265,7 +265,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); @@ -280,30 +279,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) { @@ -373,9 +351,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 9505c4c3f10e..bc15fbf5a304 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 bf4a4f24bd4c..5a98fd1613ee 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 Mon Apr 24 12:30:28 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: 13222087 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 98F84C7618E for ; Mon, 24 Apr 2023 12:30:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B56AB10E4DC; Mon, 24 Apr 2023 12:30:43 +0000 (UTC) Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6501410E4D4 for ; Mon, 24 Apr 2023 12:30:36 +0000 (UTC) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-505035e3368so7508488a12.0 for ; Mon, 24 Apr 2023 05:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682339434; x=1684931434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QbtOV18xHi9WYr7IuGSnxxwDh6rWqrd3kKdvO4LE8I4=; b=Yoqzb5x/4aRhoKEAwsG6m32L3EwIIxKuKAROc8lZ7Kdx9Tu6+MYVQ8f5RtAsKXpewd /UC4ugFSBHrTELkqj/GpymvRZ87xUJS65VoibaD3ErL/Fe6ZpEnwLTxQSrIcsmWdlk7E Geea+uDg5OlqvLSfTeIOvg2d/XbTzAgAm0zntO3PzeqMS+SvTWWPEvB+Bgcx8bosbjXp ww9mz2f3Adk7lKef7GppPeuzztg0eLGcF5SR8dituFUQXrKHRPW9on6cqV+zPvukVQ2i UB/zyFcMUt5iYJwmFCLDqD6ZEuZiwOfbk0T+W3VXRZOO98kWEjHKuVUdXN9RzjdMqVfu d9ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682339434; x=1684931434; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QbtOV18xHi9WYr7IuGSnxxwDh6rWqrd3kKdvO4LE8I4=; b=CUx9yRYri8/9HbgC8aqCBffg/A6PYZhszq1W1CkYt2W81wolC/N4fp9mLZL/axBq3H jHTWBpWLlOHK6uo0vGfD4jhhoL45Pbw+Ob0p7+KiGEDqKRKvS77F8P1gCHpzec6CTnvt FLThV2osc8ozlGC/SuM+fAfxC7w4PCt3Lf97jxh0dAuMXhEPHWt2uVW/y9fjZ5G0/n35 Qw7xP/MFBNl2Lj3WAyEje2urujrDXnDEqlV+cMQlY26UvhHFhb4anhWSSjShH3z4cJQT Z+7E0CB3QCqQiRvI8q1BgvulgWBq5gDNv3fOw75Fyb/1SBq9ykY/A+2O8Hy22PO4Sqln QFmw== X-Gm-Message-State: AAQBX9eyCisCr88llMJo+0E2vCP8CE2/TxH1vmp5YdSfA9i2zLYkv9mg XPbR/ajR4Aq2hdHOaS8pZWYJH0CtuYCu/w== X-Google-Smtp-Source: AKy350YQxB7MAYr3WhutEkbPsyTwFrY+GKwaZMjp/P8s6h6wctK1VGq2c4TK7Kac/NhkyPF8a4MQhg== X-Received: by 2002:a17:907:1c23:b0:862:c1d5:ea1b with SMTP id nc35-20020a1709071c2300b00862c1d5ea1bmr12710400ejc.8.1682339433883; Mon, 24 Apr 2023 05:30:33 -0700 (PDT) Received: from able.fritz.box (p4fc2092b.dip0.t-ipconnect.de. [79.194.9.43]) by smtp.gmail.com with ESMTPSA id wv14-20020a170907080e00b009598cbe55c2sm1608146ejb.28.2023.04.24.05.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 05:30:33 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation Date: Mon, 24 Apr 2023 14:30:28 +0200 Message-Id: <20230424123028.25986-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424123028.25986-1-christian.koenig@amd.com> References: <20230424123028.25986-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. Signed-off-by: Christian König --- drivers/accel/drm_accel.c | 2 - drivers/gpu/drm/drm_debugfs.c | 75 +++++++++------------------------- drivers/gpu/drm/drm_drv.c | 2 - drivers/gpu/drm/drm_internal.h | 5 --- 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 | 4 -- 10 files changed, 34 insertions(+), 72 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 34fda8a9b829..2f42292abd73 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -100,8 +100,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 d723143852e3..7aea06cb6be9 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -208,7 +208,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; @@ -217,14 +217,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 @@ -267,11 +281,8 @@ 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); + debugfs_create_symlink(name, root, dev->unique); /* TODO: Only for compatibility with drivers */ minor->debugfs_root = dev->debugfs_root; @@ -282,52 +293,6 @@ 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) -{ - if (!minor->debugfs_symlink) - return; - - drm_debugfs_remove_all_files(minor); - debugfs_remove(minor->debugfs_symlink); - minor->debugfs_symlink = NULL; -} - /** * drm_debugfs_add_file - Add a given file to the DRM device debugfs file list * @dev: drm device for the ioctl diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index bc15fbf5a304..14b448861c91 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -198,7 +198,6 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) return 0; err_debugfs: - drm_debugfs_cleanup(minor); return ret; } @@ -222,7 +221,6 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ - drm_debugfs_cleanup(minor); } /* diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index 5a98fd1613ee..a8f20fd58b50 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -184,7 +184,6 @@ 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_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,10 +204,6 @@ 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_connector_add(struct drm_connector *connector) { } diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c index 6e78416e64b0..d7fdc63a6632 100644 --- a/drivers/gpu/drm/tegra/dc.c +++ b/drivers/gpu/drm/tegra/dc.c @@ -1745,8 +1745,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 6eac54ae1205..d953d0a0325a 100644 --- a/drivers/gpu/drm/tegra/hdmi.c +++ b/drivers/gpu/drm/tegra/hdmi.c @@ -1114,7 +1114,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 fbb63d755496..b45c569e6a0b 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -1707,6 +1707,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 7616f457ce70..84ee27dc2317 100644 --- a/include/drm/drm_debugfs.h +++ b/include/drm/drm_debugfs.h @@ -126,8 +126,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 1fe08fcaa149..e687ce27624e 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -78,11 +78,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; - struct mutex debugfs_lock; /* Protects debugfs_list. */ }; /**