[PATCH] MAINTAINERS: update linux-user maintainer

2020-07-02 Thread riku . voipio
From: Riku Voipio 

I haven't been active for a while. Pass the maintainer hat
forward to Laurent, who has done a stellar job filling in.

Signed-off-by: Riku Voipio 
---
 MAINTAINERS | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git MAINTAINERS MAINTAINERS
index dec252f38b..29a23b6d3a 100644
--- MAINTAINERS
+++ MAINTAINERS
@@ -2629,8 +2629,7 @@ F: bsd-user/
 F: default-configs/*-bsd-user.mak
 
 Linux user
-M: Riku Voipio 
-R: Laurent Vivier 
+M: Laurent Vivier 
 S: Maintained
 F: linux-user/
 F: default-configs/*-linux-user.mak
-- 
2.20.1




Re: [Qemu-devel] [PATCH 0/2] linux-user: Fix race between threads in page_unprotect()

2018-01-19 Thread Riku Voipio
Hi Laurent,

On Mon, Jan 15, 2018 at 01:52:32PM +0100, Laurent Vivier wrote:
> Le 15/01/2018 à 13:48, Peter Maydell a écrit :
> > On 28 November 2017 at 14:35, Peter Maydell  
> > wrote:
> >> If multiple guest threads in user-mode emulation write to a
> >> page which QEMU has marked read-only because of cached TCG
> >> translations, the threads can race in page_unprotect:
> > 
> >> Peter Maydell (2):
> >>   linux-user: Propagate siginfo_t through to handle_cpu_signal()
> >>   page_unprotect(): handle calls to pages that are PAGE_WRITE
> > 
> > Ping! Linux-user maintainers, any chance this could get into
> > a pull-request sometime soon? (I have another cleanup I'm
> > thinking of that will touch the same code so I'd rather this
> > went into master before I look at that.)
> > 
> > (I have a bunch of other pending linux-user patchsets which
> > I shan't bother to ping individually unless you want me to.)
> 
> Riku,
> 
> if you have no time to prepare a pull request, I can.

Thanks, that would be great.

Riku



[Qemu-devel] [PULL 11/15] linux-user/s390x: Mask si_addr for SIGSEGV

2017-11-20 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

For s390x, the address passed to a signal handler in the
siginfo_t si_addr field is masked (in the kernel this is done in
do_sigbus() and do_sigsegv() in arch/s390/mm/fault.c). Implement
this architecture-specific oddity in linux-user.

This is one of the issues described in
https://bugs.launchpad.net/qemu/+bug/1705118

Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/main.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index aa02f25b85..b6dd9efd2d 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3238,6 +3238,10 @@ void cpu_loop(CPUAlphaState *env)
 #endif /* TARGET_ALPHA */
 
 #ifdef TARGET_S390X
+
+/* s390x masks the fault address it reports in si_addr for SIGSEGV and SIGBUS 
*/
+#define S390X_FAIL_ADDR_MASK -4096LL
+
 void cpu_loop(CPUS390XState *env)
 {
 CPUState *cs = CPU(s390_env_get_cpu(env));
@@ -3294,7 +3298,7 @@ void cpu_loop(CPUS390XState *env)
 sig = TARGET_SIGSEGV;
 /* XXX: check env->error_code */
 n = TARGET_SEGV_MAPERR;
-addr = env->__excp_addr;
+addr = env->__excp_addr & S390X_FAIL_ADDR_MASK;
 goto do_signal;
 case PGM_EXECUTE:
 case PGM_SPECIFICATION:
-- 
2.14.2




[Qemu-devel] [PULL 13/15] linux-user/sparc: Put address for data faults where linux-user expects it

2017-11-20 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

In the user-mode-only version of sparc_cpu_handle_mmu_fault(),
we must save the fault address for a data fault into the CPU
state's mmu registers, because the code in linux-user/main.c
expects to find it there in order to populate the si_addr
field of the guest siginfo.

Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 target/sparc/mmu_helper.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/target/sparc/mmu_helper.c b/target/sparc/mmu_helper.c
index 126ea5e3ee..d5b6c1e48c 100644
--- a/target/sparc/mmu_helper.c
+++ b/target/sparc/mmu_helper.c
@@ -30,10 +30,18 @@
 int sparc_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
int mmu_idx)
 {
+SPARCCPU *cpu = SPARC_CPU(cs);
+CPUSPARCState *env = >env;
+
 if (rw & 2) {
 cs->exception_index = TT_TFAULT;
 } else {
 cs->exception_index = TT_DFAULT;
+#ifdef TARGET_SPARC64
+env->dmmu.mmuregs[4] = address;
+#else
+env->mmuregs[4] = address;
+#endif
 }
 return 1;
 }
-- 
2.14.2




[Qemu-devel] [PULL 10/15] linux-user: return EINVAL from prctl(PR_*_SECCOMP)

2017-11-20 Thread riku . voipio
From: James Cowgill <james.cowg...@mips.com>

If an application tries to install a seccomp filter using
prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host
architecture. This will probably cause qemu to be immediately killed when it
executes another syscall.

Prevent this from happening by returning EINVAL from both seccomp prctl
calls. This is the error returned by the kernel when seccomp support is
disabled.

Fixes: https://bugs.launchpad.net/qemu/+bug/1726394
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: James Cowgill <james.cowg...@mips.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 84e123b67b..f31b853bb7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -10505,6 +10505,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 }
 #endif
+case PR_GET_SECCOMP:
+case PR_SET_SECCOMP:
+/* Disable seccomp to prevent the target disabling syscalls we
+ * need. */
+ret = -TARGET_EINVAL;
+break;
 default:
 /* Most prctl options have no pointer arguments */
 ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
-- 
2.14.2




[Qemu-devel] [PULL 04/15] linux-user/hppa: Fix typo for TARGET_NR_epoll_wait

2017-11-20 Thread riku . voipio
From: Helge Deller <del...@gmx.de>

Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Helge Deller <del...@gmx.de>
Message-Id: <20170311100543.ga29...@ls3530.fritz.box>
Signed-off-by: Richard Henderson <r...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/hppa/syscall_nr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/hppa/syscall_nr.h b/linux-user/hppa/syscall_nr.h
index 0f396fa1e2..55bdf71d50 100644
--- a/linux-user/hppa/syscall_nr.h
+++ b/linux-user/hppa/syscall_nr.h
@@ -228,7 +228,7 @@
 #define TARGET_NR_lookup_dcookie223
 #define TARGET_NR_epoll_create  224
 #define TARGET_NR_epoll_ctl 225
-#define TARGET_NR_epill_wait226
+#define TARGET_NR_epoll_wait226
 #define TARGET_NR_remap_file_pages  227
 #define TARGET_NR_semtimedop228
 #define TARGET_NR_mq_open   229
-- 
2.14.2




[Qemu-devel] [PULL 14/15] linux-user: Handle rt_sigaction correctly for SPARC

2017-11-20 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

SPARC is like Alpha in its handling of the rt_sigaction syscall:
it takes an extra parameter 'restorer' which needs to be copied
into the sa_restorer field of the sigaction struct. The order
of the arguments differs slightly between SPARC and Alpha but
the implementation is otherwise the same. (Compare the
rt_sigaction() functions in arch/sparc/kernel/sys_sparc_64.c
and arch/alpha/kernel/signal.c.)

Note that this change is somewhat moot until SPARC acquires
support for actually delivering RT signals.

Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f31b853bb7..11c9116c4a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8579,8 +8579,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 case TARGET_NR_rt_sigaction:
 {
 #if defined(TARGET_ALPHA)
-struct target_sigaction act, oact, *pact = 0;
+/* For Alpha and SPARC this is a 5 argument syscall, with
+ * a 'restorer' parameter which must be copied into the
+ * sa_restorer field of the sigaction struct.
+ * For Alpha that 'restorer' is arg5; for SPARC it is arg4,
+ * and arg5 is the sigsetsize.
+ * Alpha also has a separate rt_sigaction struct that it uses
+ * here; SPARC uses the usual sigaction struct.
+ */
 struct target_rt_sigaction *rt_act;
+struct target_sigaction act, oact, *pact = 0;
 
 if (arg4 != sizeof(target_sigset_t)) {
 ret = -TARGET_EINVAL;
@@ -8606,18 +8614,29 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 unlock_user_struct(rt_act, arg3, 1);
 }
 #else
+#ifdef TARGET_SPARC
+target_ulong restorer = arg4;
+target_ulong sigsetsize = arg5;
+#else
+target_ulong sigsetsize = arg4;
+#endif
 struct target_sigaction *act;
 struct target_sigaction *oact;
 
-if (arg4 != sizeof(target_sigset_t)) {
+if (sigsetsize != sizeof(target_sigset_t)) {
 ret = -TARGET_EINVAL;
 break;
 }
 if (arg2) {
-if (!lock_user_struct(VERIFY_READ, act, arg2, 1))
+if (!lock_user_struct(VERIFY_READ, act, arg2, 1)) {
 goto efault;
-} else
+}
+#ifdef TARGET_SPARC
+act->sa_restorer = restorer;
+#endif
+} else {
 act = NULL;
+}
 if (arg3) {
 if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {
 ret = -TARGET_EFAULT;
-- 
2.14.2




[Qemu-devel] [PULL 03/15] linux-user/hppa: Fix cpu_clone_regs

2017-11-20 Thread riku . voipio
From: Richard Henderson <r...@twiddle.net>

By failing to return from the syscall in the child, the child
issues another clone syscall and hilarity ensues.

Signed-off-by: Richard Henderson <r...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/hppa/target_cpu.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/linux-user/hppa/target_cpu.h b/linux-user/hppa/target_cpu.h
index 1a5cecad3c..e50522eae9 100644
--- a/linux-user/hppa/target_cpu.h
+++ b/linux-user/hppa/target_cpu.h
@@ -24,7 +24,11 @@ static inline void cpu_clone_regs(CPUHPPAState *env, 
target_ulong newsp)
 if (newsp) {
 env->gr[30] = newsp;
 }
+/* Indicate child in return value.  */
 env->gr[28] = 0;
+/* Return from the syscall.  */
+env->iaoq_f = env->gr[31];
+env->iaoq_b = env->gr[31] + 4;
 }
 
 static inline void cpu_set_tls(CPUHPPAState *env, target_ulong newtls)
-- 
2.14.2




[Qemu-devel] [PULL 15/15] linux-user: Fix calculation of auxv length

2017-11-20 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

In commit 7c4ee5bcc82e643 we changed the order in which we construct
the AUXV, but forgot to adjust the calculation of the length. The
result is that we set info->auxv_len to a bogus and negative value,
and then later on the code in open_self_auxv() gets confused and
ends up presenting the guest with an empty file.

Since we now have to calculate the auxv length up-front as part
of figuring out how much we're going to put on the stack, set
info->auxv_len then; this allows us to assert that we put the
same number of entries into auxv as we pre-calculated, rather
than merely having a comment saying we need to do that.

Fixes: https://bugs.launchpad.net/qemu/+bug/1728116

Reviewed-by: Richard Henderson <richard.hender...@linaro.org>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/elfload.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 3b857fbc9c..20f3d8c2c3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1732,6 +1732,8 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
 #ifdef ELF_HWCAP2
 size += 2;
 #endif
+info->auxv_len = size * n;
+
 size += envc + argc + 2;
 size += 1;  /* argc itself */
 size *= n;
@@ -1760,7 +1762,6 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
 put_user_ual(val, u_auxv); u_auxv += n; \
 } while(0)
 
-/* There must be exactly DLINFO_ITEMS entries here.  */
 #ifdef ARCH_DLINFO
 /*
  * ARCH_DLINFO must come first so platform specific code can enforce
@@ -1768,6 +1769,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, 
int envc,
  */
 ARCH_DLINFO;
 #endif
+/* There must be exactly DLINFO_ITEMS entries here, or the assert
+ * on info->auxv_len will trigger.
+ */
 NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff));
 NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr)));
 NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
@@ -1793,7 +1797,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int 
argc, int envc,
 NEW_AUX_ENT (AT_NULL, 0);
 #undef NEW_AUX_ENT
 
-info->auxv_len = u_argv - info->saved_auxv;
+/* Check that our initial calculation of the auxv length matches how much
+ * we actually put into it.
+ */
+assert(info->auxv_len == u_auxv - info->saved_auxv);
 
 put_user_ual(argc, u_argc);
 
-- 
2.14.2




[Qemu-devel] [PULL 06/15] linux-user/hppa: Fix TARGET_F_RDLCK, TARGET_F_WRLCK, TARGET_F_UNLCK

2017-11-20 Thread riku . voipio
From: Helge Deller <del...@gmx.de>

Signed-off-by: Helge Deller <del...@gmx.de>
Signed-off-by: Richard Henderson <r...@twiddle.net>
Message-ID: <20170311175019.ga7...@ls3530.fritz.box>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall_defs.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index a6ed30d70e..daa2a57398 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2361,6 +2361,9 @@ struct target_statfs64 {
 #define TARGET_F_SETOWN24   /*  for sockets. */
 #define TARGET_F_GETOWN23   /*  for sockets. */
 #elif defined(TARGET_HPPA)
+#define TARGET_F_RDLCK 1
+#define TARGET_F_WRLCK 2
+#define TARGET_F_UNLCK 3
 #define TARGET_F_GETLK 5
 #define TARGET_F_SETLK 6
 #define TARGET_F_SETLKW7
-- 
2.14.2




[Qemu-devel] [PULL 08/15] linux-user/syscall.c: Handle SH4's exceptional alignment for p{read, write}64

2017-11-20 Thread riku . voipio
From: James Clarke <jrt...@jrtc27.com>

Fixes: https://bugs.launchpad.net/qemu/+bug/1716767
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Richard Henderson <richard.hender...@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Tested-By: John Paul Adrian Glaubitz <glaub...@physik.fu-berlin.de>
Signed-off-by: James Clarke <jrt...@jrtc27.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 36 +---
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8047bf3aac..9268c3ef69 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -671,18 +671,32 @@ static inline int next_free_host_timer(void)
 
 /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers */
 #ifdef TARGET_ARM
-static inline int regpairs_aligned(void *cpu_env) {
+static inline int regpairs_aligned(void *cpu_env, int num)
+{
 return CPUARMState *)cpu_env)->eabi) == 1) ;
 }
 #elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
-static inline int regpairs_aligned(void *cpu_env) { return 1; }
+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
 #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
 /* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even pairs
  * of registers which translates to the same as ARM/MIPS, because we start with
  * r3 as arg1 */
-static inline int regpairs_aligned(void *cpu_env) { return 1; }
+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
+#elif defined(TARGET_SH4)
+/* SH4 doesn't align register pairs, except for p{read,write}64 */
+static inline int regpairs_aligned(void *cpu_env, int num)
+{
+switch (num) {
+case TARGET_NR_pread64:
+case TARGET_NR_pwrite64:
+return 1;
+
+default:
+return 0;
+}
+}
 #else
-static inline int regpairs_aligned(void *cpu_env) { return 0; }
+static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
 #endif
 
 #define ERRNO_TABLE_SIZE 1200
@@ -6870,7 +6884,7 @@ static inline abi_long target_truncate64(void *cpu_env, 
const char *arg1,
  abi_long arg3,
  abi_long arg4)
 {
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
 arg2 = arg3;
 arg3 = arg4;
 }
@@ -6884,7 +6898,7 @@ static inline abi_long target_ftruncate64(void *cpu_env, 
abi_long arg1,
   abi_long arg3,
   abi_long arg4)
 {
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
 arg2 = arg3;
 arg3 = arg4;
 }
@@ -10508,7 +10522,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #endif
 #ifdef TARGET_NR_pread64
 case TARGET_NR_pread64:
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, num)) {
 arg4 = arg5;
 arg5 = arg6;
 }
@@ -10518,7 +10532,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 unlock_user(p, arg2, ret);
 break;
 case TARGET_NR_pwrite64:
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, num)) {
 arg4 = arg5;
 arg5 = arg6;
 }
