Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vkms: Let shadow-plane helpers prepare the plane's FB

Replace vkms' prepare_fb and cleanup_fb functions with the generic
code for shadow-buffered planes. No functional changes.

This change also fixes a problem where IGT kms_flip tests would
create a segmentation fault within vkms. The driver's prepare_fb
function did not report an error if a BO's vmap operation failed.
The kernel later tried to operate on the non-mapped memory areas.
The shared shadow-plane helpers handle errors correctly, so that
the driver now avoids the segmantation fault.

v2:
* include paragraph about IGT tests in commit message (Melissa)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Melissa Wen <melissa.srw@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210705074633.9425-4-tzimmermann@suse.de

+1 -37
+1 -37
drivers/gpu/drm/vkms/vkms_plane.c
··· 8 8 #include <drm/drm_gem_atomic_helper.h> 9 9 #include <drm/drm_gem_framebuffer_helper.h> 10 10 #include <drm/drm_plane_helper.h> 11 - #include <drm/drm_gem_shmem_helper.h> 12 11 13 12 #include "vkms_drv.h" 14 13 ··· 149 150 return 0; 150 151 } 151 152 152 - static int vkms_prepare_fb(struct drm_plane *plane, 153 - struct drm_plane_state *state) 154 - { 155 - struct drm_gem_object *gem_obj; 156 - struct dma_buf_map map; 157 - int ret; 158 - 159 - if (!state->fb) 160 - return 0; 161 - 162 - gem_obj = drm_gem_fb_get_obj(state->fb, 0); 163 - ret = drm_gem_shmem_vmap(gem_obj, &map); 164 - if (ret) 165 - DRM_ERROR("vmap failed: %d\n", ret); 166 - 167 - return drm_gem_plane_helper_prepare_fb(plane, state); 168 - } 169 - 170 - static void vkms_cleanup_fb(struct drm_plane *plane, 171 - struct drm_plane_state *old_state) 172 - { 173 - struct drm_gem_object *gem_obj; 174 - struct drm_gem_shmem_object *shmem_obj; 175 - struct dma_buf_map map; 176 - 177 - if (!old_state->fb) 178 - return; 179 - 180 - gem_obj = drm_gem_fb_get_obj(old_state->fb, 0); 181 - shmem_obj = to_drm_gem_shmem_obj(drm_gem_fb_get_obj(old_state->fb, 0)); 182 - dma_buf_map_set_vaddr(&map, shmem_obj->vaddr); 183 - drm_gem_shmem_vunmap(gem_obj, &map); 184 - } 185 - 186 153 static const struct drm_plane_helper_funcs vkms_primary_helper_funcs = { 187 154 .atomic_update = vkms_plane_atomic_update, 188 155 .atomic_check = vkms_plane_atomic_check, 189 - .prepare_fb = vkms_prepare_fb, 190 - .cleanup_fb = vkms_cleanup_fb, 156 + DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, 191 157 }; 192 158 193 159 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,