[PATCH v1 00/18] LIBVIRT: X86: TDX support

Zhenzhong Duan posted 18 patches 8 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20250403102841.3137534-1-zhenzhong.duan@intel.com
There is a newer version of this series
docs/formatdomain.rst             |  63 ++++++++++++++++++
docs/formatdomaincaps.rst         |   1 +
examples/c/misc/event-test.c      |   6 ++
include/libvirt/libvirt-domain.h  |   2 +
src/conf/domain_capabilities.c    |   1 +
src/conf/domain_capabilities.h    |   1 +
src/conf/domain_conf.c            |  82 +++++++++++++++++++++++
src/conf/domain_conf.h            |  21 ++++++
src/conf/domain_validate.c        |  11 ++++
src/conf/schemas/domaincaps.rng   |   9 +++
src/conf/schemas/domaincommon.rng |  41 ++++++++++++
src/conf/virconftypes.h           |   2 +
src/qemu/qemu_capabilities.c      |  38 ++++++++++-
src/qemu/qemu_capabilities.h      |   1 +
src/qemu/qemu_cgroup.c            |   1 +
src/qemu/qemu_command.c           |  54 +++++++++++++++
src/qemu/qemu_driver.c            |   7 ++
src/qemu/qemu_firmware.c          |   1 +
src/qemu/qemu_monitor.c           |  28 +++++++-
src/qemu/qemu_monitor.h           |   2 +-
src/qemu/qemu_monitor_json.c      |   6 +-
src/qemu/qemu_namespace.c         |   1 +
src/qemu/qemu_process.c           | 105 ++++++++++++++++++++++++++++--
src/qemu/qemu_process.h           |   2 +
src/qemu/qemu_validate.c          |  45 +++++++++++++
src/security/security_dac.c       |   2 +
tools/virsh-domain-event.c        |   6 +-
tools/virt-host-validate-common.c |  31 ++++++++-
tools/virt-host-validate-common.h |   1 +
29 files changed, 558 insertions(+), 13 deletions(-)
[PATCH v1 00/18] LIBVIRT: X86: TDX support
Posted by Zhenzhong Duan 8 months, 2 weeks ago
Hi,

This series brings libvirt the x86 TDX support.

* What's TDX?
TDX stands for Trust Domain Extensions which isolates VMs from
the virtual-machine manager (VMM)/hypervisor and any other software on
the platform.

This patchset extends libvirt to support TDX, with which one can start a TDX
guest from high level rather than running qemu directly.

* Misc
As QEMU use a software emulated way to reset guest which isn't supported by TDX
guest for security reason. We simulate reboot for TDX guest by kill and create a
new one in FakeReboot framework.

Complete code can be found at [1], matching qemu code can be found at [2].

There is a 'QGS' element for attestation which isn't in matching qemu[2] yet.
I keep them intentionally as they will be implemented in qemu as extention
series of [2].

* Test
start/stop/reboot/reset with virsh
stop/reboot trigger in guest
stop with on_poweroff=destroy/restart
reboot with on_reboot=destroy/restart

* Patch organization
- patch 1-4:   Support query of TDX capabilities
- patch 5-11:  Add TDX type to launchsecurity framework
- patch 12-17: Add reboot/reset support to TDX guest
- patch 18:    Add docs

TODO:
- add reconnect logic in virsh command

[1] https://github.com/intel/libvirt-tdx/commits/tdx_for_upstream_v1
[2] https://github.com/intel-staging/qemu-tdx/tree/tdx-qemu-upstream-v8

Thanks
Zhenzhong

Changelog:
v1:
- s/virQEMUCapsKVMSupportsSecureGuestINTEL/virQEMUCapsKVMSupportsSecureGuestTDX (Daniel)
- make policy element optional and expose to QEMU directly (Daniel)
- s/qemuProcessSecFakeReboot/qemuProcessFakeRebootViaRecreate (Daniel)
- simplify QGS element schema by supporting only UNIX socket (Daniel)
- add new events VIR_DOMAIN_EVENT_[STOPPED|STARTED] for control plane (Daniel)
- s/quoteGenerationService/quoteGenerationSocket as QEMU
- add virsh reset support

rfcv4:
- add a check to tools/virt-host-validate-qemu.c (Daniel)
- remove check of q35 (Daniel)
- model 'SocktetAddress' QAPI in xml schema (Daniel)
- s/Quote-Generation-Service/quoteGenerationService/ (Daniel)
- define bits in tdx->policy and add validating logic (Daniel)
- presume QEMU choose split kernel irqchip for TDX guest by default (Daniel)
- utilize existing FakeReboot framework to do reboot for TDX guest (Daniel)
- drop patch11 'conf: Add support to keep same domid for hard reboot' (Daniel)
- add test in tests/ to validate parsing and formatting logic (Daniel)
- add doc in docs/formatdomain.rst (Daniel)
- add R-B

