Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754112AbbDTRJv (ORCPT ); Mon, 20 Apr 2015 13:09:51 -0400 Received: from smtp.citrix.com ([66.165.176.89]:60331 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753822AbbDTRJu (ORCPT ); Mon, 20 Apr 2015 13:09:50 -0400 X-IronPort-AV: E=Sophos;i="5.11,610,1422921600"; d="scan'208";a="254776731" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , , , "Konrad Rzeszutek Wilk" , Boris Ostrovsky , David Vrabel , "Rusty Russell" , Subject: [PATCH] [RFC] x86/cpu: Fix SMAP check in PVOPS environments Date: Mon, 20 Apr 2015 18:09:42 +0100 Message-ID: <1429549782-12962-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2808 Lines: 69 There appears to be no formal statement of what pv_irq_ops.save_fl() is supposed to return precisely. Native returns the full flags, while lguest and Xen only return the Interrupt Flag, and both have comments by the implementations stating that only the Interrupt Flag is looked at. This may have been true when initially implemented, but no longer is. To make matters worse, the Xen PVOP leaves the upper bits undefined, making the BUG_ON() undefined behaviour. Experimentally, this now trips for 32bit PV guests on Broadwell hardware. The BUG_ON() is consistent for an individual build, but not consistent for all builds. It has also been a sitting timebomb since SMAP support was introduced. Use native_save_fl() instead, which will obtain an accurate view of the AC flag. Signed-off-by: Andrew Cooper CC: Thomas Gleixner CC: Ingo Molnar CC: H. Peter Anvin CC: x86@kernel.org CC: linux-kernel@vger.kernel.org CC: Konrad Rzeszutek Wilk CC: Boris Ostrovsky CC: David Vrabel CC: xen-devel CC: Rusty Russell CC: lguest@lists.ozlabs.org --- This patch is RFC because I am not certain that native_save_fl() is necessarily the correct solution on lguest, but it does seem that setup_smap() wants to check the actual AC bit, rather than an idealised value. A different approach, given the dual nature of the AC flag now is to gate setup_smap() on a kernel rpl of 0. SMAP necessarily can't be used in a paravirtual situation where the kernel runs in cpl > 0. Another different approach would be to formally state that pv_irq_ops.save_fl() needs to return all the flags, which would make local_irq_save() safe to use in this circumstance, but that makes a hotpath longer for the sake of a single boot time check. --- arch/x86/kernel/cpu/common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index a62cf04..4f2fded 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -291,10 +291,9 @@ __setup("nosmap", setup_disable_smap); static __always_inline void setup_smap(struct cpuinfo_x86 *c) { - unsigned long eflags; + unsigned long eflags = native_save_fl(); /* This should have been cleared long ago */ - raw_local_save_flags(eflags); BUG_ON(eflags & X86_EFLAGS_AC); if (cpu_has(c, X86_FEATURE_SMAP)) { -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/