Skip to contentSkip to conversation

KVM and cpu-exec patches for 2.9 soft freeze

GIT PULL Paolo Bonzini 2 participants 7 messages Feb 28, 2017 – Mar 2, 2017

lore
Share & tools
lore
#0 lore raw

The following changes since commit d992f2f1368ceb92e6bfd8efece174110f4236ff:

Merge remote-tracking branch 'remotes/artyom/tags/pull-sun4v-20170226' into staging (2017-02-26 22:40:23 +0000)

are available in the git repository at:

git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to b9a93b6cfddd348286cd8e44d7c4d964d9553a9f:

vl: disable default cdrom when using explicitely scsi-hd (2017-02-28 11:51:12 +0100)

v3->v4: added two patches

fixed #ifdef KVM_HAVE_MCE_INJECTION

v2->v3: replace SIGPOLL with SIGIO

another missing #ifdef KVM_HAVE_MCE_INJECTION

v1->v2: add missing #ifdef KVM_HAVE_MCE_INJECTION

rebase over MTTCG pull request. -icount is currently broken but I'd like to preserve bisectability, so this pull request brings in the icount patches through a merge commit.

----------------------------------------------------------------
* kernel header update (requested by David and Vijay)
* GuestPanicInformation fixups (Anton)
* record/replay icount fixes (Pavel)
* cpu-exec cleanup, unification of icount_decr with tcg_exit_req (me)
* KVM_CAP_IMMEDIATE_EXIT support (me)
* vmxcap update (me)
* VFIO ram device fix (Yongji)
* scsi-hd vs. default CD-ROM (Hervé)

----------------------------------------------------------------
Anton Nefedov (2):
qapi: flatten GuestPanicInformation union
qmp-events: fix GUEST_PANICKED description formatting

Hervé Poussineau (1):
vl: disable default cdrom when using explicitely scsi-hd

Paolo Bonzini (15):
cpu-exec: unify icount_decr and tcg_exit_req
cpu-exec: remove unnecessary check of cpu->exit_request Merge branch 'refs/heads/icount-update' into HEAD
update-linux-headers: update for 4.11
update Linux headers to 4.11
cpus: remove ugly cast on sigbus_handler
KVM: x86: cleanup SIGBUS handlers
cpus: reorganize signal handling code
KVM: remove kvm_arch_on_sigbus
KVM: do not use sigtimedwait to catch SIGBUS
KVM: move SIG_IPI handling to kvm-all.c
kvm: use atomic_read/atomic_set to access cpu->exit_request
KVM: use KVM_CAP_IMMEDIATE_EXIT
vmxcap: port to Python 3
vmxcap: update for September 2016 SDM

Pavel Dovgalyuk (1):
replay: check icount in cpu exec loop

Yongji Xie (1):
memory: Introduce DEVICE_HOST_ENDIAN for ram device

 cpu-exec.c                                         |  93 ++---
 cpus.c                                             | 102 +----
 include/exec/cpu-common.h                          |   6 +
 include/exec/gen-icount.h                          |  53 ++-
 include/qemu/compatfd.h                            |  42 ---
 include/qemu/osdep.h                               |  37 ++
 include/qom/cpu.h                                  |  15 +-
 include/standard-headers/asm-x86/hyperv.h          |   8 +
 include/standard-headers/linux/input-event-codes.h |   2 +-
 include/standard-headers/linux/pci_regs.h          |  25 ++
 include/standard-headers/linux/virtio_ids.h        |   1 +
 include/sysemu/kvm.h                               |  11 +-
 kvm-all.c                                          | 150 +++++++-
 kvm-stub.c                                         |  12 +-
 linux-headers/asm-arm/kvm.h                        |  15 +
 linux-headers/asm-arm/unistd-common.h              | 357 ++++++++++++++++++
 linux-headers/asm-arm/unistd-eabi.h                |   5 +
 linux-headers/asm-arm/unistd-oabi.h                |  17 +
 linux-headers/asm-arm/unistd.h                     | 419 +--------------------
 linux-headers/asm-arm64/kvm.h                      |  13 +
 linux-headers/asm-powerpc/kvm.h                    |  27 ++
 linux-headers/asm-powerpc/unistd.h                 |   1 +
 linux-headers/asm-x86/kvm_para.h                   |  13 +-
 linux-headers/linux/kvm.h                          |  24 +-
 linux-headers/linux/kvm_para.h                     |   2 +
 linux-headers/linux/userfaultfd.h                  |  67 +++-
 linux-headers/linux/vfio.h                         |  10 +
 memory.c                                           |   2 +-
 qapi-schema.json                                   |  12 +
 qapi/event.json                                    |   4 +-
 qom/cpu.c                                          |   2 +-
 scripts/kvm/vmxcap                                 |  23 +-
 scripts/update-linux-headers.sh                    |  13 +-
 target/arm/kvm.c                                   |  10 -
 target/i386/cpu.c                                  |  15 +-
 target/i386/kvm.c                                  |  81 ++--
 target/mips/kvm.c                                  |  12 -
 target/ppc/kvm.c                                   |  10 -
 target/s390x/kvm.c                                 |  10 -
 tcg/tcg.h                                          |   1 -
 translate-all.c                                    |   2 +-
 translate-common.c                                 |  13 +-
 util/compatfd.c                                    |   1 -
 util/main-loop.c                                   |   5 +-
 util/oslib-posix.c                                 |  33 ++
 vl.c                                               |  13 +-
 46 files changed, 976 insertions(+), 813 deletions(-)
 delete mode 100644 include/qemu/compatfd.h
 create mode 100644 linux-headers/asm-arm/unistd-common.h
 create mode 100644 linux-headers/asm-arm/unistd-eabi.h
 create mode 100644 linux-headers/asm-arm/unistd-oabi.h
