From patchwork Wed Nov 23 02:57:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 24674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2561914wrr; Tue, 22 Nov 2022 19:03:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf4QB0ES/TRI5j1EG0RkXZXRNGIZJXkXvfOl9hBefF0DoyF8hn8CkD1KI+d4hCfkKjbKJjcX X-Received: by 2002:a05:6402:1814:b0:469:d569:a478 with SMTP id g20-20020a056402181400b00469d569a478mr7199367edy.369.1669172629287; Tue, 22 Nov 2022 19:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669172629; cv=none; d=google.com; s=arc-20160816; b=kuWjzAGH2QyodIViuzNlJ39jGotTsWtDlv7G/lFx9rS5Dx5kDNyAeMp1+tXVEAe3GW pTQMzPhMX1T534Wd6GZaC3rtZpD7EYEqd4b/6hD54pKS4LkzrqjJSsjcaGdd5AjwI8F/ Ep2dg4w+ndAbowPkvXsUGV8biwRGvrjDD4ci4Lse8gb4wP+c4MXo67QXMPRnfSe5U0nA vXaZ6jAkerZ9rGDaynWwfEJZDxdKhsApaTFCmd0vvvB2Q98uX2RWLC2pBZJh6u0qaf9r 3s0odiibNfWE4s+/OtbCz5g+ncccE953PWinsd1J9mNGyBkKdw5v+kge8IHS3v4ZfqRU uxSg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h12-20020a056402280c00b0045cecdc1fbcsi15225852ede.9.2022.11.22.19.03.24; Tue, 22 Nov 2022 19:03:49 -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 + 99 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_K=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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750254358935171348?= X-GMAIL-MSGID: =?utf-8?q?1750254358935171348?= 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__ */