rfcv3:
- Change to generate qemu cmdline with -bios
- drop firmware auto match as -bios is used
- add a hard reboot method to reboot TDX guest

rfcv3: https://www.mail-archive.com/devel@lists.libvirt.org/msg00385.html

rfcv2:
- give up using qmp cmd and check TDX directly on host for TDX capabilities.
- use launchsecurity framework to support TDX
- use <os>.<loader> for general loader
- add auto firmware match feature for TDX

A example TDVF fimware description file 70-edk2-x86_64-tdx.json:
{
    "description": "UEFI firmware for x86_64, supporting Intel TDX",
    "interface-types": [
        "uefi"
    ],
    "mapping": {
        "device": "generic",
        "filename": "/usr/share/OVMF/OVMF_CODE-tdx.fd"
    },
    "targets": [
        {
            "architecture": "x86_64",
            "machines": [
                "pc-q35-*"
            ]
        }
    ],
    "features": [
        "intel-tdx",
        "verbose-dynamic"
    ],
    "tags": [

    ]
}

rfcv2: https://www.mail-archive.com/libvir-list@redhat.com/msg219378.html

Zhenzhong Duan (18):
  tools: Secure guest check for Intel in virt-host-validate
  qemu: Check if INTEL Trust Domain Extention support is enabled
  qemu: Add TDX capability
  conf: Expose TDX feature in domain capabilities
  conf: Add tdx as launch security type
  conf: Validate TDX launchSecurity element
    mrConfigId/mrOwner/mrOwnerConfig
  qemu: Add command line and validation for TDX type
  conf: Expose TDX type in domain launch security capability
  qemu: Force special parameters enabled for TDX guest
  conf: Add Intel TDX Quote Generation Service(QGS) support
  qemu: Add command line for TDX Quote Generation Service(QGS)
  qemu: Add FakeReboot support for TDX guest
  qemu: Support reboot command in guest
  qemu: Avoid duplicate FakeReboot for secure guest
  qemu: Send event VIR_DOMAIN_EVENT_[STOPPED|STARTED] during recreation
  qemu: Bypass sending VIR_DOMAIN_EVENT_RESUMED event when TD VM reboot
  qemu: Support domain reset command for TDX guest
  docs: domain: Add documentation for Intel TDX guest

 docs/formatdomain.rst             |  63 ++++++++++++++++++
 docs/formatdomaincaps.rst         |   1 +
 examples/c/misc/event-test.c      |   6 ++
 include/libvirt/libvirt-domain.h  |   2 +
 src/conf/domain_capabilities.c    |   1 +
 src/conf/domain_capabilities.h    |   1 +
 src/conf/domain_conf.c            |  82 +++++++++++++++++++++++
 src/conf/domain_conf.h            |  21 ++++++
 src/conf/domain_validate.c        |  11 ++++
 src/conf/schemas/domaincaps.rng   |   9 +++
 src/conf/schemas/domaincommon.rng |  41 ++++++++++++
 src/conf/virconftypes.h           |   2 +
 src/qemu/qemu_capabilities.c      |  38 ++++++++++-
 src/qemu/qemu_capabilities.h      |   1 +
 src/qemu/qemu_cgroup.c            |   1 +
 src/qemu/qemu_command.c           |  54 +++++++++++++++
 src/qemu/qemu_driver.c            |   7 ++
 src/qemu/qemu_firmware.c          |   1 +
 src/qemu/qemu_monitor.c           |  28 +++++++-
 src/qemu/qemu_monitor.h           |   2 +-
 src/qemu/qemu_monitor_json.c      |   6 +-
 src/qemu/qemu_namespace.c         |   1 +
 src/qemu/qemu_process.c           | 105 ++++++++++++++++++++++++++++--
 src/qemu/qemu_process.h           |   2 +
 src/qemu/qemu_validate.c          |  45 +++++++++++++
 src/security/security_dac.c       |   2 +
 tools/virsh-domain-event.c        |   6 +-
 tools/virt-host-validate-common.c |  31 ++++++++-
 tools/virt-host-validate-common.h |   1 +
 29 files changed, 558 insertions(+), 13 deletions(-)

