qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power
@ 2014-08-13 19:04 Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 01/13] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2 Tom Musta
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

This series of patches is the result of executing the Linux Test Program
(LTP) System Call bucket (https://github.com/linux-test-project/ltp)
on the 64 bit big and little endian linux user mode targets for Power.

Some of the changes are not technically unique to Power, but are effectively
so.  For example, Power may be the only runtime that uses the ipc system call
as a hub for other system calls (semctl, semop, ...).

The series is dependent on my previous patch series that adds signal handler
support on PPC64 (http://lists.nongnu.org/archive/html/qemu-ppc/2014-06/msg00802.html).
That series has gone into Alex's ppcnext branch for QEMU 2.2.

V2: Addressing review comments from Peter Maydell.

V3: Included "linux-user: Move get_ppc64_abi" so that this series applies cleanly 
to the current git master.

Tom Musta (13):
  linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2
  linux-user: Dereference Pointer Argument to ipc/semctl Sys Call
  linux-user: Properly Handle semun Structure In Cross-Endian
    Situations
  linux-user: Make ipc syscall's third argument an abi_long
  linux-user: Conditionally Pass Attribute Pointer to mq_open()
  linux-user: Detect Negative Message Sizes in msgsnd System Call
  linux-user: Handle NULL sched_param argument to sched_*
  linux-user: Detect fault in sched_rr_get_interval
  linux-user: Move get_ppc64_abi
  linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2
  linux-user: clock_nanosleep errno Handling on PPC
  linux-user: Support target-to-host translation of mlockall argument
  linux-user: writev Partial Writes

 linux-user/aarch64/syscall.h    |    3 +
 linux-user/alpha/syscall.h      |    3 +
 linux-user/arm/syscall.h        |    4 ++
 linux-user/cris/syscall.h       |    3 +
 linux-user/elfload.c            |    9 ----
 linux-user/i386/syscall.h       |    3 +
 linux-user/m68k/syscall.h       |    4 ++
 linux-user/microblaze/syscall.h |    3 +
 linux-user/mips/syscall.h       |    3 +
 linux-user/mips64/syscall.h     |    3 +
 linux-user/openrisc/syscall.h   |    4 ++
 linux-user/ppc/syscall.h        |    4 ++
 linux-user/ppc/target_cpu.h     |   10 ++++
 linux-user/s390x/syscall.h      |    3 +
 linux-user/sh4/syscall.h        |    4 ++
 linux-user/signal.c             |   12 ++++-
 linux-user/sparc/syscall.h      |    3 +
 linux-user/sparc64/syscall.h    |    3 +
 linux-user/syscall.c            |  100 +++++++++++++++++++++++++++++++++-----
 linux-user/unicore32/syscall.h  |    4 ++
 linux-user/x86_64/syscall.h     |    3 +
 21 files changed, 164 insertions(+), 24 deletions(-)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 01/13] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 02/13] linux-user: Dereference Pointer Argument to ipc/semctl Sys Call Tom Musta
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The 64 bit PowerPC platforms eliminate the _unused1 and _unused2
elements of the semid_ds structure from <sys/sem.h>.  So eliminate
these from the target_semid_ds structure.

Signed-off-by: Tom Musta <tommusta@gmail.com>
---

 linux-user/syscall.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a50229d..540001c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2419,9 +2419,13 @@ struct target_semid_ds
 {
   struct target_ipc_perm sem_perm;
   abi_ulong sem_otime;
+#if !defined(TARGET_PPC64)
   abi_ulong __unused1;
+#endif
   abi_ulong sem_ctime;
+#if !defined(TARGET_PPC64)
   abi_ulong __unused2;
+#endif
   abi_ulong sem_nsems;
   abi_ulong __unused3;
   abi_ulong __unused4;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 02/13] linux-user: Dereference Pointer Argument to ipc/semctl Sys Call
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 01/13] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2 Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 03/13] linux-user: Properly Handle semun Structure In Cross-Endian Situations Tom Musta
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

When the ipc system call is used to wrap a semctl system call,
the ptr argument to ipc needs to be dereferenced prior to passing
it to the semctl handler.  This is because the fourth argument to
semctl is a union and not a pointer to a union.

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V2:  This is unchanged from V1.  I *did* review the QEMU, glibc and kernel code
looking for some problems but did not find anything.  I also did fairly comprehesive
testing of semctl on 4 targets (ppc-linux-user, ppc64-linux-user, ppc64le-linux-user,
x86_64-linux-user) on 3 different host platforms (x86-64 Ubuntu, PPC64 RHEL 6 (BE) and
PPC64 Ubuntu 14.04 (LE)); this provided a broad coverage of co-endian and cross endian
situations.

 linux-user/syscall.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 540001c..229c482 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3135,9 +3135,15 @@ static abi_long do_ipc(unsigned int call, int first,
         ret = get_errno(semget(first, second, third));
         break;
 
-    case IPCOP_semctl:
-        ret = do_semctl(first, second, third, (union target_semun)(abi_ulong) ptr);
+    case IPCOP_semctl: {
+        /* The semun argument to semctl is passed by value, so dereference the
+         * ptr argument. */
+        abi_ulong atptr;
+        get_user_ual(atptr, (abi_ulong)ptr);
+        ret = do_semctl(first, second, third,
+                (union target_semun)(abi_ulong) atptr);
         break;
+    }
 
     case IPCOP_msgget:
         ret = get_errno(msgget(first, second));
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 03/13] linux-user: Properly Handle semun Structure In Cross-Endian Situations
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 01/13] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2 Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 02/13] linux-user: Dereference Pointer Argument to ipc/semctl Sys Call Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 04/13] linux-user: Make ipc syscall's third argument an abi_long Tom Musta
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The semun union used in the semctl system call contains both an int (val) and
pointers.  In cross-endian situations on 64 bit targets, the value passed to
semctl is an 8 byte (abi_long) value and thus does not have the 4-byte val
field in the correct location.  In order to rectify this, the other half
of the union must be accessed.  This is achieved in code by performing
a byte swap on the entire 8 byte union, followed by a 4-byte swap of the
first half.

