From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755208AbcFQAjw (ORCPT ); Thu, 16 Jun 2016 20:39:52 -0400 Received: from mail-ty1jpn01on0108.outbound.protection.outlook.com ([104.47.93.108]:48250 "EHLO JPN01-TY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754333AbcFQAjr convert rfc822-to-8bit (ORCPT ); Thu, 16 Jun 2016 20:39:47 -0400 X-Greylist: delayed 1141 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 Jun 2016 20:39:46 EDT From: =?iso-2022-jp?B?GyRCP0BFRCEhPjAbKEI=?= To: "sparclinux@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" Subject: [PATCH] sparc64: Swap registers for fault code and address in mna trap Thread-Topic: [PATCH] sparc64: Swap registers for fault code and address in mna trap Thread-Index: AQHRyCuYdvqjH84Kd0e+W0FW7kmFeA== Date: Fri, 17 Jun 2016 00:05:28 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=hikanda@zlab.co.jp; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [25.168.40.4] x-ms-office365-filtering-correlation-id: 34a08abd-f976-400b-7850-08d396431765 x-microsoft-exchange-diagnostics: 1;TYXPR01MB0589;6:IIFzoSgHK1y8uNz2+9tDjA9nYFQJlcZlKnxc6z7O6MDrKPyP/+sQttDXgqZcVn6oRGq8GuLBKEIQtFdVwrdvTNswvd0Lf5feYcI/u5vUsJwf4pngjsFYEFcS1A5b7OWCLFbVp46hpwKiHdYIRubq1FVet9kVJcT6WFd0uDYRnRyKcJlK7TCS6xS7Hxr0Rf1lGpR8197XV8GpsZmIGe9G4cUhUoTUBxgM8bi8Svzle/l3fFubyufH2LwAlQcNBgBi/mBLtZ4q7Vi7w3dumOkX0uUDcrVtOnrCi2vusUOEePEtU77P6uoOEKP3QH1xx8EO;5:KVy9bX0R49ah+/jg6cFG8aYIX7kJvmdwEH6zJ/C4CyvWTHDaWWjzyipX50B90ADZtFvJg7DxHvWLFb6dWrS9nv7T1vN9bUqS8XwttwShyNHrGXhyZ4cPacKEmjx423T/XhbM6SkmAD3Rt1SU2vgu9w==;24:h8e5KcnGN2Ezsj/gEdf0iXgIaGePYHKST+EErDzoRPMRBuOOlBecHV1htUfKeyPSNPHo0yv32dc34lAplsFGz8Yi7IlxR7ISU8U/T9ceYsE=;7:zfqOrYF/StxgSbHBq0/7anUveW16C1HNWCxMaYcihMJWz/nZqnqp+QIAdp4Z2Ob52PsD3sxzmCHfbloFj06SNww73Tk+gFhrm0Yb+31lHqLcgqbA6E6lpWK3DXTQdlsVnPzNfP17XAVwb8JXTaoH4pr2HzqL/656rBmMau7aA5bf8+Ew3BY/ZAjASMS/L8E1G1HvK5rVMkoOu2LfBh+IRg== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:TYXPR01MB0589; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040130)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041072)(6043046);SRVR:TYXPR01MB0589;BCL:0;PCL:0;RULEID:;SRVR:TYXPR01MB0589; x-forefront-prvs: 09760A0505 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(199003)(189002)(2900100001)(101416001)(450100001)(10400500002)(122556002)(8936002)(2501003)(5004730100002)(1730700003)(8676002)(81166006)(2906002)(189998001)(4326007)(5008740100001)(81156014)(77096005)(3280700002)(6116002)(85182001)(87936001)(3846002)(68736007)(33656002)(229853001)(102836003)(5003600100002)(19580405001)(19580395003)(11100500001)(74316001)(54356999)(106356001)(586003)(9686002)(50986999)(86362001)(97736004)(106116001)(105586002)(3660700001)(92566002)(5002640100001)(2351001)(110136002)(74482002)(66066001)(76576001);DIR:OUT;SFP:1102;SCL:1;SRVR:TYXPR01MB0589;H:TYXPR01MB0589.jpnprd01.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;CAT:NONE;LANG:en;CAT:NONE; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: zlab.co.jp X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2016 00:05:28.7154 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 58f17630-b846-437d-ac06-7ecf8a587a66 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYXPR01MB0589 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Hisashi Kanda" I found a logical bug in SPARC code. So, I send this patch. Please check it. This bug may occur in the following. user_rtt_fill_64bit <= If mna trap occurred, call do_mna +-> do_mna <= Mistake storing registers for fault code and address +-> winfix_mna +-> user_rtt_fill_fixup <= Put fault address into thread_info->flag's TI_FAULT_CODE +-> do_sparc64_fault() <= If fault address has FAULT_CODE_ITLB and FAULT_CODE_DTLB bits, call BUG() +-> BUG() If mna trap occured in user_rtt_fill_64bit, then do_mna is called. So, fault address is loaded into %g4, and fault code is loaded into %g5 in do_mna. But, %g4 is stored into thread_info->flag's TI_FAULT_CODE, and %g5 is stored into thread_info->flag's TI_FAULT_ADDR in user_rtt_fill_fixup. This is a mistake. If fault address has FAULT_CODE_ITLB and FAULT_CODE_DTLB bits, BUG() may occur in do_sparc64_fault(). The patch for this bug is the following. Kernel version is Linux 4.7-rc3. Signed-off-by: Hisashi Kanda --- diff --git a/arch/sparc/kernel/misctrap.S b/arch/sparc/kernel/misctrap.S index 34b4933..0cfb367 100644 --- a/arch/sparc/kernel/misctrap.S +++ b/arch/sparc/kernel/misctrap.S @@ -35,7 +35,7 @@ do_mna: ldxa [%g3] ASI_DMMU, %g5 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit membar #Sync - bgu,pn %icc, winfix_mna + bgu,pn %icc, winfix_mna_swap rdpr %tpc, %g3 1: sethi %hi(109f), %g7 diff --git a/arch/sparc/kernel/winfixup.S b/arch/sparc/kernel/winfixup.S index 855019a..8359a1b 100644 --- a/arch/sparc/kernel/winfixup.S +++ b/arch/sparc/kernel/winfixup.S @@ -103,6 +103,11 @@ spill_fixup_dax: add %sp, PTREGS_OFF, %o0 ba,a,pt %xcc, rtrap +winfix_mna_swap: + mov %g4, %g3 ! swapping %g4 and %g5 using %g3 + mov %g5, %g4 ! %g4=SFSR + mov %g3, %g5 ! %g5=SFAR + rdpr %tpc, %g3 winfix_mna: andn %g3, 0x7f, %g3 add %g3, 0x78, %g3