drm: Support short-term vmap via vmap_local
Subsystems (12)
Thomas Zimmermann
maintainerv3 cover drm: Support short-term vmap via vmap_local
(was: drm/vram-helper: Lock GEM BOs while they are mapped)
GEM VRAM helpers used to pin the BO in their implementation of vmap, so that they could not be relocated. In recent discussions, [1][2] it became clear that this is incorrect for in-kernel use cases, such as fbdev emulation; which should rather depend on the reservation lock to prevent relocation.
This patchset addresses the issue by introducing the new interfaces vmap_local and vunmap_local throughout dma-buf and GEM. It further adds support to DRM's CMA, SHMEM and VRAM helpers and finally converts fbdev emulation to the new interface.
Patches 1 and 2 prepare the ast cursor code for the later changes.
Patches 3 and 4 add the vmap_local infrastructure throughout dma-buf, GEM and PRIME.
Patches 5 to 7 add implementations of vmap_local to DRM's various GEM helper libraries. Due to the simple nature of these libraries, existing vmap code can be reused easily. Several drivers are updateed as well to use the new interfaces.
Patch 8 converts generic fbdev emulation to use vmap_local. Only DRM drivers that use GEM helpers currently use fbdev emulation, so patches 5 to 7 covered all necessary instances.
I smoke-tested the patchset with ast (VRAM helpers), mgag200 (SHMEM) and vc4 (CMA). I also tested with a version of radeon (raw TTM) that has been converted to generic fbdev emulation.
v3:
* rewrite patchset around vmap_local
v2:
* make importers acquire resv locks by themselves
* document dma-buf vamp/vunmap ops
[1] https://patchwork.freedesktop.org/patch/400054/?series=83765&rev=1
[2] https://patchwork.freedesktop.org/patch/405407/?series=84401&rev=2
Thomas Zimmermann (8):
drm/ast: Don't pin cursor source BO explicitly during update drm/ast: Only map cursor BOs during updates
dma-buf: Add vmap_local and vnumap_local operations drm/gem: Create infrastructure for GEM vmap_local drm/cma-helper: Provide a vmap function for short-term mappings drm/shmem-helper: Provide a vmap function for short-term mappings drm/vram-helper: Provide a vmap function for short-term mappings drm/fb-helper: Move BO locking from DRM client to fbdev damage worker
drivers/dma-buf/dma-buf.c | 80 ++++++++++++++ drivers/gpu/drm/ast/ast_cursor.c | 70 +++++++----- drivers/gpu/drm/ast/ast_drv.h | 2 - drivers/gpu/drm/drm_client.c | 91 ++++++++++++++++ drivers/gpu/drm/drm_fb_helper.c | 41 +++---- drivers/gpu/drm/drm_gem.c | 28 +++++ drivers/gpu/drm/drm_gem_cma_helper.c | 35 ++++++ drivers/gpu/drm/drm_gem_shmem_helper.c | 71 ++++++++++++- drivers/gpu/drm/drm_gem_vram_helper.c | 142 ++++++++++++++++--------- drivers/gpu/drm/drm_internal.h | 2 + drivers/gpu/drm/drm_prime.c | 39 +++++++ drivers/gpu/drm/mgag200/mgag200_mode.c | 16 ++- drivers/gpu/drm/tiny/cirrus.c | 10 +- drivers/gpu/drm/tiny/gm12u320.c | 14 ++- drivers/gpu/drm/udl/udl_modeset.c | 18 ++-- drivers/gpu/drm/vboxvideo/vbox_mode.c | 15 +-- drivers/gpu/drm/vc4/vc4_bo.c | 13 +++ drivers/gpu/drm/vc4/vc4_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_prime.c | 2 + include/drm/drm_client.h | 4 + include/drm/drm_gem.h | 20 ++++ include/drm/drm_gem_cma_helper.h | 1 + include/drm/drm_gem_shmem_helper.h | 2 + include/drm/drm_gem_vram_helper.h | 2 + include/drm/drm_prime.h | 2 + include/linux/dma-buf.h | 34 ++++++ 26 files changed, 635 insertions(+), 120 deletions(-)
--
2.29.2
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 1/8 drm/ast: Don't pin cursor source BO explicitly during update
Vmapping the cursor source BO contains an implicit pin operation, so there's no need to do this manually.
--- drivers/gpu/drm/ast/ast_cursor.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +1 -9
@@ -180,12 +180,9 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb) gbo =drm_gem_vram_of_gem (fb->obj[0 ]); - ret =drm_gem_vram_pin (gbo,0 ); -if (ret) -return ret; ret =drm_gem_vram_vmap (gbo, &map);if (ret) - goto err_drm_gem_vram_unpin; +return ret; src = map.vaddr;/* TODO: Use mapping abstraction properly */ dst = ast->cursor.map[ast->cursor.next_index].vaddr_iomem;
@@ -194,13 +191,8 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb)update_cursor_image (dst, src, fb->width, fb->height);drm_gem_vram_vunmap (gbo, &map); -drm_gem_vram_unpin (gbo);return 0 ; - -err_drm_gem_vram_unpin: -drm_gem_vram_unpin (gbo); -return ret; }static void ast_cursor_set_base (struct ast_private *ast,u64 address)
Signature · 6 lines
2.29.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 1/8] drm/ast: Don't pin cursor source BO explicitly during update
Quoted 4 lines · Thomas Zimmermann
Vmapping the cursor source BO contains an implicit pin operation, so there's no need to do this manually.
Signed-off-by Thomas Zimmermann <[email protected]>
Quoted 39 lines
--- drivers/gpu/drm/ast/ast_cursor.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +1
-9@@ -180,12 +180,9 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb) gbo =drm_gem_vram_of_gem (fb->obj[0 ]); - ret =drm_gem_vram_pin (gbo,0 ); -if (ret) -return ret; ret =drm_gem_vram_vmap (gbo, &map);if (ret) - goto err_drm_gem_vram_unpin; +return ret; src = map.vaddr;/* TODO: Use mapping abstraction properly */ dst = ast->cursor.map[ast->cursor.next_index].vaddr_iomem;@@ -194,13 +191,8 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb)update_cursor_image (dst, src, fb->width, fb->height);drm_gem_vram_vunmap (gbo, &map); -drm_gem_vram_unpin (gbo);return 0 ; - -err_drm_gem_vram_unpin: -drm_gem_vram_unpin (gbo); -return ret; }static void ast_cursor_set_base (struct ast_private *ast,u64 address)Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 2/8 drm/ast: Only map cursor BOs during updates
In reply to Thomas ZimmermannThe HW cursor's BO used to be mapped permanently into the kernel's address space. GEM's vmap operation will be protected by locks, and we don't want to lock the BO's for an indefinate period of time.
Change the cursor code to map the HW BOs only during updates. The vmap operation in VRAM helpers is cheap, as a once estabished mapping is being reused until the BO actually moves. As the HW cursor BOs are permanently pinned, they never move at all.
v2:
* fix typos in commit description
--- drivers/gpu/drm/ast/ast_cursor.c | 51 ++++++++++++++++++-------------- drivers/gpu/drm/ast/ast_drv.h | 2 -- 2 files changed, 28 insertions(+), 25 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +28 -23
@@ -39,7 +39,6 @@ static void ast_cursor_fini(struct ast_private *ast)for (i =0 ; i <ARRAY_SIZE (ast->cursor.gbo); ++i) { gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }
@@ -53,14 +52,13 @@ static void ast_cursor_release(struct drm_device *dev, void *ptr) }/* -* Allocate cursor BOs and pins them at the end of VRAM. +* Allocate cursor BOs and pin them at the end of VRAM. */ int ast_cursor_init (struct ast_private *ast) {struct drm_device *dev = &ast->base;size_t size, i;struct drm_gem_vram_object *gbo; -struct dma_buf_map map;int ret; size =roundup (AST_HWC_SIZE +AST_HWC_SIGNATURE_SIZE ,PAGE_SIZE );
@@ -77,15 +75,7 @@ int ast_cursor_init(struct ast_private *ast)drm_gem_vram_put (gbo); goto err_drm_gem_vram_put; } - ret =drm_gem_vram_vmap (gbo, &map); -if (ret) { -drm_gem_vram_unpin (gbo); -drm_gem_vram_put (gbo); - goto err_drm_gem_vram_put; - } - ast->cursor.gbo[i] = gbo; - ast->cursor.map[i] = map; }return drmm_add_action_or_reset (dev, ast_cursor_release,NULL );
@@ -94,7 +84,6 @@ int ast_cursor_init(struct ast_private *ast)while (i) { --i; gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }
@@ -168,31 +157,38 @@ static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int hint ast_cursor_blit (struct ast_private *ast,struct drm_framebuffer *fb) {struct drm_device *dev = &ast->base; -struct drm_gem_vram_object *gbo; -struct dma_buf_map map; -int ret; -void *src; +struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct drm_gem_vram_object *src_gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct dma_buf_map src_map, dst_map;void __iomem *dst; +void *src; +int ret;if (drm_WARN_ON_ONCE (dev, fb->width >AST_MAX_HWC_WIDTH ) ||drm_WARN_ON_ONCE (dev, fb->height >AST_MAX_HWC_HEIGHT ))return -EINVAL ; - gbo =drm_gem_vram_of_gem (fb->obj[0 ]); - - ret =drm_gem_vram_vmap (gbo, &map); + ret =drm_gem_vram_vmap (src_gbo, &src_map);if (ret)return ret; - src = map.vaddr;/* TODO: Use mapping abstraction properly */ + src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ - dst = ast->cursor.map[ast->cursor.next_index].vaddr_iomem; + ret =drm_gem_vram_vmap (dst_gbo, &dst_map); +if (ret) + goto err_drm_gem_vram_vunmap; + dst = dst_map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ /* do data transfer to cursor BO */ update_cursor_image (dst, src, fb->width, fb->height); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap (dst_gbo, &dst_map); +drm_gem_vram_vunmap (src_gbo, &src_map);return 0 ; + +err_drm_gem_vram_vunmap: +drm_gem_vram_vunmap (src_gbo, &src_map); +return ret; }static void ast_cursor_set_base (struct ast_private *ast,u64 address)
@@ -243,17 +239,26 @@ static void ast_cursor_set_location(struct ast_private *ast, u16 x, u16 y,void ast_cursor_show (struct ast_private *ast,int x,int y,unsigned int offset_x,unsigned int offset_y) { +struct drm_device *dev = &ast->base; +struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct dma_buf_map map;u8 x_offset, y_offset;u8 __iomem *dst;u8 __iomem *sig;u8 jreg; +int ret; - dst = ast->cursor.map[ast->cursor.next_index].vaddr; + ret =drm_gem_vram_vmap (gbo, &map); +if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap() failed, ret=%d\n" , ret)) +return ; + dst = map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ sig = dst +AST_HWC_SIZE ;writel (x, sig +AST_HWC_SIGNATURE_X );writel (y, sig +AST_HWC_SIGNATURE_Y ); +drm_gem_vram_vunmap (gbo, &map); +if (x <0 ) { x_offset = (-x) + offset_x; x =0 ;
drivers/gpu/drm/ast/ast_drv.h +0 -2
@@ -28,7 +28,6 @@#ifndef __AST_DRV_H__#define __AST_DRV_H__ -#include <linux/dma-buf-map.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> #include <linux/io.h>
@@ -133,7 +132,6 @@ struct ast_private {struct {struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM ]; -struct dma_buf_map map[AST_DEFAULT_HWC_NUM ];unsigned int next_index; } cursor;
Signature · 6 lines
2.29.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v3 2/8] drm/ast: Only map cursor BOs during updates
Quoted 9 lines · Thomas Zimmermann
The HW cursor's BO used to be mapped permanently into the kernel's address space. GEM's vmap operation will be protected by locks, and we don't want to lock the BO's for an indefinate period of time.
Change the cursor code to map the HW BOs only during updates. The vmap operation in VRAM helpers is cheap, as a once estabished mapping is being reused until the BO actually moves. As the HW cursor BOs are permanently pinned, they never move at all.
Quoted 5 lines
v2:
* fix typos in commit descriptionSigned-off-by Thomas Zimmermann <[email protected]>Acked-by Christian König <[email protected]>
Now there's a pretty big issue here though: We can't take dma_resv_lock in commit_tail, because of possible deadlocks on at least gpus that do real async rendering because of the dma_fences. Unfortunately my annotations patches got stuck a bit, I need to refresh them.
Rules are you can pin and unpin stuff in prepare/cleanup_plane, and also take dma_resv_lock there, but not in commit_tail in-between. So I think our vmap_local needs to loose the unconditional assert_locked and require either that or a pin count.
-Daniel
Quoted 157 lines
--- drivers/gpu/drm/ast/ast_cursor.c | 51 ++++++++++++++++++-------------- drivers/gpu/drm/ast/ast_drv.h | 2 -- 2 files changed, 28 insertions(+), 25 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +28
-23@@ -39,7 +39,6 @@ static void ast_cursor_fini(struct ast_private *ast)for (i =0 ; i <ARRAY_SIZE (ast->cursor.gbo); ++i) { gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }@@ -53,14 +52,13 @@ static void ast_cursor_release(struct drm_device *dev, void *ptr) }/* -* Allocate cursor BOs and pins them at the end of VRAM. +* Allocate cursor BOs and pin them at the end of VRAM. */ int ast_cursor_init (struct ast_private *ast) {struct drm_device *dev = &ast->base;size_t size, i;struct drm_gem_vram_object *gbo; -struct dma_buf_map map;int ret; size =roundup (AST_HWC_SIZE +AST_HWC_SIGNATURE_SIZE ,PAGE_SIZE );@@ -77,15 +75,7 @@ int ast_cursor_init(struct ast_private *ast)drm_gem_vram_put (gbo); goto err_drm_gem_vram_put; } - ret =drm_gem_vram_vmap (gbo, &map); -if (ret) { -drm_gem_vram_unpin (gbo); -drm_gem_vram_put (gbo); - goto err_drm_gem_vram_put; - } - ast->cursor.gbo[i] = gbo; - ast->cursor.map[i] = map; }return drmm_add_action_or_reset (dev, ast_cursor_release,NULL );@@ -94,7 +84,6 @@ int ast_cursor_init(struct ast_private *ast)while (i) { --i; gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }@@ -168,31 +157,38 @@ static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int hint ast_cursor_blit (struct ast_private *ast,struct drm_framebuffer *fb) {struct drm_device *dev = &ast->base; -struct drm_gem_vram_object *gbo; -struct dma_buf_map map; -int ret; -void *src; +struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct drm_gem_vram_object *src_gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct dma_buf_map src_map, dst_map;void __iomem *dst; +void *src; +int ret;if (drm_WARN_ON_ONCE (dev, fb->width >AST_MAX_HWC_WIDTH ) ||drm_WARN_ON_ONCE (dev, fb->height >AST_MAX_HWC_HEIGHT ))return -EINVAL ; - gbo =drm_gem_vram_of_gem (fb->obj[0 ]); - - ret =drm_gem_vram_vmap (gbo, &map); + ret =drm_gem_vram_vmap (src_gbo, &src_map);if (ret)return ret; - src = map.vaddr;/* TODO: Use mapping abstraction properly */ + src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ - dst = ast->cursor.map[ast->cursor.next_index].vaddr_iomem; + ret =drm_gem_vram_vmap (dst_gbo, &dst_map); +if (ret) + goto err_drm_gem_vram_vunmap; + dst = dst_map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ /* do data transfer to cursor BO */ update_cursor_image (dst, src, fb->width, fb->height); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap (dst_gbo, &dst_map); +drm_gem_vram_vunmap (src_gbo, &src_map);return 0 ; + +err_drm_gem_vram_vunmap: +drm_gem_vram_vunmap (src_gbo, &src_map); +return ret; }static void ast_cursor_set_base (struct ast_private *ast,u64 address)@@ -243,17 +239,26 @@ static void ast_cursor_set_location(struct ast_private *ast, u16 x, u16 y,void ast_cursor_show (struct ast_private *ast,int x,int y,unsigned int offset_x,unsigned int offset_y) { +struct drm_device *dev = &ast->base; +struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct dma_buf_map map;u8 x_offset, y_offset;u8 __iomem *dst;u8 __iomem *sig;u8 jreg; +int ret; - dst = ast->cursor.map[ast->cursor.next_index].vaddr; + ret =drm_gem_vram_vmap (gbo, &map); +if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap() failed, ret=%d\n" , ret)) +return ; + dst = map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ sig = dst +AST_HWC_SIZE ;writel (x, sig +AST_HWC_SIGNATURE_X );writel (y, sig +AST_HWC_SIGNATURE_Y ); +drm_gem_vram_vunmap (gbo, &map); +if (x <0 ) { x_offset = (-x) + offset_x; x =0 ;drivers/gpu/drm/ast/ast_drv.h +0
-2@@ -28,7 +28,6 @@#ifndef __AST_DRV_H__#define __AST_DRV_H__ -#include <linux/dma-buf-map.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> #include <linux/io.h> @@ -133,7 +132,6 @@ struct ast_private {struct {struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM ]; -struct dma_buf_map map[AST_DEFAULT_HWC_NUM ];unsigned int next_index; } cursor;Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v3 2/8] drm/ast: Only map cursor BOs during updates
Am 11.12.20 um 11:18 schrieb Daniel Vetter:
Quoted 23 lines · Thomas Zimmermann
Quoted 9 lines
The HW cursor's BO used to be mapped permanently into the kernel's address space. GEM's vmap operation will be protected by locks, and we don't want to lock the BO's for an indefinate period of time.
Change the cursor code to map the HW BOs only during updates. The vmap operation in VRAM helpers is cheap, as a once estabished mapping is being reused until the BO actually moves. As the HW cursor BOs are permanently pinned, they never move at all.
Quoted 5 lines
v2:
* fix typos in commit descriptionSigned-off-by Thomas Zimmermann <[email protected]>Acked-by Christian König <[email protected]>Acked-by Daniel Vetter <[email protected]>Now there's a pretty big issue here though: We can't take
dma_resv_lockincommit_tail, because of possible deadlocks on at least gpus that do real async rendering because of thedma_fences. Unfortunately my annotations patches got stuck a bit, I need to refresh them.
Quoted 4 lines
Rules are you can pin and unpin stuff in prepare/cleanup_plane, and also take
dma_resv_lockthere, but not incommit_tailin-between. So I think ourvmap_localneeds to loose the unconditionalassert_lockedand require either that or a pin count.
I guess my commit description is misleading when it speaks of updates. ast_cursor_blit() is actually called from the cursor plane's prepare_fb function. [1] The vmap code in ast_cursor_show() could be moved into blit() as well, I think.
I guess the clean solution is to integrate the cursor code with the modesetting code in ast_mode. From there, locks and mappings can be established in prepare_fb and the HW state can be updated in atomic_commit.
Best regards
Thomas
Quoted 160 lines
-Daniel
Quoted 157 lines
--- drivers/gpu/drm/ast/ast_cursor.c | 51 ++++++++++++++++++-------------- drivers/gpu/drm/ast/ast_drv.h | 2 -- 2 files changed, 28 insertions(+), 25 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +28
-23@@ -39,7 +39,6 @@ static void ast_cursor_fini(struct ast_private *ast)for (i =0 ; i <ARRAY_SIZE (ast->cursor.gbo); ++i) { gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }@@ -53,14 +52,13 @@ static void ast_cursor_release(struct drm_device *dev, void *ptr) }/* -* Allocate cursor BOs and pins them at the end of VRAM. +* Allocate cursor BOs and pin them at the end of VRAM. */ int ast_cursor_init (struct ast_private *ast) {struct drm_device *dev = &ast->base;size_t size, i;struct drm_gem_vram_object *gbo; -struct dma_buf_map map;int ret; size =roundup (AST_HWC_SIZE +AST_HWC_SIGNATURE_SIZE ,PAGE_SIZE );@@ -77,15 +75,7 @@ int ast_cursor_init(struct ast_private *ast)drm_gem_vram_put (gbo); goto err_drm_gem_vram_put; } - ret =drm_gem_vram_vmap (gbo, &map); -if (ret) { -drm_gem_vram_unpin (gbo); -drm_gem_vram_put (gbo); - goto err_drm_gem_vram_put; - } - ast->cursor.gbo[i] = gbo; - ast->cursor.map[i] = map; }return drmm_add_action_or_reset (dev, ast_cursor_release,NULL );@@ -94,7 +84,6 @@ int ast_cursor_init(struct ast_private *ast)while (i) { --i; gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }@@ -168,31 +157,38 @@ static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int hint ast_cursor_blit (struct ast_private *ast,struct drm_framebuffer *fb) {struct drm_device *dev = &ast->base; -struct drm_gem_vram_object *gbo; -struct dma_buf_map map; -int ret; -void *src; +struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct drm_gem_vram_object *src_gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct dma_buf_map src_map, dst_map;void __iomem *dst; +void *src; +int ret;if (drm_WARN_ON_ONCE (dev, fb->width >AST_MAX_HWC_WIDTH ) ||drm_WARN_ON_ONCE (dev, fb->height >AST_MAX_HWC_HEIGHT ))return -EINVAL ; - gbo =drm_gem_vram_of_gem (fb->obj[0 ]); - - ret =drm_gem_vram_vmap (gbo, &map); + ret =drm_gem_vram_vmap (src_gbo, &src_map);if (ret)return ret; - src = map.vaddr;/* TODO: Use mapping abstraction properly */ + src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ - dst = ast->cursor.map[ast->cursor.next_index].vaddr_iomem; + ret =drm_gem_vram_vmap (dst_gbo, &dst_map); +if (ret) + goto err_drm_gem_vram_vunmap; + dst = dst_map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ /* do data transfer to cursor BO */ update_cursor_image (dst, src, fb->width, fb->height); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap (dst_gbo, &dst_map); +drm_gem_vram_vunmap (src_gbo, &src_map);return 0 ; + +err_drm_gem_vram_vunmap: +drm_gem_vram_vunmap (src_gbo, &src_map); +return ret; }static void ast_cursor_set_base (struct ast_private *ast,u64 address)@@ -243,17 +239,26 @@ static void ast_cursor_set_location(struct ast_private *ast, u16 x, u16 y,void ast_cursor_show (struct ast_private *ast,int x,int y,unsigned int offset_x,unsigned int offset_y) { +struct drm_device *dev = &ast->base; +struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct dma_buf_map map;u8 x_offset, y_offset;u8 __iomem *dst;u8 __iomem *sig;u8 jreg; +int ret; - dst = ast->cursor.map[ast->cursor.next_index].vaddr; + ret =drm_gem_vram_vmap (gbo, &map); +if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap() failed, ret=%d\n" , ret)) +return ; + dst = map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ sig = dst +AST_HWC_SIZE ;writel (x, sig +AST_HWC_SIGNATURE_X );writel (y, sig +AST_HWC_SIGNATURE_Y ); +drm_gem_vram_vunmap (gbo, &map); +if (x <0 ) { x_offset = (-x) + offset_x; x =0 ;drivers/gpu/drm/ast/ast_drv.h +0
-2@@ -28,7 +28,6 @@#ifndef __AST_DRV_H__#define __AST_DRV_H__ -#include <linux/dma-buf-map.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> #include <linux/io.h> @@ -133,7 +132,6 @@ struct ast_private {struct {struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM ]; -struct dma_buf_map map[AST_DEFAULT_HWC_NUM ];unsigned int next_index; } cursor;Signature · 1 line
2.29.2
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 2/8] drm/ast: Only map cursor BOs during updates
Quoted 31 lines · Thomas Zimmermann
Am 11.12.20 um 11:18 schrieb Daniel Vetter:
Quoted 23 lines · Thomas Zimmermann
Quoted 9 lines
The HW cursor's BO used to be mapped permanently into the kernel's address space. GEM's vmap operation will be protected by locks, and we don't want to lock the BO's for an indefinate period of time.
Change the cursor code to map the HW BOs only during updates. The vmap operation in VRAM helpers is cheap, as a once estabished mapping is being reused until the BO actually moves. As the HW cursor BOs are permanently pinned, they never move at all.
Quoted 5 lines
v2:
* fix typos in commit descriptionSigned-off-by Thomas Zimmermann <[email protected]>Acked-by Christian König <[email protected]>Acked-by Daniel Vetter <[email protected]>Now there's a pretty big issue here though: We can't take
dma_resv_lockincommit_tail, because of possible deadlocks on at least gpus that do real async rendering because of thedma_fences. Unfortunately my annotations patches got stuck a bit, I need to refresh them.Quoted 4 lines
Rules are you can pin and unpin stuff in prepare/cleanup_plane, and also take
dma_resv_lockthere, but not incommit_tailin-between. So I think ourvmap_localneeds to loose the unconditionalassert_lockedand require either that or a pin count.
Quoted 4 lines
I guess my commit description is misleading when it speaks of updates.
ast_cursor_blit()is actually called from the cursor plane'sprepare_fbfunction. [1] The vmap code inast_cursor_show()could be moved intoblit()as well, I think.
Oh I failed to check this properly. Even better.
Quoted 3 lines
I guess the clean solution is to integrate the cursor code with the modesetting code in
ast_mode. From there, locks and mappings can be established inprepare_fband the HW state can be updated inatomic_commit.
Yup. I'll still refresh my series with lockdep annotations, keeps paranoid me at peace :-)
-Daniel
Quoted 158 lines
Best regards
ThomasQuoted 143 lines
-Daniel
Quoted 140 lines
--- drivers/gpu/drm/ast/ast_cursor.c | 51 ++++++++++++++++++-------------- drivers/gpu/drm/ast/ast_drv.h | 2 -- 2 files changed, 28 insertions(+), 25 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +28
-23@@ -39,7 +39,6 @@ static void ast_cursor_fini(struct ast_private *ast)for (i =0 ; i <ARRAY_SIZE (ast->cursor.gbo); ++i) { gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }@@ -53,14 +52,13 @@ static void ast_cursor_release(struct drm_device *dev, void *ptr) }/* -* Allocate cursor BOs and pins them at the end of VRAM. +* Allocate cursor BOs and pin them at the end of VRAM. */ int ast_cursor_init (struct ast_private *ast) {struct drm_device *dev = &ast->base;size_t size, i;struct drm_gem_vram_object *gbo; -struct dma_buf_map map;int ret; size =roundup (AST_HWC_SIZE +AST_HWC_SIGNATURE_SIZE ,PAGE_SIZE );@@ -77,15 +75,7 @@ int ast_cursor_init(struct ast_private *ast)drm_gem_vram_put (gbo); goto err_drm_gem_vram_put; } - ret =drm_gem_vram_vmap (gbo, &map); -if (ret) { -drm_gem_vram_unpin (gbo); -drm_gem_vram_put (gbo); - goto err_drm_gem_vram_put; - } - ast->cursor.gbo[i] = gbo; - ast->cursor.map[i] = map; }return drmm_add_action_or_reset (dev, ast_cursor_release,NULL );@@ -94,7 +84,6 @@ int ast_cursor_init(struct ast_private *ast)while (i) { --i; gbo = ast->cursor.gbo[i]; -drm_gem_vram_vunmap (gbo, &ast->cursor.map[i]);drm_gem_vram_unpin (gbo);drm_gem_vram_put (gbo); }@@ -168,31 +157,38 @@ static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int hint ast_cursor_blit (struct ast_private *ast,struct drm_framebuffer *fb) {struct drm_device *dev = &ast->base; -struct drm_gem_vram_object *gbo; -struct dma_buf_map map; -int ret; -void *src; +struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct drm_gem_vram_object *src_gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct dma_buf_map src_map, dst_map;void __iomem *dst; +void *src; +int ret;if (drm_WARN_ON_ONCE (dev, fb->width >AST_MAX_HWC_WIDTH ) ||drm_WARN_ON_ONCE (dev, fb->height >AST_MAX_HWC_HEIGHT ))return -EINVAL ; - gbo =drm_gem_vram_of_gem (fb->obj[0 ]); - - ret =drm_gem_vram_vmap (gbo, &map); + ret =drm_gem_vram_vmap (src_gbo, &src_map);if (ret)return ret; - src = map.vaddr;/* TODO: Use mapping abstraction properly */ + src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ - dst = ast->cursor.map[ast->cursor.next_index].vaddr_iomem; + ret =drm_gem_vram_vmap (dst_gbo, &dst_map); +if (ret) + goto err_drm_gem_vram_vunmap; + dst = dst_map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ /* do data transfer to cursor BO */ update_cursor_image (dst, src, fb->width, fb->height); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap (dst_gbo, &dst_map); +drm_gem_vram_vunmap (src_gbo, &src_map);return 0 ; + +err_drm_gem_vram_vunmap: +drm_gem_vram_vunmap (src_gbo, &src_map); +return ret; }static void ast_cursor_set_base (struct ast_private *ast,u64 address)@@ -243,17 +239,26 @@ static void ast_cursor_set_location(struct ast_private *ast, u16 x, u16 y,void ast_cursor_show (struct ast_private *ast,int x,int y,unsigned int offset_x,unsigned int offset_y) { +struct drm_device *dev = &ast->base; +struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct dma_buf_map map;u8 x_offset, y_offset;u8 __iomem *dst;u8 __iomem *sig;u8 jreg; +int ret; - dst = ast->cursor.map[ast->cursor.next_index].vaddr; + ret =drm_gem_vram_vmap (gbo, &map); +if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap() failed, ret=%d\n" , ret)) +return ; + dst = map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ sig = dst +AST_HWC_SIZE ;writel (x, sig +AST_HWC_SIGNATURE_X );writel (y, sig +AST_HWC_SIGNATURE_Y ); +drm_gem_vram_vunmap (gbo, &map); +if (x <0 ) { x_offset = (-x) + offset_x; x =0 ;drivers/gpu/drm/ast/ast_drv.h +0
-2@@ -28,7 +28,6 @@#ifndef __AST_DRV_H__#define __AST_DRV_H__ -#include <linux/dma-buf-map.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> #include <linux/io.h> @@ -133,7 +132,6 @@ struct ast_private {struct {struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM ]; -struct dma_buf_map map[AST_DEFAULT_HWC_NUM ];unsigned int next_index; } cursor;Signature · 1 line
2.29.2Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 3/8 dma-buf: Add vmap_local and vnumap_local operations
In reply to Thomas ZimmermannThe existing dma-buf calls dma_buf_vmap() and dma_buf_vunmap() are allowed to pin the buffer or acquire the buffer's reservation object lock.
This is a problem for callers that only require a short-term mapping of the buffer without the pinning, or callers that have special locking requirements. These may suffer from unnecessary overhead or interfere with regular pin operations.
The new interfaces dma_buf_vmap_local(), dma_buf_vunmapo_local(), and their rsp callbacks in struct dma_buf_ops provide an alternative without pinning or reservation locking. Callers are responsible for these operations.
--- drivers/dma-buf/dma-buf.c | 80 +++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 34 +++++++++++++++++ 2 files changed, 114 insertions(+)
drivers/dma-buf/dma-buf.c +80 -0
@@ -1265,6 +1265,86 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (dma_buf_vunmap); +/** +* dma_buf_vmap_local - Create virtual mapping for the buffer object into kernel +* address space. +* @dmabuf: [in] buffer to vmap +* @map: [out] returns the vmap pointer +* +* This call may fail due to lack of virtual mapping address space. +* These calls are optional in drivers. The intended use for them +* is for mapping objects linear in kernel space for high use objects. +* Please attempt to use kmap/kunmap before thinking about these interfaces. +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +struct dma_buf_map ptr; +int ret =0 ; + +dma_buf_map_clear (map); + +if (WARN_ON (!dmabuf)) +return -EINVAL ; + +dma_resv_assert_held (dmabuf->resv); + +if (!dmabuf->ops->vmap_local) +return -EINVAL ; + +mutex_lock (&dmabuf->lock); +if (dmabuf->vmapping_counter) { + dmabuf->vmapping_counter++; +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); + *map = dmabuf->vmap_ptr; + goto out_unlock; + } + +BUG_ON (dma_buf_map_is_set (&dmabuf->vmap_ptr)); + + ret = dmabuf->ops->vmap_local (dmabuf, &ptr); +if (WARN_ON_ONCE (ret)) + goto out_unlock; + + dmabuf->vmap_ptr = ptr; + dmabuf->vmapping_counter =1 ; + + *map = dmabuf->vmap_ptr; + +out_unlock: +mutex_unlock (&dmabuf->lock); +return ret; +} +EXPORT_SYMBOL_GPL (dma_buf_vmap_local); + +/** +* dma_buf_vunmap_local - Unmap a vmap obtained by dma_buf_vmap_local. +* @dmabuf: [in] buffer to vunmap +* @map: [in] vmap pointer to vunmap +*/ +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +if (WARN_ON (!dmabuf)) +return ; + +dma_resv_assert_held (dmabuf->resv); + +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); +BUG_ON (dmabuf->vmapping_counter ==0 ); +BUG_ON (!dma_buf_map_is_equal (&dmabuf->vmap_ptr, map)); + +mutex_lock (&dmabuf->lock); +if (--dmabuf->vmapping_counter ==0 ) { +if (dmabuf->ops->vunmap_local) + dmabuf->ops->vunmap_local (dmabuf, map); +dma_buf_map_clear (&dmabuf->vmap_ptr); + } +mutex_unlock (&dmabuf->lock); +} +EXPORT_SYMBOL_GPL (dma_buf_vunmap_local); +#ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show (struct seq_file *s,void *unused) {
include/linux/dma-buf.h +34 -0
@@ -269,6 +269,38 @@ struct dma_buf_ops {int (*vmap)(struct dma_buf *dmabuf,struct dma_buf_map *map);void (*vunmap)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vmap_local: +* +* Creates a virtual mapping for the buffer into kernel address space. +* +* This callback establishes short-term mappings for situations where +* callers only use the buffer for a bounded amount of time; such as +* updates to the framebuffer or reading back contained information. +* In contrast to the regular @vmap callback, vmap_local does never pin +* the buffer to a specific domain or acquire the buffer's reservation +* lock. +* +* This is called with the dmabuf->resv object locked. Callers must hold +* the lock until after removing the mapping with @vunmap_local. +* +* This callback is optional. +* +* Returns: +* +* 0 on success or a negative error code on failure. +*/ +int (*vmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vunmap_local: +* +* Removes a virtual mapping that wa sestablished by @vmap_local. +* +* This callback is optional. +*/ +void (*vunmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); };/**
@@ -506,4 +538,6 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long);int dma_buf_vmap (struct dma_buf *dmabuf,struct dma_buf_map *map);void dma_buf_vunmap (struct dma_buf *dmabuf,struct dma_buf_map *map); +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map); +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map);#endif /* __DMA_BUF_H__ */
Signature · 6 lines
2.29.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerRe: [PATCH v3 3/8] dma-buf: Add vmap_local and vnumap_local operations
Hi
Am 09.12.20 um 15:25 schrieb Thomas Zimmermann:
Quoted 9 lines
The existing dma-buf calls
dma_buf_vmap()anddma_buf_vunmap()are allowed to pin the buffer or acquire the buffer's reservation object lock.This is a problem for callers that only require a short-term mapping of the buffer without the pinning, or callers that have special locking requirements. These may suffer from unnecessary overhead or interfere with regular pin operations.
Quoted 6 lines
The new interfaces
dma_buf_vmap_local(),dma_buf_vunmapo_local(), and their rsp callbacks in structdma_buf_opsprovide an alternative without pinning or reservation locking. Callers are responsible for these operations.Signed-off-by Thomas Zimmermann <[email protected]>
Before merging, this patch would get a Suggested-by tag to give Daniel credit. I only notices after hitting the send button.
Best regards
Thomas
Quoted 147 lines
--- drivers/dma-buf/dma-buf.c | 80 +++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 34 +++++++++++++++++ 2 files changed, 114 insertions(+)drivers/dma-buf/dma-buf.c +80
-0@@ -1265,6 +1265,86 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (dma_buf_vunmap); +/** +* dma_buf_vmap_local - Create virtual mapping for the buffer object into kernel +* address space. +* @dmabuf: [in] buffer to vmap +* @map: [out] returns the vmap pointer +* +* This call may fail due to lack of virtual mapping address space. +* These calls are optional in drivers. The intended use for them +* is for mapping objects linear in kernel space for high use objects. +* Please attempt to use kmap/kunmap before thinking about these interfaces. +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +struct dma_buf_map ptr; +int ret =0 ; + +dma_buf_map_clear (map); + +if (WARN_ON (!dmabuf)) +return -EINVAL ; + +dma_resv_assert_held (dmabuf->resv); + +if (!dmabuf->ops->vmap_local) +return -EINVAL ; + +mutex_lock (&dmabuf->lock); +if (dmabuf->vmapping_counter) { + dmabuf->vmapping_counter++; +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); + *map = dmabuf->vmap_ptr; + goto out_unlock; + } + +BUG_ON (dma_buf_map_is_set (&dmabuf->vmap_ptr)); + + ret = dmabuf->ops->vmap_local (dmabuf, &ptr); +if (WARN_ON_ONCE (ret)) + goto out_unlock; + + dmabuf->vmap_ptr = ptr; + dmabuf->vmapping_counter =1 ; + + *map = dmabuf->vmap_ptr; + +out_unlock: +mutex_unlock (&dmabuf->lock); +return ret; +} +EXPORT_SYMBOL_GPL (dma_buf_vmap_local); + +/** +* dma_buf_vunmap_local - Unmap a vmap obtained by dma_buf_vmap_local. +* @dmabuf: [in] buffer to vunmap +* @map: [in] vmap pointer to vunmap +*/ +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +if (WARN_ON (!dmabuf)) +return ; + +dma_resv_assert_held (dmabuf->resv); + +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); +BUG_ON (dmabuf->vmapping_counter ==0 ); +BUG_ON (!dma_buf_map_is_equal (&dmabuf->vmap_ptr, map)); + +mutex_lock (&dmabuf->lock); +if (--dmabuf->vmapping_counter ==0 ) { +if (dmabuf->ops->vunmap_local) + dmabuf->ops->vunmap_local (dmabuf, map); +dma_buf_map_clear (&dmabuf->vmap_ptr); + } +mutex_unlock (&dmabuf->lock); +} +EXPORT_SYMBOL_GPL (dma_buf_vunmap_local); +#ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show (struct seq_file *s,void *unused) {include/linux/dma-buf.h +34
-0@@ -269,6 +269,38 @@ struct dma_buf_ops {int (*vmap)(struct dma_buf *dmabuf,struct dma_buf_map *map);void (*vunmap)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vmap_local: +* +* Creates a virtual mapping for the buffer into kernel address space. +* +* This callback establishes short-term mappings for situations where +* callers only use the buffer for a bounded amount of time; such as +* updates to the framebuffer or reading back contained information. +* In contrast to the regular @vmap callback, vmap_local does never pin +* the buffer to a specific domain or acquire the buffer's reservation +* lock. +* +* This is called with the dmabuf->resv object locked. Callers must hold +* the lock until after removing the mapping with @vunmap_local. +* +* This callback is optional. +* +* Returns: +* +* 0 on success or a negative error code on failure. +*/ +int (*vmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vunmap_local: +* +* Removes a virtual mapping that wa sestablished by @vmap_local. +* +* This callback is optional. +*/ +void (*vunmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); };/** @@ -506,4 +538,6 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long);int dma_buf_vmap (struct dma_buf *dmabuf,struct dma_buf_map *map);void dma_buf_vunmap (struct dma_buf *dmabuf,struct dma_buf_map *map); +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map); +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map);#endif /* __DMA_BUF_H__ */
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 3/8] dma-buf: Add vmap_local and vnumap_local operations
In reply to Thomas ZimmermannQuoted 28 lines · Thomas Zimmermann
The existing dma-buf calls
dma_buf_vmap()anddma_buf_vunmap()are allowed to pin the buffer or acquire the buffer's reservation object lock.This is a problem for callers that only require a short-term mapping of the buffer without the pinning, or callers that have special locking requirements. These may suffer from unnecessary overhead or interfere with regular pin operations.
The new interfaces
dma_buf_vmap_local(),dma_buf_vunmapo_local(), and their rsp callbacks in structdma_buf_opsprovide an alternative without pinning or reservation locking. Callers are responsible for these operations.Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/dma-buf/dma-buf.c | 80 +++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 34 +++++++++++++++++ 2 files changed, 114 insertions(+)drivers/dma-buf/dma-buf.c +0
-0@@ -1265,6 +1265,86 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (dma_buf_vunmap);
drivers/dma-buf/dma-buf.c void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) · line 1277
Quoted 10 lines
drivers/dma-buf/dma-buf.c +10
-0+/** +* dma_buf_vmap_local - Create virtual mapping for the buffer object into kernel +* address space. +* @dmabuf: [in] buffer to vmap +* @map: [out] returns the vmap pointer +* +* This call may fail due to lack of virtual mapping address space. +* These calls are optional in drivers. The intended use for them +* is for mapping objects linear in kernel space for high use objects. +* Please attempt to use kmap/kunmap before thinking about these interfaces.
Kmap is gone, so the entire 2 sentences here are no longer needed. Maybe mention something like "Unlike dma_buf_vmap() this is a short term mapping and will not pin the buffer. The struct dma_resv for the @dmabuf must be locked until dma_buf_vunmap_local() is called."
Quoted 38 lines
drivers/dma-buf/dma-buf.c +38
-0+* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +struct dma_buf_map ptr; +int ret =0 ; + +dma_buf_map_clear (map); + +if (WARN_ON (!dmabuf)) +return -EINVAL ; + +dma_resv_assert_held (dmabuf->resv); + +if (!dmabuf->ops->vmap_local) +return -EINVAL ; + +mutex_lock (&dmabuf->lock); +if (dmabuf->vmapping_counter) { + dmabuf->vmapping_counter++; +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); + *map = dmabuf->vmap_ptr; + goto out_unlock; + } + +BUG_ON (dma_buf_map_is_set (&dmabuf->vmap_ptr)); + + ret = dmabuf->ops->vmap_local (dmabuf, &ptr); +if (WARN_ON_ONCE (ret)) + goto out_unlock; + + dmabuf->vmap_ptr = ptr; + dmabuf->vmapping_counter =1 ; + + *map = dmabuf->vmap_ptr; +
drivers/dma-buf/dma-buf.c void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) · line 1325
Quoted 10 lines
drivers/dma-buf/dma-buf.c +10
-0+out_unlock: +mutex_unlock (&dmabuf->lock); +return ret; +} +EXPORT_SYMBOL_GPL (dma_buf_vmap_local); + +/** +* dma_buf_vunmap_local - Unmap a vmap obtained by dma_buf_vmap_local. +* @dmabuf: [in] buffer to vunmap +* @map: [in] vmap pointer to vunmap
Maybe for hyperlinking add "Release a mapping established with dma_buf_vmap_local()."
Quoted 37 lines
drivers/dma-buf/dma-buf.c +22
-0+*/ +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +if (WARN_ON (!dmabuf)) +return ; + +dma_resv_assert_held (dmabuf->resv); + +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); +BUG_ON (dmabuf->vmapping_counter ==0 ); +BUG_ON (!dma_buf_map_is_equal (&dmabuf->vmap_ptr, map)); + +mutex_lock (&dmabuf->lock); +if (--dmabuf->vmapping_counter ==0 ) { +if (dmabuf->ops->vunmap_local) + dmabuf->ops->vunmap_local (dmabuf, map); +dma_buf_map_clear (&dmabuf->vmap_ptr); + } +mutex_unlock (&dmabuf->lock); +} +EXPORT_SYMBOL_GPL (dma_buf_vunmap_local); +#ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show (struct seq_file *s,void *unused) {include/linux/dma-buf.h +4
-0@@ -269,6 +269,38 @@ struct dma_buf_ops {int (*vmap)(struct dma_buf *dmabuf,struct dma_buf_map *map);void (*vunmap)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vmap_local: +*
include/linux/dma-buf.h struct dma_buf_ops { · line 285
Quoted 10 lines
include/linux/dma-buf.h +10
-0+* Creates a virtual mapping for the buffer into kernel address space. +* +* This callback establishes short-term mappings for situations where +* callers only use the buffer for a bounded amount of time; such as +* updates to the framebuffer or reading back contained information. +* In contrast to the regular @vmap callback, vmap_local does never pin +* the buffer to a specific domain or acquire the buffer's reservation +* lock. +* +* This is called with the dmabuf->resv object locked. Callers must hold
^^Not the right kerneldoc, I think it should be &dma_buf.resv to get the hyperlink.
Quoted 4 lines
include/linux/dma-buf.h +4
-0+* the lock until after removing the mapping with @vunmap_local. +* +* This callback is optional. +*
include/linux/dma-buf.h struct dma_buf_ops { · line 299
Quoted 10 lines
include/linux/dma-buf.h +10
-0+* Returns: +* +* 0 on success or a negative error code on failure. +*/ +int (*vmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vunmap_local: +* +* Removes a virtual mapping that wa sestablished by @vmap_local.
^^established
Quoted 8 lines
include/linux/dma-buf.h +4
-0+* +* This callback is optional. +*/ +void (*vunmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); };/**
include/linux/dma-buf.h int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, · line 543
Quoted 6 lines
include/linux/dma-buf.h +2
-0@@ -506,4 +538,6 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long);int dma_buf_vmap (struct dma_buf *dmabuf,struct dma_buf_map *map);void dma_buf_vunmap (struct dma_buf *dmabuf,struct dma_buf_map *map); +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map); +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map);#endif /* __DMA_BUF_H__ */
With the doc nits addressed:
Quoted 3 lines
Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 3/8] dma-buf: Add vmap_local and vnumap_local operations
In reply to Thomas ZimmermannQuoted 28 lines · Thomas Zimmermann
The existing dma-buf calls
dma_buf_vmap()anddma_buf_vunmap()are allowed to pin the buffer or acquire the buffer's reservation object lock.This is a problem for callers that only require a short-term mapping of the buffer without the pinning, or callers that have special locking requirements. These may suffer from unnecessary overhead or interfere with regular pin operations.
The new interfaces
dma_buf_vmap_local(),dma_buf_vunmapo_local(), and their rsp callbacks in structdma_buf_opsprovide an alternative without pinning or reservation locking. Callers are responsible for these operations.Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/dma-buf/dma-buf.c | 80 +++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 34 +++++++++++++++++ 2 files changed, 114 insertions(+)drivers/dma-buf/dma-buf.c +0
-0@@ -1265,6 +1265,86 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (dma_buf_vunmap);
drivers/dma-buf/dma-buf.c void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) · line 1277
Quoted 10 lines
drivers/dma-buf/dma-buf.c +10
-0+/** +* dma_buf_vmap_local - Create virtual mapping for the buffer object into kernel +* address space. +* @dmabuf: [in] buffer to vmap +* @map: [out] returns the vmap pointer +* +* This call may fail due to lack of virtual mapping address space. +* These calls are optional in drivers. The intended use for them +* is for mapping objects linear in kernel space for high use objects. +* Please attempt to use kmap/kunmap before thinking about these interfaces.
We also need to specify whether callers need to call dma_buf_begin/end_cpu access around these or not. For current implementations it doesn't matter, but if you want to convert udl/gm12u320, it will.
I think requiring an explicit call would be good, for more consistency with how normal vmap works.
-Daniel
Quoted 126 lines
drivers/dma-buf/dma-buf.c +70
-0+* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +struct dma_buf_map ptr; +int ret =0 ; + +dma_buf_map_clear (map); + +if (WARN_ON (!dmabuf)) +return -EINVAL ; + +dma_resv_assert_held (dmabuf->resv); + +if (!dmabuf->ops->vmap_local) +return -EINVAL ; + +mutex_lock (&dmabuf->lock); +if (dmabuf->vmapping_counter) { + dmabuf->vmapping_counter++; +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); + *map = dmabuf->vmap_ptr; + goto out_unlock; + } + +BUG_ON (dma_buf_map_is_set (&dmabuf->vmap_ptr)); + + ret = dmabuf->ops->vmap_local (dmabuf, &ptr); +if (WARN_ON_ONCE (ret)) + goto out_unlock; + + dmabuf->vmap_ptr = ptr; + dmabuf->vmapping_counter =1 ; + + *map = dmabuf->vmap_ptr; + +out_unlock: +mutex_unlock (&dmabuf->lock); +return ret; +} +EXPORT_SYMBOL_GPL (dma_buf_vmap_local); + +/** +* dma_buf_vunmap_local - Unmap a vmap obtained by dma_buf_vmap_local. +* @dmabuf: [in] buffer to vunmap +* @map: [in] vmap pointer to vunmap +*/ +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map) +{ +if (WARN_ON (!dmabuf)) +return ; + +dma_resv_assert_held (dmabuf->resv); + +BUG_ON (dma_buf_map_is_null (&dmabuf->vmap_ptr)); +BUG_ON (dmabuf->vmapping_counter ==0 ); +BUG_ON (!dma_buf_map_is_equal (&dmabuf->vmap_ptr, map)); + +mutex_lock (&dmabuf->lock); +if (--dmabuf->vmapping_counter ==0 ) { +if (dmabuf->ops->vunmap_local) + dmabuf->ops->vunmap_local (dmabuf, map); +dma_buf_map_clear (&dmabuf->vmap_ptr); + } +mutex_unlock (&dmabuf->lock); +} +EXPORT_SYMBOL_GPL (dma_buf_vunmap_local); +#ifdef CONFIG_DEBUG_FS static int dma_buf_debug_show (struct seq_file *s,void *unused) {include/linux/dma-buf.h +34
-0@@ -269,6 +269,38 @@ struct dma_buf_ops {int (*vmap)(struct dma_buf *dmabuf,struct dma_buf_map *map);void (*vunmap)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vmap_local: +* +* Creates a virtual mapping for the buffer into kernel address space. +* +* This callback establishes short-term mappings for situations where +* callers only use the buffer for a bounded amount of time; such as +* updates to the framebuffer or reading back contained information. +* In contrast to the regular @vmap callback, vmap_local does never pin +* the buffer to a specific domain or acquire the buffer's reservation +* lock. +* +* This is called with the dmabuf->resv object locked. Callers must hold +* the lock until after removing the mapping with @vunmap_local. +* +* This callback is optional. +* +* Returns: +* +* 0 on success or a negative error code on failure. +*/ +int (*vmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); + +/** +* @vunmap_local: +* +* Removes a virtual mapping that wa sestablished by @vmap_local. +* +* This callback is optional. +*/ +void (*vunmap_local)(struct dma_buf *dmabuf,struct dma_buf_map *map); };/** @@ -506,4 +538,6 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *, unsigned long);int dma_buf_vmap (struct dma_buf *dmabuf,struct dma_buf_map *map);void dma_buf_vunmap (struct dma_buf *dmabuf,struct dma_buf_map *map); +int dma_buf_vmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map); +void dma_buf_vunmap_local (struct dma_buf *dmabuf,struct dma_buf_map *map);#endif /* __DMA_BUF_H__ */ Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerPATCH v3 4/8 drm/gem: Create infrastructure for GEM vmap_local
In reply to Thomas ZimmermannThis patch adds vmap_local and vunmap_local to struct drm_gem_object_funcs; including the PRIME helpers to connect with dma-buf's related interfaces.
Besides the generic DRM core, this will become relevant for fbdev emulation with virtio, so we update it as well.
--- drivers/gpu/drm/drm_gem.c | 28 ++++++++++++++++++ drivers/gpu/drm/drm_internal.h | 2 ++ drivers/gpu/drm/drm_prime.c | 39 ++++++++++++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_prime.c | 2 ++ include/drm/drm_gem.h | 20 +++++++++++++ include/drm/drm_prime.h | 2 ++ 6 files changed, 93 insertions(+)
drivers/gpu/drm/drm_gem.c +28 -0
@@ -1234,6 +1234,34 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map)dma_buf_map_clear (map); } +int drm_gem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +int ret; + +if (!obj->funcs->vmap_local) +return -EOPNOTSUPP ; + + ret = obj->funcs->vmap_local (obj, map); +if (ret) +return ret; +else if (dma_buf_map_is_null (map)) +return -ENOMEM ; + +return 0 ; +} + +void drm_gem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +if (dma_buf_map_is_null (map)) +return ; + +if (obj->funcs->vunmap_local) + obj->funcs->vunmap_local (obj, map); + +/* Always set the mapping to NULL. Callers may rely on this. */ +dma_buf_map_clear (map); +} +/** * drm_gem_lock_reservations - Sets up the ww context and acquires * the lock on an array of GEM objects.
drivers/gpu/drm/drm_internal.h +2 -0
@@ -190,6 +190,8 @@ int drm_gem_pin(struct drm_gem_object *obj);void drm_gem_unpin (struct drm_gem_object *obj);int drm_gem_vmap (struct drm_gem_object *obj,struct dma_buf_map *map);void drm_gem_vunmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map); +void drm_gem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);/* drm_debugfs.c drm_debugfs_crc.c */ #if defined(CONFIG_DEBUG_FS )
drivers/gpu/drm/drm_prime.c +39 -0
@@ -695,6 +695,43 @@ void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_dmabuf_vunmap); +/** +* drm_gem_dmabuf_vmap_local - dma_buf vmap_local implementation for GEM +* @dma_buf: buffer to be mapped +* @map: the virtual address of the buffer +* +* Sets up a kernel virtual mapping. This can be used as the &dma_buf_ops.vmap_local +* callback. Calls into &drm_gem_object_funcs.vmap_local for device specific handling. +* The kernel virtual address is returned in map. +* +* Returns: +* 0 on success or a negative errno code otherwise. +*/ +int drm_gem_dmabuf_vmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map) +{ +struct drm_gem_object *obj = dma_buf->priv; + +return drm_gem_vmap_local (obj, map); +} +EXPORT_SYMBOL (drm_gem_dmabuf_vmap_local); + +/** +* drm_gem_dmabuf_vunmap_local - dma_buf vunmap_local implementation for GEM +* @dma_buf: buffer to be unmapped +* @map: the virtual address of the buffer +* +* Releases a kernel virtual mapping. This can be used as the +* &dma_buf_ops.vunmap_local callback. Calls into &drm_gem_object_funcs.vunmap_local +* for device specific handling. +*/ +void drm_gem_dmabuf_vunmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map) +{ +struct drm_gem_object *obj = dma_buf->priv; + +drm_gem_vunmap_local (obj, map); +} +EXPORT_SYMBOL (drm_gem_dmabuf_vunmap_local); +/** * drm_gem_prime_mmap - PRIME mmap function for GEM drivers * @obj: GEM object
@@ -787,6 +824,8 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { .mmap = drm_gem_dmabuf_mmap, .vmap = drm_gem_dmabuf_vmap, .vunmap = drm_gem_dmabuf_vunmap, + .vmap_local = drm_gem_dmabuf_vmap_local, + .vunmap_local = drm_gem_dmabuf_vunmap_local, };/**
drivers/gpu/drm/virtio/virtgpu_prime.c +2 -0
@@ -54,6 +54,8 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { .mmap = drm_gem_dmabuf_mmap, .vmap = drm_gem_dmabuf_vmap, .vunmap = drm_gem_dmabuf_vunmap, + .vmap = drm_gem_dmabuf_vmap_local, + .vunmap = drm_gem_dmabuf_vunmap_local, }, .device_attach = drm_gem_map_attach, .get_uuid = virtgpu_virtio_get_uuid,
include/drm/drm_gem.h +20 -0
@@ -151,6 +151,26 @@ struct drm_gem_object_funcs {*/ void (*vunmap)(struct drm_gem_object *obj,struct dma_buf_map *map); +/** +* @vmap_local: +* +* Returns a virtual address for the buffer. Used by the +* drm_gem_dmabuf_vmap_local() helper. +* +* This callback is optional. +*/ +int (*vmap_local)(struct drm_gem_object *obj,struct dma_buf_map *map); + +/** +* @vunmap_local: +* +* Releases the address previously returned by @vmap. Used by the +* drm_gem_dmabuf_vunmap_local() helper. +* +* This callback is optional. +*/ +void (*vunmap_local)(struct drm_gem_object *obj,struct dma_buf_map *map); +/** * @mmap: *
include/drm/drm_prime.h +2 -0
@@ -85,6 +85,8 @@ void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, enum dma_data_direction dir);int drm_gem_dmabuf_vmap (struct dma_buf *dma_buf,struct dma_buf_map *map);void drm_gem_dmabuf_vunmap (struct dma_buf *dma_buf,struct dma_buf_map *map); +int drm_gem_dmabuf_vmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map); +void drm_gem_dmabuf_vunmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map);int drm_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);int drm_gem_dmabuf_mmap (struct dma_buf *dma_buf,struct vm_area_struct *vma);
Signature · 6 lines
2.29.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
kernel test robot
build botRe: [PATCH v3 4/8] drm/gem: Create infrastructure for GEM vmap_local
I love your patch! Perhaps something to improve:
Hi Thomas,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20201209]
[cannot apply to linus/master anholt/for-next v5.10-rc7 v5.10-rc6 v5.10-rc5 v5.10-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Thomas-Zimmermann/drm-Support-short-term-vmap-via-vmap_local/20201209-222628 base: 2f1d5c77f13fe64497c2e2601605f7d7ec4da9b1 config: i386-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/7e45591797810a937bff58af4db651833ef72abe git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Thomas-Zimmermann/drm-Support-short-term-vmap-via-vmap_local/20201209-222628 git checkout 7e45591797810a937bff58af4db651833ef72abe # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/virtio/virtgpu_prime.c:57:11: warning: initialized field overwritten [-Woverride-init]
57 | .vmap = drm_gem_dmabuf_vmap_local,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/virtio/virtgpu_prime.c:57:11: note: (near initialization for 'virtgpu_dmabuf_ops.ops.vmap') drivers/gpu/drm/virtio/virtgpu_prime.c:58:13: warning: initialized field overwritten [-Woverride-init]
58 | .vunmap = drm_gem_dmabuf_vunmap_local,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/virtio/virtgpu_prime.c:58:13: note: (near initialization for 'virtgpu_dmabuf_ops.ops.vunmap')
vim +57 drivers/gpu/drm/virtio/virtgpu_prime.c
45
46 static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = {
47 .ops = {
48 .cache_sgt_mapping = true,
49 .attach = virtio_dma_buf_attach,
50 .detach = drm_gem_map_detach,
51 .map_dma_buf = drm_gem_map_dma_buf,
52 .unmap_dma_buf = drm_gem_unmap_dma_buf,
53 .release = drm_gem_dmabuf_release,
54 .mmap = drm_gem_dmabuf_mmap,
55 .vmap = drm_gem_dmabuf_vmap,
56 .vunmap = drm_gem_dmabuf_vunmap,
> 57 .vmap = drm_gem_dmabuf_vmap_local,
58 .vunmap = drm_gem_dmabuf_vunmap_local,
59 },
60 .device_attach = drm_gem_map_attach,
61 .get_uuid = virtgpu_virtio_get_uuid,
62 };
63 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v3 4/8] drm/gem: Create infrastructure for GEM vmap_local
In reply to Thomas ZimmermannQuoted 143 lines · Thomas Zimmermann
This patch adds
vmap_localandvunmap_localto structdrm_gem_object_funcs; including the PRIME helpers to connect with dma-buf's related interfaces.Besides the generic DRM core, this will become relevant for fbdev emulation with virtio, so we update it as well.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_gem.c | 28 ++++++++++++++++++ drivers/gpu/drm/drm_internal.h | 2 ++ drivers/gpu/drm/drm_prime.c | 39 ++++++++++++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_prime.c | 2 ++ include/drm/drm_gem.h | 20 +++++++++++++ include/drm/drm_prime.h | 2 ++ 6 files changed, 93 insertions(+)drivers/gpu/drm/drm_gem.c +28
-0@@ -1234,6 +1234,34 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map)dma_buf_map_clear (map); } +int drm_gem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +int ret; + +if (!obj->funcs->vmap_local) +return -EOPNOTSUPP ; + + ret = obj->funcs->vmap_local (obj, map); +if (ret) +return ret; +else if (dma_buf_map_is_null (map)) +return -ENOMEM ; + +return 0 ; +} + +void drm_gem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +if (dma_buf_map_is_null (map)) +return ; + +if (obj->funcs->vunmap_local) + obj->funcs->vunmap_local (obj, map); + +/* Always set the mapping to NULL. Callers may rely on this. */ +dma_buf_map_clear (map); +} +/** * drm_gem_lock_reservations - Sets up the ww context and acquires * the lock on an array of GEM objects. drivers/gpu/drm/drm_internal.h +2
-0@@ -190,6 +190,8 @@ int drm_gem_pin(struct drm_gem_object *obj);void drm_gem_unpin (struct drm_gem_object *obj);int drm_gem_vmap (struct drm_gem_object *obj,struct dma_buf_map *map);void drm_gem_vunmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map); +void drm_gem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);/* drm_debugfs.c drm_debugfs_crc.c */ #if defined(CONFIG_DEBUG_FS )drivers/gpu/drm/drm_prime.c +39
-0@@ -695,6 +695,43 @@ void drm_gem_dmabuf_vunmap(struct dma_buf *dma_buf, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_dmabuf_vunmap); +/** +* drm_gem_dmabuf_vmap_local - dma_buf vmap_local implementation for GEM +* @dma_buf: buffer to be mapped +* @map: the virtual address of the buffer +* +* Sets up a kernel virtual mapping. This can be used as the &dma_buf_ops.vmap_local +* callback. Calls into &drm_gem_object_funcs.vmap_local for device specific handling. +* The kernel virtual address is returned in map. +* +* Returns: +* 0 on success or a negative errno code otherwise. +*/ +int drm_gem_dmabuf_vmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map) +{ +struct drm_gem_object *obj = dma_buf->priv; + +return drm_gem_vmap_local (obj, map); +} +EXPORT_SYMBOL (drm_gem_dmabuf_vmap_local); + +/** +* drm_gem_dmabuf_vunmap_local - dma_buf vunmap_local implementation for GEM +* @dma_buf: buffer to be unmapped +* @map: the virtual address of the buffer +* +* Releases a kernel virtual mapping. This can be used as the +* &dma_buf_ops.vunmap_local callback. Calls into &drm_gem_object_funcs.vunmap_local +* for device specific handling. +*/ +void drm_gem_dmabuf_vunmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map) +{ +struct drm_gem_object *obj = dma_buf->priv; + +drm_gem_vunmap_local (obj, map); +} +EXPORT_SYMBOL (drm_gem_dmabuf_vunmap_local); +/** * drm_gem_prime_mmap - PRIME mmap function for GEM drivers * @obj: GEM object @@ -787,6 +824,8 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { .mmap = drm_gem_dmabuf_mmap, .vmap = drm_gem_dmabuf_vmap, .vunmap = drm_gem_dmabuf_vunmap, + .vmap_local = drm_gem_dmabuf_vmap_local, + .vunmap_local = drm_gem_dmabuf_vunmap_local, };/** drivers/gpu/drm/virtio/virtgpu_prime.c +2
-0@@ -54,6 +54,8 @@ static const struct virtio_dma_buf_ops virtgpu_dmabuf_ops = { .mmap = drm_gem_dmabuf_mmap, .vmap = drm_gem_dmabuf_vmap, .vunmap = drm_gem_dmabuf_vunmap, + .vmap = drm_gem_dmabuf_vmap_local, + .vunmap = drm_gem_dmabuf_vunmap_local, }, .device_attach = drm_gem_map_attach, .get_uuid = virtgpu_virtio_get_uuid,include/drm/drm_gem.h +0
-0
include/drm/drm_gem.h struct drm_gem_object_funcs { · line 158
Quoted 8 lines
include/drm/drm_gem.h +5
-0@@ -151,6 +151,26 @@ struct drm_gem_object_funcs {*/ void (*vunmap)(struct drm_gem_object *obj,struct dma_buf_map *map); +/** +* @vmap_local: +* +* Returns a virtual address for the buffer. Used by the +* drm_gem_dmabuf_vmap_local() helper.
I'd add "Callers will hold &drm_gem_object.resv already and only release it after @vunmap is called" (and pls check I typed this correctly for the linking).
Either way: Reviewed-by: Daniel Vetter <[email protected]>
Quoted 34 lines
include/drm/drm_gem.h +15
-0+* +* This callback is optional. +*/ +int (*vmap_local)(struct drm_gem_object *obj,struct dma_buf_map *map); + +/** +* @vunmap_local: +* +* Releases the address previously returned by @vmap. Used by the +* drm_gem_dmabuf_vunmap_local() helper. +* +* This callback is optional. +*/ +void (*vunmap_local)(struct drm_gem_object *obj,struct dma_buf_map *map); +/** * @mmap: * include/drm/drm_prime.h +2
-0@@ -85,6 +85,8 @@ void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, enum dma_data_direction dir);int drm_gem_dmabuf_vmap (struct dma_buf *dma_buf,struct dma_buf_map *map);void drm_gem_dmabuf_vunmap (struct dma_buf *dma_buf,struct dma_buf_map *map); +int drm_gem_dmabuf_vmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map); +void drm_gem_dmabuf_vunmap_local (struct dma_buf *dma_buf,struct dma_buf_map *map);int drm_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);int drm_gem_dmabuf_mmap (struct dma_buf *dma_buf,struct vm_area_struct *vma);Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 5/8 drm/cma-helper: Provide a vmap function for short-term mappings
In reply to Thomas ZimmermannImplementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. Callers that only require a mapping of the contained memory can thus interfere with other tasks that require exact pinning, such as scanout. This is less of an issue with private CMA buffers, but may happen with imported ones.
Therefore provide the new interface drm_gem_cma_vmap_local(), which only performs the vmap operations. Callers have to hold the reservation lock while the mapping persists.
This patch also connects GEM CMA helpers to the GEM object function with equivalent functionality.
--- drivers/gpu/drm/drm_gem_cma_helper.c | 35 ++++++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_bo.c | 13 +++++++++++ drivers/gpu/drm/vc4/vc4_drv.h | 1 + include/drm/drm_gem_cma_helper.h | 1 + 4 files changed, 50 insertions(+)
drivers/gpu/drm/drm_gem_cma_helper.c +35 -0
@@ -38,6 +38,7 @@ static const struct drm_gem_object_funcs drm_gem_cma_default_funcs = { .print_info = drm_gem_cma_print_info, .get_sg_table = drm_gem_cma_get_sg_table, .vmap = drm_gem_cma_vmap, + .vmap_local = drm_gem_cma_vmap_local, .mmap = drm_gem_cma_mmap, .vm_ops = &drm_gem_cma_vm_ops, };
@@ -471,6 +472,40 @@ int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (drm_gem_cma_vmap); +/** +* drm_gem_cma_vmap_local - map a CMA GEM object into the kernel's virtual +* address space +* @obj: GEM object +* @map: Returns the kernel virtual address of the CMA GEM object's backing +* store. +* +* This function maps a buffer into the kernel's +* virtual address space. Since the CMA buffers are already mapped into the +* kernel virtual address space this simply returns the cached virtual +* address. Drivers using the CMA helpers should set this as their DRM +* driver's &drm_gem_object_funcs.vmap_local callback. +* +* Returns: +* 0 on success, or a negative error code otherwise. +*/ +int drm_gem_cma_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_cma_object *cma_obj =to_drm_gem_cma_obj (obj); + +/* +* TODO: The code in drm_gem_cma_prime_import_sg_table_vmap() +* establishes this mapping. The correct solution would +* be to call dma_buf_vmap_local() here. +* +* If we find a case where we absolutely have to call +* dma_buf_vmap_local(), the code needs to be restructured. +*/ +dma_buf_map_set_vaddr (map, cma_obj->vaddr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (drm_gem_cma_vmap_local); +/** * drm_gem_cma_mmap - memory-map an exported CMA GEM object * @obj: GEM object
drivers/gpu/drm/vc4/vc4_bo.c +13 -0
@@ -387,6 +387,7 @@ static const struct drm_gem_object_funcs vc4_gem_object_funcs = { .export = vc4_prime_export, .get_sg_table = drm_gem_cma_get_sg_table, .vmap = vc4_prime_vmap, + .vmap_local = vc4_prime_vmap_local, .vm_ops = &vc4_vm_ops, };
@@ -797,6 +798,18 @@ int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)return drm_gem_cma_vmap (obj, map); } +int vc4_prime_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct vc4_bo *bo =to_vc4_bo (obj); + +if (bo->validated_shader) { +DRM_DEBUG ("mmaping of shader BOs not allowed.\n" ); +return -EINVAL ; + } + +return drm_gem_cma_vmap_local (obj, map); +} +struct drm_gem_object * vc4_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach,
drivers/gpu/drm/vc4/vc4_drv.h +1 -0
@@ -812,6 +812,7 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, struct sg_table *sgt);int vc4_prime_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int vc4_prime_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int vc4_bo_cache_init (struct drm_device *dev);int vc4_bo_inc_usecnt (struct vc4_bo *bo);void vc4_bo_dec_usecnt (struct vc4_bo *bo);
include/drm/drm_gem_cma_helper.h +1 -0
@@ -99,6 +99,7 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, struct sg_table *sgt);int drm_gem_cma_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_cma_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int drm_gem_cma_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);/**
Signature · 6 lines
2.29.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 5/8] drm/cma-helper: Provide a vmap function for short-term mappings
Quoted 55 lines · Thomas Zimmermann
Implementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. Callers that only require a mapping of the contained memory can thus interfere with other tasks that require exact pinning, such as scanout. This is less of an issue with private CMA buffers, but may happen with imported ones.
Therefore provide the new interface
drm_gem_cma_vmap_local(), which only performs the vmap operations. Callers have to hold the reservation lock while the mapping persists.This patch also connects GEM CMA helpers to the GEM object function with equivalent functionality.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_gem_cma_helper.c | 35 ++++++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_bo.c | 13 +++++++++++ drivers/gpu/drm/vc4/vc4_drv.h | 1 + include/drm/drm_gem_cma_helper.h | 1 + 4 files changed, 50 insertions(+)drivers/gpu/drm/drm_gem_cma_helper.c +18
-0@@ -38,6 +38,7 @@ static const struct drm_gem_object_funcs drm_gem_cma_default_funcs = { .print_info = drm_gem_cma_print_info, .get_sg_table = drm_gem_cma_get_sg_table, .vmap = drm_gem_cma_vmap, + .vmap_local = drm_gem_cma_vmap_local, .mmap = drm_gem_cma_mmap, .vm_ops = &drm_gem_cma_vm_ops, };@@ -471,6 +472,40 @@ int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (drm_gem_cma_vmap); +/** +* drm_gem_cma_vmap_local - map a CMA GEM object into the kernel's virtual +* address space +* @obj: GEM object +* @map: Returns the kernel virtual address of the CMA GEM object's backing +* store. +* +* This function maps a buffer into the kernel's +* virtual address space. Since the CMA buffers are already mapped into the +* kernel virtual address space this simply returns the cached virtual +* address. Drivers using the CMA helpers should set this as their DRM +* driver's &drm_gem_object_funcs.vmap_local callback. +* +* Returns: +* 0 on success, or a negative error code otherwise. +*/ +int drm_gem_cma_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map)
drivers/gpu/drm/drm_gem_cma_helper.c int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 501
Quoted 10 lines
drivers/gpu/drm/drm_gem_cma_helper.c +10
-0+{ +struct drm_gem_cma_object *cma_obj =to_drm_gem_cma_obj (obj); + +/* +* TODO: The code in drm_gem_cma_prime_import_sg_table_vmap() +* establishes this mapping. The correct solution would +* be to call dma_buf_vmap_local() here. +* +* If we find a case where we absolutely have to call +* dma_buf_vmap_local(), the code needs to be restructured.
dma_buf_vmap_local is only relevant for dynamic importers, pinning at import time is actually what you get anyway. That's what Christian meant with his comments for the ->pin hook. So the TODO here doesn't make sense imo, just delete it. We're very far away from making cma dynamic :-)
Quoted 23 lines
drivers/gpu/drm/drm_gem_cma_helper.c +7
-0+*/ +dma_buf_map_set_vaddr (map, cma_obj->vaddr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (drm_gem_cma_vmap_local); +/** * drm_gem_cma_mmap - memory-map an exported CMA GEM object * @obj: GEM object drivers/gpu/drm/vc4/vc4_bo.c +1
-0@@ -387,6 +387,7 @@ static const struct drm_gem_object_funcs vc4_gem_object_funcs = { .export = vc4_prime_export, .get_sg_table = drm_gem_cma_get_sg_table, .vmap = vc4_prime_vmap, + .vmap_local = vc4_prime_vmap_local, .vm_ops = &vc4_vm_ops, };
drivers/gpu/drm/vc4/vc4_bo.c int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 805
Quoted 8 lines
drivers/gpu/drm/vc4/vc4_bo.c +5
-0@@ -797,6 +798,18 @@ int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)return drm_gem_cma_vmap (obj, map); } +int vc4_prime_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct vc4_bo *bo =to_vc4_bo (obj); + +if (bo->validated_shader) {
This freaks me out. It should be impossible to export a validated shader as a dma-buf, and indeed the check exists already.
All the wrapper functions here are imo pointless. Either we should remove them, or replace the if with a BUG_ON here since if that ever happens we have a security bug already. I'd go with removing, less code. Maybe throw a patch on top?
Anyway this patch looks good, with the todo deleted:
Quoted 37 lines
drivers/gpu/drm/vc4/vc4_bo.c +7
-0+DRM_DEBUG ("mmaping of shader BOs not allowed.\n" ); +return -EINVAL ; + } + +return drm_gem_cma_vmap_local (obj, map); +} +struct drm_gem_object * vc4_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach,drivers/gpu/drm/vc4/vc4_drv.h +1
-0@@ -812,6 +812,7 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, struct sg_table *sgt);int vc4_prime_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int vc4_prime_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int vc4_bo_cache_init (struct drm_device *dev);int vc4_bo_inc_usecnt (struct vc4_bo *bo);void vc4_bo_dec_usecnt (struct vc4_bo *bo);include/drm/drm_gem_cma_helper.h +1
-0@@ -99,6 +99,7 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, struct sg_table *sgt);int drm_gem_cma_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_cma_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int drm_gem_cma_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);/** Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 5/8] drm/cma-helper: Provide a vmap function for short-term mappings
Quoted 107 lines · Daniel Vetter
Quoted 55 lines · Thomas Zimmermann
Implementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. Callers that only require a mapping of the contained memory can thus interfere with other tasks that require exact pinning, such as scanout. This is less of an issue with private CMA buffers, but may happen with imported ones.
Therefore provide the new interface
drm_gem_cma_vmap_local(), which only performs the vmap operations. Callers have to hold the reservation lock while the mapping persists.This patch also connects GEM CMA helpers to the GEM object function with equivalent functionality.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_gem_cma_helper.c | 35 ++++++++++++++++++++++++++++ drivers/gpu/drm/vc4/vc4_bo.c | 13 +++++++++++ drivers/gpu/drm/vc4/vc4_drv.h | 1 + include/drm/drm_gem_cma_helper.h | 1 + 4 files changed, 50 insertions(+)drivers/gpu/drm/drm_gem_cma_helper.c +18
-0@@ -38,6 +38,7 @@ static const struct drm_gem_object_funcs drm_gem_cma_default_funcs = { .print_info = drm_gem_cma_print_info, .get_sg_table = drm_gem_cma_get_sg_table, .vmap = drm_gem_cma_vmap, + .vmap_local = drm_gem_cma_vmap_local, .mmap = drm_gem_cma_mmap, .vm_ops = &drm_gem_cma_vm_ops, };@@ -471,6 +472,40 @@ int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL_GPL (drm_gem_cma_vmap); +/** +* drm_gem_cma_vmap_local - map a CMA GEM object into the kernel's virtual +* address space +* @obj: GEM object +* @map: Returns the kernel virtual address of the CMA GEM object's backing +* store. +* +* This function maps a buffer into the kernel's +* virtual address space. Since the CMA buffers are already mapped into the +* kernel virtual address space this simply returns the cached virtual +* address. Drivers using the CMA helpers should set this as their DRM +* driver's &drm_gem_object_funcs.vmap_local callback. +* +* Returns: +* 0 on success, or a negative error code otherwise. +*/ +int drm_gem_cma_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map)drivers/gpu/drm/drm_gem_cma_helper.c int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 501
Quoted 10 lines
drivers/gpu/drm/drm_gem_cma_helper.c +10
-0+{ +struct drm_gem_cma_object *cma_obj =to_drm_gem_cma_obj (obj); + +/* +* TODO: The code in drm_gem_cma_prime_import_sg_table_vmap() +* establishes this mapping. The correct solution would +* be to call dma_buf_vmap_local() here. +* +* If we find a case where we absolutely have to call +* dma_buf_vmap_local(), the code needs to be restructured.
dma_buf_vmap_localis only relevant for dynamic importers, pinning at import time is actually what you get anyway. That's what Christian meant with his comments for the ->pin hook. So the TODO here doesn't make sense imo, just delete it. We're very far away from making cma dynamic :-)Quoted 23 lines
drivers/gpu/drm/drm_gem_cma_helper.c +7
-0+*/ +dma_buf_map_set_vaddr (map, cma_obj->vaddr); + +return 0 ; +} +EXPORT_SYMBOL_GPL (drm_gem_cma_vmap_local); +/** * drm_gem_cma_mmap - memory-map an exported CMA GEM object * @obj: GEM object drivers/gpu/drm/vc4/vc4_bo.c +1
-0@@ -387,6 +387,7 @@ static const struct drm_gem_object_funcs vc4_gem_object_funcs = { .export = vc4_prime_export, .get_sg_table = drm_gem_cma_get_sg_table, .vmap = vc4_prime_vmap, + .vmap_local = vc4_prime_vmap_local, .vm_ops = &vc4_vm_ops, };drivers/gpu/drm/vc4/vc4_bo.c int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 805
Quoted 8 lines
drivers/gpu/drm/vc4/vc4_bo.c +5
-0@@ -797,6 +798,18 @@ int vc4_prime_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)return drm_gem_cma_vmap (obj, map); } +int vc4_prime_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct vc4_bo *bo =to_vc4_bo (obj); + +if (bo->validated_shader) {This freaks me out. It should be impossible to export a validated shader as a dma-buf, and indeed the check exists already.
Quoted 4 lines
All the wrapper functions here are imo pointless. Either we should remove them, or replace the if with a
BUG_ONhere since if that ever happens we have a security bug already. I'd go with removing, less code. Maybe throw a patch on top?
On 2nd thought, since I asked for the driver parts to be split out in all the follow-up patches. Maybe best if you do the removal of these wrappers here first, that gets rid of the vc4 changes in this patch here too. -Daniel
Quoted 48 lines
Anyway this patch looks good, with the todo deleted:
Reviewed-by Daniel Vetter <[email protected]>Quoted 37 lines
drivers/gpu/drm/vc4/vc4_bo.c +7
-0+DRM_DEBUG ("mmaping of shader BOs not allowed.\n" ); +return -EINVAL ; + } + +return drm_gem_cma_vmap_local (obj, map); +} +struct drm_gem_object * vc4_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach,drivers/gpu/drm/vc4/vc4_drv.h +1
-0@@ -812,6 +812,7 @@ struct drm_gem_object *vc4_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, struct sg_table *sgt);int vc4_prime_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int vc4_prime_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int vc4_bo_cache_init (struct drm_device *dev);int vc4_bo_inc_usecnt (struct vc4_bo *bo);void vc4_bo_dec_usecnt (struct vc4_bo *bo);include/drm/drm_gem_cma_helper.h +1
-0@@ -99,6 +99,7 @@ drm_gem_cma_prime_import_sg_table(struct drm_device *dev,struct dma_buf_attachment *attach, struct sg_table *sgt);int drm_gem_cma_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_cma_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int drm_gem_cma_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma);/** Signature · 1 line
2.29.2Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 6/8 drm/shmem-helper: Provide a vmap function for short-term mappings
In reply to Thomas ZimmermannImplementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. Callers that only require a mapping of the contained memory can thus interfere with other tasks that require exact pinning, such as scanout. This is less of an issue with private SHMEM buffers, but may happen with imported ones.
Therefore provide the new interfaces drm_gem_shmem_vmap_local() and drm_gem_shmem_vunmap_local(), which only perform the vmap/vunmap operations. Callers have to hold the reservation lock while the mapping persists.
The affected callers are display updates in cirrus, gm12u320, mgag200 and udl. All are being changed to the new interface.
This patch also connects GEM SHMEM helpers to GEM object functions with equivalent functionality.
--- drivers/gpu/drm/drm_gem_shmem_helper.c | 71 +++++++++++++++++++++++++- drivers/gpu/drm/mgag200/mgag200_mode.c | 16 ++++-- drivers/gpu/drm/tiny/cirrus.c | 10 +++- drivers/gpu/drm/tiny/gm12u320.c | 14 +++-- drivers/gpu/drm/udl/udl_modeset.c | 18 ++++--- include/drm/drm_gem_shmem_helper.h | 2 + 6 files changed, 115 insertions(+), 16 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +69 -2
@@ -32,6 +32,8 @@ static const struct drm_gem_object_funcs drm_gem_shmem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, + .vmap_local = drm_gem_shmem_vmap_local, + .vunmap_local = drm_gem_shmem_vunmap_local, .mmap = drm_gem_shmem_mmap, };
@@ -313,7 +315,7 @@ static int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem, structreturn ret; } -/* +/** * drm_gem_shmem_vmap - Create a virtual mapping for a shmem GEM object * @shmem: shmem GEM object * @map: Returns the kernel virtual address of the SHMEM GEM object's backing
@@ -346,6 +348,44 @@ int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_shmem_vmap); +/** +* drm_gem_shmem_vmap_local - Create a virtual mapping for a shmem GEM object +* @shmem: shmem GEM object +* @map: Returns the kernel virtual address of the SHMEM GEM object's backing +* store. +* +* This function makes sure that a contiguous kernel virtual address mapping +* exists for the buffer backing the shmem GEM object. +* +* The function is called with the BO's reservation object locked. Callers must +* hold the lock until after unmapping the buffer. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. But +* it can also be called by drivers directly, in which case it will hide the +* differences between dma-buf imported and natively allocated objects. +* +* Acquired mappings should be cleaned up by calling drm_gem_shmem_vunmap_local(). +* +* Returns: +* 0 on success or a negative error code on failure. +*/ +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); +int ret; + +dma_resv_assert_held (obj->resv); + + ret =mutex_lock_interruptible (&shmem->vmap_lock); +if (ret) +return ret; + ret =drm_gem_shmem_vmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); + +return ret; +} +EXPORT_SYMBOL (drm_gem_shmem_vmap_local); +static void drm_gem_shmem_vunmap_locked (struct drm_gem_shmem_object *shmem,struct dma_buf_map *map) {
@@ -366,7 +406,7 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,drm_gem_shmem_put_pages (shmem); } -/* +/** * drm_gem_shmem_vunmap - Unmap a virtual mapping fo a shmem GEM object * @shmem: shmem GEM object * @map: Kernel virtual address where the SHMEM GEM object was mapped
@@ -389,6 +429,33 @@ void drm_gem_shmem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_shmem_vunmap); +/** +* drm_gem_shmem_vunmap_local - Unmap a virtual mapping fo a shmem GEM object +* @shmem: shmem GEM object +* @map: Kernel virtual address where the SHMEM GEM object was mapped +* +* This function cleans up a kernel virtual address mapping acquired by +* drm_gem_shmem_vmap_local(). The mapping is only removed when the use count +* drops to zero. +* +* The function is called with the BO's reservation object locked. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. +* But it can also be called by drivers directly, in which case it will hide +* the differences between dma-buf imported and natively allocated objects. +*/ +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); + +dma_resv_assert_held (obj->resv); + +mutex_lock (&shmem->vmap_lock); +drm_gem_shmem_vunmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); +} +EXPORT_SYMBOL (drm_gem_shmem_vunmap_local); +struct drm_gem_shmem_object * drm_gem_shmem_create_with_handle(struct drm_file *file_priv, struct drm_device *dev, size_t size,
drivers/gpu/drm/mgag200/mgag200_mode.c +13 -3
@@ -1552,22 +1552,32 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, struct drm_rect *clip) {struct drm_device *dev = &mdev->base; +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int ret; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (drm_WARN_ON (dev, ret)) -return ;/* BUG: SHMEM BO should always be vmapped */ +return ; + ret =drm_gem_shmem_vmap_local (obj, &map); +if (drm_WARN_ON (dev, ret)) + goto err_dma_resv_unlock;/* BUG: SHMEM BO should always be vmapped */ vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ drm_fb_memcpy_dstclip (mdev->vram, vmap, fb, clip); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (obj, &map); +dma_resv_unlock (obj->resv);/* Always scanout image at VRAM offset 0 */ mgag200_set_startadd (mdev, (u32 )0 );mgag200_set_offset (mdev, fb); + +return ; + +err_dma_resv_unlock: +dma_resv_unlock (obj->resv); } static void
drivers/gpu/drm/tiny/cirrus.c +8 -2
@@ -315,6 +315,7 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, struct drm_rect *rect) {struct cirrus_device *cirrus =to_cirrus (fb->dev); +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int idx, ret;
@@ -323,9 +324,12 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,if (!drm_dev_enter (&cirrus->dev, &idx)) goto out; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (ret) goto out_dev_exit; + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) + goto out_dma_resv_unlock; vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ if (cirrus->cpp == fb->format->cpp[0 ])
@@ -345,9 +349,11 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,else WARN_ON_ONCE ("cpp mismatch" ); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); ret =0 ; +drm_gem_shmem_vunmap_local (obj, &map); +out_dma_resv_unlock: +dma_resv_unlock (obj->resv); out_dev_exit:drm_dev_exit (idx); out:
drivers/gpu/drm/tiny/gm12u320.c +11 -3
@@ -265,11 +265,16 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) y1 = gm12u320->fb_update.rect.y1; y2 = gm12u320->fb_update.rect.y2; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL );if (ret) { -GM12U320_ERR ("failed to vmap fb: %d\n" , ret); +GM12U320_ERR ("failed to reserve fb: %d\n" , ret); goto put_fb; } + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) { +GM12U320_ERR ("failed to vmap fb: %d\n" , ret); + goto unlock_resv; + } vaddr = map.vaddr;/* TODO: Use mapping abstraction properly */ if (fb->obj[0 ]->import_attach) {
@@ -321,8 +326,11 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320)if (ret)GM12U320_ERR ("dma_buf_end_cpu_access err: %d\n" , ret); } + +unlock_resv: +dma_resv_unlock (fb->obj[0 ]->resv); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); put_fb:drm_framebuffer_put (fb); gm12u320->fb_update.fb =NULL ;
drivers/gpu/drm/udl/udl_modeset.c +12 -6
@@ -290,14 +290,18 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,else if ((clip.x2 > fb->width) || (clip.y2 > fb->height))return -EINVAL ; + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL ); +if (ret) +return ret; +if (import_attach) { ret =dma_buf_begin_cpu_access (import_attach->dmabuf,DMA_FROM_DEVICE );if (ret) -return ret; + goto out_dma_resv_unlock; } - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map);if (ret) {DRM_ERROR ("failed to vmap fb\n" ); goto out_dma_buf_end_cpu_access;
@@ -307,7 +311,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, urb =udl_get_urb (dev);if (!urb) { ret = -ENOMEM ; - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; } cmd = urb->transfer_buffer;
@@ -320,7 +324,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, &cmd, byte_offset, dev_byte_offset, byte_width);if (ret) - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; }if (cmd > (char *)urb->transfer_buffer) {
@@ -336,8 +340,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, ret =0 ; -out_drm_gem_shmem_vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +out_drm_gem_shmem_vunmap_local: +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); out_dma_buf_end_cpu_access:if (import_attach) { tmp_ret = dma_buf_end_cpu_access(import_attach->dmabuf,
@@ -345,6 +349,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,if (tmp_ret && !ret) ret = tmp_ret;/* only update ret if not set yet */ } +out_dma_resv_unlock: +dma_resv_unlock (fb->obj[0 ]->resv);return ret; }
include/drm/drm_gem_shmem_helper.h +2 -0
@@ -114,7 +114,9 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem);int drm_gem_shmem_pin (struct drm_gem_object *obj);void drm_gem_shmem_unpin (struct drm_gem_object *obj);int drm_gem_shmem_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);void drm_gem_shmem_vunmap (struct drm_gem_object *obj,struct dma_buf_map *map); +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int drm_gem_shmem_madvise (struct drm_gem_object *obj,int madv);
Signature · 6 lines
2.29.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v3 6/8] drm/shmem-helper: Provide a vmap function for short-term mappings
Quoted 18 lines · Thomas Zimmermann
Implementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. Callers that only require a mapping of the contained memory can thus interfere with other tasks that require exact pinning, such as scanout. This is less of an issue with private SHMEM buffers, but may happen with imported ones.
Therefore provide the new interfaces
drm_gem_shmem_vmap_local()anddrm_gem_shmem_vunmap_local(), which only perform the vmap/vunmap operations. Callers have to hold the reservation lock while the mapping persists.The affected callers are display updates in cirrus, gm12u320, mgag200 and udl. All are being changed to the new interface.
This patch also connects GEM SHMEM helpers to GEM object functions with equivalent functionality.
Quoted 7 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/drm_gem_shmem_helper.c | 71 +++++++++++++++++++++++++- drivers/gpu/drm/mgag200/mgag200_mode.c | 16 ++++-- drivers/gpu/drm/tiny/cirrus.c | 10 +++- drivers/gpu/drm/tiny/gm12u320.c | 14 +++-- drivers/gpu/drm/udl/udl_modeset.c | 18 ++++---
I think that's a bit much driver conversion. I'd say in general split these out from the patch that adds the new functionality. More importantly, since vmap_local is optional, you can only start using it once all drivers have it. Especially with udl this will break use-cases otherwise, but also probably with gm12u320.
Quoted 48 lines
include/drm/drm_gem_shmem_helper.h | 2 + 6 files changed, 115 insertions(+), 16 deletions(-)drivers/gpu/drm/drm_gem_shmem_helper.c +22
-1@@ -32,6 +32,8 @@ static const struct drm_gem_object_funcs drm_gem_shmem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, + .vmap_local = drm_gem_shmem_vmap_local, + .vunmap_local = drm_gem_shmem_vunmap_local, .mmap = drm_gem_shmem_mmap, };@@ -313,7 +315,7 @@ static int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem, structreturn ret; } -/* +/** * drm_gem_shmem_vmap - Create a virtual mapping for a shmem GEM object * @shmem: shmem GEM object * @map: Returns the kernel virtual address of the SHMEM GEM object's backing @@ -346,6 +348,44 @@ int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_shmem_vmap); +/** +* drm_gem_shmem_vmap_local - Create a virtual mapping for a shmem GEM object +* @shmem: shmem GEM object +* @map: Returns the kernel virtual address of the SHMEM GEM object's backing +* store. +* +* This function makes sure that a contiguous kernel virtual address mapping +* exists for the buffer backing the shmem GEM object. +* +* The function is called with the BO's reservation object locked. Callers must +* hold the lock until after unmapping the buffer. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. But +* it can also be called by drivers directly, in which case it will hide the +* differences between dma-buf imported and natively allocated objects. +* +* Acquired mappings should be cleaned up by calling drm_gem_shmem_vunmap_local(). +* +* Returns:
drivers/gpu/drm/drm_gem_shmem_helper.c int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 379
Quoted 10 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +10
-0+* 0 on success or a negative error code on failure. +*/ +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); +int ret; + +dma_resv_assert_held (obj->resv); + + ret =mutex_lock_interruptible (&shmem->vmap_lock);
This bites. You need to check for shmem->import_attach and call dma_buf_vmap_local directly here before you take any shmem helper locks. Real fix would be to replace both vmap_lock and pages_lock with dma_resv lock, but that's more work. Same for vunmap_local
With that fixed on the helper part of this patch:
Quoted 250 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +37
-1+if (ret) +return ret; + ret =drm_gem_shmem_vmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); + +return ret; +} +EXPORT_SYMBOL (drm_gem_shmem_vmap_local); +static void drm_gem_shmem_vunmap_locked (struct drm_gem_shmem_object *shmem,struct dma_buf_map *map) {@@ -366,7 +406,7 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,drm_gem_shmem_put_pages (shmem); } -/* +/** * drm_gem_shmem_vunmap - Unmap a virtual mapping fo a shmem GEM object * @shmem: shmem GEM object * @map: Kernel virtual address where the SHMEM GEM object was mapped @@ -389,6 +429,33 @@ void drm_gem_shmem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_shmem_vunmap); +/** +* drm_gem_shmem_vunmap_local - Unmap a virtual mapping fo a shmem GEM object +* @shmem: shmem GEM object +* @map: Kernel virtual address where the SHMEM GEM object was mapped +* +* This function cleans up a kernel virtual address mapping acquired by +* drm_gem_shmem_vmap_local(). The mapping is only removed when the use count +* drops to zero. +* +* The function is called with the BO's reservation object locked. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. +* But it can also be called by drivers directly, in which case it will hide +* the differences between dma-buf imported and natively allocated objects. +*/ +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); + +dma_resv_assert_held (obj->resv); + +mutex_lock (&shmem->vmap_lock); +drm_gem_shmem_vunmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); +} +EXPORT_SYMBOL (drm_gem_shmem_vunmap_local); +struct drm_gem_shmem_object * drm_gem_shmem_create_with_handle(struct drm_file *file_priv, struct drm_device *dev, size_t size,drivers/gpu/drm/mgag200/mgag200_mode.c +13
-3@@ -1552,22 +1552,32 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, struct drm_rect *clip) {struct drm_device *dev = &mdev->base; +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int ret; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (drm_WARN_ON (dev, ret)) -return ;/* BUG: SHMEM BO should always be vmapped */ +return ; + ret =drm_gem_shmem_vmap_local (obj, &map); +if (drm_WARN_ON (dev, ret)) + goto err_dma_resv_unlock;/* BUG: SHMEM BO should always be vmapped */ vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ drm_fb_memcpy_dstclip (mdev->vram, vmap, fb, clip); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (obj, &map); +dma_resv_unlock (obj->resv);/* Always scanout image at VRAM offset 0 */ mgag200_set_startadd (mdev, (u32 )0 );mgag200_set_offset (mdev, fb); + +return ; + +err_dma_resv_unlock: +dma_resv_unlock (obj->resv); } static voiddrivers/gpu/drm/tiny/cirrus.c +8
-2@@ -315,6 +315,7 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, struct drm_rect *rect) {struct cirrus_device *cirrus =to_cirrus (fb->dev); +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int idx, ret;@@ -323,9 +324,12 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,if (!drm_dev_enter (&cirrus->dev, &idx)) goto out; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (ret) goto out_dev_exit; + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) + goto out_dma_resv_unlock; vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ if (cirrus->cpp == fb->format->cpp[0 ])@@ -345,9 +349,11 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,else WARN_ON_ONCE ("cpp mismatch" ); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); ret =0 ; +drm_gem_shmem_vunmap_local (obj, &map); +out_dma_resv_unlock: +dma_resv_unlock (obj->resv); out_dev_exit:drm_dev_exit (idx); out:drivers/gpu/drm/tiny/gm12u320.c +11
-3@@ -265,11 +265,16 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) y1 = gm12u320->fb_update.rect.y1; y2 = gm12u320->fb_update.rect.y2; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL );if (ret) { -GM12U320_ERR ("failed to vmap fb: %d\n" , ret); +GM12U320_ERR ("failed to reserve fb: %d\n" , ret); goto put_fb; } + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) { +GM12U320_ERR ("failed to vmap fb: %d\n" , ret); + goto unlock_resv; + } vaddr = map.vaddr;/* TODO: Use mapping abstraction properly */ if (fb->obj[0 ]->import_attach) {@@ -321,8 +326,11 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320)if (ret)GM12U320_ERR ("dma_buf_end_cpu_access err: %d\n" , ret); } + +unlock_resv: +dma_resv_unlock (fb->obj[0 ]->resv); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); put_fb:drm_framebuffer_put (fb); gm12u320->fb_update.fb =NULL ;drivers/gpu/drm/udl/udl_modeset.c +12
-6@@ -290,14 +290,18 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,else if ((clip.x2 > fb->width) || (clip.y2 > fb->height))return -EINVAL ; + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL ); +if (ret) +return ret; +if (import_attach) { ret =dma_buf_begin_cpu_access (import_attach->dmabuf,DMA_FROM_DEVICE );if (ret) -return ret; + goto out_dma_resv_unlock; } - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map);if (ret) {DRM_ERROR ("failed to vmap fb\n" ); goto out_dma_buf_end_cpu_access;@@ -307,7 +311,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, urb =udl_get_urb (dev);if (!urb) { ret = -ENOMEM ; - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; } cmd = urb->transfer_buffer;@@ -320,7 +324,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, &cmd, byte_offset, dev_byte_offset, byte_width);if (ret) - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; }if (cmd > (char *)urb->transfer_buffer) {@@ -336,8 +340,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, ret =0 ; -out_drm_gem_shmem_vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +out_drm_gem_shmem_vunmap_local: +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); out_dma_buf_end_cpu_access:if (import_attach) { tmp_ret = dma_buf_end_cpu_access(import_attach->dmabuf,@@ -345,6 +349,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,if (tmp_ret && !ret) ret = tmp_ret;/* only update ret if not set yet */ } +out_dma_resv_unlock: +dma_resv_unlock (fb->obj[0 ]->resv);return ret; }include/drm/drm_gem_shmem_helper.h +2
-0@@ -114,7 +114,9 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem);int drm_gem_shmem_pin (struct drm_gem_object *obj);void drm_gem_shmem_unpin (struct drm_gem_object *obj);int drm_gem_shmem_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);void drm_gem_shmem_vunmap (struct drm_gem_object *obj,struct dma_buf_map *map); +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int drm_gem_shmem_madvise (struct drm_gem_object *obj,int madv);Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v3 6/8] drm/shmem-helper: Provide a vmap function for short-term mappings
Hi Daniel
Am 11.12.20 um 10:50 schrieb Daniel Vetter:
[...]
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +26
-0+/** +* drm_gem_shmem_vmap_local - Create a virtual mapping for a shmem GEM object +* @shmem: shmem GEM object +* @map: Returns the kernel virtual address of the SHMEM GEM object's backing +* store. +* +* This function makes sure that a contiguous kernel virtual address mapping +* exists for the buffer backing the shmem GEM object. +* +* The function is called with the BO's reservation object locked. Callers must +* hold the lock until after unmapping the buffer. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. But +* it can also be called by drivers directly, in which case it will hide the +* differences between dma-buf imported and natively allocated objects. +* +* Acquired mappings should be cleaned up by calling drm_gem_shmem_vunmap_local(). +* +* Returns: +* 0 on success or a negative error code on failure. +*/ +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); +int ret; +
Quoted 8 lines
drivers/gpu/drm/drm_gem_shmem_helper.c int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 379
Quoted 3 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +3
-0+dma_resv_assert_held (obj->resv); + + ret =mutex_lock_interruptible (&shmem->vmap_lock);This bites. You need to check for
shmem->import_attachand calldma_buf_vmap_localdirectly here before you take any shmem helper locks. Real fix would be to replace bothvmap_lockandpages_lockwithdma_resvlock, but that's more work. Same forvunmap_local
This comment confuses me. AFAICT vmap_lock protects vmap_use_count. Why does this exact code work in drm_gem_shmem_vmap() but not in _local() ?
Best regards
Thomas
Quoted 257 lines
With that fixed on the helper part of this patch:
Reviewed-by Daniel Vetter <[email protected]>Quoted 250 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +37
-1+if (ret) +return ret; + ret =drm_gem_shmem_vmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); + +return ret; +} +EXPORT_SYMBOL (drm_gem_shmem_vmap_local); +static void drm_gem_shmem_vunmap_locked (struct drm_gem_shmem_object *shmem,struct dma_buf_map *map) {@@ -366,7 +406,7 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,drm_gem_shmem_put_pages (shmem); } -/* +/** * drm_gem_shmem_vunmap - Unmap a virtual mapping fo a shmem GEM object * @shmem: shmem GEM object * @map: Kernel virtual address where the SHMEM GEM object was mapped @@ -389,6 +429,33 @@ void drm_gem_shmem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_shmem_vunmap); +/** +* drm_gem_shmem_vunmap_local - Unmap a virtual mapping fo a shmem GEM object +* @shmem: shmem GEM object +* @map: Kernel virtual address where the SHMEM GEM object was mapped +* +* This function cleans up a kernel virtual address mapping acquired by +* drm_gem_shmem_vmap_local(). The mapping is only removed when the use count +* drops to zero. +* +* The function is called with the BO's reservation object locked. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. +* But it can also be called by drivers directly, in which case it will hide +* the differences between dma-buf imported and natively allocated objects. +*/ +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); + +dma_resv_assert_held (obj->resv); + +mutex_lock (&shmem->vmap_lock); +drm_gem_shmem_vunmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); +} +EXPORT_SYMBOL (drm_gem_shmem_vunmap_local); +struct drm_gem_shmem_object * drm_gem_shmem_create_with_handle(struct drm_file *file_priv, struct drm_device *dev, size_t size,drivers/gpu/drm/mgag200/mgag200_mode.c +13
-3@@ -1552,22 +1552,32 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, struct drm_rect *clip) {struct drm_device *dev = &mdev->base; +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int ret; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (drm_WARN_ON (dev, ret)) -return ;/* BUG: SHMEM BO should always be vmapped */ +return ; + ret =drm_gem_shmem_vmap_local (obj, &map); +if (drm_WARN_ON (dev, ret)) + goto err_dma_resv_unlock;/* BUG: SHMEM BO should always be vmapped */ vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ drm_fb_memcpy_dstclip (mdev->vram, vmap, fb, clip); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (obj, &map); +dma_resv_unlock (obj->resv);/* Always scanout image at VRAM offset 0 */ mgag200_set_startadd (mdev, (u32 )0 );mgag200_set_offset (mdev, fb); + +return ; + +err_dma_resv_unlock: +dma_resv_unlock (obj->resv); } static voiddrivers/gpu/drm/tiny/cirrus.c +8
-2@@ -315,6 +315,7 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, struct drm_rect *rect) {struct cirrus_device *cirrus =to_cirrus (fb->dev); +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int idx, ret;@@ -323,9 +324,12 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,if (!drm_dev_enter (&cirrus->dev, &idx)) goto out; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (ret) goto out_dev_exit; + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) + goto out_dma_resv_unlock; vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ if (cirrus->cpp == fb->format->cpp[0 ])@@ -345,9 +349,11 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,else WARN_ON_ONCE ("cpp mismatch" ); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); ret =0 ; +drm_gem_shmem_vunmap_local (obj, &map); +out_dma_resv_unlock: +dma_resv_unlock (obj->resv); out_dev_exit:drm_dev_exit (idx); out:drivers/gpu/drm/tiny/gm12u320.c +11
-3@@ -265,11 +265,16 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) y1 = gm12u320->fb_update.rect.y1; y2 = gm12u320->fb_update.rect.y2; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL );if (ret) { -GM12U320_ERR ("failed to vmap fb: %d\n" , ret); +GM12U320_ERR ("failed to reserve fb: %d\n" , ret); goto put_fb; } + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) { +GM12U320_ERR ("failed to vmap fb: %d\n" , ret); + goto unlock_resv; + } vaddr = map.vaddr;/* TODO: Use mapping abstraction properly */ if (fb->obj[0 ]->import_attach) {@@ -321,8 +326,11 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320)if (ret)GM12U320_ERR ("dma_buf_end_cpu_access err: %d\n" , ret); } + +unlock_resv: +dma_resv_unlock (fb->obj[0 ]->resv); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); put_fb:drm_framebuffer_put (fb); gm12u320->fb_update.fb =NULL ;drivers/gpu/drm/udl/udl_modeset.c +12
-6@@ -290,14 +290,18 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,else if ((clip.x2 > fb->width) || (clip.y2 > fb->height))return -EINVAL ; + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL ); +if (ret) +return ret; +if (import_attach) { ret =dma_buf_begin_cpu_access (import_attach->dmabuf,DMA_FROM_DEVICE );if (ret) -return ret; + goto out_dma_resv_unlock; } - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map);if (ret) {DRM_ERROR ("failed to vmap fb\n" ); goto out_dma_buf_end_cpu_access;@@ -307,7 +311,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, urb =udl_get_urb (dev);if (!urb) { ret = -ENOMEM ; - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; } cmd = urb->transfer_buffer;@@ -320,7 +324,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, &cmd, byte_offset, dev_byte_offset, byte_width);if (ret) - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; }if (cmd > (char *)urb->transfer_buffer) {@@ -336,8 +340,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, ret =0 ; -out_drm_gem_shmem_vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +out_drm_gem_shmem_vunmap_local: +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); out_dma_buf_end_cpu_access:if (import_attach) { tmp_ret = dma_buf_end_cpu_access(import_attach->dmabuf,@@ -345,6 +349,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,if (tmp_ret && !ret) ret = tmp_ret;/* only update ret if not set yet */ } +out_dma_resv_unlock: +dma_resv_unlock (fb->obj[0 ]->resv);return ret; }include/drm/drm_gem_shmem_helper.h +2
-0@@ -114,7 +114,9 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem);int drm_gem_shmem_pin (struct drm_gem_object *obj);void drm_gem_shmem_unpin (struct drm_gem_object *obj);int drm_gem_shmem_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);void drm_gem_shmem_vunmap (struct drm_gem_object *obj,struct dma_buf_map *map); +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);int drm_gem_shmem_madvise (struct drm_gem_object *obj,int madv);Signature · 1 line
2.29.2
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 6/8] drm/shmem-helper: Provide a vmap function for short-term mappings
Quoted 40 lines · Thomas Zimmermann
Hi Daniel
Am 11.12.20 um 10:50 schrieb Daniel Vetter:
[...]Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +26
-0+/** +* drm_gem_shmem_vmap_local - Create a virtual mapping for a shmem GEM object +* @shmem: shmem GEM object +* @map: Returns the kernel virtual address of the SHMEM GEM object's backing +* store. +* +* This function makes sure that a contiguous kernel virtual address mapping +* exists for the buffer backing the shmem GEM object. +* +* The function is called with the BO's reservation object locked. Callers must +* hold the lock until after unmapping the buffer. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. But +* it can also be called by drivers directly, in which case it will hide the +* differences between dma-buf imported and natively allocated objects. +* +* Acquired mappings should be cleaned up by calling drm_gem_shmem_vunmap_local(). +* +* Returns: +* 0 on success or a negative error code on failure. +*/ +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); +int ret; +Quoted 8 lines
drivers/gpu/drm/drm_gem_shmem_helper.c int drm_gem_shmem_vmap(struct drm_gem_object *obj, struct dma_buf_map *map) · line 379
Quoted 3 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +3
-0+dma_resv_assert_held (obj->resv); + + ret =mutex_lock_interruptible (&shmem->vmap_lock);This bites. You need to check for
shmem->import_attachand calldma_buf_vmap_localdirectly here before you take any shmem helper locks. Real fix would be to replace bothvmap_lockandpages_lockwithdma_resvlock, but that's more work. Same forvunmap_local
Quoted 2 lines
This comment confuses me. AFAICT
vmap_lockprotectsvmap_use_count. Why does this exact code work indrm_gem_shmem_vmap()but not in_local()?
You'd hold the dma_resv lock both inside and outside of the ->vmap_lock mutex. Which deadlocks. For the _vmap version we more or less mandate that the caller doens't hold the dma_resv lock already, hence why we can get away with that.
-Daniel
Quoted 269 lines
Best regards
ThomasQuoted 251 lines
With that fixed on the helper part of this patch:
Reviewed-by Daniel Vetter <[email protected]>Quoted 245 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +37
-1+if (ret) +return ret; + ret =drm_gem_shmem_vmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); + +return ret; +} +EXPORT_SYMBOL (drm_gem_shmem_vmap_local); +static void drm_gem_shmem_vunmap_locked (struct drm_gem_shmem_object *shmem,struct dma_buf_map *map) {@@ -366,7 +406,7 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,drm_gem_shmem_put_pages (shmem); } -/* +/** * drm_gem_shmem_vunmap - Unmap a virtual mapping fo a shmem GEM object * @shmem: shmem GEM object * @map: Kernel virtual address where the SHMEM GEM object was mapped @@ -389,6 +429,33 @@ void drm_gem_shmem_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map) }EXPORT_SYMBOL (drm_gem_shmem_vunmap); +/** +* drm_gem_shmem_vunmap_local - Unmap a virtual mapping fo a shmem GEM object +* @shmem: shmem GEM object +* @map: Kernel virtual address where the SHMEM GEM object was mapped +* +* This function cleans up a kernel virtual address mapping acquired by +* drm_gem_shmem_vmap_local(). The mapping is only removed when the use count +* drops to zero. +* +* The function is called with the BO's reservation object locked. +* +* This function can be used to implement &drm_gem_object_funcs.vmap_local. +* But it can also be called by drivers directly, in which case it will hide +* the differences between dma-buf imported and natively allocated objects. +*/ +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map) +{ +struct drm_gem_shmem_object *shmem =to_drm_gem_shmem_obj (obj); + +dma_resv_assert_held (obj->resv); + +mutex_lock (&shmem->vmap_lock); +drm_gem_shmem_vunmap_locked (shmem, map); +mutex_unlock (&shmem->vmap_lock); +} +EXPORT_SYMBOL (drm_gem_shmem_vunmap_local); +struct drm_gem_shmem_object * drm_gem_shmem_create_with_handle(struct drm_file *file_priv, struct drm_device *dev, size_t size,drivers/gpu/drm/mgag200/mgag200_mode.c +13
-3@@ -1552,22 +1552,32 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, struct drm_rect *clip) {struct drm_device *dev = &mdev->base; +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int ret; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (drm_WARN_ON (dev, ret)) -return ;/* BUG: SHMEM BO should always be vmapped */ +return ; + ret =drm_gem_shmem_vmap_local (obj, &map); +if (drm_WARN_ON (dev, ret)) + goto err_dma_resv_unlock;/* BUG: SHMEM BO should always be vmapped */ vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ drm_fb_memcpy_dstclip (mdev->vram, vmap, fb, clip); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (obj, &map); +dma_resv_unlock (obj->resv);/* Always scanout image at VRAM offset 0 */ mgag200_set_startadd (mdev, (u32 )0 );mgag200_set_offset (mdev, fb); + +return ; + +err_dma_resv_unlock: +dma_resv_unlock (obj->resv); } static voiddrivers/gpu/drm/tiny/cirrus.c +8
-2@@ -315,6 +315,7 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, struct drm_rect *rect) {struct cirrus_device *cirrus =to_cirrus (fb->dev); +struct drm_gem_object *obj = fb->obj[0 ];struct dma_buf_map map;void *vmap;int idx, ret;@@ -323,9 +324,12 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,if (!drm_dev_enter (&cirrus->dev, &idx)) goto out; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (obj->resv,NULL );if (ret) goto out_dev_exit; + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) + goto out_dma_resv_unlock; vmap = map.vaddr;/* TODO: Use mapping abstraction properly */ if (cirrus->cpp == fb->format->cpp[0 ])@@ -345,9 +349,11 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,else WARN_ON_ONCE ("cpp mismatch" ); -drm_gem_shmem_vunmap (fb->obj[0 ], &map); ret =0 ; +drm_gem_shmem_vunmap_local (obj, &map); +out_dma_resv_unlock: +dma_resv_unlock (obj->resv); out_dev_exit:drm_dev_exit (idx); out:drivers/gpu/drm/tiny/gm12u320.c +11
-3@@ -265,11 +265,16 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) y1 = gm12u320->fb_update.rect.y1; y2 = gm12u320->fb_update.rect.y2; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL );if (ret) { -GM12U320_ERR ("failed to vmap fb: %d\n" , ret); +GM12U320_ERR ("failed to reserve fb: %d\n" , ret); goto put_fb; } + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map); +if (ret) { +GM12U320_ERR ("failed to vmap fb: %d\n" , ret); + goto unlock_resv; + } vaddr = map.vaddr;/* TODO: Use mapping abstraction properly */ if (fb->obj[0 ]->import_attach) {@@ -321,8 +326,11 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320)if (ret)GM12U320_ERR ("dma_buf_end_cpu_access err: %d\n" , ret); } + +unlock_resv: +dma_resv_unlock (fb->obj[0 ]->resv); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); put_fb:drm_framebuffer_put (fb); gm12u320->fb_update.fb =NULL ;drivers/gpu/drm/udl/udl_modeset.c +12
-6@@ -290,14 +290,18 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,else if ((clip.x2 > fb->width) || (clip.y2 > fb->height))return -EINVAL ; + ret =dma_resv_lock (fb->obj[0 ]->resv,NULL ); +if (ret) +return ret; +if (import_attach) { ret =dma_buf_begin_cpu_access (import_attach->dmabuf,DMA_FROM_DEVICE );if (ret) -return ret; + goto out_dma_resv_unlock; } - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_shmem_vmap_local (fb->obj[0 ], &map);if (ret) {DRM_ERROR ("failed to vmap fb\n" ); goto out_dma_buf_end_cpu_access;@@ -307,7 +311,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, urb =udl_get_urb (dev);if (!urb) { ret = -ENOMEM ; - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; } cmd = urb->transfer_buffer;@@ -320,7 +324,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, &cmd, byte_offset, dev_byte_offset, byte_width);if (ret) - goto out_drm_gem_shmem_vunmap; + goto out_drm_gem_shmem_vunmap_local; }if (cmd > (char *)urb->transfer_buffer) {@@ -336,8 +340,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, ret =0 ; -out_drm_gem_shmem_vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +out_drm_gem_shmem_vunmap_local: +drm_gem_shmem_vunmap_local (fb->obj[0 ], &map); out_dma_buf_end_cpu_access:if (import_attach) { tmp_ret = dma_buf_end_cpu_access(import_attach->dmabuf,@@ -345,6 +349,8 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y,if (tmp_ret && !ret) ret = tmp_ret;/* only update ret if not set yet */ } +out_dma_resv_unlock: +dma_resv_unlock (fb->obj[0 ]->resv);return ret; }include/drm/drm_gem_shmem_helper.h +2
-0@@ -114,7 +114,9 @@ void drm_gem_shmem_put_pages(struct drm_gem_shmem_object *shmem);int drm_gem_shmem_pin (struct drm_gem_object *obj);void drm_gem_shmem_unpin (struct drm_gem_object *obj);int drm_gem_shmem_vmap (struct drm_gem_object *obj,struct dma_buf_map *map); +int drm_gem_shmem_vmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);void drm_gem_shmem_vunmap (struct drm_gem_object *obj,struct dma_buf_map *map); +void drm_gem_shmem_vunmap_local (struct drm_gem_object *obj,struct dma_buf_map *map);Quoted 6 lines
Quoted 5 lines
include/drm/drm_gem_shmem_helper.h +0
-1int drm_gem_shmem_madvise (struct drm_gem_object *obj,int madv); --2.29.2
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 7/8 drm/vram-helper: Provide a vmap function for short-term mappings
In reply to Thomas ZimmermannImplementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. It's somewhat inconvenient to callers that simply require a mapping of the contained memory; and also ipmplies a certain overhead.
Therefore provide drm_gem_vram_vmap_local() drm_gem_vram_vunmap_local(), which only perform the vmap/vunmap operations. Callers have to hold the reservation lock while the mapping persists; or have to pin the BO by themselves.
The affected callers are cursor updates in ast and vboxvideo. Both are being changed to the new interface.
This patch connects GEM VRAM helpers to GEM object functions with equivalent functionality.
--- drivers/gpu/drm/ast/ast_cursor.c | 37 +++++-- drivers/gpu/drm/drm_gem_vram_helper.c | 142 +++++++++++++++++--------- drivers/gpu/drm/vboxvideo/vbox_mode.c | 15 +-- include/drm/drm_gem_vram_helper.h | 2 + 4 files changed, 132 insertions(+), 64 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +27 -10
@@ -159,6 +159,8 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb)struct drm_device *dev = &ast->base;struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index];struct drm_gem_vram_object *src_gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct drm_gem_object *objs[] = {&src_gbo->bo.base, &dst_gbo->bo.base}; +struct ww_acquire_ctx ctx;struct dma_buf_map src_map, dst_map;void __iomem *dst;void *src;
@@ -168,26 +170,34 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb) drm_WARN_ON_ONCE(dev, fb->height > AST_MAX_HWC_HEIGHT)) return -EINVAL; - ret =drm_gem_vram_vmap (src_gbo, &src_map); + ret =drm_gem_lock_reservations (objs,ARRAY_SIZE (objs), &ctx);if (ret)return ret; + + ret =drm_gem_vram_vmap_local (src_gbo, &src_map); +if (ret) + goto err_drm_gem_unlock_reservations; src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ - ret =drm_gem_vram_vmap (dst_gbo, &dst_map); + ret =drm_gem_vram_vmap_local (dst_gbo, &dst_map);if (ret) - goto err_drm_gem_vram_vunmap; + goto err_drm_gem_vram_vunmap_local; dst = dst_map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ /* do data transfer to cursor BO */ update_cursor_image (dst, src, fb->width, fb->height); -drm_gem_vram_vunmap (dst_gbo, &dst_map); -drm_gem_vram_vunmap (src_gbo, &src_map); +drm_gem_vram_vunmap_local (dst_gbo, &dst_map); +drm_gem_vram_vunmap_local (src_gbo, &src_map); + +drm_gem_unlock_reservations (objs,ARRAY_SIZE (objs), &ctx);return 0 ; -err_drm_gem_vram_vunmap: -drm_gem_vram_vunmap (src_gbo, &src_map); +err_drm_gem_vram_vunmap_local: +drm_gem_vram_vunmap_local (src_gbo, &src_map); +err_drm_gem_unlock_reservations: +drm_gem_unlock_reservations (objs,ARRAY_SIZE (objs), &ctx);return ret; }
@@ -241,6 +251,7 @@ void ast_cursor_show(struct ast_private *ast, int x, int y, {struct drm_device *dev = &ast->base;struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct drm_gem_object *obj = &gbo->bo.base;struct dma_buf_map map;u8 x_offset, y_offset;u8 __iomem *dst;
@@ -248,16 +259,22 @@ void ast_cursor_show(struct ast_private *ast, int x, int y,u8 jreg;int ret; - ret =drm_gem_vram_vmap (gbo, &map); -if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap() failed, ret=%d\n" , ret)) + ret =dma_resv_lock (obj->resv,NULL ); +if (ret) +return ; + ret =drm_gem_vram_vmap_local (gbo, &map); +if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap_local() failed, ret=%d\n" , ret)) { +dma_resv_unlock (obj->resv);return ; + } dst = map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ sig = dst +AST_HWC_SIZE ;writel (x, sig +AST_HWC_SIGNATURE_X );writel (y, sig +AST_HWC_SIGNATURE_Y ); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap_local (gbo, &map); +dma_resv_unlock (obj->resv);if (x <0 ) { x_offset = (-x) + offset_x;
drivers/gpu/drm/drm_gem_vram_helper.c +94 -48
178 lines not on this page · raw message
drivers/gpu/drm/vboxvideo/vbox_mode.c +9 -6
@@ -381,7 +381,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, container_of(plane->dev, struct vbox_private, ddev);struct vbox_crtc *vbox_crtc =to_vbox_crtc (plane->state->crtc);struct drm_framebuffer *fb = plane->state->fb; -struct drm_gem_vram_object *gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct drm_gem_object *obj = fb->obj[0 ]; +struct drm_gem_vram_object *gbo =drm_gem_vram_of_gem (obj);u32 width = plane->state->crtc_w;u32 height = plane->state->crtc_h;size_t data_size, mask_size;
@@ -401,11 +402,12 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, vbox_crtc->cursor_enabled = true; - ret =drm_gem_vram_vmap (gbo, &map); + ret =dma_resv_lock (obj->resv,NULL ); +if (ret) +return ; + ret =drm_gem_vram_vmap_local (gbo, &map);if (ret) { -/* -* BUG: we should have pinned the BO in prepare_fb(). -*/ +dma_resv_unlock (obj->resv);mutex_unlock (&vbox->hw_mutex);DRM_WARN ("Could not map cursor bo, skipping update\n" );return ;
@@ -421,7 +423,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, data_size = width * height *4 + mask_size;copy_cursor_image (src, vbox->cursor_data, width, height, mask_size); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap_local (gbo, &map); +dma_resv_unlock (obj->resv); flags =VBOX_MOUSE_POINTER_VISIBLE |VBOX_MOUSE_POINTER_SHAPE |VBOX_MOUSE_POINTER_ALPHA ;
include/drm/drm_gem_vram_helper.h +2 -0
@@ -99,6 +99,8 @@ int drm_gem_vram_pin(struct drm_gem_vram_object *gbo, unsigned long pl_flag);int drm_gem_vram_unpin (struct drm_gem_vram_object *gbo);int drm_gem_vram_vmap (struct drm_gem_vram_object *gbo,struct dma_buf_map *map);void drm_gem_vram_vunmap (struct drm_gem_vram_object *gbo,struct dma_buf_map *map); +int drm_gem_vram_vmap_local (struct drm_gem_vram_object *gbo,struct dma_buf_map *map); +void drm_gem_vram_vunmap_local (struct drm_gem_vram_object *gbo,struct dma_buf_map *map); int drm_gem_vram_fill_create_dumb(struct drm_file *file, struct drm_device *dev,
Signature · 6 lines
2.29.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v3 7/8] drm/vram-helper: Provide a vmap function for short-term mappings
Quoted 13 lines · Thomas Zimmermann
Implementations of the vmap/vunmap GEM callbacks may perform pinning of the BO and may acquire the associated reservation object's lock. It's somewhat inconvenient to callers that simply require a mapping of the contained memory; and also ipmplies a certain overhead.
Therefore provide
drm_gem_vram_vmap_local()drm_gem_vram_vunmap_local(), which only perform the vmap/vunmap operations. Callers have to hold the reservation lock while the mapping persists; or have to pin the BO by themselves.The affected callers are cursor updates in ast and vboxvideo. Both are being changed to the new interface.
Quoted 6 lines
This patch connects GEM VRAM helpers to GEM object functions with equivalent functionality.
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_cursor.c | 37 +++++--
Again I'd split out the driver parts. I didn't come up with a hard functional reason for this though.
Quoted 169 lines
drivers/gpu/drm/drm_gem_vram_helper.c | 142 +++++++++++++++++--------- drivers/gpu/drm/vboxvideo/vbox_mode.c | 15 +-- include/drm/drm_gem_vram_helper.h | 2 + 4 files changed, 132 insertions(+), 64 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +27
-10@@ -159,6 +159,8 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb)struct drm_device *dev = &ast->base;struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index];struct drm_gem_vram_object *src_gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct drm_gem_object *objs[] = {&src_gbo->bo.base, &dst_gbo->bo.base}; +struct ww_acquire_ctx ctx;struct dma_buf_map src_map, dst_map;void __iomem *dst;void *src;@@ -168,26 +170,34 @@ int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb) drm_WARN_ON_ONCE(dev, fb->height > AST_MAX_HWC_HEIGHT)) return -EINVAL; - ret =drm_gem_vram_vmap (src_gbo, &src_map); + ret =drm_gem_lock_reservations (objs,ARRAY_SIZE (objs), &ctx);if (ret)return ret; + + ret =drm_gem_vram_vmap_local (src_gbo, &src_map); +if (ret) + goto err_drm_gem_unlock_reservations; src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ - ret =drm_gem_vram_vmap (dst_gbo, &dst_map); + ret =drm_gem_vram_vmap_local (dst_gbo, &dst_map);if (ret) - goto err_drm_gem_vram_vunmap; + goto err_drm_gem_vram_vunmap_local; dst = dst_map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ /* do data transfer to cursor BO */ update_cursor_image (dst, src, fb->width, fb->height); -drm_gem_vram_vunmap (dst_gbo, &dst_map); -drm_gem_vram_vunmap (src_gbo, &src_map); +drm_gem_vram_vunmap_local (dst_gbo, &dst_map); +drm_gem_vram_vunmap_local (src_gbo, &src_map); + +drm_gem_unlock_reservations (objs,ARRAY_SIZE (objs), &ctx);return 0 ; -err_drm_gem_vram_vunmap: -drm_gem_vram_vunmap (src_gbo, &src_map); +err_drm_gem_vram_vunmap_local: +drm_gem_vram_vunmap_local (src_gbo, &src_map); +err_drm_gem_unlock_reservations: +drm_gem_unlock_reservations (objs,ARRAY_SIZE (objs), &ctx);return ret; }@@ -241,6 +251,7 @@ void ast_cursor_show(struct ast_private *ast, int x, int y, {struct drm_device *dev = &ast->base;struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index]; +struct drm_gem_object *obj = &gbo->bo.base;struct dma_buf_map map;u8 x_offset, y_offset;u8 __iomem *dst;@@ -248,16 +259,22 @@ void ast_cursor_show(struct ast_private *ast, int x, int y,u8 jreg;int ret; - ret =drm_gem_vram_vmap (gbo, &map); -if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap() failed, ret=%d\n" , ret)) + ret =dma_resv_lock (obj->resv,NULL ); +if (ret) +return ; + ret =drm_gem_vram_vmap_local (gbo, &map); +if (drm_WARN_ONCE (dev, ret,"drm_gem_vram_vmap_local() failed, ret=%d\n" , ret)) { +dma_resv_unlock (obj->resv);return ; + } dst = map.vaddr_iomem;/* TODO: Use mapping abstraction properly */ sig = dst +AST_HWC_SIZE ;writel (x, sig +AST_HWC_SIGNATURE_X );writel (y, sig +AST_HWC_SIGNATURE_Y ); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap_local (gbo, &map); +dma_resv_unlock (obj->resv);if (x <0 ) { x_offset = (-x) + offset_x;drivers/gpu/drm/drm_gem_vram_helper.c +4
-43@@ -379,47 +379,6 @@ int drm_gem_vram_unpin(struct drm_gem_vram_object *gbo) }EXPORT_SYMBOL (drm_gem_vram_unpin); -static int drm_gem_vram_kmap_locked (struct drm_gem_vram_object *gbo, -struct dma_buf_map *map) -{ -int ret; - -if (gbo->vmap_use_count >0 ) - goto out; - - ret =ttm_bo_vmap (&gbo->bo, &gbo->map); -if (ret) -return ret; - -out: - ++gbo->vmap_use_count; - *map = gbo->map; - -return 0 ; -} - -static void drm_gem_vram_kunmap_locked (struct drm_gem_vram_object *gbo, -struct dma_buf_map *map) -{ -struct drm_device *dev = gbo->bo.base.dev; - -if (drm_WARN_ON_ONCE (dev, !gbo->vmap_use_count)) -return ; - -if (drm_WARN_ON_ONCE (dev, !dma_buf_map_is_equal (&gbo->map, map))) -return ;/* BUG: map not mapped from this BO */ - -if (--gbo->vmap_use_count >0 ) -return ; - -/* -* Permanently mapping and unmapping buffers adds overhead from -* updating the page tables and creates debugging output. Therefore, -* we delay the actual unmap operation until the BO gets evicted -* from memory. See drm_gem_vram_bo_driver_move_notify(). -*/ -} -/** * drm_gem_vram_vmap() - Pins and maps a GEM VRAM object into kernel address * space @@ -447,7 +406,7 @@ int drm_gem_vram_vmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *map) ret =drm_gem_vram_pin_locked (gbo,0 );if (ret) goto err_ttm_bo_unreserve; - ret =drm_gem_vram_kmap_locked (gbo, map); + ret =drm_gem_vram_vmap_local (gbo, map);if (ret) goto err_drm_gem_vram_unpin_locked;@@ -479,13 +438,84 @@ void drm_gem_vram_vunmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *maif (WARN_ONCE (ret,"ttm_bo_reserve_failed(): ret=%d\n" , ret))return ; -drm_gem_vram_kunmap_locked (gbo, map); +drm_gem_vram_vunmap_local (gbo, map);drm_gem_vram_unpin_locked (gbo);ttm_bo_unreserve (&gbo->bo); }EXPORT_SYMBOL (drm_gem_vram_vunmap); +/** +* drm_gem_vram_vmap_local() - Maps a GEM VRAM object into kernel address space
drivers/gpu/drm/drm_gem_vram_helper.c void drm_gem_vram_vunmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *ma · line 459
Quoted 10 lines
drivers/gpu/drm/drm_gem_vram_helper.c +10
-0+* @gbo: The GEM VRAM object to map +* @map: Returns the kernel virtual address of the VRAM GEM object's backing +* store. +* +* The vmap_local function maps the buffer of a GEM VRAM object into kernel address +* space. Call drm_gem_vram_vunmap_local() with the returned address to unmap and +* unpin the GEM VRAM object. +* +* The function is called with the BO's reservation object locked. For short-term +* mappings, callers must hold the lock until after unmapping the buffer. For
"the lock" is unclear, please mention the exact lock and maybe how to lock it. This is the first time we have a vram helper function which requires callers to lock, so better safe than sorry :-)
drivers/gpu/drm/drm_gem_vram_helper.c void drm_gem_vram_vunmap(struct drm_gem_vram_object *gbo, struct dma_buf_map *ma · line 461
Quoted 2 lines
drivers/gpu/drm/drm_gem_vram_helper.c +2
-0+* long-term mappings, callers are required to pin the BO to it's current location +* before calling this function.
With the dma_resv_assert_held the 2nd use-case kinda doesn't work, since there we'd access without the dma_resv_lock. I'd just drop that sentence.
For the vram helper part, with the kerneldoc polished:
Quoted 156 lines
drivers/gpu/drm/drm_gem_vram_helper.c +78
-5+* +* Returns: +* 0 on success, or a negative error code otherwise. +*/ +int drm_gem_vram_vmap_local (struct drm_gem_vram_object *gbo,struct dma_buf_map *map) +{ +int ret; + +dma_resv_assert_held (gbo->bo.base.resv); + +if (gbo->vmap_use_count >0 ) + goto out; + + ret =ttm_bo_vmap (&gbo->bo, &gbo->map); +if (ret) +return ret; + +out: + ++gbo->vmap_use_count; + *map = gbo->map; + +return 0 ; +} +EXPORT_SYMBOL (drm_gem_vram_vmap_local); + +/** +* drm_gem_vram_vunmap_local() - Unmaps a GEM VRAM object +* @gbo: The GEM VRAM object to unmap +* @map: Kernel virtual address where the VRAM GEM object was mapped +* +* A call to drm_gem_vram_vunmap_local() unmaps a GEM VRAM object's buffer. See +* the documentation for drm_gem_vram_vmap_local() for more information. +*/ +void drm_gem_vram_vunmap_local (struct drm_gem_vram_object *gbo,struct dma_buf_map *map) +{ +struct drm_device *dev = gbo->bo.base.dev; + +dma_resv_assert_held (gbo->bo.base.resv); + +if (drm_WARN_ON_ONCE (dev, !gbo->vmap_use_count)) +return ; + +if (drm_WARN_ON_ONCE (dev, !dma_buf_map_is_equal (&gbo->map, map))) +return ;/* BUG: map not mapped from this BO */ + +if (--gbo->vmap_use_count >0 ) +return ; + +/* +* Permanently mapping and unmapping buffers adds overhead from +* updating the page tables and creates debugging output. Therefore, +* we delay the actual unmap operation until the BO gets evicted +* from memory. See drm_gem_vram_bo_driver_move_notify(). +*/ +} +EXPORT_SYMBOL (drm_gem_vram_vunmap_local); +/** * drm_gem_vram_fill_create_dumb() - \ Helper for implementing &struct drm_driver.dumb_create @@ -871,17 +901,33 @@ static void drm_gem_vram_object_vunmap(struct drm_gem_object *gem, struct dma_budrm_gem_vram_vunmap (gbo, map); } +static int drm_gem_vram_object_vmap_local (struct drm_gem_object *gem,struct dma_buf_map *map) +{ +struct drm_gem_vram_object *gbo =drm_gem_vram_of_gem (gem); + +return drm_gem_vram_vmap_local (gbo, map); +} + +static void drm_gem_vram_object_vunmap_local (struct drm_gem_object *gem,struct dma_buf_map *map) +{ +struct drm_gem_vram_object *gbo =drm_gem_vram_of_gem (gem); + +drm_gem_vram_vunmap_local (gbo, map); +} +/* * GEM object funcs */ static const struct drm_gem_object_funcs drm_gem_vram_object_funcs = { - .free = drm_gem_vram_object_free, - .pin = drm_gem_vram_object_pin, - .unpin = drm_gem_vram_object_unpin, - .vmap = drm_gem_vram_object_vmap, + .free = drm_gem_vram_object_free, + .pin = drm_gem_vram_object_pin, + .unpin = drm_gem_vram_object_unpin, + .vmap = drm_gem_vram_object_vmap, .vunmap = drm_gem_vram_object_vunmap, - .mmap = drm_gem_ttm_mmap, + .vmap_local = drm_gem_vram_object_vmap_local, + .vunmap_local = drm_gem_vram_object_vunmap_local, + .mmap = drm_gem_ttm_mmap, .print_info = drm_gem_ttm_print_info, };drivers/gpu/drm/vboxvideo/vbox_mode.c +9
-6@@ -381,7 +381,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, container_of(plane->dev, struct vbox_private, ddev);struct vbox_crtc *vbox_crtc =to_vbox_crtc (plane->state->crtc);struct drm_framebuffer *fb = plane->state->fb; -struct drm_gem_vram_object *gbo =drm_gem_vram_of_gem (fb->obj[0 ]); +struct drm_gem_object *obj = fb->obj[0 ]; +struct drm_gem_vram_object *gbo =drm_gem_vram_of_gem (obj);u32 width = plane->state->crtc_w;u32 height = plane->state->crtc_h;size_t data_size, mask_size;@@ -401,11 +402,12 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, vbox_crtc->cursor_enabled = true; - ret =drm_gem_vram_vmap (gbo, &map); + ret =dma_resv_lock (obj->resv,NULL ); +if (ret) +return ; + ret =drm_gem_vram_vmap_local (gbo, &map);if (ret) { -/* -* BUG: we should have pinned the BO in prepare_fb(). -*/ +dma_resv_unlock (obj->resv);mutex_unlock (&vbox->hw_mutex);DRM_WARN ("Could not map cursor bo, skipping update\n" );return ;@@ -421,7 +423,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, data_size = width * height *4 + mask_size;copy_cursor_image (src, vbox->cursor_data, width, height, mask_size); -drm_gem_vram_vunmap (gbo, &map); +drm_gem_vram_vunmap_local (gbo, &map); +dma_resv_unlock (obj->resv); flags =VBOX_MOUSE_POINTER_VISIBLE |VBOX_MOUSE_POINTER_SHAPE |VBOX_MOUSE_POINTER_ALPHA ;include/drm/drm_gem_vram_helper.h +2
-0@@ -99,6 +99,8 @@ int drm_gem_vram_pin(struct drm_gem_vram_object *gbo, unsigned long pl_flag);int drm_gem_vram_unpin (struct drm_gem_vram_object *gbo);int drm_gem_vram_vmap (struct drm_gem_vram_object *gbo,struct dma_buf_map *map);void drm_gem_vram_vunmap (struct drm_gem_vram_object *gbo,struct dma_buf_map *map); +int drm_gem_vram_vmap_local (struct drm_gem_vram_object *gbo,struct dma_buf_map *map); +void drm_gem_vram_vunmap_local (struct drm_gem_vram_object *gbo,struct dma_buf_map *map); int drm_gem_vram_fill_create_dumb(struct drm_file *file, struct drm_device *dev,Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH v3 8/8 drm/fb-helper: Move BO locking from DRM client to fbdev damage worker
In reply to Thomas ZimmermannFbdev emulation has to lock the BO into place while flushing the shadow buffer into the BO's memory. Remove any interference with pinning by using vmap_local functionality (instead of full vmap). This requires BO reservation locking in fbdev's damage worker.
The new DRM client functions for locking and vmap_local functionality are added for consistency with the existing style.
--- drivers/gpu/drm/drm_client.c | 91 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_fb_helper.c | 41 +++++++-------- include/drm/drm_client.h | 4 ++ 3 files changed, 116 insertions(+), 20 deletions(-)
drivers/gpu/drm/drm_client.c +91 -0
@@ -288,6 +288,37 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, ureturn ERR_PTR (ret); } +/** +* drm_client_buffer_lock - Locks the DRM client buffer +* @buffer: DRM client buffer +* +* This function locks the client buffer by acquiring the buffer +* object's reservation lock. +* +* Unlock the buffer with drm_client_buffer_unlock(). +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_lock (struct drm_client_buffer *buffer) +{ +return dma_resv_lock (buffer->gem->resv,NULL ); +} +EXPORT_SYMBOL (drm_client_buffer_lock); + +/** +* drm_client_buffer_unlock - Unlock DRM client buffer +* @buffer: DRM client buffer +* +* Unlocks a client buffer. See drm_client_buffer_lock(). +*/ +void drm_client_buffer_unlock (struct drm_client_buffer *buffer) +{ +dma_resv_unlock (buffer->gem->resv); +} +EXPORT_SYMBOL (drm_client_buffer_unlock); +/** * drm_client_buffer_vmap - Map DRM client buffer into address space * @buffer: DRM client buffer
@@ -348,6 +379,66 @@ void drm_client_buffer_vunmap(struct drm_client_buffer *buffer) }EXPORT_SYMBOL (drm_client_buffer_vunmap); +/** +* drm_client_buffer_vmap_local - Map DRM client buffer into address space +* @buffer: DRM client buffer +* @map_copy: Returns the mapped memory's address +* +* This function maps a client buffer into kernel address space. If the +* buffer is already mapped, it returns the existing mapping's address. +* +* Client buffer mappings are not ref'counted. Each call to +* drm_client_buffer_vmap_local() should be followed by a call to +* drm_client_buffer_vunmap_local(); or the client buffer should be mapped +* throughout its lifetime. +* +* The returned address is a copy of the internal value. In contrast to +* other vmap interfaces, you don't need it for the client's vunmap +* function. So you can modify it at will during blit and draw operations. +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map_copy) +{ +struct dma_buf_map *map = &buffer->map; +int ret; + +/* +* FIXME: The dependency on GEM here isn't required, we could +* convert the driver handle to a dma-buf instead and use the +* backend-agnostic dma-buf vmap_local support instead. This would +* require that the handle2fd prime ioctl is reworked to pull the +* fd_install step out of the driver backend hooks, to make that +* final step optional for internal users. +*/ + ret =drm_gem_vmap_local (buffer->gem, map); +if (ret) +return ret; + + *map_copy = *map; + +return 0 ; +} +EXPORT_SYMBOL (drm_client_buffer_vmap_local); + +/** +* drm_client_buffer_vunmap_local - Unmap DRM client buffer +* @buffer: DRM client buffer +* +* This function removes a client buffer's memory mapping. Calling this +* function is only required by clients that manage their buffer mappings +* by themselves. +*/ +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer) +{ +struct dma_buf_map *map = &buffer->map; + +drm_gem_vunmap_local (buffer->gem, map); +} +EXPORT_SYMBOL (drm_client_buffer_vunmap_local); +static void drm_client_buffer_rmfb (struct drm_client_buffer *buffer) {int ret;
drivers/gpu/drm/drm_fb_helper.c +21 -20
73 lines not on this page · raw message
include/drm/drm_client.h +4 -0
@@ -156,8 +156,12 @@ struct drm_client_buffer * drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);void drm_client_framebuffer_delete (struct drm_client_buffer *buffer);int drm_client_framebuffer_flush (struct drm_client_buffer *buffer,struct drm_rect *rect); +int drm_client_buffer_lock (struct drm_client_buffer *buffer); +void drm_client_buffer_unlock (struct drm_client_buffer *buffer);int drm_client_buffer_vmap (struct drm_client_buffer *buffer,struct dma_buf_map *map);void drm_client_buffer_vunmap (struct drm_client_buffer *buffer); +int drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map); +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer);int drm_client_modeset_create (struct drm_client_dev *client);void drm_client_modeset_free (struct drm_client_dev *client);
Signature · 6 lines
2.29.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 8/8] drm/fb-helper: Move BO locking from DRM client to fbdev damage worker
Quoted 9 lines · Thomas Zimmermann
Fbdev emulation has to lock the BO into place while flushing the shadow buffer into the BO's memory. Remove any interference with pinning by using
vmap_localfunctionality (instead of full vmap). This requires BO reservation locking in fbdev's damage worker.The new DRM client functions for locking and
vmap_localfunctionality are added for consistency with the existing style.Signed-off-by Thomas Zimmermann <[email protected]>
The old vmap/vunmap in the client library aren't used anymore, please delete. That will also make it clearer in the diff what's going on and that it makes sense to have the client and fb-helper part in one patch.
With that: Reviewed-by: Daniel Vetter <[email protected]>
Quoted 215 lines
--- drivers/gpu/drm/drm_client.c | 91 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_fb_helper.c | 41 +++++++-------- include/drm/drm_client.h | 4 ++ 3 files changed, 116 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_client.c +91
-0@@ -288,6 +288,37 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, ureturn ERR_PTR (ret); } +/** +* drm_client_buffer_lock - Locks the DRM client buffer +* @buffer: DRM client buffer +* +* This function locks the client buffer by acquiring the buffer +* object's reservation lock. +* +* Unlock the buffer with drm_client_buffer_unlock(). +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_lock (struct drm_client_buffer *buffer) +{ +return dma_resv_lock (buffer->gem->resv,NULL ); +} +EXPORT_SYMBOL (drm_client_buffer_lock); + +/** +* drm_client_buffer_unlock - Unlock DRM client buffer +* @buffer: DRM client buffer +* +* Unlocks a client buffer. See drm_client_buffer_lock(). +*/ +void drm_client_buffer_unlock (struct drm_client_buffer *buffer) +{ +dma_resv_unlock (buffer->gem->resv); +} +EXPORT_SYMBOL (drm_client_buffer_unlock); +/** * drm_client_buffer_vmap - Map DRM client buffer into address space * @buffer: DRM client buffer @@ -348,6 +379,66 @@ void drm_client_buffer_vunmap(struct drm_client_buffer *buffer) }EXPORT_SYMBOL (drm_client_buffer_vunmap); +/** +* drm_client_buffer_vmap_local - Map DRM client buffer into address space +* @buffer: DRM client buffer +* @map_copy: Returns the mapped memory's address +* +* This function maps a client buffer into kernel address space. If the +* buffer is already mapped, it returns the existing mapping's address. +* +* Client buffer mappings are not ref'counted. Each call to +* drm_client_buffer_vmap_local() should be followed by a call to +* drm_client_buffer_vunmap_local(); or the client buffer should be mapped +* throughout its lifetime. +* +* The returned address is a copy of the internal value. In contrast to +* other vmap interfaces, you don't need it for the client's vunmap +* function. So you can modify it at will during blit and draw operations. +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map_copy) +{ +struct dma_buf_map *map = &buffer->map; +int ret; + +/* +* FIXME: The dependency on GEM here isn't required, we could +* convert the driver handle to a dma-buf instead and use the +* backend-agnostic dma-buf vmap_local support instead. This would +* require that the handle2fd prime ioctl is reworked to pull the +* fd_install step out of the driver backend hooks, to make that +* final step optional for internal users. +*/ + ret =drm_gem_vmap_local (buffer->gem, map); +if (ret) +return ret; + + *map_copy = *map; + +return 0 ; +} +EXPORT_SYMBOL (drm_client_buffer_vmap_local); + +/** +* drm_client_buffer_vunmap_local - Unmap DRM client buffer +* @buffer: DRM client buffer +* +* This function removes a client buffer's memory mapping. Calling this +* function is only required by clients that manage their buffer mappings +* by themselves. +*/ +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer) +{ +struct dma_buf_map *map = &buffer->map; + +drm_gem_vunmap_local (buffer->gem, map); +} +EXPORT_SYMBOL (drm_client_buffer_vunmap_local); +static void drm_client_buffer_rmfb (struct drm_client_buffer *buffer) {int ret;drivers/gpu/drm/drm_fb_helper.c +21
-20@@ -399,28 +399,34 @@ static int drm_fb_helper_damage_blit(struct drm_fb_helper *fb_helper,int ret;/* -* We have to pin the client buffer to its current location while -* flushing the shadow buffer. In the general case, concurrent -* modesetting operations could try to move the buffer and would -* fail. The modeset has to be serialized by acquiring the reservation -* object of the underlying BO here. -* * For fbdev emulation, we only have to protect against fbdev modeset * operations. Nothing else will involve the client buffer's BO. So it * is sufficient to acquire struct drm_fb_helper.lock here. */ mutex_lock (&fb_helper->lock); - ret =drm_client_buffer_vmap (buffer, &map); +/* +* We have to keep the client buffer at its current location while +* flushing the shadow buffer. Concurrent operations could otherwise +* try to move the buffer. Therefore acquiring the reservation +* object of the underlying BO here. +*/ + ret =drm_client_buffer_lock (buffer); +if (ret) + goto out_mutex_unlock; + + ret =drm_client_buffer_vmap_local (buffer, &map);if (ret) - goto out; + goto out_drm_client_buffer_unlock; dst = map;drm_fb_helper_damage_blit_real (fb_helper, clip, &dst); -drm_client_buffer_vunmap (buffer); +drm_client_buffer_vunmap_local (buffer); -out: +out_drm_client_buffer_unlock: +drm_client_buffer_unlock (buffer); +out_mutex_unlock:mutex_unlock (&fb_helper->lock);return ret;@@ -946,15 +952,11 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info)drm_modeset_lock_all (fb_helper->dev);drm_client_for_each_modeset (modeset, &fb_helper->client) { crtc = modeset->crtc; -if (!crtc->funcs->gamma_set || !crtc->gamma_size) { - ret = -EINVAL ; - goto out; - } +if (!crtc->funcs->gamma_set || !crtc->gamma_size) +return -EINVAL ; -if (cmap->start + cmap->len > crtc->gamma_size) { - ret = -EINVAL ; - goto out; - } +if (cmap->start + cmap->len > crtc->gamma_size) +return -EINVAL ; r = crtc->gamma_store; g = r + crtc->gamma_size;@@ -967,9 +969,8 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info) ret = crtc->funcs->gamma_set (crtc, r, g, b, crtc->gamma_size,NULL );if (ret) - goto out; +return ret; } -out:drm_modeset_unlock_all (fb_helper->dev);return ret;include/drm/drm_client.h +4
-0@@ -156,8 +156,12 @@ struct drm_client_buffer * drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);void drm_client_framebuffer_delete (struct drm_client_buffer *buffer);int drm_client_framebuffer_flush (struct drm_client_buffer *buffer,struct drm_rect *rect); +int drm_client_buffer_lock (struct drm_client_buffer *buffer); +void drm_client_buffer_unlock (struct drm_client_buffer *buffer);int drm_client_buffer_vmap (struct drm_client_buffer *buffer,struct dma_buf_map *map);void drm_client_buffer_vunmap (struct drm_client_buffer *buffer); +int drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map); +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer);int drm_client_modeset_create (struct drm_client_dev *client);void drm_client_modeset_free (struct drm_client_dev *client);Signature · 1 line
2.29.2
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH v3 8/8] drm/fb-helper: Move BO locking from DRM client to fbdev damage worker
Hi
Am 11.12.20 um 11:01 schrieb Daniel Vetter:
Quoted 6 lines · Thomas Zimmermann
Quoted 5 lines
Fbdev emulation has to lock the BO into place while flushing the shadow buffer into the BO's memory. Remove any interference with pinning by using
vmap_localfunctionality (instead of full vmap). This requires BO reservation locking in fbdev's damage worker.
Quoted 8 lines
Quoted 4 lines
The new DRM client functions for locking and
vmap_localfunctionality are added for consistency with the existing style.Signed-off-by Thomas Zimmermann <[email protected]>The old vmap/vunmap in the client library aren't used anymore, please delete. That will also make it clearer in the diff what's going on and that it makes sense to have the client and fb-helper part in one patch.
They are still around for perma-mapped BOs where HW supports it (really only CMA-based drivers). See drm_fb_helper_generic_probe() and drm_fbdev_cleanup().
Best regards
Thomas
Quoted 219 lines
With that: Reviewed-by: Daniel Vetter <[email protected]>
Quoted 215 lines
--- drivers/gpu/drm/drm_client.c | 91 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_fb_helper.c | 41 +++++++-------- include/drm/drm_client.h | 4 ++ 3 files changed, 116 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_client.c +91
-0@@ -288,6 +288,37 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, ureturn ERR_PTR (ret); } +/** +* drm_client_buffer_lock - Locks the DRM client buffer +* @buffer: DRM client buffer +* +* This function locks the client buffer by acquiring the buffer +* object's reservation lock. +* +* Unlock the buffer with drm_client_buffer_unlock(). +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_lock (struct drm_client_buffer *buffer) +{ +return dma_resv_lock (buffer->gem->resv,NULL ); +} +EXPORT_SYMBOL (drm_client_buffer_lock); + +/** +* drm_client_buffer_unlock - Unlock DRM client buffer +* @buffer: DRM client buffer +* +* Unlocks a client buffer. See drm_client_buffer_lock(). +*/ +void drm_client_buffer_unlock (struct drm_client_buffer *buffer) +{ +dma_resv_unlock (buffer->gem->resv); +} +EXPORT_SYMBOL (drm_client_buffer_unlock); +/** * drm_client_buffer_vmap - Map DRM client buffer into address space * @buffer: DRM client buffer @@ -348,6 +379,66 @@ void drm_client_buffer_vunmap(struct drm_client_buffer *buffer) }EXPORT_SYMBOL (drm_client_buffer_vunmap); +/** +* drm_client_buffer_vmap_local - Map DRM client buffer into address space +* @buffer: DRM client buffer +* @map_copy: Returns the mapped memory's address +* +* This function maps a client buffer into kernel address space. If the +* buffer is already mapped, it returns the existing mapping's address. +* +* Client buffer mappings are not ref'counted. Each call to +* drm_client_buffer_vmap_local() should be followed by a call to +* drm_client_buffer_vunmap_local(); or the client buffer should be mapped +* throughout its lifetime. +* +* The returned address is a copy of the internal value. In contrast to +* other vmap interfaces, you don't need it for the client's vunmap +* function. So you can modify it at will during blit and draw operations. +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map_copy) +{ +struct dma_buf_map *map = &buffer->map; +int ret; + +/* +* FIXME: The dependency on GEM here isn't required, we could +* convert the driver handle to a dma-buf instead and use the +* backend-agnostic dma-buf vmap_local support instead. This would +* require that the handle2fd prime ioctl is reworked to pull the +* fd_install step out of the driver backend hooks, to make that +* final step optional for internal users. +*/ + ret =drm_gem_vmap_local (buffer->gem, map); +if (ret) +return ret; + + *map_copy = *map; + +return 0 ; +} +EXPORT_SYMBOL (drm_client_buffer_vmap_local); + +/** +* drm_client_buffer_vunmap_local - Unmap DRM client buffer +* @buffer: DRM client buffer +* +* This function removes a client buffer's memory mapping. Calling this +* function is only required by clients that manage their buffer mappings +* by themselves. +*/ +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer) +{ +struct dma_buf_map *map = &buffer->map; + +drm_gem_vunmap_local (buffer->gem, map); +} +EXPORT_SYMBOL (drm_client_buffer_vunmap_local); +static void drm_client_buffer_rmfb (struct drm_client_buffer *buffer) {int ret;drivers/gpu/drm/drm_fb_helper.c +21
-20@@ -399,28 +399,34 @@ static int drm_fb_helper_damage_blit(struct drm_fb_helper *fb_helper,int ret;/* -* We have to pin the client buffer to its current location while -* flushing the shadow buffer. In the general case, concurrent -* modesetting operations could try to move the buffer and would -* fail. The modeset has to be serialized by acquiring the reservation -* object of the underlying BO here. -* * For fbdev emulation, we only have to protect against fbdev modeset * operations. Nothing else will involve the client buffer's BO. So it * is sufficient to acquire struct drm_fb_helper.lock here. */ mutex_lock (&fb_helper->lock); - ret =drm_client_buffer_vmap (buffer, &map); +/* +* We have to keep the client buffer at its current location while +* flushing the shadow buffer. Concurrent operations could otherwise +* try to move the buffer. Therefore acquiring the reservation +* object of the underlying BO here. +*/ + ret =drm_client_buffer_lock (buffer); +if (ret) + goto out_mutex_unlock; + + ret =drm_client_buffer_vmap_local (buffer, &map);if (ret) - goto out; + goto out_drm_client_buffer_unlock; dst = map;drm_fb_helper_damage_blit_real (fb_helper, clip, &dst); -drm_client_buffer_vunmap (buffer); +drm_client_buffer_vunmap_local (buffer); -out: +out_drm_client_buffer_unlock: +drm_client_buffer_unlock (buffer); +out_mutex_unlock:mutex_unlock (&fb_helper->lock);return ret;@@ -946,15 +952,11 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info)drm_modeset_lock_all (fb_helper->dev);drm_client_for_each_modeset (modeset, &fb_helper->client) { crtc = modeset->crtc; -if (!crtc->funcs->gamma_set || !crtc->gamma_size) { - ret = -EINVAL ; - goto out; - } +if (!crtc->funcs->gamma_set || !crtc->gamma_size) +return -EINVAL ; -if (cmap->start + cmap->len > crtc->gamma_size) { - ret = -EINVAL ; - goto out; - } +if (cmap->start + cmap->len > crtc->gamma_size) +return -EINVAL ; r = crtc->gamma_store; g = r + crtc->gamma_size;@@ -967,9 +969,8 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info) ret = crtc->funcs->gamma_set (crtc, r, g, b, crtc->gamma_size,NULL );if (ret) - goto out; +return ret; } -out:drm_modeset_unlock_all (fb_helper->dev);return ret;include/drm/drm_client.h +4
-0@@ -156,8 +156,12 @@ struct drm_client_buffer * drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);void drm_client_framebuffer_delete (struct drm_client_buffer *buffer);int drm_client_framebuffer_flush (struct drm_client_buffer *buffer,struct drm_rect *rect); +int drm_client_buffer_lock (struct drm_client_buffer *buffer); +void drm_client_buffer_unlock (struct drm_client_buffer *buffer);int drm_client_buffer_vmap (struct drm_client_buffer *buffer,struct dma_buf_map *map);void drm_client_buffer_vunmap (struct drm_client_buffer *buffer); +int drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map); +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer);int drm_client_modeset_create (struct drm_client_dev *client);void drm_client_modeset_free (struct drm_client_dev *client);Signature · 1 line
2.29.2
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v3 8/8] drm/fb-helper: Move BO locking from DRM client to fbdev damage worker
Quoted 14 lines · Thomas Zimmermann
Hi
Am 11.12.20 um 11:01 schrieb Daniel Vetter:
Quoted 11 lines · Thomas Zimmermann
Quoted 9 lines
Fbdev emulation has to lock the BO into place while flushing the shadow buffer into the BO's memory. Remove any interference with pinning by using
vmap_localfunctionality (instead of full vmap). This requires BO reservation locking in fbdev's damage worker.The new DRM client functions for locking and
vmap_localfunctionality are added for consistency with the existing style.Signed-off-by Thomas Zimmermann <[email protected]>
Quoted 7 lines
Quoted 3 lines
The old vmap/vunmap in the client library aren't used anymore, please delete. That will also make it clearer in the diff what's going on and that it makes sense to have the client and fb-helper part in one patch.
They are still around for perma-mapped BOs where HW supports it (really only CMA-based drivers). See
drm_fb_helper_generic_probe()anddrm_fbdev_cleanup().
Ah right I didn't grep this carefully enough. I guess in that case splitting this into the drm_client patch and fb-helper patch would be good I think.
Also some kerneldoc commment addition for normal vmap that vmap_local is preferred for short-term mappings, and for vmap_local that _vmap() gives you the long term mapping. Just for more links and stuff in docs.
With that: Reviewed-by: Daniel Vetter <[email protected]> -Daniel
Quoted 220 lines
Best regards
ThomasQuoted 207 lines
With that: Reviewed-by: Daniel Vetter <[email protected]>
Quoted 203 lines
--- drivers/gpu/drm/drm_client.c | 91 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_fb_helper.c | 41 +++++++-------- include/drm/drm_client.h | 4 ++ 3 files changed, 116 insertions(+), 20 deletions(-)drivers/gpu/drm/drm_client.c +91
-0@@ -288,6 +288,37 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, ureturn ERR_PTR (ret); } +/** +* drm_client_buffer_lock - Locks the DRM client buffer +* @buffer: DRM client buffer +* +* This function locks the client buffer by acquiring the buffer +* object's reservation lock. +* +* Unlock the buffer with drm_client_buffer_unlock(). +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_lock (struct drm_client_buffer *buffer) +{ +return dma_resv_lock (buffer->gem->resv,NULL ); +} +EXPORT_SYMBOL (drm_client_buffer_lock); + +/** +* drm_client_buffer_unlock - Unlock DRM client buffer +* @buffer: DRM client buffer +* +* Unlocks a client buffer. See drm_client_buffer_lock(). +*/ +void drm_client_buffer_unlock (struct drm_client_buffer *buffer) +{ +dma_resv_unlock (buffer->gem->resv); +} +EXPORT_SYMBOL (drm_client_buffer_unlock); +/** * drm_client_buffer_vmap - Map DRM client buffer into address space * @buffer: DRM client buffer @@ -348,6 +379,66 @@ void drm_client_buffer_vunmap(struct drm_client_buffer *buffer) }EXPORT_SYMBOL (drm_client_buffer_vunmap); +/** +* drm_client_buffer_vmap_local - Map DRM client buffer into address space +* @buffer: DRM client buffer +* @map_copy: Returns the mapped memory's address +* +* This function maps a client buffer into kernel address space. If the +* buffer is already mapped, it returns the existing mapping's address. +* +* Client buffer mappings are not ref'counted. Each call to +* drm_client_buffer_vmap_local() should be followed by a call to +* drm_client_buffer_vunmap_local(); or the client buffer should be mapped +* throughout its lifetime. +* +* The returned address is a copy of the internal value. In contrast to +* other vmap interfaces, you don't need it for the client's vunmap +* function. So you can modify it at will during blit and draw operations. +* +* Returns: +* 0 on success, or a negative errno code otherwise. +*/ +int +drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map_copy) +{ +struct dma_buf_map *map = &buffer->map; +int ret; + +/* +* FIXME: The dependency on GEM here isn't required, we could +* convert the driver handle to a dma-buf instead and use the +* backend-agnostic dma-buf vmap_local support instead. This would +* require that the handle2fd prime ioctl is reworked to pull the +* fd_install step out of the driver backend hooks, to make that +* final step optional for internal users. +*/ + ret =drm_gem_vmap_local (buffer->gem, map); +if (ret) +return ret; + + *map_copy = *map; + +return 0 ; +} +EXPORT_SYMBOL (drm_client_buffer_vmap_local); + +/** +* drm_client_buffer_vunmap_local - Unmap DRM client buffer +* @buffer: DRM client buffer +* +* This function removes a client buffer's memory mapping. Calling this +* function is only required by clients that manage their buffer mappings +* by themselves. +*/ +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer) +{ +struct dma_buf_map *map = &buffer->map; + +drm_gem_vunmap_local (buffer->gem, map); +} +EXPORT_SYMBOL (drm_client_buffer_vunmap_local); +static void drm_client_buffer_rmfb (struct drm_client_buffer *buffer) {int ret;drivers/gpu/drm/drm_fb_helper.c +21
-20@@ -399,28 +399,34 @@ static int drm_fb_helper_damage_blit(struct drm_fb_helper *fb_helper,int ret;/* -* We have to pin the client buffer to its current location while -* flushing the shadow buffer. In the general case, concurrent -* modesetting operations could try to move the buffer and would -* fail. The modeset has to be serialized by acquiring the reservation -* object of the underlying BO here. -* * For fbdev emulation, we only have to protect against fbdev modeset * operations. Nothing else will involve the client buffer's BO. So it * is sufficient to acquire struct drm_fb_helper.lock here. */ mutex_lock (&fb_helper->lock); - ret =drm_client_buffer_vmap (buffer, &map); +/* +* We have to keep the client buffer at its current location while +* flushing the shadow buffer. Concurrent operations could otherwise +* try to move the buffer. Therefore acquiring the reservation +* object of the underlying BO here. +*/ + ret =drm_client_buffer_lock (buffer); +if (ret) + goto out_mutex_unlock; + + ret =drm_client_buffer_vmap_local (buffer, &map);if (ret) - goto out; + goto out_drm_client_buffer_unlock; dst = map;drm_fb_helper_damage_blit_real (fb_helper, clip, &dst); -drm_client_buffer_vunmap (buffer); +drm_client_buffer_vunmap_local (buffer); -out: +out_drm_client_buffer_unlock: +drm_client_buffer_unlock (buffer); +out_mutex_unlock:mutex_unlock (&fb_helper->lock);return ret;@@ -946,15 +952,11 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info)drm_modeset_lock_all (fb_helper->dev);drm_client_for_each_modeset (modeset, &fb_helper->client) { crtc = modeset->crtc; -if (!crtc->funcs->gamma_set || !crtc->gamma_size) { - ret = -EINVAL ; - goto out; - } +if (!crtc->funcs->gamma_set || !crtc->gamma_size) +return -EINVAL ; -if (cmap->start + cmap->len > crtc->gamma_size) { - ret = -EINVAL ; - goto out; - } +if (cmap->start + cmap->len > crtc->gamma_size) +return -EINVAL ; r = crtc->gamma_store; g = r + crtc->gamma_size;@@ -967,9 +969,8 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info) ret = crtc->funcs->gamma_set (crtc, r, g, b, crtc->gamma_size,NULL );if (ret) - goto out; +return ret; } -out:drm_modeset_unlock_all (fb_helper->dev);return ret;include/drm/drm_client.h +4
-0@@ -156,8 +156,12 @@ struct drm_client_buffer * drm_client_framebuffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format);void drm_client_framebuffer_delete (struct drm_client_buffer *buffer);int drm_client_framebuffer_flush (struct drm_client_buffer *buffer,struct drm_rect *rect); +int drm_client_buffer_lock (struct drm_client_buffer *buffer); +void drm_client_buffer_unlock (struct drm_client_buffer *buffer);int drm_client_buffer_vmap (struct drm_client_buffer *buffer,struct dma_buf_map *map);void drm_client_buffer_vunmap (struct drm_client_buffer *buffer); +int drm_client_buffer_vmap_local (struct drm_client_buffer *buffer,struct dma_buf_map *map); +void drm_client_buffer_vunmap_local (struct drm_client_buffer *buffer);int drm_client_modeset_create (struct drm_client_dev *client);void drm_client_modeset_free (struct drm_client_dev *client);Signature · 1 line
2.29.2Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel