From patchwork Tue Jul 11 14:04: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: 13308786 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 213D8EB64DC for ; Tue, 11 Jul 2023 14:04:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AA53410E3A3; Tue, 11 Jul 2023 14:04:24 +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 BFEC210E3A3 for ; Tue, 11 Jul 2023 14:04:23 +0000 (UTC) Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-9928abc11deso724026666b.1 for ; Tue, 11 Jul 2023 07:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689084262; x=1691676262; 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=igxnjybBl9nRhvD39E9bq9tTp/UCx9mEEqgWgst1jfY=; b=Yuuk+19uhNTOL7XK+v1UqOkEzOlwusBc0HIKFzZ0Km+HrrL7jE3MV1/GwHNCvSnOet 8yFtSKYI9LRfy2q0x5B28JRrepflY7Zvq0GWIOz/FDCQbM0TuAtwOXOsPX4NmiN/m+Zs IabrXgtR1UqPWGpb7KNJUUWWBW9QQdE/sMAzmHqYAGlWlVp0VdeAep1jkp4AC+CKDF7G 4+Pkxi/xWBsosrt25nQYcJPPpJzbrY6SsHbTCha9kGetpGxPfU5e5T6yyQ8XBIJSW1Rq tswbH6dwzdhzOU+uEUzwuL6xsf4Yucm0PeF9afFrIPc4H/C48mqT0o+EBSLYzHK6HmFU trDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689084262; x=1691676262; 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=igxnjybBl9nRhvD39E9bq9tTp/UCx9mEEqgWgst1jfY=; b=aJTyHy7J8eTnbPKrGU5k5nP6qPogPbMLvXLho3zWbNo0Z5L7LNWw/lOZPC23QgvMw1 95qvsrDpWt/3uwgrnTfTU/gw0lxIG8g//nKZWJrtwkqpe6sXm5zdoK2o3po/mDIQrkgY jX+SUlpXRh5bnn3U4T5jyHTG9+IFY2+ykzKdTLhbE4U0y+yjDH2HW5e269sFYbzRJ1aw mZhpKNiSgRnmJgnTz4YG/GJvEcw3mTB8jkKrIhqZauJ4vB3aQJypW2V+tS61Zvv0bRQm GRly98+B/gV/ST/agz+qvT5ghg5CUDYiN627dd4pcoZOy2ywxIoa1TQXWTC/4hPU0bNZ 7GMw== X-Gm-Message-State: ABy/qLaLq69cVhIq6gbAWwGRJKoPmjWUeWfaqHO+5QAafQET8tuCF7Tx O8inY51XIbcNA103r8VoV9Xwsweukw8= X-Google-Smtp-Source: APBJJlGuLDME0AvXeNgZg4NtLwvHnoQzxTyFol6ViP1JWSh84R8T7MW8ccoCgLV78CP6ndzmvfotUg== X-Received: by 2002:a17:906:aac6:b0:992:345e:8319 with SMTP id kt6-20020a170906aac600b00992345e8319mr13091593ejb.58.1689084261850; Tue, 11 Jul 2023 07:04:21 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154b:c600:dcae:ab99:6259:7e2b]) by smtp.gmail.com with ESMTPSA id e18-20020a170906505200b00989257be620sm1199006ejk.200.2023.07.11.07.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:04:21 -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, dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/debugfs: drop debugfs_init() for the render and accel node v2 Date: Tue, 11 Jul 2023 16:04:14 +0200 Message-Id: <20230711140418.3059-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711140418.3059-1-christian.koenig@amd.com> References: <20230711140418.3059-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 --- 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 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 Tue Jul 11 14:04: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: 13308789 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 B9B62EB64DC for ; Tue, 11 Jul 2023 14:04:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AB1C10E3AD; Tue, 11 Jul 2023 14:04:31 +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 26E5C10E3A3 for ; Tue, 11 Jul 2023 14:04:24 +0000 (UTC) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-992af8b3b1bso745799466b.1 for ; Tue, 11 Jul 2023 07:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689084262; x=1691676262; 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=N9Uuouz6BCzdOfJmpXCASsGruHU4kdCFVbUUrlmsthg=; b=sUCJwZIPqfPEIgbrssAxaDRYd1iBASCwR+WRVu7xg6W3HKbWV4YzdBLyYvFldOTO26 APVLJIzBYUArZQ8lP6pHtgpRl4AxOGUK+PibMF7WKRBOE9QV8WdVfP6zCf0rNDMdQ8bh dXTq2OzhvteZqOGSWgjPvPACZgIWtBZOjfHjuoTm+tpDykEB0C7cAyu4MEbeCg19Wwnr yOuyVhvqUekjWYwFt70e4KxaowtS6I57VZyqZ4Cw1f6aAKlz8I/m6r7CiIVYrBDRGUYS leVBQ3uJbrGf5aI01pudtOGfim3ocIQ67ooZ/5sYCmq6eP3oB44va7Zf4aRjb8H+ycLE FbFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689084262; x=1691676262; 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=N9Uuouz6BCzdOfJmpXCASsGruHU4kdCFVbUUrlmsthg=; b=CR/B5berMp2IBVHrzdohENN/hV5UWw0CfiHrDgA/GGO8z3wh4y7sS+9BpX4LZXJ5pC 7Omytuyvg7dEII6I8dZU4zAhxj7DfHJAFW4EOBUdF2/ekAFhIeDIfGOdlfte2Do0kr4a SIhdwINCIub8fMb7co5gBvc4QmCw2fDfv/05VWQ0j9B47ata5R+HR/pfm1jENIh2i+3+ fRAwN21FZYYkcCfu/WE+SFHRcOA1puaj8f6hyzoaM0ok6FIAriwzzjnOWxVOdABKUXB0 sknpvnzWXFVc92PPw6sxypQdx5zcFR6MrJlniqvF9BDG5jZnI/yjX9D+BkJ8f68U43Ch Anow== X-Gm-Message-State: ABy/qLaRHj5kGsH6cpdcfvPQzKGVB0VnvZ6kEneXAwjmxf+mR/1mO/qs mah+MBnLS/xlqT71uAgKeRo= X-Google-Smtp-Source: APBJJlFDS1LhDgJBJGZjxZU0rh9MSXIOgHe1xDolv2i04YW9kU7GjIyqpmZEmM8uB2zusnPieGzEvQ== X-Received: by 2002:a17:906:2205:b0:992:a618:c3c4 with SMTP id s5-20020a170906220500b00992a618c3c4mr17488829ejs.66.1689084262532; Tue, 11 Jul 2023 07:04:22 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154b:c600:dcae:ab99:6259:7e2b]) by smtp.gmail.com with ESMTPSA id e18-20020a170906505200b00989257be620sm1199006ejk.200.2023.07.11.07.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:04:22 -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, dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/debugfs: disallow debugfs access when device isn't registered Date: Tue, 11 Jul 2023 16:04:15 +0200 Message-Id: <20230711140418.3059-3-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711140418.3059-1-christian.koenig@amd.com> References: <20230711140418.3059-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 Tue Jul 11 14:04:16 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: 13308790 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 80F27EB64DD for ; Tue, 11 Jul 2023 14:04:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 367AF10E3AE; Tue, 11 Jul 2023 14:04:31 +0000 (UTC) Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by gabe.freedesktop.org (Postfix) with ESMTPS id AAE3010E3AA for ; Tue, 11 Jul 2023 14:04:25 +0000 (UTC) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9891c73e0fbso1150381166b.1 for ; Tue, 11 Jul 2023 07:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689084264; x=1691676264; 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=3QrH+XPfXLdUbr1x1vNzJRq7EpfMEJv1MQnTPRH+W/M=; b=br/PATw5KQ/M7aAqsX5U7nzHZLFhBjYIhlWe/iQPnyd2qSoITkvJvbZnyeUtW7M7An 2Ow6AG6tVQc9NTgWIgwEalOc8AP1xyyRbIRr9+kfIipZXl7Oj27m4Cd9B7t3cDwKInce snVixi+OZFVa/GBmRRxJXm81SnkDyzr8RicoTmd3Xz6zZwefawgEdIfzr1tG+QYDD6ZR Sc3hC2hlLVJD0lKrrGKQGYBs6YuRilLWNse/pcGmzOXL9BwNuZLFHDXJoBFtNwxaFnV1 PObS5kXPS5/Tiap80VNm+6ms/Jh5CWCQULF0oJ3tfiRDhLbRc43NBPYY9rBwKC/5tnVb Zicg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689084264; x=1691676264; 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=3QrH+XPfXLdUbr1x1vNzJRq7EpfMEJv1MQnTPRH+W/M=; b=Uib1AQ7LQaHLZUjyfwIjhmVuXZbT4TS7Uxmy9nWJocyrd8YhKHJP/ofby/k30ri6Ej AhDTs0/R26EeraeHhBrPkE2P829xvs+zMH8YyBY4i+s6UYKyxMC9EfxtYuDhalLT9TTj fAVS64e1w9OR5AS4djcKTa+49QFt0b51JHQHlP0Y5halt+HmznaxvpRQpJMo4Wrxc7bs lHcDRoKCdb3qdtlycbpFqMm3jAMnr4/VqFCemVEIup3eR+SylrGICPY2L4hSYqbW1yfW O5kEVZaQSzX7ai3OaSL4STmBtLbNj8IpeOSIAN8Ti7lrulFoAuYRc0NnhmB9KeAWEsg6 o2TA== X-Gm-Message-State: ABy/qLajzBPdyHZltIvBj4Nv/6EfwPBBxFyZWk+4lHhnkpHGebYi007q 5aJUil+3gBG2FroA3XA6jBr9SymZ5tA= X-Google-Smtp-Source: APBJJlG2igrND8uspwdrUFycKx2lSt10x5AiikCHKSyvZWXR+8mMTzXi35kgpFn9v/p1DKi1gg1t4g== X-Received: by 2002:a17:906:5307:b0:993:fb68:ed6c with SMTP id h7-20020a170906530700b00993fb68ed6cmr10950847ejo.15.1689084263295; Tue, 11 Jul 2023 07:04:23 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154b:c600:dcae:ab99:6259:7e2b]) by smtp.gmail.com with ESMTPSA id e18-20020a170906505200b00989257be620sm1199006ejk.200.2023.07.11.07.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:04:22 -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, dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/debugfs: rework debugfs directory creation v4 Date: Tue, 11 Jul 2023 16:04:16 +0200 Message-Id: <20230711140418.3059-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711140418.3059-1-christian.koenig@amd.com> References: <20230711140418.3059-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 01edf2c00b5a..82c5fcbbc164 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 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_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 12687dd9e1ac..25cbe02550e6 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; @@ -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 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 b77f2c7275b7..22fdc2bb52b9 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -575,4 +575,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 966912053cb0..016fb715b9b6 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 Jul 11 14:04:17 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: 13308787 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 8024CEB64DC for ; Tue, 11 Jul 2023 14:04:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98CB410E3A7; Tue, 11 Jul 2023 14:04:28 +0000 (UTC) Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 10B7910E3A7 for ; Tue, 11 Jul 2023 14:04:26 +0000 (UTC) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2b6ff1a637bso91328331fa.3 for ; Tue, 11 Jul 2023 07:04:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689084264; x=1691676264; 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=5E6mGr7l1sCsaZiG34OLuqWu6zuEDz7WVl0t1ckurV8=; b=Ri6S/ucGtUd6VJKDiPBE49zckhFOOezfvY2celwDJ9XcRcmG3WSt7e3fdrDVNtIyFk ztoXwi35M1NhlxsliTIkiGYJ0HQIltEefOo2+JphZOhjyeRPx2uiwWFkDlglgSICEJ51 NbJe0aCHUtyGLh+Vbbq2PmSnbQr4Pi28UEEiEZITLce+JPPXDgo3y+aAwyGHbKbnJRTb o8QOpkd9YsmekNYU6++YjX2srHGRNmXrzkbLj5BcDBzktZ+oBsBonMlz1h4m9Iajyz/U GEdHjz7iDxW9+G+pLRnm9nq6Y8WlnL29Y/u/zGGgFUcmHx7F+2h/KU8m/sY5FimcXINQ r/hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689084264; x=1691676264; 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=5E6mGr7l1sCsaZiG34OLuqWu6zuEDz7WVl0t1ckurV8=; b=PxRL4AIuT274yLRZ0tbwNjbv3GsgqgD2a6ylGU9ZnaneSnYJbIuO3aAsSqmkIApB1s vk7s0X2e3HlhYQX3B6uh0ukGyMXWqYGDD475MKBVofw5gsBNAeffAOP6mCGtgjIarXoL 0OsdUMDOfYMJH/EstV5w5VNUpki/E6aUpgw4zIN0IH+z/YrYbQJev0ytImfzmwIvZTf0 ktxfPhaPg1oy6oFZVK4yWjib8s0nrXk9NxnE5j0q7VAORcOnG8JQ8wfYz3Z0/FYSFgQO +HtjdEVSPeR07qzOciljK+0FE7wlUSKsuJe60+lj/jhQrFpHUgs9UxOQdS+Tg+zlWJTL wsmQ== X-Gm-Message-State: ABy/qLaoSLEnfB8C5o0AxWiv/RCg5K0O8N+Mi5OUb9wHO3pNZ1UnmQKg cpIN595nE1uEASSrNnSsVwQ= X-Google-Smtp-Source: APBJJlH6DoE3IfyADgkj4rIChHcovHMKP+UX2DV5xGjVZ4zLDv9zzk2rTZEjI8nOUd83t0187ZbOKw== X-Received: by 2002:a2e:8611:0:b0:2b6:daa3:f0af with SMTP id a17-20020a2e8611000000b002b6daa3f0afmr14101608lji.25.1689084264115; Tue, 11 Jul 2023 07:04:24 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154b:c600:dcae:ab99:6259:7e2b]) by smtp.gmail.com with ESMTPSA id e18-20020a170906505200b00989257be620sm1199006ejk.200.2023.07.11.07.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:04:23 -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, dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/debugfs: remove dev->debugfs_list and debugfs_mutex v2 Date: Tue, 11 Jul 2023 16:04:17 +0200 Message-Id: <20230711140418.3059-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711140418.3059-1-christian.koenig@amd.com> References: <20230711140418.3059-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 25cbe02550e6..521d3d75a585 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 Tue Jul 11 14:04:18 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: 13308788 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 EC8D4EB64DD for ; Tue, 11 Jul 2023 14:04:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC1EB10E3A8; Tue, 11 Jul 2023 14:04:29 +0000 (UTC) Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by gabe.freedesktop.org (Postfix) with ESMTPS id 780DB10E3A7 for ; Tue, 11 Jul 2023 14:04:26 +0000 (UTC) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-991fe70f21bso725348366b.3 for ; Tue, 11 Jul 2023 07:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689084265; x=1691676265; 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=scOcy9OReMpJccTOKJ2glwxe6PYB1nNXFBKEXXhaSzo=; b=YJtuKeMpoOJPv7PszSP1i5/eFuQ0rEvTonlJf49mS3qkfvc/LioL6r/qAPqqcbmemz nuQQ9+YNtnjXFeAZa3MGFcAm37MnffSgtcEdieVa4rS0yy3GNYGHnnf8dwk6capJGDhP j0q/stHwn4WkLD6jtVjg2j8gMzHRc5H7Pmie6utenDS07T1P7NuYEwYKG3dwc8v7i4/6 FlWwai1axETkccqxBywbUAe2jjRf6fS14ynNqaSrnVS8IE3uJXbdvqsBjmJfGVlTe7kx q183upBGmbDk5VTFunrlLKD8GYsVg+4dmjT3Ql+dMtSnZ4RBuGe8Cq5r4k6y22d5+d/M iv3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689084265; x=1691676265; 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=scOcy9OReMpJccTOKJ2glwxe6PYB1nNXFBKEXXhaSzo=; b=a0q9IMjpNu14B8/AzOpqWEQ61p7rpGqTyLjFS4WgA1cVKPZcRbutdHN0huDDTmnZJj BhIeVOOa+QGUi7LCax9+uBwrJhrtsr4YbV0AH6k3f5zcyYOtPpYhkK2xBbkIV3ORaBjl jzZWyyW1H9AItUSEHKug5/SF0nwSoPnCzu5SSpQFdiacsCp27VT4x8+2edBZotLs6tJK k712yIJQbt++a/LEEfNGs17tIAmc+ZIKsCfcyLDCdD/JnHWaGoTm/9DuhUq5CAgjTLSc 62CDO+ktMF8OzAukI36QbapNuFjNisozKyarF/5PG2r3r7lyFNp40UAdotcpc+fp6DzJ GgvA== X-Gm-Message-State: ABy/qLYwA23aMVSm06y9kkIxUUXkFeRIgZfIzkhYyx7Yh7BAz6fuidcM tiPuF8Bf+RRTKcct5gFPqeI= X-Google-Smtp-Source: APBJJlHq+F8MgYRHAeIx0gwMGjyCYuMzfw9sFHN/pdM2i0YceBr/im7HAsZTSAbZ1PpxQaeVTvEE2w== X-Received: by 2002:a17:906:74cb:b0:993:d955:1280 with SMTP id z11-20020a17090674cb00b00993d9551280mr14585366ejl.12.1689084264771; Tue, 11 Jul 2023 07:04:24 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154b:c600:dcae:ab99:6259:7e2b]) by smtp.gmail.com with ESMTPSA id e18-20020a170906505200b00989257be620sm1199006ejk.200.2023.07.11.07.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:04:24 -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, dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/debugfs: rework drm_debugfs_create_files implementation Date: Tue, 11 Jul 2023 16:04:18 +0200 Message-Id: <20230711140418.3059-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711140418.3059-1-christian.koenig@amd.com> References: <20230711140418.3059-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 82c5fcbbc164..02ccf6520d27 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 521d3d75a585..3d5eaea12922 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 016fb715b9b6..ccdc793a8264 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -79,11 +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; - struct mutex debugfs_lock; /* Protects debugfs_list. */ }; /**