Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp343359pxf; Thu, 8 Apr 2021 04:27:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF2E3G3JVhU0GRZpZXOzBghM/rf3Ioa0a79zmsWm7ZxGFbgdCxM8JdDZwmnIWPoGxmwlqZ X-Received: by 2002:a17:90a:4a8e:: with SMTP id f14mr7933800pjh.84.1617881256403; Thu, 08 Apr 2021 04:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617881256; cv=none; d=google.com; s=arc-20160816; b=Hlw3EZ7h83j33qunJYKdbeBmOzi9Oy+7o2auyHeSMKJL26uRzO2wnKAlSlxx7Sx7PJ AjdTrzDakOt/KpIs3UtOQlTM+QKZpBsjKQPDqVUIkKDs2tB1vJWvhLXqhkKO1oT/73ar wItQmUFXZ9MPN+x267f/D0H4tGp9FXVknGynWw6X6ppzxq4rWz2Ou7+SYkxUZWtFRA5O JJLLtUH0Svq/AE47ChIEtykSvpewOT0I2+xXhZ7aR014FsYTZcnP2Mm+7DRKVeLLGPHH BRhlj0ok2Cv3TtP8/rRPv5UStkvcIszygs85Ea00/gottTDTJslOdFSynsqpg4CO2/OA JNwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=2jICgiM8byXfzl2DmuXPIL46Kmc0bp/FkLK/0863SDw=; b=yIQ4ejBAZow6HaIRKNnU+obxfyDQ2AeLOQHvzadYgqT46rEKWTGDbfvHsssQZGyBIx Druu42Wdy0eoKRvqTowGsGRh7hMizUelZmpcqGccDk225dUrFMZteKGyVQng6mgegwcV 4n4EcEQdDj8UV3T1ja+SarU7jHRW+DThcp9arHndMtuZ9KvwhdrTuoLkiKxSy46lTEPM e8KwAVVGgArC7fK8IBFGyKP1WvSbWBYyZkETiTlufcSkB7EUt+V4NfEKDxt8sZ9xvec+ UFpP01j6ftLKQYKthFP2I4EXOwlY9C4bN4lp/ikFxgi+JqgfAd9hqhybJwOHxyk41y0H NZDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EDwMrh2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v84si497947pfc.244.2021.04.08.04.27.23; Thu, 08 Apr 2021 04:27:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EDwMrh2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231244AbhDHL0L (ORCPT + 99 others); Thu, 8 Apr 2021 07:26:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58481 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231208AbhDHL0K (ORCPT ); Thu, 8 Apr 2021 07:26:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617881158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2jICgiM8byXfzl2DmuXPIL46Kmc0bp/FkLK/0863SDw=; b=EDwMrh2BWqHIG2cm50cfY9Xfx3ziJrF0YWgjXpOlwz6xkcjTJVpaMbN3L1JCHRqy8/4O4V IFhZwlegC9qRwoVW1XsvV79pcHoPr7T41iKjDygpYYuexbDKek2Lq91Q3zgdHwzwhljvOM gUrDyr5VX8a+LU7viP7/1NbtwZ++FBY= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-113-dvXH7ezYMvqWnmzWBcgxBA-1; Thu, 08 Apr 2021 07:25:57 -0400 X-MC-Unique: dvXH7ezYMvqWnmzWBcgxBA-1 Received: by mail-ed1-f70.google.com with SMTP id q12so872585edv.9 for ; Thu, 08 Apr 2021 04:25:57 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=2jICgiM8byXfzl2DmuXPIL46Kmc0bp/FkLK/0863SDw=; b=qtx1WPrzrj8fS4D5c3SwA4WLRsnBJ1+P1n03/D82lhjD1L2mA2mK4twkPCXiTYQgXu pGrM6DgZy4QPeEpTk9AzLN3i3EwmKAIabavs884591tLLJH8BJwExqORI4kJ85cH1PUB AgXpU6rfBQYWwLNrDZImDfBgVACZTIhpfOJ0q9pGlXeynJx7DzF6akN3r78OTVzOQrWM k861FdLuq7KH+sbsb215bG2WDDfvfUQGilOCfTRw6s/lev9tG1hzRBecCQHQSTMYVOKz eB3jUs4yMFuSGe/d0KcEDQNZKs3iEvo4cQXFCGmcz6ab3lAvQbqlYVZTiAd5/A6x5hvv ShaA== X-Gm-Message-State: AOAM533+p1TKTlV2VygU6ZsrTlrOM4HX43eBVhbPNli6F7tYvmIxIoaD eG1uN9JWLwAEBNXuk5ILjRN8vYmkFNLdYbnAd9zINJI6yBr5+DaID2Aq4gC3ABLzBsqW58Cu05+ ktBRt8Z4AJZX7mDV/B11n5w6L X-Received: by 2002:a05:6402:1393:: with SMTP id b19mr10568105edv.333.1617881156262; Thu, 08 Apr 2021 04:25:56 -0700 (PDT) X-Received: by 2002:a05:6402:1393:: with SMTP id b19mr10568085edv.333.1617881156118; Thu, 08 Apr 2021 04:25:56 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id y21sm1054224edr.38.2021.04.08.04.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 04:25:55 -0700 (PDT) From: Vitaly Kuznetsov To: Vineeth Pillai Cc: "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "K. Y. Srinivasan" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, Lan Tianyu , Michael Kelley , Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel , Wei Liu , Stephen Hemminger , Haiyang Zhang Subject: Re: [PATCH 7/7] KVM: SVM: hyper-v: Direct Virtual Flush support In-Reply-To: References: Date: Thu, 08 Apr 2021 13:25:54 +0200 Message-ID: <87a6q9augt.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Vineeth Pillai writes: > From Hyper-V TLFS: > "The hypervisor exposes hypercalls (HvFlushVirtualAddressSpace, > HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressList, and > HvFlushVirtualAddressListEx) that allow operating systems to more > efficiently manage the virtual TLB. The L1 hypervisor can choose to > allow its guest to use those hypercalls and delegate the responsibility > to handle them to the L0 hypervisor. This requires the use of a > partition assist page." > > Add the Direct Virtual Flush support for SVM. > > Related VMX changes: > commit 6f6a657c9998 ("KVM/Hyper-V/VMX: Add direct tlb flush support") > > Signed-off-by: Vineeth Pillai > --- > arch/x86/kvm/svm/svm.c | 48 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 48 insertions(+) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 3562a247b7e8..c6d3f3a7c986 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -440,6 +440,32 @@ static void svm_init_osvw(struct kvm_vcpu *vcpu) > vcpu->arch.osvw.status |= 1; > } > > +#if IS_ENABLED(CONFIG_HYPERV) > +static int hv_enable_direct_tlbflush(struct kvm_vcpu *vcpu) > +{ > + struct hv_enlightenments *hve; > + struct hv_partition_assist_pg **p_hv_pa_pg = > + &to_kvm_hv(vcpu->kvm)->hv_pa_pg; > + > + if (!*p_hv_pa_pg) > + *p_hv_pa_pg = kzalloc(PAGE_SIZE, GFP_KERNEL); > + > + if (!*p_hv_pa_pg) > + return -ENOMEM; > + > + hve = (struct hv_enlightenments *)&to_svm(vcpu)->vmcb->hv_enlightenments; > + > + hve->partition_assist_page = __pa(*p_hv_pa_pg); > + hve->hv_vm_id = (unsigned long)vcpu->kvm; > + if (!hve->hv_enlightenments_control.nested_flush_hypercall) { > + hve->hv_enlightenments_control.nested_flush_hypercall = 1; > + vmcb_mark_dirty(to_svm(vcpu)->vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS); > + } > + > + return 0; > +} > +#endif > + > static int has_svm(void) > { > const char *msg; > @@ -1034,6 +1060,21 @@ static __init int svm_hardware_setup(void) > svm_x86_ops.tlb_remote_flush_with_range = > kvm_hv_remote_flush_tlb_with_range; > } > + > + if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) { > + pr_info("kvm: Hyper-V Direct TLB Flush enabled\n"); > + for_each_online_cpu(cpu) { > + struct hv_vp_assist_page *vp_ap = > + hv_get_vp_assist_page(cpu); > + > + if (!vp_ap) > + continue; > + > + vp_ap->nested_control.features.directhypercall = 1; > + } > + svm_x86_ops.enable_direct_tlbflush = > + hv_enable_direct_tlbflush; > + } > #endif > > if (nrips) { > @@ -3913,6 +3954,13 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu) > } > svm->vmcb->save.cr2 = vcpu->arch.cr2; > > +#if IS_ENABLED(CONFIG_HYPERV) > + if (svm->vmcb->hv_enlightenments.hv_vp_id != to_hv_vcpu(vcpu)->vp_index) { This looks wrong (see my previous comment about mixing KVM-on-Hyper-V and Windows/Hyper-V-on-KVM). 'to_hv_vcpu(vcpu)->vp_index' is 'Windows/Hyper-V-on-KVM' thingy, it does not exist when we run without any Hyper-V enlightenments exposed (e.g. when we run Linux as our guest). > + svm->vmcb->hv_enlightenments.hv_vp_id = to_hv_vcpu(vcpu)->vp_index; > + vmcb_mark_dirty(svm->vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS); > + } > +#endif > + > /* > * Run with all-zero DR6 unless needed, so that we can get the exact cause > * of a #DB. -- Vitaly