arch/x86/include/asm/msr.h
Source file repositories/reference/linux-study-clean/arch/x86/include/asm/msr.h
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/include/asm/msr.h- Extension
.h- Size
- 7994 bytes
- Lines
- 307
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
msr-index.hasm/asm.hasm/errno.hasm/cpumask.huapi/asm/msr.hasm/shared/msr.hlinux/types.hlinux/percpu.hasm/atomic.hlinux/tracepoint-defs.hasm/paravirt.hlinux/errno.h
Detected Declarations
struct msr_infostruct msr_regs_infostruct saved_msrstruct saved_msrsfunction do_trace_write_msrfunction __wrmsrqfunction native_rdmsrqfunction native_read_msrfunction native_read_msr_safefunction native_write_msrfunction native_write_msr_safefunction native_read_pmcfunction wrmsrfunction wrmsrqfunction wrmsrq_safefunction rdmsrq_safefunction rdpmcfunction wrmsrnsfunction wrmsrq_safefunction rdmsrq_on_cpufunction wrmsrq_on_cpufunction rdmsr_on_cpusfunction wrmsr_on_cpusfunction rdmsrq_safe_on_cpufunction wrmsrq_safe_on_cpufunction rdmsr_safe_regs_on_cpufunction wrmsr_safe_regs_on_cpu
Annotated Snippet
struct msr_info {
u32 msr_no;
struct msr reg;
struct msr __percpu *msrs;
int err;
};
struct msr_regs_info {
u32 *regs;
int err;
};
struct saved_msr {
bool valid;
struct msr_info info;
};
struct saved_msrs {
unsigned int num;
struct saved_msr *array;
};
/*
* Be very careful with includes. This header is prone to include loops.
*/
#include <asm/atomic.h>
#include <linux/tracepoint-defs.h>
#ifdef CONFIG_TRACEPOINTS
DECLARE_TRACEPOINT(read_msr);
DECLARE_TRACEPOINT(write_msr);
DECLARE_TRACEPOINT(rdpmc);
extern void do_trace_write_msr(u32 msr, u64 val, int failed);
extern void do_trace_read_msr(u32 msr, u64 val, int failed);
extern void do_trace_rdpmc(u32 msr, u64 val, int failed);
#else
static inline void do_trace_write_msr(u32 msr, u64 val, int failed) {}
static inline void do_trace_read_msr(u32 msr, u64 val, int failed) {}
static inline void do_trace_rdpmc(u32 msr, u64 val, int failed) {}
#endif
/*
* __rdmsr() and __wrmsr() are the two primitives which are the bare minimum MSR
* accessors and should not have any tracing or other functionality piggybacking
* on them - those are *purely* for accessing MSRs and nothing more. So don't even
* think of extending them - you will be slapped with a stinking trout or a frozen
* shark will reach you, wherever you are! You've been warned.
*/
static __always_inline u64 __rdmsr(u32 msr)
{
EAX_EDX_DECLARE_ARGS(val, low, high);
asm volatile("1: rdmsr\n"
"2:\n"
_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_RDMSR)
: EAX_EDX_RET(val, low, high) : "c" (msr));
return EAX_EDX_VAL(val, low, high);
}
static __always_inline void __wrmsrq(u32 msr, u64 val)
{
asm volatile("1: wrmsr\n"
"2:\n"
_ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_WRMSR)
: : "c" (msr), "a" ((u32)val), "d" ((u32)(val >> 32)) : "memory");
}
#define native_rdmsr(msr, val1, val2) \
do { \
u64 __val = __rdmsr((msr)); \
(void)((val1) = (u32)__val); \
(void)((val2) = (u32)(__val >> 32)); \
} while (0)
static __always_inline u64 native_rdmsrq(u32 msr)
{
return __rdmsr(msr);
}
#define native_wrmsr(msr, low, high) \
__wrmsrq((msr), (u64)(high) << 32 | (low))
#define native_wrmsrq(msr, val) \
__wrmsrq((msr), (val))
static inline u64 native_read_msr(u32 msr)
{
u64 val;
Annotation
- Immediate include surface: `msr-index.h`, `asm/asm.h`, `asm/errno.h`, `asm/cpumask.h`, `uapi/asm/msr.h`, `asm/shared/msr.h`, `linux/types.h`, `linux/percpu.h`.
- Detected declarations: `struct msr_info`, `struct msr_regs_info`, `struct saved_msr`, `struct saved_msrs`, `function do_trace_write_msr`, `function __wrmsrq`, `function native_rdmsrq`, `function native_read_msr`, `function native_read_msr_safe`, `function native_write_msr`.
- Atlas domain: Architecture Layer / arch/x86.
- 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.