cregit-Linux how code gets into the kernel

Release 4.10 arch/x86/include/asm/msr.h

#ifndef _ASM_X86_MSR_H

#define _ASM_X86_MSR_H

#include "msr-index.h"

#ifndef __ASSEMBLY__

#include <asm/asm.h>
#include <asm/errno.h>
#include <asm/cpumask.h>
#include <uapi/asm/msr.h>


struct msr {
	union {
		struct {
			
u32 l;
			
u32 h;
		};
		
u64 q;
	};
};


struct msr_info {
	
u32 msr_no;
	
struct msr reg;
	
struct msr *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;
};

/*
 * both i386 and x86_64 returns 64-bit value in edx:eax, but gcc's "A"
 * constraint has different meanings. For i386, "A" means exactly
 * edx:eax, while for x86_64 it doesn't mean rdx:rax or edx:eax. Instead,
 * it means rax *or* rdx.
 */
#ifdef CONFIG_X86_64
/* Using 64-bit values saves one instruction clearing the high half of low */

#define DECLARE_ARGS(val, low, high)	unsigned long low, high

#define EAX_EDX_VAL(val, low, high)	((low) | (high) << 32)

#define EAX_EDX_RET(val, low, high)	"=a" (low), "=d" (high)
#else

#define DECLARE_ARGS(val, low, high)	unsigned long long val

#define EAX_EDX_VAL(val, low, high)	(val)

#define EAX_EDX_RET(val, low, high)	"=A" (val)
#endif

#ifdef CONFIG_TRACEPOINTS
/*
 * Be very careful with includes. This header is prone to include loops.
 */
#include <asm/atomic.h>
#include <linux/tracepoint-defs.h>

extern struct tracepoint __tracepoint_read_msr;
extern struct tracepoint __tracepoint_write_msr;
extern struct tracepoint __tracepoint_rdpmc;

#define msr_tracepoint_active(t) static_key_false(&(t).key)
extern void do_trace_write_msr(unsigned int msr, u64 val, int failed);
extern void do_trace_read_msr(unsigned int msr, u64 val, int failed);
extern void do_trace_rdpmc(unsigned int msr, u64 val, int failed);
#else

#define msr_tracepoint_active(t) false

static inline void do_trace_write_msr(unsigned int msr, u64 val, int failed) {}

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen1593.75%150.00%
borislav petkovborislav petkov16.25%150.00%
Total16100.00%2100.00%


static inline void do_trace_read_msr(unsigned int msr, u64 val, int failed) {}

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen1593.75%150.00%
borislav petkovborislav petkov16.25%150.00%
Total16100.00%2100.00%


static inline void do_trace_rdpmc(unsigned int msr, u64 val, int failed) {}

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen1593.75%150.00%
borislav petkovborislav petkov16.25%150.00%
Total16100.00%2100.00%

#endif
static inline unsigned long long native_read_msr(unsigned int msr) { DECLARE_ARGS(val, low, high); asm volatile("1: rdmsr\n" "2:\n" _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_rdmsr_unsafe) : EAX_EDX_RET(val, low, high) : "c" (msr)); if (msr_tracepoint_active(__tracepoint_read_msr)) do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), 0); return EAX_EDX_VAL(val, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen2339.66%125.00%
thomas gleixnerthomas gleixner1932.76%125.00%
glauber de oliveira costaglauber de oliveira costa1525.86%125.00%
andy lutomirskiandy lutomirski11.72%125.00%
Total58100.00%4100.00%


static inline unsigned long long native_read_msr_safe(unsigned int msr, int *err) { DECLARE_ARGS(val, low, high); asm volatile("2: rdmsr ; xor %[err],%[err]\n" "1:\n\t" ".section .fixup,\"ax\"\n\t" "3: mov %[fault],%[err]\n\t" "xorl %%eax, %%eax\n\t" "xorl %%edx, %%edx\n\t" "jmp 1b\n\t" ".previous\n\t" _ASM_EXTABLE(2b, 3b) : [err] "=r" (*err), EAX_EDX_RET(val, low, high) : "c" (msr), [fault] "i" (-EIO)); if (msr_tracepoint_active(__tracepoint_read_msr)) do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), *err); return EAX_EDX_VAL(val, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen2438.10%125.00%
thomas gleixnerthomas gleixner2336.51%125.00%
glauber de oliveira costaglauber de oliveira costa1523.81%125.00%
andy lutomirskiandy lutomirski11.59%125.00%
Total63100.00%4100.00%

/* Can be uninlined because referenced by paravirt */
static inline void notrace __native_write_msr_notrace(unsigned int msr, u32 low, u32 high) { asm volatile("1: wrmsr\n" "2:\n" _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wrmsr_unsafe) : : "c" (msr), "a"(low), "d" (high) : "memory"); }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner1257.14%120.00%
glauber de oliveira costaglauber de oliveira costa314.29%120.00%
borislav petkovborislav petkov314.29%120.00%
wanpeng liwanpeng li29.52%120.00%
andy lutomirskiandy lutomirski14.76%120.00%
Total21100.00%5100.00%

