Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1025137pxb; Fri, 15 Apr 2022 18:45:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybWdPMVFukqjhS0lWJ2XkMyU9dqhQKdQEM8kYBDhKBrQZF4gQbXQFfjNOCJ7wQlqLq6HTW X-Received: by 2002:a05:6a00:a26:b0:4fd:f9dd:549c with SMTP id p38-20020a056a000a2600b004fdf9dd549cmr1591704pfh.42.1650073507861; Fri, 15 Apr 2022 18:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650073507; cv=none; d=google.com; s=arc-20160816; b=Q9eIwSMeK1RFU2PE0Pm/l5eV6fHppH23a7bjJpp7bic6JhKlB8f+vVaGei+c3ql4Mq hqjfIg3k6JEBEQPtOUEJjFusJFLRlkd+kYqncHN2mxSkCrVzmKqoRW6fsfU88KtEegGI rR8w+7ozV3qMcLqTjl7FrfZ7ByLjker7xXKjl88A4k8QWJ+mofZT03THfpLB6N5g9BvL z87UeHxbj4PsKS0XLYGcQCkpnyCzaEm4MdNwKsef94JSmAFMYiXYMKnTJ6ZMOz4f5U+1 Rb6nLJgvdKic8jc4t1iI9hdA96Hlf2ENQ0oAWbVP1EVAQtQMvbQBQSxRSLVaEg3i/mlY zEaw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UOg2AgFte5MATNuwhmZnhfjrYREecC41nw9W9kik+X8=; b=ygElmWswNO2O8yxVG2A5QyeqfyyibeXXnhdzSSEW7VFIx8Xp8ADajQmTKkG4bB6Up1 nOmyVRc/8E9aXPcAS9x3izrOXDQiDnTyE++bF3FDprbbEud2GjqnvNqclqiUL72D+GlL Ep8MiWlSPhIisgex5gzrBumJbBF/YMYPskSlghhCD4pAMNp1nIJ0bNdLw4j7CERUzMzN 9ziR1Rj4A2KvATxYq46mFF5nRZ+MSyn6l6aGIlGdz3ijIDHRa+ZU3rlDF80YcZ1BZImG Qf8zRbTEueTeNDJ0xkc94s/Taho5fokYHY8jvvNyfGbGfqV7iVIv88nb3NZ3+QY8Jafo n1Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NYvdOHZ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x8-20020a17090a9dc800b001bfc324fc16si5116088pjv.99.2022.04.15.18.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NYvdOHZ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 70D2916AA47; Fri, 15 Apr 2022 18:09:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346971AbiDNOLd (ORCPT + 99 others); Thu, 14 Apr 2022 10:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244871AbiDNN2N (ORCPT ); Thu, 14 Apr 2022 09:28:13 -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 A8143A76D0 for ; Thu, 14 Apr 2022 06:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649942468; 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=UOg2AgFte5MATNuwhmZnhfjrYREecC41nw9W9kik+X8=; b=NYvdOHZ450hBoa/GTY4Be6uKlsaneN1uWd6EpAEgSFpaaDk6h+S2YNvqt4G20SN5nHucRi FpXDUzGW2V0VaBIUzO1wCEZG1t6AS7Vk931k5R/LiMnCpphcC28imu2Y5yItX+1Nnramy+ j7wsSnXVVsTC6DXwwXgsDdu7enMMHjs= 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-660-aDOaM6_EPo2bbTwEaNYNuw-1; Thu, 14 Apr 2022 09:21:05 -0400 X-MC-Unique: aDOaM6_EPo2bbTwEaNYNuw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B9E989FF06; Thu, 14 Apr 2022 13:20:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C3DD7774; Thu, 14 Apr 2022 13:20:49 +0000 (UTC) From: Vitaly Kuznetsov To: 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 Subject: [PATCH v3 17/34] KVM: x86: hyper-v: Introduce fast kvm_hv_l2_tlb_flush_exposed() check Date: Thu, 14 Apr 2022 15:19:56 +0200 Message-Id: <20220414132013.1588929-18-vkuznets@redhat.com> In-Reply-To: <20220414132013.1588929-1-vkuznets@redhat.com> References: <20220414132013.1588929-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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); +} + static inline bool kvm_hv_is_tlb_flush_hcall(struct kvm_vcpu *vcpu) { struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); -- 2.35.1