@@ -12,6 +12,7 @@
#include "ucall_common.h"
extern const struct ucall_ops ucall_ops_pio;
+extern const struct ucall_ops ucall_ops_halt;
extern const struct ucall_ops ucall_ops_default;
@@ -57,4 +57,27 @@ const struct ucall_ops ucall_ops_pio = {
.recv_cmd_shared = ucall_ops_pio_recv_cmd_shared,
};
+static void ucall_ops_halt_send_cmd_shared(struct ucall *uc)
+{
+ asm volatile("hlt" : : : "memory");
+}
+
+static uint64_t ucall_ops_halt_recv_cmd_shared(struct kvm_vm *vm, uint32_t vcpu_id,
+ struct ucall *uc)
+{
+ struct kvm_run *run = vcpu_state(vm, vcpu_id);
+
+ TEST_ASSERT(run->exit_reason == KVM_EXIT_HLT,
+ "unexpected exit reason: %u (%s)",
+ run->exit_reason, exit_reason_str(run->exit_reason));
+
+ return uc->cmd;
+}
+
+const struct ucall_ops ucall_ops_halt = {
+ .name = "halt",
+ .send_cmd_shared = ucall_ops_halt_send_cmd_shared,
+ .recv_cmd_shared = ucall_ops_halt_recv_cmd_shared,
+};
+
const struct ucall_ops ucall_ops_default = ucall_ops_pio;
With the shared ucall interfaces the only thing the ucall implementation really needs to do is generate an exit to host userspace so that the shared ucall struct can be examined. This implementation uses a 'halt' instruction to generate such an exit, and is suitable for use with SEV guests, and potentially other confidential guest implementations. Signed-off-by: Michael Roth <michael.roth@amd.com> --- .../selftests/kvm/include/x86_64/ucall.h | 1 + .../testing/selftests/kvm/lib/x86_64/ucall.c | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+)