Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4907381rwb; Mon, 31 Jul 2023 14:30:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlFQKuGNNB/V2sG2BQtJthxJ2BqrM+qd+rA+kgVNEKpP6XqgmgjWkoyvrVn0xf4oo59SZyLD X-Received: by 2002:a17:906:ef8f:b0:99b:6c47:1145 with SMTP id ze15-20020a170906ef8f00b0099b6c471145mr766259ejb.32.1690839053091; Mon, 31 Jul 2023 14:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690839053; cv=none; d=google.com; s=arc-20160816; b=spuBqAEw6IgwzVu2k9Ke+tR0d/Lj/ilCakMteTYtJYoaUnH4YkaTFBOOyiKLI63OHH HTGZ+f0On7CiWMg3AXKLhj72ayLM2yAowRI6eNUuOHAsup9a2AzFGqOt9WBv12XKTRwQ cNBb+DbYiXznKAJeHjQJkFq88P8pxUngYsJNCuIAOH75SZyhxZ3uiL7OLS7Wrq2fFKRe Y9CUbHy9ZlBPUTa6NwNs+tHgR8IzBz9oRHoSR2V+glAbmOsFICu2kas0C0lHwtdB0Auc e9J6f/zvEwTixczd+w872GCB0hCnrhnqIflGmHDwEoKU05pQyuLpwmOTgNLJcJnhzK+7 KqkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=X0gCxxFfGpH7+EO1EgURYZAY2bdhrbnISyF1lBRoK6A=; fh=K+FoIp+ebRc/w0GRwPA6V6+rEYOwOD1e2udzALcnRL8=; b=TmX/rAJ7L8HrBuCB2LuwOG4hh8ALKcrV81ohrZfuXfwLgL+DSgaXwG+V2xXrOlXQ6+ nVU5bWmXpvHISKpVcF2So1c/s2gUiPwtCmsAUMCW1MdCpdoSjlsqjLy3rxLBbXjvlVfE aJ1cd0QKm/eXq4ye5HediwyxTi46cgYRN0SwCg/2W3Xo4ljtdNxGDNhLDjJxAiACk6pv KMjYQmaRMdC585ESABgXew8X11a7OD6aq4NekRdrodWfrWhtFx6/nFPyMNQU1ayo2zPy Ifk9fnjpLGsi71Yody+weD4izExNO6KQt7cJrFIKI4h+TcWlWCTlIL1MNucA6QRSisJ9 rXyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=qZXJd0+f; 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 k8-20020a1709063e0800b00988919c8a70si7307322eji.59.2023.07.31.14.30.23; Mon, 31 Jul 2023 14:30:53 -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=qZXJd0+f; 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 S231492AbjGaSCO (ORCPT + 99 others); Mon, 31 Jul 2023 14:02:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231474AbjGaSCM (ORCPT ); Mon, 31 Jul 2023 14:02:12 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B46711718 for ; Mon, 31 Jul 2023 11:02:05 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-40c72caec5cso31691cf.0 for ; Mon, 31 Jul 2023 11:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690826525; x=1691431325; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=X0gCxxFfGpH7+EO1EgURYZAY2bdhrbnISyF1lBRoK6A=; b=qZXJd0+ffo+L4HQlrADJFOpNsrtneEkEjKGaCenKWHHQEco9dlSNxersD+gpofApiW o02MZh+LdJtBnpNbTaunNFo/yrUZVDlYroTi00ctwRDARSeVylQBSOGLLV6g3BPsFik1 4KZESg4WwqRH2heMDI/gKOTA96YxqAHdeR6cwsxRS352/fhcTvniO25FMpqKBC+vkbG+ 7U3kQrA7UwBFicH5pD7tews8lYXa8aG2Rtx/WHVJ50zWYGSnD/DEpHGm5+dNWqrCjKzK vrB7i6HMlTdlHH7oSEErO/ezx1jdtNdTdwaGk/ao8HCv4z3XUdYfTfahIP4mt6yralea cWuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690826525; x=1691431325; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X0gCxxFfGpH7+EO1EgURYZAY2bdhrbnISyF1lBRoK6A=; b=AEZFup83YU6n3gE9kuOtcOmOYjZXG+XXKOCTYtfp6UUKfz1gG2SrMF2Ni2pXENc1n9 VmLRBGM2Q5+S3B+bUbiLtwvwJXYPFMUXh2JY7UDI2QLS2qUQC044jd9Lrzh8L+xIvKyO jI9UpDsd9dk8Ud1/80EJIqD6liuX5qTMxPX6k3AYmeiBLhNR6P7DfP3PJcdGYkioqosn ZlRRr75BkiA9dfSFWzeSTLfoR4HofTyaKCGMBnlZJX40hdf01qa0aIl6uhruBkwh/Xb1 iR2CZnKdYU4ukbVm0f4Tujgr32yLGK2lbbrjBACMhFTaPnl17wsShDbMt0RkXqXWc3b4 1XAw== X-Gm-Message-State: ABy/qLYk0lxY49qK3ZQ9hvTuFWD3iPfYVuNKEYlrSePewFmv8GsEcXiA RCKRKTO9JsMQZ4iX95hWC1HiKTZHTSSuc//nWFtVnA== X-Received: by 2002:a05:622a:104d:b0:403:9572:e37f with SMTP id f13-20020a05622a104d00b004039572e37fmr425212qte.22.1690826524611; Mon, 31 Jul 2023 11:02:04 -0700 (PDT) MIME-Version: 1.0 References: <20230722022251.3446223-1-rananta@google.com> <20230722022251.3446223-9-rananta@google.com> <87o7jxr06t.wl-maz@kernel.org> <87lef1qzim.wl-maz@kernel.org> In-Reply-To: <87lef1qzim.wl-maz@kernel.org> From: Raghavendra Rao Ananta Date: Mon, 31 Jul 2023 11:01:53 -0700 Message-ID: Subject: Re: [PATCH v7 08/12] KVM: arm64: Define kvm_tlb_flush_vmid_range() To: Marc Zyngier Cc: Oliver Upton , James Morse , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Huacai Chen , Zenghui Yu , Anup Patel , Atish Patra , Jing Zhang , Reiji Watanabe , Colton Lewis , 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 , Shaoqin Huang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Thu, Jul 27, 2023 at 6:01=E2=80=AFAM Marc Zyngier wrote= : > > On Thu, 27 Jul 2023 13:47:06 +0100, > Marc Zyngier wrote: > > > > On Sat, 22 Jul 2023 03:22:47 +0100, > > Raghavendra Rao Ananta wrote: > > > > > > 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/includ= e/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_pro= t(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 entr= ies > > > + * > > > + * @mmu: Stage-2 KVM MMU struct > > > + * @addr: The base Intermediate physical address from which to inva= lidate > > > + * @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/pgtabl= e.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 *p= gt) > > > 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 =3D size >> PAGE_SHIFT; > > > + while (pages > 0) { > > > + inval_pages =3D min(pages, MAX_TLBI_RANGE_PAGES); > > > + kvm_call_hyp(__kvm_tlb_flush_vmid_range, mmu, addr, inval= _pages); > > > + > > > + addr +=3D inval_pages << PAGE_SHIFT; > > > + pages -=3D inval_pages; > > > + } > > > +} > > > + > > > > This really shouldn't live in pgtable.c. This code gets linked into > > the EL2 object. What do you think happens if, for some reason, this > > gets called *from EL2*? > > Ah, actually, nothing too bad would happen, as we convert the > kvm_call_hyp() into a function call. > > But still, we don't need two copies of this stuff, and it can live in > mmu.c. > But since we have a couple of references in pgtable.c to kvm_tlb_flush_vmid_range(), wouldn't that be an (linking) issue if we moved the definition to mmu.c? ld: error: undefined symbol: __kvm_nvhe_kvm_tlb_flush_vmid_range >>> referenced by pgtable.c:1148 (./arch/arm64/kvm/hyp/nvhe/../pgtable.c:11= 48) >>> arch/arm64/kvm/hyp/nvhe/kvm_nvhe.o:(__kvm_nvhe_kvm_pgtabl= e_stage2_unmap) in archive vmlinux.a ... Or is there some other way to make it work? - Raghavendra > M. > > -- > Without deviation from the norm, progress is not possible.