KVM and cpu-exec patches for 2.9 soft freeze
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 0819248d30877a9e0f063e7246e522a67548fc3e:
qmp-events: fix GUEST_PANICKED description formatting (2017-02-27 16:31:08 +0100)
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)
----------------------------------------------------------------
Anton Nefedov (2):
qapi: flatten GuestPanicInformation union
qmp-events: fix GUEST_PANICKED description formatting
Paolo Bonzini (14):
cpu-exec: unify icount_decr and tcg_exit_req
cpu-exec: remove unnecessary check of cpu->exit_request
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
cpu-exec.c | 93 ++--- cpus.c | 102 +---- 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 | 152 +++++++- 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 + 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 | 12 +- 44 files changed, 970 insertions(+), 812 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
[Qemu-devel] [PULL 06/17] cpus: remove ugly cast on sigbus_handler
The cast is there because sigbus_handler is invoked via sigfd_handler. But it feels just wrong to use struct qemu_signalfd_siginfo in the prototype of a function that is passed to sigaction.
Instead, do a simple-minded conversion of qemu_signalfd_siginfo to siginfo_t.
--- cpus.c | 12 +++--------- include/qemu/compatfd.h | 42 ------------------------------------------ include/qemu/osdep.h | 28 ++++++++++++++++++++++++++++ util/compatfd.c | 1 - util/main-loop.c | 5 +---- util/oslib-posix.c | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 56 deletions(-) delete mode 100644 include/qemu/compatfd.h
cpus.c +3 -9
@@ -51,10 +51,6 @@#include "hw/nmi.h" #include "sysemu/replay.h" -#ifndef _WIN32 -#include "qemu/compatfd.h" -#endif -#ifdef CONFIG_LINUX #include <sys/prctl.h>
@@ -924,11 +920,9 @@ static void sigbus_reraise(void)abort (); } -static void sigbus_handler (int n,struct qemu_signalfd_siginfo *siginfo, -void *ctx) +static void sigbus_handler (int n,siginfo_t *siginfo,void *ctx) { -if (kvm_on_sigbus (siginfo->ssi_code, - (void *)(intptr_t )siginfo->ssi_addr)) { +if (kvm_on_sigbus (siginfo->si_code, siginfo->si_addr)) {sigbus_reraise (); } }
@@ -939,7 +933,7 @@ static void qemu_init_sigbus(void)memset (&action,0 ,sizeof (action)); action.sa_flags =SA_SIGINFO ; - action.sa_sigaction = (void (*)(int ,siginfo_t *,void *))sigbus_handler; + action.sa_sigaction = sigbus_handler;sigaction (SIGBUS , &action,NULL );prctl (PR_MCE_KILL ,PR_MCE_KILL_SET ,PR_MCE_KILL_EARLY ,0 ,0 );
include/qemu/compatfd.h deleted +0 -42
42 lines not on this page · raw message
include/qemu/osdep.h +28 -0
@@ -297,6 +297,34 @@ void qemu_anon_ram_free(void *ptr, size_t size);# define QEMU_VMALLOC_ALIGN getpagesize()#endif +#ifdef CONFIG_POSIX +struct qemu_signalfd_siginfo { +uint32_t ssi_signo;/* Signal number */ +int32_t ssi_errno;/* Error number (unused) */ +int32_t ssi_code;/* Signal code */ +uint32_t ssi_pid;/* PID of sender */ +uint32_t ssi_uid;/* Real UID of sender */ +int32_t ssi_fd;/* File descriptor (SIGIO) */ +uint32_t ssi_tid;/* Kernel timer ID (POSIX timers) */ +uint32_t ssi_band;/* Band event (SIGIO) */ +uint32_t ssi_overrun;/* POSIX timer overrun count */ +uint32_t ssi_trapno;/* Trap number that caused signal */ +int32_t ssi_status;/* Exit status or signal (SIGCHLD) */ +int32_t ssi_int;/* Integer sent by sigqueue(2) */ +uint64_t ssi_ptr;/* Pointer sent by sigqueue(2) */ +uint64_t ssi_utime;/* User CPU time consumed (SIGCHLD) */ +uint64_t ssi_stime;/* System CPU time consumed (SIGCHLD) */ +uint64_t ssi_addr;/* Address that generated signal +(for hardware-generated signals) */ +uint8_t pad[48 ];/* Pad size to 128 bytes (allow for +additional fields in the future) */ +}; + +int qemu_signalfd (const sigset_t *mask); +void sigaction_invoke (struct sigaction *action, +struct qemu_signalfd_siginfo *info); +#endif +int qemu_madvise (void *addr,size_t len,int advice);int qemu_open (const char *name,int flags, ...);
util/compatfd.c +0 -1
@@ -15,7 +15,6 @@#include "qemu/osdep.h" #include "qemu-common.h" -#include "qemu/compatfd.h" #include "qemu/thread.h" #include <sys/syscall.h>
util/main-loop.c +1 -4
@@ -34,8 +34,6 @@#ifndef _WIN32 -#include "qemu/compatfd.h" -/* If we have signalfd, we mask out the signals we want to handle and then * use signalfd to listen for them. We rely on whatever the current signal * handler is to dispatch the signals when we receive them.
@@ -63,8 +61,7 @@ static void sigfd_handler(void *opaque)sigaction (info.ssi_signo,NULL , &action);if ((action.sa_flags &SA_SIGINFO ) && action.sa_sigaction) { - action.sa_sigaction (info.ssi_signo, - (siginfo_t *)&info,NULL ); +sigaction_invoke (&action, &info); }else if (action.sa_handler) { action.sa_handler (info.ssi_signo); }
util/oslib-posix.c +33 -0
@@ -603,3 +603,36 @@ void qemu_free_stack(void *stack, size_t sz)munmap (stack, sz); } + +void sigaction_invoke (struct sigaction *action, +struct qemu_signalfd_siginfo *info) +{ +siginfo_t si = {0 }; + si.si_signo = info->ssi_signo; + si.si_errno = info->ssi_errno; + si.si_code = info->ssi_code; + +/* Convert the minimal set of fields defined by POSIX. +* Positive si_code values are reserved for kernel-generated +* signals, where the valid siginfo fields are determined by +* the signal number. But according to POSIX, it is unspecified +* whether SI_USER and SI_QUEUE have values less than or equal to +* zero. +*/ +if (info->ssi_code ==SI_USER || info->ssi_code ==SI_QUEUE || + info->ssi_code <=0 ) { +/* SIGTERM, etc. */ + si.si_pid = info->ssi_pid; + si.si_uid = info->ssi_uid; + }else if (info->ssi_signo ==SIGILL || info->ssi_signo ==SIGFPE || + info->ssi_signo ==SIGSEGV || info->ssi_signo ==SIGBUS ) { + si.si_addr = (void *)(uintptr_t )info->ssi_addr; + }else if (info->ssi_signo ==SIGCHLD ) { + si.si_pid = info->ssi_pid; + si.si_status = info->ssi_status; + si.si_uid = info->ssi_uid; + }else if (info->ssi_signo ==SIGIO ) { + si.si_band = info->ssi_band; + } + action->sa_sigaction (info->ssi_signo, &si,NULL ); +}
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PULL 06/17] cpus: remove ugly cast on sigbus_handler
util/oslib-posix.c void qemu_free_stack(void *stack, size_t sz) · line 636
Quoted 11 lines · Paolo Bonzini
The cast is there because
sigbus_handleris invoked viasigfd_handler. But it feels just wrong to use structqemu_signalfd_siginfoin the prototype of a function that is passed to sigaction.Instead, do a simple-minded conversion of
qemu_signalfd_siginfotosiginfo_t.Signed-off-by Paolo Bonzini <[email protected]>util/oslib-posix.c +3
-0+ }else if (info->ssi_signo ==SIGIO ) { + si.si_band = info->ssi_band; + }
This doesn't build on OpenBSD:
In file included from /usr/include/sys/signal.h:107:0,
from /usr/include/signal.h:38,
from /root/qemu/include/qemu/osdep.h:86,
from /root/qemu/util/oslib-posix.c:29:
/root/qemu/util/oslib-posix.c: In function 'sigaction_invoke':
/root/qemu/util/oslib-posix.c:713:12: error: 'union <anonymous>' has
no member named '_file'
si.si_band = info->ssi_band;
^I dunno how much we care.
thanks
-- PMM
Re: [Qemu-devel] [PULL 06/17] cpus: remove ugly cast on sigbus_handler
Quoted 25 lines · Peter Maydell
util/oslib-posix.c void qemu_free_stack(void *stack, size_t sz) · line 636
Quoted 11 lines · Paolo Bonzini
The cast is there because
sigbus_handleris invoked viasigfd_handler. But it feels just wrong to use structqemu_signalfd_siginfoin the prototype of a function that is passed to sigaction.Instead, do a simple-minded conversion of
qemu_signalfd_siginfotosiginfo_t.Signed-off-by Paolo Bonzini <[email protected]>util/oslib-posix.c +3
-0+ }else if (info->ssi_signo ==SIGIO ) { + si.si_band = info->ssi_band; + }This doesn't build on OpenBSD:
In file included from
/usr/include/sys/signal.h:107:0,from /usr/include/signal.h:38, from /root/qemu/include/qemu/osdep.h:86, from /root/qemu/util/oslib-posix.c:29: /root/qemu/util/oslib-posix.c: In function 'sigaction_invoke': /root/qemu/util/oslib-posix.c:713:12: error: 'union <anonymous>' has no member named '_file' si.si_band = info->ssi_band; ^
Quoted 1 line
I dunno how much we care.
It's marked as obsolescent in POSIX, so it is sane to remove it. I'll send a patch.
Paolo
[Qemu-devel] [PULL 10/17] KVM: do not use sigtimedwait to catch SIGBUS
In reply to Paolo BonziniCall 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 | 37 ++++++++++++++++++++++++++++++++++++- 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, 55 insertions(+), 44 deletions(-)
cpus.c +13 -18
@@ -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
@@ -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 +36 -1
@@ -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 __threadvoid *pending_sigbus_addr; +static __threadint pending_sigbus_code; +static __threadbool have_sigbus_pending; +#endif +int kvm_cpu_exec (CPUState *cpu) {struct kvm_run *run = cpu->kvm_run;
@@ -1930,6 +1936,18 @@ int kvm_cpu_exec(CPUState *cpu) attrs =kvm_arch_post_run (cpu, run); +if (unlikely (have_sigbus_pending)) { +#ifdef KVM_HAVE_MCE_INJECTION +qemu_mutex_lock_iothread (); +kvm_arch_on_sigbus_vcpu (cpu, pending_sigbus_code, + pending_sigbus_addr); + have_sigbus_pending = false; +qemu_mutex_unlock_iothread (); +#else +abort (); +#endif + } +if (run_ret <0 ) {if (run_ret == -EINTR || run_ret == -EAGAIN ) {DPRINTF ("io window exit\n" );
@@ -2392,13 +2410,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 +2438,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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Quoted 22 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.gittags/for-upstreamfor you to fetch changes up to
0819248d30877a9e0f063e7246e522a67548fc3e:qmp-events: fix
GUEST_PANICKEDdescription formatting (2017-02-27 16:31:08 +0100)
v2->v3: replace SIGPOLL with SIGIOanother missing #ifdef
KVM_HAVE_MCE_INJECTION
v1->v2: add missing #ifdefKVM_HAVE_MCE_INJECTIONrebase 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.
Quoted 7 lines
----------------------------------------------------------------
* kernel header update (requested by David and Vijay)
* GuestPanicInformation fixups (Anton)
* record/replay icount fixes (Pavel)
* cpu-exec cleanup, unification oficount_decrwithtcg_exit_req(me)
*KVM_CAP_IMMEDIATE_EXITsupport (me)
* vmxcap update (me)
Fails to build, OSX:
/home/petmay01/qemu/kvm-all.c: In function 'kvm_cpu_exec':/home/petmay01/qemu/kvm-all.c:1995:33: error: 'have_sigbus_pending' undeclared (first use in this function)
if (unlikely(have_sigbus_pending)) {
^/home/petmay01/qemu/kvm-all.c:1995:33: note: each undeclared identifier is reported only once for each function it appears in
thanks
-- PMM