Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4803567rwb; Mon, 31 Jul 2023 12:28:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlGg6Mp6S+6l7O7Kf47absnoXyFDNW6rwQHEnfF6zn8TA+RSx+cWMeD6cw42rc+PE7SGNEnC X-Received: by 2002:a17:903:247:b0:1b8:4ec2:5200 with SMTP id j7-20020a170903024700b001b84ec25200mr12253675plh.2.1690831688237; Mon, 31 Jul 2023 12:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690831688; cv=none; d=google.com; s=arc-20160816; b=O07yc6M5LI9Nw8erVuzJaLpCcmuCSrcEMVvnkgP9opKfi6z0+IrBEedVoIff8FkHwQ C0AJ1Md75BYxtxDZIbddyHDiwZNS30rAzH9Xie/X3mBrGMcweq84JI/YPA9AKP4YNu7X /KaRC33Y5JtHAJe6cvSNePK+vvfPLVjpR5rG6KfUyF7SG6Y9gAK1JLxsXw1doRLb/Cwp WLw4z7pvqzSvkx0E+rSFMOXawFVxLjQ7rk6r/Z5uIANe635s8/MzDAlCXb8cxtzCbx7a tK53fEMneLGcDl0mDD+5AKkhRv0aN5MhxGCJ+zhgrSzrfKaElW7QK83w85z1NnCQEICT xowQ== 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=kGd0AsQAwp8H4S0Hha56MgdpWqYeFbEB+5/aXRn1dMo=; fh=EWwzkLN2YCikT78a5UUiLbTMLBntLTWPfojUhVVs5Bg=; b=CoRD/SR9gLh8prTRi7Iulf4sHDkKtU5gHkYBiChlZ49Ket3Mb4C3wvbpZJVzuBf34Q keJQj6AUzFdc8+8XBR9eLgqckxL6EIF47G9xWhuqFyprVI5Fl/f1vxjHzlD8ppvS1SdT RXN90lCpP9s+jCWIoe/5CIn+j48IQ0/RQemYZse1QVrGCn061Sj1M27ie0wfvZLSD3zp t0+q9f+aZQjfwS4nvXP7kpyKuujCv601bhgHdBEflqlvZcfzMUKtP35DbDKirOAyJ6kw 5kPIiWtvm92R5/JPdyZZv61YCdPAKmx0DLX8P4SJsyCpvdzUkF1VELZOIHKZ7y2+Dkor 4tlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="zhNx/6wz"; 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 n15-20020a170903110f00b001b886d36bf6si7841904plh.226.2023.07.31.12.27.54; Mon, 31 Jul 2023 12:28:08 -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="zhNx/6wz"; 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 S229681AbjGaRpQ (ORCPT + 99 others); Mon, 31 Jul 2023 13:45:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbjGaRpO (ORCPT ); Mon, 31 Jul 2023 13:45:14 -0400 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E26A10B for ; Mon, 31 Jul 2023 10:45:13 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-3460770afe2so7135ab.1 for ; Mon, 31 Jul 2023 10:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690825512; x=1691430312; 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=kGd0AsQAwp8H4S0Hha56MgdpWqYeFbEB+5/aXRn1dMo=; b=zhNx/6wzQh/59YeSRE6Zk4KX3oq74BFHs4UtLBkzn2jdHIAdFgvHuAar0N7QSKQ9f5 gjQxMlF+fLNY+ZUISpJHI0elU+cLIdQf9GgISZnsqfCf83nff+p8ZoI4qwMxlGSHmRGS H9vLbyX49OVEAIxHJDj0yWOJiTKWw62piWzCVMyGtpsQzzwSHz6vu5Y5Kd4s7w/bM6ad yxqnXQ65tId6WoxniRpfQrscD+4ZkZbKquP8FbIAUUvtEeAJhDc8s8hf77qxAQblxC6d MGM+hARijf69iuafH7E2VxwLQh8Zk2A1wLG/KqMNKUk0JsY95RdIIY1aKBg+ToecJziV ljcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690825512; x=1691430312; 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=kGd0AsQAwp8H4S0Hha56MgdpWqYeFbEB+5/aXRn1dMo=; b=QaDTcy/R9MMdJ7wQTFh/cTAak1zJ6GZbmUpf21rt026GwSkZt8POSVClfk5C1CMKKp 08VeUj3Ot72GoU3RXnvhRFnQy9I21C8m++3W6kg2hEzRZYHBZC018l8hCidiVsNUCHFd J+ip1jic0zlIos72bFvtJSRH9IP6y0pswBnm9pNNjGanfjMdldUYiKQ/alq+szOJ5E5U jh0Zj8jF8VmZmwYXksYoJixuoaGLN06qlc7tn3FmsJ5IktRFDKKqC2bsrkfnuWYsdMBG C6l+6lUZ8AKl+LDenZ7iMs37i05hRk7bdjK6ha3wsKviu6WYgYV6W1UhLeklFR5Wzh1z lmHA== X-Gm-Message-State: ABy/qLYb0dPRhS6AxlrsuHNUFqNvI60UhHySy0y/1kooNK11NYrgdUkB nE+Pb25CzFxe8wSWllaehL/llA91Kj2k17tGURz3Xw== X-Received: by 2002:a05:6e02:1d8e:b0:345:fd14:c32e with SMTP id h14-20020a056e021d8e00b00345fd14c32emr460245ila.25.1690825512355; Mon, 31 Jul 2023 10:45:12 -0700 (PDT) MIME-Version: 1.0 References: <20230722022251.3446223-1-rananta@google.com> <20230722022251.3446223-8-rananta@google.com> <87pm4dr0hd.wl-maz@kernel.org> In-Reply-To: <87pm4dr0hd.wl-maz@kernel.org> From: Raghavendra Rao Ananta Date: Mon, 31 Jul 2023 10:45:01 -0700 Message-ID: Subject: Re: [PATCH v7 07/12] KVM: arm64: Implement __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 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=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 On Thu, Jul 27, 2023 at 5:40=E2=80=AFAM Marc Zyngier wrote= : > > On Sat, 22 Jul 2023 03:22:46 +0100, > Raghavendra Rao Ananta wrote: > > > > Define __kvm_tlb_flush_vmid_range() (for VHE and nVHE) > > to flush a range of stage-2 page-tables using IPA in one go. > > If the system supports FEAT_TLBIRANGE, the following patches > > would conviniently replace global TLBI such as vmalls12e1is > > in the map, unmap, and dirty-logging paths with ripas2e1is > > instead. > > > > Signed-off-by: Raghavendra Rao Ananta > > Reviewed-by: Gavin Shan > > --- > > arch/arm64/include/asm/kvm_asm.h | 3 +++ > > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 11 +++++++++++ > > arch/arm64/kvm/hyp/nvhe/tlb.c | 30 ++++++++++++++++++++++++++++++ > > arch/arm64/kvm/hyp/vhe/tlb.c | 27 +++++++++++++++++++++++++++ > > 4 files changed, 71 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/= kvm_asm.h > > index 7d170aaa2db4..2c27cb8cf442 100644 > > --- a/arch/arm64/include/asm/kvm_asm.h > > +++ b/arch/arm64/include/asm/kvm_asm.h > > @@ -70,6 +70,7 @@ enum __kvm_host_smccc_func { > > __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_ipa, > > __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_ipa_nsh, > > __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid, > > + __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_range, > > __KVM_HOST_SMCCC_FUNC___kvm_flush_cpu_context, > > __KVM_HOST_SMCCC_FUNC___kvm_timer_set_cntvoff, > > __KVM_HOST_SMCCC_FUNC___vgic_v3_read_vmcr, > > @@ -229,6 +230,8 @@ extern void __kvm_tlb_flush_vmid_ipa(struct kvm_s2_= mmu *mmu, phys_addr_t ipa, > > extern void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mmu *mmu, > > phys_addr_t ipa, > > int level); > > +extern void __kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu, > > + phys_addr_t start, unsigned long = pages); > > extern void __kvm_tlb_flush_vmid(struct kvm_s2_mmu *mmu); > > > > extern void __kvm_timer_set_cntvoff(u64 cntvoff); > > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nv= he/hyp-main.c > > index a169c619db60..857d9bc04fd4 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c > > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c > > @@ -135,6 +135,16 @@ static void handle___kvm_tlb_flush_vmid_ipa_nsh(st= ruct kvm_cpu_context *host_ctx > > __kvm_tlb_flush_vmid_ipa_nsh(kern_hyp_va(mmu), ipa, level); > > } > > > > +static void > > +handle___kvm_tlb_flush_vmid_range(struct kvm_cpu_context *host_ctxt) > > +{ > > + DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1); > > + DECLARE_REG(phys_addr_t, start, host_ctxt, 2); > > + DECLARE_REG(unsigned long, pages, host_ctxt, 3); > > + > > + __kvm_tlb_flush_vmid_range(kern_hyp_va(mmu), start, pages); > > +} > > + > > static void handle___kvm_tlb_flush_vmid(struct kvm_cpu_context *host_c= txt) > > { > > DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1); > > @@ -327,6 +337,7 @@ static const hcall_t host_hcall[] =3D { > > HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa), > > HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa_nsh), > > HANDLE_FUNC(__kvm_tlb_flush_vmid), > > + HANDLE_FUNC(__kvm_tlb_flush_vmid_range), > > HANDLE_FUNC(__kvm_flush_cpu_context), > > HANDLE_FUNC(__kvm_timer_set_cntvoff), > > HANDLE_FUNC(__vgic_v3_read_vmcr), > > diff --git a/arch/arm64/kvm/hyp/nvhe/tlb.c b/arch/arm64/kvm/hyp/nvhe/tl= b.c > > index b9991bbd8e3f..09347111c2cd 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/tlb.c > > +++ b/arch/arm64/kvm/hyp/nvhe/tlb.c > > @@ -182,6 +182,36 @@ void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mm= u *mmu, > > __tlb_switch_to_host(&cxt); > > } > > > > +void __kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu, > > + phys_addr_t start, unsigned long pages) > > +{ > > + struct tlb_inv_context cxt; > > + unsigned long stride; > > + > > + /* > > + * Since the range of addresses may not be mapped at > > + * the same level, assume the worst case as PAGE_SIZE > > + */ > > + stride =3D PAGE_SIZE; > > + start =3D round_down(start, stride); > > + > > + /* Switch to requested VMID */ > > + __tlb_switch_to_guest(mmu, &cxt, false); > > + > > + __flush_tlb_range_op(ipas2e1is, start, pages, stride, 0, 0, false= ); > > I really think we need an abstraction here. All this ASID and user > nonsense shouldn't appear here. Something such as > __flush_s2_tlb_range_op(), which would pass the correct parameters > that this code shouldn't have to worry about. > Yes, a simple wrapper would be nice. I'll implement this in v8. > I'm also a bit concerned by the fact we completely lose the level > here. This is a massive fast-path for the CPU, and we don't make use > of it. It'd be worth thinking of how we can make use of it if at all > possible... > Initial implementation of the series included the 'level', but had some complexities [1], and so we had to get rid of it for things to at least be correct. But, we can think about it and include the 'level' as needed. - Raghavendra [1]: https://lore.kernel.org/all/ZCTjirkCgBkT65eP@linux.dev/ > > + > > + dsb(ish); > > + __tlbi(vmalle1is); > > + dsb(ish); > > + isb(); > > + > > + /* See the comment in __kvm_tlb_flush_vmid_ipa() */ > > + if (icache_is_vpipt()) > > + icache_inval_all_pou(); > > + > > + __tlb_switch_to_host(&cxt); > > Another thing is that it is high time that some of this call gets > refactored. All these helpers are basically the same sequence, only > differing by a couple of lines. Not something we need to do > immediately, but eventually we'll have to bite the bullet. > > M. > > -- > Without deviation from the norm, progress is not possible.