tools/testing/selftests/kvm/x86/nested_set_state_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/nested_set_state_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/nested_set_state_test.c- Extension
.c- Size
- 11679 bytes
- Lines
- 407
- 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
test_util.hkvm_util.hprocessor.hvmx.hsvm_util.herrno.hlinux/kvm.hstring.hsys/ioctl.hunistd.h
Detected Declarations
function test_nested_statefunction test_nested_state_expect_errnofunction test_nested_state_expect_einvalfunction test_nested_state_expect_efaultfunction set_revision_id_for_vmcs12function set_default_statefunction set_default_vmx_statefunction test_vmx_nested_statefunction vcpu_efer_enable_svmfunction vcpu_efer_disable_svmfunction set_default_svm_statefunction test_svm_nested_statefunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2019, Google LLC.
*
* This test verifies the integrity of calling the ioctl KVM_SET_NESTED_STATE.
*/
#include "test_util.h"
#include "kvm_util.h"
#include "processor.h"
#include "vmx.h"
#include "svm_util.h"
#include <errno.h>
#include <linux/kvm.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
/*
* Mirror of VMCS12_REVISION in arch/x86/kvm/vmx/vmcs12.h. If that value
* changes this should be updated.
*/
#define VMCS12_REVISION 0x11e57ed0
bool have_evmcs;
void test_nested_state(struct kvm_vcpu *vcpu, struct kvm_nested_state *state)
{
vcpu_nested_state_set(vcpu, state);
}
void test_nested_state_expect_errno(struct kvm_vcpu *vcpu,
struct kvm_nested_state *state,
int expected_errno)
{
int rv;
rv = __vcpu_nested_state_set(vcpu, state);
TEST_ASSERT(rv == -1 && errno == expected_errno,
"Expected %s (%d) from vcpu_nested_state_set but got rv: %i errno: %s (%d)",
strerror(expected_errno), expected_errno, rv, strerror(errno),
errno);
}
void test_nested_state_expect_einval(struct kvm_vcpu *vcpu,
struct kvm_nested_state *state)
{
test_nested_state_expect_errno(vcpu, state, EINVAL);
}
void test_nested_state_expect_efault(struct kvm_vcpu *vcpu,
struct kvm_nested_state *state)
{
test_nested_state_expect_errno(vcpu, state, EFAULT);
}
void set_revision_id_for_vmcs12(struct kvm_nested_state *state,
u32 vmcs12_revision)
{
/* Set revision_id in vmcs12 to vmcs12_revision. */
memcpy(&state->data, &vmcs12_revision, sizeof(u32));
}
void set_default_state(struct kvm_nested_state *state)
{
memset(state, 0, sizeof(*state));
state->flags = KVM_STATE_NESTED_RUN_PENDING |
KVM_STATE_NESTED_GUEST_MODE;
state->format = 0;
state->size = sizeof(*state);
}
void set_default_vmx_state(struct kvm_nested_state *state, int size)
{
memset(state, 0, size);
if (have_evmcs)
state->flags = KVM_STATE_NESTED_EVMCS;
state->format = 0;
state->size = size;
state->hdr.vmx.vmxon_pa = 0x1000;
state->hdr.vmx.vmcs12_pa = 0x2000;
state->hdr.vmx.smm.flags = 0;
set_revision_id_for_vmcs12(state, VMCS12_REVISION);
}
void test_vmx_nested_state(struct kvm_vcpu *vcpu)
{
/* Add a page for VMCS12. */
const int state_sz = sizeof(struct kvm_nested_state) + getpagesize();
Annotation
- Immediate include surface: `test_util.h`, `kvm_util.h`, `processor.h`, `vmx.h`, `svm_util.h`, `errno.h`, `linux/kvm.h`, `string.h`.
- Detected declarations: `function test_nested_state`, `function test_nested_state_expect_errno`, `function test_nested_state_expect_einval`, `function test_nested_state_expect_efault`, `function set_revision_id_for_vmcs12`, `function set_default_state`, `function set_default_vmx_state`, `function test_vmx_nested_state`, `function vcpu_efer_enable_svm`, `function vcpu_efer_disable_svm`.
- 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.