drm: refuse ADDFB2 ioctl for broken bigendian drivers
Subsystems (2)
PATCH 1/1 drm: refuse ADDFB2 ioctl for broken bigendian drivers
Drivers must set the quirk_addfb_prefer_host_byte_order quirk to make the drm_mode_addfb() compat code work correctly on bigendian machines.
If they don't they interpret pixel_format values incorrectly for bug compatibility, which in turn implies the ADDFB2 ioctl does not work correctly then. So block it to make userspace fallback to ADDFB.
--- drivers/gpu/drm/drm_ioctl.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_ioctl.c +24 -1
@@ -469,6 +469,29 @@ static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)return 0 ; } +static int drm_mode_addfb2_check (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +#ifdef __BIG_ENDIAN +if (!dev->mode_config.quirk_addfb_prefer_host_byte_order) { +/* +* Drivers must set the +* quirk_addfb_prefer_host_byte_order quirk to make +* the drm_mode_addfb() compat code work correctly on +* bigendian machines. +* +* If they don't they interpret pixel_format values +* incorrectly for bug compatibility, which in turn +* implies the ADDFB2 ioctl does not work correctly +* then. So block it to make userspace fallback to +* ADDFB. +*/ +return -EINVAL ; + } +#endif +return drm_mode_addfb2 (dev, data, file_priv); +} +/* * Get version information *
@@ -645,7 +668,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETPROPBLOB , drm_mode_getblob_ioctl,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETFB , drm_mode_getfb,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB , drm_mode_addfb_ioctl,DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB2 , drm_mode_addfb2,DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB2 , drm_mode_addfb2_check,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_RMFB , drm_mode_rmfb_ioctl,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_PAGE_FLIP , drm_mode_page_flip_ioctl,DRM_MASTER |DRM_UNLOCKED ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_UNLOCKED),
Signature · 1 line
2.9.3
Quoted 27 lines · Gerd Hoffmann
Drivers must set the
quirk_addfb_prefer_host_byte_orderquirk to make thedrm_mode_addfb()compat code work correctly on bigendian machines.If they don't they interpret
pixel_formatvalues incorrectly for bug compatibility, which in turn implies the ADDFB2 ioctl does not work correctly then. So block it to make userspace fallback to ADDFB.Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/drm_ioctl.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_ioctl.c +7
-0@@ -469,6 +469,29 @@ static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)return 0 ; } +static int drm_mode_addfb2_check (struct drm_device *dev, +void *data,struct drm_file *file_priv) +{ +#ifdef __BIG_ENDIAN +if (!dev->mode_config.quirk_addfb_prefer_host_byte_order) { +/* +* Drivers must set the
drivers/gpu/drm/drm_ioctl.c static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value) · line 488
Quoted 10 lines
drivers/gpu/drm/drm_ioctl.c +10
-0+* quirk_addfb_prefer_host_byte_order quirk to make +* the drm_mode_addfb() compat code work correctly on +* bigendian machines. +* +* If they don't they interpret pixel_format values +* incorrectly for bug compatibility, which in turn +* implies the ADDFB2 ioctl does not work correctly +* then. So block it to make userspace fallback to +* ADDFB. +*/
DRM_DEBUG_KMS would be good here I think, just to help userspace people figure out why they got an -EINVAL.
drivers/gpu/drm/drm_ioctl.c static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value) · line 492
Quoted 4 lines
drivers/gpu/drm/drm_ioctl.c +4
-0+ return -EINVAL; + } +#endif +return drm_mode_addfb2 (dev, data, file_priv);
I think it'd be better if we have all the addfb code in drm_framebuffer.c. So leave the function name, and extract the common code into __drm_mode_addfb2 helper.
With these two nits addressed:
Quoted 21 lines
drivers/gpu/drm/drm_ioctl.c +3
-1+} +/* * Get version information * @@ -645,7 +668,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETPROPBLOB , drm_mode_getblob_ioctl,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_GETFB , drm_mode_getfb,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB , drm_mode_addfb_ioctl,DRM_UNLOCKED ), -DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB2 , drm_mode_addfb2,DRM_UNLOCKED ), +DRM_IOCTL_DEF (DRM_IOCTL_MODE_ADDFB2 , drm_mode_addfb2_check,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_RMFB , drm_mode_rmfb_ioctl,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_MODE_PAGE_FLIP , drm_mode_page_flip_ioctl,DRM_MASTER |DRM_UNLOCKED ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_UNLOCKED),Signature · 6 lines
2.9.3 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch