On 5/22/2026 7:16 AM, Lisa Wang wrote:
From: Sean Christopherson<[email protected]>
Add VM_TYPE() and __VM_TYPE() macros to create a vm_shape structure given
a type (and mode), and use the macros to define VM_SHAPE_{SEV,SEV_ES,SNP}
shapes for x86's SEV family of VM shapes. Providing common infrastructure
will avoid having to copy+paste vm_sev_create_with_one_vcpu() for TDX.
Use the new SEV+ shapes and drop vm_sev_create_with_one_vcpu().
No functional change intended.
Signed-off-by: Sean Christopherson<[email protected]>
Signed-off-by: Sagi Shahar<[email protected]>
Reviewed-by: Binbin Wu<[email protected]>
Reviewed-by: Ira Weiny<[email protected]>
Signed-off-by: Lisa Wang<[email protected]>
Reviewed-by: Xiaoyao Li <[email protected]>
---
tools/testing/selftests/kvm/include/kvm_util.h | 13 +++++++
.../testing/selftests/kvm/include/x86/processor.h | 4 +++
tools/testing/selftests/kvm/include/x86/sev.h | 2 --
tools/testing/selftests/kvm/lib/x86/sev.c | 16 ---------
tools/testing/selftests/kvm/x86/sev_smoke_test.c | 40 +++++++++++-----------
5 files changed, 37 insertions(+), 38 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h
b/tools/testing/selftests/kvm/include/kvm_util.h
index dc70c6da63fa..041bdbfb93f7 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -233,6 +233,19 @@ kvm_static_assert(sizeof(struct vm_shape) == sizeof(u64));
shape; \
})
+#define __VM_TYPE(__mode, __type) \
It seems the name "__VM_SHAPE" fits better?
+({ \
+ struct vm_shape shape = { \
+ .mode = (__mode), \
+ .type = (__type) \
+ }; \
+ \
+ shape; \
+})
+
+#define VM_TYPE(__type) \
+ __VM_TYPE(VM_MODE_DEFAULT, __type)
and I think making it one line would be OK?
So something on top:
---8<---
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h
b/tools/testing/selftests/kvm/include/kvm_util.h
index 041bdbfb93f7..a1b5d2029d05 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -223,17 +223,7 @@ kvm_static_assert(sizeof(struct vm_shape) ==
sizeof(u64));
#define VM_TYPE_DEFAULT 0
-#define VM_SHAPE(__mode) \
-({ \
- struct vm_shape shape = { \
- .mode = (__mode), \
- .type = VM_TYPE_DEFAULT \
- }; \
- \
- shape; \
-})
-
-#define __VM_TYPE(__mode, __type) \
+#define __VM_SHAPE(__mode, __type) \
({ \
struct vm_shape shape = { \
.mode = (__mode), \
@@ -243,8 +233,8 @@ kvm_static_assert(sizeof(struct vm_shape) ==
sizeof(u64));
shape; \
})
-#define VM_TYPE(__type) \
- __VM_TYPE(VM_MODE_DEFAULT, __type)
+#define VM_SHAPE(__mode) __VM_SHAPE(__mode, VM_TYPE_DEFAULT)
+#define VM_TYPE(__type) __VM_SHAPE(VM_MODE_DEFAULT, __type)
extern enum vm_guest_mode vm_mode_default;