From patchwork Mon Nov 30 12:04:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 11940293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E55DC64E8A for ; Mon, 30 Nov 2020 12:04:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EC67F20825 for ; Mon, 30 Nov 2020 12:04:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC67F20825 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3026189D66; Mon, 30 Nov 2020 12:04:43 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id E324889D66 for ; Mon, 30 Nov 2020 12:04:38 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8A26BAE38; Mon, 30 Nov 2020 12:04:37 +0000 (UTC) From: Thomas Zimmermann To: airlied@redhat.com, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, hdegoede@redhat.com, christian.koenig@amd.com Subject: [PATCH 1/8] drm/gem: Write down some rules for vmap usage Date: Mon, 30 Nov 2020 13:04:26 +0100 Message-Id: <20201130120433.7205-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201130120433.7205-1-tzimmermann@suse.de> References: <20201130120433.7205-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Mapping a GEM object's buffer into kernel address space prevents the buffer from being evicted from VRAM, which in turn may result in out-of-memory errors. It's therefore required to only vmap GEM BOs for short periods of time; unless the GEM implementation provides additional guarantees. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_prime.c | 6 ++++++ include/drm/drm_gem.h | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 7db55fce35d8..9c9ece9833e0 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -669,6 +669,12 @@ EXPORT_SYMBOL(drm_gem_unmap_dma_buf); * callback. Calls into &drm_gem_object_funcs.vmap for device specific handling. * The kernel virtual address is returned in map. * + * To prevent the GEM object from being relocated, callers must hold the GEM + * object's reservation lock from when calling this function until releasing the + * mapping. Holding onto a mapping and the associated reservation lock for an + * unbound time may result in out-of-memory errors. Calls to drm_gem_dmabuf_vmap() + * should therefore be accompanied by a call to drm_gem_dmabuf_vunmap(). + * * Returns 0 on success or a negative errno code otherwise. */ int drm_gem_dmabuf_vmap(struct dma_buf *dma_buf, struct dma_buf_map *map) diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 5e6daa1c982f..7c34cd5ec261 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -137,7 +137,21 @@ struct drm_gem_object_funcs { * Returns a virtual address for the buffer. Used by the * drm_gem_dmabuf_vmap() helper. * + * Notes to implementors: + * + * - Implementations must expect pairs of @vmap and @vunmap to be + * called frequently and should optimize for this case. + * + * - Implemenations may expect the caller to hold the GEM object's + * reservation lock to protect against concurrent calls and relocation + * of the GEM object. + * + * - Implementations may provide additional guarantees (e.g., working + * without holding the reservation lock). + * * This callback is optional. + * + * See also drm_gem_dmabuf_vmap() */ int (*vmap)(struct drm_gem_object *obj, struct dma_buf_map *map); @@ -148,6 +162,8 @@ struct drm_gem_object_funcs { * drm_gem_dmabuf_vunmap() helper. * * This callback is optional. + * + * See also @vmap. */ void (*vunmap)(struct drm_gem_object *obj, struct dma_buf_map *map);