[PATCH v3 00/70] QEMU Guest memfd + QEMU TDX support

2023-11-14 Thread Xiaoyao Li
PAM initialization above SMRAM initialization q35: Introduce smm_ranges property for q35-pci-host hw/i386: add option to forcibly report edge trigger in acpi tables i386/tdx: Don't synchronize guest tsc for TDs Sean Christopherson (2): i386/kvm: Move architectural CPUID leaf generati

[PATCH] target/i386: Add support of KVM_FEATURE_ASYNC_PF_VMEXIT for guest

2023-10-24 Thread Xiaoyao Li
KVM_FEATURE_ASYNC_PF_VMEXIT has been introduced for years, however QEMU doesn't support expose it to guest. Add support for it. 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

Re: [PATCH v2 1/4] softmmu/physmem: Warn with ram_block_discard_range() on MAP_PRIVATE file mapping

2023-10-19 Thread Xiaoyao Li
On 10/19/2023 4:26 PM, David Hildenbrand wrote: On 18.10.23 18:27, Xiaoyao Li wrote: On 10/18/2023 5:26 PM, David Hildenbrand wrote: On 18.10.23 11:02, Xiaoyao Li wrote: On 10/18/2023 3:42 PM, David Hildenbrand wrote: On 18.10.23 05:02, Xiaoyao Li wrote: David, On 7/6/2023 3:56 PM, David

Re: [PATCH] i386/pc: Drop pc_machine_kvm_type()

2023-10-18 Thread Xiaoyao Li
On 10/18/2023 9:27 PM, Michael S. Tsirkin wrote: On Sat, Oct 07, 2023 at 02:58:19AM -0400, Xiaoyao Li wrote: pc_machine_kvm_type() was introduced by commit e21be724eaf5 ("i386/xen: add pc_machine_kvm_type to initialize XEN_EMULATE mode") to do Xen specific initialization by utilizin

Re: [PATCH v2 1/4] softmmu/physmem: Warn with ram_block_discard_range() on MAP_PRIVATE file mapping

2023-10-18 Thread Xiaoyao Li
On 10/18/2023 5:26 PM, David Hildenbrand wrote: On 18.10.23 11:02, Xiaoyao Li wrote: On 10/18/2023 3:42 PM, David Hildenbrand wrote: On 18.10.23 05:02, Xiaoyao Li wrote: David, On 7/6/2023 3:56 PM, David Hildenbrand wrote: ram_block_discard_range() cannot possibly do the right thing in

Re: [PATCH v2 1/4] softmmu/physmem: Warn with ram_block_discard_range() on MAP_PRIVATE file mapping

2023-10-18 Thread Xiaoyao Li
On 10/18/2023 3:42 PM, David Hildenbrand wrote: On 18.10.23 05:02, Xiaoyao Li wrote: David, On 7/6/2023 3:56 PM, David Hildenbrand wrote: ram_block_discard_range() cannot possibly do the right thing in MAP_PRIVATE file mappings in the general case. To achieve the documented semantics, we

Re: [PATCH v2 1/4] softmmu/physmem: Warn with ram_block_discard_range() on MAP_PRIVATE file mapping

2023-10-17 Thread Xiaoyao Li
David, On 7/6/2023 3:56 PM, David Hildenbrand wrote: ram_block_discard_range() cannot possibly do the right thing in MAP_PRIVATE file mappings in the general case. To achieve the documented semantics, we also have to punch a hole into the file, possibly messing with other MAP_PRIVATE/MAP_SHARED

[PATCH] targer/i386/cpu: Fix CPUID_HT exposure

2023-10-09 Thread Xiaoyao Li
ose CPUID_HT to guest when "-cpu host/max" with only 1 vcpu. To fix this, need mark CPUID_HT as the no_autoenable_flags. Signed-off-by: Xiaoyao Li --- target/i386/cpu.c | 1 + target/i386/kvm/kvm.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/target/i386/cpu.c b/target/i386

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

