dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Intel-gfx@lists.freedesktop.org,
	Daniel Stone <daniels@collabora.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH] drm: Provide compat ioctl for addfb2.1
Date: Tue, 14 Jul 2015 10:15:28 +0200	[thread overview]
Message-ID: <20150714081528.GI3736@phenom.ffwll.local> (raw)
In-Reply-To: <1436803013-21053-1-git-send-email-tvrtko.ursulin@linux.intel.com>

On Mon, Jul 13, 2015 at 04:56:53PM +0100, Tvrtko Ursulin wrote:
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> Frame buffer modifiers extensions provided in;
> 
>   commit e3eb3250d84ef97b766312345774367b6a310db8
>   Author: Rob Clark <robdclark@gmail.com>
>   Date:   Thu Feb 5 14:41:52 2015 +0000
> 
>       drm: add support for tiled/compressed/etc modifier in addfb2
> 
> Missed the structure packing/alignment problem where 64-bit
> members were added after the odd number of 32-bit ones. This
> makes the compiler produce structures of different sizes under
> 32- and 64-bit x86 targets and makes the ioctl need explicit
> compat handling.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Daniel Stone <daniels@collabora.com>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> ---
>  drivers/gpu/drm/drm_ioc32.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
> index aa8bbb460c57..2bea11bfb3ae 100644
> --- a/drivers/gpu/drm/drm_ioc32.c
> +++ b/drivers/gpu/drm/drm_ioc32.c
> @@ -70,6 +70,8 @@
>  
>  #define DRM_IOCTL_WAIT_VBLANK32		DRM_IOWR(0x3a, drm_wait_vblank32_t)
>  
> +#define DRM_IOCTL_MODE_ADDFB232		DRM_IOWR(0xb8, drm_mode_fb_cmd232_t)
> +
>  typedef struct drm_version_32 {
>  	int version_major;	  /**< Major version */
>  	int version_minor;	  /**< Minor version */
> @@ -1016,6 +1018,63 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
>  	return 0;
>  }
>  
> +typedef struct drm_mode_fb_cmd232 {

Please no typedefs for structs in new code. drm_ioc32.c has lots of them
simply because it's old. Also the patch needs cc: stable. With that

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> +	u32 fb_id;
> +	u32 width;
> +	u32 height;
> +	u32 pixel_format;
> +	u32 flags;
> +	u32 handles[4];
> +	u32 pitches[4];
> +	u32 offsets[4];
> +	u64 modifier[4];
> +} __attribute__((packed)) drm_mode_fb_cmd232_t;
> +
> +static int compat_drm_mode_addfb2(struct file *file, unsigned int cmd,
> +				  unsigned long arg)
> +{
> +	drm_mode_fb_cmd232_t __user *argp = (void __user *)arg;
> +	struct drm_mode_fb_cmd232 req32;
> +	struct drm_mode_fb_cmd2 __user *req64;
> +	int i;
> +	int err;
> +
> +	if (copy_from_user(&req32, argp, sizeof(req32)))
> +		return -EFAULT;
> +
> +	req64 = compat_alloc_user_space(sizeof(*req64));
> +
> +	if (!access_ok(VERIFY_WRITE, req64, sizeof(*req64))
> +	    || __put_user(req32.width, &req64->width)
> +	    || __put_user(req32.height, &req64->height)
> +	    || __put_user(req32.pixel_format, &req64->pixel_format)
> +	    || __put_user(req32.flags, &req64->flags))
> +		return -EFAULT;
> +
> +	for (i = 0; i < 4; i++) {
> +		if (__put_user(req32.handles[i], &req64->handles[i]))
> +			return -EFAULT;
> +		if (__put_user(req32.pitches[i], &req64->pitches[i]))
> +			return -EFAULT;
> +		if (__put_user(req32.offsets[i], &req64->offsets[i]))
> +			return -EFAULT;
> +		if (__put_user(req32.modifier[i], &req64->modifier[i]))
> +			return -EFAULT;
> +	}
> +
> +	err = drm_ioctl(file, DRM_IOCTL_MODE_ADDFB2, (unsigned long)req64);
> +	if (err)
> +		return err;
> +
> +	if (__get_user(req32.fb_id, &req64->fb_id))
> +		return -EFAULT;
> +
> +	if (copy_to_user(argp, &req32, sizeof(req32)))
> +		return -EFAULT;
> +
> +	return 0;
> +}
> +
>  static drm_ioctl_compat_t *drm_compat_ioctls[] = {
>  	[DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
>  	[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
> @@ -1048,6 +1107,7 @@ static drm_ioctl_compat_t *drm_compat_ioctls[] = {
>  	[DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32)] = compat_drm_update_draw,
>  #endif
>  	[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
> +	[DRM_IOCTL_NR(DRM_IOCTL_MODE_ADDFB232)] = compat_drm_mode_addfb2,
>  };
>  
>  /**
> -- 
> 2.4.2
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

      parent reply	other threads:[~2015-07-14  8:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-13 15:56 [PATCH] drm: Provide compat ioctl for addfb2.1 Tvrtko Ursulin
2015-07-13 17:18 ` Rob Clark
2015-07-14  8:15 ` Daniel Vetter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150714081528.GI3736@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=Intel-gfx@lists.freedesktop.org \
    --cc=daniel.vetter@intel.com \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tvrtko.ursulin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox