tools/testing/selftests/kvm/arm64/external_aborts.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/arm64/external_aborts.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/arm64/external_aborts.c- Extension
.c- Size
- 9975 bytes
- Lines
- 416
- 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
processor.htest_util.h
Detected Declarations
function expect_sea_handlerfunction unexpected_dabt_handlerfunction vcpu_inject_seafunction vcpu_has_rasfunction guest_has_rasfunction vcpu_inject_serrorfunction __vcpu_run_expectfunction vcpu_run_expect_donefunction vcpu_run_expect_syncfunction test_mmio_abort_guestfunction test_mmio_abortfunction test_mmio_nisv_guestfunction test_mmio_nisvfunction test_mmio_nisv_abortfunction unexpected_serror_handlerfunction test_serror_masked_guestfunction test_serror_maskedfunction expect_serror_handlerfunction test_serror_guestfunction test_serrorfunction expect_sea_s1ptw_handlerfunction test_s1ptw_abort_guestfunction test_s1ptw_abortfunction test_serror_emulated_guestfunction test_serror_emulatedfunction test_mmio_ease_guestfunction test_mmio_easefunction test_serror_amo_guestfunction test_serror_amofunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* external_abort - Tests for userspace external abort injection
*
* Copyright (c) 2024 Google LLC
*/
#include "processor.h"
#include "test_util.h"
#define MMIO_ADDR 0x8000000ULL
#define EXPECTED_SERROR_ISS (ESR_ELx_ISV | 0x1d1ed)
static u64 expected_abort_pc;
static void expect_sea_handler(struct ex_regs *regs)
{
u64 esr = read_sysreg(esr_el1);
GUEST_ASSERT_EQ(regs->pc, expected_abort_pc);
GUEST_ASSERT_EQ(ESR_ELx_EC(esr), ESR_ELx_EC_DABT_CUR);
GUEST_ASSERT_EQ(esr & ESR_ELx_FSC_TYPE, ESR_ELx_FSC_EXTABT);
GUEST_DONE();
}
static void unexpected_dabt_handler(struct ex_regs *regs)
{
GUEST_FAIL("Unexpected data abort at PC: %lx\n", regs->pc);
}
static struct kvm_vm *vm_create_with_dabt_handler(struct kvm_vcpu **vcpu, void *guest_code,
handler_fn dabt_handler)
{
struct kvm_vm *vm = vm_create_with_one_vcpu(vcpu, guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(*vcpu);
vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT, ESR_ELx_EC_DABT_CUR, dabt_handler);
virt_map(vm, MMIO_ADDR, MMIO_ADDR, 1);
return vm;
}
static void vcpu_inject_sea(struct kvm_vcpu *vcpu)
{
struct kvm_vcpu_events events = {};
events.exception.ext_dabt_pending = true;
vcpu_events_set(vcpu, &events);
}
static bool vcpu_has_ras(struct kvm_vcpu *vcpu)
{
u64 pfr0 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1));
return SYS_FIELD_GET(ID_AA64PFR0_EL1, RAS, pfr0);
}
static bool guest_has_ras(void)
{
return SYS_FIELD_GET(ID_AA64PFR0_EL1, RAS, read_sysreg(id_aa64pfr0_el1));
}
static void vcpu_inject_serror(struct kvm_vcpu *vcpu)
{
struct kvm_vcpu_events events = {};
events.exception.serror_pending = true;
if (vcpu_has_ras(vcpu)) {
events.exception.serror_has_esr = true;
events.exception.serror_esr = EXPECTED_SERROR_ISS;
}
vcpu_events_set(vcpu, &events);
}
static void __vcpu_run_expect(struct kvm_vcpu *vcpu, unsigned int cmd)
{
struct ucall uc;
vcpu_run(vcpu);
switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
break;
default:
if (uc.cmd == cmd)
return;
Annotation
- Immediate include surface: `processor.h`, `test_util.h`.
- Detected declarations: `function expect_sea_handler`, `function unexpected_dabt_handler`, `function vcpu_inject_sea`, `function vcpu_has_ras`, `function guest_has_ras`, `function vcpu_inject_serror`, `function __vcpu_run_expect`, `function vcpu_run_expect_done`, `function vcpu_run_expect_sync`, `function test_mmio_abort_guest`.
- 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.