[PATCH v2 8/8] target/i386/intel-pt: Access MSR_IA32_RTIT_ADDRn based on guest CPUID configuration

2022-08-08 Thread Xiaoyao Li
KVM only allows userspace to access legal number of MSR_IA32_RTIT_ADDRn, which is enumrated by guest's CPUID(0x14,0x1):EAX[2:0], i.e., env->features[FEAT_14_1_EAX] & INTEL_PT_ADDR_RANGES_NUM_MASK Signed-off-by: Xiaoyao Li --- target/i386/cpu.h | 2 ++ target/i386/kvm/kvm.c | 8

[PATCH v2 1/8] target/i386: Print CPUID subleaf info for unsupported feature

2022-08-08 Thread Xiaoyao Li
Some CPUID leaves have meaningful subleaf index. Print the subleaf info in feature_word_description for CPUID features. Signed-off-by: Xiaoyao Li Reviewed-by: Eduardo Habkost --- target/i386/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b

[PATCH v2 7/8] target/i386/intel-pt: Define specific PT feature set for IceLake-server and Snowridge

2022-08-08 Thread Xiaoyao Li
For IceLake-server, it's just the same as using the default PT feature set since the default one is exact taken from ICX. For Snowridge, define it according to real SNR silicon capabilities. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 18 ++ 1 file changed, 18 insertions

[PATCH v2 2/8] target/i386/intel-pt: Fix INTEL_PT_ADDR_RANGES_NUM_MASK

2022-08-08 Thread Xiaoyao Li
Per Intel SDM, bits 2:0 of CPUID(0x14,0x1).EAX indicate the number of address ranges for INTEL-PT. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f9646e16b872..fa02910ce811 100644

Re: [PATCH v1 00/40] TDX QEMU support

2022-08-04 Thread Xiaoyao Li
On 8/4/2022 1:44 AM, Daniel P. Berrangé wrote: On Tue, Aug 02, 2022 at 06:55:48PM +0800, Xiaoyao Li wrote: On 8/2/2022 5:49 PM, Daniel P. Berrangé wrote: On Tue, Aug 02, 2022 at 03:47:10PM +0800, Xiaoyao Li wrote: - CPU model We cannot create a TD with arbitrary CPU model like what

Re: [PATCH v1 08/40] i386/tdx: Adjust the supported CPUID based on TDX restrictions

2022-08-03 Thread Xiaoyao Li
On 8/3/2022 3:33 PM, Chenyi Qiang wrote: On 8/2/2022 3:47 PM, Xiaoyao Li wrote: According to Chapter "CPUID Virtualization" in TDX module spec, CPUID bits of TD can be classified into 6 types: 1 | As

Re: [PULL 9/9] hw/i386: pass RNG seed via setup_data entry

2022-08-02 Thread Xiaoyao Li
On 8/2/2022 11:13 PM, Jason A. Donenfeld wrote: Hi Xiaoyao, On Tue, Aug 2, 2022 at 5:06 PM Jason A. Donenfeld wrote: Hi Xiaoyao, On Tue, Aug 02, 2022 at 10:53:07PM +0800, Xiaoyao Li wrote: yes, with >= 7.1, pcmc->legacy_no_rng_seed = false by default, and RNG seed i

Re: [PULL 9/9] hw/i386: pass RNG seed via setup_data entry

