drm: Provide framebuffer vmap helpers
Subsystems (4)
Thomas Zimmermann
maintainerv3 cover drm: Provide framebuffer vmap helpers
Add the new helpers drm_gem_fb_vmap() and drm_gem_fb_vunmap(), which provide vmap/vunmap for all BOs of a framebuffer. Convert shadow- plane helpers, gud and vkms.
Callers of GEM vmap and vunmap functions used to do the minimum work or get some detail wrong. Therefore shadow-plane helpers were intro- duced to implement the details for all callers. The vmapping code in the shadow-plane helpers is also useful for gud and vkms. So it makes sense to provide rsp helpers. Simply call drm_gem_fb_vmap() to retrieve mappings of all of a framebuffer's BOs.
Future work: besides the mapping's addresses, drm_gem_fb_vmap() should also return the mappings with the framebuffer data offset added. These are the addresses were the actual image data is located. A follow-up set of patches will implement this feature.
v3:
* free instances of struct vkms_writeback_job on cleanup or errors
v2:
* update commit message for first patch (Maxime)
* fix error handling after DRM_FORMAT_MAX_PLANES changes (kernel test robot)
* fix includes (kernel test robot)
* use [static N] notations for array parameters
Thomas Zimmermann (5):
drm: Define DRM_FORMAT_MAX_PLANES
drm/gem: Provide drm_gem_fb_{vmap,vunmap}()
drm/gem: Clear mapping addresses for unused framebuffer planes drm/gud: Map framebuffer BOs with drm_gem_fb_vmap() drm/vkms: Map output framebuffer BOs with drm_gem_fb_vmap()
drivers/gpu/drm/drm_gem_atomic_helper.c | 37 +------- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 96 ++++++++++++++++++-- drivers/gpu/drm/gud/gud_pipe.c | 10 +- drivers/gpu/drm/vkms/vkms_composer.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 6 +- drivers/gpu/drm/vkms/vkms_writeback.c | 28 +++--- include/drm/drm_fourcc.h | 13 ++- include/drm/drm_framebuffer.h | 8 +- include/drm/drm_gem_atomic_helper.h | 3 +- include/drm/drm_gem_framebuffer_helper.h | 6 ++ 10 files changed, 139 insertions(+), 70 deletions(-)
base-commit: 2bda1ca4d4acb4892556fec3a7ea1f02afcd40bb
prerequisite-patch-id: c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24 --
2.32.0
Thomas Zimmermann
maintainerPATCH v3 1/5 drm: Define DRM_FORMAT_MAX_PLANES
DRM uses a magic number of 4 for the maximum number of planes per color format. Declare this constant via DRM_FORMAT_MAX_PLANES and update the related code. Some code depends on the length of arrays that are now declared with DRM_FORMAT_MAX_PLANES. Convert it from '4' to ARRAY_SIZE.
v2:
* mention usage of ARRAY_SIZE() in the commit message (Maxime)
* also fix error handling in drm_gem_fb_init_with_funcs() (kernel test robot)
* include <drm/drm_fourcc.h> for DRM_FORMAT_MAX_PLANES
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 19 +++++++++++-------- include/drm/drm_fourcc.h | 13 +++++++++---- include/drm/drm_framebuffer.h | 8 ++++---- include/drm/drm_gem_atomic_helper.h | 3 ++- 4 files changed, 26 insertions(+), 17 deletions(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +11 -8
@@ -48,7 +48,7 @@struct drm_gem_object *drm_gem_fb_get_obj (struct drm_framebuffer *fb,unsigned int plane) { -if (plane >=4 ) +if (plane >=ARRAY_SIZE (fb->obj))return NULL ;return fb->obj[plane];
@@ -62,7 +62,8 @@ drm_gem_fb_init(struct drm_device *dev, struct drm_gem_object **obj, unsigned int num_planes, const struct drm_framebuffer_funcs *funcs) { - int ret, i; + unsigned int i; +int ret;drm_helper_mode_fill_fb_struct (dev, fb, mode_cmd);
@@ -86,9 +87,9 @@ drm_gem_fb_init(struct drm_device *dev,*/ void drm_gem_fb_destroy (struct drm_framebuffer *fb) { -int i; +size_t i; -for (i =0 ; i <4 ; i++) +for (i =0 ; i <ARRAY_SIZE (fb->obj); i++)drm_gem_object_put (fb->obj[i]);drm_framebuffer_cleanup (fb);
@@ -145,8 +146,9 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) {const struct drm_format_info *info; -struct drm_gem_object *objs[4 ]; -int ret, i; +struct drm_gem_object *objs[DRM_FORMAT_MAX_PLANES ]; +unsigned int i; +int ret; info =drm_get_format_info (dev, mode_cmd);if (!info) {
@@ -187,9 +189,10 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,return 0 ; err_gem_object_put: -for (i--; i >=0 ; i--) +while (i >0 ) { + --i;drm_gem_object_put (objs[i]); - + }return ret; }EXPORT_SYMBOL_GPL (drm_gem_fb_init_with_funcs);
include/drm/drm_fourcc.h +9 -4
@@ -25,6 +25,11 @@#include <linux/types.h> #include <uapi/drm/drm_fourcc.h> +/** +* DRM_FORMAT_MAX_PLANES - maximum number of planes a DRM format can have +*/ +#define DRM_FORMAT_MAX_PLANES 4u +/* * DRM formats are little endian. Define host endian variants for the * most common formats here, to reduce the #ifdefs needed in drivers.
@@ -78,7 +83,7 @@ struct drm_format_info {* triplet @char_per_block, @block_w, @block_h for better * describing the pixel format. */ -u8 cpp[4 ]; +u8 cpp[DRM_FORMAT_MAX_PLANES ];/** * @char_per_block:
@@ -104,7 +109,7 @@ struct drm_format_info {* information from their drm_mode_config.get_format_info hook * if they want the core to be validating the pitch. */ -u8 char_per_block[4 ]; +u8 char_per_block[DRM_FORMAT_MAX_PLANES ]; };/**
@@ -113,7 +118,7 @@ struct drm_format_info {* Block width in pixels, this is intended to be accessed through * drm_format_info_block_width() */ -u8 block_w[4 ]; +u8 block_w[DRM_FORMAT_MAX_PLANES ];/** * @block_h:
@@ -121,7 +126,7 @@ struct drm_format_info {* Block height in pixels, this is intended to be accessed through * drm_format_info_block_height() */ -u8 block_h[4 ]; +u8 block_h[DRM_FORMAT_MAX_PLANES ];/** @hsub: Horizontal chroma subsampling factor */ u8 hsub;
include/drm/drm_framebuffer.h +4 -4
@@ -27,12 +27,12 @@#include <linux/list.h> #include <linux/sched.h> +#include <drm/drm_fourcc.h> #include <drm/drm_mode_object.h> struct drm_clip_rect ;struct drm_device ;struct drm_file ; -struct drm_format_info ;struct drm_framebuffer ;struct drm_gem_object ;
@@ -147,7 +147,7 @@ struct drm_framebuffer {* @pitches: Line stride per buffer. For userspace created object this * is copied from drm_mode_fb_cmd2. */ -unsigned int pitches[4 ]; +unsigned int pitches[DRM_FORMAT_MAX_PLANES ];/** * @offsets: Offset from buffer start to the actual pixel data in bytes, * per buffer. For userspace created object this is copied from
@@ -165,7 +165,7 @@ struct drm_framebuffer {* data (even for linear buffers). Specifying an x/y pixel offset is * instead done through the source rectangle in &struct drm_plane_state. */ -unsigned int offsets[4 ]; +unsigned int offsets[DRM_FORMAT_MAX_PLANES ];/** * @modifier: Data layout modifier. This is used to describe * tiling, or also special layouts (like compression) of auxiliary
@@ -210,7 +210,7 @@ struct drm_framebuffer {* This is used by the GEM framebuffer helpers, see e.g. * drm_gem_fb_create(). */ -struct drm_gem_object *obj[4 ]; +struct drm_gem_object *obj[DRM_FORMAT_MAX_PLANES ]; };#define obj_to_fb (x) container_of(x, struct drm_framebuffer, base)
include/drm/drm_gem_atomic_helper.h +2 -1
@@ -5,6 +5,7 @@#include <linux/dma-buf-map.h> +#include <drm/drm_fourcc.h> #include <drm/drm_plane.h> struct drm_simple_display_pipe ;
@@ -40,7 +41,7 @@ struct drm_shadow_plane_state {* The memory mappings stored in map should be established in the plane's * prepare_fb callback and removed in the cleanup_fb callback. */ -struct dma_buf_map map[4 ]; +struct dma_buf_map map[DRM_FORMAT_MAX_PLANES ]; };/**
Signature · 1 line
2.32.0
Thomas Zimmermann
maintainerPATCH v3 2/5 drm/gem: Provide drm_gem_fb_{vmap,vunmap}()
In reply to Thomas ZimmermannMove framebuffer vmap code from shadow-buffered plane state into the new interfaces drm_gem_fb_vmap() and drm_gem_fb_vunmap(). These functions provide mappings of a framebuffer's BOs into kernel address space. No functional changes.
v2:
* using [static N] for array parameters enables compile-time checks
* include <drm/drm_fourcc.h> for DRM_FORMAT_MAX_PLANES (kernel test robot)
--- drivers/gpu/drm/drm_gem_atomic_helper.c | 37 +--------- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 73 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 6 ++ 3 files changed, 82 insertions(+), 34 deletions(-)
drivers/gpu/drm/drm_gem_atomic_helper.c +3 -34
@@ -330,10 +330,7 @@ int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *p {struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb; -struct drm_gem_object *obj; -struct dma_buf_map map;int ret; -size_t i;if (!fb)return 0 ;
@@ -342,27 +339,7 @@ int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *pif (ret)return ret; -for (i =0 ; i <ARRAY_SIZE (shadow_plane_state->map); ++i) { - obj =drm_gem_fb_get_obj (fb, i); -if (!obj) -continue ; - ret =drm_gem_vmap (obj, &map); -if (ret) - goto err_drm_gem_vunmap; - shadow_plane_state->map[i] = map; - } - -return 0 ; - -err_drm_gem_vunmap: -while (i) { - --i; - obj =drm_gem_fb_get_obj (fb, i); -if (!obj) -continue ; -drm_gem_vunmap (obj, &shadow_plane_state->map[i]); - } -return ret; +return drm_gem_fb_vmap (fb, shadow_plane_state->map); }EXPORT_SYMBOL (drm_gem_prepare_shadow_fb);
@@ -374,25 +351,17 @@ EXPORT_SYMBOL(drm_gem_prepare_shadow_fb);* This function implements struct &drm_plane_helper_funcs.cleanup_fb. * This function unmaps all buffer objects of the plane's framebuffer. * -* See drm_gem_prepare_shadow_fb() for more inforamtion. +* See drm_gem_prepare_shadow_fb() for more information. */ void drm_gem_cleanup_shadow_fb (struct drm_plane *plane,struct drm_plane_state *plane_state) {struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);struct drm_framebuffer *fb = plane_state->fb; -size_t i =ARRAY_SIZE (shadow_plane_state->map); -struct drm_gem_object *obj;if (!fb)return ; -while (i) { - --i; - obj =drm_gem_fb_get_obj (fb, i); -if (!obj) -continue ; -drm_gem_vunmap (obj, &shadow_plane_state->map[i]); - } +drm_gem_fb_vunmap (fb, shadow_plane_state->map); }EXPORT_SYMBOL (drm_gem_cleanup_shadow_fb);
drivers/gpu/drm/drm_gem_framebuffer_helper.c +73 -0
85 lines not on this page · raw message
include/drm/drm_gem_framebuffer_helper.h +6 -0
@@ -4,6 +4,8 @@#include <linux/dma-buf.h> #include <linux/dma-buf-map.h> +#include <drm/drm_fourcc.h> +struct drm_afbc_framebuffer ;struct drm_device ;struct drm_fb_helper_surface_size ;
@@ -37,6 +39,10 @@ struct drm_framebuffer * drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd); +int drm_gem_fb_vmap (struct drm_framebuffer *fb, +struct dma_buf_map map[static DRM_FORMAT_MAX_PLANES ]); +void drm_gem_fb_vunmap (struct drm_framebuffer *fb, +struct dma_buf_map map[static DRM_FORMAT_MAX_PLANES ]);int drm_gem_fb_begin_cpu_access (struct drm_framebuffer *fb,enum dma_data_direction dir);void drm_gem_fb_end_cpu_access (struct drm_framebuffer *fb,enum dma_data_direction dir);
Signature · 1 line
2.32.0
Thomas Zimmermann
maintainerPATCH v3 3/5 drm/gem: Clear mapping addresses for unused framebuffer planes
In reply to Thomas ZimmermannSet the returned mapping address to NULL if a framebuffer plane does not have a BO associated with it. Likewise, ignore mappings of NULL during framebuffer unmap operations. Allows users of the functions to perform unmap operations of certain BOs by themselfes.
--- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_gem_framebuffer_helper.c +5 -1
@@ -336,8 +336,10 @@ int drm_gem_fb_vmap(struct drm_framebuffer *fb,for (i =0 ; i <DRM_FORMAT_MAX_PLANES ; ++i) { obj =drm_gem_fb_get_obj (fb, i); -if (!obj) +if (!obj) { +dma_buf_map_clear (&map[i]);continue ; + } ret =drm_gem_vmap (obj, &map[i]);if (ret) goto err_drm_gem_vunmap;
@@ -377,6 +379,8 @@ void drm_gem_fb_vunmap(struct drm_framebuffer *fb, obj =drm_gem_fb_get_obj (fb, i);if (!obj)continue ; +if (dma_buf_map_is_null (&map[i])) +continue ;drm_gem_vunmap (obj, &map[i]); } }
Signature · 1 line
2.32.0
Thomas Zimmermann
maintainerPATCH v3 4/5 drm/gud: Map framebuffer BOs with drm_gem_fb_vmap()
In reply to Thomas ZimmermannAbstract the framebuffer details by mapping its BOs with a call to drm_gem_fb_vmap(). Unmap with drm_gem_fb_vunmap().
The call to drm_gem_fb_vmap() ensures that all BOs are mapped correctly. Gud still only supports single-plane formats.
No functional changes.
--- drivers/gpu/drm/gud/gud_pipe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +5 -5
@@ -14,8 +14,8 @@#include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem.h> #include <drm/drm_gem_framebuffer_helper.h> -#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> #include <drm/drm_simple_kms_helper.h>
@@ -152,7 +152,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, {struct dma_buf_attachment *import_attach = fb->obj[0 ]->import_attach;u8 compression = gdrm->compression; -struct dma_buf_map map; +struct dma_buf_map map[DRM_FORMAT_MAX_PLANES ];void *vaddr, *buf;size_t pitch, len;int ret =0 ;
@@ -162,11 +162,11 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,if (len > gdrm->bulk_len)return -E2BIG ; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_fb_vmap (fb, map);if (ret)return ret; - vaddr = map.vaddr + fb->offsets[0 ]; + vaddr = map[0 ].vaddr + fb->offsets[0 ]; ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE );if (ret)
@@ -225,7 +225,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, end_cpu_access:drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_fb_vunmap (fb, map);return ret; }
Signature · 1 line
2.32.0
Re: [PATCH v3 4/5] drm/gud: Map framebuffer BOs with drm_gem_fb_vmap()
Hi Thomas,
I'm getting this on Ubuntu 22.04:
[ 0.000000] Linux version 5.15.0-27-generic (buildd@ubuntu) (gcc
(Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 (Ubuntu 5.15.0-27.28-generic 5.15.30)
[ 4.830866] usb 2-3.1: new high-speed USB device number 4 using xhci_hcd [ 4.935546] usb 2-3.1: New USB device found, idVendor=1d50, idProduct=614d, bcdDevice= 1.00 [ 4.935553] usb 2-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 4.935556] usb 2-3.1: Product: Raspberry Pi 4 Display Gadget [ 4.935558] usb 2-3.1: Manufacturer: Raspberry Pi [ 4.935560] usb 2-3.1: SerialNumber: 100000003b40d6c6
[ 7.497361] [drm] Initialized gud 1.0.0 20200422 for 2-3.1:1.0 on minor 0
[ 7.573048] gud 2-3.1:1.0: [drm] fb1: guddrmfb frame buffer device
[ 9.199402] ================================================================================ [ 9.199411] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:224:9 [ 9.199416] load of value 226 is not a valid value for type '_Bool' [ 9.199420] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu [ 9.199424] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018 [ 9.199427] Workqueue: events_long gud_flush_work [gud] [ 9.199440] Call Trace: [ 9.199443] <TASK> [ 9.199447] show_stack+0x52/0x58 [ 9.199456] dump_stack_lvl+0x4a/0x5f [ 9.199464] dump_stack+0x10/0x12 [ 9.199468] ubsan_epilogue+0x9/0x45 [ 9.199473] __ubsan_handle_load_invalid_value.cold+0x44/0x49 [ 9.199478] drm_gem_fb_vmap.cold+0x10/0x3d [drm_kms_helper] [ 9.199519] gud_prep_flush+0xaa/0x410 [gud] [ 9.199525] ? check_preempt_curr+0x5d/0x70 [ 9.199533] ? update_load_avg+0x82/0x620 [ 9.199540] ? set_next_entity+0xb7/0x200 [ 9.199545] gud_flush_work+0x1e0/0x430 [gud] [ 9.199551] ? psi_task_switch+0x1e7/0x220 [ 9.199557] process_one_work+0x22b/0x3d0 [ 9.199564] worker_thread+0x53/0x410 [ 9.199570] ? process_one_work+0x3d0/0x3d0 [ 9.199575] kthread+0x12a/0x150 [ 9.199579] ? set_kthread_struct+0x50/0x50 [ 9.199584] ret_from_fork+0x22/0x30 [ 9.199593] </TASK> [ 9.199595]
================================================================================
[ 9.199598] ================================================================================ [ 9.199600] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:194:9 [ 9.199604] load of value 226 is not a valid value for type '_Bool' [ 9.199606] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu [ 9.199610] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018 [ 9.199612] Workqueue: events_long gud_flush_work [gud] [ 9.199618] Call Trace: [ 9.199619] <TASK> [ 9.199621] show_stack+0x52/0x58 [ 9.199627] dump_stack_lvl+0x4a/0x5f [ 9.199633] dump_stack+0x10/0x12 [ 9.199637] ubsan_epilogue+0x9/0x45 [ 9.199641] __ubsan_handle_load_invalid_value.cold+0x44/0x49 [ 9.199646] drm_gem_fb_vmap.cold+0x24/0x3d [drm_kms_helper] [ 9.199675] gud_prep_flush+0xaa/0x410 [gud] [ 9.199682] ? check_preempt_curr+0x5d/0x70 [ 9.199688] ? update_load_avg+0x82/0x620 [ 9.199693] ? update_load_avg+0x82/0x620 [ 9.199697] gud_flush_work+0x1e0/0x430 [gud] [ 9.199702] ? psi_task_switch+0x1e7/0x220 [ 9.199706] process_one_work+0x22b/0x3d0 [ 9.199713] worker_thread+0x53/0x410 [ 9.199718] ? process_one_work+0x3d0/0x3d0 [ 9.199723] kthread+0x12a/0x150 [ 9.199728] ? set_kthread_struct+0x50/0x50 [ 9.199732] ret_from_fork+0x22/0x30 [ 9.199741] </TASK> [ 9.199743]
================================================================================
It's the "if (map->is_iomem)" statement in dma_buf_map_clear() and dma_buf_map_is_null() that triggers this.
I tried 5.18.0-rc5 and the problem is still present.
UBSAN entries in the config:
CONFIG_ARCH_HAS_UBSAN_SANITIZE_ALL=yCONFIG_UBSAN=y
# CONFIG_UBSAN_TRAP is not setCONFIG_CC_HAS_UBSAN_BOUNDS=yCONFIG_UBSAN_BOUNDS=yCONFIG_UBSAN_ONLY_BOUNDS=yCONFIG_UBSAN_SHIFT=y
# CONFIG_UBSAN_DIV_ZERO is not setCONFIG_UBSAN_BOOL=yCONFIG_UBSAN_ENUM=y
# CONFIG_UBSAN_ALIGNMENT is not setCONFIG_UBSAN_SANITIZE_ALL=y
# CONFIG_TEST_UBSAN is not set
Continuing further down.
Den 30.07.2021 20.35, skrev Thomas Zimmermann:
Quoted 30 lines
Abstract the framebuffer details by mapping its BOs with a call to
drm_gem_fb_vmap(). Unmap withdrm_gem_fb_vunmap().The call to
drm_gem_fb_vmap()ensures that all BOs are mapped correctly. Gud still only supports single-plane formats.No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>Acked-by Noralf Trønnes <[email protected]>Acked-by Sam Ravnborg <[email protected]>--- drivers/gpu/drm/gud/gud_pipe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -14,8 +14,8 @@#include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem.h> #include <drm/drm_gem_framebuffer_helper.h> -#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> #include <drm/drm_simple_kms_helper.h>
drivers/gpu/drm/gud/gud_pipe.c static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, · line 155
Quoted 5 lines
drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -152,7 +152,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, {struct dma_buf_attachment *import_attach = fb->obj[0 ]->import_attach;u8 compression = gdrm->compression; -struct dma_buf_map map; +struct dma_buf_map map[DRM_FORMAT_MAX_PLANES ];
Zeroing map solves the problem:
struct iosys_map map[DRM_FORMAT_MAX_PLANES] = {};I don't understand the conditional clearing in dma_buf_map_clear/iosys_map_clear(), the doc says: Clears all fields to zero. If I zero the whole structure unconditionally this also keeps UBSAN happy.
Noralf.
Quoted 26 lines
drivers/gpu/drm/gud/gud_pipe.c +3
-3void *vaddr, *buf;size_t pitch, len;int ret =0 ;@@ -162,11 +162,11 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,if (len > gdrm->bulk_len)return -E2BIG ; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_fb_vmap (fb, map);if (ret)return ret; - vaddr = map.vaddr + fb->offsets[0 ]; + vaddr = map[0 ].vaddr + fb->offsets[0 ]; ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE );if (ret)@@ -225,7 +225,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, end_cpu_access:drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_fb_vunmap (fb, map);return ret; }
Thomas Zimmermann
maintainerRe: [PATCH v3 4/5] drm/gud: Map framebuffer BOs with drm_gem_fb_vmap()
Hi
Am 06.05.22 um 16:01 schrieb Noralf Trønnes:
Quoted 153 lines
Hi Thomas,
I'm getting this on Ubuntu 22.04:
[ 0.000000] Linux version 5.15.0-27-generic (buildd@ubuntu) (gcc(Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 (Ubuntu 5.15.0-27.28-generic 5.15.30)
[ 4.830866] usb 2-3.1: new high-speed USB device number 4 using xhci_hcd [ 4.935546] usb 2-3.1: New USB device found, idVendor=1d50, idProduct=614d, bcdDevice= 1.00 [ 4.935553] usb 2-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 4.935556] usb 2-3.1: Product: Raspberry Pi 4 Display Gadget [ 4.935558] usb 2-3.1: Manufacturer: Raspberry Pi [ 4.935560] usb 2-3.1: SerialNumber: 100000003b40d6c6[ 7.497361] [drm] Initialized gud 1.0.0 20200422 for 2-3.1:1.0 on minor 0[ 7.573048] gud 2-3.1:1.0: [drm] fb1: guddrmfb frame buffer device[ 9.199402] ================================================================================ [ 9.199411] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:224:9 [ 9.199416] load of value 226 is not a valid value for type '_Bool' [ 9.199420] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu [ 9.199424] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018 [ 9.199427] Workqueue: events_long gud_flush_work [gud] [ 9.199440] Call Trace: [ 9.199443] <TASK> [ 9.199447] show_stack+0x52/0x58 [ 9.199456] dump_stack_lvl+0x4a/0x5f [ 9.199464] dump_stack+0x10/0x12 [ 9.199468] ubsan_epilogue+0x9/0x45 [ 9.199473] __ubsan_handle_load_invalid_value.cold+0x44/0x49 [ 9.199478] drm_gem_fb_vmap.cold+0x10/0x3d [drm_kms_helper] [ 9.199519] gud_prep_flush+0xaa/0x410 [gud] [ 9.199525] ? check_preempt_curr+0x5d/0x70 [ 9.199533] ? update_load_avg+0x82/0x620 [ 9.199540] ? set_next_entity+0xb7/0x200 [ 9.199545] gud_flush_work+0x1e0/0x430 [gud] [ 9.199551] ? psi_task_switch+0x1e7/0x220 [ 9.199557] process_one_work+0x22b/0x3d0 [ 9.199564] worker_thread+0x53/0x410 [ 9.199570] ? process_one_work+0x3d0/0x3d0 [ 9.199575] kthread+0x12a/0x150 [ 9.199579] ? set_kthread_struct+0x50/0x50 [ 9.199584] ret_from_fork+0x22/0x30 [ 9.199593] </TASK> [ 9.199595]================================================================================
[ 9.199598] ================================================================================ [ 9.199600] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:194:9 [ 9.199604] load of value 226 is not a valid value for type '_Bool' [ 9.199606] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu [ 9.199610] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018 [ 9.199612] Workqueue: events_long gud_flush_work [gud] [ 9.199618] Call Trace: [ 9.199619] <TASK> [ 9.199621] show_stack+0x52/0x58 [ 9.199627] dump_stack_lvl+0x4a/0x5f [ 9.199633] dump_stack+0x10/0x12 [ 9.199637] ubsan_epilogue+0x9/0x45 [ 9.199641] __ubsan_handle_load_invalid_value.cold+0x44/0x49 [ 9.199646] drm_gem_fb_vmap.cold+0x24/0x3d [drm_kms_helper] [ 9.199675] gud_prep_flush+0xaa/0x410 [gud] [ 9.199682] ? check_preempt_curr+0x5d/0x70 [ 9.199688] ? update_load_avg+0x82/0x620 [ 9.199693] ? update_load_avg+0x82/0x620 [ 9.199697] gud_flush_work+0x1e0/0x430 [gud] [ 9.199702] ? psi_task_switch+0x1e7/0x220 [ 9.199706] process_one_work+0x22b/0x3d0 [ 9.199713] worker_thread+0x53/0x410 [ 9.199718] ? process_one_work+0x3d0/0x3d0 [ 9.199723] kthread+0x12a/0x150 [ 9.199728] ? set_kthread_struct+0x50/0x50 [ 9.199732] ret_from_fork+0x22/0x30 [ 9.199741] </TASK> [ 9.199743]================================================================================
It's the "if (
map->is_iomem)" statement indma_buf_map_clear()anddma_buf_map_is_null()that triggers this.I tried 5.18.0-rc5 and the problem is still present.
UBSAN entries in the config:
CONFIG_ARCH_HAS_UBSAN_SANITIZE_ALL=yCONFIG_UBSAN=y
#CONFIG_UBSAN_TRAPis not setCONFIG_CC_HAS_UBSAN_BOUNDS=yCONFIG_UBSAN_BOUNDS=yCONFIG_UBSAN_ONLY_BOUNDS=yCONFIG_UBSAN_SHIFT=y
#CONFIG_UBSAN_DIV_ZEROis not setCONFIG_UBSAN_BOOL=yCONFIG_UBSAN_ENUM=y
#CONFIG_UBSAN_ALIGNMENTis not setCONFIG_UBSAN_SANITIZE_ALL=y
#CONFIG_TEST_UBSANis not setContinuing further down.
Den 30.07.2021 20.35, skrev Thomas Zimmermann:
Quoted 30 lines
Abstract the framebuffer details by mapping its BOs with a call to
drm_gem_fb_vmap(). Unmap withdrm_gem_fb_vunmap().The call to
drm_gem_fb_vmap()ensures that all BOs are mapped correctly. Gud still only supports single-plane formats.No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>Acked-by Noralf Trønnes <[email protected]>Acked-by Sam Ravnborg <[email protected]>--- drivers/gpu/drm/gud/gud_pipe.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -14,8 +14,8 @@#include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem.h> #include <drm/drm_gem_framebuffer_helper.h> -#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> #include <drm/drm_simple_kms_helper.h> drivers/gpu/drm/gud/gud_pipe.c static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, · line 155
Quoted 5 lines
drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -152,7 +152,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, {struct dma_buf_attachment *import_attach = fb->obj[0 ]->import_attach;u8 compression = gdrm->compression; -struct dma_buf_map map; +struct dma_buf_map map[DRM_FORMAT_MAX_PLANES ];Zeroing map solves the problem:
Quoted 6 lines
struct iosys_map map[DRM_FORMAT_MAX_PLANES] = {};I don't understand the conditional clearing in dma_buf_map_clear/iosys_map_clear(), the doc says: Clears all fields to zero. If I zero the whole structure unconditionally this also keeps UBSAN happy.
Thanks for debugging this problem. It's uninitialized and some of the internal helpers look at all planes, even if they are empty. I have a patchset to fix that throughout the DRM modules. I'll post on Monday.
If we need a quick fix, we could do the zeroing everywhere.
Best regards
Thomas
Quoted 29 lines
Noralf.
Quoted 26 lines
drivers/gpu/drm/gud/gud_pipe.c +3
-3void *vaddr, *buf;size_t pitch, len;int ret =0 ;@@ -162,11 +162,11 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,if (len > gdrm->bulk_len)return -E2BIG ; - ret =drm_gem_shmem_vmap (fb->obj[0 ], &map); + ret =drm_gem_fb_vmap (fb, map);if (ret)return ret; - vaddr = map.vaddr + fb->offsets[0 ]; + vaddr = map[0 ].vaddr + fb->offsets[0 ]; ret =drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE );if (ret)@@ -225,7 +225,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, end_cpu_access:drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); vunmap: -drm_gem_shmem_vunmap (fb->obj[0 ], &map); +drm_gem_fb_vunmap (fb, map);return ret; }
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: Ivo Totev
Thomas Zimmermann
maintainerRe: [PATCH v3 4/5] drm/gud: Map framebuffer BOs with drm_gem_fb_vmap()
Hi Noralf
Am 06.05.22 um 16:11 schrieb Thomas Zimmermann:
Quoted 167 lines
Hi
Am 06.05.22 um 16:01 schrieb Noralf Trønnes:
Quoted 164 lines
Hi Thomas,
I'm getting this on Ubuntu 22.04:
[ 0.000000] Linux version 5.15.0-27-generic (buildd@ubuntu) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 (Ubuntu 5.15.0-27.28-generic 5.15.30)
[ 4.830866] usb 2-3.1: new high-speed USB device number 4 using
xhci_hcd[ 4.935546] usb 2-3.1: New USB device found, idVendor=1d50, idProduct=614d, bcdDevice= 1.00
[ 4.935553] usb 2-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4.935556] usb 2-3.1: Product: Raspberry Pi 4 Display Gadget [ 4.935558] usb 2-3.1: Manufacturer: Raspberry Pi
[ 4.935560] usb 2-3.1: SerialNumber:100000003b40d6c6[ 7.497361] [drm] Initialized gud 1.0.0 20200422 for 2-3.1:1.0 on minor 0
[ 7.573048] gud 2-3.1:1.0: [drm] fb1: guddrmfb frame buffer device
[ 9.199402]
================================================================================[ 9.199411] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:224:9 [ 9.199416] load of value 226 is not a valid value for type '
_Bool' [ 9.199420] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu
[ 9.199424] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018
[ 9.199427] Workqueue:events_longgud_flush_work[gud]
[ 9.199440] Call Trace:
[ 9.199443] <TASK>
[ 9.199447]show_stack+0x52/0x58
[ 9.199456]dump_stack_lvl+0x4a/0x5f
[ 9.199464]dump_stack+0x10/0x12
[ 9.199468]ubsan_epilogue+0x9/0x45
[ 9.199473]__ubsan_handle_load_invalid_value.cold+0x44/0x49[ 9.199478]drm_gem_fb_vmap.cold+0x10/0x3d[drm_kms_helper] [ 9.199519]gud_prep_flush+0xaa/0x410[gud]
[ 9.199525] ?check_preempt_curr+0x5d/0x70
[ 9.199533] ?update_load_avg+0x82/0x620
[ 9.199540] ?set_next_entity+0xb7/0x200
[ 9.199545]gud_flush_work+0x1e0/0x430[gud]
[ 9.199551] ?psi_task_switch+0x1e7/0x220
[ 9.199557]process_one_work+0x22b/0x3d0
[ 9.199564]worker_thread+0x53/0x410
[ 9.199570] ?process_one_work+0x3d0/0x3d0
[ 9.199575]kthread+0x12a/0x150
[ 9.199579] ?set_kthread_struct+0x50/0x50
[ 9.199584]ret_from_fork+0x22/0x30
[ 9.199593] </TASK>
[ 9.199595]
================================================================================[ 9.199598]
================================================================================[ 9.199600] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:194:9 [ 9.199604] load of value 226 is not a valid value for type '
_Bool' [ 9.199606] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu
[ 9.199610] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018
[ 9.199612] Workqueue:events_longgud_flush_work[gud]
[ 9.199618] Call Trace:
[ 9.199619] <TASK>
[ 9.199621]show_stack+0x52/0x58
[ 9.199627]dump_stack_lvl+0x4a/0x5f
[ 9.199633]dump_stack+0x10/0x12
[ 9.199637]ubsan_epilogue+0x9/0x45
[ 9.199641]__ubsan_handle_load_invalid_value.cold+0x44/0x49[ 9.199646]drm_gem_fb_vmap.cold+0x24/0x3d[drm_kms_helper] [ 9.199675]gud_prep_flush+0xaa/0x410[gud]
[ 9.199682] ?check_preempt_curr+0x5d/0x70
[ 9.199688] ?update_load_avg+0x82/0x620
[ 9.199693] ?update_load_avg+0x82/0x620
[ 9.199697]gud_flush_work+0x1e0/0x430[gud]
[ 9.199702] ?psi_task_switch+0x1e7/0x220
[ 9.199706]process_one_work+0x22b/0x3d0
[ 9.199713]worker_thread+0x53/0x410
[ 9.199718] ?process_one_work+0x3d0/0x3d0
[ 9.199723]kthread+0x12a/0x150
[ 9.199728] ?set_kthread_struct+0x50/0x50
[ 9.199732]ret_from_fork+0x22/0x30
[ 9.199741] </TASK>
[ 9.199743]
================================================================================It's the "if (
map->is_iomem)" statement indma_buf_map_clear()anddma_buf_map_is_null()that triggers this.I tried 5.18.0-rc5 and the problem is still present.
UBSAN entries in the config:
CONFIG_ARCH_HAS_UBSAN_SANITIZE_ALL=yCONFIG_UBSAN=y
#CONFIG_UBSAN_TRAPis not setCONFIG_CC_HAS_UBSAN_BOUNDS=yCONFIG_UBSAN_BOUNDS=yCONFIG_UBSAN_ONLY_BOUNDS=yCONFIG_UBSAN_SHIFT=y
#CONFIG_UBSAN_DIV_ZEROis not setCONFIG_UBSAN_BOOL=yCONFIG_UBSAN_ENUM=y
#CONFIG_UBSAN_ALIGNMENTis not setCONFIG_UBSAN_SANITIZE_ALL=y
#CONFIG_TEST_UBSANis not setContinuing further down.
Den 30.07.2021 20.35, skrev Thomas Zimmermann:
Quoted 30 lines
Abstract the framebuffer details by mapping its BOs with a call to
drm_gem_fb_vmap(). Unmap withdrm_gem_fb_vunmap().The call to
drm_gem_fb_vmap()ensures that all BOs are mapped correctly. Gud still only supports single-plane formats.No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>Acked-by Noralf Trønnes <[email protected]>Acked-by Sam Ravnborg <[email protected]>---
drivers/gpu/drm/gud/gud_pipe.c| 10 +++++-----1 file changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -14,8 +14,8 @@ #include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem.h> #include <drm/drm_gem_framebuffer_helper.h> -#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> #include <drm/drm_simple_kms_helper.h>drivers/gpu/drm/gud/gud_pipe.c static int gud_prep_flush(struct gud_device · line 156
Quoted 6 lines
drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -152,7 +152,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, { struct dma_buf_attachment *import_attach = fb->obj[0]->import_attach; u8 compression = gdrm->compression; - struct dma_buf_map map; + struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];Zeroing map solves the problem:
struct
iosys_mapmap[DRM_FORMAT_MAX_PLANES] = {};I don't understand the conditional clearing in dma_buf_map_clear/iosys_map_clear(), the doc says: Clears all fields to zero. If I zero the whole structure unconditionally this also keeps UBSAN happy.
iomap_sys_clear() assumes that the instance is already initialized. Hence, calling it at [1] with un-zeroed, stack-allocated memory operates on undefined state. It doesn't matter for the result, though. I guess the semantics of iosys_sys_clear() are not stellar.
Quoted 2 lines
Thanks for debugging this problem. It's uninitialized and some of the internal helpers look at all planes, even if they are empty. I have a patchset to fix that throughout the DRM modules. I'll post on Monday.
I have posted that patchset at [2]. If you have the time, I'd appreciate if you could give it a test run.
Best regards
Thomas
[1] https://elixir.bootlin.com/linux/v5.17.5/source/drivers/gpu/drm/drm_gem_framebuffer_helper.c#L348
[2] https://lore.kernel.org/dri-devel/[email protected]/T/#t
Quoted 34 lines
If we need a quick fix, we could do the zeroing everywhere.
Best regards
ThomasQuoted 27 lines
Noralf.
Quoted 24 lines
drivers/gpu/drm/gud/gud_pipe.c +0
-0void *vaddr, *buf; size_t pitch, len;int ret = 0;
drivers/gpu/drm/gud/gud_pipe.c +2
-2@@ -162,11 +162,11 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, if (len > gdrm->bulk_len) return -E2BIG; - ret = drm_gem_shmem_vmap(fb->obj[0], &map); + ret = drm_gem_fb_vmap(fb, map); if (ret) return ret; - vaddr = map.vaddr + fb->offsets[0]; + vaddr = map[0].vaddr + fb->offsets[0]; ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); if (ret)@@ -225,7 +225,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,
end_cpu_access:
drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); vunmap:
-drm_gem_shmem_vunmap(fb->obj[0], &map); +drm_gem_fb_vunmap(fb, map);
return ret;
}
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: Ivo Totev
Re: [PATCH v3 4/5] drm/gud: Map framebuffer BOs with drm_gem_fb_vmap()
Den 09.05.2022 10.32, skrev Thomas Zimmermann:
Quoted 175 lines
Hi Noralf
Am 06.05.22 um 16:11 schrieb Thomas Zimmermann:
Quoted 171 lines
Hi
Am 06.05.22 um 16:01 schrieb Noralf Trønnes:
Quoted 168 lines
Hi Thomas,
I'm getting this on Ubuntu 22.04:
[ 0.000000] Linux version 5.15.0-27-generic (buildd@ubuntu) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #28-Ubuntu SMP Thu Apr 14 04:55:28 UTC 2022 (Ubuntu 5.15.0-27.28-generic 5.15.30)
[ 4.830866] usb 2-3.1: new high-speed USB device number 4 using
xhci_hcd
[ 4.935546] usb 2-3.1: New USB device found, idVendor=1d50, idProduct=614d, bcdDevice= 1.00
[ 4.935553] usb 2-3.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4.935556] usb 2-3.1: Product: Raspberry Pi 4 Display Gadget [ 4.935558] usb 2-3.1: Manufacturer: Raspberry Pi
[ 4.935560] usb 2-3.1: SerialNumber:100000003b40d6c6[ 7.497361] [drm] Initialized gud 1.0.0 20200422 for 2-3.1:1.0 on minor 0
[ 7.573048] gud 2-3.1:1.0: [drm] fb1: guddrmfb frame buffer device
[ 9.199402]
================================================================================[ 9.199411] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:224:9 [ 9.199416] load of value 226 is not a valid value for type '
_Bool' [ 9.199420] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu
[ 9.199424] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018
[ 9.199427] Workqueue:events_longgud_flush_work[gud]
[ 9.199440] Call Trace:
[ 9.199443] <TASK>
[ 9.199447]show_stack+0x52/0x58
[ 9.199456]dump_stack_lvl+0x4a/0x5f
[ 9.199464]dump_stack+0x10/0x12
[ 9.199468]ubsan_epilogue+0x9/0x45
[ 9.199473]__ubsan_handle_load_invalid_value.cold+0x44/0x49[ 9.199478]drm_gem_fb_vmap.cold+0x10/0x3d[drm_kms_helper] [ 9.199519]gud_prep_flush+0xaa/0x410[gud]
[ 9.199525] ?check_preempt_curr+0x5d/0x70
[ 9.199533] ?update_load_avg+0x82/0x620
[ 9.199540] ?set_next_entity+0xb7/0x200
[ 9.199545]gud_flush_work+0x1e0/0x430[gud]
[ 9.199551] ?psi_task_switch+0x1e7/0x220
[ 9.199557]process_one_work+0x22b/0x3d0
[ 9.199564]worker_thread+0x53/0x410
[ 9.199570] ?process_one_work+0x3d0/0x3d0
[ 9.199575]kthread+0x12a/0x150
[ 9.199579] ?set_kthread_struct+0x50/0x50
[ 9.199584]ret_from_fork+0x22/0x30
[ 9.199593] </TASK>
[ 9.199595]
================================================================================[ 9.199598]
================================================================================[ 9.199600] UBSAN: invalid-load in /build/linux-HMZHpV/linux-5.15.0/include/linux/dma-buf-map.h:194:9 [ 9.199604] load of value 226 is not a valid value for type '
_Bool' [ 9.199606] CPU: 0 PID: 113 Comm: kworker/0:2 Not tainted 5.15.0-27-generic #28-Ubuntu
[ 9.199610] Hardware name: Hewlett-Packard HP EliteBook 820 G1/1991, BIOS L71 Ver. 01.44 04/12/2018
[ 9.199612] Workqueue:events_longgud_flush_work[gud]
[ 9.199618] Call Trace:
[ 9.199619] <TASK>
[ 9.199621]show_stack+0x52/0x58
[ 9.199627]dump_stack_lvl+0x4a/0x5f
[ 9.199633]dump_stack+0x10/0x12
[ 9.199637]ubsan_epilogue+0x9/0x45
[ 9.199641]__ubsan_handle_load_invalid_value.cold+0x44/0x49[ 9.199646]drm_gem_fb_vmap.cold+0x24/0x3d[drm_kms_helper] [ 9.199675]gud_prep_flush+0xaa/0x410[gud]
[ 9.199682] ?check_preempt_curr+0x5d/0x70
[ 9.199688] ?update_load_avg+0x82/0x620
[ 9.199693] ?update_load_avg+0x82/0x620
[ 9.199697]gud_flush_work+0x1e0/0x430[gud]
[ 9.199702] ?psi_task_switch+0x1e7/0x220
[ 9.199706]process_one_work+0x22b/0x3d0
[ 9.199713]worker_thread+0x53/0x410
[ 9.199718] ?process_one_work+0x3d0/0x3d0
[ 9.199723]kthread+0x12a/0x150
[ 9.199728] ?set_kthread_struct+0x50/0x50
[ 9.199732]ret_from_fork+0x22/0x30
[ 9.199741] </TASK>
[ 9.199743]
================================================================================It's the "if (
map->is_iomem)" statement indma_buf_map_clear()anddma_buf_map_is_null()that triggers this.I tried 5.18.0-rc5 and the problem is still present.
UBSAN entries in the config:
CONFIG_ARCH_HAS_UBSAN_SANITIZE_ALL=yCONFIG_UBSAN=y
#CONFIG_UBSAN_TRAPis not setCONFIG_CC_HAS_UBSAN_BOUNDS=yCONFIG_UBSAN_BOUNDS=yCONFIG_UBSAN_ONLY_BOUNDS=yCONFIG_UBSAN_SHIFT=y
#CONFIG_UBSAN_DIV_ZEROis not setCONFIG_UBSAN_BOOL=yCONFIG_UBSAN_ENUM=y
#CONFIG_UBSAN_ALIGNMENTis not setCONFIG_UBSAN_SANITIZE_ALL=y
#CONFIG_TEST_UBSANis not setContinuing further down.
Den 30.07.2021 20.35, skrev Thomas Zimmermann:
Quoted 33 lines
Abstract the framebuffer details by mapping its BOs with a call to
drm_gem_fb_vmap(). Unmap withdrm_gem_fb_vunmap().The call to
drm_gem_fb_vmap()ensures that all BOs are mapped correctly. Gud still only supports single-plane formats.No functional changes.
Signed-off-by Thomas Zimmermann <[email protected]>Acked-by Noralf Trønnes <[email protected]>Acked-by Sam Ravnborg <[email protected]>---
drivers/gpu/drm/gud/gud_pipe.c| 10 +++++-----1 file changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/gud/gud_pipe.c +1
-1@@ -14,8 +14,8 @@ #include <drm/drm_format_helper.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem.h> #include <drm/drm_gem_framebuffer_helper.h> -#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_print.h> #include <drm/drm_rect.h> #include <drm/drm_simple_kms_helper.h>@@ -152,7 +152,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, {Quoted 5 lines
struct
dma_buf_attachment*import_attach= fb->obj[0]->import_attach;
u8 compression =gdrm->compression;
- structdma_buf_mapmap;
+ structdma_buf_mapmap[DRM_FORMAT_MAX_PLANES];Zeroing map solves the problem:
struct
iosys_mapmap[DRM_FORMAT_MAX_PLANES] = {};I don't understand the conditional clearing in dma_buf_map_clear/iosys_map_clear(), the doc says: Clears all fields to zero. If I zero the whole structure unconditionally this also keeps UBSAN happy.
Quoted 5 lines
iomap_sys_clear()assumes that the instance is already initialized. Hence, calling it at [1] with un-zeroed, stack-allocated memory operates on undefined state. It doesn't matter for the result, though. I guess the semantics ofiosys_sys_clear()are not stellar.
I did a quick look through the struct iosys_map users and found these using a stack allocated variable that has not been initialized:
These call dma_buf_vmap() directly:drm_gem_cma_prime_import_sg_table_vmapigt_dmabuf_export_vmapigt_dmabuf_import_ownershipigt_dmabuf_importetnaviv_gem_prime_vmap_impl
Ends up calling dma_buf_vmap() if the bo is imported:panfrost_perfcnt_enable_locked lima_sched_build_error_task_list tegra_bo_mmapmipi_dbi_fb_dirtymipi_dbi_buf_copygud_prep_flush
Ends up calling iosys_map_is_null() at least:ast_cursor_plane_init
Ends up calling iosys_map_is_equal():ast_cursor_plane_destroy
Quoted 8 lines
Quoted 4 lines
Thanks for debugging this problem. It's uninitialized and some of the internal helpers look at all planes, even if they are empty. I have a patchset to fix that throughout the DRM modules. I'll post on Monday.
I have posted that patchset at [2]. If you have the time, I'd appreciate if you could give it a test run.
I'll see if I can do that.
Noralf.
Quoted 45 lines
Best regards
Thomas[1]
https://elixir.bootlin.com/linux/v5.17.5/source/drivers/gpu/drm/drm_gem_framebuffer_helper.c#L348[2]
https://lore.kernel.org/dri-devel/[email protected]/T/#tQuoted 34 lines
If we need a quick fix, we could do the zeroing everywhere.
Best regards
ThomasQuoted 27 lines
Noralf.
Quoted 24 lines
void *vaddr, *buf;
size_tpitch, len;
int ret = 0;drivers/gpu/drm/gud/gud_pipe.c +2
-2@@ -162,11 +162,11 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, if (len > gdrm->bulk_len) return -E2BIG; - ret = drm_gem_shmem_vmap(fb->obj[0], &map); + ret = drm_gem_fb_vmap(fb, map); if (ret) return ret; - vaddr = map.vaddr + fb->offsets[0]; + vaddr = map[0].vaddr + fb->offsets[0]; ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); if (ret)@@ -225,7 +225,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,
end_cpu_access:
drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); vunmap:
-drm_gem_shmem_vunmap(fb->obj[0], &map); +drm_gem_fb_vunmap(fb, map);
return ret;
}
Thomas Zimmermann
maintainerPATCH v3 5/5 drm/vkms: Map output framebuffer BOs with drm_gem_fb_vmap()
In reply to Thomas ZimmermannAbstract the framebuffer details by mappings its BOs with a call to drm_gem_fb_vmap(). Unmap with drm_gem_fb_vunamp().
Before, the output address with stored as raw pointer in the priv field of struct drm_writeback_job. Introduce the new type struct vkms_writeback_job, which holds the output mappings addresses while the writeback job is active.
The patchset also cleans up some internal casting an setup of the output addresses. No functional changes.
v3:
* free instances of struct vkms_writeback_job on cleanup or errors
--- drivers/gpu/drm/vkms/vkms_composer.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 6 +++++- drivers/gpu/drm/vkms/vkms_writeback.c | 28 +++++++++++++++------------ 3 files changed, 22 insertions(+), 14 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +1 -1
@@ -257,7 +257,7 @@ void vkms_composer_worker(struct work_struct *work)return ;if (wb_pending) - vaddr_out = crtc_state->active_writeback; + vaddr_out = crtc_state->active_writeback->map[0 ].vaddr; ret =compose_active_planes (&vaddr_out, primary_composer, crtc_state);
drivers/gpu/drm/vkms/vkms_drv.h +5 -1
@@ -20,6 +20,10 @@#define XRES_MAX 8192#define YRES_MAX 8192 +struct vkms_writeback_job { +struct dma_buf_map map[DRM_FORMAT_MAX_PLANES ]; +}; +struct vkms_composer {struct drm_framebuffer fb;struct drm_rect src, dst;
@@ -57,7 +61,7 @@ struct vkms_crtc_state {int num_active_planes;/* stack of active planes for crc computation, should be in z order */ struct vkms_plane_state **active_planes; -void *active_writeback; +struct vkms_writeback_job *active_writeback;/* below four are protected by vkms_output.composer_lock */ bool crc_pending;
drivers/gpu/drm/vkms/vkms_writeback.c +16 -12
@@ -65,41 +65,45 @@ static int vkms_wb_connector_get_modes(struct drm_connector *connector)static int vkms_wb_prepare_job (struct drm_writeback_connector *wb_connector,struct drm_writeback_job *job) { -struct drm_gem_object *gem_obj; -struct dma_buf_map map; +struct vkms_writeback_job *vkmsjob;int ret;if (!job->fb)return 0 ; - gem_obj =drm_gem_fb_get_obj (job->fb,0 ); - ret =drm_gem_shmem_vmap (gem_obj, &map); + vkmsjob =kzalloc (sizeof (*vkmsjob),GFP_KERNEL ); +if (!vkmsjob) +return -ENOMEM ; + + ret =drm_gem_fb_vmap (job->fb, vkmsjob->map);if (ret) {DRM_ERROR ("vmap failed: %d\n" , ret); -return ret; + goto err_kfree; } - job->priv = map.vaddr; + job->priv = vkmsjob;return 0 ; + +err_kfree: +kfree (vkmsjob); +return ret; }static void vkms_wb_cleanup_job (struct drm_writeback_connector *connector,struct drm_writeback_job *job) { -struct drm_gem_object *gem_obj; +struct vkms_writeback_job *vkmsjob = job->priv;struct vkms_device *vkmsdev; -struct dma_buf_map map;if (!job->fb)return ; - gem_obj =drm_gem_fb_get_obj (job->fb,0 ); -dma_buf_map_set_vaddr (&map, job->priv); -drm_gem_shmem_vunmap (gem_obj, &map); +drm_gem_fb_vunmap (job->fb, vkmsjob->map); - vkmsdev =drm_device_to_vkms_device (gem_obj->dev); + vkmsdev =drm_device_to_vkms_device (job->fb->dev);vkms_set_composer (&vkmsdev->output, false); +kfree (vkmsjob); } static void vkms_wb_atomic_commit(struct drm_connector *conn,
Signature · 1 line
2.32.0