From patchwork Wed Apr 5 00:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 79417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp244849vqo; Tue, 4 Apr 2023 17:38:02 -0700 (PDT) X-Google-Smtp-Source: AKy350Y7mUGVlYP7vcXayyqnjkFW7FuMDZcFhyoiDy1Hsnj5iMEmg29W8A38g4YUhQq42gqopizH X-Received: by 2002:a05:6402:b19:b0:4fb:d620:bd27 with SMTP id bm25-20020a0564020b1900b004fbd620bd27mr405992edb.23.1680655081931; Tue, 04 Apr 2023 17:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680655081; cv=none; d=google.com; s=arc-20160816; b=EO4vwTsQZzxtGwKHU7a7zHALh8R9eosRwNRaNy6kWdKlsHJ09t4475RR1CtcmcuRZD dagCiliSmPcLjqx8XBTGWF92pBVXPzM1SGNqQej3my5/1OiK9Nnj94c90KKTsEe71B/w O+zi3dIg5kofnuda6QjJ6EqTFB6mG1yAiSqjCS7mqVjPx497tOl5lyqi68l2Fq1JKtgj QX04kwDlWoUCqqhizP5iOqoS1dLyrJGMpYaJTvHiRFDekviDnxFalIqPPCI5xui5f+Sb c1Z61QzyB3E6uiZdgOM+0f5a/Zuxtnbh4j6V/HQmGyqUNNGjNMiusOCd7JAzWSPOxSNT f1Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=/gPBL0l5v9wIVeXYa3qg3U83BOdRbqodER9mbhJVPk0=; b=x3IN7+WpF4Mw8kxtDvssfsJBL17whpnBVuxyslu8CCwX1zSzp/LIfd2q0VrwUNYze5 GPQ2pCKnNGTBHGezMlKDmuqf0fsnSeAevUs9CJv5ZmlVQV1ez29mbMLWEk0o2XPXalzB C9yTv8Dw7djIq1a5qy6rVp6TEap3puaYuByuuV5taO4yghjLmvb8cvK44cbbX+NfMS8F 45sp/8yU3Vp/VDrix7rsCAFywTVWIBSWvY583VORpXz40r1cJaBM/YcL2r//sCrcpRDL QnSIW9pG9pvyWnP92Wz/1BKhNav7YsM0j9cxPMFxpDvnlRs3RvaxDs5PW1EoF0DxUPRO tJvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nJVurvW3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020aa7c988000000b004fc63fada98si1346292edt.30.2023.04.04.17.37.27; Tue, 04 Apr 2023 17:38:01 -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=@google.com header.s=20210112 header.b=nJVurvW3; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236636AbjDEAbn (ORCPT + 99 others); Tue, 4 Apr 2023 20:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236566AbjDEAbk (ORCPT ); Tue, 4 Apr 2023 20:31:40 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF33C44BA for ; Tue, 4 Apr 2023 17:31:38 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id l14-20020a170902f68e00b001a1a9a1d326so20008150plg.9 for ; Tue, 04 Apr 2023 17:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680654698; 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=/gPBL0l5v9wIVeXYa3qg3U83BOdRbqodER9mbhJVPk0=; b=nJVurvW323NT4SWBxHv530JErfbP3mT9QYdyaXNoy+hy0eOjruZt9ZC0H56i6aplJo sB972VEVAu4g59VFuYJFiDXDBl6+yDx4s0GPgavlKCE8Vi8qJU1pjUpfHYGIG/hi7bjM 25wJaF56PnhL9ABNlS/BnwMqjff6N3tT2Uc6LsZ1R4IGCFWDDGLRU1JXPoYm3rmUamLO SF08ch4LomH26pNZBcQ3J15+5S9a500FbnEwrODy+cZUZw2AXYfa1oeanC1oh8VxxJEp k0tlOCYqa3WZzWf/ovSCN6+BIZWIaWTOY+QL6K3jRY7l+Fwg7mMNZk3FkI3rQpMYMBk2 SK4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680654698; 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=/gPBL0l5v9wIVeXYa3qg3U83BOdRbqodER9mbhJVPk0=; b=k52XeaLNWRG40n8refY+WavsSde77k1v01YnI2aJcCpEft7UvSt9An1iu5HjeG5FKE xxWZYj2RjALo5aWK4Ug71hRzX+F8Dv69L3/b4tNA+H5hhZ9cfe+ZEotcfcV8KiyJ4wOA KphbJMG/5vrVr0gUTnpzv1ia5WHA76IGEdrDQr7zIqsJGLylNjOnd7kUpq0oyGL4Yp2j s96U+2heUSyAkqaoll2e/9+IuecVcUfvT5C9IJ72r/2eTWrQ5xYaq4k/ibDAYfDU01s3 RtNhJWzPRfzPFFeHPEi4cYLpw3BEmZ0OuZrfvIqm3ti1EQTcXza+oEGrKS3pXusKu1BA pCLQ== X-Gm-Message-State: AAQBX9fp/Kvc7WilxX7sj1hMrgmiio0BayUu1xji+xkXNdfEQZQxNrRq Z+H6O/g0dFtIlgeydRej+wty2LClrCg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:4206:0:b0:514:2040:24ba with SMTP id p6-20020a634206000000b00514204024bamr1024394pga.9.1680654698523; Tue, 04 Apr 2023 17:31:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 Apr 2023 17:31:32 -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-2-seanjc@google.com> Subject: [PATCH 1/2] KVM: x86: Rename Hyper-V remote TLB hooks to match established scheme From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Vitaly Kuznetsov Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762294583065181050?= X-GMAIL-MSGID: =?utf-8?q?1762294583065181050?= Rename the Hyper-V hooks for TLB flushing to match the naming scheme used by all the other TLB flushing hooks, e.g. in kvm_x86_ops, vendor code, arch hooks from common code, etc. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm-x86-ops.h | 4 ++-- arch/x86/include/asm/kvm_host.h | 10 +++++----- arch/x86/kvm/kvm_onhyperv.c | 13 ++++++------- arch/x86/kvm/kvm_onhyperv.h | 5 ++--- arch/x86/kvm/mmu/mmu.c | 12 ++++++------ arch/x86/kvm/svm/svm_onhyperv.h | 5 ++--- arch/x86/kvm/vmx/vmx.c | 5 ++--- 7 files changed, 25 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index 8dc345cc6318..430ca22170e0 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -54,8 +54,8 @@ KVM_X86_OP(set_rflags) KVM_X86_OP(get_if_flag) KVM_X86_OP(flush_tlb_all) KVM_X86_OP(flush_tlb_current) -KVM_X86_OP_OPTIONAL(tlb_remote_flush) -KVM_X86_OP_OPTIONAL(tlb_remote_flush_with_range) +KVM_X86_OP_OPTIONAL(flush_remote_tlbs) +KVM_X86_OP_OPTIONAL(flush_remote_tlbs_range) KVM_X86_OP(flush_tlb_gva) KVM_X86_OP(flush_tlb_guest) KVM_X86_OP(vcpu_pre_run) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 991296a2f807..ec22101410ee 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1588,9 +1588,9 @@ struct kvm_x86_ops { void (*flush_tlb_all)(struct kvm_vcpu *vcpu); void (*flush_tlb_current)(struct kvm_vcpu *vcpu); - int (*tlb_remote_flush)(struct kvm *kvm); - int (*tlb_remote_flush_with_range)(struct kvm *kvm, - struct kvm_tlb_range *range); + int (*flush_remote_tlbs)(struct kvm *kvm); + int (*flush_remote_tlbs_range)(struct kvm *kvm, + struct kvm_tlb_range *range); /* * Flush any TLB entries associated with the given GVA. @@ -1794,8 +1794,8 @@ void kvm_arch_free_vm(struct kvm *kvm); #define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLB static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm) { - if (kvm_x86_ops.tlb_remote_flush && - !static_call(kvm_x86_tlb_remote_flush)(kvm)) + if (kvm_x86_ops.flush_remote_tlbs && + !static_call(kvm_x86_flush_remote_tlbs)(kvm)) return 0; else return -ENOTSUPP; diff --git a/arch/x86/kvm/kvm_onhyperv.c b/arch/x86/kvm/kvm_onhyperv.c index 482d6639ef88..2e2d08da8a3f 100644 --- a/arch/x86/kvm/kvm_onhyperv.c +++ b/arch/x86/kvm/kvm_onhyperv.c @@ -29,8 +29,7 @@ static inline int hv_remote_flush_root_tdp(hpa_t root_tdp, return hyperv_flush_guest_mapping(root_tdp); } -int hv_remote_flush_tlb_with_range(struct kvm *kvm, - struct kvm_tlb_range *range) +int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *range) { struct kvm_arch *kvm_arch = &kvm->arch; struct kvm_vcpu *vcpu; @@ -86,19 +85,19 @@ int hv_remote_flush_tlb_with_range(struct kvm *kvm, spin_unlock(&kvm_arch->hv_root_tdp_lock); return ret; } -EXPORT_SYMBOL_GPL(hv_remote_flush_tlb_with_range); +EXPORT_SYMBOL_GPL(hv_flush_remote_tlbs_range); -int hv_remote_flush_tlb(struct kvm *kvm) +int hv_flush_remote_tlbs(struct kvm *kvm) { - return hv_remote_flush_tlb_with_range(kvm, NULL); + return hv_flush_remote_tlbs_range(kvm, NULL); } -EXPORT_SYMBOL_GPL(hv_remote_flush_tlb); +EXPORT_SYMBOL_GPL(hv_flush_remote_tlbs); void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp) { struct kvm_arch *kvm_arch = &vcpu->kvm->arch; - if (kvm_x86_ops.tlb_remote_flush == hv_remote_flush_tlb) { + if (kvm_x86_ops.flush_remote_tlbs == hv_flush_remote_tlbs) { spin_lock(&kvm_arch->hv_root_tdp_lock); vcpu->arch.hv_root_tdp = root_tdp; if (root_tdp != kvm_arch->hv_root_tdp) diff --git a/arch/x86/kvm/kvm_onhyperv.h b/arch/x86/kvm/kvm_onhyperv.h index 287e98ef9df3..55d7fcb84cc1 100644 --- a/arch/x86/kvm/kvm_onhyperv.h +++ b/arch/x86/kvm/kvm_onhyperv.h @@ -7,9 +7,8 @@ #define __ARCH_X86_KVM_KVM_ONHYPERV_H__ #if IS_ENABLED(CONFIG_HYPERV) -int hv_remote_flush_tlb_with_range(struct kvm *kvm, - struct kvm_tlb_range *range); -int hv_remote_flush_tlb(struct kvm *kvm); +int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *range); +int hv_flush_remote_tlbs(struct kvm *kvm); void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp); #else /* !CONFIG_HYPERV */ static inline void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4c874d4ec68f..7654be48ff69 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -270,9 +270,9 @@ static inline unsigned long kvm_mmu_get_guest_pgd(struct kvm_vcpu *vcpu, return mmu->get_guest_pgd(vcpu); } -static inline bool kvm_available_flush_tlb_with_range(void) +static inline bool kvm_available_flush_remote_tlbs_range(void) { - return kvm_x86_ops.tlb_remote_flush_with_range; + return kvm_x86_ops.flush_remote_tlbs_range; } void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, @@ -284,8 +284,8 @@ void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, range.start_gfn = start_gfn; range.pages = nr_pages; - if (kvm_x86_ops.tlb_remote_flush_with_range) - ret = static_call(kvm_x86_tlb_remote_flush_with_range)(kvm, &range); + if (kvm_x86_ops.flush_remote_tlbs_range) + ret = static_call(kvm_x86_flush_remote_tlbs_range)(kvm, &range); if (ret) kvm_flush_remote_tlbs(kvm); @@ -1498,7 +1498,7 @@ static bool kvm_set_pte_rmap(struct kvm *kvm, struct kvm_rmap_head *rmap_head, } } - if (need_flush && kvm_available_flush_tlb_with_range()) { + if (need_flush && kvm_available_flush_remote_tlbs_range()) { kvm_flush_remote_tlbs_gfn(kvm, gfn, level); return false; } @@ -6623,7 +6623,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, PG_LEVEL_NUM)) { kvm_zap_one_rmap_spte(kvm, rmap_head, sptep); - if (kvm_available_flush_tlb_with_range()) + if (kvm_available_flush_remote_tlbs_range()) kvm_flush_remote_tlbs_sptep(kvm, sptep); else need_tlb_flush = 1; diff --git a/arch/x86/kvm/svm/svm_onhyperv.h b/arch/x86/kvm/svm/svm_onhyperv.h index cff838f15db5..823001033539 100644 --- a/arch/x86/kvm/svm/svm_onhyperv.h +++ b/arch/x86/kvm/svm/svm_onhyperv.h @@ -35,9 +35,8 @@ static inline __init void svm_hv_hardware_setup(void) if (npt_enabled && ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) { pr_info(KBUILD_MODNAME ": Hyper-V enlightened NPT TLB flush enabled\n"); - svm_x86_ops.tlb_remote_flush = hv_remote_flush_tlb; - svm_x86_ops.tlb_remote_flush_with_range = - hv_remote_flush_tlb_with_range; + svm_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs; + svm_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range; } if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) { diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d7bf14abdba1..8031bded75cc 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8432,9 +8432,8 @@ static __init int hardware_setup(void) #if IS_ENABLED(CONFIG_HYPERV) if (ms_hyperv.nested_features & HV_X64_NESTED_GUEST_MAPPING_FLUSH && enable_ept) { - vmx_x86_ops.tlb_remote_flush = hv_remote_flush_tlb; - vmx_x86_ops.tlb_remote_flush_with_range = - hv_remote_flush_tlb_with_range; + vmx_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs; + vmx_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range; } #endif From patchwork Wed Apr 5 00:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 79420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp247024vqo; Tue, 4 Apr 2023 17:43:57 -0700 (PDT) X-Google-Smtp-Source: AKy350b6mXBZDoYxsV9DyQSiNPhzHly6q5ckBg1LIjg+dnDQnhsyaWnF/a5JKoap6qmMD5V9tDKy X-Received: by 2002:a05:6a20:490a:b0:d8:b1dd:92d9 with SMTP id ft10-20020a056a20490a00b000d8b1dd92d9mr4151534pzb.18.1680655436949; Tue, 04 Apr 2023 17:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680655436; cv=none; d=google.com; s=arc-20160816; b=wAc6Tm9NaWbo5MDpP1ezYTTbpalMnEpNYW3zOnkzO9M7z/Eb/s4qSSzjJwGAduyDmW 9Uf+6pUOnz6ispfHpp8n9sy+LnRj84xMe6637/M6XwiBlUNEs7VMCKReCZyQsR9glduz QwimujqsWe07erNjCjJNgGlauNsAR1tHSi5KDZiYl5haXJ6Dj6YxnUHf7vRBUf902Tml DX2goXDLcR8i7ZbHWMA0vEr5kIZ3d+Q4PLWXagvEB+mJBZ0VVPeM2xEqgLCr14GjKXC6 YPuvfb5Vth7LueLEbXrgIvgeY+7GqPZEU+S80QTyhBCl3OEGAflx2wHnAfwe95SMLybJ G/oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=QhmadyCW7rZ0IkiRTP5OSx3MvkvEXJ8KKkSyEhLJ39I=; b=Gu8pVwC0hxOlX0Vkhd3d/I5IdXPeJUh7eeuDAfT2C75VD5eCafF+imNyfiZIeOFb6W Kp20qLINTL1aWzZdPhCtiXgLgnyC9XMX3+J0MvS2YZocUNmz0qvJN6CIkXfFLAtRlQvO OghREhmPd8FRz17Yjh99B7LJ1SjRqHH8D2q0BPWBpENWbqbYDKhg/7I7OcvvArsgnRM3 +iu7J3kNIzupmsyOCbAsXy8d2gPufOr4gY7oQHUn9+/9j298ZtIQCZ6BYbwCvAze3LTw OtsC6AlsAdJJbBp4B0vzIwe+MRPIKm7bskaFBA/chMNN6jRjbSM36Y5hTUPWpjZqGklD rztQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TjPY9E34; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a635b4f000000b004fb95c8f647si11423333pgm.407.2023.04.04.17.43.40; Tue, 04 Apr 2023 17:43:56 -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=@google.com header.s=20210112 header.b=TjPY9E34; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229484AbjDEAbs (ORCPT + 99 others); Tue, 4 Apr 2023 20:31:48 -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-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 X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762294955621315914?= X-GMAIL-MSGID: =?utf-8?q?1762294955621315914?= 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_host.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 */ }; -struct kvm_tlb_range { - u64 start_gfn; - u64 pages; -}; - enum pmc_type { KVM_PMC_GP = 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); /* * 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" +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 = data; + struct kvm_hv_tlb_range *range = data; return hyperv_fill_flush_guest_mapping_list(flush, range->start_gfn, range->pages); } 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); } -int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *range) +static int __hv_flush_remote_tlbs_range(struct kvm *kvm, + struct kvm_hv_tlb_range *range) { struct kvm_arch *kvm_arch = &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 = { + .start_gfn = start_gfn, + .pages = nr_pages, + }; + + return __hv_flush_remote_tlbs_range(kvm, &range); +} EXPORT_SYMBOL_GPL(hv_flush_remote_tlbs_range); 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); 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__ #if IS_ENABLED(CONFIG_HYPERV) -int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *range); +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_range(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 = -EOPNOTSUPP; - range.start_gfn = start_gfn; - range.pages = nr_pages; - if (kvm_x86_ops.flush_remote_tlbs_range) - ret = static_call(kvm_x86_flush_remote_tlbs_range)(kvm, &range); - + ret = static_call(kvm_x86_flush_remote_tlbs_range)(kvm, start_gfn, + nr_pages); if (ret) kvm_flush_remote_tlbs(kvm); }