Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2914930rwo; Mon, 24 Jul 2023 03:28:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHu2Gzg4uI9NAbc5IfHYiEDNdRJ9iSxKBjDx88+yuHxf9GcDwparGKb86Fd31pmKfPdMCAu X-Received: by 2002:a50:ee8d:0:b0:51d:f7b2:e95b with SMTP id f13-20020a50ee8d000000b0051df7b2e95bmr8803234edr.34.1690194509543; Mon, 24 Jul 2023 03:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690194509; cv=none; d=google.com; s=arc-20160816; b=CFc+isfDibxIH3twIFBsmDE5GjCtvtFmH8PLFgaWoNTZNCOxazg331ZL0XzfFDOkLQ kGY3fhRB5k8t/Nf96xXt1BWqu7gHPwRXXh3dHjyxCtNAUybGl0sIRMRanb4rQoLVbrFF 5g8r3dvY8EkhkDzf8IsddQc//fE8PBYQqBgUOjovBVmwEYH/S4Vzf2tFZIonWdqsz19/ Z+QT3xGz9NGuKM9CYRiGrJ9YqJ7qK0rpSrzKhZKivwIkQFzXYLw4zHlDb33cEFTNP2Z/ lQANTuy5WqLaZ2I7dCb0JM/czAwymMQfuEuD67XXZ8XZV64x7MocxM+C7qFbue4jN6TJ tpIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ijXK5mx/mHT57SLCIb40VpMSvRABTcruzVYNxBiTMvo=; fh=gm/wB+lOOzZww3HmgaIqMcdrLti4woZm/XihfEcQns8=; b=SnIUn2ApSfkVW8qApCddsud6Tnrtr4QW2A+bj1xwT9lUM8heRZyoLpHNLUc3AukzFF dXAN74ofwe1RtGX75BWsRaUUiVuNIUKqvq1vP9pZwUxRTtUZPOK8hUh4zs1ATxWIUXBJ 0MxMRYLKt8uqZEY7N9E1rZHbpRwgdpIIhJCqFKL3diQQHGCD61B0lg6r+XlxNk41a9Kl rBJ6qaf140ExqCsmjf+Iay+mdajgulF/7c8/6WSlb6w12aIXjFwHyoaTz87LF0/p83Bo gUw5wEt4C9/qV6ao5jiyzWVeNmUarhqzjliOGv9d8tBnmCwwVm6GxkAE/KMUqcBjoO2e GwEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="PnCPT/QS"; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020aa7d447000000b00521dd32056csi6109685edr.487.2023.07.24.03.28.05; Mon, 24 Jul 2023 03:28:29 -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=@redhat.com header.s=mimecast20190719 header.b="PnCPT/QS"; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232033AbjGXJW2 (ORCPT + 99 others); Mon, 24 Jul 2023 05:22:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230225AbjGXJW0 (ORCPT ); Mon, 24 Jul 2023 05:22:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE954133 for ; Mon, 24 Jul 2023 02:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690190503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ijXK5mx/mHT57SLCIb40VpMSvRABTcruzVYNxBiTMvo=; b=PnCPT/QSuHfGQQiO8obUoFTHlK3/o3+eICUySW+UHFafFTx0hgOaO//VAUDeumtt19WNU3 5r9GcaCMyF9IJPAZG4wAV2hX/kHmujyPxDBMRPMG3jq9Jre+wbLbnUTnHu5EjcKRjMXOrc lL0Tv9wYBEUUAGrYIG1kqRno7adBhzM= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-90-EdYVnII9P4Op_50fA5AvRg-1; Mon, 24 Jul 2023 05:21:41 -0400 X-MC-Unique: EdYVnII9P4Op_50fA5AvRg-1 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-1b88d18c2c6so4237415ad.0 for ; Mon, 24 Jul 2023 02:21:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690190500; x=1690795300; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ijXK5mx/mHT57SLCIb40VpMSvRABTcruzVYNxBiTMvo=; b=gTcqa/bX6NLZzGrByP88JQ+48k0xKtZKApOzwFVKRzAr7BP6uuCQPOEXO+BNQSJw/r DNkDcsJRKM3CAfIEWa+t0ypYcuf3iEoU0BPAkNH/dzhI6q28jYP5Tnq51RGHxyArIvKk WYkROtn+N3oEzGbdRogkcPk/ku2Xjkd9sqaU0MS88hmYQuNJ3zIPal6org4VqFnjMBaT 1SRV97bsl8K8I04uXbVaJhZlPWUen1xCBJOqnCi7yb9EcZWnLo/erT9u/xxAZEYBimqk C//fcj7DFUQMEhECzF+33iQfC8qypIKDgCuJ34RMG6rYV2VCC9DMlB6QCVwsZsUmI4Db Nk5Q== X-Gm-Message-State: ABy/qLZgR4yOE0EwoxRBzbFT9Vp/8upJNI/aeBeoJDpVGVb12u1dKUKO EHf1xGAp6/2jvEnEe+hOdctPE11WVAjxam1rtl9y7u2+TFlJogSxJ2Aq4K41Qj5ZuBYTzOPok3h uw8YAYHxeuEsjnppznT26RLMz X-Received: by 2002:a17:903:24f:b0:1b8:ac61:ffcd with SMTP id j15-20020a170903024f00b001b8ac61ffcdmr12283766plh.3.1690190500639; Mon, 24 Jul 2023 02:21:40 -0700 (PDT) X-Received: by 2002:a17:903:24f:b0:1b8:ac61:ffcd with SMTP id j15-20020a170903024f00b001b8ac61ffcdmr12283739plh.3.1690190500295; Mon, 24 Jul 2023 02:21:40 -0700 (PDT) Received: from [10.66.61.39] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id n10-20020a170902e54a00b001bb34ae3f47sm8365727plf.122.2023.07.24.02.21.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Jul 2023 02:21:39 -0700 (PDT) Message-ID: <86b36980-0a3b-7f56-44b4-079e8058021e@redhat.com> Date: Mon, 24 Jul 2023 17:21:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v7 07/12] KVM: arm64: Implement __kvm_tlb_flush_vmid_range() Content-Language: en-US To: Raghavendra Rao Ananta , 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 , 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 References: <20230722022251.3446223-1-rananta@google.com> <20230722022251.3446223-8-rananta@google.com> From: Shaoqin Huang In-Reply-To: <20230722022251.3446223-8-rananta@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,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 7/22/23 10:22, 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 Reviewed-by: Shaoqin Huang > --- > 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/nvhe/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(struct 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_ctxt) > { > DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1); > @@ -327,6 +337,7 @@ static const hcall_t host_hcall[] = { > 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/tlb.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_mmu *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 = PAGE_SIZE; > + start = 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); > + > + 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); > +} > + > void __kvm_tlb_flush_vmid(struct kvm_s2_mmu *mmu) > { > struct tlb_inv_context cxt; > diff --git a/arch/arm64/kvm/hyp/vhe/tlb.c b/arch/arm64/kvm/hyp/vhe/tlb.c > index e69da550cdc5..02f4ed2fd715 100644 > --- a/arch/arm64/kvm/hyp/vhe/tlb.c > +++ b/arch/arm64/kvm/hyp/vhe/tlb.c > @@ -138,6 +138,33 @@ void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mmu *mmu, > dsb(nsh); > __tlbi(vmalle1); > dsb(nsh); > + > + __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 = PAGE_SIZE; > + start = round_down(start, stride); > + > + dsb(ishst); > + > + /* Switch to requested VMID */ > + __tlb_switch_to_guest(mmu, &cxt); > + > + __flush_tlb_range_op(ipas2e1is, start, pages, stride, 0, 0, false); > + > + dsb(ish); > + __tlbi(vmalle1is); > + dsb(ish); > isb(); > > __tlb_switch_to_host(&cxt); -- Shaoqin