Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82965C7EE2E for ; Mon, 27 Feb 2023 06:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjB0GDm (ORCPT ); Mon, 27 Feb 2023 01:03:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjB0GDZ (ORCPT ); Mon, 27 Feb 2023 01:03:25 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD6F136D7 for ; Sun, 26 Feb 2023 22:03:17 -0800 (PST) Received: from workpc.. (109-252-117-89.nat.spd-mgts.ru [109.252.117.89]) (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 madras.collabora.co.uk (Postfix) with ESMTPSA id 2C5226602CEE; Mon, 27 Feb 2023 06:03:15 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1677477796; bh=zckXdlaLMbNl0/o5ZLcD7xzHUhB1lCzZWIIP5en5/Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OwAWprx6b206YuDeM/zVCDA0N3eOvCUEM+EMH6JSsEnMjzjjSzF93e6x8NjRdIstQ TMXCOBQ3F04ftrfGPlkcEjyzYAUsTEX0svL6Pg2GP6NGtlNNzy3/s9ghJ+r9LpTrEa OcOhXgj3WImZP6+oX08jDO94UCz+2WBUxxODwVorg+SnbrS16L1sLa2axdfk4rmwws hX9fkK/moqYZPWraw61/w+3983JB6/hbo1ZkCZDro6KlW48+5Ceg9jLuhf4pXN0VtL t2ChYvKWt5xbHqOh+bznZ6FG0H3X0fdTwpv/1+dfjF7a/CLZG2onBcUuoFIUeWxi25 /XrIHE7j55cDA== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gustavo Padovan , Daniel Stone , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v11 08/10] drm/gem: Add drm_gem_pin_unlocked() Date: Mon, 27 Feb 2023 09:02:17 +0300 Message-Id: <20230227060219.904986-9-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230227060219.904986-1-dmitry.osipenko@collabora.com> References: <20230227060219.904986-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add unlocked variants of drm_gem_un/pin() functions. These new helpers will take care of GEM dma-reservation locking for DRM drivers. VirtIO-GPU driver will use these helpers to pin shmem framebuffers, preventing them from eviction during scanout. Reviewed-by: Thomas Zimmermann Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem.c | 29 +++++++++++++++++++++++++++++ include/drm/drm_gem.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index e5b2c077b314..3b16026e47f8 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1167,6 +1167,35 @@ void drm_gem_unpin(struct drm_gem_object *obj) obj->funcs->unpin(obj); } +int drm_gem_pin_unlocked(struct drm_gem_object *obj) +{ + int ret; + + if (!obj->funcs->pin) + return 0; + + ret = dma_resv_lock_interruptible(obj->resv, NULL); + if (ret) + return ret; + + ret = obj->funcs->pin(obj); + dma_resv_unlock(obj->resv); + + return ret; +} +EXPORT_SYMBOL(drm_gem_pin_unlocked); + +void drm_gem_unpin_unlocked(struct drm_gem_object *obj) +{ + if (!obj->funcs->unpin) + return; + + dma_resv_lock(obj->resv, NULL); + obj->funcs->unpin(obj); + dma_resv_unlock(obj->resv); +} +EXPORT_SYMBOL(drm_gem_unpin_unlocked); + int drm_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map) { int ret; diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 7bd8e2bbbb36..b0a03d2dac99 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -493,4 +493,7 @@ unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru, int drm_gem_evict(struct drm_gem_object *obj); +int drm_gem_pin_unlocked(struct drm_gem_object *obj); +void drm_gem_unpin_unlocked(struct drm_gem_object *obj); + #endif /* __DRM_GEM_H__ */ -- 2.39.2