-- 
2.34.1
Re: [PATCH v1 00/18] LIBVIRT: X86: TDX support
Posted by Peter Krempa via Devel 8 months, 2 weeks ago
On Thu, Apr 03, 2025 at 18:28:23 +0800, Zhenzhong Duan wrote:

[...]

> 
> Zhenzhong Duan (18):
>   tools: Secure guest check for Intel in virt-host-validate
>   qemu: Check if INTEL Trust Domain Extention support is enabled
>   qemu: Add TDX capability
>   conf: Expose TDX feature in domain capabilities
>   conf: Add tdx as launch security type
>   conf: Validate TDX launchSecurity element
>     mrConfigId/mrOwner/mrOwnerConfig
>   qemu: Add command line and validation for TDX type
>   conf: Expose TDX type in domain launch security capability
>   qemu: Force special parameters enabled for TDX guest
>   conf: Add Intel TDX Quote Generation Service(QGS) support
>   qemu: Add command line for TDX Quote Generation Service(QGS)

[1]

>   qemu: Add FakeReboot support for TDX guest
>   qemu: Support reboot command in guest
>   qemu: Avoid duplicate FakeReboot for secure guest
>   qemu: Send event VIR_DOMAIN_EVENT_[STOPPED|STARTED] during recreation
>   qemu: Bypass sending VIR_DOMAIN_EVENT_RESUMED event when TD VM reboot
>   qemu: Support domain reset command for TDX guest
>   docs: domain: Add documentation for Intel TDX guest
> 
>  docs/formatdomain.rst             |  63 ++++++++++++++++++
>  docs/formatdomaincaps.rst         |   1 +
>  examples/c/misc/event-test.c      |   6 ++
>  include/libvirt/libvirt-domain.h  |   2 +
>  src/conf/domain_capabilities.c    |   1 +
>  src/conf/domain_capabilities.h    |   1 +
>  src/conf/domain_conf.c            |  82 +++++++++++++++++++++++
>  src/conf/domain_conf.h            |  21 ++++++
>  src/conf/domain_validate.c        |  11 ++++
>  src/conf/schemas/domaincaps.rng   |   9 +++
>  src/conf/schemas/domaincommon.rng |  41 ++++++++++++
>  src/conf/virconftypes.h           |   2 +
>  src/qemu/qemu_capabilities.c      |  38 ++++++++++-
>  src/qemu/qemu_capabilities.h      |   1 +

I'm seeing a capability being added but it's not detected anywhere.

>  src/qemu/qemu_cgroup.c            |   1 +
>  src/qemu/qemu_command.c           |  54 +++++++++++++++
>  src/qemu/qemu_driver.c            |   7 ++
>  src/qemu/qemu_firmware.c          |   1 +
>  src/qemu/qemu_monitor.c           |  28 +++++++-
>  src/qemu/qemu_monitor.h           |   2 +-
>  src/qemu/qemu_monitor_json.c      |   6 +-
>  src/qemu/qemu_namespace.c         |   1 +
>  src/qemu/qemu_process.c           | 105 ++++++++++++++++++++++++++++--
>  src/qemu/qemu_process.h           |   2 +
>  src/qemu/qemu_validate.c          |  45 +++++++++++++
>  src/security/security_dac.c       |   2 +
>  tools/virsh-domain-event.c        |   6 +-
>  tools/virt-host-validate-common.c |  31 ++++++++-
>  tools/virt-host-validate-common.h |   1 +
>  29 files changed, 558 insertions(+), 13 deletions(-)

Also there are no qemuxmlconftest cases to be seen, while there are
commandline changes [1].

IIUC the qemu patches are not merged yet, but

See commits
0e58c04fc98c93482ce63589bf2b3042e7b5dd6c and
17945b8ec979fcc93232d55d3111cfc363e3cacc

on how to add a variant of capability test data and how the caps dump
looks. See also tests/qemucapabilitiesdata/README.rst

You then can add qemuxmlconftest test cases based on the capability
data:

8a852c3a909f0d11a61e1e3cd3bae89937e3a07c

Note that if you create the capability dump based on a in-development
qemu version (which is acceptable after the patches are merged upstream)
you will be expected to update the capability dump on the same hardware
once the qemu version becomes released:

b0527a8f8e00f30911b6ffc5ac93d9d9bba6bff0
RE: [PATCH v1 00/18] LIBVIRT: X86: TDX support
Posted by Duan, Zhenzhong 8 months, 2 weeks ago

