tools/testing/selftests/kvm/x86/fastops_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/fastops_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/fastops_test.c- Extension
.c- Size
- 7702 bytes
- Lines
- 210
- 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.h
Detected Declarations
function guest_codefunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include "test_util.h"
#include "kvm_util.h"
#include "processor.h"
/*
* Execute a fastop() instruction, with or without forced emulation. BT bit 0
* to set RFLAGS.CF based on whether or not the input is even or odd, so that
* instructions like ADC and SBB are deterministic.
*/
#define fastop(__insn) \
"bt $0, %[bt_val]\n\t" \
__insn "\n\t" \
"pushfq\n\t" \
"pop %[flags]\n\t"
#define flags_constraint(flags_val) [flags]"=r"(flags_val)
#define bt_constraint(__bt_val) [bt_val]"rm"((u32)__bt_val)
#define guest_execute_fastop_1(FEP, insn, __val, __flags) \
({ \
__asm__ __volatile__(fastop(FEP insn " %[val]") \
: [val]"+r"(__val), flags_constraint(__flags) \
: bt_constraint(__val) \
: "cc", "memory"); \
})
#define guest_test_fastop_1(insn, type_t, __val) \
({ \
type_t val = __val, ex_val = __val, input = __val; \
u64 flags, ex_flags; \
\
guest_execute_fastop_1("", insn, ex_val, ex_flags); \
guest_execute_fastop_1(KVM_FEP, insn, val, flags); \
\
__GUEST_ASSERT(val == ex_val, \
"Wanted 0x%lx for '%s 0x%lx', got 0x%lx", \
(u64)ex_val, insn, (u64)input, (u64)val); \
__GUEST_ASSERT(flags == ex_flags, \
"Wanted flags 0x%lx for '%s 0x%lx', got 0x%lx", \
ex_flags, insn, (u64)input, flags); \
})
#define guest_execute_fastop_2(FEP, insn, __input, __output, __flags) \
({ \
__asm__ __volatile__(fastop(FEP insn " %[input], %[output]") \
: [output]"+r"(__output), flags_constraint(__flags) \
: [input]"r"(__input), bt_constraint(__output) \
: "cc", "memory"); \
})
#define guest_test_fastop_2(insn, type_t, __val1, __val2) \
({ \
type_t input = __val1, input2 = __val2, output = __val2, ex_output = __val2; \
u64 flags, ex_flags; \
\
guest_execute_fastop_2("", insn, input, ex_output, ex_flags); \
guest_execute_fastop_2(KVM_FEP, insn, input, output, flags); \
\
__GUEST_ASSERT(output == ex_output, \
"Wanted 0x%lx for '%s 0x%lx 0x%lx', got 0x%lx", \
(u64)ex_output, insn, (u64)input, \
(u64)input2, (u64)output); \
__GUEST_ASSERT(flags == ex_flags, \
"Wanted flags 0x%lx for '%s 0x%lx, 0x%lx', got 0x%lx", \
ex_flags, insn, (u64)input, (u64)input2, flags); \
})
#define guest_execute_fastop_cl(FEP, insn, __shift, __output, __flags) \
({ \
__asm__ __volatile__(fastop(FEP insn " %%cl, %[output]") \
: [output]"+r"(__output), flags_constraint(__flags) \
: "c"(__shift), bt_constraint(__output) \
: "cc", "memory"); \
})
#define guest_test_fastop_cl(insn, type_t, __val1, __val2) \
({ \
type_t output = __val2, ex_output = __val2, input = __val2; \
u8 shift = __val1; \
u64 flags, ex_flags; \
\
guest_execute_fastop_cl("", insn, shift, ex_output, ex_flags); \
guest_execute_fastop_cl(KVM_FEP, insn, shift, output, flags); \
\
__GUEST_ASSERT(output == ex_output, \
"Wanted 0x%lx for '%s 0x%x, 0x%lx', got 0x%lx", \
(u64)ex_output, insn, shift, (u64)input, \
(u64)output); \
__GUEST_ASSERT(flags == ex_flags, \
Annotation
- Immediate include surface: `test_util.h`, `kvm_util.h`, `processor.h`.
- Detected declarations: `function guest_code`, `function main`.
- 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.