From patchwork Thu Feb 14 10:14:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 1041960 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Cv9jpj9S"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 440XLl607Xz9sMx for ; Thu, 14 Feb 2019 21:14:39 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wjMsQQHUQrdFn3OPWXqCAZX/rtAHocmg2Jl6hpa4uR0=; b=Cv9jpj9SjC1a8E XkuQfrLPzkD8cj2oSfMk6eqwRdZ0tyLVVa1/vtiuqhI7aYnzNfX+9Dyf1EONhhc0JtoCrKNVh/UGv QKAJlVSjPjjL/UcN1VGY8r/lNWyltqS3i/g5meURFoBJCvNomMAqsLVc4iTzxZ0bxLyORuqq+BWgm y/AVauS2NW9szfiNJdFNo8O+Ca3A2kAGx0+/xiexaisriafslvO3UMtaQF+zgXxydaY3JZhQFM4Cv +SAWnndhKcmRmaXWt29/Y1fgBiSE+As+3fFTEWmWqXjkSoiVJ1xHY5ttDTLh0iiWDpjwqPv6m9t3y jQIVIlHwY1QCsBSepGwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1guE2N-0007X4-Ge; Thu, 14 Feb 2019 10:14:35 +0000 Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1guE2K-0007WI-00; Thu, 14 Feb 2019 10:14:32 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D036D20298375; Thu, 14 Feb 2019 11:14:29 +0100 (CET) Date: Thu, 14 Feb 2019 11:14:29 +0100 From: Peter Zijlstra To: Andy Lutomirski Subject: [PATCH] sched/x86: Save [ER]FLAGS on context switch Message-ID: <20190214101429.GD32494@hirez.programming.kicks-ass.net> References: <1c2429a4-9df9-40a3-98e0-51577de4bd6a@arm.com> <20190213131720.GU32494@hirez.programming.kicks-ass.net> <20190213140025.GB6346@brain-police> <20190213142524.GW32494@hirez.programming.kicks-ass.net> <20190213144145.GY32494@hirez.programming.kicks-ass.net> <20190213154532.GQ32534@hirez.programming.kicks-ass.net> <20190213222146.GC32494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dvlasenk@redhat.com, brgerst@gmail.com, Julien Thierry , catalin.marinas@arm.com, jpoimboe@redhat.com, Will Deacon , linux-kernel@vger.kernel.org, valentin.schneider@arm.com, mingo@redhat.com, james.morse@arm.com, luto@kernel.org, hpa@zytor.com, bp@alien8.de, tglx@linutronix.de, torvalds@linux-foundation.org, Ingo Molnar , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org On Wed, Feb 13, 2019 at 02:49:47PM -0800, Andy Lutomirski wrote: > Do we need to backport this thing? Possibly, just to be safe. > The problem can’t be too widespread or we would have heard of it before. Yes, so far we've been lucky. --- Subject: sched/x86: Save [ER]FLAGS on context switch From: Peter Zijlstra Date: Thu Feb 14 10:30:52 CET 2019 Effectively revert commit: 2c7577a75837 ("sched/x86_64: Don't save flags on context switch") Specifically because SMAP uses FLAGS.AC which invalidates the claim that the kernel has clean flags. In particular; while preemption from interrupt return is fine (the IRET frame on the exception stack contains FLAGS) it breaks any code that does synchonous scheduling, including preempt_enable(). This has become a significant issue ever since commit: 5b24a7a2aa20 ("Add 'unsafe' user access functions for batched accesses") provided for means of having 'normal' C code between STAC / CLAC, exposing the FLAGS.AC state. So far this hasn't led to trouble, however fix it before it comes apart. Fixes: 5b24a7a2aa20 ("Add 'unsafe' user access functions for batched accesses") Acked-by: Andy Lutomirski Reported-by: Julien Thierry Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/entry/entry_32.S | 2 ++ arch/x86/entry/entry_64.S | 2 ++ arch/x86/include/asm/switch_to.h | 1 + 3 files changed, 5 insertions(+) --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -650,6 +650,7 @@ ENTRY(__switch_to_asm) pushl %ebx pushl %edi pushl %esi + pushfl /* switch stack */ movl %esp, TASK_threadsp(%eax) @@ -672,6 +673,7 @@ ENTRY(__switch_to_asm) #endif /* restore callee-saved registers */ + popfl popl %esi popl %edi popl %ebx --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -291,6 +291,7 @@ ENTRY(__switch_to_asm) pushq %r13 pushq %r14 pushq %r15 + pushfq /* switch stack */ movq %rsp, TASK_threadsp(%rdi) @@ -313,6 +314,7 @@ ENTRY(__switch_to_asm) #endif /* restore callee-saved registers */ + popfq popq %r15 popq %r14 popq %r13 --- a/arch/x86/include/asm/switch_to.h +++ b/arch/x86/include/asm/switch_to.h @@ -40,6 +40,7 @@ asmlinkage void ret_from_fork(void); * order of the fields must match the code in __switch_to_asm(). */ struct inactive_task_frame { + unsigned long flags; #ifdef CONFIG_X86_64 unsigned long r15; unsigned long r14;