>-----Original Message-----
>From: Peter Krempa <pkrempa@redhat.com>
>Subject: Re: [PATCH v1 00/18] LIBVIRT: X86: TDX support
>
>On Thu, Apr 03, 2025 at 18:28:23 +0800, Zhenzhong Duan wrote:
>
>[...]
>
>>
>> Zhenzhong Duan (18):
>>   tools: Secure guest check for Intel in virt-host-validate
>>   qemu: Check if INTEL Trust Domain Extention support is enabled
>>   qemu: Add TDX capability
>>   conf: Expose TDX feature in domain capabilities
>>   conf: Add tdx as launch security type
>>   conf: Validate TDX launchSecurity element
>>     mrConfigId/mrOwner/mrOwnerConfig
>>   qemu: Add command line and validation for TDX type
>>   conf: Expose TDX type in domain launch security capability
>>   qemu: Force special parameters enabled for TDX guest
>>   conf: Add Intel TDX Quote Generation Service(QGS) support
>>   qemu: Add command line for TDX Quote Generation Service(QGS)
>
>[1]
>
>>   qemu: Add FakeReboot support for TDX guest
>>   qemu: Support reboot command in guest
>>   qemu: Avoid duplicate FakeReboot for secure guest
>>   qemu: Send event VIR_DOMAIN_EVENT_[STOPPED|STARTED] during
>recreation
>>   qemu: Bypass sending VIR_DOMAIN_EVENT_RESUMED event when TD VM
>reboot
>>   qemu: Support domain reset command for TDX guest
>>   docs: domain: Add documentation for Intel TDX guest
>>
>>  docs/formatdomain.rst             |  63 ++++++++++++++++++
>>  docs/formatdomaincaps.rst         |   1 +
>>  examples/c/misc/event-test.c      |   6 ++
>>  include/libvirt/libvirt-domain.h  |   2 +
>>  src/conf/domain_capabilities.c    |   1 +
>>  src/conf/domain_capabilities.h    |   1 +
>>  src/conf/domain_conf.c            |  82 +++++++++++++++++++++++
>>  src/conf/domain_conf.h            |  21 ++++++
>>  src/conf/domain_validate.c        |  11 ++++
>>  src/conf/schemas/domaincaps.rng   |   9 +++
>>  src/conf/schemas/domaincommon.rng |  41 ++++++++++++
>>  src/conf/virconftypes.h           |   2 +
>>  src/qemu/qemu_capabilities.c      |  38 ++++++++++-
>>  src/qemu/qemu_capabilities.h      |   1 +
>
>I'm seeing a capability being added but it's not detected anywhere.
>
>>  src/qemu/qemu_cgroup.c            |   1 +
>>  src/qemu/qemu_command.c           |  54 +++++++++++++++
>>  src/qemu/qemu_driver.c            |   7 ++
>>  src/qemu/qemu_firmware.c          |   1 +
>>  src/qemu/qemu_monitor.c           |  28 +++++++-
>>  src/qemu/qemu_monitor.h           |   2 +-
>>  src/qemu/qemu_monitor_json.c      |   6 +-
>>  src/qemu/qemu_namespace.c         |   1 +
>>  src/qemu/qemu_process.c           | 105 ++++++++++++++++++++++++++++--
>>  src/qemu/qemu_process.h           |   2 +
>>  src/qemu/qemu_validate.c          |  45 +++++++++++++
>>  src/security/security_dac.c       |   2 +
>>  tools/virsh-domain-event.c        |   6 +-
>>  tools/virt-host-validate-common.c |  31 ++++++++-
>>  tools/virt-host-validate-common.h |   1 +
>>  29 files changed, 558 insertions(+), 13 deletions(-)
>
>Also there are no qemuxmlconftest cases to be seen, while there are
>commandline changes [1].
>
>IIUC the qemu patches are not merged yet, but
>
>See commits
>0e58c04fc98c93482ce63589bf2b3042e7b5dd6c and
>17945b8ec979fcc93232d55d3111cfc363e3cacc
>
>on how to add a variant of capability test data and how the caps dump
>looks. See also tests/qemucapabilitiesdata/README.rst
>
>You then can add qemuxmlconftest test cases based on the capability
>data:
>
>8a852c3a909f0d11a61e1e3cd3bae89937e3a07c
>
>Note that if you create the capability dump based on a in-development
>qemu version (which is acceptable after the patches are merged upstream)
>you will be expected to update the capability dump on the same hardware
>once the qemu version becomes released:
>
>b0527a8f8e00f30911b6ffc5ac93d9d9bba6bff0

Thanks for your guidance, I have added test in v2 candidate, see https://github.com/intel/libvirt-tdx/commits/tdx_for_upstream_v2.wip
But I'd like to collect more comments before send v2.

Thanks
Zhenzhong