Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp42147imu; Tue, 15 Jan 2019 16:10:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN7j/AOSUPnhLNKtEIB9d1/8W/UyAuNOCFvRNZtZqP40pZgAKZc2+QzN7UJcX1Sgd1gY1m6K X-Received: by 2002:a62:9fcf:: with SMTP id v76mr1285370pfk.144.1547597453612; Tue, 15 Jan 2019 16:10:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547597453; cv=none; d=google.com; s=arc-20160816; b=p5bcfnEGA/Xze1M2g2qYHMdwIdGP9kkdOQHEgINEJuCmfYVHgFQZw+epj02hyOjwHX I4bvAMI7wgFgZCc3XpAHWEpdjA/3eenLn3slbkk/i3EazonBiZbel2nxPwk+0ZDzV6kZ 5AcA/lAAcrdom0m0hYoiDbVweX2jm83Jnkdv/Gi2LFjfnvIArPGqX0pOgCbRiZJ1KpIM Vut77oIoWbV+9SkjPX3Xs0tlA6+53pFGsUej5rLMcwkNBNsjz+eHO6mCjyqCwMzOhpwV dbGRB20flXWPVFnJtx78gE+mq82uC7uqOk4fY+QL/d4oziErG4g2UVOZe6kvVY/seIlx Qt9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1F8gRBN+zfyP8xLoAqymaglNp1ui4Win8VhCeP6a5V0=; b=ebG7QERmgoruJThr1CS9eN6+0jtJfza21qrwQjtL/gmrvhKhMkonfKomjL2Mj1UrKd y6Ob6X0gsMc39C1rew4UzPM8TmCBlz2VPtqWP6EsJCOhlWJAl+lB1bPgOmfVIPstzRuN n0m3obbo3X6LemEKHyaNJYVNoalbqHebe0FgYIRHJwzaZ0Ch5i3iNUXnMHCIRLD876L8 sXWRBbEY9qEvl8/Pl1EYoOiotxwqn4wM6xKePfugPqn6TO+ZJdMQKXkmUARHKJaKyKJM /oKJrGlFTU6gP9StUQDrRBpe6zpHdLNa9dcAbR5xj4votldg6oiYMG9xMn+plV4VDYnz RVkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x+0GEGMM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p5si4305425pga.352.2019.01.15.16.09.45; Tue, 15 Jan 2019 16:10:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x+0GEGMM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387417AbfAOQx1 (ORCPT + 99 others); Tue, 15 Jan 2019 11:53:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:33132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733272AbfAOQng (ORCPT ); Tue, 15 Jan 2019 11:43:36 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C1EDC20675; Tue, 15 Jan 2019 16:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570615; bh=SSaqSRbhIu0GJo1FlYZ3TwNMahQ05dCv8d223HPREAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x+0GEGMMWYZGexqF2V3gOuSytJznFAN75FuE1/dPP9TLWlsgdgiAgK5ji5lNEPb/8 0xmvqc9A3Hizt2KGRcmlqkrNdAyQjLaMed5hIxAHmRdO+H3tZG8Pjb0gjrFkdXZsLB n340ljl2WOsceTdbbuje79Dcfsv1xxq8wpeT9lS4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Breno Leitao , =?UTF-8?q?Michal=20Such=C3=A1nek?= , Michael Ellerman Subject: [PATCH 4.20 01/57] powerpc/tm: Unset MSR[TS] if not recheckpointing Date: Tue, 15 Jan 2019 17:35:42 +0100 Message-Id: <20190115154910.811528107@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao commit 6f5b9f018f4c7686fd944d920209d1382d320e4e upstream. There is a TM Bad Thing bug that can be caused when you return from a signal context in a suspended transaction but with ucontext MSR[TS] unset. This forces regs->msr[TS] to be set at syscall entrance (since the CPU state is transactional). It also calls treclaim() to flush the transaction state, which is done based on the live (mfmsr) MSR state. Since user context MSR[TS] is not set, then restore_tm_sigcontexts() is not called, thus, not executing recheckpoint, keeping the CPU state as not transactional. When calling rfid, SRR1 will have MSR[TS] set, but the CPU state is non transactional, causing the TM Bad Thing with the following stack: [ 33.862316] Bad kernel stack pointer 3fffd9dce3e0 at c00000000000c47c cpu 0x8: Vector: 700 (Program Check) at [c00000003ff7fd40] pc: c00000000000c47c: fast_exception_return+0xac/0xb4 lr: 00003fff865f442c sp: 3fffd9dce3e0 msr: 8000000102a03031 current = 0xc00000041f68b700 paca = 0xc00000000fb84800 softe: 0 irq_happened: 0x01 pid = 1721, comm = tm-signal-sigre Linux version 4.9.0-3-powerpc64le (debian-kernel@lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18) ) #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) WARNING: exception is not recoverable, can't continue The same problem happens on 32-bits signal handler, and the fix is very similar, if tm_recheckpoint() is not executed, then regs->msr[TS] should be zeroed. This patch also fixes a sparse warning related to lack of indentation when CONFIG_PPC_TRANSACTIONAL_MEM is set. Fixes: 2b0a576d15e0e ("powerpc: Add new transactional memory state to the signal context") CC: Stable # 3.10+ Signed-off-by: Breno Leitao Tested-by: Michal Suchánek Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/signal_32.c | 18 +++++++++++++----- arch/powerpc/kernel/signal_64.c | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) --- a/arch/powerpc/kernel/signal_32.c +++ b/arch/powerpc/kernel/signal_32.c @@ -1158,11 +1158,11 @@ SYSCALL_DEFINE0(rt_sigreturn) { struct rt_sigframe __user *rt_sf; struct pt_regs *regs = current_pt_regs(); + int tm_restore = 0; #ifdef CONFIG_PPC_TRANSACTIONAL_MEM struct ucontext __user *uc_transact; unsigned long msr_hi; unsigned long tmp; - int tm_restore = 0; #endif /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn = do_no_restart_syscall; @@ -1210,11 +1210,19 @@ SYSCALL_DEFINE0(rt_sigreturn) goto bad; } } - if (!tm_restore) - /* Fall through, for non-TM restore */ + if (!tm_restore) { + /* + * Unset regs->msr because ucontext MSR TS is not + * set, and recheckpoint was not called. This avoid + * hitting a TM Bad thing at RFID + */ + regs->msr &= ~MSR_TS_MASK; + } + /* Fall through, for non-TM restore */ #endif - if (do_setcontext(&rt_sf->uc, regs, 1)) - goto bad; + if (!tm_restore) + if (do_setcontext(&rt_sf->uc, regs, 1)) + goto bad; /* * It's not clear whether or why it is desirable to save the --- a/arch/powerpc/kernel/signal_64.c +++ b/arch/powerpc/kernel/signal_64.c @@ -756,11 +756,23 @@ SYSCALL_DEFINE0(rt_sigreturn) &uc_transact->uc_mcontext)) goto badframe; } - else - /* Fall through, for non-TM restore */ #endif - if (restore_sigcontext(current, NULL, 1, &uc->uc_mcontext)) - goto badframe; + /* Fall through, for non-TM restore */ + if (!MSR_TM_ACTIVE(msr)) { + /* + * Unset MSR[TS] on the thread regs since MSR from user + * context does not have MSR active, and recheckpoint was + * not called since restore_tm_sigcontexts() was not called + * also. + * + * If not unsetting it, the code can RFID to userspace with + * MSR[TS] set, but without CPU in the proper state, + * causing a TM bad thing. + */ + current->thread.regs->msr &= ~MSR_TS_MASK; + if (restore_sigcontext(current, NULL, 1, &uc->uc_mcontext)) + goto badframe; + } if (restore_altstack(&uc->uc_stack)) goto badframe;