kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kishen Maloor <kishen.maloor@intel.com>
To: Peter Xu <peterx@redhat.com>, Artem Bityutskiy <dedekind1@gmail.com>
Cc: "Tony Lindgren" <tony.lindgren@linux.intel.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Sean Christopherson" <seanjc@google.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Jon Grimm" <Jon.Grimm@amd.com>,
	"Pankaj Gupta" <pankaj.gupta@amd.com>,
	"Tom Lendacky" <thomas.lendacky@amd.com>,
	"Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oliver.upton@linux.dev>,
	"Steven Price" <steven.price@arm.com>,
	"Anup Patel" <anup@brainfault.org>,
	"Samuel Ortiz" <sameo@rivosinc.com>,
	"Jakub Růžička" <jakub.ruzicka@matfyz.cz>,
	"Jörg Rödel" <joro@8bytes.org>,
	"Vishal Annapurve" <vannapurve@google.com>,
	"Elena Reshetova" <elena.reshetova@intel.com>,
	"Kai Huang" <kai.huang@intel.com>,
	"Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Peter Fang" <peter.fang@intel.com>,
	"Rick Edgecombe" <rick.p.edgecombe@intel.com>,
	"Xiaoyao Li" <xiaoyao.li@intel.com>,
	"Xu Yilun" <yilun.xu@linux.intel.com>,
	kvm@vger.kernel.org
Subject: Re: [RFC PATCH v2 0/4] Add KVM API for confidential guest live migration
Date: Sun, 20 Sep 2026 16:56:20 -0700	[thread overview]
Message-ID: <a4ec3af5-5494-4fb4-bf66-e3a8b67325e3@intel.com> (raw)
In-Reply-To: <aqxbMGLwvtT8zkEb@zhexu-thinkpadt14gen5.rmtcaon.csb>

Hi Peter,

Thank you for your comments. Just adding a few other details to
complement Artem's response. 

On 9/17/26 2:27 PM, Peter Xu wrote:
> On Fri, Sep 04, 2026 at 09:24:25PM +0300, Artem Bityutskiy wrote:
>> On Mon, 2026-08-31 at 10:13 +0300, Tony Lindgren wrote:
> ...
>> - Should the same uAPIs also support traditional VMs? But the only use-case
>>   I imagine here is "for testing purposes".
> 
> This is an interesting idea, I think this could be useful.  Especially, I
> wonder if you already have it done and PoC branches you can share, so that
> I can play with it.

I had once attempted this and hit a breaking case while migrating regular VMs.
I didn't dig further since the primary use of this UAPI set is with CoCo VMs.

Here's what I gathered: KVM-mediated transfer needs KVM to resolve a GFN to the
HVA where the data lands, and on x86 QEMU mutates that mapping at runtime in a
way that is opaque to KVM. For the PAM window QEMU overlays a separate region on
top of pc.ram, and KVM sees only the flattened view, the winning memslot, with
no way to address what that slot shadows. On the source, firmware reprograms PAM
and QEMU drops the overlay. On the destination the firmware never runs, so it still
has its boot-time layout and the overlay is still in place. So importing, say, GFN 0xc0
lands on the overlay's backing store, which is a read-only memslot, and the GFN->HVA
translation fails. I suppose even if it were writable, the data would land there
rather than in the pc.ram underneath where it belongs. Without mediation, QEMU is
able to write to the HVA directly, so the problem doesn't arise.

Generally, I think KVM mediation only works if KVM's view of memory is authoritative.
TDX skirts this issue entirely because QEMU doesn't create overlays for TDX VMs.

> ...
> Could you elaborate this ITERATION operation?  Is that something the
> userapp must do after full scan of a round of guest memory?

Essentially, yes. TDX migration architecture delimits such pre-copy rounds as
"migration epochs" and emits an epoch token at each round boundary that needs to be
consumed on the destination. It allows the TDX module to verify that everything from
the prior round has been received at the destination and that two versions of the
same GPA aren't sent in the same epoch. It is userspace that decides where a round
ends, but any deviation from this model and migration would fail.

> 
>>>        |    (repeat until convergence)                  |
>>>  CMD(STOP_AND_COPY/PAUSE)                               |
>>>  CMD(STOP_AND_COPY/TD_STATE) --- VM state ------> CMD(STOP_AND_COPY/TD_STATE)
>>>  KVM_EXPORT_VCPU             --- vCPU state ----> KVM_IMPORT_VCPU
>>>  KVM_EXPORT_MEMORY           -- final memory ---> KVM_IMPORT_MEMORY
> 
> When read/write encrypted memories, two questions:
> 
> - Is there an upper bound of the buffer size per-page?

