Path: blob/master/tools/testing/selftests/kvm/arm64/kvm-uuid.c
38237 views
// SPDX-License-Identifier: GPL-2.012// Check that nobody has tampered with KVM's UID34#include <errno.h>5#include <linux/arm-smccc.h>6#include <asm/kvm.h>7#include <kvm_util.h>89#include "processor.h"1011/*12* Do NOT redefine these constants, or try to replace them with some13* "common" version. They are hardcoded here to detect any potential14* breakage happening in the rest of the kernel.15*16* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a7417*/18#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 0xb66fb428U19#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 0xe911c52eU20#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 0x564bcaa9U21#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3 0x743a004dU2223static void guest_code(void)24{25struct arm_smccc_res res = {};2627do_smccc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);2829__GUEST_ASSERT(res.a0 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 &&30res.a1 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 &&31res.a2 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 &&32res.a3 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3,33"Unexpected KVM-specific UID %lx %lx %lx %lx\n", res.a0, res.a1, res.a2, res.a3);34GUEST_DONE();35}3637int main (int argc, char *argv[])38{39struct kvm_vcpu *vcpu;40struct kvm_vm *vm;41struct ucall uc;42bool guest_done = false;4344vm = vm_create_with_one_vcpu(&vcpu, guest_code);4546while (!guest_done) {47vcpu_run(vcpu);4849switch (get_ucall(vcpu, &uc)) {50case UCALL_SYNC:51break;52case UCALL_DONE:53guest_done = true;54break;55case UCALL_ABORT:56REPORT_GUEST_ASSERT(uc);57break;58case UCALL_PRINTF:59printf("%s", uc.buffer);60break;61default:62TEST_FAIL("Unexpected guest exit");63}64}6566kvm_vm_free(vm);6768return 0;69}707172