From: Andy Lutomirski <luto@kernel.org>
To: x86@kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
KVM list <kvm@vger.kernel.org>,
Arjan van de Ven <arjan@linux.intel.com>,
xen-devel <Xen-devel@lists.xen.org>,
linux-kernel@vger.kernel.org, Andy Lutomirski <luto@kernel.org>
Subject: [PATCH 2/3] x86/paravirt: Add paravirt_{read,write}_msr
Date: Wed, 16 Sep 2015 16:33:13 -0700 [thread overview]
Message-ID: <54487a210e2b389c2504c6391d33053e8ea40963.1442445946.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1442445946.git.luto@kernel.org>
In-Reply-To: <cover.1442445946.git.luto@kernel.org>
This adds paravirt hooks for unsafe MSR access. On native, they
call native_{read,write}_msr. On Xen, they use
xen_{read,write}_msr_safe.
Nothing uses them yet for ease of bisection. The next patch will
use them in rdmsrl, wrmsrl, etc.
I intentionally didn't make them OOPS on #GP on Xen. I think that
should be done separately by the Xen maintainers.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
arch/x86/include/asm/paravirt.h | 11 +++++++++++
arch/x86/include/asm/paravirt_types.h | 10 ++++++++--
arch/x86/kernel/paravirt.c | 2 ++
arch/x86/xen/enlighten.c | 23 +++++++++++++++++++++++
4 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
index 9cf6e5232b0d..e6569a3b0a37 100644
--- a/arch/x86/include/asm/paravirt.h
+++ b/arch/x86/include/asm/paravirt.h
@@ -123,6 +123,17 @@ static inline void wbinvd(void)
#define get_kernel_rpl() (pv_info.kernel_rpl)
+static inline u64 paravirt_read_msr(unsigned msr)
+{
+ return PVOP_CALL1(u64, pv_cpu_ops.read_msr, msr);
+}
+
+static inline void paravirt_write_msr(unsigned msr,
+ unsigned low, unsigned high)
+{
+ return PVOP_VCALL3(pv_cpu_ops.write_msr, msr, low, high);
+}
+
static inline u64 paravirt_read_msr_safe(unsigned msr, int *err)
{
return PVOP_CALL2(u64, pv_cpu_ops.read_msr_safe, msr, err);
diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
index 810e8ccaa42a..cb1e7af9fe42 100644
--- a/arch/x86/include/asm/paravirt_types.h
+++ b/arch/x86/include/asm/paravirt_types.h
@@ -151,8 +151,14 @@ struct pv_cpu_ops {
void (*cpuid)(unsigned int *eax, unsigned int *ebx,
unsigned int *ecx, unsigned int *edx);
- /* MSR operations.
- err = 0/-EIO. wrmsr returns 0/-EIO. */
+ /* Unsafe MSR operations. These either succeed or crash. */
+ u64 (*read_msr)(unsigned int msr);
+ int (*write_msr)(unsigned int msr, unsigned low, unsigned high);
+
+ /*
+ * Safe MSR operations.
+ * err = 0/-EIO. wrmsr returns 0/-EIO.
+ */
u64 (*read_msr_safe)(unsigned int msr, int *err);
int (*write_msr_safe)(unsigned int msr, unsigned low, unsigned high);
diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
index fe8cd519a796..21fc4686f760 100644
--- a/arch/x86/kernel/paravirt.c
+++ b/arch/x86/kernel/paravirt.c
@@ -349,6 +349,8 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
.write_cr8 = native_write_cr8,
#endif
.wbinvd = native_wbinvd,
+ .read_msr = native_read_msr,
+ .write_msr = native_write_msr,
.read_msr_safe = native_read_msr_safe,
.write_msr_safe = native_write_msr_safe,
.read_pmc = native_read_pmc,
diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 8523d42d163e..d2bc6afeaf33 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1086,6 +1086,26 @@ static int xen_write_msr_safe(unsigned int msr, unsigned low, unsigned high)
return ret;
}
+static u64 xen_read_msr(unsigned int msr)
+{
+ /*
+ * This will silently swallow a #GP from RDMSR. It may be worth
+ * changing that.
+ */
+ int err;
+
+ return xen_read_msr_safe(msr, &err);
+}
+
+static void xen_write_msr(unsigned int msr, unsigned low, unsigned high)
+{
+ /*
+ * This will silently swallow a #GP from WRMSR. It may be worth
+ * changing that.
+ */
+ xen_write_msr_safe(msr, low, high);
+}
+
void xen_setup_shared_info(void)
{
if (!xen_feature(XENFEAT_auto_translated_physmap)) {
@@ -1216,6 +1236,9 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
.wbinvd = native_wbinvd,
+ .read_msr = xen_read_msr,
+ .write_msr = xen_write_msr,
+
.read_msr_safe = xen_read_msr_safe,
.write_msr_safe = xen_write_msr_safe,
--
2.4.3
next prev parent reply other threads:[~2015-09-16 23:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 23:33 [PATCH 0/3] x86/paravirt: Fix baremetal paravirt MSR ops Andy Lutomirski
2015-09-16 23:33 ` [PATCH 1/3] x86/paravirt: Add _safe to the read_msr and write_msr PV hooks Andy Lutomirski
2015-09-16 23:33 ` Andy Lutomirski [this message]
2015-09-16 23:33 ` [PATCH 3/3] x86/paravirt: Make "unsafe" MSR accesses unsafe even if PARAVIRT=y Andy Lutomirski
2015-09-17 7:19 ` [PATCH 0/3] x86/paravirt: Fix baremetal paravirt MSR ops Ingo Molnar
2015-09-17 9:31 ` Borislav Petkov
2015-09-17 11:22 ` H. Peter Anvin
2015-09-17 11:39 ` Paolo Bonzini
2015-09-17 15:27 ` Borislav Petkov
2015-09-17 15:32 ` [Xen-devel] " Andrew Cooper
2015-09-17 15:37 ` Borislav Petkov
2015-09-17 15:23 ` Andy Lutomirski
2015-09-17 15:27 ` Arjan van de Ven
2015-09-17 15:29 ` Paolo Bonzini
2015-09-17 15:31 ` Arjan van de Ven
2015-09-17 15:33 ` Paolo Bonzini
2015-09-17 17:30 ` Ingo Molnar
2015-09-17 18:51 ` Andy Lutomirski
2015-09-17 8:58 ` Peter Zijlstra
2015-09-17 11:40 ` Paolo Bonzini
2015-09-17 12:27 ` Peter Zijlstra
2015-09-17 15:17 ` Andy Lutomirski
2015-09-17 15:17 ` Peter Zijlstra
2015-09-17 15:26 ` Andy Lutomirski
2015-09-17 15:29 ` Paolo Bonzini
2015-09-17 9:10 ` [Xen-devel] " Andrew Cooper
2015-09-17 15:11 ` Boris Ostrovsky
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=54487a210e2b389c2504c6391d33053e8ea40963.1442445946.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=Xen-devel@lists.xen.org \
--cc=arjan@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®