From: "Tycho Andersen (AMD)" <[email protected]>

In addition to the errno, sometimes it is useful to know the underlying SEV
firmware error. Update the raw vm ioctl macro to allow for optionally
retrieving this.

Signed-off-by: Tycho Andersen (AMD) <[email protected]>
---
 tools/testing/selftests/kvm/include/x86/sev.h       | 6 ++++--
 tools/testing/selftests/kvm/x86/sev_migrate_tests.c | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/x86/sev.h 
b/tools/testing/selftests/kvm/include/x86/sev.h
index 008b4169f5e2..fd11f4222ec2 100644
--- a/tools/testing/selftests/kvm/include/x86/sev.h
+++ b/tools/testing/selftests/kvm/include/x86/sev.h
@@ -76,7 +76,7 @@ static inline u64 snp_default_policy(void)
  * creating an overlay to pass in an "unsigned long" without a cast (casting
  * will make the compiler unhappy due to dereferencing an aliased pointer).
  */
-#define __vm_sev_ioctl(vm, cmd, arg)                                   \
+#define __vm_sev_ioctl(vm, cmd, arg, errorp)                           \
 ({                                                                     \
        int r;                                                          \
                                                                        \
@@ -90,12 +90,14 @@ static inline u64 snp_default_policy(void)
        } };                                                            \
                                                                        \
        r = __vm_ioctl(vm, KVM_MEMORY_ENCRYPT_OP, &sev_cmd.raw);        \
+       if (errorp != NULL)                                             \
+               *((__u32 *)errorp) = sev_cmd.c.error;                   \
        r ?: sev_cmd.c.error;                                           \
 })
 
 #define vm_sev_ioctl(vm, cmd, arg)                                     \
 ({                                                                     \
-       int ret = __vm_sev_ioctl(vm, cmd, arg);                         \
+       int ret = __vm_sev_ioctl(vm, cmd, arg, NULL);                   \
                                                                        \
        __TEST_ASSERT_VM_VCPU_IOCTL(!ret, #cmd, ret, vm);               \
 })
diff --git a/tools/testing/selftests/kvm/x86/sev_migrate_tests.c 
b/tools/testing/selftests/kvm/x86/sev_migrate_tests.c
index 0a6dfba3905b..18f3091e0bd8 100644
--- a/tools/testing/selftests/kvm/x86/sev_migrate_tests.c
+++ b/tools/testing/selftests/kvm/x86/sev_migrate_tests.c
@@ -232,7 +232,7 @@ static void verify_mirror_allowed_cmds(struct kvm_vm *vm)
                 * These commands should be disallowed before the data
                 * parameter is examined so NULL is OK here.
                 */
-               ret = __vm_sev_ioctl(vm, cmd_id, NULL);
+               ret = __vm_sev_ioctl(vm, cmd_id, NULL, NULL);
                TEST_ASSERT(
                        ret == -1 && errno == EINVAL,
                        "Should not be able call command: %d. ret: %d, errno: 
%d",
-- 
2.53.0


Reply via email to