Re: [RFC PATCH v5 09/29] KVM: selftests: TDX: Add report_fatal_error test

2024-04-17 Thread Yan Zhao
On Tue, Apr 16, 2024 at 11:50:19AM -0700, Sean Christopherson wrote: > On Mon, Apr 15, 2024, Yan Zhao wrote: > > On Mon, Apr 15, 2024 at 08:05:49AM +, Ackerley Tng wrote: > > > >> The Intel GHCI Spec says in R12, bit 63 is set if the GPA is valid. As > > > >

Re: [RFC PATCH v5 09/29] KVM: selftests: TDX: Add report_fatal_error test

2024-04-15 Thread Yan Zhao
On Mon, Apr 15, 2024 at 08:05:49AM +, Ackerley Tng wrote: > Yan Zhao writes: > > > On Fri, Apr 12, 2024 at 04:56:36AM +, Ackerley Tng wrote: > >> Yan Zhao writes: > >> > >> > ... > >> >> diff --git a/tools/testing/selftests/kv

Re: [RFC PATCH v5 09/29] KVM: selftests: TDX: Add report_fatal_error test

2024-04-12 Thread Yan Zhao
On Fri, Apr 12, 2024 at 04:56:36AM +, Ackerley Tng wrote: > Yan Zhao writes: > > > ... > >> diff --git a/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h > >> b/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h > >> index b570b6d978f

Re: [RFC PATCH v5 28/29] KVM: selftests: TDX: Add TDX UPM selftest

2024-03-06 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:43PM -0800, Sagi Shahar wrote: > From: Ackerley Tng > > This tests the use of guest memory with explicit MapGPA calls. > > Signed-off-by: Ackerley Tng > Signed-off-by: Ryan Afranji > Signed-off-by: Sagi Shahar > --- > tools/testing/selftests/kvm/Makefile

Re: [RFC PATCH v5 21/29] KVM: selftests: TDX: Add TDG.VP.INFO test

