Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6771897rwb; Tue, 22 Nov 2022 19:20:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf69dlAu6hHmY0LIh7udRLtsTeaR/XyCP2ebMeODQksx2QVvHjGfiBXJJxfcuRIVMpnIU+D7 X-Received: by 2002:a17:906:2d49:b0:7ae:16a9:e4d7 with SMTP id e9-20020a1709062d4900b007ae16a9e4d7mr21774265eji.574.1669173650835; Tue, 22 Nov 2022 19:20:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669173650; cv=none; d=google.com; s=arc-20160816; b=rF8pwkxuKYEzIvNs5iA1LsxRXRVfi9ao1z1UVlirerfQM+wCxU9+CVndvF0f6H0oZ2 ehzlLqh3xQX0TZtmpfZVwcqE8jhcIuyuQ3ngBBrgphzXZq4VaOpPXVF6xfFJUuKyGPm8 mTb84tGeqwd26L3QjmHDRKP969qqUSECTEz5moFAjh5MBSBW4OhPhye9cxV9Ecwa9cUm VKNuwn00wEyLsziX53qmeAUHFqMZpCpPl9R2k8C9cDMpYuhzOelMLcgIqLc/x934bFMw GTNqVGXMiT9QZ9gRb44hzrOBe2JQJ1smFZ/+F+rOy4rWjz//jlKHuuarWDMc3gvy23xN 824g== 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=3ma6ACH/RftPZLziPTXM0Tgb8xniwMHSFZuPCbEpWek=; b=nJNRqus94D58YDQZz4BdCSl5XKj16lAk3HRnQwGZX+6dkjRzLWCpJwx1eE4nrdTszh YIAXx70BcRLLsLesOYKTcuGXE+QZsq3EfQyJKWt1KcdZFUOcedNs3c5iwhiuCiQ5gImG 3ldzO7UWPmNynq4uE1PNpBpL+A/9UN0gzxPP+SjhsBc82XGmrtXh656+OlonXVgD9V1v 8hnulWkvlAt/pehviROPfiJ3j7LSArqXfXIAbLoQgCUU0VTHCrjOcUhIoJOJBPXMRXaS 0vbXRJLbGtCut2YUFdE2WAq/8m3mTdX14J2Epb+SSyN6OuviL+l+HagOiz/FI6E0TAD1 a0Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="kt7sUC/b"; 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 k20-20020aa7c394000000b0045c9904fdafsi516157edq.74.2022.11.22.19.20.26; Tue, 22 Nov 2022 19:20:50 -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="kt7sUC/b"; 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 S235376AbiKWDBF (ORCPT + 89 others); Tue, 22 Nov 2022 22:01:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235499AbiKWDAh (ORCPT ); Tue, 22 Nov 2022 22:00:37 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3FBCE6749 for ; Tue, 22 Nov 2022 19:00:31 -0800 (PST) Received: from dimapc.. (109-252-117-140.nat.spd-mgts.ru [109.252.117.140]) (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 7DA756602AE6; Wed, 23 Nov 2022 03:00:28 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1669172430; bh=7KjneL+L43Td+Zu5d4wJCYl000K2YCO+sqyPKgW4Sm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kt7sUC/blNUKne8qsrtLLzhvPC64Ar1ZFXFx2UAhR9P1wPsv3JjG4byL2JrNi/JJn tbXpxL5lmSYnf7qd/7UC5yUcQ4xJuB5xLwIJhU7JjW1aFEyFgWNIIx7djkD1zhj0KO vfcmAAGjRII4V0Knq9nH3sXBzB9+aK+Y5xDCKll7XQT3JwAj2sdOCXBO5Xg2T750Db pbODOplneHuL2UDnG2rx35DyS6ABIh/POMmAEGZ+khx9E0+QKxIyUuANSKcIgXu2DV SBrvnqkGn0X4Dw3NBW4VCxzREhV1LF1sNbc6g86fMXm6HDALMmlu70yoeyysDcL5aB 5/IszkYSimCLw== 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 v9 09/11] drm/gem: Add drm_gem_pin_unlocked() Date: Wed, 23 Nov 2022 05:57:21 +0300 Message-Id: <20221123025723.695075-10-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123025723.695075-1-dmitry.osipenko@collabora.com> References: <20221123025723.695075-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 c0510b8080d2..0ac5f69ee292 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1154,6 +1154,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 add1371453f0..8a3a07eae8fa 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -492,4 +492,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