Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7082602rwp; Tue, 18 Jul 2023 09:46:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlH8mauTbgsp9tvi1sePF+4CxG5HzR5EdppzkgYqrKZATmJhr1q179524F9JhzhyoYdfMhrh X-Received: by 2002:a05:6402:2711:b0:521:66b4:13f2 with SMTP id y17-20020a056402271100b0052166b413f2mr311084edd.4.1689698764884; Tue, 18 Jul 2023 09:46:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689698764; cv=none; d=google.com; s=arc-20160816; b=m2H7UfyZb2hKKf/vVw3G8/p/9O8ln+oUen6y0xVFXEvnxf9oMJ5cKKtq8NyAzXo+v7 2exY2U8IJ/pvYwxIBH3wfGfUQjIqaOaABfbO8hW6ZZskGbUWTUAPQhjW/AYDUl3S/qYn ZOXgY/jb+ddMaTg3iCsq+dOaqi2H0sOcBZ4J+M/uvZhZ53E2Zf6+XLleTRG15+CIQk3a O0oB3GLeW2dxDWX2Q6orvdFHNmPGy8bi2NImnsdBQCOwGNxhShNRXOQcDJcUjafTlZVW /vWAyaBk0Yz95odZUDwq8S8kvHLxY/s97uTR4HJbeEFRiLvSRTJbo/JCvgUhFeGsf0eU lTMw== 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=FOUt0ycfIIC4G92ZHk96f3py83XofJ3hc7BWl3IwSXo=; fh=TtUpESWTx+5BxfxmaQgVMW6/KIZ1yDe/Hk4eP6JQQtc=; b=J07Fi5VA3BDOqETGpndp541UnATfP70Lw2AatgZNUpreMidBMpa7qWGay6VQoQvYCU QihOfAEtcS6VRKjCu5DPzScg1Jr3xq1bnfBv2SUoJcXSPBhEgOL4mE/S3wSrBz3HpFTY vD3ERASKyYw/6CCRp94VOhcLYpuAg4SbJYURtNkow3v1Uyg3bAAg2X+TQq8TyO11XZVV zyInSAZO7wOEF2CV3GDAoOYMXQg9QOdyBemquKD4p2DisLD4XTaHgvX7TXVmLYX9iwhc OQ9tP6EL3xobcyMmEkFcJllIPye50KYyJ5QuoVcsKbe5ioY/iAthCY8DDnXplK2R+wOc FtwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=70EYw8mQ; 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 c5-20020aa7df05000000b00514a4541769si1519181edy.81.2023.07.18.09.45.40; Tue, 18 Jul 2023 09:46:04 -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=70EYw8mQ; 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 S232753AbjGRQbh (ORCPT + 99 others); Tue, 18 Jul 2023 12:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231618AbjGRQbf (ORCPT ); Tue, 18 Jul 2023 12:31:35 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60CB510F0 for ; Tue, 18 Jul 2023 09:31:34 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-345bc4a438fso141225ab.1 for ; Tue, 18 Jul 2023 09:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689697893; x=1690302693; 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=FOUt0ycfIIC4G92ZHk96f3py83XofJ3hc7BWl3IwSXo=; b=70EYw8mQUne1cNpTuVS0kMr31zvHYUt7jMEY5WFkQMZBfCcJIiLIETbDzK0JXOJ4Nb o7zLGOeq5Y4Kcl59mMGBHYDHb1N2qivCEsecXmwhGzqyIktQtxxQgfZa0nuVzldc1mYK 1YVDEGGtjV910sPWe+g+ml5wvq3TqGoCYgLeILNgyRlGhe6eJ3lIRsm7QrAHqbIc16iO xXQvaTZ84vTOaqA9NUMCMXvrhEiThuuMWZhAGrbCWnGHX7sDiEk0cnpqvdzZUB4ghQGY QtT89zT9eN26NqxZPsW6fDAu67sawQDnR4GVx8BwBSuTs2HltUcGsgtm53Amj8OI093n dK0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689697893; x=1690302693; 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=FOUt0ycfIIC4G92ZHk96f3py83XofJ3hc7BWl3IwSXo=; b=XNaOVMFcj0H8oNWqkX9vLnEF17hDOdIovxzLvZ8heU8L18QpDyFThQs+Up3MLmlMed FjtF6++Mc7ddPTugZvcrMm3vAvwCZdT0MhNG8kaWtVjBeyvp5ODOSxZDgPRnZydFqd0T cYPnb5vkxbnlGF/pSFhGqlLYR1Z+cCSBr0X8SZvAPldziuEPrq5wxQcYp0trK4mnFumN ukJCkYfTGwcIX4veesGIwwEWPzUBQNInKTyZMzj3tDCo2lMV694NGh8SLU3W+Uic3JbJ si29FBznOkx+haBGxfQsdRpU03mzQXS+q4Cp+qp5rD0DO9SXbKzz8A9fz1NB/a9KlZlX 4KSg== X-Gm-Message-State: ABy/qLbXmvUDjpk7DFho+2weSFThk7hQ7OyvCaGgdEmSuLTCbHVGUa/L +h8EKBAvT+0YT2khLbXqpv8dhw+2Vpq35CKa7bh0YA== X-Received: by 2002:a05:6e02:1a0b:b0:33c:a46c:23b3 with SMTP id s11-20020a056e021a0b00b0033ca46c23b3mr252894ild.1.1689697893605; Tue, 18 Jul 2023 09:31:33 -0700 (PDT) MIME-Version: 1.0 References: <20230715005405.3689586-1-rananta@google.com> <20230715005405.3689586-4-rananta@google.com> <199d18de-1214-7683-b87a-03cc7e49719a@redhat.com> In-Reply-To: From: Raghavendra Rao Ananta Date: Tue, 18 Jul 2023 09:31:20 -0700 Message-ID: Subject: Re: [PATCH v6 03/11] KVM: Allow range-based TLB invalidation from common code To: Shaoqin Huang Cc: Oliver Upton , Marc Zyngier , James Morse , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Huacai Chen , Zenghui Yu , Anup Patel , Atish Patra , Jing Zhang , 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_NONE,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 Hi Shaoqin, On Mon, Jul 17, 2023 at 7:49=E2=80=AFPM Shaoqin Huang = wrote: > > > > On 7/18/23 00:37, Raghavendra Rao Ananta wrote: > > On Mon, Jul 17, 2023 at 4:40=E2=80=AFAM Shaoqin Huang wrote: > >> > >> > >> > >> On 7/15/23 08:53, Raghavendra Rao Ananta wrote: > >>> From: David Matlack > >>> > >>> Make kvm_flush_remote_tlbs_range() visible in common code and create = a > >>> default implementation that just invalidates the whole TLB. > >>> > >>> This paves the way for several future features/cleanups: > >>> > >>> - Introduction of range-based TLBI on ARM. > >>> - Eliminating kvm_arch_flush_remote_tlbs_memslot() > >>> - Moving the KVM/x86 TDP MMU to common code. > >>> > >>> No functional change intended. > >>> > >>> Signed-off-by: David Matlack > >>> Signed-off-by: Raghavendra Rao Ananta > >>> Reviewed-by: Gavin Shan > >>> --- > >>> arch/x86/include/asm/kvm_host.h | 3 +++ > >>> arch/x86/kvm/mmu/mmu.c | 9 ++++----- > >>> arch/x86/kvm/mmu/mmu_internal.h | 3 --- > >>> include/linux/kvm_host.h | 9 +++++++++ > >>> virt/kvm/kvm_main.c | 13 +++++++++++++ > >>> 5 files changed, 29 insertions(+), 8 deletions(-) > >>> > >>> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/k= vm_host.h > >>> index a2d3cfc2eb75..08900afbf2ad 100644 > >>> --- a/arch/x86/include/asm/kvm_host.h > >>> +++ b/arch/x86/include/asm/kvm_host.h > >>> @@ -1804,6 +1804,9 @@ static inline int kvm_arch_flush_remote_tlbs(st= ruct kvm *kvm) > >>> return -ENOTSUPP; > >>> } > >>> > >>> +#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE > >>> +int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gf= n, u64 pages); > >>> + > >>> #define kvm_arch_pmi_in_guest(vcpu) \ > >>> ((vcpu) && (vcpu)->arch.handling_intr_from_guest) > >>> > >>> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > >>> index ec169f5c7dce..aaa5e336703a 100644 > >>> --- a/arch/x86/kvm/mmu/mmu.c > >>> +++ b/arch/x86/kvm/mmu/mmu.c > >>> @@ -278,16 +278,15 @@ static inline bool kvm_available_flush_remote_t= lbs_range(void) > >>> return kvm_x86_ops.flush_remote_tlbs_range; > >>> } > >>> > >>> -void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, > >>> - gfn_t nr_pages) > >>> +int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gf= n, u64 pages) > >>> { > >>> int ret =3D -EOPNOTSUPP; > >>> > >>> if (kvm_x86_ops.flush_remote_tlbs_range) > >>> ret =3D static_call(kvm_x86_flush_remote_tlbs_range)(k= vm, start_gfn, > >>> - nr_p= ages); > >>> - if (ret) > >>> - kvm_flush_remote_tlbs(kvm); > >>> + = pages); > >> This will be good if parameter pages aligned with parameter kvm. > >> > > Agreed, but pulling 'pages' above brings the char count to 83. If > > that's acceptable, I'm happy to do it in v7. > > Hi Raghavendra, > > no need to pulling 'pages' above, just delete one tab, and add some > space before the pages, just like the original `nr_pages` position. > Oh yes, that can be done. Thanks! - Raghavendra > Thanks, > Shaoqin > > Thank you. > > Raghavendra > >> Reviewed-by: Shaoqin Huang > >>> + > >>> + return ret; > >>> } > >>> > >>> static gfn_t kvm_mmu_page_get_gfn(struct kvm_mmu_page *sp, int ind= ex); > >>> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_i= nternal.h > >>> index d39af5639ce9..86cb83bb3480 100644 > >>> --- a/arch/x86/kvm/mmu/mmu_internal.h > >>> +++ b/arch/x86/kvm/mmu/mmu_internal.h > >>> @@ -170,9 +170,6 @@ bool kvm_mmu_slot_gfn_write_protect(struct kvm *k= vm, > >>> struct kvm_memory_slot *slot, u64 = gfn, > >>> int min_level); > >>> > >>> -void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, > >>> - gfn_t nr_pages); > >>> - > >>> /* Flush the given page (huge or not) of guest memory. */ > >>> static inline void kvm_flush_remote_tlbs_gfn(struct kvm *kvm, gfn_= t gfn, int level) > >>> { > >>> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > >>> index e3f968b38ae9..a731967b24ff 100644 > >>> --- a/include/linux/kvm_host.h > >>> +++ b/include/linux/kvm_host.h > >>> @@ -1359,6 +1359,7 @@ int kvm_vcpu_yield_to(struct kvm_vcpu *target); > >>> void kvm_vcpu_on_spin(struct kvm_vcpu *vcpu, bool yield_to_kernel_= mode); > >>> > >>> void kvm_flush_remote_tlbs(struct kvm *kvm); > >>> +void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 pag= es); > >>> > >>> #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > >>> int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, in= t min); > >>> @@ -1486,6 +1487,14 @@ static inline int kvm_arch_flush_remote_tlbs(s= truct kvm *kvm) > >>> } > >>> #endif > >>> > >>> +#ifndef __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE > >>> +static inline int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, > >>> + gfn_t gfn, u64 pages= ) > >>> +{ > >>> + return -EOPNOTSUPP; > >>> +} > >>> +#endif > >>> + > >>> #ifdef __KVM_HAVE_ARCH_NONCOHERENT_DMA > >>> void kvm_arch_register_noncoherent_dma(struct kvm *kvm); > >>> void kvm_arch_unregister_noncoherent_dma(struct kvm *kvm); > >>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > >>> index d6b050786155..804470fccac7 100644 > >>> --- a/virt/kvm/kvm_main.c > >>> +++ b/virt/kvm/kvm_main.c > >>> @@ -366,6 +366,19 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) > >>> } > >>> EXPORT_SYMBOL_GPL(kvm_flush_remote_tlbs); > >>> > >>> +void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 pag= es) > >>> +{ > >>> + if (!kvm_arch_flush_remote_tlbs_range(kvm, gfn, pages)) > >>> + return; > >>> + > >>> + /* > >>> + * Fall back to a flushing entire TLBs if the architecture rang= e-based > >>> + * TLB invalidation is unsupported or can't be performed for wh= atever > >>> + * reason. > >>> + */ > >>> + kvm_flush_remote_tlbs(kvm); > >>> +} > >>> + > >>> static void kvm_flush_shadow_all(struct kvm *kvm) > >>> { > >>> kvm_arch_flush_shadow_all(kvm); > >> > >> -- > >> Shaoqin > >> > > > > -- > Shaoqin >