Return-path: Received: from userp2130.oracle.com ([156.151.31.86]) by Galois.linutronix.de with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fInH9-0003dD-KH for speck@linutronix.de; Wed, 16 May 2018 05:38:52 +0200 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w4G3af0N136383 for ; Wed, 16 May 2018 03:38:45 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2hx29waw3w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 May 2018 03:38:44 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w4G3citg017491 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 16 May 2018 03:38:44 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4G3ciT1024275 for ; Wed, 16 May 2018 03:38:44 GMT Date: Tue, 15 May 2018 23:38:35 -0400 From: Konrad Rzeszutek Wilk Subject: [MODERATED] Re: [patch 10/15] Hidden 10 Message-ID: <20180516033835.GB26939@char.us.oracle.com> References: <20180513140048.543641807@linutronix.de> <20180513140539.060453691@linutronix.de> MIME-Version: 1.0 In-Reply-To: <20180513140539.060453691@linutronix.de> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: speck@linutronix.de List-ID: > +void > +x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool guest) > { > - u64 host = x86_spec_ctrl_base; > + u64 hostssbd = ssbd_tif_to_spec_ctrl(current_thread_info()->flags); Would it make sense to move the: hostssbd = ssbd_tif_to.. > + u64 msr, host = x86_spec_ctrl_base; > > /* Is MSR_SPEC_CTRL implemented ? */ > - if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) > - return; > - > - /* SSBD controlled in MSR_SPEC_CTRL */ > - if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD)) > - host |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags); > - > - if (host != guest_spec_ctrl) > - wrmsrl(MSR_IA32_SPEC_CTRL, guest_spec_ctrl); > -} > -EXPORT_SYMBOL_GPL(x86_spec_ctrl_set_guest); > - > -/** > - * x86_spec_ctrl_restore_host - Restore host speculation control registers > - * @guest_spec_ctrl: The guest content of MSR_SPEC_CTRL > - * @guest_virt_spec_ctrl: The guest controlled bits of MSR_VIRT_SPEC_CTRL > - * (may get translated to MSR_AMD64_LS_CFG bits) > - * > - * Avoids writing to the MSR if the content/bits are the same > - */ > -void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl) > -{ > - u64 host = x86_spec_ctrl_base; > - > - /* Is MSR_SPEC_CTRL implemented ? */ > - if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) > - return; > - > - /* SSBD controlled in MSR_SPEC_CTRL */ > - if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD)) > - host |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags); > - > - if (host != guest_spec_ctrl) > - wrmsrl(MSR_IA32_SPEC_CTRL, host); > + if (static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) { > + /* SSBD controlled in MSR_SPEC_CTRL */ > + if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD)) > + host |= hostssbd; to here? That is you are reading the ssbd_tif_to_spec_ctrl even if the X86_FEATURE_MSR_SPEC_CTRL hasn't been enabled? (In theory, the compiler has it probably optimized). > + > + if (host != guest_spec_ctrl) { > + msr = guest ? guest_spec_ctrl : host; > + wrmsrl(MSR_IA32_SPEC_CTRL, msr); > + } > + } > } > -EXPORT_SYMBOL_GPL(x86_spec_ctrl_restore_host); > +EXPORT_SYMBOL_GPL(x86_virt_spec_ctrl); > > static void x86_amd_ssb_disable(void) > { >