linux-user patches
From: Riku Voipio <[email protected]>
The following changes since commit 6fffa26244737f8fd8641a21fee29bd6aa9fdff5:
Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-2014-03-15' into staging (2014-03-15 18:22:11 +0000)
are available in the git repository at:
git://git.linaro.org/people/riku.voipio/qemu.git linux-user-for-upstream
for you to fetch changes up to e0eb210ec0c1cd262e3f642133ee93acdaf60aa0:
linux-user: Implement capget, capset (2014-03-17 15:26:58 +0200)
Alex Barcelo (1):
signal: added a wrapper for sigprocmask function
Andreas Schwab (1):
linux-user: implement F_[GS]ETOWN_EX
Peter Maydell (5):
linux-user/signal.c: Correct error path for AArch64 do_rt_sigreturn
linux-user: Don't return uninitialized value for atomic_barrier
syscall
linux-user: Don't reserve space for commpage for AArch64
linux-user: Don't allow guest to block SIGSEGV
linux-user: Implement capget, capset
linux-user/elfload.c | 5 +- linux-user/qemu.h | 2 + linux-user/signal.c | 120 ++++++++++++++++++++++++++++++++++--------- linux-user/syscall.c | 126 ++++++++++++++++++++++++++++++++++++++++++---- linux-user/syscall_defs.h | 18 +++++++ 5 files changed, 236 insertions(+), 35 deletions(-)
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 2/7] linux-user: Don't return uninitialized value for atomic_barrier syscall
From: Peter Maydell <[email protected]>
QEMU's implementation of the m68k atomic_barrier syscall, like the kernel's, is just a no-op. However we still need to return a result code from it.
--- linux-user/syscall.c | 1 + 1 file changed, 1 insertion(+)
linux-user/syscall.c +1 -0
@@ -9148,6 +9148,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,case TARGET_NR_atomic_barrier: {/* Like the kernel implementation and the qemu arm barrier, no-op this? */ + ret =0 ;break ; }#endif
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 3/7] linux-user: implement F_[GS]ETOWN_EX
In reply to [email protected]From: Andreas Schwab <[email protected]>
F_GETOWN is replaced by F_GETOWN_EX inside the glibc fcntl wrapper
--- linux-user/syscall.c | 36 ++++++++++++++++++++++++++++++++++++ linux-user/syscall_defs.h | 7 +++++++ 2 files changed, 43 insertions(+)
linux-user/syscall.c +36 -0
@@ -4421,6 +4421,14 @@ static int target_to_host_fcntl_cmd(int cmd)#endif case TARGET_F_NOTIFY :return F_NOTIFY ; +#ifdef F_GETOWN_EX +case TARGET_F_GETOWN_EX : +return F_GETOWN_EX ; +#endif +#ifdef F_SETOWN_EX +case TARGET_F_SETOWN_EX : +return F_SETOWN_EX ; +#endif default :return -TARGET_EINVAL ; }
@@ -4443,6 +4451,10 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)struct target_flock *target_fl;struct flock64 fl64;struct target_flock64 *target_fl64; +#ifdef F_GETOWN_EX +struct f_owner_ex fox; +struct target_f_owner_ex *target_fox; +#endif abi_long ret;int host_cmd =target_to_host_fcntl_cmd (cmd);
@@ -4536,6 +4548,30 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg) ret =get_errno (fcntl (fd, host_cmd,target_to_host_bitmask (arg, fcntl_flags_tbl)));break ; +#ifdef F_GETOWN_EX +case TARGET_F_GETOWN_EX : + ret =get_errno (fcntl (fd, host_cmd, &fox)); +if (ret >=0 ) { +if (!lock_user_struct (VERIFY_WRITE , target_fox, arg,0 )) +return -TARGET_EFAULT ; + target_fox->type =tswap32 (fox.type); + target_fox->pid =tswap32 (fox.pid); +unlock_user_struct (target_fox, arg,1 ); + } +break ; +#endif + +#ifdef F_SETOWN_EX +case TARGET_F_SETOWN_EX : +if (!lock_user_struct (VERIFY_READ , target_fox, arg,1 )) +return -TARGET_EFAULT ; + fox.type =tswap32 (target_fox->type); + fox.pid =tswap32 (target_fox->pid); +unlock_user_struct (target_fox, arg,0 ); + ret =get_errno (fcntl (fd, host_cmd, &fox)); +break ; +#endif +case TARGET_F_SETOWN :case TARGET_F_GETOWN :case TARGET_F_SETSIG :
linux-user/syscall_defs.h +7 -0
@@ -2123,6 +2123,8 @@ struct target_statfs64 {#define TARGET_F_SETOWN 8/* for sockets. */ #define TARGET_F_GETOWN 9/* for sockets. */ #endif +#define TARGET_F_SETOWN_EX 15 +#define TARGET_F_GETOWN_EX 16#ifndef TARGET_F_RDLCK #define TARGET_F_RDLCK 0
@@ -2305,6 +2307,11 @@ struct target_eabi_flock64 { } QEMU_PACKED;#endif +struct target_f_owner_ex { +int type;/* Owner type of ID. */ +int pid;/* ID of owner. */ +}; +/* soundcard defines */ /* XXX: convert them all to arch indepedent entries */ #define TARGET_SNDCTL_COPR_HALT TARGET_IOWR('C', 7, int);
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 4/7] linux-user: Don't reserve space for commpage for AArch64
In reply to [email protected]From: Peter Maydell <[email protected]>
AArch64 Linux, unlike AArch32, doesn't use a commpage. This means we should not be reserving room in the guest address space for one. Fixes LP:1287195.
--- linux-user/elfload.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
linux-user/elfload.c +4 -1
@@ -352,6 +352,9 @@ enum ARM_HWCAP_ARM_VFPv3D16 = 1 << 13, }; +#ifndef TARGET_AARCH64 +/* The commpage only exists for 32 bit kernels */ +#define TARGET_HAS_VALIDATE_GUEST_SPACE /* Return 1 if the proposed guest space is suitable for the guest. * Return 0 if the proposed guest space isn't suitable, but another
@@ -411,7 +414,7 @@ static int validate_guest_space(unsigned long guest_base, return 1; /* All good */ } - +#endif #define ELF_HWCAP get_elf_hwcap()
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 1/7] linux-user/signal.c: Correct error path for AArch64 do_rt_sigreturn
In reply to [email protected]From: Peter Maydell <[email protected]>
The error path in AArch64 do_rt_sigreturn() which fails before attempting lock_user_struct() was doing an unlock_user_struct() on an uninitialized variable. Initialize frame to NULL so we can use the same error-exit path in all cases (unlock of NULL is permitted and does nothing).
--- linux-user/signal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/signal.c +1 -1
@@ -1340,7 +1340,7 @@ static void setup_frame(int sig, struct target_sigaction *ka,long do_rt_sigreturn (CPUARMState *env) { -struct target_rt_sigframe *frame; +struct target_rt_sigframe *frame =NULL ;abi_ulong frame_addr = env->xregs[31 ];if (frame_addr &15 ) {
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 5/7] signal: added a wrapper for sigprocmask function
In reply to [email protected]From: Alex Barcelo <[email protected]>
Create a wrapper for signal mask changes initiated by the guest; (this includes syscalls and also the sigreturns from signal.c) this will give us a place to put code which prevents the guest from changing the handling of signals used by QEMU itself internally.
The wrapper is called from all the guest-initiated sigprocmask, but is not called from internal qemu sigprocmask calls.
[PMM: Added calls to wrapper for sigprocmask uses in signal.c when setting the signal mask on entry and exit from signal handlers, since these also are guest-provided signal masks.]
--- linux-user/qemu.h | 1 + linux-user/signal.c | 58 ++++++++++++++++++++++++++++++---------------------- linux-user/syscall.c | 14 ++++++------- 3 files changed, 42 insertions(+), 31 deletions(-)
linux-user/qemu.h +1 -0
@@ -235,6 +235,7 @@ int host_to_target_signal(int sig);long do_sigreturn (CPUArchState *env);long do_rt_sigreturn (CPUArchState *env);abi_long do_sigaltstack (abi_ulong uss_addr,abi_ulong uoss_addr,abi_ulong sp); +int do_sigprocmask (int how,const sigset_t *set,sigset_t *oldset);#ifdef TARGET_I386 /* vm86.c */
linux-user/signal.c +34 -24
208 lines not on this page · raw message
linux-user/syscall.c +7 -7
@@ -6029,7 +6029,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, {sigset_t cur_set;abi_ulong target_set; -sigprocmask (0 ,NULL , &cur_set); +do_sigprocmask (0 ,NULL , &cur_set);host_to_target_old_sigset (&target_set, &cur_set); ret = target_set; }
@@ -6040,10 +6040,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, {sigset_t set, oset, cur_set;abi_ulong target_set = arg1; -sigprocmask (0 ,NULL , &cur_set); +do_sigprocmask (0 ,NULL , &cur_set);target_to_host_old_sigset (&set, &target_set);sigorset (&set, &set, &cur_set); -sigprocmask (SIG_SETMASK , &set, &oset); +do_sigprocmask (SIG_SETMASK , &set, &oset);host_to_target_old_sigset (&target_set, &oset); ret = target_set; }
@@ -6074,7 +6074,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, mask = arg2;target_to_host_old_sigset (&set, &mask); - ret =get_errno (sigprocmask (how, &set, &oldset)); + ret =get_errno (do_sigprocmask (how, &set, &oldset));if (!is_error (ret)) {host_to_target_old_sigset (&mask, &oldset); ret = mask;
@@ -6108,7 +6108,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, how =0 ; set_ptr =NULL ; } - ret =get_errno (sigprocmask (how, set_ptr, &oldset)); + ret =get_errno (do_sigprocmask (how, set_ptr, &oldset));if (!is_error (ret) && arg3) {if (!(p =lock_user (VERIFY_WRITE , arg3,sizeof (target_sigset_t),0 ))) goto efault;
@@ -6148,7 +6148,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, how =0 ; set_ptr =NULL ; } - ret =get_errno (sigprocmask (how, set_ptr, &oldset)); + ret =get_errno (do_sigprocmask (how, set_ptr, &oldset));if (!is_error (ret) && arg3) {if (!(p =lock_user (VERIFY_WRITE , arg3,sizeof (target_sigset_t),0 ))) goto efault;
@@ -8161,7 +8161,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } mask = arg2;target_to_host_old_sigset (&set, &mask); -sigprocmask (how, &set, &oldset); +do_sigprocmask (how, &set, &oldset);host_to_target_old_sigset (&mask, &oldset); ret = mask; }
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 6/7] linux-user: Don't allow guest to block SIGSEGV
In reply to [email protected]From: Peter Maydell <[email protected]>
Don't allow the linux-user guest to block SIGSEGV -- QEMU needs this signal to detect accesses to pages which it has marked read-only because it has cached translated code from them.
We implement this by making the do_sigprocmask() wrapper suppress SIGSEGV when doing the host process signal mask manipulation; instead we store the current state of SIGSEGV in the TaskState struct.
If we get a SIGSEGV for the guest when the guest has blocked the signal, we treat it as if the default SEGV handler was in place, as the kernel does for forced SIGSEGV delivery.
This patch is based on an idea by Alex Barcelo, but rather than simply lying to the guest about the SIGSEGV state we track it.
--- linux-user/qemu.h | 1 + linux-user/signal.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-)
linux-user/qemu.h +1 -0
@@ -126,6 +126,7 @@ typedef struct TaskState {#endif uint32_t stack_base;int used;/* non zero if used */ +bool sigsegv_blocked;/* SIGSEGV blocked by guest */ struct image_info *info;struct linux_binprm *bprm;
linux-user/signal.c +61 -1
80 lines not on this page · raw message
Signature · 1 line
1.8.1.2
[Qemu-devel] [PULL for-2.0 7/7] linux-user: Implement capget, capset
In reply to [email protected]From: Peter Maydell <[email protected]>
Implement the capget and capset syscalls. This is useful because simple programs like 'ls' try to use it in AArch64, and otherwise we emit a lot of noise about it being unimplemented.
--- linux-user/syscall.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-- linux-user/syscall_defs.h | 11 +++++++ 2 files changed, 84 insertions(+), 2 deletions(-)
linux-user/syscall.c +73 -2
@@ -43,6 +43,7 @@#include <sys/resource.h> #include <sys/mman.h> #include <sys/swap.h> +#include <linux/capability.h> #include <signal.h> #include <sched.h> #ifdef __ia64__
@@ -243,6 +244,10 @@ _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr); _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, void *, arg); +_syscall2(int, capget, struct __user_cap_header_struct *, header, + struct __user_cap_data_struct *, data); +_syscall2(int, capset, struct __user_cap_header_struct *, header, + struct __user_cap_data_struct *, data);static bitmask_transtbl fcntl_flags_tbl[] = { {TARGET_O_ACCMODE ,TARGET_O_WRONLY ,O_ACCMODE ,O_WRONLY , },
@@ -7677,9 +7682,75 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,unlock_user (p, arg1, ret);break ;case TARGET_NR_capget: - goto unimplemented;case TARGET_NR_capset: - goto unimplemented; + { +struct target_user_cap_header *target_header; +struct target_user_cap_data *target_data =NULL ; +struct __user_cap_header_struct header; +struct __user_cap_data_struct data[2 ]; +struct __user_cap_data_struct *dataptr =NULL ; +int i, target_datalen; +int data_items =1 ; + +if (!lock_user_struct (VERIFY_WRITE , target_header, arg1,1 )) { + goto efault; + } + header.version =tswap32 (target_header->version); + header.pid =tswap32 (target_header->pid); + +if (header.version != _LINUX_CAPABILITY_VERSION_1) { +/* Version 2 and up takes pointer to two user_data structs */ + data_items =2 ; + } + + target_datalen =sizeof (*target_data) * data_items; + +if (arg2) { +if (num == TARGET_NR_capget) { + target_data =lock_user (VERIFY_WRITE , arg2, target_datalen,0 ); + }else { + target_data =lock_user (VERIFY_READ , arg2, target_datalen,1 ); + } +if (!target_data) { +unlock_user_struct (target_header, arg1,0 ); + goto efault; + } + +if (num == TARGET_NR_capset) { +for (i =0 ; i < data_items; i++) { + data[i].effective =tswap32 (target_data[i].effective); + data[i].permitted =tswap32 (target_data[i].permitted); + data[i].inheritable =tswap32 (target_data[i].inheritable); + } + } + + dataptr = data; + } + +if (num == TARGET_NR_capget) { + ret =get_errno (capget (&header, dataptr)); + }else { + ret =get_errno (capset (&header, dataptr)); + } + +/* The kernel always updates version for both capget and capset */ + target_header->version =tswap32 (header.version); +unlock_user_struct (target_header, arg1,1 ); + +if (arg2) { +if (num == TARGET_NR_capget) { +for (i =0 ; i < data_items; i++) { + target_data[i].effective =tswap32 (data[i].effective); + target_data[i].permitted =tswap32 (data[i].permitted); + target_data[i].inheritable =tswap32 (data[i].inheritable); + } +unlock_user (target_data, arg2, target_datalen); + }else { +unlock_user (target_data, arg2,0 ); + } + } +break ; + }case TARGET_NR_sigaltstack: #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \
linux-user/syscall_defs.h +11 -0
@@ -2566,3 +2566,14 @@ struct target_sigevent { } _sigev_thread; } _sigev_un; }; + +struct target_user_cap_header { +uint32_t version; +int pid; +}; + +struct target_user_cap_data { +uint32_t effective; +uint32_t permitted; +uint32_t inheritable; +};
Signature · 1 line
1.8.1.2
Re: [Qemu-devel] [PULL for-2.0 7/7] linux-user: Implement capget, capset
Hello,
Quoted 49 lines · On Wed, Mar 19, 2014 at 3:03 PM, <[email protected]> wrote:
From: Peter Maydell <[email protected]>
Implement the capget and capset syscalls. This is useful because simple programs like 'ls' try to use it in AArch64, and otherwise we emit a lot of noise about it being unimplemented.
Signed-off-by Peter Maydell <[email protected]>Signed-off-by Riku Voipio <[email protected]>--- linux-user/syscall.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-- linux-user/syscall_defs.h | 11 +++++++ 2 files changed, 84 insertions(+), 2 deletions(-)linux-user/syscall.c +11
-2@@ -43,6 +43,7 @@#include <sys/resource.h> #include <sys/mman.h> #include <sys/swap.h> +#include <linux/capability.h> #include <signal.h> #include <sched.h> #ifdef __ia64__@@ -243,6 +244,10 @@ _syscall3(int, sys_sched_setaffinity, pid_t, pid, unsigned int, len, unsigned long *, user_mask_ptr); _syscall4(int, reboot, int, magic1, int, magic2, unsigned int, cmd, void *, arg); +_syscall2(int, capget, struct __user_cap_header_struct *, header, + struct __user_cap_data_struct *, data); +_syscall2(int, capset, struct __user_cap_header_struct *, header, + struct __user_cap_data_struct *, data);static bitmask_transtbl fcntl_flags_tbl[] = { {TARGET_O_ACCMODE ,TARGET_O_WRONLY ,O_ACCMODE ,O_WRONLY , },@@ -7677,9 +7682,75 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,unlock_user (p, arg1, ret);break ;case TARGET_NR_capget: - goto unimplemented;case TARGET_NR_capset: - goto unimplemented; + { +struct target_user_cap_header *target_header; +struct target_user_cap_data *target_data =NULL ; +struct __user_cap_header_struct header; +struct __user_cap_data_struct data[2 ]; +struct __user_cap_data_struct *dataptr =NULL ;
linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 7701
Quoted 10 lines
linux-user/syscall.c +10
-0+int i, target_datalen; +int data_items =1 ; + +if (!lock_user_struct (VERIFY_WRITE , target_header, arg1,1 )) { + goto efault; + } + header.version =tswap32 (target_header->version); + header.pid =tswap32 (target_header->pid); + +if (header.version != _LINUX_CAPABILITY_VERSION_1) {
Sorry for spotting this late, but older kernels (in my case 2.6.18-238.el5, CentOS 5.6) don't have _LINUX_CAPABILITY_VERSION_1 defined. I think _LINUX_CAPABILITY_VERSION should be used instead in that case.
Thanks,
Laurent
Quoted 78 lines
linux-user/syscall.c +52
-0+/* Version 2 and up takes pointer to two user_data structs */ + data_items =2 ; + } + + target_datalen =sizeof (*target_data) * data_items; + +if (arg2) { +if (num == TARGET_NR_capget) { + target_data =lock_user (VERIFY_WRITE , arg2, target_datalen,0 ); + }else { + target_data =lock_user (VERIFY_READ , arg2, target_datalen,1 ); + } +if (!target_data) { +unlock_user_struct (target_header, arg1,0 ); + goto efault; + } + +if (num == TARGET_NR_capset) { +for (i =0 ; i < data_items; i++) { + data[i].effective =tswap32 (target_data[i].effective); + data[i].permitted =tswap32 (target_data[i].permitted); + data[i].inheritable =tswap32 (target_data[i].inheritable); + } + } + + dataptr = data; + } + +if (num == TARGET_NR_capget) { + ret =get_errno (capget (&header, dataptr)); + }else { + ret =get_errno (capset (&header, dataptr)); + } + +/* The kernel always updates version for both capget and capset */ + target_header->version =tswap32 (header.version); +unlock_user_struct (target_header, arg1,1 ); + +if (arg2) { +if (num == TARGET_NR_capget) { +for (i =0 ; i < data_items; i++) { + target_data[i].effective =tswap32 (data[i].effective); + target_data[i].permitted =tswap32 (data[i].permitted); + target_data[i].inheritable =tswap32 (data[i].inheritable); + } +unlock_user (target_data, arg2, target_datalen); + }else { +unlock_user (target_data, arg2,0 ); + } + } +break ; + }case TARGET_NR_sigaltstack: #if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_MIPS) || \ defined(TARGET_SPARC) || defined(TARGET_PPC) || defined(TARGET_ALPHA) || \linux-user/syscall_defs.h +11
-1@@ -2566,3 +2566,14 @@ struct target_sigevent { } _sigev_thread; } _sigev_un; }; + +struct target_user_cap_header { +uint32_t version; +int pid; +}; + +struct target_user_cap_data { +uint32_t effective; +uint32_t permitted; +uint32_t inheritable; +}; --1.8.1.2
Re: [Qemu-devel] [PULL for-2.0 7/7] linux-user: Implement capget, capset
Quoted 10 lines · Laurent Desnogues
Hello,
Quoted 3 lines · On Wed, Mar 19, 2014 at 3:03 PM, <[email protected]> wrote:
From: Peter Maydell <[email protected]>
+ if (header.version !=
_LINUX_CAPABILITY_VERSION_1) {Sorry for spotting this late, but older kernels (in my case 2.6.18-238.el5, CentOS 5.6) don't have
_LINUX_CAPABILITY_VERSION_1defined.
Oops.
Quoted 3 lines
I think
_LINUX_CAPABILITY_VERSIONshould be used instead
in that case.
Simplest is to just use the non _1 suffix version always; later kernels define that for source compatibility.
thanks
-- PMM
Peter Maydell
AppliedQuoted 6 lines · On 19 March 2014 14:02, <[email protected]> wrote:
From: Riku Voipio <[email protected]>
The following changes since commit
6fffa26244737f8fd8641a21fee29bd6aa9fdff5:Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-2014-03-15' into staging (2014-03-15 18:22:11 +0000)
Quoted 7 lines
are available in the git repository at:
git://git.linaro.org/people/riku.voipio/qemu.gitlinux-user-for-upstreamfor you to fetch changes up to
e0eb210ec0c1cd262e3f642133ee93acdaf60aa0:linux-user: Implement capget, capset (2014-03-17 15:26:58 +0200)
Applied, thanks.
-- PMM