mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-14 00:55:19 -04:00
selftests: kvm: s390: Add s390x ucontrol test suite with hpage test
Add test suite to validate the s390x architecture specific ucontrol KVM interface. Make use of the selftest test harness. * uc_cap_hpage testcase verifies that a ucontrol VM cannot be run with hugepages. To allow testing of the ucontrol interface the kernel needs a non-default config containing CONFIG_KVM_S390_UCONTROL. This config needs to be set to built-in (y) as this cannot be built as module. Signed-off-by: Christoph Schlameuss <schlameuss@linux.ibm.com> Reviewed-by: Janosch Frank <frankja@linux.ibm.com> Link: https://lore.kernel.org/r/20240807154512.316936-4-schlameuss@linux.ibm.com Signed-off-by: Janosch Frank <frankja@linux.ibm.com> Message-ID: <20240807154512.316936-4-schlameuss@linux.ibm.com>
This commit is contained in:
committed by
Janosch Frank
parent
845482188e
commit
011901fc22
1
tools/testing/selftests/kvm/.gitignore
vendored
1
tools/testing/selftests/kvm/.gitignore
vendored
@@ -5,3 +5,4 @@
|
||||
!*.h
|
||||
!*.S
|
||||
!*.sh
|
||||
!config
|
||||
|
||||
@@ -186,6 +186,7 @@ TEST_GEN_PROGS_s390x += s390x/tprot
|
||||
TEST_GEN_PROGS_s390x += s390x/cmma_test
|
||||
TEST_GEN_PROGS_s390x += s390x/debug_test
|
||||
TEST_GEN_PROGS_s390x += s390x/shared_zeropage_test
|
||||
TEST_GEN_PROGS_s390x += s390x/ucontrol_test
|
||||
TEST_GEN_PROGS_s390x += demand_paging_test
|
||||
TEST_GEN_PROGS_s390x += dirty_log_test
|
||||
TEST_GEN_PROGS_s390x += guest_print_test
|
||||
|
||||
2
tools/testing/selftests/kvm/s390x/config
Normal file
2
tools/testing/selftests/kvm/s390x/config
Normal file
@@ -0,0 +1,2 @@
|
||||
CONFIG_KVM=y
|
||||
CONFIG_KVM_S390_UCONTROL=y
|
||||
76
tools/testing/selftests/kvm/s390x/ucontrol_test.c
Normal file
76
tools/testing/selftests/kvm/s390x/ucontrol_test.c
Normal file
@@ -0,0 +1,76 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Test code for the s390x kvm ucontrol interface
|
||||
*
|
||||
* Copyright IBM Corp. 2024
|
||||
*
|
||||
* Authors:
|
||||
* Christoph Schlameuss <schlameuss@linux.ibm.com>
|
||||
*/
|
||||
#include "kselftest_harness.h"
|
||||
#include "kvm_util.h"
|
||||
|
||||
#include <linux/capability.h>
|
||||
#include <linux/sizes.h>
|
||||
|
||||
/* so directly declare capget to check caps without libcap */
|
||||
int capget(cap_user_header_t header, cap_user_data_t data);
|
||||
|
||||
/**
|
||||
* In order to create user controlled virtual machines on S390,
|
||||
* check KVM_CAP_S390_UCONTROL and use the flag KVM_VM_S390_UCONTROL
|
||||
* as privileged user (SYS_ADMIN).
|
||||
*/
|
||||
void require_ucontrol_admin(void)
|
||||
{
|
||||
struct __user_cap_data_struct data[_LINUX_CAPABILITY_U32S_3];
|
||||
struct __user_cap_header_struct hdr = {
|
||||
.version = _LINUX_CAPABILITY_VERSION_3,
|
||||
};
|
||||
int rc;
|
||||
|
||||
rc = capget(&hdr, data);
|
||||
TEST_ASSERT_EQ(0, rc);
|
||||
TEST_REQUIRE((data->effective & CAP_TO_MASK(CAP_SYS_ADMIN)) > 0);
|
||||
|
||||
TEST_REQUIRE(kvm_has_cap(KVM_CAP_S390_UCONTROL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert HPAGE CAP cannot be enabled on UCONTROL VM
|
||||
*/
|
||||
TEST(uc_cap_hpage)
|
||||
{
|
||||
int rc, kvm_fd, vm_fd, vcpu_fd;
|
||||
struct kvm_enable_cap cap = {
|
||||
.cap = KVM_CAP_S390_HPAGE_1M,
|
||||
};
|
||||
|
||||
require_ucontrol_admin();
|
||||
|
||||
kvm_fd = open_kvm_dev_path_or_exit();
|
||||
vm_fd = ioctl(kvm_fd, KVM_CREATE_VM, KVM_VM_S390_UCONTROL);
|
||||
ASSERT_GE(vm_fd, 0);
|
||||
|
||||
/* assert hpages are not supported on ucontrol vm */
|
||||
rc = ioctl(vm_fd, KVM_CHECK_EXTENSION, KVM_CAP_S390_HPAGE_1M);
|
||||
EXPECT_EQ(0, rc);
|
||||
|
||||
/* Test that KVM_CAP_S390_HPAGE_1M can't be enabled for a ucontrol vm */
|
||||
rc = ioctl(vm_fd, KVM_ENABLE_CAP, cap);
|
||||
EXPECT_EQ(-1, rc);
|
||||
EXPECT_EQ(EINVAL, errno);
|
||||
|
||||
/* assert HPAGE CAP is rejected after vCPU creation */
|
||||
vcpu_fd = ioctl(vm_fd, KVM_CREATE_VCPU, 0);
|
||||
ASSERT_GE(vcpu_fd, 0);
|
||||
rc = ioctl(vm_fd, KVM_ENABLE_CAP, cap);
|
||||
EXPECT_EQ(-1, rc);
|
||||
EXPECT_EQ(EBUSY, errno);
|
||||
|
||||
close(vcpu_fd);
|
||||
close(vm_fd);
|
||||
close(kvm_fd);
|
||||
}
|
||||
|
||||
TEST_HARNESS_MAIN
|
||||
Reference in New Issue
Block a user