[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221209015307.1781352-8-oliver.upton@linux.dev>
Date: Fri, 9 Dec 2022 01:53:06 +0000
From: Oliver Upton <oliver.upton@...ux.dev>
To: Marc Zyngier <maz@...nel.org>, James Morse <james.morse@....com>,
Alexandru Elisei <alexandru.elisei@....com>,
Paolo Bonzini <pbonzini@...hat.com>,
Shuah Khan <shuah@...nel.org>,
Andrew Jones <andrew.jones@...ux.dev>,
Peter Gonda <pgonda@...gle.com>,
Sean Christopherson <seanjc@...gle.com>
Cc: linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.cs.columbia.edu,
kvm@...r.kernel.org, kvmarm@...ts.linux.dev,
Ricardo Koller <ricarkol@...gle.com>,
Oliver Upton <oliver.upton@...ux.dev>,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH v2 7/7] KVM: selftests: Avoid infinite loop if ucall_alloc() fails
Guest assertions depend on successfully allocating a ucall structure. As
such, the use of guest assertions when ucall_alloc() fails simply leads
to an infinite loop in guest code.
Use GUEST_UCALL_NONE() to indicate failure instead. Though not
technically necessary, use a goto to have a single callsite and an
associated comment about why assertions don't work here. It isn't
perfect, at least the poor developer gets some signal out of the
guest...
Fixes: 426729b2cf2e ("KVM: selftests: Add ucall pool based implementation")
Signed-off-by: Oliver Upton <oliver.upton@...ux.dev>
---
tools/testing/selftests/kvm/lib/ucall_common.c | 12 ++++++++++--
1 file changed, 10 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..e8370da3de24 100644
--- a/tools/testing/selftests/kvm/lib/ucall_common.c
+++ b/tools/testing/selftests/kvm/lib/ucall_common.c
@@ -41,7 +41,8 @@ static struct ucall *ucall_alloc(void)
struct ucall *uc;
int i;
- GUEST_ASSERT(ucall_pool);
+ if (!ucall_pool)
+ goto out;
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
if (!test_and_set_bit(i, ucall_pool->in_use)) {
@@ -51,7 +52,14 @@ static struct ucall *ucall_alloc(void)
}
}
- GUEST_ASSERT(0);
+out:
+ /*
+ * If the guest cannot grab a ucall structure from the pool then the
+ * only option to get out to userspace is a bare ucall. This is probably
+ * a good time to mention that guest assertions depend on ucalls with
+ * arguments too.
+ */
+ GUEST_UCALL_NONE();
return NULL;
}
--
2.39.0.rc1.256.g54fd8350bd-goog
Powered by blists - more mailing lists