@@ -11288,7 +11302,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 arg6 = ret;
 #else
 /* 6 args: fd, offset (high, low), len (high, low), advice */
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, num)) {
 /* offset is in (3,4), len in (5,6) and advice in 7 */
 arg2 = arg3;
 arg3 = arg4;
@@ -11307,7 +11321,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #ifdef TARGET_NR_fadvise64
 case TARGET_NR_fadvise64:
 /* 5 args: fd, offset (high, low), len, advice */
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, num)) {
 /* offset is in (3,4), len in 5 and advice in 6 */
 arg2 = arg3;
 arg3 = arg4;
@@ -11420,7 +11434,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #ifdef TARGET_NR_readahead
 case TARGET_NR_readahead:
 #if TARGET_ABI_BITS == 32
-if (regpairs_aligned(cpu_env)) {
+if (regpairs_aligned(cpu_env, num)) {
 arg2 = arg3;
 arg3 = arg4;
 arg4 = arg5;
-- 
2.14.2




[Qemu-devel] [PULL 12/15] linux-user/ppc: Report correct fault address for data faults

2017-11-20 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

For faults on loads and stores, ppc_cpu_handle_mmu_fault() in
target/ppc/user_only_helper.c stores the offending address
in env->spr[SPR_DAR]. Report this correctly to the guest
in si_addr, rather than incorrectly using the address of the
instruction that caused the fault.

This fixes the test case in
https://bugs.launchpad.net/qemu/+bug/1077116
for ppc, ppc64 and ppc64le.

Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index b6dd9efd2d..6286661bd3 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1420,7 +1420,7 @@ void cpu_loop(CPUPPCState *env)
 info.si_code = TARGET_SEGV_MAPERR;
 break;
 }
-info._sifields._sigfault._addr = env->nip;
+info._sifields._sigfault._addr = env->spr[SPR_DAR];
 queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
 break;
 case POWERPC_EXCP_ISI:  /* Instruction storage exception */
-- 
2.14.2




[Qemu-devel] [PULL 05/15] linux-user/hppa: Fix TARGET_MAP_TYPE

2017-11-20 Thread riku . voipio
From: Helge Deller <del...@gmx.de>

TARGET_MAP_TYPE needs to be 0x03 instead of 0x0f on the hppa
architecture, otherwise it conflicts with MAP_FIXED which is 0x04.

Signed-off-by: Helge Deller <del...@gmx.de>
Signed-off-by: Richard Henderson <r...@twiddle.net>
Message-ID: <20170311175019.ga7...@ls3530.fritz.box>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall_defs.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 38339ecb9a..a6ed30d70e 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -1336,7 +1336,11 @@ struct target_winsize {
 /* Common */
 #define TARGET_MAP_SHARED  0x01/* Share changes */
 #define TARGET_MAP_PRIVATE 0x02/* Changes are private */
-#define TARGET_MAP_TYPE0x0f/* Mask for type of 
mapping */
+#if defined(TARGET_HPPA)
+#define TARGET_MAP_TYPE 0x03   /* Mask for type of mapping */
+#else
+#define TARGET_MAP_TYPE 0x0f   /* Mask for type of mapping */
+#endif
 
 /* Target specific */
 #if defined(TARGET_MIPS)
-- 
2.14.2




[Qemu-devel] [PULL 02/15] linux-user/hppa: Fix TARGET_SA_* defines

2017-11-20 Thread riku . voipio
From: Helge Deller <del...@gmx.de>

Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Helge Deller <del...@gmx.de>
Signed-off-by: Richard Henderson <r...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall_defs.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index e366183419..38339ecb9a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -473,6 +473,14 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 #define TARGET_SA_RESETHAND0x0010
 #define TARGET_SA_NOCLDWAIT0x0020 /* not supported yet */
 #define TARGET_SA_SIGINFO  0x0040
+#elif defined(TARGET_HPPA)
+#define TARGET_SA_ONSTACK   0x0001
+#define TARGET_SA_RESETHAND 0x0004
+#define TARGET_SA_NOCLDSTOP 0x0008
+#define TARGET_SA_SIGINFO   0x0010
+#define TARGET_SA_NODEFER   0x0020
+#define TARGET_SA_RESTART   0x0040
+#define TARGET_SA_NOCLDWAIT 0x0080
 #else
 #define TARGET_SA_NOCLDSTOP0x0001
 #define TARGET_SA_NOCLDWAIT0x0002 /* not supported yet */
-- 
2.14.2




[Qemu-devel] [PULL 01/15] linux-user: Restrict usage of sa_restorer

2017-11-20 Thread riku . voipio
From: Richard Henderson <r...@twiddle.net>

Reading and writing to an sa_restorer member that isn't supposed to
exist corrupts user memory.  Introduce TARGET_ARCH_HAS_SA_RESTORER,
similar to the kernel's __ARCH_HAS_SA_RESTORER.

Reported-by: Helge Deller <del...@gmx.de>
Signed-off-by: Richard Henderson <r...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/signal.c   |  4 ++--
 linux-user/syscall_defs.h | 13 +
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 7a238aaea1..cf35473671 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -777,7 +777,7 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 if (oact) {
 __put_user(k->_sa_handler, >_sa_handler);
 __put_user(k->sa_flags, >sa_flags);
-#if !defined(TARGET_MIPS)
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
 __put_user(k->sa_restorer, >sa_restorer);
 #endif
 /* Not swapped.  */
@@ -787,7 +787,7 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 /* FIXME: This is not threadsafe.  */
 __get_user(k->_sa_handler, >_sa_handler);
 __get_user(k->sa_flags, >sa_flags);
-#if !defined(TARGET_MIPS)
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
 __get_user(k->sa_restorer, >sa_restorer);
 #endif
 /* To be swapped in target_to_host_sigset.  */
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 450960bb54..e366183419 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -445,6 +445,7 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 #define TARGET_SA_RESTART  2u
 #define TARGET_SA_NODEFER  0x20u
 #define TARGET_SA_RESETHAND4u
+#define TARGET_ARCH_HAS_SA_RESTORER 1
 #elif defined(TARGET_MIPS)
 #define TARGET_SA_NOCLDSTOP0x0001
 #define TARGET_SA_NOCLDWAIT0x0001
@@ -483,6 +484,10 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 #define TARGET_SA_RESTORER 0x0400
 #endif
 
+#ifdef TARGET_SA_RESTORER
+#define TARGET_ARCH_HAS_SA_RESTORER 1
+#endif
+
 #if defined(TARGET_ALPHA)
 
 #define TARGET_SIGHUP1
@@ -718,19 +723,27 @@ struct target_sigaction {
abi_ulong   _sa_handler;
 #endif
target_sigset_t sa_mask;
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
+/* ??? This is always present, but ignored unless O32.  */
+abi_ulong sa_restorer;
+#endif
 };
 #else
 struct target_old_sigaction {
 abi_ulong _sa_handler;
 abi_ulong sa_mask;
 abi_ulong sa_flags;
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
 abi_ulong sa_restorer;
+#endif
 };
 
 struct target_sigaction {
 abi_ulong _sa_handler;
 abi_ulong sa_flags;
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
 abi_ulong sa_restorer;
+#endif
 target_sigset_t sa_mask;
 };
 #endif
-- 
2.14.2




[Qemu-devel] [PULL 07/15] linux-user: Handle TARGET_MAP_STACK and TARGET_MAP_HUGETLB

2017-11-20 Thread riku . voipio
From: Helge Deller <del...@gmx.de>

Add the missing defines and for TARGET_MAP_STACK and TARGET_MAP_HUGETLB
for alpha, mips, ppc, x86, hppa.  Fix the mmap_flags translation table
to translate MAP_HUGETLB between host and target architecture, and to
drop MAP_STACK.

Signed-off-by: Helge Deller <del...@gmx.de>
Message-Id: <20170311183016.ga20...@ls3530.fritz.box>
[rth: Drop MAP_STACK instead of translating it, since it is ignored
in the kernel anyway.  Fix tabs to spaces.]
Signed-off-by: Richard Henderson <r...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c  | 31 ---
 linux-user/syscall_defs.h | 10 ++
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d4497dec5d..8047bf3aac 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5872,17 +5872,26 @@ static const StructEntry struct_termios_def = {
 };
 
 static bitmask_transtbl mmap_flags_tbl[] = {
-   { TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED },
-   { TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE },
-   { TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED },
-   { TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS, MAP_ANONYMOUS, 
MAP_ANONYMOUS },
-   { TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN, MAP_GROWSDOWN, 
MAP_GROWSDOWN },
-   { TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, 
MAP_DENYWRITE },
-   { TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, 
MAP_EXECUTABLE },
-   { TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED },
-{ TARGET_MAP_NORESERVE, TARGET_MAP_NORESERVE, MAP_NORESERVE,
-  MAP_NORESERVE },
-   { 0, 0, 0, 0 }
+{ TARGET_MAP_SHARED, TARGET_MAP_SHARED, MAP_SHARED, MAP_SHARED },
+{ TARGET_MAP_PRIVATE, TARGET_MAP_PRIVATE, MAP_PRIVATE, MAP_PRIVATE },
+{ TARGET_MAP_FIXED, TARGET_MAP_FIXED, MAP_FIXED, MAP_FIXED },
+{ TARGET_MAP_ANONYMOUS, TARGET_MAP_ANONYMOUS,
+  MAP_ANONYMOUS, MAP_ANONYMOUS },
+{ TARGET_MAP_GROWSDOWN, TARGET_MAP_GROWSDOWN,
+  MAP_GROWSDOWN, MAP_GROWSDOWN },
+{ TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE,
+  MAP_DENYWRITE, MAP_DENYWRITE },
+{ TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE,
+  MAP_EXECUTABLE, MAP_EXECUTABLE },
+{ TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED },
+{ TARGET_MAP_NORESERVE, TARGET_MAP_NORESERVE,
+  MAP_NORESERVE, MAP_NORESERVE },
+{ TARGET_MAP_HUGETLB, TARGET_MAP_HUGETLB, MAP_HUGETLB, MAP_HUGETLB },
+/* MAP_STACK had been ignored by the kernel for quite some time.
+   Recognize it for the target insofar as we do not want to pass
+   it through to the host.  */
+{ TARGET_MAP_STACK, TARGET_MAP_STACK, 0, 0 },
+{ 0, 0, 0, 0 }
 };
 
 #if defined(TARGET_I386)
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index daa2a57398..bec3680b94 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -1353,6 +1353,8 @@ struct target_winsize {
 #define TARGET_MAP_NORESERVE   0x0400  /* don't check for reservations 
*/
 #define TARGET_MAP_POPULATE0x1 /* populate (prefault) 
pagetables */
 #define TARGET_MAP_NONBLOCK0x2 /* do not block on IO */
+#define TARGET_MAP_STACK0x4 /* ignored */
+#define TARGET_MAP_HUGETLB  0x8 /* create a huge page mapping 
*/
 #elif defined(TARGET_PPC)
 #define TARGET_MAP_FIXED   0x10/* Interpret addr exactly */
 #define TARGET_MAP_ANONYMOUS   0x20/* don't use a file */
@@ -1363,6 +1365,8 @@ struct target_winsize {
 #define TARGET_MAP_NORESERVE   0x0040  /* don't check for reservations 
*/
 #define TARGET_MAP_POPULATE0x8000  /* populate (prefault) 
pagetables */
 #define TARGET_MAP_NONBLOCK0x1 /* do not block on IO */
+#define TARGET_MAP_STACK0x2 /* ignored */
+#define TARGET_MAP_HUGETLB  0x4 /* create a huge page mapping 
*/
 #elif defined(TARGET_ALPHA)
 #define TARGET_MAP_ANONYMOUS   0x10/* don't use a file */
 #define TARGET_MAP_FIXED   0x100   /* Interpret addr exactly */
@@ -1373,6 +1377,8 @@ struct target_winsize {
 #define TARGET_MAP_NORESERVE   0x1 /* no check for reservations */
 #define TARGET_MAP_POPULATE0x2 /* pop (prefault) pagetables */
 #define TARGET_MAP_NONBLOCK0x4 /* do not block on IO */
+#define TARGET_MAP_STACK0x8 /* ignored */
+#define TARGET_MAP_HUGETLB  0x10/* create a huge page mapping 
*/
 #elif defined(TARGET_HPPA)
 #define TARGET_MAP_ANONYMOUS   0x10/* don't use a file */
 #define TARGET_MAP_FIXED   0x04/* Interpret addr exactly */
@@ -1383,6 +1389,8 @@ struct target_winsize {
 #define TARGET_MAP_NORESERVE   0x04000   

[Qemu-devel] [PULL 00/15] late linux-user fixes for 2.11

2017-11-20 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

The following changes since commit b0fbe46ad82982b289a44ee2495b59b0bad8a842:

  Update version for v2.11.0-rc0 release (2017-11-07 16:05:28 +)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20171120

for you to fetch changes up to f516511ea84d8bb3395d6ea95a7c7b80dc2a05e9:

  linux-user: Fix calculation of auxv length (2017-11-20 16:15:41 +0200)


late linux-user fixes for Qemu 2.11


Emilio G. Cota (1):
  linux-user: fix 'finshed' typo in comment

Helge Deller (5):
  linux-user/hppa: Fix TARGET_SA_* defines
  linux-user/hppa: Fix typo for TARGET_NR_epoll_wait
  linux-user/hppa: Fix TARGET_MAP_TYPE
  linux-user/hppa: Fix TARGET_F_RDLCK, TARGET_F_WRLCK, TARGET_F_UNLCK
  linux-user: Handle TARGET_MAP_STACK and TARGET_MAP_HUGETLB

James Clarke (1):
  linux-user/syscall.c: Handle SH4's exceptional alignment for p{read, 
write}64

James Cowgill (1):
  linux-user: return EINVAL from prctl(PR_*_SECCOMP)

Peter Maydell (5):
  linux-user/s390x: Mask si_addr for SIGSEGV
  linux-user/ppc: Report correct fault address for data faults
  linux-user/sparc: Put address for data faults where linux-user expects it
  linux-user: Handle rt_sigaction correctly for SPARC
  linux-user: Fix calculation of auxv length

Richard Henderson (2):
  linux-user: Restrict usage of sa_restorer
  linux-user/hppa: Fix cpu_clone_regs

 linux-user/elfload.c |  11 +++--
 linux-user/hppa/syscall_nr.h |   2 +-
 linux-user/hppa/target_cpu.h |   4 
 linux-user/main.c|   8 +--
 linux-user/signal.c  |   4 ++--
 linux-user/syscall.c | 102 
++--
 linux-user/syscall_defs.h|  40 -
 target/sparc/mmu_helper.c|   8 +++
 8 files changed, 144 insertions(+), 35 deletions(-)




[Qemu-devel] [PULL 09/15] linux-user: fix 'finshed' typo in comment

2017-11-20 Thread riku . voipio
From: "Emilio G. Cota" <c...@braap.org>

Signed-off-by: Emilio G. Cota <c...@braap.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9268c3ef69..84e123b67b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6258,7 +6258,7 @@ static void *clone_func(void *arg)
 pthread_mutex_lock(>mutex);
 pthread_cond_broadcast(>cond);
 pthread_mutex_unlock(>mutex);
-/* Wait until the parent has finshed initializing the tls state.  */
+/* Wait until the parent has finished initializing the tls state.  */
 pthread_mutex_lock(_lock);
 pthread_mutex_unlock(_lock);
 cpu_loop(env);
-- 
2.14.2




Re: [Qemu-devel] [PATCH v2] linux-user: fix is_proc_myself to check the paths via realpath

2017-11-07 Thread Riku Voipio
Hi,

On Mon, Nov 06, 2017 at 08:17:44PM +, Zach Riggle wrote:
> Ping! What needs to be done to move this forward? My current implementation
> is compatible with musl.

I'll have a look at it soon.

Riku

> On Thu, Nov 2, 2017 at 12:36 PM Peter Maydell 
> wrote:
> 
> > On 28 October 2017 at 06:14, Eric Blake  wrote:
> > > By definition, in linux-user, we ARE using glibc; therefore, you are
> > > free to use all GNU extensions.
> >
> > Don't we also support musl libc? I forget...
> >
> > thanks
> > -- PMM
> >



Re: [Qemu-devel] [PATCH 0/4] linux-user: fix various SIGSEGV delivery bugs

2017-11-07 Thread Riku Voipio
On Mon, Nov 06, 2017 at 06:33:22PM +, Peter Maydell wrote:
> This patchset fixes most of the problems with delivering SIGSEGV
> noted in https://bugs.launchpad.net/qemu/+bug/1705118:
>  * s390x is missing masking operations on the fault address
>passed to the guest in si_addr
>  * ppc is passing the PC of the offending insn, not the data
>address, into si_addr
>  * sparc fails to record the address of a data fault and so
>passes 0 into si_addr
>  * sparc isn't implementing rt_sigaction correctly (it has an
>extra 'restorer' argument, similar to alpha)
> 
> It doesn't actually get the sparc testcase from that bug working,
> though, because SPARC is entirely missing support for setup_rt_frame()
> and do_rt_sigreturn(), so it can't deliver RT signals.
> 
> Implementing RT signal delivery is too big a bugfix for an afternoon,
> so here are the simpler parts. I'll leave the signal delivery part
> to somebody who cares about SPARC guests...
> 
> thanks
> -- PMM

Thanks!

series applied to linux-user tree,

Riku

 
> Peter Maydell (4):
>   linux-user/s390x: Mask si_addr for SIGSEGV
>   linux-user/ppc: Report correct fault address for data faults
>   linux-user/sparc: Put address for data faults where linux-user expects
> it
>   linux-user: Handle rt_sigaction correctly for SPARC
> 
>  linux-user/main.c |  8 ++--
>  linux-user/syscall.c  | 27 +++
>  target/sparc/mmu_helper.c |  8 
>  3 files changed, 37 insertions(+), 6 deletions(-)
> 
> -- 
> 2.7.4
> 



Re: [Qemu-devel] [PATCH v2] linux-user: return EINVAL from prctl(PR_*_SECCOMP)

2017-11-06 Thread Riku Voipio
On Mon, Nov 06, 2017 at 06:03:51PM +, James Cowgill wrote:
> If an application tries to install a seccomp filter using
> prctl(PR_SET_SECCOMP), the filter is likely for the target instead of the host
> architecture. This will probably cause qemu to be immediately killed when it
> executes another syscall.
> 
> Prevent this from happening by returning EINVAL from both seccomp prctl
> calls. This is the error returned by the kernel when seccomp support is
> disabled.

Thanks, applied to linux-user
 
> Fixes: https://bugs.launchpad.net/qemu/+bug/1726394
> Signed-off-by: James Cowgill 
> ---
> Changes from v1:
> - add comment
> 
>  linux-user/syscall.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index d4497dec5d..419991e834 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -10482,6 +10482,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  break;
>  }
>  #endif
> +case PR_GET_SECCOMP:
> +case PR_SET_SECCOMP:
> +/* Disable seccomp to prevent the target disabling syscalls we
> + * need. */
> +ret = -TARGET_EINVAL;
> +break;
>  default:
>  /* Most prctl options have no pointer arguments */
>  ret = get_errno(prctl(arg1, arg2, arg3, arg4, arg5));
> -- 
> 2.15.0
> 
> 



Re: [Qemu-devel] [PATCH 2/4] linux-user: fix 'finshed' typo in comment

2017-11-06 Thread Riku Voipio
Applied to linux-user, thanks

Riku

On Wed, Oct 18, 2017 at 06:01:41PM -0400, Emilio G. Cota wrote:
> Signed-off-by: Emilio G. Cota 
> ---
>  linux-user/syscall.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 9d4cc4c..47b4a79 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -6231,7 +6231,7 @@ static void *clone_func(void *arg)
>  pthread_mutex_lock(>mutex);
>  pthread_cond_broadcast(>cond);
>  pthread_mutex_unlock(>mutex);
> -/* Wait until the parent has finshed initializing the tls state.  */
> +/* Wait until the parent has finished initializing the tls state.  */
>  pthread_mutex_lock(_lock);
>  pthread_mutex_unlock(_lock);
>  cpu_loop(env);
> -- 
> 2.7.4
> 
> 



Re: [Qemu-devel] [PATCH v3] linux-user/syscall.c: Handle SH4's exceptional alignment for p{read, write}64

2017-11-06 Thread Riku Voipio
On Wed, Oct 04, 2017 at 10:38:50AM +0200, John Paul Adrian Glaubitz wrote:
> Hi!
> 
> Any chance that this patch gets merged soon?
> 
> Looks like it has been reviewed by at least Richard and Philippe.

Sorry, slipped under radar. Applied to linux-user.
 
> Adrian
> 
> On 09/15/2017 09:33 PM, James Clarke wrote:
> >Fixes: https://bugs.launchpad.net/qemu/+bug/1716767
> >Signed-off-by: James Clarke 
> >---
> >
> >Changes since v2:
> >  * Fixed opening curly brace formatting, both for my new SH4-specific
> >regpairs_aligned function, as well as the Arm one I touched, to appease
> >checkpatch.pl
> >
> >Changes since v1:
> >  * Removed all changes in v1 :)
> >  * Added syscall num argument to regpairs_aligned
> >  * Added SH4-specific implementation of regpairs_aligned to return 1 for
> >p{read,write}64
> >
> >  linux-user/syscall.c | 36 +---
> >  1 file changed, 25 insertions(+), 11 deletions(-)
> >
> >diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> >index 9b6364a266..0c1bd80bed 100644
> >--- a/linux-user/syscall.c
> >+++ b/linux-user/syscall.c
> >@@ -667,18 +667,32 @@ static inline int next_free_host_timer(void)
> >  /* ARM EABI and MIPS expect 64bit types aligned even on pairs or registers 
> > */
> >  #ifdef TARGET_ARM
> >-static inline int regpairs_aligned(void *cpu_env) {
> >+static inline int regpairs_aligned(void *cpu_env, int num)
> >+{
> >  return CPUARMState *)cpu_env)->eabi) == 1) ;
> >  }
> >  #elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32)
> >-static inline int regpairs_aligned(void *cpu_env) { return 1; }
> >+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> >  #elif defined(TARGET_PPC) && !defined(TARGET_PPC64)
> >  /* SysV AVI for PPC32 expects 64bit parameters to be passed on odd/even 
> > pairs
> >   * of registers which translates to the same as ARM/MIPS, because we start 
> > with
> >   * r3 as arg1 */
> >-static inline int regpairs_aligned(void *cpu_env) { return 1; }
> >+static inline int regpairs_aligned(void *cpu_env, int num) { return 1; }
> >+#elif defined(TARGET_SH4)
> >+/* SH4 doesn't align register pairs, except for p{read,write}64 */
> >+static inline int regpairs_aligned(void *cpu_env, int num)
> >+{
> >+switch (num) {
> >+case TARGET_NR_pread64:
> >+case TARGET_NR_pwrite64:
> >+return 1;
> >+
> >+default:
> >+return 0;
> >+}
> >+}
> >  #else
> >-static inline int regpairs_aligned(void *cpu_env) { return 0; }
> >+static inline int regpairs_aligned(void *cpu_env, int num) { return 0; }
> >  #endif
> >  #define ERRNO_TABLE_SIZE 1200
> >@@ -6857,7 +6871,7 @@ static inline abi_long target_truncate64(void 
> >*cpu_env, const char *arg1,
> >   abi_long arg3,
> >   abi_long arg4)
> >  {
> >-if (regpairs_aligned(cpu_env)) {
> >+if (regpairs_aligned(cpu_env, TARGET_NR_truncate64)) {
> >  arg2 = arg3;
> >  arg3 = arg4;
> >  }
> >@@ -6871,7 +6885,7 @@ static inline abi_long target_ftruncate64(void 
> >*cpu_env, abi_long arg1,
> >abi_long arg3,
> >abi_long arg4)
> >  {
> >-if (regpairs_aligned(cpu_env)) {
> >+if (regpairs_aligned(cpu_env, TARGET_NR_ftruncate64)) {
> >  arg2 = arg3;
> >  arg3 = arg4;
> >  }
> >@@ -10495,7 +10509,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> >arg1,
> >  #endif
> >  #ifdef TARGET_NR_pread64
> >  case TARGET_NR_pread64:
> >-if (regpairs_aligned(cpu_env)) {
> >+if (regpairs_aligned(cpu_env, num)) {
> >  arg4 = arg5;
> >  arg5 = arg6;
> >  }
> >@@ -10505,7 +10519,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> >arg1,
> >  unlock_user(p, arg2, ret);
> >  break;
> >  case TARGET_NR_pwrite64:
> >-if (regpairs_aligned(cpu_env)) {
> >+if (regpairs_aligned(cpu_env, num)) {
> >  arg4 = arg5;
> >  arg5 = arg6;
> >  }
> >@@ -11275,7 +11289,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> >arg1,
> >  arg6 = ret;
> >  #else
> >  /* 6 args: fd, offset (high, low), len (high, low), advice */
> >-if (regpairs_aligned(cpu_env)) {
> >+if (regpairs_aligned(cpu_env, num)) {
> >  /* offset is in (3,4), len in (5,6) and advice in 7 */
> >  arg2 = arg3;
> >  arg3 = arg4;
> >@@ -11294,7 +11308,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> >arg1,
> >  #ifdef TARGET_NR_fadvise64
> >  case TARGET_NR_fadvise64:
> >  /* 5 args: fd, offset (high, low), len, advice */
> >-if (regpairs_aligned(cpu_env)) {
> >+if (regpairs_aligned(cpu_env, num)) {
> >  /* offset is in (3,4), len in 5 and advice in 6 */
> >  arg2 = arg3;
> >  

Re: [Qemu-devel] [PATCH 0/7] linux-user fixes, mostly for hppa

2017-11-06 Thread Riku Voipio
On Tue, Oct 31, 2017 at 01:53:51PM +0100, Richard Henderson wrote:
> I believe these were last posted back in March.
> I must claim responsibility for not pinging earlier.

Thanks, applied to linux-user 
 
> 
> r~
> 
> 
> Helge Deller (5):
>   linux-user/hppa: Fix TARGET_SA_* defines
>   linux-user/hppa: Fix typo for TARGET_NR_epoll_wait
>   linux-user/hppa: Fix TARGET_MAP_TYPE
>   linux-user/hppa: Fix TARGET_F_RDLCK, TARGET_F_WRLCK, TARGET_F_UNLCK
>   linux-user: Handle TARGET_MAP_STACK and TARGET_MAP_HUGETLB
> 
> Richard Henderson (2):
>   linux-user: Restrict usage of sa_restorer
>   linux-user/hppa: Fix cpu_clone_regs
> 
>  linux-user/hppa/syscall_nr.h |  2 +-
>  linux-user/hppa/target_cpu.h |  4 
>  linux-user/syscall_defs.h| 40 +++-
>  linux-user/signal.c  |  4 ++--
>  linux-user/syscall.c | 31 ---
>  5 files changed, 66 insertions(+), 15 deletions(-)
> 
> -- 
> 2.13.6
> 
> 



Re: [Qemu-devel] [PATCH v2] linux-user: fix is_proc_myself to check the paths via realpath

2017-10-27 Thread Riku Voipio
On Thu, Oct 26, 2017 at 04:06:22PM -0500, Zach Riggle wrote:
> Friendly ping :)
> 
> I've updated the patch with v2 which addresses the style issue

I'll have a look at it soon.
 
> 
> *Zach Riggle*
> 
> On Tue, Oct 24, 2017 at 10:34 PM, Zach Riggle  wrote:
> 
> > Previously, it was possible to get a handle to the "real" /proc/self/mem
> > by creating a symlink to it and opening the symlink, or opening e.g.
> > "./mem" after chdir'ing to "/proc/self"

When is this a problem? Symlinking to /proc/self seems to be a quite weird 
usecase.

> >
> > $ ln -s /proc/self self
> > $ cat self/maps
> > 6000-602bc000 r-xp  fc:01 270375
> >/usr/bin/qemu-arm-static
> > 604bc000-6050f000 rw-p 002bc000 fc:01 270375
> >/usr/bin/qemu-arm-static
> > ...
> >
> > Signed-off-by: Zach Riggle 
> > ---
> >  linux-user/syscall.c | 47 ---
> >  1 file changed, 28 insertions(+), 19 deletions(-)
> >
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index 9bf901fa11..6c1f28a1f7 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -7496,26 +7496,35 @@ static int open_self_auxv(void *cpu_env, int fd)
> >
> >  static int is_proc_myself(const char *filename, const char *entry)
> >  {
> > -if (!strncmp(filename, "/proc/", strlen("/proc/"))) {
> > -filename += strlen("/proc/");
> > -if (!strncmp(filename, "self/", strlen("self/"))) {
> > -filename += strlen("self/");
> > -} else if (*filename >= '1' && *filename <= '9') {
> > -char myself[80];
> > -snprintf(myself, sizeof(myself), "%d/", getpid());
> > -if (!strncmp(filename, myself, strlen(myself))) {
> > -filename += strlen(myself);
> > -} else {
> > -return 0;
> > -}
> > -} else {
> > -return 0;
> > -}
> > -if (!strcmp(filename, entry)) {
> > -return 1;
> > -}
> > +char proc_self_entry[PATH_MAX + 1];
> > +char proc_self_entry_realpath[PATH_MAX + 1];
> > +char filename_realpath[PATH_MAX + 1];
> > +
> > +if (PATH_MAX < snprintf(proc_self_entry,
> > +sizeof(proc_self_entry),
> > +"/proc/self/%s",
> > +entry)) {
> > +/* Full path to "entry" is too long to fit in the buffer */
> > +return 0;
> >  }
> > -return 0;
> > +
> > +if (!realpath(filename, filename_realpath)) {
> > +/* File does not exist, or can't be canonicalized */
> > +return 0;
> > +}
> > +
> > +if (!realpath(proc_self_entry, proc_self_entry_realpath)) {
> > +/* Procfs entry does not exist */
> > +return 0;
> > +}
> > +
> > +if (strcmp(filename_realpath, proc_self_entry_realpath) != 0) {
> > +/* Paths are different */
> > +return 0;
> > +}
> > +
> > +/* filename refers to /proc/self/ */
> > +return 1;
> >  }
> >
> >  #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
> > --
> > 2.14.3
> >
> >



[Qemu-devel] [PULL 08/10] linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers

2017-10-18 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

We were defining TARGET_FS_IOC_GETFLAGS and TARGET_FS_IOC_SETFLAGS
using the host 'long' type in the size field, which meant that
they had the wrong values if the host and guest had different
sized longs. Switch to abi_long instead.

This fixes a bug where these ioctls don't work on 32-bit guests
on 64-bit hosts (and makes the LTP test 'setxattr03' pass
where it did not previously.)

Reported-by: pgndev <pgnet@gmail.com>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 6e2287e918..447915cf80 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -1101,8 +1101,8 @@ struct target_pollfd {
 /* Note that the ioctl numbers claim type "long" but the actual type
  * used by the kernel is "int".
  */
-#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, long)
-#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, long)
+#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, abi_long)
+#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, abi_long)
 
 #define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
 
-- 
2.14.2




[Qemu-devel] [PULL 10/10] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values

2017-10-18 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

The TARGET_MTIOCTOP/TARGET_MTIOCGET/TARGET_MTIOCPOS values
were being defined in terms of host struct types, but
these structures are such that their size might differ
on different hosts. Switch to using a target struct
definition instead.

Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall_defs.h | 31 ---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 447915cf80..e405d1d31d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2712,9 +2712,34 @@ struct target_f_owner_ex {
 #define TARGET_VFAT_IOCTL_READDIR_BOTHTARGET_IORU('r', 1)
 #define TARGET_VFAT_IOCTL_READDIR_SHORT   TARGET_IORU('r', 2)
 
-#define TARGET_MTIOCTOPTARGET_IOW('m', 1, struct mtop)
-#define TARGET_MTIOCGETTARGET_IOR('m', 2, struct mtget)
-#define TARGET_MTIOCPOSTARGET_IOR('m', 3, struct mtpos)
+struct target_mtop {
+abi_short mt_op;
+abi_int mt_count;
+};
+
+#if defined(TARGET_SPARC) || defined(TARGET_MIPS)
+typedef abi_long target_kernel_daddr_t;
+#else
+typedef abi_int target_kernel_daddr_t;
+#endif
+
+struct target_mtget {
+abi_long mt_type;
+abi_long mt_resid;
+abi_long mt_dsreg;
+abi_long mt_gstat;
+abi_long mt_erreg;
+target_kernel_daddr_t mt_fileno;
+target_kernel_daddr_t mt_blkno;
+};
+
+struct target_mtpos {
+abi_long mt_blkno;
+};
+
+#define TARGET_MTIOCTOPTARGET_IOW('m', 1, struct target_mtop)
+#define TARGET_MTIOCGETTARGET_IOR('m', 2, struct target_mtget)
+#define TARGET_MTIOCPOSTARGET_IOR('m', 3, struct target_mtpos)
 
 struct target_sysinfo {
 abi_long uptime;/* Seconds since boot */
-- 
2.14.2




[Qemu-devel] [PULL 06/10] linux-user: Tidy and enforce reserved_va initialization

2017-10-18 Thread riku . voipio
From: Richard Henderson <r...@twiddle.net>

We had a check using TARGET_VIRT_ADDR_SPACE_BITS to make sure
that the allocation coming in from the command-line option was
not too large, but that didn't include target-specific knowledge
about other restrictions on user-space.

Remove several target-specific hacks in linux-user/main.c.

For MIPS and Nios, we can replace them with proper adjustments
to the respective target's TARGET_VIRT_ADDR_SPACE_BITS definition.

For ARM, we had no existing ifdef but I suspect that the current
default value of 0xf700 was chosen with this in mind.  Define
a workable value in linux-user/arm/, and also document why the
special case is required.

Signed-off-by: Richard Henderson <r...@twiddle.net>
Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>
Message-Id: <20170708025030.15845-3-...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/arm/target_cpu.h |  4 
 linux-user/main.c   | 38 +-
 target/mips/mips-defs.h |  6 +-
 target/nios2/cpu.h  |  6 +-
 4 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h
index d888219150..c3eb4b243d 100644
--- a/linux-user/arm/target_cpu.h
+++ b/linux-user/arm/target_cpu.h
@@ -19,6 +19,10 @@
 #ifndef ARM_TARGET_CPU_H
 #define ARM_TARGET_CPU_H
 
+/* We need to be able to map the commpage.
+   See validate_guest_space in linux-user/elfload.c.  */
+#define MAX_RESERVED_VA  0xul
+
 static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
 {
 if (newsp) {
diff --git a/linux-user/main.c b/linux-user/main.c
index 829f974662..fd54d344bb 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -60,23 +60,38 @@ do {
\
 }   \
 } while (0)
 
-#if (TARGET_LONG_BITS == 32) && (HOST_LONG_BITS == 64)
 /*
  * When running 32-on-64 we should make sure we can fit all of the possible
  * guest address space into a contiguous chunk of virtual host memory.
  *
  * This way we will never overlap with our own libraries or binaries or stack
  * or anything else that QEMU maps.
+ *
+ * Many cpus reserve the high bit (or more than one for some 64-bit cpus)
+ * of the address for the kernel.  Some cpus rely on this and user space
+ * uses the high bit(s) for pointer tagging and the like.  For them, we
+ * must preserve the expected address space.
  */
-# if defined(TARGET_MIPS) || defined(TARGET_NIOS2)
-/*
- * MIPS only supports 31 bits of virtual address space for user space.
- * Nios2 also only supports 31 bits.
- */
-unsigned long reserved_va = 0x7700;
+#ifndef MAX_RESERVED_VA
+# if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
+#  if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \
+  (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32))
+/* There are a number of places where we assign reserved_va to a variable
+   of type abi_ulong and expect it to fit.  Avoid the last page.  */
+#   define MAX_RESERVED_VA  (0xul & TARGET_PAGE_MASK)
+#  else
+#   define MAX_RESERVED_VA  (1ul << TARGET_VIRT_ADDR_SPACE_BITS)
+#  endif
 # else
-unsigned long reserved_va = 0xf700;
+#  define MAX_RESERVED_VA  0
 # endif
+#endif
+
+/* That said, reserving *too* much vm space via mmap can run into problems
+   with rlimits, oom due to page table creation, etc.  We will still try it,
+   if directed by the command-line option, but not by default.  */
+#if HOST_LONG_BITS == 64 && TARGET_VIRT_ADDR_SPACE_BITS <= 32
+unsigned long reserved_va = MAX_RESERVED_VA;
 #else
 unsigned long reserved_va;
 #endif
@@ -3978,11 +3993,8 @@ static void handle_arg_reserved_va(const char *arg)
 unsigned long unshifted = reserved_va;
 p++;
 reserved_va <<= shift;
-if (((reserved_va >> shift) != unshifted)
-#if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
-|| (reserved_va > (1ul << TARGET_VIRT_ADDR_SPACE_BITS))
-#endif
-) {
+if (reserved_va >> shift != unshifted
+|| (MAX_RESERVED_VA && reserved_va > MAX_RESERVED_VA)) {
 fprintf(stderr, "Reserved virtual address too big\n");
 exit(EXIT_FAILURE);
 }
diff --git a/target/mips/mips-defs.h b/target/mips/mips-defs.h
index 047554ee45..d239069975 100644
--- a/target/mips/mips-defs.h
+++ b/target/mips/mips-defs.h
@@ -15,7 +15,11 @@
 #else
 #define TARGET_LONG_BITS 32
 #define TARGET_PHYS_ADDR_SPACE_BITS 40
-#define TARGET_VIRT_ADDR_SPACE_BITS 32
+# ifdef CONFIG_USER_ONLY
+#  define TARGET_VIRT_ADDR_SPACE_BITS 31
+# else
+#  define TARGET_VIRT_ADDR_SPACE_BITS 32
+#endif
 #endif
 
 /* Masks used to mark instructions to indicate which ISA level they
diff --git a/target/nios2/cpu.h b/target/nios2/cpu.h
index 50d803a2

[Qemu-devel] [PULL 00/10] linux-user update for 2.11

2017-10-18 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

The following changes since commit 40a1e8ac2e10155b5df13a2508ac080b00cd7e23:

  Merge remote-tracking branch 'remotes/elmarco/tags/vu-pull-request' into 
staging (2017-10-16 10:22:39 +0100)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20171018

for you to fetch changes up to f443e3960d9d3340dd286e5fc0b661bb165a8b22:

  linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values (2017-10-17 22:24:02 
+0300)


Linux-user updates for Qemu 2.11


Alex Bennée (1):
  linux-user/main: support dfilter

Carlo Marcelo Arenas Belón (1):
  linux-user: remove duplicate break in syscall

Laurent Vivier (1):
  target/m68k,linux-user: manage FP registers in ucontext

Peter Maydell (3):
  linux-user: Allow -R values up to 0x for 32-bit ARM guests
  linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers
  linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values

Richard Henderson (3):
  tcg: Fix off-by-one in assert in page_set_flags
  linux-user: Tidy and enforce reserved_va initialization
  linux-user/sh4: Reduce TARGET_VIRT_ADDR_SPACE_BITS to 31

Riku Voipio (1):
  linux-user: fix O_TMPFILE handling

 accel/tcg/translate-all.c   |  2 +-
 linux-user/arm/target_cpu.h |  4 
 linux-user/elfload.c|  2 +-
 linux-user/main.c   | 45 -
 linux-user/signal.c | 43 +++
 linux-user/strace.c |  4 
 linux-user/syscall.c|  4 +++-
 linux-user/syscall_defs.h   | 43 +--
 target/mips/mips-defs.h |  6 +-
 target/nios2/cpu.h  |  6 +-
 target/sh4/cpu.h|  6 +-
 11 files changed, 140 insertions(+), 25 deletions(-)




[Qemu-devel] [PULL 07/10] linux-user/sh4: Reduce TARGET_VIRT_ADDR_SPACE_BITS to 31

2017-10-18 Thread riku . voipio
From: Richard Henderson <r...@twiddle.net>

The real kernel has TASK_SIZE as 0x7c00, due to quirks with
a couple of SH parts.  But nominally user-space is limited to 2GB.

Signed-off-by: Richard Henderson <r...@twiddle.net>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Message-Id: <20170708025030.15845-4-...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 target/sh4/cpu.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/target/sh4/cpu.h b/target/sh4/cpu.h
index 79f85d3365..123f34783a 100644
--- a/target/sh4/cpu.h
+++ b/target/sh4/cpu.h
@@ -45,7 +45,11 @@
 #define TARGET_PAGE_BITS 12/* 4k X */
 
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
-#define TARGET_VIRT_ADDR_SPACE_BITS 32
+#ifdef CONFIG_USER_ONLY
+# define TARGET_VIRT_ADDR_SPACE_BITS 31
+#else
+# define TARGET_VIRT_ADDR_SPACE_BITS 32
+#endif
 
 #define SR_MD 30
 #define SR_RB 29
-- 
2.14.2




[Qemu-devel] [PULL 05/10] tcg: Fix off-by-one in assert in page_set_flags

2017-10-18 Thread riku . voipio
From: Richard Henderson <r...@twiddle.net>

Most of the users of page_set_flags offset (page, page + len) as
the end points.  One might consider this an error, since the other
users do supply an endpoint as the last byte of the region.

However, the first thing that page_set_flags does is round end UP
to the start of the next page.  Which means computing page + len - 1
is in the end pointless.  Therefore, accept this usage and do not
assert when given the exact size of the vm as the endpoint.

Signed-off-by: Richard Henderson <r...@twiddle.net>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Message-Id: <20170708025030.15845-2-...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 accel/tcg/translate-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index c5ce99d549..1b43deb0cd 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2114,7 +2114,7 @@ void page_set_flags(target_ulong start, target_ulong end, 
int flags)
guest address space.  If this assert fires, it probably indicates
a missing call to h2g_valid.  */
 #if TARGET_ABI_BITS > L1_MAP_ADDR_SPACE_BITS
-assert(end < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS));
+assert(end <= ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS));
 #endif
 assert(start < end);
 assert_memory_lock();
-- 
2.14.2




[Qemu-devel] [PULL 04/10] linux-user: Allow -R values up to 0xffff0000 for 32-bit ARM guests

2017-10-18 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

The 32-bit ARM validate_guest_space() check tests whether the
specified -R value leaves enough space for us to put the
commpage in at 0x0f00. However it was incorrectly doing
a <= check for the check against (guest_base + guest_size),
which meant that it wasn't permitting the guest space to
butt right up against the commpage.

Fix the comparison, so that -R values all the way up to 0x
work correctly.

Reviewed-by: Emilio G. Cota <c...@braap.org>
Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/elfload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 79062882ba..3b857fbc9c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -377,7 +377,7 @@ static int validate_guest_space(unsigned long guest_base,
  * then there is no way we can allocate it.
  */
 if (test_page_addr >= guest_base
-&& test_page_addr <= (guest_base + guest_size)) {
+&& test_page_addr < (guest_base + guest_size)) {
 return -1;
 }
 
-- 
2.14.2




[Qemu-devel] [PULL 01/10] linux-user: fix O_TMPFILE handling

2017-10-18 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

Since O_TMPFILE might differ between guest and host,
add it to the bitmask_transtbl. While at it, fix the definitions
of O_DIRECTORY etc which should arm32 according to kernel sources.

This fixes open14 and openat03 ltp testcases. Fixes:

https://bugs.launchpad.net/qemu/+bug/1709170
---
 linux-user/strace.c   | 4 
 linux-user/syscall.c  | 3 +++
 linux-user/syscall_defs.h | 8 +++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index d821d165ff..bd897a3f20 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -837,6 +837,10 @@ UNUSED static struct flags open_flags[] = {
 #endif
 #ifdef O_PATH
 FLAG_TARGET(O_PATH),
+#endif
+#ifdef O_TMPFILE
+FLAG_TARGET(O_TMPFILE),
+FLAG_TARGET(__O_TMPFILE),
 #endif
 FLAG_END,
 };
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9b6364a266..08fbc4d5f7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -341,6 +341,9 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
 #endif
 #if defined(O_PATH)
   { TARGET_O_PATH,  TARGET_O_PATH,  O_PATH,  O_PATH   },
+#endif
+#if defined(O_TMPFILE)
+  { TARGET_O_TMPFILE,   TARGET_O_TMPFILE,   O_TMPFILE,   O_TMPFILE},
 #endif
   /* Don't terminate the list prematurely on 64-bit host+guest.  */
 #if TARGET_O_LARGEFILE != 0 || O_LARGEFILE != 0
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 40c5027e93..6e2287e918 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2416,7 +2416,7 @@ struct target_statfs64 {
 #define TARGET_O_CLOEXEC 01000
 #define TARGET___O_SYNC  00010
 #define TARGET_O_PATH02000
-#elif defined(TARGET_ARM) || defined(TARGET_M68K)
+#elif defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_AARCH64)
 #define TARGET_O_DIRECTORY  04 /* must be a directory */
 #define TARGET_O_NOFOLLOW  010 /* don't follow links */
 #define TARGET_O_DIRECT020 /* direct disk access hint */
@@ -2513,6 +2513,12 @@ struct target_statfs64 {
 #ifndef TARGET_O_PATH
 #define TARGET_O_PATH01000
 #endif
+#ifndef TARGET___O_TMPFILE
+#define TARGET___O_TMPFILE   02000
+#endif
+#ifndef TARGET_O_TMPFILE
+#define TARGET_O_TMPFILE (TARGET___O_TMPFILE | TARGET_O_DIRECTORY)
+#endif
 #ifndef TARGET_O_NDELAY
 #define TARGET_O_NDELAY  TARGET_O_NONBLOCK
 #endif
-- 
2.14.2




[Qemu-devel] [PULL 02/10] target/m68k, linux-user: manage FP registers in ucontext

2017-10-18 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Richard Henderson <r...@twiddle.net>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/signal.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index cc0c3fcee9..7a238aaea1 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -5704,6 +5704,24 @@ give_sigsegv:
 force_sigsegv(sig);
 }
 
+static inline void target_rt_save_fpu_state(struct target_ucontext *uc,
+   CPUM68KState *env)
+{
+int i;
+target_fpregset_t *fpregs = >tuc_mcontext.fpregs;
+
+__put_user(env->fpcr, >f_fpcntl[0]);
+__put_user(env->fpsr, >f_fpcntl[1]);
+/* fpiar is not emulated */
+
+for (i = 0; i < 8; i++) {
+uint32_t high = env->fregs[i].d.high << 16;
+__put_user(high, >f_fpregs[i * 3]);
+__put_user(env->fregs[i].d.low,
+   (uint64_t *)>f_fpregs[i * 3 + 1]);
+}
+}
+
 static inline int target_rt_setup_ucontext(struct target_ucontext *uc,
CPUM68KState *env)
 {
@@ -5730,9 +5748,32 @@ static inline int target_rt_setup_ucontext(struct 
target_ucontext *uc,
 __put_user(env->pc, [16]);
 __put_user(sr, [17]);
 
+target_rt_save_fpu_state(uc, env);
+
 return 0;
 }
 
+static inline void target_rt_restore_fpu_state(CPUM68KState *env,
+   struct target_ucontext *uc)
+{
+int i;
+target_fpregset_t *fpregs = >tuc_mcontext.fpregs;
+uint32_t fpcr;
+
+__get_user(fpcr, >f_fpcntl[0]);
+cpu_m68k_set_fpcr(env, fpcr);
+__get_user(env->fpsr, >f_fpcntl[1]);
+/* fpiar is not emulated */
+
+for (i = 0; i < 8; i++) {
+uint32_t high;
+__get_user(high, >f_fpregs[i * 3]);
+env->fregs[i].d.high = high >> 16;
+__get_user(env->fregs[i].d.low,
+   (uint64_t *)>f_fpregs[i * 3 + 1]);
+}
+}
+
 static inline int target_rt_restore_ucontext(CPUM68KState *env,
  struct target_ucontext *uc)
 {
@@ -5764,6 +5805,8 @@ static inline int target_rt_restore_ucontext(CPUM68KState 
*env,
 __get_user(temp, [17]);
 cpu_m68k_set_ccr(env, temp);
 
+target_rt_restore_fpu_state(env, uc);
+
 return 0;
 
 badframe:
-- 
2.14.2




[Qemu-devel] [PULL 03/10] linux-user: remove duplicate break in syscall

2017-10-18 Thread riku . voipio
From: Carlo Marcelo Arenas Belón <care...@gmail.com>

likely introduced in 3532fa7402cda16f7b95261b0339c58630051f0b

Signed-off-by: Carlo Marcelo Arenas Belón <care...@gmail.com>
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 08fbc4d5f7..a25bbffd16 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3134,7 +3134,6 @@ set_timeout:
 case TARGET_SO_RCVLOWAT:
optname = SO_RCVLOWAT;
break;
-break;
 default:
 goto unimplemented;
 }
-- 
2.14.2




[Qemu-devel] [PULL 09/10] linux-user/main: support dfilter

2017-10-18 Thread riku . voipio
From: Alex Bennée <alex.ben...@linaro.org>

This adds the -dfilter support to linux-user. There is a minor
checkpatch complaint about formatting which I've ignored for aesthetic
reasons.

Signed-off-by: Alex Bennée <alex.ben...@linaro.org>
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Richard Henderson <richard.hender...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/main.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/linux-user/main.c b/linux-user/main.c
index fd54d344bb..dde04c769a 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3869,6 +3869,11 @@ static void handle_arg_log(const char *arg)
 qemu_set_log(mask);
 }
 
+static void handle_arg_dfilter(const char *arg)
+{
+qemu_set_dfilter_ranges(arg, NULL);
+}
+
 static void handle_arg_log_filename(const char *arg)
 {
 qemu_set_log_filename(arg, _fatal);
@@ -4066,6 +4071,8 @@ static const struct qemu_argument arg_table[] = {
 {"d",  "QEMU_LOG", true,  handle_arg_log,
  "item[,...]", "enable logging of specified items "
  "(use '-d help' for a list of items)"},
+{"dfilter","QEMU_DFILTER", true,  handle_arg_dfilter,
+ "range[,...]","filter logging based on address range"},
 {"D",  "QEMU_LOG_FILENAME", true, handle_arg_log_filename,
  "logfile", "write logs to 'logfile' (default stderr)"},
 {"p",  "QEMU_PAGESIZE",true,  handle_arg_pagesize,
-- 
2.14.2




Re: [Qemu-devel] [PATCH] linux-user/main: support dfilter

2017-10-17 Thread Riku Voipio
On Tue, Oct 17, 2017 at 11:35:14AM +0100, Alex Bennée wrote:
> This adds the -dfilter support to linux-user. There is a minor
> checkpatch complaint about formatting which I've ignored for aesthetic
> reasons.

Applied to linux-user, thanks
 
> Signed-off-by: Alex Bennée 
> Reviewed-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 
> 
> ---
> v2
>   - add r-b tags
>   - expand comment to mention checkpatch failure
> ---
>  linux-user/main.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 829f974662..5072aa855b 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -3854,6 +3854,11 @@ static void handle_arg_log(const char *arg)
>  qemu_set_log(mask);
>  }
>  
> +static void handle_arg_dfilter(const char *arg)
> +{
> +qemu_set_dfilter_ranges(arg, NULL);
> +}
> +
>  static void handle_arg_log_filename(const char *arg)
>  {
>  qemu_set_log_filename(arg, _fatal);
> @@ -4054,6 +4059,8 @@ static const struct qemu_argument arg_table[] = {
>  {"d",  "QEMU_LOG", true,  handle_arg_log,
>   "item[,...]", "enable logging of specified items "
>   "(use '-d help' for a list of items)"},
> +{"dfilter","QEMU_DFILTER", true,  handle_arg_dfilter,
> + "range[,...]","filter logging based on address range"},
>  {"D",  "QEMU_LOG_FILENAME", true, handle_arg_log_filename,
>   "logfile", "write logs to 'logfile' (default stderr)"},
>  {"p",  "QEMU_PAGESIZE",true,  handle_arg_pagesize,
> -- 
> 2.14.1
> 



Re: [Qemu-devel] [PATCH 2/2] linux-user: Fix TARGET_MTIOCTOP/MTIOCGET/MTIOCPOS values

2017-10-16 Thread Riku Voipio
On Thu, Oct 12, 2017 at 07:08:55PM +0200, Laurent Vivier wrote:
> Le 12/10/2017 à 18:53, Peter Maydell a écrit :
> > On 12 October 2017 at 17:49, Laurent Vivier  wrote:
> >> Le 12/10/2017 à 17:30, Peter Maydell a écrit :
> >>> +#if defined(TARGET_SPARC) || defined(TARGET_MIPS)
> >>> +typedef abi_long target_kernel_daddr_t;
> >>> +#else
> >>> +typedef abi_int target_kernel_daddr_t;
> >>> +#endif
> >>
> >> Perhaps you can add these ones into include/exec/user/abitypes.h ?
> > 
> > I don't think they belong there -- that file is for basic
> > CPU ABI dependent types, not things which are just part of
> > the kernel interface.

> I agree

So we should go with the patch as-is?

Riku



Re: [Qemu-devel] [PATCH 1/2] linux-user: Fix target FS_IOC_GETFLAGS and FS_IOC_SETFLAGS numbers

2017-10-16 Thread Riku Voipio
On Thu, Oct 12, 2017 at 04:30:44PM +0100, Peter Maydell wrote:
> We were defining TARGET_FS_IOC_GETFLAGS and TARGET_FS_IOC_SETFLAGS
> using the host 'long' type in the size field, which meant that
> they had the wrong values if the host and guest had different
> sized longs. Switch to abi_long instead.
> 
> This fixes a bug where these ioctls don't work on 32-bit guests
> on 64-bit hosts (and makes the LTP test 'setxattr03' pass
> where it did not previously.)

Applied to linux-user, thanks
 
> Reported-by: pgndev 
> Signed-off-by: Peter Maydell 
> ---
>  linux-user/syscall_defs.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index 40c5027..f7cc9f9 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -1101,8 +1101,8 @@ struct target_pollfd {
>  /* Note that the ioctl numbers claim type "long" but the actual type
>   * used by the kernel is "int".
>   */
> -#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, long)
> -#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, long)
> +#define TARGET_FS_IOC_GETFLAGS TARGET_IOR('f', 1, abi_long)
> +#define TARGET_FS_IOC_SETFLAGS TARGET_IOW('f', 2, abi_long)
>  
>  #define TARGET_FS_IOC_FIEMAP TARGET_IOWR('f',11,struct fiemap)
>  
> -- 
> 2.7.4
> 



Re: [Qemu-devel] [PATCH v2 0/4] linux-user fixes for va mapping

2017-10-16 Thread Riku Voipio
On Thu, Oct 05, 2017 at 10:35:57AM -0400, Richard Henderson wrote:
> Version 1 was back in July,
> 
>   https://lists.gnu.org/archive/html/qemu-devel/2017-07/msg02033.html
> 
>   > At first I was simply going to add TARGET_SH to the existing
>   > set of defines that trigger a 31-bit address space.  But then
>   > I realized that one could create non-working va configurations
>   > from the command-line.
> 
> Changes since v1:
>   * Peter fixes the elfload bug that prevented ARM using the proper
> MAX_RESERVED_VA setting.
>   * Adjust the arm MAX_RESERVED_VA.
> 

Thanks, applied to linux-user
 
> r~
> 
> 
> Peter Maydell (1):
>   linux-user: Allow -R values up to 0x for 32-bit ARM guests
> 
> Richard Henderson (3):
>   tcg: Fix off-by-one in assert in page_set_flags
>   linux-user: Tidy and enforce reserved_va initialization
>   linux-user/sh4: Reduce TARGET_VIRT_ADDR_SPACE_BITS to 31
> 
>  linux-user/arm/target_cpu.h |  4 
>  target/mips/mips-defs.h |  6 +-
>  target/nios2/cpu.h  |  6 +-
>  target/sh4/cpu.h|  6 +-
>  accel/tcg/translate-all.c   |  2 +-
>  linux-user/elfload.c|  2 +-
>  linux-user/main.c   | 38 +-
>  7 files changed, 46 insertions(+), 18 deletions(-)
> 
> -- 
> 2.13.6
> 



Re: [Qemu-devel] [PATCH] linux-user: remove duplicate break in syscall

2017-10-16 Thread Riku Voipio
On Mon, Sep 25, 2017 at 09:14:20PM -0700, Carlo Marcelo Arenas Belón wrote:
> likely introduced in 3532fa7402cda16f7b95261b0339c58630051f0b
> 
> Signed-off-by: Carlo Marcelo Arenas Belón 

Applied to linux-user, thanks

> ---
>  linux-user/syscall.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 9b6364a266..3ef4d1c568 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -3131,7 +3131,6 @@ set_timeout:
>  case TARGET_SO_RCVLOWAT:
>   optname = SO_RCVLOWAT;
>   break;
> -break;
>  default:
>  goto unimplemented;
>  }
> -- 
> 2.14.1
> 



Re: [Qemu-devel] linux-user: refactor socket.h into architecture specific sockbits

2017-10-16 Thread Riku Voipio
On Wed, Oct 11, 2017 at 12:10:04AM -0700, Carlo Arenas wrote:
> ping

Thanks for your patience
 
> some of the patches already have a Reviewed-by as shown by :
> 
>   http://patchwork.ozlabs.org/patch/818378/

Can you send the series without the whitespace-only changes?
 
> On Mon, Sep 25, 2017 at 4:19 PM, Carlo Marcelo Arenas Belón
>  wrote:
> > the definitions in socket.h are meant to reflect the ones in linux for each
> > respective target, but are sometimes difficult to maintain.
> >
> > hppa (AKA parisc) was initially merged with an independent file that mirrors
> > more closely the corresponding one in linux but hasn't been updated since.
> >
> > this series updates hppa with the latest bits from linux 4.14 and makes sure
> > all relevant architectures had a sockbits file that would be easy to 
> > maintain
> > going forward.
> >
> > most of the changes are pretty mechanical and I had made (thanks to 
> > Laurent's
> > tough review) every effort to ensure no value gets changed accidentaly and
> > all changes (even the ones where the value remains but is now in a different
> > base to better match what was used in the linux headers) are documented, so
> > it should be fairly safe and will fix bugs (mostly for sparc).
> >



Re: [Qemu-devel] [PATCH v4 1/1] target/m68k, linux-user: manage FP registers in ucontext

2017-10-16 Thread Riku Voipio
On Thu, Sep 14, 2017 at 06:35:05PM +0200, Laurent Vivier wrote:
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 

Applied to linux-user que, thnanks

> ---
>  linux-user/signal.c | 43 +++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index cc0c3fcee9..7a238aaea1 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -5704,6 +5704,24 @@ give_sigsegv:
>  force_sigsegv(sig);
>  }
>  
> +static inline void target_rt_save_fpu_state(struct target_ucontext *uc,
> +   CPUM68KState *env)
> +{
> +int i;
> +target_fpregset_t *fpregs = >tuc_mcontext.fpregs;
> +
> +__put_user(env->fpcr, >f_fpcntl[0]);
> +__put_user(env->fpsr, >f_fpcntl[1]);
> +/* fpiar is not emulated */
> +
> +for (i = 0; i < 8; i++) {
> +uint32_t high = env->fregs[i].d.high << 16;
> +__put_user(high, >f_fpregs[i * 3]);
> +__put_user(env->fregs[i].d.low,
> +   (uint64_t *)>f_fpregs[i * 3 + 1]);
> +}
> +}
> +
>  static inline int target_rt_setup_ucontext(struct target_ucontext *uc,
> CPUM68KState *env)
>  {
> @@ -5730,9 +5748,32 @@ static inline int target_rt_setup_ucontext(struct 
> target_ucontext *uc,
>  __put_user(env->pc, [16]);
>  __put_user(sr, [17]);
>  
> +target_rt_save_fpu_state(uc, env);
> +
>  return 0;
>  }
>  
> +static inline void target_rt_restore_fpu_state(CPUM68KState *env,
> +   struct target_ucontext *uc)
> +{
> +int i;
> +target_fpregset_t *fpregs = >tuc_mcontext.fpregs;
> +uint32_t fpcr;
> +
> +__get_user(fpcr, >f_fpcntl[0]);
> +cpu_m68k_set_fpcr(env, fpcr);
> +__get_user(env->fpsr, >f_fpcntl[1]);
> +/* fpiar is not emulated */
> +
> +for (i = 0; i < 8; i++) {
> +uint32_t high;
> +__get_user(high, >f_fpregs[i * 3]);
> +env->fregs[i].d.high = high >> 16;
> +__get_user(env->fregs[i].d.low,
> +   (uint64_t *)>f_fpregs[i * 3 + 1]);
> +}
> +}
> +
>  static inline int target_rt_restore_ucontext(CPUM68KState *env,
>   struct target_ucontext *uc)
>  {
> @@ -5764,6 +5805,8 @@ static inline int 
> target_rt_restore_ucontext(CPUM68KState *env,
>  __get_user(temp, [17]);
>  cpu_m68k_set_ccr(env, temp);
>  
> +target_rt_restore_fpu_state(env, uc);
> +
>  return 0;
>  
>  badframe:
> -- 
> 2.13.5
> 



[Qemu-devel] [Bug 1709170] [PATCH] linux-user: fix O_TMPFILE handling

2017-08-08 Thread Riku Voipio
Since O_TMPFILE might differ between guest and host,
add it to the bitmask_transtbl. While at it, fix the definitions
of O_DIRECTORY etc on arm64, which are identical to arm32 according
to kernel sources.

This fixes open14 and openat03 ltp testcases.

Fixes: https://bugs.launchpad.net/qemu/+bug/1709170

---
 linux-user/strace.c   | 4 
 linux-user/syscall.c  | 3 +++
 linux-user/syscall_defs.h | 8 +++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index d821d165ff..bd897a3f20 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -838,6 +838,10 @@ UNUSED static struct flags open_flags[] = {
 #ifdef O_PATH
 FLAG_TARGET(O_PATH),
 #endif
+#ifdef O_TMPFILE
+FLAG_TARGET(O_TMPFILE),
+FLAG_TARGET(__O_TMPFILE),
+#endif
 FLAG_END,
 };
 
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 54343c06be..b3aa8099b4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -342,6 +342,9 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
 #if defined(O_PATH)
   { TARGET_O_PATH,  TARGET_O_PATH,  O_PATH,  O_PATH   },
 #endif
+#if defined(O_TMPFILE)
+  { TARGET_O_TMPFILE,   TARGET_O_TMPFILE,   O_TMPFILE,   O_TMPFILE},
+#endif
   /* Don't terminate the list prematurely on 64-bit host+guest.  */
 #if TARGET_O_LARGEFILE != 0 || O_LARGEFILE != 0
   { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, },
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 40c5027e93..6e2287e918 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2416,7 +2416,7 @@ struct target_statfs64 {
 #define TARGET_O_CLOEXEC 01000
 #define TARGET___O_SYNC  00010
 #define TARGET_O_PATH02000
-#elif defined(TARGET_ARM) || defined(TARGET_M68K)
+#elif defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_AARCH64)
 #define TARGET_O_DIRECTORY  04 /* must be a directory */
 #define TARGET_O_NOFOLLOW  010 /* don't follow links */
 #define TARGET_O_DIRECT020 /* direct disk access hint */
@@ -2513,6 +2513,12 @@ struct target_statfs64 {
 #ifndef TARGET_O_PATH
 #define TARGET_O_PATH01000
 #endif
+#ifndef TARGET___O_TMPFILE
+#define TARGET___O_TMPFILE   02000
+#endif
+#ifndef TARGET_O_TMPFILE
+#define TARGET_O_TMPFILE (TARGET___O_TMPFILE | TARGET_O_DIRECTORY)
+#endif
 #ifndef TARGET_O_NDELAY
 #define TARGET_O_NDELAY  TARGET_O_NONBLOCK
 #endif
-- 
2.11.0

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1709170

Title:
  QEMU fails to honor O_TMPFILE

Status in QEMU:
  New

Bug description:
  When making a call like

open("/tmp", O_TMPFILE | O_RDWR);

  under QEMU, we ged -EISDIR.

  Under any kernel 3.11 or later, we are supposed to get an unnamed file
  in /tmp. In case the filesystem for /tmp does not support unnamed
  files, we are supposed to get EOPNOTSUPP.

  [I don't know the QEMU version, since this happened in a system I
  don't have access to]

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1709170/+subscriptions



Re: [Qemu-devel] [Bug 1709170] [NEW] QEMU fails to honor O_TMPFILE

2017-08-08 Thread Riku Voipio
On Mon, Aug 07, 2017 at 08:18:04PM -, Thiago Macieira wrote:
> Public bug reported:
> 
> When making a call like
> 
>   open("/tmp", O_TMPFILE | O_RDWR);
> 
> under QEMU, we ged -EISDIR.
> 
> Under any kernel 3.11 or later, we are supposed to get an unnamed file
> in /tmp. In case the filesystem for /tmp does not support unnamed files,
> we are supposed to get EOPNOTSUPP.

Actually, -EISDIR is valid error when underlying system doesn't support 
O_TMPFILE.
See man openat or the kernel definition for O_TMPFILE.

Regardless, I'm submitting a patch to properly translate the O_TMPFILE.

Riku



[Qemu-devel] [Bug 1709170] Re: QEMU fails to honor O_TMPFILE

2017-08-08 Thread Riku Voipio
Hi Thiago,

What is the version of glibc on the targets you are building to? There
was an O_TMPFILE bug in older glibc's:

https://sourceware.org/bugzilla/show_bug.cgi?id=17912

** Bug watch added: Sourceware.org Bugzilla #17912
   https://sourceware.org/bugzilla/show_bug.cgi?id=17912

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1709170

Title:
  QEMU fails to honor O_TMPFILE

Status in QEMU:
  New

Bug description:
  When making a call like

open("/tmp", O_TMPFILE | O_RDWR);

  under QEMU, we ged -EISDIR.

  Under any kernel 3.11 or later, we are supposed to get an unnamed file
  in /tmp. In case the filesystem for /tmp does not support unnamed
  files, we are supposed to get EOPNOTSUPP.

  [I don't know the QEMU version, since this happened in a system I
  don't have access to]

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1709170/+subscriptions



Re: [Qemu-devel] [PATCH v5 6/6] target-m68k, linux-user: manage FP registers in ucontext

2017-06-29 Thread Riku Voipio
On Wed, Jun 28, 2017 at 10:44:57PM +0200, Laurent Vivier wrote:
> Riku,
> 
> could you ACK this patch, so I will add it in my next pull request for m68k?

Whatabout Richard's comment about using cpu_m68k_set_fpcr ?

Riku
 
> Thanks,
> Laurent
> 
> Le 20/06/2017 à 22:51, Laurent Vivier a écrit :
> > Signed-off-by: Laurent Vivier 
> > ---
> >  linux-user/signal.c | 41 +
> >  1 file changed, 41 insertions(+)
> > 
> > diff --git a/linux-user/signal.c b/linux-user/signal.c
> > index 3d18d1b..d3753e4 100644
> > --- a/linux-user/signal.c
> > +++ b/linux-user/signal.c
> > @@ -5673,6 +5673,24 @@ give_sigsegv:
> >  force_sigsegv(sig);
> >  }
> >  
> > +static inline void target_rt_save_fpu_state(struct target_ucontext *uc,
> > +   CPUM68KState *env)
> > +{
> > +int i;
> > +target_fpregset_t *fpregs = >tuc_mcontext.fpregs;
> > +
> > +__put_user(env->fpcr, >f_fpcntl[0]);
> > +__put_user(env->fpsr, >f_fpcntl[1]);
> > +/* fpiar is not emulated */
> > +
> > +for (i = 0; i < 8; i++) {
> > +uint32_t high = env->fregs[i].d.high << 16;
> > +__put_user(high, >f_fpregs[i * 3]);
> > +__put_user(env->fregs[i].d.low,
> > +   (uint64_t *)>f_fpregs[i * 3 + 1]);
> > +}
> > +}
> > +
> >  static inline int target_rt_setup_ucontext(struct target_ucontext *uc,
> > CPUM68KState *env)
> >  {
> > @@ -5699,9 +5717,30 @@ static inline int target_rt_setup_ucontext(struct 
> > target_ucontext *uc,
> >  __put_user(env->pc, [16]);
> >  __put_user(sr, [17]);
> >  
> > +target_rt_save_fpu_state(uc, env);
> > +
> >  return 0;
> >  }
> >  
> > +static inline void target_rt_restore_fpu_state(CPUM68KState *env,
> > +   struct target_ucontext *uc)
> > +{
> > +int i;
> > +target_fpregset_t *fpregs = >tuc_mcontext.fpregs;
> > +
> > +__get_user(env->fpcr, >f_fpcntl[0]);
> > +__get_user(env->fpsr, >f_fpcntl[1]);
> > +/* fpiar is not emulated */
> > +
> > +for (i = 0; i < 8; i++) {
> > +uint32_t high;
> > +__get_user(high, >f_fpregs[i * 3]);
> > +env->fregs[i].d.high = high >> 16;
> > +__get_user(env->fregs[i].d.low,
> > +   (uint64_t *)>f_fpregs[i * 3 + 1]);
> > +}
> > +}
> > +
> >  static inline int target_rt_restore_ucontext(CPUM68KState *env,
> >   struct target_ucontext *uc)
> >  {
> > @@ -5733,6 +5772,8 @@ static inline int 
> > target_rt_restore_ucontext(CPUM68KState *env,
> >  __get_user(temp, [17]);
> >  cpu_m68k_set_ccr(env, temp);
> >  
> > +target_rt_restore_fpu_state(env, uc);
> > +
> >  return 0;
> >  
> >  badframe:
> > 
> 



[Qemu-devel] [PULL 15/15] linux-user: add strace support for uinfo structure of rt_sigqueueinfo() and rt_tgsigqueueinfo()

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

This commit adds support for printing the content of the target_siginfo_t
structure in a similar way to how it is printed by the host strace. The
pointer to this structure is sent as the last argument of the
rt_sigqueueinfo() and rt_tgsigqueueinfo() system calls.
For this purpose, print_siginfo() is used and the get_target_siginfo()
function is implemented in order to get the information obtained from
the pointer into the form that print_siginfo() expects.

The get_target_siginfo() function is based on
host_to_target_siginfo_noswap() in linux-user mode, but here both
arguments are pointers to target_siginfo_t, so instead of converting
the information to siginfo_t it just extracts and copies it to a
target_siginfo_t structure.

Prior to this commit, typical strace output used to look like this:
8307 rt_sigqueueinfo(8307,50,0x0040007ff6b0) = 0

After this commit, it looks like this:
8307 rt_sigqueueinfo(8307,50,{si_signo=50, si_code=SI_QUEUE, si_pid=8307,
si_uid=1000, si_sigval=17716762128}) = 0

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c | 113 +++-
 1 file changed, 111 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 5fbe067fd5..d821d165ff 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -188,6 +188,93 @@ static void print_si_code(int arg)
 gemu_log("%s", codename);
 }
 
+static void get_target_siginfo(target_siginfo_t *tinfo,
+const target_siginfo_t *info)
+{
+abi_ulong sival_ptr;
+
+int sig;
+int si_errno;
+int si_code;
+int si_type;
+
+__get_user(sig, >si_signo);
+__get_user(si_errno, >si_errno);
+__get_user(si_code, >si_code);
+
+tinfo->si_signo = sig;
+tinfo->si_errno = si_errno;
+tinfo->si_code = si_code;
+
+/* Ensure we don't leak random junk to the guest later */
+memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad));
+
+/* This is awkward, because we have to use a combination of
+ * the si_code and si_signo to figure out which of the union's
+ * members are valid. (Within the host kernel it is always possible
+ * to tell, but the kernel carefully avoids giving userspace the
+ * high 16 bits of si_code, so we don't have the information to
+ * do this the easy way...) We therefore make our best guess,
+ * bearing in mind that a guest can spoof most of the si_codes
+ * via rt_sigqueueinfo() if it likes.
+ *
+ * Once we have made our guess, we record it in the top 16 bits of
+ * the si_code, so that print_siginfo() later can use it.
+ * print_siginfo() will strip these top bits out before printing
+ * the si_code.
+ */
+
+switch (si_code) {
+case SI_USER:
+case SI_TKILL:
+case SI_KERNEL:
+/* Sent via kill(), tkill() or tgkill(), or direct from the kernel.
+ * These are the only unspoofable si_code values.
+ */
+__get_user(tinfo->_sifields._kill._pid, >_sifields._kill._pid);
+__get_user(tinfo->_sifields._kill._uid, >_sifields._kill._uid);
+si_type = QEMU_SI_KILL;
+break;
+default:
+/* Everything else is spoofable. Make best guess based on signal */
+switch (sig) {
+case TARGET_SIGCHLD:
+__get_user(tinfo->_sifields._sigchld._pid,
+   >_sifields._sigchld._pid);
+__get_user(tinfo->_sifields._sigchld._uid,
+   >_sifields._sigchld._uid);
+__get_user(tinfo->_sifields._sigchld._status,
+   >_sifields._sigchld._status);
+__get_user(tinfo->_sifields._sigchld._utime,
+   >_sifields._sigchld._utime);
+__get_user(tinfo->_sifields._sigchld._stime,
+   >_sifields._sigchld._stime);
+si_type = QEMU_SI_CHLD;
+break;
+case TARGET_SIGIO:
+__get_user(tinfo->_sifields._sigpoll._band,
+   >_sifields._sigpoll._band);
+__get_user(tinfo->_sifields._sigpoll._fd,
+   >_sifields._sigpoll._fd);
+si_type = QEMU_SI_POLL;
+break;
+default:
+/* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */
+__get_user(tinfo->_sifields._rt._pid, >_sifields._rt._pid);
+__get_user(tinfo->_sifields._rt._uid, >_sifields._rt._uid);
+/* XXX: potential problem if 64 bit */
+__get_user(sival_ptr, >_sifields._rt._sigval.sival_ptr);
+tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr;
+
+si_type = QEMU_SI_RT;
+break;
+}
+break;
+

[Qemu-devel] [PULL 10/15] linux-user: fix mismatch of lock/unlock_user() invocations in rt_sigqueinfo() syscall

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

Change the unlock_user() argument from arg1 to arg3 to match with
lock_user(), since arg3 contains the pointer to the siginfo_t structure.

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 93bc6f679e..de85bce167 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8868,7 +8868,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 goto efault;
 }
 target_to_host_siginfo(, p);
-unlock_user(p, arg1, 0);
+unlock_user(p, arg3, 0);
 ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, ));
 }
 break;
-- 
2.11.0




[Qemu-devel] [PULL 08/15] linux-user: add tkill(), tgkill() and rt_sigqueueinfo() strace

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

Improve strace support for syscall tkill(), tgkill() and rt_sigqueueinfo()
by implementing print functions that match arguments types of the system
calls and add them to the corresponding starce.list entry.

tkill:
Prior to this commit, typical strace output used to look like this:
4886 tkill(4886,50,0,4832615904,0,-9151031864016699136) = 0
After this commit, it looks like this:
4886 tkill(4886,50) = 0

tgkill:
Prior to this commit, typical strace output used to look like this:
4890 tgkill(4890,4890,50,8,4832630528,4832615904) = 0
After this commit, it looks like this:
4890 tgkill(4890,4890,50) = 0

rt_sigqueueinfo:
Prior to this commit, typical strace output used to look like this:
8307 rt_sigqueueinfo(8307,50,1996483164,0,0,50) = 0
After this commit, it looks like this:
8307 rt_sigqueueinfo(8307,50,0x0040007ff6b0) = 0

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c| 41 +
 linux-user/strace.list |  6 +++---
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 8fb1b6e252..f6f76a5bd4 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1901,6 +1901,20 @@ print_rt_sigprocmask(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_rt_sigqueueinfo
+static void
+print_rt_sigqueueinfo(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_signal(arg1, 0);
+print_pointer(arg2, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_syslog
 static void
 print_syslog_action(abi_ulong arg, int last)
@@ -2415,6 +2429,33 @@ print_kill(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_tkill
+static void
+print_tkill(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_signal(arg1, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
+#ifdef TARGET_NR_tgkill
+static void
+print_tgkill(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_raw_param("%d", arg1, 0);
+print_signal(arg2, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 /*
  * An array of all of the syscalls we know about
  */
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 6e33788a17..373d43689a 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1155,7 +1155,7 @@
 { TARGET_NR_rt_sigprocmask, "rt_sigprocmask" , NULL, print_rt_sigprocmask, 
NULL },
 #endif
 #ifdef TARGET_NR_rt_sigqueueinfo
-{ TARGET_NR_rt_sigqueueinfo, "rt_sigqueueinfo" , NULL, NULL, NULL },
+{ TARGET_NR_rt_sigqueueinfo, "rt_sigqueueinfo" , NULL, print_rt_sigqueueinfo, 
NULL },
 #endif
 #ifdef TARGET_NR_rt_sigreturn
 { TARGET_NR_rt_sigreturn, "rt_sigreturn" , NULL, NULL, NULL },
@@ -1498,7 +1498,7 @@
 { TARGET_NR_tee, "tee" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_tgkill
-{ TARGET_NR_tgkill, "tgkill" , NULL, NULL, NULL },
+{ TARGET_NR_tgkill, "tgkill" , NULL, print_tgkill, NULL },
 #endif
 #ifdef TARGET_NR_time
 { TARGET_NR_time, "time" , NULL, NULL, NULL },
@@ -1534,7 +1534,7 @@
 { TARGET_NR_times, "times" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_tkill
-{ TARGET_NR_tkill, "tkill" , NULL, NULL, NULL },
+{ TARGET_NR_tkill, "tkill" , NULL, print_tkill, NULL },
 #endif
 #ifdef TARGET_NR_truncate
 { TARGET_NR_truncate, "truncate" , NULL, NULL, NULL },
-- 
2.11.0




[Qemu-devel] [PULL 13/15] linux-user: add rt_tgsigqueueinfo() strace

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

This commit improves strace support for syscall rt_tgsigqueueinfo().

Prior to this commit, typical strace output used to look like this:
7775 rt_tgsigqueueinfo(7775,7775,50,1996483164,0,0) = 0

After this commit, it looks like this:
7775 rt_tgsigqueueinfo(7775,7775,50,0x76ffea5c) = 0

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c| 15 +++
 linux-user/strace.list |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index f6f76a5bd4..779cda1a5e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1915,6 +1915,21 @@ print_rt_sigqueueinfo(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_rt_tgsigqueueinfo
+static void
+print_rt_tgsigqueueinfo(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_raw_param("%d", arg0, 0);
+print_raw_param("%d", arg1, 0);
+print_signal(arg2, 0);
+print_pointer(arg3, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_syslog
 static void
 print_syslog_action(abi_ulong arg, int last)
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 373d43689a..a91e33f7e5 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1167,7 +1167,7 @@
 { TARGET_NR_rt_sigtimedwait, "rt_sigtimedwait" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_rt_tgsigqueueinfo
-{ TARGET_NR_rt_tgsigqueueinfo, "rt_tgsigqueueinfo" , NULL, NULL, NULL },
+{ TARGET_NR_rt_tgsigqueueinfo, "rt_tgsigqueueinfo" , NULL, 
print_rt_tgsigqueueinfo, NULL },
 #endif
 #ifdef TARGET_NR_sched_getaffinity
 { TARGET_NR_sched_getaffinity, "sched_getaffinity" , NULL, NULL, NULL },
-- 
2.11.0




[Qemu-devel] [PULL 11/15] linux-user: fix argument type declaration of rt_sigqueinfo() syscall

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

Change the type of the first argument of rt_sigqueinfo() from int to pid_t
in the syscall declaration to match specifications of the system call.

Proper spacing is added to satisfy checkpatch.pl.

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index de85bce167..3373853bb9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -274,7 +274,7 @@ _syscall3(int, sys_getdents64, uint, fd, struct 
linux_dirent64 *, dirp, uint, co
 _syscall5(int, _llseek,  uint,  fd, ulong, hi, ulong, lo,
   loff_t *, res, uint, wh);
 #endif
-_syscall3(int,sys_rt_sigqueueinfo,int,pid,int,sig,siginfo_t *,uinfo)
+_syscall3(int, sys_rt_sigqueueinfo, pid_t, pid, int, sig, siginfo_t *, uinfo)
 _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)
 #ifdef __NR_exit_group
 _syscall1(int,exit_group,int,error_code)
-- 
2.11.0




[Qemu-devel] [PULL 07/15] linux-user: add strace for getuid(), gettid(), getppid(), geteuid()

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

Improve strace support for syscalls getuid(), gettid(), getppid()
and geteuid(). Since these system calls don't have arguments, "%s()"
is added in the corresponding strace.list entry so that no arguments
are printed.

getuid:
Prior to this commit, typical strace output used to look like this:
4894 getuid(4894,0,0,274886293296,-3689348814741910323,4832615904) = 1000
After this commit, it looks like this:
4894 getuid() = 1000

gettid:
Prior to this commit, typical strace output used to look like this:
8307 gettid(0,0,64,0,4832630528,4832615840) = 8307
After this commit, it looks like this:
8307 gettid() = 8307

getppid:
Prior to this commit, typical strace output used to look like this:
20588 getppid(20588,64,0,4832630528,4832615888,0) = 20625
After this commit, it looks like this:
20588 getppid() = 20625

geteuid:
Prior to this commit, typical strace output used to look like this:
20588 geteuid(64,0,0,4832615888,0,-9151031864016699136) = 1000
After this commit, it looks like this:
20588 geteuid() = 1000

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.list | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 3b1282ec1a..6e33788a17 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -290,7 +290,7 @@
 { TARGET_NR_getegid32, "getegid32" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_geteuid
-{ TARGET_NR_geteuid, "geteuid" , NULL, NULL, NULL },
+{ TARGET_NR_geteuid, "geteuid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_geteuid32
 { TARGET_NR_geteuid32, "geteuid32" , NULL, NULL, NULL },
@@ -338,7 +338,7 @@
 { TARGET_NR_getpmsg, "getpmsg" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_getppid
-{ TARGET_NR_getppid, "getppid" , NULL, NULL, NULL },
+{ TARGET_NR_getppid, "getppid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getpriority
 { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
@@ -381,13 +381,13 @@
   NULL, NULL },
 #endif
 #ifdef TARGET_NR_gettid
-{ TARGET_NR_gettid, "gettid" , NULL, NULL, NULL },
+{ TARGET_NR_gettid, "gettid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_gettimeofday
 { TARGET_NR_gettimeofday, "gettimeofday" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_getuid
-{ TARGET_NR_getuid, "getuid" , NULL, NULL, NULL },
+{ TARGET_NR_getuid, "getuid" , "%s()", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getuid32
 { TARGET_NR_getuid32, "getuid32" , NULL, NULL, NULL },
-- 
2.11.0




[Qemu-devel] [PULL 14/15] linux-user: fix inconsistent spaces in print_siginfo() output

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

This patch improves the consistentcy of the output from print_siginfo()
by removing spaces around the equal sign of si_pid, si_uid, si_timer1,
si_timer2, si_band, si_fd, si_addr, si_status and si_sigval. This way
they match si_signo and ci_code. Host strace was used as a reference
for this chage.

Prior to this commit, typical strace output used to look like this:

Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 779cda1a5e..5fbe067fd5 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -206,26 +206,26 @@ static void print_siginfo(const target_siginfo_t *tinfo)
 
 switch (si_type) {
 case QEMU_SI_KILL:
-gemu_log(", si_pid = %u, si_uid = %u",
+gemu_log(", si_pid=%u, si_uid=%u",
  (unsigned int)tinfo->_sifields._kill._pid,
  (unsigned int)tinfo->_sifields._kill._uid);
 break;
 case QEMU_SI_TIMER:
-gemu_log(", si_timer1 = %u, si_timer2 = %u",
+gemu_log(", si_timer1=%u, si_timer2=%u",
  tinfo->_sifields._timer._timer1,
  tinfo->_sifields._timer._timer2);
 break;
 case QEMU_SI_POLL:
-gemu_log(", si_band = %d, si_fd = %d",
+gemu_log(", si_band=%d, si_fd=%d",
  tinfo->_sifields._sigpoll._band,
  tinfo->_sifields._sigpoll._fd);
 break;
 case QEMU_SI_FAULT:
-gemu_log(", si_addr = ");
+gemu_log(", si_addr=");
 print_pointer(tinfo->_sifields._sigfault._addr, 1);
 break;
 case QEMU_SI_CHLD:
-gemu_log(", si_pid = %u, si_uid = %u, si_status = %d"
+gemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
  ", si_utime=" TARGET_ABI_FMT_ld
  ", si_stime=" TARGET_ABI_FMT_ld,
  (unsigned int)(tinfo->_sifields._sigchld._pid),
@@ -235,7 +235,7 @@ static void print_siginfo(const target_siginfo_t *tinfo)
  tinfo->_sifields._sigchld._stime);
 break;
 case QEMU_SI_RT:
-gemu_log(", si_pid = %u, si_uid = %u, si_sigval = " TARGET_ABI_FMT_ld,
+gemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
  (unsigned int)tinfo->_sifields._rt._pid,
  (unsigned int)tinfo->_sifields._rt._uid,
  tinfo->_sifields._rt._sigval.sival_ptr);
-- 
2.11.0




[Qemu-devel] [PULL 06/15] linux-user: remove all traces of qemu from /proc/self/cmdline

2017-05-31 Thread riku . voipio
From: Andreas Schwab <sch...@suse.de>

Instead of post-processing the real contents use the remembered target
argv.  That removes all traces of qemu, including command line options,
and handles QEMU_ARGV0.

Signed-off-by: Andreas Schwab <sch...@suse.de>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 47 +++
 1 file changed, 7 insertions(+), 40 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c8f6efc89c..909dde6de6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7358,52 +7358,19 @@ int host_to_target_waitstatus(int status)
 
 static int open_self_cmdline(void *cpu_env, int fd)
 {
-int fd_orig = -1;
-bool word_skipped = false;
-
-fd_orig = open("/proc/self/cmdline", O_RDONLY);
-if (fd_orig < 0) {
-return fd_orig;
-}
+CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
+struct linux_binprm *bprm = ((TaskState *)cpu->opaque)->bprm;
+int i;
 
-while (true) {
-ssize_t nb_read;
-char buf[128];
-char *cp_buf = buf;
+for (i = 0; i < bprm->argc; i++) {
+size_t len = strlen(bprm->argv[i]) + 1;
 
-nb_read = read(fd_orig, buf, sizeof(buf));
-if (nb_read < 0) {
-int e = errno;
-fd_orig = close(fd_orig);
-errno = e;
+if (write(fd, bprm->argv[i], len) != len) {
 return -1;
-} else if (nb_read == 0) {
-break;
-}
-
-if (!word_skipped) {
-/* Skip the first string, which is the path to qemu-*-static
-   instead of the actual command. */
-cp_buf = memchr(buf, 0, nb_read);
-if (cp_buf) {
-/* Null byte found, skip one string */
-cp_buf++;
-nb_read -= cp_buf - buf;
-word_skipped = true;
-}
-}
-
-if (word_skipped) {
-if (write(fd, cp_buf, nb_read) != nb_read) {
-int e = errno;
-close(fd_orig);
-errno = e;
-return -1;
-}
 }
 }
 
-return close(fd_orig);
+return 0;
 }
 
 static int open_self_maps(void *cpu_env, int fd)
-- 
2.11.0




[Qemu-devel] [PULL 12/15] linux-user: add support for rt_tgsigqueueinfo() system call

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

Add a new system call: rt_tgsigqueueinfo().

This system call is similar to rt_sigqueueinfo(), but instead of
sending the signal and data to the whole thread group with the ID
equal to the argument tgid, it sends it to a single thread within
that thread group. The ID of the thread is specified by the tid
argument.

The implementation is based on the rt_sigqueueinfo() in linux-user
mode, where the tid is added as the second argument and the
previous second and third argument become arguments three and four,
respectively.

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>

Conflicts:
linux-user/syscall.c
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3373853bb9..925ae11ea6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -238,6 +238,7 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 
arg4,type5 arg5,   \
 #define __NR_sys_getdents64 __NR_getdents64
 #define __NR_sys_getpriority __NR_getpriority
 #define __NR_sys_rt_sigqueueinfo __NR_rt_sigqueueinfo
+#define __NR_sys_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
 #define __NR_sys_syslog __NR_syslog
 #define __NR_sys_futex __NR_futex
 #define __NR_sys_inotify_init __NR_inotify_init
@@ -275,6 +276,8 @@ _syscall5(int, _llseek,  uint,  fd, ulong, hi, ulong, lo,
   loff_t *, res, uint, wh);
 #endif
 _syscall3(int, sys_rt_sigqueueinfo, pid_t, pid, int, sig, siginfo_t *, uinfo)
+_syscall4(int, sys_rt_tgsigqueueinfo, pid_t, pid, pid_t, tid, int, sig,
+  siginfo_t *, uinfo)
 _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)
 #ifdef __NR_exit_group
 _syscall1(int,exit_group,int,error_code)
@@ -8872,6 +8875,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = get_errno(sys_rt_sigqueueinfo(arg1, arg2, ));
 }
 break;
+case TARGET_NR_rt_tgsigqueueinfo:
+{
+siginfo_t uinfo;
+
+p = lock_user(VERIFY_READ, arg4, sizeof(target_siginfo_t), 1);
+if (!p) {
+goto efault;
+}
+target_to_host_siginfo(, p);
+unlock_user(p, arg4, 0);
+ret = get_errno(sys_rt_tgsigqueueinfo(arg1, arg2, arg3, ));
+}
+break;
 #ifdef TARGET_NR_sigreturn
 case TARGET_NR_sigreturn:
 if (block_signals()) {
-- 
2.11.0




[Qemu-devel] [PULL 09/15] linux-user: fix ssetmask() system call

2017-05-31 Thread riku . voipio
From: Miloš Stojanović <milos.stojano...@rt-rk.com>

Fix the ssetmask() system call by removing the invocation of sigorset().

The ssetmask() system call should replace the old signal mask
with the new and return the old mask. It shouldn't combine
the old and the new mask with sigorset(). Fetching the old
mask for sigorset() is also no longer needed.

The problem was detected after running LTP test group syscalls
for the MIPS EL 32 R2 architecture where the test ssetmask01 failed
with exit code 1. The test passes now that the ssetmask() system call
is fixed.

Signed-off-by: Miloš Stojanović <milos.stojano...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 909dde6de6..93bc6f679e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8621,17 +8621,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #ifdef TARGET_NR_ssetmask /* not on alpha */
 case TARGET_NR_ssetmask:
 {
-sigset_t set, oset, cur_set;
+sigset_t set, oset;
 abi_ulong target_set = arg1;
-/* We only have one word of the new mask so we must read
- * the rest of it with do_sigprocmask() and OR in this word.
- * We are guaranteed that a do_sigprocmask() that only queries
- * the signal mask will not fail.
- */
-ret = do_sigprocmask(0, NULL, _set);
-assert(!ret);
 target_to_host_old_sigset(, _set);
-sigorset(, , _set);
 ret = do_sigprocmask(SIG_SETMASK, , );
 if (!ret) {
 host_to_target_old_sigset(_set, );
-- 
2.11.0




[Qemu-devel] [PULL 03/15] linux-user: fix fadvise64_64() on ppc

2017-05-31 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

On ppc, advice is arg2, not arg6:

long ppc_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
  u32 len_high, u32 len_low)

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2da8426aaa..671b13a23b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11261,6 +11261,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 
 #ifdef TARGET_NR_fadvise64_64
 case TARGET_NR_fadvise64_64:
+#if defined(TARGET_PPC)
+/* 6 args: fd, advice, offset (high, low), len (high, low) */
+ret = arg2;
+arg2 = arg3;
+arg3 = arg4;
+arg4 = arg5;
+arg5 = arg6;
+arg6 = ret;
+#else
 /* 6 args: fd, offset (high, low), len (high, low), advice */
 if (regpairs_aligned(cpu_env)) {
 /* offset is in (3,4), len in (5,6) and advice in 7 */
@@ -11270,6 +11279,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 arg5 = arg6;
 arg6 = arg7;
 }
+#endif
 ret = -host_to_target_errno(posix_fadvise(arg1,
   target_offset64(arg2, arg3),
   target_offset64(arg4, arg5),
-- 
2.11.0




[Qemu-devel] [PULL 04/15] linux-user: fix inotify

2017-05-31 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

When a fd is opened using inotify_init(), a read provides
one or more inotify_event structures:

struct inotify_event {
int  wd;
uint32_t mask;
uint32_t cookie;
uint32_t len;
char name[];
};

The integer fields must be byte-swapped to the target endianness.

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 671b13a23b..32aba195c5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7693,6 +7693,33 @@ static TargetFdTrans target_eventfd_trans = {
 .target_to_host_data = swap_data_eventfd,
 };
 
+#if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
+(defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
+ defined(__NR_inotify_init1))
+static abi_long host_to_target_data_inotify(void *buf, size_t len)
+{
+struct inotify_event *ev;
+int i;
+uint32_t name_len;
+
+for (i = 0; i < len; i += sizeof(struct inotify_event) + name_len) {
+ev = (struct inotify_event *)((char *)buf + i);
+name_len = ev->len;
+
+ev->wd = tswap32(ev->wd);
+ev->mask = tswap32(ev->mask);
+ev->cookie = tswap32(ev->cookie);
+ev->len = tswap32(name_len);
+}
+
+return len;
+}
+
+static TargetFdTrans target_inotify_trans = {
+.host_to_target_data = host_to_target_data_inotify,
+};
+#endif
+
 /* do_syscall() should always have a single exit point at the end so
that actions, such as logging of syscall results, can be performed.
All errnos that do_syscall() returns must be -TARGET_. */
@@ -11736,6 +11763,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
 case TARGET_NR_inotify_init:
 ret = get_errno(sys_inotify_init());
+fd_trans_register(ret, _inotify_trans);
 break;
 #endif
 #ifdef CONFIG_INOTIFY1
@@ -11743,6 +11771,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 case TARGET_NR_inotify_init1:
 ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1,
   fcntl_flags_tbl)));
+fd_trans_register(ret, _inotify_trans);
 break;
 #endif
 #endif
-- 
2.11.0




[Qemu-devel] [PULL 00/15] Misc linux-user updates

2017-05-31 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

The following changes since commit 9964e96dccf7f7c936ee854a795415d19b60:

  Merge remote-tracking branch 'jasowang/tags/net-pull-request' into staging 
(2017-05-23 15:01:31 +0100)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20170531

for you to fetch changes up to ba9fcea1cb6d80536f780760d870416fe5b85863:

  linux-user: add strace support for uinfo structure of rt_sigqueueinfo() and 
rt_tgsigqueueinfo() (2017-05-29 14:56:09 +0300)


Misc linux-user updates



Andreas Schwab (1):
  linux-user: remove all traces of qemu from /proc/self/cmdline

Laurent Vivier (4):
  linux-user: call fd_trans_target_to_host_data() for write()
  linux-user: fix eventfd
  linux-user: fix fadvise64_64() on ppc
  linux-user: fix inotify

Miloš Stojanović (9):
  linux-user: add strace for getuid(), gettid(), getppid(), geteuid()
  linux-user: add tkill(), tgkill() and rt_sigqueueinfo() strace
  linux-user: fix ssetmask() system call
  linux-user: fix mismatch of lock/unlock_user() invocations in
rt_sigqueinfo() syscall
  linux-user: fix argument type declaration of rt_sigqueinfo() syscall
  linux-user: add support for rt_tgsigqueueinfo() system call
  linux-user: add rt_tgsigqueueinfo() strace
  linux-user: fix inconsistent spaces in print_siginfo() output
  linux-user: add strace support for uinfo structure of
rt_sigqueueinfo() and rt_tgsigqueueinfo()

Prasad J Pandit (1):
  linux-user: allocate heap memory for execve arguments

 linux-user/strace.c| 177 +++--
 linux-user/strace.list |  16 ++---
 linux-user/syscall.c   | 161 
 3 files changed, 284 insertions(+), 70 deletions(-)

-- 
2.11.0




[Qemu-devel] [PULL 05/15] linux-user: allocate heap memory for execve arguments

2017-05-31 Thread riku . voipio
From: Prasad J Pandit <p...@fedoraproject.org>

Arguments passed to execve(2) call from user program could
be large, allocating stack memory for them via alloca(3) call
would lead to bad behaviour. Use 'g_new0' to allocate memory
for such arguments.

Reported-by: Jann Horn <ja...@google.com>
Signed-off-by: Prasad J Pandit <p...@fedoraproject.org>
Reviewed-by: Eric Blake <ebl...@redhat.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 32aba195c5..c8f6efc89c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7985,8 +7985,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 envc++;
 }
 
-argp = alloca((argc + 1) * sizeof(void *));
-envp = alloca((envc + 1) * sizeof(void *));
+argp = g_new0(char *, argc + 1);
+envp = g_new0(char *, envc + 1);
 
 for (gp = guest_argp, q = argp; gp;
   gp += sizeof(abi_ulong), q++) {
@@ -8047,6 +8047,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 break;
 unlock_user(*q, addr, 0);
 }
+
+g_free(argp);
+g_free(envp);
 }
 break;
 case TARGET_NR_chdir:
-- 
2.11.0




[Qemu-devel] [PULL 02/15] linux-user: fix eventfd

2017-05-31 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

When a fd is opened using eventfd(), a read provides
a 64bit counter in the host byte order, and a
write increase the internal counter by the provided
64bit value.

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 26 --
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b2b563e388..2da8426aaa 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7671,6 +7671,28 @@ static target_timer_t get_timer_id(abi_long arg)
 return timerid;
 }
 
+static abi_long swap_data_eventfd(void *buf, size_t len)
+{
+uint64_t *counter = buf;
+int i;
+
+if (len < sizeof(uint64_t)) {
+return -EINVAL;
+}
+
+for (i = 0; i < len; i += sizeof(uint64_t)) {
+*counter = tswap64(*counter);
+counter++;
+}
+
+return len;
+}
+
+static TargetFdTrans target_eventfd_trans = {
+.host_to_target_data = swap_data_eventfd,
+.target_to_host_data = swap_data_eventfd,
+};
+
 /* do_syscall() should always have a single exit point at the end so
that actions, such as logging of syscall results, can be performed.
All errnos that do_syscall() returns must be -TARGET_. */
@@ -11876,7 +11898,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #if defined(TARGET_NR_eventfd)
 case TARGET_NR_eventfd:
 ret = get_errno(eventfd(arg1, 0));
-fd_trans_unregister(ret);
+fd_trans_register(ret, _eventfd_trans);
 break;
 #endif
 #if defined(TARGET_NR_eventfd2)
@@ -11890,7 +11912,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 host_flags |= O_CLOEXEC;
 }
 ret = get_errno(eventfd(arg1, host_flags));
-fd_trans_unregister(ret);
+fd_trans_register(ret, _eventfd_trans);
 break;
 }
 #endif
-- 
2.11.0




[Qemu-devel] [PULL 01/15] linux-user: call fd_trans_target_to_host_data() for write()

2017-05-31 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

As for sendmsg() or sendto(), we must call the target to
host data translator if it is defined. This is needed for
eventfd(): the write() syscall allows to add a value to
the internal counter, and so, it must be byte-swapped to
the host order.

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index cec8428589..b2b563e388 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7767,7 +7767,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 case TARGET_NR_write:
 if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
 goto efault;
-ret = get_errno(safe_write(arg1, p, arg3));
+if (fd_trans_target_to_host_data(arg1)) {
+void *copy = g_malloc(arg3);
+memcpy(copy, p, arg3);
+ret = fd_trans_target_to_host_data(arg1)(copy, arg3);
+if (ret >= 0) {
+ret = get_errno(safe_write(arg1, copy, ret));
+}
+g_free(copy);
+} else {
+ret = get_errno(safe_write(arg1, p, arg3));
+}
 unlock_user(p, arg2, 0);
 break;
 #ifdef TARGET_NR_open
-- 
2.11.0




Re: [Qemu-devel] [PATCH] linux-user: remove all traces of qemu from /proc/self/cmdline

2017-05-19 Thread Riku Voipio
On Mon, Mar 20, 2017 at 12:31:55PM +0100, Andreas Schwab wrote:
> Instead of post-processing the real contents use the remembered target
> argv.  That removes all traces of qemu, including command line options,
> and handles QEMU_ARGV0.

Applied to Linux-user, thanks

Riku
 
> Signed-off-by: Andreas Schwab 
> ---
>  linux-user/syscall.c | 47 +++
>  1 file changed, 7 insertions(+), 40 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index cec8428589..ec1fd20386 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -7358,52 +7358,19 @@ int host_to_target_waitstatus(int status)
>  
>  static int open_self_cmdline(void *cpu_env, int fd)
>  {
> -int fd_orig = -1;
> -bool word_skipped = false;
> -
> -fd_orig = open("/proc/self/cmdline", O_RDONLY);
> -if (fd_orig < 0) {
> -return fd_orig;
> -}
> +CPUState *cpu = ENV_GET_CPU((CPUArchState *)cpu_env);
> +struct linux_binprm *bprm = ((TaskState *)cpu->opaque)->bprm;
> +int i;
>  
> -while (true) {
> -ssize_t nb_read;
> -char buf[128];
> -char *cp_buf = buf;
> +for (i = 0; i < bprm->argc; i++) {
> +size_t len = strlen(bprm->argv[i]) + 1;
>  
> -nb_read = read(fd_orig, buf, sizeof(buf));
> -if (nb_read < 0) {
> -int e = errno;
> -fd_orig = close(fd_orig);
> -errno = e;
> +if (write(fd, bprm->argv[i], len) != len) {
>  return -1;
> -} else if (nb_read == 0) {
> -break;
> -}
> -
> -if (!word_skipped) {
> -/* Skip the first string, which is the path to qemu-*-static
> -   instead of the actual command. */
> -cp_buf = memchr(buf, 0, nb_read);
> -if (cp_buf) {
> -/* Null byte found, skip one string */
> -cp_buf++;
> -nb_read -= cp_buf - buf;
> -word_skipped = true;
> -}
> -}
> -
> -if (word_skipped) {
> -if (write(fd, cp_buf, nb_read) != nb_read) {
> -int e = errno;
> -close(fd_orig);
> -errno = e;
> -return -1;
> -}
>  }
>  }
>  
> -return close(fd_orig);
> +return 0;
>  }
>  
>  static int open_self_maps(void *cpu_env, int fd)
> -- 
> 2.12.0
> 
> 
> -- 
> Andreas Schwab, SUSE Labs, sch...@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."



Re: [Qemu-devel] [PATCH] linux-user: Fix TARGET_MAP* and TARGET_F_??LCK for hppa arch

2017-05-19 Thread Riku Voipio
On Sun, Mar 12, 2017 at 08:17:46AM +1000, Richard Henderson wrote:
> On 03/12/2017 03:50 AM, Helge Deller wrote:
> >TARGET_MAP_TYPE needs to be 0x03 instead of 0x0f on the hppa
> >architecture, otherwise it conflicts with MAP_FIXED which is 0x04.
> >
> >Add missing TARGET_MAP_STACK and TARGET_MAP_HUGETLB values.
> >
> >Fix TARGET_F_RDLCK, TARGET_F_WRLCK and TARGET_F_UNLCK.
> >
> >Signed-off-by: Helge Deller 
> 
> I applied the MAP_FIXED and TARGET_F_* parts separately in my tree.  I'd
> like to see what others think about the other MAP_* defines before including
> that.

What's the current state of these patches? Are these patches still waiting for
opinions?

Riku



Re: [Qemu-devel] [PATCH 0/2] linux-user: fix eventfd()

2017-05-19 Thread Riku Voipio
On Tue, Apr 25, 2017 at 06:32:30PM +0200, Laurent Vivier wrote:
> Ping?

Applied, thanks. 

> Laurent
> 
> Le 01/03/2017 à 10:37, Laurent Vivier a écrit :
> > This patch series byte-swap the uint64_t data stream
> > of a file-descriptor opened with eventfd().
> > 
> > It allows to pass more LTP test cases:
> > 
> > eventfd011  TPASS  :  counter value matches required
> > eventfd012  TPASS  :  read failed with EAGAIN as expected
> > eventfd013  TPASS  :  counter value matches required
> > eventfd014  TPASS  :  write failed with EAGAIN as expected
> > eventfd015  TPASS  :  read failed with EINVAL as expected
> > eventfd016  TPASS  :  write failed with EINVAL as expected
> > eventfd017  TPASS  :  write failed with EINVAL as expected
> > eventfd018  TPASS  :  fd is set in readfds
> > eventfd019  TPASS  :  fd is not set in readfds
> > eventfd01   10  TPASS  :  fd is set in writefds
> > eventfd01   11  TPASS  :  fd is not set in writefds
> > eventfd011  TPASS  :  counter value matches required
> > eventfd012  TPASS  :  read failed with EAGAIN as expected
> > eventfd013  TPASS  :  counter value matches required
> > eventfd014  TPASS  :  write failed with EAGAIN as expected
> > eventfd015  TPASS  :  read failed with EINVAL as expected
> > eventfd016  TPASS  :  write failed with EINVAL as expected
> > eventfd017  TPASS  :  write failed with EINVAL as expected
> > eventfd018  TPASS  :  fd is set in readfds
> > eventfd019  TPASS  :  fd is not set in readfds
> > eventfd01   10  TPASS  :  fd is set in writefds
> > eventfd01   11  TPASS  :  fd is not set in writefds
> > eventfd01   12  TPASS  :  counter value write from child successful
> > eventfd01   13  TCONF  :  eventfd01.c:642: eventfd support is not available 
> > in AIO subsystem
> > eventfd01   14  TCONF  :  eventfd01.c:647: eventfd support is not available 
> > in AIO subsystem
> > eventfd01   15  TCONF  :  eventfd01.c:652: eventfd support is not available 
> > in AIO subsystem
> > 
> > Laurent Vivier (2):
> >   linux-user: call fd_trans_target_to_host_data() for write()
> >   linux-user: fix eventfd
> > 
> >  linux-user/syscall.c | 38 +++---
> >  1 file changed, 35 insertions(+), 3 deletions(-)
> > 
> 



Re: [Qemu-devel] [PATCH] maintainers: Add myself as linux-user reviewer

2017-05-11 Thread Riku Voipio
On Wed, May 10, 2017 at 05:39:50PM +0200, Laurent Vivier wrote:
> I volunteer to review linux-user patches.
> Adding myself will help to not miss some of them.
> 
> Signed-off-by: Laurent Vivier <laur...@vivier.eu>

Acked-by: Riku Voipio <riku.voi...@linaro.org>

> ---
>  MAINTAINERS | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 8224be0..c9eed8a 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1577,6 +1577,7 @@ F: default-configs/*-bsd-user.mak
>  
>  Linux user
>  M: Riku Voipio <riku.voi...@iki.fi>
> +R: Laurent Vivier <laur...@vivier.eu>
>  S: Maintained
>  F: linux-user/
>  F: default-configs/*-linux-user.mak
> -- 
> 2.9.3
> 



Re: [Qemu-devel] [PATCH v2 7/7] linux-user: Fix mq_open

2017-01-05 Thread Riku Voipio
On Thu, Nov 24, 2016 at 05:08:58PM +0100, Lena Djokic wrote:
> If fourth argument is NULL it should be passed without
> using lock_user function which would, in that case, return
> EFAULT, and system call supports passing NULL as fourth argument.

Thanks, applied to linux-user
 
> Signed-off-by: Lena Djokic 
> ---
>  linux-user/syscall.c | 11 ---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 3faf4f0..dad03e9 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11694,17 +11694,22 @@ abi_long do_syscall(void *cpu_env, int num, 
> abi_long arg1,
>  case TARGET_NR_mq_open:
>  {
>  struct mq_attr posix_mq_attr;
> +struct mq_attr *pposix_mq_attr;
>  int host_flags;
>  
>  host_flags = target_to_host_bitmask(arg2, fcntl_flags_tbl);
> -if (copy_from_user_mq_attr(_mq_attr, arg4) != 0) {
> -goto efault;
> +pposix_mq_attr = NULL;
> +if (arg4) {
> +if (copy_from_user_mq_attr(_mq_attr, arg4) != 0) {
> +goto efault;
> +}
> +pposix_mq_attr = _mq_attr;
>  }
>  p = lock_user_string(arg1 - 1);
>  if (!p) {
>  goto efault;
>  }
> -ret = get_errno(mq_open(p, host_flags, arg3, _mq_attr));
> +ret = get_errno(mq_open(p, host_flags, arg3, pposix_mq_attr));
>  unlock_user (p, arg1, 0);
>  }
>  break;
> -- 
> 2.7.4
> 



Re: [Qemu-devel] [PATCH v2 5/7] linux-user: Fix readahead

2017-01-05 Thread Riku Voipio
On Thu, Nov 24, 2016 at 05:08:56PM +0100, Lena Djokic wrote:
> Calculation of 64-bit offset was not correct for all cases.

Thanks, applied to linux-user
 
> Signed-off-by: Lena Djokic 
> ---
>  linux-user/syscall.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 1b59a71..61c4126 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11296,7 +11296,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  arg3 = arg4;
>  arg4 = arg5;
>  }
> -ret = get_errno(readahead(arg1, ((off64_t)arg3 << 32) | arg2, arg4));
> +ret = get_errno(readahead(arg1, target_offset64(arg2, arg3) , arg4));
>  #else
>  ret = get_errno(readahead(arg1, arg2, arg3));
>  #endif
> -- 
> 2.7.4
> 



Re: [Qemu-devel] [PATCH v2 2/7] linux-user: Fix inotify_init1 support

2017-01-05 Thread Riku Voipio
On Thu, Nov 24, 2016 at 05:08:53PM +0100, Lena Djokic wrote:
> This commit adds necessary conversion of argument passed to inotify_init1.
> inotify_init1 flags can be IN_NONBLOCK and IN_CLOEXEC which rely on O_NONBLOCK
> and O_CLOEXEC and those can have different values on different platforms.

Thanks, applied to linux-user
 
> Signed-off-by: Lena Djokic 
> ---
>  linux-user/syscall.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index f5d9a26..41873ca 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -11625,7 +11625,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  #ifdef CONFIG_INOTIFY1
>  #if defined(TARGET_NR_inotify_init1) && defined(__NR_inotify_init1)
>  case TARGET_NR_inotify_init1:
> -ret = get_errno(sys_inotify_init1(arg1));
> +ret = get_errno(sys_inotify_init1(target_to_host_bitmask(arg1,
> +  fcntl_flags_tbl)));
>  break;
>  #endif
>  #endif
> -- 
> 2.7.4
> 



Re: [Qemu-devel] [PATCH v2] linux-user: Fix s390x safe-syscall for z900

2017-01-05 Thread Riku Voipio
On Wed, Oct 26, 2016 at 12:08:52PM -0700, Richard Henderson wrote:
> The LT instruction was added in the extended immediate facility
> introduced with the z9-109 processor.

Sorry I missed this during 2.8. This is stable-2.8 material once it
opens. Applied to linux-user now, thanks.
 
> Cc: Riku Voipio <riku.voi...@iki.fi>
> Reported-by: Michael Tokarev <m...@tls.msk.ru>
> Fixes: c9bc3437a905b660561a26cd4ecc64579843267b
> Suggested-by: Aurelien Jarno <aurel...@aurel32.net>
> Signed-off-by: Richard Henderson <r...@twiddle.net>
> ---
>  linux-user/host/s390x/safe-syscall.inc.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/host/s390x/safe-syscall.inc.S 
> b/linux-user/host/s390x/safe-syscall.inc.S
> index f1b446a..414b44a 100644
> --- a/linux-user/host/s390x/safe-syscall.inc.S
> +++ b/linux-user/host/s390x/safe-syscall.inc.S
> @@ -72,7 +72,7 @@ safe_syscall_base:
>*/
>  safe_syscall_start:
>   /* if signal_pending is non-zero, don't do the call */
> - lt  %r0,0(%r8)
> + icm %r0,15,0(%r8)
>   jne 2f
>   svc 0
>  safe_syscall_end:
> -- 
> 2.7.4
> 



[Qemu-devel] [Bug 902413] Re: qemu-i386-user on ARM host: wine hangs/spins when trying to run anything

2016-11-22 Thread Riku Voipio
You might want to retry wine with qemu-i386-static again now with qemu
2.7, which has a major thread/signal rework done.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/902413

Title:
  qemu-i386-user on ARM host: wine hangs/spins when trying to run
  anything

Status in QEMU:
  New
Status in wine package in Gentoo Linux:
  New

Bug description:
  With qemu built from git from 217bfb445b54db618a30f3a39170bebd9fd9dbf2
  and configured with './configure --target-list=i386-linux-user
  --static --interp-prefix=/home/pgriffais/natty-i386/', trying to run
  wine 1.3.15 from an Ubuntu 11.04 chroot results in hangs. If I run an
  i386 emulated wineserver, wineserver hangs in:

  0x600c7f8c in read () at ../sysdeps/unix/syscall-template.S:82
  82../sysdeps/unix/syscall-template.S: No such file or directory.
in ../sysdeps/unix/syscall-template.S
  (gdb) bt
  #0  0x600c7f8c in read () at ../sysdeps/unix/syscall-template.S:82
  #1  0x6004a316 in read (cpu_env=0x622c3ee8, num=3, arg1=6, arg2=1121255519, 
  arg3=1, arg4=134875664, arg5=1, arg6=1121255528, arg7=0, arg8=0)
  at /usr/include/bits/unistd.h:45
  #2  do_syscall (cpu_env=0x622c3ee8, num=3, arg1=6, arg2=1121255519, arg3=1, 
  arg4=134875664, arg5=1, arg6=1121255528, arg7=0, arg8=0)
  at /home/ubuntu/src/qemu/linux-user/syscall.c:4691
  #3  0x600262f0 in cpu_loop (env=0x622c3ee8)
  at /home/ubuntu/src/qemu/linux-user/main.c:321
  #4  0x60026bbc in main (argc=, 
  argv=, envp=)
  at /home/ubuntu/src/qemu/linux-user/main.c:3817

  While wine hangs in:

  0x600c84ac in recvmsg () at ../sysdeps/unix/syscall-template.S:82
  82../sysdeps/unix/syscall-template.S: No such file or directory.
in ../sysdeps/unix/syscall-template.S
  (gdb) bt
  #0  0x600c84ac in recvmsg () at ../sysdeps/unix/syscall-template.S:82
  #1  0x60041c4e in do_sendrecvmsg (fd=4, target_msg=, 
  flags=1073741824, send=0)
  at /home/ubuntu/src/qemu/linux-user/syscall.c:1834
  #2  0x600497ec in do_socketcall (cpu_env=, num=102, 
  arg1=17, arg2=1122504544, arg3=2076831732, arg4=1122504568, 
  arg5=2076942688, arg6=1122504888, arg7=0, arg8=0)
  at /home/ubuntu/src/qemu/linux-user/syscall.c:2235
  #3  do_syscall (cpu_env=, num=102, arg1=17, 
  arg2=1122504544, arg3=2076831732, arg4=1122504568, arg5=2076942688, 
  arg6=1122504888, arg7=0, arg8=0)
  at /home/ubuntu/src/qemu/linux-user/syscall.c:6085
  #4  0x600262f0 in cpu_loop (env=0x622c3f08)
  at /home/ubuntu/src/qemu/linux-user/main.c:321
  #5  0x60026bbc in main (argc=, 
  argv=, envp=)
  at /home/ubuntu/src/qemu/linux-user/main.c:3817

  However if I build wineserver 1.3.15 natively for ARM and run it on
  the host while wine is emulated, I get the following:

  root@tiberiusstation:/home/ubuntu# ./natty-i386/usr/bin/wine notepad
  Unsupported ancillary data: 1/2
  Unsupported ancillary data: 1/2
  Unsupported ancillary data: 1/2
  err:process:__wine_kernel_init boot event wait timed out

  I assume the last one is due to wineboot.exe hanging. The main wine
  process hangs in there:

  cg_temp_new_internal_i32 (temp_local=)
  at /home/ubuntu/src/qemu/tcg/tcg.c:483
  483   }
  (gdb) bt
  #0  tcg_temp_new_internal_i32 (temp_local=)
  at /home/ubuntu/src/qemu/tcg/tcg.c:483
  #1  0x60052ac6 in tcg_temp_new_i32 (val=6)
  at /home/ubuntu/src/qemu/tcg/tcg.h:442
  #2  tcg_const_i32 (val=6) at /home/ubuntu/src/qemu/tcg/tcg.c:530
  #3  0x6005ef0c in tcg_gen_shri_i32 (ot=2, op1=2, op2=7, is_right=1, 
  is_arith=0, s=)
  at /home/ubuntu/src/qemu/tcg/tcg-op.h:605
  #4  gen_shift_rm_im (ot=2, op1=2, op2=7, is_right=1, is_arith=0, 
  s=)
  at /home/ubuntu/src/qemu/target-i386/translate.c:1514
  #5  0x6006df90 in gen_shifti (s=0xbefea970, pc_start=)
  at /home/ubuntu/src/qemu/target-i386/translate.c:1946
  #6  disas_insn (s=0xbefea970, pc_start=)
  at /home/ubuntu/src/qemu/target-i386/translate.c:5397
  #7  0x60091758 in gen_intermediate_code_internal (env=0x625656f8, 
  tb=0x402cdf48) at /home/ubuntu/src/qemu/target-i386/translate.c:7825
  #8  gen_intermediate_code_pc (env=0x625656f8, tb=0x402cdf48)
  at /home/ubuntu/src/qemu/target-i386/translate.c:7896
  #9  0x60054bf2 in cpu_restore_state (tb=0x402cdf48, env=0x62565690, 
  searched_pc=1617393812) at /home/ubuntu/src/qemu/translate-all.c:126
  #10 0x60091d9e in handle_cpu_signal (host_signum=, 
  pinfo=, puc=0xbefeab70)
  at /home/ubuntu/src/qemu/user-exec.c:117
  #11 cpu_x86_signal_handler (host_signum=, 
  pinfo=, puc=0xbefeab70)
  at /home/ubuntu/src/qemu/user-exec.c:458
  #12 0x6003c764 in host_signal_handler (host_signum=11, info=0xbefeaaf0, 
  puc=)
  at /home/ubuntu/src/qemu/linux-user/signal.c:492
  #13 
  #14 0x60677894 in static_code_gen_buffer ()
  #15 0x6000a260 in cpu_x86_exec (env=0x0)
  at /home/ubuntu/src/qemu/cpu-exec.c:566
  #16 

Re: [Qemu-devel] [PATCH v7 05/10] linux-user: Add support for ustat() syscall

2016-10-21 Thread Riku Voipio
On Thu, Sep 22, 2016 at 06:56:54PM +0200, Aleksandar Markovic wrote:
> From: Aleksandar Markovic 
> 
> This patch implements Qemu user mode ustat() syscall support.
> 
> Syscall ustat() returns information about a mounted filesystem.
> 
> Its declaration is:
> 
> int ustat(dev_t dev, struct ustat *ubuf);
> 
> Its Linux kernel implementation is at fs/compat.c, line 334.
> 
> The Qemu implementation proposed in this patch is similar to the
> Qemu implementations of statfs(), fstatfs() and other related syscalls.
> It is based on invocation of host's ustat(), and its key part is in the
> correspondent case segment of the main switch statement of the function
> do_syscall(), in file linux-user/syscalls.c. All necessary conversions
> of data structures from target to host and from host to target are
> covered. Support for target_ustat is included. Sufficient support for
> "-strace" option for this syscall is already present, and this patch
> does not change it.
> 
> This patch also fixes failures of LTP tests ustat01, and ustat02, if
> executed on Qemu-emulated systems.

Had to drop this patch from my series. Not all platforms implement
ustat anymore. As Peter suggested, it is probably better implement ustat
with calling statvfs or statfs.
 
> Signed-off-by: Aleksandar Markovic 
> ---
>  linux-user/syscall.c  | 23 +--
>  linux-user/syscall_defs.h |  6 ++
>  2 files changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 563796a..d28f3e6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -8226,9 +8227,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
> arg1,
>  ret = get_errno(chroot(p));
>  unlock_user(p, arg1, 0);
>  break;
> -#ifdef TARGET_NR_ustat
> +#if defined(TARGET_NR_ustat)
>  case TARGET_NR_ustat:
> -goto unimplemented;
> +{
> +struct ustat ust;
> +
> +ret = get_errno(ustat(arg1, ));
> +if (!is_error(ret)) {
> +struct target_ustat *target_ust;
> +
> +if (!lock_user_struct(VERIFY_WRITE, target_ust, arg2, 0)) {
> +goto efault;
> +}
> +__put_user(ust.f_tfree, _ust->f_tfree);
> +__put_user(ust.f_tinode, _ust->f_tinode);
> +memcpy(target_ust->f_fname, ust.f_fname, 6);
> +memcpy(target_ust->f_fpack, ust.f_fpack, 6);
> +unlock_user_struct(target_ust, arg2, 1);
> +}
> +}
> +break;
> +
>  #endif
>  #ifdef TARGET_NR_dup2
>  case TARGET_NR_dup2:
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index e47a61a..2c183d1 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -2164,6 +2164,12 @@ struct target_statfs64 {
>  };
>  #endif
>  
> +struct target_ustat {
> +abi_ulong f_tfree;
> +abi_int f_tinode;
> +char f_fname[6];
> +char f_fpack[6];
> +};
>  
>  #define TARGET_F_DUPFD 0   /* dup */
>  #define TARGET_F_GETFD 1   /* get close_on_exec */
> -- 
> 2.9.3
> 



[Qemu-devel] [PULL v3] linux-user changes

2016-10-21 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

The following changes since commit da158a86c407fa7b9da848b571356a26809d8df9:

  Merge remote-tracking branch 
'remotes/berrange/tags/pull-qcrypto-2016-10-20-1' into staging (2016-10-20 
14:46:19 +0100)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20160921

for you to fetch changes up to 5e2b40f7271cf9d02960944d5e0ce233a3dac5b7:

  linux-user: disable unicore32 linux-user build (2016-10-21 15:20:14 +0300)


Linux-user changes, mostly bugfixes and adding support for some
new syscalls and some obscure syscalls as well. Includes some
missed patches from earlier rounds, and dropping unicore32 target.

v2: fix the syslog patch and test build with clang-3.8
v3: drop ustat patch



Aleksandar Markovic (12):
  linux-user: Add support for adjtimex() syscall
  linux-user: Fix mq_open() syscall support
  linux-user: Fix msgrcv() and msgsnd() syscalls support
  linux-user: Fix socketcall() syscall support
  linux-user: Fix syslog() syscall support
  linux-user: Remove a duplicate item from strace.list
  linux-user: Add support for clock_adjtime() syscall
  linux-user: Add support for syncfs() syscall
  linux-user: Update mips_syscall_args[] array in main.c
  linux-user: Update ioctls definitions for Mips32
  linux-user: Redirect termbits.h for Mips64 to termbits.h for Mips32
  linux-user: Fix fadvise64() syscall support for Mips32

Dejan Jovicevic (2):
  linux-user: added support for preadv() system call.
  linux-user: added support for pwritev() system call.

Felix Janda (1):
  linux-user: use libc wrapper instead of direct mremap syscall

Laurent Vivier (2):
  linux-user: add kcmp() syscall
  linux-user: add RTA_PRIORITY in netlink

Peter Maydell (3):
  linux-user: sparc64: Use correct target SHMLBA in shmat()
  linux-user: Don't use alloca() for epoll_wait's epoll event array
  linux-user: Fix definition of target_sigevent for 32-bit guests

Riku Voipio (1):
  linux-user: disable unicore32 linux-user build

 configure|  36 
 default-configs/unicore32-linux-user.mak |   1 -
 linux-user/main.c|  24 ++-
 linux-user/mips/syscall_nr.h |   2 +-
 linux-user/mips/termbits.h   |  12 ++
 linux-user/mips64/termbits.h | 245 +
 linux-user/mmap.c|  14 +-
 linux-user/sparc64/target_syscall.h  |   7 +
 linux-user/strace.c  | 233 ++--
 linux-user/strace.list   |  13 +-
 linux-user/syscall.c | 356 ---
 linux-user/syscall_defs.h| 111 +++---
 12 files changed, 671 insertions(+), 383 deletions(-)
 delete mode 100644 default-configs/unicore32-linux-user.mak

-- 
2.1.4




[Qemu-devel] [PULL v2 21/22] linux-user: added support for pwritev() system call.

2016-10-18 Thread riku . voipio
From: Dejan Jovicevic <dejan.jovice...@rt-rk.com>

This system call performs the same task as the writev() system call,
with the exception of having the fourth argument, offset, which
specifes the file offset at which the input operation is to be performed.
Because of this, the pwritev() implementation is based on the writev()
implementation in linux-user mode.

But, since pwritev() is implemented in the kernel as a 5-argument syscall,
5 arguments are needed to be handled as input and passed to the host
syscall.

The pos_l and pos_h argument of the safe_pwritev() are of type unsigned
long, which can be of different sizes on different platforms. The input
arguments are converted to the appropriate host size when passed to
safe_pwritev().

Signed-off-by: Dejan Jovicevic <dejan.jovice...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9cb2a8f..dfc483c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -921,6 +921,8 @@ safe_syscall3(ssize_t, readv, int, fd, const struct iovec 
*, iov, int, iovcnt)
 safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt)
 safe_syscall5(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
   unsigned long, pos_l, unsigned long, pos_h)
+safe_syscall5(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, 
iovcnt,
+  unsigned long, pos_l, unsigned long, pos_h)
 safe_syscall3(int, connect, int, fd, const struct sockaddr *, addr,
   socklen_t, addrlen)
 safe_syscall6(ssize_t, sendto, int, fd, const void *, buf, size_t, len,
@@ -10093,6 +10095,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 }
 break;
 #endif
+#if defined(TARGET_NR_pwritev)
+case TARGET_NR_pwritev:
+{
+struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
+if (vec != NULL) {
+ret = get_errno(safe_pwritev(arg1, vec, arg3, arg4, arg5));
+unlock_iovec(vec, arg2, arg3, 0);
+} else {
+ret = -host_to_target_errno(errno);
+   }
+}
+break;
+#endif
 case TARGET_NR_getsid:
 ret = get_errno(getsid(arg1));
 break;
-- 
2.1.4




[Qemu-devel] [PULL v2 22/22] linux-user: disable unicore32 linux-user build

2016-10-18 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

In order to cleanup linux-user, we need support for most relatively
modern syscalls. unicore32 lacks support for syscalls like
epoll_pwait, preventing cleaning up the CONFIG_EPOLL mess.

This patch can be reverted when unicore32 starts either supporting
the syscalls as defined in mainline kernel, or the oldabi interface
gains support for syscalls supported since at kernel 2.6.19 / glibc 2.6

Cc: MPRC <zhangh...@mprc.pku.edu.cn>
Cc: Xuetao Guan <g...@mprc.pku.edu.cn>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 default-configs/unicore32-linux-user.mak | 1 -
 1 file changed, 1 deletion(-)
 delete mode 100644 default-configs/unicore32-linux-user.mak

diff --git a/default-configs/unicore32-linux-user.mak 
b/default-configs/unicore32-linux-user.mak
deleted file mode 100644
index 6aafd21..000
--- a/default-configs/unicore32-linux-user.mak
+++ /dev/null
@@ -1 +0,0 @@
-# Default configuration for unicore32-linux-user
-- 
2.1.4




[Qemu-devel] [PULL v2 17/22] linux-user: Update ioctls definitions for Mips32

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

Update linux-user/mips/termbits.h with ioctl definitions from kernel
file arch/mips/include/uapi/asm/ioctls.h.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/mips/termbits.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/linux-user/mips/termbits.h b/linux-user/mips/termbits.h
index d3a6cf8..a0bcad0 100644
--- a/linux-user/mips/termbits.h
+++ b/linux-user/mips/termbits.h
@@ -219,8 +219,20 @@ struct target_termios {
 #define TARGET_TIOCSBRK0x5427  /* BSD compatibility */
 #define TARGET_TIOCCBRK0x5428  /* BSD compatibility */
 #define TARGET_TIOCGSID0x7416  /* Return the session ID of FD */
+#define TARGET_TCGETS2  TARGET_IOR('T', 0x2A, struct termios2)
+#define TARGET_TCSETS2  TARGET_IOW('T', 0x2B, struct termios2)
+#define TARGET_TCSETSW2 TARGET_IOW('T', 0x2C, struct termios2)
+#define TARGET_TCSETSF2 TARGET_IOW('T', 0x2D, struct termios2)
+#define TARGET_TIOCGRS485   TARGET_IOR('T', 0x2E, struct serial_rs485)
+#define TARGET_TIOCSRS485   TARGET_IOWR('T', 0x2F, struct serial_rs485)
 #define TARGET_TIOCGPTNTARGET_IOR('T',0x30, unsigned int) /* Get Pty 
Number (of pty-mux device) */
 #define TARGET_TIOCSPTLCK  TARGET_IOW('T',0x31, int)  /* Lock/unlock Pty */
+#define TARGET_TIOCGDEV TARGET_IOR('T', 0x32, unsigned int)
+#define TARGET_TIOCSIG  TARGET_IOW('T', 0x36, int)
+#define TARGET_TIOCVHANGUP  0x5437
+#define TARGET_TIOCGPKT TARGET_IOR('T', 0x38, int)
+#define TARGET_TIOCGPTLCK   TARGET_IOR('T', 0x39, int)
+#define TARGET_TIOCGEXCLTARGET_IOR('T', 0x40, int)
 
 /* I hope the range from 0x5480 on is free ... */
 #define TARGET_TIOCSCTTY   0x5480  /* become controlling tty */
-- 
2.1.4




[Qemu-devel] [PULL v2 20/22] linux-user: added support for preadv() system call.

2016-10-18 Thread riku . voipio
From: Dejan Jovicevic <dejan.jovice...@rt-rk.com>

This system call performs the same task as the readv() system call,
with the exception of having the fourth argument, offset, which
specifes the file offset at which the input operation is to be performed.
Because of this, the preadv() implementation is based on the readv()
implementation in linux-user mode.

But, since preadv() is implemented in the kernel as a 5-argument syscall,
5 arguments are needed to be handled as input and passed to the host
syscall.

The pos_l and pos_h argument of the safe_preadv() are of type unsigned
long, which can be of different sizes on different platforms. The input
arguments are converted to the appropriate host size when passed to
safe_preadv().

Signed-off-by: Dejan Jovicevic <dejan.jovice...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index d85a0b5..9cb2a8f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -919,6 +919,8 @@ safe_syscall2(int, tkill, int, tid, int, sig)
 safe_syscall3(int, tgkill, int, tgid, int, pid, int, sig)
 safe_syscall3(ssize_t, readv, int, fd, const struct iovec *, iov, int, iovcnt)
 safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt)
+safe_syscall5(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
+  unsigned long, pos_l, unsigned long, pos_h)
 safe_syscall3(int, connect, int, fd, const struct sockaddr *, addr,
   socklen_t, addrlen)
 safe_syscall6(ssize_t, sendto, int, fd, const void *, buf, size_t, len,
@@ -10078,6 +10080,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 }
 }
 break;
+#if defined(TARGET_NR_preadv)
+case TARGET_NR_preadv:
+{
+struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
+if (vec != NULL) {
+ret = get_errno(safe_preadv(arg1, vec, arg3, arg4, arg5));
+unlock_iovec(vec, arg2, arg3, 1);
+} else {
+ret = -host_to_target_errno(errno);
+   }
+}
+break;
+#endif
 case TARGET_NR_getsid:
 ret = get_errno(getsid(arg1));
 break;
-- 
2.1.4




[Qemu-devel] [PULL v2 16/22] linux-user: Update mips_syscall_args[] array in main.c

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

Array mips_syscall_args[] determines number of arguments for each
syscall on Mips32. It wasn't updated with newer syscalls. Also,
preadv and pwritev have 5 arguments, not 6.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/main.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 0e31dad..18d5a62 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2295,8 +2295,8 @@ static const uint8_t mips_syscall_args[] = {
 MIPS_SYS(sys_dup3, 3)
 MIPS_SYS(sys_pipe2, 2)
 MIPS_SYS(sys_inotify_init1, 1)
-MIPS_SYS(sys_preadv, 6) /* 4330 */
-MIPS_SYS(sys_pwritev, 6)
+MIPS_SYS(sys_preadv, 5) /* 4330 */
+MIPS_SYS(sys_pwritev, 5)
 MIPS_SYS(sys_rt_tgsigqueueinfo, 4)
 MIPS_SYS(sys_perf_event_open, 5)
 MIPS_SYS(sys_accept4, 4)
@@ -2308,6 +2308,26 @@ static const uint8_t mips_syscall_args[] = {
 MIPS_SYS(sys_open_by_handle_at, 3) /* 4340 */
 MIPS_SYS(sys_clock_adjtime, 2)
 MIPS_SYS(sys_syncfs, 1)
+MIPS_SYS(sys_sendmmsg, 4)
+MIPS_SYS(sys_setns, 2)
+MIPS_SYS(sys_process_vm_readv, 6) /* 345 */
+MIPS_SYS(sys_process_vm_writev, 6)
+MIPS_SYS(sys_kcmp, 5)
+MIPS_SYS(sys_finit_module, 3)
+MIPS_SYS(sys_sched_setattr, 2)
+MIPS_SYS(sys_sched_getattr, 3)  /* 350 */
+MIPS_SYS(sys_renameat2, 5)
+MIPS_SYS(sys_seccomp, 3)
+MIPS_SYS(sys_getrandom, 3)
+MIPS_SYS(sys_memfd_create, 2)
+MIPS_SYS(sys_bpf, 3)/* 355 */
+MIPS_SYS(sys_execveat, 5)
+MIPS_SYS(sys_userfaultfd, 1)
+MIPS_SYS(sys_membarrier, 2)
+MIPS_SYS(sys_mlock2, 3)
+MIPS_SYS(sys_copy_file_range, 6) /* 360 */
+MIPS_SYS(sys_preadv2, 6)
+MIPS_SYS(sys_pwritev2, 6)
 };
 #  undef MIPS_SYS
 # endif /* O32 */
-- 
2.1.4




[Qemu-devel] [PULL v2 19/22] linux-user: Fix fadvise64() syscall support for Mips32

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

By looking at the file arch/mips/kernel/scall32-o32.S in Linux
kernel, it can be deduced that, for Mips32 platform, syscall
corresponding to number _NR_fadvise64 as defined in kernel file
arch/mips/include/uapi/asm/unistd.h translates to kernel function
sys_fadvise64_64, and that argument layout for this system call is
as follows:

  0 32 0 32
 +++
  (arg1) |   fd   | __pad  | (arg2)
 +++
  (arg3) | buffer  | (arg4)
 +++
  (arg5) |   len   | (arg6)
 +++
  (arg7) | advise |not used| (arg8)
 +++

The same argument layout can be deduced from glibc code, and
relevant commit messages in linux kernel and glibc.

The fix is to change TARGET_NR_fadvise64 to TARGET_NR_fadvise64_64
in Mips32 syscall numbers table. Array mips_syscall_args[] in
linux-user/main.c also already have "fadvise64_64" (and not
"fadvise64") in corresponding place for the syscall number in
question, so no change for linux-user/main.c.

This patch also fixes the failure LTP test posix_fadvise03, if
executed on Qemu-emulated Mips32 platform (user mode).

Signed-off-by: Aleksandar Rikalo <aleksandar.rik...@imgtec.com>
Signed-off-by: Miroslav Tisma <miroslav.ti...@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/mips/syscall_nr.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/mips/syscall_nr.h b/linux-user/mips/syscall_nr.h
index 6819f86..ced3280 100644
--- a/linux-user/mips/syscall_nr.h
+++ b/linux-user/mips/syscall_nr.h
@@ -256,7 +256,7 @@
 #define TARGET_NR_remap_file_pages (TARGET_NR_Linux + 251)
 #define TARGET_NR_set_tid_address  (TARGET_NR_Linux + 252)
 #define TARGET_NR_restart_syscall  (TARGET_NR_Linux + 253)
-#define TARGET_NR_fadvise64(TARGET_NR_Linux + 254)
+#define TARGET_NR_fadvise64_64  (TARGET_NR_Linux + 254)
 #define TARGET_NR_statfs64 (TARGET_NR_Linux + 255)
 #define TARGET_NR_fstatfs64(TARGET_NR_Linux + 256)
 #define TARGET_NR_timer_create (TARGET_NR_Linux + 257)
-- 
2.1.4




[Qemu-devel] [PULL v2 10/22] linux-user: add RTA_PRIORITY in netlink

2016-10-18 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

Used by fedora21 on ppc64 in the network initialization

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e005401..bbdf316 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2601,6 +2601,7 @@ static abi_long target_to_host_data_route_rtattr(struct 
rtattr *rtattr)
 case RTA_GATEWAY:
 break;
 /* u32 */
+case RTA_PRIORITY:
 case RTA_OIF:
 u32 = RTA_DATA(rtattr);
 *u32 = tswap32(*u32);
-- 
2.1.4




[Qemu-devel] [PULL v2 18/22] linux-user: Redirect termbits.h for Mips64 to termbits.h for Mips32

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

linux-user/mips64/termbits.h and linux-user/mips/termbits.h
originate from the same files in Linux kernel. There is no plan
to split original headers in Linux kernel into Mips32 and Mips64
versions any time soon. Therefore, it is better not to have
separate Mips32 and Mips64 variants in Qemu.

This patch makes these two files effectively the same, allowing the
mainenance by changing only a single file. (This is already done in
the same fashion for some other headers in same directories.)

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/mips64/termbits.h | 245 +--
 1 file changed, 1 insertion(+), 244 deletions(-)

diff --git a/linux-user/mips64/termbits.h b/linux-user/mips64/termbits.h
index d3a6cf8..d0a271e 100644
--- a/linux-user/mips64/termbits.h
+++ b/linux-user/mips64/termbits.h
@@ -1,245 +1,2 @@
-/* from asm/termbits.h */
+#include "../mips/termbits.h"
 
-#define TARGET_NCCS 23
-
-struct target_termios {
-unsigned int c_iflag;   /* input mode flags */
-unsigned int c_oflag;   /* output mode flags */
-unsigned int c_cflag;   /* control mode flags */
-unsigned int c_lflag;   /* local mode flags */
-unsigned char c_line;/* line discipline */
-unsigned char c_cc[TARGET_NCCS];/* control characters */
-};
-
-/* c_iflag bits */
-#define TARGET_IGNBRK  001
-#define TARGET_BRKINT  002
-#define TARGET_IGNPAR  004
-#define TARGET_PARMRK  010
-#define TARGET_INPCK   020
-#define TARGET_ISTRIP  040
-#define TARGET_INLCR   100
-#define TARGET_IGNCR   200
-#define TARGET_ICRNL   400
-#define TARGET_IUCLC   0001000
-#define TARGET_IXON0002000
-#define TARGET_IXANY   0004000
-#define TARGET_IXOFF   001
-#define TARGET_IMAXBEL 002
-#define TARGET_IUTF8   004
-
-/* c_oflag bits */
-#define TARGET_OPOST   001
-#define TARGET_OLCUC   002
-#define TARGET_ONLCR   004
-#define TARGET_OCRNL   010
-#define TARGET_ONOCR   020
-#define TARGET_ONLRET  040
-#define TARGET_OFILL   100
-#define TARGET_OFDEL   200
-#define TARGET_NLDLY   400
-#define   TARGET_NL0   000
-#define   TARGET_NL1   400
-#define TARGET_CRDLY   0003000
-#define   TARGET_CR0   000
-#define   TARGET_CR1   0001000
-#define   TARGET_CR2   0002000
-#define   TARGET_CR3   0003000
-#define TARGET_TABDLY  0014000
-#define   TARGET_TAB0  000
-#define   TARGET_TAB1  0004000
-#define   TARGET_TAB2  001
-#define   TARGET_TAB3  0014000
-#define   TARGET_XTABS 0014000
-#define TARGET_BSDLY   002
-#define   TARGET_BS0   000
-#define   TARGET_BS1   002
-#define TARGET_VTDLY   004
-#define   TARGET_VT0   000
-#define   TARGET_VT1   004
-#define TARGET_FFDLY   010
-#define   TARGET_FF0   000
-#define   TARGET_FF1   010
-
-/* c_cflag bit meaning */
-#define TARGET_CBAUD   0010017
-#define  TARGET_B0 000 /* hang up */
-#define  TARGET_B50001
-#define  TARGET_B75002
-#define  TARGET_B110   003
-#define  TARGET_B134   004
-#define  TARGET_B150   005
-#define  TARGET_B200   006
-#define  TARGET_B300   007
-#define  TARGET_B600   010
-#define  TARGET_B1200  011
-#define  TARGET_B1800  012
-#define  TARGET_B2400  013
-#define  TARGET_B4800  014
-#define  TARGET_B9600  015
-#define  TARGET_B19200 016
-#define  TARGET_B38400 017
-#define TARGET_EXTA B19200
-#define TARGET_EXTB B38400
-#define TARGET_CSIZE   060
-#define   TARGET_CS5   000
-#define   TARGET_CS6   020
-#define   TARGET_CS7   040
-#define   TARGET_CS8   060
-#define TARGET_CSTOPB  100
-#define TARGET_CREAD   200
-#define TARGET_PARENB  400
-#define TARGET_PARODD  0001000
-#define TARGET_HUPCL   0002000
-#define TARGET_CLOCAL  0004000
-#define TARGET_CBAUDEX 001
-#define  TARGET_BOTHER   001
-#define  TARGET_B57600   0010001
-#define  TARGET_B115200  0010002
-#define  TARGET_B230400  0010003
-#define  TARGET_B460800  0010004
-#define  TARGET_B50  0010005
-#define  TARGET_B576000  0010006
-#define  TARGET_B921600  0010007
-#define  TARGET_B100 0010010
-#define  TARGET_B1152000 0010011
-#define  TARGET_B150 0010012
-#define  TARGET_B200 0010013
-#define  TARGET_B250 0010014
-#define  TARGET_B300 0010015
-#define  TARGET_B350 0010016
-#define  TARGET_B400 0010017
-#define TARGET_CIBAUD00200360  /* input baud rate (not used) */
-#define TARGET_CMSPAR0100  /* mark or space (stick) parity */
-#define TARGET_CRTSCTS   0200  /* flow control */
-
-/* c_lflag bits */
-#define TARGET_ISIG001
-#define TARGET_ICANON  002
-#define TARGET_XCASE   004
-#define TARGET_ECHO0

[Qemu-devel] [PULL v2 09/22] linux-user: add kcmp() syscall

2016-10-18 Thread riku . voipio
From: Laurent Vivier <laur...@vivier.eu>

Signed-off-by: Laurent Vivier <laur...@vivier.eu>
Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3396d4b..e005401 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -306,6 +306,11 @@ _syscall3(int, ioprio_set, int, which, int, who, int, 
ioprio)
 _syscall3(int, getrandom, void *, buf, size_t, buflen, unsigned int, flags)
 #endif
 
+#if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
+_syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
+  unsigned long, idx1, unsigned long, idx2)
+#endif
+
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,O_ACCMODE,   O_WRONLY,},
   { TARGET_O_ACCMODE,   TARGET_O_RDWR,  O_ACCMODE,   O_RDWR,  },
@@ -12099,6 +12104,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = get_errno(unshare(arg1));
 break;
 #endif
+#if defined(TARGET_NR_kcmp) && defined(__NR_kcmp)
+case TARGET_NR_kcmp:
+ret = get_errno(kcmp(arg1, arg2, arg3, arg4, arg5));
+break;
+#endif
 
 default:
 unimplemented:
-- 
2.1.4




[Qemu-devel] [PULL v2 11/22] linux-user: Don't use alloca() for epoll_wait's epoll event array

2016-10-18 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

The epoll event array which epoll_wait() allocates has a size
determined by the guest which could potentially be quite large.
Use g_try_new() rather than alloca() so that we can fail more
cleanly if the guest hands us an oversize value. (ENOMEM is
not a documented return value for epoll_wait() but in practice
some kernel configurations can return it -- see for instance
sys_oabi_epoll_wait() on ARM.)

This rearrangement includes fixing a bug where we were
incorrectly passing a negative length to unlock_user() in
the error-exit codepath.

Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bbdf316..fb56fed 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11796,7 +11796,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 goto efault;
 }
 
-ep = alloca(maxevents * sizeof(struct epoll_event));
+ep = g_try_new(struct epoll_event, maxevents);
+if (!ep) {
+unlock_user(target_ep, arg2, 0);
+ret = -TARGET_ENOMEM;
+break;
+}
 
 switch (num) {
 #if defined(TARGET_NR_epoll_pwait)
@@ -11814,8 +11819,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 target_set = lock_user(VERIFY_READ, arg5,
sizeof(target_sigset_t), 1);
 if (!target_set) {
-unlock_user(target_ep, arg2, 0);
-goto efault;
+ret = -TARGET_EFAULT;
+break;
 }
 target_to_host_sigset(set, target_set);
 unlock_user(target_set, arg5, 0);
@@ -11843,8 +11848,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 target_ep[i].events = tswap32(ep[i].events);
 target_ep[i].data.u64 = tswap64(ep[i].data.u64);
 }
+unlock_user(target_ep, arg2,
+ret * sizeof(struct target_epoll_event));
+} else {
+unlock_user(target_ep, arg2, 0);
 }
-unlock_user(target_ep, arg2, ret * sizeof(struct target_epoll_event));
+g_free(ep);
 break;
 }
 #endif
-- 
2.1.4




[Qemu-devel] [PULL v2 12/22] linux-user: use libc wrapper instead of direct mremap syscall

2016-10-18 Thread riku . voipio
From: Felix Janda <felix.ja...@posteo.de>

This commit essentially reverts commit
3af72a4d98dca033492102603734cbc63cd2694a, which has replaced
five-argument calls to mremap() by direct mremap syscalls for
compatibility with glibc older than version 2.4.

The direct syscall was buggy for 64bit targets on 32bit hosts
because of the default integer type promotions. Since glibc-2.4
is now a decade old, we can remove this workaround.

Signed-off-by: Felix Janda <felix.ja...@posteo.de>
Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/mmap.c | 14 --
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index c4371d9..ffd099d 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -17,8 +17,6 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
-#include 
-#include 
 
 #include "qemu.h"
 #include "qemu-common.h"
@@ -681,10 +679,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
 mmap_lock();
 
 if (flags & MREMAP_FIXED) {
-host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
- old_size, new_size,
- flags,
- g2h(new_addr));
+host_addr = mremap(g2h(old_addr), old_size, new_size,
+   flags, g2h(new_addr));
 
 if (reserved_va && host_addr != MAP_FAILED) {
 /* If new and old addresses overlap then the above mremap will
@@ -700,10 +696,8 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong 
old_size,
 errno = ENOMEM;
 host_addr = MAP_FAILED;
 } else {
-host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
- old_size, new_size,
- flags | MREMAP_FIXED,
- g2h(mmap_start));
+host_addr = mremap(g2h(old_addr), old_size, new_size,
+   flags | MREMAP_FIXED, g2h(mmap_start));
 if (reserved_va) {
 mmap_reserve(old_addr, old_size);
 }
-- 
2.1.4




[Qemu-devel] [PULL v2 14/22] linux-user: Add support for clock_adjtime() syscall

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

This patch implements Qemu user mode clock_adjtime() syscall support.

The implementation is based on invocation of host's clock_adjtime().

Signed-off-by: Aleksandar Rikalo <aleksandar.rik...@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 configure  | 18 
 linux-user/strace.c| 76 ++
 linux-user/strace.list |  3 ++
 linux-user/syscall.c   | 18 
 4 files changed, 115 insertions(+)

diff --git a/configure b/configure
index dd9e679..1ce3d00 100755
--- a/configure
+++ b/configure
@@ -3911,6 +3911,21 @@ if compile_prog "" "" ; then
   setns=yes
 fi
 
+# clock_adjtime probe
+clock_adjtime=no
+cat > $TMPC <
+
+int main(void)
+{
+return clock_adjtime(0, 0);
+}
+EOF
+clock_adjtime=no
+if compile_prog "" "" ; then
+  clock_adjtime=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$docs" != "no" ; then
   if has makeinfo && has pod2man; then
@@ -5196,6 +5211,9 @@ fi
 if test "$setns" = "yes" ; then
   echo "CONFIG_SETNS=y" >> $config_host_mak
 fi
+if test "$clock_adjtime" = "yes" ; then
+  echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 679f840..489dbc9 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -435,6 +435,69 @@ print_fdset(int n, abi_ulong target_fds_addr)
 }
 #endif
 
+#ifdef TARGET_NR_clock_adjtime
+/* IDs of the various system clocks */
+#define TARGET_CLOCK_REALTIME  0
+#define TARGET_CLOCK_MONOTONIC 1
+#define TARGET_CLOCK_PROCESS_CPUTIME_ID2
+#define TARGET_CLOCK_THREAD_CPUTIME_ID 3
+#define TARGET_CLOCK_MONOTONIC_RAW 4
+#define TARGET_CLOCK_REALTIME_COARSE   5
+#define TARGET_CLOCK_MONOTONIC_COARSE  6
+#define TARGET_CLOCK_BOOTTIME  7
+#define TARGET_CLOCK_REALTIME_ALARM8
+#define TARGET_CLOCK_BOOTTIME_ALARM9
+#define TARGET_CLOCK_SGI_CYCLE 10
+#define TARGET_CLOCK_TAI   11
+
+static void
+print_clockid(int clockid, int last)
+{
+switch (clockid) {
+case TARGET_CLOCK_REALTIME:
+gemu_log("CLOCK_REALTIME");
+break;
+case TARGET_CLOCK_MONOTONIC:
+gemu_log("CLOCK_MONOTONIC");
+break;
+case TARGET_CLOCK_PROCESS_CPUTIME_ID:
+gemu_log("CLOCK_PROCESS_CPUTIME_ID");
+break;
+case TARGET_CLOCK_THREAD_CPUTIME_ID:
+gemu_log("CLOCK_THREAD_CPUTIME_ID");
+break;
+case TARGET_CLOCK_MONOTONIC_RAW:
+gemu_log("CLOCK_MONOTONIC_RAW");
+break;
+case TARGET_CLOCK_REALTIME_COARSE:
+gemu_log("CLOCK_REALTIME_COARSE");
+break;
+case TARGET_CLOCK_MONOTONIC_COARSE:
+gemu_log("CLOCK_MONOTONIC_COARSE");
+break;
+case TARGET_CLOCK_BOOTTIME:
+gemu_log("CLOCK_BOOTTIME");
+break;
+case TARGET_CLOCK_REALTIME_ALARM:
+gemu_log("CLOCK_REALTIME_ALARM");
+break;
+case TARGET_CLOCK_BOOTTIME_ALARM:
+gemu_log("CLOCK_BOOTTIME_ALARM");
+break;
+case TARGET_CLOCK_SGI_CYCLE:
+gemu_log("CLOCK_SGI_CYCLE");
+break;
+case TARGET_CLOCK_TAI:
+gemu_log("CLOCK_TAI");
+break;
+default:
+gemu_log("%d", clockid);
+break;
+}
+gemu_log("%s", get_comma(last));
+}
+#endif
+
 /*
  * Sysycall specific output functions
  */
@@ -1096,6 +1159,19 @@ print_chmod(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_clock_adjtime
+static void
+print_clock_adjtime(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_clockid(arg0, 0);
+print_pointer(arg1, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_clone
 static void do_print_clone(unsigned int flags, abi_ulong newsp,
abi_ulong parent_tidptr, target_ulong newtls,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 4bbe0d3..dcd3812 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -79,6 +79,9 @@
 #ifdef TARGET_NR_chroot
 { TARGET_NR_chroot, "chroot" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_clock_adjtime
+{ TARGET_NR_clock_adjtime, "clock_adjtime" , NULL, print_clock_adjtime, NULL },
+#endif
 #ifdef TARGET_NR_clock_getres
 { TARGET_NR_cloc

[Qemu-devel] [PULL v2 13/22] linux-user: Fix definition of target_sigevent for 32-bit guests

2016-10-18 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

The sigevent structure includes a union with some fields which
are pointers. For the QEMU target_sigevent structure we must
represent these as abi_ulongs, not host function pointers.

This error was causing the compiler to believe it should 8-align
the _sigev_un union on a 64-bit host, which meant that the
code in target_to_host_sigevent() was looking at the wrong
offset to find the _tid field, and timer_create() would
spuriously fail with EINVAL.

This fixes the final loose end noted in LP:1042388.

While we're editing the structure, switch the 'int32_t' fields
to 'abi_int'; this will only matter for guests with non-standard
integer alignment like m68k.

Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall_defs.h | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 61270ef..714ae28 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2664,15 +2664,19 @@ typedef int32_t target_timer_t;
 
 struct target_sigevent {
 target_sigval_t sigev_value;
-int32_t sigev_signo;
-int32_t sigev_notify;
+abi_int sigev_signo;
+abi_int sigev_notify;
 union {
-int32_t _pad[TARGET_SIGEV_PAD_SIZE];
-int32_t _tid;
+abi_int _pad[TARGET_SIGEV_PAD_SIZE];
+abi_int _tid;
 
+/* The kernel (and thus QEMU) never looks at these;
+ * they're only used as part of the ABI between a
+ * userspace program and libc.
+ */
 struct {
-void (*_function)(sigval_t);
-void *_attribute;
+abi_ulong _function;
+abi_ulong _attribute;
 } _sigev_thread;
 } _sigev_un;
 };
-- 
2.1.4




[Qemu-devel] [PULL v2 07/22] linux-user: Remove a duplicate item from strace.list

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

There is a duplicate item in strace.list. It is benign, but it
shouldn't be there, since it may lead to confusion and even bugs
in the future. It is the only duplicate in strace.list. This
patch removes it.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.list | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index 2c7ad2b..4bbe0d3 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1455,9 +1455,6 @@
 #ifdef TARGET_NR_sync
 { TARGET_NR_sync, "sync" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_sync_file_range
-{ TARGET_NR_sync_file_range, "sync_file_range" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_syncfs
 { TARGET_NR_syncfs, "syncfs" , NULL, NULL, NULL },
 #endif
-- 
2.1.4




[Qemu-devel] [PULL v2 02/22] linux-user: Add support for ustat() syscall

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

This patch implements Qemu user mode ustat() syscall support.

Syscall ustat() returns information about a mounted filesystem.

Its declaration is:

int ustat(dev_t dev, struct ustat *ubuf);

Its Linux kernel implementation is at fs/compat.c, line 334.

The Qemu implementation proposed in this patch is similar to the
Qemu implementations of statfs(), fstatfs() and other related syscalls.
It is based on invocation of host's ustat(), and its key part is in the
correspondent case segment of the main switch statement of the function
do_syscall(), in file linux-user/syscalls.c. All necessary conversions
of data structures from target to host and from host to target are
covered. Support for target_ustat is included. Sufficient support for
"-strace" option for this syscall is already present, and this patch
does not change it.

This patch also fixes failures of LTP tests ustat01, and ustat02, if
executed on Qemu-emulated systems.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c  | 23 +--
 linux-user/syscall_defs.h |  6 ++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0379b8a..88007e0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -48,6 +48,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -8227,9 +8228,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = get_errno(chroot(p));
 unlock_user(p, arg1, 0);
 break;
-#ifdef TARGET_NR_ustat
+#if defined(TARGET_NR_ustat)
 case TARGET_NR_ustat:
-goto unimplemented;
+{
+struct ustat ust;
+
+ret = get_errno(ustat(arg1, ));
+if (!is_error(ret)) {
+struct target_ustat *target_ust;
+
+if (!lock_user_struct(VERIFY_WRITE, target_ust, arg2, 0)) {
+goto efault;
+}
+__put_user(ust.f_tfree, _ust->f_tfree);
+__put_user(ust.f_tinode, _ust->f_tinode);
+memcpy(target_ust->f_fname, ust.f_fname, 6);
+memcpy(target_ust->f_fpack, ust.f_fpack, 6);
+unlock_user_struct(target_ust, arg2, 1);
+}
+}
+break;
+
 #endif
 #ifdef TARGET_NR_dup2
 case TARGET_NR_dup2:
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index ca8fa6e..7872b9d 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2168,6 +2168,12 @@ struct target_statfs64 {
 };
 #endif
 
+struct target_ustat {
+abi_ulong f_tfree;
+abi_int f_tinode;
+char f_fname[6];
+char f_fpack[6];
+};
 
 #define TARGET_F_DUPFD 0   /* dup */
 #define TARGET_F_GETFD 1   /* get close_on_exec */
-- 
2.1.4




[Qemu-devel] [PULL v2 15/22] linux-user: Add support for syncfs() syscall

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

This patch implements Qemu user mode syncfs() syscall support. Syscall
syncfs() syncs the filesystem containing file determined by the open
file descriptor passed as the argument to syncfs().

The implementation consists of a straightforward invocation of host's
syncfs(). Configure and strace support is included as well.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 configure  | 18 ++
 linux-user/strace.list |  2 +-
 linux-user/syscall.c   |  5 +
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 1ce3d00..d3dafcb 100755
--- a/configure
+++ b/configure
@@ -3926,6 +3926,21 @@ if compile_prog "" "" ; then
   clock_adjtime=yes
 fi
 
+# syncfs probe
+syncfs=no
+cat > $TMPC <
+
+int main(void)
+{
+return syncfs(0);
+}
+EOF
+syncfs=no
+if compile_prog "" "" ; then
+  syncfs=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$docs" != "no" ; then
   if has makeinfo && has pod2man; then
@@ -5214,6 +5229,9 @@ fi
 if test "$clock_adjtime" = "yes" ; then
   echo "CONFIG_CLOCK_ADJTIME=y" >> $config_host_mak
 fi
+if test "$syncfs" = "yes" ; then
+  echo "CONFIG_SYNCFS=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
diff --git a/linux-user/strace.list b/linux-user/strace.list
index dcd3812..3b1282e 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1459,7 +1459,7 @@
 { TARGET_NR_sync, "sync" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_syncfs
-{ TARGET_NR_syncfs, "syncfs" , NULL, NULL, NULL },
+{ TARGET_NR_syncfs, "syncfs" , "%s(%d)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_syscall
 { TARGET_NR_syscall, "syscall" , NULL, NULL, NULL },
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 28d2b8e..d85a0b5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8091,6 +8091,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 sync();
 ret = 0;
 break;
+#if defined(TARGET_NR_syncfs) && defined(CONFIG_SYNCFS)
+case TARGET_NR_syncfs:
+ret = get_errno(syncfs(arg1));
+break;
+#endif
 case TARGET_NR_kill:
 ret = get_errno(safe_kill(arg1, target_to_host_signal(arg2)));
 break;
-- 
2.1.4




[Qemu-devel] [PULL v2 08/22] linux-user: sparc64: Use correct target SHMLBA in shmat()

2016-10-18 Thread riku . voipio
From: Peter Maydell <peter.mayd...@linaro.org>

In commit 40df8c0c0722 support was added for target-specific
handling of SHMLBA. Unfortunately the sparc64-specific part
of the change got lost somewhere between the patch being
posted to the list and going into master:
 http://patchwork.ozlabs.org/patch/646980/
 http://patchwork.ozlabs.org/patch/673339/

Add the accidentally-dropped code.

Signed-off-by: Peter Maydell <peter.mayd...@linaro.org>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/sparc64/target_syscall.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/linux-user/sparc64/target_syscall.h 
b/linux-user/sparc64/target_syscall.h
index b7e3bf8..2cbbaae 100644
--- a/linux-user/sparc64/target_syscall.h
+++ b/linux-user/sparc64/target_syscall.h
@@ -23,4 +23,11 @@ struct target_pt_regs {
 #define TARGET_MLOCKALL_MCL_CURRENT 0x2000
 #define TARGET_MLOCKALL_MCL_FUTURE  0x4000
 
+#define TARGET_FORCE_SHMLBA
+
+static inline abi_ulong target_shmlba(CPUSPARCState *env)
+{
+return MAX(TARGET_PAGE_SIZE, 16 * 1024);
+}
+
 #endif /* SPARC64_TARGET_SYSCALL_H */
-- 
2.1.4




[Qemu-devel] [PULL v2 03/22] linux-user: Fix mq_open() syscall support

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

Conversion of file creation flags (O_CREAT, ...) from target to host
was missing.

Also, this patch implements better error handling.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 88007e0..e031ecf 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -11476,16 +11476,18 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
 case TARGET_NR_mq_open:
 {
-struct mq_attr posix_mq_attr, *attrp;
+struct mq_attr posix_mq_attr;
+int host_flags;
 
+host_flags = target_to_host_bitmask(arg2, fcntl_flags_tbl);
+if (copy_from_user_mq_attr(_mq_attr, arg4) != 0) {
+goto efault;
+}
 p = lock_user_string(arg1 - 1);
-if (arg4 != 0) {
-copy_from_user_mq_attr (_mq_attr, arg4);
-attrp = _mq_attr;
-} else {
-attrp = 0;
+if (!p) {
+goto efault;
 }
-ret = get_errno(mq_open(p, arg2, arg3, attrp));
+ret = get_errno(mq_open(p, host_flags, arg3, _mq_attr));
 unlock_user (p, arg1, 0);
 }
 break;
-- 
2.1.4




[Qemu-devel] [PULL v2 05/22] linux-user: Fix socketcall() syscall support

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

Since not all Linux host platforms support socketcall() (most notably
Intel), do_socketcall() function in Qemu's syscalls.c is implemented to
mirror the corespondant implementation of socketcall() in Linux kernel,
and to utilise individual socket operations that are supported on all
Linux platforms. (see kernel source file net/socket.c, definition of
socketcall).

However, error codes produced by Qemu implementation are wrong for the
cases of invalid values of the first argument. Also, naming of constants
is not consistent with kernel one, and not consistant with Qemu convention
of prefixing such constants with "TARGET_". This patch in that light
brings do_socketcall() closer to its kernel counterpart, and in that way
fixes the errors and yields more consisrtent Qemu code.

There were also three missing cases (among 20) for strace support for
socketcall(). The array that contains pointers for appropriate printing
functions is updated with 3 elements, however pointers to functions are
left NULL, and its implementation is left for future.

Also, this patch fixes failure of LTP test socketcall02, if executed on some
Qemu emulated sywstems (uer mode).

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c   |  39 ---
 linux-user/syscall.c  | 119 --
 linux-user/syscall_defs.h |  42 
 3 files changed, 105 insertions(+), 95 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index f37b386..a0e45b5 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1675,29 +1675,32 @@ print_optint:
 }
 
 #define PRINT_SOCKOP(name, func) \
-[SOCKOP_##name] = { #name, func }
+[TARGET_SYS_##name] = { #name, func }
 
 static struct {
 const char *name;
 void (*print)(const char *, abi_long);
 } scall[] = {
-PRINT_SOCKOP(socket, do_print_socket),
-PRINT_SOCKOP(bind, do_print_sockaddr),
-PRINT_SOCKOP(connect, do_print_sockaddr),
-PRINT_SOCKOP(listen, do_print_listen),
-PRINT_SOCKOP(accept, do_print_sockaddr),
-PRINT_SOCKOP(getsockname, do_print_sockaddr),
-PRINT_SOCKOP(getpeername, do_print_sockaddr),
-PRINT_SOCKOP(socketpair, do_print_socketpair),
-PRINT_SOCKOP(send, do_print_sendrecv),
-PRINT_SOCKOP(recv, do_print_sendrecv),
-PRINT_SOCKOP(sendto, do_print_msgaddr),
-PRINT_SOCKOP(recvfrom, do_print_msgaddr),
-PRINT_SOCKOP(shutdown, do_print_shutdown),
-PRINT_SOCKOP(sendmsg, do_print_msg),
-PRINT_SOCKOP(recvmsg, do_print_msg),
-PRINT_SOCKOP(setsockopt, do_print_sockopt),
-PRINT_SOCKOP(getsockopt, do_print_sockopt),
+PRINT_SOCKOP(SOCKET, do_print_socket),
+PRINT_SOCKOP(BIND, do_print_sockaddr),
+PRINT_SOCKOP(CONNECT, do_print_sockaddr),
+PRINT_SOCKOP(LISTEN, do_print_listen),
+PRINT_SOCKOP(ACCEPT, do_print_sockaddr),
+PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr),
+PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr),
+PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair),
+PRINT_SOCKOP(SEND, do_print_sendrecv),
+PRINT_SOCKOP(RECV, do_print_sendrecv),
+PRINT_SOCKOP(SENDTO, do_print_msgaddr),
+PRINT_SOCKOP(RECVFROM, do_print_msgaddr),
+PRINT_SOCKOP(SHUTDOWN, do_print_shutdown),
+PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt),
+PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt),
+PRINT_SOCKOP(SENDMSG, do_print_msg),
+PRINT_SOCKOP(RECVMSG, do_print_msg),
+PRINT_SOCKOP(ACCEPT4, NULL),
+PRINT_SOCKOP(RECVMMSG, NULL),
+PRINT_SOCKOP(SENDMMSG, NULL),
 };
 
 static void
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 032cb76..05b4c41 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3898,89 +3898,94 @@ fail:
 }
 
 #ifdef TARGET_NR_socketcall
-/* do_socketcall() Must return target values and target errnos. */
+/* do_socketcall() must return target values and target errnos. */
 static abi_long do_socketcall(int num, abi_ulong vptr)
 {
-static const unsigned ac[] = { /* number of arguments per call */
-[SOCKOP_socket] = 3,  /* domain, type, protocol */
-[SOCKOP_bind] = 3,/* sockfd, addr, addrlen */
-[SOCKOP_connect] = 3, /* sockfd, addr, addrlen */
-[SOCKOP_listen] = 2,  /* sockfd, backlog */
-[SOCKOP_accept] = 3,  /* sockfd, addr, addrlen */
-[SOCKOP_accept4] = 4, /* sockfd, addr, addrlen, flags */
-[SOCKOP_getsockname] = 3, /* sockfd, addr, addrlen */
-[SOCKOP_getpeername] = 3, /* sockfd, addr, addrlen */
-[SOCKOP_socketpair] = 4,  /* domain, type, protocol, tab */
-[SOCKOP_send] = 4,/* sockfd, msg, len, flags */
-[SOCKOP_recv] = 4,/* sockfd, msg, len, flags */
-[SOCKOP_sendto] = 6,  /* sockfd, msg, len, flags, addr, addrlen */
-[SOCKOP_recvfrom]

[Qemu-devel] [PULL v2 06/22] linux-user: Fix syslog() syscall support

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

There are currently several problems related to syslog() support.

For example, if the second argument "bufp" of target syslog() syscall
is NULL, the current implementation always returns error code EFAULT.
However, NULL is a perfectly valid value for the second argument for
many use cases of this syscall. This is, for example, visible from
this excerpt of man page for syslog(2):

> EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is
>NULL, or len is less than zero; or for type 8, the level is
>outside the range 1 to 8).

Moreover, the argument "bufp" is ignored for all cases of values of the
first argument, except 2, 3 and 4. This means that for such cases
(the first argument is not 2, 3 or 4), there is no need to pass "buf"
between host and target, and it can be set to NULL while calling host's
syslog(), without loss of emulation accuracy.

Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the
correct returned error code is EINVAL, not EFAULT.

All these details are reflected in this patch.

"#ifdef TARGET_NR_syslog" is also proprerly inserted when needed.

Support for Qemu's "-strace" switch for syslog() syscall is included too.

LTP tests syslog11 and syslog12 pass with this patch (while fail without
it), on any platform.

Changes to original patch by Riku Voipio:

 fixed error paths in TARGET_SYSLOG_ACTION_READ_ALL to match

http://lxr.free-electrons.com/source/kernel/printk/printk.c?v=4.7#L1335

Should fix also the build error in:

https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg03721.html

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c   | 72 +++
 linux-user/strace.list|  2 +-
 linux-user/syscall.c  | 50 
 linux-user/syscall_defs.h | 25 
 4 files changed, 142 insertions(+), 7 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index a0e45b5..679f840 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -1827,6 +1827,78 @@ print_rt_sigprocmask(const struct syscallname *name,
 }
 #endif
 
+#ifdef TARGET_NR_syslog
+static void
+print_syslog_action(abi_ulong arg, int last)
+{
+const char *type;
+
+switch (arg) {
+case TARGET_SYSLOG_ACTION_CLOSE: {
+type = "SYSLOG_ACTION_CLOSE";
+break;
+}
+case TARGET_SYSLOG_ACTION_OPEN: {
+type = "SYSLOG_ACTION_OPEN";
+break;
+}
+case TARGET_SYSLOG_ACTION_READ: {
+type = "SYSLOG_ACTION_READ";
+break;
+}
+case TARGET_SYSLOG_ACTION_READ_ALL: {
+type = "SYSLOG_ACTION_READ_ALL";
+break;
+}
+case TARGET_SYSLOG_ACTION_READ_CLEAR: {
+type = "SYSLOG_ACTION_READ_CLEAR";
+break;
+}
+case TARGET_SYSLOG_ACTION_CLEAR: {
+type = "SYSLOG_ACTION_CLEAR";
+break;
+}
+case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
+type = "SYSLOG_ACTION_CONSOLE_OFF";
+break;
+}
+case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
+type = "SYSLOG_ACTION_CONSOLE_ON";
+break;
+}
+case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
+type = "SYSLOG_ACTION_CONSOLE_LEVEL";
+break;
+}
+case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
+type = "SYSLOG_ACTION_SIZE_UNREAD";
+break;
+}
+case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
+type = "SYSLOG_ACTION_SIZE_BUFFER";
+break;
+}
+default: {
+print_raw_param("%ld", arg, last);
+return;
+}
+}
+gemu_log("%s%s", type, get_comma(last));
+}
+
+static void
+print_syslog(const struct syscallname *name,
+abi_long arg0, abi_long arg1, abi_long arg2,
+abi_long arg3, abi_long arg4, abi_long arg5)
+{
+print_syscall_prologue(name);
+print_syslog_action(arg0, 0);
+print_pointer(arg1, 0);
+print_raw_param("%d", arg2, 1);
+print_syscall_epilogue(name);
+}
+#endif
+
 #ifdef TARGET_NR_mknod
 static void
 print_mknod(const struct syscallname *name,
diff --git a/linux-user/strace.list b/linux-user/strace.list
index f6dd044..2c7ad2b 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1486,7 +1486,7 @@
 { TARGET_NR_sys_kexec_load, "sys_kexec_load" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_syslog
-{ TARGET_NR_syslog, "syslog" , NULL, NULL, NULL },
+{ TARGET_NR_syslog, "syslog" , NULL, print

[Qemu-devel] [PULL v2 04/22] linux-user: Fix msgrcv() and msgsnd() syscalls support

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

If syscalls msgrcv() and msgsnd() fail, they return E2BIG, EACCES,
EAGAIN, EFAULT, EIDRM, EINTR, EINVAL, ENOMEM, or ENOMSG.

By examining negative scenarios of these syscalls for Mips, it was
established that ENOMSG does not have the same value accross all
platforms, but it is nevertheless not included for conversion in
the correspondant conversion table defined in linux-user/syscall.c.
This is certainly a bug, since it leads to the incorrect emulation
of msgrcv() and msgsnd() for scenarios involving ENOMSG.

This patch fixes this by extending the conversion table to include
ENOMSG.

Also, LTP test msgrcv04 will be fixed for some platforms.

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e031ecf..032cb76 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -790,6 +790,9 @@ static uint16_t 
host_to_target_errno_table[ERRNO_TABLE_SIZE] = {
 #ifdef ENOTRECOVERABLE
 [ENOTRECOVERABLE]  = TARGET_ENOTRECOVERABLE,
 #endif
+#ifdef ENOMSG
+[ENOMSG]= TARGET_ENOMSG,
+#endif
 };
 
 static inline int host_to_target_errno(int err)
-- 
2.1.4




[Qemu-devel] [PULL v2 01/22] linux-user: Add support for adjtimex() syscall

2016-10-18 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

This patch implements Qemu user mode adjtimex() syscall support.

Syscall adjtimex() reads and optionally sets parameters for a clock
adjustment algorithm used in network synchonization or similar scenarios.

Its declaration is:

int adjtimex(struct timex *buf);

The correspondent source code in the Linux kernel is at kernel/time.c,
line 206.

The Qemu implementation is based on invocation of host's adjtimex(), and
its key part is in the "TARGET_NR_adjtimex" case segment of the the main
switch statement of the function do_syscall(), in linux-user/syscalls.c. All
necessary conversions of the data structures from target to host and from
host to target are covered. Two new functions, target_to_host_timex() and
host_to_target_timex(), are provided for the purpose of such conversions.
For that purpose, the support for related structure "timex" had tp be added
to the file linux-user/syscall_defs.h, based on its definition in Linux
kernel. Also, the relevant support for "-strace" Qemu option is included
in files linux-user/strace.c and linux-user/strace.list.

This patch also fixes failures of LTP tests adjtimex01 and adjtimex02, if
executed in Qemu user mode.

Signed-off-by: Aleksandar Rikalo <aleksandar.rik...@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/strace.c   | 46 +
 linux-user/strace.list|  3 +-
 linux-user/syscall.c  | 87 ++-
 linux-user/syscall_defs.h | 28 +++
 4 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 1e51360..f37b386 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -577,6 +577,52 @@ print_syscall_ret_newselect(const struct syscallname 
*name, abi_long ret)
 }
 #endif
 
+/* special meanings of adjtimex()' non-negative return values */
+#define TARGET_TIME_OK   0   /* clock synchronized, no leap second */
+#define TARGET_TIME_INS  1   /* insert leap second */
+#define TARGET_TIME_DEL  2   /* delete leap second */
+#define TARGET_TIME_OOP  3   /* leap second in progress */
+#define TARGET_TIME_WAIT 4   /* leap second has occurred */
+#define TARGET_TIME_ERROR5   /* clock not synchronized */
+static void
+print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
+{
+const char *errstr = NULL;
+
+gemu_log(" = ");
+if (ret < 0) {
+gemu_log("-1 errno=%d", errno);
+errstr = target_strerror(-ret);
+if (errstr) {
+gemu_log(" (%s)", errstr);
+}
+} else {
+gemu_log(TARGET_ABI_FMT_ld, ret);
+switch (ret) {
+case TARGET_TIME_OK:
+gemu_log(" TIME_OK (clock synchronized, no leap second)");
+break;
+case TARGET_TIME_INS:
+gemu_log(" TIME_INS (insert leap second)");
+break;
+case TARGET_TIME_DEL:
+gemu_log(" TIME_DEL (delete leap second)");
+break;
+case TARGET_TIME_OOP:
+gemu_log(" TIME_OOP (leap second in progress)");
+break;
+case TARGET_TIME_WAIT:
+gemu_log(" TIME_WAIT (leap second has occurred)");
+break;
+case TARGET_TIME_ERROR:
+gemu_log(" TIME_ERROR (clock not synchronized)");
+break;
+}
+}
+
+gemu_log("\n");
+}
+
 UNUSED static struct flags access_flags[] = {
 FLAG_GENERIC(F_OK),
 FLAG_GENERIC(R_OK),
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 608f7e0..f6dd044 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -19,7 +19,8 @@
 { TARGET_NR_add_key, "add_key" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_adjtimex
-{ TARGET_NR_adjtimex, "adjtimex" , NULL, NULL, NULL },
+{ TARGET_NR_adjtimex, "adjtimex" , "%s(%p)", NULL,
+  print_syscall_ret_adjtimex },
 #endif
 #ifdef TARGET_NR_afs_syscall
 { TARGET_NR_afs_syscall, "afs_syscall" , NULL, NULL, NULL },
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 03339ba..0379b8a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #ifdef __ia64__
 int __clone2(int (*fn)(void *), void *child_stack_base,
  size_t stack_size, int flags, void *arg, ...);
@@ -6770,6 +6771,77 @@ static inline abi_long 
host_to_target_itimerspec(abi_ulong target_addr,
 return 0;
 }
 
+static inline abi_long target_to_host_timex(struct timex *host_tx,
+abi_long target_addr)
+{
+struct target_timex *target_tx;
+
+if (!lock_user

[Qemu-devel] [PULL v2 00/22] linux-user changes

2016-10-18 Thread riku . voipio
From: Riku Voipio <riku.voi...@linaro.org>

The following changes since commit 7bf59dfec4234e75e31b3f397374cb5bab1a5b2c:

  Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.8-20161017' into 
staging (2016-10-17 12:59:54 +0100)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git tags/pull-linux-user-20161018

for you to fetch changes up to cee1d8afec98e0e686c894b06982e08b8bf242ba:

  linux-user: disable unicore32 linux-user build (2016-10-18 11:57:57 +0300)


Linux-user changes, mostly bugfixes and adding support for some
new syscalls and some obscure syscalls as well. Includes some
missed patches from earlier rounds, and dropping unicore32 target.

v2: fix the syslog patch and test build with clang-3.8



Aleksandar Markovic (13):
  linux-user: Add support for adjtimex() syscall
  linux-user: Add support for ustat() syscall
  linux-user: Fix mq_open() syscall support
  linux-user: Fix msgrcv() and msgsnd() syscalls support
  linux-user: Fix socketcall() syscall support
  linux-user: Fix syslog() syscall support
  linux-user: Remove a duplicate item from strace.list
  linux-user: Add support for clock_adjtime() syscall
  linux-user: Add support for syncfs() syscall
  linux-user: Update mips_syscall_args[] array in main.c
  linux-user: Update ioctls definitions for Mips32
  linux-user: Redirect termbits.h for Mips64 to termbits.h for Mips32
  linux-user: Fix fadvise64() syscall support for Mips32

Dejan Jovicevic (2):
  linux-user: added support for preadv() system call.
  linux-user: added support for pwritev() system call.

Felix Janda (1):
  linux-user: use libc wrapper instead of direct mremap syscall

Laurent Vivier (2):
  linux-user: add kcmp() syscall
  linux-user: add RTA_PRIORITY in netlink

Peter Maydell (3):
  linux-user: sparc64: Use correct target SHMLBA in shmat()
  linux-user: Don't use alloca() for epoll_wait's epoll event array
  linux-user: Fix definition of target_sigevent for 32-bit guests

Riku Voipio (1):
  linux-user: disable unicore32 linux-user build

 configure|  36 +++
 default-configs/unicore32-linux-user.mak |   1 -
 linux-user/main.c|  24 +-
 linux-user/mips/syscall_nr.h |   2 +-
 linux-user/mips/termbits.h   |  12 +
 linux-user/mips64/termbits.h | 245 +---
 linux-user/mmap.c|  14 +-
 linux-user/sparc64/target_syscall.h  |   7 +
 linux-user/strace.c  | 233 +--
 linux-user/strace.list   |  13 +-
 linux-user/syscall.c | 379 ---
 linux-user/syscall_defs.h| 117 +++---
 12 files changed, 698 insertions(+), 385 deletions(-)
 delete mode 100644 default-configs/unicore32-linux-user.mak

-- 
2.1.4




Re: [Qemu-devel] [PULL 06/22] linux-user: Fix syslog() syscall support

2016-10-18 Thread Riku Voipio
On Mon, Oct 17, 2016 at 04:24:24PM +0300, riku.voi...@linaro.org wrote:
> From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
> 
> There are currently several problems related to syslog() support.
> 
> For example, if the second argument "bufp" of target syslog() syscall
> is NULL, the current implementation always returns error code EFAULT.
> However, NULL is a perfectly valid value for the second argument for
> many use cases of this syscall. This is, for example, visible from
> this excerpt of man page for syslog(2):
> 
> > EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is
> >NULL, or len is less than zero; or for type 8, the level is
> >outside the range 1 to 8).
> 
> Moreover, the argument "bufp" is ignored for all cases of values of the
> first argument, except 2, 3 and 4. This means that for such cases
> (the first argument is not 2, 3 or 4), there is no need to pass "buf"
> between host and target, and it can be set to NULL while calling host's
> syslog(), without loss of emulation accuracy.
> 
> Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the
> correct returned error code is EINVAL, not EFAULT.
> 
> All these details are reflected in this patch.
> 
> "#ifdef TARGET_NR_syslog" is also proprerly inserted when needed.
> 
> Support for Qemu's "-strace" switch for syslog() syscall is included too.
> 
> LTP tests syslog11 and syslog12 pass with this patch (while fail without
> it), on any platform.
> 
> Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
> Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
> ---
>  linux-user/strace.c   | 72 
> +++
>  linux-user/strace.list|  2 +-
>  linux-user/syscall.c  | 49 
>  linux-user/syscall_defs.h | 25 
>  4 files changed, 141 insertions(+), 7 deletions(-)
> 
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index a0e45b5..679f840 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -1827,6 +1827,78 @@ print_rt_sigprocmask(const struct syscallname *name,
>  }
>  #endif
>  
> +#ifdef TARGET_NR_syslog
> +static void
> +print_syslog_action(abi_ulong arg, int last)
> +{
> +const char *type;
> +
> +switch (arg) {
> +case TARGET_SYSLOG_ACTION_CLOSE: {
> +type = "SYSLOG_ACTION_CLOSE";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_OPEN: {
> +type = "SYSLOG_ACTION_OPEN";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_READ: {
> +type = "SYSLOG_ACTION_READ";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_READ_ALL: {
> +type = "SYSLOG_ACTION_READ_ALL";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_READ_CLEAR: {
> +type = "SYSLOG_ACTION_READ_CLEAR";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_CLEAR: {
> +type = "SYSLOG_ACTION_CLEAR";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_CONSOLE_OFF: {
> +type = "SYSLOG_ACTION_CONSOLE_OFF";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_CONSOLE_ON: {
> +type = "SYSLOG_ACTION_CONSOLE_ON";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_CONSOLE_LEVEL: {
> +type = "SYSLOG_ACTION_CONSOLE_LEVEL";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_SIZE_UNREAD: {
> +type = "SYSLOG_ACTION_SIZE_UNREAD";
> +break;
> +}
> +case TARGET_SYSLOG_ACTION_SIZE_BUFFER: {
> +type = "SYSLOG_ACTION_SIZE_BUFFER";
> +break;
> +}
> +default: {
> +print_raw_param("%ld", arg, last);
> +return;
> +}
> +}
> +gemu_log("%s%s", type, get_comma(last));
> +}
> +
> +static void
> +print_syslog(const struct syscallname *name,
> +abi_long arg0, abi_long arg1, abi_long arg2,
> +abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +print_syscall_prologue(name);
> +print_syslog_action(arg0, 0);
> +print_pointer(arg1, 0);
> +print_raw_param("%d", arg2, 1);
> +print_syscall_epilogue(name);
> +}
> +#endif
> +
>  #ifdef TARGET_NR_mknod
>  static void
>  print_mknod(const struct sysca

[Qemu-devel] [PULL 18/22] linux-user: Redirect termbits.h for Mips64 to termbits.h for Mips32

2016-10-17 Thread riku . voipio
From: Aleksandar Markovic <aleksandar.marko...@imgtec.com>

linux-user/mips64/termbits.h and linux-user/mips/termbits.h
originate from the same files in Linux kernel. There is no plan
to split original headers in Linux kernel into Mips32 and Mips64
versions any time soon. Therefore, it is better not to have
separate Mips32 and Mips64 variants in Qemu.

This patch makes these two files effectively the same, allowing the
mainenance by changing only a single file. (This is already done in
the same fashion for some other headers in same directories.)

Signed-off-by: Aleksandar Markovic <aleksandar.marko...@imgtec.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/mips64/termbits.h | 245 +--
 1 file changed, 1 insertion(+), 244 deletions(-)

diff --git a/linux-user/mips64/termbits.h b/linux-user/mips64/termbits.h
index d3a6cf8..d0a271e 100644
--- a/linux-user/mips64/termbits.h
+++ b/linux-user/mips64/termbits.h
@@ -1,245 +1,2 @@
-/* from asm/termbits.h */
+#include "../mips/termbits.h"
 
-#define TARGET_NCCS 23
-
-struct target_termios {
-unsigned int c_iflag;   /* input mode flags */
-unsigned int c_oflag;   /* output mode flags */
-unsigned int c_cflag;   /* control mode flags */
-unsigned int c_lflag;   /* local mode flags */
-unsigned char c_line;/* line discipline */
-unsigned char c_cc[TARGET_NCCS];/* control characters */
-};
-
-/* c_iflag bits */
-#define TARGET_IGNBRK  001
-#define TARGET_BRKINT  002
-#define TARGET_IGNPAR  004
-#define TARGET_PARMRK  010
-#define TARGET_INPCK   020
-#define TARGET_ISTRIP  040
-#define TARGET_INLCR   100
-#define TARGET_IGNCR   200
-#define TARGET_ICRNL   400
-#define TARGET_IUCLC   0001000
-#define TARGET_IXON0002000
-#define TARGET_IXANY   0004000
-#define TARGET_IXOFF   001
-#define TARGET_IMAXBEL 002
-#define TARGET_IUTF8   004
-
-/* c_oflag bits */
-#define TARGET_OPOST   001
-#define TARGET_OLCUC   002
-#define TARGET_ONLCR   004
-#define TARGET_OCRNL   010
-#define TARGET_ONOCR   020
-#define TARGET_ONLRET  040
-#define TARGET_OFILL   100
-#define TARGET_OFDEL   200
-#define TARGET_NLDLY   400
-#define   TARGET_NL0   000
-#define   TARGET_NL1   400
-#define TARGET_CRDLY   0003000
-#define   TARGET_CR0   000
-#define   TARGET_CR1   0001000
-#define   TARGET_CR2   0002000
-#define   TARGET_CR3   0003000
-#define TARGET_TABDLY  0014000
-#define   TARGET_TAB0  000
-#define   TARGET_TAB1  0004000
-#define   TARGET_TAB2  001
-#define   TARGET_TAB3  0014000
-#define   TARGET_XTABS 0014000
-#define TARGET_BSDLY   002
-#define   TARGET_BS0   000
-#define   TARGET_BS1   002
-#define TARGET_VTDLY   004
-#define   TARGET_VT0   000
-#define   TARGET_VT1   004
-#define TARGET_FFDLY   010
-#define   TARGET_FF0   000
-#define   TARGET_FF1   010
-
-/* c_cflag bit meaning */
-#define TARGET_CBAUD   0010017
-#define  TARGET_B0 000 /* hang up */
-#define  TARGET_B50001
-#define  TARGET_B75002
-#define  TARGET_B110   003
-#define  TARGET_B134   004
-#define  TARGET_B150   005
-#define  TARGET_B200   006
-#define  TARGET_B300   007
-#define  TARGET_B600   010
-#define  TARGET_B1200  011
-#define  TARGET_B1800  012
-#define  TARGET_B2400  013
-#define  TARGET_B4800  014
-#define  TARGET_B9600  015
-#define  TARGET_B19200 016
-#define  TARGET_B38400 017
-#define TARGET_EXTA B19200
-#define TARGET_EXTB B38400
-#define TARGET_CSIZE   060
-#define   TARGET_CS5   000
-#define   TARGET_CS6   020
-#define   TARGET_CS7   040
-#define   TARGET_CS8   060
-#define TARGET_CSTOPB  100
-#define TARGET_CREAD   200
-#define TARGET_PARENB  400
-#define TARGET_PARODD  0001000
-#define TARGET_HUPCL   0002000
-#define TARGET_CLOCAL  0004000
-#define TARGET_CBAUDEX 001
-#define  TARGET_BOTHER   001
-#define  TARGET_B57600   0010001
-#define  TARGET_B115200  0010002
-#define  TARGET_B230400  0010003
-#define  TARGET_B460800  0010004
-#define  TARGET_B50  0010005
-#define  TARGET_B576000  0010006
-#define  TARGET_B921600  0010007
-#define  TARGET_B100 0010010
-#define  TARGET_B1152000 0010011
-#define  TARGET_B150 0010012
-#define  TARGET_B200 0010013
-#define  TARGET_B250 0010014
-#define  TARGET_B300 0010015
-#define  TARGET_B350 0010016
-#define  TARGET_B400 0010017
-#define TARGET_CIBAUD00200360  /* input baud rate (not used) */
-#define TARGET_CMSPAR0100  /* mark or space (stick) parity */
-#define TARGET_CRTSCTS   0200  /* flow control */
-
-/* c_lflag bits */
-#define TARGET_ISIG001
-#define TARGET_ICANON  002
-#define TARGET_XCASE   004
-#define TARGET_ECHO0

[Qemu-devel] [PULL 21/22] linux-user: added support for pwritev() system call.

2016-10-17 Thread riku . voipio
From: Dejan Jovicevic <dejan.jovice...@rt-rk.com>

This system call performs the same task as the writev() system call,
with the exception of having the fourth argument, offset, which
specifes the file offset at which the input operation is to be performed.
Because of this, the pwritev() implementation is based on the writev()
implementation in linux-user mode.

But, since pwritev() is implemented in the kernel as a 5-argument syscall,
5 arguments are needed to be handled as input and passed to the host
syscall.

The pos_l and pos_h argument of the safe_pwritev() are of type unsigned
long, which can be of different sizes on different platforms. The input
arguments are converted to the appropriate host size when passed to
safe_pwritev().

Signed-off-by: Dejan Jovicevic <dejan.jovice...@rt-rk.com>
Signed-off-by: Riku Voipio <riku.voi...@linaro.org>
---
 linux-user/syscall.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 10c940c..2072b1f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -921,6 +921,8 @@ safe_syscall3(ssize_t, readv, int, fd, const struct iovec 
*, iov, int, iovcnt)
 safe_syscall3(ssize_t, writev, int, fd, const struct iovec *, iov, int, iovcnt)
 safe_syscall5(ssize_t, preadv, int, fd, const struct iovec *, iov, int, iovcnt,
   unsigned long, pos_l, unsigned long, pos_h)
+safe_syscall5(ssize_t, pwritev, int, fd, const struct iovec *, iov, int, 
iovcnt,
+  unsigned long, pos_l, unsigned long, pos_h)
 safe_syscall3(int, connect, int, fd, const struct sockaddr *, addr,
   socklen_t, addrlen)
 safe_syscall6(ssize_t, sendto, int, fd, const void *, buf, size_t, len,
@@ -10092,6 +10094,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 }
 break;
 #endif
+#if defined(TARGET_NR_pwritev)
+case TARGET_NR_pwritev:
+{
+struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
+if (vec != NULL) {
+ret = get_errno(safe_pwritev(arg1, vec, arg3, arg4, arg5));
+unlock_iovec(vec, arg2, arg3, 0);
+} else {
+ret = -host_to_target_errno(errno);
+   }
+}
+break;
+#endif
 case TARGET_NR_getsid:
 ret = get_errno(getsid(arg1));
 break;
-- 
2.1.4




  1   2   3   4   5   6   7   8   9   10   >