* [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze @ 2017-02-28 16:13 Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini ` (3 more replies) 0 siblings, 4 replies; 8+ messages in thread From: Paolo Bonzini @ 2017-02-28 16:13 UTC (permalink / raw) To: qemu-devel 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS 2017-02-28 16:13 [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Paolo Bonzini @ 2017-02-28 16:14 ` Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 18/19] memory: Introduce DEVICE_HOST_ENDIAN for ram device Paolo Bonzini ` (2 subsequent siblings) 3 siblings, 0 replies; 8+ messages in thread From: Paolo Bonzini @ 2017-02-28 16:14 UTC (permalink / raw) To: qemu-devel 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. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- 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(-) diff --git a/cpus.c b/cpus.c index 399e271..56b1338 100644 --- a/cpus.c +++ b/cpus.c @@ -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) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 6ecb61c..a1b019d 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -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); diff --git a/kvm-all.c b/kvm-all.c index a433ad3..0baa193 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -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) diff --git a/target/arm/kvm.c b/target/arm/kvm.c index e5218f6..4555468 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -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. */ diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 2adf992..7698421 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -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) diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 3e686e7..0982e87 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -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) { } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index bc011c6..f22ecab 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -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) { } diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index e7eea6d..ac47154 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -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) -- 2.9.3 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PULL 18/19] memory: Introduce DEVICE_HOST_ENDIAN for ram device 2017-02-28 16:13 [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini @ 2017-02-28 16:14 ` Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 19/19] vl: disable default cdrom when using explicitely scsi-hd Paolo Bonzini 2017-03-01 17:58 ` [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Peter Maydell 3 siblings, 0 replies; 8+ messages in thread From: Paolo Bonzini @ 2017-02-28 16:14 UTC (permalink / raw) To: qemu-devel; +Cc: Yongji Xie From: Yongji Xie <xyjxie@linux.vnet.ibm.com> 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. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Yongji Xie <xyjxie@linux.vnet.ibm.com> Message-Id: <1488171164-28319-1-git-send-email-xyjxie@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- include/exec/cpu-common.h | 6 ++++++ memory.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index bd15853..eef74df 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -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; diff --git a/memory.c b/memory.c index d61caee..573fa6e 100644 --- a/memory.c +++ b/memory.c @@ -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, -- 2.9.3 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Qemu-devel] [PULL 19/19] vl: disable default cdrom when using explicitely scsi-hd 2017-02-28 16:13 [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 18/19] memory: Introduce DEVICE_HOST_ENDIAN for ram device Paolo Bonzini @ 2017-02-28 16:14 ` Paolo Bonzini 2017-03-01 17:58 ` [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Peter Maydell 3 siblings, 0 replies; 8+ messages in thread From: Paolo Bonzini @ 2017-02-28 16:14 UTC (permalink / raw) To: qemu-devel; +Cc: Hervé Poussineau From: Hervé Poussineau <hpoussin@reactos.org> 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. Signed-off-by: Hervé Poussineau <hpoussin@reactos.org> Message-Id: <1487623279-29930-1-git-send-email-hpoussin@reactos.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- vl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/vl.c b/vl.c index 7f57ded..16a3b5e 100644 --- a/vl.c +++ b/vl.c @@ -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 }, -- 2.9.3 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze 2017-02-28 16:13 [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Paolo Bonzini ` (2 preceding siblings ...) 2017-02-28 16:14 ` [Qemu-devel] [PULL 19/19] vl: disable default cdrom when using explicitely scsi-hd Paolo Bonzini @ 2017-03-01 17:58 ` Peter Maydell 2017-03-02 18:01 ` Paolo Bonzini 3 siblings, 1 reply; 8+ messages in thread From: Peter Maydell @ 2017-03-01 17:58 UTC (permalink / raw) To: Paolo Bonzini; +Cc: QEMU Developers On 28 February 2017 at 16:13, Paolo Bonzini <pbonzini@redhat.com> wrote: > 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. 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze 2017-03-01 17:58 ` [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Peter Maydell @ 2017-03-02 18:01 ` Paolo Bonzini 2017-03-02 23:20 ` Peter Maydell 0 siblings, 1 reply; 8+ messages in thread From: Paolo Bonzini @ 2017-03-02 18:01 UTC (permalink / raw) To: Peter Maydell; +Cc: QEMU Developers On 01/03/2017 18:58, Peter Maydell wrote: > 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) 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze 2017-03-02 18:01 ` Paolo Bonzini @ 2017-03-02 23:20 ` Peter Maydell 0 siblings, 0 replies; 8+ messages in thread From: Peter Maydell @ 2017-03-02 23:20 UTC (permalink / raw) To: Paolo Bonzini; +Cc: QEMU Developers On 2 March 2017 at 18:01, Paolo Bonzini <pbonzini@redhat.com> wrote: > > > On 01/03/2017 18:58, Peter Maydell wrote: >> 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) > > 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze @ 2017-03-01 12:29 Paolo Bonzini 2017-03-01 12:29 ` [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini 0 siblings, 1 reply; 8+ messages in thread From: Paolo Bonzini @ 2017-03-01 12:29 UTC (permalink / raw) To: qemu-devel 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS 2017-03-01 12:29 Paolo Bonzini @ 2017-03-01 12:29 ` Paolo Bonzini 0 siblings, 0 replies; 8+ messages in thread From: Paolo Bonzini @ 2017-03-01 12:29 UTC (permalink / raw) To: qemu-devel 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. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- 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(-) diff --git a/cpus.c b/cpus.c index 399e271..56b1338 100644 --- a/cpus.c +++ b/cpus.c @@ -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) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 6ecb61c..a1b019d 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -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); diff --git a/kvm-all.c b/kvm-all.c index a433ad3..0baa193 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -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) diff --git a/target/arm/kvm.c b/target/arm/kvm.c index e5218f6..4555468 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -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. */ diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 2adf992..7698421 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -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) diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 3e686e7..0982e87 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -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) { } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index bc011c6..f22ecab 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -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) { } diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index e7eea6d..ac47154 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -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) -- 2.9.3 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-03-02 23:20 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-02-28 16:13 [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 18/19] memory: Introduce DEVICE_HOST_ENDIAN for ram device Paolo Bonzini 2017-02-28 16:14 ` [Qemu-devel] [PULL 19/19] vl: disable default cdrom when using explicitely scsi-hd Paolo Bonzini 2017-03-01 17:58 ` [Qemu-devel] [PULL v4 00/19] KVM and cpu-exec patches for 2.9 soft freeze Peter Maydell 2017-03-02 18:01 ` Paolo Bonzini 2017-03-02 23:20 ` Peter Maydell -- strict thread matches above, loose matches on Subject: below -- 2017-03-01 12:29 Paolo Bonzini 2017-03-01 12:29 ` [Qemu-devel] [PULL 10/19] KVM: do not use sigtimedwait to catch SIGBUS Paolo Bonzini
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).