Skip to contentSkip to conversation

TDX KVM selftests

RFC PATCH In review Sagi Shahar 10 participants 109 messages Dec 12, 2023 – Jul 30, 2024 3 messages not in the archive Page 2 of 2

Subsystems (4)
lore
Share & tools
lore
#90 lore raw

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

In reply to Sagi Shahar
Quoted 5 lines · Sagi Shahar

From: Ackerley Tng <[email protected]>

vm_vaddr_alloc always allocates memory in memslot 0. This allows users of this function to choose which memslot to allocate virtual memory in.

Nit: The patch exposes ____vm_vaddr_alloc() instead of _vm_vaddr_alloc().

Quoted 39 lines
---
  tools/testing/selftests/kvm/include/kvm_util_base.h | 3 +++
  tools/testing/selftests/kvm/lib/kvm_util.c          | 6 +++---
  2 files changed, 6 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/include/kvm_util_base.h +3 -0
index efd7ae8abb20..5dbebf5cfd07 100644
@@ -561,6 +561,9 @@ void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot);
  struct kvm_vcpu *__vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id);
  void vm_populate_vaddr_bitmap(struct kvm_vm *vm);
  vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min);
+vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz,
+			      vm_vaddr_t vaddr_min, vm_paddr_t paddr_min,
+			      uint32_t data_memslot, bool encrypt);
  vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min);
  vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
  			    enum kvm_mem_region_type type);
tools/testing/selftests/kvm/lib/kvm_util.c +3 -3
index 28780fa1f0f2..d024abc5379c 100644
@@ -1410,9 +1410,9 @@ vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz,
   * a unique set of pages, with the minimum real allocation being at least
   * a page.
   */
-static vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz,
-				     vm_vaddr_t vaddr_min, vm_paddr_t paddr_min,
-				     uint32_t data_memslot, bool encrypt)
+vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz,
+			      vm_vaddr_t vaddr_min, vm_paddr_t paddr_min,
+			      uint32_t data_memslot, bool encrypt)
  {
  	uint64_t pages = (sz >> vm->page_shift) + ((sz % vm->page_size) != 0);
 
#91 lore raw

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

In reply to Sagi Shahar
Quoted 33 lines · Sagi Shahar

From: Ackerley Tng <[email protected]>

vm_vaddr_alloc always allocates memory in memslot 0. This allows users of this function to choose which memslot to allocate virtual memory in.

---
 tools/testing/selftests/kvm/include/kvm_util_base.h | 3 +++
 tools/testing/selftests/kvm/lib/kvm_util.c          | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)
tools/testing/selftests/kvm/include/kvm_util_base.h +3 -0
index efd7ae8abb20..5dbebf5cfd07 100644
@@ -561,6 +561,9 @@ void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot);
 struct kvm_vcpu *__vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpu_id);
 void vm_populate_vaddr_bitmap(struct kvm_vm *vm);
 vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min);
+vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz,
+			      vm_vaddr_t vaddr_min, vm_paddr_t paddr_min,
+			      uint32_t data_memslot, bool encrypt);
 vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min);
 vm_vaddr_t __vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min,
 			    enum kvm_mem_region_type type);
tools/testing/selftests/kvm/lib/kvm_util.c +0 -0
index 28780fa1f0f2..d024abc5379c 100644

tools/testing/selftests/kvm/lib/kvm_util.c vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, · line 1415

Quoted 9 lines
tools/testing/selftests/kvm/lib/kvm_util.c +3 -3
@@ -1410,9 +1410,9 @@ vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz,
  * a unique set of pages, with the minimum real allocation being at least
  * a page.
  */
-static vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz,
-				     vm_vaddr_t vaddr_min, vm_paddr_t paddr_min,
-				     uint32_t data_memslot, bool encrypt)
+vm_vaddr_t ____vm_vaddr_alloc(struct kvm_vm *vm, size_t sz,
+			      vm_vaddr_t vaddr_min, vm_paddr_t paddr_min,
+			      uint32_t data_memslot, bool encrypt)

Is it better to expose a helper function with meaningful name? It's annoying to count the number of "_" to figure out which version is used, especially when there're "__", "____" versions :)

Quoted 7 lines
tools/testing/selftests/kvm/lib/kvm_util.c +0 -0
 {
 	uint64_t pages = (sz >> vm->page_shift) + ((sz % vm->page_size) != 0);
 
Signature · 1 line
2.43.0.472.g3155946c3a-goog
#92 lore raw

RFC PATCH v5 25/29 KVM: selftests: TDX: Add support for TDG.MEM.PAGE.ACCEPT

In reply to Sagi Shahar

From: Ackerley Tng <[email protected]>

---
 tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h | 2 ++
 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c     | 5 +++++
 2 files changed, 7 insertions(+)
tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h +2 -0
index db4cc62abb5d..b71bcea40b5c 100644
@@ -6,6 +6,7 @@
 #include "kvm_util_base.h"
 
 #define TDG_VP_INFO 1
+#define TDG_MEM_PAGE_ACCEPT 6
 
 #define TDG_VP_VMCALL_GET_TD_VM_CALL_INFO 0x10000
 #define TDG_VP_VMCALL_MAP_GPA 0x10001
@@ -38,5 +39,6 @@ uint64_t tdg_vp_info(uint64_t *rcx, uint64_t *rdx,
 		     uint64_t *r8, uint64_t *r9,
 		     uint64_t *r10, uint64_t *r11);
 uint64_t tdg_vp_vmcall_map_gpa(uint64_t address, uint64_t size, uint64_t *data_out);
+uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level);
 
 #endif // SELFTEST_TDX_TDX_H
tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c +5 -0
index 061a5c0bef34..d8c4ab635c06 100644
@@ -236,3 +236,8 @@ uint64_t tdg_vp_vmcall_map_gpa(uint64_t address, uint64_t size, uint64_t *data_o
 		*data_out = args.r11;
 	return ret;
 }
+
+uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level)
+{
+	return __tdx_module_call(TDG_MEM_PAGE_ACCEPT, gpa | level, 0, 0, 0, NULL);
+}
Signature · 1 line
2.43.0.472.g3155946c3a-goog
#93 lore raw

RFC PATCH v5 26/29 KVM: selftests: TDX: Add support for TDG.VP.VEINFO.GET

In reply to Sagi Shahar

From: Ackerley Tng <[email protected]>

---
 .../selftests/kvm/include/x86_64/tdx/tdx.h    | 21 +++++++++++++++++++
 .../selftests/kvm/lib/x86_64/tdx/tdx.c        | 19 +++++++++++++++++
 2 files changed, 40 insertions(+)
tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h +21 -0
index b71bcea40b5c..12863a8beaae 100644
@@ -6,6 +6,7 @@
 #include "kvm_util_base.h"
 
 #define TDG_VP_INFO 1
+#define TDG_VP_VEINFO_GET 3
 #define TDG_MEM_PAGE_ACCEPT 6
 
 #define TDG_VP_VMCALL_GET_TD_VM_CALL_INFO 0x10000
@@ -41,4 +42,24 @@ uint64_t tdg_vp_info(uint64_t *rcx, uint64_t *rdx,
 uint64_t tdg_vp_vmcall_map_gpa(uint64_t address, uint64_t size, uint64_t *data_out);
 uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level);
 
+/*
+ * Used by the #VE exception handler to gather the #VE exception
+ * info from the TDX module. This is a software only structure
+ * and not part of the TDX module/VMM ABI.
+ *
+ * Adapted from arch/x86/include/asm/tdx.h
+ */
+struct ve_info {
+	uint64_t exit_reason;
+	uint64_t exit_qual;
+	/* Guest Linear (virtual) Address */
+	uint64_t gla;
+	/* Guest Physical Address */
+	uint64_t gpa;
+	uint32_t instr_len;
+	uint32_t instr_info;
+};
+
+uint64_t tdg_vp_veinfo_get(struct ve_info *ve);
+
 #endif // SELFTEST_TDX_TDX_H
tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c +19 -0
index d8c4ab635c06..71d9f55007f7 100644
@@ -241,3 +241,22 @@ uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level)
 {
 	return __tdx_module_call(TDG_MEM_PAGE_ACCEPT, gpa | level, 0, 0, 0, NULL);
 }
+
+uint64_t tdg_vp_veinfo_get(struct ve_info *ve)
+{
+	uint64_t ret;
+	struct tdx_module_output out;
+
+	memset(&out, 0, sizeof(struct tdx_module_output));
+
+	ret = __tdx_module_call(TDG_VP_VEINFO_GET, 0, 0, 0, 0, &out);
+
+	ve->exit_reason = out.rcx;
+	ve->exit_qual   = out.rdx;
+	ve->gla         = out.r8;
+	ve->gpa         = out.r9;
+	ve->instr_len   = out.r10 & 0xffffffff;
+	ve->instr_info  = out.r10 >> 32;
+
+	return ret;
+}
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Reviewed-by on v5 26/29
#94 lore raw

Re: [RFC PATCH v5 26/29] KVM: selftests: TDX: Add support for TDG.VP.VEINFO.GET

Quoted 9 lines · Sagi Shahar

From: Ackerley Tng <[email protected]>

---
  .../selftests/kvm/include/x86_64/tdx/tdx.h    | 21 +++++++++++++++++++
  .../selftests/kvm/lib/x86_64/tdx/tdx.c        | 19 +++++++++++++++++
  2 files changed, 40 insertions(+)
Quoted 65 lines
tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h +21 -0
index b71bcea40b5c..12863a8beaae 100644
@@ -6,6 +6,7 @@
  #include "kvm_util_base.h"
 
  #define TDG_VP_INFO 1
+#define TDG_VP_VEINFO_GET 3
  #define TDG_MEM_PAGE_ACCEPT 6
 
  #define TDG_VP_VMCALL_GET_TD_VM_CALL_INFO 0x10000
@@ -41,4 +42,24 @@ uint64_t tdg_vp_info(uint64_t *rcx, uint64_t *rdx,
  uint64_t tdg_vp_vmcall_map_gpa(uint64_t address, uint64_t size, uint64_t *data_out);
  uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level);
 
+/*
+ * Used by the #VE exception handler to gather the #VE exception
+ * info from the TDX module. This is a software only structure
+ * and not part of the TDX module/VMM ABI.
+ *
+ * Adapted from arch/x86/include/asm/tdx.h
+ */
+struct ve_info {
+	uint64_t exit_reason;
+	uint64_t exit_qual;
+	/* Guest Linear (virtual) Address */
+	uint64_t gla;
+	/* Guest Physical Address */
+	uint64_t gpa;
+	uint32_t instr_len;
+	uint32_t instr_info;
+};
+
+uint64_t tdg_vp_veinfo_get(struct ve_info *ve);
+
  #endif // SELFTEST_TDX_TDX_H
tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c +19 -0
index d8c4ab635c06..71d9f55007f7 100644
@@ -241,3 +241,22 @@ uint64_t tdg_mem_page_accept(uint64_t gpa, uint8_t level)
  {
  	return __tdx_module_call(TDG_MEM_PAGE_ACCEPT, gpa | level, 0, 0, 0, NULL);
  }
