Commit Graph

100060 Commits

Author SHA1 Message Date
Yao Yuan
06270a5863 kvm/tdx: Intoduce WAIT_SYNC/READY Session state
These 2 states are used to manage the session's lifecycle,
to make sure no resource leakage for disconnecting.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
8f83837129 kvm/tdx: Use session's socket for data sending
STREAM socket uses separated socket fd for each
connection, unlike unix datagram socket which
can relies only one socket fd for multi clients.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
b55b95c2a5 kvm/tdx: Introduce TDX_VTPM_TRANS_PROTOCOL_TYPE_SYNC for vTPM Server
Do preparation for accepting the new client, thus server
side is ready for new accepted client's incoming data
transfer.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
b2dae7c30e kvm/tdx: Introduce TDX_VTPM_TRANS_PROTOCOL_TYPE_SYNC for vTPM Client
This new trans_protocol is used for client to pass its role
and session ID (vTPM instance id) to server side, thus
server side can prepare for later data transfer.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yuan Yao
c992aacda0 kvm/tdx: Rename tdx_vtpm_init_base2() to tdx_vtpm_init_base()
Client and server now moves to use new helper function
for initialize base object, replace original tdx_vtpm_init_base()
with new one.

Signed-off-by: Yuan Yao <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
3b4ec1ffef kvm/tdx: Basic STREAM socket support for vTPM Client
Client now works as stub: Just closes connection when data
is received.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
64c33b7242 kmv/tdx: Add reference count support for client session of vTPM Server
The socket Server listening on can accept client now, but
disconnect client immediately when new data is received due
to there's more necessary changes pending.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
2da68cbca4 kvm/tdx: Basic STREAM socket support for vTPM Server
DGRAM socket supporting is dropped from this patch,
only listean() + accept() for STREAM socket.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
418db0865f kvm/tdx: Add STREAM socket supporting for tdx_vtpm_trans_send()
vTPM Server and Client relies on this common helper function
for communicating via STREAM socket.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
618a5ac329 kvm/tdx: Use SocketRecvBuffer for vTPM Client
TDX_VTPM_TRANS_PROTOCOL_MAX_LEN is eliminated
due to SocketRecvBuffer has no limitation on
completed package size.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:57 +02:00
Yao Yuan
970b4e9fea kvm/tdx: Use SocketRecvBuffer for vTPM Server
Peer disconnection is acceptable for STEAM socket,
don't error_report().

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
349f7b8820 kvm/tdx: Introduce SocketRecvBuffer
This is common helper functions to support message boundary
for STREAM socket communication, it also works for
DGRAM socket.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
d4fa41750f kvm/tdx: LOGs for Integration Testing with TDVF
Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
e2c09409f4 kvm/tdx: Enable VMCALL.Service<Query>
Allow query vTPM client/server vmcall service
GUID from guest.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
b15032c507 kvm/tdx: Enable ReceiveMessage for vTPM client
The received message will been cached if no pending
receive message request there.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
3c6dafc8c2 kvm/tdx: Intdroduce Session Data Index for vTPM Server
Sort the data received from VTPM clients be treated
in FIFO mode meanwhile keep using hash table for case
of WaitForRequest with non-null user id.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
2339c7a6dc kvm/tdx: QMP protocol for create/destroy vTPM instance
The vTPM instance lifecycle is not related to TD guest
lifecycle, it's longer than TD guest's lifecycle:

|------------- vTPM instance lifecycle -----------|
  |--guest lifecycle--|       |--guest lifecycle--|
  guest up   guest down       guest up   guest down

The QMP protocol is used for Orchestrator (e.g. libvrt) to
create vTPM instance before the TD guest is deploied to
cloud, or destroy the vTPM instance after the TD guest is
deleted from cloud.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
290e4dbb60 kvm/tdx: Enable ReportStatus for vTPM Server
The session in server side will been re-created
if reportstatus' operation is TDX_VTPM_OPERATION_CREATE
and the session is existed already.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
f9fd280bf3 kvm/tdx: Enable WaitForRequest for vTPM Server
Each client connects to the server is abstracted to one
"Session". Each client has separate data cache to store the
data received from client which have not been handled by the
server.

The separated data cache allows keeping received client's
message even the session is "disconnected".

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
1906c6bb08 kvm/tdx: Enable SendMessage for vTPM client
A simply protocol "TRANS_PROTOCOL" is introduced
for data transfering between vTPM client and server,
the main reason to introduce this to pass vTPM ID
from client side to server side.

