Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp941000pxb; Wed, 6 Apr 2022 04:55:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB1TgDPr6UBn6rcFl1mV9OtWYclUPgY9SnvZ9skU840dji3yMow3PwuSpP6W/l7blf086d X-Received: by 2002:a17:90b:915:b0:1ca:b584:8241 with SMTP id bo21-20020a17090b091500b001cab5848241mr9489210pjb.46.1649246154896; Wed, 06 Apr 2022 04:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246154; cv=none; d=google.com; s=arc-20160816; b=S1+Nud8Gtug6UiZwt4D0Ua5at9qTjHOOkoCPWW4sd1BR0fwmsJ7LlmmNSWgVt1XI9i lqPKfyYFRppwv17HSz2ycRNrxTUOc+3q6qoxfOSOL3b9H+RUXk+Hm3nUt6L5neP47L1a DXPZXCuw90sKAO8maZmdQurTXkKqeTfwA6Y6Dt2lJK6Pfxa+9kD0SFCALlC59peCzj89 W8qSOlRX+lalOCg+5UPhRPYxEgubO/sqoHzYMTJiNb4QKKqr0j/IXeYDJVZGn1zkUAJs bwaIzV5A9wHroy1PEitNvsCyqT+BqP0QuNWbpjHh0GmpuvQjfjIuSKAkueb60CAJfvdo vqfg== 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=iAgWhjRrYpIhx8E90XItBzeThRQ5JiMqIe491O7AfVA=; b=pX+2QYziiY15dtxrR8MgWy3oeLjr2tfCSNAtXoZ6rE7LLTS+wCOKi2zedUuj/4IHBo VrPNUFuH+NReYUe7fej6mZkaIM8MSe6hEQKHRPeVFFaq837JeLxPjnYHqJ+AVBXbwcNF AfhaYvs4F7DqHK4l4UtqY4VFchUZEst5jZE94Dj7Imm3s1oPN/vhSrXrcaI6/npyvADw HKX3fMFUkuuQsO8/SbqqZJY3tMYiaVVjA28zR5hOmYa6wBkHZw3eyEhfPWIZGULbsbUt qrNfYO9clRxS1P5BOhZHF5oYB3n/uLISvAfxPbeN+zcTo0WUzvCd6iiVYbqxyZguGnYJ VPTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RTeLStRB; 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 b15-20020a056a000a8f00b004fa3a8dff9csi16708151pfl.83.2022.04.06.04.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:55:54 -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=RTeLStRB; 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 4617464ECD8; Wed, 6 Apr 2022 03:18:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1580049AbiDEXdm (ORCPT + 99 others); Tue, 5 Apr 2022 19:33:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389909AbiDENe3 (ORCPT ); Tue, 5 Apr 2022 09:34:29 -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 ESMTP id 6C004104A62 for ; Tue, 5 Apr 2022 05:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649162462; 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=iAgWhjRrYpIhx8E90XItBzeThRQ5JiMqIe491O7AfVA=; b=RTeLStRBMRUHBXaEEe097sk40fKR4/XvMpIEEkQ+QtAK8kgxIpMpqIbidq0wUfxiavOOO0 fcqLNwzDngWtu6c/BXvrsM2wEUe7pcyzmwLwdS+d87lGCxPxYVd0D1Yy56qXfr9j7b0/xE +9lVVGycUiwHQ7JMN05Kyvs8a+bnp5k= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-310-nS_WsDmoMyK4lTSKq77RYQ-1; Tue, 05 Apr 2022 08:41:01 -0400 X-MC-Unique: nS_WsDmoMyK4lTSKq77RYQ-1 Received: by mail-wm1-f72.google.com with SMTP id 189-20020a1c02c6000000b0038e6c4c6472so1291426wmc.1 for ; Tue, 05 Apr 2022 05:41:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=iAgWhjRrYpIhx8E90XItBzeThRQ5JiMqIe491O7AfVA=; b=GDS7yCw5RWTFvOy5d8HN9xBH44/XaJ3xTbB0OPM/kFqs7LmdKlpoVWFQ96qLpbDCrL I1P6TMJGCVOD5D/LGhGR46KfY37X22FaW6MO8z3Tux5QY/Pb/5QbXuqjaaLWtgDQdPbU NkLPGWnxChWLz7C042oP6hbdSMWBVT71jqeH3uNsqQvETT/lQ86/NMpAr/hAKpDqlYSZ lJp21xvmzGkXzo4wSy8HqW7whlhcJiJktTqFputb2iFaHTyZ/PeEVXUS+zFRTKfGKRuv tJsFe+pKGrPueUY1/T4e0LMBGKDlMIbCNs/7VZIcOjY1n0adj2mVRWAKiNTYLw9O3Kda RU6A== X-Gm-Message-State: AOAM532P3HL+r9DTE3KSMPThMHJVv3/GDpjoqLIgfZD+XW83QYaWjtIx PdQISAFaynN0iHoYKS8l/wWlpldOZH7Th4QJfGUQ//6PbBUEQ85dqskCAUsHJv4TICe5HbBUDon vdC0oYl3+QbCkxSu/Y/5hzRZ1 X-Received: by 2002:a05:600c:3ca7:b0:38e:50d2:27fe with SMTP id bg39-20020a05600c3ca700b0038e50d227femr2975268wmb.159.1649162460264; Tue, 05 Apr 2022 05:41:00 -0700 (PDT) X-Received: by 2002:a05:600c:3ca7:b0:38e:50d2:27fe with SMTP id bg39-20020a05600c3ca700b0038e50d227femr2975243wmb.159.1649162460003; Tue, 05 Apr 2022 05:41:00 -0700 (PDT) Received: from [10.32.181.87] (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.googlemail.com with ESMTPSA id p18-20020a1c5452000000b0038e70261309sm2147830wmi.1.2022.04.05.05.40.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Apr 2022 05:40:59 -0700 (PDT) Message-ID: <9a319273-b2ed-2eb7-a00d-3c46588e45d8@redhat.com> Date: Tue, 5 Apr 2022 14:40:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [RFC PATCH v5 021/104] KVM: x86: Introduce hooks to free VM callback prezap and vm_free Content-Language: en-US To: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@gmail.com, Jim Mattson , erdemaktas@google.com, Connor Kuehl , Sean Christopherson References: From: Paolo Bonzini In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 3/4/22 20:48, 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); Please rename the hook to (*flush_shadow_all_private). Otherwise ok, Paolo > } >