#1 lore raw

[Qemu-devel] [PULL 18/19] memory: Introduce DEVICE_HOST_ENDIAN for ram device

From: Yongji Xie <[email protected]>

At the moment ram device's memory regions are DEVICE_NATIVE_ENDIAN. It's incorrect. This memory region is backed by a MMIO area in host, so the uint64_t data that MemoryRegionOps read from/write to this area should be host-endian rather than target-endian. Hence, current code does not work when target and host endianness are different which is the most common case on PPC64. To fix it, this introduces DEVICE_HOST_ENDIAN for the ram device.

This has been tested on PPC64 BE/LE host/guest in all possible combinations including TCG.

Message-Id: <[email protected]>

---
 include/exec/cpu-common.h | 6 ++++++
 memory.c                  | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
include/exec/cpu-common.h +6 -0
index bd15853..eef74df 100644
@@ -36,6 +36,12 @@ enum device_endian {
     DEVICE_LITTLE_ENDIAN,
 };
 
+#if defined(HOST_WORDS_BIGENDIAN)
+#define DEVICE_HOST_ENDIAN DEVICE_BIG_ENDIAN
+#else
+#define DEVICE_HOST_ENDIAN DEVICE_LITTLE_ENDIAN
+#endif
+
 /* address in the RAM (different from a physical address) */
 #if defined(CONFIG_XEN_BACKEND)
 typedef uint64_t ram_addr_t;
memory.c +1 -1
index d61caee..573fa6e 100644
@@ -1182,7 +1182,7 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,
 static const MemoryRegionOps ram_device_mem_ops = {
     .read = memory_region_ram_device_read,
     .write = memory_region_ram_device_write,
-    .endianness = DEVICE_NATIVE_ENDIAN,
+    .endianness = DEVICE_HOST_ENDIAN,
     .valid = {
         .min_access_size = 1,
         .max_access_size = 8,
Signature · 1 line
2.9.3
#2 lore raw

[Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS

In reply to Paolo Bonzini

Call kvm_on_sigbus_vcpu asynchronously from the VCPU thread. Information for the SIGBUS can be stored in thread-local variables and processed later in kvm_cpu_exec.

---
 cpus.c               | 31 +++++++++++++------------------
 include/sysemu/kvm.h |  5 ++++-
 kvm-all.c            | 35 ++++++++++++++++++++++++++++++++++-
 target/arm/kvm.c     |  5 -----
 target/i386/kvm.c    |  5 ++---
 target/mips/kvm.c    |  6 ------
 target/ppc/kvm.c     |  5 -----
 target/s390x/kvm.c   |  5 -----
 8 files changed, 53 insertions(+), 44 deletions(-)
cpus.c +13 -18
index 399e271..56b1338 100644
@@ -926,8 +926,16 @@ static void sigbus_handler(int n, siginfo_t *siginfo, void *ctx)
         sigbus_reraise();
     }
 
-    if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) {
-        sigbus_reraise();
+    if (current_cpu) {
+        /* Called asynchronously in VCPU thread.  */
+        if (kvm_on_sigbus_vcpu(current_cpu, siginfo->si_code, siginfo->si_addr)) {
+            sigbus_reraise();
+        }
+    } else {
+        /* Called synchronously (via signalfd) in main thread.  */
+        if (kvm_on_sigbus(siginfo->si_code, siginfo->si_addr)) {
+            sigbus_reraise();
+        }
     }
 }
 
@@ -958,8 +966,9 @@ static void qemu_kvm_init_cpu_signals(CPUState *cpu)
     sigaction(SIG_IPI, &sigact, NULL);
 
     pthread_sigmask(SIG_BLOCK, NULL, &set);
-    sigdelset(&set, SIG_IPI);
     sigdelset(&set, SIGBUS);
+    pthread_sigmask(SIG_SETMASK, &set, NULL);
+    sigdelset(&set, SIG_IPI);
     r = kvm_set_signal_mask(cpu, &set);
     if (r) {
         fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r));
