From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967978AbeAON7o (ORCPT + 1 other); Mon, 15 Jan 2018 08:59:44 -0500 Received: from twosheds.infradead.org ([90.155.92.209]:53862 "EHLO twosheds.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933580AbeAON7f (ORCPT ); Mon, 15 Jan 2018 08:59:35 -0500 Message-ID: <1516024762.22147.173.camel@infradead.org> Subject: Re: [PATCH 3/5] x86/ibrs: Add direct access support for MSR_IA32_SPEC_CTRL From: David Woodhouse To: Peter Zijlstra Cc: Dave Hansen , Ashok Raj , linux-kernel@vger.kernel.org, Thomas Gleixner , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick In-Reply-To: <20180115134500.GB2228@hirez.programming.kicks-ass.net> References: <1515720739-43819-1-git-send-email-ashok.raj@intel.com> <1515720739-43819-4-git-send-email-ashok.raj@intel.com> <20180112095148.GP3040@hirez.programming.kicks-ass.net> <1515751748.22302.421.camel@infradead.org> <20180115134500.GB2228@hirez.programming.kicks-ass.net> Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAG1BMVEUHBwcUFBQpKSlGRkZhYWF9fX2Xl5eysrLMzMxFF+rXAAACaElEQVQ4y21UQXbbIBQE9wJALmAg6ToWON22FrhZthHgbvssUPathC7QWMful2JHSmtWwGg+zPxBCE0DU4QoJQgRgsg4w2gJjBNE8PjFBZgnQMBs+uZ1NQNQjZO3BV4AGDFC0f+l4DBG0VUAM4yv7SO8IgRdHXQ+A78HKL5OAeCfNQV5cHX8DsBUyIJKtYbt98BKaGNCKjfgFVkqYVLbkHKsRsbSCSa0T6npIqLrpRBgQKHUpQmgs9eEKaiUcooE8WWfCGVnBiUcn1uF2XhbfmN9apKnmMP2K4kizKkQWxuaVNOpU2cACIyxO1Po8ETHcXEDMVnozcejkAYA9iaD4pU0ZvNQ8VurNnTuFAYVtuIPUZW25PjDIjQAlGyffIiRQxoWAZBmJ0LTdW2Nyc0iP3DqRhxizvGJkBWZmyFVyZkddWzmBoIBVMpCCJ1CFzl98xav4VJKSSD45KbUT75ixikTphDSRh8+Uz7JLgUTAgAFwzqzjxc/nDY7WUApqY0OMdTwCKZSXplSKkgIRCHElCp8ZnhnKqXuwcNbk1L0VXE+I9alUXoHlLHl3mv7/dWQlJwtjREC7mu9L/U2jQyMUuO2EDS4q9Kl2ddm232bxIE5pjJuVwiljNn/Cfv25/T0cu5cZbwHGVq7h/zp0B4n3S99V/utD+Uo8BiGx9xCsOAV5z7/tjo4Z4z1Lvb90KZ7eFOoOeXOukqF2seo234YYuaQPpRP+cVZU5adT1Edun5Iz3z8fTz3+eSDh0Ip1c7zx1MaijGzTd/3MbRuBHz8cvcVgCMBRpOHvgu59WDhoat+nIZm+LWm9C/aaaGq5DCP9QAAAABJRU5ErkJggg== Content-Type: multipart/signed; micalg="sha-256"; protocol="application/x-pkcs7-signature"; boundary="=-itV7Xq1iDjMkeUjuaews" Date: Mon, 15 Jan 2018 14:59:22 +0100 Mime-Version: 1.0 X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 X-SRS-Rewrite: SMTP reverse-path rewritten from by twosheds.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: --=-itV7Xq1iDjMkeUjuaews Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 2018-01-15 at 14:45 +0100, Peter Zijlstra wrote: > On Fri, Jan 12, 2018 at 10:09:08AM +0000, David Woodhouse wrote: > > static_cpu_has() + asm-goto is NOT SUFFICIENT. > >=C2=A0 > > It's still *possible* for a missed optimisation in GCC to still leave > > us with a conditional branch around the wrmsr, letting the CPU > > speculate around it too. >=20 > OK, so GCC would have to be bloody retarded to mess this up; Like *that's* never happened before? In corner cases where it just gets confused and certain optimisations go out the window? > but would something like the below work for you? >=20 > The usage is like: >=20 > =C2=A0 if (static_branch_unlikely(key)) { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0arch_static_assert(); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0stuff(); > =C2=A0 } >=20 > And then objtool will fail things if the first instruction into that > branch is not immediately after a NOP/JMP patch site (on either the NOP > or the JMP+disp side of things). That seems reasonable; thanks. Bonus points if you can make the arch_static_assert happen() automatically with vile tricks like #define IF_FEATURE(ftr) if (static_cpu_has(ftr)) arch_static_assert,=C2=A0 So then it just becomes =C2=A0 =C2=A0IF_FEATURE(key) { =C2=A0 =C2=A0 =C2=A0 =C2=A0stuff(); =C2=A0 =C2=A0} There might not be a sane way to do that though. And it's OK to have to manually annotate the call sites where this is for correctness and not purely optimisation. --=-itV7Xq1iDjMkeUjuaews Content-Type: application/x-pkcs7-signature; name="smime.p7s" Content-Disposition: attachment; filename="smime.p7s" Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCCEFQw ggUxMIIEGaADAgECAhBNRhEyk/HZ7naOeTHWrzuAMA0GCSqGSIb3DQEBCwUAMIGXMQswCQYDVQQG EwJHQjEbMBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRowGAYD VQQKExFDT01PRE8gQ0EgTGltaXRlZDE9MDsGA1UEAxM0Q09NT0RPIFJTQSBDbGllbnQgQXV0aGVu dGljYXRpb24gYW5kIFNlY3VyZSBFbWFpbCBDQTAeFw0xNzEyMjEwMDAwMDBaFw0xODEyMjEyMzU5 NTlaMCQxIjAgBgkqhkiG9w0BCQEWE2R3bXcyQGluZnJhZGVhZC5vcmcwggEiMA0GCSqGSIb3DQEB AQUAA4IBDwAwggEKAo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