From patchwork Mon Jun 26 12:02:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 13292795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2DC58EB64D7 for ; Mon, 26 Jun 2023 12:03:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8BBD10E1F1; Mon, 26 Jun 2023 12:03:09 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7F03010E1E9 for ; Mon, 26 Jun 2023 12:02:56 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (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: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 0B286660714F; Mon, 26 Jun 2023 13:02:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687780974; bh=Yo+pz+Tp+bqdyprITgKnXcZA+Qz/RRRbu5C4yTdFidk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MJji4tPomBasuVSibAAYimTd9IVMmHanBvi6k/mb4hOdwivggvnaoBo4ziQ4Vcf70 zikD7mt9vcWsy7EB1zzMrjKJO6CpuujYm1yvUBXSFXNPqbGA/WUuiwPgcWYOW7LM8V BqBjDQpGLnG2uCEIjZVXBU12bnvpDM/6soEwepPA1rV+1v0PADzLmAByFeSQ2e0B6F yAeiWiufD5tvwi3B01+uyb51DZDPtm6sNS1XvJXgDAgYXk2GSPhBRsWxIpRkgHfiaO n8y2MHt92iB+BbWPU/fUCqFGSQm4srHBQXCRW1TXYu4oysF1OagC/Ff/JSkvBnwFwl CS0YUcZB5n4lA== From: Boris Brezillon To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/panfrost: Stop using drm_gem_shmem_put_pages() Date: Mon, 26 Jun 2023 14:02:43 +0200 Message-ID: <20230626120247.1337962-2-boris.brezillon@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626120247.1337962-1-boris.brezillon@collabora.com> References: <20230626120247.1337962-1-boris.brezillon@collabora.com> 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 , Emil Velikov , Steven Price , Boris Brezillon , Dmitry Osipenko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We want to get rid of this helper function, so let's use drm_gem_shmem_unpin() and move this call out of the dma_resv-locked section. Signed-off-by: Boris Brezillon Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Emil Velikov Cc: Dmitry Osipenko Cc: Rob Herring Cc: Steven Price --- drivers/gpu/drm/panfrost/panfrost_mmu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index c0123d09f699..0b12f03ef0be 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -447,6 +447,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, pgoff_t page_offset; struct sg_table *sgt; struct page **pages; + bool pinned = false; bomapping = addr_to_mapping(pfdev, as, addr); if (!bomapping) @@ -488,12 +489,14 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, } bo->base.pages = pages; bo->base.pages_use_count = 1; + pinned = true; } else { pages = bo->base.pages; if (pages[page_offset]) { /* Pages are already mapped, bail out. */ goto out; } + pinned = true; } mapping = bo->base.base.filp->f_mapping; @@ -504,7 +507,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, if (IS_ERR(pages[i])) { ret = PTR_ERR(pages[i]); pages[i] = NULL; - goto err_pages; + goto err_unlock; } } @@ -512,7 +515,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, ret = sg_alloc_table_from_pages(sgt, pages + page_offset, NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL); if (ret) - goto err_pages; + goto err_unlock; ret = dma_map_sgtable(pfdev->dev, sgt, DMA_BIDIRECTIONAL, 0); if (ret) @@ -534,10 +537,12 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, err_map: sg_free_table(sgt); -err_pages: - drm_gem_shmem_put_pages(&bo->base); err_unlock: dma_resv_unlock(obj->resv); + + if (ret && pinned) + drm_gem_shmem_unpin(&bo->base); + err_bo: panfrost_gem_mapping_put(bomapping); return ret; From patchwork Mon Jun 26 12:02:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 13292794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 359ADEB64DC for ; Mon, 26 Jun 2023 12:03:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C948910E1EE; Mon, 26 Jun 2023 12:03:09 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id D9C7A10E1EC for ; Mon, 26 Jun 2023 12:02:56 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (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: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 6E5076607150; Mon, 26 Jun 2023 13:02:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687780974; bh=LQiDihajyS4lpLnWl0hRNS1aTYOBaC2aOlpCoubhNJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l0RA8Y2qJ/jjzI580eEQshqNwApQGSAxZQnh8m8aZeinkwOyGCLTZmFzrCcqrcN30 apy2wNNyuBt/GQYpNFqQuEnBBh6uWVLbX+RGyfEdiFVwO67owySBhegkh9yBwFm4I9 lxXuky6t/tynsot3rZAoVit6Xd4vCF+U50Um4iKXkzYnBNKJaQAxR/We6ZTis37NzI 1gqixAdcaNc4YVIGBTKWmtDScIl98h7Xw20g9p4y9ci6bq2Tp5cXRC4A8rh9nqpWr4 9P/0djIcVpQCWldYgAG/5Xa7NSmJrPE4p6LxXEgNH4PTfb6GL+NslQgHcLMdHWnu3O TDQPHQ/VD9iaQ== From: Boris Brezillon To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/shmem-helper: Stop exposing drm_gem_shmem_put_pages() Date: Mon, 26 Jun 2023 14:02:44 +0200 Message-ID: <20230626120247.1337962-3-boris.brezillon@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626120247.1337962-1-boris.brezillon@collabora.com> References: <20230626120247.1337962-1-boris.brezillon@collabora.com> 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: Dmitry Osipenko , Boris Brezillon , Emil Velikov , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The last user (panfrost) moved to drm_gem_shmem_unpin(), so it's now safe to make this function private. Signed-off-by: Boris Brezillon Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Emil Velikov Cc: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 5 +++-- include/drm/drm_gem_shmem_helper.h | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index a783d2245599..d6fc034164c0 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -128,6 +128,8 @@ struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t } EXPORT_SYMBOL_GPL(drm_gem_shmem_create); +static void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem); + /** * drm_gem_shmem_free - Free resources associated with a shmem GEM object * @shmem: shmem GEM object to free @@ -204,7 +206,7 @@ static int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem) * * This function decreases the use count and puts the backing pages when use drops to zero. */ -void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) +static void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) { struct drm_gem_object *obj = &shmem->base; @@ -226,7 +228,6 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) shmem->pages_mark_accessed_on_put); shmem->pages = NULL; } -EXPORT_SYMBOL(drm_gem_shmem_put_pages); static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem) { diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h index 2867d2aba88b..f55f8739acc0 100644 --- a/include/drm/drm_gem_shmem_helper.h +++ b/include/drm/drm_gem_shmem_helper.h @@ -99,7 +99,6 @@ struct drm_gem_shmem_object { struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t size); void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem); -void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem); int drm_gem_shmem_pin(struct drm_gem_shmem_object *shmem); void drm_gem_shmem_unpin(struct drm_gem_shmem_object *shmem); int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, From patchwork Mon Jun 26 12:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 13292790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 12A44EB64DA for ; Mon, 26 Jun 2023 12:02:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F51510E1E8; Mon, 26 Jun 2023 12:02:58 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id D5F0D10E1E9 for ; Mon, 26 Jun 2023 12:02:56 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (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: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id C4CD46607152; Mon, 26 Jun 2023 13:02:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687780975; bh=8StPnC8cFjLppoEu1zuY4PPBYBiFmydbk7VeE+rIuhs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EVqidSsHQ7mlBUUONOkt9Vz/0Kc5xCif98W9c2HDAuHutoAcufMZs1BboGElAT4+f O9h3NvgTsVoNq3DxmyjetMlOF7lzRiRPEYU+6h4KWWS6nywHcQkRoH0ybBBmALXOzm bFKoctBKVJDaZwTrXTchQI+MsxKtNvYO49SV5sDlUZnUeY7kSljNv1eijCzxolZ85p llvmGqYIIg10wZb1b8GnU/fMEmWwDocU567LVcVkalD6jrLm+vlC9kmFFQKq9M3s2u FXSjZNLapED3ODNr4uLwitWp/KCvhc6rp8M/OMvfHFxuAWIosPms990aiG23ylA8gM 5+e5V0lr5FN3g== From: Boris Brezillon To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/shmem-helper: Inline drm_gem_shmem_{get,put}_pages() Date: Mon, 26 Jun 2023 14:02:45 +0200 Message-ID: <20230626120247.1337962-4-boris.brezillon@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626120247.1337962-1-boris.brezillon@collabora.com> References: <20230626120247.1337962-1-boris.brezillon@collabora.com> 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: Dmitry Osipenko , Boris Brezillon , Emil Velikov , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Move code drm_gem_shmem_{get,put}_pages() code to drm_gem_shmem_{pin,unpin}_locked(). Signed-off-by: Boris Brezillon Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Emil Velikov Cc: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 108 ++++++++++--------------- 1 file changed, 41 insertions(+), 67 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index d6fc034164c0..f406556e42e0 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -128,46 +128,7 @@ struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t } EXPORT_SYMBOL_GPL(drm_gem_shmem_create); -static void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem); - -/** - * drm_gem_shmem_free - Free resources associated with a shmem GEM object - * @shmem: shmem GEM object to free - * - * This function cleans up the GEM object state and frees the memory used to - * store the object itself. - */ -void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) -{ - struct drm_gem_object *obj = &shmem->base; - - if (obj->import_attach) { - drm_prime_gem_destroy(obj, shmem->sgt); - } else { - dma_resv_lock(shmem->base.resv, NULL); - - drm_WARN_ON(obj->dev, shmem->vmap_use_count); - - if (shmem->sgt) { - dma_unmap_sgtable(obj->dev->dev, shmem->sgt, - DMA_BIDIRECTIONAL, 0); - sg_free_table(shmem->sgt); - kfree(shmem->sgt); - } - if (shmem->pages) - drm_gem_shmem_put_pages(shmem); - - drm_WARN_ON(obj->dev, shmem->pages_use_count); - - dma_resv_unlock(shmem->base.resv); - } - - drm_gem_object_release(obj); - kfree(shmem); -} -EXPORT_SYMBOL_GPL(drm_gem_shmem_free); - -static int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem) +static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem) { struct drm_gem_object *obj = &shmem->base; struct page **pages; @@ -200,13 +161,7 @@ static int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem) return 0; } -/* - * drm_gem_shmem_put_pages - Decrease use count on the backing pages for a shmem GEM object - * @shmem: shmem GEM object - * - * This function decreases the use count and puts the backing pages when use drops to zero. - */ -static void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) +static void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem) { struct drm_gem_object *obj = &shmem->base; @@ -229,23 +184,42 @@ static void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem) shmem->pages = NULL; } -static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem) +/** + * drm_gem_shmem_free - Free resources associated with a shmem GEM object + * @shmem: shmem GEM object to free + * + * This function cleans up the GEM object state and frees the memory used to + * store the object itself. + */ +void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) { - int ret; + struct drm_gem_object *obj = &shmem->base; - dma_resv_assert_held(shmem->base.resv); + if (obj->import_attach) { + drm_prime_gem_destroy(obj, shmem->sgt); + } else { + dma_resv_lock(shmem->base.resv, NULL); - ret = drm_gem_shmem_get_pages(shmem); + drm_WARN_ON(obj->dev, shmem->vmap_use_count); - return ret; -} - -static void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem) -{ - dma_resv_assert_held(shmem->base.resv); - - drm_gem_shmem_put_pages(shmem); + if (shmem->sgt) { + dma_unmap_sgtable(obj->dev->dev, shmem->sgt, + DMA_BIDIRECTIONAL, 0); + sg_free_table(shmem->sgt); + kfree(shmem->sgt); + } + if (shmem->pages) + drm_gem_shmem_unpin_locked(shmem); + + drm_WARN_ON(obj->dev, shmem->pages_use_count); + + dma_resv_unlock(shmem->base.resv); + } + + drm_gem_object_release(obj); + kfree(shmem); } +EXPORT_SYMBOL_GPL(drm_gem_shmem_free); /** * drm_gem_shmem_pin - Pin backing pages for a shmem GEM object @@ -332,7 +306,7 @@ int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, return 0; } - ret = drm_gem_shmem_get_pages(shmem); + ret = drm_gem_shmem_pin_locked(shmem); if (ret) goto err_zero_use; @@ -355,7 +329,7 @@ int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, err_put_pages: if (!obj->import_attach) - drm_gem_shmem_put_pages(shmem); + drm_gem_shmem_unpin_locked(shmem); err_zero_use: shmem->vmap_use_count = 0; @@ -392,7 +366,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem, return; vunmap(shmem->vaddr); - drm_gem_shmem_put_pages(shmem); + drm_gem_shmem_unpin_locked(shmem); } shmem->vaddr = NULL; @@ -452,7 +426,7 @@ void drm_gem_shmem_purge(struct drm_gem_shmem_object *shmem) kfree(shmem->sgt); shmem->sgt = NULL; - drm_gem_shmem_put_pages(shmem); + drm_gem_shmem_unpin_locked(shmem); shmem->madv = -1; @@ -565,7 +539,7 @@ static void drm_gem_shmem_vm_close(struct vm_area_struct *vma) struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj); dma_resv_lock(shmem->base.resv, NULL); - drm_gem_shmem_put_pages(shmem); + drm_gem_shmem_unpin_locked(shmem); dma_resv_unlock(shmem->base.resv); drm_gem_vm_close(vma); @@ -606,7 +580,7 @@ int drm_gem_shmem_mmap(struct drm_gem_shmem_object *shmem, struct vm_area_struct } dma_resv_lock(shmem->base.resv, NULL); - ret = drm_gem_shmem_get_pages(shmem); + ret = drm_gem_shmem_pin_locked(shmem); dma_resv_unlock(shmem->base.resv); if (ret) @@ -674,7 +648,7 @@ static struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_ drm_WARN_ON(obj->dev, obj->import_attach); - ret = drm_gem_shmem_get_pages(shmem); + ret = drm_gem_shmem_pin_locked(shmem); if (ret) return ERR_PTR(ret); @@ -696,7 +670,7 @@ static struct sg_table *drm_gem_shmem_get_pages_sgt_locked(struct drm_gem_shmem_ sg_free_table(sgt); kfree(sgt); err_put_pages: - drm_gem_shmem_put_pages(shmem); + drm_gem_shmem_unpin_locked(shmem); return ERR_PTR(ret); } From patchwork Mon Jun 26 12:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 13292792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2C360EB64DA for ; Mon, 26 Jun 2023 12:03:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1064110E1ED; Mon, 26 Jun 2023 12:02:59 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 98BB110E1EC for ; Mon, 26 Jun 2023 12:02:56 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (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: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2A8406607153; Mon, 26 Jun 2023 13:02:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687780975; bh=sWh39NW5LoQNauNv9C28QV+IdVUwgwQoOS9c8mIjZqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YKtYrbMPqpcc1xhtYRWOqpGNnIpRCuDi1/cxQ4SbhxBoiSY+j0e6FePmdREVJp84o lZ8u/Fzd73MBPMOODyoe4U9swl6R5LsoQmBwFpga/Np+McYVPMS/Tgic6WRS321TSc T6Seaw4rp1sWhGQXSeQ/LnbS/5ezLa8bXchlLY5p5GGa0ZyyrwMCrZyxLgAjcgJqnm bul1/MuIf00YGEI7ET5IxAeyowV3GYTKi4+07UCPZjouuFFbqbFRfToMpfof1B34mw CiawzYFV1Xu2aNm3cIVqwucB71RudF2SNmBUe0RYtaACzkm6+mAPvjHY7Yvoxa1+fo V7djSiSeLLzNg== From: Boris Brezillon To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/shmem-helper: Make dma_resv_assert_held() unconditional in drm_gem_shmem_v[un]map() Date: Mon, 26 Jun 2023 14:02:46 +0200 Message-ID: <20230626120247.1337962-5-boris.brezillon@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626120247.1337962-1-boris.brezillon@collabora.com> References: <20230626120247.1337962-1-boris.brezillon@collabora.com> 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: Dmitry Osipenko , Boris Brezillon , Emil Velikov , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" dma_resv lock should be held in both the dma_buf and native GEM case, so let's just move the dma_resv_assert_held() check out of the !dma-buf block. Signed-off-by: Boris Brezillon Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Emil Velikov Cc: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index f406556e42e0..2b8a32f6b656 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -288,6 +288,8 @@ int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, struct drm_gem_object *obj = &shmem->base; int ret = 0; + dma_resv_assert_held(shmem->base.resv); + if (obj->import_attach) { ret = dma_buf_vmap(obj->import_attach->dmabuf, map); if (!ret) { @@ -299,8 +301,6 @@ int drm_gem_shmem_vmap(struct drm_gem_shmem_object *shmem, } else { pgprot_t prot = PAGE_KERNEL; - dma_resv_assert_held(shmem->base.resv); - if (shmem->vmap_use_count++ > 0) { iosys_map_set_vaddr(map, shmem->vaddr); return 0; @@ -354,11 +354,11 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem, { struct drm_gem_object *obj = &shmem->base; + dma_resv_assert_held(shmem->base.resv); + if (obj->import_attach) { dma_buf_vunmap(obj->import_attach->dmabuf, map); } else { - dma_resv_assert_held(shmem->base.resv); - if (drm_WARN_ON_ONCE(obj->dev, !shmem->vmap_use_count)) return; From patchwork Mon Jun 26 12:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 13292793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1F91DEB64DA for ; Mon, 26 Jun 2023 12:03:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 526D210E1EC; Mon, 26 Jun 2023 12:03:08 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id D87B710E1E8 for ; Mon, 26 Jun 2023 12:02:57 +0000 (UTC) Received: from localhost.localdomain (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (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: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 812866607154; Mon, 26 Jun 2023 13:02:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687780975; bh=FtIPjBHK+0db5j7gIdEtN2CKYsvW4d1S38hd5oN/+Es=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LyKEljStQ4ZOrmmMmq2zHPmH8G88kXu0jZu9kWISCXbryLsVk3ctb+It5zAB5qPt+ Mm8X7gcd0MqfvERbwGVPDDTdYl0ZO5/5yhcTQSe05Ho84CHJPnDJUoN3P0ktxoRgfA yAAPN+bmO1W1IGyxzhN+7ULi5vV4dLKZSOFZKRsQWrg2xEXoBkFLMaWSEItOWEYwXe Bjo6XnlnPqlRkYcGPLLVVmapq+QudL792DOL2322LJVBpWCFPyGNf+s9iCn/lVZv7y g8q5U1zbNtxm5w+ib/E4cOULJoRH8HEhqTq1jnb91uR/zQCrC7Xj3I40YuDMYVjbfo uziZTl0gJg4jg== From: Boris Brezillon To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/shmem-helper: Clarify drm_gem_shmem_v[un]map() usage Date: Mon, 26 Jun 2023 14:02:47 +0200 Message-ID: <20230626120247.1337962-6-boris.brezillon@collabora.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626120247.1337962-1-boris.brezillon@collabora.com> References: <20230626120247.1337962-1-boris.brezillon@collabora.com> 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: Dmitry Osipenko , Boris Brezillon , Emil Velikov , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Drivers are not supposed to call these functions directly when they want to map/unamp a GEM in kernel space. They should instead go through drm_gem_v[un]map[_unlocked]() that will forward the request to drm_gem_object_funcs::v[un]map() which in turn will call drm_gem_shmem_v[un]map(). Let's clarify that in the functions doc. Signed-off-by: Boris Brezillon Cc: Daniel Vetter Cc: Thomas Zimmermann Cc: Emil Velikov Cc: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 2b8a32f6b656..daada172fe70 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -279,6 +279,11 @@ EXPORT_SYMBOL(drm_gem_shmem_unpin); * * Acquired mappings should be cleaned up by calling drm_gem_shmem_vunmap(). * + * This function is not meant to be used directly, but rather used as a helper + * to implement driver-specific versions of drm_gem_object_funcs::vmap(). If + * you need to vmap() a GEM object from your driver, use + * drm_gem_vmap[_unlocked]() instead. + * * Returns: * 0 on success or a negative error code on failure. */ @@ -348,6 +353,11 @@ EXPORT_SYMBOL(drm_gem_shmem_vmap); * * This function hides the differences between dma-buf imported and natively * allocated objects. + * + * This function is not meant to be used directly, but rather used as a helper + * to implement driver-specific versions of drm_gem_object_funcs::vunmap(). If + * you need to vunmap() a GEM object from your driver, use + * drm_gem_vunmap[_unlocked]() instead. */ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem, struct iosys_map *map)