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: 10812315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 058CC13A4 for ; Thu, 14 Feb 2019 10:14:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E391928433 for ; Thu, 14 Feb 2019 10:14:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D67E029853; Thu, 14 Feb 2019 10:14:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A14C28433 for ; Thu, 14 Feb 2019 10:14:44 +0000 (UTC) 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-3m; 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-Id: 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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;