2022-08-02 Thread Xiaoyao Li
On 8/2/2022 9:21 PM, Jason A. Donenfeld wrote: Hi, On Tue, Aug 02, 2022 at 11:28:15AM +0800, Xiaoyao Li wrote: static void pc_q35_7_0_machine_options(MachineClass *m) { +PCMachineClass *pcmc = PC_MACHINE_CLASS(m); pc_q35_7_1_machine_options(m); m->alias = N

Re: [PATCH v1 00/40] TDX QEMU support

2022-08-02 Thread Xiaoyao Li
On 8/2/2022 5:49 PM, Daniel P. Berrangé wrote: On Tue, Aug 02, 2022 at 03:47:10PM +0800, Xiaoyao Li wrote: - CPU model We cannot create a TD with arbitrary CPU model like what for non-TDX VMs, because only a subset of features can be configured for TD. - It's recommended to use

Re: [PATCH v1 01/40] *** HACK *** linux-headers: Update headers to pull in TDX API changes

2022-08-02 Thread Xiaoyao Li
On 8/2/2022 5:47 PM, Daniel P. Berrangé wrote: On Tue, Aug 02, 2022 at 03:47:11PM +0800, Xiaoyao Li wrote: 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

[PATCH v1 36/40] i386/tdx: Don't synchronize guest tsc for TDs

2022-08-02 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

[PATCH v1 33/40] i386/tdx: Don't allow system reset for TDX VMs

2022-08-02 Thread Xiaoyao Li
TDX CPU state is protected and thus vcpu state cann't be reset by VMM. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- 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 1545b6f870f5..8c282122ed67

[PATCH v1 32/40] i386/tdx: Disable PIC for TDX VMs

2022-08-02 Thread Xiaoyao Li
and error out if user wants PIC. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- 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 70c56b7ba32c..2f317a6bb55b 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm

[PATCH v1 31/40] i386/tdx: Disable SMM for TDX VMs

2022-08-02 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 Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 8 1 file changed, 8

[PATCH v1 30/40] i386/tdx: Finalize TDX VM

2022-08-02 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 Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/target/i386/kvm/tdx.c b

[PATCH v1 37/40] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() for TDs

2022-08-02 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 Acked-by: Gerd

[PATCH v1 35/40] hw/i386: add option to forcibly report edge trigger in acpi tables

2022-08-02 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

[PATCH v1 28/40] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION

2022-08-02 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 Acked-by: Gerd Hoffmann --- Changes from RFC v4: - rename variable

[PATCH v1 25/40] i386/tdx: Track RAM entries for TDX VM

2022-08-02 Thread Xiaoyao Li
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 --- Changes from RFC v4: - simplify the algorithm of tdx_accept_ram_range() (Suggested-by: Gerd Hoffman

[PATCH v1 34/40] hw/i386: add eoi_intercept_unsupported member to X86MachineState

2022-08-02 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 a389ee26265a..6ab023713bf1 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1401,6 +1401,7

[PATCH v1 26/40] headers: Add definitions from UEFI spec for volumes, resources, etc...

2022-08-02 Thread Xiaoyao Li
, EFI_RESOURCE_MEMORY_UNACCEPTED will be added in future UEFI spec. [1] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-virtual-firmware-design-guide-rev-1.pdf Signed-off-by: Xiaoyao Li --- include/standard-headers/uefi/uefi.h | 198 +++ 1 file changed, 198 insertions

[PATCH v1 38/40] i386/tdx: Skip kvm_put_apicbase() for TDs

2022-08-02 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 53ab539e7e4d..948c87ebdb97 100644 --- a/target/i386/kvm/kvm.c +++ b/target

[PATCH v1 24/40] i386/tdx: Track mem_ptr for each firmware entry of TDVF

2022-08-02 Thread Xiaoyao Li
to do the stuff. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- hw/i386/tdvf.c | 1 + include/hw/i386/tdvf.h | 7 +++ target/i386/kvm/tdx.c | 32 3 files changed, 40 insertions(+) diff --git a/hw/i386/tdvf.c b/hw/i386/tdvf.c index a40198f9407a

[PATCH v1 21/40] i386/tdx: Parse TDVF metadata for TDX VM

2022-08-02 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 Acked-by: Gerd Hoffmann

[PATCH v1 22/40] i386/tdx: Skip BIOS shadowing setup

2022-08-02 Thread Xiaoyao Li
TDX doesn't support map different GPAs to same private memory. Thus, aliasing top 128KB of BIOS as isa-bios is not supported. On the other hand, TDX guest cannot go to real mode, it can work fine without isa-bios. Signed-off-by: Xiaoyao Li --- Changes from RFC v4: - update commit message

[PATCH v1 23/40] i386/tdx: Don't initialize pc.rom for TDX VMs

2022-08-02 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 --- This is more as a workaround of the issue that for q35 machine type, the real memslot update (which requires memslot deletion )for pc.rom happens after

[PATCH v1 40/40] docs: Add TDX documentation

2022-08-02 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 --- changes in v5: - add the restriction that kernel-irqchip must be split --- docs/system/confidential-guest-support.rst | 1 + docs/system/i386/tdx.rst

[PATCH v1 18/40] i386/tdx: Implement user specified tsc frequency

2022-08-02 Thread Xiaoyao Li
Reuse "-cpu,tsc-frequency=" to get user wanted tsc frequency and call VM scope VM_SET_TSC_KHZ to set the tsc frequency of TD before 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:

[PATCH v1 27/40] i386/tdx: Setup the TD HOB list

2022-08-02 Thread Xiaoyao Li
-by: Isaku Yamahata Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li --- Changes from RFC v4: - drop the code of adding mmio resources since OVMF prepares all the MMIO hob itself. --- hw/i386/meson.build | 2 +- hw/i386/tdvf-hob.c

[PATCH v1 17/40] i386/tdx: Validate TD attributes

2022-08-02 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

[PATCH v1 39/40] i386/tdx: Don't get/put guest state for TDX VMs

2022-08-02 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 948c87ebdb97..95afbbac7116 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4584,6 +4584,11 @@ int

[PATCH v1 16/40] i386/tdx: Wire CPU features up with attributes of TD guest

2022-08-02 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

[PATCH v1 15/40] i386/tdx: Add property sept-ve-disable for tdx-guest object

2022-08-02 Thread Xiaoyao Li
this bit. Signed-off-by: Xiaoyao Li --- qapi/qom.json | 4 +++- target/i386/kvm/tdx.c | 24 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index 38177848abc1..2a5486bfed3e 100644 --- a/qapi/qom.json +++ b/qapi/qom.json

[PATCH v1 20/40] i386/tdvf: Introduce function to parse TDVF metadata

2022-08-02 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 from RFC v4: - rename

[PATCH v1 29/40] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu

2022-08-02 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 Acked-by: Gerd Hoffmann --- target/i386

[PATCH v1 14/40] i386/tdx: Initialize TDX before creating TD vcpus

2022-08-02 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 |

[PATCH v1 13/40] KVM: Introduce kvm_arch_pre_create_vcpu()

2022-08-02 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

[PATCH v1 11/40] i386/tdx: Integrate tdx_caps->attrs_fixed0/1 to tdx_cpuid_lookup

2022-08-02 Thread Xiaoyao Li
Some bits in TD attributes have corresponding CPUID feature bits. Reflect the fixed0/1 restriction on TD attributes to their corresponding CPUID bits in tdx_cpuid_lookup[] as well. Signed-off-by: Xiaoyao Li --- target/i386/cpu-internal.h | 9 + target/i386/cpu.c | 9

[PATCH v1 08/40] i386/tdx: Adjust the supported CPUID based on TDX restrictions

2022-08-02 Thread Xiaoyao Li
overs the other part of type #1); - fix the ones in vmm_fixup; - filter the one has valid .supported field; (Calculated type is ignored since it's determined at runtime). Co-developed-by: Chenyi Qiang Signed-off-by: Chenyi Qiang Signed-off-by: Xiaoyao Li --- target/i386/cpu.h | 16 +++ t

[PATCH v1 19/40] i386/tdx: Set kvm_readonly_mem_enabled to false for TDX VM

2022-08-02 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 Acked-by: Gerd Hoffmann

[PATCH v1 12/40] i386/kvm: Move architectural CPUID leaf generation to separate helper

2022-08-02 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

[PATCH v1 09/40] i386/tdx: Update tdx_fixed0/1 bits by tdx_caps.cpuid_config[]

2022-08-02 Thread Xiaoyao Li
by removing the bits that reported from TDX module as configurable. This can adapt with the updated TDX (module) automatically. Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 30 ++ 1 file changed, 30 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm

[PATCH v1 07/40] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object

2022-08-02 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 |

[PATCH v1 06/40] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES

2022-08-02 Thread Xiaoyao Li
, QEMU chooses to try starting with a known number and abort when it exceeds KVM_MAX_CPUID_ENTRIES. Besides, introduce the interfaces to invoke TDX "ioctls" at different scope (KVM, VM and VCPU) in preparation. Signed-off-by: Xiaoyao Li --- changes from RFC v4: - start from nr_cpuid_c

[PATCH v1 05/40] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context

2022-08-02 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 Acked-by: Gerd Hoffmann --- target/i386/kvm/kvm.c | 15 ++- target/i386/kvm/meson.build | 2 +- target/i386/kvm/tdx

[PATCH v1 02/40] i386: Introduce tdx-guest object

2022-08-02 Thread Xiaoyao Li
and not configurable so far. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- changes from RFC-V4 - make @attributes not user-settable --- configs/devices/i386-softmmu/default.mak | 1 + hw/i386/Kconfig | 5 +++ qapi/qom.json| 12 +++ target/i386

[PATCH v1 10/40] i386/tdx: Integrate tdx_caps->xfam_fixed0/1 into tdx_cpuid_lookup

2022-08-02 Thread Xiaoyao Li
KVMM requires userspace to pass XFAM configuration via CPUID leaves 0xDs. Convert tdx_caps->xfam_fixed0/1 into corresponding tdx_cpuid_lookup[].tdx_fixed0/1 field of CPUID leaves 0xD. Thus the requirement can applied naturally. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c |

[PATCH v1 04/40] target/i386: Introduce kvm_confidential_guest_init()

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

[PATCH v1 03/40] target/i386: Implement mc->kvm_type() to get VM type

2022-08-02 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 Acked-by: Gerd Hoffmann --- hw/i386/x86.c | 6 ++ target/i386/kvm/kvm.c | 30 ++ target/i386/kvm/kvm_i386.h | 1 + 3 files changed,

[PATCH v1 01/40] *** HACK *** linux-headers: Update headers to pull in TDX API changes

2022-08-02 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

[PATCH v1 00/40] TDX QEMU support

2022-08-02 Thread Xiaoyao Li
trigger in acpi tables i386/tdx: Don't synchronize 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 (34): *** HACK *** linux-headers: Update headers to pull in TDX API

Re: [PULL 9/9] hw/i386: pass RNG seed via setup_data entry

2022-08-01 Thread Xiaoyao Li
On 7/22/2022 12:36 AM, Paolo Bonzini wrote: From: "Jason A. Donenfeld" Tiny machines optimized for fast boot time generally don't use EFI, which means a random seed has to be supplied some other way. For this purpose, Linux (≥5.20) supports passing a seed in the setup_data table with

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

2022-07-29 Thread Xiaoyao Li
On 5/30/2022 7:49 PM, Gerd Hoffmann wrote: On Thu, May 26, 2022 at 10:48:56AM +0800, Xiaoyao Li wrote: On 5/24/2022 3:08 PM, Gerd Hoffmann wrote: On Thu, May 12, 2022 at 11:17:45AM +0800, Xiaoyao Li wrote: TDX guest cannot go to real mode, so just skip the setup of isa-bios. Does isa-bios

Re: [PATCH v2] target/i386: Restore TSX features with taa-no

2022-07-14 Thread Xiaoyao Li
On 7/14/2022 3:59 PM, Paolo Bonzini wrote: On 7/14/22 07:36, Zhenzhong Duan wrote: On ICX-2S2 host, when run L2 guest with both L1/L2 using Icelake-Server-v3 or above, we got below warning: "warning: host doesn't support requested feature: MSR(10AH).taa-no [bit 8]" This is because L1 KVM

[PATCH 2/2] i386/cpuid: Remove subleaf constraint on CPUID leaf 1F

2022-07-11 Thread Xiaoyao Li
No such constraint that subleaf index needs to be less than 64. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 4 1 file changed, 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index a0b412a1129f..3efa524b4b93 100644 --- a/target/i386/kvm/kvm.c +++ b

[PATCH 0/2] i386/cpuid: Minor fixes for CPUID leaf 1f setup

2022-07-11 Thread Xiaoyao Li
The issue that fixed by Patch 1 looks fatal though it doesn't appear on KVM because KVM always searches with assending order and hit with the correct cpuid leaf 0. Patch 2 removes the wrong constraint on CPUID leaf 1f Xiaoyao Li (2): i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F

[PATCH 1/2] i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F

2022-07-11 Thread Xiaoyao Li
Decrease array index cpuid_i when CPUID leaf 1F is skipped, otherwise it will get an all zero'ed CPUID entry with leaf 0 and subleaf 0. It conflicts with correct leaf 0. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/kvm/kvm.c

Re: [PATCH] target/i386: Restore TSX features with taa-no

2022-07-08 Thread Xiaoyao Li
On 7/8/2022 1:42 PM, Zhenzhong Duan wrote: In L1 kernel side, taa-no is cleared because RTM is disabled which will lead to below warning when starting L2 qemu: "warning: host doesn't support requested feature: MSR(10AH).taa-no [bit 8]" If host isn't susceptible to TSX Async Abort (TAA)

Re: [PATCH v6 6/8] KVM: Handle page fault for private memory

2022-07-07 Thread Xiaoyao Li
On 7/8/2022 4:08 AM, Sean Christopherson wrote: On Fri, Jul 01, 2022, Xiaoyao Li wrote: On 7/1/2022 6:21 AM, Michael Roth wrote: On Thu, Jun 30, 2022 at 12:14:13PM -0700, Vishal Annapurve wrote: With transparent_hugepages=always setting I see issues with the current implementation

Re: [PATCH v6 6/8] KVM: Handle page fault for private memory

2022-06-30 Thread Xiaoyao Li
On 7/1/2022 6:21 AM, Michael Roth wrote: On Thu, Jun 30, 2022 at 12:14:13PM -0700, Vishal Annapurve wrote: With transparent_hugepages=always setting I see issues with the current implementation. Scenario: 1) Guest accesses a gfn range 0x800-0xa00 as private 2) Guest calls mapgpa to convert the

