[PATCH v3 5/5] KVM: arm64: selftests: Test for setting ID register from usersapce

Cornelia Huck cohuck at redhat.com
Mon Oct 16 08:30:06 PDT 2023


On Wed, Oct 11 2023, Oliver Upton <oliver.upton at linux.dev> wrote:

> From: Jing Zhang <jingzhangos at google.com>
>
> 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 at google.com>
> Signed-off-by: Oliver Upton <oliver.upton at linux.dev>
> ---
>  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);




More information about the linux-arm-kernel mailing list