arch/arm64/kvm/guest.c
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/guest.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/guest.c- Extension
.c- Size
- 27084 bytes
- Lines
- 1082
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/errno.hlinux/err.hlinux/nospec.hlinux/kvm_host.hlinux/module.hlinux/stddef.hlinux/string.hlinux/vmalloc.hlinux/fs.hkvm/arm_hypercalls.hasm/cputype.hlinux/uaccess.hasm/fpsimd.hasm/kvm.hasm/kvm_emulate.hasm/kvm_nested.hasm/sigcontext.htrace.h
Detected Declarations
struct sve_state_reg_regionfunction core_reg_offset_is_vregfunction core_reg_offset_from_idfunction core_reg_size_from_offsetfunction get_core_regfunction set_core_regfunction get_sve_vlsfunction set_sve_vlsfunction sve_reg_to_regionfunction get_sve_regfunction set_sve_regfunction kvm_arch_vcpu_ioctl_get_regsfunction kvm_arch_vcpu_ioctl_set_regsfunction copy_core_reg_indicesfunction num_core_regsfunction num_sve_regsfunction copy_sve_reg_indicesfunction kvm_arm_num_regsfunction kvm_arm_copy_reg_indicesfunction kvm_arm_get_regfunction kvm_arm_set_regfunction kvm_arch_vcpu_ioctl_get_sregsfunction kvm_arch_vcpu_ioctl_set_sregsfunction __kvm_arm_vcpu_get_eventsfunction commit_pending_eventsfunction __kvm_arm_vcpu_set_eventsfunction kvm_target_cpufunction kvm_arch_vcpu_ioctl_get_fpufunction kvm_arch_vcpu_ioctl_set_fpufunction kvm_arch_vcpu_ioctl_translatefunction kvm_arch_vcpu_ioctl_set_guest_debugfunction kvm_arm_vcpu_arch_set_attrfunction kvm_arm_vcpu_arch_get_attrfunction kvm_arm_vcpu_arch_has_attrfunction kvm_vm_ioctl_mte_copy_tags
Annotated Snippet
struct sve_state_reg_region {
unsigned int koffset; /* offset into sve_state in kernel memory */
unsigned int klen; /* length in kernel memory */
unsigned int upad; /* extra trailing padding in user memory */
};
/*
* Validate SVE register ID and get sanitised bounds for user/kernel SVE
* register copy
*/
static int sve_reg_to_region(struct sve_state_reg_region *region,
struct kvm_vcpu *vcpu,
const struct kvm_one_reg *reg)
{
/* reg ID ranges for Z- registers */
const u64 zreg_id_min = KVM_REG_ARM64_SVE_ZREG(0, 0);
const u64 zreg_id_max = KVM_REG_ARM64_SVE_ZREG(SVE_NUM_ZREGS - 1,
SVE_NUM_SLICES - 1);
/* reg ID ranges for P- registers and FFR (which are contiguous) */
const u64 preg_id_min = KVM_REG_ARM64_SVE_PREG(0, 0);
const u64 preg_id_max = KVM_REG_ARM64_SVE_FFR(SVE_NUM_SLICES - 1);
unsigned int vq;
unsigned int reg_num;
unsigned int reqoffset, reqlen; /* User-requested offset and length */
unsigned int maxlen; /* Maximum permitted length */
size_t sve_state_size;
const u64 last_preg_id = KVM_REG_ARM64_SVE_PREG(SVE_NUM_PREGS - 1,
SVE_NUM_SLICES - 1);
/* Verify that the P-regs and FFR really do have contiguous IDs: */
BUILD_BUG_ON(KVM_REG_ARM64_SVE_FFR(0) != last_preg_id + 1);
/* Verify that we match the UAPI header: */
BUILD_BUG_ON(SVE_NUM_SLICES != KVM_ARM64_SVE_MAX_SLICES);
reg_num = (reg->id & SVE_REG_ID_MASK) >> SVE_REG_ID_SHIFT;
if (reg->id >= zreg_id_min && reg->id <= zreg_id_max) {
if (!vcpu_has_sve(vcpu) || (reg->id & SVE_REG_SLICE_MASK) > 0)
return -ENOENT;
vq = vcpu_sve_max_vq(vcpu);
reqoffset = SVE_SIG_ZREG_OFFSET(vq, reg_num) -
SVE_SIG_REGS_OFFSET;
reqlen = KVM_SVE_ZREG_SIZE;
maxlen = SVE_SIG_ZREG_SIZE(vq);
} else if (reg->id >= preg_id_min && reg->id <= preg_id_max) {
if (!vcpu_has_sve(vcpu) || (reg->id & SVE_REG_SLICE_MASK) > 0)
return -ENOENT;
vq = vcpu_sve_max_vq(vcpu);
reqoffset = SVE_SIG_PREG_OFFSET(vq, reg_num) -
SVE_SIG_REGS_OFFSET;
reqlen = KVM_SVE_PREG_SIZE;
maxlen = SVE_SIG_PREG_SIZE(vq);
} else {
return -EINVAL;
}
sve_state_size = vcpu_sve_state_size(vcpu);
if (WARN_ON(!sve_state_size))
return -EINVAL;
region->koffset = array_index_nospec(reqoffset, sve_state_size);
region->klen = min(maxlen, reqlen);
region->upad = reqlen - region->klen;
return 0;
}
static int get_sve_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
{
int ret;
struct sve_state_reg_region region;
char __user *uptr = (char __user *)reg->addr;
/* Handle the KVM_REG_ARM64_SVE_VLS pseudo-reg as a special case: */
if (reg->id == KVM_REG_ARM64_SVE_VLS)
return get_sve_vls(vcpu, reg);
/* Try to interpret reg ID as an architectural SVE register... */
ret = sve_reg_to_region(®ion, vcpu, reg);
if (ret)
Annotation
- Immediate include surface: `linux/bits.h`, `linux/errno.h`, `linux/err.h`, `linux/nospec.h`, `linux/kvm_host.h`, `linux/module.h`, `linux/stddef.h`, `linux/string.h`.
- Detected declarations: `struct sve_state_reg_region`, `function core_reg_offset_is_vreg`, `function core_reg_offset_from_id`, `function core_reg_size_from_offset`, `function get_core_reg`, `function set_core_reg`, `function get_sve_vls`, `function set_sve_vls`, `function sve_reg_to_region`, `function get_sve_reg`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.