Skip to contentSkip to conversation

testing, tcg and plugin updates

GIT PULL Applied Alex Bennée 5 participants 21 messages May 15, 2020 – Jun 5, 2020

lore
Share & tools
lore
#0 lore raw

The following changes since commit 2478b8ecd45f81a21b9aa319ce7147a790a2144f:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20200515-pull-request' into staging (2020-05-15 11:18:13 +0100)

are available in the Git repository at:

https://github.com/stsquad/qemu.git tags/pull-testing-tcg-plugins-150520-2

for you to fetch changes up to adf1cfbdc29e6e3342ca07701be4d2cbfd7d3907:

MAINTAINERS: update the orphaned cpus-common.c file (2020-05-15 15:25:16 +0100)

----------------------------------------------------------------
Various testing, tcg and plugin updates

- fix bug in gdbstub tests that leave hanging QEMUs
- tweak s390x travis test
- re-factor guest_base handling
- support "notes" in disassembler output
- include guest address notes in out_asm
- cleanup plugin headers and and constify hwaddr
- updates MAINTAINERS for cpu-common.c

----------------------------------------------------------------
Alex Bennée (7):
tests/guest-debug: catch hanging guests
linux-user: completely re-write init_guest_space accel/tcg: don't disable exec_tb trace events
disas: include an optional note for the start of disassembly
disas: add optional note support to cap_disas
translate-all: include guest address in out_asm output
MAINTAINERS: update the orphaned cpus-common.c file

Philippe Mathieu-Daudé (3):
qemu/plugin: Trivial code movement
qemu/plugin: Move !CONFIG_PLUGIN stubs altogether qemu/qemu-plugin: Make qemu_plugin_hwaddr_is_io() hwaddr argument const

Richard Henderson (2):
exec/cpu-all: Use bool for have_guest_base accel/tcg: Relax va restrictions on 64-bit guests

Thomas Huth (1):

      travis.yml: Improve the --disable-tcg test on s390x
 include/disas/disas.h         |   2 +-
 include/exec/cpu-all.h        |  25 ++-
 include/exec/log.h            |   4 +-
 include/qemu/plugin.h         |  65 +++---
 include/qemu/qemu-plugin.h    |   2 +-
 linux-user/qemu.h             |  31 ++-
 target/alpha/cpu-param.h      |  15 +-
 accel/tcg/translate-all.c     |  54 ++++-
 bsd-user/main.c               |   4 +-
 disas.c                       |  37 +++-
 linux-user/elfload.c          | 503 +++++++++++++++++++++---------------------
 linux-user/flatload.c         |   6 +
 linux-user/main.c             |  27 +--
 plugins/api.c                 |   4 +-
 tcg/tcg.c                     |   4 +-
 .travis.yml                   |  18 +-
 MAINTAINERS                   |   1 +
 accel/tcg/trace-events        |   8 +-
 tests/guest-debug/run-test.py |   6 +
 19 files changed, 424 insertions(+), 392 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

[PULL v2 10/13] qemu/plugin: Trivial code movement

From: Philippe Mathieu-Daudé <[email protected]>

Move the qemu_plugin_event enum declaration earlier. This will make the next commit easier to review.

Message-Id: <[email protected]>
Message-Id: <[email protected]>

include/qemu/plugin.h +16 -16
index 11687e8cdc3..e45f950fe36 100644
@@ -13,6 +13,22 @@
 #include "qemu/queue.h"
 #include "qemu/option.h"
 
+/*
+ * Events that plugins can subscribe to.
+ */
+enum qemu_plugin_event {
+    QEMU_PLUGIN_EV_VCPU_INIT,
+    QEMU_PLUGIN_EV_VCPU_EXIT,
+    QEMU_PLUGIN_EV_VCPU_TB_TRANS,
+    QEMU_PLUGIN_EV_VCPU_IDLE,
+    QEMU_PLUGIN_EV_VCPU_RESUME,
+    QEMU_PLUGIN_EV_VCPU_SYSCALL,
+    QEMU_PLUGIN_EV_VCPU_SYSCALL_RET,
+    QEMU_PLUGIN_EV_FLUSH,
+    QEMU_PLUGIN_EV_ATEXIT,
+    QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */
+};
+
 /*
  * Option parsing/processing.
  * Note that we can load an arbitrary number of plugins.
@@ -47,22 +63,6 @@ static inline int qemu_plugin_load_list(QemuPluginList *head)
 }
 #endif /* !CONFIG_PLUGIN */
 
