Skip to contentSkip to conversation

Multi-level page tables and userland mapping fixes, v3

PATCH Applied Richard Henderson 8 participants 23 messages Mar 11, 2010 – Mar 17, 2010

lore
Share & tools
lore
#0 lore raw

cover Multi-level page tables and userland mapping fixes, v3

Changes since v2:
* Fix two errors pointed out by pbrook: l1_map size in system mode, and h2g_valid definition for 64-on-32-bit.
* Assertions that addresses are not outside the bounds of the guest address space.
* Re-base vs master, after l1_map_phys changes.

r~

Richard Henderson (6):
Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h. Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.
linux-user: Use h2g_valid in qemu_vmalloc.
linux-user: Fix mmap_find_vma returning invalid addresses. Implement multi-level page tables.
Fix last page errors in page_check_range and page_set_flags.

 cpu-all.h               |   23 ++-
 exec.c                  |  522 ++++++++++++++++++++++++++++-------------------
 linux-user/main.c       |   11 +-
 linux-user/mmap.c       |  111 ++++++++---
 linux-user/qemu.h       |    2 -
 target-alpha/cpu.h      |    4 +-
 target-arm/cpu.h        |    3 +
 target-cris/cpu.h       |    3 +
 target-i386/cpu.h       |   11 +
 target-m68k/cpu.h       |    3 +
 target-microblaze/cpu.h |    3 +
 target-mips/mips-defs.h |    4 +
 target-ppc/cpu.h        |   17 ++
 target-s390x/cpu.h      |    5 +
 target-sh4/cpu.h        |    3 +
 target-sparc/cpu.h      |    8 +
 16 files changed, 474 insertions(+), 259 deletions(-)
#11 lore raw

PATCH 6/6 Fix last page errors in page_check_range and page_set_flags.

The addr < end comparison prevents iterating over the last page in the guest address space; an iteration based on length avoids this problem.

At the same time, assert that the given address is in the guest address space.

---
 exec.c |   54 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 18 deletions(-)
exec.c +36 -18
index 5455a74..245535a 100644
@@ -2315,27 +2315,35 @@ int page_get_flags(target_ulong address)
     return p->flags;
 }
 