+
+uint64_t tdg_vp_veinfo_get(struct ve_info *ve)
+{
+	uint64_t ret;
+	struct tdx_module_output out;
+
+	memset(&out, 0, sizeof(struct tdx_module_output));
+
+	ret = __tdx_module_call(TDG_VP_VEINFO_GET, 0, 0, 0, 0, &out);
+
+	ve->exit_reason = out.rcx;
+	ve->exit_qual   = out.rdx;
+	ve->gla         = out.r8;
+	ve->gpa         = out.r9;
+	ve->instr_len   = out.r10 & 0xffffffff;
+	ve->instr_info  = out.r10 >> 32;
+
+	return ret;
+}
#95 lore raw

RFC PATCH v5 27/29 KVM: selftests: Propagate KVM_EXIT_MEMORY_FAULT to userspace

In reply to Sagi Shahar

Allow userspace to handle KVM_EXIT_MEMORY_FAULT instead of triggering TEST_ASSERT.

From the KVM_EXIT_MEMORY_FAULT documentation:
Note! KVM_EXIT_MEMORY_FAULT is unique among all KVM exit reasons in that it accompanies a return code of '-1', not '0'! errno will always be set to EFAULT or EHWPOISON when KVM exits with KVM_EXIT_MEMORY_FAULT, userspace should assume kvm_run.exit_reason is stale/undefined for all other error numbers.

---
 tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/kvm/lib/kvm_util.c +4 -0
index d024abc5379c..8fb041e51484 100644
@@ -1742,6 +1742,10 @@ void vcpu_run(struct kvm_vcpu *vcpu)
 {
 	int ret = _vcpu_run(vcpu);
 
+	// Allow this scenario to be handled by the caller.
+	if (ret == -1 && errno == EFAULT)
+		return;
+
 	TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_RUN, ret));
 }
 
Signature · 1 line
2.43.0.472.g3155946c3a-goog

A message that is not in the archive (sent off-list or not yet received): DS7PR11MB78860170A5FD77253573BC09F6292@DS7PR11MB7886.namprd11.prod.outlook.com

#97 lore raw

Re: [RFC PATCH v5 27/29] KVM: selftests: Propagate KVM_EXIT_MEMORY_FAULT to userspace

Quoted 9 lines · Sagi

-----Original Message-----
From: Sagi Shahar <[email protected]>
Sent: Tuesday, December 12, 2023 12:47 PM
To: [email protected]; Ackerley Tng <[email protected]>; Afranji, Ryan <[email protected]>; Aktas, Erdem <[email protected]>; Sagi Shahar <[email protected]>; Yamahata, Isaku <[email protected]>
Cc: Sean Christopherson <[email protected]>; Paolo Bonzini <[email protected]>; Shuah Khan <[email protected]>; Peter Gonda <[email protected]>; Xu, Haibo1 <[email protected]>; Chao Peng <[email protected]>; Annapurve, Vishal <[email protected]>; Roger Wang <[email protected]>; Vipin Sharma <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [RFC PATCH v5 27/29] KVM: selftests: Propagate KVM_EXIT_MEMORY_FAULT to userspace

Quoted 4 lines

Allow userspace to handle KVM_EXIT_MEMORY_FAULT instead of triggering TEST_ASSERT.

From the KVM_EXIT_MEMORY_FAULT documentation:
Note! KVM_EXIT_MEMORY_FAULT is unique among all KVM exit reasons in that it accompanies a return code of '-1', not '0'! errno will always be set to EFAULT or EHWPOISON when KVM exits with KVM_EXIT_MEMORY_FAULT, userspace should assume kvm_run.exit_reason is stale/undefined for all other error numbers.

If KVM exits to userspace with KVM_EXIT_MEMORY_FAULT, most likely it's because the guest attempts to access the gfn in a way that is different from what the KVM is configured, in terms of private/shared property. I'd suggest to drop this patch and work on the selftests code to eliminate this exit.

If we need a testcase to catch this exit intentionally, we may call _vcpu_run() directly from the testcase and keep the common API vcpu_run() intact.

Quoted 22 lines
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/kvm/lib/kvm_util.c +4 -1
index d024abc5379c..8fb041e51484 100644
@@ -1742,6 +1742,10 @@ void vcpu_run(struct kvm_vcpu *vcpu)  {
 	int ret = _vcpu_run(vcpu);
 
+	// Allow this scenario to be handled by the caller.
+	if (ret == -1 && errno == EFAULT)
+		return;
+
 	TEST_ASSERT(!ret, KVM_IOCTL_ERROR(KVM_RUN, ret));  }
 
--

2.43.0.472.g3155946c3a-goog

#98 lore raw

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

In reply to Sagi Shahar

From: Ackerley Tng <[email protected]>

This tests the use of guest memory with explicit MapGPA calls.

---
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/x86_64/tdx_upm_test.c       | 401 ++++++++++++++++++
 2 files changed, 402 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_upm_test.c
tools/testing/selftests/kvm/Makefile +1 -0
index 8c0a6b395ee5..2f2669af15d6 100644
@@ -157,6 +157,7 @@ TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
 TEST_GEN_PROGS_x86_64 += system_counter_offset_test
 TEST_GEN_PROGS_x86_64 += x86_64/tdx_vm_tests
 TEST_GEN_PROGS_x86_64 += x86_64/tdx_shared_mem_test
+TEST_GEN_PROGS_x86_64 += x86_64/tdx_upm_test
 
 # Compiled outputs used by test targets
 TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +401 -0

401 lines not on this page · raw message

Signature · 1 line
2.43.0.472.g3155946c3a-goog
#99 lore raw

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

Quoted 271 lines · Sagi Shahar

From: Ackerley Tng <[email protected]>

This tests the use of guest memory with explicit MapGPA calls.

---
  tools/testing/selftests/kvm/Makefile          |   1 +
  .../selftests/kvm/x86_64/tdx_upm_test.c       | 401 ++++++++++++++++++
  2 files changed, 402 insertions(+)

create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_upm_test.c

tools/testing/selftests/kvm/Makefile +1 -0
index 8c0a6b395ee5..2f2669af15d6 100644
@@ -157,6 +157,7 @@ TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
  TEST_GEN_PROGS_x86_64 += system_counter_offset_test
  TEST_GEN_PROGS_x86_64 += x86_64/tdx_vm_tests
  TEST_GEN_PROGS_x86_64 += x86_64/tdx_shared_mem_test
+TEST_GEN_PROGS_x86_64 += x86_64/tdx_upm_test
 
  # Compiled outputs used by test targets
  TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +240 -0
