Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9720071rwd; Wed, 21 Jun 2023 10:54:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ588oCJW7SJwGHgTEX1s7dFFrPUQ1g4+oEmtFBmUYHwUx4f1D5WXV5Cg3l/1djwSKbTnar1 X-Received: by 2002:a05:6a21:7897:b0:122:9e67:1d77 with SMTP id bf23-20020a056a21789700b001229e671d77mr5300004pzc.38.1687370084887; Wed, 21 Jun 2023 10:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687370084; cv=none; d=google.com; s=arc-20160816; b=VAAtgYhzz21ObQm0ZLJ5j77Q8X6vtcJgZGc9GVLltExZcCNP4ocpESiytGjUlIH132 warqA97ewCVY25ZsMo0tjmW7I5Scbf3PhvKAYCS01eVEyGEIouvtBwAJphIz3tVvtOpP ZsdYEib/bK8X7sd6xpXEkyoRWnUQWBcoERnXS+xWDH7RyKFXQO+fg4Psm9K2a5ur7Neq 5VqD/iyJwBQKWTDyDv//9IBYhZcJs7JS8imFZxC1jUj7vlVOhC7nWA/x9gv1RVVLpErQ p5N4xPdfwaxATevCUewHXNbrB3qvm+52DHmFd1pjkERUgbl+AX95InT7G99g/+9zES0E kt8g== 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=j157PG4NSYE82v2fAItKFhVfRcmmpeiCHUTGpM3SOrs=; b=QSNINhJ/snN21r9pPpLJtBVHDlxxtypW61rTtqLI2l7fX8iMADaeWr8BzQOhgQ8j4P TaCRVcxrwZeahZcpcflRh7zPyNFzn/QNaTNKs3jE4jIb5Yv/iFKiSTGEESNTqqWFttDS 419CNGsh4y/7+Ufk7JkdVKOF9iK4uzQN4l1/un0qHNRXe3UJYkxbB+4RXDya9LnyU3hx qsVY0ecL08rhRnTQWjPlzoPJPVboIsDul2s4SbxQxfFSJXYvRZ0aS7PCuhjDigSn6ueY 2K3yO60IdydXVJUO07upNyJGqHRPJTUiRFqptHtwQzEWqujujlfAJAE6QbDUUhakdxxx TSeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=Gl6wq+mE; 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 m18-20020a637112000000b0051b1966e6b6si4286433pgc.521.2023.06.21.10.54.32; Wed, 21 Jun 2023 10:54:44 -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=Gl6wq+mE; 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 S230303AbjFURvd (ORCPT + 99 others); Wed, 21 Jun 2023 13:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231713AbjFURuk (ORCPT ); Wed, 21 Jun 2023 13:50:40 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 313FB210A for ; Wed, 21 Jun 2023 10:50:29 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bfe702f99b8so1479526276.1 for ; Wed, 21 Jun 2023 10:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687369828; x=1689961828; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=j157PG4NSYE82v2fAItKFhVfRcmmpeiCHUTGpM3SOrs=; b=Gl6wq+mEywBMdam4XfA6Jx3xs02PqlG2630KExwZ+IZ1eaEu2M8C4gqV/l7wcdwgF3 /D1SpZQ0iJjXckKesr45c+8QYgxKeaJkXk4CzLhdqEna8C9zX/I5d6oFGpNmP8iq6sY5 AD2tneZCrgHa95MtCXOU6/zAbzMhBOWLtGo2xx45SVnmLsd1KeV2yL43QUWZzbPYsRE5 0KFNo+sYozd7eoDI93xm/37wexRwY8LUWph38U1kdZ/ZPiRwyt7W5rsyP0dZypbTXy1d v4IZ0o/cb4ZauS58uWHhZOddMD4erO5Pva1AdW/HnuLgUZTI3rDNpeArz5G2OY0RmC2L 7aKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687369828; x=1689961828; 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=j157PG4NSYE82v2fAItKFhVfRcmmpeiCHUTGpM3SOrs=; b=gS7tfNwNV54Nk3G0JEqZ0ovGbfBpAvleKEqgmXgs9DFR/okxYo4czFwU7LFQ2dTzUZ /VA2txFqaZdurAY7lcrQ9K7MNpZQveiifazXlEPhUh9o/5vAJSPF47Tw25XZgO8JsHnC kwgpO7Q4oYzpxhfqT5NUyAPWG4N3LSvvQGwWcTD+isTKbRsMwpGbHsQT2RMma1fdmKJF H9Y6nus2olO1B1RrdNRrf+AzfZDNoX6bQAoUaJjUcEwyAdykmaDj/SMRb4R9RR3enCZr QdUvmGxmm+dipXIqHCyFQ+BKRv6fsy1wx4HHME58mzZtrUr+2W+BfjGk7riwVP+KZeeB uRaw== X-Gm-Message-State: AC+VfDxOJRhyK+nh5mhAibDfZIloikMytu3BKSTgpj5m524g5vRT5tGx nJp1K4K36JNlqC/FxYr3RwIgsOxAEmo4 X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:22b5]) (user=rananta job=sendgmr) by 2002:a25:74c9:0:b0:ba8:4ff5:3217 with SMTP id p192-20020a2574c9000000b00ba84ff53217mr2202294ybc.3.1687369828056; Wed, 21 Jun 2023 10:50:28 -0700 (PDT) Date: Wed, 21 Jun 2023 17:49:58 +0000 In-Reply-To: <20230621175002.2832640-1-rananta@google.com> Mime-Version: 1.0 References: <20230621175002.2832640-1-rananta@google.com> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230621175002.2832640-8-rananta@google.com> Subject: [RESEND PATCH v5 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 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,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 --- 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 4cd6762bda805..1b12295a83595 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -682,4 +682,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 3d61bd3e591d2..df8ac14d9d3d4 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -631,6 +631,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.162.gfafddb0af9-goog