From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-3643807-1523235173-2-12864988542814942441 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org', XOriginatingCountry='US' X-Spam-charsets: plain='iso-8859-1' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: stable-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=fm2; t= 1523235172; b=pNBcIYG1+0SZC8vAovfWSiDWkFsKuvhaTbtMDbrfaR18T4yut+ G+XW3X6St6Eb1AWlLgqelTJdXI/C27fXQCJWiJPxe8cCws2akKFLZQrnOw8m/t95 Kmm2qPzqqLwadRXqSo8uvcAS5Fi9Hddui4HPgpchsxp2yGxsBsbTa7FmnYn1D4Jp D8KR5T0ml5ccON3/JcybT2kFMMQwY1RlIlJHdkMJOvOcvkSFNQpFVfL8uqX7O2Lh Bk8HpN0/XzNFmJUq8JY/vmD8Gh7BgeB/XzE9AFXf11JY7lBiekcIvDOOvPW32rtT 6Q4KSjRjUhvoCxx946Fm5ATJHFZZuhGlkinA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=from:to:cc:subject:date:message-id :references:in-reply-to:content-type:content-transfer-encoding :mime-version:sender:list-id; s=fm2; t=1523235172; bh=eYs6vcigFz 1CUWlzAi7UOxb2IfBD50RqdL5VbEUAjvU=; b=noqqIcAvXmWMrI5tkK2vGb8ywa pZlp5jfPOPYbwn8l6clShAw0SbvmcGkiWAD54y+57HoK7K76/Dmp5E/CtoqIKAjh 3HrnfBw7s9FsFdSSVKeSCQJy92wcf+1zR+Fo2tm5J+vGsVg2k7E4ACspyHV9LbiP 6pXUsZGqDAimxZSDtoKS1jiPveF7tv+Z+rTLUsDX+cBmVFOuw5I6qPPVgupKxKGO VG/bcY0cglZZGmLkH5uapHmPrug+3HXqQJKQ0K6PDj96yEpbV56Zfkl2rL0+OhVc 4QrC1NdobVELNNhzEZwCw7vEjgTmRScbed0c0jX7z6t9pfpsg4DnyLR6adbQ== ARC-Authentication-Results: i=1; mx2.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=lxB9tulD x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=reject,has-list-id=yes,d=none) header.from=microsoft.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-cm=none score=0; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=microsoft.com header.result=pass header_is_org_domain=yes; x-vs=clean score=-100 state=0 Authentication-Results: mx2.messagingengine.com; arc=none (no signatures found); dkim=pass (1024-bit rsa key sha256) header.d=microsoft.com header.i=@microsoft.com header.b=lxB9tulD x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=selector1; dmarc=pass (p=reject,has-list-id=yes,d=none) header.from=microsoft.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=stable-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-cm=none score=0; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=microsoft.com header.result=pass header_is_org_domain=yes; x-vs=clean score=-100 state=0 X-ME-VSCategory: clean X-CM-Envelope: MS4wfBeZ/Ah6haBj9XgGV6RWebs7Jv3m0pyD/pWjbAaAIXYr4ZHJsvPPDKtVdVUhAvGZCSCOyQ819QxBD/T7KLVylaCw8Ge8oZ7hQ15rv6hAkqD0Gev0PhTi aEr6eW1kdWIDhTcqCPQ8skuaXuUO2ugVBib9kxCyKAVLqWhx94+SeMCPJLJbxZ82siUEVYuW/iZCsCruITymBVx6z+04usLqi5qmV6vScFtgLfapNBoGWgBu X-CM-Analysis: v=2.3 cv=E8HjW5Vl c=1 sm=1 tr=0 a=UK1r566ZdBxH71SXbqIOeA==:117 a=UK1r566ZdBxH71SXbqIOeA==:17 a=wRwT6uffUbIA:10 a=t_PdEiP4ckcA:10 a=mw6kJ3eo-EIA:10 a=8nJEP1OIZ-IA:10 a=xqWC_Br6kY4A:10 a=Kd1tUaAdevIA:10 a=Lf-vpJhqX20A:10 a=r_1tXGB3AAAA:8 a=WPyIoOwQAAAA:8 a=yMhMjlubAAAA:8 a=JTNdz_s2QjFUoanZVWUA:9 a=wPNLvfGTeEIA:10 a=t8nPyN_e6usw4ciXM-Pk:22 a=S-HzPIwwDS8t1QcwSuWs:22 X-ME-CMScore: 0 X-ME-CMCategory: none Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933421AbeDIAwT (ORCPT ); Sun, 8 Apr 2018 20:52:19 -0400 Received: from mail-by2nam03on0126.outbound.protection.outlook.com ([104.47.42.126]:24363 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932479AbeDIAlY (ORCPT ); Sun, 8 Apr 2018 20:41:24 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Paul Burton , "linux-mips@linux-mips.org" , Ralf Baechle , Sasha Levin Subject: [PATCH AUTOSEL for 3.18 056/101] MIPS: Handle tlbex-tlbp race condition Thread-Topic: [PATCH AUTOSEL for 3.18 056/101] MIPS: Handle tlbex-tlbp race condition Thread-Index: AQHTz5t6/VF1ZzXlukGzrM7ArnXD0g== Date: Mon, 9 Apr 2018 00:41:20 +0000 Message-ID: <20180409004042.164920-6-alexander.levin@microsoft.com> References: <20180409004042.164920-1-alexander.levin@microsoft.com> In-Reply-To: <20180409004042.164920-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;DM5PR2101MB0901;7:62XCOP6wyO0Z4FTdZXyO4H6Ejli/LvZ2EIcbjzqtxHb1Mbd84tC4zWz8rGFXsIcB3WDE4dQCWLXiqLbpW0iA/9pSrTMBSP6MXX+dnzm7Jte0puk0AEh18KIkiS1nyWWLFf+LeUodjueUWg946aPOSptHGt5atsp1RQ+TEP/CHWQ4PvW/2F+2FULDinngZurwJhTjwyvbhgm1hK1q4DffhdRR36wcCx7QYczsYu3UOwnBbHdADP3PrkfUxqmUI6rl;20:ZPsQkEx3kt67owDJcm3pYD9wbfxWSmmuhwvLMwGMj3shXIYbrvaKzTH3hzoiv3OK7hi6Y1DrPaUiQeGL+0RSCFmaL+8afx3qBsQupyx5QwGGcfYoPiHWmQA4mXp8/JLcAtx8OS9Cx0Y5KKcguLz4u911hGUN0xzsSW290Bb9gkQ= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: ef23419d-39f8-4cc8-f025-08d59db29dc3 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0901; x-ms-traffictypediagnostic: DM5PR2101MB0901: 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)(788757137089); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0901;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0901; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(39380400002)(376002)(346002)(396003)(366004)(189003)(199004)(59450400001)(99286004)(68736007)(10290500003)(25786009)(86612001)(6116002)(66066001)(97736004)(3846002)(76176011)(6512007)(6306002)(54906003)(6436002)(4326008)(53936002)(105586002)(110136005)(6486002)(3280700002)(1076002)(107886003)(8676002)(10090500001)(2501003)(966005)(81156014)(81166006)(5660300001)(14454004)(186003)(3660700001)(102836004)(7736002)(2906002)(26005)(5250100002)(36756003)(478600001)(446003)(316002)(6506007)(2616005)(106356001)(8936002)(11346002)(22452003)(2900100001)(86362001)(486006)(476003)(305945005)(72206003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0901;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; x-microsoft-antispam-message-info: pQ0Yc9ZFdEjbJ6qn8yK0DJCui+CBkcdz2etSqyVLRyqIUDtY/FZwFp5VkKPoS1LK8y/MBkk8cscbxQ9myflY/9oiaXZlfnIx4rCbOGzweUbyha/5QxE4lk1xcuwEDCDSmJjgyrSFIBlqeFRI88N52AHKW+SD1FHOgUnuWAv60LUvbD496JMccmFNWJyea/LkAEosKdPKYsYBB86cKpGuLtpFBr1WX7a9xSjzAdiPoJOz/LNsv6egJ3OwDcWiUMy3KjEY/9Q1C2lwxT5aCCkGPmofuqWM2D7D6YyyU3ft0OjOcRLuTnZK/gRbhIkkIfHXrBJfD9HcEd/42OAOvDjaQuzLWu2u+ZYLaV4tabA/B8i4mpESzYivHVF5xC4ATBx/kbunX04O6sNeqVWX10lFgrct8FaFZjnj4t8XA3aMvcM= 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: ef23419d-39f8-4cc8-f025-08d59db29dc3 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:41:20.4865 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0901 Sender: stable-owner@vger.kernel.org X-Mailing-List: stable@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: From: Paul Burton [ Upstream commit f39878cc5b09c75d35eaf52131e920b872e3feb4 ] In systems where there are multiple actors updating the TLB, the potential exists for a race condition wherein a CPU hits a TLB exception but by the time it reaches a TLBP instruction the affected TLB entry may have been replaced. This can happen if, for example, a CPU shares the TLB between hardware threads (VPs) within a core and one of them replaces the entry that another has just taken a TLB exception for. We handle this race in the case of the Hardware Table Walker (HTW) being the other actor already, but didn't take into account the potential for multiple threads racing. Include the code for aborting TLB exception handling in affected multi-threaded systems, those being the I6400 & I6500 CPUs which share TLB entries between VPs. In the case of using RiXi without dedicated exceptions we have never handled this race even for HTW. This patch adds WARN()s to these cases which ought never to be hit because all CPUs with either HTW or shared FTLB RAMs also include dedicated RiXi exceptions, but the WARN()s will ensure this is always the case. Signed-off-by: Paul Burton Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/16203/ Signed-off-by: Ralf Baechle Signed-off-by: Sasha Levin --- arch/mips/mm/tlbex.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c index e3328a96e809..4be16c81be9f 100644 --- a/arch/mips/mm/tlbex.c +++ b/arch/mips/mm/tlbex.c @@ -1838,6 +1838,26 @@ static void build_r3000_tlb_modify_handler(void) } #endif /* CONFIG_MIPS_PGD_C0_CONTEXT */ =20 +static bool cpu_has_tlbex_tlbp_race(void) +{ + /* + * When a Hardware Table Walker is running it can replace TLB entries + * at any time, leading to a race between it & the CPU. + */ + if (cpu_has_htw) + return true; + + /* + * If the CPU shares FTLB RAM with its siblings then our entry may be + * replaced at any time by a sibling performing a write to the FTLB. + */ + if (cpu_has_shared_ftlb_ram) + return true; + + /* In all other cases there ought to be no race condition to handle */ + return false; +} + /* * R4000 style TLB load/store/modify handlers. */ @@ -1874,7 +1894,7 @@ build_r4000_tlbchange_handler_head(u32 **p, struct ua= sm_label **l, iPTE_LW(p, wr.r1, wr.r2); /* get even pte */ if (!m4kc_tlbp_war()) { build_tlb_probe_entry(p); - if (cpu_has_htw) { + if (cpu_has_tlbex_tlbp_race()) { /* race condition happens, leaving */ uasm_i_ehb(p); uasm_i_mfc0(p, wr.r3, C0_INDEX); @@ -1948,6 +1968,14 @@ static void build_r4000_tlb_load_handler(void) } uasm_i_nop(&p); =20 + /* + * Warn if something may race with us & replace the TLB entry + * before we read it here. Everything with such races should + * also have dedicated RiXi exception handlers, so this + * shouldn't be hit. + */ + WARN(cpu_has_tlbex_tlbp_race(), "Unhandled race in RiXi path"); + uasm_i_tlbr(&p); =20 switch (current_cpu_type()) { @@ -2015,6 +2043,14 @@ static void build_r4000_tlb_load_handler(void) } uasm_i_nop(&p); =20 + /* + * Warn if something may race with us & replace the TLB entry + * before we read it here. Everything with such races should + * also have dedicated RiXi exception handlers, so this + * shouldn't be hit. + */ + WARN(cpu_has_tlbex_tlbp_race(), "Unhandled race in RiXi path"); + uasm_i_tlbr(&p); =20 switch (current_cpu_type()) { --=20 2.15.1