new file mode 100644
index 000000000000..44671874a4f1
@@ -0,0 +1,401 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <asm/kvm.h>
+#include <asm/vmx.h>
+#include <linux/kvm.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "kvm_util_base.h"
+#include "processor.h"
+#include "tdx/tdcall.h"
+#include "tdx/tdx.h"
+#include "tdx/tdx_util.h"
+#include "tdx/test_util.h"
+#include "test_util.h"
+
+/* TDX UPM test patterns */
+#define PATTERN_CONFIDENCE_CHECK (0x11)
+#define PATTERN_HOST_FOCUS (0x22)
+#define PATTERN_GUEST_GENERAL (0x33)
+#define PATTERN_GUEST_FOCUS (0x44)
+
+/*
+ * 0x80000000 is arbitrarily selected. The selected address need not be the same
+ * as TDX_UPM_TEST_AREA_GVA_PRIVATE, but it should not overlap with selftest
+ * code or boot page.
+ */
+#define TDX_UPM_TEST_AREA_GPA (0x80000000)
+/* Test area GPA is arbitrarily selected */
+#define TDX_UPM_TEST_AREA_GVA_PRIVATE (0x90000000)
+/* Select any bit that can be used as a flag */
+#define TDX_UPM_TEST_AREA_GVA_SHARED_BIT (32)
+/*
+ * TDX_UPM_TEST_AREA_GVA_SHARED is used to map the same GPA twice into the
+ * guest, once as shared and once as private
+ */
+#define TDX_UPM_TEST_AREA_GVA_SHARED				\
+	(TDX_UPM_TEST_AREA_GVA_PRIVATE |			\
+		BIT_ULL(TDX_UPM_TEST_AREA_GVA_SHARED_BIT))
+
+/* The test area is 2MB in size */
+#define TDX_UPM_TEST_AREA_SIZE (2 << 20)
+/* 0th general area is 1MB in size */
+#define TDX_UPM_GENERAL_AREA_0_SIZE (1 << 20)
+/* Focus area is 40KB in size */
+#define TDX_UPM_FOCUS_AREA_SIZE (40 << 10)
+/* 1st general area is the rest of the space in the test area */
+#define TDX_UPM_GENERAL_AREA_1_SIZE				\
+	(TDX_UPM_TEST_AREA_SIZE - TDX_UPM_GENERAL_AREA_0_SIZE -	\
+		TDX_UPM_FOCUS_AREA_SIZE)
+
+/*
+ * The test memory area is set up as two general areas, sandwiching a focus
+ * area.  The general areas act as control areas. After they are filled, they
+ * are not expected to change throughout the tests. The focus area is memory
+ * permissions change from private to shared and vice-versa.
+ *
+ * The focus area is intentionally small, and sandwiched to test that when the
+ * focus area's permissions change, the other areas' permissions are not
+ * affected.
+ */
+struct __packed tdx_upm_test_area {
+	uint8_t general_area_0[TDX_UPM_GENERAL_AREA_0_SIZE];
+	uint8_t focus_area[TDX_UPM_FOCUS_AREA_SIZE];
+	uint8_t general_area_1[TDX_UPM_GENERAL_AREA_1_SIZE];
+};
+
+static void fill_test_area(struct tdx_upm_test_area *test_area_base,
+			uint8_t pattern)
+{
+	memset(test_area_base, pattern, sizeof(*test_area_base));
+}
+
+static void fill_focus_area(struct tdx_upm_test_area *test_area_base,
+			    uint8_t pattern)
+{
+	memset(test_area_base->focus_area, pattern,
+	       sizeof(test_area_base->focus_area));
+}
+
+static bool check_area(uint8_t *base, uint64_t size, uint8_t expected_pattern)
+{
+	size_t i;
+
+	for (i = 0; i < size; i++) {
+		if (base[i] != expected_pattern)
+			return false;
+	}
+
+	return true;
+}
+
+static bool check_general_areas(struct tdx_upm_test_area *test_area_base,
+				uint8_t expected_pattern)
+{
+	return (check_area(test_area_base->general_area_0,
+			   sizeof(test_area_base->general_area_0),
+			   expected_pattern) &&
+		check_area(test_area_base->general_area_1,
+			   sizeof(test_area_base->general_area_1),
+			   expected_pattern));
+}
+
+static bool check_focus_area(struct tdx_upm_test_area *test_area_base,
+			     uint8_t expected_pattern)
+{
+	return check_area(test_area_base->focus_area,
+			  sizeof(test_area_base->focus_area), expected_pattern);
+}
+
+static bool check_test_area(struct tdx_upm_test_area *test_area_base,
+			    uint8_t expected_pattern)
+{
+	return (check_general_areas(test_area_base, expected_pattern) &&
+		check_focus_area(test_area_base, expected_pattern));
+}
+
+static bool fill_and_check(struct tdx_upm_test_area *test_area_base, uint8_t pattern)
+{
+	fill_test_area(test_area_base, pattern);
+
+	return check_test_area(test_area_base, pattern);
+}
+
+#define TDX_UPM_TEST_ASSERT(x)				\
+	do {						\
+		if (!(x))				\
+			tdx_test_fatal(__LINE__);	\
+	} while (0)
+
+/*
+ * Shared variables between guest and host
+ */
+static struct tdx_upm_test_area *test_area_gpa_private;
+static struct tdx_upm_test_area *test_area_gpa_shared;
+
+/*
+ * Test stages for syncing with host
+ */
+enum {
+	SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST = 1,
+	SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST,
+	SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN,
+};
+
+#define TDX_UPM_TEST_ACCEPT_PRINT_PORT 0x87
+
+/**
+ * Does vcpu_run, and also manages memory conversions if requested by the TD.
+ */
+void vcpu_run_and_manage_memory_conversions(struct kvm_vm *vm,
+					    struct kvm_vcpu *vcpu)
+{
+	for (;;) {
+		vcpu_run(vcpu);
+		if (vcpu->run->exit_reason == KVM_EXIT_TDX &&
+			vcpu->run->tdx.type == KVM_EXIT_TDX_VMCALL &&
+			vcpu->run->tdx.u.vmcall.subfunction == TDG_VP_VMCALL_MAP_GPA) {
+			struct kvm_tdx_vmcall *vmcall_info = &vcpu->run->tdx.u.vmcall;
+			uint64_t gpa = vmcall_info->in_r12 & ~vm->arch.s_bit;
+
+			handle_memory_conversion(vm, gpa, vmcall_info->in_r13,
+				!(vm->arch.s_bit & vmcall_info->in_r12));
+			vmcall_info->status_code = 0;
+			continue;
+		} else if (
+			vcpu->run->exit_reason == KVM_EXIT_IO &&
+			vcpu->run->io.port == TDX_UPM_TEST_ACCEPT_PRINT_PORT) {
+			uint64_t gpa = tdx_test_read_64bit(
+				vcpu, TDX_UPM_TEST_ACCEPT_PRINT_PORT);
+			printf("\t ... guest accepting 1 page at GPA: 0x%lx\n", gpa);
+			continue;
+		}
+
+		break;
+	}
+}
+
+static void guest_upm_explicit(void)
+{
+	uint64_t ret = 0;
+	uint64_t failed_gpa;
+
+	struct tdx_upm_test_area *test_area_gva_private =
+		(struct tdx_upm_test_area *)TDX_UPM_TEST_AREA_GVA_PRIVATE;
+	struct tdx_upm_test_area *test_area_gva_shared =
+		(struct tdx_upm_test_area *)TDX_UPM_TEST_AREA_GVA_SHARED;
+
+	/* Check: host reading private memory does not modify guest's view */
+	fill_test_area(test_area_gva_private, PATTERN_GUEST_GENERAL);
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST);
+
+	TDX_UPM_TEST_ASSERT(
+		check_test_area(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/* Remap focus area as shared */
+	ret = tdg_vp_vmcall_map_gpa((uint64_t)test_area_gpa_shared->focus_area,
+				    sizeof(test_area_gpa_shared->focus_area),
+				    &failed_gpa);
+	TDX_UPM_TEST_ASSERT(!ret);
+
+	/* General areas should be unaffected by remapping */
+	TDX_UPM_TEST_ASSERT(
+		check_general_areas(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/*
+	 * Use memory contents to confirm that the memory allocated using mmap
+	 * is used as backing memory for shared memory - PATTERN_CONFIDENCE_CHECK
+	 * was written by the VMM at the beginning of this test.
+	 */
+	TDX_UPM_TEST_ASSERT(
+		check_focus_area(test_area_gva_shared, PATTERN_CONFIDENCE_CHECK));
+
+	/* Guest can use focus area after remapping as shared */
+	fill_focus_area(test_area_gva_shared, PATTERN_GUEST_FOCUS);
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST);
+
+	/* Check that guest has the same view of shared memory */
+	TDX_UPM_TEST_ASSERT(
+		check_focus_area(test_area_gva_shared, PATTERN_HOST_FOCUS));
+
+	/* Remap focus area back to private */
+	ret = tdg_vp_vmcall_map_gpa((uint64_t)test_area_gpa_private->focus_area,
+				    sizeof(test_area_gpa_private->focus_area),
+				    &failed_gpa);
+	TDX_UPM_TEST_ASSERT(!ret);
+
+	/* General areas should be unaffected by remapping */
+	TDX_UPM_TEST_ASSERT(
+		check_general_areas(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/* Focus area should be zeroed after remapping */
+	TDX_UPM_TEST_ASSERT(check_focus_area(test_area_gva_private, 0));
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN);
+
+	/* Check that guest can use private memory after focus area is remapped as private */
+	TDX_UPM_TEST_ASSERT(

tools/testing/selftests/kvm/x86_64/tdx_upm_test.c line 250

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +10 -0
+		fill_and_check(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	tdx_test_success();
+}
+
+static void run_selftest(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
+			 struct tdx_upm_test_area *test_area_base_hva)
+{
+	vcpu_run(vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);

This check seems to be a vain.

tools/testing/selftests/kvm/x86_64/tdx_upm_test.c

Quoted 8 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +8 -0
+	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
+		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
+	TEST_ASSERT_EQ(*(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset),
+		  SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST);
+
+	/*
+	 * Check that host should read PATTERN_CONFIDENCE_CHECK from guest's
+	 * private memory.

I think this description is confusing.
It's not actually accessing guest's private memory.

Quoted 144 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +143 -0
  This confirms that regular memory (userspace_addr in
+	 * struct kvm_userspace_memory_region) is used to back the host's view
+	 * of private memory, since PATTERN_CONFIDENCE_CHECK was written to that
+	 * memory before starting the guest.
+	 */
+	TEST_ASSERT(check_test_area(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Host should read PATTERN_CONFIDENCE_CHECK from guest's private memory.");
+
+	vcpu_run_and_manage_memory_conversions(vm, vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
+		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
+	TEST_ASSERT_EQ(*(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset),
+		  SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST);
+
+	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_GUEST_FOCUS),
+		"Host should have the same view of shared memory as guest.");
+	TEST_ASSERT(check_general_areas(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Host's view of private memory should still be backed by regular memory.");
+
+	/* Check that host can use shared memory */
+	fill_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS);
+	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS),
+		    "Host should be able to use shared memory.");
+
+	vcpu_run_and_manage_memory_conversions(vm, vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
+		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
+	TEST_ASSERT_EQ(*(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset),
+		  SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN);
+
+	TEST_ASSERT(check_general_areas(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Host's view of private memory should be backed by regular memory.");
+	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS),
+		"Host's view of private memory should be backed by regular memory.");
+
+	vcpu_run(vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_SUCCESS(vcpu);
+
+	printf("\t ... PASSED\n");
+}
+
+static bool address_between(uint64_t addr, void *lo, void *hi)
+{
+	return (uint64_t)lo <= addr && addr < (uint64_t)hi;
+}
+
+static void guest_ve_handler(struct ex_regs *regs)
+{
+	uint64_t ret;
+	struct ve_info ve;
+
+	ret = tdg_vp_veinfo_get(&ve);
+	TDX_UPM_TEST_ASSERT(!ret);
+
+	/* For this test, we will only handle EXIT_REASON_EPT_VIOLATION */
+	TDX_UPM_TEST_ASSERT(ve.exit_reason == EXIT_REASON_EPT_VIOLATION);
+
+	/* Validate GPA in fault */
+	TDX_UPM_TEST_ASSERT(
+		address_between(ve.gpa,
+				test_area_gpa_private->focus_area,
+				test_area_gpa_private->general_area_1));
+
+	tdx_test_send_64bit(TDX_UPM_TEST_ACCEPT_PRINT_PORT, ve.gpa);
+
+#define MEM_PAGE_ACCEPT_LEVEL_4K 0
+#define MEM_PAGE_ACCEPT_LEVEL_2M 1
+	ret = tdg_mem_page_accept(ve.gpa, MEM_PAGE_ACCEPT_LEVEL_4K);
+	TDX_UPM_TEST_ASSERT(!ret);
+}
+
+static void verify_upm_test(void)
+{
+	struct kvm_vm *vm;
+	struct kvm_vcpu *vcpu;
+
+	vm_vaddr_t test_area_gva_private;
+	struct tdx_upm_test_area *test_area_base_hva;
+	uint64_t test_area_npages;
+
+	vm = td_create();
+	td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0);
+	vcpu = td_vcpu_add(vm, 0, guest_upm_explicit);
+
+	vm_install_exception_handler(vm, VE_VECTOR, guest_ve_handler);
+
+	/*
+	 * Set up shared memory page for testing by first allocating as private
+	 * and then mapping the same GPA again as shared. This way, the TD does
+	 * not have to remap its page tables at runtime.
+	 */
+	test_area_npages = TDX_UPM_TEST_AREA_SIZE / vm->page_size;
+	vm_userspace_mem_region_add(vm,
+				    VM_MEM_SRC_ANONYMOUS, TDX_UPM_TEST_AREA_GPA,
+				    3, test_area_npages, KVM_MEM_PRIVATE);
+
+	test_area_gva_private = ____vm_vaddr_alloc(
+		vm, TDX_UPM_TEST_AREA_SIZE, TDX_UPM_TEST_AREA_GVA_PRIVATE,
+		TDX_UPM_TEST_AREA_GPA, 3, true);
+	TEST_ASSERT_EQ(test_area_gva_private, TDX_UPM_TEST_AREA_GVA_PRIVATE);
+
+	test_area_gpa_private = (struct tdx_upm_test_area *)
+		addr_gva2gpa(vm, test_area_gva_private);
+	virt_map_shared(vm, TDX_UPM_TEST_AREA_GVA_SHARED,
+			(uint64_t)test_area_gpa_private,
+			test_area_npages);
+	TEST_ASSERT_EQ(addr_gva2gpa(vm, TDX_UPM_TEST_AREA_GVA_SHARED),
+		  (vm_paddr_t)test_area_gpa_private);
+
+	test_area_base_hva = addr_gva2hva(vm, TDX_UPM_TEST_AREA_GVA_PRIVATE);
+
+	TEST_ASSERT(fill_and_check(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Failed to mark memory intended as backing memory for TD shared memory");
+
+	sync_global_to_guest(vm, test_area_gpa_private);
+	test_area_gpa_shared = (struct tdx_upm_test_area *)
+		((uint64_t)test_area_gpa_private | BIT_ULL(vm->pa_bits - 1));
+	sync_global_to_guest(vm, test_area_gpa_shared);
+
+	td_finalize(vm);
+
+	printf("Verifying UPM functionality: explicit MapGPA\n");
+
+	run_selftest(vm, vcpu, test_area_base_hva);
+
+	kvm_vm_free(vm);
+}
+
+int main(int argc, char **argv)
+{
+	/* Disable stdout buffering */
+	setbuf(stdout, NULL);
+
+	if (!is_tdx_enabled()) {
+		printf("TDX is not supported by the KVM\n"
+		       "Skipping the TDX tests.\n");
+		return 0;
+	}
+
+	run_in_new_process(&verify_upm_test);
+}
#100 lore raw

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

In reply to Sagi Shahar
Quoted 195 lines · Sagi Shahar

From: Ackerley Tng <[email protected]>

This tests the use of guest memory with explicit MapGPA calls.

---
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/x86_64/tdx_upm_test.c       | 401 ++++++++++++++++++
 2 files changed, 402 insertions(+)
 create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_upm_test.c
tools/testing/selftests/kvm/Makefile +1 -0
index 8c0a6b395ee5..2f2669af15d6 100644
@@ -157,6 +157,7 @@ TEST_GEN_PROGS_x86_64 += kvm_binary_stats_test
 TEST_GEN_PROGS_x86_64 += system_counter_offset_test
 TEST_GEN_PROGS_x86_64 += x86_64/tdx_vm_tests
 TEST_GEN_PROGS_x86_64 += x86_64/tdx_shared_mem_test
+TEST_GEN_PROGS_x86_64 += x86_64/tdx_upm_test
 
 # Compiled outputs used by test targets
 TEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +163 -0
new file mode 100644
index 000000000000..44671874a4f1
@@ -0,0 +1,401 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <asm/kvm.h>
+#include <asm/vmx.h>
+#include <linux/kvm.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "kvm_util_base.h"
+#include "processor.h"
+#include "tdx/tdcall.h"
+#include "tdx/tdx.h"
+#include "tdx/tdx_util.h"
+#include "tdx/test_util.h"
+#include "test_util.h"
+
+/* TDX UPM test patterns */
+#define PATTERN_CONFIDENCE_CHECK (0x11)
+#define PATTERN_HOST_FOCUS (0x22)
+#define PATTERN_GUEST_GENERAL (0x33)
+#define PATTERN_GUEST_FOCUS (0x44)
+
+/*
+ * 0x80000000 is arbitrarily selected. The selected address need not be the same
+ * as TDX_UPM_TEST_AREA_GVA_PRIVATE, but it should not overlap with selftest
+ * code or boot page.
+ */
+#define TDX_UPM_TEST_AREA_GPA (0x80000000)
+/* Test area GPA is arbitrarily selected */
+#define TDX_UPM_TEST_AREA_GVA_PRIVATE (0x90000000)
+/* Select any bit that can be used as a flag */
+#define TDX_UPM_TEST_AREA_GVA_SHARED_BIT (32)
+/*
+ * TDX_UPM_TEST_AREA_GVA_SHARED is used to map the same GPA twice into the
+ * guest, once as shared and once as private
+ */
+#define TDX_UPM_TEST_AREA_GVA_SHARED				\
+	(TDX_UPM_TEST_AREA_GVA_PRIVATE |			\
+		BIT_ULL(TDX_UPM_TEST_AREA_GVA_SHARED_BIT))
+
+/* The test area is 2MB in size */
+#define TDX_UPM_TEST_AREA_SIZE (2 << 20)
+/* 0th general area is 1MB in size */
+#define TDX_UPM_GENERAL_AREA_0_SIZE (1 << 20)
+/* Focus area is 40KB in size */
+#define TDX_UPM_FOCUS_AREA_SIZE (40 << 10)
+/* 1st general area is the rest of the space in the test area */
+#define TDX_UPM_GENERAL_AREA_1_SIZE				\
+	(TDX_UPM_TEST_AREA_SIZE - TDX_UPM_GENERAL_AREA_0_SIZE -	\
+		TDX_UPM_FOCUS_AREA_SIZE)
+
+/*
+ * The test memory area is set up as two general areas, sandwiching a focus
+ * area.  The general areas act as control areas. After they are filled, they
+ * are not expected to change throughout the tests. The focus area is memory
+ * permissions change from private to shared and vice-versa.
+ *
+ * The focus area is intentionally small, and sandwiched to test that when the
+ * focus area's permissions change, the other areas' permissions are not
+ * affected.
+ */
+struct __packed tdx_upm_test_area {
+	uint8_t general_area_0[TDX_UPM_GENERAL_AREA_0_SIZE];
+	uint8_t focus_area[TDX_UPM_FOCUS_AREA_SIZE];
+	uint8_t general_area_1[TDX_UPM_GENERAL_AREA_1_SIZE];
+};
+
+static void fill_test_area(struct tdx_upm_test_area *test_area_base,
+			uint8_t pattern)
+{
+	memset(test_area_base, pattern, sizeof(*test_area_base));
+}
+
+static void fill_focus_area(struct tdx_upm_test_area *test_area_base,
+			    uint8_t pattern)
+{
+	memset(test_area_base->focus_area, pattern,
+	       sizeof(test_area_base->focus_area));
+}
+
+static bool check_area(uint8_t *base, uint64_t size, uint8_t expected_pattern)
+{
+	size_t i;
+
+	for (i = 0; i < size; i++) {
+		if (base[i] != expected_pattern)
+			return false;
+	}
+
+	return true;
+}
+
+static bool check_general_areas(struct tdx_upm_test_area *test_area_base,
+				uint8_t expected_pattern)
+{
+	return (check_area(test_area_base->general_area_0,
+			   sizeof(test_area_base->general_area_0),
+			   expected_pattern) &&
+		check_area(test_area_base->general_area_1,
+			   sizeof(test_area_base->general_area_1),
+			   expected_pattern));
+}
+
+static bool check_focus_area(struct tdx_upm_test_area *test_area_base,
+			     uint8_t expected_pattern)
+{
+	return check_area(test_area_base->focus_area,
+			  sizeof(test_area_base->focus_area), expected_pattern);
+}
+
+static bool check_test_area(struct tdx_upm_test_area *test_area_base,
+			    uint8_t expected_pattern)
+{
+	return (check_general_areas(test_area_base, expected_pattern) &&
+		check_focus_area(test_area_base, expected_pattern));
+}
+
+static bool fill_and_check(struct tdx_upm_test_area *test_area_base, uint8_t pattern)
+{
+	fill_test_area(test_area_base, pattern);
+
+	return check_test_area(test_area_base, pattern);
+}
+
+#define TDX_UPM_TEST_ASSERT(x)				\
+	do {						\
+		if (!(x))				\
+			tdx_test_fatal(__LINE__);	\
+	} while (0)
+
+/*
+ * Shared variables between guest and host
+ */
+static struct tdx_upm_test_area *test_area_gpa_private;
+static struct tdx_upm_test_area *test_area_gpa_shared;
+
+/*
+ * Test stages for syncing with host
+ */
+enum {
+	SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST = 1,
+	SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST,
+	SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN,
+};
+
+#define TDX_UPM_TEST_ACCEPT_PRINT_PORT 0x87
+
+/**
+ * Does vcpu_run, and also manages memory conversions if requested by the TD.
+ */
+void vcpu_run_and_manage_memory_conversions(struct kvm_vm *vm,
+					    struct kvm_vcpu *vcpu)
+{
+	for (;;) {
+		vcpu_run(vcpu);
+		if (vcpu->run->exit_reason == KVM_EXIT_TDX &&
+			vcpu->run->tdx.type == KVM_EXIT_TDX_VMCALL &&
+			vcpu->run->tdx.u.vmcall.subfunction == TDG_VP_VMCALL_MAP_GPA) {
+			struct kvm_tdx_vmcall *vmcall_info = &vcpu->run->tdx.u.vmcall;
+			uint64_t gpa = vmcall_info->in_r12 & ~vm->arch.s_bit;
+
+			handle_memory_conversion(vm, gpa, vmcall_info->in_r13,
+				!(vm->arch.s_bit & vmcall_info->in_r12));

tools/testing/selftests/kvm/x86_64/tdx_upm_test.c line 173

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +10 -0
+			vmcall_info->status_code = 0;
+			continue;
+		} else if (
+			vcpu->run->exit_reason == KVM_EXIT_IO &&
+			vcpu->run->io.port == TDX_UPM_TEST_ACCEPT_PRINT_PORT) {
+			uint64_t gpa = tdx_test_read_64bit(
+				vcpu, TDX_UPM_TEST_ACCEPT_PRINT_PORT);
+			printf("\t ... guest accepting 1 page at GPA: 0x%lx\n", gpa);
+			continue;
+		}

Lack of converting TDG_VP_VMCALL_REPORT_FATAL_ERROR to KVM_EXIT_SYSTEM_EVENT.

Quoted 16 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +16 -0
+		break;
+	}
+}
+
+static void guest_upm_explicit(void)
+{
+	uint64_t ret = 0;
+	uint64_t failed_gpa;
+
+	struct tdx_upm_test_area *test_area_gva_private =
+		(struct tdx_upm_test_area *)TDX_UPM_TEST_AREA_GVA_PRIVATE;
+	struct tdx_upm_test_area *test_area_gva_shared =
+		(struct tdx_upm_test_area *)TDX_UPM_TEST_AREA_GVA_SHARED;
+
+	/* Check: host reading private memory does not modify guest's view */
+	fill_test_area(test_area_gva_private, PATTERN_GUEST_GENERAL);

tools/testing/selftests/kvm/x86_64/tdx_upm_test.c line 200

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +10 -0
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST);
+
+	TDX_UPM_TEST_ASSERT(
+		check_test_area(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/* Remap focus area as shared */
+	ret = tdg_vp_vmcall_map_gpa((uint64_t)test_area_gpa_shared->focus_area,
+				    sizeof(test_area_gpa_shared->focus_area),
+				    &failed_gpa);

"failed gpa" is not filled by host and is uninitialized.

Quoted 39 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +39 -0
+	TDX_UPM_TEST_ASSERT(!ret);
+
+	/* General areas should be unaffected by remapping */
+	TDX_UPM_TEST_ASSERT(
+		check_general_areas(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/*
+	 * Use memory contents to confirm that the memory allocated using mmap
+	 * is used as backing memory for shared memory - PATTERN_CONFIDENCE_CHECK
+	 * was written by the VMM at the beginning of this test.
+	 */
+	TDX_UPM_TEST_ASSERT(
+		check_focus_area(test_area_gva_shared, PATTERN_CONFIDENCE_CHECK));
+
+	/* Guest can use focus area after remapping as shared */
+	fill_focus_area(test_area_gva_shared, PATTERN_GUEST_FOCUS);
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST);
+
+	/* Check that guest has the same view of shared memory */
+	TDX_UPM_TEST_ASSERT(
+		check_focus_area(test_area_gva_shared, PATTERN_HOST_FOCUS));
+
+	/* Remap focus area back to private */
+	ret = tdg_vp_vmcall_map_gpa((uint64_t)test_area_gpa_private->focus_area,
+				    sizeof(test_area_gpa_private->focus_area),
+				    &failed_gpa);
+	TDX_UPM_TEST_ASSERT(!ret);
+
+	/* General areas should be unaffected by remapping */
+	TDX_UPM_TEST_ASSERT(
+		check_general_areas(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/* Focus area should be zeroed after remapping */
+	TDX_UPM_TEST_ASSERT(check_focus_area(test_area_gva_private, 0));
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN);
+
+	/* Check that guest can use private memory after focus area is remapped as private */

tools/testing/selftests/kvm/x86_64/tdx_upm_test.c line 249

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +10 -0
+	TDX_UPM_TEST_ASSERT(
+		fill_and_check(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	tdx_test_success();
+}
+
+static void run_selftest(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
+			 struct tdx_upm_test_area *test_area_base_hva)
+{
+	vcpu_run(vcpu);

Should be td_vcpu_run()?
Otherwise, nowhere to convert TDG_VP_VMCALL_REPORT_FATAL_ERROR to exit_reason KVM_EXIT_SYSTEM_EVENT required by TDX_TEST_CHECK_GUEST_FAILURE().

Quoted 69 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +69 -0
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
+		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
+	TEST_ASSERT_EQ(*(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset),
+		  SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST);
+
+	/*
+	 * Check that host should read PATTERN_CONFIDENCE_CHECK from guest's
+	 * private memory. This confirms that regular memory (userspace_addr in
+	 * struct kvm_userspace_memory_region) is used to back the host's view
+	 * of private memory, since PATTERN_CONFIDENCE_CHECK was written to that
+	 * memory before starting the guest.
+	 */
+	TEST_ASSERT(check_test_area(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Host should read PATTERN_CONFIDENCE_CHECK from guest's private memory.");
+
+	vcpu_run_and_manage_memory_conversions(vm, vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
+		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
+	TEST_ASSERT_EQ(*(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset),
+		  SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST);
+
+	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_GUEST_FOCUS),
+		"Host should have the same view of shared memory as guest.");
+	TEST_ASSERT(check_general_areas(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Host's view of private memory should still be backed by regular memory.");
+
+	/* Check that host can use shared memory */
+	fill_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS);
+	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS),
+		    "Host should be able to use shared memory.");
+
+	vcpu_run_and_manage_memory_conversions(vm, vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
+		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
+	TEST_ASSERT_EQ(*(uint32_t *)((void *)vcpu->run + vcpu->run->io.data_offset),
+		  SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN);
+
+	TEST_ASSERT(check_general_areas(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Host's view of private memory should be backed by regular memory.");
+	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS),
+		"Host's view of private memory should be backed by regular memory.");
+
+	vcpu_run(vcpu);
+	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
+	TDX_TEST_ASSERT_SUCCESS(vcpu);
+
+	printf("\t ... PASSED\n");
+}
+
+static bool address_between(uint64_t addr, void *lo, void *hi)
+{
+	return (uint64_t)lo <= addr && addr < (uint64_t)hi;
+}
+
+static void guest_ve_handler(struct ex_regs *regs)
+{
+	uint64_t ret;
+	struct ve_info ve;
+
+	ret = tdg_vp_veinfo_get(&ve);
+	TDX_UPM_TEST_ASSERT(!ret);
+
+	/* For this test, we will only handle EXIT_REASON_EPT_VIOLATION */
+	TDX_UPM_TEST_ASSERT(ve.exit_reason == EXIT_REASON_EPT_VIOLATION);
+
+	/* Validate GPA in fault */

tools/testing/selftests/kvm/x86_64/tdx_upm_test.c line 328

Quoted 10 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +10 -0
+	TDX_UPM_TEST_ASSERT(
+		address_between(ve.gpa,
+				test_area_gpa_private->focus_area,
+				test_area_gpa_private->general_area_1));
+
+	tdx_test_send_64bit(TDX_UPM_TEST_ACCEPT_PRINT_PORT, ve.gpa);
+
+#define MEM_PAGE_ACCEPT_LEVEL_4K 0
+#define MEM_PAGE_ACCEPT_LEVEL_2M 1
+	ret = tdg_mem_page_accept(ve.gpa, MEM_PAGE_ACCEPT_LEVEL_4K);

What if ve.gpa could end with 1?
e.g. if could be 0x80100001 if guest accesses test_area_gva_private->focus_area[1] after remapping focus area back to private.

Though this does not happen in current test, it's better to strip the low 12 bits of ve.gpa before passing to tdg_mem_page_accept(),

Quoted 77 lines
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c new file +73 -0
+	TDX_UPM_TEST_ASSERT(!ret);
+}
+
+static void verify_upm_test(void)
+{
+	struct kvm_vm *vm;
+	struct kvm_vcpu *vcpu;
+
+	vm_vaddr_t test_area_gva_private;
+	struct tdx_upm_test_area *test_area_base_hva;
+	uint64_t test_area_npages;
+
+	vm = td_create();
+	td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0);
+	vcpu = td_vcpu_add(vm, 0, guest_upm_explicit);
+
+	vm_install_exception_handler(vm, VE_VECTOR, guest_ve_handler);
+
+	/*
+	 * Set up shared memory page for testing by first allocating as private
+	 * and then mapping the same GPA again as shared. This way, the TD does
+	 * not have to remap its page tables at runtime.
+	 */
+	test_area_npages = TDX_UPM_TEST_AREA_SIZE / vm->page_size;
+	vm_userspace_mem_region_add(vm,
+				    VM_MEM_SRC_ANONYMOUS, TDX_UPM_TEST_AREA_GPA,
+				    3, test_area_npages, KVM_MEM_PRIVATE);
+
+	test_area_gva_private = ____vm_vaddr_alloc(
+		vm, TDX_UPM_TEST_AREA_SIZE, TDX_UPM_TEST_AREA_GVA_PRIVATE,
+		TDX_UPM_TEST_AREA_GPA, 3, true);
+	TEST_ASSERT_EQ(test_area_gva_private, TDX_UPM_TEST_AREA_GVA_PRIVATE);
+
+	test_area_gpa_private = (struct tdx_upm_test_area *)
+		addr_gva2gpa(vm, test_area_gva_private);
+	virt_map_shared(vm, TDX_UPM_TEST_AREA_GVA_SHARED,
+			(uint64_t)test_area_gpa_private,
+			test_area_npages);
+	TEST_ASSERT_EQ(addr_gva2gpa(vm, TDX_UPM_TEST_AREA_GVA_SHARED),
+		  (vm_paddr_t)test_area_gpa_private);
+
+	test_area_base_hva = addr_gva2hva(vm, TDX_UPM_TEST_AREA_GVA_PRIVATE);
+
+	TEST_ASSERT(fill_and_check(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
+		"Failed to mark memory intended as backing memory for TD shared memory");
+
+	sync_global_to_guest(vm, test_area_gpa_private);
+	test_area_gpa_shared = (struct tdx_upm_test_area *)
+		((uint64_t)test_area_gpa_private | BIT_ULL(vm->pa_bits - 1));
+	sync_global_to_guest(vm, test_area_gpa_shared);
+
+	td_finalize(vm);
+
+	printf("Verifying UPM functionality: explicit MapGPA\n");
+
+	run_selftest(vm, vcpu, test_area_base_hva);
+
+	kvm_vm_free(vm);
+}
+
+int main(int argc, char **argv)
+{
+	/* Disable stdout buffering */
+	setbuf(stdout, NULL);
+
+	if (!is_tdx_enabled()) {
+		printf("TDX is not supported by the KVM\n"
+		       "Skipping the TDX tests.\n");
+		return 0;
+	}
+
+	run_in_new_process(&verify_upm_test);
+}
Signature · 1 line
2.43.0.472.g3155946c3a-goog
#101 lore raw

RFC PATCH v5 29/29 KVM: selftests: TDX: Add TDX UPM selftests for implicit conversion

In reply to Sagi Shahar

From: Ackerley Tng <[email protected]>

This tests the use of guest memory without explicit MapGPA calls.

---
 .../selftests/kvm/x86_64/tdx_upm_test.c       | 86 +++++++++++++++++--
 1 file changed, 77 insertions(+), 9 deletions(-)
tools/testing/selftests/kvm/x86_64/tdx_upm_test.c +77 -9
index 44671874a4f1..bfa921f125a0 100644
@@ -149,7 +149,7 @@ enum {
  * Does vcpu_run, and also manages memory conversions if requested by the TD.
  */
 void vcpu_run_and_manage_memory_conversions(struct kvm_vm *vm,
-					    struct kvm_vcpu *vcpu)
+					    struct kvm_vcpu *vcpu, bool handle_conversions)
 {
 	for (;;) {
 		vcpu_run(vcpu);
@@ -163,6 +163,13 @@ void vcpu_run_and_manage_memory_conversions(struct kvm_vm *vm,
 				!(vm->arch.s_bit & vmcall_info->in_r12));
 			vmcall_info->status_code = 0;
 			continue;
+		} else if (handle_conversions &&
+			vcpu->run->exit_reason == KVM_EXIT_MEMORY_FAULT) {
+			handle_memory_conversion(
+				vm, vcpu->run->memory_fault.gpa,
+				vcpu->run->memory_fault.size,
+				vcpu->run->memory_fault.flags == KVM_MEMORY_EXIT_FLAG_PRIVATE);
+			continue;
 		} else if (
 			vcpu->run->exit_reason == KVM_EXIT_IO &&
 			vcpu->run->io.port == TDX_UPM_TEST_ACCEPT_PRINT_PORT) {
@@ -243,8 +250,53 @@ static void guest_upm_explicit(void)
 	tdx_test_success();
 }
 
+static void guest_upm_implicit(void)
+{
+	struct tdx_upm_test_area *test_area_gva_private =
+		(struct tdx_upm_test_area *)TDX_UPM_TEST_AREA_GVA_PRIVATE;
+	struct tdx_upm_test_area *test_area_gva_shared =
+		(struct tdx_upm_test_area *)TDX_UPM_TEST_AREA_GVA_SHARED;
+
+	/* Check: host reading private memory does not modify guest's view */
+	fill_test_area(test_area_gva_private, PATTERN_GUEST_GENERAL);
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST);
+
+	TDX_UPM_TEST_ASSERT(
+		check_test_area(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	/* Use focus area as shared */
+	fill_focus_area(test_area_gva_shared, PATTERN_GUEST_FOCUS);
+
+	/* General areas should not be affected */
+	TDX_UPM_TEST_ASSERT(
+		check_general_areas(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_SHARED_MEMORY_FROM_HOST);
+
+	/* Check that guest has the same view of shared memory */
+	TDX_UPM_TEST_ASSERT(
+		check_focus_area(test_area_gva_shared, PATTERN_HOST_FOCUS));
+
+	/* Use focus area as private */
+	fill_focus_area(test_area_gva_private, PATTERN_GUEST_FOCUS);
+
+	/* General areas should be unaffected by remapping */
+	TDX_UPM_TEST_ASSERT(
+		check_general_areas(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	tdx_test_report_to_user_space(SYNC_CHECK_READ_PRIVATE_MEMORY_FROM_HOST_AGAIN);
+
+	/* Check that guest can use private memory after focus area is remapped as private */
+	TDX_UPM_TEST_ASSERT(
+		fill_and_check(test_area_gva_private, PATTERN_GUEST_GENERAL));
+
+	tdx_test_success();
+}
+
 static void run_selftest(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
-			 struct tdx_upm_test_area *test_area_base_hva)
+			 struct tdx_upm_test_area *test_area_base_hva,
+			 bool implicit)
 {
 	vcpu_run(vcpu);
 	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
@@ -263,7 +315,7 @@ static void run_selftest(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
 	TEST_ASSERT(check_test_area(test_area_base_hva, PATTERN_CONFIDENCE_CHECK),
 		"Host should read PATTERN_CONFIDENCE_CHECK from guest's private memory.");
 
-	vcpu_run_and_manage_memory_conversions(vm, vcpu);
+	vcpu_run_and_manage_memory_conversions(vm, vcpu, implicit);
 	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
 	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
 		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
@@ -280,7 +332,7 @@ static void run_selftest(struct kvm_vm *vm, struct kvm_vcpu *vcpu,
 	TEST_ASSERT(check_focus_area(test_area_base_hva, PATTERN_HOST_FOCUS),
 		    "Host should be able to use shared memory.");
 
-	vcpu_run_and_manage_memory_conversions(vm, vcpu);
+	vcpu_run_and_manage_memory_conversions(vm, vcpu, implicit);
 	TDX_TEST_CHECK_GUEST_FAILURE(vcpu);
 	TDX_TEST_ASSERT_IO(vcpu, TDX_TEST_REPORT_PORT, TDX_TEST_REPORT_SIZE,
 		 TDG_VP_VMCALL_INSTRUCTION_IO_WRITE);
@@ -329,18 +381,20 @@ static void guest_ve_handler(struct ex_regs *regs)
 	TDX_UPM_TEST_ASSERT(!ret);
 }
 
-static void verify_upm_test(void)
+static void verify_upm_test(bool implicit)
 {
 	struct kvm_vm *vm;
 	struct kvm_vcpu *vcpu;
 
+	void *guest_code;
 	vm_vaddr_t test_area_gva_private;
 	struct tdx_upm_test_area *test_area_base_hva;
 	uint64_t test_area_npages;
 
 	vm = td_create();
 	td_initialize(vm, VM_MEM_SRC_ANONYMOUS, 0);
-	vcpu = td_vcpu_add(vm, 0, guest_upm_explicit);
+	guest_code = implicit ? guest_upm_implicit : guest_upm_explicit;
+	vcpu = td_vcpu_add(vm, 0, guest_code);
 
 	vm_install_exception_handler(vm, VE_VECTOR, guest_ve_handler);
 
@@ -379,13 +433,26 @@ static void verify_upm_test(void)
 
 	td_finalize(vm);
 
-	printf("Verifying UPM functionality: explicit MapGPA\n");
+	if (implicit)
+		printf("Verifying UPM functionality: implicit conversion\n");
+	else
+		printf("Verifying UPM functionality: explicit MapGPA\n");
 
-	run_selftest(vm, vcpu, test_area_base_hva);
+	run_selftest(vm, vcpu, test_area_base_hva, implicit);
 
 	kvm_vm_free(vm);
 }
 
+void verify_upm_test_explicit(void)
+{
+	verify_upm_test(false);
+}
+
+void verify_upm_test_implicit(void)
+{
+	verify_upm_test(true);
+}
+
 int main(int argc, char **argv)
 {
 	/* Disable stdout buffering */
@@ -397,5 +464,6 @@ int main(int argc, char **argv)
 		return 0;
 	}
 
-	run_in_new_process(&verify_upm_test);
+	run_in_new_process(&verify_upm_test_explicit);
+	run_in_new_process(&verify_upm_test_implicit);
 }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
#102 lore raw
In reply to Sagi Shahar
Quoted 10 lines · Sagi Shahar

Hello,

This is v4 of the patch series for TDX selftests.

It has been updated for Intel’s v17 of the TDX host patches which was proposed here:
https://lore.kernel.org/all/[email protected]/

The tree can be found at:
https://github.com/googleprodkernel/linux-cc/tree/tdx-selftests-rfc-v5

Hello,

I wanted to check if there were any plans from Google to refresh this series for the current TDX patches and the kvm-coco-queue baseline?

I'm setting up a CI system that the team is using to test updates to the different TDX patch series, and it currently runs the KVM Unit tests, and kvm selftests, and we'd like to be able to add these three new TDX tests to that as well.

I tried to take a quick shot at rebasing it, but ran into several conflicts since kvm-coco-queue has in the meantime made changes e.g. in tools/testing/selftests/kvm/lib/x86_64/processor.c vcpu_setup().

If you can help rebase this, Rick's MMU prep series might be a good baseline to use:
https://lore.kernel.org/all/[email protected]/

This is also available in a tree at:
https://github.com/intel/tdx/tree/tdx_kvm_dev-2024-05-30

Thank you,
Vishal

Quoted 127 lines

Changes from RFC v4:

Added patch to propagate KVM_EXIT_MEMORY_FAULT to userspace.

Minor tweaks to align the tests to the new TDX 1.5 spec such as changes in the expected values in TDG.VP.INFO.

In RFCv5, TDX selftest code is organized into:

+ headers in tools/testing/selftests/kvm/include/x86_64/tdx/
+ common code in tools/testing/selftests/kvm/lib/x86_64/tdx/
+ selftests in tools/testing/selftests/kvm/x86_64/tdx_*

Dependencies

+ Peter’s patches, which provide functions for the host to allocate and track protected memory in the guest.
  https://lore.kernel.org/all/[email protected]/

Further work for this patch series/TODOs

+ Sean’s comments for the non-confidential UPM selftests patch series at https://lore.kernel.org/lkml/[email protected]/T/#u apply here as well
+ Add ucall support for TDX selftests

I would also like to acknowledge the following people, who helped review or test patches in previous versions:

+ Sean Christopherson <[email protected]>
+ Zhenzhong Duan <[email protected]>
+ Peter Gonda <[email protected]>
+ Andrew Jones <[email protected]>
+ Maxim Levitsky <[email protected]>
+ Xiaoyao Li <[email protected]>
+ David Matlack <[email protected]>
+ Marc Orr <[email protected]>
+ Isaku Yamahata <[email protected]>
+ Maciej S. Szmigiero <[email protected]>

Links to earlier patch series

+ RFC v1: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v2: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v3: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v4: https://lore.kernel.org/lkml/[email protected]/

*** BLURB HERE ***

Ackerley Tng (12):
  KVM: selftests: Add function to allow one-to-one GVA to GPA mappings
  KVM: selftests: Expose function that sets up sregs based on VM's mode
  KVM: selftests: Store initial stack address in struct kvm_vcpu
  KVM: selftests: Refactor steps in vCPU descriptor table initialization
  KVM: selftests: TDX: Use KVM_TDX_CAPABILITIES to validate TDs' attribute configuration
  KVM: selftests: TDX: Update load_td_memory_region for VM memory backed by guest memfd
  KVM: selftests: Add functions to allow mapping as shared
  KVM: selftests: Expose _vm_vaddr_alloc
  KVM: selftests: TDX: Add support for TDG.MEM.PAGE.ACCEPT
  KVM: selftests: TDX: Add support for TDG.VP.VEINFO.GET
  KVM: selftests: TDX: Add TDX UPM selftest
  KVM: selftests: TDX: Add TDX UPM selftests for implicit conversion

Erdem Aktas (3):
  KVM: selftests: Add helper functions to create TDX VMs
  KVM: selftests: TDX: Add TDX lifecycle test
  KVM: selftests: TDX: Adding test case for TDX port IO

Roger Wang (1):
  KVM: selftests: TDX: Add TDG.VP.INFO test

Ryan Afranji (2):
  KVM: selftests: TDX: Verify the behavior when host consumes a TD private memory
  KVM: selftests: TDX: Add shared memory test

Sagi Shahar (11):
  KVM: selftests: TDX: Add report_fatal_error test
  KVM: selftests: TDX: Add basic TDX CPUID test
  KVM: selftests: TDX: Add basic get_td_vmcall_info test
  KVM: selftests: TDX: Add TDX IO writes test
  KVM: selftests: TDX: Add TDX IO reads test
  KVM: selftests: TDX: Add TDX MSR read/write tests
  KVM: selftests: TDX: Add TDX HLT exit test
  KVM: selftests: TDX: Add TDX MMIO reads test
  KVM: selftests: TDX: Add TDX MMIO writes test
  KVM: selftests: TDX: Add TDX CPUID TDVMCALL test
  KVM: selftests: Propagate KVM_EXIT_MEMORY_FAULT to userspace

 tools/testing/selftests/kvm/Makefile          |    8 + .../selftests/kvm/include/kvm_util_base.h     |   30 + .../selftests/kvm/include/x86_64/processor.h  |    4 + .../kvm/include/x86_64/tdx/td_boot.h          |   82 + .../kvm/include/x86_64/tdx/td_boot_asm.h      |   16 + .../selftests/kvm/include/x86_64/tdx/tdcall.h |   59 + .../selftests/kvm/include/x86_64/tdx/tdx.h    |   65 + .../kvm/include/x86_64/tdx/tdx_util.h         |   19 + .../kvm/include/x86_64/tdx/test_util.h        |  164 ++ tools/testing/selftests/kvm/lib/kvm_util.c    |  101 +- .../selftests/kvm/lib/x86_64/processor.c      |   77 +- .../selftests/kvm/lib/x86_64/tdx/td_boot.S    |  101 ++ .../selftests/kvm/lib/x86_64/tdx/tdcall.S     |  158 ++ .../selftests/kvm/lib/x86_64/tdx/tdx.c        |  262 ++++ .../selftests/kvm/lib/x86_64/tdx/tdx_util.c   |  558 +++++++ .../selftests/kvm/lib/x86_64/tdx/test_util.c  |  101 ++ .../kvm/x86_64/tdx_shared_mem_test.c          |  135 ++ .../selftests/kvm/x86_64/tdx_upm_test.c       |  469 ++++++ .../selftests/kvm/x86_64/tdx_vm_tests.c       | 1319 +++++++++++++++++

 19 files changed, 3693 insertions(+), 35 deletions(-)

 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/td_boot.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/td_boot_asm.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdx_util.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/td_boot.S create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdcall.S create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/test_util.c create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_shared_mem_test.c create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_upm_test.c create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c

#103 lore raw
Quoted 10 lines · Vishal L
Quoted 8 lines · Sagi Shahar

Hello,

This is v4 of the patch series for TDX selftests.

It has been updated for Intel’s v17 of the TDX host patches which was proposed here:
https://lore.kernel.org/all/[email protected]/

Quoted 8 lines
Quoted 2 lines

The tree can be found at:
https://github.com/googleprodkernel/linux-cc/tree/tdx-selftests-rfc-v5

Hello,

I wanted to check if there were any plans from Google to refresh this series for the current TDX patches and the kvm-coco-queue baseline?

I'm going to work on it soon and was planning on using Isaku's V19 of the TDX host patches

Quoted 5 lines

I'm setting up a CI system that the team is using to test updates to the different TDX patch series, and it currently runs the KVM Unit tests, and kvm selftests, and we'd like to be able to add these three new TDX tests to that as well.

Quoted 7 lines

I tried to take a quick shot at rebasing it, but ran into several conflicts since kvm-coco-queue has in the meantime made changes e.g. in tools/testing/selftests/kvm/lib/x86_64/processor.c vcpu_setup().

If you can help rebase this, Rick's MMU prep series might be a good baseline to use:
https://lore.kernel.org/all/[email protected]/

This patch series only includes the basic TDX MMU changes and is missing a lot of the TDX support. Not sure how this can be used as a baseline without the rest of the TDX patches. Are there other patch series that were posted based on this series which provides the rest of the TDX support?

Quoted 135 lines

This is also available in a tree at:
https://github.com/intel/tdx/tree/tdx_kvm_dev-2024-05-30

Thank you,
Vishal

Quoted 127 lines

Changes from RFC v4:

Added patch to propagate KVM_EXIT_MEMORY_FAULT to userspace.

Minor tweaks to align the tests to the new TDX 1.5 spec such as changes in the expected values in TDG.VP.INFO.

In RFCv5, TDX selftest code is organized into:

+ headers in tools/testing/selftests/kvm/include/x86_64/tdx/
+ common code in tools/testing/selftests/kvm/lib/x86_64/tdx/
+ selftests in tools/testing/selftests/kvm/x86_64/tdx_*

Dependencies

+ Peter’s patches, which provide functions for the host to allocate and track protected memory in the guest.
https://lore.kernel.org/all/[email protected]/

Further work for this patch series/TODOs

+ Sean’s comments for the non-confidential UPM selftests patch series at https://lore.kernel.org/lkml/[email protected]/T/#u apply here as well
+ Add ucall support for TDX selftests

I would also like to acknowledge the following people, who helped review or test patches in previous versions:

+ Sean Christopherson <[email protected]>
+ Zhenzhong Duan <[email protected]>
+ Peter Gonda <[email protected]>
+ Andrew Jones <[email protected]>
+ Maxim Levitsky <[email protected]>
+ Xiaoyao Li <[email protected]>
+ David Matlack <[email protected]>
+ Marc Orr <[email protected]>
+ Isaku Yamahata <[email protected]>
+ Maciej S. Szmigiero <[email protected]>

Links to earlier patch series

+ RFC v1: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v2: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v3: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v4: https://lore.kernel.org/lkml/[email protected]/

*** BLURB HERE ***

Ackerley Tng (12):
KVM: selftests: Add function to allow one-to-one GVA to GPA mappings
KVM: selftests: Expose function that sets up sregs based on VM's mode
KVM: selftests: Store initial stack address in struct kvm_vcpu
KVM: selftests: Refactor steps in vCPU descriptor table initialization
KVM: selftests: TDX: Use KVM_TDX_CAPABILITIES to validate TDs'
attribute configuration
KVM: selftests: TDX: Update load_td_memory_region for VM memory backed
by guest memfd
KVM: selftests: Add functions to allow mapping as shared
KVM: selftests: Expose _vm_vaddr_alloc
KVM: selftests: TDX: Add support for TDG.MEM.PAGE.ACCEPT
KVM: selftests: TDX: Add support for TDG.VP.VEINFO.GET
KVM: selftests: TDX: Add TDX UPM selftest
KVM: selftests: TDX: Add TDX UPM selftests for implicit conversion

Erdem Aktas (3):
KVM: selftests: Add helper functions to create TDX VMs
KVM: selftests: TDX: Add TDX lifecycle test
KVM: selftests: TDX: Adding test case for TDX port IO

Roger Wang (1):
KVM: selftests: TDX: Add TDG.VP.INFO test

Ryan Afranji (2):
KVM: selftests: TDX: Verify the behavior when host consumes a TD
private memory
KVM: selftests: TDX: Add shared memory test

Sagi Shahar (11):
KVM: selftests: TDX: Add report_fatal_error test
KVM: selftests: TDX: Add basic TDX CPUID test
KVM: selftests: TDX: Add basic get_td_vmcall_info test
KVM: selftests: TDX: Add TDX IO writes test
KVM: selftests: TDX: Add TDX IO reads test
KVM: selftests: TDX: Add TDX MSR read/write tests
KVM: selftests: TDX: Add TDX HLT exit test
KVM: selftests: TDX: Add TDX MMIO reads test
KVM: selftests: TDX: Add TDX MMIO writes test
KVM: selftests: TDX: Add TDX CPUID TDVMCALL test
KVM: selftests: Propagate KVM_EXIT_MEMORY_FAULT to userspace

 tools/testing/selftests/kvm/Makefile          |    8 +
 .../selftests/kvm/include/kvm_util_base.h     |   30 +
 .../selftests/kvm/include/x86_64/processor.h  |    4 +
 .../kvm/include/x86_64/tdx/td_boot.h          |   82 +
 .../kvm/include/x86_64/tdx/td_boot_asm.h      |   16 +
 .../selftests/kvm/include/x86_64/tdx/tdcall.h |   59 +
 .../selftests/kvm/include/x86_64/tdx/tdx.h    |   65 +
 .../kvm/include/x86_64/tdx/tdx_util.h         |   19 +
 .../kvm/include/x86_64/tdx/test_util.h        |  164 ++
 tools/testing/selftests/kvm/lib/kvm_util.c    |  101 +-
 .../selftests/kvm/lib/x86_64/processor.c      |   77 +-
 .../selftests/kvm/lib/x86_64/tdx/td_boot.S    |  101 ++
 .../selftests/kvm/lib/x86_64/tdx/tdcall.S     |  158 ++
 .../selftests/kvm/lib/x86_64/tdx/tdx.c        |  262 ++++
 .../selftests/kvm/lib/x86_64/tdx/tdx_util.c   |  558 +++++++
 .../selftests/kvm/lib/x86_64/tdx/test_util.c  |  101 ++
 .../kvm/x86_64/tdx_shared_mem_test.c          |  135 ++
 .../selftests/kvm/x86_64/tdx_upm_test.c       |  469 ++++++
 .../selftests/kvm/x86_64/tdx_vm_tests.c       | 1319 +++++++++++++++++
 19 files changed, 3693 insertions(+), 35 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/td_boot.h
 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/td_boot_asm.h
 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h
 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h
 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdx_util.h
 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h
 create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/td_boot.S
 create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdcall.S
 create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c
 create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c
 create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/test_util.c
 create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_shared_mem_test.c
 create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_upm_test.c
 create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c
#104 lore raw
Quoted 14 lines · Sagi Shahar
Quoted 13 lines · Vishal L
Quoted 10 lines · Sagi Shahar

Hello,

This is v4 of the patch series for TDX selftests.

It has been updated for Intel’s v17 of the TDX host patches which was proposed here:
https://lore.kernel.org/all/[email protected]/

The tree can be found at:
https://github.com/googleprodkernel/linux-cc/tree/tdx-selftests-rfc-v5

Quoted 7 lines
Quoted 5 lines

Hello,

I wanted to check if there were any plans from Google to refresh this series for the current TDX patches and the kvm-coco-queue baseline?

I'm going to work on it soon and was planning on using Isaku's V19 of the TDX host patches

That's great, thank you!

Quoted 14 lines
Quoted 6 lines

I'm setting up a CI system that the team is using to test updates to the different TDX patch series, and it currently runs the KVM Unit tests, and kvm selftests, and we'd like to be able to add these three new TDX tests to that as well.

Quoted 7 lines

I tried to take a quick shot at rebasing it, but ran into several conflicts since kvm-coco-queue has in the meantime made changes e.g. in tools/testing/selftests/kvm/lib/x86_64/processor.c vcpu_setup().

If you can help rebase this, Rick's MMU prep series might be a good baseline to use:
https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

This patch series only includes the basic TDX MMU changes and is missing a lot of the TDX support. Not sure how this can be used as a baseline without the rest of the TDX patches. Are there other patch series that were posted based on this series which provides the rest of the TDX support?

Hm you're right, I was looking more narrowly because of the kvm-coco- queue conflicts, for some of which even v19 might be too old. The MMU prep series uses a much more recent kvm-coco-queue baseline.

Rick, can we post a branch with /everything/ on this MMU prep baseline for this selftest refresh?

Quoted 135 lines
Quoted 135 lines

This is also available in a tree at:
https://github.com/intel/tdx/tree/tdx_kvm_dev-2024-05-30

Thank you,
Vishal

Quoted 127 lines

Changes from RFC v4:

Added patch to propagate KVM_EXIT_MEMORY_FAULT to userspace.

Minor tweaks to align the tests to the new TDX 1.5 spec such as changes in the expected values in TDG.VP.INFO.

In RFCv5, TDX selftest code is organized into:

+ headers in tools/testing/selftests/kvm/include/x86_64/tdx/
+ common code in tools/testing/selftests/kvm/lib/x86_64/tdx/
+ selftests in tools/testing/selftests/kvm/x86_64/tdx_*

Dependencies

+ Peter’s patches, which provide functions for the host to allocate and track protected memory in the guest.
  https://lore.kernel.org/all/[email protected]/

Further work for this patch series/TODOs

+ Sean’s comments for the non-confidential UPM selftests patch series at https://lore.kernel.org/lkml/[email protected]/T/#u apply here as well
+ Add ucall support for TDX selftests

I would also like to acknowledge the following people, who helped review or test patches in previous versions:

+ Sean Christopherson <[email protected]>
+ Zhenzhong Duan <[email protected]>
+ Peter Gonda <[email protected]>
+ Andrew Jones <[email protected]>
+ Maxim Levitsky <[email protected]>
+ Xiaoyao Li <[email protected]>
+ David Matlack <[email protected]>
+ Marc Orr <[email protected]>
+ Isaku Yamahata <[email protected]>
+ Maciej S. Szmigiero <[email protected]>

Links to earlier patch series

+ RFC v1: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v2: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v3: https://lore.kernel.org/lkml/[email protected]/T/#u
+ RFC v4: https://lore.kernel.org/lkml/[email protected]/

*** BLURB HERE ***

Ackerley Tng (12):
  KVM: selftests: Add function to allow one-to-one GVA to GPA mappings
  KVM: selftests: Expose function that sets up sregs based on VM's mode
  KVM: selftests: Store initial stack address in struct kvm_vcpu
  KVM: selftests: Refactor steps in vCPU descriptor table initialization
  KVM: selftests: TDX: Use KVM_TDX_CAPABILITIES to validate TDs' attribute configuration
  KVM: selftests: TDX: Update load_td_memory_region for VM memory backed by guest memfd
  KVM: selftests: Add functions to allow mapping as shared
  KVM: selftests: Expose _vm_vaddr_alloc
  KVM: selftests: TDX: Add support for TDG.MEM.PAGE.ACCEPT
  KVM: selftests: TDX: Add support for TDG.VP.VEINFO.GET
  KVM: selftests: TDX: Add TDX UPM selftest
  KVM: selftests: TDX: Add TDX UPM selftests for implicit conversion

Erdem Aktas (3):
  KVM: selftests: Add helper functions to create TDX VMs
  KVM: selftests: TDX: Add TDX lifecycle test
  KVM: selftests: TDX: Adding test case for TDX port IO

Roger Wang (1):
  KVM: selftests: TDX: Add TDG.VP.INFO test

Ryan Afranji (2):
  KVM: selftests: TDX: Verify the behavior when host consumes a TD private memory
  KVM: selftests: TDX: Add shared memory test

Sagi Shahar (11):
  KVM: selftests: TDX: Add report_fatal_error test
  KVM: selftests: TDX: Add basic TDX CPUID test
  KVM: selftests: TDX: Add basic get_td_vmcall_info test
  KVM: selftests: TDX: Add TDX IO writes test
  KVM: selftests: TDX: Add TDX IO reads test
  KVM: selftests: TDX: Add TDX MSR read/write tests
  KVM: selftests: TDX: Add TDX HLT exit test
  KVM: selftests: TDX: Add TDX MMIO reads test
  KVM: selftests: TDX: Add TDX MMIO writes test
  KVM: selftests: TDX: Add TDX CPUID TDVMCALL test
  KVM: selftests: Propagate KVM_EXIT_MEMORY_FAULT to userspace

 tools/testing/selftests/kvm/Makefile          |    8 + .../selftests/kvm/include/kvm_util_base.h     |   30 + .../selftests/kvm/include/x86_64/processor.h  |    4 + .../kvm/include/x86_64/tdx/td_boot.h          |   82 + .../kvm/include/x86_64/tdx/td_boot_asm.h      |   16 + .../selftests/kvm/include/x86_64/tdx/tdcall.h |   59 + .../selftests/kvm/include/x86_64/tdx/tdx.h    |   65 + .../kvm/include/x86_64/tdx/tdx_util.h         |   19 + .../kvm/include/x86_64/tdx/test_util.h        |  164 ++ tools/testing/selftests/kvm/lib/kvm_util.c    |  101 +- .../selftests/kvm/lib/x86_64/processor.c      |   77 +- .../selftests/kvm/lib/x86_64/tdx/td_boot.S    |  101 ++ .../selftests/kvm/lib/x86_64/tdx/tdcall.S     |  158 ++ .../selftests/kvm/lib/x86_64/tdx/tdx.c        |  262 ++++ .../selftests/kvm/lib/x86_64/tdx/tdx_util.c   |  558 +++++++ .../selftests/kvm/lib/x86_64/tdx/test_util.c  |  101 ++ .../kvm/x86_64/tdx_shared_mem_test.c          |  135 ++ .../selftests/kvm/x86_64/tdx_upm_test.c       |  469 ++++++ .../selftests/kvm/x86_64/tdx_vm_tests.c       | 1319 +++++++++++++++++

 19 files changed, 3693 insertions(+), 35 deletions(-)

 create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/td_boot.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/td_boot_asm.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdcall.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdx.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/tdx_util.h create mode 100644 tools/testing/selftests/kvm/include/x86_64/tdx/test_util.h create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/td_boot.S create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdcall.S create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx.c create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/tdx_util.c create mode 100644 tools/testing/selftests/kvm/lib/x86_64/tdx/test_util.c create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_shared_mem_test.c create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_upm_test.c create mode 100644 tools/testing/selftests/kvm/x86_64/tdx_vm_tests.c

#105 lore raw
Quoted 45 lines · Vishal L
Quoted 14 lines · Sagi Shahar
Quoted 13 lines · Vishal L
Quoted 10 lines · Sagi Shahar

Hello,

This is v4 of the patch series for TDX selftests.

It has been updated for Intel’s v17 of the TDX host patches which was proposed here:
https://lore.kernel.org/all/[email protected]/

The tree can be found at:
https://github.com/googleprodkernel/linux-cc/tree/tdx-selftests-rfc-v5

Quoted 7 lines
Quoted 5 lines

Hello,

I wanted to check if there were any plans from Google to refresh this series for the current TDX patches and the kvm-coco-queue baseline?

I'm going to work on it soon and was planning on using Isaku's V19 of the TDX host patches

That's great, thank you!

Quoted 14 lines
Quoted 6 lines

I'm setting up a CI system that the team is using to test updates to the different TDX patch series, and it currently runs the KVM Unit tests, and kvm selftests, and we'd like to be able to add these three new TDX tests to that as well.

Quoted 7 lines

I tried to take a quick shot at rebasing it, but ran into several conflicts since kvm-coco-queue has in the meantime made changes e.g. in tools/testing/selftests/kvm/lib/x86_64/processor.c vcpu_setup().

If you can help rebase this, Rick's MMU prep series might be a good baseline to use:
https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

This patch series only includes the basic TDX MMU changes and is missing a lot of the TDX support. Not sure how this can be used as a baseline without the rest of the TDX patches. Are there other patch series that were posted based on this series which provides the rest of the TDX support?

Quoted 6 lines

Hm you're right, I was looking more narrowly because of the kvm-coco- queue conflicts, for some of which even v19 might be too old. The MMU prep series uses a much more recent kvm-coco-queue baseline.

Rick, can we post a branch with /everything/ on this MMU prep baseline for this selftest refresh?

Actually I see the branch below does contain everything, not just the MMU prep patches. Sagi, is this fine for a baseline?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This is also available in a tree at:
https://github.com/intel/tdx/tree/tdx_kvm_dev-2024-05-30

Quoted 1 line
#106 lore raw
Quoted 51 lines · Vishal L
Quoted 49 lines · Vishal L
Quoted 14 lines · Sagi Shahar
Quoted 13 lines · Vishal L
Quoted 10 lines · Sagi Shahar

Hello,

This is v4 of the patch series for TDX selftests.

It has been updated for Intel’s v17 of the TDX host patches which was proposed here:
https://lore.kernel.org/all/[email protected]/

The tree can be found at:
https://github.com/googleprodkernel/linux-cc/tree/tdx-selftests-rfc-v5

Quoted 7 lines
Quoted 5 lines

Hello,

I wanted to check if there were any plans from Google to refresh this series for the current TDX patches and the kvm-coco-queue baseline?

I'm going to work on it soon and was planning on using Isaku's V19 of the TDX host patches

That's great, thank you!

Quoted 14 lines
Quoted 6 lines

I'm setting up a CI system that the team is using to test updates to the different TDX patch series, and it currently runs the KVM Unit tests, and kvm selftests, and we'd like to be able to add these three new TDX tests to that as well.

Quoted 7 lines

I tried to take a quick shot at rebasing it, but ran into several conflicts since kvm-coco-queue has in the meantime made changes e.g. in tools/testing/selftests/kvm/lib/x86_64/processor.c vcpu_setup().

If you can help rebase this, Rick's MMU prep series might be a good baseline to use:
https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

This patch series only includes the basic TDX MMU changes and is missing a lot of the TDX support. Not sure how this can be used as a baseline without the rest of the TDX patches. Are there other patch series that were posted based on this series which provides the rest of the TDX support?

Hm you're right, I was looking more narrowly because of the kvm-coco- queue conflicts, for some of which even v19 might be too old. The MMU prep series uses a much more recent kvm-coco-queue baseline.

Quoted 6 lines
Quoted 2 lines

Rick, can we post a branch with /everything/ on this MMU prep baseline for this selftest refresh?

Actually I see the branch below does contain everything, not just the MMU prep patches. Sagi, is this fine for a baseline?

Maybe for internal development but I don't think I can post an upstream patchset based on an internal Intel development branch. Do you know if there's a plan to post a patch series based on that branch soon?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

This is also available in a tree at:
https://github.com/intel/tdx/tree/tdx_kvm_dev-2024-05-30

Quoted 1 line
#107 lore raw
Quoted 7 lines · Sagi Shahar
Quoted 7 lines
Quoted 6 lines

Hm you're right, I was looking more narrowly because of the kvm-coco- queue conflicts, for some of which even v19 might be too old. The MMU prep series uses a much more recent kvm-coco-queue baseline.

Rick, can we post a branch with /everything/ on this MMU prep baseline for this selftest refresh?

Quoted 7 lines
Quoted 3 lines

Actually I see the branch below does contain everything, not just the MMU prep patches. Sagi, is this fine for a baseline?

Maybe for internal development but I don't think I can post an upstream patchset based on an internal Intel development branch. Do you know if there's a plan to post a patch series based on that branch soon?

We don't currently have plans to post a whole ~130 patch series. Instead we plan to post subsections out of the series as they slowly move into a maintainer branch.

We are trying to use the selftests as part of the development of the base TDX base series. So we need to be able to run them on development branches to catch regressions and such. For this purpose, we wouldn't need updates to be posted to the mailing list. It probably needs either some sort of co-development, or otherwise we will need to maintain an internal fork of the selftests.

We also need to add some specific tests that can cover gaps in our current testing. Probably we could contribute those back to the series.

What do you think?

#108 lore raw
Quoted 12 lines · Rick P
Quoted 10 lines · Sagi Shahar
Quoted 10 lines
Quoted 6 lines

Hm you're right, I was looking more narrowly because of the kvm-coco- queue conflicts, for some of which even v19 might be too old. The MMU prep series uses a much more recent kvm-coco-queue baseline.

Rick, can we post a branch with /everything/ on this MMU prep baseline for this selftest refresh?

Actually I see the branch below does contain everything, not just the MMU prep patches. Sagi, is this fine for a baseline?

Quoted 8 lines
Quoted 4 lines

Maybe for internal development but I don't think I can post an upstream patchset based on an internal Intel development branch. Do you know if there's a plan to post a patch series based on that branch soon?

We don't currently have plans to post a whole ~130 patch series. Instead we plan to post subsections out of the series as they slowly move into a maintainer branch.

So this means that we won't be able to post an updated version of the selftests for a while unless we lock it to the V19 patchset which is based on v6.8-rc5
Do you have an estimate on when the TDX patches get to the point where they could support the basic lifecycle selftest?

Quoted 11 lines

We are trying to use the selftests as part of the development of the base TDX base series. So we need to be able to run them on development branches to catch regressions and such. For this purpose, we wouldn't need updates to be posted to the mailing list. It probably needs either some sort of co-development, or otherwise we will need to maintain an internal fork of the selftests.

We also need to add some specific tests that can cover gaps in our current testing. Probably we could contribute those back to the series.

What do you think?

I will take a look at rebasing the selftests on top of the Intel development branch and I can post it on our github branch. We can talk about co-development offline. We already have some code that was suggested by Isaku as part of our tests.

#109 lore raw
Quoted 10 lines · Sagi Shahar
Quoted 4 lines

We don't currently have plans to post a whole ~130 patch series. Instead we plan
to post subsections out of the series as they slowly move into a maintainer branch.

So this means that we won't be able to post an updated version of the selftests for a while unless we lock it to the V19 patchset which is based on v6.8-rc5
Do you have an estimate on when the TDX patches get to the point where they could support the basic lifecycle selftest?

I don't understand. The MMU prep series postings come with a full branch in github that can boot a TD. What is different if we post the other commits as patches vs just linking to them in github? The selftests won't be upstreamed ahead of the base TDX support anyway, right?

Quoted 13 lines
Quoted 13 lines

We are trying to use the selftests as part of the development of the base TDX
base series. So we need to be able to run them on development branches to catch
regressions and such. For this purpose, we wouldn't need updates to be posted to
the mailing list. It probably needs either some sort of co-development, or otherwise we will need to maintain an internal fork of the selftests.

We also need to add some specific tests that can cover gaps in our current testing. Probably we could contribute those back to the series.

Quoted 6 lines
Quoted 1 line

What do you think?

I will take a look at rebasing the selftests on top of the Intel development branch and I can post it on our github branch. We can talk about co-development offline. We already have some code that was suggested by Isaku as part of our tests.

That would be great, thanks.

#110 lore raw

+Yan

Quoted 6 lines · Rick Edgecombe
Quoted 4 lines

I will take a look at rebasing the selftests on top of the Intel development branch and I can post it on our github branch. We can talk about co-development offline. We already have some code that was suggested by Isaku as part of our tests.

That would be great, thanks.

Hi,

Any update on this rebase?

Thanks,

Rick

#111 lore raw
Quoted 9 lines · Rick P

+Yan

Quoted 5 lines · Rick Edgecombe
Quoted 4 lines

I will take a look at rebasing the selftests on top of the Intel development branch and I can post it on our github branch. We can talk about co-development offline. We already have some code that was suggested by Isaku as part of our tests.

Quoted 5 lines
Quoted 1 line

That would be great, thanks.

Hi,

Any update on this rebase?

I finished rebasing the basic life cycle test and found a bug in tdx_gmem_post_populate which took me some time to debug and fix. I'm going to start a separate thread to share and discuss the selftests.

Quoted 4 lines

Thanks,

Rick