arch/riscv/kernel/traps_misaligned.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/traps_misaligned.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/traps_misaligned.c- Extension
.c- Size
- 15865 bytes
- Lines
- 649
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/init.hlinux/mm.hlinux/module.hlinux/perf_event.hlinux/irq.hlinux/stringify.hasm/processor.hasm/ptrace.hasm/csr.hasm/entry-common.hasm/hwprobe.hasm/cpufeature.hasm/sbi.hasm/vector.hasm/insn.h
Detected Declarations
function set_f32_rdfunction set_f64_rdfunction get_f64_rsfunction get_f64_rsfunction get_f32_rsfunction set_f32_rdfunction get_f32_rsfunction get_insnfunction handle_vector_misaligned_loadfunction handle_vector_misaligned_loadfunction handle_scalar_misaligned_loadfunction handle_scalar_misaligned_storefunction handle_misaligned_loadfunction handle_misaligned_storefunction check_vector_unaligned_access_emulatedfunction check_vector_unaligned_access_emulated_all_cpusfunction check_vector_unaligned_access_emulated_all_cpusfunction all_cpus_unaligned_scalar_access_emulatedfunction check_unaligned_access_emulatedfunction cpu_online_check_unaligned_access_emulatedfunction check_unaligned_access_emulated_all_cpusfunction unaligned_ctl_availablefunction check_unaligned_access_emulated_all_cpusfunction cpu_online_check_unaligned_access_emulatedfunction cpu_online_sbi_unaligned_setupfunction unaligned_access_initfunction check_unaligned_access_emulatedfunction cpu_online_unaligned_access_initfunction misaligned_traps_can_delegateexport misaligned_traps_can_delegate
Annotated Snippet
static void set_f64_rd(unsigned long insn, struct pt_regs *regs, u64 val) {}
static unsigned long get_f64_rs(unsigned long insn, u8 fp_reg_offset,
struct pt_regs *regs)
{
return 0;
}
static unsigned long get_f32_rs(unsigned long insn, u8 fp_reg_offset,
struct pt_regs *regs)
{
return 0;
}
#endif
#define GET_F64_RS2(insn, regs) (get_f64_rs(insn, 20, regs))
#define GET_F64_RS2C(insn, regs) (get_f64_rs(insn, 2, regs))
#define GET_F64_RS2S(insn, regs) (get_f64_rs(RVC_RS2S(insn), 0, regs))
#define GET_F32_RS2(insn, regs) (get_f32_rs(insn, 20, regs))
#define GET_F32_RS2C(insn, regs) (get_f32_rs(insn, 2, regs))
#define GET_F32_RS2S(insn, regs) (get_f32_rs(RVC_RS2S(insn), 0, regs))
#define __read_insn(regs, insn, insn_addr, type) \
({ \
int __ret; \
\
if (user_mode(regs)) { \
__ret = get_user(insn, (type __user *) insn_addr); \
} else { \
insn = *(type *)insn_addr; \
__ret = 0; \
} \
\
__ret; \
})
static inline int get_insn(struct pt_regs *regs, ulong epc, ulong *r_insn)
{
ulong insn = 0;
if (epc & 0x2) {
ulong tmp = 0;
if (__read_insn(regs, insn, epc, u16))
return -EFAULT;
/* __get_user() uses regular "lw" which sign extend the loaded
* value make sure to clear higher order bits in case we "or" it
* below with the upper 16 bits half.
*/
insn &= GENMASK(15, 0);
if ((insn & __INSN_LENGTH_MASK) != __INSN_LENGTH_32) {
*r_insn = insn;
return 0;
}
epc += sizeof(u16);
if (__read_insn(regs, tmp, epc, u16))
return -EFAULT;
*r_insn = (tmp << 16) | insn;
return 0;
} else {
if (__read_insn(regs, insn, epc, u32))
return -EFAULT;
if ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) {
*r_insn = insn;
return 0;
}
insn &= GENMASK(15, 0);
*r_insn = insn;
return 0;
}
}
union reg_data {
u8 data_bytes[8];
ulong data_ulong;
u64 data_u64;
};
/* sysctl hooks */
int unaligned_enabled __read_mostly = 1; /* Enabled by default */
#ifdef CONFIG_RISCV_VECTOR_MISALIGNED
static int handle_vector_misaligned_load(struct pt_regs *regs)
{
unsigned long epc = regs->epc;
unsigned long insn;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/mm.h`, `linux/module.h`, `linux/perf_event.h`, `linux/irq.h`, `linux/stringify.h`, `asm/processor.h`.
- Detected declarations: `function set_f32_rd`, `function set_f64_rd`, `function get_f64_rs`, `function get_f64_rs`, `function get_f32_rs`, `function set_f32_rd`, `function get_f32_rs`, `function get_insn`, `function handle_vector_misaligned_load`, `function handle_vector_misaligned_load`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: integration 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.