Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1559519rwo; Wed, 2 Aug 2023 16:46:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlH4wx+ykyhF4C5g9U/BO6eQVPodGrrEYtoS/IDPU2lyQhcph8faY771nbJxbueSGZ/Te6HE X-Received: by 2002:aa7:cd74:0:b0:521:9d92:5863 with SMTP id ca20-20020aa7cd74000000b005219d925863mr4981972edb.42.1691020004070; Wed, 02 Aug 2023 16:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691020004; cv=none; d=google.com; s=arc-20160816; b=ZU1fHDdldh0MZbNvtMHLXQtUOg/kmsG8kFFYX1qm7k1Um3BPA8KCDxQfk4Ycu9NFvZ K8unV7fhyyr85BDzuBUMgmGJugbW4u6IHt9BND/kVADdSPtVLaDcQTnqyzlqrBOUX+ou zovZJNFPSpivJZKqI8Pe5JNQBje0eOv95e+6sxb0pKbFgAITrwzhIKyhKaSInU5wXfkH Zaqb6EFI0gRIHbBauhWyKo403d3kintziqWMeTB/dpJ/nMmYiTEd/lL+mTq1/ua4PEsG ohvld7CykPK8aF8E3oaqZsG8+A4aq3vS1yfj98EAUdtQfQ73FkLRCjM+4ge7Nroyl2ze kZOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=0z3oUtofUC9G3ZrOPpetV5DJjlGuP+Y8ggW9gvUVKbs=; fh=OcemPTDAL5Bi7V6B11JB5Z4EzIBo5fZZLy7iVlrQXxk=; b=CIWBMjyMJyxTTtvavCCNdUbX4np/cePZ6YbZBuycAtKsqsIQ4MIIOY1aDuVkKEFbaC QSjaFEM/IqyE5XZWC+oMRG/7/ThnxS0rcMk7Dsl1bTQt2CrQ7jUuYMI3gp0qDf7QuOZb kJZIbcLAAG2m44ng7JsKGbaE/94W1UEb+N22OFbOtW7DvQiEq72UEpIbHYlA/EgaW5GV 4WpQmJer/6kBogjdJJgvDUe/fkblaqQTq7oQFwc2u0gahzjdZoKYu1xubGwP6/GrWbVt BLbkC7f6FxVMHjR+Ksf2KChE+rQtXBYuMEnAbLiBcUu9B1N8SlZMgUAQvYXbHi61335l Pevg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vKnBfzTb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u4-20020aa7d0c4000000b005223a219e26si11586890edo.191.2023.08.02.16.46.20; Wed, 02 Aug 2023 16:46: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=@kernel.org header.s=k20201202 header.b=vKnBfzTb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232148AbjHBXZm (ORCPT + 99 others); Wed, 2 Aug 2023 19:25:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbjHBXZk (ORCPT ); Wed, 2 Aug 2023 19:25:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3705BD9; Wed, 2 Aug 2023 16:25:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ADD5861B7D; Wed, 2 Aug 2023 23:25:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 053E6C433C8; Wed, 2 Aug 2023 23:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691018738; bh=Zx3cU1AZGQaxXPGcCJrj5p1vHuj6co3/D60PUthhRSM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=vKnBfzTb81DgZpoziNV0oB22VyDwO1WFiZhXntDBeusTiG8UdC5Z2OBiQnbAP1ShY qcuVlWga2yTSL9HcGToI/faLHDLtyqdkcwgrnVTv0MeEqPqiEBtXPKl6+Eukjy7qty c9qlVnmi43y4FVC5mIhwmWAGEPylLQWbxx21TFKR2ZfzElIbR5PnIVSf3qFhbGyqlN JZ2zTwgl97buvmko9yGDiH2GvZFPoFmBLQ6Senku43wvuASp8IQU/sNScOMUfc75dv QbQjPqFkxNRUe4FslUdhHpAR2Qr2cVW0rUL2ZigJTMP5rHkKx6JfytnjvMFSE6X3gc GjBlx97VwG1XQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qRLDj-001Vp2-FV; Thu, 03 Aug 2023 00:25:35 +0100 Date: Thu, 03 Aug 2023 00:25:35 +0100 Message-ID: <86h6ph58nk.wl-maz@kernel.org> From: Marc Zyngier To: Raghavendra Rao Ananta 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 Subject: Re: [PATCH v7 08/12] KVM: arm64: Define kvm_tlb_flush_vmid_range() In-Reply-To: References: <20230722022251.3446223-1-rananta@google.com> <20230722022251.3446223-9-rananta@google.com> <87o7jxr06t.wl-maz@kernel.org> <87lef1qzim.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: rananta@google.com, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, pbonzini@redhat.com, seanjc@google.com, chenhuacai@kernel.org, yuzenghui@huawei.com, anup@brainfault.org, atishp@atishpatra.org, jingzhangos@google.com, reijiw@google.com, coltonlewis@google.com, dmatlack@google.com, 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, gshan@redhat.com, shahuang@redhat.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Mon, 31 Jul 2023 19:01:53 +0100, Raghavendra Rao Ananta wrote: >=20 > On Thu, Jul 27, 2023 at 6:01=E2=80=AFAM Marc Zyngier wro= te: > > > > 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/incl= ude/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_p= rot(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 en= tries > > > > + * > > > > + * @mmu: Stage-2 KVM MMU struct > > > > + * @addr: The base Intermediate physical address from which to in= validate > > > > + * @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/pgta= ble.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 =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, inv= al_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? >=20 > ld: error: undefined symbol: __kvm_nvhe_kvm_tlb_flush_vmid_range > >>> referenced by pgtable.c:1148 (./arch/arm64/kvm/hyp/nvhe/../pgtable.c:= 1148) > >>> arch/arm64/kvm/hyp/nvhe/kvm_nvhe.o:(__kvm_nvhe_kvm_pgta= ble_stage2_unmap) in archive vmlinux.a > ... Ah crap, I missed that. What a mess. Forget it then. It really is a shame that all the neat separation between mmu.c and pgtable.c that we were aiming for is ultimately lost. M. --=20 Without deviation from the norm, progress is not possible.