-/*
- * Events that plugins can subscribe to.
- */
-enum qemu_plugin_event {
-    QEMU_PLUGIN_EV_VCPU_INIT,
-    QEMU_PLUGIN_EV_VCPU_EXIT,
-    QEMU_PLUGIN_EV_VCPU_TB_TRANS,
-    QEMU_PLUGIN_EV_VCPU_IDLE,
-    QEMU_PLUGIN_EV_VCPU_RESUME,
-    QEMU_PLUGIN_EV_VCPU_SYSCALL,
-    QEMU_PLUGIN_EV_VCPU_SYSCALL_RET,
-    QEMU_PLUGIN_EV_FLUSH,
-    QEMU_PLUGIN_EV_ATEXIT,
-    QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */
-};
-
 union qemu_plugin_cb_sig {
     qemu_plugin_simple_cb_t          simple;
     qemu_plugin_udata_cb_t           udata;
Signature · 1 line
2.20.1
#2 lore raw

[PULL v2 02/13] travis.yml: Improve the --disable-tcg test on s390x

In reply to Alex Bennée

From: Thomas Huth <[email protected]>

Since the s390x containers do not allow KVM, we only compile-test the --disable-tcg build on s390x and do not run the qtests. Thus, it does not make sense to install genisoimage here, and it also does not make sense to build the s390-ccw.img here again - it is simply not used without the qtests.
On the other hand, if we do not build the s390-ccw.img anymore, we can also compile with Clang - so let's use that compiler here to get some additional test coverage.

Message-Id: <[email protected]>
Message-Id: <[email protected]>

.travis.yml +4 -14
index fe708792ca2..1ec8a7b4657 100644
@@ -502,9 +502,10 @@ jobs:
               $(exit $BUILD_RC);
           fi
 
-    - name: "[s390x] GCC check (KVM)"
+    - name: "[s390x] Clang (disable-tcg)"
       arch: s390x
       dist: bionic
+      compiler: clang
       addons:
         apt_packages:
           - libaio-dev
@@ -528,21 +529,10 @@ jobs:
           - libusb-1.0-0-dev
           - libvdeplug-dev
           - libvte-2.91-dev
-          # Tests dependencies
-          - genisoimage
       env:
         - TEST_CMD="make check-unit"
-        - CONFIG="--disable-containers --disable-tcg --enable-kvm --disable-tools"
-      script:
-        - ( cd ${SRC_DIR} ; git submodule update --init roms/SLOF )
-        - BUILD_RC=0 && make -j${JOBS} || BUILD_RC=$?
-        - |
-          if [ "$BUILD_RC" -eq 0 ] ; then
-              mv pc-bios/s390-ccw/*.img pc-bios/ ;
-              ${TEST_CMD} ;
-          else
-              $(exit $BUILD_RC);
-          fi
+        - CONFIG="--disable-containers --disable-tcg --enable-kvm
+                  --disable-tools --host-cc=clang --cxx=clang++"
 
     # Release builds
     # The make-release script expect a QEMU version, so our tag must start with a 'v'.
Signature · 1 line
2.20.1
#3 lore raw

[PULL v2 11/13] qemu/plugin: Move !CONFIG_PLUGIN stubs altogether

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Simplify the ifdef'ry by moving all stubs together.

Message-Id: <[email protected]>
Message-Id: <[email protected]>

include/qemu/plugin.h +15 -18
index e45f950fe36..ab790ad105c 100644
@@ -46,22 +46,6 @@ static inline void qemu_plugin_add_opts(void)
 
 void qemu_plugin_opt_parse(const char *optarg, QemuPluginList *head);
 int qemu_plugin_load_list(QemuPluginList *head);
-#else /* !CONFIG_PLUGIN */
-static inline void qemu_plugin_add_opts(void)
-{ }
-
-static inline void qemu_plugin_opt_parse(const char *optarg,
-                                         QemuPluginList *head)
-{
-    error_report("plugin interface not enabled in this build");
-    exit(1);
-}
-
-static inline int qemu_plugin_load_list(QemuPluginList *head)
-{
-    return 0;
-}
-#endif /* !CONFIG_PLUGIN */
 
 union qemu_plugin_cb_sig {
     qemu_plugin_simple_cb_t          simple;
@@ -182,8 +166,6 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb)
     return insn;
 }
 
-#ifdef CONFIG_PLUGIN
-
 void qemu_plugin_vcpu_init_hook(CPUState *cpu);
 void qemu_plugin_vcpu_exit_hook(CPUState *cpu);
 void qemu_plugin_tb_trans_cb(CPUState *cpu, struct qemu_plugin_tb *tb);
@@ -207,6 +189,21 @@ void qemu_plugin_disable_mem_helpers(CPUState *cpu);
 
 #else /* !CONFIG_PLUGIN */
 
+static inline void qemu_plugin_add_opts(void)
+{ }
+
+static inline void qemu_plugin_opt_parse(const char *optarg,
+                                         QemuPluginList *head)
+{
+    error_report("plugin interface not enabled in this build");
+    exit(1);
+}
+
+static inline int qemu_plugin_load_list(QemuPluginList *head)
+{
+    return 0;
+}
+
 static inline void qemu_plugin_vcpu_init_hook(CPUState *cpu)
 { }
 
Signature · 1 line
2.20.1
#4 lore raw

[PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

In reply to Alex Bennée

From: Richard Henderson <[email protected]>

We cannot at present limit a 64-bit guest to a virtual address space smaller than the host. It will mostly work to ignore this limitation, except if the guest uses high bits of the address space for tags. But it will certainly work better, as presently we can wind up failing to allocate the guest stack.

Widen our user-only page tree to the host or abi pointer width. Remove the workaround for this problem from target/alpha. Always validate guest addresses vs reserved_va, as there we control allocation ourselves.

Message-Id: <[email protected]>

include/exec/cpu-all.h +19 -4
index 0895a57881a..d14374bdd49 100644
@@ -162,12 +162,27 @@ extern unsigned long guest_base;
 extern bool have_guest_base;
 extern unsigned long reserved_va;
 
-#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
-#define GUEST_ADDR_MAX (~0ul)
+/*
+ * Limit the guest addresses as best we can.
+ *
+ * When not using -R reserved_va, we cannot really limit the guest
+ * to less address space than the host.  For 32-bit guests, this
+ * acts as a sanity check that we're not giving the guest an address
+ * that it cannot even represent.  For 64-bit guests... the address
+ * might not be what the real kernel would give, but it is at least
+ * representable in the guest.
+ *
+ * TODO: Improve address allocation to avoid this problem, and to
+ * avoid setting bits at the top of guest addresses that might need
+ * to be used for tags.
+ */
+#if MIN(TARGET_VIRT_ADDR_SPACE_BITS, TARGET_ABI_BITS) <= 32
+# define GUEST_ADDR_MAX_  UINT32_MAX
 #else
-#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : \
-                                    (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1)
+# define GUEST_ADDR_MAX_  (~0ul)
 #endif
+#define GUEST_ADDR_MAX    (reserved_va ? reserved_va - 1 : GUEST_ADDR_MAX_)
+
 #else
 
 #include "exec/hwaddr.h"
target/alpha/cpu-param.h +2 -13
index 692aee27ca9..1153992e42a 100644
@@ -10,22 +10,11 @@
 
 #define TARGET_LONG_BITS 64
 #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
+
 #define NB_MMU_MODES 3
 
 #endif
accel/tcg/translate-all.c +9 -6
index 9924e66d1f7..e4f703a7e6d 100644
@@ -173,8 +173,13 @@ struct page_collection {
 #define TB_FOR_EACH_JMP(head_tb, tb, n)                                 \
     TB_FOR_EACH_TAGGED((head_tb)->jmp_list_head, tb, n, jmp_list_next)
 
-/* In system mode we want L1_MAP to be based on ram offsets,
-   while in user mode we want it to be based on virtual addresses.  */
+/*
+ * In system mode we want L1_MAP to be based on ram offsets,
+ * while in user mode we want it to be based on virtual addresses.
+ *
+ * TODO: For user mode, see the caveat re host vs guest virtual
+ * address spaces near GUEST_ADDR_MAX.
+ */
 #if !defined(CONFIG_USER_ONLY)
 #if HOST_LONG_BITS < TARGET_PHYS_ADDR_SPACE_BITS
 # define L1_MAP_ADDR_SPACE_BITS  HOST_LONG_BITS
@@ -182,7 +187,7 @@ struct page_collection {
 # define L1_MAP_ADDR_SPACE_BITS  TARGET_PHYS_ADDR_SPACE_BITS
 #endif
 #else
-# define L1_MAP_ADDR_SPACE_BITS  TARGET_VIRT_ADDR_SPACE_BITS
+# define L1_MAP_ADDR_SPACE_BITS  MIN(HOST_LONG_BITS, TARGET_ABI_BITS)
 #endif
 
 /* Size of the L2 (and L3, etc) page tables.  */
@@ -2497,9 +2502,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)
     /* 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 TARGET_ABI_BITS > L1_MAP_ADDR_SPACE_BITS
-    assert(end <= ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS));
-#endif
+    assert(end - 1 <= GUEST_ADDR_MAX);
     assert(start < end);
     assert_memory_lock();
 
Signature · 1 line
2.20.1
#5 lore raw

Re: [PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

Quoted 13 lines · Alex Bennée

From: Richard Henderson <[email protected]>

We cannot at present limit a 64-bit guest to a virtual address space smaller than the host. It will mostly work to ignore this limitation, except if the guest uses high bits of the address space for tags. But it will certainly work better, as presently we can wind up failing to allocate the guest stack.

Widen our user-only page tree to the host or abi pointer width. Remove the workaround for this problem from target/alpha. Always validate guest addresses vs reserved_va, as there we control allocation ourselves.

Quoted 5 lines

Message-Id: <[email protected]>

This patch breaks a test case in LTP with 64bit targets on x86_64 host:

sudo linux-user/mips64el-linux-user/qemu-mips64el \
-L chroot/mips64el/stretch/ \
chroot/mips64el/stretch/opt/ltp/testcases/bin/mmap15

qemu-mips64el: accel/tcg/translate-all.c:2533: page_set_flags: Assertion `start < end' failed.
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x7f0015f6e7cb

Could you have a look?

Thanks,
Laurent

#6 lore raw

Re: [PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

Quoted 26 lines · Laurent Vivier
Quoted 13 lines · Alex Bennée

From: Richard Henderson <[email protected]>

We cannot at present limit a 64-bit guest to a virtual address space smaller than the host. It will mostly work to ignore this limitation, except if the guest uses high bits of the address space for tags. But it will certainly work better, as presently we can wind up failing to allocate the guest stack.

Widen our user-only page tree to the host or abi pointer width. Remove the workaround for this problem from target/alpha. Always validate guest addresses vs reserved_va, as there we control allocation ourselves.

Quoted 5 lines

Message-Id: <[email protected]>

This patch breaks a test case in LTP with 64bit targets on x86_64 host:

sudo linux-user/mips64el-linux-user/qemu-mips64el \
-L chroot/mips64el/stretch/ \
chroot/mips64el/stretch/opt/ltp/testcases/bin/mmap15

Quoted 6 lines

qemu-mips64el: accel/tcg/translate-all.c:2533: page_set_flags: Assertion `start < end' failed.
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x7f0015f6e7cb

Could you have a look?

Can confirm I've replicated:

18:30:20 [alex.bennee@hackbox2:~/l/q/b/user.static] next/various-fixes|✔ 32 +
sudo ./mips64el-linux-user/qemu-mips64el -L ~/lsrc/buildroot.git/builds/mips64el/target/ ~/lsrc/buildroot.git/builds/mips64el/target/usr/lib/ltp-testsuite/testcases/bin/mmap 15
[sudo] password for alex.bennee:
qemu-mips64el: /home/alex.bennee/lsrc/qemu.git/accel/tcg/translate-all.c:2533: page_set_flags: Assertion `start < end' failed. qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x6c28c2

Also TIL you can use buildroot to build ltp ;-)

Quoted 3 lines

Thanks,
Laurent

Signature · 1 line
Alex Bennée
#7 lore raw

Re: [PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

Quoted 37 lines · Alex Bennée
Quoted 26 lines · Laurent Vivier
Quoted 13 lines · Alex Bennée

From: Richard Henderson <[email protected]>

We cannot at present limit a 64-bit guest to a virtual address space smaller than the host. It will mostly work to ignore this limitation, except if the guest uses high bits of the address space for tags. But it will certainly work better, as presently we can wind up failing to allocate the guest stack.

Widen our user-only page tree to the host or abi pointer width. Remove the workaround for this problem from target/alpha. Always validate guest addresses vs reserved_va, as there we control allocation ourselves.

Quoted 5 lines

Message-Id: <[email protected]>

This patch breaks a test case in LTP with 64bit targets on x86_64 host:

sudo linux-user/mips64el-linux-user/qemu-mips64el \
-L chroot/mips64el/stretch/ \
chroot/mips64el/stretch/opt/ltp/testcases/bin/mmap15

Quoted 6 lines

qemu-mips64el: accel/tcg/translate-all.c:2533: page_set_flags: Assertion `start < end' failed.
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x7f0015f6e7cb

Could you have a look?

Can confirm I've replicated:

Quoted 8 lines

18:30:20 [alex.bennee@hackbox2:~/l/q/b/user.static] next/various-fixes|✔ 32 +
sudo ./mips64el-linux-user/qemu-mips64el -L ~/lsrc/buildroot.git/builds/mips64el/target/ ~/lsrc/buildroot.git/builds/mips64el/target/usr/lib/ltp-testsuite/testcases/bin/mmap 15
[sudo] password for alex.bennee:
qemu-mips64el: /home/alex.bennee/lsrc/qemu.git/accel/tcg/translate-all.c:2533: page_set_flags: Assertion `start < end' failed. qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x6c28c2

Also TIL you can use buildroot to build ltp ;-)

I'm not sure how the change has tripped this failure but it seems to be a simple overflow. The following fixes it but I'm curious about the formulation of guest_addr_valid and why it's written that way:

modified linux-user/mmap.c
@@ -467,7 +467,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
* It can fail only on 64-bit host with 32-bit target.
* On any other target/host host mmap() handles this error correctly. */
- if (!guest_range_valid(start, len)) {

+        if (end < start || !guest_range_valid(start, len)) {
             errno = ENOMEM;
             goto fail;
         }
Quoted 4 lines
Quoted 4 lines

Thanks,
Laurent

Signature · 1 line
Alex Bennée
#8 lore raw

Re: [PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

Review abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, · line 473

Quoted 9 lines · Alex Bennée
(quoted diff) +1 -1
@@ -467,7 +467,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
          * It can fail only on 64-bit host with 32-bit target.
          * On any other target/host host mmap() handles this error correctly.
          */
-        if (!guest_range_valid(start, len)) {
+        if (end < start || !guest_range_valid(start, len)) {
             errno = ENOMEM;
             goto fail;
         }

Interesting. I was adjusting guest_range_valid tagged pointers yesterday, and thought that it looked buggy.

r~

#9 lore raw

Re: [PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

Quoted 13 lines · Richard Henderson

Review abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, · line 473

Quoted 9 lines · Alex Bennée
(quoted diff) +1 -1
@@ -467,7 +467,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
          * It can fail only on 64-bit host with 32-bit target.
          * On any other target/host host mmap() handles this error correctly.
          */
-        if (!guest_range_valid(start, len)) {
+        if (end < start || !guest_range_valid(start, len)) {
             errno = ENOMEM;
             goto fail;
         }

Interesting. I was adjusting guest_range_valid tagged pointers yesterday, and thought that it looked buggy.

Should be picking this up in guest_range_valid?

Signature · 1 line
Alex Bennée
#10 lore raw

Re: [PULL v2 05/13] accel/tcg: Relax va restrictions on 64-bit guests

Quoted 17 lines · Alex Bennée
Quoted 13 lines · Richard Henderson

Review abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, · line 473

Quoted 9 lines · Alex Bennée
(quoted diff) +1 -1
@@ -467,7 +467,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
          * It can fail only on 64-bit host with 32-bit target.
          * On any other target/host host mmap() handles this error correctly.
          */
-        if (!guest_range_valid(start, len)) {
+        if (end < start || !guest_range_valid(start, len)) {
             errno = ENOMEM;
             goto fail;
         }

Interesting. I was adjusting guest_range_valid tagged pointers yesterday, and thought that it looked buggy.

Quoted 1 line

Should be picking this up in guest_range_valid?

I think so. How can a range really be considered valid if it wraps?

r~

#11 lore raw

[PULL v2 01/13] tests/guest-debug: catch hanging guests

In reply to Alex Bennée

If gdb never actually connected with the guest we need to catch that and clean-up after ourselves.

Message-Id: <[email protected]>

tests/guest-debug/run-test.py +6 -0
index d9af9573b9e..71c55690546 100755
@@ -80,4 +80,10 @@ if __name__ == '__main__':
         print("GDB crashed? SKIPPING")
         exit(0)
 
+    try:
+        inferior.wait(2)
+    except subprocess.TimeoutExpired:
+        print("GDB never connected? Killed guest")
+        inferior.kill()
+
     exit(result)
Signature · 1 line
2.20.1
#12 lore raw

[PULL v2 04/13] exec/cpu-all: Use bool for have_guest_base

In reply to Alex Bennée

From: Richard Henderson <[email protected]>

Message-Id: <[email protected]>

include/exec/cpu-all.h +1 -1
index 43ddcf024c6..0895a57881a 100644
@@ -159,7 +159,7 @@ static inline void tswap64s(uint64_t *s)
  * This allows the guest address space to be offset to a convenient location.
  */
 extern unsigned long guest_base;
-extern int have_guest_base;
+extern bool have_guest_base;
 extern unsigned long reserved_va;
 
 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
bsd-user/main.c +2 -2
index 28f122b80e6..0bfe46cff93 100644
@@ -42,7 +42,7 @@
 int singlestep;
 unsigned long mmap_min_addr;
 unsigned long guest_base;
-int have_guest_base;
+bool have_guest_base;
 unsigned long reserved_va;
 
 static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX;
@@ -828,7 +828,7 @@ int main(int argc, char **argv)
             }
         } else if (!strcmp(r, "B")) {
            guest_base = strtol(argv[optind++], NULL, 0);
-           have_guest_base = 1;
+           have_guest_base = true;
         } else if (!strcmp(r, "drop-ld-preload")) {
             (void) envlist_unsetenv(envlist, "LD_PRELOAD");
         } else if (!strcmp(r, "bsd")) {
linux-user/main.c +2 -2
index e18c1fb9523..3597e99bb10 100644
@@ -59,7 +59,7 @@ static const char *cpu_type;
 static const char *seed_optarg;
 unsigned long mmap_min_addr;
 unsigned long guest_base;
-int have_guest_base;
+bool have_guest_base;
 
 /*
  * Used to implement backwards-compatibility for the `-strace`, and
@@ -334,7 +334,7 @@ static void handle_arg_cpu(const char *arg)
 static void handle_arg_guest_base(const char *arg)
 {
     guest_base = strtol(arg, NULL, 0);
-    have_guest_base = 1;
+    have_guest_base = true;
 }
 
 static void handle_arg_reserved_va(const char *arg)
Signature · 1 line
2.20.1
#13 lore raw

[PULL v2 06/13] accel/tcg: don't disable exec_tb trace events

In reply to Alex Bennée

I doubt the well predicted trace event check is particularly special in the grand context of TCG code execution.

Message-Id: <[email protected]>

accel/tcg/trace-events +4 -4
index 01852217a66..385b9f749b8 100644
@@ -1,10 +1,10 @@
 # See docs/devel/tracing.txt for syntax documentation.
 
-# TCG related tracing (mostly disabled by default)
+# TCG related tracing
 # cpu-exec.c
-disable exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
-disable exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
-disable exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=0x%x"
+exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
+exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
+exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=0x%x"
 
 # translate-all.c
 translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
Signature · 1 line
2.20.1
#14 lore raw

[PULL v2 03/13] linux-user: completely re-write init_guest_space

In reply to Alex Bennée

First we ensure all guest space initialisation logic comes through probe_guest_base once we understand the nature of the binary we are loading. The convoluted init_guest_space routine is removed and replaced with a number of pgb_* helpers which are called depending on what requirements we have when loading the binary.

We first try to do what is requested by the host. Failing that we try and satisfy the guest requested base address. If all those options fail we fall back to finding a space in the memory map using our recently written read_self_maps() helper.

There are some additional complications we try and take into account when looking for holes in the address space. We try not to go directly after the system brk() space so there is space for a little growth. We also don't want to have to use negative offsets which would result in slightly less efficient code on x86 when it's unable to use the segment offset register.

Less mind-binding gotos and hopefully clearer logic throughout.

Message-Id: <[email protected]>

linux-user/qemu.h +20 -11
index 792c74290f8..ce902f5132a 100644
@@ -219,18 +219,27 @@ void init_qemu_uname_release(void);
 void fork_start(void);
 void fork_end(int child);
 
-/* Creates the initial guest address space in the host memory space using
- * the given host start address hint and size.  The guest_start parameter
- * specifies the start address of the guest space.  guest_base will be the
- * difference between the host start address computed by this function and
- * guest_start.  If fixed is specified, then the mapped address space must
- * start at host_start.  The real start address of the mapped memory space is
- * returned or -1 if there was an error.
+/**
+ * probe_guest_base:
+ * @image_name: the executable being loaded
+ * @loaddr: the lowest fixed address in the executable
+ * @hiaddr: the highest fixed address in the executable
+ *
+ * Creates the initial guest address space in the host memory space.
+ *
+ * If @loaddr == 0, then no address in the executable is fixed,
+ * i.e. it is fully relocatable.  In that case @hiaddr is the size
+ * of the executable.
+ *
+ * This function will not return if a valid value for guest_base
+ * cannot be chosen.  On return, the executable loader can expect
+ *
+ *    target_mmap(loaddr, hiaddr - loaddr, ...)
+ *
+ * to succeed.
  */
-unsigned long init_guest_space(unsigned long host_start,
-                               unsigned long host_size,
-                               unsigned long guest_start,
-                               bool fixed);
+void probe_guest_base(const char *image_name,
+                      abi_ulong loaddr, abi_ulong hiaddr);
 
 #include "qemu/log.h"
 
linux-user/elfload.c +250 -253

569 lines not on this page · raw message

linux-user/flatload.c +6 -0
index 66901f39cc5..8fb448f0bf0 100644
@@ -441,6 +441,12 @@ static int load_flat_file(struct linux_binprm * bprm,
     indx_len = MAX_SHARED_LIBS * sizeof(abi_ulong);
     indx_len = (indx_len + 15) & ~(abi_ulong)15;
 
+    /*
+     * Alloate the address space.
+     */
+    probe_guest_base(bprm->filename, 0,
+                     text_len + data_len + extra + indx_len);
+
     /*
      * there are a couple of cases here,  the separate code/data
      * case,  and then the fully copied to RAM case which lumps
linux-user/main.c +1 -22
index 2cd443237d8..e18c1fb9523 100644
@@ -24,6 +24,7 @@
 #include "qemu-version.h"
 #include <sys/syscall.h>
 #include <sys/resource.h>
+#include <sys/shm.h>
 
 #include "qapi/error.h"
 #include "qemu.h"
@@ -747,28 +748,6 @@ int main(int argc, char **argv, char **envp)
     target_environ = envlist_to_environ(envlist, NULL);
     envlist_free(envlist);
 
-    /*
-     * Now that page sizes are configured in tcg_exec_init() we can do
-     * proper page alignment for guest_base.
-     */
-    guest_base = HOST_PAGE_ALIGN(guest_base);
-
-    if (reserved_va || have_guest_base) {
-        guest_base = init_guest_space(guest_base, reserved_va, 0,
-                                      have_guest_base);
-        if (guest_base == (unsigned long)-1) {
-            fprintf(stderr, "Unable to reserve 0x%lx bytes of virtual address "
-                    "space for use as guest address space (check your virtual "
-                    "memory ulimit setting or reserve less using -R option)\n",
-                    reserved_va);
-            exit(EXIT_FAILURE);
-        }
-
-        if (reserved_va) {
-            mmap_next_start = reserved_va;
-        }
-    }
-
     /*
      * Read in mmap_min_addr kernel parameter.  This value is used
      * When loading the ELF image to determine whether guest_base
Signature · 1 line
2.20.1
#15 lore raw

[PULL v2 08/13] disas: add optional note support to cap_disas

In reply to Alex Bennée

Include support for outputting a note at the top of a chunk of disassembly to capstone as well.

Message-Id: <[email protected]>

disas.c +15 -8
index 7e8692de301..45285d3f63f 100644
@@ -260,7 +260,8 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn,
     }
 }
 
-static void cap_dump_insn(disassemble_info *info, cs_insn *insn)
+static void cap_dump_insn(disassemble_info *info, cs_insn *insn,
+                          const char *note)
 {
     fprintf_function print = info->fprintf_func;
     int i, n, split;
@@ -281,7 +282,11 @@ static void cap_dump_insn(disassemble_info *info, cs_insn *insn)
     }
 
     /* Print the actual instruction.  */
-    print(info->stream, "  %-8s %s\n", insn->mnemonic, insn->op_str);
+    print(info->stream, "  %-8s %s", insn->mnemonic, insn->op_str);
+    if (note) {
+        print(info->stream, "\t\t%s", note);
+    }
+    print(info->stream, "\n");
 
     /* Dump any remaining part of the insn on subsequent lines.  */
     for (i = split; i < n; i += split) {
@@ -313,7 +318,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
         size -= tsize;
 
         while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
-           cap_dump_insn(info, insn);
+            cap_dump_insn(info, insn, NULL);
         }
 
         /* If the target memory is not consumed, go back for more... */
@@ -342,7 +347,8 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
 }
 
 /* Disassemble SIZE bytes at CODE for the host.  */
-static bool cap_disas_host(disassemble_info *info, void *code, size_t size)
+static bool cap_disas_host(disassemble_info *info, void *code, size_t size,
+                           const char *note)
 {
     csh handle;
     const uint8_t *cbuf;
@@ -358,7 +364,8 @@ static bool cap_disas_host(disassemble_info *info, void *code, size_t size)
     pc = (uintptr_t)code;
 
     while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) {
-       cap_dump_insn(info, insn);
+        cap_dump_insn(info, insn, note);
+        note = NULL;
     }
     if (size != 0) {
         (*info->fprintf_func)(info->stream,
@@ -402,7 +409,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
         csize += tsize;
 
         if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
-            cap_dump_insn(info, insn);
+            cap_dump_insn(info, insn, NULL);
             if (--count <= 0) {
                 break;
             }
@@ -416,7 +423,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
 #endif /* !CONFIG_USER_ONLY */
 #else
 # define cap_disas_target(i, p, s)  false
-# define cap_disas_host(i, p, s)  false
+# define cap_disas_host(i, p, s, n)  false
 # define cap_disas_monitor(i, p, c)  false
 # define cap_disas_plugin(i, p, c) false
 #endif /* CONFIG_CAPSTONE */
@@ -664,7 +671,7 @@ void disas(FILE *out, void *code, unsigned long size, const char *note)
     print_insn = print_insn_hppa;
 #endif
 
-    if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) {
+    if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size, note)) {
         return;
     }
 
Signature · 1 line
2.20.1
#16 lore raw

[PULL v2 09/13] translate-all: include guest address in out_asm output

In reply to Alex Bennée

We already have information about where each guest instructions representation starts stored in the tcg_ctx->gen_insn_data so we can rectify the PC for faults. We can re-use this information to annotate the out_asm output with guest instruction address which makes it a bit easier to work out where you are especially with longer blocks. A minor wrinkle is that some instructions get optimised away so we have to scan forward until we find some actual generated code.

Message-Id: <[email protected]>

accel/tcg/translate-all.c +33 -6
index cdf58bb420e..42ce1dfcff7 100644
@@ -1794,14 +1794,43 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) &&
         qemu_log_in_addr_range(tb->pc)) {
         FILE *logfile = qemu_log_lock();
+        int code_size, data_size = 0;
+        g_autoptr(GString) note = g_string_new("[tb header & initial instruction]");
+        size_t chunk_start = 0;
+        int insn = 0;
         qemu_log("OUT: [size=%d]\n", gen_code_size);
         if (tcg_ctx->data_gen_ptr) {
-            size_t code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr;
-            size_t data_size = gen_code_size - code_size;
-            size_t i;
+            code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr;
+            data_size = gen_code_size - code_size;
+        } else {
+            code_size = gen_code_size;
+        }
 
-            log_disas(tb->tc.ptr, code_size, NULL);
+        /* Dump header and the first instruction */
+        chunk_start = tcg_ctx->gen_insn_end_off[insn];
+        log_disas(tb->tc.ptr, chunk_start, note->str);
 
+        /*
+         * Dump each instruction chunk, wrapping up empty chunks into
+         * the next instruction. The whole array is offset so the
+         * first entry is the beginning of the 2nd instruction.
+         */
+        while (insn <= tb->icount && chunk_start < code_size) {
+            size_t chunk_end = tcg_ctx->gen_insn_end_off[insn];
+            if (chunk_end > chunk_start) {
+                g_string_printf(note, "[guest addr: " TARGET_FMT_lx "]",
+                                tcg_ctx->gen_insn_data[insn][0]);
+                log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_start,
+                          note->str);
+                chunk_start = chunk_end;
+            }
+            insn++;
+        }
+
+        /* Finally dump any data we may have after the block */
+        if (data_size) {
+            int i;
+            qemu_log("  data: [size=%d]\n", data_size);
             for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) {
                 if (sizeof(tcg_target_ulong) == 8) {
                     qemu_log("0x%08" PRIxPTR ":  .quad  0x%016" PRIx64 "\n",
@@ -1813,8 +1842,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
                              *(uint32_t *)(tcg_ctx->data_gen_ptr + i));
                 }
             }
-        } else {
-            log_disas(tb->tc.ptr, gen_code_size, NULL);
         }
         qemu_log("\n");
         qemu_log_flush();
Signature · 1 line
2.20.1
#17 lore raw

[PULL v2 07/13] disas: include an optional note for the start of disassembly

In reply to Alex Bennée

This will become useful shortly for providing more information about output assembly inline. While there fix up the indenting and code formatting in disas().

Message-Id: <[email protected]>

include/disas/disas.h +1 -1
index 36c33f6f194..1b6e035e32d 100644
@@ -7,7 +7,7 @@
 #include "cpu.h"
 
 /* Disassemble this for me please... (debugging). */
-void disas(FILE *out, void *code, unsigned long size);
+void disas(FILE *out, void *code, unsigned long size, const char *note);
 void target_disas(FILE *out, CPUState *cpu, target_ulong code,
                   target_ulong size);
 
include/exec/log.h +2 -2
index fcc7b9e00ba..3ed797c1c8c 100644
@@ -56,13 +56,13 @@ static inline void log_target_disas(CPUState *cpu, target_ulong start,
     rcu_read_unlock();
 }
 
-static inline void log_disas(void *code, unsigned long size)
+static inline void log_disas(void *code, unsigned long size, const char *note)
 {
     QemuLogFile *logfile;
     rcu_read_lock();
     logfile = atomic_rcu_read(&qemu_logfile);
     if (logfile) {
-        disas(logfile->fd, code, size);
+        disas(logfile->fd, code, size, note);
     }
     rcu_read_unlock();
 }
accel/tcg/translate-all.c +2 -2
index e4f703a7e6d..cdf58bb420e 100644
@@ -1800,7 +1800,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
             size_t data_size = gen_code_size - code_size;
             size_t i;
 
-            log_disas(tb->tc.ptr, code_size);
+            log_disas(tb->tc.ptr, code_size, NULL);
 
             for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) {
                 if (sizeof(tcg_target_ulong) == 8) {
@@ -1814,7 +1814,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
                 }
             }
         } else {
-            log_disas(tb->tc.ptr, gen_code_size);
+            log_disas(tb->tc.ptr, gen_code_size, NULL);
         }
         qemu_log("\n");
         qemu_log_flush();
disas.c +10 -4
index 3937da61571..7e8692de301 100644
@@ -586,7 +586,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
 }
 
 /* Disassemble this for me please... (debugging). */
-void disas(FILE *out, void *code, unsigned long size)
+void disas(FILE *out, void *code, unsigned long size, const char *note)
 {
     uintptr_t pc;
     int count;
@@ -674,10 +674,16 @@ void disas(FILE *out, void *code, unsigned long size)
     for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) {
         fprintf(out, "0x%08" PRIxPTR ":  ", pc);
         count = print_insn(pc, &s.info);
-	fprintf(out, "\n");
-	if (count < 0)
-	    break;
+        if (note) {
+            fprintf(out, "\t\t%s", note);
+            note = NULL;
+        }
+        fprintf(out, "\n");
+        if (count < 0) {
+            break;
+        }
     }
+
 }
 
 /* Look up symbol for debugging purpose.  Returns "" if unknown. */
