Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5340469rwl; Sun, 8 Jan 2023 13:14:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXtHjg2KVAmNDPXZDSYWyso4dIcRjYzEFKH8jO4n5YrRMaAZfAxEFlRZMHboQ3qFTk91KjNR X-Received: by 2002:a17:906:f13:b0:7b2:7a42:3e43 with SMTP id z19-20020a1709060f1300b007b27a423e43mr51096897eji.23.1673212466485; Sun, 08 Jan 2023 13:14:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673212466; cv=none; d=google.com; s=arc-20160816; b=e3aSVzvO/QE7tCdYB0sEXaxMopE89LJWQAh0+6wAsIm8q+JMb+E7SjKfohy1I1UTlA DsdHL1w2x++AKTe16GWvR/O5VB/afcW8lzA2jJXLEc/W06jX7Hb8Iq6tTchzS3j+GSrQ rYg1+dq9SyUBnoI3AUrN40qFALU+tF7KTxyPmifgn56sSZ14Vj3+PB/FR/rQckIFTztd drdTOnZv6whuD3Q+KZinVs3/RVhueT8upuIyqHfFBzD3lk4TX18Vv8fUFRDFWIYUuvVR U3w/DaklJfY3bb8T0o1GZiaaVB+V3CSM6n0HhqIWz9VZredxVk9dDOUVS93tNUfJbGKo VQtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tt1uz9i+VPVdaDhi2T9WqMIynKCuXRkBTgWM9BwLebY=; b=D9kwyb079Ig0/h0est5JP7kQ3Wnb0WoMLYF7omVDKxO/XyLo9TyS5E3P/IjNLIEUM1 38Mo4R9uZsoywPAOWFhArhBf9poFc6DWzrnup3B2+xDbeWiaP3tUjmWP3CG51Udvy3wM 997wyCHKpV5kRNsbppSb/cDFln6UR0+652ixGHBgQBLrE9zgwhOh418beiiQ9FEVouvH SueEp9cHVF6Qqf7BWHybC84jNSvpq7JbkfJCoPiPgs2rlXMxFOYRTxrr0RsTgeksXFlA OY0FYArSvQcyHbQiDo4EHJenuSY6DjRZZ/UnjPsNEYwK+RMcfWL9kSqstVY9zfvkDmEI ufog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KCU0U9TI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s22-20020a50ab16000000b0048eafc90734si7123340edc.544.2023.01.08.13.14.14; Sun, 08 Jan 2023 13:14:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KCU0U9TI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236289AbjAHVHd (ORCPT + 53 others); Sun, 8 Jan 2023 16:07:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233834AbjAHVGY (ORCPT ); Sun, 8 Jan 2023 16:06:24 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD70510FED for ; Sun, 8 Jan 2023 13:06:03 -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 44CC46602D58; Sun, 8 Jan 2023 21:05:57 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1673211962; bh=GRt7VASNZp8eBXEdr3FBo1IkPFpurJqLk8d4YopbNTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KCU0U9TIDYDksCUdeKGD2RjXCxfT4aO7VItFgWTSMAgsEHlxmB5SWmzTeAhGxm6yL s/LZM0HHssGv+I6Gov3ZaU+f5PdS/fghtyXjHyZmvGT9tDEOh8hKSazUsMBYaRukCA tGCpPFNOH4N5Ot8Dr+B3AD6kEfpj6x0KSbnhjAXZ2ZgsNTSvej/xvSMHsaKQAMqh6Q H8MXF1U9VRv6glj2KireobtrzeP/3eTLSASrn5rdT3KuMN4TYCapz5lEFSvelvYYqy c3G1yuyc8uzykM5gDx/XaxuwJF6Q8ug6HvQqkwEi+isu48eRaxSu8yTiPw5uF+Xt/k wXSN+q47UY0KQ== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gustavo Padovan , Daniel Stone , Tomeu Vizoso , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Clark , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring , Sean Paul , Dmitry Baryshkov , Abhinav Kumar Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v10 09/11] drm/gem: Add drm_gem_pin_unlocked() Date: Mon, 9 Jan 2023 00:04:43 +0300 Message-Id: <20230108210445.3948344-10-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230108210445.3948344-1-dmitry.osipenko@collabora.com> References: <20230108210445.3948344-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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. 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 dbb48fc9dff3..0b8d3da985c7 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 8e5c22f25691..6f6d96f79a67 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, bool drm_gem_object_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.38.1