tools/testing/selftests/kvm/lib/x86/processor.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/lib/x86/processor.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/kvm/lib/x86/processor.c
Extension
.c
Size
39495 bytes
Lines
1472
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2018, Google LLC.
 */

#include "linux/bitmap.h"
#include "test_util.h"
#include "kvm_util.h"
#include "pmu.h"
#include "processor.h"
#include "smm.h"
#include "svm_util.h"
#include "sev.h"
#include "vmx.h"

#ifndef NUM_INTERRUPTS
#define NUM_INTERRUPTS 256
#endif

#define KERNEL_CS	0x8
#define KERNEL_DS	0x10
#define KERNEL_TSS	0x18

gva_t exception_handlers;
bool host_cpu_is_amd;
bool host_cpu_is_intel;
bool host_cpu_is_hygon;
bool host_cpu_is_amd_compatible;
bool is_forced_emulation_enabled;
u64 guest_tsc_khz;

const char *ex_str(int vector)
{
	switch (vector) {
#define VEC_STR(v) case v##_VECTOR: return "#" #v
	case DE_VECTOR: return "no exception";
	case KVM_MAGIC_DE_VECTOR: return "#DE";
	VEC_STR(DB);
	VEC_STR(NMI);
	VEC_STR(BP);
	VEC_STR(OF);
	VEC_STR(BR);
	VEC_STR(UD);
	VEC_STR(NM);
	VEC_STR(DF);
	VEC_STR(TS);
	VEC_STR(NP);
	VEC_STR(SS);
	VEC_STR(GP);
	VEC_STR(PF);
	VEC_STR(MF);
	VEC_STR(AC);
	VEC_STR(MC);
	VEC_STR(XM);
	VEC_STR(VE);
	VEC_STR(CP);
	VEC_STR(HV);
	VEC_STR(VC);
	VEC_STR(SX);
	default: return "#??";
#undef VEC_STR
	}
}

static void regs_dump(FILE *stream, struct kvm_regs *regs, u8 indent)
{
	fprintf(stream, "%*srax: 0x%.16llx rbx: 0x%.16llx "
		"rcx: 0x%.16llx rdx: 0x%.16llx\n",
		indent, "",
		regs->rax, regs->rbx, regs->rcx, regs->rdx);
	fprintf(stream, "%*srsi: 0x%.16llx rdi: 0x%.16llx "
		"rsp: 0x%.16llx rbp: 0x%.16llx\n",
		indent, "",
		regs->rsi, regs->rdi, regs->rsp, regs->rbp);
	fprintf(stream, "%*sr8:  0x%.16llx r9:  0x%.16llx "
		"r10: 0x%.16llx r11: 0x%.16llx\n",
		indent, "",
		regs->r8, regs->r9, regs->r10, regs->r11);
	fprintf(stream, "%*sr12: 0x%.16llx r13: 0x%.16llx "
		"r14: 0x%.16llx r15: 0x%.16llx\n",
		indent, "",
		regs->r12, regs->r13, regs->r14, regs->r15);
	fprintf(stream, "%*srip: 0x%.16llx rfl: 0x%.16llx\n",
		indent, "",
		regs->rip, regs->rflags);
}

static void segment_dump(FILE *stream, struct kvm_segment *segment,
			 u8 indent)
{

Annotation

Implementation Notes