summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/kvm/lib/ucall_common.c
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2023-02-23 10:27:32 +0100
committerMiquel Raynal <miquel.raynal@bootlin.com>2023-02-23 10:27:32 +0100
commit27121864ab366992583d894961ecdc6e2ffe0ca1 (patch)
tree87ef1dcf82ce2d0d29b686d5ae81003ab3eb3b4a /tools/testing/selftests/kvm/lib/ucall_common.c
parent84549c816dc317f012798e706e58669b3b013604 (diff)
parentf047382519ca41702ebaee5a862e87390f687137 (diff)
Merge tag 'spi-nor/for-6.3' into mtd/next
SPI NOR changes: * small fixes on core and spansion driver.
Diffstat (limited to 'tools/testing/selftests/kvm/lib/ucall_common.c')
-rw-r--r--tools/testing/selftests/kvm/lib/ucall_common.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/tools/testing/selftests/kvm/lib/ucall_common.c b/tools/testing/selftests/kvm/lib/ucall_common.c
index 0cc0971ce60e..2f0e2ea941cc 100644
--- a/tools/testing/selftests/kvm/lib/ucall_common.c
+++ b/tools/testing/selftests/kvm/lib/ucall_common.c
@@ -4,6 +4,8 @@
#include "linux/bitmap.h"
#include "linux/atomic.h"
+#define GUEST_UCALL_FAILED -1
+
struct ucall_header {
DECLARE_BITMAP(in_use, KVM_MAX_VCPUS);
struct ucall ucalls[KVM_MAX_VCPUS];
@@ -41,7 +43,8 @@ static struct ucall *ucall_alloc(void)
struct ucall *uc;
int i;
- GUEST_ASSERT(ucall_pool);
+ if (!ucall_pool)
+ goto ucall_failed;
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
if (!test_and_set_bit(i, ucall_pool->in_use)) {
@@ -51,7 +54,13 @@ static struct ucall *ucall_alloc(void)
}
}
- GUEST_ASSERT(0);
+ucall_failed:
+ /*
+ * If the vCPU cannot grab a ucall structure, make a bare ucall with a
+ * magic value to signal to get_ucall() that things went sideways.
+ * GUEST_ASSERT() depends on ucall_alloc() and so cannot be used here.
+ */
+ ucall_arch_do_ucall(GUEST_UCALL_FAILED);
return NULL;
}
@@ -93,6 +102,9 @@ uint64_t get_ucall(struct kvm_vcpu *vcpu, struct ucall *uc)
addr = ucall_arch_get_ucall(vcpu);
if (addr) {
+ TEST_ASSERT(addr != (void *)GUEST_UCALL_FAILED,
+ "Guest failed to allocate ucall struct");
+
memcpy(uc, addr, sizeof(*uc));
vcpu_run_complete_io(vcpu);
} else {