linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
PATCH v5 1/1 linux-user: syscall: ioctls: support DRM_IOCTL_VERSION
From: Chen Gang <[email protected]>
Another DRM_IOCTL_* commands will be done later.
--- configure | 10 ++++ linux-user/ioctls.h | 5 ++ linux-user/syscall.c | 117 +++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 15 +++++ linux-user/syscall_types.h | 11 ++++ 5 files changed, 158 insertions(+)
configure +10 -0
@@ -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
linux-user/ioctls.h +5 -0
@@ -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)
linux-user/syscall.c +117 -0
129 lines not on this page · raw message
linux-user/syscall_defs.h +15 -0
@@ -1167,6 +1167,9 @@ struct target_rtc_pll_info {#define TARGET_DM_TARGET_MSG TARGET_IOWRU(0xfd, 0x0e)#define TARGET_DM_DEV_SET_GEOMETRY TARGET_IOWRU(0xfd, 0x0f) +/* drm ioctls */ +#define TARGET_DRM_IOCTL_VERSION TARGET_IOWRU('d', 0x00) +/* from asm/termbits.h */ #define TARGET_NCC 8
@@ -2598,6 +2601,18 @@ struct target_mq_attr {abi_long mq_curmsgs; }; +struct target_drm_version { +int version_major; +int version_minor; +int version_patchlevel; +abi_ulong name_len; +abi_ulong name; +abi_ulong date_len; +abi_ulong date; +abi_ulong desc_len; +abi_ulong desc; +}; +#include "socket.h" #include "errno_defs.h"
linux-user/syscall_types.h +11 -0
@@ -292,6 +292,17 @@ STRUCT(dm_target_versions,STRUCT (dm_target_msg, TYPE_ULONGLONG) /* sector */ +STRUCT (drm_version, +TYPE_INT ,/* version_major */ +TYPE_INT ,/* version_minor */ +TYPE_INT ,/* version_patchlevel */ +TYPE_ULONG ,/* name_len */ +TYPE_PTRVOID ,/* name */ +TYPE_ULONG ,/* date_len */ +TYPE_PTRVOID ,/* date */ +TYPE_ULONG ,/* desc_len */ + TYPE_PTRVOID) /* desc */ + STRUCT(file_clone_range, TYPE_LONGLONG, /* src_fd */ TYPE_ULONGLONG, /* src_offset */
Signature · 1 line
2.24.0.308.g228f53135a
Le 03/06/2020 à 03:08, [email protected] a écrit :
Quoted 72 lines
From: Chen Gang <[email protected]>
Another DRM_IOCTL_* commands will be done later.
Signed-off-by Chen Gang <[email protected]>--- configure | 10 ++++ linux-user/ioctls.h | 5 ++ linux-user/syscall.c | 117 +++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 15 +++++ linux-user/syscall_types.h | 11 ++++ 5 files changed, 158 insertions(+)configure +10
-0@@ -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 filinux-user/ioctls.h +5
-0@@ -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)linux-user/syscall.c +3
-0@@ -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"
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5286
Quoted 9 lines
linux-user/syscall.c +6
-0@@ -5275,6 +5278,120 @@ static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, }#endif +#ifdef HAVE_DRM_H + +static void unlock_drm_version (struct drm_version *host_ver) +{ +if (host_ver->name) { +unlock_user (host_ver->name,0UL ,0 );
unlock_user() allows to have a NULL host pointer parameter, so you don't need to check. But you must provide the target pointer, with the length. The same below.
Quoted 43 lines
linux-user/syscall.c +43
-0+ } +if (host_ver->date) { +unlock_user (host_ver->date,0UL ,0 ); + } +if (host_ver->desc) { +unlock_user (host_ver->desc,0UL ,0 ); + } +} + +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 ; + } + +memset (host_ver,0 ,sizeof (*host_ver)); + +__get_user (host_ver->name_len, &target_ver->name_len); +if (host_ver->name_len) { + host_ver->name =lock_user (VERIFY_WRITE , target_ver->name, + target_ver->name_len,0 ); +if (!host_ver->name) { + goto err; + } + } + +__get_user (host_ver->date_len, &target_ver->date_len); +if (host_ver->date_len) { + host_ver->date =lock_user (VERIFY_WRITE , target_ver->date, + target_ver->date_len,0 ); +if (!host_ver->date) { + goto err; + } + } + +__get_user (host_ver->desc_len, &target_ver->desc_len); +if (host_ver->desc_len) { + host_ver->desc =lock_user (VERIFY_WRITE , target_ver->desc, + target_ver->desc_len,0 ); +if (!host_ver->desc) {
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5339
Quoted 10 lines
linux-user/syscall.c +10
-0+ goto err; + } + } + +unlock_user_struct (target_ver, target_addr,0 ); +return 0 ; +err: +unlock_drm_version (host_ver); +unlock_user_struct (target_ver, target_addr,0 ); +return -ENOMEM ;
In fact it should be -TARGET_EFAULT: it has failed because of access rights.
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5347
Quoted 8 lines
linux-user/syscall.c +8
-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 )) {
I think you should not unlock_struct() in target_to_host_drmversion() so you don't have to lock it again here.
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5359
Quoted 12 lines
linux-user/syscall.c +12
-0+unlock_drm_version (host_ver); +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); +__put_user (host_ver->date_len, &target_ver->date_len); +__put_user (host_ver->desc_len, &target_ver->desc_len); +if (host_ver->name) { +unlock_user (host_ver->name, target_ver->name, host_ver->name_len); + }
No need to check if host_ver->name is NULL.
Same below.
Quoted 9 lines
linux-user/syscall.c +9
-0+if (host_ver->date) { +unlock_user (host_ver->date, target_ver->date, host_ver->date_len); + } +if (host_ver->desc) { +unlock_user (host_ver->desc, target_ver->desc, host_ver->desc_len); + } +unlock_user_struct (target_ver, target_addr,0 ); +return 0 ; +}
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5378
Quoted 10 lines
linux-user/syscall.c +10
-0+ +static abi_long do_ioctl_drm (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +struct drm_version *ver; +abi_long ret; + +switch (ie->host_cmd) { +case DRM_IOCTL_VERSION : + ver = (struct drm_version *)buf_temp;
you should lock the structure here (rather than in target_to_host_drmversion())...
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5388
Quoted 10 lines
linux-user/syscall.c +10
-0+ ret =target_to_host_drmversion (ver, arg); +if (is_error (ret)) { +return ret; + } + ret =get_errno (safe_ioctl (fd, ie->host_cmd, ver)); +if (is_error (ret)) { +unlock_drm_version (ver); +return ret; + } +return host_to_target_drmversion (arg, ver);
and unlock the structure here (rather than in host_to_target_drmversion()).
You should return "ret" too.
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5390
Quoted 2 lines
linux-user/syscall.c +2
-0+ } +return -TARGET_EFAULT ;
Why -TARGET_EFAULT? -TARGET_ENOSYS would be better.
Quoted 53 lines
linux-user/syscall.c +4
-0+} + +#endif + static IOCTLEntry ioctl_entries[] = { #define IOCTL(cmd, access, ...) \ { TARGET_ ## cmd, cmd, #cmd, access, 0, { __VA_ARGS__ } },linux-user/syscall_defs.h +15
-0@@ -1167,6 +1167,9 @@ struct target_rtc_pll_info {#define TARGET_DM_TARGET_MSG TARGET_IOWRU(0xfd, 0x0e)#define TARGET_DM_DEV_SET_GEOMETRY TARGET_IOWRU(0xfd, 0x0f) +/* drm ioctls */ +#define TARGET_DRM_IOCTL_VERSION TARGET_IOWRU('d', 0x00) +/* from asm/termbits.h */ #define TARGET_NCC 8@@ -2598,6 +2601,18 @@ struct target_mq_attr {abi_long mq_curmsgs; }; +struct target_drm_version { +int version_major; +int version_minor; +int version_patchlevel; +abi_ulong name_len; +abi_ulong name; +abi_ulong date_len; +abi_ulong date; +abi_ulong desc_len; +abi_ulong desc; +}; +#include "socket.h" #include "errno_defs.h" linux-user/syscall_types.h +4
-0@@ -292,6 +292,17 @@ STRUCT(dm_target_versions,STRUCT (dm_target_msg, TYPE_ULONGLONG) /* sector */ +STRUCT(drm_version, + TYPE_INT, /* version_major */ + TYPE_INT, /* version_minor */ + TYPE_INT, /* version_patchlevel */
linux-user/syscall_types.h STRUCT(dm_target_versions, · line 308
Quoted 10 lines
linux-user/syscall_types.h +7
-0+ TYPE_ULONG, /* name_len */ +TYPE_PTRVOID ,/* name */ +TYPE_ULONG ,/* date_len */ +TYPE_PTRVOID ,/* date */ + TYPE_ULONG, /* desc_len */ + TYPE_PTRVOID) /* desc */ + STRUCT(file_clone_range, TYPE_LONGLONG, /* src_fd */ TYPE_ULONGLONG, /* src_offset */
Thanks,
Laurent
Quoted 12 lines · Laurent Vivier
Le 03/06/2020 à 03:08, [email protected] a écrit :
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5286
Quoted 6 lines
linux-user/syscall.c +6
-0+#ifdef HAVE_DRM_H + +static void unlock_drm_version (struct drm_version *host_ver) +{ +if (host_ver->name) { +unlock_user (host_ver->name,0UL ,0 );
unlock_user()allows to have a NULL host pointer parameter, so you don't need to check. But you must provide the target pointer, with the length. The same below.
As far as I know, the unlock_user is defined in include/exec/softmmu-semi.h, which only checks the len before calling cpu_memory_rw_debug, and only calls free() for the host pointer.
So we have to be sure that the host pointer must be valid. When we pass 0 length to unlock_user, we want it to free host pointer only.
Quoted 8 lines
Quoted 8 lines
linux-user/syscall.c +8
-0+if (host_ver->desc_len) { + host_ver->desc =lock_user (VERIFY_WRITE , target_ver->desc, + target_ver->desc_len,0 ); +if (!host_ver->desc) { + goto err; + } + } +
Quoted 9 lines
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5339
Quoted 6 lines
linux-user/syscall.c +6
-0+unlock_user_struct (target_ver, target_addr,0 ); +return 0 ; +err: +unlock_drm_version (host_ver); +unlock_user_struct (target_ver, target_addr,0 ); +return -ENOMEM ;In fact it should be -TARGET_EFAULT: it has failed because of access rights.
As far as I know, the lock_user is defined in include/exec/softmmu-semi.h. If the parameter 'copy' is 0 (in our case), lock_user will only malloc a host pointer and return it.
In our case, I guess the only failure from malloc() is "no memory".
Quoted 12 lines
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5347
Quoted 8 lines
linux-user/syscall.c +7
-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 )) {I think you should not
unlock_struct()intarget_to_host_drmversion()so you don't have to lock it again here.
OK, thanks.
Quoted 4 lines
Quoted 4 lines
linux-user/syscall.c +4
-0+static abi_long do_ioctl_drm (const IOCTLEntry *ie,uint8_t *buf_temp, +int fd,int cmd,abi_long arg) +{ +struct drm_version *ver;
Quoted 9 lines
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5378
Quoted 5 lines
linux-user/syscall.c +5
-0+abi_long ret; + +switch (ie->host_cmd) { +case DRM_IOCTL_VERSION : + ver = (struct drm_version *)buf_temp;you should lock the structure here (rather than in
target_to_host_drmversion())...
OK, thanks.
Quoted 11 lines
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5388
Quoted 10 lines
linux-user/syscall.c +10
-0+ ret =target_to_host_drmversion (ver, arg); +if (is_error (ret)) { +return ret; + } + ret =get_errno (safe_ioctl (fd, ie->host_cmd, ver)); +if (is_error (ret)) { +unlock_drm_version (ver); +return ret; + } +return host_to_target_drmversion (arg, ver);
Quoted 4 lines
and unlock the structure here (rather than in
host_to_target_drmversion()).You should return "ret" too.
OK, thanks.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + return -TARGET_EFAULT;Why -TARGET_EFAULT? -TARGET_ENOSYS would be better.
OK, thanks.
Chen Gang.
Le 03/06/2020 à 13:05, Chen Gang a écrit :
Quoted 14 lines · Laurent Vivier
Quoted 12 lines
Le 03/06/2020 à 03:08, [email protected] a écrit :
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5286
Quoted 6 lines
linux-user/syscall.c +6
-0+#ifdef HAVE_DRM_H + +static void unlock_drm_version (struct drm_version *host_ver) +{ +if (host_ver->name) { +unlock_user (host_ver->name,0UL ,0 );
unlock_user()allows to have a NULL host pointer parameter, so you don't need to check. But you must provide the target pointer, with the length. The same below.
Quoted 6 lines
As far as I know, the
unlock_useris defined ininclude/exec/softmmu-semi.h, which only checks the len before callingcpu_memory_rw_debug, and only callsfree()for the host pointer.So we have to be sure that the host pointer must be valid. When we pass 0 length to
unlock_user, we want it to free host pointer only.
No, it is defined in our case in linux-user/qemu.h, and associated comment is:
/* Unlock an area of guest memory. The first LEN bytes must be
flushed back to guest memory. host_ptr = NULL is explicitly allowed and does nothing. */
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
linux-user/syscall.c +4
-0+if (host_ver->desc_len) { + host_ver->desc =lock_user (VERIFY_WRITE , target_ver->desc, + target_ver->desc_len,0 ); +if (!host_ver->desc) {linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5339
Quoted 10 lines
linux-user/syscall.c +10
-0+ goto err; + } + } + +unlock_user_struct (target_ver, target_addr,0 ); +return 0 ; +err: +unlock_drm_version (host_ver); +unlock_user_struct (target_ver, target_addr,0 ); +return -ENOMEM ;In fact it should be -TARGET_EFAULT: it has failed because of access rights.
Quoted 3 lines
As far as I know, the
lock_useris defined ininclude/exec/softmmu-semi.h. If the parameter 'copy' is 0 (in our case),lock_userwill only malloc a host pointer and return it.
No, in linux-user/qemu.h:
/* Lock an area of guest memory into the host. If copy is true then the
host area will have the same contents as the guest. */
Quoted 1 line
In our case, I guess the only failure from
malloc()is "no memory".
See use-cases in syscall.c, they all fail with -TARGET_EFAULT.
Thanks,
Laurent
OK, thanks. I'll send patch v6. :)
Quoted 60 lines · Laurent Vivier
Le 03/06/2020 à 13:05, Chen Gang a écrit :
Quoted 14 lines · Laurent Vivier
Quoted 12 lines
Le 03/06/2020 à 03:08, [email protected] a écrit :
linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5286
Quoted 6 lines
linux-user/syscall.c +6
-0+#ifdef HAVE_DRM_H + +static void unlock_drm_version (struct drm_version *host_ver) +{ +if (host_ver->name) { +unlock_user (host_ver->name,0UL ,0 );
unlock_user()allows to have a NULL host pointer parameter, so you don't need to check. But you must provide the target pointer, with the length. The same below.Quoted 6 lines
As far as I know, the
unlock_useris defined ininclude/exec/softmmu-semi.h, which only checks the len before callingcpu_memory_rw_debug, and only callsfree()for the host pointer.So we have to be sure that the host pointer must be valid. When we pass 0 length to
unlock_user, we want it to free host pointer only.No, it is defined in our case in
linux-user/qemu.h, and associated comment is:/* Unlock an area of guest memory. The first LEN bytes must be
flushed back to guest memory.host_ptr= NULL is explicitly allowed and does nothing. */Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
linux-user/syscall.c +4
-0+if (host_ver->desc_len) { + host_ver->desc =lock_user (VERIFY_WRITE , target_ver->desc, + target_ver->desc_len,0 ); +if (!host_ver->desc) {linux-user/syscall.c static abi_long do_ioctl_tiocgptpeer(const IOCTLEntry *ie, uint8_t *buf_temp, · line 5339
Quoted 10 lines
linux-user/syscall.c +10
-0+ goto err; + } + } + +unlock_user_struct (target_ver, target_addr,0 ); +return 0 ; +err: +unlock_drm_version (host_ver); +unlock_user_struct (target_ver, target_addr,0 ); +return -ENOMEM ;In fact it should be -TARGET_EFAULT: it has failed because of access rights.
Quoted 3 lines
As far as I know, the
lock_useris defined ininclude/exec/softmmu-semi.h. If the parameter 'copy' is 0 (in our case),lock_userwill only malloc a host pointer and return it.No, in
linux-user/qemu.h:/* Lock an area of guest memory into the host. If copy is true then the
host area will have the same contents as the guest. */Quoted 1 line
In our case, I guess the only failure from
malloc()is "no memory".See use-cases in
syscall.c, they all fail with -TARGET_EFAULT.