From patchwork Mon Aug 19 13:17:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 11100971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC11B1398 for ; Mon, 19 Aug 2019 13:18:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C907427D16 for ; Mon, 19 Aug 2019 13:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC5D527FA9; Mon, 19 Aug 2019 13:18:11 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68DC827D16 for ; Mon, 19 Aug 2019 13:18:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727766AbfHSNSH (ORCPT ); Mon, 19 Aug 2019 09:18:07 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46324 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727750AbfHSNSH (ORCPT ); Mon, 19 Aug 2019 09:18:07 -0400 Received: by mail-pf1-f196.google.com with SMTP id q139so1152152pfc.13; Mon, 19 Aug 2019 06:18:06 -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:in-reply-to:references; bh=XzmPhJrk3sYccy1T+84Jue9XGrfBlOC3sGHKCIWYcCg=; b=EwmiWA+hMiVVdcUocJGviVtaq0225spUIo76LJuwgcpx01tyfVJe8AYY1oXwjJXzVS RFSFU2O1oIXTfHlusUiBSxdsy6CBXdObNE9vMoyKC+7juhjSUy+ov/qAbyIojpVuDJdu lwx/SelwSMFMmdgXqyI2jAqEzrHW8AXJEHD0JzMrqyp3gmj8yaZ6OuwhWEHTwilRCOK2 yMTxg3eMItGQhTVEdE0fvwzQgJ3fk8fs9tcTxAaYfMyr5BhIYNFPe4wHbnoTTuBgv6K0 M61AIQM1xoItEIx69C7IhWeVTjmBZwn35TjWN8X9Rx1MgCDMLzfYPP9/DGzyLPNwnExP AcXg== 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:in-reply-to :references; bh=XzmPhJrk3sYccy1T+84Jue9XGrfBlOC3sGHKCIWYcCg=; b=lnalLXjsPdqrFeYE0+e7bBU2pl+HI6Ippij8teFiAhohhM7zvA2v3bY74nM8XOf0tP u1DkRrhnw41fCnLOFQfEfWGfLLX+5AB4wa7SEaC8iu+4DEanIVNHaNhDSVKdwtOaa2Cd fLHZndwwVhSqMPDc4FZVire5CXMNWfOFKnBOnsOIfP7bXBm5Ju0lua/NKyHrexK35vLo VwjlPNujFu1xIvDUnG3VjuelmtfatP+Flz0+gpstHlxKJZMNbYCX0zMmQ10BzW9XGbuq 1aUG3LQICjpQPwJNehH/NYA8c0IRQCLKZt2rpjekCM5kAQr6ZEFnr2BKbGP15Umt7pi0 8yeQ== X-Gm-Message-State: APjAAAWxZC6gIp++KQCxyvUKytRkuuT7UjHBD7hx0c4yC6oZ7TSB4WG8 dCb//vanYPuVfvksLH/ONRr5xIIv+3A= X-Google-Smtp-Source: APXvYqy/HXajUqBsSoG9hyffw5Qkz2hHTI71+UcFam797hR5va8vvK79kyFh0x3JMjkmVT9aWrVgBg== X-Received: by 2002:a63:e610:: with SMTP id g16mr19472362pgh.392.1566220686554; Mon, 19 Aug 2019 06:18:06 -0700 (PDT) Received: from localhost.corp.microsoft.com ([167.220.255.114]) by smtp.googlemail.com with ESMTPSA id h20sm16184329pfq.156.2019.08.19.06.18.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 06:18:06 -0700 (PDT) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: pbonzini@redhat.com, rkrcmar@redhat.com, corbet@lwn.net, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, michael.h.kelley@microsoft.com Cc: Tianyu Lan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, vkuznets@redhat.com Subject: [PATCH V3 1/3] x86/Hyper-V: Fix definition of struct hv_vp_assist_page Date: Mon, 19 Aug 2019 21:17:35 +0800 Message-Id: <20190819131737.26942-2-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> References: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tianyu Lan The struct hv_vp_assist_page was defined incorrectly. The "vtl_control" should be u64[3], "nested_enlightenments _control" should be a u64 and there is 7 reserved bytes following "enlighten_vmentry". This patch is to fix it. Signed-off-by: Tianyu Lan --- Change since v1: Move definition of struct hv_nested_enlightenments_control into this patch to fix offset issue. --- arch/x86/include/asm/hyperv-tlfs.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index af78cd72b8f3..cf0b2a04271d 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -514,14 +514,24 @@ struct hv_timer_message_payload { __u64 delivery_time; /* When the message was delivered */ } __packed; +struct hv_nested_enlightenments_control { + struct { + __u32 directhypercall:1; + __u32 reserved:31; + } features; + struct { + __u32 reserved; + } hypercallControls; +} __packed; + /* Define virtual processor assist page structure. */ struct hv_vp_assist_page { __u32 apic_assist; - __u32 reserved; - __u64 vtl_control[2]; - __u64 nested_enlightenments_control[2]; - __u32 enlighten_vmentry; - __u32 padding; + __u32 reserved1; + __u64 vtl_control[3]; + struct hv_nested_enlightenments_control nested_control; + __u8 enlighten_vmentry; + __u8 reserved2[7]; __u64 current_nested_vmcs; } __packed; From patchwork Mon Aug 19 13:17:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 11100973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 671C314F7 for ; Mon, 19 Aug 2019 13:18:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5582427D16 for ; Mon, 19 Aug 2019 13:18:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 489CF27FA9; Mon, 19 Aug 2019 13:18:18 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAE6E27D16 for ; Mon, 19 Aug 2019 13:18:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727782AbfHSNSO (ORCPT ); Mon, 19 Aug 2019 09:18:14 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40876 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbfHSNSO (ORCPT ); Mon, 19 Aug 2019 09:18:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id w16so1165167pfn.7; Mon, 19 Aug 2019 06:18:13 -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:in-reply-to:references; bh=jhCOccuCzPzG2s+OQkIdwKuf0Hs2BSmGnlAfPo3gJDY=; b=SSbDy30NapSw8nHHwn1JLMwbNA0vfTRGU1iDjq3SKBqN1KGP/m+LeAv3PRlyAzQmQg bkkueQgMJu7eFwNVM6y84oTQ5gHMh6D6iksUAvH45v83RXY5v/dK5qeLWS4Wl2uDFBPz f9ovypltlxBT4ybYgThtMHe8Pul/7LnCbP6RdXytBQmktC7+1MIflQkRl6JoRaOx6K4M u+iZ07xWrHxaRXPTySmoFjWO303tExfRTaBdWvjLLRiIf/J34q1ECFEPxu3YgtmkbCLi rxQUrXLoHtEb613F9ONPS1TC9U64qt995cYo+9xWlwvdBFNMLwvGM6r19ywCR2uk+XNH GqaA== 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:in-reply-to :references; bh=jhCOccuCzPzG2s+OQkIdwKuf0Hs2BSmGnlAfPo3gJDY=; b=XnxOPALrTgal66JBooDbi3IK/swP9lgqyTltWvhMLqxIsQnG7phCa51O8R7tNiBrPf ix87VLa6yZBgltFADQQ6pvif3dgFysrUABiqCFh0FplIY+Vc1Llm2XK/+f3NUWx94lsc LlJe0ucV7MG+TZdZNsb49VcwiEbMSmtKi+NXiPQFibKLvY1ndNKDGLKG3Swt09n3zlq4 TvcOjLuF6Fe7S5zkTMn10r+kzkSCYb5zdT4vmooVZ9T8xt4mu3m0cmaVsDgAoumFnslB bXhLoi+2+dkSveDqjs1u9DtQckBJmRjAeQ1X/l9XFwGTiYAi2cQ/7QmBQJQSE0VT5exa 2ESw== X-Gm-Message-State: APjAAAW1Ta4ffhas5y3+kMEZzXq4/ct6APbxMMPpGKVZ64vlfVWC7xyA boNzLs93raUa9tTwHsvgY5VVvzgiv1o= X-Google-Smtp-Source: APXvYqzO69+SFNQD25sX+v/CwJUb3PhBiHPL7gAr9CGC0HPcUtSl++xVF3BgpvmVUKjdi/rviIxLMw== X-Received: by 2002:a63:ee04:: with SMTP id e4mr19888533pgi.53.1566220691994; Mon, 19 Aug 2019 06:18:11 -0700 (PDT) Received: from localhost.corp.microsoft.com ([167.220.255.114]) by smtp.googlemail.com with ESMTPSA id h20sm16184329pfq.156.2019.08.19.06.18.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 06:18:11 -0700 (PDT) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: pbonzini@redhat.com, rkrcmar@redhat.com, corbet@lwn.net, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, michael.h.kelley@microsoft.com Cc: Tianyu Lan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, vkuznets@redhat.com Subject: [PATCH V3 2/3] KVM/Hyper-V: Add new KVM cap KVM_CAP_HYPERV_DIRECT_TLBFLUSH Date: Mon, 19 Aug 2019 21:17:36 +0800 Message-Id: <20190819131737.26942-3-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> References: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tianyu Lan This patch adds new KVM cap KVM_CAP_HYPERV_DIRECT_TLBFLUSH and let user space to enable direct tlb flush function when only Hyper-V hypervsior capability is exposed to VM. This patch also adds enable_direct_tlbflush callback in the struct kvm_x86_ops and platforms may use it to implement direct tlb flush support. Signed-off-by: Tianyu Lan --- Change since v1: Update description of KVM_CAP_HYPERV_DIRECT_TLBFLUSH in the KVM API doc. --- Documentation/virtual/kvm/api.txt | 13 +++++++++++++ arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 8 ++++++++ include/uapi/linux/kvm.h | 1 + 4 files changed, 24 insertions(+) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 2cd6250b2896..0c6e1b25d0c8 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -5289,3 +5289,16 @@ Architectures: x86 This capability indicates that KVM supports paravirtualized Hyper-V IPI send hypercalls: HvCallSendSyntheticClusterIpi, HvCallSendSyntheticClusterIpiEx. +8.21 KVM_CAP_HYPERV_DIRECT_TLBFLUSH + +Architecture: x86 + +This capability indicates that KVM running on top of Hyper-V hypervisor +enables Direct TLB flush for its guests meaning that TLB flush +hypercalls are handled by Level 0 hypervisor (Hyper-V) bypassing KVM. +Due to the different ABI for hypercall parameters between Hyper-V and +KVM, enabling this capability effectively disables all hypercall +handling by KVM (as some KVM hypercall may be mistakenly treated as TLB +flush hypercalls by Hyper-V) so userspace should disable KVM identification +in CPUID and only exposes Hyper-V identification. In this case, guest +thinks it's running on Hyper-V and only use Hyper-V hypercalls. diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 0cc5b611a113..667d154e89d4 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1205,6 +1205,8 @@ struct kvm_x86_ops { uint16_t (*nested_get_evmcs_version)(struct kvm_vcpu *vcpu); bool (*need_emulation_on_page_fault)(struct kvm_vcpu *vcpu); + + int (*enable_direct_tlbflush)(struct kvm_vcpu *vcpu); }; struct kvm_arch_async_pf { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 9d7b9e6a0939..a9d8ee7f7bf0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3183,6 +3183,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r = kvm_x86_ops->get_nested_state ? kvm_x86_ops->get_nested_state(NULL, NULL, 0) : 0; break; + case KVM_CAP_HYPERV_DIRECT_TLBFLUSH: + r = kvm_x86_ops->enable_direct_tlbflush ? 1 : 0; + break; default: break; } @@ -3953,6 +3956,11 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, r = -EFAULT; } return r; + case KVM_CAP_HYPERV_DIRECT_TLBFLUSH: + if (!kvm_x86_ops->enable_direct_tlbflush) + return -ENOTTY; + + return kvm_x86_ops->enable_direct_tlbflush(vcpu); default: return -EINVAL; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index a7c19540ce21..cb959bc925b1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -996,6 +996,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_ARM_PTRAUTH_ADDRESS 171 #define KVM_CAP_ARM_PTRAUTH_GENERIC 172 #define KVM_CAP_PMU_EVENT_FILTER 173 +#define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 174 #ifdef KVM_CAP_IRQ_ROUTING From patchwork Mon Aug 19 13:17:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 11100975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E660D14F7 for ; Mon, 19 Aug 2019 13:18:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3FC627D16 for ; Mon, 19 Aug 2019 13:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C78B627FA9; Mon, 19 Aug 2019 13:18:23 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47E9C27D16 for ; Mon, 19 Aug 2019 13:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727795AbfHSNSS (ORCPT ); Mon, 19 Aug 2019 09:18:18 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43220 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727791AbfHSNSS (ORCPT ); Mon, 19 Aug 2019 09:18:18 -0400 Received: by mail-pg1-f196.google.com with SMTP id k3so1211309pgb.10; Mon, 19 Aug 2019 06:18:17 -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:in-reply-to:references; bh=MwCwhv7/mOAIHEUN/DfGOFamSbYs1fDAQfF5eyRVr04=; b=XtoeDxnfWc31i/QohntcS+gh8DOVcJP8NpMvT1Ol0we57AIO8tKqIHziizHyITduHd g2/RkHyFaIYo6k0L29l5KvZ9BCntfLxewyJlZFmbU7W7fhV21RIV+RyL95Pwcpj3LvrS k3M+qdVuCPYs7fosGNE/9KrtaZhNIyLOrLoTuLE6ZzX+B3AbSAR4mfsASXg9NKUeTDMM Q3N9OPRGFeDpwBaKWnFNxmIOgxwLb9nXsLMf6U6bcCPjCnmliQZJulN17604J+OiooTG 44No/trTqsMsTeqHLRVk9gcaEwzVkD1MZejodzBAeJuEKei8Jo8H+kqYVDr6J9BT3H/K atFg== 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:in-reply-to :references; bh=MwCwhv7/mOAIHEUN/DfGOFamSbYs1fDAQfF5eyRVr04=; b=SjZICZgoDCzHHPR7hDanuKIPTgKWIWQhMBd7AYng2aGbb18BgGVfXq4jLR/IWd9GmA rxt0/0rR7UXw2MGI9C6yUKTI9ugg5HDxd3Z061Za7FsMgUq1OJh3F3ip6w4OLwSlA0mq dT9KYZQprypKHNRMeIzxtTe6DhIwdZshkv+E9PcTIcdeuDKB8DlEqy3fkmy9eJ8aSdvx KsHMK53GI7iUR8k3XaK00cWF8YIrZNiJeUewfeLwQEhj6Bfj867ct68xIqFMPMoMonWp k/zE/y3TRQouG/+8bW3BRhitB3gon7Xvly2TLpJr1s6oxBlRIGEmvYH3rvb/0WAsP4pq j0Vg== X-Gm-Message-State: APjAAAWKtPA8mi+JqoagtnBbRPmzkUWGnnb+1ateqtRG+32tJOULVdb0 SkiRp3wfnD6q2Ado3zLeWmA= X-Google-Smtp-Source: APXvYqyGpzWL29Jd/PLwDH1iYnPyYubyt0V/nkXugJpPfIfLh0C7xMGcY3dg7CtHXtixF9Vg1jS0Mg== X-Received: by 2002:a62:cdc3:: with SMTP id o186mr24187692pfg.168.1566220696960; Mon, 19 Aug 2019 06:18:16 -0700 (PDT) Received: from localhost.corp.microsoft.com ([167.220.255.114]) by smtp.googlemail.com with ESMTPSA id h20sm16184329pfq.156.2019.08.19.06.18.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 06:18:16 -0700 (PDT) From: lantianyu1986@gmail.com X-Google-Original-From: Tianyu.Lan@microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, sashal@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, michael.h.kelley@microsoft.com Cc: Vitaly Kuznetsov , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Tianyu Lan Subject: [PATCH V3 3/3] KVM/Hyper-V/VMX: Add direct tlb flush support Date: Mon, 19 Aug 2019 21:17:37 +0800 Message-Id: <20190819131737.26942-4-Tianyu.Lan@microsoft.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> References: <20190819131737.26942-1-Tianyu.Lan@microsoft.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vitaly Kuznetsov This patch is to enable Hyper-V direct tlb flush function for vmx. Signed-off-by: Vitaly Kuznetsov Signed-off-by: Tianyu Lan --- Change since v2: - Move hv assist page(hv_pa_pg) from struct kvm to struct kvm_hv. --- arch/x86/include/asm/hyperv-tlfs.h | 4 ++++ arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/vmx/evmcs.h | 2 ++ arch/x86/kvm/vmx/vmx.c | 39 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index cf0b2a04271d..d53d6e4a6210 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -171,6 +171,7 @@ #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14) /* Nested features. These are HYPERV_CPUID_NESTED_FEATURES.EAX bits. */ +#define HV_X64_NESTED_DIRECT_FLUSH BIT(17) #define HV_X64_NESTED_GUEST_MAPPING_FLUSH BIT(18) #define HV_X64_NESTED_MSR_BITMAP BIT(19) @@ -882,4 +883,7 @@ struct hv_tlb_flush_ex { u64 gva_list[]; } __packed; +struct hv_partition_assist_pg { + u32 tlb_lock_count; +}; #endif diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 667d154e89d4..ad4b5c02db0e 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -840,6 +840,8 @@ struct kvm_hv { /* How many vCPUs have VP index != vCPU index */ atomic_t num_mismatched_vp_indexes; + + struct hv_partition_assist_pg *hv_pa_pg; }; enum kvm_irqchip_mode { diff --git a/arch/x86/kvm/vmx/evmcs.h b/arch/x86/kvm/vmx/evmcs.h index 39a24eec8884..07ebf6882a45 100644 --- a/arch/x86/kvm/vmx/evmcs.h +++ b/arch/x86/kvm/vmx/evmcs.h @@ -178,6 +178,8 @@ static inline void evmcs_load(u64 phys_addr) struct hv_vp_assist_page *vp_ap = hv_get_vp_assist_page(smp_processor_id()); + if (current_evmcs->hv_enlightenments_control.nested_flush_hypercall) + vp_ap->nested_control.features.directhypercall = 1; vp_ap->current_nested_vmcs = phys_addr; vp_ap->enlighten_vmentry = 1; } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 84f8d49a2fd2..ed8056049070 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -486,6 +486,35 @@ static int hv_remote_flush_tlb(struct kvm *kvm) return hv_remote_flush_tlb_with_range(kvm, NULL); } +static int hv_enable_direct_tlbflush(struct kvm_vcpu *vcpu) +{ + struct hv_enlightened_vmcs *evmcs; + struct hv_partition_assist_pg **p_hv_pa_pg = + &vcpu->kvm->arch.hyperv.hv_pa_pg; + /* + * Synthetic VM-Exit is not enabled in current code and so All + * evmcs in singe VM shares same assist page. + */ + if (!*p_hv_pa_pg) { + *p_hv_pa_pg = kzalloc(PAGE_SIZE, GFP_KERNEL); + if (!*p_hv_pa_pg) + return -ENOMEM; + pr_debug("KVM: Hyper-V: allocated PA_PG for %llx\n", + (u64)&vcpu->kvm); + } + + evmcs = (struct hv_enlightened_vmcs *)to_vmx(vcpu)->loaded_vmcs->vmcs; + + evmcs->partition_assist_page = + __pa(*p_hv_pa_pg); + evmcs->hv_vm_id = (u64)vcpu->kvm; + evmcs->hv_enlightenments_control.nested_flush_hypercall = 1; + + pr_debug("KVM: Hyper-V: enabled DIRECT flush for %llx\n", + (u64)vcpu->kvm); + return 0; +} + #endif /* IS_ENABLED(CONFIG_HYPERV) */ /* @@ -6516,6 +6545,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) current_evmcs->hv_clean_fields |= HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL; + if (static_branch_unlikely(&enable_evmcs)) + current_evmcs->hv_vp_id = vcpu->arch.hyperv.vp_index; + /* MSR_IA32_DEBUGCTLMSR is zeroed on vmexit. Restore it if needed */ if (vmx->host_debugctlmsr) update_debugctlmsr(vmx->host_debugctlmsr); @@ -6583,6 +6615,7 @@ static struct kvm *vmx_vm_alloc(void) static void vmx_vm_free(struct kvm *kvm) { + kfree(kvm->arch.hyperv.hv_pa_pg); vfree(to_kvm_vmx(kvm)); } @@ -7815,6 +7848,7 @@ static void vmx_exit(void) if (!vp_ap) continue; + vp_ap->nested_control.features.directhypercall = 0; vp_ap->current_nested_vmcs = 0; vp_ap->enlighten_vmentry = 0; } @@ -7854,6 +7888,11 @@ static int __init vmx_init(void) pr_info("KVM: vmx: using Hyper-V Enlightened VMCS\n"); static_branch_enable(&enable_evmcs); } + + if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) + vmx_x86_ops.enable_direct_tlbflush + = hv_enable_direct_tlbflush; + } else { enlightened_vmcs = false; }