To simply the implementation the vTPM ID is carried
every time even it's only necessary for 1st time
communicats with the server side, the vTPM
client/server communication frequency is not high.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
36cb60436e kvm/tdx: Introduce vTPM client/server vmcall service
Register the vTPM client/server vmcall service GUID,
setup basic communication via UNIX datagram socket.

Linux abstract namespace is used for generating the
file path & name for UNIX datagram socket.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
d7851975e9 kvm/tdx: Add userid/path/type parameter for TDX vTPM
New parameters will be used for vTPM vmcall service
initialization

userid: the id of vTPM instance, 2 types allowed:
1. GUID in "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" format
2. plain text <= 16 characters

path: the communication endpoint accepts by QEMU:
e.g "unix:/tmp/abc.sock"

type: the type of vTPM, 2 strings:
"client": indicates it's vTPM client
"server": indicates it's vTPM server

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
4e168d7c15 kvm/tdx: Basic supporting of TDCALL.VMCALL<Service>
Below TDCALL.VMCALL<Service> features are supported:

1. blocking/non-blocking type service call.
2. Event interrupt notify to service caller.
3. timeout for blocking/non-blocking service call,

Each service call request is abstracted to
"TdxVmcallServiceItem", the service implementation
can get use provided API to get cmd/rsp buffer,
set response state and complete the request easily,
without care low level details of the service call.

Also privodes APIs for vmcall service implementation
register, decoups these basic supporting from different
vmcall service implementations.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
fb35cb6e5a kvm/tdx: Refactor tdx_td_notify() to generic helper
vTPM will use this to inject interrupt to guest in
later patch.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
6cb2305e5a io/channel-socket: Support recvmsg() for Unix datagram socket
Support to get remote address from recvmsg(), this allows send
data to multi-clients for connectionless Unix datagram socket.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
069c561bf2 io/channel-socket: Support sendmsg() for Unix datagram socket
Add target address for sendmsg() to support sending data via Unix
datagram socket to remote peer.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
affb22d740 util/qemu-sockets: Export prepare_sockaddr() from qemu-sockets
High level component like IOChannelSocket can reuse this function
to do UnixSocketAddress to sockaddr_un conversion without duplicated
code.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
e848b88b59 util/qemu-sockets: Support creating Unix datagram socket
Allow socket_dgram() creates datagram socket with
SOCK_DGRAM.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Yao Yuan
f1050c8815 util/qemu-sockets: Abstract the address parse function for Unix socket
Abstracted the common part of address parsing to support UNIX datagram
socket.

Signed-off-by: Yao Yuan <yuan.yao@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
1331bb66ee migration/cgs: fix a issue about live migration self check hangs
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
225e6bd582 migration/cgs: fix the downstream mistake in cgs_mig_loadvm_state_setup
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
c3ada4bc28 migration: postcopy support for private pages
Signed-off-by: Wei Wang <wei.w.wang@intel.com>

migration: fix td postcopy migration

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
e6d1beea29 migration: add multifd support for TD guest
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
38dafdee72 migration: default cgs_bmap to shared
Default cgs_bmap to shared, i.e. 0 means shared page and 1 means private
pages. This is to align to the KVM side design. So for the destination,
during the bulk stage, update the cgs_bmap for private pages.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Wei Wang
ea93caa1df softmmu/physmem: fix cgs_bmap allocation
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:56 +02:00
Isaku Yamahata
9994869161 i386/tdx: Support getquote after TD migration
Some state needs to be saved/loaded. Especially get quote inflight
requests. On destination, resend the request.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
2023-11-28 17:14:56 +02:00
Chenyi Qiang
bf1be8526e KVM: invoke the memory region listener when memory attribute converted
Once the hypervisor exits to userspace to convert the page from private
to shared ro vice versa, notify the state change via memory listener so
that other components (e.g. VFIO) can be notified.

Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
2023-11-28 17:14:56 +02:00
Chenyi Qiang
1d88724aef memory: introduce convert_mem_attr() callback in memory listener
UPM (Unmapping guest Private Memory) introduces a new kind of ram memory
region which contains a restricted_fd in its corresponding ramblock. For
such kind of region, it has the concept of memory attribute, i.e. private
memory and shared memory.