Also, eliminate an extraneous (dead) line of code that sets target_su.val in
the IPC_SET/IPC_GET case.

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V2: Reworked per comments from Peter.

 linux-user/syscall.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 229c482..bee1f4e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2647,9 +2647,18 @@ static inline abi_long do_semctl(int semid, int semnum, int cmd,
     switch( cmd ) {
 	case GETVAL:
 	case SETVAL:
-            arg.val = tswap32(target_su.val);
+            /* In 64 bit cross-endian situations, we will erroneously pick up
+             * the wrong half of the union for the "val" element.  To rectify
+             * this, the entire 8-byte structure is byteswapped, followed by
+	     * a swap of the 4 byte val field. In other cases, the data is
+	     * already in proper host byte order. */
+	    if (sizeof(target_su.val) != (sizeof(target_su.buf))) {
+		target_su.buf = tswapal(target_su.buf);
+		arg.val = tswap32(target_su.val);
+	    } else {
+		arg.val = target_su.val;
+	    }
             ret = get_errno(semctl(semid, semnum, cmd, arg));
-            target_su.val = tswap32(arg.val);
             break;
 	case GETALL:
 	case SETALL:
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 04/13] linux-user: Make ipc syscall's third argument an abi_long
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (2 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 03/13] linux-user: Properly Handle semun Structure In Cross-Endian Situations Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 05/13] linux-user: Conditionally Pass Attribute Pointer to mq_open() Tom Musta
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

For those target ABIs that use the ipc system call (e.g. POWER),
the third argument is used in the shmat path as a pointer.  It
therefore must be declared as an abi_long (versus int) so that
the address bits are not lost in truncation.  In fact, all arguments
to do_ipc should be declared as abit_long.

In fact, it makes more sense for all of the arguments to be declared
as abi_long (except call).

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V2: Changed all do_ipc arguments (except "call") to abi_long per Peter
Maydell's review.

 linux-user/syscall.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bee1f4e..3a4f432 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3125,8 +3125,8 @@ static inline abi_long do_shmdt(abi_ulong shmaddr)
 #ifdef TARGET_NR_ipc
 /* ??? This only works with linear mappings.  */
 /* do_ipc() must return target values and target errnos. */
-static abi_long do_ipc(unsigned int call, int first,
-                       int second, int third,
+static abi_long do_ipc(unsigned int call, abi_long first,
+                       abi_long second, abi_long third,
                        abi_long ptr, abi_long fifth)
 {
     int version;
@@ -3148,9 +3148,9 @@ static abi_long do_ipc(unsigned int call, int first,
         /* The semun argument to semctl is passed by value, so dereference the
          * ptr argument. */
         abi_ulong atptr;
-        get_user_ual(atptr, (abi_ulong)ptr);
+        get_user_ual(atptr, ptr);
         ret = do_semctl(first, second, third,
-                (union target_semun)(abi_ulong) atptr);
+                (union target_semun) atptr);
         break;
     }
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 05/13] linux-user: Conditionally Pass Attribute Pointer to mq_open()
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (3 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 04/13] linux-user: Make ipc syscall's third argument an abi_long Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 06/13] linux-user: Detect Negative Message Sizes in msgsnd System Call Tom Musta
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The mq_open system call takes an optional struct mq_attr pointer
argument in the fourth position.  This pointer is used when O_CREAT
is specified in the flags (second) argument.  It may be NULL, in
which case the queue is created with implementation defined attributes.

Change the code to properly handle the case when NULL is passed in the
arg4 position.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---

 linux-user/syscall.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3a4f432..04f4820 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9081,12 +9081,16 @@ 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;
+            struct mq_attr posix_mq_attr, *attrp;
 
             p = lock_user_string(arg1 - 1);
