From patchwork Sat Nov 5 23:27:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 16050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1224175wru; Sat, 5 Nov 2022 16:32:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4sBitmcXNqAAeDb/Apn1DeksTqg/m14gAqZLuMvz0WTZKhRMjxzg2xhhPuWRWIWuTRGYtk X-Received: by 2002:a17:907:2cea:b0:7a3:4ebe:5eb with SMTP id hz10-20020a1709072cea00b007a34ebe05ebmr40401204ejc.228.1667691129922; Sat, 05 Nov 2022 16:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667691129; cv=none; d=google.com; s=arc-20160816; b=zaWChNGbQcpgVeMgxKIxnPb4/Dr46CvFviR5FrxYqqAqmlb9fjBgV5rqxFtoAZ9R1A sGkT/xIXGUL77m1SMFcNz32H4u7kJdeCh4YB+k/cVsl+9geszdCIYtcW6iWJ6tttU3o7 LTSjog3HXd+qis7vqWADNhdfwYkvW/IiaMyRt9rBpu7znNgp3mD8Y9v19yiUSA2i2BAX gZYWLtSfcmLUkl2/u8DKWYWcZOriz9GUaIN87FbiCltSIg0LnTSL4cgg+oI2tMMaQZKy f73EUrS8ihSsoQf5Z2MmzRunhLYdhh2U4pcFfSCXanTzWpHwVav+Smz798C/je5vuT2T f5ZQ== 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 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.31.46; Sat, 05 Nov 2022 16:32:09 -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 + 99 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_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, 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 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?1748700894347178460?= X-GMAIL-MSGID: =?utf-8?q?1748700894347178460?= 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__ */