@@ -35,20 +35,22 @@ struct saved_msrs {
3535};
3636
3737/*
38- * both i386 and x86_64 returns 64-bit value in edx:eax, but gcc's "A"
39- * constraint has different meanings. For i386, "A" means exactly
40- * edx:eax, while for x86_64 it doesn't mean rdx:rax or edx:eax. Instead,
41- * it means rax *or* rdx.
38+ * Both i386 and x86_64 returns 64-bit values in edx:eax for certain
39+ * instructions, but GCC's "A" constraint has different meanings.
40+ * For i386, "A" means exactly edx:eax, while for x86_64 it
41+ * means rax *or* rdx.
42+ *
43+ * These helpers wrapping these semantic differences save one instruction
44+ * clearing the high half of 'low':
4245 */
4346#ifdef CONFIG_X86_64
44- /* Using 64-bit values saves one instruction clearing the high half of low */
45- #define DECLARE_ARGS (val , low , high ) unsigned long low, high
46- #define EAX_EDX_VAL (val , low , high ) ((low) | (high) << 32)
47- #define EAX_EDX_RET (val , low , high ) "=a" (low), "=d" (high)
47+ # define EAX_EDX_DECLARE_ARGS (val , low , high ) unsigned long low, high
48+ # define EAX_EDX_VAL (val , low , high ) ((low) | (high) << 32)
49+ # define EAX_EDX_RET (val , low , high ) "=a" (low), "=d" (high)
4850#else
49- #define DECLARE_ARGS (val , low , high ) unsigned long long val
50- #define EAX_EDX_VAL (val , low , high ) (val)
51- #define EAX_EDX_RET (val , low , high ) "=A" (val)
51+ # define EAX_EDX_DECLARE_ARGS (val , low , high ) u64 val
52+ # define EAX_EDX_VAL (val , low , high ) (val)
53+ # define EAX_EDX_RET (val , low , high ) "=A" (val)
5254#endif
5355
5456/*
@@ -77,9 +79,9 @@ static inline void do_trace_rdpmc(unsigned int msr, u64 val, int failed) {}
7779 * think of extending them - you will be slapped with a stinking trout or a frozen
7880 * shark will reach you, wherever you are! You've been warned.
7981 */
80- static __always_inline unsigned long long __rdmsr (unsigned int msr )
82+ static __always_inline u64 __rdmsr (unsigned int msr )
8183{
82- DECLARE_ARGS (val , low , high );
84+ EAX_EDX_DECLARE_ARGS (val , low , high );
8385
8486 asm volatile ("1: rdmsr\n"
8587 "2:\n"
@@ -124,9 +126,9 @@ do { \
124126 __wrmsr((msr), (u32)((u64)(val)), \
125127 (u32)((u64)(val) >> 32))
126128
127- static inline unsigned long long native_read_msr (unsigned int msr )
129+ static inline u64 native_read_msr (unsigned int msr )
128130{
129- unsigned long long val ;
131+ u64 val ;
130132
131133 val = __rdmsr (msr );
132134
@@ -136,10 +138,10 @@ static inline unsigned long long native_read_msr(unsigned int msr)
136138 return val ;
137139}
138140
139- static inline unsigned long long native_read_msr_safe (unsigned int msr ,
141+ static inline u64 native_read_msr_safe (unsigned int msr ,
140142 int * err )
141143{
142- DECLARE_ARGS (val , low , high );
144+ EAX_EDX_DECLARE_ARGS (val , low , high );
143145
144146 asm volatile ("1: rdmsr ; xor %[err],%[err]\n"
145147 "2:\n\t"
@@ -190,9 +192,9 @@ extern int wrmsr_safe_regs(u32 regs[8]);
190192 * CPU can and will speculatively execute that RDTSC, though, so the
191193 * results can be non-monotonic if compared on different CPUs.
192194 */
193- static __always_inline unsigned long long rdtsc (void )
195+ static __always_inline u64 rdtsc (void )
194196{
195- DECLARE_ARGS (val , low , high );
197+ EAX_EDX_DECLARE_ARGS (val , low , high );
196198
197199 asm volatile ("rdtsc" : EAX_EDX_RET (val , low , high ));
198200
@@ -207,9 +209,9 @@ static __always_inline unsigned long long rdtsc(void)
207209 * be impossible to observe non-monotonic rdtsc_unordered() behavior
208210 * across multiple CPUs as long as the TSC is synced.
209211 */
210- static __always_inline unsigned long long rdtsc_ordered (void )
212+ static __always_inline u64 rdtsc_ordered (void )
211213{
212- DECLARE_ARGS (val , low , high );
214+ EAX_EDX_DECLARE_ARGS (val , low , high );
213215
214216 /*
215217 * The RDTSC instruction is not ordered relative to memory
@@ -235,9 +237,9 @@ static __always_inline unsigned long long rdtsc_ordered(void)
235237 return EAX_EDX_VAL (val , low , high );
236238}
237239
238- static inline unsigned long long native_read_pmc (int counter )
240+ static inline u64 native_read_pmc (int counter )
239241{
240- DECLARE_ARGS (val , low , high );
242+ EAX_EDX_DECLARE_ARGS (val , low , high );
241243
242244 asm volatile ("rdpmc" : EAX_EDX_RET (val , low , high ) : "c" (counter ));
243245 if (tracepoint_enabled (rdpmc ))
@@ -291,7 +293,7 @@ static inline int wrmsr_safe(unsigned int msr, u32 low, u32 high)
291293 __err; \
292294})
293295
294- static inline int rdmsrl_safe (unsigned int msr , unsigned long long * p )
296+ static inline int rdmsrl_safe (unsigned int msr , u64 * p )
295297{
296298 int err ;
297299
0 commit comments