Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp778071rdg; Thu, 10 Aug 2023 21:52:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGADABv1lIjIW+acrIOtM2TI/Hgave4ZVAllwReRKBuoSgjPpJGlPoP8C6XPO9jThDO3kL+ X-Received: by 2002:a17:902:cec7:b0:1bc:671d:6d2d with SMTP id d7-20020a170902cec700b001bc671d6d2dmr5608957plg.21.1691729530667; Thu, 10 Aug 2023 21:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691729530; cv=none; d=google.com; s=arc-20160816; b=U18EZ9E7+YSdSuYYGLmt1nLzz3vw4z1Rt2G3d806EBZnUk6YNNb2HG3s6J9vcmk8wg trUhiFmUyqe8fT1yc4wR5zgr88nf/YpFZQmcNrbId+d8zSy9h286LmlsrajT4k/BgiSb JFz5kQ2sEU6RrMbYbjHPC6CDimDsrzuFpKC2WVRZ2zdeNUtDreXgZWByqC8YxelN84Z/ 6XvQ08MMS3W/OkxCt/aU/iXWslL5WypO/3vfO9p/IsvWKOu2PwRrksLqAdSvg8fquB9g WFVsZhuYlnorUu2SQSzBYVHh7zllZktW8S4iUajMPujrMsBvwkYsfo51W2M6T0q8qNde L6iQ== 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=CuhtWJgSKcM9nbJJ30I78GHH5pQTfbRo2u019oEL2nM=; fh=ad6vJxgYdmjp1AX3pzh0EYxiKdG1YEK6uyZENE8XtG8=; b=Ztc3f+4JzCCGdyKDjMGvdVdNn/ZS2Uuc9kfV57LPKw7fZe6jJRxF2hBNl+RXV0ywnV 93BrA4g0gHatpNNdX5/SyRBYIEzq9WV7QxlyhtNK/CvqGJP0AT10CnVNl91qBkaAQNgs aQCOaogRA0n6Gh6VKgBs/S904p+iSSRdFPUg0038fN9wDtSgP6i6x+5u69/MdCdOZjT7 l0qoMM8hJwMz6Q/XU1BzkXC9PZY3Mksgr5rI5+/6jGoGC+nw06cnAthdTgr550PKweEx Hupb1i6D03RkdAs89PZKntKLtLHefNaH2YywvRFWnBz/e5MCnhKAtPPZMgbsA3iRYHji EAHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WVvBT0F2; 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 ja11-20020a170902efcb00b001b3414a1fa9si2676514plb.175.2023.08.10.21.51.58; Thu, 10 Aug 2023 21:52:10 -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=WVvBT0F2; 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 S232994AbjHKDQW (ORCPT + 99 others); Thu, 10 Aug 2023 23:16:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232953AbjHKDQG (ORCPT ); Thu, 10 Aug 2023 23:16:06 -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 E5A702D68 for ; Thu, 10 Aug 2023 20:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691723718; 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=CuhtWJgSKcM9nbJJ30I78GHH5pQTfbRo2u019oEL2nM=; b=WVvBT0F2cuIIPzrD4CNSlajgZmaXiLdFUkwCoC1RHLJh0lj6HDU/64t0H0/Gj/8iCc7AI8 KvPf/G2AxGuU7INSFZ3lEIjRwNYQVzg0V/MRgHjBh+7S4qfTSE26Wyq1IongLkygyxLpx2 rP7CmjICk31nHz7xEwdXV3dw1q2GEBU= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-X7Nnh5kmOoC8Q1f4hTjJtA-1; Thu, 10 Aug 2023 23:15:16 -0400 X-MC-Unique: X7Nnh5kmOoC8Q1f4hTjJtA-1 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-26953535169so409363a91.0 for ; Thu, 10 Aug 2023 20:15:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691723716; x=1692328516; 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=CuhtWJgSKcM9nbJJ30I78GHH5pQTfbRo2u019oEL2nM=; b=WYZfNPV6E/bhNvV46Rkq+GnHX37MvvhLq2wEMhYyb7i9c5X3AIILW8AVNu/2rQR4Dv 7b8N2GdFxqPfkJJbAwoBQURo/EB9vIxywBQ5uNXQDyw9ePbDidD8DQhV0YxlBCKpH6Oo I1uLOFxjznclEYdoR+rYVwCDogAYMOsGJzZjKymkXywFoq2FC/1fy1evjhIYnb054jKc 37efYXj4k8Wsx501Mz8WOY5I8Ly6HBnvYCtx7YRS1dkggQ0pdlB1FwETeSCnM5Nhf1Tq uepBgRsI3+TTbdfBBXHQII86kJqt/fX+L4QVQxFRAjpi2aS61Cbjgf0V8WZoJgvihpWz ozBQ== X-Gm-Message-State: AOJu0YwkvjTxGxkbtmDNWC/8bGkGsCyeQkdCvS5xkzUH4p/B3vS1mYVY IlNtXO5XxxNKcqG4cpcu8KY+6dJUslzfW+IvwhhP5xWDV0nfVOT4rVpeNr9Ilm62+bfhGjyGLW8 DWdUdQmeWVg0FPGOGHcQL4Hmh X-Received: by 2002:a17:90a:2a05:b0:269:34a6:d4ca with SMTP id i5-20020a17090a2a0500b0026934a6d4camr484329pjd.0.1691723715679; Thu, 10 Aug 2023 20:15:15 -0700 (PDT) X-Received: by 2002:a17:90a:2a05:b0:269:34a6:d4ca with SMTP id i5-20020a17090a2a0500b0026934a6d4camr484298pjd.0.1691723715388; Thu, 10 Aug 2023 20:15:15 -0700 (PDT) Received: from [10.72.112.92] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id ms16-20020a17090b235000b0026b12768e46sm1811306pjb.42.2023.08.10.20.15.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Aug 2023 20:15:15 -0700 (PDT) Message-ID: Date: Fri, 11 Aug 2023 11:15:07 +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 v8 09/14] 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 , 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 References: <20230808231330.3855936-1-rananta@google.com> <20230808231330.3855936-10-rananta@google.com> From: Shaoqin Huang In-Reply-To: <20230808231330.3855936-10-rananta@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 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 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 8/9/23 07:13, 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 | 28 ++++++++++++++++++++++++++++ > 4 files changed, 72 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h > index 7d170aaa2db41..2c27cb8cf442d 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 a169c619db60b..857d9bc04fd48 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 b9991bbd8e3fd..1b265713d6bed 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_s2_tlb_range_op(ipas2e1is, start, pages, stride, 0); > + > + 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 e69da550cdc5b..46bd43f61d76f 100644 > --- a/arch/arm64/kvm/hyp/vhe/tlb.c > +++ b/arch/arm64/kvm/hyp/vhe/tlb.c > @@ -143,6 +143,34 @@ 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); > + > + dsb(ishst); > + > + /* Switch to requested VMID */ > + __tlb_switch_to_guest(mmu, &cxt); > + > + __flush_s2_tlb_range_op(ipas2e1is, start, pages, stride, 0); > + > + dsb(ish); > + __tlbi(vmalle1is); > + dsb(ish); > + isb(); > + > + __tlb_switch_to_host(&cxt); > +} > + > void __kvm_tlb_flush_vmid(struct kvm_s2_mmu *mmu) > { > struct tlb_inv_context cxt; -- Shaoqin