Commit b0b73cb4 authored by H. Peter Anvin's avatar H. Peter Anvin Committed by Linus Torvalds

i386: msr.h: be paranoid about types and parentheses

When implementing things as macros, make sure we use typecasts and
parentheses where needed.  The macros as defined were vulnerable to
surreptitious promotion causing problems.

Avoid macros where practical; e.g. wrmsr() can be an inline instead.
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 29bd4433
...@@ -86,55 +86,50 @@ static inline unsigned long long native_read_pmc(void) ...@@ -86,55 +86,50 @@ static inline unsigned long long native_read_pmc(void)
#define rdmsr(msr,val1,val2) \ #define rdmsr(msr,val1,val2) \
do { \ do { \
unsigned long long __val = native_read_msr(msr); \ u64 __val = native_read_msr(msr); \
val1 = __val; \ (val1) = (u32)__val; \
val2 = __val >> 32; \ (val2) = (u32)(__val >> 32); \
} while(0) } while(0)
#define wrmsr(msr,val1,val2) \ static inline void wrmsr(u32 __msr, u32 __low, u32 __high)
native_write_msr(msr, ((unsigned long long)val2 << 32) | val1) {
native_write_msr(__msr, ((u64)__high << 32) | __low);
}
#define rdmsrl(msr,val) \ #define rdmsrl(msr,val) \
do { \ ((val) = native_read_msr(msr))
(val) = native_read_msr(msr); \
} while(0)
static inline void wrmsrl (unsigned long msr, unsigned long long val) #define wrmsrl(msr,val) native_write_msr(msr, val)
{
unsigned long lo, hi;
lo = (unsigned long) val;
hi = val >> 32;
wrmsr (msr, lo, hi);
}
/* wrmsr with exception handling */ /* wrmsr with exception handling */
#define wrmsr_safe(msr,val1,val2) \ static inline int wrmsr_safe(u32 __msr, u32 __low, u32 __high)
(native_write_msr_safe(msr, ((unsigned long long)val2 << 32) | val1)) {
return native_write_msr_safe(__msr, ((u64)__high << 32) | __low);
}
/* rdmsr with exception handling */ /* rdmsr with exception handling */
#define rdmsr_safe(msr,p1,p2) \ #define rdmsr_safe(msr,p1,p2) \
({ \ ({ \
int __err; \ int __err; \
unsigned long long __val = native_read_msr_safe(msr, &__err);\ u64 __val = native_read_msr_safe(msr, &__err); \
(*p1) = __val; \ (*p1) = (u32)__val; \
(*p2) = __val >> 32; \ (*p2) = (u32)(__val >> 32); \
__err; \ __err; \
}) })
#define rdtscl(low) \ #define rdtscl(low) \
do { \ ((low) = (u32)native_read_tsc())
(low) = native_read_tsc(); \
} while(0)
#define rdtscll(val) ((val) = native_read_tsc()) #define rdtscll(val) \
((val) = native_read_tsc())
#define write_tsc(val1,val2) wrmsr(0x10, val1, val2) #define write_tsc(val1,val2) wrmsr(0x10, val1, val2)
#define rdpmc(counter,low,high) \ #define rdpmc(counter,low,high) \
do { \ do { \
u64 _l = native_read_pmc(); \ u64 _l = native_read_pmc(); \
low = (u32)_l; \ (low) = (u32)_l; \
high = _l >> 32; \ (high) = (u32)(_l >> 32); \
} while(0) } while(0)
#endif /* !CONFIG_PARAVIRT */ #endif /* !CONFIG_PARAVIRT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment