From patchwork Sat Feb 2 15:41:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring (Arm)" X-Patchwork-Id: 10794415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE99313B5 for ; Sat, 2 Feb 2019 15:42:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFEDF2F161 for ; Sat, 2 Feb 2019 15:42:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B13E72F167; Sat, 2 Feb 2019 15:42:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E69D2F161 for ; Sat, 2 Feb 2019 15:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbfBBPmD (ORCPT ); Sat, 2 Feb 2019 10:42:03 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46424 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbfBBPmD (ORCPT ); Sat, 2 Feb 2019 10:42:03 -0500 Received: by mail-oi1-f193.google.com with SMTP id x202so8259720oif.13 for ; Sat, 02 Feb 2019 07:42:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kXO9EnLK/WG9l04J2zoTVZIyTiSdpAPmcoczIKV7sqM=; b=Spz5cINv7S0JaL/vfF4Hm2w7Z+lhIxvjszRP/aTHNx8CrxlQvO4uAW3chhOAgKrF6T Kw99lGDccwkYJ+4DkRaDHPSkADbXCwjm8ayU1NWOT0s90PsckDBEVaskD01LGwEwJaDu sFHC3j3JvzqEGzD7BQ5Y61nwA4Qpc3u97/AGu93WRspzCfjGP6Zm42ogbmQO0dZWEboV 4r+BmmFrCTHsZAvKXGPTBMWHNTH6xX2jasHVOvSgTyhxi7uehUOMtLOVHn0GTVnXODnU DwO/tnhbowoB+TcTk9TO1LsIlIxHdrlwJVscVV84IzXZfMcMqURBd4bQiXJZ1xGooidd QsCg== X-Gm-Message-State: AJcUukeF5nCGPTQzpP56WG72p7CpY3sI4/9NIXV56/yzYlJDjyTF9GeP XA00MpZY/UwWUTw6ElkECA== X-Google-Smtp-Source: AHgI3IZiEQWi/0jm030K4Z3iavUu+lSghcBBMWBuIR2R7HSXvNJF3giW+WdQlPGrEu++SHQDvNlslg== X-Received: by 2002:aca:f1d7:: with SMTP id p206mr22581205oih.239.1549122120725; Sat, 02 Feb 2019 07:42:00 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id 187sm5215559oic.12.2019.02.02.07.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Feb 2019 07:42:00 -0800 (PST) From: Rob Herring To: dri-devel@lists.freedesktop.org Cc: Christian Gmeiner , Daniel Vetter , David Airlie , Eric Anholt , etnaviv@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Lucas Stach , Maarten Lankhorst , Maxime Ripard , Rob Clark , Russell King , Sean Paul Subject: [PATCH v2 1/5] drm: Add reservation_object to drm_gem_object Date: Sat, 2 Feb 2019 09:41:54 -0600 Message-Id: <20190202154158.10443-2-robh@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190202154158.10443-1-robh@kernel.org> References: <20190202154158.10443-1-robh@kernel.org> MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Many users of drm_gem_object embed a struct reservation_object into their subclassed struct, so let's add one to struct drm_gem_object. This will allow removing the reservation object from the subclasses and removing the ->gem_prime_res_obj callback. With the addition, add a drm_gem_reservation_object_wait() helper function for drivers to use in wait ioctls. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Signed-off-by: Rob Herring Acked-by: Daniel Vetter Reviewed-by: Eric Anholt Reviewed-by: Christian Gmeiner --- v2: - Fix missing kerneldoc - Reword todo with what is left todo. - Fix timeout error handling (added to drm_gem_reservation_object_wait) Documentation/gpu/todo.rst | 8 +++---- drivers/gpu/drm/drm_gem.c | 43 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_prime.c | 1 + include/drm/drm_gem.h | 21 ++++++++++++++++++ 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst index 14191b64446d..c9ed55605641 100644 --- a/Documentation/gpu/todo.rst +++ b/Documentation/gpu/todo.rst @@ -209,12 +209,12 @@ Would be great to refactor this all into a set of small common helpers. Contact: Daniel Vetter -Put a reservation_object into drm_gem_object +Remove the ->gem_prime_res_obj callback -------------------------------------------- -This would remove the need for the ->gem_prime_res_obj callback. It would also -allow us to implement generic helpers for waiting for a bo, allowing for quite a -bit of refactoring in the various wait ioctl implementations. +The ->gem_prime_res_obj callback can be removed from drivers by using the +reservation_object in the drm_gem_object. It may also be possible to use the +generic drm_gem_reservation_object_wait helper for waiting for a bo. Contact: Daniel Vetter diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 8b55ece97967..b09acbc5a655 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -170,6 +170,10 @@ void drm_gem_private_object_init(struct drm_device *dev, kref_init(&obj->refcount); obj->handle_count = 0; obj->size = size; + reservation_object_init(&obj->_resv); + if (!obj->resv) + obj->resv = &obj->_resv; + drm_vma_node_reset(&obj->vma_node); } EXPORT_SYMBOL(drm_gem_private_object_init); @@ -657,6 +661,44 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle) } EXPORT_SYMBOL(drm_gem_object_lookup); +/** + * drm_gem_reservation_object_wait - Wait on GEM object's reservation's objects + * shared and/or exclusive fences. + * @filep: DRM file private date + * @handle: userspace handle + * @wait_all: if true, wait on all fences, else wait on just exclusive fence + * @timeout: timeout value in jiffies or zero to return immediately + * + * Returns: + * + * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or + * greater than 0 on success. + */ +long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, + bool wait_all, unsigned long timeout) +{ + long ret; + struct drm_gem_object *obj; + + obj = drm_gem_object_lookup(filep, handle); + if (!obj) { + DRM_DEBUG("Failed to look up GEM BO %d\n", handle); + return -EINVAL; + } + + ret = reservation_object_wait_timeout_rcu(obj->resv, wait_all, + true, timeout); + if (ret == 0) + ret = -ETIME; + else if (ret > 0) + ret = 0; + + drm_gem_object_put_unlocked(obj); + + return ret; +} +EXPORT_SYMBOL(drm_gem_reservation_object_wait); + /** * drm_gem_close_ioctl - implementation of the GEM_CLOSE ioctl * @dev: drm_device @@ -821,6 +863,7 @@ drm_gem_object_release(struct drm_gem_object *obj) if (obj->filp) fput(obj->filp); + reservation_object_fini(&obj->_resv); drm_gem_free_mmap_offset(obj); } EXPORT_SYMBOL(drm_gem_object_release); diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 231e3f6d5f41..dc079efb3b0f 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -504,6 +504,7 @@ struct dma_buf *drm_gem_prime_export(struct drm_device *dev, .size = obj->size, .flags = flags, .priv = obj, + .resv = obj->resv, }; if (dev->driver->gem_prime_res_obj) diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index c95727425284..25f1ff2df464 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -35,6 +35,7 @@ */ #include +#include #include @@ -262,6 +263,24 @@ struct drm_gem_object { */ struct dma_buf_attachment *import_attach; + /** + * @resv: + * + * Pointer to reservation object associated with the this GEM object. + * + * Normally (@resv == &@_resv) except for imported GEM objects. + */ + struct reservation_object *resv; + + /** + * @_resv: + * + * A reservation object for this GEM object. + * + * This is unused for imported GEM objects. + */ + struct reservation_object _resv; + /** * @funcs: * @@ -363,6 +382,8 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, bool dirty, bool accessed); struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle); +long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle, + bool wait_all, unsigned long timeout); int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev, u32 handle, u64 *offset); int drm_gem_dumb_destroy(struct drm_file *file,