2023-10-09 Thread Xiaoyao Li
On 10/10/2023 9:02 AM, Tina Zhang wrote: Hi, On 8/18/23 17:49, 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: [RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem

2023-10-07 Thread Xiaoyao Li
On 9/22/2023 3:08 PM, David Hildenbrand wrote: On 22.09.23 02:22, Xiaoyao Li wrote: On 9/21/2023 4:55 PM, David Hildenbrand wrote: On 14.09.23 05:50, Xiaoyao Li wrote: From: Chao Peng Add KVM gmem support to RAMBlock so both normal hva based memory and kvm gmem fd based private memory can

[PATCH] i386/pc: Drop pc_machine_kvm_type()

2023-10-06 Thread Xiaoyao Li
ves the Xen specific initialization to pc_basic_device_init(). There is no need to keep the PC specific kvm_type() implementation anymore. So we'll fallback to kvm_arch_get_default_type(), which simply returns 0. Signed-off-by: Xiaoyao Li Reviewed-by: Isaku Yamahata Reviewed-by: David Hildenbrand

Re: [RFC PATCH v2 00/21] QEMU gmem implemention

2023-09-22 Thread Xiaoyao Li
On 9/21/2023 5:11 PM, David Hildenbrand wrote: 3. What is KVM_X86_SW_PROTECTED_VM going to look like? and do we need it? Why implement it when you have to ask others for a motivation? 😉 Personally, I'm not sure if it is really useful, especially in this state. Yeah, as of today, KVM_X86_S

Re: [RFC PATCH v2 07/21] i386/pc: Drop pc_machine_kvm_type()

2023-09-21 Thread Xiaoyao Li
On 9/21/2023 4:51 PM, David Hildenbrand wrote: On 14.09.23 05:51, Xiaoyao Li wrote: pc_machine_kvm_type() was introduced by commit e21be724eaf5 ("i386/xen: add pc_machine_kvm_type to initialize XEN_EMULATE mode") to do Xen specific initialization by utilizing kvm_type metho

Re: [RFC PATCH v2 05/21] kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot

2023-09-21 Thread Xiaoyao Li
On 9/21/2023 4:56 PM, David Hildenbrand wrote: On 14.09.23 05:51, Xiaoyao Li wrote: From: Chao Peng Switch to KVM_SET_USER_MEMORY_REGION2 when supported by KVM. With KVM_SET_USER_MEMORY_REGION2, QEMU can set up memory region that backend'ed both by hva-based shared memory and gmem fd

Re: [RFC PATCH v2 04/21] memory: Introduce memory_region_has_gmem_fd()

2023-09-21 Thread Xiaoyao Li
On 9/21/2023 4:46 PM, David Hildenbrand wrote: On 14.09.23 05:51, Xiaoyao Li wrote: Introduce memory_region_has_gmem_fd() to query if the MemoryRegion has KVM gmem fd allocated. *probably* best to just squash that into patch #2. Sure, I will do it.

Re: [RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem

2023-09-21 Thread Xiaoyao Li
On 9/21/2023 4:55 PM, David Hildenbrand wrote: On 14.09.23 05:50, Xiaoyao Li wrote: From: Chao Peng Add KVM gmem support to RAMBlock so both normal hva based memory and kvm gmem fd based private memory can be associated in one RAMBlock. Introduce new flag RAM_KVM_GMEM. It calls KVM ioctl to

Re: [RFC PATCH v2 03/21] HostMem: Add private property and associate it with RAM_KVM_GMEM

2023-09-21 Thread Xiaoyao Li
On 9/20/2023 11:42 PM, Markus Armbruster wrote: David Hildenbrand writes: On 20.09.23 16:35, Xiaoyao Li wrote: On 9/20/2023 3:30 PM, Markus Armbruster wrote: Xiaoyao Li writes: On 9/19/2023 5:46 PM, Markus Armbruster wrote: Xiaoyao Li writes: From: Isaku Yamahata Add a new property

Re: [RFC PATCH v2 03/21] HostMem: Add private property and associate it with RAM_KVM_GMEM

2023-09-20 Thread Xiaoyao Li
On 9/20/2023 3:30 PM, Markus Armbruster wrote: Xiaoyao Li writes: On 9/19/2023 5:46 PM, Markus Armbruster wrote: Xiaoyao Li writes: From: Isaku Yamahata Add a new property "private" to memory backends. When it's set to true, it indicates the RAMblock of the backend al

Re: [RFC PATCH v2 03/21] HostMem: Add private property and associate it with RAM_KVM_GMEM

2023-09-19 Thread Xiaoyao Li
On 9/19/2023 5:46 PM, Markus Armbruster wrote: Xiaoyao Li writes: From: Isaku Yamahata Add a new property "private" to memory backends. When it's set to true, it indicates the RAMblock of the backend also requires kvm gmem. Can you add a brief explanation why you need the

Re: [RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem

2023-09-14 Thread Xiaoyao Li
On 9/15/2023 10:04 AM, Wang, Lei wrote: On 9/14/2023 11:50, Xiaoyao Li wrote: From: Chao Peng Add KVM gmem support to RAMBlock so both normal hva based memory and kvm gmem fd based private memory can be associated in one RAMBlock. Introduce new flag RAM_KVM_GMEM. It calls KVM ioctl to create

Re: [RFC PATCH v2 00/21] QEMU gmem implemention

2023-09-14 Thread Xiaoyao Li
On 9/14/2023 9:09 PM, David Hildenbrand wrote: On 14.09.23 05:50, Xiaoyao Li wrote: It's the v2 RFC of enabling KVM gmem[1] as the backend for private memory. For confidential-computing, KVM provides gmem/guest_mem interfaces for userspace, like QEMU, to allocate user-unaccesible pr

[RFC PATCH v2 07/21] i386/pc: Drop pc_machine_kvm_type()

2023-09-13 Thread Xiaoyao Li
ves the Xen specific initialization to pc_basic_device_init(). There is no need to keep the PC specific kvm_type() implementation anymore. On the other hand, later patch will implement kvm_type() method for all x86/i386 machines to support KVM_X86_SW_PROTECTED_VM. Signed-off-by: Xiaoyao Li Reviewed-by: Isa

[RFC PATCH v2 19/21] pci-host/q35: Move PAM initialization above SMRAM initialization

2023-09-13 Thread Xiaoyao Li
From: Isaku Yamahata In mch_realize(), process PAM initialization before SMRAM initialization so that later patch can skill all the SMRAM related with a single check. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- hw/pci-host/q35.c | 19 ++- 1 file changed, 10

[RFC PATCH v2 13/21] i386/kvm: Set memory to default private for KVM_X86_SW_PROTECTED_VM

2023-09-13 Thread Xiaoyao Li
Register a memory listener for KVM_X86_SW_PROVTED_VM. It set RAM to private by default. Signed-off-by: Xiaoyao Li --- include/exec/memory.h | 1 + target/i386/kvm/sw-protected-vm.c | 18 ++ 2 files changed, 19 insertions(+) diff --git a/include/exec/memory.h b

[RFC PATCH v2 10/21] i386/kvm: Implement kvm_sw_protected_vm_init() for sw-protcted-vm specific functions

2023-09-13 Thread Xiaoyao Li
Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm.c | 2 ++ target/i386/kvm/sw-protected-vm.c | 10 ++ target/i386/kvm/sw-protected-vm.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index fb1be16471b4..e126bf4e7ddd

[RFC PATCH v2 18/21] trace/kvm: Add trace for page convertion between shared and private

2023-09-13 Thread Xiaoyao Li
From: Isaku Yamahata Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c| 1 + accel/kvm/trace-events | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c67aa66b0559..229b7038a4c2 100644 --- a

[RFC PATCH v2 15/21] physmem: extract ram_block_discard_range_fd() from ram_block_discard_range()

2023-09-13 Thread Xiaoyao Li
. When doing private memory <-> shared memory conversion, it requires 4KB alignment instead of RamBlock.page_size. Signed-off-by: Xiaoyao Li --- softmmu/physmem.c | 192 -- 1 file changed, 100 insertions(+), 92 deletions(-) diff --git a/s

[RFC PATCH v2 20/21] q35: Introduce smm_ranges property for q35-pci-host

2023-09-13 Thread Xiaoyao Li
stopherson Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li --- hw/i386/pc_q35.c | 3 ++- hw/pci-host/q35.c | 42 +++ include/hw/i386/pc.h | 1 + include/hw/pci-host/q35.h | 1 + 4 files changed, 33 insertions(+), 14

[RFC PATCH v2 21/21] i386: Disable SMM mode for X86_SW_PROTECTED_VM

2023-09-13 Thread Xiaoyao Li
Signed-off-by: Xiaoyao Li --- target/i386/kvm/sw-protected-vm.c | 8 1 file changed, 8 insertions(+) diff --git a/target/i386/kvm/sw-protected-vm.c b/target/i386/kvm/sw-protected-vm.c index f47ac383e1dd..65347067aa03 100644 --- a/target/i386/kvm/sw-protected-vm.c +++ b/target/i386/kvm

[RFC PATCH v2 16/21] physmem: Introduce ram_block_convert_range()

2023-09-13 Thread Xiaoyao Li
It's used for discarding oppsite memory after memory conversion to shared/private. Note, private-shared page conversion is done at 4KB granularity. Don't check alignment with rb->page_size, instead qemu_host_page_size, which is 4K. Originally-from: Isaku Yamahata Signed-off-b

[RFC PATCH v2 11/21] kvm: Introduce support for memory_attributes

2023-09-13 Thread Xiaoyao Li
Introcude the helper functions to set the attributes of a range of memory to private and shared. Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 43 +++ include/sysemu/kvm.h | 3 +++ 2 files changed, 46 insertions(+) diff --git a/accel/kvm/kvm

[RFC PATCH v2 05/21] kvm: Enable KVM_SET_USER_MEMORY_REGION2 for memslot

2023-09-13 Thread Xiaoyao Li
From: Chao Peng Switch to KVM_SET_USER_MEMORY_REGION2 when supported by KVM. With KVM_SET_USER_MEMORY_REGION2, QEMU can set up memory region that backend'ed both by hva-based shared memory and gmem fd based private memory. Signed-off-by: Chao Peng Codeveloped-by: Xiaoyao Li Signed-o

[RFC PATCH v2 02/21] RAMBlock: Add support of KVM private gmem

2023-09-13 Thread Xiaoyao Li
From: Chao Peng Add KVM gmem support to RAMBlock so both normal hva based memory and kvm gmem fd based private memory can be associated in one RAMBlock. Introduce new flag RAM_KVM_GMEM. It calls KVM ioctl to create private gmem for the RAMBlock when it's set. Signed-off-by: Xiaoy

[RFC PATCH v2 17/21] kvm: handle KVM_EXIT_MEMORY_FAULT

2023-09-13 Thread Xiaoyao Li
only when the RAMBlock has gmem memory backend. Signed-off-by: Chao Peng Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 54 + 1 file changed, 54 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 7e32ee83b258..c67aa66b0559

[RFC PATCH v2 12/21] kvm/memory: Introduce the infrastructure to set the default shared/private value

2023-09-13 Thread Xiaoyao Li
Introduce new flag RAM_DEFAULT_PRIVATE for RAMBlock. It's used to indicate the default attribute, private or not. Set the RAM range to private explicitly when it's default private. Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 10 +

[RFC PATCH v2 01/21] *** HACK *** linux-headers: Update headers to pull in gmem APIs

2023-09-13 Thread Xiaoyao Li
This patch needs to be updated by script scripts/update-linux-headers.sh once gmem fd support is upstreamed in Linux kernel. Signed-off-by: Xiaoyao Li --- linux-headers/asm-x86/kvm.h | 3 +++ linux-headers/linux/kvm.h | 50 + 2 files changed, 53

[RFC PATCH v2 14/21] physmem: replace function name with __func__ in ram_block_discard_range()

2023-09-13 Thread Xiaoyao Li
Signed-off-by: Xiaoyao Li --- softmmu/physmem.c | 34 +++--- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 2d98a88f41f0..34d580ec0d39 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3440,16

[RFC PATCH v2 09/21] target/i386: Introduce kvm_confidential_guest_init()

2023-09-13 Thread Xiaoyao Li
Introduce a separate function kvm_confidential_guest_init(), which dispatches specific confidential guest initialization function by ms->cgs type. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daudé --- target/i386/kvm/kvm.c | 11 ++- target/i

[RFC PATCH v2 08/21] target/i386: Implement mc->kvm_type() to get VM type

2023-09-13 Thread Xiaoyao Li
Implement mc->kvm_type() for i386 machines. It provides a way for user to create SW_PROTECTE_VM. Also store the vm_type in machinestate to other code to query what the VM type is. Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 12 include/hw/i386/x86.h |

[RFC PATCH v2 03/21] HostMem: Add private property and associate it with RAM_KVM_GMEM

2023-09-13 Thread Xiaoyao Li
From: Isaku Yamahata Add a new property "private" to memory backends. When it's set to true, it indicates the RAMblock of the backend also requires kvm gmem. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- backends/hostmem-file.c | 1 + backends/hostmem-memfd.c |

[RFC PATCH v2 00/21] QEMU gmem implemention

2023-09-13 Thread Xiaoyao Li
d and private pci-host/q35: Move PAM initialization above SMRAM initialization q35: Introduce smm_ranges property for q35-pci-host Xiaoyao Li (14): *** HACK *** linux-headers: Update headers to pull in gmem APIs memory: Introduce memory_region_has_gmem_fd() i386: Add support for sw-protec

[RFC PATCH v2 06/21] i386: Add support for sw-protected-vm object

2023-09-13 Thread Xiaoyao Li
Introduce sw-protected-vm object which implements the interface of CONFIDENTIAL_GUEST_SUPPORT, and will be used to create X86_SW_PROTECTED_VM via $qemu -machine ...,confidential-guest-support=sp-vm0 \ -object sw-protected-vm,id=sp-vm0 Signed-off-by: Xiaoyao Li --- qapi/qom.json

[RFC PATCH v2 04/21] memory: Introduce memory_region_has_gmem_fd()

2023-09-13 Thread Xiaoyao Li
Introduce memory_region_has_gmem_fd() to query if the MemoryRegion has KVM gmem fd allocated. Signed-off-by: Xiaoyao Li --- include/exec/memory.h | 10 ++ softmmu/memory.c | 5 + 2 files changed, 15 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h

Re: [RFC PATCH 15/19] kvm: handle KVM_EXIT_MEMORY_FAULT

2023-09-13 Thread Xiaoyao Li
On 8/9/2023 11:02 PM, Xu Yilun wrote: On 2023-07-31 at 12:21:57 -0400, Xiaoyao Li wrote: From: Chao Peng Currently only KVM_MEMORY_EXIT_FLAG_PRIVATE in flags is valid when KVM_EXIT_MEMORY_FAULT happens. It indicates userspace needs to do the memory conversion on the RAMBlock to turn the

Re: [RFC PATCH 15/19] kvm: handle KVM_EXIT_MEMORY_FAULT

2023-09-13 Thread Xiaoyao Li
On 8/3/2023 6:25 AM, Isaku Yamahata wrote: On Mon, Jul 31, 2023 at 12:21:57PM -0400, Xiaoyao Li wrote: From: Chao Peng Currently only KVM_MEMORY_EXIT_FLAG_PRIVATE in flags is valid when KVM_EXIT_MEMORY_FAULT happens. It indicates userspace needs to do the memory conversion on the RAMBlock

Re: [PATCH v2 41/58] i386/tdx: handle TDG.VP.VMCALL

2023-08-30 Thread Xiaoyao Li
On 8/30/2023 3:48 PM, Daniel P. Berrangé wrote: On Wed, Aug 30, 2023 at 01:57:59PM +0800, Xiaoyao Li wrote: On 8/30/2023 1:18 PM, Chenyi Qiang wrote: On 8/29/2023 6:25 PM, Daniel P. Berrangé wrote: On Tue, Aug 29, 2023 at 01:31:37PM +0800, Chenyi Qiang wrote: On 8/22/2023 4:24 PM, Daniel

Re: [PATCH v2 41/58] i386/tdx: handle TDG.VP.VMCALL

2023-08-29 Thread Xiaoyao Li
On 8/30/2023 1:18 PM, Chenyi Qiang wrote: On 8/29/2023 6:25 PM, Daniel P. Berrangé wrote: On Tue, Aug 29, 2023 at 01:31:37PM +0800, Chenyi Qiang wrote: On 8/22/2023 4:24 PM, Daniel P. Berrangé wrote: On Tue, Aug 22, 2023 at 08:52:30AM +0200, Markus Armbruster wrote: Xiaoyao Li writes

Re: [PATCH v2 47/58] i386/tdx: Wire REPORT_FATAL_ERROR with GuestPanic facility

2023-08-29 Thread Xiaoyao Li
On 8/29/2023 6:28 PM, Daniel P. Berrangé wrote: On Mon, Aug 28, 2023 at 09:14:41PM +0800, Xiaoyao Li wrote: On 8/21/2023 5:58 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:50:30AM -0400, Xiaoyao Li wrote: Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- qapi/run

Re: [PATCH v2 36/58] memory: Introduce memory_region_init_ram_gmem()

2023-08-29 Thread Xiaoyao Li
On 8/29/2023 10:33 PM, Philippe Mathieu-Daudé wrote: On 18/8/23 11:50, Xiaoyao Li wrote: Introduce memory_region_init_ram_gmem() to allocate private gmem on the MemoryRegion initialization. It's for the usercase of TDVF, which must be private on TDX case. Signed-off-by: Xiaoy

Re: [PATCH v2 13/58] kvm: Introduce kvm_arch_pre_create_vcpu()

2023-08-29 Thread Xiaoyao Li
On 8/29/2023 10:40 PM, Philippe Mathieu-Daudé wrote: On 18/8/23 11:49, 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-by: Xiaoyao Li

Re: [PATCH v2 47/58] i386/tdx: Wire REPORT_FATAL_ERROR with GuestPanic facility

2023-08-28 Thread Xiaoyao Li
On 8/21/2023 5:58 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:50:30AM -0400, Xiaoyao Li wrote: Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- qapi/run-state.json | 17 +-- softmmu/runstate.c| 49

Re: [PATCH v2 43/58] i386/tdx: setup a timer for the qio channel

2023-08-24 Thread Xiaoyao Li
On 8/24/2023 3:21 PM, Chenyi Qiang wrote: On 8/18/2023 5:50 PM, Xiaoyao Li wrote: From: Chenyi Qiang To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to

Re: [PATCH v2 33/58] headers: Add definitions from UEFI spec for volumes, resources, etc...

2023-08-24 Thread Xiaoyao Li
On 8/24/2023 3:50 PM, Xiaoyao Li wrote: On 8/24/2023 3:41 AM, Isaku Yamahata wrote: On Fri, Aug 18, 2023 at 05:50:16AM -0400, Xiaoyao Li wrote: Add UEFI definitions for literals, enums, structs, GUIDs, etc... that will be used by TDX to build the UEFI Hand-Off Block (HOB) that is passed to

Re: [PATCH v2 33/58] headers: Add definitions from UEFI spec for volumes, resources, etc...

2023-08-24 Thread Xiaoyao Li
On 8/24/2023 3:41 AM, Isaku Yamahata wrote: On Fri, Aug 18, 2023 at 05:50:16AM -0400, Xiaoyao Li wrote: Add UEFI definitions for literals, enums, structs, GUIDs, etc... that will be used by TDX to build the UEFI Hand-Off Block (HOB) that is passed to the Trusted Domain Virtual Firmware (TDVF

Re: [PATCH v2 18/58] i386/tdx: Validate TD attributes

2023-08-23 Thread Xiaoyao Li
On 8/22/2023 10:42 PM, Daniel P. Berrangé wrote: On Tue, Aug 22, 2023 at 10:30:47PM +0800, Xiaoyao Li wrote: On 8/21/2023 5:16 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:50:01AM -0400, Xiaoyao Li wrote: Validate TD attributes with tdx_caps that fixed-0 bits must be zero and

Re: [PATCH v2 02/58] i386: Introduce tdx-guest object

2023-08-23 Thread Xiaoyao Li
On 8/22/2023 2:22 PM, Markus Armbruster wrote: Xiaoyao Li writes: Introduce tdx-guest object which implements the interface of CONFIDENTIAL_GUEST_SUPPORT, and will be used to create TDX VMs (TDs) by qemu -machine ...,confidential-guest-support=tdx0\ -object tdx-guset,id=tdx0

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

2023-08-22 Thread Xiaoyao Li
On 8/22/2023 7:00 AM, Isaku Yamahata wrote: On Fri, Aug 18, 2023 at 05:49:51AM -0400, Xiaoyao Li wrote: diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 56cb826f6125..3198bc9fd5fb 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c ... +static inline uint32_t

Re: [PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM

2023-08-22 Thread Xiaoyao Li
On 8/22/2023 7:40 AM, Isaku Yamahata wrote: On Fri, Aug 18, 2023 at 05:50:15AM -0400, Xiaoyao Li wrote: diff --git a/target/i386/kvm/tdx.h b/target/i386/kvm/tdx.h index e9d2888162ce..9b3c427766ef 100644 --- a/target/i386/kvm/tdx.h +++ b/target/i386/kvm/tdx.h @@ -15,6 +15,17 @@ typedef struct

Re: [PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM

2023-08-22 Thread Xiaoyao Li
On 8/21/2023 5:38 PM, Daniel P. Berrangé wrote: diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index bb806736b4ff..ed617ebab266 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c +static int tdx_accept_ram_range(uint64_t address, uint64_t length) +{ +uint64_t head_star

Re: [PATCH v2 18/58] i386/tdx: Validate TD attributes

2023-08-22 Thread Xiaoyao Li
On 8/21/2023 5:16 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:50:01AM -0400, Xiaoyao Li wrote: 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

Re: [PATCH v2 18/58] i386/tdx: Validate TD attributes

2023-08-22 Thread Xiaoyao Li
On 8/21/2023 5:16 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:50:01AM -0400, Xiaoyao Li wrote: 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

Re: [PATCH v2 15/58] i386/tdx: Add property sept-ve-disable for tdx-guest object

2023-08-22 Thread Xiaoyao Li
On 8/22/2023 2:27 PM, Markus Armbruster wrote: Daniel P. Berrangé writes: On Fri, Aug 18, 2023 at 05:49:58AM -0400, Xiaoyao Li wrote: Bit 28 of TD attribute, named SEPT_VE_DISABLE. When set to 1, it disables EPT violation conversion to #VE on guest TD access of PENDING pages. Some guest OS

Re: [PATCH v2 07/58] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object

2023-08-22 Thread Xiaoyao Li
On 8/21/2023 4:48 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:49:50AM -0400, Xiaoyao Li wrote: 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 ev

Re: [PATCH v2 06/58] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES

2023-08-22 Thread Xiaoyao Li
On 8/21/2023 4:46 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:49:49AM -0400, Xiaoyao Li wrote: KVM provides TDX capabilities via sub command KVM_TDX_CAPABILITIES of IOCTL(KVM_MEMORY_ENCRYPT_OP). Get the capabilities when initializing TDX context. It will be used to validate user&#

Re: [PATCH v2 03/58] target/i386: Parse TDX vm type

2023-08-21 Thread Xiaoyao Li
On 8/21/2023 4:27 PM, Daniel P. Berrangé wrote: On Fri, Aug 18, 2023 at 05:49:46AM -0400, Xiaoyao Li wrote: TDX VM requires VM type KVM_X86_TDX_VM to be passed to kvm_ioctl(KVM_CREATE_VM). If tdx-guest object is specified to confidential-guest-support, like, qemu -machine ...,confidential

[PATCH v2 56/58] i386/tdx: Skip kvm_put_apicbase() for TDs

2023-08-18 Thread Xiaoyao Li
KVM doesn't allow wirting to MSR_IA32_APICBASE for TDs. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- 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 53d8d65f6667..d542351983cd 100644 --- a/target

[PATCH v2 50/58] i386/tdx: Don't allow system reset for TDX VMs

2023-08-18 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 601683d836c8..50b0218

[PATCH v2 47/58] i386/tdx: Wire REPORT_FATAL_ERROR with GuestPanic facility

2023-08-18 Thread Xiaoyao Li
Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- qapi/run-state.json | 17 +-- softmmu/runstate.c| 49 +++ target/i386/kvm/tdx.c | 24 - 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a

[PATCH v2 42/58] i386/tdx: register the fd read callback with the main loop to read the quote data

2023-08-18 Thread Xiaoyao Li
the server returns. Set the io channel non-blocking and register the socket fd with the main loop. Move the read operation into the callback. When the fd is readable, inovke the callback to handle the quote data. Signed-off-by: Chenyi Qiang Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c

[PATCH v2 52/58] hw/i386: add eoi_intercept_unsupported member to X86MachineState

2023-08-18 Thread Xiaoyao Li
. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- 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 a0c9f4d646e2..567384484244 100644 --- a/hw/i386/x86.c +++ b/hw/i386

[PATCH v2 58/58] docs: Add TDX documentation

2023-08-18 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 since v1: - Add prerequisite of private gmem; - update example command to launch TD; Changes since RFC v4: - add the restriction that kernel-irqchip must be

[PATCH v2 48/58] i386/tdx: Disable SMM for TDX VMs

2023-08-18 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

[PATCH v2 57/58] i386/tdx: Don't get/put guest state for TDX VMs

2023-08-18 Thread Xiaoyao Li
Sean Christopherson Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- 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 d542351983cd..1422c79aca40 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/

[PATCH v2 45/58] i386/tdx: Limit the range size for MapGPA

2023-08-18 Thread Xiaoyao Li
igned-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 19 ++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 0c43c1f7759f..ced55be506d1 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -994,12 +9

[PATCH v2 40/58] i386/tdx: handle TDG.VP.VMCALL

2023-08-18 Thread Xiaoyao Li
: Xiaoyao Li --- target/i386/kvm/kvm.c | 9 ++ target/i386/kvm/tdx-stub.c | 4 +++ target/i386/kvm/tdx.c | 61 ++ target/i386/kvm/tdx.h | 6 4 files changed, 80 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index

[PATCH v2 51/58] i386/tdx: LMCE is not supported for TDX

2023-08-18 Thread Xiaoyao Li
LMCE is not supported TDX since KVM doesn't provide emulation for MSR_IA32_FEAT_CTL. Signed-off-by: Xiaoyao Li --- target/i386/kvm/kvm-cpu.c | 5 + 1 file changed, 5 insertions(+) diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index 7237378a7d4e..bec8b5f918e7 1

[PATCH v2 41/58] i386/tdx: handle TDG.VP.VMCALL

2023-08-18 Thread Xiaoyao Li
mmand line example: qemu-system-x86_64 \ -object 'tdx-guest,id=tdx0,quote-generation-service=localhost:1234' \ -machine confidential-guest-support=tdx0 Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- qapi/qom.json | 5 +- target/i386/kvm/tdx.c | 380 +

[PATCH v2 37/58] i386/tdx: register TDVF as private memory

2023-08-18 Thread Xiaoyao Li
From: Chao Peng Allocate private gmem memory for BIOS if it's TD VM. Signed-off-by: Chao Peng Co-developed-by: Xiaoyao Li Signed-off-by: Xiaoyao Li --- hw/i386/x86.c | 9 - target/i386/kvm/tdx.c | 17 + target/i386/kvm/tdx.h | 2 ++ 3 files change

[PATCH v2 54/58] i386/tdx: Don't synchronize guest tsc for TDs

2023-08-18 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 Acked-by: Gerd Hof

[PATCH v2 46/58] i386/tdx: Handle TDG.VP.VMCALL

2023-08-18 Thread Xiaoyao Li
Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 40 1 file changed, 40 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index ced55be506d1..f111b46dac92 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c

[PATCH v2 49/58] i386/tdx: Disable PIC for TDX VMs

2023-08-18 Thread Xiaoyao Li
s 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 f9d03ab0f461..23ecd84a9e21 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i38

[PATCH v2 39/58] i386/tdx: Finalize TDX VM

2023-08-18 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/td

[PATCH v2 38/58] i386/tdx: Call KVM_TDX_INIT_VCPU to initialize TDX vcpu

2023-08-18 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 v2 53/58] hw/i386: add option to forcibly report edge trigger in acpi tables

2023-08-18 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 Acked-by: Gerd Hoffmann --- hw/i386/acpi-build.c | 99 --- hw/i386

[PATCH v2 55/58] i386/tdx: Only configure MSR_IA32_UCODE_REV in kvm_init_msrs() for TDs

2023-08-18 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 v2 20/58] i386/tdx: Allows mrconfigid/mrowner/mrownerconfig for TDX_INIT_VM

2023-08-18 Thread Xiaoyao Li
onfig=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- TODO: - community requests to use base64 encoding if no special reason --- qapi/qom.json | 11 ++- target/i386/kvm/tdx.c

[PATCH v2 29/58] i386/tdx: Skip BIOS shadowing setup

2023-08-18 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 Acked-by: Gerd Hoffmann --- Changes from R

[PATCH v2 31/58] i386/tdx: Track mem_ptr for each firmware entry of TDVF

2023-08-18 Thread Xiaoyao Li
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 | 31 +++ 3 files changed, 39 insertions(+) diff --git a/hw/i386/tdvf.c b/hw/i386/tdvf.c index ff51f40088f0

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

2023-08-18 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/kv

[PATCH v2 23/58] i386/tdx: Make memory type private by default

2023-08-18 Thread Xiaoyao Li
iolation Originated-from: Isaku Yamahata Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 22 ++ 1 file changed, 22 insertions(+) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 8a2491ed03c2..775110f8bd02 100644 --- a/target/i386/kvm/tdx.c +++ b/target/

[PATCH v2 36/58] memory: Introduce memory_region_init_ram_gmem()

2023-08-18 Thread Xiaoyao Li
Introduce memory_region_init_ram_gmem() to allocate private gmem on the MemoryRegion initialization. It's for the usercase of TDVF, which must be private on TDX case. Signed-off-by: Xiaoyao Li --- include/exec/memory.h | 6 + softmmu/memory.c

[PATCH v2 24/58] i386/tdx: Create kvm gmem for TD

2023-08-18 Thread Xiaoyao Li
From: Isaku Yamahata Allocate private gmem for TD guest, if the MemoryRegion is memory backend and has private property on. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- target/i386/kvm/tdx.c | 27 +-- 1 file changed, 25 insertions(+), 2 deletions

[PATCH v2 18/58] i386/tdx: Validate TD attributes

2023-08-18 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 v2 33/58] headers: Add definitions from UEFI spec for volumes, resources, etc...

2023-08-18 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 Acked-by: Gerd Hoffmann --- include/standard-headers/uefi/uefi.h | 198 +++ 1 file

[PATCH v2 30/58] i386/tdx: Don't initialize pc.rom for TDX VMs

2023-08-18 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 v2 34/58] i386/tdx: Setup the TD HOB list

2023-08-18 Thread Xiaoyao Li
d-off-by: Isaku Yamahata Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- Changes from RFC v4: - drop the code of adding mmio resources since OVMF prepares all the MMIO hob itself. --- hw/i386/meson.build

[PATCH v2 35/58] i386/tdx: Add TDVF memory via KVM_TDX_INIT_MEM_REGION

2023-08-18 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 var

[PATCH v2 25/58] kvm/tdx: Don't complain when converting vMMIO region to shared

2023-08-18 Thread Xiaoyao Li
From: Isaku Yamahata Because vMMIO region needs to be shared region, guest TD may explicitly convert such region from private to shared. Don't complain such conversion. Signed-off-by: Isaku Yamahata Signed-off-by: Xiaoyao Li --- accel/kvm/kvm-all.c | 20 ++-- 1 file ch

[PATCH v2 32/58] i386/tdx: Track RAM entries for TDX VM

2023-08-18 Thread Xiaoyao Li
;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 Acked-by: Gerd Hoffmann --- Changes from RFC v4: - simplify the algorithm of tdx_accept

[PATCH v2 27/58] i386/tdvf: Introduce function to parse TDVF metadata

2023-08-18 Thread Xiaoyao Li
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 Acked-by: Gerd Hoffmann --- Changes

<    1   2   3   4   5   6   7   8   9   10   >