/* Can be uninlined because referenced by paravirt */
static inline void notrace native_write_msr(unsigned int msr, u32 low, u32 high) { __native_write_msr_notrace(msr, low, high); if (msr_tracepoint_active(__tracepoint_write_msr)) do_trace_write_msr(msr, ((u64)high << 32 | low), 0); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen2446.15%120.00%
wanpeng liwanpeng li2344.23%120.00%
borislav petkovborislav petkov35.77%120.00%
david alan gilbertdavid alan gilbert11.92%120.00%
thomas gleixnerthomas gleixner11.92%120.00%
Total52100.00%5100.00%


static inline void wrmsr_notrace(unsigned int msr, u32 low, u32 high) { __native_write_msr_notrace(msr, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
wanpeng liwanpeng li2388.46%150.00%
borislav petkovborislav petkov311.54%150.00%
Total26100.00%2100.00%

/* Can be uninlined because referenced by paravirt */
static inline int notrace native_write_msr_safe(unsigned int msr, u32 low, u32 high) { int err; asm volatile("2: wrmsr ; xor %[err],%[err]\n" "1:\n\t" ".section .fixup,\"ax\"\n\t" "3: mov %[fault],%[err] ; jmp 1b\n\t" ".previous\n\t" _ASM_EXTABLE(2b, 3b) : [err] "=a" (err) : "c" (msr), "0" (low), "d" (high), [fault] "i" (-EIO) : "memory"); if (msr_tracepoint_active(__tracepoint_write_msr)) do_trace_write_msr(msr, ((u64)high << 32 | low), err); return err; }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen2446.15%116.67%
thomas gleixnerthomas gleixner2038.46%116.67%
borislav petkovborislav petkov35.77%116.67%
glauber de oliveira costaglauber de oliveira costa35.77%116.67%
david alan gilbertdavid alan gilbert11.92%116.67%
h. peter anvinh. peter anvin11.92%116.67%
Total52100.00%6100.00%

extern int rdmsr_safe_regs(u32 regs[8]); extern int wrmsr_safe_regs(u32 regs[8]); /** * rdtsc() - returns the current TSC without ordering constraints * * rdtsc() returns the result of RDTSC as a 64-bit integer. The * only ordering constraint it supplies is the ordering implied by * "asm volatile": it will put the RDTSC in the place you expect. The * CPU can and will speculatively execute that RDTSC, though, so the * results can be non-monotonic if compared on different CPUs. */
static __always_inline unsigned long long rdtsc(void) { DECLARE_ARGS(val, low, high); asm volatile("rdtsc" : EAX_EDX_RET(val, low, high)); return EAX_EDX_VAL(val, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
ingo molnaringo molnar3296.97%150.00%
andy lutomirskiandy lutomirski13.03%150.00%
Total33100.00%2100.00%

/** * rdtsc_ordered() - read the current TSC in program order * * rdtsc_ordered() returns the result of RDTSC as a 64-bit integer. * It is ordered like a load to a global in-memory counter. It should * be impossible to observe non-monotonic rdtsc_unordered() behavior * across multiple CPUs as long as the TSC is synced. */
static __always_inline unsigned long long rdtsc_ordered(void) { /* * The RDTSC instruction is not ordered relative to memory * access. The Intel SDM and the AMD APM are both vague on this * point, but empirically an RDTSC instruction can be * speculatively executed before prior loads. An RDTSC * immediately after an appropriate barrier appears to be * ordered as a normal load, that is, it provides the same * ordering guarantees as reading from a global memory location * that some other imaginary CPU is updating continuously with a * time stamp. */ alternative_2("", "mfence", X86_FEATURE_MFENCE_RDTSC, "lfence", X86_FEATURE_LFENCE_RDTSC); return rdtsc(); }

Contributors

PersonTokensPropCommitsCommitProp
andy lutomirskiandy lutomirski29100.00%1100.00%
Total29100.00%1100.00%

/* Deprecated, keep it for a cycle for easier merging: */ #define rdtscll(now) do { (now) = rdtsc_ordered(); } while (0)
static inline unsigned long long native_read_pmc(int counter) { DECLARE_ARGS(val, low, high); asm volatile("rdpmc" : EAX_EDX_RET(val, low, high) : "c" (counter)); if (msr_tracepoint_active(__tracepoint_rdpmc)) do_trace_rdpmc(counter, EAX_EDX_VAL(val, low, high), 0); return EAX_EDX_VAL(val, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen2340.35%125.00%
glauber de oliveira costaglauber de oliveira costa1831.58%250.00%
thomas gleixnerthomas gleixner1628.07%125.00%
Total57100.00%4100.00%

#ifdef CONFIG_PARAVIRT #include <asm/paravirt.h> #else #include <linux/errno.h> /* * Access to machine-specific registers (available on 586 and better only) * Note: the rd* operations modify the parameters directly (without using * pointer indirection), this allows gcc to optimize better */ #define rdmsr(msr, low, high) \ do { \ u64 __val = native_read_msr((msr)); \ (void)((low) = (u32)__val); \ (void)((high) = (u32)(__val >> 32)); \ } while (0)
static inline void wrmsr(unsigned int msr, u32 low, u32 high) { native_write_msr(msr, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner1557.69%133.33%
glauber de oliveira costaglauber de oliveira costa830.77%133.33%
borislav petkovborislav petkov311.54%133.33%
Total26100.00%3100.00%

#define rdmsrl(msr, val) \ ((val) = native_read_msr((msr)))
static inline void wrmsrl(unsigned int msr, u64 val) { native_write_msr(msr, (u32)(val & 0xffffffffULL), (u32)(val >> 32)); }

Contributors

PersonTokensPropCommitsCommitProp
andy lutomirskiandy lutomirski2464.86%125.00%
borislav petkovborislav petkov718.92%250.00%
thomas gleixnerthomas gleixner616.22%125.00%
Total37100.00%4100.00%

/* wrmsr with exception handling */
static inline int wrmsr_safe(unsigned int msr, u32 low, u32 high) { return native_write_msr_safe(msr, low, high); }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner1659.26%133.33%
glauber de oliveira costaglauber de oliveira costa829.63%133.33%
borislav petkovborislav petkov311.11%133.33%
Total27100.00%3100.00%

/* rdmsr with exception handling */ #define rdmsr_safe(msr, low, high) \ ({ \ int __err; \ u64 __val = native_read_msr_safe((msr), &__err); \ (*low) = (u32)__val; \ (*high) = (u32)(__val >> 32); \ __err; \ })
static inline int rdmsrl_safe(unsigned int msr, unsigned long long *p) { int err; *p = native_read_msr_safe(msr, &err); return err; }

Contributors

PersonTokensPropCommitsCommitProp
andi kleenandi kleen3397.06%150.00%
borislav petkovborislav petkov12.94%150.00%
Total34100.00%2100.00%

#define rdpmc(counter, low, high) \ do { \ u64 _l = native_read_pmc((counter)); \ (low) = (u32)_l; \ (high) = (u32)(_l >> 32); \ } while (0) #define rdpmcl(counter, val) ((val) = native_read_pmc(counter)) #endif /* !CONFIG_PARAVIRT */ /* * 64-bit version of wrmsr_safe(): */
static inline int wrmsrl_safe(u32 msr, u64 val) { return wrmsr_safe(msr, (u32)val, (u32)(val >> 32)); }

Contributors

PersonTokensPropCommitsCommitProp
andy lutomirskiandy lutomirski2781.82%133.33%
thomas gleixnerthomas gleixner515.15%133.33%
h. peter anvinh. peter anvin13.03%133.33%
Total33100.00%3100.00%

#define write_tsc(low, high) wrmsr(MSR_IA32_TSC, (low), (high)) #define write_rdtscp_aux(val) wrmsr(MSR_TSC_AUX, (val), 0) struct msr *msrs_alloc(void); void msrs_free(struct msr *msrs); int msr_set_bit(u32 msr, u8 bit); int msr_clear_bit(u32 msr, u8 bit); #ifdef CONFIG_SMP int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q); void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs); void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs); int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q); int wrmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q); int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8]); int wrmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8]); #else /* CONFIG_SMP */
static inline int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) { rdmsr(msr_no, *l, *h); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner3288.89%150.00%
h. peter anvinh. peter anvin411.11%150.00%
Total36100.00%2100.00%


static inline int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) { wrmsr(msr_no, l, h); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner2887.50%150.00%
h. peter anvinh. peter anvin412.50%150.00%
Total32100.00%2100.00%


static inline int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q) { rdmsrl(msr_no, *q); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
jacob panjacob pan29100.00%1100.00%
Total29100.00%1100.00%


static inline int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q) { wrmsrl(msr_no, q); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
jacob panjacob pan27100.00%1100.00%
Total27100.00%1100.00%


static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no, struct msr *msrs) { rdmsr_on_cpu(0, msr_no, &(msrs[0].l), &(msrs[0].h)); }

Contributors

PersonTokensPropCommitsCommitProp
borislav petkovborislav petkov4695.83%150.00%
rusty russellrusty russell24.17%150.00%
Total48100.00%2100.00%


static inline void wrmsr_on_cpus(const struct cpumask *m, u32 msr_no, struct msr *msrs) { wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h); }

Contributors

PersonTokensPropCommitsCommitProp
borislav petkovborislav petkov4095.24%150.00%
rusty russellrusty russell24.76%150.00%
Total42100.00%2100.00%


static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h) { return rdmsr_safe(msr_no, l, h); }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner32100.00%1100.00%
Total32100.00%1100.00%


static inline int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h) { return wrmsr_safe(msr_no, l, h); }

Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner30100.00%1100.00%
Total30100.00%1100.00%


static inline int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q) { return rdmsrl_safe(msr_no, q); }

Contributors

PersonTokensPropCommitsCommitProp
jacob panjacob pan26100.00%1100.00%
Total26100.00%1100.00%


static inline int wrmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q) { return wrmsrl_safe(msr_no, q); }

Contributors

PersonTokensPropCommitsCommitProp
jacob panjacob pan25100.00%1100.00%
Total25100.00%1100.00%


static inline int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8]) { return rdmsr_safe_regs(regs); }

Contributors

PersonTokensPropCommitsCommitProp
h. peter anvinh. peter anvin23100.00%1100.00%
Total23100.00%1100.00%


static inline int wrmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8]) { return wrmsr_safe_regs(regs); }

