Skip to contentSkip to conversation

{alpha-}linux user improvements

PATCH Superseded Richard Henderson 4 participants 21 messages Jun 7, 2012 – Jun 22, 2012

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover {alpha-}linux user improvements

Changes v2-v3:
Fix fcntl translation table in O_CLOEXEC patch. The O_LARGEFILE entry could result in an end-of-table {0,0,0,0} marker.

Handle sigprocmask and getpriority properly for alpha.

Changes v1-v2:
Dropped -stracefile patch. That clearly needs more iteration in order to make everyone happy. I don't want the rest of this to get caught up in that.

Two patches that fix all of the mmap problems I've been able to find in the glibc testsuite. The iconv tests that load lots of shared libraries are particularly good at triggering both problems.

Handle O_CLOEXEC et al properly.

Handle pipe2 properly.

r~

Richard Henderson (9):
alpha-linux-user: Fix signal handling
alpha-linux-user: Work around hosted mmap allocation problems
alpha-linux-user: Handle TARGET_SSI_IEEE_RAISE_EXCEPTION properly
linux-user: Handle O_SYNC, O_NOATIME, O_CLOEXEC, O_PATH
linux-user: Allocate the right amount of space for non-fixed file
maps
linux-user: Translate pipe2 flags; add to strace
alpha-linux-user: Fix a3 error return with v0 error bypass.
alpha-linux-user: Properly handle the non-rt sigprocmask syscall.
alpha-linux-user: Fix the getpriority syscall

 linux-user/alpha/syscall_nr.h |    2 +-
 linux-user/main.c             |   15 ++--
 linux-user/mmap.c             |   30 ++++--
 linux-user/strace.c           |   12 ++-
 linux-user/strace.list        |    3 +
 linux-user/syscall.c          |  108 +++++++++++++++----
 linux-user/syscall_defs.h     |  236 +++++++++++++++++++++++------------------
 target-alpha/cpu.h            |   11 ++
 8 files changed, 273 insertions(+), 144 deletions(-)
Signature · 1 line
1.7.7.6
#1 lore raw

PATCH v3 1/9 alpha-linux-user: Fix signal handling

Proper signal numbers were not defined, and EXCP_INTERRUPT was unhandled, leading to all sorts of subtle confusion.

---
 linux-user/main.c         |    3 +++
 linux-user/syscall_defs.h |   41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletions(-)
linux-user/main.c +3 -0
index 49108b8..e81abb2 100644
@@ -2833,6 +2833,9 @@ void cpu_loop(CPUAlphaState *env)
         case EXCP_STQ_C:
             do_store_exclusive(env, env->error_code, trapnr - EXCP_STL_C);
             break;
+        case EXCP_INTERRUPT:
+            /* Just indicate that signals should be handled asap.  */
+            break;
         default:
             printf ("Unhandled trap: 0x%x\n", trapnr);
             cpu_dump_state(env, stderr, fprintf, 0);
linux-user/syscall_defs.h +40 -1

47 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#3 lore raw

PATCH v3 2/9 alpha-linux-user: Work around hosted mmap allocation problems

In reply to Richard Henderson
---
 target-alpha/cpu.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
target-alpha/cpu.h +11 -0
index 99f9ee1..0d87fa7 100644
@@ -40,9 +40,20 @@
 
 #define TARGET_PAGE_BITS 13
 
+#ifdef CONFIG_USER_ONLY
+/* ??? The kernel likes to give addresses in high memory.  If the host has
+   more virtual address space than the guest, this can lead to impossible
+   allocations.  Honor the long-standing assumption that only kernel addrs
+   are negative, but otherwise allow allocations anywhere.  This could lead
+   to tricky emulation problems for programs doing tagged addressing, but
+   that's far fewer than encounter the impossible allocation problem.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS	63
+#define TARGET_VIRT_ADDR_SPACE_BITS	63
+#else
 /* ??? EV4 has 34 phys addr bits, EV5 has 40, EV6 has 44.  */
 #define TARGET_PHYS_ADDR_SPACE_BITS	44
 #define TARGET_VIRT_ADDR_SPACE_BITS	(30 + TARGET_PAGE_BITS)