When the memory attribute is converted, some operations are necessary in
other components, e.g. in VFIO, the DMA mapping needs to be adjusted.
Introduce a new memory region listener for the attribute conversion so
that other components can register its own manipulation.

Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
2023-11-28 17:14:56 +02:00
Chenyi Qiang
1ecc52f24e Revert "hostmem: Add RamDiscardManager interface in private memfd backend"
This reverts commit 3ef892bf16ce0e6a888ce2c519249fee7561d865.
2023-11-28 17:14:56 +02:00
Chenyi Qiang
43994affd3 Revert "KVM: Notify the state change via RamDiscardListener"
This reverts commit 1d5ee360d6b4c0f4e7538f12c066d15c6faf4c43.
2023-11-28 17:14:56 +02:00
Chenyi Qiang
0ab7f737e4 Revert "hostmem: Add the placeholder for some live migration callbacks"
This reverts commit 52b69740ceaac136b4fe01171e588665825e63b5.
2023-11-28 17:14:55 +02:00
Chenyi Qiang
b4fba14d06 migration/cgs-tdx: fix a argument negative issue
strerror() only accept a positive parameter for the errno.
Reported by Coverity code scan.

Signed-off-by: Chenyi Qiang <chenyi.qiang@intel.com>
2023-11-28 17:14:55 +02:00
Isaku Yamahata
a081f00a2d i386/tdx: fix tdx_getquote_task_cleanup()
Don't call timer_del() when timer isn't initialized. When error happens
in tdx_handle_get_quote_connected(), the function calls
tdx_getquote_task_cleanup() without initializing tdx_get_quote_task::timer.
As a result tdx_getquote_task_cleanup() calls timer_del() for uninitialized
struct QEMUTimer for segv.

Keep track of the timer variable initialized or not, don't call
timer_del() when timer is uninitialized.

Fixes: e971e95e9e ("i386/tdx: setup a timer for the qio channel")
Reported-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Cc: Chenyi Qiang <chenyi.qiang@intel.com>
2023-11-28 17:14:55 +02:00
Xiaocheng Dong
2156f0dc89 pc: fix multiple default machines when machine not specified
The commit of clean up compat machines (d08a7504) unset
alias and is_default only once, but default values are
all true, qemu will fail in multiple default machines.
this patch keep default machine to 7.2 and unset other
machine's alias and is_default.

Signed-off-by: Xiaocheng Dong <xiaocheng.dong@intel.com>
2023-11-28 17:14:55 +02:00
Wei Wang
b747149380 i386/kvm: allow migration to put registers of a TD guest
Some emulated register states need to be migrated, so return in advance
from kvm_arch_put_registers only for debuggable TD.

Signed-off-by: Wei Wang <wei.w.wang@intel.com>
2023-11-28 17:14:55 +02:00
Michael S. Tsirkin
47ec3407be Revert "hw/i386: pass RNG seed via setup_data entry"
This reverts commit 67f7e426e5.

Additionally to the automatic revert, I went over the code
and dropped all mentions of legacy_no_rng_seed manually,
effectively reverting a combination of 2 additional commits:

    commit ffe2d2382e
    Author: Jason A. Donenfeld <Jason@zx2c4.com>
    Date:   Wed Sep 21 11:31:34 2022 +0200

        x86: re-enable rng seeding via SetupData

    commit 3824e25db1
    Author: Gerd Hoffmann <kraxel@redhat.com>
    Date:   Wed Aug 17 10:39:40 2022 +0200

        x86: disable rng seeding via setup_data

Fixes: 67f7e426e5 ("hw/i386: pass RNG seed via setup_data entry")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-28 17:14:55 +02:00
Cornelia Huck
f6b692a9ed pc: clean up compat machines
We can move setting default_cpu_version into the base machine options,
and we need to unset alias and is_default only once.

Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
Message-Id: <20221212152145.124317-3-cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2023-11-28 17:14:55 +02:00
Michael S. Tsirkin
cbccd84d4a Revert "x86: return modified setup_data only if read as memory, not as file"
This reverts commit e935b73508.

Fixes: e935b73508 ("x86: return modified setup_data only if read as memory, not as file")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-28 17:14:55 +02:00
Michael S. Tsirkin
bc0aac1c9c Revert "x86: use typedef for SetupData struct"
This reverts commit eebb38a563.

Fixes: eebb38a563 ("x86: use typedef for SetupData struct")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-28 17:14:55 +02:00
Michael S. Tsirkin
4fff1c5f44 Revert "x86: reinitialize RNG seed on system reboot"
This reverts commit 763a2828bf.

Fixes: 763a2828bf ("x86: reinitialize RNG seed on system reboot")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2023-11-28 17:14:55 +02:00