Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp3115347rwp; Fri, 14 Jul 2023 18:04:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlFGVwsBkMHqwDkP7sdTYVfYB5PqbmD7aW9Ayvjf6b2w9puHxv26/4S2p5JdPlYT33MT4diw X-Received: by 2002:a17:90a:eac9:b0:263:f36e:d610 with SMTP id ev9-20020a17090aeac900b00263f36ed610mr5862253pjb.0.1689383073797; Fri, 14 Jul 2023 18:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689383073; cv=none; d=google.com; s=arc-20160816; b=vvuKINLHDdwZjRBi2XYoQYDsBCpyDRMlHY5ie1Y81TjDJXcxlZN4V7MAIuIW21LzJy +EEqa6vQ1IE6Miggyr2GRFWZlNQfXVuU20BmMNBINDVXYPwj0DnRv76NnF1FfeQH8qvr pVymgQOxat2PBKZnyzYmu21zlJpFj36m0PitVHO/LxJTKtuowYqwFOwnCl34BK6ruBv1 DQ5MUu/O8Zo7hO9iet4/fMDtIVjKUGTmFRNQ9cOqwzgMCy0/14pEmDsr8VyImugdIpBg m9O2DmfSNC6SC3umNmDoiwFy4iUaHUHWxjqkm3HJs+DbZh/ybHRZgeCecU4y9IHCawF6 yLlg== 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=U4OZjoW9BqjNxcy4RlxY9pkc5PoIDGveDxU+kXtMBcc=; fh=0mgYt7awHARBqooV7+boW/ys14vuECt03vTY4pGVtiM=; b=w5O3hBYnll8+8XaGafapgRRf9pe4BY9wd9Xz37dL6ZWmeUcxx1ByjNQ7g5xMDmvG64 jIVVHDW1cHJl04W3M60l/hun35UhtWk09n5yYD0rnVAe2dcArwM+RpYZvpC+K3UdPcmh GaUm/5Biafy+6c87+Agd6akgRV5gZidzc50BEwY4FFzZ1J4KSNCod2izvptHqe6sUl8i r0FsLMq3gE6/xkm35zP+ylqAqsxIW84TasGk6UIK5deroMMMbQkfr5Z/HfqoqoaglLQT xmFzBQ19tfCK3cB7Jg4X7KsOXxtLFROQcF5sjBN8p2apm2eAOaBpSs9Q1NV4A1KoufaD iVrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=KKRWmCcp; 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 d2-20020a17090ab30200b00263fa42fdcbsi1990081pjr.107.2023.07.14.18.04.21; Fri, 14 Jul 2023 18:04:33 -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=20221208 header.b=KKRWmCcp; 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 S230523AbjGOAyg (ORCPT + 99 others); Fri, 14 Jul 2023 20:54:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbjGOAyV (ORCPT ); Fri, 14 Jul 2023 20:54:21 -0400 Received: from mail-oi1-x24a.google.com (mail-oi1-x24a.google.com [IPv6:2607:f8b0:4864:20::24a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C81F03AA3 for ; Fri, 14 Jul 2023 17:54:18 -0700 (PDT) Received: by mail-oi1-x24a.google.com with SMTP id 5614622812f47-39eab9b2163so4149936b6e.3 for ; Fri, 14 Jul 2023 17:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689382458; x=1689987258; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=U4OZjoW9BqjNxcy4RlxY9pkc5PoIDGveDxU+kXtMBcc=; b=KKRWmCcpJXud3QITKn5f94EERCBvnHfPo2Jd+ekvTDvit1ZKtL2At/rqLvkk4EbxYh bmv7L5z/I6o+5NvucbGQ3K/kzCTqCMksln5zbsw+MH51Mq23uoECcPykuMVuXgs/PZud 5lgv/htkcYPoczACz2XxnIE0lYxBwMph7p2vFFTX1Bbj2MJhQ9+vg3FCoV+ZWqWxc0Fs 8w/rrCxOr/GEutoHZlF+pVrS1gEqAxig3LcGCszVXObyi6SOjyH9F0QOp4wPuHsmLJot viR1y/i87qN0pJZ1fI3ZxyhwcGyqozylSHVo1vzB+ZQbxgU2/o0DLNIpJ0px4eAfctld qWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689382458; x=1689987258; 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=U4OZjoW9BqjNxcy4RlxY9pkc5PoIDGveDxU+kXtMBcc=; b=dzW5O7clkkWQ0zGnfrWIFZLX3y2wAxFqS9e5I5AB2pgAmwPDWI0qyjXUIe6hlVSA2P RQfZOANXuk2+uNd3J2eqGB0lgi9o2P3EFo+DpT1phzpTMAEY6m1t4E1z5j6OvwTbY/Ul 6cUQlMqaXUuLWXjQzIbcIG9DQ6ej18AATO+uKkW72E1qrv0FrX1nrQPsyRAyYMjb5+Vt B3qlMdo2zWzW7Y7n6RYfZB2KtNOmYFeSUa4W0kyRuzG+3CF8GsDTu4RiTZDaasAatRNd iBCPaIqgub9M3KBxhN4SfGtmpIUUI1suXWG2XFJBR1pAf2SORj1yS2Z1+jUuvLDEkT4V UkRQ== X-Gm-Message-State: ABy/qLY3vbI6kNKmZez5UXmz50HB80DC8Ru9qSeaHpuFOfw6r74JxznB 2Wit0QAAm9MLoa/jqDjtHWDBkNbhQ4C6 X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:22b5]) (user=rananta job=sendgmr) by 2002:a05:6808:d4f:b0:3a4:26e5:8b24 with SMTP id w15-20020a0568080d4f00b003a426e58b24mr7748513oik.9.1689382458208; Fri, 14 Jul 2023 17:54:18 -0700 (PDT) Date: Sat, 15 Jul 2023 00:54:01 +0000 In-Reply-To: <20230715005405.3689586-1-rananta@google.com> Mime-Version: 1.0 References: <20230715005405.3689586-1-rananta@google.com> X-Mailer: git-send-email 2.41.0.455.g037347b96a-goog Message-ID: <20230715005405.3689586-8-rananta@google.com> Subject: [PATCH v6 07/11] KVM: arm64: Define kvm_tlb_flush_vmid_range() From: Raghavendra Rao Ananta To: Oliver Upton , Marc Zyngier , James Morse , Suzuki K Poulose Cc: Paolo Bonzini , Sean Christopherson , Huacai Chen , Zenghui Yu , Anup Patel , Atish Patra , Jing Zhang , Colton Lewis , Raghavendra Rao Anata , David Matlack , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Gavin Shan 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=ham 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 Implement the helper kvm_tlb_flush_vmid_range() that acts as a wrapper for range-based TLB invalidations. For the given VMID, use the range-based TLBI instructions to do the job or fallback to invalidating all the TLB entries. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Gavin Shan --- arch/arm64/include/asm/kvm_pgtable.h | 10 ++++++++++ arch/arm64/kvm/hyp/pgtable.c | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 8294a9a7e566..5e8b1ff07854 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -754,4 +754,14 @@ enum kvm_pgtable_prot kvm_pgtable_stage2_pte_prot(kvm_pte_t pte); * kvm_pgtable_prot format. */ enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte); + +/** + * kvm_tlb_flush_vmid_range() - Invalidate/flush a range of TLB entries + * + * @mmu: Stage-2 KVM MMU struct + * @addr: The base Intermediate physical address from which to invalidate + * @size: Size of the range from the base to invalidate + */ +void kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu, + phys_addr_t addr, size_t size); #endif /* __ARM64_KVM_PGTABLE_H__ */ diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index aa740a974e02..5d14d5d5819a 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -670,6 +670,26 @@ static bool stage2_has_fwb(struct kvm_pgtable *pgt) return !(pgt->flags & KVM_PGTABLE_S2_NOFWB); } +void kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu, + phys_addr_t addr, size_t size) +{ + unsigned long pages, inval_pages; + + if (!system_supports_tlb_range()) { + kvm_call_hyp(__kvm_tlb_flush_vmid, mmu); + return; + } + + pages = size >> PAGE_SHIFT; + while (pages > 0) { + inval_pages = min(pages, MAX_TLBI_RANGE_PAGES); + kvm_call_hyp(__kvm_tlb_flush_vmid_range, mmu, addr, inval_pages); + + addr += inval_pages << PAGE_SHIFT; + pages -= inval_pages; + } +} + #define KVM_S2_MEMATTR(pgt, attr) PAGE_S2_MEMATTR(attr, stage2_has_fwb(pgt)) static int stage2_set_prot_attr(struct kvm_pgtable *pgt, enum kvm_pgtable_prot prot, -- 2.41.0.455.g037347b96a-goog