On Wed, Oct 11 2023, Oliver Upton <oliver.upton@xxxxxxxxx> wrote: > From: Jing Zhang <jingzhangos@xxxxxxxxxx> > > Add tests to verify setting ID registers from userspace is handled > correctly by KVM. Also add a test case to use ioctl > KVM_ARM_GET_REG_WRITABLE_MASKS to get writable masks. > > Signed-off-by: Jing Zhang <jingzhangos@xxxxxxxxxx> > Signed-off-by: Oliver Upton <oliver.upton@xxxxxxxxx> > --- > tools/testing/selftests/kvm/Makefile | 1 + > .../selftests/kvm/aarch64/set_id_regs.c | 479 ++++++++++++++++++ > 2 files changed, 480 insertions(+) > create mode 100644 tools/testing/selftests/kvm/aarch64/set_id_regs.c (...) > +static void test_user_set_reg(struct kvm_vcpu *vcpu, bool aarch64_only) > +{ > + uint64_t masks[KVM_ARM_FEATURE_ID_RANGE_SIZE]; > + struct reg_mask_range range = { > + .addr = (__u64)masks, > + }; > + int ret; > + > + /* KVM should return error when reserved field is not zero */ > + range.reserved[0] = 1; > + ret = __vm_ioctl(vcpu->vm, KVM_ARM_GET_REG_WRITABLE_MASKS, &range); > + TEST_ASSERT(ret, "KVM doesn't check invalid parameters."); I think the code should first check for KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES -- newer kselftests are supposed to be able to run on older kernels, and we should just skip all of this if the API isn't there. > + > + /* Get writable masks for feature ID registers */ > + memset(range.reserved, 0, sizeof(range.reserved)); > + vm_ioctl(vcpu->vm, KVM_ARM_GET_REG_WRITABLE_MASKS, &range);