arch/riscv/kvm/vcpu_sbi_system.c
Source file repositories/reference/linux-study-clean/arch/riscv/kvm/vcpu_sbi_system.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kvm/vcpu_sbi_system.c- Extension
.c- Size
- 2039 bytes
- Lines
- 79
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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
linux/kvm_host.hlinux/wordpart.hasm/kvm_vcpu_sbi.hasm/sbi.h
Detected Declarations
function Copyrightfunction kvm_for_each_vcpu
Annotated Snippet
if (lower_32_bits(cp->a0) != SBI_SUSP_SLEEP_TYPE_SUSPEND_TO_RAM) {
retdata->err_val = SBI_ERR_INVALID_PARAM;
return 0;
}
if (!(cp->sstatus & SR_SPP)) {
retdata->err_val = SBI_ERR_FAILURE;
return 0;
}
hva = kvm_vcpu_gfn_to_hva_prot(vcpu, cp->a1 >> PAGE_SHIFT, NULL);
if (kvm_is_error_hva(hva)) {
retdata->err_val = SBI_ERR_INVALID_ADDRESS;
return 0;
}
/*
* Check that all other vCPUs are stopped before entering
* system suspend.
*
* There is a known TOCTOU race here: a concurrent HSM
* HART_START on another vCPU can start a vCPU after it
* has already passed this check, violating the invariant.
*
* We do not fix this because:
* 1. Triggering the race requires a pathological guest.
* 2. Only guest state is at risk, not host integrity.
* 3. Userspace can double-check vCPU states before
* proceeding with suspend.
*/
kvm_for_each_vcpu(i, tmp, vcpu->kvm) {
if (tmp == vcpu)
continue;
if (!kvm_riscv_vcpu_stopped(tmp)) {
retdata->err_val = SBI_ERR_DENIED;
return 0;
}
}
kvm_riscv_vcpu_sbi_request_reset(vcpu, cp->a1, cp->a2);
/* userspace provides the suspend implementation */
return kvm_riscv_vcpu_sbi_forward_handler(vcpu, run, retdata);
default:
retdata->err_val = SBI_ERR_NOT_SUPPORTED;
break;
}
return 0;
}
const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_susp = {
.extid_start = SBI_EXT_SUSP,
.extid_end = SBI_EXT_SUSP,
.default_disabled = true,
.handler = kvm_sbi_ext_susp_handler,
};
Annotation
- Immediate include surface: `linux/kvm_host.h`, `linux/wordpart.h`, `asm/kvm_vcpu_sbi.h`, `asm/sbi.h`.
- Detected declarations: `function Copyright`, `function kvm_for_each_vcpu`.
- Atlas domain: Architecture Layer / arch/riscv.
- 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.