From patchwork Wed Jul 21 15:23:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12391283 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 70663C636C9 for ; Wed, 21 Jul 2021 15:25: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 4095A61244 for ; Wed, 21 Jul 2021 15:25:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4095A61244 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 D097E6E90C; Wed, 21 Jul 2021 15:25:00 +0000 (UTC) Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2F13A6E8DD for ; Wed, 21 Jul 2021 15:24:59 +0000 (UTC) Received: by mail-pj1-x1034.google.com with SMTP id gv20-20020a17090b11d4b0290173b9578f1cso1137656pjb.0 for ; Wed, 21 Jul 2021 08:24: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=fxrOgIujpF8i4wx+EiH358bwMj50Ob54hlyrZAnhxWw=; b=ZTZWdei5NlKvXYiDTGiCpLCoDa907cXvxISKOfdXrVbIOLyXT5BbvfAfOT+As3pBi7 glmd6OccYAtlMwn5OuWEKe470d57rGQM3jPO/y0MWtI+F2Wyj/d62AYOGpjIviU7oALa Fg9yBoypwsDQQncxlmKVVX5Y29YMoixsjXJmgpiM+MN6YKZ+5oMT1OHPxmCrwKzFytWM GmMvo9MMx7pDO/M+plS5kwOr586ZPCMEBD7vml+vjFABJUwKHcFhRlK4h5k6mfRTcOvc y9vvIid+OeWCsP7PW0H/bEQQnAdvBImb2zbZWSBJBEhoNlHNbmpEg+3AeTKLfEwFecbQ fFAw== 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=qkPB/rd4KctvjW86iULxQxUUSPDR/NwnFcq78T1McnJ1o040n5yZJu3J+iv3hWC97p vhcqQQsamJ/Ihh2LYGd+sILfqcJS6mAIbPhDgmE6X/86ruP5IaVUjBrKat3u0tLbFeC2 QV7HXuueEo6ro9SmCBoMV9M6EW0YcZv6Gjb74k8dmLdweCp04HGQPwrgs9EPRsn/VQgX ybjyRlP+P87UTrC18S+dUZH6wkbG8JSRXG1x651nkM2O0ARAp0IJoVhCCXbc35tifFiT K9u2bts5PLW7IS77nuPT/0wHs7Af1KExm2TE/EPiLwMEnX+uYwVJ2rb4rTcK5a1db2js 8ysQ== X-Gm-Message-State: AOAM532kwu9D284mNfjFLE/mjjfTZ8RLmtfIjfg2qpXP6kQTErkjxh+D 86KxW2B8dvAnqTSclvLC9zeIb9uCD4FBhA== X-Google-Smtp-Source: ABdhPJwF1Ny4BhYMjEnpJFkvHCEYUQeXvffSorR8q6UDpztUnjFv86YpoyDgDaoepYYC3r+zCI/SJw== X-Received: by 2002:a17:90a:e7c7:: with SMTP id kb7mr35317769pjb.43.1626881098331; Wed, 21 Jul 2021 08:24:58 -0700 (PDT) Received: from omlet.com ([134.134.137.82]) by smtp.gmail.com with ESMTPSA id e4sm32451034pgi.94.2021.07.21.08.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:24:57 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Wed, 21 Jul 2021 10:23:53 -0500 Message-Id: <20210721152358.2893314-2-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721152358.2893314-1-jason@jlekstrand.net> References: <20210721152358.2893314-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 Wed Jul 21 15:23:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12391285 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 AB700C12002 for ; Wed, 21 Jul 2021 15:25:06 +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 7F09561244 for ; Wed, 21 Jul 2021 15:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F09561244 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 EFD326E9A2; Wed, 21 Jul 2021 15:25:04 +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 CA5F56E8DD for ; Wed, 21 Jul 2021 15:25:00 +0000 (UTC) Received: by mail-pj1-x1031.google.com with SMTP id nt18-20020a17090b2492b02901765d605e14so273765pjb.5 for ; Wed, 21 Jul 2021 08:25: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=lE5imCQIk9KskralIlWDyDnEk557cQKh31aZ6Ny2Za4=; b=JHxBtie525D0RuMAvgo8nvwKq0u7paJjaMP0TEZQkqpptuGp2xibf5j58D+qe7pUz1 053QZlGi0CYalBUuFpyAlxKVYn4wVnIUk2Sr6yrJFLcxKig1bxrB3GzN3sQkHqIW+l7f w/kLYfuy4/LER+7tCjwBLJm3W3Ar8N4gauYNUOc4gvhg6O9pFDqYRXzEUjUiQtb4NeT0 CoMZKh1Aqe8MP9yKwL+dLKGtvyocZ1zmR9gxqfhI9IUO52A/QJFKTMPI12SfBIZsiBsU rz/jLR0lID3ZfsLdoqHkBPoOV65t8QAsEuj7zp1N5d4L4UzlhXXpFw6hBfHWkzyEgpkO uEdg== 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=lE5imCQIk9KskralIlWDyDnEk557cQKh31aZ6Ny2Za4=; b=sQw7hUJ6HHcwaRayUPNDmjyVPgU6fg+JiYzBFfBWeHuGAPRf2DlUdgzVjse+lcAUqU JNzkBw12XNEDJ4nrLcfWM0IBUnjGBUvAHEHvMljdzXGVxbXvzX76kOEsmAtaLiVNZxex IT4zpcpA3StOdBEixDS4+vxzIe/fVVa33SSzG/MBZDnYbED7oxygZQkl1HhQdjDmRLBm +VVxkov1hdnLqSrzu/BW7724+Dcbq+k7Tso7hcQpcdp9/12sifLq6Aw2LTpZVfEgk2BI AqOE/yc1imVphLKUbhgX28GdurOsZZBfSzF4yyqzxcO5DOyQ2k2tR9P/A6n+eAJipV1N umYw== X-Gm-Message-State: AOAM533kPIl+x+B+AZGI1qM9djkE3d+x//q2c+2qW3ag9k9gAO7QKd9b otSE2ulZCyaDAsWzLOD5N+K3w0Zc+UDQyQ== X-Google-Smtp-Source: ABdhPJzxP7BZqzzLuir1p6diui1mV6+sXsr46qpr67KRknsA/A7d56Hmk9GIoqIAwVQgXxMOI8P+dQ== X-Received: by 2002:a17:90a:3c8c:: with SMTP id g12mr6072252pjc.134.1626881100104; Wed, 21 Jul 2021 08:25:00 -0700 (PDT) Received: from omlet.com ([134.134.137.82]) by smtp.gmail.com with ESMTPSA id e4sm32451034pgi.94.2021.07.21.08.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:24:59 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Wed, 21 Jul 2021 10:23:54 -0500 Message-Id: <20210721152358.2893314-3-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721152358.2893314-1-jason@jlekstrand.net> References: <20210721152358.2893314-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: , Cc: Daniel Vetter 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") 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 Wed Jul 21 15:23:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12391287 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 9D400C636C9 for ; Wed, 21 Jul 2021 15:25: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 6FCF261244 for ; Wed, 21 Jul 2021 15:25:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FCF261244 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 F07596E9B2; Wed, 21 Jul 2021 15:25:05 +0000 (UTC) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by gabe.freedesktop.org (Postfix) with ESMTPS id 872756E9A1 for ; Wed, 21 Jul 2021 15:25:03 +0000 (UTC) Received: by mail-pl1-x631.google.com with SMTP id y3so1126581plp.4 for ; Wed, 21 Jul 2021 08:25:03 -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=gcrDl1ifXL7AdQuGEj7BhkWSyCWUi3i70UQr7yQo6u0=; b=fO+x1DlRxG+CTszsMDHaYNey+LByQjb2ZwyEInb1eC+21rU5LHMOfiXXHKjPG8cF2g HVhruFbLTKf8koyOu36JCqjxKTEOF8DVthXLaA4ZK2By2aSD35IBuoDFIpJAuFbc110R GxM9/olqK8AE2E5Y7IIYxg0vgVfcfYwbNyJQIMDFcM59X5apkwEoF2POgWSGSVZm11lB 38w1VvTmpUprmMrY73sWZv5f4cmVBFO+fS6ACH/ra5VmvyfSNxLfEe7ppyCCIzGPB55i tNC7qdDHU8+fYQFN8xg5U3Ku1p95Emedr1yzI1Sa+U+idQ17tZC+y+kCI5FtMeuB1wqx dG9Q== 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=gcrDl1ifXL7AdQuGEj7BhkWSyCWUi3i70UQr7yQo6u0=; b=jHf8SnHQR4Wr9itXU40n5at/l99PJ0Dof0QhsgUYvjtDClT+13a6bs4IASPTAFWwvS RNiGjN1FZ7rgFOrrlmBWCDEoaLHDALC4zjWZNb9kVfDaFAa6xMdzNlFLJtUmUwTmgh6v Ix8/q12Y6b5IMKYjy8AM7rUMhMMniGWTq+iS3C/lzMlShTAMYzfBHKZkz7pjAFFMp3nW EoHJiKEDd3Ppwca9R0XdUYvVpxNGnYKdH1ntGAdH7qJRgKJPyvfTwl4rLiQ9Cw6HTyGW xEc+c14ztBU6yrrRWhiUu6dwEkaLJLv0afPoZJ/vipZjM1dZrRy2ImSaNrS1DzVtjHwL 1S3Q== X-Gm-Message-State: AOAM533Oh1ib8l5m+qtXU4VtQFAJPfG+32oIfLxLM1cOB7uLhk4Wa6BJ tymlEhmK2xlubzQcoN1wHHL6Ib0CWHnaWA== X-Google-Smtp-Source: ABdhPJzth6v1+Wkd7FoAtepzuLrb4GYkvnsXH8qyZBoR4Ba8jt0dp5eFieKbjKzJ4izYbTYdx6BmSw== X-Received: by 2002:a17:90a:a087:: with SMTP id r7mr4424171pjp.84.1626881102527; Wed, 21 Jul 2021 08:25:02 -0700 (PDT) Received: from omlet.com ([134.134.137.82]) by smtp.gmail.com with ESMTPSA id e4sm32451034pgi.94.2021.07.21.08.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:25:01 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Wed, 21 Jul 2021 10:23:55 -0500 Message-Id: <20210721152358.2893314-4-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721152358.2893314-1-jason@jlekstrand.net> References: <20210721152358.2893314-1-jason@jlekstrand.net> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 3/6] drm/i915: Use a table for i915_init/exit (v2) 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" 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. The mock selftests case is 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 syscall. 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 is at least one syscall boundary in between. In order to handle all the delicate init/exit cases, we convert the whole thing to a table of init/exit pairs and track the init status in the new init_progress global. This allows us to ensure that i915_exit() always tears down exactly the things that i915_init() successfully initialized. We also allow early-exit of i915_init() without failure by an init function returning > 0. This is useful for nomodeset, and selftests. For the mock selftests, we convert them to always return 1 so we get the desired behavior of the driver always succeeding to load the driver and then properly tearing down the partially loaded driver. v2 (Tvrtko Ursulin): - Guard init_funcs[i].exit with GEM_BUG_ON(i >= ARRAY_SIZE(init_funcs)) v2 (Daniel Vetter): - Update the docstring for i915.mock_selftests Signed-off-by: Jason Ekstrand Reviewed-by: Daniel Vetter Cc: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_pci.c | 105 ++++++++++++------ drivers/gpu/drm/i915/i915_perf.c | 3 +- drivers/gpu/drm/i915/i915_perf.h | 2 +- drivers/gpu/drm/i915/i915_pmu.c | 4 +- drivers/gpu/drm/i915/i915_pmu.h | 4 +- .../gpu/drm/i915/selftests/i915_selftest.c | 4 +- 6 files changed, 82 insertions(+), 40 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c index 4e627b57d31a2..5f05cb1b5ac6b 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -1185,27 +1185,9 @@ static void i915_pci_shutdown(struct pci_dev *pdev) i915_driver_shutdown(i915); } -static struct pci_driver i915_pci_driver = { - .name = DRIVER_NAME, - .id_table = pciidlist, - .probe = i915_pci_probe, - .remove = i915_pci_remove, - .shutdown = i915_pci_shutdown, - .driver.pm = &i915_pm_ops, -}; - -static int __init i915_init(void) +static int i915_check_nomodeset(void) { bool use_kms = true; - int err; - - err = i915_globals_init(); - if (err) - return err; - - err = i915_mock_selftests(); - if (err) - return err > 0 ? 0 : err; /* * Enable KMS by default, unless explicitly overriden by @@ -1222,31 +1204,88 @@ static int __init i915_init(void) if (!use_kms) { /* Silently fail loading to not upset userspace. */ DRM_DEBUG_DRIVER("KMS disabled.\n"); - return 0; + return 1; } - i915_pmu_init(); + return 0; +} - err = pci_register_driver(&i915_pci_driver); - if (err) { - i915_pmu_exit(); - i915_globals_exit(); - return err; +static struct pci_driver i915_pci_driver = { + .name = DRIVER_NAME, + .id_table = pciidlist, + .probe = i915_pci_probe, + .remove = i915_pci_remove, + .shutdown = i915_pci_shutdown, + .driver.pm = &i915_pm_ops, +}; + +static int i915_register_pci_driver(void) +{ + return pci_register_driver(&i915_pci_driver); +} + +static void i915_unregister_pci_driver(void) +{ + pci_unregister_driver(&i915_pci_driver); +} + +static const struct { + int (*init)(void); + void (*exit)(void); +} init_funcs[] = { + { i915_globals_init, i915_globals_exit }, + { i915_mock_selftests, NULL }, + { i915_check_nomodeset, NULL }, + { i915_pmu_init, i915_pmu_exit }, + { i915_register_pci_driver, i915_unregister_pci_driver }, + { i915_perf_sysctl_register, i915_perf_sysctl_unregister }, +}; +static int init_progress; + +static int __init i915_init(void) +{ + int err, i; + + for (i = 0; i < ARRAY_SIZE(init_funcs); i++) { + err = init_funcs[i].init(); + if (err < 0) { + while (i--) { + if (init_funcs[i].exit) + init_funcs[i].exit(); + } + return err; + } else if (err > 0) { + /* + * Early-exit success is reserved for things which + * don't have an exit() function because we have no + * idea how far they got or how to partially tear + * them down. + */ + WARN_ON(init_funcs[i].exit); + + /* + * We don't want to advertise devices with an only + * partially initialized driver. + */ + WARN_ON(i915_pci_driver.driver.owner); + break; + } } - i915_perf_sysctl_register(); + init_progress = i; + return 0; } static void __exit i915_exit(void) { - if (!i915_pci_driver.driver.owner) - return; + int i; - i915_perf_sysctl_unregister(); - pci_unregister_driver(&i915_pci_driver); - i915_pmu_exit(); - i915_globals_exit(); + for (i = init_progress - 1; i >= 0; i--) { + GEM_BUG_ON(i >= ARRAY_SIZE(init_funcs)); + if (init_funcs[i].exit) + init_funcs[i].exit(); + } } module_init(i915_init); diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c index b4ec114a4698b..48ddb363b3bda 100644 --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -4483,9 +4483,10 @@ static int destroy_config(int id, void *p, void *data) return 0; } -void i915_perf_sysctl_register(void) +int i915_perf_sysctl_register(void) { sysctl_header = register_sysctl_table(dev_root); + return 0; } void i915_perf_sysctl_unregister(void) diff --git a/drivers/gpu/drm/i915/i915_perf.h b/drivers/gpu/drm/i915/i915_perf.h index 882fdd0a76800..1d1329e5af3ae 100644 --- a/drivers/gpu/drm/i915/i915_perf.h +++ b/drivers/gpu/drm/i915/i915_perf.h @@ -23,7 +23,7 @@ void i915_perf_fini(struct drm_i915_private *i915); void i915_perf_register(struct drm_i915_private *i915); void i915_perf_unregister(struct drm_i915_private *i915); int i915_perf_ioctl_version(void); -void i915_perf_sysctl_register(void); +int i915_perf_sysctl_register(void); void i915_perf_sysctl_unregister(void); int i915_perf_open_ioctl(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index 34d37d46a1262..eca92076f31d2 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -1088,7 +1088,7 @@ static int i915_pmu_cpu_offline(unsigned int cpu, struct hlist_node *node) static enum cpuhp_state cpuhp_slot = CPUHP_INVALID; -void i915_pmu_init(void) +int i915_pmu_init(void) { int ret; @@ -1101,6 +1101,8 @@ void i915_pmu_init(void) ret); else cpuhp_slot = ret; + + return 0; } void i915_pmu_exit(void) diff --git a/drivers/gpu/drm/i915/i915_pmu.h b/drivers/gpu/drm/i915/i915_pmu.h index 60f9595f902cd..449057648f39b 100644 --- a/drivers/gpu/drm/i915/i915_pmu.h +++ b/drivers/gpu/drm/i915/i915_pmu.h @@ -147,14 +147,14 @@ struct i915_pmu { }; #ifdef CONFIG_PERF_EVENTS -void i915_pmu_init(void); +int i915_pmu_init(void); void i915_pmu_exit(void); void i915_pmu_register(struct drm_i915_private *i915); void i915_pmu_unregister(struct drm_i915_private *i915); void i915_pmu_gt_parked(struct drm_i915_private *i915); void i915_pmu_gt_unparked(struct drm_i915_private *i915); #else -static inline void i915_pmu_init(void) {} +static inline int i915_pmu_init(void) { return 0; } static inline void i915_pmu_exit(void) {} static inline void i915_pmu_register(struct drm_i915_private *i915) {} static inline void i915_pmu_unregister(struct drm_i915_private *i915) {} diff --git a/drivers/gpu/drm/i915/selftests/i915_selftest.c b/drivers/gpu/drm/i915/selftests/i915_selftest.c index 1bc11c09faef5..484759c9409c0 100644 --- a/drivers/gpu/drm/i915/selftests/i915_selftest.c +++ b/drivers/gpu/drm/i915/selftests/i915_selftest.c @@ -187,7 +187,7 @@ int i915_mock_selftests(void) err = run_selftests(mock, NULL); if (err) { i915_selftest.mock = err; - return err; + return 1; } if (i915_selftest.mock < 0) { @@ -430,7 +430,7 @@ module_param_named(st_timeout, i915_selftest.timeout_ms, uint, 0400); module_param_named(st_filter, i915_selftest.filter, charp, 0400); module_param_named_unsafe(mock_selftests, i915_selftest.mock, int, 0400); -MODULE_PARM_DESC(mock_selftests, "Run selftests before loading, using mock hardware (0:disabled [default], 1:run tests then load driver, -1:run tests then exit module)"); +MODULE_PARM_DESC(mock_selftests, "Run selftests before loading, using mock hardware (0:disabled [default], 1:run tests then load driver, -1:run tests then leave dummy module)"); module_param_named_unsafe(live_selftests, i915_selftest.live, int, 0400); MODULE_PARM_DESC(live_selftests, "Run selftests after driver initialisation on the live system (0:disabled [default], 1:run tests then continue, -1:run tests then exit module)"); From patchwork Wed Jul 21 15:23:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12391289 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 89636C636CA for ; Wed, 21 Jul 2021 15:25: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 5BEB661019 for ; Wed, 21 Jul 2021 15:25:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BEB661019 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 E76456EB5C; Wed, 21 Jul 2021 15:25:06 +0000 (UTC) Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by gabe.freedesktop.org (Postfix) with ESMTPS id 182866E9A4 for ; Wed, 21 Jul 2021 15:25:05 +0000 (UTC) Received: by mail-pj1-x1032.google.com with SMTP id jx7-20020a17090b46c7b02901757deaf2c8so1267701pjb.0 for ; Wed, 21 Jul 2021 08:25: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=BhkbkDYY5lvapWHEYykIm8DO+eSuMufmOfIOn+p1+24=; b=ICuQed88N2DSLox8+2+WLSYjWX9567etIPd6e2gZVhN5e9WAwnSsnYltZ0bOQncTA2 PDSqyDltnwfZ+8eTQNYEjRO14OClQbNt256BFV9i8zepxyvIZxA7PSkpUKoF+wMONJeE RHbke94hJmTDTWCtXDUp/HVe50qgC5PFNqzwpiZ4kAMhL2537ofK5aqZidAFl2eOQEf1 U1oXDkZToBXBqokztVEvNieliqQRpJpWBT/4u4pUtuD9chViEfVfbX8UUpkF1XYgooC8 CO5nTp8+aF1iEZvcybwx2iAYbB6OLg5cutw+jpqnkVe2TPiC3qVUamwr7Hcj1QWnIigs C3mA== 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=BhkbkDYY5lvapWHEYykIm8DO+eSuMufmOfIOn+p1+24=; b=HrTjUJC7R1U5vWU+fCjOb4fpUIjdoz0olOTfX8JWMHO1/ZHu2KdMcdfmtr7xclL+I7 2alDvqgyed1VmC3q+Hbvd2kXqSZi2urxutWcS4Ven2UeAhy96u3B6gCuGdpwYBBKm7Su BOroD6IhCFYaRrVtTFzlh9ljBY33E1b0s1yy1HHwlSggTkZV8IfIJlRgAAhhPv+P8ejH ctR9nzuJiP09PPArp3Nf4IG786yZnDRlTXLxo5pUsPCwVz1g158M+OBnj/ZtKOu9tnDF VoNSIUfNozWQ+5F8oh3mQkf10wHobjC1T4nu/WP3CLAc4pBkZy4Rvuju+jFUdNlXsKX1 l7wA== X-Gm-Message-State: AOAM5315BrFKOjoYslpXQB9KoGJSmG7TceI7g2ZfmxOXm7PuFMP627pp iEowzPASEz7fz7/N6Ul77dbqPiaZkn9tuQ== X-Google-Smtp-Source: ABdhPJx+ValW3pKWYpEKgfKlU+q31MmAziW6tzU+OAKOMBI8RQolg01wyhynj1LpxSDAxZ9wxbw0UQ== X-Received: by 2002:a17:90a:642:: with SMTP id q2mr4250208pje.205.1626881104316; Wed, 21 Jul 2021 08:25:04 -0700 (PDT) Received: from omlet.com ([134.134.137.82]) by smtp.gmail.com with ESMTPSA id e4sm32451034pgi.94.2021.07.21.08.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:25:03 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Wed, 21 Jul 2021 10:23:56 -0500 Message-Id: <20210721152358.2893314-5-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721152358.2893314-1-jason@jlekstrand.net> References: <20210721152358.2893314-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") Reviewed-by: 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 Wed Jul 21 15:23: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: 12391291 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 65125C636CA for ; Wed, 21 Jul 2021 15:25:17 +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 36F4961244 for ; Wed, 21 Jul 2021 15:25:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36F4961244 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 113416EB74; Wed, 21 Jul 2021 15:25:14 +0000 (UTC) Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by gabe.freedesktop.org (Postfix) with ESMTPS id DAA646E9A4 for ; Wed, 21 Jul 2021 15:25:06 +0000 (UTC) Received: by mail-pl1-x62f.google.com with SMTP id b12so1110913plh.10 for ; Wed, 21 Jul 2021 08:25:06 -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=ReIHw+eskmExAvlnepg8gr2vNrQ8gC8vqz4lIfsdf9M=; b=cx4NkDTXmjWRjxdpEmqXmgEoug9yEw1drICy1oEyxkj7s3kyeXv2ZOm+2RHy/a/uBF RBXW32jDAVcomik4Z5g4tl/GqoTcN5cagWxgGx6LaAp1ObAnCj+YWcl4H0iaRzQf5E0H IiO+0kkPNQ1Iyu1UQCfOOqnQl0f13KuTmxEOX0OXC2vDf/TujSwb2nq//dz+FpWFzKK0 1okqYPZN4RPsoeCXEuHKVnuylFtKqmidnYZV4V3bRbX1umOx/cYCziCtxgu1YYO9TwXO wu7BmRFRgIIBr8dNiPVQvfHsAmg6QAmRU3bb7Njg7P8f9AMf9r9FZkzp63oVsBCls/4w bYUg== 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=ReIHw+eskmExAvlnepg8gr2vNrQ8gC8vqz4lIfsdf9M=; b=eVlf5Km6v8yTncU70lqk/Iwt4sTE/uCX54XzGs2zYWj941VaoeWFeRxY+YT561JdWM IudRnOBQ5ldWPpRCG1gSJO9YpVr1G7jPiYSVKASsd3LSS7SM/co+FqaPWtXeBYf+JJ3H aqUIxLsz1CPh2hw9K/23E7pcBI2Oj3KmiobyAif2EqG3XmCwCp1/bWtYJGlUYWPcb+IH b1SbcIkFKP9CVLJrehNBbzD5BTp8q+0ahoWkYO8QUuEyA07ymfRxGe+aUARpCZu+sRvh WEznMMF00WC7qmr0Kn/WtivYXDWMHHGJxWJrBXo2+lESjSYX5NfnKiTglHpAWRentKvZ uF0Q== X-Gm-Message-State: AOAM530kCSaN5/9vq7yqirF9FHpBU8QPHiLTKJEbeLbEhfrwDCEawwHU Q8OlleMvPwyujq4lvbtmpcb8kVKNKwts9g== X-Google-Smtp-Source: ABdhPJxuTUBirkIPqBQAE7yxteaKmjNJyniIHrCHUdGlRBJyQmVuAK/n8mvtAme6mXGeRhRjsJLhnA== X-Received: by 2002:a17:902:e80b:b029:12b:56f4:dd1 with SMTP id u11-20020a170902e80bb029012b56f40dd1mr26223843plg.68.1626881106044; Wed, 21 Jul 2021 08:25:06 -0700 (PDT) Received: from omlet.com ([134.134.137.82]) by smtp.gmail.com with ESMTPSA id e4sm32451034pgi.94.2021.07.21.08.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:25:05 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Wed, 21 Jul 2021 10:23:57 -0500 Message-Id: <20210721152358.2893314-6-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721152358.2893314-1-jason@jlekstrand.net> References: <20210721152358.2893314-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: , Cc: Daniel Vetter 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 | 16 ---------------- 2 files changed, 12 insertions(+), 16 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..7fcdef278c742 100644 --- a/drivers/gpu/drm/ttm/ttm_module.c +++ b/drivers/gpu/drm/ttm/ttm_module.c @@ -72,22 +72,6 @@ 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); -module_exit(ttm_exit); - MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse"); MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)"); MODULE_LICENSE("GPL and additional rights"); From patchwork Wed Jul 21 15:23:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Ekstrand X-Patchwork-Id: 12391293 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 F2EE8C636C9 for ; Wed, 21 Jul 2021 15:25:17 +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 BED8361244 for ; Wed, 21 Jul 2021 15:25:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BED8361244 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 F39F76EC03; Wed, 21 Jul 2021 15:25:14 +0000 (UTC) Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by gabe.freedesktop.org (Postfix) with ESMTPS id A88616E9A4 for ; Wed, 21 Jul 2021 15:25:08 +0000 (UTC) Received: by mail-pj1-x102a.google.com with SMTP id p9so1863569pjl.3 for ; Wed, 21 Jul 2021 08:25:08 -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=wBe561iGBsYpzWCDlSpT4F5Gkt6tlNPBtKIWvJ9Ua7g=; b=FXOlZ8tV6zEZsiRlrhQacNvsM1IYuE4a0Tnmn5iRB4dx/mHVnxGvAGZ+WDjrX9RGCg 0P9GBbCvuQ4k1WrIHF0Pjh1aJ5Pp5g2k0fe57YaIrYbXKCWulBt0Ea7l29dDTAduUX9B /1IXRGDkd8wGGQVC40azHWVfblAqEVuejypnL+s6wxrZQ1JZD9H6kv7XNo/Wvn1IGV7Y X1ynBxQ6Yv5aItRkldOKHL3ziLBt0A4ikc9lClZfOVDHoVYbpFuz2xKxrop+cG4zpsVg Ms/o7iJGwUC3APS5ywKemvj6JHE3rl0HC4jWkX4FOh/7I63xiwQuM+WT5GanQvmmAvDi mJxg== 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=wBe561iGBsYpzWCDlSpT4F5Gkt6tlNPBtKIWvJ9Ua7g=; b=flNO18/0vrmlGWIH5TTxJSs82q2yedfcvY/jDX5pqzB3bQE2O76YXbdIdWl2mlWiEU L+GF4ISohsjDAJ9t8VUJu9AU7+lvRnFcY+go8cGgmn83QIrLZA0CAPu5+2YS9HPK7z1w ddRg39eJCKI4vEC2rlMKhRdX1sWVNNu/73nQ3+dGNqNf2U6WkvB8TqTJ6Rgb55sIYM4C VAI8CAY4CUZS0r8XtBYvm4RO3gQMiHIYwJzoAWIn9RHOu6fbERkBUFJD1NrtIV8S3msF ADXpzebmLpqLrenk+pb059Y9GvD2vSws3IK6gOeEexRoJiTbemHT35D3IQIjdtBZPNJd CvwA== X-Gm-Message-State: AOAM533uUB6D8ieHFtUDoX3lkzzpRtXtu/VTva1ogKV0B0zvciSSi8e3 VdJGxP7AQ1hoZzvosgvc09AEqb6H2Z5weg== X-Google-Smtp-Source: ABdhPJziT2XJbK+YUOHZFP+uR6hYW3oMg3yGs4dGYRLRhEI/eJtnxuqjrRICQZ+OvUVbv4rYNLHpDg== X-Received: by 2002:a17:90a:9484:: with SMTP id s4mr4380402pjo.231.1626881107992; Wed, 21 Jul 2021 08:25:07 -0700 (PDT) Received: from omlet.com ([134.134.137.82]) by smtp.gmail.com with ESMTPSA id e4sm32451034pgi.94.2021.07.21.08.25.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:25:07 -0700 (PDT) From: Jason Ekstrand To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Wed, 21 Jul 2021 10:23:58 -0500 Message-Id: <20210721152358.2893314-7-jason@jlekstrand.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210721152358.2893314-1-jason@jlekstrand.net> References: <20210721152358.2893314-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 , =?utf-8?q?Christian_K=C3=B6nig?= 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 Cc: Christian König Reviewed-by: 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,