Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp793846rdg; Thu, 10 Aug 2023 22:46:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHR49FdNcBFdXCb4FJQrtIsDGyujf3AW+YypwMkmeK8f43+MUDK50VJbf1pHI7I9/xnICob X-Received: by 2002:a05:6a00:1816:b0:681:c372:5aa4 with SMTP id y22-20020a056a00181600b00681c3725aa4mr1376466pfa.27.1691732764996; Thu, 10 Aug 2023 22:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691732764; cv=none; d=google.com; s=arc-20160816; b=GQtB4q+6KHnDexTwUK4ucvkWu25afYzm43VX4WBwldGrbL9yDyNoTPnUDRC3rx+neH G8EHDELLoavGJDl+CbS+vJxbH1g7y3nLEag6BlUNcnrxmvCYqhTyQ4gamZbO62xIAOQy HdFVWn2RFJKnCJf5zHdzmRbNWJdUqAUu29QFXhjvCjyPH3dhqsy6T2a5yczak0GTgu9A lIukVi6KwAfWpAagW41iiG9hKeB1egy1XvZuloRavIEv1K6hC/Df+kGuYEXJYHnzJ2fa BSIpHguBcDS2Y0cd/rcnWXLFDTClpyDW2w8mvZK9FDT05VRdFTFNLam/W6Hr47kzffnT RSkA== 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=CwKTqZRHBF6wuN1C9cAW2HapO35gWwZnaXscRj6lwnc=; fh=yw5tXiXa6fgZNcqMuRzw9eeT6vziy3WnhZBwRz1vFio=; b=0q7QpTEqzwCXhozLCqKRM7yU47MB59TwnJRFdNJNeajwAIJPTiRgL5E6UYzJjS8Z0G rrbY0OiVrCzpbV0al8nzuDqd9cf3tL0n4YUKPhLdg9ki6rQd5MABUuTRSmT0a8MwZzjL /+FX2bqEumR/xB/RAmjdrbFWp5sQi20RR54aHe/38GlpVh4aceBR420tY4ljI26q/oZV SkQjcKAf+kx2XUgJYqdXvv1ujTsaufcRRZEBMtO1lLUHZLUiMm5riCi2LXeez9rk9S7q h3p0P7LwS006D1zgdkh2Owp4TJY1CTM1K3nsn3lRf6LL55UpLgn/SwjehRYAN5EZm0uU Y5Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=siKzlnye; 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 y7-20020a056a00180700b00687207bce71si2890108pfa.357.2023.08.10.22.45.52; Thu, 10 Aug 2023 22:46:04 -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=siKzlnye; 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 S233852AbjHKEwc (ORCPT + 99 others); Fri, 11 Aug 2023 00:52:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233351AbjHKEv6 (ORCPT ); Fri, 11 Aug 2023 00:51:58 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD98A30C0 for ; Thu, 10 Aug 2023 21:51:46 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-583d1d0de65so20507217b3.0 for ; Thu, 10 Aug 2023 21:51:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691729506; x=1692334306; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CwKTqZRHBF6wuN1C9cAW2HapO35gWwZnaXscRj6lwnc=; b=siKzlnyeJYxNxz3Le8APQ8uLcQDtQqwiSQdt6bti4OnKCrnHioFgjEot+EwjAKZlZk P9katyZ2JtDsI8FPdIPMQYuckWNVQ5RfjwpRdQhAMFEwhgD7E0eUrp3A0uStx/N0UzhL 4Ib4FS/HKhPlrslYEhf4bRkLeti0q5O+S43TqWtGnA5mbcXMOQ0sOHExR4e18KudVMIM +gsKAXATZIeVV6zWjmXpe2nel8pvZAoV6Cdm7wSDFmb+FgKWoTaCWMpAZi1va3S+D+BS 4KbaNzlRFGZu0d060Mbd+mqHAW0BvsFI1Oql8h2q/mQt8DVk9UFWyigyB13jSZ+L3pM7 Nm/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691729506; x=1692334306; 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=CwKTqZRHBF6wuN1C9cAW2HapO35gWwZnaXscRj6lwnc=; b=fPTDK1z6wOJAcQwFph5tZVEJE5jCop3n2tM1OTosyqKrqRsk7PLelCRFR5D8+iaa7t VoEhZ3rKlYDlpratLLMciTtByDpQ4plvrCSMrO7++XeN+a6IjYgCMbPNN7v568CHhfz8 WDeLVQytjSjePueEOz4MPGtOjx5G/yaBFNHm9oAtb0ANR9u306B/1igI1ToWgpWMolIm 0/Vtq/7p/t7SL0mAPE6kF03FqjC1hiwJYyVpmKLRdT7oX/mge5cQVQPPt/0yqOIt+E4T BcNBi3gyQJl4s6wyv/kBWSFNNBfikuzBdzwwx7XmJf3kg6O1Yo00ZLEb67pmdlNmmOhS 8eew== X-Gm-Message-State: AOJu0YwDMkiVXHCnHZAgavSa4e3glASvjrpwK3FQSFdLCxZCHkYyFscG WMFj8fralGThfOaYPjM2hzIJxvLkuI8L X-Received: from rananta-linux.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:22b5]) (user=rananta job=sendgmr) by 2002:a25:8185:0:b0:d63:1d2b:624e with SMTP id p5-20020a258185000000b00d631d2b624emr9342ybk.0.1691729505983; Thu, 10 Aug 2023 21:51:45 -0700 (PDT) Date: Fri, 11 Aug 2023 04:51:23 +0000 In-Reply-To: <20230811045127.3308641-1-rananta@google.com> Mime-Version: 1.0 References: <20230811045127.3308641-1-rananta@google.com> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog Message-ID: <20230811045127.3308641-11-rananta@google.com> Subject: [PATCH v9 10/14] 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 , Reiji Watanabe , Colton Lewis , Raghavendra Rao Anata , David Matlack , Fuad Tabba , 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 , Shaoqin Huang 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,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 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 Reviewed-by: Shaoqin Huang --- 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 8294a9a7e566d..5e8b1ff07854b 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 aa740a974e024..5d14d5d5819a1 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.640.ga95def55d0-goog