Jan Kiszka wrote: > This patch extends the qemu-kvm state sync logic with the event substate > from the new VCPU state interface, giving access to yet missing > exception, interrupt and NMI states. > > The patch does not switch the rest of qemu-kvm's code to the new > interface as it is expected to be morphed into upstream's version > anyway. Instead, a full conversion will be submitted for upstream. > > Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx> > --- > > Changes from v1: > - added support for has_error_code > - properly clear exception_index and interrupt_injected in case the > kernel does not support KVM_GET_VCPU_STATE > > qemu-kvm-x86.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ > target-i386/cpu.h | 5 +++ > target-i386/machine.c | 5 +++ > 3 files changed, 96 insertions(+), 0 deletions(-) > > diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c > index e03a4ba..dc3e6cb 100644 > --- a/qemu-kvm-x86.c > +++ b/qemu-kvm-x86.c > @@ -903,6 +903,82 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs) > | (rhs->avl * DESC_AVL_MASK); > } > > +static void kvm_get_events(CPUState *env) > +{ > +#ifdef KVM_CAP_VCPU_STATE > + struct { > + struct kvm_vcpu_state header; > + struct kvm_vcpu_substate substates[1]; > + } request; > + struct kvm_x86_event_state events; > + int r; > + > + request.header.nsubstates = 1; > + request.header.substates[0].type = KVM_X86_VCPU_STATE_EVENTS; > + request.header.substates[0].offset = (size_t)&events - (size_t)&request; > + r = kvm_vcpu_ioctl(env, KVM_GET_VCPU_STATE, &request); > + if (r == 0) { > + env->exception_index = > + events.exception.injected ? events.exception.nr : -1; > + env->has_error_code = events.exception.has_error_code; > + env->error_code = events.exception.error_code; > + > + env->interrupt_injected = > + events.interrupt.injected ? events.interrupt.nr : -1; > + env->soft_interrupt = events.interrupt.soft; > + > + env->nmi_injected = events.nmi.injected; > + env->nmi_pending = events.nmi.pending; > + if (events.nmi.masked) { > + env->hflags2 |= HF2_NMI_MASK; > + } else { > + env->hflags2 &= ~HF2_NMI_MASK; > + } > + > + env->sipi_vector = events.sipi_vector; > + > + return; > + } > +#endif > + env->exception_index = -1; > + env->interrupt_injected = -1; > + env->nmi_injected = 0; > + env->nmi_pending = 0; > + env->hflags2 &= ~HF2_NMI_MASK; Frankly, I don't recall anymore why I added these 5 lines. This state is reached on every guest reset and won't change afterwards unless the kernel actually supports KVM_X86_VCPU_STATE_EVENTS. This is temporary code, the upstream version will not contain it, but if you want me to clean this up, just drop me a note. Jan
Attachment:
signature.asc
Description: OpenPGP digital signature