tcg/tcg.c +2 -2
index dd4b3d76844..a2268d9db0a 100644
@@ -1092,7 +1092,7 @@ void tcg_prologue_init(TCGContext *s)
             size_t data_size = prologue_size - code_size;
             size_t i;
 
-            log_disas(buf0, code_size);
+            log_disas(buf0, code_size, NULL);
 
             for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) {
                 if (sizeof(tcg_target_ulong) == 8) {
@@ -1106,7 +1106,7 @@ void tcg_prologue_init(TCGContext *s)
                 }
             }
         } else {
-            log_disas(buf0, prologue_size);
+            log_disas(buf0, prologue_size, NULL);
         }
         qemu_log("\n");
         qemu_log_flush();
Signature · 1 line
2.20.1
#18 lore raw

[PULL v2 13/13] MAINTAINERS: update the orphaned cpus-common.c file

In reply to Alex Bennée

We forgot to update MAINTAINERS when this code was re-factored.

Message-Id: <[email protected]>

MAINTAINERS +1 -0
index f02e2907023..47ef3139e6d 100644
@@ -115,6 +115,7 @@ M: Richard Henderson <[email protected]>
 R: Paolo Bonzini <[email protected]>
 S: Maintained
 F: cpus.c
+F: cpus-common.c
 F: exec.c
 F: accel/tcg/
 F: accel/stubs/tcg-stub.c
