Received: by 10.213.65.68 with SMTP id h4csp2154680imn; Sun, 8 Apr 2018 21:07:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+3F3e/ATrq/pawSpQX8Bw3XVnPpXI3pmJ5FEtmhvaYDBp3BilXyI3fNGyz+s6zr6DiV40Z X-Received: by 10.98.14.215 with SMTP id 84mr27607105pfo.168.1523246842187; Sun, 08 Apr 2018 21:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523246842; cv=none; d=google.com; s=arc-20160816; b=YolIHEcgTXz+jJUNBxTIKJYEHqZlRujtKCI+DQD1anf4wFAmvPIUFEW4efWholj3Dd RenA7ls8IghUaScOE8JOUoyF1A1AnYtq2LCU401aGfNh3VUqInnPjrkeB/3WgVc/BvZo xcidlMrRqPw+uJm9YytwFggv614naz6QiAByHO+h3v6oT/kQ9OE15imz8yQhGB1UJTKK MmfkeaWHeK0B/gbnzAAHNdzYrbKv3KtKrrGPKFMAVNLfvG0W/PKeT8DZsgjwD0oKkklH NY3k89g5adECfMle3UBUGhgqX67LW4wkiRuUGhW7af/0IgAeaoKkDWZEl9gTa5pUJTsb F2Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=55g3CtRwTRTxkO1SFI12hC8jjFV8xX4m1Tys/Aa5Vhc=; b=uzAkLARaRc+gI6E2zqSBjjvXqfacuIT66HhTA4L18iJHF6jzyYBbxAaIqAoksnAieF SbQi8ZOHWoM0bLP9Bfp2Hz1kI9ictJrB8gylP5m4HIgTsHMaEFXT91SsqJtFAyumOJ0q Vh+O/uMfrUdeW2aJhy1aINi7yvXrdp8KACFpycXdGqwXQfPC+OLRLub2P7DYRl/vCaGU bE7GsB4+o9cL1IGloDF0kPYBb6CNORZhbPTWa6XXS0mXc1sDWXI7GUGz2PJtpF2vC9nU 3RGzUt+z9KSbqFKZctvDWxFA0usJ0HqPPaxZkphOqDcnyii3oGnFX9jTN52C8FOmpQla UcbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=J2aHbb3v; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c143si10335761pfc.197.2018.04.08.21.06.44; Sun, 08 Apr 2018 21:07:22 -0700 (PDT) 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=@microsoft.com header.s=selector1 header.b=J2aHbb3v; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753894AbeDIEBq (ORCPT + 99 others); Mon, 9 Apr 2018 00:01:46 -0400 Received: from mail-co1nam03on0107.outbound.protection.outlook.com ([104.47.40.107]:43410 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753399AbeDIASJ (ORCPT ); Sun, 8 Apr 2018 20:18:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=55g3CtRwTRTxkO1SFI12hC8jjFV8xX4m1Tys/Aa5Vhc=; b=J2aHbb3v23rkerOpaWvbmIxgmXdQc4nK6KpicA1LkIgd1X5FJop+9qbNjKDeo+CqZDTV4MfEtpXcLL5F/AP3+YRV15AfwHDXoCQt+RagJ+XXpUH9gjXq3ZBmMTNBtejT1RA2TO+tquzU6/qOt0GwVA2yW2ueuDOaqbVQrCz0A+4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1046.namprd21.prod.outlook.com (52.132.128.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:17:55 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:17:55 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Gustavo Romero , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 057/189] powerpc/tm: Fix endianness flip on trap Thread-Topic: [PATCH AUTOSEL for 4.15 057/189] powerpc/tm: Fix endianness flip on trap Thread-Index: AQHTz5gmvlbKkkVfE0CUHTfuM7QNIA== Date: Mon, 9 Apr 2018 00:17:30 +0000 Message-ID: <20180409001637.162453-57-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1046;7:3IkQP4oeCiwXpKibZIYT5bTG7dxcre7S50DWUtTxQ5lhHKU8HN6Yk63dKN6ynB2wYn7ACsRSpEJkKBlKjQMPsGEVPvz2feDa7q5J5hAjAT9B472fcY5LokQDl/f2fL83CWpGKicji2sK6YYRDReyQjGEppNSRwCWQzhyGuznoBpEdSXXn5rLyp46194YQlPAXECiojNt3WnCv6+o8YstVWXMAw15ZcseAsxQjSTkCZEjJ1qSyTpIYvTm3FbisegM;20:Ga2zKcr2Ih6HgaPJMcA4Ww2Au6/VZb5VdV7Ds03JtcNZ+6LAWyVdXYOKl9lsqzrbvEhUC6gxLLN5hz/c5SuPNxEuHIJRUmSCyAp4P8vKBZPXnFDhz2zKzS7JeIKATdnc3GqMyed7Hz9e5IBlaufrTl3DjYYvHqIeauBtTMBsgr0= X-MS-Office365-Filtering-Correlation-Id: 7892cb1c-ca87-4ee9-4de2-08d59daf57a2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1046; x-ms-traffictypediagnostic: DM5PR2101MB1046: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1046;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1046; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(376002)(396003)(366004)(39860400002)(199004)(189003)(36756003)(186003)(11346002)(446003)(476003)(2616005)(7736002)(5660300001)(26005)(10290500003)(478600001)(106356001)(6666003)(68736007)(10090500001)(54906003)(3846002)(59450400001)(22452003)(6116002)(86612001)(110136005)(99286004)(86362001)(72206003)(305945005)(76176011)(102836004)(6506007)(486006)(316002)(3280700002)(3660700001)(81166006)(551934003)(81156014)(8676002)(2906002)(14454004)(2900100001)(97736004)(6486002)(8936002)(1076002)(6512007)(6436002)(105586002)(25786009)(4326008)(2501003)(5250100002)(53936002)(66066001)(107886003)(22906009)(217873001)(357404004);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1046;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: fc/Ll1u/0G/KRRVzBVWvhxoshYjGSN31rOfmAme8BjWIJvTotghj2KykETTyZeOshW5CHLY2Vatqia1yVS1r+S0x2WvJZb/idGZhGrxtDDRRUnl6VzML6lp5jUFlknKUyfgUXovROTjK5PZcJHWreGFhA1mY8+O5Z4ur8+fbgzkLDzUl0ObO56Av0sU7K/Fret4/CCyCee4rbIRnVrdLCTJ3MY6c+CqfrPt0sIzli8PMP5pTPkRwKBa+1JU7m7AR4iOe0uKiOWXBNojExR7LnhclevglRAk8vw0RyKA4F0QYedwGsREfYmG7hauuklW0L+yiMdtdQgXqQIWON5FWDgMMB18kKQXs2YQyzLWG91iOWwxT+hyRLhTzkJirz6XUKZblqKFrADCmQhlThcoR2IST2Gp7Xnpt9thwGstOE1Y= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7892cb1c-ca87-4ee9-4de2-08d59daf57a2 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:17:30.6656 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1046 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gustavo Romero [ Upstream commit 1c200e63d055ec0125e44a5e386b9b78aada7eb3 ] Currently it's possible that a thread on PPC64 LE has its endianness flipped inadvertently to Big-Endian resulting in a crash once the process is back from the signal handler. If giveup_all() is called when regs->msr has the bits MSR.FP and MSR.VEC disabled (and hence MSR.VSX disabled too) it returns without calling check_if_tm_restore_required() which copies regs->msr to ckpt_regs->msr if the process caught a signal whilst in transactional mode. Then once in setup_tm_sigcontexts() MSR from ckpt_regs.msr is used, but since check_if_tm_restore_required() was not called previuosly, gp_regs[PT_MSR] gets a copy of invalid MSR bits as MSR in ckpt_regs was not updated from regs->msr and so is zeroed. Later when leaving the signal handler once in sys_rt_sigreturn() the TS bits of gp_regs[PT_MSR] are checked to determine if restore_tm_sigcontexts() must be called to pull in the correct MSR state into the user context. Because TS bits are zeroed restore_tm_sigcontexts() is never called and MSR restored from the user context on returning from the signal handler has the MSR.LE (the endianness bit) forced to zero (Big-Endian). That leads, for instance, to 'nop' being treated as an illegal instruction in the following sequence: tbegin. beq 1f trap tend. 1: nop on PPC64 LE machines and the process dies just after returning from the signal handler. PPC64 BE is also affected but in a subtle way since forcing Big-Endian on a BE machine does not change the endianness. This commit fixes the issue described above by ensuring that once in setup_tm_sigcontexts() the MSR used is from regs->msr instead of from ckpt_regs->msr and by ensuring that we pull in only the MSR.FP, MSR.VEC, and MSR.VSX bits from ckpt_regs->msr. The fix was tested both on LE and BE machines and no regression regarding the powerpc/tm selftests was observed. Signed-off-by: Gustavo Romero Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/kernel/signal_64.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_6= 4.c index 4b9ca3570344..b1b9962db3dd 100644 --- a/arch/powerpc/kernel/signal_64.c +++ b/arch/powerpc/kernel/signal_64.c @@ -207,7 +207,7 @@ static long setup_tm_sigcontexts(struct sigcontext __us= er *sc, elf_vrreg_t __user *tm_v_regs =3D sigcontext_vmx_regs(tm_sc); #endif struct pt_regs *regs =3D tsk->thread.regs; - unsigned long msr =3D tsk->thread.ckpt_regs.msr; + unsigned long msr =3D tsk->thread.regs->msr; long err =3D 0; =20 BUG_ON(tsk !=3D current); @@ -216,6 +216,12 @@ static long setup_tm_sigcontexts(struct sigcontext __u= ser *sc, =20 WARN_ON(tm_suspend_disabled); =20 + /* Restore checkpointed FP, VEC, and VSX bits from ckpt_regs as + * it contains the correct FP, VEC, VSX state after we treclaimed + * the transaction and giveup_all() was called on reclaiming. + */ + msr |=3D tsk->thread.ckpt_regs.msr & (MSR_FP | MSR_VEC | MSR_VSX); + /* Remove TM bits from thread's MSR. The MSR in the sigcontext * just indicates to userland that we were doing a transaction, but we * don't want to return in transactional state. This also ensures --=20 2.15.1