Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1675015ioo; Sun, 22 May 2022 23:58:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5IlCyG18UU7cquLkoD4MnItDisHNJ7z4JH66Mfdk8620Rsk42AYrvq+ociY2qE+jQjJ7k X-Received: by 2002:a17:902:f549:b0:161:f216:4f46 with SMTP id h9-20020a170902f54900b00161f2164f46mr14921608plf.70.1653289115140; Sun, 22 May 2022 23:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653289115; cv=none; d=google.com; s=arc-20160816; b=jPLNNqqZHvtWXlXshxXO3nS130QOCIn6D8NYxnHrU9oX0v7rRIMIo7SxBNBUfgSb1P xohOAsGXi1g9eJ0sg2r9G+4zYQfG237OkHjb1HfrDb7Pi9sh0NdloFYCZpyOuWof3Xak y81bIa6c1n46ccjjCogPsck8BYEQc8Pd4DnD83CzlAYwsEhj8QBdW1stir/4ISGQqpau ADsw+N6Q7K7MTli7Txp4l5AebILFsKDR2IGMzsFffh3syFQQqAvrHasTyFnV9P4fQHUJ COIM/gru/rXbo1CFw8mLZHe7VyiLnmvrKau1AZ1ZN7m5woTuJRDcAipG/fSgHW2oGjKL m16w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=ajSKHpDgMxCnIlOKAJfBL23NVlLdxTAamDLVJE7LOew=; b=KcCKPkREZn0ptbyVyAhzWRM4MBr/bEJJTFsdxTTgdSMxSPqI93UEJpo6f2IOzFvfNY nJUtZx06/VlayhVCPIWlSjL5b1qARkg43yzKaLtBKndZB8c6f2hygJiGEy5JZSm/DcMc DGKCxgUUbfwV6yKz4V/h85fOZAWD532HCoUH7xCcq3nM0VDmOwCxXcg3Ma3wkgLztQ3o BcH+IYX7DObGlr2SJIlouzvKE7DG6D7s3LgwU4kmS++LDyKbkVeOjOqz9phl4y0htJG1 z4wefi5Jj0qpuohvUWA9VbjXdGJsDQygXRv9pE85Yfj/EXvoK2uSdFX6ub98aIjJDEIt Lhbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D6wvRPrU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p29-20020a056a000a1d00b00518468aecbbsi13202939pfh.285.2022.05.22.23.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 23:58:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D6wvRPrU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A3EDA5AED3; Sun, 22 May 2022 23:23:44 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240658AbiEVKWA (ORCPT + 99 others); Sun, 22 May 2022 06:22:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbiEVKV6 (ORCPT ); Sun, 22 May 2022 06:21:58 -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 ESMTP id 0B7C335A8C for ; Sun, 22 May 2022 03:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653214913; 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=ajSKHpDgMxCnIlOKAJfBL23NVlLdxTAamDLVJE7LOew=; b=D6wvRPrUreFhDLPEhWvPD9xozK3MjAh1fcPUTqExhmoLlExpE51bpnEfgsfXHhDQNMquDq kXb5BhOVv8GCHUrIL8ZD2Qr36zLuvy8/USEXOL85uPbtwWzEMxJz/P8i8j74RkPK1FA+Jk vq9n1anzr9VIMY6w7R6zSF+d7+0B00M= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-LOb20kgOPOukB8UtH84T5A-1; Sun, 22 May 2022 06:21:50 -0400 X-MC-Unique: LOb20kgOPOukB8UtH84T5A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1D461C05AED; Sun, 22 May 2022 10:21:48 +0000 (UTC) Received: from starship (unknown [10.40.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id B29232026D6A; Sun, 22 May 2022 10:21:42 +0000 (UTC) Message-ID: Subject: Re: [RFC PATCH v3 04/19] KVM: x86: mmu: allow to enable write tracking externally From: Maxim Levitsky To: Sean Christopherson Cc: kvm@vger.kernel.org, Wanpeng Li , Vitaly Kuznetsov , Jani Nikula , Paolo Bonzini , Tvrtko Ursulin , Rodrigo Vivi , Zhenyu Wang , Joonas Lahtinen , Tom Lendacky , Ingo Molnar , David Airlie , Thomas Gleixner , Dave Hansen , x86@kernel.org, intel-gfx@lists.freedesktop.org, Daniel Vetter , Borislav Petkov , Joerg Roedel , linux-kernel@vger.kernel.org, Jim Mattson , Zhi Wang , Brijesh Singh , "H. Peter Anvin" , intel-gvt-dev@lists.freedesktop.org, dri-devel@lists.freedesktop.org Date: Sun, 22 May 2022 13:21:41 +0300 In-Reply-To: References: <20220427200314.276673-1-mlevitsk@redhat.com> <20220427200314.276673-5-mlevitsk@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_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 Thu, 2022-05-19 at 16:27 +0000, Sean Christopherson wrote: > On Wed, Apr 27, 2022, Maxim Levitsky wrote: > > This will be used to enable write tracking from nested AVIC code > > and can also be used to enable write tracking in GVT-g module > > when it actually uses it as opposed to always enabling it, > > when the module is compiled in the kernel. > > Wrap at ~75. Well, the checkpatch.pl didn't complain, so I didn't notice. > > > No functional change intended. > > > > Signed-off-by: Maxim Levitsky > > --- > > arch/x86/include/asm/kvm_host.h | 2 +- > > arch/x86/include/asm/kvm_page_track.h | 1 + > > arch/x86/kvm/mmu.h | 8 +++++--- > > arch/x86/kvm/mmu/mmu.c | 17 ++++++++++------- > > arch/x86/kvm/mmu/page_track.c | 10 ++++++++-- > > 5 files changed, 25 insertions(+), 13 deletions(-) > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > > index 636df87542555..fc7df778a3d71 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1254,7 +1254,7 @@ struct kvm_arch { > > * is used as one input when determining whether certain memslot > > * related allocations are necessary. > > */ > > The above comment needs to be rewritten. Good catch, thank a lot!! > > > - bool shadow_root_allocated; > > + bool mmu_page_tracking_enabled; > > #if IS_ENABLED(CONFIG_HYPERV) > > hpa_t hv_root_tdp; > > diff --git a/arch/x86/include/asm/kvm_page_track.h b/arch/x86/include/asm/kvm_page_track.h > > index eb186bc57f6a9..955a5ae07b10e 100644 > > --- a/arch/x86/include/asm/kvm_page_track.h > > +++ b/arch/x86/include/asm/kvm_page_track.h > > @@ -50,6 +50,7 @@ int kvm_page_track_init(struct kvm *kvm); > > void kvm_page_track_cleanup(struct kvm *kvm); > > > > bool kvm_page_track_write_tracking_enabled(struct kvm *kvm); > > +int kvm_page_track_write_tracking_enable(struct kvm *kvm); > > int kvm_page_track_write_tracking_alloc(struct kvm_memory_slot *slot); > > > > void kvm_page_track_free_memslot(struct kvm_memory_slot *slot); > > diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h > > index 671cfeccf04e9..44d15551f7156 100644 > > --- a/arch/x86/kvm/mmu.h > > +++ b/arch/x86/kvm/mmu.h > > @@ -269,7 +269,7 @@ int kvm_arch_write_log_dirty(struct kvm_vcpu *vcpu); > > int kvm_mmu_post_init_vm(struct kvm *kvm); > > void kvm_mmu_pre_destroy_vm(struct kvm *kvm); > > > > -static inline bool kvm_shadow_root_allocated(struct kvm *kvm) > > +static inline bool mmu_page_tracking_enabled(struct kvm *kvm) > > { > > /* > > * Read shadow_root_allocated before related pointers. Hence, threads > > @@ -277,9 +277,11 @@ static inline bool kvm_shadow_root_allocated(struct kvm *kvm) > > * see the pointers. Pairs with smp_store_release in > > * mmu_first_shadow_root_alloc. > > */ > > This comment also needs to be rewritten. Also thanks a lot, next time I'll check comments better. > > > - return smp_load_acquire(&kvm->arch.shadow_root_allocated); > > + return smp_load_acquire(&kvm->arch.mmu_page_tracking_enabled); > > } > > ... > > > diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c > > index 2e09d1b6249f3..8857d629036d7 100644 > > --- a/arch/x86/kvm/mmu/page_track.c > > +++ b/arch/x86/kvm/mmu/page_track.c > > @@ -21,10 +21,16 @@ > > > > bool kvm_page_track_write_tracking_enabled(struct kvm *kvm) > > This can be static, it's now used only by page_track.c. I'll fix this. > > > { > > - return IS_ENABLED(CONFIG_KVM_EXTERNAL_WRITE_TRACKING) || > > - !tdp_enabled || kvm_shadow_root_allocated(kvm); > > + return mmu_page_tracking_enabled(kvm); > > } > > > > +int kvm_page_track_write_tracking_enable(struct kvm *kvm) > > This is too similar to the "enabled" version; "kvm_page_track_enable_write_tracking()" > would maintain namespacing and be less confusing. Makes sense, thanks, will do! > > Hmm, I'd probably vote to make this a "static inline" in kvm_page_track.h, and > rename mmu_enable_write_tracking() to kvm_mmu_enable_write_tracking and export. > Not a strong preference, just feels silly to export a one-liner. The sole reason I did it this way, because 'page_track.c' this way contains all the interfaces that an external user of write tracking needs to use. > > > +{ > > + return mmu_enable_write_tracking(kvm); > > +} > > +EXPORT_SYMBOL_GPL(kvm_page_track_write_tracking_enable); > > + > > + > > void kvm_page_track_free_memslot(struct kvm_memory_slot *slot) > > { > > int i; > > -- > > 2.26.3 > > Best regards, Maxim Levitsky