arch/x86/coco/sev/vc-shared.c
Source file repositories/reference/linux-study-clean/arch/x86/coco/sev/vc-shared.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/coco/sev/vc-shared.c- Extension
.c- Size
- 14879 bytes
- Lines
- 657
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct cpuid_ctxfunction vc_check_opcode_bytesfunction vc_decoding_neededfunction vc_init_em_ctxtfunction vc_finish_insnfunction vc_insn_string_checkfunction vc_insn_string_readfunction vc_insn_string_writefunction vc_ioio_exitinfofunction vc_handle_ioiofunction verify_exception_infofunction sev_es_ghcb_hv_callfunction __sev_cpuid_hv_ghcbfunction snp_cpuid_hv_ghcbfunction vc_handle_cpuid_snpfunction vc_handle_cpuidfunction vc_handle_rdtscfunction snp_register_ghcb_earlyfunction sev_es_check_cpu_featuresfunction sev_es_negotiate_protocol
Annotated Snippet
struct cpuid_ctx {
struct ghcb *ghcb;
struct es_em_ctxt *ctxt;
};
static void snp_cpuid_hv_ghcb(void *p, struct cpuid_leaf *leaf)
{
struct cpuid_ctx *ctx = p;
if (__sev_cpuid_hv_ghcb(ctx->ghcb, ctx->ctxt, leaf))
sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV);
}
static int vc_handle_cpuid_snp(struct ghcb *ghcb, struct es_em_ctxt *ctxt)
{
struct cpuid_ctx ctx = { ghcb, ctxt };
struct pt_regs *regs = ctxt->regs;
struct cpuid_leaf leaf;
int ret;
leaf.fn = regs->ax;
leaf.subfn = regs->cx;
ret = snp_cpuid(snp_cpuid_hv_ghcb, &ctx, &leaf);
if (!ret) {
regs->ax = leaf.eax;
regs->bx = leaf.ebx;
regs->cx = leaf.ecx;
regs->dx = leaf.edx;
}
return ret;
}
static enum es_result vc_handle_cpuid(struct ghcb *ghcb,
struct es_em_ctxt *ctxt)
{
struct pt_regs *regs = ctxt->regs;
u32 cr4 = native_read_cr4();
enum es_result ret;
int snp_cpuid_ret;
snp_cpuid_ret = vc_handle_cpuid_snp(ghcb, ctxt);
if (!snp_cpuid_ret)
return ES_OK;
if (snp_cpuid_ret != -EOPNOTSUPP)
return ES_VMM_ERROR;
ghcb_set_rax(ghcb, regs->ax);
ghcb_set_rcx(ghcb, regs->cx);
if (cr4 & X86_CR4_OSXSAVE)
/* Safe to read xcr0 */
ghcb_set_xcr0(ghcb, xgetbv(XCR_XFEATURE_ENABLED_MASK));
else
/* xgetbv will cause #GP - use reset value for xcr0 */
ghcb_set_xcr0(ghcb, 1);
if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx == 1) {
struct msr m;
raw_rdmsr(MSR_IA32_XSS, &m);
ghcb_set_xss(ghcb, m.q);
}
ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0);
if (ret != ES_OK)
return ret;
if (!(ghcb_rax_is_valid(ghcb) &&
ghcb_rbx_is_valid(ghcb) &&
ghcb_rcx_is_valid(ghcb) &&
ghcb_rdx_is_valid(ghcb)))
return ES_VMM_ERROR;
regs->ax = ghcb->save.rax;
regs->bx = ghcb->save.rbx;
regs->cx = ghcb->save.rcx;
regs->dx = ghcb->save.rdx;
return ES_OK;
}
static enum es_result vc_handle_rdtsc(struct ghcb *ghcb,
struct es_em_ctxt *ctxt,
unsigned long exit_code)
{
bool rdtscp = (exit_code == SVM_EXIT_RDTSCP);
enum es_result ret;
/*
Annotation
- Detected declarations: `struct cpuid_ctx`, `function vc_check_opcode_bytes`, `function vc_decoding_needed`, `function vc_init_em_ctxt`, `function vc_finish_insn`, `function vc_insn_string_check`, `function vc_insn_string_read`, `function vc_insn_string_write`, `function vc_ioio_exitinfo`, `function vc_handle_ioio`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.