2024-03-05 Thread Yan Zhao
> +/* > + * TDG.VP.INFO call from the guest. Verify the right values are returned > + */ > +void verify_tdcall_vp_info(void) > +{ > + const int num_vcpus = 2; > + struct kvm_vcpu *vcpus[num_vcpus]; > + struct kvm_vm *vm; > + > + uint64_t rcx, rdx, r8, r9, r10, r11; > + uint32_t

Re: [RFC PATCH v5 24/29] KVM: selftests: Expose _vm_vaddr_alloc

2024-03-05 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:39PM -0800, Sagi Shahar wrote: > From: Ackerley Tng > > vm_vaddr_alloc always allocates memory in memslot 0. This allows users > of this function to choose which memslot to allocate virtual memory > in. > > Signed-off-by: Ackerley Tng > Signed-off-by: Ryan Afranji

Re: [RFC PATCH v5 23/29] KVM: selftests: TDX: Add shared memory test

2024-03-05 Thread Yan Zhao
On Fri, Mar 01, 2024 at 08:02:43PM +0800, Yan Zhao wrote: > > +void guest_shared_mem(void) > > +{ > > + uint32_t *test_mem_shared_gva = > > + (uint32_t *)TDX_SHARED_MEM_TEST_SHARED_GVA; > > + > > + uint64_t placeholder; > > + uint64

Re: [RFC PATCH v5 23/29] KVM: selftests: TDX: Add shared memory test

2024-03-05 Thread Yan Zhao
> +int verify_shared_mem(void) > +{ > + struct kvm_vm *vm; > + struct kvm_vcpu *vcpu; > + > + vm_vaddr_t test_mem_private_gva; > + uint32_t *test_mem_hva; > + > + vm = td_create(); > + td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0); > + vcpu = td_vcpu_add(vm, 0, guest_shared

Re: [RFC PATCH v5 22/29] KVM: selftests: Add functions to allow mapping as shared

2024-03-05 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:37PM -0800, Sagi Shahar wrote: > From: Ackerley Tng > > Signed-off-by: Ackerley Tng > Signed-off-by: Ryan Afranji > Signed-off-by: Sagi Shahar > --- > .../selftests/kvm/include/kvm_util_base.h | 24 ++ > tools/testing/selftests/kvm/lib/kvm_util.c

Re: [RFC PATCH v5 18/29] KVM: selftests: TDX: Add TDX MMIO writes test

2024-03-05 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:33PM -0800, Sagi Shahar wrote: > The test verifies MMIO writes of various sizes from the guest to the host. > > Signed-off-by: Sagi Shahar > Signed-off-by: Ackerley Tng > Signed-off-by: Ryan Afranji > --- > .../selftests/kvm/include/x86_64/tdx/tdx.h| 2 + > .

Re: [RFC PATCH v5 17/29] KVM: selftests: TDX: Add TDX MMIO reads test

2024-03-04 Thread Yan Zhao
> +/* Pick any address that was not mapped into the guest to test MMIO */ > +#define TDX_MMIO_TEST_ADDR 0x2 Also need to test below MMIO addresses (1) GPA with shared bit on. (2) GPA in memslot

Re: [RFC PATCH v5 16/29] KVM: selftests: TDX: Add TDX HLT exit test

2024-03-04 Thread Yan Zhao
On Sat, Mar 02, 2024 at 03:31:07PM +0800, Binbin Wu wrote: > On 12/13/2023 4:46 AM, Sagi Shahar wrote: > > The test verifies that the guest runs TDVMCALL and the > > guest vCPU enters to the halted state. > > > > Signed-off-by: Erdem Aktas > > Signed-off-by: Sagi Shahar > > Signed-off-by: Ackerl

Re: [RFC PATCH v5 15/29] KVM: selftests: TDX: Add TDX MSR read/write tests

2024-03-04 Thread Yan Zhao
> +void verify_guest_msr_writes(void) > +{ > + struct kvm_vcpu *vcpu; > + struct kvm_vm *vm; > + > + uint64_t data; > + int ret; > + > + vm = td_create(); > + td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0); > + > + /* > + * Set explicit MSR filter map to control access

Re: [RFC PATCH v5 10/29] KVM: selftests: TDX: Adding test case for TDX port IO

2024-03-04 Thread Yan Zhao
On Mon, Mar 04, 2024 at 05:16:53PM +0800, Binbin Wu wrote: > > > On 3/4/2024 10:19 AM, Yan Zhao wrote: > > On Tue, Dec 12, 2023 at 12:46:25PM -0800, Sagi Shahar wrote: > > > From: Erdem Aktas > > > > > > Verifies TDVMCALL READ and WRITE operation

Re: [RFC PATCH v5 10/29] KVM: selftests: TDX: Adding test case for TDX port IO

2024-03-03 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:25PM -0800, Sagi Shahar wrote: > From: Erdem Aktas > > Verifies TDVMCALL READ and WRITE operations. > > Signed-off-by: Erdem Aktas > Signed-off-by: Sagi Shahar > Signed-off-by: Ackerley Tng > Signed-off-by: Ryan Afranji > --- > .../kvm/include/x86_64/tdx/test_u

Re: [RFC PATCH v5 09/29] KVM: selftests: TDX: Add report_fatal_error test

2024-03-01 Thread Yan Zhao
... > diff --git a/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h > b/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h > index b570b6d978ff..6d69921136bd 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h > +++ b/tools/testing/selftests/kvm/include/x86_

Re: [RFC PATCH v5 23/29] KVM: selftests: TDX: Add shared memory test

2024-03-01 Thread Yan Zhao
> +void guest_shared_mem(void) > +{ > + uint32_t *test_mem_shared_gva = > + (uint32_t *)TDX_SHARED_MEM_TEST_SHARED_GVA; > + > + uint64_t placeholder; > + uint64_t ret; > + > + /* Map gpa as shared */ > + ret = tdg_vp_vmcall_map_gpa(test_mem_shared_gpa, PAGE_SIZE, > +

Re: [RFC PATCH v5 08/29] KVM: selftests: TDX: Add TDX lifecycle test

2024-03-01 Thread Yan Zhao
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c > b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c > index 063ff486fb86..b302060049d5 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c > @@

Re: [RFC PATCH v5 08/29] KVM: selftests: TDX: Add TDX lifecycle test

2024-02-29 Thread Yan Zhao
> diff --git a/tools/testing/selftests/kvm/lib/x86_64/tdx/tdcall.S > b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdcall.S > new file mode 100644 > index ..df9c1ed4bb2d > --- /dev/null > +++ b/tools/testing/selftests/kvm/lib/x86_64/tdx/tdcall.S > @@ -0,0 +1,90 @@ > +/* SPDX-License-Ide

Re: [RFC PATCH v5 05/29] KVM: selftests: Add helper functions to create TDX VMs

2024-02-22 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:20PM -0800, Sagi Shahar wrote: > From: Erdem Aktas > +/** > + * Adds a vCPU to a TD (Trusted Domain) with minimum defaults. It will not > set > + * up any general purpose registers as they will be initialized by the TDX. > In > + * TDX, vCPUs RIP is set to 0xFFF

Re: [RFC PATCH v5 07/29] KVM: selftests: TDX: Update load_td_memory_region for VM memory backed by guest memfd

2024-02-22 Thread Yan Zhao
On Tue, Dec 12, 2023 at 12:46:22PM -0800, Sagi Shahar wrote: > From: Ackerley Tng > > If guest memory is backed by restricted memfd > > + UPM is being used, hence encrypted memory region has to be > registered > + Can avoid making a copy of guest memory before getting TDX to > initialize the

Re: [RFC PATCH v2 1/3] KVM: allow mapping of compound tail pages for IO or PFNMAP mapping

2024-02-20 Thread Yan Zhao
On Mon, Feb 12, 2024 at 07:17:21PM -0800, Sean Christopherson wrote: > On Wed, Jan 03, 2024, Yan Zhao wrote: > > Allow mapping of tail pages of compound pages for IO or PFNMAP mapping > > by trying and getting ref count of its head page. > > > > For IO or PFNMAP mappin

Re: [RFC PATCH v2 0/3] KVM: allow mapping of compound tail pages for IO or PFNMAP mapping

2024-02-20 Thread Yan Zhao
On Mon, Feb 12, 2024 at 07:07:25PM -0800, Sean Christopherson wrote: > On Wed, Jan 03, 2024, Yan Zhao wrote: > > This is a v2 for previous series [1] to allow mapping for compound tail > > pages for IO or PFNMAP mapping. > > > > Compared to v1, this version

Re: [RFC PATCH v2 2/3] KVM: selftests: add selftest driver for KVM to test memory slots for MMIO BARs

2024-01-11 Thread Yan Zhao
On Wed, Jan 10, 2024 at 02:27:08PM +0800, Yuan Yao wrote: > > > Do you have plan to allow user to change the bar_size via IOCTL ? > > > If no "order" and "bar_size" can be removed. > > > > > Currently no. But this structure is private to the test driver. > > What the benefit to remove the two? > >

Re: [RFC PATCH v2 3/3] KVM: selftests: Add set_memory_region_io to test memslots for MMIO BARs

2024-01-05 Thread Yan Zhao
On Fri, Jan 05, 2024 at 02:25:26PM +0800, Yuan Yao wrote: > On Wed, Jan 03, 2024 at 04:45:35PM +0800, Yan Zhao wrote: > > Added a selftest set_memory_region_io to test memslots for MMIO BARs. > > Emm.. "set_memory_region_io" doesn't represent the real testing pur

Re: [RFC PATCH v2 2/3] KVM: selftests: add selftest driver for KVM to test memory slots for MMIO BARs

2024-01-05 Thread Yan Zhao
On Thu, Jan 04, 2024 at 04:16:04PM +0800, Yuan Yao wrote: > On Wed, Jan 03, 2024 at 04:44:57PM +0800, Yan Zhao wrote: > > This driver is for testing KVM memory slots for device MMIO BARs that are > > mapped to pages serving as device resources. > > > > This driver imp

[RFC PATCH v2 3/3] KVM: selftests: Add set_memory_region_io to test memslots for MMIO BARs

2024-01-03 Thread Yan Zhao
KVM_MOCK_DEVICE=m must be enabled in the kernel. Currently, this selftest is only compiled for __x86_64__. Signed-off-by: Yan Zhao --- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/set_memory_region_io.c | 188 ++ 2 files changed, 189 insertions(+)

[RFC PATCH v2 2/3] KVM: selftests: add selftest driver for KVM to test memory slots for MMIO BARs

2024-01-03 Thread Yan Zhao
mslot add/removal. Signed-off-by: Yan Zhao --- lib/Kconfig.debug | 14 ++ lib/Makefile| 1 + lib/test_kvm_mock_device.c | 281 lib/test_kvm_mock_device_uapi.h | 16 ++ 4 files changed, 312 insertions(+) create mode 10064

[RFC PATCH v2 1/3] KVM: allow mapping of compound tail pages for IO or PFNMAP mapping

2024-01-03 Thread Yan Zhao
of a non-compound tail page is the same as the page itself. On the other side, put_page() has already converted page to folio before putting page ref. Signed-off-by: Yan Zhao --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/vir

[RFC PATCH v2 0/3] KVM: allow mapping of compound tail pages for IO or PFNMAP mapping

2024-01-03 Thread Yan Zhao
e...@google.com/ v2: added patch 2 and 3 to do selftest for patch 1 (Sean). Yan Zhao (3): KVM: allow mapping of compound tail pages for IO or PFNMAP mapping KVM: selftests: add selftest driver for KVM to test memory slots for MMIO BARs KVM: selftests: Add set_memory_region_io to test memslo

Re: [PATCH v4 03/17] iommufd: Unite all kernel-managed members into a struct

2023-10-08 Thread Yan Zhao
On Mon, Oct 09, 2023 at 12:13:52PM +0800, Yi Liu wrote: > On 2023/10/7 18:08, Yan Zhao wrote: > > On Thu, Sep 21, 2023 at 12:51:24AM -0700, Yi Liu wrote: > > > From: Nicolin Chen > > > > > > The struct iommufd_hw_pagetable has been representing a kernel-

Re: [PATCH v4 03/17] iommufd: Unite all kernel-managed members into a struct

2023-10-07 Thread Yan Zhao
On Thu, Sep 21, 2023 at 12:51:24AM -0700, Yi Liu wrote: > From: Nicolin Chen > > The struct iommufd_hw_pagetable has been representing a kernel-managed > HWPT, yet soon will be reused to represent a user-managed HWPT. These > two types of HWPTs has the same IOMMUFD object type and an iommu_domain

Re: [PATCH v4 09/17] iommufd/device: Add helpers to enforce/remove device reserved regions

2023-10-07 Thread Yan Zhao
> @@ -444,10 +465,9 @@ iommufd_device_do_replace(struct iommufd_device *idev, > } > > old_hwpt = igroup->hwpt; > - if (hwpt->ioas != old_hwpt->ioas) { > + if (iommufd_hw_pagetable_compare_ioas(old_hwpt, hwpt)) { > list_for_each_entry(cur, &igroup->device_list, gr