Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp28035rwl; Wed, 9 Aug 2023 10:22:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAaFAXUiARQaZKcOiFCtJaZMEjMHRie7tSxvrFsKc0npSgY2c9ERgBIyu3RXSz3uww6A+v X-Received: by 2002:a05:6808:213:b0:3a7:4c7f:8b6f with SMTP id l19-20020a056808021300b003a74c7f8b6fmr3331868oie.48.1691601719855; Wed, 09 Aug 2023 10:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691601719; cv=none; d=google.com; s=arc-20160816; b=qOh4zOM58jYey/a2h+gQK/xHXApMtkDkIGmhjtjqEYp/JpeFyfATysrnu990R88Xrj qAkNkFwU42T+wyhyxoavKXFZOU1TVTnvJ4u9INnjBco9A5ya/VAVyOdGQydhWPgKNdzF T6YMYnqo8O7W5jb8zmlnKJHpxqx1UIml13yStN9mgjxn4zRTKeV44xTY1BS/aXd1Xtf2 07/NE6G4/WCtuuxQyrZZIKrn2xuMzO1TefFuIu0lvRPNWrHMyiYG6HOGkpLOGK6+88t+ SsXSwfybD9r5mh5DqXQITgqyC24IMx2cGgVyFCJ+KDedARAVI6KURJPXe2lLuz2dc5et urgA== 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=lPf4XGOX6Yz3caGFLI4HNiFX/4urner6v/ltX/ESS/0=; fh=T44VKHcpax+afpCVFQww35FkfFaSJG33EnpIgkbho5Y=; b=k+GncJoJFceRWHeROo5J3LcKxGWD6EO0vRvRqhBw92DpWQt45457H6yBBUQevk4q/+ UKGTY5yXbzJjcoxa1QYTe2PPYXg+m1ipcXurzPZ5pA1Ge467YpjlmhTwykZKRbRzD/iS ub6YYmtXVi1fxBlPGFIUmkmI41a9wu03/zbG6ApeYTDSBwozhCbt1yfKZrF/MLbv7fPP FlfVUYrKDCFiQp5T13S7mr2L6yUPmdKgkbCDXSQpAY6iE6U2tEdoWgo7i8/umEfZOBc0 AMVLkHq9flYiIMGoCTa7b2pK6p75crWUup94dP20pGCdvTUaXOKgHqkpnVi7qNpy4ff7 6tAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=M8NqHm95; 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 q1-20020a17090a68c100b00262df8f6cf2si1869855pjj.43.2023.08.09.10.21.47; Wed, 09 Aug 2023 10:21:59 -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=M8NqHm95; 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 S230078AbjHIQmA (ORCPT + 99 others); Wed, 9 Aug 2023 12:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbjHIQl6 (ORCPT ); Wed, 9 Aug 2023 12:41:58 -0400 Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB93C1B2 for ; Wed, 9 Aug 2023 09:41:57 -0700 (PDT) Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-40a47e8e38dso309731cf.1 for ; Wed, 09 Aug 2023 09:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691599317; x=1692204117; 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=lPf4XGOX6Yz3caGFLI4HNiFX/4urner6v/ltX/ESS/0=; b=M8NqHm95x4nGnCdrVnscaqRXS4zv1xJk+mKi6qhzpoV0xAgedW8xKK1WrktthW+/qX b79Rjw1HWdoTj0bfrzxyYngD13WhEXYtTDNUTB4Nwp3syn4yn8vOXHVKklDeZcJZpc9o GDICgnZbUUQ4VwPvxkozg6ZrzrsWy820TbFiNBjvXSnVlLga3PusimdxiUHWSrjmgq9M YMKKBcxudeH5NygCy+Ei5czOibqi8SOG3nDIHx+h0cIT0Z9F1Ff0QOjnl3TwU7bKPVG3 fESF+gvCoCtyd47weuYbH5uFlwg9LfCAVKAGmtq8i8np6ERRNhFQ4wt4KpNnlYCunDKT NTyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691599317; x=1692204117; 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=lPf4XGOX6Yz3caGFLI4HNiFX/4urner6v/ltX/ESS/0=; b=BFAEOz/LDV4eGEF+9wXBlitfQu2PtTVqIOTZTRnlZy66yaSJBBCTNEAdUHgA+P6eDd /uix1YWjCvgHtQAjg8Sf5ibPKx3SlY94DmNi6nmvuVwTW1K6eQhNxA8HBeDT2fcNZJYr r5ocN7KgFG6J613M7hQ1ekgpU5MpjPMFZDukbeCFbMNtu9e7huxUbXIBUv2FsSGRvpyz DUBfkY2Te9VK1Zw/S/z8n67Q1+M2nkevn9JhsDqJxAcbfOZJm4dRkxA+2YUhvlrTyvWt VAgIkkNeSWprn9UrZJPmQdBqH6WxSKN9fRE2fawoHZUYCc6Xur1eW0fllhK9Z533aw9o 9c7Q== X-Gm-Message-State: AOJu0YwTlSPGSJCoFqAWvNaNRR+Yl5gaMzvG3E5Pg2rqB9R1dp/a2ogb oyvZzCLBZnt13P5niDQIYrJsTBcUhX8iumm55Ma4dA== X-Received: by 2002:ac8:5dc9:0:b0:3f5:2006:50f1 with SMTP id e9-20020ac85dc9000000b003f5200650f1mr133814qtx.12.1691599316808; Wed, 09 Aug 2023 09:41:56 -0700 (PDT) MIME-Version: 1.0 References: <20230808231330.3855936-1-rananta@google.com> <20230808231330.3855936-6-rananta@google.com> <15975205-6161-d54b-fe40-805a16b0cb27@redhat.com> In-Reply-To: <15975205-6161-d54b-fe40-805a16b0cb27@redhat.com> From: Raghavendra Rao Ananta Date: Wed, 9 Aug 2023 09:41:44 -0700 Message-ID: Subject: Re: [PATCH v8 05/14] KVM: Allow range-based TLB invalidation from common code To: Gavin Shan Cc: Oliver Upton , Marc Zyngier , 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 , 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, Shaoqin Huang 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, 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 On Tue, Aug 8, 2023 at 11:09=E2=80=AFPM Gavin Shan wrote= : > > On 8/9/23 09:13, 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 > > Reviewed-by: Shaoqin Huang > > Reviewed-by: Anup Patel > > --- > > arch/x86/include/asm/kvm_host.h | 2 ++ > > arch/x86/kvm/mmu/mmu.c | 8 ++++---- > > arch/x86/kvm/mmu/mmu_internal.h | 3 --- > > include/linux/kvm_host.h | 12 ++++++++++++ > > virt/kvm/kvm_main.c | 13 +++++++++++++ > > 5 files changed, 31 insertions(+), 7 deletions(-) > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm= _host.h > > index a2d3cfc2eb75c..b547d17c58f63 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1804,6 +1804,8 @@ static inline int kvm_arch_flush_remote_tlbs(stru= ct kvm *kvm) > > return -ENOTSUPP; > > } > > > > +#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE > > + > > #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 ec169f5c7dce2..6adbe6c870982 100644 > > --- a/arch/x86/kvm/mmu/mmu.c > > +++ b/arch/x86/kvm/mmu/mmu.c > > @@ -278,16 +278,16 @@ static inline bool kvm_available_flush_remote_tlb= s_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_gfn, > > + u64 nr_pages) > > { > > int ret =3D -EOPNOTSUPP; > > > > if (kvm_x86_ops.flush_remote_tlbs_range) > > ret =3D static_call(kvm_x86_flush_remote_tlbs_range)(kvm,= start_gfn, > > nr_pag= es); > > - if (ret) > > - kvm_flush_remote_tlbs(kvm); > > + > > + return ret; > > } > > > > I guess @start_gfn can be renamed to @gfn, to be consistent with its decl= aration > in include/linux/kvm_host.h and struct kvm_x86_ops::flush_remote_tlbs_ran= ge() > Oh, yes. I'll consider this change for v9 (if there are enough changes and we plan to push one). Thank you. Raghavendra > > static gfn_t kvm_mmu_page_get_gfn(struct kvm_mmu_page *sp, int index)= ; > > diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_int= ernal.h > > index d39af5639ce97..86cb83bb34804 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 *kvm= , > > 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 g= fn, int level) > > { > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > index ade5d4500c2ce..f0be5d9c37dd1 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_mod= e); > > > > void kvm_flush_remote_tlbs(struct kvm *kvm); > > +void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 nr_pa= ges); > > > > #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > > int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int m= in); > > @@ -1488,6 +1489,17 @@ static inline int kvm_arch_flush_remote_tlbs(str= uct kvm *kvm) > > int kvm_arch_flush_remote_tlbs(struct 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 nr_pag= es) > > +{ > > + return -EOPNOTSUPP; > > +} > > +#else > > +int kvm_arch_flush_remote_tlbs_range(struct kvm *kvm, > > + gfn_t gfn, u64 nr_pages); > > +#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 d6b0507861550..26e91000f579d 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 nr_pa= ges) > > +{ > > + if (!kvm_arch_flush_remote_tlbs_range(kvm, gfn, nr_pages)) > > + return; > > + > > + /* > > + * Fall back to a flushing entire TLBs if the architecture range-= based > > + * TLB invalidation is unsupported or can't be performed for what= ever > > + * reason. > > + */ > > + kvm_flush_remote_tlbs(kvm); > > +} > > + > > static void kvm_flush_shadow_all(struct kvm *kvm) > > { > > kvm_arch_flush_shadow_all(kvm); > > Thanks, > Gavin >