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

drm: Copy drm_wait_vblank to user before returning

[Why]
Userspace should get back a copy of drm_wait_vblank that's been modified
even when drm_wait_vblank_ioctl returns a failure.

Rationale:
drm_wait_vblank_ioctl modifies the request and expects the user to read
it back. When the type is RELATIVE, it modifies it to ABSOLUTE and updates
the sequence to become current_vblank_count + sequence (which was
RELATIVE), but now it became ABSOLUTE.
drmWaitVBlank (in libdrm) expects this to be the case as it modifies
the request to be Absolute so it expects the sequence to would have been
updated.

The change is in compat_drm_wait_vblank, which is called by
drm_compat_ioctl. This change of copying the data back regardless of the
return number makes it en par with drm_ioctl, which always copies the
data before returning.

[How]
Return from the function after everything has been copied to user.

Fixes IGT:kms_flip::modeset-vs-vblank-race-interruptible
Tested on ChromeOS Trogdor(msm)

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Signed-off-by: Mark Yacoub <markyacoub@chromium.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210812194917.1703356-1-markyacoub@chromium.org

authored by

Mark Yacoub and committed by
Sean Paul
fa0b1ef5 958f4425

+1 -3
+1 -3
drivers/gpu/drm/drm_ioc32.c
··· 855 855 req.request.sequence = req32.request.sequence; 856 856 req.request.signal = req32.request.signal; 857 857 err = drm_ioctl_kernel(file, drm_wait_vblank_ioctl, &req, DRM_UNLOCKED); 858 - if (err) 859 - return err; 860 858 861 859 req32.reply.type = req.reply.type; 862 860 req32.reply.sequence = req.reply.sequence; ··· 863 865 if (copy_to_user(argp, &req32, sizeof(req32))) 864 866 return -EFAULT; 865 867 866 - return 0; 868 + return err; 867 869 } 868 870 869 871 #if defined(CONFIG_X86)