Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp3055066rwl; Sat, 5 Nov 2022 16:33:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5A0ZThgAy91t9aNZPQZD+IpgtpE9JsMnt1L4UphQNdo08hDw1uVvNP+PY8ShsFg8e23X1G X-Received: by 2002:a05:6402:5cb:b0:452:e416:2bc4 with SMTP id n11-20020a05640205cb00b00452e4162bc4mr41664680edx.114.1667691203717; Sat, 05 Nov 2022 16:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667691203; cv=none; d=google.com; s=arc-20160816; b=N3UuLguj33V+2s/HbjOMSLqpn+IGdytq2e+prWKWg480x2bZrWOuxjd8Jgkab7RgI7 07cAXzcrfJYC6l6MQiiVOCe3Exwm2ApEARzO0gCHTkcqgsmZwV113viXzkf5/HZjinYY 6XVoXQXVBYQYvnFolkg3zYPZdo5HFhFNQLu0JeobSgRz9vGw2OdLv3FZvRvhp8AOCXwc ef1U/JiWD026n4dOgNUZ769R7pzWxlG+RNq44GJVCZxqQovZvJjIqhDQeD8XWZzXxEb+ swrhNELuSJ8sCXUIbyktpp0G7BhIessL+jzfq4aNYvjA7Hd1jswHMFsADbAt9MRoeNDM pGVw== 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=0uNjFv//qGKn8R2jxr1c7C66dvfiSNudhJh+cjYlhZY=; b=cHapQS+P1d7+g68DPLpq+h2yVaPlwNiMI3w3JyRugHrVcOBZSAf68kjZhnlKUbAlb7 +pEphN4c4YgJJR28IBSBVcAEl2cRqGnRIdkHC0P+HRWsf5qC3lMbktg5yA0yCnq1ok6E qZ9JLzwjaaNz+fvyErG2F6BvQYlGnhTfqZ2CFjjb9l7g/Fby9fyPNIukD3h4+mrQnqeG DAks3PR6M+46PFAHVYS3uYIQROe3WHt69kRh3xt5gAuojz2LoiX2gJmNsSaRg9SGC+ab nJgdfTcXmppQE6Q3UrVsul72IB358redrDEfYWL+38fRW82aCIHEudVbA8/PfZ9Akrr0 fkdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lxg4owk8; 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 ht12-20020a170907608c00b0073dda1430b9si4341630ejc.403.2022.11.05.16.32.59; Sat, 05 Nov 2022 16:33:23 -0700 (PDT) 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=lxg4owk8; 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 S230156AbiKEX3l (ORCPT + 97 others); Sat, 5 Nov 2022 19:29:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbiKEX3S (ORCPT ); Sat, 5 Nov 2022 19:29:18 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A306310B6A for ; Sat, 5 Nov 2022 16:29:13 -0700 (PDT) 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 7D46E6602966; Sat, 5 Nov 2022 23:29:10 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1667690952; bh=vbVBlvxc2Xe9eEsRj4GTle+nnT3PFJq80uOvrVBOKHM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lxg4owk8Wj8lCKX2iriLQJDmAXo6LCYQcVBH2wKNWh7xXy7u1+RPH8xrq1uT1hia0 C7Eo8mZfOrJNQawIVCGlxNCW3Bzbc4UKj8FiedWRsjvYUgR2RDzUf9dP/AC03M/pnz G6qsTemVYuiUcBwYveJlTr0/Ori5tJJZe7X7TC2xLol7culnPwjvDR4YXhst5oTYyx xocbL70C6rcz5FY1KYMjyf49DwNZttv5hCxcXN/whKJThsCv2KB4uuGfWR3VpJfb48 X1Sc7jM+E14K6ERFsRPdKQ2AAwCLLbQbMmTHbT3YxwdV8ONr0AnWllk2NY0kKEyIM0 pbejPAnhrtWAA== 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, Dmitry Osipenko , kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: [PATCH v8 5/7] drm/gem: Add drm_gem_pin_unlocked() Date: Sun, 6 Nov 2022 02:27:17 +0300 Message-Id: <20221105232719.302619-6-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221105232719.302619-1-dmitry.osipenko@collabora.com> References: <20221105232719.302619-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 299bca1390aa..5b8c66f113a9 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 b46ade812443..b43da1652356 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -480,4 +480,7 @@ unsigned long drm_gem_lru_scan(struct drm_gem_lru *lru, unsigned long *remaining, bool (*shrink)(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.37.3