-/* modify the flags of a page and invalidate the code if
-   necessary. The flag PAGE_WRITE_ORG is positioned automatically
-   depending on PAGE_WRITE */
+/* Modify the flags of a page and invalidate the code if necessary.
+   The flag PAGE_WRITE_ORG is positioned automatically depending
+   on PAGE_WRITE.  The mmap_lock should already be held.  */
 void page_set_flags(target_ulong start, target_ulong end, int flags)
 {
-    PageDesc *p;
-    target_ulong addr;
+    target_ulong addr, len;
+
+    /* This function should never be called with addresses outside the
+       guest address space.  If this assert fires, it probably indicates
+       a missing call to h2g_valid.  */
+#if HOST_LONG_BITS > L1_MAP_ADDR_SPACE_BITS
+    assert(end < (1ul << L1_MAP_ADDR_SPACE_BITS));
+#endif
+    assert(start < end);
 
-    /* mmap_lock should already be held.  */
     start = start & TARGET_PAGE_MASK;
     end = TARGET_PAGE_ALIGN(end);
-    if (flags & PAGE_WRITE)
+
+    if (flags & PAGE_WRITE) {
         flags |= PAGE_WRITE_ORG;
-    for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
-        p = page_find_alloc(addr >> TARGET_PAGE_BITS);
-        /* We may be called for host regions that are outside guest
-           address space.  */
-        if (!p)
-            return;
-        /* if the write protection is set, then we invalidate the code
-           inside */
+    }
+
+    for (addr = start, len = end - start;
+         len != 0;
+         len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {
+        PageDesc *p = page_find_alloc(addr >> TARGET_PAGE_BITS, 1);
+
+        /* If the write protection bit is set, then we invalidate
+           the code inside.  */
         if (!(p->flags & PAGE_WRITE) &&
             (flags & PAGE_WRITE) &&
             p->first_tb) {
@@ -2351,14 +2359,24 @@ int page_check_range(target_ulong start, target_ulong len, int flags)
     target_ulong end;
     target_ulong addr;
 
-    if (start + len < start)
-        /* we've wrapped around */
+    /* This function should never be called with addresses outside the
+       guest address space.  If this assert fires, it probably indicates
+       a missing call to h2g_valid.  */
+#if HOST_LONG_BITS > L1_MAP_ADDR_SPACE_BITS
+    assert(start < (1ul << L1_MAP_ADDR_SPACE_BITS));
+#endif
+
+    if (start + len - 1 < start) {
+        /* We've wrapped around.  */
         return -1;
+    }
 
     end = TARGET_PAGE_ALIGN(start+len); /* must do before we loose bits in the next step */
     start = start & TARGET_PAGE_MASK;
 
-    for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) {
+    for (addr = start, len = end - start;
+         len != 0;
+         len -= TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {
         p = page_find(addr >> TARGET_PAGE_BITS);
         if( !p )
             return -1;
Signature · 1 line
1.6.6.1
#5 lore raw

PATCH 3/6 linux-user: Use h2g_valid in qemu_vmalloc.

In reply to Richard Henderson
---
 linux-user/mmap.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
linux-user/mmap.c +4 -5
index 25fc0b2..65fdc33 100644
@@ -80,16 +80,15 @@ void mmap_unlock(void)
 void *qemu_vmalloc(size_t size)
 {
     void *p;
-    unsigned long addr;
+
     mmap_lock();
     /* Use map and mark the pages as used.  */
     p = mmap(NULL, size, PROT_READ | PROT_WRITE,
              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
-    addr = (unsigned long)p;
-    if (addr == (target_ulong) addr) {
-        /* Allocated region overlaps guest address space.
-           This may recurse.  */
+    if (h2g_valid(p)) {
+        /* Allocated region overlaps guest address space. This may recurse.  */
+        unsigned long addr = h2g(p);
         page_set_flags(addr & TARGET_PAGE_MASK, TARGET_PAGE_ALIGN(addr + size),
                        PAGE_RESERVED);
     }
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 1/6 Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h.

In reply to Richard Henderson

Removes a set of ifdefs from exec.c.

Introduce TARGET_VIRT_ADDR_SPACE_BITS for all targets other than Alpha. This will be used for page_find_alloc, which is supposed to be using virtual addresses in the first place.

---
 exec.c                  |   17 -----------------
 target-alpha/cpu.h      |    4 +++-
 target-arm/cpu.h        |    3 +++
 target-cris/cpu.h       |    3 +++
 target-i386/cpu.h       |   11 +++++++++++
 target-m68k/cpu.h       |    3 +++
 target-microblaze/cpu.h |    3 +++
 target-mips/mips-defs.h |    4 ++++
 target-ppc/cpu.h        |   17 +++++++++++++++++
 target-s390x/cpu.h      |    5 +++++
 target-sh4/cpu.h        |    3 +++
 target-sparc/cpu.h      |    8 ++++++++
 12 files changed, 63 insertions(+), 18 deletions(-)
exec.c +0 -17
index 891e0ee..431f5b2 100644
@@ -62,23 +62,6 @@
 
 #define SMC_BITMAP_USE_THRESHOLD 10
 
-#if defined(TARGET_SPARC64)
-#define TARGET_PHYS_ADDR_SPACE_BITS 41
-#elif defined(TARGET_SPARC)
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#elif defined(TARGET_ALPHA)
-#define TARGET_PHYS_ADDR_SPACE_BITS 42
-#define TARGET_VIRT_ADDR_SPACE_BITS 42
-#elif defined(TARGET_PPC64)
-#define TARGET_PHYS_ADDR_SPACE_BITS 42
-#elif defined(TARGET_X86_64)
-#define TARGET_PHYS_ADDR_SPACE_BITS 42
-#elif defined(TARGET_I386)
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#else
-#define TARGET_PHYS_ADDR_SPACE_BITS 32
-#endif
-
 static TranslationBlock *tbs;
 int code_gen_max_blocks;
 TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE];
target-alpha/cpu.h +3 -1
index 617f55c..8afe16d 100644
@@ -41,7 +41,9 @@
 
 #define TARGET_PAGE_BITS 13
 
-#define VA_BITS 43
+/* ??? 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)
 
 /* Alpha major type */
 enum {
target-arm/cpu.h +3 -0
index 4a1c53f..3892db4 100644
@@ -405,6 +405,9 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define TARGET_PAGE_BITS 10
 #endif
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_arm_init
 #define cpu_exec cpu_arm_exec
 #define cpu_gen_code cpu_arm_gen_code
target-cris/cpu.h +3 -0
index 8ff86d9..063a240 100644
@@ -200,6 +200,9 @@ enum {
 #define TARGET_PAGE_BITS 13
 #define MMAP_SHIFT TARGET_PAGE_BITS
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_cris_init
 #define cpu_exec cpu_cris_exec
 #define cpu_gen_code cpu_cris_gen_code
target-i386/cpu.h +11 -0
index ef7d951..a9dab6f 100644
@@ -874,6 +874,17 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 
 #define TARGET_PAGE_BITS 12
 
+#ifdef TARGET_X86_64
+#define TARGET_PHYS_ADDR_SPACE_BITS 52
+/* ??? This is really 48 bits, sign-extended, but the only thing 
+   accessible to userland with bit 48 set is the VSYSCALL, and that
+   is handled via other mechanisms.  */
+#define TARGET_VIRT_ADDR_SPACE_BITS 47
+#else
+#define TARGET_PHYS_ADDR_SPACE_BITS 36
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+#endif
+
 #define cpu_init cpu_x86_init
 #define cpu_exec cpu_x86_exec
 #define cpu_gen_code cpu_x86_gen_code
target-m68k/cpu.h +3 -0
index 68a7e41..b2f37ec 100644
@@ -210,6 +210,9 @@ void register_m68k_insns (CPUM68KState *env);
 #define TARGET_PAGE_BITS 10
 #endif
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_m68k_init
 #define cpu_exec cpu_m68k_exec
 #define cpu_gen_code cpu_m68k_gen_code
target-microblaze/cpu.h +3 -0
index 1bf4875..5999386 100644
@@ -253,6 +253,9 @@ enum {
 #define TARGET_PAGE_BITS 12
 #define MMAP_SHIFT TARGET_PAGE_BITS
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_mb_init
 #define cpu_exec cpu_mb_exec
 #define cpu_gen_code cpu_mb_gen_code
target-mips/mips-defs.h +4 -0
index 54e80f1..0f6a956 100644
@@ -8,6 +8,10 @@
 #define TARGET_PAGE_BITS 12
 #define MIPS_TLB_MAX 128
 
+/* ??? MIPS64 no doubt has a larger address space.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #if defined(TARGET_MIPS64)
 #define TARGET_LONG_BITS 64
 #else
target-ppc/cpu.h +17 -0
index 63aeb86..2550186 100644
@@ -29,6 +29,20 @@
 #define TARGET_LONG_BITS 64
 #define TARGET_PAGE_BITS 12
 
+/* Note that the official physical address space bits is 62-M where M
+   is implementation dependent.  I've not looked up M for the set of
+   cpus we emulate at the system level.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 62
+ 
+/* Note that the PPC environment architecture talks about 80 bit virtual
+   addresses, with segmentation.  Obviously that's not all visible to a
+   single process, which is all we're concerned with here.  */
+#ifdef TARGET_ABI32
+# define TARGET_VIRT_ADDR_SPACE_BITS 32
+#else
+# define TARGET_VIRT_ADDR_SPACE_BITS 64
+#endif
+
 #else /* defined (TARGET_PPC64) */
 /* PowerPC 32 definitions */
 #define TARGET_LONG_BITS 32
@@ -50,6 +64,9 @@
 #define TARGET_PAGE_BITS 12
 #endif /* defined(TARGET_PPCEMB) */
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #endif /* defined (TARGET_PPC64) */
 
 #define CPUState struct CPUPPCState
target-s390x/cpu.h +5 -0
index 827f4e3..dd407b2 100644
@@ -99,6 +99,11 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw
 
 #define TARGET_PAGE_BITS 12
 
+/* ??? This is certainly wrong for 64-bit s390x, but given that only KVM
+   emulation actually works, this is good enough for a placeholder.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #ifndef CONFIG_USER_ONLY
 extern int s390_virtio_hypercall(CPUState *env);
 extern void kvm_s390_virtio_irq(CPUState *env, int config_change, uint64_t token);
target-sh4/cpu.h +3 -0
index 85f221d..18a5532 100644
@@ -44,6 +44,9 @@
 
 #define TARGET_PAGE_BITS 12	/* 4k XXXXX */
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define SR_MD (1 << 30)
 #define SR_RB (1 << 29)
 #define SR_BL (1 << 28)
target-sparc/cpu.h +8 -0
index 5980deb..0c5a7ef 100644
@@ -7,10 +7,18 @@
 #define TARGET_LONG_BITS 32
 #define TARGET_FPREGS 32
 #define TARGET_PAGE_BITS 12 /* 4k */
+#define TARGET_PHYS_ADDR_SPACE_BITS 41
+# ifdef TARGET_ABI32
+#  define TARGET_VIRT_ADDR_SPACE_BITS 32
+# else
+#  define TARGET_VIRT_ADDR_SPACE_BITS 44
+# endif
 #else
 #define TARGET_LONG_BITS 64
 #define TARGET_FPREGS 64
 #define TARGET_PAGE_BITS 13 /* 8k */
+#define TARGET_PHYS_ADDR_SPACE_BITS 36
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
 #define CPUState struct CPUSPARCState
Signature · 1 line
1.6.6.1
#6 lore raw

PATCH 4/6 linux-user: Fix mmap_find_vma returning invalid addresses.

In reply to Richard Henderson

Don't return addresses that aren't properly aligned for the guest, e.g. when the guest has a larger page size than the host. Don't return addresses that are outside the virtual address space for the target, by paying proper attention to the h2g/g2h macros.

At the same time, place the default mapping base for 64-bit guests (on 64-bit hosts) outside the low 4G. Consistently interpret mmap_next_start in the guest address space.

---
 linux-user/main.c |   11 ++----
 linux-user/mmap.c |  102 ++++++++++++++++++++++++++++++++++++++++------------
 linux-user/qemu.h |    2 -
 3 files changed, 82 insertions(+), 33 deletions(-)
linux-user/main.c +4 -7
index eeae22e..4614e3c 100644
@@ -39,8 +39,8 @@
 char *exec_path;
 
 int singlestep;
-#if defined(CONFIG_USE_GUEST_BASE)
 unsigned long mmap_min_addr;
+#if defined(CONFIG_USE_GUEST_BASE)
 unsigned long guest_base;
 int have_guest_base;
 #endif
@@ -2812,16 +2812,14 @@ int main(int argc, char **argv, char **envp)
      * proper page alignment for guest_base.
      */
     guest_base = HOST_PAGE_ALIGN(guest_base);
+#endif /* CONFIG_USE_GUEST_BASE */
 
     /*
      * Read in mmap_min_addr kernel parameter.  This value is used
      * When loading the ELF image to determine whether guest_base
-     * is needed.
-     *
-     * When user has explicitly set the quest base, we skip this
-     * test.
+     * is needed.  It is also used in mmap_find_vma.
      */
-    if (!have_guest_base) {
+    {
         FILE *fp;
 
         if ((fp = fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL) {
@@ -2833,7 +2831,6 @@ int main(int argc, char **argv, char **envp)
             fclose(fp);
         }
     }
-#endif /* CONFIG_USE_GUEST_BASE */
 
     /*
      * Prepare copy of argv vector for target.
linux-user/mmap.c +78 -24

140 lines not on this page · raw message

linux-user/qemu.h +0 -2
index d129deb..6ab9517 100644
@@ -133,9 +133,7 @@ void init_task_state(TaskState *ts);
 void task_settid(TaskState *);
 void stop_all_tasks(void);
 extern const char *qemu_uname_release;
-#if defined(CONFIG_USE_GUEST_BASE)
 extern unsigned long mmap_min_addr;
-#endif
 
 /* ??? See if we can avoid exposing so much of the loader internals.  */
 /*
Signature · 1 line
1.6.6.1
#7 lore raw

PATCH 5/6 Implement multi-level page tables.

In reply to Richard Henderson

Define L1_MAP_ADDR_SPACE_BITS to be either the virtual address size (in user mode) or physical address size (in system mode), and use that to size l1_map. This rewrites page_find_alloc, page_flush_tb, and walk_memory_regions.

Use TARGET_PHYS_ADDR_SPACE_BITS for the physical memory map based off of l1_phys_map. This rewrites page_phys_find_alloc and phys_page_for_each.

---
 cpu-all.h |    7 +-
 exec.c    |  451 +++++++++++++++++++++++++++++++++++++------------------------
 2 files changed, 278 insertions(+), 180 deletions(-)
cpu-all.h +5 -2
index 68848e9..a51b301 100644
@@ -745,8 +745,11 @@ extern unsigned long qemu_host_page_mask;
 #define PAGE_RESERVED  0x0020
 
 void page_dump(FILE *f);
-int walk_memory_regions(void *,
-    int (*fn)(void *, unsigned long, unsigned long, unsigned long));
+
+typedef int (*walk_memory_regions_fn)(void *, unsigned long,
+                                      unsigned long, unsigned long);
+int walk_memory_regions(void *, walk_memory_regions_fn);
+
 int page_get_flags(target_ulong address);
 void page_set_flags(target_ulong start, target_ulong end, int flags);
 int page_check_range(target_ulong start, target_ulong len, int flags);
exec.c +270 -175

557 lines not on this page · raw message

Signature · 1 line
1.6.6.1
#4 lore raw

PATCH 2/6 Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.

In reply to Richard Henderson

Previously, only 32-bit guests had a proper check for the validity of the virtual address. Extend that check to 64-bit guests with a restricted virtual address space.

---
 cpu-all.h |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
cpu-all.h +11 -5
index 9823c24..68848e9 100644
@@ -634,16 +634,22 @@ extern int have_guest_base;
 
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
+
+#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
+#define h2g_valid(x) 1
+#else
+#define h2g_valid(x) ({ \
+    unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
+    __guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \
+})
+#endif
+
 #define h2g(x) ({ \
     unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
     /* Check if given address fits target address space */ \
-    assert(__ret == (abi_ulong)__ret); \
+    assert(h2g_valid(x)); \
     (abi_ulong)__ret; \
 })
-#define h2g_valid(x) ({ \
-    unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
-    (__guest == (abi_ulong)__guest); \
-})
 
 #define saddr(x) g2h(x)
 #define laddr(x) g2h(x)
Signature · 1 line
1.6.6.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h.

In reply to Richard Henderson
Quoted 148 lines · Richard Henderson

Removes a set of ifdefs from exec.c.

Introduce TARGET_VIRT_ADDR_SPACE_BITS for all targets other than Alpha. This will be used for page_find_alloc, which is supposed to be using virtual addresses in the first place.

---
 exec.c                  |   17 -----------------
 target-alpha/cpu.h      |    4 +++-
 target-arm/cpu.h        |    3 +++
 target-cris/cpu.h       |    3 +++
 target-i386/cpu.h       |   11 +++++++++++
 target-m68k/cpu.h       |    3 +++
 target-microblaze/cpu.h |    3 +++
 target-mips/mips-defs.h |    4 ++++
 target-ppc/cpu.h        |   17 +++++++++++++++++
 target-s390x/cpu.h      |    5 +++++
 target-sh4/cpu.h        |    3 +++
 target-sparc/cpu.h      |    8 ++++++++
 12 files changed, 63 insertions(+), 18 deletions(-)
exec.c +0 -17
index 891e0ee..431f5b2 100644
@@ -62,23 +62,6 @@
 
 #define SMC_BITMAP_USE_THRESHOLD 10
 
-#if defined(TARGET_SPARC64)
-#define TARGET_PHYS_ADDR_SPACE_BITS 41
-#elif defined(TARGET_SPARC)
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#elif defined(TARGET_ALPHA)
-#define TARGET_PHYS_ADDR_SPACE_BITS 42
-#define TARGET_VIRT_ADDR_SPACE_BITS 42
-#elif defined(TARGET_PPC64)
-#define TARGET_PHYS_ADDR_SPACE_BITS 42
-#elif defined(TARGET_X86_64)
-#define TARGET_PHYS_ADDR_SPACE_BITS 42
-#elif defined(TARGET_I386)
-#define TARGET_PHYS_ADDR_SPACE_BITS 36
-#else
-#define TARGET_PHYS_ADDR_SPACE_BITS 32
-#endif
-
 static TranslationBlock *tbs;
 int code_gen_max_blocks;
 TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE];
target-alpha/cpu.h +3 -1
index 617f55c..8afe16d 100644
@@ -41,7 +41,9 @@
 
 #define TARGET_PAGE_BITS 13
 
-#define VA_BITS 43
+/* ??? 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)
 
 /* Alpha major type */
 enum {
target-arm/cpu.h +3 -0
index 4a1c53f..3892db4 100644
@@ -405,6 +405,9 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define TARGET_PAGE_BITS 10
 #endif
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_arm_init
 #define cpu_exec cpu_arm_exec
 #define cpu_gen_code cpu_arm_gen_code
target-cris/cpu.h +3 -0
index 8ff86d9..063a240 100644
@@ -200,6 +200,9 @@ enum {
 #define TARGET_PAGE_BITS 13
 #define MMAP_SHIFT TARGET_PAGE_BITS
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_cris_init
 #define cpu_exec cpu_cris_exec
 #define cpu_gen_code cpu_cris_gen_code
target-i386/cpu.h +11 -0
index ef7d951..a9dab6f 100644
@@ -874,6 +874,17 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 
 #define TARGET_PAGE_BITS 12
 
+#ifdef TARGET_X86_64
+#define TARGET_PHYS_ADDR_SPACE_BITS 52
+/* ??? This is really 48 bits, sign-extended, but the only thing 
+   accessible to userland with bit 48 set is the VSYSCALL, and that
+   is handled via other mechanisms.  */
+#define TARGET_VIRT_ADDR_SPACE_BITS 47
+#else
+#define TARGET_PHYS_ADDR_SPACE_BITS 36
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+#endif
+
 #define cpu_init cpu_x86_init
 #define cpu_exec cpu_x86_exec
 #define cpu_gen_code cpu_x86_gen_code
target-m68k/cpu.h +3 -0
index 68a7e41..b2f37ec 100644
@@ -210,6 +210,9 @@ void register_m68k_insns (CPUM68KState *env);
 #define TARGET_PAGE_BITS 10
 #endif
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_m68k_init
 #define cpu_exec cpu_m68k_exec
 #define cpu_gen_code cpu_m68k_gen_code
target-microblaze/cpu.h +3 -0
index 1bf4875..5999386 100644
@@ -253,6 +253,9 @@ enum {
 #define TARGET_PAGE_BITS 12
 #define MMAP_SHIFT TARGET_PAGE_BITS
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define cpu_init cpu_mb_init
 #define cpu_exec cpu_mb_exec
 #define cpu_gen_code cpu_mb_gen_code
target-mips/mips-defs.h +0 -0
index 54e80f1..0f6a956 100644

target-mips/mips-defs.h line 14

Quoted 7 lines
target-mips/mips-defs.h +4 -0
@@ -8,6 +8,10 @@
 #define TARGET_PAGE_BITS 12
 #define MIPS_TLB_MAX 128
 
+/* ??? MIPS64 no doubt has a larger address space.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+

In 32-bit mode, TARGET_VIRT_ADDR_SPACE_BITS is 32 bits, and TARGET_PHYS_ADDR_SPACE_BITS is 36 bits.

In 64-bit mode, TARGET_VIRT_ADDR_SPACE_BITS is 42 bits, and TARGET_PHYS_ADDR_SPACE_BITS is 36 bits for the CPUs emulated by QEMU, though the architecture specification limits those value to respectively 62 and 59 bits.

Quoted 97 lines
target-mips/mips-defs.h +0 -0
 #if defined(TARGET_MIPS64)
 #define TARGET_LONG_BITS 64
 #else
target-ppc/cpu.h +17 -0
index 63aeb86..2550186 100644
@@ -29,6 +29,20 @@
 #define TARGET_LONG_BITS 64
 #define TARGET_PAGE_BITS 12
 
+/* Note that the official physical address space bits is 62-M where M
+   is implementation dependent.  I've not looked up M for the set of
+   cpus we emulate at the system level.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 62
+ 
+/* Note that the PPC environment architecture talks about 80 bit virtual
+   addresses, with segmentation.  Obviously that's not all visible to a
+   single process, which is all we're concerned with here.  */
+#ifdef TARGET_ABI32
+# define TARGET_VIRT_ADDR_SPACE_BITS 32
+#else
+# define TARGET_VIRT_ADDR_SPACE_BITS 64
+#endif
+
 #else /* defined (TARGET_PPC64) */
 /* PowerPC 32 definitions */
 #define TARGET_LONG_BITS 32
@@ -50,6 +64,9 @@
 #define TARGET_PAGE_BITS 12
 #endif /* defined(TARGET_PPCEMB) */
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #endif /* defined (TARGET_PPC64) */
 
 #define CPUState struct CPUPPCState
target-s390x/cpu.h +5 -0
index 827f4e3..dd407b2 100644
@@ -99,6 +99,11 @@ int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, int rw
 
 #define TARGET_PAGE_BITS 12
 
+/* ??? This is certainly wrong for 64-bit s390x, but given that only KVM
+   emulation actually works, this is good enough for a placeholder.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #ifndef CONFIG_USER_ONLY
 extern int s390_virtio_hypercall(CPUState *env);
 extern void kvm_s390_virtio_irq(CPUState *env, int config_change, uint64_t token);
target-sh4/cpu.h +3 -0
index 85f221d..18a5532 100644
@@ -44,6 +44,9 @@
 
 #define TARGET_PAGE_BITS 12	/* 4k XXXXX */
 
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+
 #define SR_MD (1 << 30)
 #define SR_RB (1 << 29)
 #define SR_BL (1 << 28)
target-sparc/cpu.h +8 -0
index 5980deb..0c5a7ef 100644
@@ -7,10 +7,18 @@
 #define TARGET_LONG_BITS 32
 #define TARGET_FPREGS 32
 #define TARGET_PAGE_BITS 12 /* 4k */
+#define TARGET_PHYS_ADDR_SPACE_BITS 41
+# ifdef TARGET_ABI32
+#  define TARGET_VIRT_ADDR_SPACE_BITS 32
+# else
+#  define TARGET_VIRT_ADDR_SPACE_BITS 44
+# endif
 #else
 #define TARGET_LONG_BITS 64
 #define TARGET_FPREGS 64
 #define TARGET_PAGE_BITS 13 /* 8k */
+#define TARGET_PHYS_ADDR_SPACE_BITS 36
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
 #define CPUState struct CPUSPARCState
Signature · 1 line
1.6.6.1
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw

Re: [Qemu-devel] [PATCH 1/6] Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h.

Quoted 8 lines · Aurelien Jarno

target-mips/mips-defs.h line 14

Quoted 4 lines
target-mips/mips-defs.h +4 -0
+/* ??? MIPS64 no doubt has a larger address space.  */
+#define TARGET_PHYS_ADDR_SPACE_BITS 32
+#define TARGET_VIRT_ADDR_SPACE_BITS 32
+

In 32-bit mode, TARGET_VIRT_ADDR_SPACE_BITS is 32 bits, and TARGET_PHYS_ADDR_SPACE_BITS is 36 bits.

Quoted 4 lines

In 64-bit mode, TARGET_VIRT_ADDR_SPACE_BITS is 42 bits, and TARGET_PHYS_ADDR_SPACE_BITS is 36 bits for the CPUs emulated by QEMU, though the architecture specification limits those value to respectively 62 and 59 bits.

Thanks. I'll queue that either for a subsequent round or a follow-up patch (since the current tree doesn't use anything but the 32 above).

r~

Applied
#12 lore raw
In reply to Richard Henderson
Quoted 7 lines

Richard Henderson (6):
Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h. Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.
linux-user: Use h2g_valid in qemu_vmalloc.
linux-user: Fix mmap_find_vma returning invalid addresses. Implement multi-level page tables.
Fix last page errors in page_check_range and page_set_flags.

Applied, plus a bunch of follow-on patches that isolate the userspace emulation from any concept of physical address space.

Paul

#13 lore raw
Quoted 11 lines · Paul Brook
Quoted 7 lines

Richard Henderson (6):
Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h. Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.
linux-user: Use h2g_valid in qemu_vmalloc.
linux-user: Fix mmap_find_vma returning invalid addresses. Implement multi-level page tables.
Fix last page errors in page_check_range and page_set_flags.

Applied, plus a bunch of follow-on patches that isolate the userspace
emulation from any concept of physical address space.

Now I get these warnings on OpenBSD/Sparc64:
CC sparc-bsd-user/exec.o
/src/qemu/exec.c: In function `page_set_flags':
/src/qemu/exec.c:2336: warning: comparison is always true due to limited range of data type
/src/qemu/exec.c: In function `page_check_range':
/src/qemu/exec.c:2373: warning: comparison is always true due to limited range of data type

#14 lore raw
Quoted 3 lines

/src/qemu/exec.c: In function `page_set_flags':
/src/qemu/exec.c:2336: warning: comparison is always true due to limited range of data type

Should be fixed by b480d9b74dfd1efd29026b7dc6438364a633ee99

Paul

#15 lore raw
In reply to Paul Brook
Quoted 11 lines · Paul Brook
Quoted 7 lines

Richard Henderson (6):
Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h. Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.
linux-user: Use h2g_valid in qemu_vmalloc.
linux-user: Fix mmap_find_vma returning invalid addresses. Implement multi-level page tables.
Fix last page errors in page_check_range and page_set_flags.

Applied, plus a bunch of follow-on patches that isolate the userspace emulation from any concept of physical address space.

The patch "Implement multi-level page tables" breaks i386/x86_64 system emulation. Using the image on [1], qemu now segfaults during the initrd parts. This is not 100% reproducible, a few times it hanged instead of crashing.

[1] http://people.debian.org/~aurel32/qemu/i386/debian_lenny_i386_small.qcow2

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#16 lore raw

I am sorry to bring us all down to earth, we all had wished that this stuff gets finally fixed, but it seems that those patches applied to QEMU master have killed QEMU user mode.

I am referring to the user mode fixes after commit 0aef4261ac0ec9089ade0e3a92f986cb4ba7317e

I had QEMU working on PowerPC and ARM in chroots from the Linux versions:

- Fedora 11 / 12
- Ubuntu 9.04, 9.10, 10.04
- Debian 4, 5 and Sid

for ARM and PowerPC. My host OS is openSUSE 11.2 using a 2.6.31 kernel, or openSUSE 11.1. All machines are 64 Bit machines.

Now I have the situation that all the listed target chroots fail, except:
- Fedora 11 / 12 @ ARM

As you might guess (or even know), I am one of the Open Build Service (http://en.opensuse.org/Build_Service/Testing) developers and can automatedly setup and test such a big number of Targets and automatically run testsuites or compile jobs on them. The last fixes in the QEMU user mode memory allocator before your rewrite came from Jan-Simon and me.

I think its long overdue to fix the user mode stuff, so I am happy that now someone that knows more about QEMU than me cares about. SO my offering is to help to track this down and fix it. But I would be happy if you give me a hint about what your changes are really doing to track down the problem.

Quoted 23 lines · Aurelien Jarno
Quoted 8 lines · Paul Brook
Quoted 8 lines

Richard Henderson (6):
Move TARGET_PHYS_ADDR_SPACE_BITS to target-*/cpu.h. Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.
linux-user: Use h2g_valid in qemu_vmalloc.
linux-user: Fix mmap_find_vma returning invalid addresses. Implement multi-level page tables.
Fix last page errors in page_check_range and page_set_flags.

Quoted 4 lines

Applied, plus a bunch of follow-on patches that isolate the userspace emulation from any concept of physical address space.

The patch "Implement multi-level page tables" breaks i386/x86_64 system emulation. Using the image on [1], qemu now segfaults during the initrd parts. This is not 100% reproducible, a few times it hanged instead of crashing.

[1] http://people.debian.org/~aurel32/qemu/i386/debian_lenny_i386_small.qcow2

#8 lore raw

Re: [Qemu-devel] [PATCH 5/6] Implement multi-level page tables.

In reply to Richard Henderson
Quoted 9 lines · Richard Henderson

Define L1_MAP_ADDR_SPACE_BITS to be either the virtual address size (in user mode) or physical address size (in system mode), and use that to size l1_map. This rewrites page_find_alloc, page_flush_tb, and walk_memory_regions.

Use TARGET_PHYS_ADDR_SPACE_BITS for the physical memory map based off of l1_phys_map. This rewrites page_phys_find_alloc and phys_page_for_each.

Quoted 5 lines
---
 cpu-all.h |    7 +-
 exec.c    |  451 +++++++++++++++++++++++++++++++++++++------------------------
 2 files changed, 278 insertions(+), 180 deletions(-)

This patch breaks remote debugging (QEMU crash).

Test scenario:

x86_64 debian host, mips malta (32/64 bit, big/little endian) target

start qemu system emulation with a malta kernel and options -s -S, attach remote debugger, start mips kernel with "c" in debugger => qemu crash:

page_flush_tb is filled with zero in page_flush_tb tb_phys_invalidate is called, access fault in tb_remove.

Other targets might be affected, too.

Regards,
Stefan Weil

#9 lore raw

Re: [Qemu-devel] [PATCH 5/6] Implement multi-level page tables.

Quoted 10 lines
Quoted 9 lines · Richard Henderson

Define L1_MAP_ADDR_SPACE_BITS to be either the virtual address size (in user mode) or physical address size (in system mode), and use that to size l1_map. This rewrites page_find_alloc, page_flush_tb, and walk_memory_regions.

Use TARGET_PHYS_ADDR_SPACE_BITS for the physical memory map based off of l1_phys_map. This rewrites page_phys_find_alloc and phys_page_for_each.

Quoted 8 lines
Quoted 6 lines
---
 cpu-all.h |    7 +-
 exec.c    |  451

+++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 278 insertions(+), 180 deletions(-)

This patch breaks remote debugging (QEMU crash).

Probably nothing to do with debugging. Should be fixed by 7296abaccc98872e28cec50091dbf26d38e4f062

Paul

#10 lore raw

Re: [Qemu-devel] [PATCH 5/6] Implement multi-level page tables.

Quoted 17 lines · Paul Brook
Quoted 17 lines
Quoted 15 lines · Richard Henderson

Define L1_MAP_ADDR_SPACE_BITS to be either the virtual address size (in user mode) or physical address size (in system mode), and use that to size l1_map. This rewrites page_find_alloc, page_flush_tb, and walk_memory_regions.

Use TARGET_PHYS_ADDR_SPACE_BITS for the physical memory map based off of l1_phys_map. This rewrites page_phys_find_alloc and phys_page_for_each.

---
 cpu-all.h |    7 +-
 exec.c    |  451

+++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 278 insertions(+), 180 deletions(-)

Quoted 5 lines
Quoted 1 line

This patch breaks remote debugging (QEMU crash).

Probably nothing to do with debugging. Should be fixed by 7296abaccc98872e28cec50091dbf26d38e4f062

Thanks it also fixes the problem I have reported.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#17 lore raw
In reply to Martin Mohring
Quoted 1 line · Martin Mohring

I am sorry to bring us all down to earth, we all had wished that this stuff gets finally fixed, but it seems that those patches applied to QEMU master have killed QEMU user mode.

sid and maemo userlands work for me like before (64bit and 32bit hosts).

Quoted 4 lines

I am referring to the user mode fixes after commit 0aef4261ac0ec9089ade0e3a92f986cb4ba7317e

I had QEMU working on PowerPC and ARM in chroots from the Linux versions:

Quoted 8 lines

- Fedora 11 / 12
- Ubuntu 9.04, 9.10, 10.04
- Debian 4, 5 and Sid

for ARM and PowerPC. My host OS is openSUSE 11.2 using a 2.6.31 kernel, or openSUSE 11.1. All machines are 64 Bit machines.

Now I have the situation that all the listed target chroots fail, except:
- Fedora 11 / 12 @ ARM

Please try to be more specific. What is killed? what do you mean by "chroots fail". qemu segfault? some binary doesn't work that before did? some syscall doesn't work anymore?

#18 lore raw
Quoted 9 lines
Quoted 9 lines

I had QEMU working on PowerPC and ARM in chroots from the Linux versions:

- Fedora 11 / 12
- Ubuntu 9.04, 9.10, 10.04
- Debian 4, 5 and Sid

for ARM and PowerPC. My host OS is openSUSE 11.2 using a 2.6.31 kernel, or openSUSE 11.1. All machines are 64 Bit machines.

Quoted 7 lines
Quoted 2 lines

Now I have the situation that all the listed target chroots fail, except:
- Fedora 11 / 12 @ ARM

Please try to be more specific. What is killed? what do you mean by "chroots fail". qemu segfault? some binary doesn't work that before did? some syscall doesn't work anymore?

We're still investigating the topic. So far, we tracked one failure down to ldconfig.real which is a static arm binary executed after the chroot got the basic packages installed. If we setup a chroot with an older qemu-arm and exchange it afterwards with the new qemu and rerun just the build step, it works. Thus it seems to be an issue with static arm binaries atm.

Strace of a call of ldconfig.real with the qemu-arm failing:

http://pastie.org/870189

Sort version:

root@frodo:/# qemu-arm -strace /sbin/ldconfig.real                  
16359 uname(0x403fef78) = 0                                         
16359 brk(NULL) = 0x000a9000                                        
16359 brk(0x000a9d08) = 0x000a9d08                                  
16359 open("/dev/urandom",O_RDONLY) = 3                             
16359 read(3,0x403ff27d,3) = 3                                      
16359 close(3) = 0                                                  
[...]
16359 stat64("/usr/lib/libgettextlib.so",0x403fdf28) = 0
16359 stat64("/usr/lib/libgettextpo.so.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libgettextpo.so.0.4.0",0x403fdf28) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdf28) = 0
16359 open("/etc/ld.so.cache~",O_WRONLY|O_CREAT|O_NOFOLLOW|O_TRUNC,0600) = 3
16359 write(3,0xb03d0,1288) = 1288
16359 write(3,0x403ff0a0,0) = -1 errno=14 (Bad address)
16359 write(2,0x403fca08,21)/sbin/ldconfig.real:  = 21
16359 write(2,0x403fc9e8,28)Writing of cache data failed = 28
16359 write(2,0x403fc5b8,13): Bad address = 13
16359 write(2,0x403fc9c0,1)
 = 1
16359 exit_group(1)

Best,
Jan-Simon

#19 lore raw
Quoted 12 lines · Jan-Simon Möller

We're still investigating the topic. So far, we tracked one failure down to ldconfig.real which is a static arm binary executed after the chroot got the basic packages installed. If we setup a chroot with an older qemu-arm and exchange it afterwards with the new qemu and rerun just the build step, it works. Thus it seems to be an issue with static arm binaries atm.

Strace of a call of ldconfig.real with the qemu-arm failing:

http://pastie.org/870189

Sort version:

Quoted 16 lines
root@frodo:/# qemu-arm -strace /sbin/ldconfig.real                  
16359 uname(0x403fef78) = 0                                         
16359 brk(NULL) = 0x000a9000                                        
16359 brk(0x000a9d08) = 0x000a9d08                                  
16359 open("/dev/urandom",O_RDONLY) = 3                             
16359 read(3,0x403ff27d,3) = 3                                      
16359 close(3) = 0                                                  
[...]
16359 stat64("/usr/lib/libgettextlib.so",0x403fdf28) = 0
16359 stat64("/usr/lib/libgettextpo.so.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libgettextpo.so.0.4.0",0x403fdf28) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdf28) = 0
16359 open("/etc/ld.so.cache~",O_WRONLY|O_CREAT|O_NOFOLLOW|O_TRUNC,0600) = 3
16359 write(3,0xb03d0,1288) = 1288
16359 write(3,0x403ff0a0,0) = -1 errno=14 (Bad address)

A zero sized write. According to manpage ok.

In qemu we do a lock_user to to get the string to write. Richards change changes the access checks the get called by lock_user:

page_check_range:

- if (start + len < start)
- /* we've wrapped around */
...
+ if (start + len - 1 < start) {
+ /* We've wrapped around. */

This now blows up with len = 0;

Quoted 10 lines

16359 write(2,0x403fca08,21)/sbin/ldconfig.real: = 21 16359 write(2,0x403fc9e8,28)Writing of cache data failed = 28 16359 write(2,0x403fc5b8,13): Bad address = 13 16359 write(2,0x403fc9c0,1)
= 1
16359 exit_group(1)

Best,
Jan-Simon

#20 lore raw

Am Montag, 15. März 2010 15:48:03 schrieb Riku Voipio:

Quoted 44 lines · Jan-Simon Möller
Quoted 13 lines

We're still investigating the topic. So far, we tracked one failure down to ldconfig.real which is a static arm binary executed after the chroot got the basic packages installed. If we setup a chroot with an older qemu-arm and exchange it afterwards with the new qemu and rerun just the build step, it works. Thus it seems to be an issue with static arm binaries atm.

Strace of a call of ldconfig.real with the qemu-arm failing:

http://pastie.org/870189

Sort version:

Quoted 16 lines
root@frodo:/# qemu-arm -strace /sbin/ldconfig.real
16359 uname(0x403fef78) = 0
16359 brk(NULL) = 0x000a9000
16359 brk(0x000a9d08) = 0x000a9d08
16359 open("/dev/urandom",O_RDONLY) = 3
16359 read(3,0x403ff27d,3) = 3
16359 close(3) = 0
[...]
16359 stat64("/usr/lib/libgettextlib.so",0x403fdf28) = 0
16359 stat64("/usr/lib/libgettextpo.so.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libgettextpo.so.0.4.0",0x403fdf28) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdf28) = 0
16359 open("/etc/ld.so.cache~",O_WRONLY|O_CREAT|O_NOFOLLOW|O_TRUNC,0600)
= 3 16359 write(3,0xb03d0,1288) = 1288
16359 write(3,0x403ff0a0,0) = -1 errno=14 (Bad address)

A zero sized write. According to manpage ok.

In qemu we do a lock_user to to get the string to write. Richards change
changes the access checks the get called by lock_user:

page_check_range:

(quoted diff) +2 -2
-    if (start + len < start)
-        /* we've wrapped around */
...
+    if (start + len - 1 < start) {
+        /* We've wrapped around.  */
Quoted 1 line

This now blows up with len = 0;

Confirmed. A quick test with if (len > 0) around and ldconfig.real runs.

Best,
Jan-Simon

#21 lore raw
Quoted 32 lines · Jan-Simon Möller

Am Montag, 15. März 2010 15:48:03 schrieb Riku Voipio:

Quoted 31 lines · Jan-Simon Möller
Quoted 8 lines
root@frodo:/# qemu-arm -strace /sbin/ldconfig.real
16359 uname(0x403fef78) = 0
16359 brk(NULL) = 0x000a9000
16359 brk(0x000a9d08) = 0x000a9d08
16359 open("/dev/urandom",O_RDONLY) = 3
16359 read(3,0x403ff27d,3) = 3
16359 close(3) = 0
[...]
Quoted 8 lines
16359 stat64("/usr/lib/libgettextlib.so",0x403fdf28) = 0
16359 stat64("/usr/lib/libgettextpo.so.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libgettextpo.so.0.4.0",0x403fdf28) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdec0) = 0
16359 stat64("/usr/lib/libpython2.6.so.1.0",0x403fdf28) = 0
16359 open("/etc/ld.so.cache~",O_WRONLY|O_CREAT|O_NOFOLLOW|O_TRUNC,0600)
= 3 16359 write(3,0xb03d0,1288) = 1288
16359 write(3,0x403ff0a0,0) = -1 errno=14 (Bad address)

A zero sized write. According to manpage ok.

In qemu we do a lock_user to to get the string to write. Richards change
changes the access checks the get called by lock_user:

page_check_range:

(quoted diff) +2 -2
-    if (start + len < start)
-        /* we've wrapped around */
...
+    if (start + len - 1 < start) {
+        /* We've wrapped around.  */
Quoted 3 lines
Quoted 1 line

This now blows up with len = 0;

Confirmed. A quick test with if (len > 0) around and ldconfig.real runs.

Richard, would you be ok with that change? Or should we rather have explicit

if (len == 0) return 0;

?

#22 lore raw
Quoted 8 lines · Riku Voipio
Quoted 8 lines
Quoted 8 lines

page_check_range:

(quoted diff) +2 -2
-    if (start + len < start)
-        /* we've wrapped around */
...
+    if (start + len - 1 < start) {
+        /* We've wrapped around.  */
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This now blows up with len = 0;

Confirmed. A quick test with if (len > 0) around and ldconfig.real runs.

Richard, would you be ok with that change? Or should we rather have explicit

if (len == 0) return 0;

My personal preference is

  if (len != 0 && start + len - 1 < start)

but don't let that stop anyone checking in any correct variant.

r~