Yes. For TDX a 4KB guest page produces exactly 4KB of encrypted payload plus a small
fixed amount of ancillary data. The bound can be pre-computed and userspace 
can size its buffers accordingly. The UAPI itself doesn't impose one. The vendor 
implementation decides how pages and ancillary data are laid out.

> 
> - Does this operation supports concurrency?  If it supports, how well it
>   scales per expectation (e.g. is there known big lock for that)?

Yes, these operations can support multifd and kvm_memory_transfer carries the
channel ID. The encryption/decryption work is per-channel, so it scales as multifd
does. The one serialization point is the epoch boundary, i.e. the ITERATION call,
which has to drain in-flight transfers for that round. That's inherent to the epoch 
model rather than a lock that could be dropped.

> ...
> IMHO we should really take postcopy into account when designing the API and
> state machine.  We don't need to implement it in the first version, even
> until merging, but we need to make sure postcopy will be new ioctls on top
> of existing and it should have no major loopholes that it'll need a new set
> of APIs.

Agreed. We honestly haven't looked at post-copy in depth, but supporting it thus
far appears to be additive. One item that comes to mind is a new command in KVM_MIGRATE_CMD
to mark the post-copy switchover point. On the source, vendor code could send all
previously exported and dirty pages (deferring all un-exported pages to post-copy) and
prepare to serve pages on demand. On the destination, vendor code could make the VM
runnable with incomplete memory. This is based on a preliminary assessment though.

> For example, I think we should consider KVM_EXPORT_MEMORY being usable
> after END on source, KVM_IMPORT_MEMORY while TD is in operation, etc.  We

Yes, though I think some of these details could be handled in the vendor
implementation -- e.g., KVM_EXPORT/IMPORT_MEMORY might not need to know that
they're servicing post-copy.

> should likely also need to still picture the rough process of postcopy,
> reserve those APIs since the start (but return -EINVAL or something).

Agreed. We shall attempt to sketch that flow. Your thoughts and feedback would 
be very helpful as we work through this.

> ...
> Could you elaborate what's the relations between TDH.MEM.SCAN.RANGE and the
> GET_DIRTY_LOG ioctl?  I recall above mentioned GET_DIRTY_LOG will be
> available even for CoCo, which makes sense assuming dirty information isn't
> confidential.  However then I don't understand what TDH.MEM.SCAN.RANGE
> plays the role here.

GET_DIRTY_LOG is the UAPI, but the slot dirty bitmaps need to be populated somehow and
TDH.MEM.SCAN.RANGE fills that gap for TDX. It is a SEAMCALL that scans the SEPT upon
request to return the list of currently dirty pages. We wanted to avoid inventing a new
UAPI for this and GET_DIRTY_LOG seemed to be a natural fit. In our current PoC, we've added
a barebones kvm_x86_ops hook that is plugged into kvm_arch_sync_dirty_log(). The TDX
implementation of that hook invokes the scans and records the dirty pages into KVM's slot
dirty bitmaps that GET_DIRTY_LOG serves up to userspace (as usual).

  parent reply	other threads:[~2026-09-20 23:56 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  7:13 [RFC PATCH v2 0/4] Add KVM API for confidential guest live migration Tony Lindgren
2026-08-31  7:13 ` [RFC PATCH v2 1/4] Documentation: KVM: Add live migration API for confidential guests Tony Lindgren
2026-08-31  7:20   ` sashiko-bot
2026-09-18 11:35   ` Peter Xu
2026-09-21  4:20     ` Tony Lindgren
2026-09-24  1:50     ` Wei Wang
2026-09-24  4:51       ` Tony Lindgren
2026-08-31  7:13 ` [RFC PATCH v2 2/4] KVM: x86: Add optional KVM_CAP_LIVE_MIGRATION and KVM_MIGRATE_CMD Tony Lindgren
2026-08-31  7:23   ` sashiko-bot
2026-09-01  6:03     ` Tony Lindgren
2026-09-07 11:53   ` Tony Lindgren
2026-09-07 13:15     ` Jörg Rödel
2026-09-07 13:32       ` Artem Bityutskiy
2026-09-08  4:15         ` Tony Lindgren
2026-09-08  4:43         ` Tony Lindgren
2026-09-09  0:22           ` Kishen Maloor
2026-09-09  6:57             ` Tony Lindgren
2026-09-10  1:11               ` Kishen Maloor
2026-09-10  6:33                 ` Tony Lindgren
2026-09-11  1:40                   ` Kishen Maloor
2026-09-11  4:23                     ` Tony Lindgren
2026-09-15  0:14                       ` Kishen Maloor
2026-09-15  4:44                         ` Tony Lindgren
2026-09-15 15:53                           ` Kishen Maloor
2026-09-16  5:09                             ` Tony Lindgren
2026-09-17  3:31                               ` Kishen Maloor
2026-09-17  6:42                                 ` Tony Lindgren
2026-09-18  4:32                                   ` Kishen Maloor
2026-09-18  5:58                                     ` Tony Lindgren
2026-09-21  0:13                                       ` Kishen Maloor
2026-09-21  6:52                                         ` Tony Lindgren
2026-09-21  9:24                                           ` Tony Lindgren
2026-09-21 10:58                                             ` Tony Lindgren
2026-09-22  3:57                                           ` Kishen Maloor
2026-09-22  5:25                                             ` Tony Lindgren
2026-09-23  0:38                                               ` Kishen Maloor
2026-09-23  6:04                                                 ` Tony Lindgren
2026-09-24  5:53                                                   ` Kishen Maloor
2026-09-24  6:59                                                     ` Tony Lindgren
2026-09-18  4:33   ` Kishen Maloor
2026-09-21  5:58     ` Tony Lindgren
2026-09-21  6:56       ` Tony Lindgren
2026-09-22  3:56         ` Kishen Maloor
2026-09-22  6:27           ` Tony Lindgren
2026-09-23  0:37             ` Kishen Maloor
2026-09-23  6:50               ` Tony Lindgren
2026-09-24  5:34                 ` Kishen Maloor
2026-09-24  7:15                   ` Tony Lindgren
2026-10-08  9:22                     ` Tony Lindgren
2026-08-31  7:13 ` [RFC PATCH v2 3/4] KVM: x86: Add optional KVM_EXPORT_MEMORY and KVM_IMPORT_MEMORY Tony Lindgren
2026-08-31  7:23   ` sashiko-bot
2026-09-01  6:10     ` Tony Lindgren
2026-08-31  7:13 ` [RFC PATCH v2 4/4] KVM: x86: Add optional KVM_EXPORT_VCPU and KVM_IMPORT_VCPU Tony Lindgren
2026-08-31  7:23   ` sashiko-bot
2026-09-01  6:12     ` Tony Lindgren
2026-09-04 18:24 ` [RFC PATCH v2 0/4] Add KVM API for confidential guest live migration Artem Bityutskiy
2026-09-17 21:27   ` Peter Xu
2026-09-18 12:46     ` Artem Bityutskiy
2026-09-18 15:53       ` Peter Xu
2026-09-22  8:09         ` Artem Bityutskiy
2026-09-22  9:42           ` Tony Lindgren
2026-09-22 11:54             ` Artem Bityutskiy
2026-09-23  4:20               ` Tony Lindgren
2026-09-22 21:18           ` Peter Xu
2026-09-23 12:05             ` Artem Bityutskiy
2026-09-24 21:19               ` Peter Xu
2026-09-28 14:15                 ` Artem Bityutskiy
2026-09-29 21:05                   ` Peter Xu
2026-10-02 19:57                     ` Artem Bityutskiy
2026-10-07 20:00                       ` Peter Xu
2026-09-23 15:28           ` Serge Hallyn (AMD)
2026-09-20 23:56     ` Kishen Maloor [this message]
2026-09-23 21:36       ` Peter Xu
2026-09-24  4:27         ` Kishen Maloor
2026-09-25 14:18           ` Peter Xu
2026-09-29  1:28             ` Kishen Maloor
2026-09-30 20:42               ` Peter Xu
2026-10-07  4:27                 ` Kishen Maloor
2026-10-07 20:13                   ` Peter Xu
2026-10-08  6:23                     ` Tony Lindgren
2026-10-08 14:31                       ` Peter Xu
2026-09-18 18:36 ` Ionut Mihalcea
2026-09-21  4:35   ` Tony Lindgren
2026-09-25 16:03 ` Serge Hallyn (AMD)
2026-09-28  3:24   ` Kishen Maloor

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=a4ec3af5-5494-4fb4-bf66-e3a8b67325e3@intel.com \
    --to=kishen.maloor@intel.com \
    --cc=Jon.Grimm@amd.com \
    --cc=anup@brainfault.org \
    --cc=dedekind1@gmail.com \
    --cc=elena.reshetova@intel.com \
    --cc=farosas@suse.de \
    --cc=jakub.ruzicka@matfyz.cz \
    --cc=joro@8bytes.org \
    --cc=kai.huang@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=oliver.upton@linux.dev \
    --cc=pankaj.gupta@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.fang@intel.com \
    --cc=peterx@redhat.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=sameo@rivosinc.com \
    --cc=seanjc@google.com \
    --cc=steven.price@arm.com \
    --cc=thomas.lendacky@amd.com \
    --cc=tony.lindgren@linux.intel.com \
    --cc=vannapurve@google.com \
    --cc=xiaoyao.li@intel.com \
    --cc=yilun.xu@linux.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;
as well as URLs for NNTP newsgroup(s).