Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp37094pxb; Wed, 30 Mar 2022 22:16:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxL4LTIH2pOsQ55jnNDf4MQl4XNFEswMPTYAgdr+F+VhVQU89JODk0FmYvpx/Xl4qg7cwoR X-Received: by 2002:a17:903:2446:b0:154:3bb0:7ba0 with SMTP id l6-20020a170903244600b001543bb07ba0mr3620071pls.38.1648703793038; Wed, 30 Mar 2022 22:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648703793; cv=none; d=google.com; s=arc-20160816; b=C6UCFw5uqgyBQTze5bqGSjM7H29chQENa7qz9MEzCjimgwocPc/MG4bTzx1X/z92Xv w4I39Fqu5nvNB6NsGESstjTBR57dAqzMzubQlgBTfEmPa97eDrYgUtv42w07qx0DgR5H uDghybdL+g+ooDdqgNjIj1aYyIEa/Dp90tlT89ogA61ohY3NLHdqG/W2YOHVp4hWeQ6H LprwFpMmeAmgUU1qqlnTU2q77dDDGxlsTlixKNZJnpPbpcgEX7xVJRoGpNaToMEaJGgG 41b8lcHprV/Uqz91fSdEHJclhJEY1Wh3y4z/L5A2oNb7Vcy2fIb6gl2eqVkqPmG6vXXF mcEg== 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=XBjvA5zeTFp/CQilx/lDzY875VR4ejnGO0QGtuhhNV8=; b=dblTCUf7ZD1sYzSPHt2ITpsck/zMlo1nQmSZVrg5ODO/sCdLYALjiu4p8dLM9TEkT8 5x3pj7+YtT259TWcbQLXDQV4VARKVnxTvOnDVg32RjPEH2TOpcg/S4OrURSu70Z+329o /+cqSBJKGX+XeyWnpYzsjZQ5B+zL7EyPz7hL4hA6xFB9d54jl/XrqB66uz13iNNHm6ip jfWxHLDoArM00Gq7zB391oz874YgZhPqqTTQ/Xm5148v/mDfV/5m00cowa4LPtAjRIkg T+FGdPs13n9WJ4mq3L9x6z3H3R70xdsVnFEhSkEtbUFi+RJrt0Ds3lx6eRX6QDMcQ/au 6GWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VXoqaOWa; 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=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s33-20020a632161000000b003816043f08bsi22874070pgm.640.2022.03.30.22.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 22:16:33 -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=@intel.com header.s=Intel header.b=VXoqaOWa; 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=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B407D19530B; Wed, 30 Mar 2022 21:23:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbiCaEZE (ORCPT + 99 others); Thu, 31 Mar 2022 00:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbiCaEYt (ORCPT ); Thu, 31 Mar 2022 00:24:49 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2606C10DA6C; Wed, 30 Mar 2022 21:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648700047; x=1680236047; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lrf29M1FoQwZkT3rwYPlkkdAMRzetcMAr56weDYEJfw=; b=VXoqaOWaJ+Z1bw2UKOkAMqNjGsOabwgJL1IiFSU2wF9PRWFp6QizkD/2 s6lflT3f4QrNWky5ej8bcUYVo/R6CPknQfvdRJpiQQ6EnGRR+qd2LPBxT HRC2lT7MV6ftfDu/ZQF7dSruS7V5MGOLIWb6VE2KMbAhTw6nKlXyJu41x kxpZrv7oKYWXVHPe+cN/0Z76fKBhSydGOC6fOs1iMTMp1MMlKqYn8tcUL Jnz+CCBekyQWLw4TVVDj1RYVp+WrfCeSYG7FLkZTNXU3exTzB3gwNMblY ATQFLhovh2sN2sry8Y5TcWyKeHsV641XTQnz1OGjG0jSpQl9uHmHtWN+N g==; X-IronPort-AV: E=McAfee;i="6200,9189,10302"; a="240301454" X-IronPort-AV: E=Sophos;i="5.90,224,1643702400"; d="scan'208";a="240301454" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 20:02:28 -0700 X-IronPort-AV: E=Sophos;i="5.90,224,1643702400"; d="scan'208";a="838892137" Received: from dhathawa-mobl.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.254.53.226]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2022 20:02:26 -0700 Message-ID: <03d3c1ac92cee3b0e8e325da0f703d1dd9657b4b.camel@intel.com> Subject: Re: [RFC PATCH v5 021/104] KVM: x86: Introduce hooks to free VM callback prezap and vm_free From: Kai Huang To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Paolo Bonzini , Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson Date: Thu, 31 Mar 2022 16:02:24 +1300 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 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=no 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 Fri, 2022-03-04 at 11:48 -0800, isaku.yamahata@intel.com wrote: > From: Kai Huang > > Before tearing down private page tables, TDX requires some resources of the > guest TD to be destroyed (i.e. keyID must have been reclaimed, etc). Add > prezap callback before tearing down private page tables for it. > > TDX needs to free some resources after other resources (i.e. vcpu related > resources). Add vm_free callback at the end of kvm_arch_destroy_vm(). > > Signed-off-by: Kai Huang > Signed-off-by: Isaku Yamahata > --- > arch/x86/include/asm/kvm-x86-ops.h | 2 ++ > arch/x86/include/asm/kvm_host.h | 2 ++ > arch/x86/kvm/x86.c | 8 ++++++++ > 3 files changed, 12 insertions(+) > > diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h > index 8125d43d3566..ef48dcc98cfc 100644 > --- a/arch/x86/include/asm/kvm-x86-ops.h > +++ b/arch/x86/include/asm/kvm-x86-ops.h > @@ -20,7 +20,9 @@ KVM_X86_OP(has_emulated_msr) > KVM_X86_OP(vcpu_after_set_cpuid) > KVM_X86_OP(is_vm_type_supported) > KVM_X86_OP(vm_init) > +KVM_X86_OP_NULL(mmu_prezap) > KVM_X86_OP_NULL(vm_destroy) > +KVM_X86_OP_NULL(vm_free) > KVM_X86_OP(vcpu_create) > KVM_X86_OP(vcpu_free) > KVM_X86_OP(vcpu_reset) > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index 8de357a9ad30..5ff7a0fba311 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -1326,7 +1326,9 @@ struct kvm_x86_ops { > bool (*is_vm_type_supported)(unsigned long vm_type); > unsigned int vm_size; > int (*vm_init)(struct kvm *kvm); > + void (*mmu_prezap)(struct kvm *kvm); > void (*vm_destroy)(struct kvm *kvm); > + void (*vm_free)(struct kvm *kvm); > > /* Create, but do not attach this VCPU */ > int (*vcpu_create)(struct kvm_vcpu *vcpu); > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index f6438750d190..a48f5c69fadb 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -11779,6 +11779,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) > kvm_page_track_cleanup(kvm); > kvm_xen_destroy_vm(kvm); > kvm_hv_destroy_vm(kvm); > + static_call_cond(kvm_x86_vm_free)(kvm); > } > > static void memslot_rmap_free(struct kvm_memory_slot *slot) > @@ -12036,6 +12037,13 @@ void kvm_arch_commit_memory_region(struct kvm *kvm, > > void kvm_arch_flush_shadow_all(struct kvm *kvm) > { > + /* > + * kvm_mmu_zap_all() zaps both private and shared page tables. Before > + * tearing down private page tables, TDX requires some TD resources to > + * be destroyed (i.e. keyID must have been reclaimed, etc). Invoke > + * kvm_x86_mmu_prezap() for this. > + */ > + static_call_cond(kvm_x86_mmu_prezap)(kvm); > kvm_mmu_zap_all(kvm); > } > The two callbacks are introduced here but they are actually implemented in 2 patches later (patch 24 KVM: TDX: create/destroy VM structure). Why not just squash this patch to patch 24? Or at least you can put this patch right before patch 24. Please feel free to remove my SoB and From if this bothers you to squash.