From patchwork Mon Jul 19 18:30:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12386561 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,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 C62DDC07E9D for ; Mon, 19 Jul 2021 18:31:08 +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 8FC9461009 for ; Mon, 19 Jul 2021 18:31:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FC9461009 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 7CFF56E06D; Mon, 19 Jul 2021 18:31:01 +0000 (UTC) Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by gabe.freedesktop.org (Postfix) with ESMTPS id CA80089D56 for ; Mon, 19 Jul 2021 18:30:53 +0000 (UTC) Received: by mail-pg1-x535.google.com with SMTP id r21so1695550pgv.13 for ; Mon, 19 Jul 2021 11:30:53 -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=fxrOgIujpF8i4wx+EiH358bwMj50Ob54hlyrZAnhxWw=; b=WSj3yFC5wywCm3Dp5J7EnMAPTMUlz4YAfq0+deEfXLB8duBSGM8M6pcb7ppaponmDl BPHRsJxlwbUXXmveOZoJS6v+zlWYQkEtpGY3oDO+Nivtkqc0kk/mH60uKYaqRXn3SUf9 9rTsmlqqOSyy1le37VfiAelMLPaZRTO2iOB0d1PN2a031QueuCuCNGrbtzj7TDJgyT67 QqOrZQWgO1o0YOnvW+R2v7CX0tTLwf3FiRcstFU5TNKu/z4qGhEj+R1GUjQjJUi9b7Ra qQFcLFT3llnFQ2Pc/YXuOydgST1ulWws668hkhv9PYQsXU+9x4A1erLt/LoUEJ4EjkBt YULQ== 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=fxrOgIujpF8i4wx+EiH358bwMj50Ob54hlyrZAnhxWw=; b=auxKbk9Tu1NfgeHQzikytD5a2W+u3Xhb94ltmrWRLDgX6kuYmRxnoNuYpd0SIX3p01 6d2x6Xoc6DiadBxeljJK1830nbqnmE7ZA/BEkdgS53PAyKPCKlLrVNCuPzdLJ+58zgM2 rsmyq9NttD1hffEWkQkEzSBOfSQJ68E4/ht0R1cfmwV3qz0Ke3v7QvIgcP0LB8vB8Vkz 3ObgM2LeJ8utgqBBtqyiXOJxMYKWZNtAftUaWOhBeJIaGprr6Xzhr9DqvYAtv9Q7z9FB cZza9jFesW3P9Kuqb1yIB8BEK4ClqgAZifibDtL2eRGws1Zkb9eyNui/rRu9PhUc2xKz B1Qw== X-Gm-Message-State: AOAM533BxYO2GJpTqUI7+LeyAWZWbyBGtw7Ok4j1OLUKbI6iolW1FrV1 +XwaV0oPbPX8lfd5YnkzELdh39/9lTL0uQ== X-Google-Smtp-Source: ABdhPJx01TNQtfAKLxBA01vsesOEr0Wb+/g276nv+WAOKU6tJ5q1uIrj4DNFws4gN6UBzHpLSWJ//A== X-Received: by 2002:a63:4e4d:: with SMTP id o13mr11760575pgl.300.1626719453219; Mon, 19 Jul 2021 11:30:53 -0700 (PDT) Received: from omlet.com ([134.134.137.83]) by smtp.gmail.com with ESMTPSA id w23sm6961555pfc.60.2021.07.19.11.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 11:30:52 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Mon, 19 Jul 2021 13:30:42 -0500 Message-Id: <20210719183047.2624569-2-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719183047.2624569-1-jason@jlekstrand.net> References: <20210719183047.2624569-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/6] 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: , Cc: Daniel Vetter 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 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 Mon Jul 19 18:30:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12386557 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,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 BDE2FC07E95 for ; Mon, 19 Jul 2021 18:31:01 +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 8894761003 for ; Mon, 19 Jul 2021 18:31:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8894761003 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 6A91089DE6; Mon, 19 Jul 2021 18:30:57 +0000 (UTC) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4854F89D56 for ; Mon, 19 Jul 2021 18:30:55 +0000 (UTC) Received: by mail-pf1-x42c.google.com with SMTP id j199so17215694pfd.7 for ; Mon, 19 Jul 2021 11:30:55 -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=dnXFAvNsp4VhwTehs3gkAabKcxBUBsGHtr27v2mGrwU=; b=Yzy6Q+lPCBSRFI4vehA0kxzDLPBF7/hOVr4BjpL8Io9yxSv8qQtUoOJMGf/0fymsoh fnpn5R7U+E3x3jmy1ldUDvHp5DQbgn12tf6W+u4uuYWouCjEdwxQW25Wat8vg+AAZ/Ar x9CAyTUJt71AaUqXRV0grYiHXzjJKgJsnweeoWJ21fw4wENyJs+WSeh4CLSHEdIBLgWx FeA5RYp3Xx0GvCmPpAYf1rNEKmNkyKKhehYx6lmMkuCEPZ0De8UQ9LxviNS4Aeikjc6x Pnq8Md0pqG93wLd8G79a6li9ayo2Zb9QBmhT1qQCTrZwtsPQ9aKB3s9T0X2A3xirKm8A XE6A== 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=dnXFAvNsp4VhwTehs3gkAabKcxBUBsGHtr27v2mGrwU=; b=Y/cWINwkhJBm4kjMsYP8103pvF/DFB2lsZ4WA4S04b7mRTOiLA92AgbHHqsjjfAhey MJYpcDlceE+sVXgO0bXXE4EJiznWwcW1o2YZdjvRc63TnN05dfKeyi2GZ0bS1WYOhU1s IM0KivXO5mA25NslfgZAMMjwo6r2DrDx/+VjLy17LKp7OHNT5gHd7mJwVr5kmnxiSONK Ql78qr/ecvcspstQnIIOhtEapIMLgAzBvQ0s3ctx95kqU/lVDK1NVruXica8MnggzNJ2 sD61unpT/dbJwmGYCu5Hw3mhTGkTzfFUhTceTDRoNKAv/cBi4i2Aav/PD7wVLq36je5D D5UA== X-Gm-Message-State: AOAM533GO04eLt5E4fQBPGDql/5mBqr1hF3xaIQJz0oMPbqDJjjgDbuD WiAZkUG22fzYW4+wJYxxTXuxvYvzwQdS4w== X-Google-Smtp-Source: ABdhPJwFGcpS1KY6LYWmB3ab+eMdliHYuXyUCL+z1ob55EJrr6OGXEf8Yd5gCa5vFeNzEKQBgU9oUA== X-Received: by 2002:a63:d84b:: with SMTP id k11mr26769538pgj.372.1626719454638; Mon, 19 Jul 2021 11:30:54 -0700 (PDT) Received: from omlet.com ([134.134.137.83]) by smtp.gmail.com with ESMTPSA id w23sm6961555pfc.60.2021.07.19.11.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 11:30:54 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Mon, 19 Jul 2021 13:30:43 -0500 Message-Id: <20210719183047.2624569-3-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719183047.2624569-1-jason@jlekstrand.net> References: <20210719183047.2624569-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/6] drm/i915: Call i915_globals_exit() if pci_register_device() fails 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 the unlikely event that pci_register_device() fails, we were tearing down our PMU setup but not globals. This leaves a bunch of memory slabs lying around. Signed-off-by: Jason Ekstrand Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global") Cc: Daniel Vetter Reviewed-by: Daniel Vetter --- drivers/gpu/drm/i915/i915_globals.c | 4 ++-- drivers/gpu/drm/i915/i915_pci.c | 1 + 2 files changed, 3 insertions(+), 2 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..4e627b57d31a2 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -1230,6 +1230,7 @@ static int __init i915_init(void) err = pci_register_driver(&i915_pci_driver); if (err) { i915_pmu_exit(); + i915_globals_exit(); return err; } From patchwork Mon Jul 19 18:30:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12386559 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,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 CBF44C07E9D for ; Mon, 19 Jul 2021 18:31:02 +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 8E5C860FF4 for ; Mon, 19 Jul 2021 18:31:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E5C860FF4 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 C6AF989DC2; Mon, 19 Jul 2021 18:30:57 +0000 (UTC) Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by gabe.freedesktop.org (Postfix) with ESMTPS id 887B789D56 for ; Mon, 19 Jul 2021 18:30:56 +0000 (UTC) Received: by mail-pl1-x634.google.com with SMTP id c15so10018544pls.13 for ; Mon, 19 Jul 2021 11:30:56 -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=3PudCVQU2PCqP7pn5iCbGILZ8XUpfJcSPWpnuGkDbfg=; b=PqggbUah24VP/C6HhXeC4GM9AqL4qRRub+REo6xg9FAVZkiYb9NuYH51D9xyb6C9b7 9d/X0dObK2apq5CCGgN0Y6fIpHzk6lOfr0kBwjMyXVvFUDIh1W/2PVAW/OmGmi1u0vBp O1FCMHVxvVzlOWZT9Jw7+qmOPnHrXmU7QYso7qLjd+aVdMJFbPOrixPSaLDgIq5hebRv XoyoyMzWajJOUhtZcOEPuyk//60W1W8ePbKz16o1jGcXmgNt0d5qdfyW0o8BxG0sy07A ppO4NX46rdTv9MbizsxGfZ9CfrezpV8tEnRGtqjopOhz5qLhaqJO7VE8Jqp3aGVryid/ G/ZQ== 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=3PudCVQU2PCqP7pn5iCbGILZ8XUpfJcSPWpnuGkDbfg=; b=kWdFy4bTnJsXdWP8GehkAyDNEpKT9A1AmXsOgalqV0dLarAh0rv1HEImvgsHsXRU9S TA3eWMv2it/R9sezDmrKqoMD5RxL2Hjwx02lTWPWeEgsqhW3tPE0PVkLJjL9FtBBeUew czA/uc1cbAMDZFeJynWvGbUNhb+pRnuwE9Jz1+//PiHYhTegrUtu+wq7KgHQ1/4ueIZM hmj1kQfKUEWGz6Usbzom0sQOmbcJaIW/I9Rij/WdKtUUn8cDtfTb4/qK2gbqVdwlDfOF JqMrVGpk/3aEzXzlBMBPhx3tuapVyOF1zN/VY3CJpNy+TgpDPcJAtsKqRsfjye2DDqz9 Y3VQ== X-Gm-Message-State: AOAM530ugUa6LAzj3Fg4aRFNp8DYBsLkVfnnM27zvvALgsiPcFHuX2VN aB2zmPRgw0MwieE+lyLMRN6gMsjvoW/AQg== X-Google-Smtp-Source: ABdhPJxAPECcQuoJbVXo2jKq/NX+T4JGnp/Ul9k7ganeqejH6IsKsZGPf2/oYtgRs18k2GPcICy1jg== X-Received: by 2002:a17:90a:4302:: with SMTP id q2mr30005914pjg.189.1626719455849; Mon, 19 Jul 2021 11:30:55 -0700 (PDT) Received: from omlet.com ([134.134.137.83]) by smtp.gmail.com with ESMTPSA id w23sm6961555pfc.60.2021.07.19.11.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 11:30:55 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Mon, 19 Jul 2021 13:30:44 -0500 Message-Id: <20210719183047.2624569-4-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719183047.2624569-1-jason@jlekstrand.net> References: <20210719183047.2624569-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 3/6] drm/i915: Always call i915_globals_exit() from i915_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" If the driver was not fully loaded, we may still have globals lying around. If we don't tear those down in i915_exit(), we'll leak a bunch of memory slabs. This can happen two ways: use_kms = false and if we've run mock selftests. In either case, we have an early exit from i915_init which happens after i915_globals_init() and we need to clean up those globals. While we're here, add an explicit boolean instead of using a random field from i915_pci_device to detect partial loads. The mock selftests case gets especially sticky. The load isn't entirely a no-op. We actually do quite a bit inside those selftests including allocating a bunch of mock objects and running tests on them. Once all those tests are complete, we exit early from i915_init(). Perviously, i915_init() would return a non-zero error code on failure and a zero error code on success. In the success case, we would get to i915_exit() and check i915_pci_driver.driver.owner to detect if i915_init exited early and do nothing. In the failure case, we would fail i915_init() but there would be no opportunity to clean up 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. While the obvious thing to do here might be to call i915_globals_exit() after selftests, that's not actually safe. The dma-buf selftests call i915_gem_prime_export which creates a file. We call dma_buf_put() on the resulting dmabuf which calls fput() on the file. However, fput() isn't immediate and gets flushed right before syscall returns. This means that all the fput()s from the selftests don't happen until right before the module load syscall used to fire off the selftests returns which is after i915_init(). If we call i915_globals_exit() in i915_init() after selftests, we end up freeing slabs out from under objects which won't get released until fput() is flushed at the end of the module load. The solution here is to let i915_init() return success early and detect the early success in i915_exit() and only tear down globals and nothing else. This way the module loads successfully, regardless of the success or failure of the tests. Because we've not enumerated any PCI devices, no device nodes are created and it's entirely useless from userspace. The only thing the module does at that point is hold on to a bit of memory until we unload it and i915_exit() is called. Importantly, this means that everything from our selftests has the ability to properly flush out between i915_init() and i915_exit() because there are a couple syscall boundaries in between. Signed-off-by: Jason Ekstrand Fixes: 32eb6bcfdda9 ("drm/i915: Make request allocation caches global") Cc: Daniel Vetter Reviewed-by: Daniel Vetter --- drivers/gpu/drm/i915/i915_pci.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c index 4e627b57d31a2..24e4e54516936 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -1194,18 +1194,31 @@ static struct pci_driver i915_pci_driver = { .driver.pm = &i915_pm_ops, }; +static bool i915_fully_loaded = false; + static int __init i915_init(void) { bool use_kms = true; int err; + i915_fully_loaded = false; + err = i915_globals_init(); if (err) return err; + /* i915_mock_selftests() only returns zero if no mock subtests were + * run. If we get any non-zero error code, we return early here. + * We always return success because selftests may have allocated + * objects from slabs which will get cleaned up by i915_exit(). We + * could attempt to clean up immediately and fail module load but, + * thanks to interactions with other parts of the kernel (struct + * file, in particular), it's safer to let the module fully load + * and then clean up on unload. + */ err = i915_mock_selftests(); if (err) - return err > 0 ? 0 : err; + return 0; /* * Enable KMS by default, unless explicitly overriden by @@ -1225,6 +1238,12 @@ static int __init i915_init(void) return 0; } + /* After this point, i915_init() must either fully succeed or + * properly tear everything down and fail. We don't have separate + * flags for each set-up bit. + */ + i915_fully_loaded = true; + i915_pmu_init(); err = pci_register_driver(&i915_pci_driver); @@ -1240,12 +1259,11 @@ static int __init i915_init(void) static void __exit i915_exit(void) { - if (!i915_pci_driver.driver.owner) - return; - - i915_perf_sysctl_unregister(); - pci_unregister_driver(&i915_pci_driver); - i915_pmu_exit(); + if (i915_fully_loaded) { + i915_perf_sysctl_unregister(); + pci_unregister_driver(&i915_pci_driver); + i915_pmu_exit(); + } i915_globals_exit(); } From patchwork Mon Jul 19 18:30:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12386563 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,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 9CC52C12002 for ; Mon, 19 Jul 2021 18:31:09 +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 5F84161003 for ; Mon, 19 Jul 2021 18:31:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F84161003 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 CDC716E07B; Mon, 19 Jul 2021 18:31:01 +0000 (UTC) Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2990089E33 for ; Mon, 19 Jul 2021 18:30:58 +0000 (UTC) Received: by mail-pf1-x435.google.com with SMTP id b12so17236896pfv.6 for ; Mon, 19 Jul 2021 11:30:58 -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=qFNdhkykZcCs3HXRfapYY9OkVQ/lDSNnVRyFvwWEZ84=; b=LDjnX2FSQrlmSDxmQqhF3UZTYEjB3opXAgjmZl7d/IU6t7qJi3n/wlFASNdRJLwoL5 pu5g65wb6YUYtnUPgT5BDqRsP8hX0AIY3nfdzjzBxUAqIyNkJwawDD0OVDr2fnJteppW 0jx/Gr9dfw4UaatdLu6mAy9EspiX1GOIsi+2k+M/ucvNdn/7pejFWMBvWz+mCNv8hL/c mE07NK1eLorJQrAlo0BpmnqTeTeon4Q1FqnqlZuIGDqmtyK3WbBlvZPU+XY8Y/doGmpz 4zELtwX2zIm3DA9B1IpjACCPCpRg14fKDM02rLIRIfFpJKgXBcQ86Ppaez0ZsPddAEsm g5YQ== 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=qFNdhkykZcCs3HXRfapYY9OkVQ/lDSNnVRyFvwWEZ84=; b=MQLtqlO31x2u61bcFXVo1OWqtliUkxZ00NnE2Yd6t+gThp6jhI1P3UzzTnW0BCpzwG 1jxxRUur80jLJ/zHGEMwb4JbZGy8KR/1bs1oloKD0ERJ8tfu46baveoCXk94lArLFIby CKXkVQhky9jXGdk2yFXvbcHFCBJ4EyAutQghq2VwPz8T95pTfWOXHcQuRAxjbbZo5sZK n/t9EuNjxY3EItYFF8uyWrInvYgjKuBMcYIJr6JdDUGbQ2OZneE7mVX+yTxQoDlnTP6+ LtmSKJaXZ+YusoQ1SZlnp6KZSyqeUyKV6IydEZ5nZG3pq+9afTppyOBfsmt/QkKOrrB8 ga7A== X-Gm-Message-State: AOAM533CoQAChp4OGCv1G9rv7px3utBx65g67YnITlBGJJUPmqNOrhwU tUsYgjI7IduACjGZQOxf15j3QdKI0QBzHA== X-Google-Smtp-Source: ABdhPJyCSaK1BnjPMSbDfFGRDUr24/UBx8EAgEtP2JUda23KRKsR0D09mUnkHbwjSN6IBYFUMzGIYQ== X-Received: by 2002:a63:43c4:: with SMTP id q187mr26495416pga.172.1626719457407; Mon, 19 Jul 2021 11:30:57 -0700 (PDT) Received: from omlet.com ([134.134.137.83]) by smtp.gmail.com with ESMTPSA id w23sm6961555pfc.60.2021.07.19.11.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 11:30:56 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Mon, 19 Jul 2021 13:30:45 -0500 Message-Id: <20210719183047.2624569-5-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719183047.2624569-1-jason@jlekstrand.net> References: <20210719183047.2624569-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 4/6] drm/ttm: Force re-init if ttm_global_init() fails 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: , Cc: =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" If we have a failure, decrement the reference count so that the next call to ttm_global_init() will actually do something instead of assume everything is all set up. Signed-off-by: Jason Ekstrand Fixes: 62b53b37e4b1 ("drm/ttm: use a static ttm_bo_global instance") Cc: Christian König --- drivers/gpu/drm/ttm/ttm_device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c index 5f31acec3ad76..519deea8e39b7 100644 --- a/drivers/gpu/drm/ttm/ttm_device.c +++ b/drivers/gpu/drm/ttm/ttm_device.c @@ -100,6 +100,8 @@ static int ttm_global_init(void) debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root, &glob->bo_count); out: + if (ret) + --ttm_glob_use_count; mutex_unlock(&ttm_global_mutex); return ret; } From patchwork Mon Jul 19 18:30:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12386567 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,USER_AGENT_GIT autolearn=unavailable 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 9D776C07E95 for ; Mon, 19 Jul 2021 18:31:14 +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 63C4A60FDB for ; Mon, 19 Jul 2021 18:31:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63C4A60FDB 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 205EF6E156; Mon, 19 Jul 2021 18:31:09 +0000 (UTC) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D8C66E07B for ; Mon, 19 Jul 2021 18:30:59 +0000 (UTC) Received: by mail-pl1-x62d.google.com with SMTP id n11so10038031plc.2 for ; Mon, 19 Jul 2021 11:30:59 -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=fjh1pne4zBZdNoYmMIDQC5NmO7Tt9dtvXTfBxijHdaA=; b=Qilqv6QP1cdeOlIti9RbVVaBJ/uxXtRDdPIjyRDQgre0cy+2ROOwXQWmuCBEHucCDL GvmSzr+hO2UAW/GolXhdYS9EvGQMYya9dDdYkVYthuxMnGx8g7J8Ybnfm9nMtUh049l7 ZUXFFZWMYKvPV4sg3g+uCwCi2pSM/fduJTI7c0uLH/oVwv8Dnxa3CJZy5uHfzoRvBbQJ 0Y6XHWdeV+ougBrWuqktdRmuKecGL9RNnhLpkA0B4946nJ2eBXkLvP4IwpOoZCJYCKGT 4Y4PD252flQ/pTYYQPbdXwnZGBUQAf5GkERh4WklbHU7NqxwQXcr6l3wX/GvdZ8P6Qm7 dSMw== 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=fjh1pne4zBZdNoYmMIDQC5NmO7Tt9dtvXTfBxijHdaA=; b=nNNrbqoT0+/P9T0wxc6QRhC3HVdLxb2vpPjaWbd3NmrZu91X7pd7R3Z6YX2LGVI6+5 paNibkoGkyrWIhyDpkTjZrqS+Js7mN1FNOJd1SrZBSOobc4rpZrRgm1r0NZjPHmsLCjm uPzAbNNdno9j6UmFA9Lno0FSQdf24yYm9tp54ekVWgnW2oTzV5G69HYjoUYjUeIh65vN gA3L/Ojjwup/Qo7PHnbCFajAaHb7iQVQ8yV4XhsycBP+yXv+mEUcQBDtMJBrKokdJ94Y nBAlV3+Yp7sib+wKXo7f4pTf5kjNXvUftVYeMju0kZk5QMAJ6p2Cxq2ucP30ZAzBVaPh cEzA== X-Gm-Message-State: AOAM531e8gkoYOiEWuO/6H04kaS4aEt1GkdU71qV6GOknOpH2OdNNU3s hruFcubZweWcs7eyw93wgZcOqEySMy+clA== X-Google-Smtp-Source: ABdhPJwPlYCjNkH/FRdImJ2TGC5LdYeERjFmInkHZt8xqBITt87+foH0grdPX6FonxhKSDXzbJc+4Q== X-Received: by 2002:a17:90a:d244:: with SMTP id o4mr32444217pjw.71.1626719458817; Mon, 19 Jul 2021 11:30:58 -0700 (PDT) Received: from omlet.com ([134.134.137.83]) by smtp.gmail.com with ESMTPSA id w23sm6961555pfc.60.2021.07.19.11.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 11:30:58 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Mon, 19 Jul 2021 13:30:46 -0500 Message-Id: <20210719183047.2624569-6-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719183047.2624569-1-jason@jlekstrand.net> References: <20210719183047.2624569-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 5/6] drm/ttm: Initialize debugfs from ttm_global_init() 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 create a bunch of debugfs entries as a side-effect of ttm_global_init() and then never clean them up. This isn't usually a problem because we free the whole debugfs directory on module unload. However, if the global reference count ever goes to zero and then ttm_global_init() is called again, we'll re-create those debugfs entries and debugfs will complain in dmesg that we're creating entries that already exist. This patch fixes this problem by changing the lifetime of the whole TTM debugfs directory to match that of the TTM global state. Signed-off-by: Jason Ekstrand Reviewed-by: Daniel Vetter --- drivers/gpu/drm/ttm/ttm_device.c | 12 ++++++++++++ drivers/gpu/drm/ttm/ttm_module.c | 4 ---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c index 519deea8e39b7..74e3b460132b3 100644 --- a/drivers/gpu/drm/ttm/ttm_device.c +++ b/drivers/gpu/drm/ttm/ttm_device.c @@ -44,6 +44,8 @@ static unsigned ttm_glob_use_count; struct ttm_global ttm_glob; EXPORT_SYMBOL(ttm_glob); +struct dentry *ttm_debugfs_root; + static void ttm_global_release(void) { struct ttm_global *glob = &ttm_glob; @@ -53,6 +55,7 @@ static void ttm_global_release(void) goto out; ttm_pool_mgr_fini(); + debugfs_remove(ttm_debugfs_root); __free_page(glob->dummy_read_page); memset(glob, 0, sizeof(*glob)); @@ -73,6 +76,13 @@ static int ttm_global_init(void) si_meminfo(&si); + ttm_debugfs_root = debugfs_create_dir("ttm", NULL); + if (IS_ERR(ttm_debugfs_root)) { + ret = PTR_ERR(ttm_debugfs_root); + ttm_debugfs_root = NULL; + goto out; + } + /* Limit the number of pages in the pool to about 50% of the total * system memory. */ @@ -100,6 +110,8 @@ static int ttm_global_init(void) debugfs_create_atomic_t("buffer_objects", 0444, ttm_debugfs_root, &glob->bo_count); out: + if (ret && ttm_debugfs_root) + debugfs_remove(ttm_debugfs_root); if (ret) --ttm_glob_use_count; mutex_unlock(&ttm_global_mutex); diff --git a/drivers/gpu/drm/ttm/ttm_module.c b/drivers/gpu/drm/ttm/ttm_module.c index 997c458f68a9a..88554f2db11fe 100644 --- a/drivers/gpu/drm/ttm/ttm_module.c +++ b/drivers/gpu/drm/ttm/ttm_module.c @@ -72,17 +72,13 @@ pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp) return tmp; } -struct dentry *ttm_debugfs_root; - static int __init ttm_init(void) { - ttm_debugfs_root = debugfs_create_dir("ttm", NULL); return 0; } static void __exit ttm_exit(void) { - debugfs_remove(ttm_debugfs_root); } module_init(ttm_init); From patchwork Mon Jul 19 18:30:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12386565 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,USER_AGENT_GIT autolearn=unavailable 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 09592C07E9B for ; Mon, 19 Jul 2021 18:31: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 C5B2560FF4 for ; Mon, 19 Jul 2021 18:31:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5B2560FF4 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 C15596E14F; Mon, 19 Jul 2021 18:31:08 +0000 (UTC) Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB7D86E07B for ; Mon, 19 Jul 2021 18:31:00 +0000 (UTC) Received: by mail-pj1-x102d.google.com with SMTP id jx7-20020a17090b46c7b02901757deaf2c8so583411pjb.0 for ; Mon, 19 Jul 2021 11:31:00 -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=E/GP8kKx9GV1KDV40SZ5oe0nrG9fM0ehQJYkajDCId0=; b=jGoB/k0rmyX7DJd5WRK8QTKjLzMT3s1JaEob/np7/Ss4idygid4EWEuDzOjn0NMZ2G E1PPsCIpKnbs6Kzs7ycbbVeXE4s3UiOUhmqgyJ4s/2JqOWE2zX8jm2+QKkh1wwzkncJ2 EAWq4j8ngwzGRfeULvQiUd0eTS5OUnpVaThNoqeV847TjE2IbYU2gii8hNt9vjOCwGzV soFc41TvqDdl0ZeWEehqQevr8tLEeL0bZMWwXiiooPOEkPDLUcfFjdAVDYaI+2KgcrV9 8gN2lE2W9oIlnzdSMiCDobArKKR2ShY3wpSrJKKAdZDFMgIxU3dp4GtQgpglhFJnn6Bf yJ9Q== 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=E/GP8kKx9GV1KDV40SZ5oe0nrG9fM0ehQJYkajDCId0=; b=KrHvDX1ajy1tNX+4Qr1hWDyzVLzdlNCKTwOpKEi0xqokbUizj0DvYCpCBSYZkxi8xE Px/uFY/lU/6e/5/rZTHMlRdNXyzC+zbi0eTxPW78pthxgMpMr3elejAzJIQ/5ZWBedL5 eUzwBt1j8Ja3lmr5xbeDQf1/f0OezLZ+aocY3vyK+gFt1SGnsxE5jmQhfw0orfIkQm27 pM6QNsmG8nnbA7RZoeG5PCihpoJ54Npz9MZzSJi3kCppjzdEey6ts7v6cUCMILDPrKB2 ofET7/PlKTepqNoLYmVzT5KkrWBVgL3aM6XIeM1g1vFGXGwux2Udze9w3orWge/4SYqx /w5A== X-Gm-Message-State: AOAM533hCqC2s5n+DIAhb037N0+amxCB3gQ0N5g2pw7b/npXhZAYrjZp aaxAoKeRWxaQCpXW1wEShj99y7JI36r+Ug== X-Google-Smtp-Source: ABdhPJzT/6XqSXWhLpC5fZ2HOlqFNWc1sktZ71B6Oe2F9SkuRbx+LUZ4tEP2XBs7VsgNRD6Iecrfxw== X-Received: by 2002:a17:902:e04f:b029:eb:66b0:6d08 with SMTP id x15-20020a170902e04fb02900eb66b06d08mr20252079plx.50.1626719460238; Mon, 19 Jul 2021 11:31:00 -0700 (PDT) Received: from omlet.com ([134.134.137.83]) by smtp.gmail.com with ESMTPSA id w23sm6961555pfc.60.2021.07.19.11.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 11:30:59 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Mon, 19 Jul 2021 13:30:47 -0500 Message-Id: <20210719183047.2624569-7-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210719183047.2624569-1-jason@jlekstrand.net> References: <20210719183047.2624569-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 6/6] drm/i915: Make the kmem slab for i915_buddy_block a global 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: , Cc: Matthew Auld Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" There's no reason that I can tell why this should be per-i915_buddy_mm and doing so causes KMEM_CACHE to throw dmesg warnings because it tries to create a debugfs entry with the name i915_buddy_block multiple times. We could handle this by carefully giving each slab its own name but that brings its own pain because then we have to store that string somewhere and manage the lifetimes of the different slabs. The most likely outcome would be a global atomic which we increment to get a new name or something like that. The much easier solution is to use the i915_globals system like we do for every other slab in i915. This ensures that we have exactly one of them for each i915 driver load and it gets neatly created on module load and destroyed on module unload. Using the globals system also means that its now tied into the shrink handler so we can properly respond to low-memory situations. Signed-off-by: Jason Ekstrand Fixes: 88be9a0a06b7 ("drm/i915/ttm: add ttm_buddy_man") Cc: Matthew Auld --- drivers/gpu/drm/i915/i915_buddy.c | 44 ++++++++++++++++++++++------- drivers/gpu/drm/i915/i915_buddy.h | 3 +- drivers/gpu/drm/i915/i915_globals.c | 2 ++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c index 29dd7d0310c1f..911feedad4513 100644 --- a/drivers/gpu/drm/i915/i915_buddy.c +++ b/drivers/gpu/drm/i915/i915_buddy.c @@ -8,8 +8,14 @@ #include "i915_buddy.h" #include "i915_gem.h" +#include "i915_globals.h" #include "i915_utils.h" +static struct i915_global_buddy { + struct i915_global base; + struct kmem_cache *slab_blocks; +} global; + static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_mm *mm, struct i915_buddy_block *parent, unsigned int order, @@ -19,7 +25,7 @@ static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_mm *mm, GEM_BUG_ON(order > I915_BUDDY_MAX_ORDER); - block = kmem_cache_zalloc(mm->slab_blocks, GFP_KERNEL); + block = kmem_cache_zalloc(global.slab_blocks, GFP_KERNEL); if (!block) return NULL; @@ -34,7 +40,7 @@ static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_mm *mm, static void i915_block_free(struct i915_buddy_mm *mm, struct i915_buddy_block *block) { - kmem_cache_free(mm->slab_blocks, block); + kmem_cache_free(global.slab_blocks, block); } static void mark_allocated(struct i915_buddy_block *block) @@ -85,15 +91,11 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) GEM_BUG_ON(mm->max_order > I915_BUDDY_MAX_ORDER); - mm->slab_blocks = KMEM_CACHE(i915_buddy_block, SLAB_HWCACHE_ALIGN); - if (!mm->slab_blocks) - return -ENOMEM; - mm->free_list = kmalloc_array(mm->max_order + 1, sizeof(struct list_head), GFP_KERNEL); if (!mm->free_list) - goto out_destroy_slab; + return -ENOMEM; for (i = 0; i <= mm->max_order; ++i) INIT_LIST_HEAD(&mm->free_list[i]); @@ -145,8 +147,6 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) kfree(mm->roots); out_free_list: kfree(mm->free_list); -out_destroy_slab: - kmem_cache_destroy(mm->slab_blocks); return -ENOMEM; } @@ -161,7 +161,6 @@ void i915_buddy_fini(struct i915_buddy_mm *mm) kfree(mm->roots); kfree(mm->free_list); - kmem_cache_destroy(mm->slab_blocks); } static int split_block(struct i915_buddy_mm *mm, @@ -410,3 +409,28 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm, #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) #include "selftests/i915_buddy.c" #endif + +static void i915_global_buddy_shrink(void) +{ + kmem_cache_shrink(global.slab_blocks); +} + +static void i915_global_buddy_exit(void) +{ + kmem_cache_destroy(global.slab_blocks); +} + +static struct i915_global_buddy global = { { + .shrink = i915_global_buddy_shrink, + .exit = i915_global_buddy_exit, +} }; + +int __init i915_global_buddy_init(void) +{ + global.slab_blocks = KMEM_CACHE(i915_buddy_block, 0); + if (!global.slab_blocks) + return -ENOMEM; + + i915_global_register(&global.base); + return 0; +} diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h index 37f8c42071d12..d8f26706de52f 100644 --- a/drivers/gpu/drm/i915/i915_buddy.h +++ b/drivers/gpu/drm/i915/i915_buddy.h @@ -47,7 +47,6 @@ struct i915_buddy_block { * i915_buddy_alloc* and i915_buddy_free* should suffice. */ struct i915_buddy_mm { - struct kmem_cache *slab_blocks; /* Maintain a free list for each order. */ struct list_head *free_list; @@ -130,4 +129,6 @@ void i915_buddy_free(struct i915_buddy_mm *mm, struct i915_buddy_block *block); void i915_buddy_free_list(struct i915_buddy_mm *mm, struct list_head *objects); +int i915_global_buddy_init(void); + #endif diff --git a/drivers/gpu/drm/i915/i915_globals.c b/drivers/gpu/drm/i915/i915_globals.c index 87267e1d2ad92..e57102a4c8d16 100644 --- a/drivers/gpu/drm/i915/i915_globals.c +++ b/drivers/gpu/drm/i915/i915_globals.c @@ -8,6 +8,7 @@ #include #include "i915_active.h" +#include "i915_buddy.h" #include "gem/i915_gem_context.h" #include "gem/i915_gem_object.h" #include "i915_globals.h" @@ -87,6 +88,7 @@ static void __i915_globals_cleanup(void) static __initconst int (* const initfn[])(void) = { i915_global_active_init, + i915_global_buddy_init, i915_global_context_init, i915_global_gem_context_init, i915_global_objects_init,