From nobody Wed Feb 11 08:11:49 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E985CC761A6 for ; Wed, 5 Apr 2023 00:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235798AbjDEAbt (ORCPT ); Tue, 4 Apr 2023 20:31:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236628AbjDEAbm (ORCPT ); Tue, 4 Apr 2023 20:31:42 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E488F44A8 for ; Tue, 4 Apr 2023 17:31:40 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id c2-20020a62f842000000b0062d93664ad5so11398005pfm.19 for ; Tue, 04 Apr 2023 17:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680654700; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=QhmadyCW7rZ0IkiRTP5OSx3MvkvEXJ8KKkSyEhLJ39I=; b=TjPY9E34iEfwYFaF5STVJtPZRBXPRvz5M/6M3FOVwwDlCAT+skmp6E4KUcFo2kC5Hu ESlOwxOIJZ+AwqvwQMPhdUdsgqIyevhBDskiSNXbSRDq/u1OBDUHF6ASpnEVfLI4N3+N pHZRQJML+PNb7zf4uLE3Q7dpvrJJYAfzFfa0QbKcQx6BrNCCXnXsQm/JsLHzbGASSxRe wZYOH2Zm4q+zVn3QI2GB+hjjaI8H45hFSc8jwNf3wvSzgMQM/Yjwxk5ES7/yWGqsfCP1 Nn7QeImq972HTDSQRx33gpzp+2JpUGTNBSATvuEScKz5/xred2TKdLfPNPILCI5OkQ4X v+4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680654700; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QhmadyCW7rZ0IkiRTP5OSx3MvkvEXJ8KKkSyEhLJ39I=; b=2wQNFRj952acAbPSj2c7TO42BlWD8lvlK4V6mrBKBiKuFK5LlvOvvrVT5Fqs7zhKuL MASweP0dY8xdl4FCJlqT+inAISKU51aMo8BmG1zV+dsqf4ABS1Xa/Yi1PNtpq6BRXCrj yaa/p3qKSAO+B7/mD8cjy6pDi9NPtaFw8WiN1xEYiMrzfkX4klmWpvSWu1DHSJ2ztwBV SkPqUVUspng7m7EVwSJMqVnjXSntMbpfW8mToZC2m55QfLuNGP3yA8RxvdszFvK7yrWe OjggTWNntpyAwl5HMbkJ9XKjm7DrpzyafPvEPXuC/LEFAlYyhIBn3z29ckirW2i/CzSV k6EA== X-Gm-Message-State: AAQBX9fvME6+0W0y7zfHQ7JFXi4rzjQDnfl8jKxVO3Qsjgu8IDbNxtpG lQg7Tanhkg6vP1UtHBh/9oOz2TMjUqY= X-Google-Smtp-Source: AKy350ZRhkvVvcfVPJZNFICm5BlfTqckFjlCgk5lnKdeEMpLC+LvRw7dm4CTlKyK0lwXS/mzLak/k+CCUD8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:46c1:b0:23f:a851:4f04 with SMTP id jx1-20020a17090b46c100b0023fa8514f04mr1644915pjb.3.1680654700461; Tue, 04 Apr 2023 17:31:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 Apr 2023 17:31:33 -0700 In-Reply-To: <20230405003133.419177-1-seanjc@google.com> Mime-Version: 1.0 References: <20230405003133.419177-1-seanjc@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230405003133.419177-3-seanjc@google.com> Subject: [PATCH 2/2] KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V code From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor Hyper-V's range-based TLB flushing API to take a gfn+nr_pages pair instead of a struct, and bury said struct in Hyper-V specific code. Passing along two params generates much better code for the common case where KVM is _not_ running on Hyper-V, as forwarding the flush on to Hyper-V's hv_flush_remote_tlbs_range() from kvm_flush_remote_tlbs_range() becomes a tail call. Cc: David Matlack Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 9 ++------- arch/x86/kvm/kvm_onhyperv.c | 24 ++++++++++++++++++++---- arch/x86/kvm/kvm_onhyperv.h | 2 +- arch/x86/kvm/mmu/mmu.c | 8 ++------ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index ec22101410ee..09eb37853cb1 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -482,11 +482,6 @@ struct kvm_mmu { u64 pdptrs[4]; /* pae */ }; =20 -struct kvm_tlb_range { - u64 start_gfn; - u64 pages; -}; - enum pmc_type { KVM_PMC_GP =3D 0, KVM_PMC_FIXED, @@ -1589,8 +1584,8 @@ struct kvm_x86_ops { void (*flush_tlb_all)(struct kvm_vcpu *vcpu); void (*flush_tlb_current)(struct kvm_vcpu *vcpu); int (*flush_remote_tlbs)(struct kvm *kvm); - int (*flush_remote_tlbs_range)(struct kvm *kvm, - struct kvm_tlb_range *range); + int (*flush_remote_tlbs_range)(struct kvm *kvm, gfn_t gfn, + gfn_t nr_pages); =20 /* * Flush any TLB entries associated with the given GVA. diff --git a/arch/x86/kvm/kvm_onhyperv.c b/arch/x86/kvm/kvm_onhyperv.c index 2e2d08da8a3f..ded0bd688c65 100644 --- a/arch/x86/kvm/kvm_onhyperv.c +++ b/arch/x86/kvm/kvm_onhyperv.c @@ -10,17 +10,22 @@ #include "hyperv.h" #include "kvm_onhyperv.h" =20 +struct kvm_hv_tlb_range { + u64 start_gfn; + u64 pages; +}; + static int kvm_fill_hv_flush_list_func(struct hv_guest_mapping_flush_list = *flush, void *data) { - struct kvm_tlb_range *range =3D data; + struct kvm_hv_tlb_range *range =3D data; =20 return hyperv_fill_flush_guest_mapping_list(flush, range->start_gfn, range->pages); } =20 static inline int hv_remote_flush_root_tdp(hpa_t root_tdp, - struct kvm_tlb_range *range) + struct kvm_hv_tlb_range *range) { if (range) return hyperv_flush_guest_mapping_range(root_tdp, @@ -29,7 +34,8 @@ static inline int hv_remote_flush_root_tdp(hpa_t root_tdp, return hyperv_flush_guest_mapping(root_tdp); } =20 -int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *rang= e) +static int __hv_flush_remote_tlbs_range(struct kvm *kvm, + struct kvm_hv_tlb_range *range) { struct kvm_arch *kvm_arch =3D &kvm->arch; struct kvm_vcpu *vcpu; @@ -85,11 +91,21 @@ int hv_flush_remote_tlbs_range(struct kvm *kvm, struct = kvm_tlb_range *range) spin_unlock(&kvm_arch->hv_root_tdp_lock); return ret; } + +int hv_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, gfn_t nr_= pages) +{ + struct kvm_hv_tlb_range range =3D { + .start_gfn =3D start_gfn, + .pages =3D nr_pages, + }; + + return __hv_flush_remote_tlbs_range(kvm, &range); +} EXPORT_SYMBOL_GPL(hv_flush_remote_tlbs_range); =20 int hv_flush_remote_tlbs(struct kvm *kvm) { - return hv_flush_remote_tlbs_range(kvm, NULL); + return __hv_flush_remote_tlbs_range(kvm, NULL); } EXPORT_SYMBOL_GPL(hv_flush_remote_tlbs); =20 diff --git a/arch/x86/kvm/kvm_onhyperv.h b/arch/x86/kvm/kvm_onhyperv.h index 55d7fcb84cc1..ff127d313242 100644 --- a/arch/x86/kvm/kvm_onhyperv.h +++ b/arch/x86/kvm/kvm_onhyperv.h @@ -7,7 +7,7 @@ #define __ARCH_X86_KVM_KVM_ONHYPERV_H__ =20 #if IS_ENABLED(CONFIG_HYPERV) -int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *rang= e); +int hv_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, gfn_t nr_pages); int hv_flush_remote_tlbs(struct kvm *kvm); void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp); #else /* !CONFIG_HYPERV */ diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 7654be48ff69..a7adbac0855c 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -278,15 +278,11 @@ static inline bool kvm_available_flush_remote_tlbs_ra= nge(void) void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, gfn_t nr_pages) { - struct kvm_tlb_range range; int ret =3D -EOPNOTSUPP; =20 - range.start_gfn =3D start_gfn; - range.pages =3D nr_pages; - if (kvm_x86_ops.flush_remote_tlbs_range) - ret =3D static_call(kvm_x86_flush_remote_tlbs_range)(kvm, &range); - + ret =3D static_call(kvm_x86_flush_remote_tlbs_range)(kvm, start_gfn, + nr_pages); if (ret) kvm_flush_remote_tlbs(kvm); } --=20 2.40.0.348.gf938b09366-goog