All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: chengang@emindsoft.com.cn, riku.voipio@iki.fi
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v4] linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
Date: Tue, 2 Jun 2020 15:40:26 +0200	[thread overview]
Message-ID: <5525a258-7e9e-d52f-736c-db51ea2ea9cc@vivier.eu> (raw)
In-Reply-To: <20200602120023.5963-1-chengang@emindsoft.com.cn>

Le 02/06/2020 à 14:00, chengang@emindsoft.com.cn a écrit :
> From: Chen Gang <chengang@emindsoft.com.cn>
> 
> Another DRM_IOCTL_* commands will be done later.
> 
> Signed-off-by: Chen Gang <chengang@emindsoft.com.cn>
> ---
>  configure                  | 10 ++++++
>  linux-user/ioctls.h        |  5 +++
>  linux-user/syscall.c       | 67 ++++++++++++++++++++++++++++++++++++++
>  linux-user/syscall_defs.h  | 15 +++++++++
>  linux-user/syscall_types.h | 11 +++++++
>  5 files changed, 108 insertions(+)
> 
> diff --git a/configure b/configure
> index e225a1e3ff..3cf28a649a 100755
> --- a/configure
> +++ b/configure
> @@ -3140,6 +3140,13 @@ if ! check_include "ifaddrs.h" ; then
>    have_ifaddrs_h=no
>  fi
>  
> +#########################################
> +# libdrm check
> +have_drm_h=no
> +if check_include "libdrm/drm.h" ; then
> +    have_drm_h=yes
> +fi
> +
>  ##########################################
>  # VTE probe
>  
> @@ -7149,6 +7156,9 @@ fi
>  if test "$have_ifaddrs_h" = "yes" ; then
>      echo "HAVE_IFADDRS_H=y" >> $config_host_mak
>  fi
> +if test "$have_drm_h" = "yes" ; then
> +  echo "HAVE_DRM_H=y" >> $config_host_mak
> +fi
>  if test "$have_broken_size_max" = "yes" ; then
>      echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
>  fi

The configure and HAVE_DRM_H look good...

> diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
> index 0defa1d8c1..f2e2fa9c87 100644
> --- a/linux-user/ioctls.h
> +++ b/linux-user/ioctls.h
> @@ -574,6 +574,11 @@
>    IOCTL_SPECIAL(SIOCDELRT, IOC_W, do_ioctl_rt,
>                  MK_PTR(MK_STRUCT(STRUCT_rtentry)))
>  
> +#ifdef HAVE_DRM_H
> +  IOCTL_SPECIAL(DRM_IOCTL_VERSION, IOC_RW, do_ioctl_drm,
> +                MK_PTR(MK_STRUCT(STRUCT_drm_version)))
> +#endif
> +
>  #ifdef TARGET_TIOCSTART
>    IOCTL_IGNORE(TIOCSTART)
>    IOCTL_IGNORE(TIOCSTOP)
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 5af55fca78..006889cea6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -112,6 +112,9 @@
>  #include <linux/if_alg.h>
>  #include <linux/rtc.h>
>  #include <sound/asound.h>
> +#ifdef HAVE_DRM_H
> +#include <libdrm/drm.h>
> +#endif
>  #include "linux_loop.h"
>  #include "uname.h"
>  
> @@ -5275,6 +5278,70 @@ static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp,
>  }
>  #endif
>  
> +#ifdef HAVE_DRM_H
> +
> +static inline abi_long target_to_host_drmversion(struct drm_version *host_ver,
> +                                                abi_long target_addr)
> +{
> +    struct target_drm_version *target_ver;
> +
> +    if (!lock_user_struct(VERIFY_READ, target_ver, target_addr, 0)) {
> +        return -TARGET_EFAULT;
> +    }
> +    __get_user(host_ver->name_len, &target_ver->name_len);
> +    host_ver->name = host_ver->name_len ? g2h(target_ver->name) : NULL;
> +    __get_user(host_ver->date_len, &target_ver->date_len);
> +    host_ver->date = host_ver->date_len ? g2h(target_ver->date) : NULL;
> +    __get_user(host_ver->desc_len, &target_ver->desc_len);
> +    host_ver->desc = host_ver->desc_len ? g2h(target_ver->desc) : NULL;

but I think the string buffers must be locked and access rights must be
checked.

So I think you should have something like:

host_ver->name = lock_user(VERIFY_WRITE, target_ver->name,
                           target_ver->name_len, 0);
...

> +    unlock_user_struct(target_ver, target_addr, 0);
> +    return 0;
> +}
> +
> +static inline abi_long host_to_target_drmversion(abi_ulong target_addr,
> +                                                 struct drm_version *host_ver)
> +{
> +    struct target_drm_version *target_ver;
> +
> +    if (!lock_user_struct(VERIFY_WRITE, target_ver, target_addr, 0)) {
> +        return -TARGET_EFAULT;
> +    }
> +    __put_user(host_ver->version_major, &target_ver->version_major);
> +    __put_user(host_ver->version_minor, &target_ver->version_minor);
> +    __put_user(host_ver->version_patchlevel, &target_ver->version_patchlevel);
> +    __put_user(host_ver->name_len, &target_ver->name_len);

unlock_user(host_ver->name, target_ver->name, host_ver->name_len);
...

> +    __put_user(host_ver->date_len, &target_ver->date_len);
> +    __put_user(host_ver->desc_len, &target_ver->desc_len);
> +    unlock_user_struct(target_ver, target_addr, 0);
> +    return 0;
> +}
> +

Thanks,
Laurent



  reply	other threads:[~2020-06-02 13:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-02 12:00 [PATCH v4] linux-user: syscall: ioctls: support DRM_IOCTL_VERSION chengang
2020-06-02 13:40 ` Laurent Vivier [this message]
2020-06-02 14:19   ` Chen Gang

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=5525a258-7e9e-d52f-736c-db51ea2ea9cc@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=chengang@emindsoft.com.cn \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.