[RFC PATCH v4 13/36] i386/tdx: Validate TD attributes

2022-05-11 Thread Xiaoyao Li
Validate TD attributes with tdx_caps that fixed-0 bits must be zero and fixed-1 bits must be set. Besides, sanity check the attribute bits that have not been supported by QEMU yet. e.g., debug bit, it will be allowed in the future when debug TD support lands in QEMU. Signed-off-by: Xiaoyao Li

[RFC PATCH v4 17/36] i386/tdx: Parse TDVF metadata for TDX VM

2022-05-11 Thread Xiaoyao Li
TDX cannot support pflash device since it doesn't support read-only memslot and doesn't support emulation. Load TDVF(OVMF) with -bios option for TDs. When boot a TD, besides load TDVF to the address below 4G, it needs parse TDVF metadata. Signed-off-by: Xiaoyao Li --- hw/i386/pc_sysfw.c

[RFC PATCH v4 20/36] i386/tdx: Register a machine_init_done callback for TD

2022-05-11 Thread Xiaoyao Li
Before a TD can run, it needs to - setup/configure TD HOB list; - initialize TDVF into TD's private memory; - initialize TD vcpu state; Register a machine_init_done callback to all those stuff. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 12 1 file changed, 12

[RFC PATCH v4 25/36] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu

2022-05-11 Thread Xiaoyao Li
TDX vcpu needs to be initialized by SEAMCALL(TDH.VP.INIT) and KVM provides vcpu level IOCTL KVM_TDX_INIT_VCPU for it. KVM_TDX_INIT_VCPU needs the address of the HOB as input. Invoke it for each vcpu after HOB list is created. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 18

[RFC PATCH v4 11/36] i386/tdx: Initialize TDX before creating TD vcpus

2022-05-11 Thread Xiaoyao Li
ote, this doesn't address the fact that QEMU may change the CPUID configuration when creating vCPUs, i.e. punts on refactoring QEMU to provide a stable CPUID config prior to kvm_arch_init(). Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c| 9 - target/i386/kvm/kvm.c |

[RFC PATCH v4 18/36] i386/tdx: Skip BIOS shadowing setup

2022-05-11 Thread Xiaoyao Li
TDX guest cannot go to real mode, so just skip the setup of isa-bios. Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 24 +--- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index fdf6af2f6add..17f2252296c5 100644 --- a/hw/i386

[RFC PATCH v4 16/36] i386/tdvf: Introduce function to parse TDVF metadata

2022-05-11 Thread Xiaoyao Li
that is the offset of TDX metadata to the end of firmware file. Select X86_FW_OVMF when TDX is enable to leverage existing functions to parse and search OVMF's GUID-ed structures. Signed-off-by: Isaku Yamahata Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li --- Changes in v4: - rename

[RFC PATCH v4 09/36] KVM: Introduce kvm_arch_pre_create_vcpu()

2022-05-11 Thread Xiaoyao Li
Introduce kvm_arch_pre_create_vcpu(), to perform arch-dependent work prior to create any vcpu. This is for i386 TDX because it needs call TDX_INIT_VM before creating any vcpu. Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 12 include/sysemu/kvm.h | 1 + 2 files changed, 13

[RFC PATCH v4 08/36] i386/tdx: Adjust get_supported_cpuid() for TDX VM

2022-05-11 Thread Xiaoyao Li
needs to be cap'ed by tdx_caps, because KVM uses them to setup XFAM of TD. Introduce tdx_get_supported_cpuid() to adjust the kvm_arch_get_supported_cpuid() for TDX VM. Signed-off-by: Xiaoyao Li --- target/i386/cpu.h | 5 + target/i386/kvm/kvm.c | 4 target/i386/kvm/tdx.c | 44

[RFC PATCH v4 14/36] i386/tdx: Implement user specified tsc frequency

2022-05-11 Thread Xiaoyao Li
Reuse "-cpu,tsc-frequency=" to get user wanted tsc frequency and pass it to KVM_TDX_INIT_VM. Besides, sanity check the tsc frequency to be in the legal range and legal granularity (required by TDX module). Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 8 target/i386

[RFC PATCH v4 15/36] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM

2022-05-11 Thread Xiaoyao Li
TDX only supports readonly for shared memory but not for private memory. In the view of QEMU, it has no idea whether a memslot is used as shared memory of private. Thus just mark kvm_readonly_mem_enabled to false to TDX VM for simplicity. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 9

[RFC PATCH v4 05/36] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context

2022-05-11 Thread Xiaoyao Li
Introduce tdx_kvm_init() and invoke it in kvm_confidential_guest_init() if it's a TDX VM. More initialization will be added later. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 15 ++- target/i386/kvm/meson.build | 2 +- target/i386/kvm/tdx-stub.c | 9

[RFC PATCH v4 12/36] i386/tdx: Wire CPU features up with attributes of TD guest

2022-05-11 Thread Xiaoyao Li
For QEMU VMs, PKS is configured via CPUID_7_0_ECX_PKS and PMU is configured by x86cpu->enable_pmu. Reuse the existing configuration interface for TDX VMs. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/target/i386/

[RFC PATCH v4 06/36] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES

