1 #include <linux/export.h>
2 #include <linux/percpu.h>
3 #include <linux/preempt.h>
5 #define CREATE_TRACE_POINTS
6 #include <asm/msr-trace.h>
8 struct msr
*msrs_alloc(void)
10 struct msr
*msrs
= NULL
;
12 msrs
= alloc_percpu(struct msr
);
14 pr_warn("%s: error allocating msrs\n", __func__
);
20 EXPORT_SYMBOL(msrs_alloc
);
22 void msrs_free(struct msr
*msrs
)
26 EXPORT_SYMBOL(msrs_free
);
29 * Read an MSR with error handling
32 * @m: value to read into
34 * It returns read data only on success, otherwise it doesn't change the output
38 int msr_read(u32 msr
, struct msr
*m
)
43 err
= rdmsrl_safe(msr
, &val
);
51 * Write an MSR with error handling
56 int msr_write(u32 msr
, struct msr
*m
)
58 return wrmsrl_safe(msr
, m
->q
);
61 static inline int __flip_bit(u32 msr
, u8 bit
, bool set
)
69 err
= msr_read(msr
, &m
);
82 err
= msr_write(msr
, &m1
);
90 * Set @bit in a MSR @msr.
93 * < 0: An error was encountered.
94 * = 0: Bit was already set.
95 * > 0: Hardware accepted the MSR write.
97 int msr_set_bit(u32 msr
, u8 bit
)
99 return __flip_bit(msr
, bit
, true);
103 * Clear @bit in a MSR @msr.
106 * < 0: An error was encountered.
107 * = 0: Bit was already cleared.
108 * > 0: Hardware accepted the MSR write.
110 int msr_clear_bit(u32 msr
, u8 bit
)
112 return __flip_bit(msr
, bit
, false);
115 #ifdef CONFIG_TRACEPOINTS
116 void do_trace_write_msr(unsigned int msr
, u64 val
, int failed
)
118 trace_write_msr(msr
, val
, failed
);
120 EXPORT_SYMBOL(do_trace_write_msr
);
121 EXPORT_TRACEPOINT_SYMBOL(write_msr
);
123 void do_trace_read_msr(unsigned int msr
, u64 val
, int failed
)
125 trace_read_msr(msr
, val
, failed
);
127 EXPORT_SYMBOL(do_trace_read_msr
);
128 EXPORT_TRACEPOINT_SYMBOL(read_msr
);
130 void do_trace_rdpmc(unsigned counter
, u64 val
, int failed
)
132 trace_rdpmc(counter
, val
, failed
);
134 EXPORT_SYMBOL(do_trace_rdpmc
);
135 EXPORT_TRACEPOINT_SYMBOL(rdpmc
);