On 6/17/2026 12:51 AM, Sean Christopherson wrote:
From: Sean Christopherson<[email protected]>
Date: Tue, 28 Oct 2025 21:20:27 +0000
Subject: [PATCH] KVM: selftests: Add macros to simplify creating VM shapes for
  non-default types

Add VM_TYPE() and __VM_SHAPE() 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().

Opportunistically move the existing VM_SHAPE() (now __VM_SHAPE()) macro
below the definitions of VM_MODE_DEFAULT so that all of the SHAPE/TYPE
macros are bundled together.

No functional change intended.

Reviewed-by: Binbin Wu<[email protected]>
Reviewed-by: Ira Weiny<[email protected]>
Signed-off-by: Sean Christopherson<[email protected]>

Reviewed-by: Xiaoyao Li <[email protected]>

some nits below

---
  .../testing/selftests/kvm/include/kvm_util.h  | 28 +++++++------
  .../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 --------
  .../selftests/kvm/x86/sev_smoke_test.c        | 40 +++++++++----------
  5 files changed, 40 insertions(+), 50 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/kvm_util.h 
b/tools/testing/selftests/kvm/include/kvm_util.h
index dc70c6da63fa..46bae183d7fc 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -221,18 +221,6 @@ struct vm_shape {
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;                                  \
-})
-
  extern enum vm_guest_mode vm_mode_default;
#if defined(__aarch64__)
@@ -270,8 +258,24 @@ extern enum vm_guest_mode vm_mode_default;
#endif +#define VM_TYPE_DEFAULT 0
+
+#define __VM_SHAPE(__mode, __type)                     \

inconsistent indentation with below lines.

+({                                             \
+       struct vm_shape shape = {               \
+               .mode = (__mode),               \
+               .type = (__type),               \
+       };                                      \
+                                               \
+       shape;                                  \
+})
+
+

one extra new line.

+#define VM_SHAPE(__mode)       __VM_SHAPE(__mode, VM_TYPE_DEFAULT)
  #define VM_SHAPE_DEFAULT      VM_SHAPE(VM_MODE_DEFAULT)
+#define VM_TYPE(__type) __VM_SHAPE(VM_MODE_DEFAULT, __type)
+
  #define MIN_PAGE_SIZE         (1U << MIN_PAGE_SHIFT)
  #define PTES_PER_MIN_PAGE     ptes_per_page(MIN_PAGE_SIZE)


Reply via email to