tools/testing/selftests/kvm/x86/xapic_ipi_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/xapic_ipi_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/xapic_ipi_test.c- Extension
.c- Size
- 14331 bytes
- Lines
- 501
- 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
getopt.hpthread.hinttypes.hstring.htime.hkvm_util.hnumaif.hprocessor.htest_util.hvmx.h
Detected Declarations
struct test_data_pagestruct thread_paramsfunction verify_apic_base_addrfunction halter_guest_codefunction guest_ipi_handlerfunction sender_guest_codefunction cancel_join_vcpu_threadfunction do_migrationsfunction get_cmdline_argsfunction main
Annotated Snippet
struct test_data_page {
u32 halter_apic_id;
volatile u64 hlt_count;
volatile u64 wake_count;
u64 ipis_sent;
u64 migrations_attempted;
u64 migrations_completed;
u32 icr;
u32 icr2;
u32 halter_tpr;
u32 halter_ppr;
/*
* Record local version register as a cross-check that APIC access
* worked. Value should match what KVM reports (APIC_VERSION in
* arch/x86/kvm/lapic.c). If test is failing, check that values match
* to determine whether APIC access exits are working.
*/
u32 halter_lvr;
};
struct thread_params {
struct test_data_page *data;
struct kvm_vcpu *vcpu;
u64 *pipis_rcvd; /* host address of ipis_rcvd global */
};
void verify_apic_base_addr(void)
{
u64 msr = rdmsr(MSR_IA32_APICBASE);
u64 base = GET_APIC_BASE(msr);
GUEST_ASSERT(base == APIC_DEFAULT_GPA);
}
static void halter_guest_code(struct test_data_page *data)
{
verify_apic_base_addr();
xapic_enable();
data->halter_apic_id = GET_APIC_ID_FIELD(xapic_read_reg(APIC_ID));
data->halter_lvr = xapic_read_reg(APIC_LVR);
/*
* Loop forever HLTing and recording halts & wakes. Disable interrupts
* each time around to minimize window between signaling the pending
* halt to the sender vCPU and executing the halt. No need to disable on
* first run as this vCPU executes first and the host waits for it to
* signal going into first halt before starting the sender vCPU. Record
* TPR and PPR for diagnostic purposes in case the test fails.
*/
for (;;) {
data->halter_tpr = xapic_read_reg(APIC_TASKPRI);
data->halter_ppr = xapic_read_reg(APIC_PROCPRI);
data->hlt_count++;
safe_halt();
cli();
data->wake_count++;
}
}
/*
* Runs on halter vCPU when IPI arrives. Write an arbitrary non-zero value to
* enable diagnosing errant writes to the APIC access address backing page in
* case of test failure.
*/
static void guest_ipi_handler(struct ex_regs *regs)
{
ipis_rcvd++;
xapic_write_reg(APIC_EOI, 77);
}
static void sender_guest_code(struct test_data_page *data)
{
u64 last_wake_count;
u64 last_hlt_count;
u64 last_ipis_rcvd_count;
u32 icr_val;
u32 icr2_val;
u64 tsc_start;
verify_apic_base_addr();
xapic_enable();
/*
* Init interrupt command register for sending IPIs
*
* Delivery mode=fixed, per SDM:
* "Delivers the interrupt specified in the vector field to the target
* processor."
Annotation
- Immediate include surface: `getopt.h`, `pthread.h`, `inttypes.h`, `string.h`, `time.h`, `kvm_util.h`, `numaif.h`, `processor.h`.
- Detected declarations: `struct test_data_page`, `struct thread_params`, `function verify_apic_base_addr`, `function halter_guest_code`, `function guest_ipi_handler`, `function sender_guest_code`, `function cancel_join_vcpu_thread`, `function do_migrations`, `function get_cmdline_args`, `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.