From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH v2 2/3] x86: use optimal NOPs to fill the SMEP/SMAP placeholders Date: Thu, 10 Mar 2016 02:54:32 -0700 Message-ID: <56E1526802000078000DB24B@prv-mh.provo.novell.com> References: <56E14FF502000078000DB232@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartD3E46948.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1adxIj-0000Xf-Sz for xen-devel@lists.xenproject.org; Thu, 10 Mar 2016 09:54:37 +0000 In-Reply-To: <56E14FF502000078000DB232@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper , Keir Fraser , Feng Wu List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartD3E46948.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Alternatives patching code picks the most suitable NOPs for the running system, so simply use it to replace the pre-populated ones. Use an arbitrary, always available feature to key off from, but hide this behind the new X86_FEATURE_ALWAYS. Signed-off-by: Jan Beulich --- v2: Introduce and use X86_FEATURE_ALWAYS. --- a/xen/arch/x86/x86_64/compat/entry.S +++ b/xen/arch/x86/x86_64/compat/entry.S @@ -185,6 +185,7 @@ ENTRY(compat_restore_all_guest) mov %rax, %cr4 .Lcr4_alt_end: .section .altinstructions, "a" + altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, = 12, 0 altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMEP, 12, = \ (.Lcr4_alt_end - .Lcr4_alt) altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMAP, 12, = \ --- a/xen/include/asm-x86/asm_defns.h +++ b/xen/include/asm-x86/asm_defns.h @@ -204,6 +204,7 @@ void ret_from_intr(void); 662: __ASM_##op; \ .popsection; \ .pushsection .altinstructions, "a"; \ + altinstruction_entry 661b, 661b, X86_FEATURE_ALWAYS, 3, 0; \ altinstruction_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3; \ .popsection =20 @@ -215,6 +216,7 @@ void ret_from_intr(void); .pushsection .altinstr_replacement, "ax"; \ 668: call cr4_pv32_restore; \ .section .altinstructions, "a"; \ + altinstruction_entry 667b, 667b, X86_FEATURE_ALWAYS, 5, 0; \ altinstruction_entry 667b, 668b, X86_FEATURE_SMEP, 5, 5; \ altinstruction_entry 667b, 668b, X86_FEATURE_SMAP, 5, 5; \ .popsection --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -162,6 +162,9 @@ #define cpufeat_bit(idx) ((idx) % 32) #define cpufeat_mask(idx) (_AC(1, U) << cpufeat_bit(idx)) =20 +/* An alias of a feature we know is always going to be present. */ +#define X86_FEATURE_ALWAYS X86_FEATURE_LM + #if !defined(__ASSEMBLY__) && !defined(X86_FEATURES_ONLY) #include =20 --=__PartD3E46948.2__= Content-Type: text/plain; name="x86-SMEP-SMAP-NOPs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-SMEP-SMAP-NOPs.patch" x86: use optimal NOPs to fill the SMEP/SMAP placeholders=0A=0AAlternatives = patching code picks the most suitable NOPs for the=0Arunning system, so = simply use it to replace the pre-populated ones.=0A=0AUse an arbitrary, = always available feature to key off from, but=0Ahide this behind the new = X86_FEATURE_ALWAYS.=0A=0ASigned-off-by: Jan Beulich =0A-= --=0Av2: Introduce and use X86_FEATURE_ALWAYS.=0A=0A--- a/xen/arch/x86/x86_= 64/compat/entry.S=0A+++ b/xen/arch/x86/x86_64/compat/entry.S=0A@@ -185,6 = +185,7 @@ ENTRY(compat_restore_all_guest)=0A mov %rax, %cr4=0A = .Lcr4_alt_end:=0A .section .altinstructions, "a"=0A+ = altinstruction_entry .Lcr4_orig, .Lcr4_orig, X86_FEATURE_ALWAYS, 12, 0=0A = altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMEP, 12, = \=0A (.Lcr4_alt_end - .Lcr4_alt)=0A = altinstruction_entry .Lcr4_orig, .Lcr4_alt, X86_FEATURE_SMAP, 12, \=0A--- = a/xen/include/asm-x86/asm_defns.h=0A+++ b/xen/include/asm-x86/asm_defns.h= =0A@@ -204,6 +204,7 @@ void ret_from_intr(void);=0A 662: __ASM_##op= ; \=0A .popsection; = \=0A .pushsection = .altinstructions, "a"; \=0A+ altinstructi= on_entry 661b, 661b, X86_FEATURE_ALWAYS, 3, 0; \=0A altinstruct= ion_entry 661b, 662b, X86_FEATURE_SMAP, 3, 3; \=0A .popsectio= n=0A =0A@@ -215,6 +216,7 @@ void ret_from_intr(void);=0A .pushsecti= on .altinstr_replacement, "ax"; \=0A 668: call = cr4_pv32_restore; \=0A .section = .altinstructions, "a"; \=0A+ altinstructi= on_entry 667b, 667b, X86_FEATURE_ALWAYS, 5, 0; \=0A altinstruction_= entry 667b, 668b, X86_FEATURE_SMEP, 5, 5; \=0A altinstruction_ent= ry 667b, 668b, X86_FEATURE_SMAP, 5, 5; \=0A .popsection=0A--- = a/xen/include/asm-x86/cpufeature.h=0A+++ b/xen/include/asm-x86/cpufeature.h= =0A@@ -162,6 +162,9 @@=0A #define cpufeat_bit(idx) ((idx) % 32)=0A = #define cpufeat_mask(idx) (_AC(1, U) << cpufeat_bit(idx))=0A =0A+/* = An alias of a feature we know is always going to be present. */=0A+#define = X86_FEATURE_ALWAYS X86_FEATURE_LM=0A+=0A #if !defined(__ASSEMBLY__) = && !defined(X86_FEATURES_ONLY)=0A #include =0A =0A --=__PartD3E46948.2__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --=__PartD3E46948.2__=--