tools/testing/selftests/kvm/s390/ucontrol_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/s390/ucontrol_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/s390/ucontrol_test.c- Extension
.c- Size
- 22391 bytes
- Lines
- 799
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
debug_print.hkselftest_harness.hkvm_util.hprocessor.hsie.hlinux/capability.hlinux/sizes.h
Detected Declarations
function userfunction uc_map_extfunction uc_unmap_extfunction uc_handle_exit_ucontrolfunction uc_skey_enablefunction uc_handle_insn_icfunction uc_handle_sieicfunction uc_handle_exitfunction uc_run_oncefunction uc_assert_diag44
Annotated Snippet
// 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 "debug_print.h"
#include "kselftest_harness.h"
#include "kvm_util.h"
#include "processor.h"
#include "sie.h"
#include <linux/capability.h>
#include <linux/sizes.h>
#define PGM_SEGMENT_TRANSLATION 0x10
#define VM_MEM_SIZE (4 * SZ_1M)
#define VM_MEM_EXT_SIZE (2 * SZ_1M)
#define VM_MEM_MAX_M ((VM_MEM_SIZE + VM_MEM_EXT_SIZE) / SZ_1M)
/* 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));
}
/* Test program setting some registers and looping */
extern char test_gprs_asm[];
asm("test_gprs_asm:\n"
"xgr %r0, %r0\n"
"lgfi %r1,1\n"
"lgfi %r2,2\n"
"lgfi %r3,3\n"
"lgfi %r4,4\n"
"lgfi %r5,5\n"
"lgfi %r6,6\n"
"lgfi %r7,7\n"
"0:\n"
" diag 0,0,0x44\n"
" ahi %r0,1\n"
" j 0b\n"
);
/* Test program manipulating memory */
extern char test_mem_asm[];
asm("test_mem_asm:\n"
"xgr %r0, %r0\n"
"0:\n"
" ahi %r0,1\n"
" st %r1,0(%r5,%r6)\n"
" xgr %r1,%r1\n"
" l %r1,0(%r5,%r6)\n"
" ahi %r0,1\n"
" diag 0,0,0x44\n"
" j 0b\n"
);
/* Test program manipulating storage keys */
extern char test_skey_asm[];
asm("test_skey_asm:\n"
"xgr %r0, %r0\n"
"0:\n"
" ahi %r0,1\n"
" st %r1,0(%r5,%r6)\n"
Annotation
- Immediate include surface: `debug_print.h`, `kselftest_harness.h`, `kvm_util.h`, `processor.h`, `sie.h`, `linux/capability.h`, `linux/sizes.h`.
- Detected declarations: `function user`, `function uc_map_ext`, `function uc_unmap_ext`, `function uc_handle_exit_ucontrol`, `function uc_skey_enable`, `function uc_handle_insn_ic`, `function uc_handle_sieic`, `function uc_handle_exit`, `function uc_run_once`, `function uc_assert_diag44`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.