Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6870861rwl; Mon, 9 Jan 2023 14:20:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXsbbcSN9QMgZLrtmPqp9YaiPoZfVH8QtK7CjR6IYd0E9xhZYjHhCpPs232zqFYSy3ctp1au X-Received: by 2002:a05:6402:2a08:b0:470:4d71:6d43 with SMTP id ey8-20020a0564022a0800b004704d716d43mr60935821edb.25.1673302819677; Mon, 09 Jan 2023 14:20:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673302819; cv=none; d=google.com; s=arc-20160816; b=kR2dg6T+BzZwJweSZCValosT0170xUGijs8fB7fYUZIfHM31uo/67lG8igzUrrbsJN w6zsu3iAnsDs8tgGgm+YOtnaekM6rA7emmdmf4X4Ez8yHH62uvVEMk0TYYYAN4Qe7ERy XURTKgjKVJJZ7lc8uy5fZzTeWEfzTUWoZ45XGyy3ROTDaZRx/4znuAxts3ys2u+nO3dV Jr0CgnvObIAyuYrvXYPlcAW9JmeYlmXCDHw09lBEu7RapDfXm5QXORZEFTBniYXxQUPP Q7Wd2+rLrCq5KqS+d7aXDQU2JKdGXYcwD/00y8fmtF6ZVbTHYwyOmQ0cJdG1AjyNC10o 7lMg== 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:dkim-signature; bh=SDYN0MRDIF+SnOeyd4pyYdGIKCrHRaNe9q+tU9g7tHk=; b=RF91B4mmlhrj0rzlWnCr88XkJx8dLkQzAMpJRf7kDxzs/N0ox7W0xKJH208Ht14ZYM EwpCv3a7G/M0Lrfp+Fi9AAbJFSsNbox7WDSaUEaKeXLaNL7GVmAwVaADJPGUw3Gx3Ocx d8WBVJ0pjrt8EOhsVWifslK+3hD16FBGzWvdEgCcAFSeiOgS7Xy2Mvor3S5pZ1Rnsbv/ BvihiPkLEd2q+GYPnnlnR0zswnXaKZ+f01aHKepB68f5V4Ct17/8jynIcAeDV6fdz5NB Y8ugbFxZT90YX3Fj02AArA9tU8GSW5tEYeD+15B/CBIwEATMeHst4tpyLKcWvdQ9HjyA ICWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JpgU+lBo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb17-20020a1709076d9100b0082b07d48ce3si11141388ejc.495.2023.01.09.14.20.06; Mon, 09 Jan 2023 14:20:19 -0800 (PST) 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=JpgU+lBo; 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 S235575AbjAIVyX (ORCPT + 53 others); Mon, 9 Jan 2023 16:54:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237601AbjAIVyI (ORCPT ); Mon, 9 Jan 2023 16:54:08 -0500 Received: from mail-ot1-x349.google.com (mail-ot1-x349.google.com [IPv6:2607:f8b0:4864:20::349]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C8BB14D13 for ; Mon, 9 Jan 2023 13:54:07 -0800 (PST) Received: by mail-ot1-x349.google.com with SMTP id cz20-20020a0568306a1400b006849b669d65so570193otb.10 for ; Mon, 09 Jan 2023 13:54:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SDYN0MRDIF+SnOeyd4pyYdGIKCrHRaNe9q+tU9g7tHk=; b=JpgU+lBoUCLbZ56Jvj7Pn/vdi78vU5U3QuKtvIBxucZgLmZuMLmd88ZuQTUzyBKvak 6URYiypCIW+TZt6tpj3vahCJkJfZ/bLR5/iBFmcgS2xJWZjSs5Km1XmDOCZFVyYNrNdF aQxMRNm9CoVdpDALfBC57x8+EFA1cfuvZqgDxyITXdGCIOEqTxQiAuVy9uJ1cxGO/3EV abfT9ocI5Otykw8Nadc9eXPbqcQZXXaZrNB0el9+yvluuWfZF1VWhrmpIVzBQ0tBz6CD +6oL0xnc06/xPuEhNIL+kfwdmFZFTaFbgKl3SlvFFlUqQ7wMRKAH+9CjY0D5URbPHfBd jhMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SDYN0MRDIF+SnOeyd4pyYdGIKCrHRaNe9q+tU9g7tHk=; b=nHXUnBLmbpCrMrKDdDHa+yfY5zztlxds2uXJF7VqDIZrXZ3TEu+wPxbkidlLxSDuSp jgKsoY62oLX/pKzL5sSCw/vmP2fqhO4o00OcsvJITPXFjG3WpQTdvQQWtBrIqnFs3de4 xg3qyQShIAQP0FUUk8SyNVWCcWZ9ASfLYIRQMPcLTERDPAQE7jVmoo5pc9p/N9RkHUUg W8O295G0atdSo0sB+vr6MB4GZwnpfbK+/MaR3h5sxlZ07h88m/wqFnLJQXyKtiyr/ioX 2VLVmxQnDBCr57w3/40Cw3TVHJP9L9HOCLweqYLUo3bjIDs8A/OkisBOkVAIepAencRa d3Cg== X-Gm-Message-State: AFqh2kpRn1JWcazTFAgdVuvowfRO6IuYedsJ3cQx4SvFt24foHmI6n8L zO65E3HQ4lh5xw7BM7IUkRO3B99sk8yx X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:22b5]) (user=rananta job=sendgmr) by 2002:a05:6808:1a1d:b0:364:532d:215a with SMTP id bk29-20020a0568081a1d00b00364532d215amr195559oib.187.1673301246427; Mon, 09 Jan 2023 13:54:06 -0800 (PST) Date: Mon, 9 Jan 2023 21:53:44 +0000 In-Reply-To: <20230109215347.3119271-1-rananta@google.com> Mime-Version: 1.0 References: <20230109215347.3119271-1-rananta@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109215347.3119271-4-rananta@google.com> Subject: [RFC PATCH 3/6] KVM: Define kvm_flush_remote_tlbs_range From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier , Ricardo Koller , Reiji Watanabe , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Jing Zhang , Colton Lewis , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,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 Define kvm_flush_remote_tlbs_range() to limit the TLB flush only to a certain range of addresses. Replace this with the existing call to kvm_flush_remote_tlbs() in the MMU notifier path. Architectures such as arm64 can define this to flush only the necessary addresses, instead of the entire range. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/kvm/mmu.c | 10 ++++++++++ include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 39d9a334efb57..70f76bc909c5d 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -91,6 +91,16 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) kvm_call_hyp(__kvm_tlb_flush_vmid, &kvm->arch.mmu); } +void kvm_flush_remote_tlbs_range(struct kvm *kvm, unsigned long start, unsigned long end) +{ + struct kvm_s2_mmu *mmu = &kvm->arch.mmu; + + if (system_supports_tlb_range()) + kvm_call_hyp(__kvm_tlb_flush_range_vmid_ipa, mmu, start, end, 0); + else + kvm_flush_remote_tlbs(kvm); +} + static bool kvm_is_device_pfn(unsigned long pfn) { return !pfn_is_map_memory(pfn); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f51eb9419bfc3..a76cede9dc3bb 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1359,6 +1359,7 @@ int kvm_vcpu_yield_to(struct kvm_vcpu *target); void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu, bool usermode_vcpu_not_eligible); void kvm_flush_remote_tlbs(struct kvm *kvm); +void kvm_flush_remote_tlbs_range(struct kvm *kvm, unsigned long start, unsigned long end); #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 03e6a38094c17..f538ecc984f5b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -376,6 +376,11 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) ++kvm->stat.generic.remote_tlb_flush; } EXPORT_SYMBOL_GPL(kvm_flush_remote_tlbs); + +void kvm_flush_remote_tlbs_range(struct kvm *kvm, unsigned long start, unsigned long end) +{ + kvm_flush_remote_tlbs(kvm); +} #endif static void kvm_flush_shadow_all(struct kvm *kvm) @@ -637,7 +642,7 @@ static __always_inline int __kvm_handle_hva_range(struct kvm *kvm, } if (range->flush_on_ret && ret) - kvm_flush_remote_tlbs(kvm); + kvm_flush_remote_tlbs_range(kvm, range->start, range->end - 1); if (locked) { KVM_MMU_UNLOCK(kvm); -- 2.39.0.314.g84b9a713c41-goog