+#endif
 
 /* Alpha major type */
 enum {
Signature · 1 line
1.7.7.6
#10 lore raw

PATCH v3 3/9 alpha-linux-user: Handle TARGET_SSI_IEEE_RAISE_EXCEPTION properly

In reply to Richard Henderson

We weren't aggregating the exceptions, nor raising signals properly.

---
 linux-user/syscall.c |   61 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 51 insertions(+), 10 deletions(-)
linux-user/syscall.c +51 -10
index 539af3f..1cbbfbf 100644
@@ -7699,13 +7699,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = -TARGET_EOPNOTSUPP;
         switch (arg1) {
           case TARGET_SSI_IEEE_FP_CONTROL:
-          case TARGET_SSI_IEEE_RAISE_EXCEPTION:
             {
                 uint64_t swcr, fpcr, orig_fpcr;
 
-                if (get_user_u64 (swcr, arg2))
+                if (get_user_u64 (swcr, arg2)) {
                     goto efault;
-                orig_fpcr = cpu_alpha_load_fpcr (cpu_env);
+                }
+                orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
                 fpcr = orig_fpcr & FPCR_DYN_MASK;
 
                 /* Copied from linux ieee_swcr_to_fpcr.  */
@@ -7719,16 +7719,57 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                 fpcr |= (swcr & SWCR_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);
                 fpcr |= (~swcr & SWCR_TRAP_ENABLE_DNO) << 41;
 
-                cpu_alpha_store_fpcr (cpu_env, fpcr);
+                cpu_alpha_store_fpcr(cpu_env, fpcr);
                 ret = 0;
+            }
+            break;
+
+          case TARGET_SSI_IEEE_RAISE_EXCEPTION:
+            {
+                uint64_t exc, fpcr, orig_fpcr;
+                int si_code;
+
+                if (get_user_u64(exc, arg2)) {
+                    goto efault;
+                }
 
-                if (arg1 == TARGET_SSI_IEEE_RAISE_EXCEPTION) {
-                    /* Old exceptions are not signaled.  */
-                    fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK);
+                orig_fpcr = cpu_alpha_load_fpcr(cpu_env);
 
-                    /* If any exceptions set by this call, and are unmasked,
-                       send a signal.  */
-                    /* ??? FIXME */
+                /* We only add to the exception status here.  */
+                fpcr = orig_fpcr | ((exc & SWCR_STATUS_MASK) << 35);
+
+                cpu_alpha_store_fpcr(cpu_env, fpcr);
+                ret = 0;
+
+                /* Old exceptions are not signaled.  */
+                fpcr &= ~(orig_fpcr & FPCR_STATUS_MASK);
+
+                /* If any exceptions set by this call,
+                   and are unmasked, send a signal.  */
+                si_code = 0;
+                if ((fpcr & (FPCR_INE | FPCR_INED)) == FPCR_INE) {
+                    si_code = TARGET_FPE_FLTRES;
+                }
+                if ((fpcr & (FPCR_UNF | FPCR_UNFD)) == FPCR_UNF) {
+                    si_code = TARGET_FPE_FLTUND;
+                }
+                if ((fpcr & (FPCR_OVF | FPCR_OVFD)) == FPCR_OVF) {
+                    si_code = TARGET_FPE_FLTOVF;
+                }
+                if ((fpcr & (FPCR_DZE | FPCR_DZED)) == FPCR_DZE) {
+                    si_code = TARGET_FPE_FLTDIV;
+                }
+                if ((fpcr & (FPCR_INV | FPCR_INVD)) == FPCR_INV) {
+                    si_code = TARGET_FPE_FLTINV;
+                }
+                if (si_code != 0) {
+                    target_siginfo_t info;
+                    info.si_signo = SIGFPE;
+                    info.si_errno = 0;
+                    info.si_code = si_code;
+                    info._sifields._sigfault._addr
+                        = ((CPUArchState *)cpu_env)->pc;
+                    queue_signal((CPUArchState *)cpu_env, info.si_signo, &info);
                 }
             }
             break;
Signature · 1 line
1.7.7.6
#11 lore raw

PATCH v3 4/9 linux-user: Handle O_SYNC, O_NOATIME, O_CLOEXEC, O_PATH

In reply to Richard Henderson

And tidy up syscall_defs.h a little bit. For each target, only define the bits in arch/target/include/asm/fcntl.h, leaving the others to a new asm-generic section below.

---
 linux-user/strace.c       |   12 +++-
 linux-user/syscall.c      |   15 +++-
 linux-user/syscall_defs.h |  195 +++++++++++++++++++++-----------------------
 3 files changed, 118 insertions(+), 104 deletions(-)
linux-user/strace.c +11 -1
index 05a0d3e..6ec90e8 100644
@@ -371,11 +371,21 @@ UNUSED static struct flags open_flags[] = {
     FLAG_TARGET(O_NOCTTY),
     FLAG_TARGET(O_NOFOLLOW),
     FLAG_TARGET(O_NONBLOCK),      /* also O_NDELAY */
-    FLAG_TARGET(O_SYNC),
+    FLAG_TARGET(O_DSYNC),
+    FLAG_TARGET(__O_SYNC),
     FLAG_TARGET(O_TRUNC),
 #ifdef O_DIRECT
     FLAG_TARGET(O_DIRECT),
 #endif
+#ifdef O_NOATIME
+    FLAG_TARGET(O_NOATIME),
+#endif
+#ifdef O_CLOEXEC
+    FLAG_TARGET(O_CLOEXEC),
+#endif
+#ifdef O_PATH
+    FLAG_TARGET(O_PATH),
+#endif
     FLAG_END,
 };
 
linux-user/syscall.c +14 -1
index 1cbbfbf..8a454cc 100644
@@ -261,14 +261,27 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_TRUNC,     TARGET_O_TRUNC,     O_TRUNC,     O_TRUNC,     },
   { TARGET_O_APPEND,    TARGET_O_APPEND,    O_APPEND,    O_APPEND,    },
   { TARGET_O_NONBLOCK,  TARGET_O_NONBLOCK,  O_NONBLOCK,  O_NONBLOCK,  },
+  { TARGET_O_SYNC,      TARGET_O_DSYNC,     O_SYNC,      O_DSYNC,     },
   { TARGET_O_SYNC,      TARGET_O_SYNC,      O_SYNC,      O_SYNC,      },
   { TARGET_FASYNC,      TARGET_FASYNC,      FASYNC,      FASYNC,      },
   { TARGET_O_DIRECTORY, TARGET_O_DIRECTORY, O_DIRECTORY, O_DIRECTORY, },
   { TARGET_O_NOFOLLOW,  TARGET_O_NOFOLLOW,  O_NOFOLLOW,  O_NOFOLLOW,  },
-  { TARGET_O_LARGEFILE, TARGET_O_LARGEFILE, O_LARGEFILE, O_LARGEFILE, },
 #if defined(O_DIRECT)
   { TARGET_O_DIRECT,    TARGET_O_DIRECT,    O_DIRECT,    O_DIRECT,    },
 #endif
+#if defined(O_NOATIME)
+  { TARGET_O_NOATIME,   TARGET_O_NOATIME,   O_NOATIME,   O_NOATIME    },
+#endif
+#if defined(O_CLOEXEC)
+  { TARGET_O_CLOEXEC,   TARGET_O_CLOEXEC,   O_CLOEXEC,   O_CLOEXEC    },
+#endif
+#if defined(O_PATH)
+  { TARGET_O_PATH,      TARGET_O_PATH,      O_PATH,      O_PATH       },
+#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, },
+#endif
   { 0, 0, 0, 0 }
 };
 