-            if (arg4 != 0)
+            if (arg4 != 0) {
                 copy_from_user_mq_attr (&posix_mq_attr, arg4);
-            ret = get_errno(mq_open(p, arg2, arg3, &posix_mq_attr));
+                attrp = &posix_mq_attr;
+            } else {
+                attrp = 0;
+            }
+            ret = get_errno(mq_open(p, arg2, arg3, attrp));
             unlock_user (p, arg1, 0);
         }
         break;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 06/13] linux-user: Detect Negative Message Sizes in msgsnd System Call
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (4 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 05/13] linux-user: Conditionally Pass Attribute Pointer to mq_open() Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 07/13] linux-user: Handle NULL sched_param argument to sched_* Tom Musta
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The msgsnd system call takes an argument that describes the message
size (msgsz) and is of type size_t.  The system call should set
errno to EINVAL in the event that a negative message size is passed.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---

 linux-user/syscall.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 04f4820..79fb3cb 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2874,12 +2874,16 @@ struct target_msgbuf {
 };
 
 static inline abi_long do_msgsnd(int msqid, abi_long msgp,
-                                 unsigned int msgsz, int msgflg)
+                                 ssize_t msgsz, int msgflg)
 {
     struct target_msgbuf *target_mb;
     struct msgbuf *host_mb;
     abi_long ret = 0;
 
+    if (msgsz < 0) {
+        return -TARGET_EINVAL;
+    }
+
     if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0))
         return -TARGET_EFAULT;
     host_mb = malloc(msgsz+sizeof(long));
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 07/13] linux-user: Handle NULL sched_param argument to sched_*
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (5 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 06/13] linux-user: Detect Negative Message Sizes in msgsnd System Call Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 08/13] linux-user: Detect fault in sched_rr_get_interval Tom Musta
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The sched_getparam, sched_setparam and sched_setscheduler system
calls take a pointer argument to a sched_param structure.  When
this pointer is null, errno should be set to EINVAL.

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V2: Including sched_setscheduler in the changes per Peter Maydell's
review.

 linux-user/syscall.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 79fb3cb..49b8a07 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7702,6 +7702,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             struct sched_param *target_schp;
             struct sched_param schp;
 
+            if (arg2 == 0) {
+                return -TARGET_EINVAL;
+            }
             if (!lock_user_struct(VERIFY_READ, target_schp, arg2, 1))
                 goto efault;
             schp.sched_priority = tswap32(target_schp->sched_priority);
@@ -7713,6 +7716,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             struct sched_param *target_schp;
             struct sched_param schp;
+
+            if (arg2 == 0) {
+                return -TARGET_EINVAL;
+            }
             ret = get_errno(sched_getparam(arg1, &schp));
             if (!is_error(ret)) {
                 if (!lock_user_struct(VERIFY_WRITE, target_schp, arg2, 0))
@@ -7726,6 +7733,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         {
             struct sched_param *target_schp;
             struct sched_param schp;
+            if (arg3 == 0) {
+                return -TARGET_EINVAL;
+            }
             if (!lock_user_struct(VERIFY_READ, target_schp, arg3, 1))
                 goto efault;
             schp.sched_priority = tswap32(target_schp->sched_priority);
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 08/13] linux-user: Detect fault in sched_rr_get_interval
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (6 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 07/13] linux-user: Handle NULL sched_param argument to sched_* Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 09/13] linux-user: Move get_ppc64_abi Tom Musta
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

Properly detect a fault when attempting to store into an invalid
struct timespec pointer.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
V2: Peter has observed that there are other call sites that may need to
be fixed.  I will address that in future patch(es).

 linux-user/syscall.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 49b8a07..a20c2f7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7760,7 +7760,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             struct timespec ts;
             ret = get_errno(sched_rr_get_interval(arg1, &ts));
             if (!is_error(ret)) {
-                host_to_target_timespec(arg2, &ts);
+                ret = host_to_target_timespec(arg2, &ts);
             }
         }
         break;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 09/13] linux-user: Move get_ppc64_abi
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (7 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 08/13] linux-user: Detect fault in sched_rr_get_interval Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 10/13] linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2 Tom Musta
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The get_ppc64_abi is used to determine the ELF ABI (i.e. V1 or V2). This
routine is currently implemented in the linux-user/elfload.c file but
is useful in other scenarios.  Move the routine to a more generally
available location (linux-user/ppc/target_cpu.h).

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V3: new patch

 linux-user/elfload.c        |    9 ---------
 linux-user/ppc/target_cpu.h |   10 ++++++++++
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 60777fe..bea803b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -824,8 +824,6 @@ static uint32_t get_elf_hwcap2(void)
         NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
     } while (0)
 