Re: New "IndustryStandard" fw_cfg?

2022-06-16 Thread Xiaoyao Li
On 6/16/2022 4:28 PM, Gerd Hoffmann wrote: Hi, After re-read and re-think, I think the problem is better to state as: we need an interface for QEMU to tell OVMF how much memory it needs to accept, from [Minimum to All]. So for the case that user wants to boot an partial-enabled confidential

Re: New "IndustryStandard" fw_cfg?

2022-06-16 Thread Xiaoyao Li
On 6/15/2022 8:46 AM, Xu, Min M wrote: I would like to add more engineers (Confidential Computing Reviewers in EDK2 community and Intel's QEMU engineers) in this mail thread. -Original Message- From: Dionna Amalie Glaze Sent: Wednesday, June 15, 2022 2:09 AM To: qemu-devel@nongnu.org

Re: New "IndustryStandard" fw_cfg?

2022-06-15 Thread Xiaoyao Li
On 6/16/2022 1:37 PM, Gerd Hoffmann wrote: Hi, Per my understanding, Unaccepted Memory in UEFI is introduced for confidential VMs, i.e., for Intel TDX and AMD SEV-SNP. The only reason UEFI/OVMF reports "Unaccepted Memory" to OS, is a confidential VM is desired. No. Reporting "Unaccepted

Re: New "IndustryStandard" fw_cfg?

2022-06-15 Thread Xiaoyao Li
On 6/15/2022 8:46 AM, Xu, Min M wrote: I would like to add more engineers (Confidential Computing Reviewers in EDK2 community and Intel's QEMU engineers) in this mail thread. -Original Message- From: Dionna Amalie Glaze Sent: Wednesday, June 15, 2022 2:09 AM To: qemu-devel@nongnu.org

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

2022-06-07 Thread Xiaoyao Li
On 6/7/2022 7:16 PM, Gerd Hoffmann wrote: Hi, I guess it could be helpful for the discussion when you can outine the 'big picture' for tdx initialization. How does kvm accel setup look like without TDX, and what additional actions are needed for TDX? What ordering requirements and other

Re: [RFC PATCH v4 23/36] i386/tdx: Setup the TD HOB list

2022-06-02 Thread Xiaoyao Li
On 5/24/2022 3:56 PM, Gerd Hoffmann wrote: Hi, +static void tdvf_hob_add_mmio_resources(TdvfHob *hob) +{ +MachineState *ms = MACHINE(qdev_get_machine()); +X86MachineState *x86ms = X86_MACHINE(ms); +PCIHostState *pci_host; +uint64_t start, end; +uint64_t mcfg_base,

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

2022-06-01 Thread Xiaoyao Li
On 6/1/2022 3:54 PM, Gerd Hoffmann wrote: On Wed, Jun 01, 2022 at 03:20:46PM +0800, Xiaoyao Li wrote: On 5/24/2022 2:57 PM, Gerd Hoffmann wrote: Hi, Maybe it's a bit more work to add VM-scope initialization support to qemu. If just introducing VM-scope initialization to QEMU, it would

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

2022-06-01 Thread Xiaoyao Li
On 5/24/2022 2:57 PM, Gerd Hoffmann wrote: Hi, Hmm, hooking *vm* initialization into *vcpu* creation looks wrong to me. That's because for TDX, it has to do VM-scope (feature) initialization before creating vcpu. This is new to KVM and QEMU, that every feature is vcpu-scope and configured

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

2022-05-30 Thread Xiaoyao Li
On 5/30/2022 7:59 PM, Gerd Hoffmann wrote: Hi, tdx_add_ram_entry() increments tdx_guest->nr_ram_entries. I think it's worth for comments why this is safe regarding to this for-loop. The for-loop is to find the valid existing RAM entry (from E820 table). It will update the RAM entry and

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

2022-05-27 Thread Xiaoyao Li
On 5/27/2022 2:48 AM, Isaku Yamahata wrote: On Thu, May 26, 2022 at 03:33:10PM +0800, Xiaoyao Li wrote: On 5/24/2022 3:37 PM, Gerd Hoffmann wrote: I think all this can be simplified, by (1) Change the existing entry to cover the accepted ram range. (2) If there is room before

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

2022-05-27 Thread Xiaoyao Li
On 5/26/2022 3:33 PM, Xiaoyao Li wrote: On 5/24/2022 3:37 PM, Gerd Hoffmann wrote: +    if (e->address == address && e->length == length) { +    e->type = TDX_RAM_ADDED; +    } else if (e->address == address) { +    e->address += length;

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

2022-05-26 Thread Xiaoyao Li
On 5/24/2022 3:37 PM, Gerd Hoffmann wrote: +static int tdx_accept_ram_range(uint64_t address, uint64_t length) +{ +TdxRamEntry *e; +int i; + +for (i = 0; i < tdx_guest->nr_ram_entries; i++) { +e = _guest->ram_entries[i]; + +if (address + length < e->address || +

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

2022-05-25 Thread Xiaoyao Li
On 5/24/2022 4:29 PM, Gerd Hoffmann wrote: On Tue, May 24, 2022 at 04:11:56PM +0800, Xiaoyao Li wrote: On 5/24/2022 2:59 PM, Gerd Hoffmann wrote: On Tue, May 24, 2022 at 12:19:51PM +0800, Xiaoyao Li wrote: On 5/23/2022 5:39 PM, Gerd Hoffmann wrote: So, how is this supposed to work? Patch #2

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

2022-05-25 Thread Xiaoyao Li
On 5/24/2022 3:09 PM, Gerd Hoffmann wrote: On Thu, May 12, 2022 at 11:17:47AM +0800, Xiaoyao Li wrote: 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

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

2022-05-25 Thread Xiaoyao Li
On 5/24/2022 3:08 PM, Gerd Hoffmann wrote: On Thu, May 12, 2022 at 11:17:45AM +0800, Xiaoyao Li wrote: TDX guest cannot go to real mode, so just skip the setup of isa-bios. Does isa-bios setup cause any actual problems? (same question for patch #19). It causes mem_region split and mem_slot

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

2022-05-25 Thread Xiaoyao Li
On 5/24/2022 3:02 PM, Gerd Hoffmann wrote: Hi, +static int tdvf_parse_section_entry(const TdvfSectionEntry *src, + TdxFirmwareEntry *entry) +/* sanity check */ That is what the whole function is doing. So rename it to tdvf_check_section_entry to

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

2022-05-24 Thread Xiaoyao Li
On 5/24/2022 2:59 PM, Gerd Hoffmann wrote: On Tue, May 24, 2022 at 12:19:51PM +0800, Xiaoyao Li wrote: On 5/23/2022 5:39 PM, Gerd Hoffmann wrote: So, how is this supposed to work? Patch #2 introduces attributes as user-settable property. So do users have to manually figure and pass

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

2022-05-23 Thread Xiaoyao Li
On 5/23/2022 5:39 PM, Gerd Hoffmann wrote: Validate TD attributes with tdx_caps that fixed-0 bits must be zero and fixed-1 bits must be set. -static void setup_td_guest_attributes(X86CPU *x86cpu) +static int tdx_validate_attributes(TdxGuest *tdx) +{ +if (((tdx->attributes &

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

2022-05-23 Thread Xiaoyao Li
On 5/23/2022 5:20 PM, Gerd Hoffmann wrote: +int tdx_pre_create_vcpu(CPUState *cpu) +{ +MachineState *ms = MACHINE(qdev_get_machine()); +X86CPU *x86cpu = X86_CPU(cpu); +CPUX86State *env = >env; +struct kvm_tdx_init_vm init_vm; +int r = 0; + +qemu_mutex_lock(_guest->lock);

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

2022-05-23 Thread Xiaoyao Li
On 5/23/2022 5:01 PM, Gerd Hoffmann wrote: Hi, - The supported XCR0 and XSS bits needs to be cap'ed by tdx_caps, because KVM uses them to setup XFAM of TD. +case 0xd: +if (index == 0) { +if (reg == R_EAX) { +*ret &=

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

2022-05-23 Thread Xiaoyao Li
On 5/23/2022 4:45 PM, Gerd Hoffmann wrote: Hi, +do { +size = sizeof(struct kvm_tdx_capabilities) + + max_ent * sizeof(struct kvm_tdx_cpuid_config); +caps = g_malloc0(size); +caps->nr_cpuid_configs = max_ent; + +r =

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

2022-05-12 Thread Xiaoyao Li
On 5/13/2022 2:04 AM, Isaku Yamahata wrote: On Thu, May 12, 2022 at 11:17:41AM +0800, Xiaoyao Li wrote: 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 g

Re: [RFC PATCH v4 24/36] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION

2022-05-12 Thread Xiaoyao Li
On 5/13/2022 2:34 AM, Isaku Yamahata wrote: On Thu, May 12, 2022 at 11:17:51AM +0800, Xiaoyao Li wrote: 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

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

2022-05-12 Thread Xiaoyao Li
On 5/13/2022 1:48 AM, Isaku Yamahata wrote: On Thu, May 12, 2022 at 11:17:37AM +0800, Xiaoyao Li wrote: diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index b434feaa6b1d..5c7972f617e8 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -24,6

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

2022-05-12 Thread Xiaoyao Li
On 5/13/2022 1:50 AM, Isaku Yamahata wrote: On Thu, May 12, 2022 at 11:17:36AM +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. Because &qu

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

2022-05-11 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 v4 34/36] i386/tdx: Skip kvm_put_apicbase() for TDs

2022-05-11 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 9c5bf075b542..4d520d0e34bd 100644 --- a/target/i386/kvm/kvm.c +++ b/target

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

2022-05-11 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 c51125ab200f..9a1e1dab938f 100644 --- a/target/i386

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

2022-05-11 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 v4 32/36] i386/tdx: Don't synchronize guest tsc for TDs

2022-05-11 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 v4 28/36] i386/tdx: Disable PIC for TDX VMs

2022-05-11 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 7ff4c6a9a7ca..59c7aa8f1818 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -333,6 +333,13

[RFC PATCH v4 24/36] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION

2022-05-11 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 | 24 1 file changed

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

2022-05-11 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 v4 23/36] i386/tdx: Setup the TD HOB list

2022-05-11 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 v4 35/36] i386/tdx: Don't get/put guest state for TDX VMs

2022-05-11 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 4d520d0e34bd..3e26dacf7807 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -4478,6 +4478,11 @@ int

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

2022-05-11 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 17f2252296c5..182ec544611b 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1365,6 +1365,7

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

2022-05-11 Thread Xiaoyao Li
be classified into two groups: - Firmware itself, e.g., BFV and CFV, that locates separated from guest RAM. It's memory pointer is the bios pointer. - Sections located at guest RAM, e.g., TEMP_MEM and TD_HOB. mmap a new memory range for them. Signed-off-by: Xiaoyao Li --- hw/i386/tdvf.c

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

2022-05-11 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 v4 22/36] i386/tdx: Track RAM entries for TDX VM

2022-05-11 Thread Xiaoyao Li
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 +++ target/i386/kvm/tdx.h | 14

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

2022-05-11 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 | 8 1 file changed, 8 insertions(+) diff --git

<    2   3   4   5   6   7   8   9   >