linux-user/syscall_defs.h +93 -102

228 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#13 lore raw

PATCH v3 5/9 linux-user: Allocate the right amount of space for non-fixed file maps

In reply to Richard Henderson

If we let the kernel handle the implementation of mmap_find_vma, via an anon mmap, we must use the size as indicated by the user and not the size truncated to the filesize.

This happens often in ld.so, where we initially mmap the file to the size of the text+data+bss to reserve an area, then mmap+fixed over the top to properly handle data and bss.

---
 linux-user/mmap.c |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)
linux-user/mmap.c +19 -11
index d9468fe..b412e3f 100644
@@ -382,7 +382,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                      int flags, int fd, abi_ulong offset)
 {
     abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len;
-    unsigned long host_start;
 
     mmap_lock();
 #ifdef DEBUG_MMAP
@@ -421,6 +420,19 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
     if (len == 0)
         goto the_end;
     real_start = start & qemu_host_page_mask;
+    host_offset = offset & qemu_host_page_mask;
+
+    /* If the user is asking for the kernel to find a location, do that
+       before we truncate the length for mapping files below.  */
+    if (!(flags & MAP_FIXED)) {
+        host_len = len + offset - host_offset;
+        host_len = HOST_PAGE_ALIGN(host_len);
+        start = mmap_find_vma(real_start, host_len);
+        if (start == (abi_ulong)-1) {
+            errno = ENOMEM;
+            goto fail;
+        }
+    }
 
     /* When mapping files into a memory area larger than the file, accesses
        to pages beyond the file size will cause a SIGBUS. 
@@ -453,27 +465,23 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
     }
 
     if (!(flags & MAP_FIXED)) {
-        abi_ulong mmap_start;
+        unsigned long host_start;
         void *p;
-        host_offset = offset & qemu_host_page_mask;
+
         host_len = len + offset - host_offset;
         host_len = HOST_PAGE_ALIGN(host_len);
-        mmap_start = mmap_find_vma(real_start, host_len);
-        if (mmap_start == (abi_ulong)-1) {
-            errno = ENOMEM;
-            goto fail;
-        }
+
         /* Note: we prefer to control the mapping address. It is
            especially important if qemu_host_page_size >
            qemu_real_host_page_size */
-        p = mmap(g2h(mmap_start),
-                 host_len, prot, flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
+        p = mmap(g2h(start), host_len, prot,
+                 flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
         if (p == MAP_FAILED)
             goto fail;
         /* update start so that it points to the file position at 'offset' */
         host_start = (unsigned long)p;
         if (!(flags & MAP_ANONYMOUS)) {
-            p = mmap(g2h(mmap_start), len, prot, 
+            p = mmap(g2h(start), len, prot,
                      flags | MAP_FIXED, fd, host_offset);
             host_start += offset - host_offset;
         }
Signature · 1 line
1.7.7.6
#14 lore raw

PATCH v3 6/9 linux-user: Translate pipe2 flags; add to strace

In reply to Richard Henderson
---
 linux-user/strace.list |    3 +++
 linux-user/syscall.c   |    3 ++-
 2 files changed, 5 insertions(+), 1 deletions(-)
linux-user/strace.list +3 -0
index a7eeaef..af3c6a0 100644
@@ -1527,3 +1527,6 @@
 #ifdef TARGET_NR_sync_file_range2
 { TARGET_NR_sync_file_range2, "sync_file_range2", NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_pipe2
+{ TARGET_NR_pipe2, "pipe2", NULL, NULL, NULL },
+#endif
linux-user/syscall.c +2 -1
index 8a454cc..1a12f14 100644
@@ -5595,7 +5595,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #ifdef TARGET_NR_pipe2
     case TARGET_NR_pipe2:
-        ret = do_pipe(cpu_env, arg1, arg2, 1);
+        ret = do_pipe(cpu_env, arg1,
+                      target_to_host_bitmask(arg2, fcntl_flags_tbl), 1);
         break;
 #endif
     case TARGET_NR_times:
Signature · 1 line
1.7.7.6
#16 lore raw

PATCH v3 7/9 alpha-linux-user: Fix a3 error return with v0 error bypass.

In reply to Richard Henderson

We were failing to initialize a3 for syscalls that bypass the negative return value error check.

---
 linux-user/main.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
linux-user/main.c +5 -7
index e81abb2..605018a 100644
@@ -2758,13 +2758,11 @@ void cpu_loop(CPUAlphaState *env)
                     break;
                 }
                 /* Syscall writes 0 to V0 to bypass error check, similar
-                   to how this is handled internal to Linux kernel.  */
-                if (env->ir[IR_V0] == 0) {
-                    env->ir[IR_V0] = sysret;
-                } else {
-                    env->ir[IR_V0] = (sysret < 0 ? -sysret : sysret);
-                    env->ir[IR_A3] = (sysret < 0);
-                }
+                   to how this is handled internal to Linux kernel.
+                   (Ab)use trapnr temporarily as boolean indicating error.  */
+                trapnr = (env->ir[IR_V0] != 0 && sysret < 0);
+                env->ir[IR_V0] = (trapnr ? -sysret : sysret);
+                env->ir[IR_A3] = trapnr;
                 break;
             case 0x86:
                 /* IMB */
Signature · 1 line
1.7.7.6
#19 lore raw

PATCH v3 9/9 alpha-linux-user: Fix the getpriority syscall

In reply to Richard Henderson

Alpha uses unbiased priority values in the syscall, with the a3 return value signaling error conditions. Therefore, properly interpret the libc getpriority as needed for the guest rather than passing the host value through unchanged.

---
 linux-user/syscall.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
linux-user/syscall.c +15 -5
index bc77b79..bc65c32 100644
@@ -218,7 +218,6 @@ _syscall3(int, sys_getdents, uint, fd, struct linux_dirent *, dirp, uint, count)
 #if defined(TARGET_NR_getdents64) && defined(__NR_getdents64)
 _syscall3(int, sys_getdents64, uint, fd, struct linux_dirent64 *, dirp, uint, count);
 #endif
-_syscall2(int, sys_getpriority, int, which, int, who);
 #if defined(TARGET_NR__llseek) && defined(__NR_llseek)
 _syscall5(int, _llseek,  uint,  fd, ulong, hi, ulong, lo,
           loff_t *, res, uint, wh);
@@ -6447,10 +6446,21 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
     case TARGET_NR_getpriority:
-        /* libc does special remapping of the return value of
-         * sys_getpriority() so it's just easiest to call
-         * sys_getpriority() directly rather than through libc. */
-        ret = get_errno(sys_getpriority(arg1, arg2));
+        /* Note that negative values are valid for getpriority, so we must
+           differentiate based on errno settings.  */
+        errno = 0;
+        ret = getpriority(arg1, arg2);
+        if (ret == -1 && errno != 0) {
+            ret = get_errno(errno);
+            break;
+        }
+#ifdef TARGET_ALPHA
+        /* Return value is the unbiased priority.  Signal no error.  */
+        ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0;
+#else
+        /* Return value is a biased priority to avoid negative numbers.  */
+        ret = 20 - ret;
+#endif
         break;
     case TARGET_NR_setpriority:
         ret = get_errno(setpriority(arg1, arg2, arg3));
Signature · 1 line
1.7.7.6
#17 lore raw

PATCH v3 8/9 alpha-linux-user: Properly handle the non-rt sigprocmask syscall.

In reply to Richard Henderson

Name the syscall properly for QEMU, kernel source notwithstanding. Fix syntax errors in the code thus enabled within do_syscall.

---
 linux-user/alpha/syscall_nr.h |    2 +-
 linux-user/syscall.c          |    9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
linux-user/alpha/syscall_nr.h +1 -1
index f6284db..49648a1 100644
@@ -46,7 +46,7 @@
 #define TARGET_NR_open		 45
 #define TARGET_NR_osf_old_sigaction	 46	/* not implemented */
 #define TARGET_NR_getxgid		 47
-#define TARGET_NR_osf_sigprocmask	 48
+#define TARGET_NR_sigprocmask	 48
 #define TARGET_NR_osf_getlogin	 49	/* not implemented */
 #define TARGET_NR_osf_setlogin	 50	/* not implemented */
 #define TARGET_NR_acct		 51
linux-user/syscall.c +5 -4
index 1a12f14..bc77b79 100644
@@ -5880,12 +5880,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             mask = arg2;
             target_to_host_old_sigset(&set, &mask);
 
-            ret = get_errno(sigprocmask(how, &set, &oldset));
-
-            if (!is_error(ret)) {
+            ret = sigprocmask(how, &set, &oldset);
+            if (is_error(ret)) {
+                ret = get_errno(ret);
+            } else {
                 host_to_target_old_sigset(&mask, &oldset);
                 ret = mask;
-                ((CPUAlphaState *)cpu_env)->[IR_V0] = 0; /* force no error */
+                ((CPUAlphaState *)cpu_env)->ir[IR_V0] = 0; /* force no error */
             }
 #else
             sigset_t set, oldset, *set_ptr;
Signature · 1 line
1.7.7.6
#20 lore raw
In reply to Richard Henderson

Ping?

r~

Quoted 45 lines · Richard Henderson

Changes v2-v3:
Fix fcntl translation table in O_CLOEXEC patch. The O_LARGEFILE entry could result in an end-of-table {0,0,0,0} marker.

Handle sigprocmask and getpriority properly for alpha.

Changes v1-v2:
Dropped -stracefile patch. That clearly needs more iteration in order to make everyone happy. I don't want the rest of this to get caught up in that.

Two patches that fix all of the mmap problems I've been able to find in the glibc testsuite. The iconv tests that load lots of shared libraries are particularly good at triggering both problems.

Handle O_CLOEXEC et al properly.

Handle pipe2 properly.

r~

Richard Henderson (9):
alpha-linux-user: Fix signal handling
alpha-linux-user: Work around hosted mmap allocation problems
alpha-linux-user: Handle TARGET_SSI_IEEE_RAISE_EXCEPTION properly
linux-user: Handle O_SYNC, O_NOATIME, O_CLOEXEC, O_PATH
linux-user: Allocate the right amount of space for non-fixed file
maps
linux-user: Translate pipe2 flags; add to strace
alpha-linux-user: Fix a3 error return with v0 error bypass.
alpha-linux-user: Properly handle the non-rt sigprocmask syscall.
alpha-linux-user: Fix the getpriority syscall

 linux-user/alpha/syscall_nr.h |    2 +-
 linux-user/main.c             |   15 ++--
 linux-user/mmap.c             |   30 ++++--
 linux-user/strace.c           |   12 ++-
 linux-user/strace.list        |    3 +
 linux-user/syscall.c          |  108 +++++++++++++++----
 linux-user/syscall_defs.h     |  236 +++++++++++++++++++++++------------------
 target-alpha/cpu.h            |   11 ++
 8 files changed, 273 insertions(+), 144 deletions(-)
#4 lore raw

Re: [Qemu-devel] [PATCH 2/9] alpha-linux-user: Work around hosted mmap allocation problems

In reply to Richard Henderson

Am 08.06.2012 00:24, schrieb Richard Henderson:

Quoted 20 lines
---
 target-alpha/cpu.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
target-alpha/cpu.h +7 -0
index 99f9ee1..0d87fa7 100644
@@ -40,9 +40,20 @@
 
 #define TARGET_PAGE_BITS 13
 
+#ifdef CONFIG_USER_ONLY
+/* ??? The kernel likes to give addresses in high memory.  If the host has
+   more virtual address space than the guest, this can lead to impossible
+   allocations.  Honor the long-standing assumption that only kernel addrs
+   are negative, but otherwise allow allocations anywhere.  This could lead
+   to tricky emulation problems for programs doing tagged addressing, but
+   that's far fewer than encounter the impossible allocation problem.  */

target-alpha/cpu.h line 59

Quoted 10 lines
target-alpha/cpu.h +4 -0
+#define TARGET_PHYS_ADDR_SPACE_BITS	63
+#define TARGET_VIRT_ADDR_SPACE_BITS	63
+#else
 /* ??? EV4 has 34 phys addr bits, EV5 has 40, EV6 has 44.  */
 #define TARGET_PHYS_ADDR_SPACE_BITS	44
 #define TARGET_VIRT_ADDR_SPACE_BITS	(30 + TARGET_PAGE_BITS)
+#endif
 
 /* Alpha major type */
 enum {

This looks fishy to me... why should the kernel use a bigger address space than hardware? For arm on x86_64 such a workaround was not necessary iirc.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw

Re: [Qemu-devel] [PATCH 2/9] alpha-linux-user: Work around hosted mmap allocation problems

Quoted 3 lines · Andreas Färber

This looks fishy to me... why should the kernel use a bigger address space than hardware? For arm on x86_64 such a workaround was not necessary iirc.

I can tell you what I observe. That with a certain sequence of allocations the x86_64 kernel will quit accepting an address "near" (1<<38) as a hint for where to allocate memory and begin returning an addresses near (1<<48). Further, the logic in find_mmap_vma tries about 5 times (with different hints) to get a target-page-aligned address at a lower address, all of which fail: the kernel continues to return the (1<<48) address. At which point one wonders why we should keep refusing the (1<<48) address when the target is in fact 64-bit capable.

I believe the host vs target page size difference plays a part in this, which is why you wouldn't see this on arm.

All of the other targets with page size larger than 4k are 64 bit, and set TARGET_VIRT_ADDR_SPACE_BITS to 64. So Alpha was unique in being an 8k page size with T_B_A_S_B < 48, and so probably unique in being able to tickle this problem.

r~

#6 lore raw

Re: [Qemu-devel] [PATCH 2/9] alpha-linux-user: Work around hosted mmap allocation problems

Quoted 9 lines · Richard Henderson
Quoted 3 lines · Andreas Färber

This looks fishy to me... why should the kernel use a bigger address space than hardware? For arm on x86_64 such a workaround was not necessary iirc.

I can tell you what I observe. That with a certain sequence of allocations the x86_64 kernel will quit accepting an address "near" (1<<38) as a hint for where to allocate memory and begin returning an addresses near (1<<48).

Hrm, does -R work for you? :)

Alex

#7 lore raw

Re: [Qemu-devel] [PATCH 2/9] alpha-linux-user: Work around hosted mmap allocation problems

Quoted 9 lines · Alexander Graf
Quoted 5 lines · Richard Henderson
Quoted 3 lines · Andreas Färber

This looks fishy to me... why should the kernel use a bigger address space than hardware? For arm on x86_64 such a workaround was not necessary iirc.

Quoted 6 lines
Quoted 4 lines

I can tell you what I observe. That with a certain sequence of allocations the x86_64 kernel will quit accepting an address "near" (1<<38) as a hint for where to allocate memory and begin returning an addresses near (1<<48).

Hrm, does -R work for you? :)

Lol.

Actually I've tried it a couple of times: -R 32G. And, no, it doesn't work very well. ;-)

r~

#8 lore raw

Re: [Qemu-devel] [PATCH 2/9] alpha-linux-user: Work around hosted mmap allocation problems

Quoted 15 lines · Richard Henderson
Quoted 14 lines · Alexander Graf
Quoted 9 lines · Richard Henderson
Quoted 3 lines · Andreas Färber

This looks fishy to me... why should the kernel use a bigger address space than hardware? For arm on x86_64 such a workaround was not necessary iirc.

I can tell you what I observe. That with a certain sequence of allocations the x86_64 kernel will quit accepting an address "near" (1<<38) as a hint for where to allocate memory and begin returning an addresses near (1<<48).

Quoted 5 lines
Quoted 1 line

Hrm, does -R work for you? :)

Lol.

Actually I've tried it a couple of times: -R 32G.

32G is way too much. Do you have to preallocate such a big address space? Usually 1G should be good enough for most programs, no?

Alex

Quoted 5 lines

And, no, it
doesn't work very well. ;-)

r~

#9 lore raw

Re: [Qemu-devel] [PATCH 2/9] alpha-linux-user: Work around hosted mmap allocation problems

Quoted 2 lines · Alexander Graf

32G is way too much. Do you have to preallocate such a big address space? Usually 1G should be good enough for most programs, no?

The default start to .text is 6G for alpha executables, so anything less than that + reasonable room will fail for obvious reasons.

One would think that e.g. 8G would be good enough, giving 2G above the executable for brk and shared library mapping, but... failure. Alternately, there's some other problem with -R that needs to be investigated.

That said, problems with ld.so erroring out with ENOMEM went away with this patch, so...

r~

#12 lore raw

Re: [Qemu-devel] [PATCH 4/9] linux-user: Handle O_SYNC, O_NOATIME, O_CLOEXEC, O_PATH

In reply to Richard Henderson
Quoted 3 lines · Richard Henderson

And tidy up syscall_defs.h a little bit.  For each target, only define the bits in arch/target/include/asm/fcntl.h, leaving the others to a new asm-generic section below.

This patch is doing two things at once -- could you separate the refactoring and the "support more O_*" bits, please?

-- PMM

#18 lore raw

Re: [Qemu-devel] [PATCH 8/9] alpha-linux-user: Properly handle the non-rt sigprocmask syscall.

In reply to Richard Henderson

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 5886

Quoted 11 lines · Richard Henderson
linux-user/syscall.c +4 -3
@@ -5880,12 +5880,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             mask = arg2;
             target_to_host_old_sigset(&set, &mask);
 
-            ret = get_errno(sigprocmask(how, &set, &oldset));
-
-            if (!is_error(ret)) {
+            ret = sigprocmask(how, &set, &oldset);
+            if (is_error(ret)) {
+                ret = get_errno(ret);
+            } else {

This looks kinda bogus. get_errno() is supposed to be used on something which is a (value-or-negative-for-target-errno) value, eg what you get out of get_errno(). If you're just testing the straight return value from the host sigprocmask() then "if (ret == -1)" or similar would be better.

-- PMM