1 #include <linux/module.h>
2 #include <linux/preempt.h>
4 #define CREATE_TRACE_POINTS
5 #include <asm/msr-trace.h>
7 struct msr
*msrs_alloc(void)
9 struct msr
*msrs
= NULL
;
11 msrs
= alloc_percpu(struct msr
);
13 pr_warn("%s: error allocating msrs\n", __func__
);
19 EXPORT_SYMBOL(msrs_alloc
);
21 void msrs_free(struct msr
*msrs
)
25 EXPORT_SYMBOL(msrs_free
);
28 * Read an MSR with error handling
31 * @m: value to read into
33 * It returns read data only on success, otherwise it doesn't change the output
37 int msr_read(u32 msr
, struct msr
*m
)
42 err
= rdmsrl_safe(msr
, &val
);
50 * Write an MSR with error handling
55 int msr_write(u32 msr
, struct msr
*m
)
57 return wrmsrl_safe(msr
, m
->q
);
60 static inline int __flip_bit(u32 msr
, u8 bit
, bool set
)
68 err
= msr_read(msr
, &m
);
81 err
= msr_write(msr
, &m1
);
89 * Set @bit in a MSR @msr.
92 * < 0: An error was encountered.
93 * = 0: Bit was already set.
94 * > 0: Hardware accepted the MSR write.
96 int msr_set_bit(u32 msr
, u8 bit
)
98 return __flip_bit(msr
, bit
, true);
102 * Clear @bit in a MSR @msr.
105 * < 0: An error was encountered.
106 * = 0: Bit was already cleared.
107 * > 0: Hardware accepted the MSR write.
109 int msr_clear_bit(u32 msr
, u8 bit
)
111 return __flip_bit(msr
, bit
, false);
114 #ifdef CONFIG_TRACEPOINTS
115 void do_trace_write_msr(unsigned msr
, u64 val
, int failed
)
117 trace_write_msr(msr
, val
, failed
);
119 EXPORT_SYMBOL(do_trace_write_msr
);
120 EXPORT_TRACEPOINT_SYMBOL(write_msr
);
122 void do_trace_read_msr(unsigned msr
, u64 val
, int failed
)
124 trace_read_msr(msr
, val
, failed
);
126 EXPORT_SYMBOL(do_trace_read_msr
);
127 EXPORT_TRACEPOINT_SYMBOL(read_msr
);
129 void do_trace_rdpmc(unsigned counter
, u64 val
, int failed
)
131 trace_rdpmc(counter
, val
, failed
);
133 EXPORT_SYMBOL(do_trace_rdpmc
);
134 EXPORT_TRACEPOINT_SYMBOL(rdpmc
);