arch/riscv/kvm/vcpu_pmu.c
Source file repositories/reference/linux-study-clean/arch/riscv/kvm/vcpu_pmu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kvm/vcpu_pmu.c- Extension
.c- Size
- 25799 bytes
- Lines
- 935
- 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.
- 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/bitops.hlinux/errno.hlinux/err.hlinux/kvm_host.hlinux/nospec.hlinux/perf/riscv_pmu.hasm/csr.hasm/kvm_isa.hasm/kvm_vcpu_sbi.hasm/kvm_vcpu_pmu.hasm/sbi.h
Detected Declarations
function kvm_pmu_get_sample_periodfunction kvm_pmu_get_perf_event_typefunction kvm_pmu_is_fw_eventfunction kvm_pmu_release_perf_eventfunction kvm_pmu_get_perf_event_hw_configfunction kvm_pmu_get_perf_event_cache_configfunction kvm_pmu_get_perf_event_configfunction kvm_pmu_get_fixed_pmc_indexfunction kvm_pmu_get_programmable_pmc_indexfunction for_each_set_bitfunction pmu_get_pmc_indexfunction pmu_fw_ctr_read_hifunction pmu_ctr_readfunction kvm_pmu_validate_counter_maskfunction kvm_riscv_pmu_overflowfunction kvm_pmu_create_perf_eventfunction kvm_riscv_vcpu_pmu_incr_fwfunction kvm_riscv_vcpu_pmu_read_hpmfunction kvm_pmu_clear_snapshot_areafunction kvm_riscv_vcpu_pmu_snapshot_set_shmemfunction kvm_riscv_vcpu_pmu_event_infofunction kvm_riscv_vcpu_pmu_num_ctrsfunction kvm_riscv_vcpu_pmu_ctr_infofunction kvm_riscv_vcpu_pmu_ctr_startfunction kvm_riscv_vcpu_pmu_ctr_stopfunction kvm_riscv_vcpu_pmu_ctr_cfg_matchfunction kvm_riscv_vcpu_pmu_fw_ctr_read_hifunction kvm_riscv_vcpu_pmu_fw_ctr_readfunction kvm_riscv_vcpu_pmu_initfunction kvm_riscv_vcpu_pmu_deinitfunction for_each_set_bitfunction kvm_riscv_vcpu_pmu_reset
Annotated Snippet
if (csr_num == CSR_CYCLE || csr_num == CSR_INSTRET) {
*val = 0;
return ret;
} else {
return KVM_INSN_ILLEGAL_TRAP;
}
}
/* The counter CSR are read only. Thus, any write should result in illegal traps */
if (wr_mask)
return KVM_INSN_ILLEGAL_TRAP;
cidx = csr_num - CSR_CYCLE;
if (pmu_ctr_read(vcpu, cidx, val) < 0)
return KVM_INSN_ILLEGAL_TRAP;
return ret;
}
static void kvm_pmu_clear_snapshot_area(struct kvm_vcpu *vcpu)
{
struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
kfree(kvpmu->sdata);
kvpmu->sdata = NULL;
kvpmu->snapshot_addr = INVALID_GPA;
}
int kvm_riscv_vcpu_pmu_snapshot_set_shmem(struct kvm_vcpu *vcpu, unsigned long saddr_low,
unsigned long saddr_high, unsigned long flags,
struct kvm_vcpu_sbi_return *retdata)
{
struct kvm_pmu *kvpmu = vcpu_to_pmu(vcpu);
int snapshot_area_size = sizeof(struct riscv_pmu_snapshot_data);
int sbiret = 0;
gpa_t saddr;
if (!kvpmu || flags) {
sbiret = SBI_ERR_INVALID_PARAM;
goto out;
}
if (saddr_low == SBI_SHMEM_DISABLE && saddr_high == SBI_SHMEM_DISABLE) {
kvm_pmu_clear_snapshot_area(vcpu);
return 0;
}
saddr = saddr_low;
if (saddr_high != 0) {
if (IS_ENABLED(CONFIG_32BIT)) {
saddr |= ((gpa_t)saddr_high << 32);
} else {
sbiret = SBI_ERR_INVALID_ADDRESS;
goto out;
}
}
kvpmu->sdata = kzalloc(snapshot_area_size, GFP_ATOMIC);
if (!kvpmu->sdata) {
sbiret = SBI_ERR_FAILURE;
goto out;
}
/* No need to check writable slot explicitly as kvm_vcpu_write_guest does it internally */
if (kvm_vcpu_write_guest(vcpu, saddr, kvpmu->sdata, snapshot_area_size)) {
kfree(kvpmu->sdata);
kvpmu->sdata = NULL;
sbiret = SBI_ERR_INVALID_ADDRESS;
goto out;
}
kvpmu->snapshot_addr = saddr;
out:
retdata->err_val = sbiret;
return 0;
}
int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low,
unsigned long saddr_high, unsigned long num_events,
unsigned long flags, struct kvm_vcpu_sbi_return *retdata)
{
struct riscv_pmu_event_info *einfo = NULL;
int shmem_size = num_events * sizeof(*einfo);
gpa_t shmem;
u32 eidx, etype;
u64 econfig;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/errno.h`, `linux/err.h`, `linux/kvm_host.h`, `linux/nospec.h`, `linux/perf/riscv_pmu.h`, `asm/csr.h`, `asm/kvm_isa.h`.
- Detected declarations: `function kvm_pmu_get_sample_period`, `function kvm_pmu_get_perf_event_type`, `function kvm_pmu_is_fw_event`, `function kvm_pmu_release_perf_event`, `function kvm_pmu_get_perf_event_hw_config`, `function kvm_pmu_get_perf_event_cache_config`, `function kvm_pmu_get_perf_event_config`, `function kvm_pmu_get_fixed_pmc_index`, `function kvm_pmu_get_programmable_pmc_index`, `function for_each_set_bit`.
- 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.