@@ -977,7 +986,6 @@ static void qemu_kvm_eat_signals(CPUState *cpu)
 
     sigemptyset(&waitset);
     sigaddset(&waitset, SIG_IPI);
-    sigaddset(&waitset, SIGBUS);
 
     do {
         r = sigtimedwait(&waitset, &siginfo, &ts);
@@ -986,25 +994,12 @@ static void qemu_kvm_eat_signals(CPUState *cpu)
             exit(1);
         }
 
-        switch (r) {
-        case SIGBUS:
-            if (siginfo.si_code != BUS_MCEERR_AO && siginfo.si_code != BUS_MCEERR_AR) {
-                sigbus_reraise();
-            }
-            if (kvm_on_sigbus_vcpu(cpu, siginfo.si_code, siginfo.si_addr)) {
-                sigbus_reraise();
-            }
-            break;
-        default:
-            break;
-        }
-
         r = sigpending(&chkset);
         if (r == -1) {
             perror("sigpending");
             exit(1);
         }
-    } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS));
+    } while (sigismember(&chkset, SIG_IPI));
 }
 #else /* !CONFIG_LINUX */
 static void qemu_init_sigbus(void)
include/sysemu/kvm.h +4 -1
index 6ecb61c..a1b019d 100644
@@ -357,7 +357,10 @@ bool kvm_vcpu_id_is_valid(int vcpu_id);
 /* Returns VCPU ID to be used on KVM_CREATE_VCPU ioctl() */
 unsigned long kvm_arch_vcpu_id(CPUState *cpu);
 
-int kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
+#ifdef TARGET_I386
+#define KVM_HAVE_MCE_INJECTION 1
+void kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
+#endif
 
 void kvm_arch_init_irq_routing(KVMState *s);
 
kvm-all.c +34 -1
index a433ad3..0baa193 100644
@@ -1893,6 +1893,12 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu)
     run_on_cpu(cpu, do_kvm_cpu_synchronize_post_init, RUN_ON_CPU_NULL);
 }
 
+#ifdef KVM_HAVE_MCE_INJECTION
+static __thread void *pending_sigbus_addr;
+static __thread int pending_sigbus_code;
+static __thread bool have_sigbus_pending;
+#endif
+
 int kvm_cpu_exec(CPUState *cpu)
 {
     struct kvm_run *run = cpu->kvm_run;
@@ -1930,6 +1936,16 @@ int kvm_cpu_exec(CPUState *cpu)
 
         attrs = kvm_arch_post_run(cpu, run);
 
+#ifdef KVM_HAVE_MCE_INJECTION
+        if (unlikely(have_sigbus_pending)) {
+            qemu_mutex_lock_iothread();
+            kvm_arch_on_sigbus_vcpu(cpu, pending_sigbus_code,
+                                    pending_sigbus_addr);
+            have_sigbus_pending = false;
+            qemu_mutex_unlock_iothread();
+        }
+#endif
+
         if (run_ret < 0) {
             if (run_ret == -EINTR || run_ret == -EAGAIN) {
                 DPRINTF("io window exit\n");
@@ -2392,13 +2408,27 @@ int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset)
     return r;
 }
 
+/* Called asynchronously in VCPU thread.  */
 int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
 {
-    return kvm_arch_on_sigbus_vcpu(cpu, code, addr);
+#ifdef KVM_HAVE_MCE_INJECTION
+    if (have_sigbus_pending) {
+        return 1;
+    }
+    have_sigbus_pending = true;
+    pending_sigbus_addr = addr;
+    pending_sigbus_code = code;
+    atomic_set(&cpu->exit_request, 1);
+    return 0;
+#else
+    return 1;
+#endif
 }
 
+/* Called synchronously (via signalfd) in main thread.  */
 int kvm_on_sigbus(int code, void *addr)
 {
+#ifdef KVM_HAVE_MCE_INJECTION
     /* Action required MCE kills the process if SIGBUS is blocked.  Because
      * that's what happens in the I/O thread, where we handle MCE via signalfd,
      * we can only get action optional here.
@@ -2406,6 +2436,9 @@ int kvm_on_sigbus(int code, void *addr)
     assert(code != BUS_MCEERR_AR);
     kvm_arch_on_sigbus_vcpu(first_cpu, code, addr);
     return 0;
+#else
+    return 1;
+#endif
 }
 
 int kvm_create_device(KVMState *s, uint64_t type, bool test)
target/arm/kvm.c +0 -5
index e5218f6..4555468 100644
@@ -560,11 +560,6 @@ int kvm_arch_process_async_events(CPUState *cs)
     return 0;
 }
 
-int kvm_arch_on_sigbus_vcpu(CPUState *cs, int code, void *addr)
-{
-    return 1;
-}
-
 /* The #ifdef protections are until 32bit headers are imported and can
  * be removed once both 32 and 64 bit reach feature parity.
  */
target/i386/kvm.c +2 -3
index 2adf992..7698421 100644
@@ -455,7 +455,7 @@ static void hardware_memory_error(void)
     exit(1);
 }
 
-int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
+void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
 {
     X86CPU *cpu = X86_CPU(c);
     CPUX86State *env = &cpu->env;
@@ -475,7 +475,7 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
             kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)) {
             kvm_hwpoison_page_add(ram_addr);
             kvm_mce_inject(cpu, paddr, code);
-            return 0;
+            return;
         }
 
         fprintf(stderr, "Hardware memory error for memory used by "
@@ -487,7 +487,6 @@ int kvm_arch_on_sigbus_vcpu(CPUState *c, int code, void *addr)
     }
 
     /* Hope we are lucky for AO MCE */
