mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Vishal Annapurve <vannapurve@google.com>
Cc: <pbonzini@redhat.com>, <seanjc@google.com>, <kvm@vger.kernel.org>,
	<rick.p.edgecombe@intel.com>, <kirill.shutemov@linux.intel.com>,
	<kai.huang@intel.com>, <reinette.chatre@intel.com>,
	<xiaoyao.li@intel.com>, <tony.lindgren@linux.intel.com>,
	<binbin.wu@linux.intel.com>, <isaku.yamahata@intel.com>,
	<linux-kernel@vger.kernel.org>, <yan.y.zhao@intel.com>,
	<chao.gao@intel.com>
Subject: Re: [PATCH V4 1/1] KVM: TDX: Add sub-ioctl KVM_TDX_TERMINATE_VM
Date: Wed, 18 Jun 2025 08:50:04 +0300	[thread overview]
Message-ID: <e86aa631-bedd-44b4-b95a-9e941d14b059@intel.com> (raw)
In-Reply-To: <CAGtprH_cpbPLvW2rSc2o7BsYWYZKNR6QAEsA4X-X77=2A7s=yg@mail.gmail.com>

On 16/06/2025 06:40, Vishal Annapurve wrote:
> On Wed, Jun 11, 2025 at 2:52 AM Adrian Hunter <adrian.hunter@intel.com> wrote:
>>
>> From: Sean Christopherson <seanjc@google.com>
>>
>> Add sub-ioctl KVM_TDX_TERMINATE_VM to release the HKID prior to shutdown,
>> which enables more efficient reclaim of private memory.
>>
>> Private memory is removed from MMU/TDP when guest_memfds are closed. If
>> the HKID has not been released, the TDX VM is still in RUNNABLE state,
>> so pages must be removed using "Dynamic Page Removal" procedure (refer
>> TDX Module Base spec) which involves a number of steps:
>>         Block further address translation
>>         Exit each VCPU
>>         Clear Secure EPT entry
>>         Flush/write-back/invalidate relevant caches
>>
>> However, when the HKID is released, the TDX VM moves to TD_TEARDOWN state
>> where all TDX VM pages are effectively unmapped, so pages can be reclaimed
>> directly.
>>
>> Reclaiming TD Pages in TD_TEARDOWN State was seen to decrease the total
>> reclaim time.  For example:
>>
>>         VCPUs   Size (GB)       Before (secs)   After (secs)
>>          4       18               72             24
>>         32      107              517            134
>>         64      400             5539            467
>>
>> Link: https://lore.kernel.org/r/Z-V0qyTn2bXdrPF7@google.com
>> Link: https://lore.kernel.org/r/aAL4dT1pWG5dDDeo@google.com
>> Signed-off-by: Sean Christopherson <seanjc@google.com>
>> Co-developed-by: Adrian Hunter <adrian.hunter@intel.com>
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>> ---
>>
>>
>> Changes in V4:
>>
>>         Drop TDX_FLUSHVP_NOT_DONE change.  It will be done separately.
>>         Use KVM_BUG_ON() instead of WARN_ON().
>>         Correct kvm_trylock_all_vcpus() return value.
>>
>> Changes in V3:
>>
>>         Remove KVM_BUG_ON() from tdx_mmu_release_hkid() because it would
>>         trigger on the error path from __tdx_td_init()
>>
>>         Put cpus_read_lock() handling back into tdx_mmu_release_hkid()
>>
>>         Handle KVM_TDX_TERMINATE_VM in the switch statement, i.e. let
>>         tdx_vm_ioctl() deal with kvm->lock
>> ....
>>
>> +static int tdx_terminate_vm(struct kvm *kvm)
>> +{
>> +       if (kvm_trylock_all_vcpus(kvm))
>> +               return -EBUSY;
>> +
>> +       kvm_vm_dead(kvm);
> 
> With this no more VM ioctls can be issued on this instance. How would
> userspace VMM clean up the memslots? Is the expectation that
> guest_memfd and VM fds are closed to actually reclaim the memory?

Yes

> 
> Ability to clean up memslots from userspace without closing
> VM/guest_memfd handles is useful to keep reusing the same guest_memfds
> for the next boot iteration of the VM in case of reboot.

TD lifecycle does not include reboot.  In other words, reboot is
done by shutting down the TD and then starting again with a new TD.

AFAIK it is not currently possible to shut down without closing
guest_memfds since the guest_memfd holds a reference (users_count)
to struct kvm, and destruction begins when users_count hits zero.


  reply	other threads:[~2025-06-18  5:51 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11  9:51 [PATCH V4 0/1] KVM: TDX: Decrease TDX VM shutdown time Adrian Hunter
2025-06-11  9:51 ` [PATCH V4 1/1] KVM: TDX: Add sub-ioctl KVM_TDX_TERMINATE_VM Adrian Hunter
2025-06-16  3:40   ` Vishal Annapurve
2025-06-18  5:50     ` Adrian Hunter [this message]
2025-06-18  6:00       ` Vishal Annapurve
2025-06-18  8:33         ` Adrian Hunter
2025-06-19  0:33           ` Sean Christopherson
2025-06-19 11:12             ` Adrian Hunter
2025-06-20 14:24               ` Sean Christopherson
2025-06-20 16:14                 ` Vishal Annapurve
2025-06-20 16:26                   ` Sean Christopherson
2025-06-23 20:36                   ` Vishal Annapurve
2025-06-23 21:39                     ` Sean Christopherson
2025-06-23 23:35                       ` Vishal Annapurve
2025-06-20 18:59                 ` Edgecombe, Rick P
2025-06-20 21:21                   ` Vishal Annapurve
2025-06-20 23:34                     ` Edgecombe, Rick P
2025-06-21  3:00                       ` Vishal Annapurve
2025-06-23 16:23                         ` Edgecombe, Rick P
2025-06-23 20:22                           ` Vishal Annapurve
2025-06-23 22:51                             ` Edgecombe, Rick P
2025-06-18 22:07         ` Edgecombe, Rick P
2025-06-23 20:40   ` Vishal Annapurve
2025-06-25 22:25 ` [PATCH V4 0/1] KVM: TDX: Decrease TDX VM shutdown time Sean Christopherson
2025-06-26 15:58   ` Sean Christopherson
2025-06-26 19:52     ` Adrian Hunter
2025-07-11  8:55     ` Xiaoyao Li
2025-07-11 13:05       ` Sean Christopherson
2025-07-11 13:40         ` Xiaoyao Li
2025-07-11 14:19           ` Sean Christopherson
2025-07-11 22:31             ` Edgecombe, Rick P
2025-07-11 22:54               ` Sean Christopherson
2025-07-11 23:04                 ` Edgecombe, Rick P
2025-07-11 23:00             ` Edgecombe, Rick P
2025-07-11 23:05               ` Sean Christopherson
2025-07-11 23:17                 ` Edgecombe, Rick P
2025-07-14  3:20                   ` Xiaoyao Li
2025-07-14 13:56                     ` Sean Christopherson
2025-07-14 15:06                       ` Xiaoyao Li
2025-07-16  9:22             ` Xiaoyao Li
2025-07-18 15:35               ` Sean Christopherson
2025-07-17  9:14             ` Nikolay Borisov
2025-07-18 14:36               ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e86aa631-bedd-44b4-b95a-9e941d14b059@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=chao.gao@intel.com \
    --cc=isaku.yamahata@intel.com \
    --cc=kai.huang@intel.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=reinette.chatre@intel.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=seanjc@google.com \
    --cc=tony.lindgren@linux.intel.com \
    --cc=vannapurve@google.com \
    --cc=xiaoyao.li@intel.com \
    --cc=yan.y.zhao@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®