Message ID | 1498652927-10554-1-git-send-email-wanpeng.li@hotmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 28/06/2017 14:28, Wanpeng Li wrote: > From: Wanpeng Li <wanpeng.li@hotmail.com> > > This patch adds async page fault flag to KVM_GET/SET_VCPU_EVENTS interface. > > Cc: Paolo Bonzini <pbonzini@redhat.com> > Cc: Radim Krčmář <rkrcmar@redhat.com> > Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com> > --- > v2 -> v3: > * nested_apf for vcpu events > v1 -> v2: > * reuse the pad for async_page_fault > * cleanup coding style > > linux-headers/asm-x86/kvm.h | 3 ++- > target/i386/cpu.h | 1 + > target/i386/kvm.c | 8 ++++++-- > 3 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h > index c2824d0..27b368b 100644 > --- a/linux-headers/asm-x86/kvm.h > +++ b/linux-headers/asm-x86/kvm.h > @@ -287,6 +287,7 @@ struct kvm_reinject_control { > #define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002 > #define KVM_VCPUEVENT_VALID_SHADOW 0x00000004 > #define KVM_VCPUEVENT_VALID_SMM 0x00000008 > +#define KVM_VCPUEVENT_VALID_ASYNC_PF 0x00000010 > > /* Interrupt shadow states */ > #define KVM_X86_SHADOW_INT_MOV_SS 0x01 > @@ -298,7 +299,7 @@ struct kvm_vcpu_events { > __u8 injected; > __u8 nr; > __u8 has_error_code; > - __u8 pad; > + __u8 nested_apf; > __u32 error_code; > } exception; > struct { > diff --git a/target/i386/cpu.h b/target/i386/cpu.h > index cfe825f..90cb692 100644 > --- a/target/i386/cpu.h > +++ b/target/i386/cpu.h > @@ -1105,6 +1105,7 @@ typedef struct CPUX86State { > > /* exception/interrupt handling */ > int error_code; > + uint8_t async_page_fault; > int exception_is_int; > target_ulong exception_next_eip; > target_ulong dr[8]; /* debug registers; note dr4 and dr5 are unused */ > diff --git a/target/i386/kvm.c b/target/i386/kvm.c > index 49b6115..b2405ec 100644 > --- a/target/i386/kvm.c > +++ b/target/i386/kvm.c > @@ -2491,8 +2491,8 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) > events.exception.injected = (env->exception_injected >= 0); > events.exception.nr = env->exception_injected; > events.exception.has_error_code = env->has_error_code; > + events.exception.nested_apf = env->async_page_fault; > events.exception.error_code = env->error_code; > - events.exception.pad = 0; > > events.interrupt.injected = (env->interrupt_injected >= 0); > events.interrupt.nr = env->interrupt_injected; > @@ -2531,7 +2531,8 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) > > if (level >= KVM_PUT_RESET_STATE) { > events.flags |= > - KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR; > + KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR | > + KVM_VCPUEVENT_VALID_ASYNC_PF; > } > > return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events); > @@ -2555,6 +2556,9 @@ static int kvm_get_vcpu_events(X86CPU *cpu) > env->exception_injected = > events.exception.injected ? events.exception.nr : -1; > env->has_error_code = events.exception.has_error_code; > + if (events.flags & KVM_VCPUEVENT_VALID_ASYNC_PF) { > + env->async_page_fault = events.exception.nested_apf; > + } > env->error_code = events.exception.error_code; > > env->interrupt_injected = > You are missing the code in machine.c to transmit this (in a new subsection). But let's iron out the KVM parts first of all. Paolo
diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index c2824d0..27b368b 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -287,6 +287,7 @@ struct kvm_reinject_control { #define KVM_VCPUEVENT_VALID_SIPI_VECTOR 0x00000002 #define KVM_VCPUEVENT_VALID_SHADOW 0x00000004 #define KVM_VCPUEVENT_VALID_SMM 0x00000008 +#define KVM_VCPUEVENT_VALID_ASYNC_PF 0x00000010 /* Interrupt shadow states */ #define KVM_X86_SHADOW_INT_MOV_SS 0x01 @@ -298,7 +299,7 @@ struct kvm_vcpu_events { __u8 injected; __u8 nr; __u8 has_error_code; - __u8 pad; + __u8 nested_apf; __u32 error_code; } exception; struct { diff --git a/target/i386/cpu.h b/target/i386/cpu.h index cfe825f..90cb692 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1105,6 +1105,7 @@ typedef struct CPUX86State { /* exception/interrupt handling */ int error_code; + uint8_t async_page_fault; int exception_is_int; target_ulong exception_next_eip; target_ulong dr[8]; /* debug registers; note dr4 and dr5 are unused */ diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 49b6115..b2405ec 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -2491,8 +2491,8 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) events.exception.injected = (env->exception_injected >= 0); events.exception.nr = env->exception_injected; events.exception.has_error_code = env->has_error_code; + events.exception.nested_apf = env->async_page_fault; events.exception.error_code = env->error_code; - events.exception.pad = 0; events.interrupt.injected = (env->interrupt_injected >= 0); events.interrupt.nr = env->interrupt_injected; @@ -2531,7 +2531,8 @@ static int kvm_put_vcpu_events(X86CPU *cpu, int level) if (level >= KVM_PUT_RESET_STATE) { events.flags |= - KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR; + KVM_VCPUEVENT_VALID_NMI_PENDING | KVM_VCPUEVENT_VALID_SIPI_VECTOR | + KVM_VCPUEVENT_VALID_ASYNC_PF; } return kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events); @@ -2555,6 +2556,9 @@ static int kvm_get_vcpu_events(X86CPU *cpu) env->exception_injected = events.exception.injected ? events.exception.nr : -1; env->has_error_code = events.exception.has_error_code; + if (events.flags & KVM_VCPUEVENT_VALID_ASYNC_PF) { + env->async_page_fault = events.exception.nested_apf; + } env->error_code = events.exception.error_code; env->interrupt_injected =