From: Marc Zyngier <maz@kernel.org>
To: Andrew Jones <ajones@ventanamicro.com>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Zenghui Yu <yuzenghui@huawei.com>, Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
jackabt@amazon.com
Subject: Re: [PATCH] KVM: arm64: selftest: Add standalone test checking for KVM's own UUID
Date: Tue, 22 Jul 2025 16:47:26 +0100 [thread overview]
Message-ID: <86h5z48bxt.wl-maz@kernel.org> (raw)
In-Reply-To: <20250722-87ac9d7e0b27cf7c67a4fbd3@orel>
On Tue, 22 Jul 2025 10:18:10 +0100,
Andrew Jones <ajones@ventanamicro.com> wrote:
>
> Hi Marc,
>
> On Mon, Jul 21, 2025 at 04:51:36PM +0100, Marc Zyngier wrote:
> > Tinkering with UUIDs is a perilious task, and the KVM UUID gets
> > broken at times. In order to spot this early enough, add a selftest
> > that will shout if the expected value isn't found.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > Link: https://lore.kernel.org/r/20250721130558.50823-1-jackabt.amazon@gmail.com
> > ---
> > tools/testing/selftests/kvm/Makefile.kvm | 1 +
> > tools/testing/selftests/kvm/arm64/kvm-uuid.c | 67 ++++++++++++++++++++
> > 2 files changed, 68 insertions(+)
> > create mode 100644 tools/testing/selftests/kvm/arm64/kvm-uuid.c
> >
> > diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> > index ce817a975e50a..e1eb1ba238a2a 100644
> > --- a/tools/testing/selftests/kvm/Makefile.kvm
> > +++ b/tools/testing/selftests/kvm/Makefile.kvm
> > @@ -167,6 +167,7 @@ TEST_GEN_PROGS_arm64 += arm64/vgic_irq
> > TEST_GEN_PROGS_arm64 += arm64/vgic_lpi_stress
> > TEST_GEN_PROGS_arm64 += arm64/vpmu_counter_access
> > TEST_GEN_PROGS_arm64 += arm64/no-vgic-v3
> > +TEST_GEN_PROGS_arm64 += arm64/kvm-uuid
> > TEST_GEN_PROGS_arm64 += access_tracking_perf_test
> > TEST_GEN_PROGS_arm64 += arch_timer
> > TEST_GEN_PROGS_arm64 += coalesced_io_test
> > diff --git a/tools/testing/selftests/kvm/arm64/kvm-uuid.c b/tools/testing/selftests/kvm/arm64/kvm-uuid.c
> > new file mode 100644
> > index 0000000000000..89d9c8b182ae5
> > --- /dev/null
> > +++ b/tools/testing/selftests/kvm/arm64/kvm-uuid.c
> > @@ -0,0 +1,67 @@
> > +#include <errno.h>
> > +#include <linux/arm-smccc.h>
> > +#include <asm/kvm.h>
> > +#include <kvm_util.h>
> > +
> > +#include "processor.h"
> > +
> > +/*
> > + * Do NOT redefine these constants, or try to replace them with some
> > + * "common" version. They are hardcoded here to detect any potential
> > + * breakage happening in the rest of the kernel.
> > + *
> > + * KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74
> > + */
> > +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 0xb66fb428U
> > +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 0xe911c52eU
> > +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 0x564bcaa9U
> > +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3 0x743a004dU
> > +
> > +static void guest_code(void)
> > +{
> > + struct arm_smccc_res res = {};
> > +
> > + smccc_hvc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);
> > +
> > + __GUEST_ASSERT(res.a0 != SMCCC_RET_NOT_SUPPORTED, "a0 = %lx\n", res.a0);
>
> Should this check res.a0 == SMCCC_RET_SUCCESS instead?
Yeah, probably.
>
> > + __GUEST_ASSERT(res.a0 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 &&
> > + res.a1 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 &&
> > + res.a2 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 &&
> > + res.a3 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3,
> > + "Unexpected KVM-specific UID %lx %lx %lx %lx\n", res.a0, res.a1, res.a2, res.a3);
> > + GUEST_DONE();
> > +}
> > +
> > +int main (int argc, char *argv[])
> > +{
> > + struct kvm_vcpu *vcpu;
> > + struct kvm_vm *vm;
> > + struct ucall uc;
> > + bool guest_done = false;
> > +
> > + vm = vm_create_with_one_vcpu(&vcpu, guest_code);
> > +
> > + while (!guest_done) {
> > + vcpu_run(vcpu);
> > +
> > + switch (get_ucall(vcpu, &uc)) {
> > + case UCALL_SYNC:
> > + break;
> > + case UCALL_DONE:
> > + guest_done = true;
> > + break;
> > + case UCALL_ABORT:
> > + REPORT_GUEST_ASSERT(uc);
> > + break;
> > + case UCALL_PRINTF:
> > + printf("%s", uc.buffer);
> > + break;
> > + default:
> > + TEST_FAIL("Unexpected guest exit");
> > + }
> > + }
>
> This is becoming a very common and useful pattern. I wonder if it's time
> for a ucall helper
>
> static void ucall_vcpu_run(struct kvm_vcpu *vcpu,
> void (*sync_func)(struct kvm_vcpu *, void *),
> void *sync_data)
> {
> bool guest_done = false;
> struct ucall uc;
>
> while (!guest_done) {
> vcpu_run(vcpu);
>
> switch (get_ucall(vcpu, &uc)) {
> case UCALL_SYNC:
> if (sync_func)
> sync_func(vcpu, sync_data);
> break;
> case UCALL_DONE:
> guest_done = true;
> break;
> case UCALL_ABORT:
> REPORT_GUEST_ASSERT(uc);
> break;
> case UCALL_PRINTF:
> printf("%s", uc.buffer);
> break;
> default:
> TEST_FAIL("Unexpected guest exit");
> }
> }
> }
Honestly, I don't know. My understanding is that the common kvm
selftest code is now mostly a pile of x86-specific stuff, and I've
made it a goal not to touch any of it.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-07-22 15:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 15:51 [PATCH] KVM: arm64: selftest: Add standalone test checking for KVM's own UUID Marc Zyngier
2025-07-22 9:18 ` Andrew Jones
2025-07-22 15:47 ` Marc Zyngier [this message]
2025-08-06 17:10 ` Marc Zyngier
2025-07-22 14:39 ` Sebastian Ott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86h5z48bxt.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=ajones@ventanamicro.com \
--cc=jackabt@amazon.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox