linux-user: Misc patches for 4.2
v2 cover linux-user: Misc patches for 4.2
From: Aleksandar Markovic <[email protected]>
A set of misc linux user patches for 4.2.
v2->v3:
- minor code formatting improvements
- added a patch on semtimedop()
v1->v2:
- updated commit messages
- minor improvements of code formatting
- added three patches containing support for ten additional ioctls
Aleksandar Markovic (5):
linux-user: Add support for FDMSGON and FDMSGOFF ioctls
linux-user: Add support for FDRESET, FDRAWCMD, FDTWADDLE, and FDEJECT
ioctls
linux-user: Add support for FDFMTBEG, FDFMTTRK, and FDFMTEND ioctls
linux-user: Add support for FDSETEMSGTRESH, FDSETMAXERRS, and
FDGETMAXERRS ioctls
linux-user: Add support for RNDRESEEDCRNG ioctl
Aleksandar Rikalo (1):
linux-user: Add support for semtimedop() syscall
Yunqiang Su (1):
linux user: Add support for FDFLUSH ioctl
linux-user/ioctls.h | 16 ++++++++++++++++ linux-user/syscall.c | 37 +++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 33 +++++++++++++++++++++++++++++++++ linux-user/syscall_types.h | 12 ++++++++++++ 4 files changed, 98 insertions(+)
Signature · 1 line
2.7.4
PATCH v2 1/7 linux user: Add support for FDFLUSH ioctl
From: Yunqiang Su <[email protected]>
FDFLUSH is used for flushing buffers of floppy drives. Support in QEMU is needed because some of Debian packages use this ioctl while running post-build tests. One such example is 'tar' package.
--- linux-user/ioctls.h | 2 ++ linux-user/syscall.c | 1 + linux-user/syscall_defs.h | 4 ++++ 3 files changed, 7 insertions(+)
linux-user/ioctls.h +2 -0
@@ -112,6 +112,8 @@ IOCTL(BLKZEROOUT, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2)))#endif + IOCTL(FDFLUSH, 0, TYPE_NULL) +#ifdef FIBMAP IOCTL(FIBMAP, IOC_W | IOC_R, MK_PTR(TYPE_LONG))#endif
linux-user/syscall.c +1 -0
@@ -87,6 +87,7 @@#include <linux/kd.h> #include <linux/mtio.h> #include <linux/fs.h> +#include <linux/fd.h> #if defined(CONFIG_FIEMAP )#include <linux/fiemap.h> #endif
linux-user/syscall_defs.h +4 -0
@@ -883,6 +883,10 @@ struct target_pollfd {#define TARGET_BLKROTATIONAL TARGET_IO(0x12, 126)#define TARGET_BLKZEROOUT TARGET_IO(0x12, 127) +/* From <linux/fd.h> */ + +#define TARGET_FDFLUSH TARGET_IO(2, 0x4b) +#define TARGET_FIBMAP TARGET_IO(0x00,1)/* bmap access */ #define TARGET_FIGETBSZ TARGET_IO(0x00,2)/* get the block size used for bmap */
Signature · 1 line
2.7.4
PATCH v2 2/7 linux-user: Add support for FDMSGON and FDMSGOFF ioctls
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
FDMSGON and FDMSGOFF switch informational messages of floppy drives on and off.
--- linux-user/ioctls.h | 2 ++ linux-user/syscall_defs.h | 2 ++ 2 files changed, 4 insertions(+)
linux-user/ioctls.h +2 -0
@@ -112,6 +112,8 @@ IOCTL(BLKZEROOUT, IOC_W, MK_PTR(MK_ARRAY(TYPE_ULONGLONG, 2)))#endif + IOCTL(FDMSGON, 0, TYPE_NULL) + IOCTL(FDMSGOFF, 0, TYPE_NULL) IOCTL(FDFLUSH, 0, TYPE_NULL)#ifdef FIBMAP
linux-user/syscall_defs.h +2 -0
@@ -885,6 +885,8 @@ struct target_pollfd {/* From <linux/fd.h> */ +#define TARGET_FDMSGON TARGET_IO(2, 0x45) +#define TARGET_FDMSGOFF TARGET_IO(2, 0x46)#define TARGET_FDFLUSH TARGET_IO(2, 0x4b)#define TARGET_FIBMAP TARGET_IO(0x00,1)/* bmap access */
Signature · 1 line
2.7.4
PATCH v2 3/7 linux-user: Add support for FDRESET, FDRAWCMD, FDTWADDLE, and FDEJECT ioctls
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
FDRESET, FDRAWCMD, FDTWADDLE, and FDEJECT ioctls are misc commands for controlling a floppy drive.
--- linux-user/ioctls.h | 4 ++++ linux-user/syscall_defs.h | 4 ++++ 2 files changed, 8 insertions(+)
linux-user/ioctls.h +4 -0
@@ -115,6 +115,10 @@ IOCTL(FDMSGON, 0, TYPE_NULL) IOCTL(FDMSGOFF, 0, TYPE_NULL) IOCTL(FDFLUSH, 0, TYPE_NULL) + IOCTL(FDRESET, 0, TYPE_NULL) + IOCTL(FDRAWCMD, 0, TYPE_NULL) + IOCTL(FDTWADDLE, 0, TYPE_NULL) + IOCTL(FDEJECT, 0, TYPE_NULL)#ifdef FIBMAP IOCTL (FIBMAP ,IOC_W |IOC_R ,MK_PTR (TYPE_LONG ))
linux-user/syscall_defs.h +4 -0
@@ -888,6 +888,10 @@ struct target_pollfd {#define TARGET_FDMSGON TARGET_IO(2, 0x45)#define TARGET_FDMSGOFF TARGET_IO(2, 0x46)#define TARGET_FDFLUSH TARGET_IO(2, 0x4b) +#define TARGET_FDRESET TARGET_IO(2, 0x54) +#define TARGET_FDRAWCMD TARGET_IO(2, 0x58) +#define TARGET_FDTWADDLE TARGET_IO(2, 0x59) +#define TARGET_FDEJECT TARGET_IO(2, 0x5a)#define TARGET_FIBMAP TARGET_IO(0x00,1)/* bmap access */ #define TARGET_FIGETBSZ TARGET_IO(0x00,2)/* get the block size used for bmap */
Signature · 1 line
2.7.4
PATCH v2 4/7 linux-user: Add support for FDFMTBEG, FDFMTTRK, and FDFMTEND ioctls
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
FDFMTBEG, FDFMTTRK, and FDFMTEND ioctls provide means for controlling formatting of a floppy drive.
--- linux-user/ioctls.h | 3 +++ linux-user/syscall_defs.h | 3 +++ linux-user/syscall_types.h | 5 +++++ 3 files changed, 11 insertions(+)
linux-user/ioctls.h +3 -0
@@ -114,6 +114,9 @@ IOCTL(FDMSGON, 0, TYPE_NULL) IOCTL(FDMSGOFF, 0, TYPE_NULL) + IOCTL(FDFMTBEG, 0, TYPE_NULL) + IOCTL(FDFMTTRK, IOC_W, MK_PTR(MK_STRUCT(STRUCT_format_descr))) + IOCTL(FDFMTEND, 0, TYPE_NULL) IOCTL(FDFLUSH, 0, TYPE_NULL) IOCTL(FDRESET, 0, TYPE_NULL)IOCTL (FDRAWCMD ,0 ,TYPE_NULL )
linux-user/syscall_defs.h +3 -0
@@ -887,6 +887,9 @@ struct target_pollfd {#define TARGET_FDMSGON TARGET_IO(2, 0x45)#define TARGET_FDMSGOFF TARGET_IO(2, 0x46) +#define TARGET_FDFMTBEG TARGET_IO(2, 0x47) +#define TARGET_FDFMTTRK TARGET_IOW(2, 0x48, struct target_format_descr) +#define TARGET_FDFMTEND TARGET_IO(2, 0x49)#define TARGET_FDFLUSH TARGET_IO(2, 0x4b)#define TARGET_FDRESET TARGET_IO(2, 0x54)#define TARGET_FDRAWCMD TARGET_IO(2, 0x58)
linux-user/syscall_types.h +5 -0
@@ -261,6 +261,11 @@ STRUCT(blkpg_ioctl_arg, TYPE_INT, /* datalen */ TYPE_PTRVOID) /* data */ +STRUCT (format_descr, +TYPE_INT ,/* device */ +TYPE_INT ,/* head */ + TYPE_INT) /* track */ +#if defined(CONFIG_USBFS )/* usb device ioctls */ STRUCT(usbdevfs_ctrltransfer,
Signature · 1 line
2.7.4
PATCH v2 5/7 linux-user: Add support for FDSETEMSGTRESH, FDSETMAXERRS, and FDGETMAXERRS ioctls
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
FDSETEMSGTRESH, FDSETMAXERRS, and FDGETMAXERRS ioctls are commands for controlling error reporting of a floppy drive.
--- linux-user/ioctls.h | 2 ++ linux-user/syscall_defs.h | 19 +++++++++++++++++++ linux-user/syscall_types.h | 7 +++++++ 3 files changed, 28 insertions(+)
linux-user/ioctls.h +2 -0
@@ -118,6 +118,8 @@ IOCTL(FDFMTTRK, IOC_W, MK_PTR(MK_STRUCT(STRUCT_format_descr))) IOCTL(FDFMTEND, 0, TYPE_NULL) IOCTL(FDFLUSH, 0, TYPE_NULL) + IOCTL(FDSETMAXERRS, IOC_W, MK_PTR(MK_STRUCT(STRUCT_floppy_max_errors))) + IOCTL(FDGETMAXERRS, IOC_R, MK_PTR(MK_STRUCT(STRUCT_floppy_max_errors))) IOCTL(FDRESET, 0, TYPE_NULL) IOCTL(FDRAWCMD, 0, TYPE_NULL)IOCTL (FDTWADDLE ,0 ,TYPE_NULL )
linux-user/syscall_defs.h +19 -0
@@ -885,12 +885,31 @@ struct target_pollfd {/* From <linux/fd.h> */ +struct target_floppy_max_errors { +abi_uint abort; +abi_uint read_track; +abi_uint reset; +abi_uint recal; +abi_uint reporting; +}; + +struct target_format_descr { +abi_uint device; +abi_uint head; +abi_uint track; +}; +#define TARGET_FDMSGON TARGET_IO(2, 0x45)#define TARGET_FDMSGOFF TARGET_IO(2, 0x46)#define TARGET_FDFMTBEG TARGET_IO(2, 0x47)#define TARGET_FDFMTTRK TARGET_IOW(2, 0x48, struct target_format_descr)#define TARGET_FDFMTEND TARGET_IO(2, 0x49) +#define TARGET_FDSETEMSGTRESH TARGET_IO(2, 0x4a)#define TARGET_FDFLUSH TARGET_IO(2, 0x4b) +#define TARGET_FDSETMAXERRS TARGET_IOW(2, 0x4c, \ + struct target_floppy_max_errors) +#define TARGET_FDGETMAXERRS TARGET_IOR(2, 0x0e, \ + struct target_floppy_max_errors)#define TARGET_FDRESET TARGET_IO(2, 0x54)#define TARGET_FDRAWCMD TARGET_IO(2, 0x58)#define TARGET_FDTWADDLE TARGET_IO(2, 0x59)
linux-user/syscall_types.h +7 -0
@@ -261,6 +261,13 @@ STRUCT(blkpg_ioctl_arg, TYPE_INT, /* datalen */ TYPE_PTRVOID) /* data */ +STRUCT (floppy_max_errors, +TYPE_INT ,/* abort */ +TYPE_INT ,/* read_track */ +TYPE_INT ,/* reset */ +TYPE_INT ,/* recal */ + TYPE_INT) /* reporting */ + STRUCT(format_descr, TYPE_INT, /* device */ TYPE_INT, /* head */
Signature · 1 line
2.7.4
PATCH v2 6/7 linux-user: Add support for RNDRESEEDCRNG ioctl
In reply to Aleksandar MarkovicFrom: Aleksandar Markovic <[email protected]>
RNDRESEEDCRNG is a newer ioctl (added in kernel 4.17), and an "ifdef" guard is used for that reason in this patch.
--- linux-user/ioctls.h | 3 +++ linux-user/syscall_defs.h | 1 + 2 files changed, 4 insertions(+)
linux-user/ioctls.h +3 -0
@@ -259,6 +259,9 @@ IOCTL(RNDADDTOENTCNT, IOC_W, MK_PTR(TYPE_INT)) IOCTL(RNDZAPENTCNT, 0, TYPE_NULL) IOCTL(RNDCLEARPOOL, 0, TYPE_NULL) +#ifdef RNDRESEEDCRNG + IOCTL(RNDRESEEDCRNG, 0, TYPE_NULL) +#endif IOCTL(CDROMPAUSE, 0, TYPE_NULL)IOCTL (CDROMSTART ,0 ,TYPE_NULL )
linux-user/syscall_defs.h +1 -0
@@ -850,6 +850,7 @@ struct target_pollfd {#define TARGET_RNDADDTOENTCNT TARGET_IOW('R', 0x01, int)#define TARGET_RNDZAPENTCNT TARGET_IO('R', 0x04)#define TARGET_RNDCLEARPOOL TARGET_IO('R', 0x06) +#define TARGET_RNDRESEEDCRNG TARGET_IO('R', 0x07)/* From <linux/fs.h> */
Signature · 1 line
2.7.4
PATCH v2 7/7 linux-user: Add support for semtimedop() syscall
In reply to Aleksandar MarkovicFrom: Aleksandar Rikalo <[email protected]>
Add support for semtimedop() emulation. It is based on invocation of safe_semtimedop().
Conversion is left out of safe_semtimedop(), since other safe_xxx() usually don't contain similar conversions.
--- linux-user/syscall.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
linux-user/syscall.c +36 -0
@@ -6650,7 +6650,39 @@ static inline abi_long host_to_target_statx(struct target_statx *host_stx,return 0 ; }#endif +#ifdef TARGET_NR_semtimedop +static inline abi_long do_semtimedop (int semid,abi_long ptr,unsigned nsops, +abi_long timeout) +{ +struct sembuf *sops; +struct timespec ts, *pts; +abi_long ret; + +if (timeout) { + pts = &ts; +if (target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } + }else { + pts =NULL ; + } + sops =g_malloc (sizeof (struct sembuf ) * nsops); +if (sops ==NULL ) { +return -TARGET_EFAULT ; + } + +if (target_to_host_sembuf (sops, ptr, nsops)) { +g_free (sops); +return -TARGET_EFAULT ; + } + + ret =get_errno (safe_semtimedop (semid, sops, nsops, pts)); +g_free (sops); + +return ret; +} +#endif /* ??? Using host futex calls even when target atomic operations are not really atomic probably breaks things. However implementing
@@ -9194,6 +9226,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,case TARGET_NR_semop:return do_semop (arg1, arg2, arg3);#endif +#ifdef TARGET_NR_semtimedop +case TARGET_NR_semtimedop: +return do_semtimedop (arg1, arg2, arg3, arg4); +#endif #ifdef TARGET_NR_semctlcase TARGET_NR_semctl:return do_semctl (arg1, arg2, arg3, arg4);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH for 4.1 v2 7/7] linux-user: Add support for semtimedop() syscall
Quoted 5 lines · Aleksandar Markovic
From: Aleksandar Rikalo <[email protected]>
Add support for
semtimedop()emulation. It is based on invocation ofsafe_semtimedop().
Quoted 7 lines
Conversion is left out of
safe_semtimedop(), since othersafe_xxx()usually don't contain similar conversions.Signed-off-by Aleksandar Rikalo <[email protected]>Signed-off-by Aleksandar Markovic <[email protected]>---
Aleksandar R., Laurent,
Please note that I just rebased the patch compared to its last incarnation
- no code change.
Laurent's hints were as follows last time:
"To avoid duplicate code (and cleanup the stack allocation), you should
remove do_semop() and call do_semtimedop(..., NULL) from IPCOP_semop and TARGET_NR_semop.
Thanks, Laurent"
I guess they are still valid.
Thanks,
Aleksandar
Quoted 66 lines
linux-user/syscall.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)linux-user/syscall.c +32
-0@@ -6650,7 +6650,39 @@ static inline abi_long host_to_target_statx(structtarget_statx *host_stx, return 0; }#endif +#ifdef TARGET_NR_semtimedop +static inline abi_long do_semtimedop (int semid,abi_long ptr,unsigned nsops, +abi_long timeout) +{ +struct sembuf *sops; +struct timespec ts, *pts; +abi_long ret; + +if (timeout) { + pts = &ts; +if (target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } + }else { + pts =NULL ; + } + sops =g_malloc (sizeof (struct sembuf ) * nsops); +if (sops ==NULL ) { +return -TARGET_EFAULT ; + } + +if (target_to_host_sembuf (sops, ptr, nsops)) { +g_free (sops); +return -TARGET_EFAULT ; + } + + ret =get_errno (safe_semtimedop (semid, sops, nsops, pts)); +g_free (sops); + +return ret; +} +#endif /* ??? Using host futex calls even when target atomic operations
are not really atomic probably breaks things. However implementinglinux-user/syscall.c +4
-0@@ -9194,6 +9226,10 @@ static abi_long do_syscall1(void *cpu_env, int num,abi_long arg1, case TARGET_NR_semop: return do_semop(arg1, arg2, arg3);#endif +#ifdef TARGET_NR_semtimedop +case TARGET_NR_semtimedop: +return do_semtimedop (arg1, arg2, arg3, arg4); +#endif #ifdef TARGET_NR_semctlcase TARGET_NR_semctl:return do_semctl(arg1, arg2, arg3, arg4);--
2.7.4
Re: [Qemu-devel] [PATCH for 4.1 v2 7/7] linux-user: Add support for semtimedop() syscall
Le 29/07/2019 à 15:26, Aleksandar Markovic a écrit :
Quoted 29 lines
On Mon, Jul 29, 2019 at 3:11 PM Aleksandar Markovic <[email protected] <mailto:[email protected]>> wrote:
From: Aleksandar Rikalo <[email protected]
<mailto:[email protected]>>Add support for
semtimedop()emulation. It is based on invocation ofsafe_semtimedop().Conversion is left out of
safe_semtimedop(), since othersafe_xxx()usually don't contain similar conversions.Signed-off-by Aleksandar Rikalo <[email protected]<mailto:[email protected]>>
Signed-off-by Aleksandar Markovic <[email protected]<mailto:[email protected]>>
---Aleksandar R., Laurent,
Please note that I just rebased the patch compared to its last incarnation - no code change.
Laurent's hints were as follows last time:
Quoted 8 lines
"To avoid duplicate code (and cleanup the stack allocation), you should
remove
do_semop()and calldo_semtimedop(..., NULL)fromIPCOP_semopandTARGET_NR_semop.Thanks, Laurent"
I guess they are still valid.
Yes, I didn't remember my comment and do the same again...
Thanks,
Laurent
Re: [Qemu-devel] [PATCH for 4.1 v2 7/7] linux-user: Add support for semtimedop() syscall
In reply to Aleksandar MarkovicLe 29/07/2019 à 15:09, Aleksandar Markovic a écrit :
Quoted 45 lines
From: Aleksandar Rikalo <[email protected]>
Add support for
semtimedop()emulation. It is based on invocation ofsafe_semtimedop().Conversion is left out of
safe_semtimedop(), since othersafe_xxx()usually don't contain similar conversions.Signed-off-by Aleksandar Rikalo <[email protected]>Signed-off-by Aleksandar Markovic <[email protected]>--- linux-user/syscall.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)linux-user/syscall.c +22
-0@@ -6650,7 +6650,39 @@ static inline abi_long host_to_target_statx(struct target_statx *host_stx,return 0 ; }#endif +#ifdef TARGET_NR_semtimedop +static inline abi_long do_semtimedop (int semid,abi_long ptr,unsigned nsops, +abi_long timeout) +{ +struct sembuf *sops; +struct timespec ts, *pts; +abi_long ret; + +if (timeout) { + pts = &ts; +if (target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } + }else { + pts =NULL ; + } + sops =g_malloc (sizeof (struct sembuf ) * nsops); +if (sops ==NULL ) { +return -TARGET_EFAULT ; + } + +if (target_to_host_sembuf (sops, ptr, nsops)) {
linux-user/syscall.c static inline abi_long host_to_target_statx(struct target_statx *host_stx, · line 6685
Quoted 10 lines
linux-user/syscall.c +10
-0+g_free (sops); + return -TARGET_EFAULT; + } + + ret =get_errno (safe_semtimedop (semid, sops, nsops, pts)); +g_free (sops); + +return ret; +} +#endif
As we have a "#ifdef__NR_semtimedop" around the definition of safe_semtimedop() you need the same #ifdef around its use:
perhaps you can update the existing do_semop() to implement do_semtimedop().
Quoted 5 lines
linux-user/syscall.c +0
-0/* ??? Using host futex calls even when target atomic operations are not really atomic probably breaks things. However implementing
linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 9235
Quoted 10 lines
linux-user/syscall.c +4
-0@@ -9194,6 +9226,10 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,case TARGET_NR_semop:return do_semop (arg1, arg2, arg3);#endif +#ifdef TARGET_NR_semtimedop +case TARGET_NR_semtimedop: +return do_semtimedop (arg1, arg2, arg3, arg4); +#endif #ifdef TARGET_NR_semctlcase TARGET_NR_semctl:return do_semctl (arg1, arg2, arg3, arg4);
You should also implement in do_ipc() the IPCOP_semtimedop operation.
Thanks,
Laurent