2022-05-11 Thread Xiaoyao Li
M and VCPU) in preparation. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 85 +++ 1 file changed, 85 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 77e33ae01147..68bedbad0ebe 100644 --- a/target/i386/kvm/tdx.c +++ b/t

[RFC PATCH v4 03/36] target/i386: Implement mc->kvm_type() to get VM type

2022-05-11 Thread Xiaoyao Li
dx0,... it parses VM type as KVM_X86_TDX_VM. Otherwise, it's KVM_X86_DEFAULT_VM. Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 6 ++ target/i386/kvm/kvm.c | 30 ++ target/i386/kvm/kvm_i386.h | 1 + 3 files changed, 37 insertions(+) diff --git a

[RFC PATCH v4 10/36] i386/kvm: Move architectural CPUID leaf generation to separate helper

2022-05-11 Thread Xiaoyao Li
From: Sean Christopherson Move the architectural (for lack of a better term) CPUID leaf generation to a separate helper so that the generation code can be reused by TDX, which needs to generate a canonical VM-scoped configuration. Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li

[RFC PATCH v4 19/36] i386/tdx: Don't initialize pc.rom for TDX VMs

2022-05-11 Thread Xiaoyao Li
For TDX, the address below 1MB are entirely general RAM. No need to initialize pc.rom memory region for TDs. Signed-off-by: Xiaoyao Li --- hw/i386/pc.c | 21 - 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5ef20e2071a7

[RFC PATCH v4 04/36] target/i386: Introduce kvm_confidential_guest_init()

2022-05-11 Thread Xiaoyao Li
Introduce a separate function kvm_confidential_guest_init() for SEV (and future TDX). Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 11 ++- target/i386/sev.c | 1 - target/i386/sev.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/target/i386

[RFC PATCH v4 01/36] *** HACK *** linux-headers: Update headers to pull in TDX API changes

2022-05-11 Thread Xiaoyao Li
Pull in recent TDX updates, which are not backwards compatible. It's just to make this series runnable. It will be updated by script scripts/update-linux-headers.sh once TDX support is upstreamed in linux kernel. Signed-off-by: Xiaoyao Li Co-developed-by: Sean Christopherson Signed

[RFC PATCH v4 00/36] TDX QEMU support

2022-05-11 Thread Xiaoyao Li
generation to separate helper i386/tdx: Don't get/put guest state for TDX VMs Xiaoyao Li (30): *** HACK *** linux-headers: Update headers to pull in TDX API changes i386: Introduce tdx-guest object target/i386: Implement mc->kvm_type() to get VM type target/i386: Introd

[RFC PATCH v4 07/36] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object

2022-05-11 Thread Xiaoyao Li
It will need special handling for TDX VMs all around the QEMU. Introduce is_tdx_vm() helper to query if it's a TDX VM. Cache tdx_guest object thus no need to cast from ms->cgs every time. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 13 + target/i386/kvm/tdx.h |

[RFC PATCH v4 02/36] i386: Introduce tdx-guest object

2022-05-11 Thread Xiaoyao Li
and not configurable so far. Signed-off-by: Xiaoyao Li --- configs/devices/i386-softmmu/default.mak | 1 + hw/i386/Kconfig | 5 +++ qapi/qom.json| 14 + target/i386/kvm/meson.build | 2 ++ target/i386/kvm/tdx.c| 40

Re: [PATCH RESEND v1 0/2] i386: Make PIT and PIC the property of common x86 base machine type

2022-04-21 Thread Xiaoyao Li
On 3/10/2022 9:07 PM, Michael S. Tsirkin wrote: On Thu, Mar 10, 2022 at 08:28:09PM +0800, Xiaoyao Li wrote: For PIT, it's straightforward to merge microvm::pit and pc_machine::pit_enabled into x86ms::pit For PIC, move microvm::pic to x86ms:pic, which gives PC machine the ability to dis-/en

Re: [PATCH RESEND v1] trace: Split address space and slot id in trace_kvm_set_user_memory()

2022-04-06 Thread Xiaoyao Li
On 3/10/2022 8:22 PM, Xiaoyao Li wrote: The upper 16 bits of kvm_userspace_memory_region::slot are address space id. Parse it separately in trace_kvm_set_user_memory(). Hi QEMU maintainers, I think this patch is simple and straightforward. Please take your time to look at it. Thanks

Re: [PATCH 2/3] i386: factor out x86_firmware_configure()

