On Mon, Feb 2, 2026 at 11:07 AM Arnd Bergmann <[email protected]> wrote:
>
> From: Arnd Bergmann <[email protected]>
>
> These two ioctls are incompatible on 32-bit x86 userspace, because
> the data structures are shorter than they are on 64-bit.
>
> Add compad handling to the regular ioctl handler to just handle
> them the same way and ignore the extra padding. This could be
> done in a separate .compat_ioctl handler, but the main one already
> handles two versions of VDUSE_IOTLB_GET_FD, so adding a third one
> fits in rather well.
>

I'm just learning about the COMPAT_ stuff but does this mean the
userland app need to call a different ioctl depending if it is
compiled for 32 bits or 64 bits? I guess it is not the case, but how
is that handled?

> Fixes: ad146355bfad ("vduse: Support querying information of IOVA regions")
> Fixes: c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace")
> Signed-off-by: Arnd Bergmann <[email protected]>
> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 43 +++++++++++++++++++++++++++---
>  1 file changed, 40 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c 
> b/drivers/vdpa/vdpa_user/vduse_dev.c
> index 405d59610f76..39cbff2f379d 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -1341,6 +1341,37 @@ static int vduse_dev_iotlb_entry(struct vduse_dev *dev,
>         return r;
>  }
>
> +#if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT)
> +/*
> + * i386 has different alignment constraints than x86_64,
> + * so there are only 3 bytes of padding instead of 7.
> + */
> +struct compat_vduse_iotlb_entry {
> +       compat_u64 offset;
> +       compat_u64 start;
> +       compat_u64 last;
> +       __u8 perm;
> +       __u8 padding[__alignof__(compat_u64) - 1];
> +};
> +#define COMPAT_VDUSE_IOTLB_GET_FD      _IOWR(VDUSE_BASE, 0x10, struct 
> compat_vduse_iotlb_entry)
> +
> +struct compat_vduse_vq_info {
> +       __u32 index;
> +       __u32 num;
> +       compat_u64 desc_addr;
> +       compat_u64 driver_addr;
> +       compat_u64 device_addr;
> +       union {
> +               struct vduse_vq_state_split split;
> +               struct vduse_vq_state_packed packed;
> +       };
> +       __u8 ready;
> +       __u8 padding[__alignof__(compat_u64) - 1];
> +} __uapi_arch_align;
> +#define COMPAT_VDUSE_VQ_GET_INFO       _IOWR(VDUSE_BASE, 0x15, struct 
> compat_vduse_vq_info)
> +
> +#endif
> +
>  static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
>                             unsigned long arg)
>  {
> @@ -1352,6 +1383,9 @@ static long vduse_dev_ioctl(struct file *file, unsigned 
> int cmd,
>                 return -EPERM;
>
>         switch (cmd) {
> +#if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT)
> +       case COMPAT_VDUSE_IOTLB_GET_FD:
> +#endif
>         case VDUSE_IOTLB_GET_FD:
>         case VDUSE_IOTLB_GET_FD2: {
>                 struct vduse_iotlb_entry_v2 entry = {0};
> @@ -1455,13 +1489,16 @@ static long vduse_dev_ioctl(struct file *file, 
> unsigned int cmd,
>                 ret = 0;
>                 break;
>         }
> +#if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT)
> +       case COMPAT_VDUSE_VQ_GET_INFO:
> +#endif
>         case VDUSE_VQ_GET_INFO: {
> -               struct vduse_vq_info vq_info;
> +               struct vduse_vq_info vq_info = {};
>                 struct vduse_virtqueue *vq;
>                 u32 index;
>
>                 ret = -EFAULT;
> -               if (copy_from_user(&vq_info, argp, sizeof(vq_info)))
> +               if (copy_from_user(&vq_info, argp, _IOC_SIZE(cmd)))
>                         break;
>
>                 ret = -EINVAL;
> @@ -1491,7 +1528,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned 
> int cmd,
>                 vq_info.ready = vq->ready;
>
>                 ret = -EFAULT;
> -               if (copy_to_user(argp, &vq_info, sizeof(vq_info)))
> +               if (copy_to_user(argp, &vq_info, _IOC_SIZE(cmd)))
>                         break;
>
>                 ret = 0;
> --
> 2.39.5
>
>


Reply via email to