From patchwork Wed Jun 28 12:28:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 9814181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DB3CE60383 for ; Wed, 28 Jun 2017 12:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD4B028437 for ; Wed, 28 Jun 2017 12:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFF732849E; Wed, 28 Jun 2017 12:45:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5B15028437 for ; Wed, 28 Jun 2017 12:45:03 +0000 (UTC) Received: from localhost ([::1]:33121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCL8-0007su-Fp for patchwork-qemu-devel@patchwork.kernel.org; Wed, 28 Jun 2017 08:45:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQC5Z-0003iq-RA for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:28:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQC5V-0006EF-TV for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:28:57 -0400 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34227) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQC5V-0006Ce-Nj for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:28:53 -0400 Received: by mail-pf0-x244.google.com with SMTP id d5so8907131pfe.1 for ; Wed, 28 Jun 2017 05:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MqekUB9zSnLKmdY8lOz9UBFFrJzIzmT0xRiHlmdxLPw=; b=QrPHueXA7/w8cPw9wrpr444E7NAHPnNMhwCp+sQoKIRGK+g7mclV4CCxJ7sObSN4Ep S/YVxZgHfnzE4LGELwbgvIZQM1stOOSIlL3JEuG87SB61VboWOYfFkvPFBowB/d0ZIuv J/0hbNtH207sY5AeDYR6dyeljLt9wgvWwPAUYzi0XzV25lQr3Vt6ekYlLV48R897pJsJ MZ4YIsw8GrogxzSuK9JAIYt3bIhJbTpRogfM0vyov9iYBzvKO85qvO/MQwuvwW4ZlXMG fSfyBUMqzdKmcV7LyJO13sXpLee9cUOx4JaYEEe4B1M2HB89yoXQu4SIxbsYv1D6pEKR Gxpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MqekUB9zSnLKmdY8lOz9UBFFrJzIzmT0xRiHlmdxLPw=; b=CvBSDMU7sAgbMYLM0ZU1T06irpDKYF3aeuCaxoGVdysiw3oze0Wc0PAxhN3vXhrus/ Bc4NSObly+myFFihoWvRNv08LjfVHxuzCP9b+wCeUoH/Ku17GUHVluiWbBZxNa5QALjR wKm8UYmZKFUerSDFm4Gqg3KTm3k/dZaWjypqQY/+mi8OEgKj4WxsoCVww45nsUeiSYV1 8kQQElYRL0BnKH63ysR/f9lcJuxlz4GsFKP/VXpAQwLqO1/T3XwVXSRWDFxDL7vNj2wT A4lnvf8IOvxABl4styExSj/jKXeVxX8+cRje1Z5SwjSj+HF3VUikHb9+FuwwiHkbX81J jkkw== X-Gm-Message-State: AKS2vOxWpwXlqUndCCPebDz3TKw5c/l7wjf6AxFfYjc8Zg+icoYQpwqA fTRN0rE4SrB0p4tW38c= X-Received: by 10.84.224.11 with SMTP id r11mr11729169plj.267.1498652931248; Wed, 28 Jun 2017 05:28:51 -0700 (PDT) Received: from localhost ([203.205.141.123]) by smtp.gmail.com with ESMTPSA id n74sm5432895pfh.118.2017.06.28.05.28.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 05:28:50 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Wed, 28 Jun 2017 05:28:47 -0700 Message-Id: <1498652927-10554-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH v3] KVM: Add async pf flag to KVM_GET/SET_VCPU_EVENTS interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Wanpeng Li , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Wanpeng Li This patch adds async page fault flag to KVM_GET/SET_VCPU_EVENTS interface. Cc: Paolo Bonzini Cc: Radim Krčmář Signed-off-by: Wanpeng Li --- 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 =