2022-04-01 Thread Xiaoyao Li
On 4/1/2022 6:36 PM, Philippe Mathieu-Daudé wrote: On 1/4/22 07:28, Xiaoyao Li wrote: On 4/1/2022 1:08 PM, Gerd Hoffmann wrote:    if (sev_enabled()) { ^^^ Can we remove the SEV check ... +    pc_system_parse_ovmf_flash(ptr, size

Re: [PATCH 2/3] i386: factor out x86_firmware_configure()

2022-03-31 Thread Xiaoyao Li
On 4/1/2022 1:08 PM, Gerd Hoffmann wrote: if (sev_enabled()) { ^^^ Can we remove the SEV check ... +pc_system_parse_ovmf_flash(ptr, size); + +if (sev_enabled()) { ... because we are still checking SEV here. Well, the two checks have

Re: [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-31 Thread Xiaoyao Li
On 3/31/2022 5:00 PM, Daniel P. Berrangé wrote: On Thu, Mar 31, 2022 at 04:51:27PM +0800, Xiaoyao Li wrote: On 3/22/2022 5:27 PM, Daniel P. Berrangé wrote: ... IMHO the AmdSev build for OVMF gets this right by entirely disabling the split OVMF_CODE.fd vs OVMF_VARS.fd, and just having a single

Re: [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-31 Thread Xiaoyao Li
On 3/22/2022 5:27 PM, Daniel P. Berrangé wrote: ... IMHO the AmdSev build for OVMF gets this right by entirely disabling the split OVMF_CODE.fd vs OVMF_VARS.fd, and just having a single OVMF.fd file that is exposed read-only to the guest. This is further represented in

Re: [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-31 Thread Xiaoyao Li
On 3/24/2022 4:35 PM, Gerd Hoffmann wrote: On Tue, Mar 22, 2022 at 01:20:24PM +0100, Gerd Hoffmann wrote: Hi, At the time I did try a gross hack that (IIRC) disabled the rom_reset logic, and munged x86_bios_rom_init so that it would force load it straight at the RAM location. Sounds

Re: [PATCH RESEND v1 0/2] i386: Make PIT and PIC the property of common x86 base machine type

2022-03-24 Thread Xiaoyao Li
On 3/10/2022 9:07 PM, Michael S. Tsirkin wrote: On Thu, Mar 10, 2022 at 08:28:09PM +0800, Xiaoyao Li wrote: For PIT, it's straightforward to merge microvm::pit and pc_machine::pit_enabled into x86ms::pit For PIC, move microvm::pic to x86ms:pic, which gives PC machine the ability to dis-/en

Re: [RFC PATCH v3 12/36] i386/tdx: Add property sept-ve-disable for tdx-guest object

2022-03-24 Thread Xiaoyao Li
On 3/24/2022 5:37 PM, Gerd Hoffmann wrote: Hi, #VE can be triggered in various situations. e.g., CPUID on some leaves, and RD/WRMSR on some MSRs. #VE on pending page is just one of the sources, Linux just wants to disable this kind of #VE since it wants to prevent unexpected #VE during

Re: [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-24 Thread Xiaoyao Li
On 3/24/2022 3:58 PM, Gerd Hoffmann wrote: Hi, Well, if persistent vars are not supported anyway there is little reason to split the firmware into CODE and VARS files. You can use just use OVMF.fd with a single pflash device. libvirt recently got support for that. Agreed. The purpose

Re: [RFC PATCH v3 12/36] i386/tdx: Add property sept-ve-disable for tdx-guest object

2022-03-24 Thread Xiaoyao Li
On 3/24/2022 3:57 PM, Gerd Hoffmann wrote: On Thu, Mar 24, 2022 at 02:52:10PM +0800, Xiaoyao Li wrote: On 3/22/2022 5:02 PM, Gerd Hoffmann wrote: On Thu, Mar 17, 2022 at 09:58:49PM +0800, Xiaoyao Li wrote: Add sept-ve-disable property for tdx-guest object. It's used to configure bit 28 of TD

Re: [RFC PATCH v3 12/36] i386/tdx: Add property sept-ve-disable for tdx-guest object

2022-03-24 Thread Xiaoyao Li
On 3/22/2022 5:02 PM, Gerd Hoffmann wrote: On Thu, Mar 17, 2022 at 09:58:49PM +0800, Xiaoyao Li wrote: Add sept-ve-disable property for tdx-guest object. It's used to configure bit 28 of TD attributes. What is this? It seems this bit doesn't show up in the public spec yet. Bit 28

Re: [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-24 Thread Xiaoyao Li
On 3/22/2022 5:29 PM, Daniel P. Berrangé wrote: On Tue, Mar 22, 2022 at 10:21:41AM +0100, Gerd Hoffmann wrote: Hi, If you don't need a pflash device, don't use it: simply map your nvram region as ram in your machine. No need to clutter the pflash model like that. Using the pflash device

Re: [RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-21 Thread Xiaoyao Li
On 3/18/2022 10:07 PM, Philippe Mathieu-Daudé wrote: Hi, On 17/3/22 14:58, Xiaoyao Li wrote: TDX VM needs to boot with Trust Domain Virtual Firmware (TDVF). Unlike that OVMF is mapped as rom device, TDVF needs to be mapped as private memory. This is because TDX architecture doesn't provide

Re: [RFC PATCH v3 16/36] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM

2022-03-21 Thread Xiaoyao Li
On 3/19/2022 1:11 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:58:53PM +0800, Xiaoyao Li wrote: TDX only supports readonly for shared memory but not for private memory. In the view of QEMU, it has no idea whether a memslot is used by shared memory of private. Thus just mark

Re: [RFC PATCH v3 09/36] KVM: Introduce kvm_arch_pre_create_vcpu()

2022-03-21 Thread Xiaoyao Li
On 3/19/2022 12:56 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:58:46PM +0800, Xiaoyao Li wrote: Introduce kvm_arch_pre_create_vcpu(), to perform arch-dependent work prior to create any vcpu. This is for i386 TDX because it needs call TDX_INIT_VM before creating any vcpu. Signed-off

Re: [RFC PATCH v3 27/36] i386/tdx: Disable SMM for TDX VMs

2022-03-21 Thread Xiaoyao Li
On 3/17/2022 9:59 PM, Xiaoyao Li wrote: TDX doesn't support SMM and VMM cannot emulate SMM for TDX VMs because VMM cannot manipulate TDX VM's memory. Disable SMM for TDX VMs and error out if user requests to enable SMM. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 13

Re: [RFC PATCH v3 06/36] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES

2022-03-21 Thread Xiaoyao Li
On 3/18/2022 10:08 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:58:43PM +0800, Xiaoyao Li wrote: diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index e3b94373b316..bed337e5ba18 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -14,10 +14,77 @@ #include

Re: [RFC PATCH v3 18/36] i386/tdvf: Introduce function to parse TDVF metadata

2022-03-21 Thread Xiaoyao Li
On 3/19/2022 1:19 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:58:55PM +0800, Xiaoyao Li wrote: diff --git a/hw/i386/tdvf.c b/hw/i386/tdvf.c new file mode 100644 index ..02da1d2c12dd --- /dev/null +++ b/hw/i386/tdvf.c @@ -0,0 +1,196 @@ +/* + * SPDX-License-Identifier: GPL

Re: [RFC PATCH v3 33/36] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() for TDs

2022-03-21 Thread Xiaoyao Li
On 3/19/2022 1:31 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:59:10PM +0800, Xiaoyao Li wrote: For TDs, only MSR_IA32_UCODE_REV in kvm_init_msrs() can be configured by VMM, while the features enumerated/controlled by other MSRs except MSR_IA32_UCODE_REV in kvm_init_msrs

Re: [RFC PATCH v3 08/36] i386/tdx: Adjust get_supported_cpuid() for TDX VM

2022-03-20 Thread Xiaoyao Li
On 3/19/2022 12:55 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:58:45PM +0800, Xiaoyao Li wrote: ... +void tdx_get_supported_cpuid(uint32_t function, uint32_t index, int reg, + uint32_t *ret) +{ +switch (function) { +case 1: +if (reg

Re: [RFC PATCH v3 05/36] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context

2022-03-20 Thread Xiaoyao Li
On 3/18/2022 10:07 AM, Isaku Yamahata wrote: On Thu, Mar 17, 2022 at 09:58:42PM +0800, Xiaoyao Li wrote: Introduce tdx_kvm_init() and invoke it in kvm_confidential_guest_init() if it's a TDX VM. More initialization will be added later. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c

[RFC PATCH v3 31/36] hw/i386: add option to forcibly report edge trigger in acpi tables

2022-03-17 Thread Xiaoyao Li
From: Isaku Yamahata When level trigger isn't supported on x86 platform, forcibly report edge trigger in acpi tables. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- hw/i386/acpi-build.c | 99 --- hw/i386/acpi-common.c | 50

[RFC PATCH v3 29/36] i386/tdx: Don't allow system reset for TDX VMs

2022-03-17 Thread Xiaoyao Li
TDX CPU state is protected and thus vcpu state cann't be reset by VMM. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4a8b6e2c8797..ccbafb4ca183 100644 --- a/target/i386

[RFC PATCH v3 28/36] i386/tdx: Disable PIC for TDX VMs

2022-03-17 Thread Xiaoyao Li
and error out if user wants PIC. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index ec6f5d7a2e48..6e9cb7178d25 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -321,6 +321,13

[RFC PATCH v3 35/36] i386/tdx: Don't get/put guest state for TDX VMs

2022-03-17 Thread Xiaoyao Li
Christopherson Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 9c7eb3dea0a8..dafb63d4d2d7 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4395,6 +4395,11 @@ int

[RFC PATCH v3 20/36] i386/tdx: Get and store the mem_ptr of TDVF firmware

2022-03-17 Thread Xiaoyao Li
QEMU needs to later copy the context of TDVF firmware to guest private memory. So get the mem_ptr of CODE.fd and VARS.fd and store them in tdx_guest object. Signed-off-by: Xiaoyao Li --- hw/i386/pc_sysfw.c | 20 include/hw/i386/tdvf.h | 4 target/i386/kvm

[RFC PATCH v3 27/36] i386/tdx: Disable SMM for TDX VMs

2022-03-17 Thread Xiaoyao Li
TDX doesn't support SMM and VMM cannot emulate SMM for TDX VMs because VMM cannot manipulate TDX VM's memory. Disable SMM for TDX VMs and error out if user requests to enable SMM. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 13 + 1 file changed, 13 insertions(+) diff

[RFC PATCH v3 33/36] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() for TDs

2022-03-17 Thread Xiaoyao Li
For TDs, only MSR_IA32_UCODE_REV in kvm_init_msrs() can be configured by VMM, while the features enumerated/controlled by other MSRs except MSR_IA32_UCODE_REV in kvm_init_msrs() are not under control of VMM. Only configure MSR_IA32_UCODE_REV for TDs. Signed-off-by: Xiaoyao Li --- target/i386

[RFC PATCH v3 19/36] i386/tdx: Parse TDVF metadata for TDX VM

2022-03-17 Thread Xiaoyao Li
) are provided, metadata is located in CODE.fd, which means pflash[0]. So parse TDVF on plash[0]. Signed-off-by: Xiaoyao Li --- hw/i386/pc_sysfw.c | 21 ++--- target/i386/kvm/tdx-stub.c | 5 + target/i386/kvm/tdx.c | 4 target/i386/kvm/tdx.h | 4 4

[RFC PATCH v3 26/36] i386/tdx: Finalize TDX VM

2022-03-17 Thread Xiaoyao Li
Invoke KVM_TDX_FINALIZE_VM to finalize the TD's measurement and make the TD vCPUs runnable once machine initialization is complete. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index

[RFC PATCH v3 32/36] i386/tdx: Don't synchronize guest tsc for TDs

2022-03-17 Thread Xiaoyao Li
From: Isaku Yamahata TSC of TDs is not accessible and KVM doesn't allow access of MSR_IA32_TSC for TDs. To avoid the assert() in kvm_get_tsc, make kvm_synchronize_all_tsc() noop for TDs, Signed-off-by: Isaku Yamahata Reviewed-by: Connor Kuehl Signed-off-by: Xiaoyao Li --- target/i386/kvm

[RFC PATCH v3 17/36] pflash_cfi01/tdx: Introduce ram_mode of pflash for TDVF

2022-03-17 Thread Xiaoyao Li
the firmware as RAM. Note, this implies two things: 1. TDVF (OVMF) is not read-only (write-protected). 2. It doesn't support non-volatile UEFI variables as what pflash supports that the change to non-volatile UEFI variables won't get synced back to backend vars.fd file. Signed-off-by: Xiaoyao Li

[RFC PATCH v3 30/36] hw/i386: add eoi_intercept_unsupported member to X86MachineState

2022-03-17 Thread Xiaoyao Li
. Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 1 + include/hw/i386/x86.h | 1 + target/i386/kvm/tdx.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 10a88faf4c0e..03101f1ba1dc 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1347,6 +1347,7

[RFC PATCH v3 25/36] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION

2022-03-17 Thread Xiaoyao Li
From: Isaku Yamahata TDVF firmware (CODE and VARS) needs to be added/copied to TD's private memory via KVM_TDX_INIT_MEM_REGION, as well as TD HOB and TEMP memory. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 18 ++ 1 file changed, 18

[RFC PATCH v3 15/36] i386/tdx: Implement user specified tsc frequency

2022-03-17 Thread Xiaoyao Li
Reuse "-cpu,tsc-frequency=" to get user wanted tsc frequency and pass it to KVM_TDX_INIT_VM. Besides, sanity check the tsc frequency to be in the legal range and legal granularity (required by TDX module). Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 8 target/i386

[RFC PATCH v3 23/36] i386/tdx: Create the TD HOB list upon machine init done

2022-03-17 Thread Xiaoyao Li
-by: Isaku Yamahata Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li --- hw/i386/meson.build | 2 +- hw/i386/tdvf-hob.c| 212 ++ hw/i386/tdvf-hob.h| 25 + hw/i386/uefi.h| 198

[RFC PATCH v3 24/36] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu

2022-03-17 Thread Xiaoyao Li
TDX vcpu needs to be initialized by SEAMCALL(TDH.VP.INIT) and KVM provides vcpu level IOCTL KVM_TDX_INIT_VCPU for it. KVM_TDX_INIT_VCPU needs the address of the HOB as input. Invoke it for each vcpu after HOB list is created. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 18

[RFC PATCH v3 34/36] i386/tdx: Skip kvm_put_apicbase() for TDs

2022-03-17 Thread Xiaoyao Li
KVM doesn't allow wirting to MSR_IA32_APICBASE for TDs. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 5 + 1 file changed, 5 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 480c05d6c969..9c7eb3dea0a8 100644 --- a/target/i386/kvm/kvm.c +++ b/target

[RFC PATCH v3 13/36] i386/tdx: Wire CPU features up with attributes of TD guest

2022-03-17 Thread Xiaoyao Li
For QEMU VMs, PKS is configured via CPUID_7_0_ECX_PKS and PMU is configured by x86cpu->enable_pmu. Reuse the existing configuration interface for TDX VMs. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 13 + 1 file changed, 13 insertions(+) diff --git a/target/i386/kvm/td

[RFC PATCH v3 21/36] i386/tdx: Track mem_ptr for each firmware entry of TDVF

2022-03-17 Thread Xiaoyao Li
, specifically starting from 0x80 (8M) Signed-off-by: Xiaoyao Li --- include/hw/i386/tdvf.h | 5 + target/i386/kvm/tdx.c | 42 ++ 2 files changed, 47 insertions(+) diff --git a/include/hw/i386/tdvf.h b/include/hw/i386/tdvf.h index 773bd39a3bff

[RFC PATCH v3 22/36] i386/tdx: Track RAM entries for TDX VM

2022-03-17 Thread Xiaoyao Li
these ranges will be ADD'ed before TD runs and no need to be accepted runtime. The TdxRamEntries[] are later used to setup the memory TD resource HOB that passes memory info from QEMU to TDVF. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 99

[RFC PATCH v3 36/36] docs: Add TDX documentation

2022-03-17 Thread Xiaoyao Li
Add docs/system/i386/tdx.rst for TDX support, and add tdx in confidential-guest-support.rst Signed-off-by: Xiaoyao Li --- docs/system/confidential-guest-support.rst | 1 + docs/system/i386/tdx.rst | 103 + docs/system/target-i386.rst| 1

[RFC PATCH v3 06/36] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES

2022-03-17 Thread Xiaoyao Li
M and VCPU) in preparation. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 71 +++ 1 file changed, 71 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index e3b94373b316..bed337e5ba18 100644 --- a/target/i386/kvm/tdx.c +++ b/targe

[RFC PATCH v3 16/36] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM

2022-03-17 Thread Xiaoyao Li
KVM while TDX wants to reuse pflash interface to load TDVF (as OVMF). Excuse TDX VM for readonly check in pflash. Signed-off-by: Xiaoyao Li --- hw/i386/pc_sysfw.c| 2 +- target/i386/kvm/tdx.c | 9 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/hw/i386/pc_sysfw.c b/hw

[RFC PATCH v3 18/36] i386/tdvf: Introduce function to parse TDVF metadata

2022-03-17 Thread Xiaoyao Li
that is the offset of TDX metadata to the end of firmware file. Select X86_FW_OVMF when TDX is enable to leverage existing functions to parse and search OVMF's GUID-ed structures. Signed-off-by: Isaku Yamahata Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li --- hw/i386/Kconfig| 1 + hw

[RFC PATCH v3 14/36] i386/tdx: Validate TD attributes

2022-03-17 Thread Xiaoyao Li
Validate TD attributes with tdx_caps that fixed-0 bits must be zero and fixed-1 bits must be set. Besides, sanity check the attribute bits that have not been supported by QEMU yet. e.g., debug bit, that it will be allowed in the future when debug TD support lands in QEMU. Signed-off-by: Xiaoyao

[RFC PATCH v3 05/36] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context

2022-03-17 Thread Xiaoyao Li
Introduce tdx_kvm_init() and invoke it in kvm_confidential_guest_init() if it's a TDX VM. More initialization will be added later. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 15 ++- target/i386/kvm/meson.build | 2 +- target/i386/kvm/tdx-stub.c | 9

[RFC PATCH v3 11/36] i386/tdx: Initialize TDX before creating TD vcpus

2022-03-17 Thread Xiaoyao Li
ote, this doesn't address the fact that QEMU may change the CPUID configuration when creating vCPUs, i.e. punts on refactoring QEMU to provide a stable CPUID config prior to kvm_arch_init(). Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c| 9 ++- target/i386/kvm/kvm.c |

[RFC PATCH v3 12/36] i386/tdx: Add property sept-ve-disable for tdx-guest object

2022-03-17 Thread Xiaoyao Li
Add sept-ve-disable property for tdx-guest object. It's used to configure bit 28 of TD attributes. Signed-off-by: Xiaoyao Li --- qapi/qom.json | 5 - target/i386/kvm/tdx.c | 24 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b

[RFC PATCH v3 00/36] TDX QEMU support

2022-03-17 Thread Xiaoyao Li
guest tsc for TDs Sean Christopherson (2): i386/kvm: Move architectural CPUID leaf generation to separate helper i386/tdx: Don't get/put guest state for TDX VMs Xiaoyao Li (30): *** HACK *** linux-headers: Update headers to pull in TDX API changes i386: Introduce tdx-guest object target

[RFC PATCH v3 10/36] i386/kvm: Move architectural CPUID leaf generation to separate helper

2022-03-17 Thread Xiaoyao Li
From: Sean Christopherson Move the architectural (for lack of a better term) CPUID leaf generation to a separate helper so that the generation code can be reused by TDX, which needs to generate a canonical VM-scoped configuration. Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li

[RFC PATCH v3 07/36] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object

2022-03-17 Thread Xiaoyao Li
It will need special handling for TDX VMs all around the QEMU. Introduce is_tdx_vm() helper to query if it's a TDX VM. Cache tdx_guest object thus no need to cast from ms->cgs every time. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 10 ++ target/i386/kvm/tdx.h |

[RFC PATCH v3 09/36] KVM: Introduce kvm_arch_pre_create_vcpu()

2022-03-17 Thread Xiaoyao Li
Introduce kvm_arch_pre_create_vcpu(), to perform arch-dependent work prior to create any vcpu. This is for i386 TDX because it needs call TDX_INIT_VM before creating any vcpu. Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c| 7 +++ include/sysemu/kvm.h | 1 + target/arm/kvm64.c

[RFC PATCH v3 08/36] i386/tdx: Adjust get_supported_cpuid() for TDX VM

2022-03-17 Thread Xiaoyao Li
needs to be caped by tdx_caps, because KVM uses them to setup XFAM of TD. Introduce tdx_get_supported_cpuid() to adjust the kvm_arch_get_supported_cpuid() for TDX VM. Signed-off-by: Xiaoyao Li --- target/i386/cpu.h | 5 + target/i386/kvm/kvm.c | 4 target/i386/kvm/tdx.c | 39

[RFC PATCH v3 03/36] target/i386: Implement mc->kvm_type() to get VM type

2022-03-17 Thread Xiaoyao Li
dx0,... it parses VM type as KVM_X86_TDX_VM. Otherwise, it's KVM_X86_DEFAULT_VM. Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 6 ++ target/i386/kvm/kvm.c | 30 ++ target/i386/kvm/kvm_i386.h | 1 + 3 files changed, 37 insertions(+) diff --git a

[RFC PATCH v3 01/36] *** HACK *** linux-headers: Update headers to pull in TDX API changes

2022-03-17 Thread Xiaoyao Li
Pull in recent TDX updates, which are not backwards compatible. It's just to make this series runnable. It will be updated by script scripts/update-linux-headers.sh once TDX support is upstreamed in linux kernel. Signed-off-by: Xiaoyao Li Co-developed-by: Sean Christopherson Signed

[RFC PATCH v3 02/36] i386: Introduce tdx-guest object

2022-03-17 Thread Xiaoyao Li
and not configurable so far. Signed-off-by: Xiaoyao Li --- configs/devices/i386-softmmu/default.mak | 1 + hw/i386/Kconfig | 5 +++ qapi/qom.json| 14 + target/i386/kvm/meson.build | 2 ++ target/i386/kvm/tdx.c| 40

[RFC PATCH v3 04/36] target/i386: Introduce kvm_confidential_guest_init()

2022-03-17 Thread Xiaoyao Li
Introduce a separate function kvm_confidential_guest_init() for SEV (and future TDX). Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 11 ++- target/i386/sev.c | 1 - target/i386/sev.h | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/target/i386

Re: [PATCH RESEND v1 0/2] i386: Make PIT and PIC the property of common x86 base machine type

2022-03-10 Thread Xiaoyao Li
On 3/10/2022 9:07 PM, Michael S. Tsirkin wrote: On Thu, Mar 10, 2022 at 08:28:09PM +0800, Xiaoyao Li wrote: For PIT, it's straightforward to merge microvm::pit and pc_machine::pit_enabled into x86ms::pit For PIC, move microvm::pic to x86ms:pic, which gives PC machine the ability to dis-/en

[PATCH RESEND v1 0/2] i386: Make PIT and PIC the property of common x86 base machine type

2022-03-10 Thread Xiaoyao Li
to 2048c4eba2b4 ("Merge remote-tracking branch 'remotes/philmd/tags/pmbus-20220308' into staging") Xiaoyao Li (2): hw/i386: Make pit a property of common x86 base machine type hw/i386: Make pic a property of common x86 base machine type hw/i386/microvm.c

[PATCH RESEND v1] trace: Split address space and slot id in trace_kvm_set_user_memory()

2022-03-10 Thread Xiaoyao Li
The upper 16 bits of kvm_userspace_memory_region::slot are address space id. Parse it separately in trace_kvm_set_user_memory(). Signed-off-by: Xiaoyao Li --- Resend: - rebase to 2048c4eba2b4 ("Merge remote-tracking branch 'remotes/philmd/tags/pmbus-20220308' into staging") --- acc

[PATCH RESEND v1 2/2] hw/i386: Make pic a property of common x86 base machine type

2022-03-10 Thread Xiaoyao Li
x86 machine type. Hence all x86 machines, including microvm, can disable it. Signed-off-by: Xiaoyao Li Reviewed-by: Sergio Lopez --- hw/i386/microvm.c | 27 +-- hw/i386/pc_piix.c | 4 +++- hw/i386/pc_q35.c | 4 +++- hw/i386/x86.c | 25

[PATCH RESEND v1 1/2] hw/i386: Make pit a property of common x86 base machine type

2022-03-10 Thread Xiaoyao Li
Both pc and microvm have pit property individually. Let's just make it the property of common x86 base machine type. Signed-off-by: Xiaoyao Li Reviewed-by: Sergio Lopez --- hw/i386/microvm.c | 27 +-- hw/i386/pc.c | 24 +++- hw

Re: [PATCH v1 0/2] i386: Make PIT and PIC the property of common x86 base machine type

2022-02-14 Thread Xiaoyao Li
ping. On 1/11/2022 3:35 PM, Xiaoyao Li wrote: For PIT, it's straightforward to merge microvm::pit and pc_machine::pit_enabled into x86ms::pit For PIC, move microvm::pic to x86ms:pic, which gives PC machine the ability to dis-/en-able PIC and it's the preparation for future TDX support

Re: [PATCH] trace: Split address space and slot id in trace_kvm_set_user_memory()

2022-02-14 Thread Xiaoyao Li
kindly ping. On 1/4/2022 10:35 AM, Xiaoyao Li wrote: The upper 16 bits of kvm_userspace_memory_region::slot are address space id. Parse it separately in trace_kvm_set_user_memory(). Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c| 5 +++-- accel/kvm/trace-events | 2 +- 2 files

Re: [RFC PATCH v2 20/44] i386/tdx: Parse tdx metadata and store the result into TdxGuestState

2022-01-25 Thread Xiaoyao Li
On 1/25/2022 3:42 PM, Gerd Hoffmann wrote: Regarding what interface should be used to load TDVF, there are three options: 1) pflash: the same as how we load OVMF. Suppose TDVF support will finally get into OVMF, using this interface, it's full compatible with normal VMs. No change

Re: [RFC PATCH v2 20/44] i386/tdx: Parse tdx metadata and store the result into TdxGuestState

2022-01-23 Thread Xiaoyao Li
On 1/10/2022 7:01 PM, Gerd Hoffmann wrote: Regarding pflash itself, the read-only KVM memslot is required for it. Otherwise pflash cannot work as a "ROMD device" (= you can't flip it back and forth between ROM mode and programming (MMIO) mode). We don't need Read-only mode for TDVF so far. If

Re: [PATCH v1 1/2] hw/i386: Make pit a property of common x86 base machine type

2022-01-11 Thread Xiaoyao Li
+ Paolo On 1/11/2022 3:35 PM, Xiaoyao Li wrote: Both pc and microvm have pit property individually. Let's just make it the property of common x86 base machine type. Signed-off-by: Xiaoyao Li --- hw/i386/microvm.c | 27 +-- hw/i386/pc.c | 24

Re: [PATCH v1 2/2] hw/i386: Make pic a property of common x86 base machine type

2022-01-11 Thread Xiaoyao Li
+ Paolo On 1/11/2022 3:35 PM, Xiaoyao Li wrote: Legacy PIC (8259) cannot be supported for TDX guests since TDX module doesn't allow directly interrupt injection. Using posted interrupts for the PIC is not a viable option as the guest BIOS/kernel will not do EOI for PIC IRQs, i.e. will leave

[PATCH v1 2/2] hw/i386: Make pic a property of common x86 base machine type

2022-01-10 Thread Xiaoyao Li
x86 machine type. Hence all x86 machines, including microvm, can disable it. Signed-off-by: Xiaoyao Li --- hw/i386/microvm.c | 27 +-- hw/i386/pc_piix.c | 4 +++- hw/i386/pc_q35.c | 4 +++- hw/i386/x86.c | 25

[PATCH v1 0/2] i386: Make PIT and PIC the property of common x86 base machine type

2022-01-10 Thread Xiaoyao Li
For PIT, it's straightforward to merge microvm::pit and pc_machine::pit_enabled into x86ms::pit For PIC, move microvm::pic to x86ms:pic, which gives PC machine the ability to dis-/en-able PIC and it's the preparation for future TDX support. Xiaoyao Li (2): hw/i386: Make pit a property

[PATCH v1 1/2] hw/i386: Make pit a property of common x86 base machine type

2022-01-10 Thread Xiaoyao Li
Both pc and microvm have pit property individually. Let's just make it the property of common x86 base machine type. Signed-off-by: Xiaoyao Li --- hw/i386/microvm.c | 27 +-- hw/i386/pc.c | 24 +++- hw/i386/x86.c | 25

Re: [RFC PATCH v2 20/44] i386/tdx: Parse tdx metadata and store the result into TdxGuestState

2022-01-10 Thread Xiaoyao Li
On 1/10/2022 7:01 PM, Gerd Hoffmann wrote: If you go without pflash, then you likely will not have a standards-conformant UEFI variable store. (Unless you reimplement the variable arch protocols in edk2 on top of something else than the Fault Tolerant Write and Firmware Volume Block protocols.)

Re: [RFC PATCH v2 06/44] hw/i386: Introduce kvm-type for TDX guest

2022-01-10 Thread Xiaoyao Li
On 1/10/2022 7:18 PM, Daniel P. Berrangé wrote: On Wed, Nov 24, 2021 at 03:31:13PM +0800, Xiaoyao Li wrote: On 8/26/2021 6:22 PM, Gerd Hoffmann wrote: On Wed, Jul 07, 2021 at 05:54:36PM -0700, isaku.yamah...@gmail.com wrote: From: Xiaoyao Li Introduce a machine property, kvm-type, to allow

Re: [RFC PATCH v2 20/44] i386/tdx: Parse tdx metadata and store the result into TdxGuestState

2022-01-06 Thread Xiaoyao Li
On 1/7/2022 12:06 AM, Laszlo Ersek wrote: On 01/04/22 14:08, Xiaoyao Li wrote: + Laszlo, Regarding laoding TDVF as pflash, I have some questions: - pflash requires KVM to support readonly mmeory. However, for TDX, it doesn't support readonly memory. Is it a must? or we can make an exception

Re: [RFC PATCH v2 20/44] i386/tdx: Parse tdx metadata and store the result into TdxGuestState

2022-01-04 Thread Xiaoyao Li
On 8/26/2021 7:18 PM, Gerd Hoffmann wrote: +int load_tdvf(const char *filename) +{ +for_each_fw_entry(fw, entry) { +if (entry->address < x86ms->below_4g_mem_size || +entry->address > 4 * GiB) { +tdvf_init_ram_memory(ms, entry); +} else { +

[PATCH] sysemu: Cleanup qemu_run_machine_init_done_notifiers()

2022-01-03 Thread Xiaoyao Li
Remove qemu_run_machine_init_done_notifiers() since no implementation and user. Signed-off-by: Xiaoyao Li --- include/sysemu/sysemu.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 8fae667172ac..b9421e03ffdd 100644 --- a/include/sysemu

<    3   4   5   6   7   8   9   >