Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp319512rdb; Fri, 5 Jan 2024 10:50:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuo0oZtcgIBwo4FJur+vadSAQmjjSGiVCfcSDCYhfknM9cDDMhMoDV4rajX7LnE4SYvje5 X-Received: by 2002:a17:90b:8b:b0:28c:f93d:9c6d with SMTP id bb11-20020a17090b008b00b0028cf93d9c6dmr2093167pjb.74.1704480616859; Fri, 05 Jan 2024 10:50:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480616; cv=none; d=google.com; s=arc-20160816; b=JAdcktRl2PmGTPy3HkYZoUsbhnc3Qqp+a7yElhUTG4UpJjI+9BD4iThbL80Yz4hxHt ole2TUBEkf5Rdx4UgGrBk1UcCTBXXNn5yVcQ46SVNFdGPMep5jn0akdAGLf+VV6xl6Z/ c5mK0hzVw7DRzP4NuVgP4dIVwaDmNkYPGHlMpBD+HxnCq7YA+Fhkp6YtANX0pxmH0+Hp hzAdn7mQx6IA+R9iiUc4ldgLy/1gsoUsJKe9S9QN1rQnilazn/1LOx5N7lNt3VDRAccY k87zAtUHWJiPFvEJgG5JwN7jrMHmH+f3Z854wvETS38nQTA4aDwSHrCXuAqVKDOjWC/b 7FLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HG8xtjGKlzb1iX9kRct4tAAyeRO0kf/udAOhuq2wib8=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=b9qFIeGTixa8ABDwu1zjH5LUcl2OHI5T83zVCAXTL6LZ+lBcR5uy1hW4rV71/X6t+G Wxx+ettpsVFuKYMJaF8IKiVgb/L0a+VKwAvmen03CCzL2QiWqqAIOjrSZFJu7VSY1TlZ GKdewc3uxyVuqUBArtef1OHE3F9HBmNCD3uYiwtXIeohK/qbUB3MHuwPuTx5ckWjjA4j 38T2IAJmtp+V6PZ0ExNg0l+QEBxN7WyB3HkAkCcBzVc+d89Jk3vUDh9TECefn+VPy5Fm yGrEOiz7o5wIApGeeUm0FO9/Dk0EMR2V1sZf85Y8lgAXx5Oj/v52m6jO1Yl8Iskgv/Da GqXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aVeYBhwZ; spf=pass (google.com: domain of linux-kernel+bounces-18250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18250-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s15-20020a17090a880f00b0028ced82a7dcsi1238920pjn.4.2024.01.05.10.50.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:50:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aVeYBhwZ; spf=pass (google.com: domain of linux-kernel+bounces-18250-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18250-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5FF95281660 for ; Fri, 5 Jan 2024 18:50:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB5EF38DEE; Fri, 5 Jan 2024 18:47:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="aVeYBhwZ" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9981A381D1 for ; Fri, 5 Jan 2024 18:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1704480423; bh=xi7umfn3odK5/kuqYD+1GYoRfQ0wyb5ZdiidzOwD6Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aVeYBhwZRIhsDGR8JNg4W1K4IyB5of3osKSyffgpHpmO7cUAD1oSr6XDnxCxplEGt cbbPrZH8nlbs87hGn59EXGf+0cQikhVOXvLjnXqTEMhsQQmeXU2TOprdWPaqmKQU2Y S4xcYlV6Z5xpnLTyRXl+NS75Akvw9m3E1XRZh8n79DDi/WFqzdtCkqQKYi1WwPNDEv yOmMAYeaUOYaM5VGQsj3+pkIc+qjgOOfsC+L6yRRpZRu5Ztns/KvU4Zz2X8wnPYJNx 9Hz4sv675X/aEWT/iAeIqa+5ZYk0hgvY78HCj09JEyy+RhzHeff/yYtuvAT1PiC4WJ WYUY8nQfqD1Aw== Received: from workpc.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 6B0083782042; Fri, 5 Jan 2024 18:47:02 +0000 (UTC) From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?q?Christian=20K=C3=B6nig?= , Qiang Yu , Steven Price , Boris Brezillon , Emma Anholt , Melissa Wen Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v19 12/30] drm/shmem-helper: Prepare drm_gem_shmem_free() to shrinker addition Date: Fri, 5 Jan 2024 21:46:06 +0300 Message-ID: <20240105184624.508603-13-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105184624.508603-1-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Prepare drm_gem_shmem_free() to addition of memory shrinker support to drm-shmem by adding and using variant of put_pages() that doesn't touch reservation lock. Reservation shouldn't be touched because lockdep will trigger a bogus warning about locking contention with fs_reclaim code paths that can't happen during the time when GEM is freed and lockdep doesn't know about that. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 40 ++++++++++++++------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 3403700780c3..799a3c5015ad 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -128,6 +128,22 @@ struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t } EXPORT_SYMBOL_GPL(drm_gem_shmem_create); +static void +drm_gem_shmem_free_pages(struct drm_gem_shmem_object *shmem) +{ + struct drm_gem_object *obj = &shmem->base; + +#ifdef CONFIG_X86 + if (shmem->map_wc) + set_pages_array_wb(shmem->pages, obj->size >> PAGE_SHIFT); +#endif + + drm_gem_put_pages(obj, shmem->pages, + shmem->pages_mark_dirty_on_put, + shmem->pages_mark_accessed_on_put); + shmem->pages = NULL; +} + /** * drm_gem_shmem_free - Free resources associated with a shmem GEM object * @shmem: shmem GEM object to free @@ -142,8 +158,6 @@ void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) if (obj->import_attach) { drm_prime_gem_destroy(obj, shmem->sgt); } else { - dma_resv_lock(shmem->base.resv, NULL); - drm_WARN_ON(obj->dev, refcount_read(&shmem->vmap_use_count)); if (shmem->sgt) { @@ -152,13 +166,12 @@ void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) sg_free_table(shmem->sgt); kfree(shmem->sgt); } - if (shmem->pages) - drm_gem_shmem_put_pages_locked(shmem); + if (shmem->pages && + refcount_dec_and_test(&shmem->pages_use_count)) + drm_gem_shmem_free_pages(shmem); drm_WARN_ON(obj->dev, refcount_read(&shmem->pages_use_count)); drm_WARN_ON(obj->dev, refcount_read(&shmem->pages_pin_count)); - - dma_resv_unlock(shmem->base.resv); } drm_gem_object_release(obj); @@ -208,21 +221,10 @@ static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem) */ void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem) { - struct drm_gem_object *obj = &shmem->base; - dma_resv_assert_held(shmem->base.resv); - if (refcount_dec_and_test(&shmem->pages_use_count)) { -#ifdef CONFIG_X86 - if (shmem->map_wc) - set_pages_array_wb(shmem->pages, obj->size >> PAGE_SHIFT); -#endif - - drm_gem_put_pages(obj, shmem->pages, - shmem->pages_mark_dirty_on_put, - shmem->pages_mark_accessed_on_put); - shmem->pages = NULL; - } + if (refcount_dec_and_test(&shmem->pages_use_count)) + drm_gem_shmem_free_pages(shmem); } EXPORT_SYMBOL_GPL(drm_gem_shmem_put_pages_locked); -- 2.43.0