arch/x86/coco/sev/vc-handle.c
Source file repositories/reference/linux-study-clean/arch/x86/coco/sev/vc-handle.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/coco/sev/vc-handle.c- Extension
.c- Size
- 26820 bytes
- Lines
- 1090
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sched/debug.hlinux/cc_platform.hlinux/printk.hlinux/mm_types.hlinux/kernel.hlinux/mm.hlinux/io.hlinux/psp-sev.hlinux/efi.huapi/linux/sev-guest.hasm/init.hasm/stacktrace.hasm/sev.hasm/insn-eval.hasm/fpu/xcr.hasm/processor.hasm/setup.hasm/traps.hasm/svm.hasm/smp.hasm/cpu.hasm/apic.hasm/cpuid/api.hinternal.hvc-shared.c
Detected Declarations
function Copyrightfunction vc_ioio_checkfunction vc_forward_exceptionfunction vc_fetch_insn_kernelfunction __vc_decode_user_insnfunction __vc_decode_kern_insnfunction vc_decode_insnfunction vc_write_memfunction __put_userfunction vc_read_memfunction __get_userfunction __vc_handle_msr_caafunction __vc_handle_secure_tsc_msrsfunction __vc_handle_msrfunction vc_handle_msrfunction vc_early_forward_exceptionfunction vc_do_mmiofunction memcpy_fromiofunction vc_handle_mmiofunction vc_handle_dr7_writefunction vc_handle_dr7_readfunction vc_handle_wbinvdfunction vc_handle_rdpmcfunction vc_handle_monitorfunction vc_handle_mwaitfunction vc_handle_vmmcallfunction vc_handle_trap_acfunction vc_handle_exitcodefunction is_vc2_stackfunction vc_from_invalid_contextfunction vc_raw_handle_exceptionfunction vc_is_dbfunction kernel_exc_vmm_communicationfunction user_exc_vmm_communicationfunction handle_vc_boot_ghcb
Annotated Snippet
if (bytes == 1) {
u8 *val = (u8 *)ghcb->shared_buffer;
sign_byte = (*val & 0x80) ? 0xff : 0x00;
} else {
u16 *val = (u16 *)ghcb->shared_buffer;
sign_byte = (*val & 0x8000) ? 0xff : 0x00;
}
/* Sign extend based on operand size */
memset(reg_data, sign_byte, insn->opnd_bytes);
memcpy(reg_data, ghcb->shared_buffer, bytes);
break;
case INSN_MMIO_MOVS:
ret = vc_handle_mmio_movs(ctxt, bytes);
break;
default:
ret = ES_UNSUPPORTED;
break;
}
return ret;
}
static enum es_result vc_handle_dr7_write(struct ghcb *ghcb,
struct es_em_ctxt *ctxt)
{
struct sev_es_runtime_data *data = this_cpu_read(runtime_data);
long val, *reg = vc_insn_get_rm(ctxt);
enum es_result ret;
if (sev_status & MSR_AMD64_SNP_DEBUG_SWAP)
return ES_VMM_ERROR;
if (!reg)
return ES_DECODE_FAILED;
val = *reg;
/* Upper 32 bits must be written as zeroes */
if (val >> 32) {
ctxt->fi.vector = X86_TRAP_GP;
ctxt->fi.error_code = 0;
return ES_EXCEPTION;
}
/* Clear out other reserved bits and set bit 10 */
val = (val & 0xffff23ffL) | BIT(10);
/* Early non-zero writes to DR7 are not supported */
if (!data && (val & ~DR7_RESET_VALUE))
return ES_UNSUPPORTED;
/* Using a value of 0 for ExitInfo1 means RAX holds the value */
ghcb_set_rax(ghcb, val);
ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WRITE_DR7, 0, 0);
if (ret != ES_OK)
return ret;
if (data)
data->dr7 = val;
return ES_OK;
}
static enum es_result vc_handle_dr7_read(struct ghcb *ghcb,
struct es_em_ctxt *ctxt)
{
struct sev_es_runtime_data *data = this_cpu_read(runtime_data);
long *reg = vc_insn_get_rm(ctxt);
if (sev_status & MSR_AMD64_SNP_DEBUG_SWAP)
return ES_VMM_ERROR;
if (!reg)
return ES_DECODE_FAILED;
if (data)
*reg = data->dr7;
else
*reg = DR7_RESET_VALUE;
return ES_OK;
}
static enum es_result vc_handle_wbinvd(struct ghcb *ghcb,
struct es_em_ctxt *ctxt)
{
return sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_WBINVD, 0, 0);
Annotation
- Immediate include surface: `linux/sched/debug.h`, `linux/cc_platform.h`, `linux/printk.h`, `linux/mm_types.h`, `linux/kernel.h`, `linux/mm.h`, `linux/io.h`, `linux/psp-sev.h`.
- Detected declarations: `function Copyright`, `function vc_ioio_check`, `function vc_forward_exception`, `function vc_fetch_insn_kernel`, `function __vc_decode_user_insn`, `function __vc_decode_kern_insn`, `function vc_decode_insn`, `function vc_write_mem`, `function __put_user`, `function vc_read_mem`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.