Skip to contentSkip to conversation

solve SMAP/SMEP issues with 32-bit pv guests

PATCH In review He Chen 3 participants 4 messages Aug 9, 2016 – Aug 10, 2016

lore
Share & tools
lore

He Chen

author
#0 lore raw

PATCH 1/1 solve SMAP/SMEP issues with 32-bit pv guests

This patch is going to solve SMAP/SMEP issues with 32-bit pv guests by adding new xen command line options "xen_smap" and "xen_smep".

For the details, please see: https://lists.xen.org/archives/html/xen-devel/2016-06/msg03441.html

I am sorry that I don't have 32-bit PV environment to test this patch, I would really appreciate it if someone could help verify this patch :)

He Chen (1):
xen: enable/disable SMAP/SMEP for Xen itself

 docs/misc/xen-command-line.markdown | 14 ++++++++++++++
 xen/arch/x86/setup.c                | 12 ++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

PATCH 1/1 xen: enable/disable SMAP/SMEP for Xen itself

SMAP/SMEP may affect the 32-bit pv guests.
Users can determine whether turn SMAP/SMEP on for Xen hyperviosr when running 32-bit pv guests.

---
 docs/misc/xen-command-line.markdown | 14 ++++++++++++++
 xen/arch/x86/setup.c                | 12 ++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
docs/misc/xen-command-line.markdown +14 -0
index 3a250cb..a48c4aa 100644
@@ -1434,6 +1434,13 @@ Set the serial transmit buffer size.
 
 Flag to enable Supervisor Mode Execution Protection
 
+### xen_smep
+> `= <boolean>`
+
+> Default: `true`
+
+Flag to enable SMEP for Xen itself
+
 ### smap
 > `= <boolean>`
 
@@ -1441,6 +1448,13 @@ Flag to enable Supervisor Mode Execution Protection
 
 Flag to enable Supervisor Mode Access Prevention
 
+### xen_smap
+> `= <boolean>`
+
+> Default: `true`
+
+Flag to enable SMAP for Xen itself
+
 ### snb\_igd\_quirk
 > `= <boolean> | cap | <integer>`
 
xen/arch/x86/setup.c +10 -2
index 217c775..84debc3 100644
@@ -65,10 +65,18 @@ integer_param("maxcpus", max_cpus);
 static bool_t __initdata opt_smep = 1;
 boolean_param("smep", opt_smep);
 
+/* xen_smep: Enable/disable SMEP for Xen itself (default on). */
+static bool_t __initdata opt_xen_smep = 1;
+boolean_param("xen_smep", opt_xen_smep);
+
 /* smap: Enable/disable Supervisor Mode Access Prevention (default on). */
 static bool_t __initdata opt_smap = 1;
 boolean_param("smap", opt_smap);
 
+/* xen_smap: Enable/disable SMAP for Xen itself (default on). */
+static bool_t __initdata opt_xen_smap = 1;
+boolean_param("xen_smap", opt_xen_smap);
+
 unsigned long __read_mostly cr4_pv32_mask;
 
 /* Boot dom0 in pvh mode */
@@ -1403,12 +1411,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !opt_smep )
         setup_clear_cpu_cap(X86_FEATURE_SMEP);
-    if ( cpu_has_smep )
+    if ( cpu_has_smep && opt_xen_smep )
         set_in_cr4(X86_CR4_SMEP);
 
     if ( !opt_smap )
         setup_clear_cpu_cap(X86_FEATURE_SMAP);
-    if ( cpu_has_smap )
+    if ( cpu_has_smap && opt_xen_smap )
         set_in_cr4(X86_CR4_SMAP);
 
     cr4_pv32_mask = mmu_cr4_features & XEN_CR4_PV32_BITS;
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH] xen: enable/disable SMAP/SMEP for Xen itself

Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 09.08.16 at 11:13, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +7 -0
@@ -1434,6 +1434,13 @@ Set the serial transmit buffer size.
 
 Flag to enable Supervisor Mode Execution Protection
 
+### xen_smep
+> `= <boolean>`
+
+> Default: `true`
+
+Flag to enable SMEP for Xen itself
+
 ### smap
 > `= <boolean>`
 
@@ -1441,6 +1448,13 @@ Flag to enable Supervisor Mode Execution Protection
 
 Flag to enable Supervisor Mode Access Prevention
 

docs/misc/xen-command-line.markdown Flag to enable Supervisor Mode Execution Protection · line 1460

Quoted 10 lines
docs/misc/xen-command-line.markdown +7 -0
+### xen_smap
+> `= <boolean>`
+
+> Default: `true`
+
+Flag to enable SMAP for Xen itself
+
 ### snb\_igd\_quirk
 > `= <boolean> | cap | <integer>`
 

If these were to stay, please obey to the (mostly) alphabetical sorting. But I'd much rather see the "smap=" and "smep=" options enhanced, e.g. with allowing "hvm" as a value alongside the currently permitted boolean indicators.

Quoted 5 lines
docs/misc/xen-command-line.markdown +0 -1
@@ -1403,12 +1411,12 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     if ( !opt_smep )
         setup_clear_cpu_cap(X86_FEATURE_SMEP);
-    if ( cpu_has_smep )

docs/misc/xen-command-line.markdown void __init noreturn __start_xen(unsigned long mbi_p) · line 1422

Quoted 10 lines
docs/misc/xen-command-line.markdown +2 -1
+    if ( cpu_has_smep && opt_xen_smep )
         set_in_cr4(X86_CR4_SMEP);
 
     if ( !opt_smap )
         setup_clear_cpu_cap(X86_FEATURE_SMAP);
-    if ( cpu_has_smap )
+    if ( cpu_has_smap && opt_xen_smap )
         set_in_cr4(X86_CR4_SMAP);
 
     cr4_pv32_mask = mmu_cr4_features & XEN_CR4_PV32_BITS;

It's extremely hard to believe that this would be all it takes:
Already the two cpu_has_smap uses further down in this file would need similar adjustment afaict. Furthermore mmu_cr4_features (which now won't have the two flags set if their use for Xen gets disabled) gets used, among other places, in vmx.c. If indeed no other changes were necessary, the minimum imo would be for you to justify this in the patch description.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to He Chen
Quoted 11 lines · He Chen

This patch is going to solve SMAP/SMEP issues with 32-bit pv guests by adding new xen command line options "xen_smap" and "xen_smep".

For the details, please see: https://lists.xen.org/archives/html/xen-devel/2016-06/msg03441.html

I am sorry that I don't have 32-bit PV environment to test this patch, I would really appreciate it if someone could help verify this patch :)

He Chen (1):
xen: enable/disable SMAP/SMEP for Xen itself

Quoted 6 lines
 docs/misc/xen-command-line.markdown | 14 ++++++++++++++
 xen/arch/x86/setup.c                | 12 ++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

--
1.9.1

There doesn't seem to be any actual content here.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel