From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796316932; b=jVqwMA6dCKMmVpJPgPosBbknV/yo6C8NhrfomXNYOJ+yvcTI8FB4uqQpGchBIFNm+AuO zMOPLia+EN53uNk0Xk7rzxqBvu5sAEVvxDXwOo3DHSAV87PQT55TQ2I2JVjV+pHksQ5ew yKu+CEBUo0I+cOWVLTOpohWHy4GZ762up6Z/gAlf37B2+kBa+14Fp61RwJdXz42tVwhN7 5igzn/H4Et23uEm1ZhPYVU0wYcPYOem2559WQ5XTwnxXD6/CPCQxgxDNOrzknM9SeP/ZN YBg4gySnVqDuvWDkaxMuc1erGvg4EVi+FU6EBF4wocXQ3X/aSfqS+WB7U19Mz9ZLJ+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796316932; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=3lSIYJN7s0Y7OPhjTl3qM/NPmmivfrziGakxvkKHGEs=; b=IsrJ9zKemnemp5TZ8Jf39FD1nCzMB7dK7kr66WhMyqdj88S3QXHgXEbMBb5Zyx12TF+t 84TTDXafg3tqCsShkvaxp39r0dzNJKSSTC64uXulga8qP9x1Pbjj6lifo3ftt+LYWGrf7 9S97rSwW371C/PNrAuIjUY++UWYYJuguCYGRTSJm6++TSs8LQFhCOOmN5n3fdEjtVbk5c qtHJiZCz6ObB70+BGJ1P2RpRHZU2C6h2Jk92Bq1w4CndR4f3fruUDrmVlEvDxVAHUZRMA +RqNW6TD++0XlAccAy8bobxq6DEfQT51Wf/BgyEqrUPzsBkCIhbdGsVW8nOO7qddrIQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OGvtrZh2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0898606A322 for ; Thu, 3 Dec 2026 16:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OGvtrZh2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21BA81F00919; Thu, 3 Dec 2026 16:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796316931; bh=3lSIYJN7s0Y7OPhjTl3qM/NPmmivfrziGakxvkKHGEs=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=OGvtrZh2mYj8L2zYH3lR1DZgsIndD0eMr4pLgpH5BsMK7FPllX2HPR3zSO3L9/zNy y5HzcKDhSqBi04tLDH6lI672s/iYUHHiISyFmKrSjlR5pD2KwZoZwOVZx282Ao+pdN bWUnfAdNQH71xBaZr6tBKjPEXK/flbecM/fWUXBiRlVna4g6QjBzEVnkP7Wjvjk+BL XFlm5Xi0DUgmJ5vaputt84PJ3igta1bq8FkPn7sgqSiJhC0yYOn6AMJsOi+jn5VY6b vOwsvFh5SjKw0jYNUEr4NAqRKHnW8R4J21Gj6ADPIM9mShYaKBTka3vonz32MbYNoJ xECB3nzZUeElA== Date: Thu, 3 Dec 2026 10:55:24 -0600 From: "Serge Hallyn (AMD)" To: Artem Bityutskiy Cc: Mathias Brossard , Peter Xu , Tony Lindgren , Kishen Maloor , "Serge E. Hallyn" , Paolo Bonzini , Sean Christopherson , Fabiano Rosas , Jon Grimm , Pankaj Gupta , Tom Lendacky , Marc Zyngier , Oliver Upton , Steven Price , Anup Patel , Samuel Ortiz , Jakub =?utf-8?B?UsWvxb5pxI1rYQ==?= , =?iso-8859-1?Q?J=F6rg_R=F6del?= , Vishal Annapurve , Elena Reshetova , Kai Huang , Mika Westerberg , Peter Fang , Rick Edgecombe , Xiaoyao Li , Xu Yilun , "kvm@vger.kernel.org" , "David.Kaplan@amd.com" , "tycho@kernel.org" , "Adam, Mahmoud" , Daniil Egranov Subject: Re: Negotiation Model Message-ID: References: X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Dec 02, 2026 at 03:31:52PM +0200, Artem Bityutskiy wrote: > Hi, > > let me reply only about CoCo negotiation model. > > On Thu, 2026-11-19 at 22:35 +0000, Mathias Brossard wrote: > > > > On Thu, Nov 19, 2026 at 11:27, Peter Xu wrote: > > > Hopefully it shouldn't be anything complex. My current expectation is the > > > migration thread should own the main iochannel (for bi-directional IOs) for > > > a short while because the handshake needs talks back and forth, and it > > > should forward the return path channel only until handshake done, then > > > it'll become almost outgoing traffic like before (unless there's a postcopy > > > afterwards). > > > > > > We are looking to see how we can define for the CCA migration session > > establishment to be routed over the NEGOTIATE command. So hopefully this > > should be something that could be leveraged on Arm too. > > # Terminology > > First, let's agree on terminology. Serge suggested the word > "negotiate" earlier, so let's try building the terminology around it. > I used the TDX terms before ("setup session", "migration setup"), but > I am fine with "negotiate" if folks like it. Let me know. Right, I wasn't really thinking about it, I've just been calling it negotiation bc the two sides have to vet each other and agree on a key. > This would be the generic Linux terminology. Each vendor can keep its > own terms in its specs. > > - Negotiation phase: the migration phase that establishes trust > between the source and destination, checks the migration policy, and > sets up the migration keys. It ends when both sides have the keys. > TDX calls it the "setup session", the AMD ARG (AMD Root Guest) spec > calls it "Pre-Migration", and Arm calls it "session establishment" > (per Mathias). > > - Negotiation agent: a separate trusted entity that negotiates on > behalf of the migrated guest. Examples are TDX MigTD and AMD MA, > which are special TDX and SNP guests. As I understand from Mathias, > Arm CCA may have a similar agent too. The point is that negotiation > agents are not part of the kernel. From QEMU's point of view, they > are separate processes, and may or may not be VMs. The interface > between QEMU and negotiation agents is a separate topic. > > - Agent binding: attaching a negotiation agent to the migrated guest. > The VMM does it when the guest is created, on both the source and > the destination. The binding is reflected in the guest attestation, > and only the bound agent can install the guest's migration keys. > TDX does it with TDH.SERVTD.BIND (optionally preceded by > TDH.SERVTD.PREBIND), AMD with SNP_LAUNCH_START_EX. Agent binding > needs a KVM interface, but it is part of guest creation, not of the > migration uAPI. > > - Direct negotiation: the platform security component (e.g. the TDX > module) negotiates with its peer itself. QEMU drives it with > KVM_MIGRATE_NEGOTIATE, relays opaque blobs between the source and > destination, and provides an attestation quote when asked. > > - Agent negotiation: negotiation agents on the source and destination > negotiate with each other, then install the migration keys into the > platform security component. QEMU of the migrated guest does not > take part and does not call KVM_MIGRATE_NEGOTIATE. Oh. FWIW I had assumed that for agent negotiation, qemu would still drive the negotiation over its migration buffer using KVM_MIGRATE_NEGOTIATE steps, and the hypervisor through the platform would communicate with the agent. Guess that's kind of silly. But it was a simple way to allow the qemu buffer to be used for it, so the MAs dont' have to initiate their own connection. > - KVM_MIGRATE_NEGOTIATE: the KVM ioctl command that drives direct > negotiation. QEMU calls it repeatedly until it returns "done". It is > not used with agent negotiation. > > - KVM_MIGRATE_BEGIN: the KVM ioctl command that begins the migration > session after the negotiation phase, in both models. It transfers > the initial VM state, such as the VM identity and configuration, > which the destination uses to create the VM. TDX calls it the > "immutable state", and AMD ARG calls it the "guest context". It > requires the migration keys, so it fails if the negotiation phase is > not done yet. > > - QEMU handshake: the early phase Peter mentioned, where the source and > destination QEMUs talk in both directions before migration starts. > It is a QEMU-level transport phase, also used for non-CoCo needs, and > not specific to the negotiation phase. With direct negotiation, the > KVM_MIGRATE_NEGOTIATE blobs are carried over the QEMU handshake. With > agent negotiation, the agents have their own transport. > > Whether a guest uses direct or agent negotiation is decided by > userspace when the guest is created: agent negotiation requires agent > binding. So KVM does not need to decide or report it. > > Notes: > > - MigTD is mentioned here only as an example of agent negotiation. We > do not plan to work on MigTD support upstream for now. Our focus is > direct negotiation via the TDX module. This is also why I did not go > into agent binding details, but it looks like AMD will need it. > > - AMD also has a variant where the negotiation logic runs inside the > migrated guest itself, in its SVSM. If KVM is the channel between > QEMU and the SVSM, I think this is direct negotiation: QEMU drives it > via KVM_MIGRATE_NEGOTIATE, and the SVSM installs the migration key > itself. Serge, is this how you see it? Yes, that's exactly how I see it. Mind you, agent negotiation would also be an option for us. It's just not the path we started down. > # The negotiation phase model > > ## Direct negotiation > > QEMU calls KVM_MIGRATE_NEGOTIATE in a loop on both the source and the > destination. Each call returns what QEMU should do next: > > - send this blob to the peer > - provide an attestation quote > - done. And "cancel/reject" ? > 1. QEMU calls KVM_MIGRATE_NEGOTIATE. The first call may carry a > migration policy, which defines the rules for the migration, e.g. > which destinations are acceptable. Later calls carry the blobs > received from the peer. The policy is opaque to KVM, and its format > is vendor specific. For TDX, it is a JSON document provided by the > TD owner and, optionally, the platform owner. > 2. KVM passes the input to the platform security component and returns > the next action: "send this blob to the peer" or "provide a quote". > 3. QEMU does that, using the QEMU handshake for the peer messages, and > calls KVM_MIGRATE_NEGOTIATE again. > 4. This repeats until KVM_MIGRATE_NEGOTIATE returns "done" on both > sides. > 5. QEMU then calls KVM_MIGRATE_BEGIN. > > The blobs are opaque to QEMU and KVM. > > ## Agent negotiation > > 1. When creating the guest,QEMU binds it to a negotiation agent, > on both the source and the destination. > 2. QEMU asks the negotiation agents to start the negotiation, using > a QEMU<->agent API, which is not defined yet. > 3. The negotiation agents negotiate with each other, using their own > transport, and install the migration keys into the platform > security component. > 4. QEMU learns from the negotiation agent that the negotiation phase > is done, again via the QEMU<->agent API, and calls > KVM_MIGRATE_BEGIN. > > The QEMU<->agent API is not part of the KVM uAPI. So, if every platform is going to have such an API, do we want to have a separate conversation on qemu-devel about a platform agnostic API for that? > The migration policy is the business of the negotiation agent, and > QEMU and KVM do not see it. > > So in both models, KVM_MIGRATE_BEGIN starts the migration. If it is > called before the negotiation phase is done, it fails. > > > > In theory, the session establishment could happen orthogonally (another > > VMM), would we use a vendor error code to signal that > > > I think the ioctl should return both: > > - A generic errno, e.g. -ENOKEY, so QEMU can handle "negotiation not > done" the same way on all platforms. > - The platform-specific status, in a field of the ioctl structure, for > details and debugging. For example, TDX returns > TDX_MIGRATION_DECRYPTION_KEY_NOT_SET, and AMD ARG returns > INVALID_GUEST. For Arm, it could be your UNFINISHED_NEGOTIATION. > > Artem. thanks, -serge