Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5290772rwb; Wed, 9 Aug 2023 01:31:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3WeTnP2+KPaFCyrHYMkd5f4rBuL6Sd20cCAlsa50DoPuu6r8u87m6ukkrA7pNxNzLGvJs X-Received: by 2002:a17:90a:a418:b0:267:fc61:5a37 with SMTP id y24-20020a17090aa41800b00267fc615a37mr1319966pjp.39.1691569863231; Wed, 09 Aug 2023 01:31:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691569863; cv=none; d=google.com; s=arc-20160816; b=DLiOH0cWmE8CvzujONamyGUloTmuYBtbCHSf+U4758Cw+CZr+tI41mW5LmUYhH+BSN C8x3ttdiwPi/MbZVDo3EwT5O6R0CIlZ8jJ5iLR05l/2dmdEC27C6/V8cXi4FN3vG1ECE WHuTU9SQVcEgOI6maA9JMUp2esXruDOyDdaBBaxxAaf6pcOXmrD5ymRgeHfpbBR+5FSA +aD/2nCjMkV4CHSrE6U/dET1/s8ARix9ktuNSXgOAWiN5F5Ho/M+RY4Unfm1S76bw6S2 8jdNCuC1HZRKyps0BstCin3V38FAemAnmlQMvOb4JK4CvJNis9MuVDCXQwh4sM6lXiKY 7aEQ== 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=gjOdGDWIQkT0phMReVz2eflzO/ETttLoRuiht6Bh+vs=; fh=Bs4IlUUrR08+5RcvALEk5OwqZCdlb6dszx82ZRjpnrU=; b=eZvSqO9OUuPifixZ8sSI2Ma9cTJlKOP6alTwLsz2kN7MLnDoLHRBv/I7NP5NWQup5e yRKIYnbYKZkQUWPXNQ8VLJ3Sdd2Q6AZXYOqnPnE7rnOnveejF2G5bWaZF9btDpKSy1w2 V/N2mU5REA5bUomYSqCt5uXkJZVlZgiCAiTxDOCVSPLWziFImi4AUAb1ONPrgRf0VqMp NytvU9SY0JS0LP7WaV4QKBpvRlcBgEwNc1F9UpiDCe7gGvC9JkpYeRtzO3lhesVddiyd kuyy1NHnRzqsFX97DnGa2j09ZWFBrrQWDxx4yomd0oon/gpXoPJVW6/ZxEuRqd5wh5M2 f50A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ed9vRJ8u; 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 m6-20020a17090a5a4600b002683fd38fd4si972988pji.31.2023.08.09.01.30.52; Wed, 09 Aug 2023 01:31:03 -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=Ed9vRJ8u; 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 S230397AbjHIGKK (ORCPT + 99 others); Wed, 9 Aug 2023 02:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjHIGKI (ORCPT ); Wed, 9 Aug 2023 02:10:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1D612D for ; Tue, 8 Aug 2023 23:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691561368; 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=gjOdGDWIQkT0phMReVz2eflzO/ETttLoRuiht6Bh+vs=; b=Ed9vRJ8uLWLmm4uWaIW/w4+TgxMNGICHw9C3jAXwK2rZLZ3UwlRIBmIypRA8N7hpLUoJFQ lEHi24Swr2+tCzU56GdtzOeaRR/bxfZOQvtmyC4mgEOwCCXfiMe33MKWCoqjao3Eb6qprh XFKlIxL+sWncEuA7baLosqdATP0IbUQ= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-ziSmT54ANKCBeyM8s053gQ-1; Wed, 09 Aug 2023 02:09:27 -0400 X-MC-Unique: ziSmT54ANKCBeyM8s053gQ-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3a5aa4a8fd6so12013020b6e.1 for ; Tue, 08 Aug 2023 23:09:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691561366; x=1692166166; 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=gjOdGDWIQkT0phMReVz2eflzO/ETttLoRuiht6Bh+vs=; b=GM05SoYKT8w5MiyragS7sdasfLbuqEbqErBgq3Pg3axNaHqB/Z4FkNXfxChHcWttke v7vJskHx8SDE/76ASA+D7czXw5Ms10MihR6eU+/0Ae0sY5KqbL0OtY4tXNivRhO3LguZ sD12VHbDbw4g4oEiCJD9bwSuVrtiwgTtsVJWx28ITkQtIE0Zy+Mxak09QWxDb+NlsJ/B Ycb/vXyEBijtQYa530U+U9caMw1UQpQJZSymtaaaRYvbuQAgwrNauZTNL6nmwlVNMpIc ucU3V/ClBSqRjsjrurW1PtLRew3WS/B/lPVPdvRByRjCwImisYfh9JZM5d4qv91Eb6hp cprw== X-Gm-Message-State: AOJu0Yy6tZhFcyOKByhDMV4rOrf+TwWoKxF8aGViKuLqpNkLFP8hbVp2 8r6oD3Y+7FSinS97WeYhlTybQeqqpVMvEf8qJu5HaX+7dYEWQCW/cK6JHHBMcQtksqP3dQf/L/D DCsGbQCu/NYJcMB3ix8BAr0Aa X-Received: by 2002:a05:6808:193:b0:3a6:f7d7:4cfe with SMTP id w19-20020a056808019300b003a6f7d74cfemr1751343oic.50.1691561366664; Tue, 08 Aug 2023 23:09:26 -0700 (PDT) X-Received: by 2002:a05:6808:193:b0:3a6:f7d7:4cfe with SMTP id w19-20020a056808019300b003a6f7d74cfemr1751333oic.50.1691561366353; Tue, 08 Aug 2023 23:09:26 -0700 (PDT) Received: from ?IPV6:2001:8003:e5b0:9f00:dbbc:1945:6e65:ec5? ([2001:8003:e5b0:9f00:dbbc:1945:6e65:ec5]) by smtp.gmail.com with ESMTPSA id 30-20020a17090a001e00b002630bfd35b0sm621062pja.7.2023.08.08.23.09.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Aug 2023 23:09:25 -0700 (PDT) Message-ID: <15975205-6161-d54b-fe40-805a16b0cb27@redhat.com> Date: Wed, 9 Aug 2023 16:09:15 +1000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v8 05/14] KVM: Allow range-based TLB invalidation from common code 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, Shaoqin Huang References: <20230808231330.3855936-1-rananta@google.com> <20230808231330.3855936-6-rananta@google.com> From: Gavin Shan In-Reply-To: <20230808231330.3855936-6-rananta@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 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=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 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(struct 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_tlbs_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 = -EOPNOTSUPP; > > if (kvm_x86_ops.flush_remote_tlbs_range) > ret = static_call(kvm_x86_flush_remote_tlbs_range)(kvm, start_gfn, > nr_pages); > - if (ret) > - kvm_flush_remote_tlbs(kvm); > + > + return ret; > } > I guess @start_gfn can be renamed to @gfn, to be consistent with its declaration in include/linux/kvm_host.h and struct kvm_x86_ops::flush_remote_tlbs_range() > 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_internal.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 gfn, 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_mode); > > void kvm_flush_remote_tlbs(struct kvm *kvm); > +void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, u64 nr_pages); > > #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE > int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min); > @@ -1488,6 +1489,17 @@ static inline int kvm_arch_flush_remote_tlbs(struct 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_pages) > +{ > + 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_pages) > +{ > + 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 whatever > + * reason. > + */ > + kvm_flush_remote_tlbs(kvm); > +} > + > static void kvm_flush_shadow_all(struct kvm *kvm) > { > kvm_arch_flush_shadow_all(kvm); Thanks, Gavin