-    return 0;
 }
 
 static int kvm_inject_mce_oldstyle(X86CPU *cpu)
target/mips/kvm.c +0 -6
index 3e686e7..0982e87 100644
@@ -180,12 +180,6 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
     return true;
 }
 
-int kvm_arch_on_sigbus_vcpu(CPUState *cs, int code, void *addr)
-{
-    DPRINTF("%s\n", __func__);
-    return 1;
-}
-
 void kvm_arch_init_irq_routing(KVMState *s)
 {
 }
target/ppc/kvm.c +0 -5
index bc011c6..f22ecab 100644
@@ -2582,11 +2582,6 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu)
     return true;
 }
 
-int kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
-{
-    return 1;
-}
-
 void kvm_arch_init_irq_routing(KVMState *s)
 {
 }
target/s390x/kvm.c +0 -5
index e7eea6d..ac47154 100644
@@ -2140,11 +2140,6 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cpu)
     return true;
 }
 
-int kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
-{
-    return 1;
-}
-
 void kvm_s390_io_interrupt(uint16_t subchannel_id,
                            uint16_t subchannel_nr, uint32_t io_int_parm,
                            uint32_t io_int_word)
Signature · 1 line
2.9.3
#3 lore raw

[Qemu-devel] [PULL 19/19] vl: disable default cdrom when using explicitely scsi-hd

In reply to Paolo Bonzini

From: Hervé Poussineau <[email protected]>

In commit af6bf1328ef90fae617857c02697e0174b84d596 (May 2011), ide-hd, ide-cd and scsi-cd have been added to disable default cdrom, "or else you can't put one on secondary master without -nodefaults".

Make it the same for scsi-hd, so you can put one on scsi-id 2 without using -nodefaults.
scsi-hd has probably been forgotten, as it has been added in the preceding commit (b443ae67130d32ad06b06fc9aa6d04d05ccd93ce).

Affected users are the ones using a machine with SCSI devices and start QEMU with -device scsi-hd but without -device scsi-cd or -cdrom
In that case, the default cdrom device will disappear instead of being empty.

Message-Id: <[email protected]>

---
 vl.c | 1 +
 1 file changed, 1 insertion(+)
