Skip to content

Commit 3fac373

Browse files
committed
xen/pv: support selecting safe/unsafe msr accesses
Instead of always doing the safe variants for reading and writing MSRs in Xen PV guests, make the behavior controllable via Kconfig option and a boot parameter. The default will be the current behavior, which is to always use the safe variant. Signed-off-by: Juergen Gross <[email protected]>
1 parent a1886b9 commit 3fac373

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6836,6 +6836,12 @@
68366836
Crash from Xen panic notifier, without executing late
68376837
panic() code such as dumping handler.
68386838

6839+
xen_msr_safe= [X86,XEN]
6840+
Format: <bool>
6841+
Select whether to always use non-faulting (safe) MSR
6842+
access functions when running as Xen PV guest. The
6843+
default value is controlled by CONFIG_XEN_PV_MSR_SAFE.
6844+
68396845
xen_nopvspin [X86,XEN]
68406846
Disables the qspinlock slowpath using Xen PV optimizations.
68416847
This parameter is obsoleted by "nopvspin" parameter, which

arch/x86/xen/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,12 @@ config XEN_DOM0
9292
select X86_X2APIC if XEN_PVH && X86_64
9393
help
9494
Support running as a Xen Dom0 guest.
95+
96+
config XEN_PV_MSR_SAFE
97+
bool "Always use safe MSR accesses in PV guests"
98+
default y
99+
depends on XEN_PV
100+
help
101+
Use safe (not faulting) MSR access functions even if the MSR access
102+
should not fault anyway.
103+
The default can be changed by using the "xen_msr_safe" boot parameter.

arch/x86/xen/enlighten_pv.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ struct tls_descs {
108108
*/
109109
static DEFINE_PER_CPU(struct tls_descs, shadow_tls_desc);
110110

111+
static __read_mostly bool xen_msr_safe = IS_ENABLED(CONFIG_XEN_PV_MSR_SAFE);
112+
113+
static int __init parse_xen_msr_safe(char *str)
114+
{
115+
if (str)
116+
return strtobool(str, &xen_msr_safe);
117+
return -EINVAL;
118+
}
119+
early_param("xen_msr_safe", parse_xen_msr_safe);
120+
111121
static void __init xen_pv_init_platform(void)
112122
{
113123
/* PV guests can't operate virtio devices without grants. */
@@ -1010,22 +1020,16 @@ static int xen_write_msr_safe(unsigned int msr, unsigned int low,
10101020

10111021
static u64 xen_read_msr(unsigned int msr)
10121022
{
1013-
/*
1014-
* This will silently swallow a #GP from RDMSR. It may be worth
1015-
* changing that.
1016-
*/
10171023
int err;
10181024

1019-
return xen_read_msr_safe(msr, &err);
1025+
return xen_do_read_msr(msr, xen_msr_safe ? &err : NULL);
10201026
}
10211027

10221028
static void xen_write_msr(unsigned int msr, unsigned low, unsigned high)
10231029
{
1024-
/*
1025-
* This will silently swallow a #GP from WRMSR. It may be worth
1026-
* changing that.
1027-
*/
1028-
xen_write_msr_safe(msr, low, high);
1030+
int err;
1031+
1032+
xen_do_write_msr(msr, low, high, xen_msr_safe ? &err : NULL);
10291033
}
10301034

10311035
/* This is called once we have the cpu_possible_mask */

0 commit comments

Comments
 (0)