-static inline uint32_t get_ppc64_abi(struct image_info *infop);
-
 static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
 {
     _regs->gpr[1] = infop->start_stack;
@@ -1205,13 +1203,6 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i
 
 #include "elf.h"
 
-#ifdef TARGET_PPC
-static inline uint32_t get_ppc64_abi(struct image_info *infop)
-{
-  return infop->elf_flags & EF_PPC64_ABI;
-}
-#endif
-
 struct exec
 {
     unsigned int a_info;   /* Use macros N_MAGIC, etc for access */
diff --git a/linux-user/ppc/target_cpu.h b/linux-user/ppc/target_cpu.h
index 9cc0c3b..26f4ba2 100644
--- a/linux-user/ppc/target_cpu.h
+++ b/linux-user/ppc/target_cpu.h
@@ -38,4 +38,14 @@ static inline void cpu_set_tls(CPUPPCState *env, target_ulong newtls)
 #endif
 }
 
+#ifndef EF_PPC64_ABI
+#define EF_PPC64_ABI           0x3
+#endif
+
+static inline uint32_t get_ppc64_abi(struct image_info *infop)
+{
+  return infop->elf_flags & EF_PPC64_ABI;
+}
+
+
 #endif
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 10/13] linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (8 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 09/13] linux-user: Move get_ppc64_abi Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 11/13] linux-user: clock_nanosleep errno Handling on PPC Tom Musta
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The ELF V2 ABI for PPC64 defines MINSIGSTKSZ as 4096 bytes whereas it was
2048 previously.

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V2: Define and use TARGET_MINSIGSTKSZ constants from the various
linux-user/$ARCH/syscall.h files (per Peter Maydell's review).

 linux-user/aarch64/syscall.h    |    1 +
 linux-user/alpha/syscall.h      |    1 +
 linux-user/arm/syscall.h        |    2 ++
 linux-user/cris/syscall.h       |    1 +
 linux-user/i386/syscall.h       |    1 +
 linux-user/m68k/syscall.h       |    2 ++
 linux-user/microblaze/syscall.h |    1 +
 linux-user/mips/syscall.h       |    1 +
 linux-user/mips64/syscall.h     |    1 +
 linux-user/openrisc/syscall.h   |    2 ++
 linux-user/ppc/syscall.h        |    2 ++
 linux-user/s390x/syscall.h      |    1 +
 linux-user/sh4/syscall.h        |    2 ++
 linux-user/signal.c             |   12 +++++++++++-
 linux-user/sparc/syscall.h      |    1 +
 linux-user/sparc64/syscall.h    |    1 +
 linux-user/unicore32/syscall.h  |    2 ++
 linux-user/x86_64/syscall.h     |    1 +
 18 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/linux-user/aarch64/syscall.h b/linux-user/aarch64/syscall.h
index 18f44a8..d1f4823 100644
--- a/linux-user/aarch64/syscall.h
+++ b/linux-user/aarch64/syscall.h
@@ -8,3 +8,4 @@ struct target_pt_regs {
 #define UNAME_MACHINE "aarch64"
 #define UNAME_MINIMUM_RELEASE "3.8.0"
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ       2048
diff --git a/linux-user/alpha/syscall.h b/linux-user/alpha/syscall.h
index ed13d9a..3adedeb 100644
--- a/linux-user/alpha/syscall.h
+++ b/linux-user/alpha/syscall.h
@@ -252,3 +252,4 @@ struct target_pt_regs {
 #define TARGET_UAC_NOPRINT		1
 #define TARGET_UAC_NOFIX		2
 #define TARGET_UAC_SIGBUS		4
+#define TARGET_MINSIGSTKSZ              4096
diff --git a/linux-user/arm/syscall.h b/linux-user/arm/syscall.h
index e0d2cc3..cdadb0c 100644
--- a/linux-user/arm/syscall.h
+++ b/linux-user/arm/syscall.h
@@ -44,3 +44,5 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
+
+#define TARGET_MINSIGSTKSZ 2048
diff --git a/linux-user/cris/syscall.h b/linux-user/cris/syscall.h
index f5783c0..a75bcc4 100644
--- a/linux-user/cris/syscall.h
+++ b/linux-user/cris/syscall.h
@@ -39,5 +39,6 @@ struct target_pt_regs {
 };
 
 #define TARGET_CLONE_BACKWARDS2
+#define TARGET_MINSIGSTKSZ 2048
 
 #endif
diff --git a/linux-user/i386/syscall.h b/linux-user/i386/syscall.h
index 9bfc1ad..acf6856 100644
--- a/linux-user/i386/syscall.h
+++ b/linux-user/i386/syscall.h
@@ -147,3 +147,4 @@ struct target_vm86plus_struct {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ 2048
diff --git a/linux-user/m68k/syscall.h b/linux-user/m68k/syscall.h
index 889eaf7..f8553f8 100644
--- a/linux-user/m68k/syscall.h
+++ b/linux-user/m68k/syscall.h
@@ -18,4 +18,6 @@ struct target_pt_regs {
 #define UNAME_MACHINE "m68k"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
+#define TARGET_MINSIGSTKSZ 2048
+
 void do_m68k_simcall(CPUM68KState *, int);
diff --git a/linux-user/microblaze/syscall.h b/linux-user/microblaze/syscall.h
index 5b5f6b4..2a5e160 100644
--- a/linux-user/microblaze/syscall.h
+++ b/linux-user/microblaze/syscall.h
@@ -49,5 +49,6 @@ struct target_pt_regs {
 };
 
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ      2048
 
 #endif
diff --git a/linux-user/mips/syscall.h b/linux-user/mips/syscall.h
index 5bc5696..0b4662c 100644
--- a/linux-user/mips/syscall.h
+++ b/linux-user/mips/syscall.h
@@ -228,3 +228,4 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ 2048
diff --git a/linux-user/mips64/syscall.h b/linux-user/mips64/syscall.h
index a7f5a58..39b8bed 100644
--- a/linux-user/mips64/syscall.h
+++ b/linux-user/mips64/syscall.h
@@ -225,3 +225,4 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ      2048
diff --git a/linux-user/openrisc/syscall.h b/linux-user/openrisc/syscall.h
index c3b36da..e5e6180 100644
--- a/linux-user/openrisc/syscall.h
+++ b/linux-user/openrisc/syscall.h
@@ -23,3 +23,5 @@ struct target_pt_regs {
 
 #define UNAME_MACHINE "openrisc"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
+
+#define TARGET_MINSIGSTKSZ 2048
diff --git a/linux-user/ppc/syscall.h b/linux-user/ppc/syscall.h
index db92bbe..5311cc6 100644
--- a/linux-user/ppc/syscall.h
+++ b/linux-user/ppc/syscall.h
@@ -69,3 +69,5 @@ struct target_revectored_struct {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS
+
+#define TARGET_MINSIGSTKSZ 2048
diff --git a/linux-user/s390x/syscall.h b/linux-user/s390x/syscall.h
index aaad512..b11a3b2 100644
--- a/linux-user/s390x/syscall.h
+++ b/linux-user/s390x/syscall.h
@@ -24,3 +24,4 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_CLONE_BACKWARDS2
+#define TARGET_MINSIGSTKSZ        2048
diff --git a/linux-user/sh4/syscall.h b/linux-user/sh4/syscall.h
index ccd2216..285ecf3 100644
--- a/linux-user/sh4/syscall.h
+++ b/linux-user/sh4/syscall.h
@@ -11,3 +11,5 @@ struct target_pt_regs {
 
 #define UNAME_MACHINE "sh4"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
+
+#define TARGET_MINSIGSTKSZ 2048
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 1141054..26929c5 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -617,6 +617,15 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
     {
         struct target_sigaltstack *uss;
         struct target_sigaltstack ss;
+        size_t minstacksize = TARGET_MINSIGSTKSZ;
+
+#if defined(TARGET_PPC64)
+        /* ELF V2 for PPC64 has a 4K minimum stack size for signal handlers */
+        struct image_info *image = ((TaskState *)thread_cpu->opaque)->info;
+        if (get_ppc64_abi(image) > 1) {
+            minstacksize = 4096;
+        }
+#endif
 
 	ret = -TARGET_EFAULT;
         if (!lock_user_struct(VERIFY_READ, uss, uss_addr, 1)) {
@@ -642,8 +651,9 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
             ss.ss_sp = 0;
 	} else {
             ret = -TARGET_ENOMEM;
-            if (ss.ss_size < MINSIGSTKSZ)
+            if (ss.ss_size < minstacksize) {
                 goto out;
+            }
 	}
 
         target_sigaltstack_used.ss_sp = ss.ss_sp;
diff --git a/linux-user/sparc/syscall.h b/linux-user/sparc/syscall.h
index 9549ea0..ae40744 100644
--- a/linux-user/sparc/syscall.h
+++ b/linux-user/sparc/syscall.h
@@ -15,3 +15,4 @@ struct target_pt_regs {
  * and copy_thread().
  */
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ      4096
diff --git a/linux-user/sparc64/syscall.h b/linux-user/sparc64/syscall.h
index 82b1680..816a00f 100644
--- a/linux-user/sparc64/syscall.h
+++ b/linux-user/sparc64/syscall.h
@@ -16,3 +16,4 @@ struct target_pt_regs {
  * and copy_thread().
  */
 #define TARGET_CLONE_BACKWARDS
+#define TARGET_MINSIGSTKSZ      4096
diff --git a/linux-user/unicore32/syscall.h b/linux-user/unicore32/syscall.h
index f7e5525..3ed6237 100644
--- a/linux-user/unicore32/syscall.h
+++ b/linux-user/unicore32/syscall.h
@@ -53,4 +53,6 @@ struct target_pt_regs {
 #define UNAME_MACHINE "UniCore-II"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
+#define TARGET_MINSIGSTKSZ 2048
+
 #endif /* __UC32_SYSCALL_H__ */
diff --git a/linux-user/x86_64/syscall.h b/linux-user/x86_64/syscall.h
index e03b5a0..5828b91 100644
--- a/linux-user/x86_64/syscall.h
+++ b/linux-user/x86_64/syscall.h
@@ -97,3 +97,4 @@ struct target_msqid64_ds {
 #define TARGET_ARCH_SET_FS 0x1002
 #define TARGET_ARCH_GET_FS 0x1003
 #define TARGET_ARCH_GET_GS 0x1004
+#define TARGET_MINSIGSTKSZ 2048
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 11/13] linux-user: clock_nanosleep errno Handling on PPC
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (9 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 10/13] linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2 Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 12/13] linux-user: Support target-to-host translation of mlockall argument Tom Musta
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The clock_nanosleep syscall is unusual in that it returns positive
numbers in error handling situations, versus returning -1 and setting
errno, or returning a negative errno value.  On POWER, the kernel will
set the SO bit of CR0 to indicate failure in a syscall.  QEMU has
generic handling to do this for syscalls with standard return values.

Add special case code for clock_nanosleep to handle CR0 properly.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
V2: Eliminated redundant "#if defined" condition per Peter Maydell's
review.

 linux-user/syscall.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index a20c2f7..fc828ae 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8999,6 +8999,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = get_errno(clock_nanosleep(arg1, arg2, &ts, arg4 ? &ts : NULL));
         if (arg4)
             host_to_target_timespec(arg4, &ts);
+
+#if defined(TARGET_PPC)
+        /* clock_nanosleep is odd in that it returns positive errno values.
+         * On PPC, CR0 bit 3 should be set in such a situation. */
+        if (ret) {
+            ((CPUPPCState *)cpu_env)->crf[0] |= 1;
+        }
+#endif
         break;
     }
 #endif
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 12/13] linux-user: Support target-to-host translation of mlockall argument
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (10 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 11/13] linux-user: clock_nanosleep errno Handling on PPC Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 13/13] linux-user: writev Partial Writes Tom Musta
  2014-08-14 13:30 ` [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Riku Voipio
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

The argument to the mlockall system call is not necessarily the same on
all platforms and thus may require translation prior to passing to the
host.

For example, PowerPC 64 bit platforms define values for MCL_CURRENT
(0x2000) and MCL_FUTURE (0x4000) which are different from Intel platforms
(0x1 and 0x2, respectively)

Signed-off-by: Tom Musta <tommusta@gmail.com>
---
V2: Per Peter Maydell's review, added a complete set of TARGET_MCL_*
macros in the various linux-user/$ARCH/syscall.h files.

 linux-user/aarch64/syscall.h    |    2 ++
 linux-user/alpha/syscall.h      |    2 ++
 linux-user/arm/syscall.h        |    2 ++
 linux-user/cris/syscall.h       |    2 ++
 linux-user/i386/syscall.h       |    2 ++
 linux-user/m68k/syscall.h       |    2 ++
 linux-user/microblaze/syscall.h |    2 ++
 linux-user/mips/syscall.h       |    2 ++
 linux-user/mips64/syscall.h     |    2 ++
 linux-user/openrisc/syscall.h   |    2 ++
 linux-user/ppc/syscall.h        |    2 ++
 linux-user/s390x/syscall.h      |    2 ++
 linux-user/sh4/syscall.h        |    2 ++
 linux-user/sparc/syscall.h      |    2 ++
 linux-user/sparc64/syscall.h    |    2 ++
 linux-user/syscall.c            |   17 ++++++++++++++++-
 linux-user/unicore32/syscall.h  |    2 ++
 linux-user/x86_64/syscall.h     |    2 ++
 18 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/linux-user/aarch64/syscall.h b/linux-user/aarch64/syscall.h
index d1f4823..dc72a15 100644
--- a/linux-user/aarch64/syscall.h
+++ b/linux-user/aarch64/syscall.h
@@ -9,3 +9,5 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "3.8.0"
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ       2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/alpha/syscall.h b/linux-user/alpha/syscall.h
index 3adedeb..245cff2 100644
--- a/linux-user/alpha/syscall.h
+++ b/linux-user/alpha/syscall.h
@@ -253,3 +253,5 @@ struct target_pt_regs {
 #define TARGET_UAC_NOFIX		2
 #define TARGET_UAC_SIGBUS		4
 #define TARGET_MINSIGSTKSZ              4096
+#define TARGET_MLOCKALL_MCL_CURRENT     0x2000
+#define TARGET_MLOCKALL_MCL_FUTURE      0x4000
diff --git a/linux-user/arm/syscall.h b/linux-user/arm/syscall.h
index cdadb0c..3844a96 100644
--- a/linux-user/arm/syscall.h
+++ b/linux-user/arm/syscall.h
@@ -46,3 +46,5 @@ struct target_pt_regs {
 #define TARGET_CLONE_BACKWARDS
 
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/cris/syscall.h b/linux-user/cris/syscall.h
index a75bcc4..2957b0d 100644
--- a/linux-user/cris/syscall.h
+++ b/linux-user/cris/syscall.h
@@ -40,5 +40,7 @@ struct target_pt_regs {
 
 #define TARGET_CLONE_BACKWARDS2
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
 
 #endif
diff --git a/linux-user/i386/syscall.h b/linux-user/i386/syscall.h
index acf6856..906aaac 100644
--- a/linux-user/i386/syscall.h
+++ b/linux-user/i386/syscall.h
@@ -148,3 +148,5 @@ struct target_vm86plus_struct {
 
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/m68k/syscall.h b/linux-user/m68k/syscall.h
index f8553f8..9218493 100644
--- a/linux-user/m68k/syscall.h
+++ b/linux-user/m68k/syscall.h
@@ -19,5 +19,7 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
 
 void do_m68k_simcall(CPUM68KState *, int);
diff --git a/linux-user/microblaze/syscall.h b/linux-user/microblaze/syscall.h
index 2a5e160..3c1ed27 100644
--- a/linux-user/microblaze/syscall.h
+++ b/linux-user/microblaze/syscall.h
@@ -50,5 +50,7 @@ struct target_pt_regs {
 
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ      2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
 
 #endif
diff --git a/linux-user/mips/syscall.h b/linux-user/mips/syscall.h
index 0b4662c..35ca23b 100644
--- a/linux-user/mips/syscall.h
+++ b/linux-user/mips/syscall.h
@@ -229,3 +229,5 @@ struct target_pt_regs {
 
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/mips64/syscall.h b/linux-user/mips64/syscall.h
index 39b8bed..6733107 100644
--- a/linux-user/mips64/syscall.h
+++ b/linux-user/mips64/syscall.h
@@ -226,3 +226,5 @@ struct target_pt_regs {
 
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ      2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/openrisc/syscall.h b/linux-user/openrisc/syscall.h
index e5e6180..8ac0365 100644
--- a/linux-user/openrisc/syscall.h
+++ b/linux-user/openrisc/syscall.h
@@ -25,3 +25,5 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/ppc/syscall.h b/linux-user/ppc/syscall.h
index 5311cc6..0daf5cd 100644
--- a/linux-user/ppc/syscall.h
+++ b/linux-user/ppc/syscall.h
@@ -71,3 +71,5 @@ struct target_revectored_struct {
 #define TARGET_CLONE_BACKWARDS
 
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 0x2000
+#define TARGET_MLOCKALL_MCL_FUTURE  0x4000
diff --git a/linux-user/s390x/syscall.h b/linux-user/s390x/syscall.h
index b11a3b2..35f170a 100644
--- a/linux-user/s390x/syscall.h
+++ b/linux-user/s390x/syscall.h
@@ -25,3 +25,5 @@ struct target_pt_regs {
 
 #define TARGET_CLONE_BACKWARDS2
 #define TARGET_MINSIGSTKSZ        2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/sh4/syscall.h b/linux-user/sh4/syscall.h
index 285ecf3..7aa4f23 100644
--- a/linux-user/sh4/syscall.h
+++ b/linux-user/sh4/syscall.h
@@ -13,3 +13,5 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
diff --git a/linux-user/sparc/syscall.h b/linux-user/sparc/syscall.h
index ae40744..58573b9 100644
--- a/linux-user/sparc/syscall.h
+++ b/linux-user/sparc/syscall.h
@@ -16,3 +16,5 @@ struct target_pt_regs {
  */
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ      4096
+#define TARGET_MLOCKALL_MCL_CURRENT 0x2000
+#define TARGET_MLOCKALL_MCL_FUTURE  0x4000
diff --git a/linux-user/sparc64/syscall.h b/linux-user/sparc64/syscall.h
index 816a00f..8398d3f 100644
--- a/linux-user/sparc64/syscall.h
+++ b/linux-user/sparc64/syscall.h
@@ -17,3 +17,5 @@ struct target_pt_regs {
  */
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MINSIGSTKSZ      4096
+#define TARGET_MLOCKALL_MCL_CURRENT 0x2000
+#define TARGET_MLOCKALL_MCL_FUTURE  0x4000
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index fc828ae..edc48e1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4937,6 +4937,21 @@ static inline abi_long host_to_target_itimerspec(abi_ulong target_addr,
     return 0;
 }
 
+#if defined(TARGET_NR_mlockall)
+static inline int target_to_host_mlockall_arg(int arg)
+{
+    int result = 0;
+
+    if (arg & TARGET_MLOCKALL_MCL_CURRENT) {
+        result |= MCL_CURRENT;
+    }
+    if (arg & TARGET_MLOCKALL_MCL_FUTURE) {
+        result |= MCL_FUTURE;
+    }
+    return result;
+}
+#endif
+
 #if defined(TARGET_NR_stat64) || defined(TARGET_NR_newfstatat)
 static inline abi_long host_to_target_stat64(void *cpu_env,
                                              abi_ulong target_addr,
@@ -6786,7 +6801,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #endif
 #ifdef TARGET_NR_mlockall
     case TARGET_NR_mlockall:
-        ret = get_errno(mlockall(arg1));
+        ret = get_errno(mlockall(target_to_host_mlockall_arg(arg1)));
         break;
 #endif
 #ifdef TARGET_NR_munlockall
diff --git a/linux-user/unicore32/syscall.h b/linux-user/unicore32/syscall.h
index 3ed6237..385a975 100644
--- a/linux-user/unicore32/syscall.h
+++ b/linux-user/unicore32/syscall.h
@@ -54,5 +54,7 @@ struct target_pt_regs {
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
 
 #endif /* __UC32_SYSCALL_H__ */
diff --git a/linux-user/x86_64/syscall.h b/linux-user/x86_64/syscall.h
index 5828b91..88b3c3f 100644
--- a/linux-user/x86_64/syscall.h
+++ b/linux-user/x86_64/syscall.h
@@ -98,3 +98,5 @@ struct target_msqid64_ds {
 #define TARGET_ARCH_GET_FS 0x1003
 #define TARGET_ARCH_GET_GS 0x1004
 #define TARGET_MINSIGSTKSZ 2048
+#define TARGET_MLOCKALL_MCL_CURRENT 1
+#define TARGET_MLOCKALL_MCL_FUTURE  2
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [V3 PATCH 13/13] linux-user: writev Partial Writes
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (11 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 12/13] linux-user: Support target-to-host translation of mlockall argument Tom Musta
@ 2014-08-13 19:04 ` Tom Musta
  2014-08-14 13:30 ` [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Riku Voipio
  13 siblings, 0 replies; 15+ messages in thread
From: Tom Musta @ 2014-08-13 19:04 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Tom Musta, riku.voipio, agraf

Although not technically not required by POSIX, the writev system call will
typically write out its buffers individually.  That is, if the first buffer
is written successfully, but the second buffer pointer is invalid, then
the first chuck will be written and its size is returned.

Signed-off-by: Tom Musta <tommusta@gmail.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
V2: Use bool instead of int for "bad_address" per Peter Maydell's review.

 linux-user/syscall.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index edc48e1..fb54f0e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1798,6 +1798,7 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr,
     abi_ulong total_len, max_len;
     int i;
     int err = 0;
+    bool bad_address = false;
 
     if (count == 0) {
         errno = 0;
@@ -1838,9 +1839,20 @@ static struct iovec *lock_iovec(int type, abi_ulong target_addr,
             vec[i].iov_base = 0;
         } else {
             vec[i].iov_base = lock_user(type, base, len, copy);
+            /* If the first buffer pointer is bad, this is a fault.  But
+             * subsequent bad buffers will result in a partial write; this
+             * is realized by filling the vector with null pointers and
+             * zero lengths. */
             if (!vec[i].iov_base) {
-                err = EFAULT;
-                goto fail;
+                if (i == 0) {
+                    err = EFAULT;
+                    goto fail;
+                } else {
+                    bad_address = true;
+                }
+            }
+            if (bad_address) {
+                len = 0;
             }
             if (len > max_len - total_len) {
                 len = max_len - total_len;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power
  2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
                   ` (12 preceding siblings ...)
  2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 13/13] linux-user: writev Partial Writes Tom Musta
@ 2014-08-14 13:30 ` Riku Voipio
  13 siblings, 0 replies; 15+ messages in thread
From: Riku Voipio @ 2014-08-14 13:30 UTC (permalink / raw)
  To: Tom Musta; +Cc: riku.voipio, qemu-ppc, qemu-devel, agraf

Hi,

On Wed, Aug 13, 2014 at 02:04:35PM -0500, Tom Musta wrote:
> This series of patches is the result of executing the Linux Test Program
> (LTP) System Call bucket (https://github.com/linux-test-project/ltp)
> on the 64 bit big and little endian linux user mode targets for Power.
 
> Some of the changes are not technically unique to Power, but are effectively
> so.  For example, Power may be the only runtime that uses the ipc system call
> as a hub for other system calls (semctl, semop, ...).
> 
> The series is dependent on my previous patch series that adds signal handler
> support on PPC64 (http://lists.nongnu.org/archive/html/qemu-ppc/2014-06/msg00802.html).
> That series has gone into Alex's ppcnext branch for QEMU 2.2.
> 
> V2: Addressing review comments from Peter Maydell.
> 
> V3: Included "linux-user: Move get_ppc64_abi" so that this series applies cleanly 
> to the current git master.

Thanks, All applied to:

https://git.linaro.org/people/riku.voipio/qemu.git/shortlog/refs/heads/linux-user-for-upstream

> Tom Musta (13):
>   linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2
>   linux-user: Dereference Pointer Argument to ipc/semctl Sys Call
>   linux-user: Properly Handle semun Structure In Cross-Endian
>     Situations
>   linux-user: Make ipc syscall's third argument an abi_long
>   linux-user: Conditionally Pass Attribute Pointer to mq_open()
>   linux-user: Detect Negative Message Sizes in msgsnd System Call
>   linux-user: Handle NULL sched_param argument to sched_*
>   linux-user: Detect fault in sched_rr_get_interval
>   linux-user: Move get_ppc64_abi
>   linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2
>   linux-user: clock_nanosleep errno Handling on PPC
>   linux-user: Support target-to-host translation of mlockall argument
>   linux-user: writev Partial Writes
> 
>  linux-user/aarch64/syscall.h    |    3 +
>  linux-user/alpha/syscall.h      |    3 +
>  linux-user/arm/syscall.h        |    4 ++
>  linux-user/cris/syscall.h       |    3 +
>  linux-user/elfload.c            |    9 ----
>  linux-user/i386/syscall.h       |    3 +
>  linux-user/m68k/syscall.h       |    4 ++
>  linux-user/microblaze/syscall.h |    3 +
>  linux-user/mips/syscall.h       |    3 +
>  linux-user/mips64/syscall.h     |    3 +
>  linux-user/openrisc/syscall.h   |    4 ++
>  linux-user/ppc/syscall.h        |    4 ++
>  linux-user/ppc/target_cpu.h     |   10 ++++
>  linux-user/s390x/syscall.h      |    3 +
>  linux-user/sh4/syscall.h        |    4 ++
>  linux-user/signal.c             |   12 ++++-
>  linux-user/sparc/syscall.h      |    3 +
>  linux-user/sparc64/syscall.h    |    3 +
>  linux-user/syscall.c            |  100 +++++++++++++++++++++++++++++++++-----
>  linux-user/unicore32/syscall.h  |    4 ++
>  linux-user/x86_64/syscall.h     |    3 +
>  21 files changed, 164 insertions(+), 24 deletions(-)
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-08-14 13:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-13 19:04 [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 01/13] linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2 Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 02/13] linux-user: Dereference Pointer Argument to ipc/semctl Sys Call Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 03/13] linux-user: Properly Handle semun Structure In Cross-Endian Situations Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 04/13] linux-user: Make ipc syscall's third argument an abi_long Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 05/13] linux-user: Conditionally Pass Attribute Pointer to mq_open() Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 06/13] linux-user: Detect Negative Message Sizes in msgsnd System Call Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 07/13] linux-user: Handle NULL sched_param argument to sched_* Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 08/13] linux-user: Detect fault in sched_rr_get_interval Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 09/13] linux-user: Move get_ppc64_abi Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 10/13] linux-user: Minimum Sig Handler Stack Size for PPC64 ELF V2 Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 11/13] linux-user: clock_nanosleep errno Handling on PPC Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 12/13] linux-user: Support target-to-host translation of mlockall argument Tom Musta
2014-08-13 19:04 ` [Qemu-devel] [V3 PATCH 13/13] linux-user: writev Partial Writes Tom Musta
2014-08-14 13:30 ` [Qemu-devel] [V3 PATCH 00/13] target-ppc: Linux-User Mode Bug Fixes for Power Riku Voipio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).