vl.c +1 -0
index 7f57ded..16a3b5e 100644
@@ -227,6 +227,7 @@ static struct {
     { .driver = "ide-hd",               .flag = &default_cdrom     },
     { .driver = "ide-drive",            .flag = &default_cdrom     },
     { .driver = "scsi-cd",              .flag = &default_cdrom     },
+    { .driver = "scsi-hd",              .flag = &default_cdrom     },
     { .driver = "virtio-serial-pci",    .flag = &default_virtcon   },
     { .driver = "virtio-serial",        .flag = &default_virtcon   },
     { .driver = "VGA",                  .flag = &default_vga       },
Signature · 1 line
2.9.3
#4 lore raw
In reply to Paolo Bonzini
Quoted 18 lines · Paolo Bonzini

The following changes since commit d992f2f1368ceb92e6bfd8efece174110f4236ff:

Merge remote-tracking branch 'remotes/artyom/tags/pull-sun4v-20170226' into staging (2017-02-26 22:40:23 +0000)

are available in the git repository at:

git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to b9a93b6cfddd348286cd8e44d7c4d964d9553a9f:

vl: disable default cdrom when using explicitely scsi-hd (2017-02-28 11:51:12 +0100)

v3->v4: added two patches

fixed #ifdef KVM_HAVE_MCE_INJECTION

v2->v3: replace SIGPOLL with SIGIO

Quoted 7 lines

another missing #ifdef KVM_HAVE_MCE_INJECTION

v1->v2: add missing #ifdef KVM_HAVE_MCE_INJECTION

rebase over MTTCG pull request. -icount is currently broken but I'd like to preserve bisectability, so this pull request brings in the icount patches through a merge commit.

Fails to build, ppc64, aarch64 (and probably others):

In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,

                 from /home/pm215/qemu/kvm-all.c:16:
/home/pm215/qemu/kvm-all.c: In function ‘kvm_cpu_exec’:
/home/pm215/qemu/kvm-all.c:1995:22: error: ‘have_sigbus_pending’
undeclared (first use in this function)
         if (unlikely(have_sigbus_pending)) {
                      ^
/home/pm215/qemu/include/qemu/compiler.h:66:43: note: in definition of
macro ‘unlikely’
 #define unlikely(x)   __builtin_expect(!!(x), 0)
                                           ^
/home/pm215/qemu/kvm-all.c:1995:22: note: each undeclared identifier
is reported only once for each function it appears in
         if (unlikely(have_sigbus_pending)) {
                      ^
/home/pm215/qemu/include/qemu/compiler.h:66:43: note: in definition of
macro ‘unlikely’
 #define unlikely(x)   __builtin_expect(!!(x), 0)
                                           ^

thanks
-- PMM

#5 lore raw
Quoted 17 lines · Peter Maydell

Fails to build, ppc64, aarch64 (and probably others):

In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,

                 from /home/pm215/qemu/kvm-all.c:16:
/home/pm215/qemu/kvm-all.c: In function ‘kvm_cpu_exec’:
/home/pm215/qemu/kvm-all.c:1995:22: error: ‘have_sigbus_pending’
undeclared (first use in this function)
         if (unlikely(have_sigbus_pending)) {
                      ^
/home/pm215/qemu/include/qemu/compiler.h:66:43: note: in definition of
macro ‘unlikely’
 #define unlikely(x)   __builtin_expect(!!(x), 0)
                                           ^
/home/pm215/qemu/kvm-all.c:1995:22: note: each undeclared identifier
is reported only once for each function it appears in
         if (unlikely(have_sigbus_pending)) {
                      ^
Quoted 3 lines

/home/pm215/qemu/include/qemu/compiler.h:66:43: note: in definition of macro ‘unlikely’
#define unlikely(x) __builtin_expect(!!(x), 0)

Are you sure you updated the tag? Line 1995 here is:

#ifdef KVM_HAVE_MCE_INJECTION

and that error would have come from v3.

Paolo

#6 lore raw
Quoted 24 lines · Paolo Bonzini
Quoted 17 lines · Peter Maydell

Fails to build, ppc64, aarch64 (and probably others):

In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,

                 from /home/pm215/qemu/kvm-all.c:16:
/home/pm215/qemu/kvm-all.c: In function ‘kvm_cpu_exec’:
/home/pm215/qemu/kvm-all.c:1995:22: error: ‘have_sigbus_pending’
undeclared (first use in this function)
         if (unlikely(have_sigbus_pending)) {
                      ^
/home/pm215/qemu/include/qemu/compiler.h:66:43: note: in definition of
macro ‘unlikely’
 #define unlikely(x)   __builtin_expect(!!(x), 0)
                                           ^
/home/pm215/qemu/kvm-all.c:1995:22: note: each undeclared identifier
is reported only once for each function it appears in
         if (unlikely(have_sigbus_pending)) {
                      ^
Quoted 3 lines

/home/pm215/qemu/include/qemu/compiler.h:66:43: note: in definition of macro ‘unlikely’
#define unlikely(x) __builtin_expect(!!(x), 0)

Quoted 1 line

Are you sure you updated the tag?

Your cover letter says "changes up to b9a93b6cfd" but the tag is of commit 0819248. My script always does a git fetch, so it looks to me like maybe you failed to push the new tag?

thanks
-- PMM