Signature · 1 line
2.20.1
#19 lore raw

[PULL v2 12/13] qemu/qemu-plugin: Make qemu_plugin_hwaddr_is_io() hwaddr argument const

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Rename qemu_plugin_hwaddr_is_io() address argument 'haddr' similarly to qemu_plugin_hwaddr_device_offset(), and make it const.

Message-Id: <[email protected]>
Message-Id: <[email protected]>

include/qemu/qemu-plugin.h +1 -1
index 5502e112c81..89ed579f559 100644
@@ -331,7 +331,7 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
  * to return information about it. For non-IO accesses the device
  * offset will be into the appropriate block of RAM.
  */
-bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr);
+bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr);
 uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr);
 
 typedef void
plugins/api.c +2 -2
index 53c8a735823..bbdc5a4eb46 100644
@@ -275,10 +275,10 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
 }
 #endif
 
-bool qemu_plugin_hwaddr_is_io(struct qemu_plugin_hwaddr *hwaddr)
+bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr)
 {
 #ifdef CONFIG_SOFTMMU
-    return hwaddr->is_io;
+    return haddr->is_io;
 #else
     return false;
 #endif
Signature · 1 line
2.20.1
#20 lore raw
In reply to Alex Bennée
Quoted 16 lines · Alex Bennée

The following changes since commit 2478b8ecd45f81a21b9aa319ce7147a790a2144f:

Merge remote-tracking branch 'remotes/kraxel/tags/ui-20200515-pull-request' into staging (2020-05-15 11:18:13 +0100)

are available in the Git repository at:

https://github.com/stsquad/qemu.git tags/pull-testing-tcg-plugins-150520-2

for you to fetch changes up to adf1cfbdc29e6e3342ca07701be4d2cbfd7d3907:

MAINTAINERS: update the orphaned cpus-common.c file (2020-05-15 15:25:16 +0100)

----------------------------------------------------------------
Various testing, tcg and plugin updates

Quoted 7 lines

- fix bug in gdbstub tests that leave hanging QEMUs
- tweak s390x travis test
- re-factor guest_base handling
- support "notes" in disassembler output
- include guest address notes in out_asm
- cleanup plugin headers and and constify hwaddr
- updates MAINTAINERS for cpu-common.c

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM