Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1547989iob; Thu, 19 May 2022 08:50:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG9dVblz9AJq61WDZ8WeeVZ04hOnUd2DT37DbF+HMnmH8RrSLOm01QjabeetIQlXAwmg6y X-Received: by 2002:a17:902:db0e:b0:15e:b847:2937 with SMTP id m14-20020a170902db0e00b0015eb8472937mr5471430plx.8.1652975452135; Thu, 19 May 2022 08:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652975452; cv=none; d=google.com; s=arc-20160816; b=qyEuoenypiNAluLqQ8cPDNBd1pqniFtPIEwpz/HS1caKWprPy7DIO0Ev89GWGMFQI5 YkADavR5XzoMn8hMgpGOQjCZXain0ZHE/uYJzojmzQI0CrRSu2IrZDifK54sLl8gddF8 yKSRmtFc2ESW0FUpKLwEvhHCQpn4A4fhmmwF8mWCZ96Pb8cbx8pt4ZaPhvopKPmLDYOa vkdsiRFr33eKhe059F3BFgU30xHeP1g6n9191cNvCTlA3T6+qPqcPtPqlKEfmPnrvgrK ghDYpr9H1ZCQikqOt29U21mExaoRznhiadaAllg0MQMOAQpPfUoRdyq1SSAnSZxwCx4K ULxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=chcH0p5yUvxNOuMG6xpUSYUYVPOIVaBK57Vn0yWf5ZY=; b=BgdlDYvfvQEK8KuyLijhTP6xcG/62P33vnSKpfmDwPGlBrdlHHJ+c26NXG+VNO1Csr ccwg90p9gipya/Xopbbzi6UEZIG7Fh53KHFUj6kpi78u59cy9deVmZVQ1UeCPM4cawEV iP7hyuAHg/zwwxIK5TKdmuI/f8UP0gDrl+Og3Jfgp1JqUmATg6pkbhkRrFSkqRPb5EyB Grt3Jx44YVLtMbuPWJ09ln00SwhpXopj2CjjW1u7w5RMBhJybAZoDwtAcDCLUeQyg0SC IgxKa5uUTD3dRlJ47uQj/h3bob1mpeSLtvnfjzohbK2/kKbBbj5hJZxjD+PWsJYFzXtS iuZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PxOHuUFb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 31-20020a63135f000000b003c620dacf86si6587794pgt.818.2022.05.19.08.50.39; Thu, 19 May 2022 08:50:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PxOHuUFb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238756AbiESN2U (ORCPT + 99 others); Thu, 19 May 2022 09:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236430AbiESN2R (ORCPT ); Thu, 19 May 2022 09:28:17 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2F53DCEB84 for ; Thu, 19 May 2022 06:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652966894; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=chcH0p5yUvxNOuMG6xpUSYUYVPOIVaBK57Vn0yWf5ZY=; b=PxOHuUFbbvVBFr4zML1hGt1a/9lSelgEy/qVd0OGGt6aIA9YUPkODddgTJstmowu761Q0s zNUvQh3XLUZnYYkSlvPV7sVL2N5KFdgWxuJbdXBRYAN0wbSrL28as6WLFqydgwgF4skOBP xnq/pUwKJ/eGanuW9zUjiSqPtWFnTws= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-132-u1DynL4UM6W4pJ-h8IxAYQ-1; Thu, 19 May 2022 09:28:10 -0400 X-MC-Unique: u1DynL4UM6W4pJ-h8IxAYQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D237E811E81; Thu, 19 May 2022 13:28:09 +0000 (UTC) Received: from starship (unknown [10.40.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88B94492CA2; Thu, 19 May 2022 13:28:07 +0000 (UTC) Message-ID: Subject: Re: [PATCH v3 17/34] KVM: x86: hyper-v: Introduce fast kvm_hv_l2_tlb_flush_exposed() check From: Maxim Levitsky To: Vitaly Kuznetsov , kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 19 May 2022 16:28:06 +0300 In-Reply-To: <877d6hu012.fsf@redhat.com> References: <20220414132013.1588929-1-vkuznets@redhat.com> <20220414132013.1588929-18-vkuznets@redhat.com> <3a4199c0b7ba7cf82c4eadf2881e24be609c2f0d.camel@redhat.com> <877d6hu012.fsf@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2022-05-19 at 15:25 +0200, Vitaly Kuznetsov wrote: > Maxim Levitsky writes: > > > On Thu, 2022-04-14 at 15:19 +0200, Vitaly Kuznetsov wrote: > > > Introduce a helper to quickly check if KVM needs to handle VMCALL/VMMCALL > > > from L2 in L0 to process L2 TLB flush requests. > > > > > > Signed-off-by: Vitaly Kuznetsov > > > --- > > > arch/x86/include/asm/kvm_host.h | 1 + > > > arch/x86/kvm/hyperv.c | 6 ++++++ > > > arch/x86/kvm/hyperv.h | 7 +++++++ > > > 3 files changed, 14 insertions(+) > > > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > > index ce62fde5f4ff..168600490bd1 100644 > > > --- a/arch/x86/include/asm/kvm_host.h > > > +++ b/arch/x86/include/asm/kvm_host.h > > > @@ -616,6 +616,7 @@ struct kvm_vcpu_hv { > > > u32 enlightenments_eax; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EAX */ > > > u32 enlightenments_ebx; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EBX */ > > > u32 syndbg_cap_eax; /* HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX */ > > > + u32 nested_features_eax; /* HYPERV_CPUID_NESTED_FEATURES.EAX */ > > > } cpuid_cache; > > > > > > struct kvm_vcpu_hv_tlb_flush_ring tlb_flush_ring[HV_NR_TLB_FLUSH_RINGS]; > > > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > > > index 79aabe0c33ec..68a0df4e3f66 100644 > > > --- a/arch/x86/kvm/hyperv.c > > > +++ b/arch/x86/kvm/hyperv.c > > > @@ -2281,6 +2281,12 @@ void kvm_hv_set_cpuid(struct kvm_vcpu *vcpu) > > > hv_vcpu->cpuid_cache.syndbg_cap_eax = entry->eax; > > > else > > > hv_vcpu->cpuid_cache.syndbg_cap_eax = 0; > > > + > > > + entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_NESTED_FEATURES, 0); > > > + if (entry) > > > + hv_vcpu->cpuid_cache.nested_features_eax = entry->eax; > > > + else > > > + hv_vcpu->cpuid_cache.nested_features_eax = 0; > > > } > > > > > > int kvm_hv_set_enforce_cpuid(struct kvm_vcpu *vcpu, bool enforce) > > > diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h > > > index f593c9fd1dee..d8cb6d70dbc8 100644 > > > --- a/arch/x86/kvm/hyperv.h > > > +++ b/arch/x86/kvm/hyperv.h > > > @@ -168,6 +168,13 @@ static inline void kvm_hv_vcpu_empty_flush_tlb(struct kvm_vcpu *vcpu) > > > tlb_flush_ring->read_idx = tlb_flush_ring->write_idx; > > > } > > > > > > +static inline bool kvm_hv_l2_tlb_flush_exposed(struct kvm_vcpu *vcpu) > > > +{ > > > + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); > > > + > > > + return hv_vcpu && (hv_vcpu->cpuid_cache.nested_features_eax & HV_X64_NESTED_DIRECT_FLUSH); > > > +} > > > > Tiny nipick (feel free to ignore): maybe use 'supported' instead of 'exposed', > > as we don't use this term in KVM often. > > > > Indeed we don't. Basically, this is guest_cpuid_has() but for a Hyper-V > bit. I don't quite like 'supported' because we don't actually check > whether KVM or even L1 guest 'support' this feature or not, we check > whether the feature was 'exposed' to L1 so it can actually use it. I'm > going to rename this to > > guest_hv_cpuid_has_l2_tlb_flush() Sounds perfect! Best regards, Maxim Levitsky > > then. > > > Reviewed-by: Maxim Levitsky > > > > Thanks! >