From: Rusty Russell <rusty@rustcorp.com.au>
To: Avi Kivity <avi@qumranet.com>
Cc: Andrew Morton <akpm@osdl.org>,
Jeremy Fitzhardinge <jeremy@goop.org>,
lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>,
Andi Kleen <ak@muc.de>
Subject: Re: [PATCH] Cleanup: rationalize paravirt wrappers
Date: Thu, 22 Mar 2007 20:55:19 +1100 [thread overview]
Message-ID: <1174557319.2713.148.camel@localhost.localdomain> (raw)
In-Reply-To: <460239C3.5000404@qumranet.com>
On Thu, 2007-03-22 at 10:09 +0200, Avi Kivity wrote:
> Right, scratch that. Was confused by rdmsr_safe().
Heh... me too 8)
> > The behaviour change (don't oops when an invalid rdmsr is used) was
> > there with CONFIG_PARAVIRT=y, the cleanup just made !CONFIG_PARAVIRT the
> > same. Is it important?
>
> I think so. A function should either never fail, or indicate that it
> has failed (panic, error return, debug message). With the kinder,
> gentler rdmsr() one can code the wrong msr value and not notice that
> something is wrong.
This is persuasive. I think restoring native_read_msr &
native_write_msr make sense, and Jeremy's BUG_ON suggestion will cover
the CONFIG_PARAVIRT case.
Something like this (I'll roll back into the main patch, retest, and
resend tomorrow).
Thanks!
Rusty.
diff -r 3ddb2898e72a include/asm-i386/msr.h
--- a/include/asm-i386/msr.h Thu Mar 22 19:31:11 2007 +1100
+++ b/include/asm-i386/msr.h Thu Mar 22 19:42:30 2007 +1100
@@ -3,7 +3,16 @@
#include <asm/errno.h>
-static inline unsigned long long native_read_msr(unsigned int msr, int *err)
+static inline unsigned long long native_read_msr(unsigned int msr)
+{
+ unsigned long long val;
+
+ asm volatile("rdmsr" : "=A" (val) : "c" (msr));
+ return val;
+}
+
+static inline unsigned long long native_read_msr_safe(unsigned int msr,
+ int *err)
{
unsigned long long val;
@@ -22,7 +31,13 @@ static inline unsigned long long native_
return val;
}
-static inline int native_write_msr(unsigned int msr, unsigned long long val)
+static inline void native_write_msr(unsigned int msr, unsigned long long val)
+{
+ asm volatile("wrmsr" : : "c" (msr), "A"(val));
+}
+
+static inline int native_write_msr_safe(unsigned int msr,
+ unsigned long long val)
{
int err;
asm volatile("2: wrmsr ; xorl %0,%0\n"
@@ -66,21 +81,17 @@ static inline unsigned long long native_
#define rdmsr(msr,val1,val2) \
do { \
- int __err; \
- unsigned long long __val = native_read_msr(msr, &__err); \
+ unsigned long long __val = native_read_msr(msr); \
val1 = __val; \
val2 = __val >> 32; \
} while(0)
#define wrmsr(msr,val1,val2) \
- do { \
- native_write_msr(msr, ((unsigned long long)val2 << 32) | val1); \
- } while(0)
+ native_write_msr(msr, ((unsigned long long)val2 << 32) | val1)
#define rdmsrl(msr,val) \
do { \
- int __err; \
- (val) = native_read_msr(msr, &__err); \
+ (val) = native_read_msr(msr); \
} while(0)
static inline void wrmsrl (unsigned long msr, unsigned long long val)
@@ -93,13 +104,13 @@ static inline void wrmsrl (unsigned long
/* wrmsr with exception handling */
#define wrmsr_safe(msr,val1,val2) \
- (native_write_msr(msr, ((unsigned long long)val2 << 32) | val1))
+ (native_write_msr_safe(msr, ((unsigned long long)val2 << 32) | val1))
/* rdmsr with exception handling */
#define rdmsr_safe(msr,p1,p2) \
({ \
int __err; \
- unsigned long long __val = native_read_msr(msr, &__err);\
+ unsigned long long __val = native_read_msr_safe(msr, &__err);\
(*p1) = __val; \
(*p2) = __val >> 32; \
__err; \
diff -r 3ddb2898e72a include/asm-i386/paravirt.h
--- a/include/asm-i386/paravirt.h Thu Mar 22 19:31:11 2007 +1100
+++ b/include/asm-i386/paravirt.h Thu Mar 22 19:44:03 2007 +1100
@@ -237,19 +237,26 @@ static inline void halt(void)
u64 _l = paravirt_ops.read_msr(msr,&_err); \
val1 = (u32)_l; \
val2 = _l >> 32; \
+ BUG_ON(_err); \
} while(0)
#define wrmsr(msr,val1,val2) do { \
u64 _l = ((u64)(val2) << 32) | (val1); \
- paravirt_ops.write_msr((msr), _l); \
+ int _err = paravirt_ops.write_msr((msr), _l); \
+ BUG_ON(_err); \
} while(0)
#define rdmsrl(msr,val) do { \
int _err; \
val = paravirt_ops.read_msr((msr),&_err); \
-} while(0)
-
-#define wrmsrl(msr,val) (paravirt_ops.write_msr((msr),(val)))
+ BUG_ON(_err); \
+} while(0)
+
+#define wrmsrl(msr,val) do { \
+ int _err = paravirt_ops.write_msr((msr),(val)); \
+ BUG_ON(_err); \
+} while(0)
+
#define wrmsr_safe(msr,a,b) ({ \
u64 _l = ((u64)(b) << 32) | (a); \
paravirt_ops.write_msr((msr),_l); \
next prev parent reply other threads:[~2007-03-22 9:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-22 2:41 [PATCH] Cleanup: rationalize paravirt wrappers Rusty Russell
2007-03-22 7:30 ` Avi Kivity
2007-03-22 8:00 ` Rusty Russell
2007-03-22 8:09 ` Jeremy Fitzhardinge
2007-03-22 8:09 ` Avi Kivity
2007-03-22 9:55 ` Rusty Russell [this message]
2007-03-23 11:05 ` Rusty Russell
2007-03-23 11:19 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1174557319.2713.148.camel@localhost.localdomain \
--to=rusty@rustcorp.com.au \
--cc=ak@muc.de \
--cc=akpm@osdl.org \
--cc=avi@qumranet.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.