Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp319270rdb; Fri, 5 Jan 2024 10:49:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGL9C8GMs+wI4z+VsujXT+UOiURuf01TgH7QpDISBYe/h7zvO3+BG7fNTNe+TztmrBtL+uW X-Received: by 2002:a05:620a:66a:b0:781:de2d:9fd7 with SMTP id a10-20020a05620a066a00b00781de2d9fd7mr2313909qkh.55.1704480578483; Fri, 05 Jan 2024 10:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704480578; cv=none; d=google.com; s=arc-20160816; b=y/rvWIL/U746vYM7OzVg/x/xbMPmzKNTum4Fjx17wQFDENZdIRVw4Cw6UwH+5Ff19J WksvcLxT+rmOuC32t/x0nOQSNEm7znhr/7TjrY2zYwmhvOHM7TPDHQCZXyKt1CEeIbdi bG7kpZMNlS3wjwE/KmMwKWkA3Rig3RYJ5t4SfjxdpADcNElxmZelZd5cIHw21UjyfOIa L9jF1Y5VEjT5PtxWEzc8Wq0ieJB4g9oS/Aeu8yLzOoqD6B7SPe4o8ua2BLm6gA03PMRW TqFK/0RakFG2feqR4Ustng7lXXcv5gLEL07ZgaoS4u/B6HclOTfvJ/RvZmDR/t6VRMkZ f4wQ== 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=+lntD0zDdA9lKwFJWJgVuItHEt2KjM7PLuNolPBfnyA=; fh=5cel2jD5h+yPMXVwxbomyVhwojHUqATy6nFjd4aOh4o=; b=i246bbKBVm03f5RR+b8epYTz5Qnd7I2uBT1KGa0fUaOEitcYE6U7YHoJGbwV9e+Ysa jQY6fIFbltJmz0lCEul++c0Vj7xc0VUNuhwJgJ7XL/xzgsvONfngcS2oc5yvq8w1oecW /+f6AAI0euCRdlYO4bnqew37druuFUZqYoFhpLbz6HZ9iuqnOL+zVVeW+aPt/LPt//YT WXuBL6e4Y20ZWFumYhqhhWTBNUBDKoRjhqhmMxzZ8gYIUY/1avG2wEfcXvffIl4Izck8 OdRuhn3+fR9qsg6VjLHZM4b2pMrgcTresb1zTXK7YK3ReAEkS+WcRhJY4uxHkJ4TwaSV pgWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=foN9vxtm; spf=pass (google.com: domain of linux-kernel+bounces-18248-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18248-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s19-20020a05620a0bd300b0078307a2f9bcsi2439549qki.15.2024.01.05.10.49.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 10:49:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18248-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=foN9vxtm; spf=pass (google.com: domain of linux-kernel+bounces-18248-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18248-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 402181C23B88 for ; Fri, 5 Jan 2024 18:49:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62EDD381B7; Fri, 5 Jan 2024 18:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="foN9vxtm" 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 327D8374E3 for ; Fri, 5 Jan 2024 18:47:01 +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=1704480420; bh=8xy9qG3NliGtZPVd2hDSN91KOpRZFrkHzfliPWL1Kr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=foN9vxtmljHtDoFxKZXdVfUlvUk2ldHQPkysEuMIrETOzSthVpHbW8FrNMkkctFbI DUPAoLi9rJaMXAE1q+5pDZrSwThFYaQrk9oUJPH5bE7RY4VFdzjA1CAGbcLUL5qi3n SOJ26VbLZDldYr7D9USPHVQ9Mx0SjnYr6gCe9BLSnr6+chRZ5JWn/hJzpJCR8HtHW7 nac4YIRyxvZdGG31a0mq9S46EA6fdhtNzngGy03ko8VIF36vggCoISL58oQq4MKQQW Ip0WEQ6JQRjX8E2x+cVBXfIumzyu2kCtG4yu4uM2ZpL5h5tNGwX4ofghxUSqRGkruE wSWbCppHn48VA== 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 30AC2378204E; Fri, 5 Jan 2024 18:46:59 +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 10/30] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin Date: Fri, 5 Jan 2024 21:46:04 +0300 Message-ID: <20240105184624.508603-11-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 The vmapped pages shall be pinned in memory and previously get/put_pages() were implicitly hard-pinning/unpinning the pages. This will no longer be the case with addition of memory shrinker because pages_use_count > 0 won't determine anymore whether pages are hard-pinned (they will be soft-pinned), while the new pages_pin_count will do the hard-pinning. Switch the vmap/vunmap() to use pin/unpin() functions in a preparation of addition of the memory shrinker support to drm-shmem. Acked-by: Maxime Ripard Reviewed-by: Boris Brezillon Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 19 ++++++++++++------- include/drm/drm_gem_shmem_helper.h | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 1c032513abf1..9c89183f81b7 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -256,6 +256,14 @@ static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem) return ret; } +static void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem) +{ + dma_resv_assert_held(shmem->base.resv); + + if (refcount_dec_and_test(&shmem->pages_pin_count)) + drm_gem_shmem_put_pages_locked(shmem); +} + /** * drm_gem_shmem_pin - Pin backing pages for a shmem GEM object * @shmem: shmem GEM object @@ -303,10 +311,7 @@ void drm_gem_shmem_unpin(struct drm_gem_shmem_object *shmem) return; dma_resv_lock(shmem->base.resv, NULL); - - if (refcount_dec_and_test(&shmem->pages_pin_count)) - drm_gem_shmem_put_pages_locked(shmem); - + drm_gem_shmem_unpin_locked(shmem); dma_resv_unlock(shmem->base.resv); } EXPORT_SYMBOL_GPL(drm_gem_shmem_unpin); @@ -344,7 +349,7 @@ int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem, return 0; } - ret = drm_gem_shmem_get_pages_locked(shmem); + ret = drm_gem_shmem_pin_locked(shmem); if (ret) goto err_zero_use; @@ -367,7 +372,7 @@ int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem, err_put_pages: if (!obj->import_attach) - drm_gem_shmem_put_pages_locked(shmem); + drm_gem_shmem_unpin_locked(shmem); err_zero_use: shmem->vmap_use_count = 0; @@ -404,7 +409,7 @@ void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem, return; vunmap(shmem->vaddr); - drm_gem_shmem_put_pages_locked(shmem); + drm_gem_shmem_unpin_locked(shmem); } shmem->vaddr = NULL; diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h index 2c5dc62df20c..80623b897803 100644 --- a/include/drm/drm_gem_shmem_helper.h +++ b/include/drm/drm_gem_shmem_helper.h @@ -124,7 +124,7 @@ int drm_gem_shmem_madvise_locked(struct drm_gem_shmem_object *shmem, int madv); static inline bool drm_gem_shmem_is_purgeable(struct drm_gem_shmem_object *shmem) { return (shmem->madv > 0) && - !shmem->vmap_use_count && shmem->sgt && + !refcount_read(&shmem->pages_pin_count) && shmem->sgt && !shmem->base.dma_buf && !shmem->base.import_attach; } -- 2.43.0