From patchwork Fri Jul 16 22:47:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12382969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80CA6C636CB for ; Fri, 16 Jul 2021 22:48:07 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2B099613F1 for ; Fri, 16 Jul 2021 22:48:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B099613F1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=jlekstrand.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7FC906E8C8; Fri, 16 Jul 2021 22:48:06 +0000 (UTC) Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by gabe.freedesktop.org (Postfix) with ESMTPS id AAC7C6E8C8 for ; Fri, 16 Jul 2021 22:48:05 +0000 (UTC) Received: by mail-pj1-x1031.google.com with SMTP id x13-20020a17090a46cdb0290175cf22899cso1701399pjg.2 for ; Fri, 16 Jul 2021 15:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=26BfJp5P7eFvEwspn0bZn+OrsVxNX++BisccW8Z+Oe4=; b=MjEi3RoRlDVK7ZRGa/CCM4Z2uU9RTRIixNhcNRPaxUKU3mvJLwjqnAnaBgsuYD32hv CrBhgnPd9SUkOt4sAzOZC3zmHSlKpY6J2coyo5+zB9AA5cT+5Gu2tinASllQhq4dj8Da Gq3QpIZUC0RWEaySkfFgbEHUjTwly2ESsZS/voQUZ1wd5nm4FwMlmu6yBORhWG3Oxi4w +6H5CIKr7dQyvIOK1SvSdLn7NuOLoLtC1lpp/3CUEOGa7wS0gZif4KVwL4Wb0QNDx2Ih OcKztb4Ul+OUxJ20mVJ26v05LUXrl2bc8hP6FH+1EfNoaYLwlFW7RTfj7BVj7PNjgfXR 4hwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=26BfJp5P7eFvEwspn0bZn+OrsVxNX++BisccW8Z+Oe4=; b=ZfV3P6mvYfyWN7kNFu7lwlqqqS8q/Y+lZeLsiEP+qv/M+6X/3v1qHrrrL9hhNpgq9m Z++B83AAHP6+6IfvuMdib4ztzJglU3gpktjAdG93FOh4w01oF2re2lc4cD0zsjwhigJt s/Dzfi3mrfElC/DzyOGJCNavD9p7ux6znSR+bp6VVmlKDFUHtShgvwUwUc8kh48i5cuy wfOuGjv8BVl85WfGKxLU+fx7MP6s0HaAdfGFzP8JKclPRt6j1Gz93xeAIT4UiW5LPeSc IcjjRcEiDIx2Y969RCjDiUr9rS+AwH47QSoEDsnfcKWk6hv3Fs7DY/BV4oTvKQf9N07m 2//w== X-Gm-Message-State: AOAM530abQLpsQLqDafm0rRvy+WaiQtGgDyOaMi59MYegRdsX5cYIE0R 02NJnQ5Qd6HjeI28y7f5INQhk/igJHhDZw== X-Google-Smtp-Source: ABdhPJy1BDHpLHZlEZ+6VefSJXtTPuOJHs1y9CP2sGSyRPut6NuK1h3srvyxGQVhkZ0Cl5cciva4dg== X-Received: by 2002:a17:90a:a6e:: with SMTP id o101mr12037103pjo.208.1626475684933; Fri, 16 Jul 2021 15:48:04 -0700 (PDT) Received: from omlet.com ([134.134.139.84]) by smtp.gmail.com with ESMTPSA id u24sm11991993pfm.141.2021.07.16.15.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 15:48:04 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Fri, 16 Jul 2021 17:47:57 -0500 Message-Id: <20210716224758.2162003-1-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Call i915_globals_exit() after i915_pmu_exit() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" We should tear down in the opposite order we set up. Signed-off-by: Jason Ekstrand Fixes: 537f9c84a427 ("drm/i915/pmu: Fix CPU hotplug with multiple GPUs") Cc: Daniel Vetter Reviewed-by: Daniel Vetter Reviewed-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c index 67696d7522718..50ed93b03e582 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -1244,8 +1244,8 @@ static void __exit i915_exit(void) i915_perf_sysctl_unregister(); pci_unregister_driver(&i915_pci_driver); - i915_globals_exit(); i915_pmu_exit(); + i915_globals_exit(); } module_init(i915_init); From patchwork Fri Jul 16 22:47:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12382971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6DC6C12002 for ; Fri, 16 Jul 2021 22:48:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8BC28613E8 for ; Fri, 16 Jul 2021 22:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BC28613E8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=jlekstrand.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B57F56E953; Fri, 16 Jul 2021 22:48:07 +0000 (UTC) Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1980D6E952 for ; Fri, 16 Jul 2021 22:48:07 +0000 (UTC) Received: by mail-pj1-x102e.google.com with SMTP id p9so7266670pjl.3 for ; Fri, 16 Jul 2021 15:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jlekstrand-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wIkYJWAJaTrGItMh1rW+qwg69uMn+qusOczMLNDUoLk=; b=qRSgDjvuZKjOlJEz+OMFf8Br5oEEZNTjY0o8D8tkQPAqy/1miv6me8dfOAT60T2UQ5 HDD9CT7V5rSfojZ+/zf1O/02640kif6NgFm27ArGoHZTLrlogNbJ+SBjO0hsV2OgRUHn M0Ubc/U6/wnoG+rOiRflR2zzNkAOztvEQcqGB/jizWZuFM9AWcAJ0p9BbSAWeHze4kHQ KPnj2DYp/98V8Bu6rRDCA5u+9AI9zrNXh8cai5PN4+7boenTups2Zd4pxBv90NgK7cfh xBTy72S1JiYACuFrRYaIyTb6JY2zMiQQKNYJIRAgTlDTxgxSqafX1bm9gb0Ujxcja3p2 Jlcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wIkYJWAJaTrGItMh1rW+qwg69uMn+qusOczMLNDUoLk=; b=Nng6/eqyhuMcKiRPf9TDxX7eWKH1RR9IYWOTvlE70+sUiGKpUQ2Rk/UzdNNOv9aBjd tcUB5R0QihlhfXCvUc6ZXDhuxnCHck4tr31g+TO8SmXBEAFCLysI/NBV/vtOmNE1O/G3 uRUyjyJTex6uBv3kSmXmjzgx1zfi/POwXjpa7rwRIrg9cnNV4eQnve5BxLc9CfgSnED1 3WngO10GtTYdtHWRUxgL2GvO5WIdnW5Z3JXXGj2fz5UeuFEjmV8KxaGIlTnu/sbUdwuU A0eWvg1H81ti1nET6JnVUtHCCsUe3QpbjNyzMGMB1oAWXGbzYokuhRuv3ZgWQPGAHrV6 2lUA== X-Gm-Message-State: AOAM533Yfl6jDlEM/xpoz8sjx2o2eOQhsBqIe6RTYgrWLw6uyeH1UTM1 WmdFZlDUI46gUcGi8F2QUJ21FuxwhK+npQ== X-Google-Smtp-Source: ABdhPJx0IAjPDqH78QY7/YkshC+8w5LUkmqdWig1CEhSbkJ/posJBn85u7k5UjdUrhnJtFpR7Bn+rQ== X-Received: by 2002:a17:90a:de16:: with SMTP id m22mr5704185pjv.54.1626475686484; Fri, 16 Jul 2021 15:48:06 -0700 (PDT) Received: from omlet.com ([134.134.139.84]) by smtp.gmail.com with ESMTPSA id u24sm11991993pfm.141.2021.07.16.15.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 15:48:06 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Fri, 16 Jul 2021 17:47:58 -0500 Message-Id: <20210716224758.2162003-2-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210716224758.2162003-1-jason@jlekstrand.net> References: <20210716224758.2162003-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/2] drm/i915: Tear down properly on early i915_init exit X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" In i915_exit(), we check i915_pci_driver.driver.owner to detect if i915_init exited early and don't tear anything down. However, we didn't have proper tear-down paths for early exits in i915_init(). Most of the time, you would never notice this as driver init failures are extremely rare and generally the sign of a bigger bug. However, when the mock self-tests are run, they run as part of i915_init() and exit early once they complete. They run after i915_globals_init() and before we set up anything else. The IGT test then unloads the module, invoking i915_exit() which, thanks to our i915_pci_driver.driver.owner check, doesn't actually tear anything down. Importantly, this means i915_globals_exit() never gets called even though i915_globals_init() was and we leak the globals. The most annoying part is that you don't actually notice the failure as part of the self-tests since leaking a bit of memory, while bad, doesn't result in anything observable from userspace. Instead, the next time we load the driver (usually for next IGT test), i915_globals_init() gets invoked again, we go to allocate a bunch of new memory slabs, those implicitly create debugfs entries, and debugfs warns that we're trying to create directories and files that already exist. Since this all happens as part of the next driver load, it shows up in the dmesg-warn of whatever IGT test ran after the mock selftests. Signed-off-by: Jason Ekstrand Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global") Cc: Daniel Vetter --- drivers/gpu/drm/i915/i915_globals.c | 4 ++-- drivers/gpu/drm/i915/i915_pci.c | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_globals.c b/drivers/gpu/drm/i915/i915_globals.c index 77f1911c463b8..87267e1d2ad92 100644 --- a/drivers/gpu/drm/i915/i915_globals.c +++ b/drivers/gpu/drm/i915/i915_globals.c @@ -138,7 +138,7 @@ void i915_globals_unpark(void) atomic_inc(&active); } -static void __exit __i915_globals_flush(void) +static void __i915_globals_flush(void) { atomic_inc(&active); /* skip shrinking */ @@ -148,7 +148,7 @@ static void __exit __i915_globals_flush(void) atomic_dec(&active); } -void __exit i915_globals_exit(void) +void i915_globals_exit(void) { GEM_BUG_ON(atomic_read(&active)); diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c index 50ed93b03e582..783f547be0990 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -1199,13 +1199,20 @@ static int __init i915_init(void) bool use_kms = true; int err; + /* We use this to detect early returns from i915_init() so we don't + * tear anything down in i915_exit() + */ + i915_pci_driver.driver.owner = NULL; + err = i915_globals_init(); if (err) return err; err = i915_mock_selftests(); - if (err) - return err > 0 ? 0 : err; + if (err) { + err = err > 0 ? 0 : err; + goto globals_exit; + } /* * Enable KMS by default, unless explicitly overriden by @@ -1228,13 +1235,17 @@ static int __init i915_init(void) i915_pmu_init(); err = pci_register_driver(&i915_pci_driver); - if (err) { - i915_pmu_exit(); - return err; - } + if (err) + goto pmu_exit; i915_perf_sysctl_register(); return 0; + +pmu_exit: + i915_pmu_exit(); +globals_exit: + i915_globals_exit(); + return err; } static void __exit i915_exit(void)