Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6306232rwp; Mon, 17 Jul 2023 20:06:50 -0700 (PDT) X-Google-Smtp-Source: APBJJlE50tEYEB5G/h7v7h9pt7hixbPBPp2mEGX383CoMreEpXEk0efcsvd2kI37jgr0gMAMAo1s X-Received: by 2002:a05:6e02:1a4e:b0:348:8158:c386 with SMTP id u14-20020a056e021a4e00b003488158c386mr1506565ilv.8.1689649610301; Mon, 17 Jul 2023 20:06:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689649610; cv=none; d=google.com; s=arc-20160816; b=Nbcoq2FgStTFMn9rnbGOqej7fiEISBRuNcH5zqox0H+lG3BCgHyogsX5VG8+ZIoLMx p52U5o17ZkRC34kDPC06dW7pdi9E2iAfPRF6SHSaWompp24G+MB91elAQmZ0j9vVaWni VI4NDzrj2FdndbJxUvKzL8rIZzmBASmClhCQu6rUuqvj6VodpwK/WXetyxIkmuOgsKzs INmdZlUwTcEd8Yoo5dcwcdSkDk00IrRWEZGatfOSBcFt5dRYb9XN9+QaQ3CRW26PXFeQ VRNigPKbMlDCOOYoaPLSrhvUUZ7POLr/0ANcKtSV9Y6Ral3V5Oc5/D4l+oMLiqmwlA6m 8RGg== 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=H+45ZyWb2HqRyHH2F0pUkKRaEVhoBXUcXoMtMWwioBo=; fh=xhJrmoOwPxw6zxJEH5sahNHaKm7jlyfw5GVNMZTEFoQ=; b=dJ8ink3uiHaM4+ei6enzu9bMz+dKkOlq0WEon/wxBerjsbdooaxLDb/gj37r5QDC82 CEs0cEyPbQRHLjAxiDDN7uxMOpKtmfa8tmV7MVyzzJPxeVVApoLoNoEUSrNd21crsQXX L1GcVQpt8IgNIowUKC2BAruYvkylcfGTljnP5LoC+6wt2yzcuUS0V5Ygid9Knv+zRJLf 6S9fJi1lS7iznRUf+t5EmxwG9HdUcT64GEJzoQ3F3rq7Dh4xNI+Xs94mMo4JCV1o0qFO 0LTrhv0rtEpBHqDJsGgIQ23duKmGYjLVi9tqcPP+PANiJhgbuE3Rq4YaJhDWDQfyuub7 qa2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cPnLEiEz; 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 t2-20020a63f342000000b0055c71f20a30si782952pgj.753.2023.07.17.20.06.37; Mon, 17 Jul 2023 20:06:50 -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=cPnLEiEz; 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 S230412AbjGRCuZ (ORCPT + 99 others); Mon, 17 Jul 2023 22:50:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbjGRCuY (ORCPT ); Mon, 17 Jul 2023 22:50:24 -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 3517010CC for ; Mon, 17 Jul 2023 19:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689648580; 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=H+45ZyWb2HqRyHH2F0pUkKRaEVhoBXUcXoMtMWwioBo=; b=cPnLEiEzrqkluvY0xYCH8m1vk80xKCyKDh0GKV4zkXNlNR4/5on9UlJPRFSchnHuBjDYmG njTOlLZskHUTl8oQNjLjVinxcSuMlxxNg3aHLB44QFAhXrW8UAAWdC3Rk01QcfrLqDnias /zbWCNS39C7o3ojFHQr7sPP+/yg51eo= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-bq51UHy4MMGOTo82FsTsKw-1; Mon, 17 Jul 2023 22:49:38 -0400 X-MC-Unique: bq51UHy4MMGOTo82FsTsKw-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-262d2cae3efso573569a91.1 for ; Mon, 17 Jul 2023 19:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689648577; x=1690253377; 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=H+45ZyWb2HqRyHH2F0pUkKRaEVhoBXUcXoMtMWwioBo=; b=IJ4OpO89VutnP/xxhqg72wc1BTRWnPJuqsF/ZYMAeJ0W4TN7N0UMiqL+Pgp3rc9l5P vpxOqCiVNACuli5GGjIQZClw9RrmT9wG9RSqVDLQppz+3Wo0EfF87n56LbOBS9cY8MZ5 rUO2xMOi0BDiOk86VtJcW3xzcjIsomUdxFkvyFFcmyUzpEvIyukivaedNwkj7bCHOz1w tzO2JmTD7RfROqZRAeQVJ5NgbB3ckQ4+S4GDFaqvsZuJ8klEJ02ZxPi2sN/DNv9CcxiV dFfTEwV77sHTguJ62NCfwnEQ8TB/kyIA5wTYnYuZNtsc6xMubSRUDUJHDvmdytsUS8++ nmog== X-Gm-Message-State: ABy/qLZh3jWnBQ0ni7LQd8Wfr2CgFuhw6Op7sdCJxEQ9mTfOYipO5TA/ PhzdgauVH8kBT1vANF6MUFlezls/qaGfxeCH6UA5HpY4mQdW77Q8/P+gKQSDqlawMtwfBhxRfg5 GueLqjSUms5Q0SYBlmlcfVEVd X-Received: by 2002:a17:90b:4f85:b0:264:942:ad27 with SMTP id qe5-20020a17090b4f8500b002640942ad27mr8520270pjb.4.1689648577414; Mon, 17 Jul 2023 19:49:37 -0700 (PDT) X-Received: by 2002:a17:90b:4f85:b0:264:942:ad27 with SMTP id qe5-20020a17090b4f8500b002640942ad27mr8520243pjb.4.1689648577079; Mon, 17 Jul 2023 19:49:37 -0700 (PDT) Received: from [10.66.61.39] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id cm10-20020a17090afa0a00b0025dc5749b4csm5693845pjb.21.2023.07.17.19.49.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Jul 2023 19:49:36 -0700 (PDT) Message-ID: Date: Tue, 18 Jul 2023 10:49:30 +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 v6 03/11] KVM: Allow range-based TLB invalidation from common code Content-Language: en-US To: Raghavendra Rao Ananta 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 References: <20230715005405.3689586-1-rananta@google.com> <20230715005405.3689586-4-rananta@google.com> <199d18de-1214-7683-b87a-03cc7e49719a@redhat.com> From: Shaoqin Huang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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_BLOCKED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 7/18/23 00:37, Raghavendra Rao Ananta wrote: > On Mon, Jul 17, 2023 at 4:40 AM 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/kvm_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(struct 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_gfn, 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_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 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); >>> + 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. 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 index); >>> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.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 *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 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 pages); >>> >>> #ifdef KVM_ARCH_NR_OBJS_PER_MEMORY_CACHE >>> int kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int min); >>> @@ -1486,6 +1487,14 @@ static inline 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 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 pages) >>> +{ >>> + if (!kvm_arch_flush_remote_tlbs_range(kvm, gfn, 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); >> >> -- >> Shaoqin >> > -- Shaoqin