Contributors

PersonTokensPropCommitsCommitProp
h. peter anvinh. peter anvin23100.00%1100.00%
Total23100.00%1100.00%

#endif /* CONFIG_SMP */ #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_MSR_H */

Overall Contributors

PersonTokensPropCommitsCommitProp
thomas gleixnerthomas gleixner40525.22%24.08%
andi kleenandi kleen28117.50%24.08%
borislav petkovborislav petkov27417.06%1122.45%
jacob panjacob pan16510.27%12.04%
glauber de oliveira costaglauber de oliveira costa1509.34%48.16%
andy lutomirskiandy lutomirski1016.29%816.33%
h. peter anvinh. peter anvin976.04%714.29%
wanpeng liwanpeng li493.05%12.04%
ingo molnaringo molnar412.55%36.12%
chen yuchen yu261.62%12.04%
rusty russellrusty russell40.25%12.04%
george spelvingeorge spelvin30.19%12.04%
mike frysingermike frysinger20.12%12.04%
david alan gilbertdavid alan gilbert20.12%12.04%
andre przywaraandre przywara20.12%12.04%
joe perchesjoe perches10.06%12.04%
frederic weisbeckerfrederic weisbecker10.06%12.04%
jike songjike song10.06%12.04%
sheng yangsheng yang10.06%12.04%
Total1606100.00%49100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.