From patchwork Sat Aug 18 18:10:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 10569599 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 DB14213B6 for ; Sat, 18 Aug 2018 18:11:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA9EE2A3C2 for ; Sat, 18 Aug 2018 18:11:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD73A2A3D0; Sat, 18 Aug 2018 18:11:24 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1557B2A3C2 for ; Sat, 18 Aug 2018 18:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726368AbeHRVTz (ORCPT ); Sat, 18 Aug 2018 17:19:55 -0400 Received: from mail-cys01nam02on0134.outbound.protection.outlook.com ([104.47.37.134]:49386 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726300AbeHRVTz (ORCPT ); Sat, 18 Aug 2018 17:19:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavesemi.onmicrosoft.com; s=selector1-wavecomp-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nSwpJsT8wFQaIsYGZpytZaMy1SX/9uFUvR3+DfoG4ik=; b=iRQpw6Ic/wAxy1O7h7iZTsbM2zrQkd3m0aiUixLdrJ6DomvRa0bTQ+SkrZcdnB5F5kSwePYDksWz4WRB8bmLqtUiKtbvvTHRNrPTKGyFXChwtvRySBAtHCdtj/H0G3q8GWY4Ss/wORyXc62gP4ng1OiMeqyh+384USQXIy8+mfA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; Received: from pburton-laptop.mipstec.com (4.16.204.77) by BYAPR08MB4935.namprd08.prod.outlook.com (2603:10b6:a03:6a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.22; Sat, 18 Aug 2018 18:11:12 +0000 From: Paul Burton To: linux-mips@linux-mips.org Cc: linux-arch@vger.kernel.org, Arnd Bergmann , James Hogan , Masahiro Yamada , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Burton , Ralf Baechle Subject: [PATCH v8 1/2] kbuild: Allow asm-specific compiler_types.h Date: Sat, 18 Aug 2018 11:10:16 -0700 Message-Id: <20180818181017.1246-2-paul.burton@mips.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180818181017.1246-1-paul.burton@mips.com> References: <20180818181017.1246-1-paul.burton@mips.com> MIME-Version: 1.0 X-Originating-IP: [4.16.204.77] X-ClientProxiedBy: DM5PR21CA0035.namprd21.prod.outlook.com (2603:10b6:3:ed::21) To BYAPR08MB4935.namprd08.prod.outlook.com (2603:10b6:a03:6a::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 192a53bd-524b-47e6-3d34-08d60535fbf0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BYAPR08MB4935; X-Microsoft-Exchange-Diagnostics: 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QkP6Lm1G07120sRoapkm3f8WUZiTxl7dqIkLJ8CHA8dP6u5yH1Vj/H67fyb3tTJ9hUZQ+NqQhiC9tVyl7EgujefJ/ew2/d9Sumn8B;4:9awydkMXl9lOT3btJ/w20wpnxjVmmjYjRv/fKYmqKkUaf31zzeh0vafosvQVFpeO4ol3Gr+h429zwenak+QdJeHv+AvLzNFRlVaj4F3VBVfPIHLunZ5Fo8qB3Bdm9XqcIXMiloLj2r39kHnTNd1h79cqjQCIHk12Bxogusda7hTdim4L8R+c/bF5zjOWulEeq5ZiIbn86DbRZ1lMvXVOnR0nvHV0NjAK5fiAHgb1PmOFePjfJ05+EYDOVbc4RAouwto5Q7CeEH+j3Hp8T3Fxo0cJhyC+Or+heicy/EVo1C5JZGLTVJE2AxZIki8+X07bbtCtHnwvyf9KgyuapuF/p/m9hbBetaRil6XUgZtAYXE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(9452136761055)(162533806227266); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231311)(944501410)(52105095)(93006095)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201708071742011)(7699016);SRVR:BYAPR08MB4935;BCL:0;PCL:0;RULEID:;SRVR:BYAPR08MB4935; X-Forefront-PRVS: 076804FE30 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(376002)(346002)(396003)(136003)(366004)(39840400004)(199004)(189003)(53416004)(47776003)(106356001)(105586002)(14444005)(50466002)(6486002)(6916009)(48376002)(386003)(6506007)(11346002)(956004)(476003)(2906002)(2616005)(8936002)(42882007)(16586007)(486006)(316002)(446003)(2351001)(36756003)(68736007)(66066001)(54906003)(966005)(50226002)(186003)(16526019)(478600001)(26005)(1076002)(51416003)(52116002)(53936002)(97736004)(76176011)(69596002)(6306002)(6512007)(81166006)(8676002)(81156014)(305945005)(44832011)(3846002)(6116002)(7736002)(4326008)(2361001)(5660300001)(25786009);DIR:OUT;SFP:1102;SCL:1;SRVR:BYAPR08MB4935;H:pburton-laptop.mipstec.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;BYAPR08MB4935;23:sokQhFSRy32uSUbIeKrU6egRCVTTI5vgMmP83ylvYLWh2LvmVACR0LXEbAj8AmwY8s9uxEY0//f+OysZF5ZklFTxAM2dz3ix4TaPi6U2p+GkxTX4WGJiP6Fubv4KvYIeTaD8HDVlQEP73eR4XU3WXlBXVl5gkFfZi1SQj0iic61L9P3kAK1MZsuCdqTctRsHlCxWCWNzKA53U2VmSeqX3bXTytNpKGS8yF6dEvuqSdP6D1jgaXep/jvu9efLc2OcvEuB/aGnJ/SVeuKd142GhyRT28jQvKmKJSWQqlspJOK+aMx5RKHYFy+VDBhDYcHognsrwdR7zMmEs4AHuH+2GF4EvnxjITyBm1181OVzXKRk1lYo97HRVXy5xqZLnss+YHi1ASUU5lxJTHUpRrhFkbN46zBHUO3XzWXl8vL7vfUW7OIE7vN3J6+WHO6noRZ1YycN2WyBndCQn9gzQ7Nyf6R71V8tyd+vd8f0fD6YNDi1K2BWSLk0f0ecgtxj9lCb0tRSK651yiBtmH3TC01p+lCZSK1guGZ/3a9Veim3eeb2LNYzXz4ot+N4CyCnE0DLMxUDzWfcO8nSkW87+fZ3U4iGr8iqe1SDwjKjHFIGfbo+UqCH0HI6s+pFgfS7wynNVVYqHxt+toqC5vNdHITcNn+nGWcZbHKfQ6V/HoBr7cKJbxxZ5A7nfmsP063MFc1j51KknrQaR9ScNeSStrktpu3jsYruohAFzQD9ti7s9kO8tkKOFhvXtOiEIWdxQUYv605znl+wVhCjqioEEI2zjZtel582ejFbiG+jIK+Ic08r932J/f06W+5wotuHqKLeB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DGP3EhPMiH31p4P96Iofog5oioPagU4/C1I0AiGTtjJIQ/OnYBvDyRtYDNZqAkU9QIKUR9V9OpZ/26iPh2B/+5AYSLZlD4+/jUKZDB15vj38iulOSVdHIIDI32eC/wSYsg5Ej4+K1PHJURpuRZhRS1zx2wW+uOxttKnmOu6jpl4+5Ux2xlsl/AhHD28cuIWQsEOmd/1SvPoJO8jf1RuZWZD0JVLUrhOt+84BotRNKqm8nO3k3aIC/tH8uVg+OVYMnexKrscdiYxfCWo8CnpaFH+nFDRf2W6EVOCiugeLrtTXJpguP8db3Re9O1AasDg==;5:EKyJfij8qwOGjJX73uDnUdj7LAlR99xiHU98LpFFADKMcQhJH7bgq5+DYEHvpAkBFxE46WAgkPF08OfC0sHXvOnT0WE0iu17ZNoAkj0lug8yLEum8weHcUEvtWIoiQP1A/dSgvDxgHvVK1FU6C6B4/QEeRz2xmmJ4mFkbij2O1Q=;7:8tfw/TxAIX99N0+rkh7qwmZdhAF1zMQ/1F0mFtXLc7XvJ1mRtQ7nVMtyGo58rEFDyZh+bgbCiL6J7sgohlA0AovcNOOf/PhYjntB3u5/dEg4snk/LTIP5SYhcAtZP5RWb/0PUol5z1qyjU8E8uka1OM5PLIODPsFyCNGgnT4INSZ+huKledRYuX/YD5//H2MQKth83iuEiuF3EYvPI0NRx+oYcYDbsFqYgppKkBdlIB7P7X3v/p7Upv8seSYT6Tt SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2018 18:11:12.8203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 192a53bd-524b-47e6-3d34-08d60535fbf0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR08MB4935 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have a need to override the definition of barrier_before_unreachable() for MIPS, which means we either need to add architecture-specific code into linux/compiler-gcc.h or we need to allow the architecture to provide a header that can define the macro before the generic definition. The latter seems like the better approach. A straightforward approach to the per-arch header is to make use of asm-generic to provide a default empty header & adjust architectures which don't need anything specific to make use of that by adding the header to generic-y. Unfortunately this doesn't work so well due to commit a95b37e20db9 ("kbuild: get out of ") which moved the inclusion of linux/compiler.h to cflags using the -include compiler flag. Because the -include flag is present for all C files we compile, we need the architecture-provided header to be present before any C files are compiled. If any C files can be compiled prior to the asm-generic header wrappers being generated then we hit a build failure due to missing header. Such cases do exist - one pointed out by the kbuild test robot is the compilation of arch/ia64/kernel/nr-irqs.c, which occurs as part of the archprepare target [1]. This leaves us with a few options: 1) Use generic-y & fix any build failures we find by enforcing ordering such that the asm-generic target occurs before any C compilation, such that linux/compiler_types.h can always include the generated asm-generic wrapper which in turn includes the empty asm-generic header. This would rely on us finding all the problematic cases - I don't know for sure that the ia64 issue is the only one. 2) Add an actual empty header to each architecture, so that we don't need the generated asm-generic wrapper. This seems messy. 3) Give up & add #ifdef CONFIG_MIPS or similar to linux/compiler_types.h. This seems messy too. 4) Include the arch header only when it's actually needed, removing the need for the asm-generic wrapper for all other architectures. This patch allows us to use approach 4, by including an asm/compiler_types.h header using the -include flag in the same way we do for linux/compiler_types.h, but only if the header actually exists. [1] https://lists.01.org/pipermail/kbuild-all/2018-August/051175.html Signed-off-by: Paul Burton Cc: Arnd Bergmann Cc: James Hogan Cc: Masahiro Yamada Cc: Ralf Baechle Cc: linux-arch@vger.kernel.org Cc: linux-kbuild@vger.kernel.org Cc: linux-mips@linux-mips.org --- Any thoughts anyone? This isn't the prettiest it could possibly be but it's a small change & clearly shouldn't break anything, which are good qualities for a patch fixing build failures that we'd ideally backport as far as 4.16. Changes in v8: - New patch. scripts/Makefile.lib | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 1bb594fcfe12..4e7b41ef029b 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -151,8 +151,11 @@ __a_flags = $(call flags,_a_flags) __cpp_flags = $(call flags,_cpp_flags) endif +c_includes = $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/compiler_types.h) +c_includes += $(srctree)/include/linux/compiler_types.h + c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ - -include $(srctree)/include/linux/compiler_types.h \ + $(addprefix -include ,$(c_includes)) \ $(__c_flags) $(modkern_cflags) \ $(basename_flags) $(modname_flags) From patchwork Sat Aug 18 18:10:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 10569601 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 369C113B6 for ; Sat, 18 Aug 2018 18:11:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24E8D2A3C2 for ; Sat, 18 Aug 2018 18:11:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18EEC2A3D0; Sat, 18 Aug 2018 18:11:34 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 434A92A3C2 for ; Sat, 18 Aug 2018 18:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726300AbeHRVT6 (ORCPT ); Sat, 18 Aug 2018 17:19:58 -0400 Received: from mail-cys01nam02on0134.outbound.protection.outlook.com ([104.47.37.134]:49386 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726265AbeHRVT6 (ORCPT ); Sat, 18 Aug 2018 17:19:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavesemi.onmicrosoft.com; s=selector1-wavecomp-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=axr3lji30FelzXcjd45bcsbNzC0X1BTnSuI1Dn8YaJk=; b=UXiGruUm9nTHiSUvXW3711HQRxyKQ33DARkiV8OQW93SkqJQJOg39Zf9a7Mqoin4bpFZ0jIT0hRr/iAGUk1J6VVSlm6EbzBMNfnTOlO5srLQcMlvMCN88X0JHHkaFf3Mghm59qa4ywk5R1OvWjgMTOndL9kBkHO4nrveVSThh1c= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pburton@wavecomp.com; Received: from pburton-laptop.mipstec.com (4.16.204.77) by BYAPR08MB4935.namprd08.prod.outlook.com (2603:10b6:a03:6a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.22; Sat, 18 Aug 2018 18:11:14 +0000 From: Paul Burton To: linux-mips@linux-mips.org Cc: linux-arch@vger.kernel.org, Arnd Bergmann , James Hogan , Masahiro Yamada , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Burton , Ralf Baechle Subject: [PATCH v8 2/2] MIPS: Workaround GCC __builtin_unreachable reordering bug Date: Sat, 18 Aug 2018 11:10:17 -0700 Message-Id: <20180818181017.1246-3-paul.burton@mips.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180818181017.1246-1-paul.burton@mips.com> References: <20180818181017.1246-1-paul.burton@mips.com> MIME-Version: 1.0 X-Originating-IP: [4.16.204.77] X-ClientProxiedBy: DM5PR21CA0035.namprd21.prod.outlook.com (2603:10b6:3:ed::21) To BYAPR08MB4935.namprd08.prod.outlook.com (2603:10b6:a03:6a::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f39ce75a-adca-46cd-59f4-08d60535fcd0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BYAPR08MB4935; X-Microsoft-Exchange-Diagnostics: 1;BYAPR08MB4935;3:q0ToXm9KHYmsJNDYWLbwOEPvyQ/bvSw0GOptKD8/0NLekdIzGsZEaXWw4NQPnkbUn1wWxAigeQUEC1EUJP6eKJwWh7aYqFlFEpiNZCnZtNMKvcGM8v+Mdug7G80VJxMvUaIvPrWMMan4BhwZl1Xbu9HD4tDnZU9nBCD0xcl544hM44GDheRam8KE51SuqWkPoQrS8R+i1IxeVM+SFJzNUvuQjyVvEi54kIb25Mj/gakWYrMqXT9I3N6skM5cngnq;25:uwVG1Lng0YmCZqe1dW0G/nQr6IOrplLIZ4K+BdQaFJRRMVooqixyda3szVaZ5bS/hj/ERngbmd3wOA/8H9SuIx0mZ9ok/4TaE2O0QWVqM2nEZJYk6LnSF+7fSsMU5W9+UcGKrXudyMKdsgt2RR/KjrC55OSXUUsyACj5xaXztvOqX9GptaeupP+CM0pPKyRloActB44q6+oRGoavYUamoAr6PjLzDkSegl6H2rYCD/fMNHoqp5oibaMy8LkA5ouRakzXxBzcXz+vYzN+fFIv/a4HMSI2We9TckJcqh68d7BbMVo3DO6kGLQ9s/Rki5CvwUXESs6a6w95wrJnWfIoug==;31:7A3cFLN4uA0rNya1uFoJjxIGT8YERe6v+RSPwB64PibLFZ6xRXGzpcY39adX6PzQ+cTjWUaqcAf6D1dgr1O0K+bQh4/AMcao+Ivt+5qG/cOZShy81ALEvkKxN1A8jgA9qKsYsiSZcxAQ0//nwxKg8ki2l2OyT2+G0ke5+9KopAt9P6SzrAZaPvZcqpJpoXuMUITox5MdZY3Ys2usjASuj4WIzqZRistBD9mwa/2lZhg= X-MS-TrafficTypeDiagnostic: BYAPR08MB4935: X-Microsoft-Exchange-Diagnostics: 1;BYAPR08MB4935;20:XBTae1Xb//EsnJRA1t8Dr6bav3L0f1lyycs9mwzUgbFtWJJ1ML1LZKCrgsAy1Nha+ZWrsa63d5eSo3Nnv8uZcpQNLVeSgLAxnUsPNmzD6i06vbCRRwdLvj+br2TLGYS7oc8TdKu99UOUJk4tIkR3o5OdhuzenPOQ3LYDaz2wL5o57hifCxYb/DBFvsnYUhOaKJC0y3H8wiLAOxt0GTUBAElVZtNsbse9KGNjSGIqpWogtbDZtR6TELmguOiqPbI5;4:sEYLW98pK5r554VnW1HegkVvLlFlMcLj0epSd0W5B/BPnub5iBllfTvFTjW7k26pvkyOoX4oU6yR/6V9CbPnQllWeMhNYHEVjCIP1vb5IZZit/hqoWkdtkL1tgwpz9dQZRNt+eY49eSD2nt6nWJX82MxIWBCoxijOLTxz4mLKgOLr7670JQ5lp0TmEwB8k6ZTE/R/D85EndSrrgLhkencivSvfr9XmBOtwW9xiWTN1UzmsauSEbcMa9T9KSBmvfsIIJ81coNnE8rXEhT/mzw3s9/CK2Jhbm+2EWWJ8tmcTGjX68RyPo6+ax1JjnPYEOpYOOBVtUNusv0kgU011WpjN7Ymf3gT9cVjUVza1z8Jwg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(22074186197030)(183786458502308); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231311)(944501410)(52105095)(93006095)(3002001)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201708071742011)(7699016);SRVR:BYAPR08MB4935;BCL:0;PCL:0;RULEID:;SRVR:BYAPR08MB4935; X-Forefront-PRVS: 076804FE30 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(376002)(346002)(396003)(136003)(366004)(39840400004)(199004)(189003)(53416004)(47776003)(106356001)(105586002)(14444005)(50466002)(6486002)(6916009)(48376002)(386003)(6506007)(11346002)(956004)(476003)(2906002)(2616005)(8936002)(42882007)(16586007)(486006)(316002)(446003)(2351001)(36756003)(68736007)(66066001)(54906003)(966005)(50226002)(186003)(16526019)(478600001)(26005)(1076002)(51416003)(52116002)(53936002)(97736004)(76176011)(69596002)(6306002)(6512007)(81166006)(8676002)(81156014)(305945005)(44832011)(3846002)(6116002)(7736002)(4326008)(2361001)(5660300001)(25786009);DIR:OUT;SFP:1102;SCL:1;SRVR:BYAPR08MB4935;H:pburton-laptop.mipstec.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;BYAPR08MB4935;23:v7Ls6GU5X+Q+laqXeNssfS01t+PB4M2jEdN7N8lk+3nKlpnGXs/9DcHBVCDCVc/3AkTMLae4QI8FqRz87wPGDzLB5TTPKvxU1FwhNFlWPo6WYj+3rF+HUbctiSZhAy27/p0aaDzl2UPrFwUqzbMGNEjZ8tGAsOF5LG1JoGf26YErmioxk0dx7lqzd3p7Wr8OfrHFJhc3ON3t6w18JJnfz7bnpPYXxyb+FkDe4VhtIWSrjTTJpBjRuO6JZ65qF20MR16krx/dxfd9I7N8Dhsz0WY5TT5o8t0PDf++QS4xqM2YHJpMG4mNx577/lRVmJEeh1uduVmV/mXgBCNEeQuZwYPVVSRkNjE4Z0taUcHcE6jQ5gUckiJqJG0+yyFeUYiH7/bfLacbTfTpQrvfP1Fdng/tET8p8ZMW1JDLjVNzp7kWJIMorGDdtKqgkO39278rJ+NfCqoo+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FgqZIjiFXUx9pW9u5lPI7ayWSWjl3YV07ezmwDFDbkpRGNbN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: mips.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2018 18:11:14.2891 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f39ce75a-adca-46cd-59f4-08d60535fcd0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 463607d3-1db3-40a0-8a29-970c56230104 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR08MB4935 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some versions of GCC for the MIPS architecture suffer from a bug which can lead to instructions from beyond an unreachable statement being incorrectly reordered into earlier branch delay slots if the unreachable statement is the only content of a case in a switch statement. This can lead to seemingly random behaviour, such as invalid memory accesses from incorrectly reordered loads or stores, and link failures on microMIPS builds. See this potential GCC fix for details: https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html Runtime problems resulting from this bug were initially observed using a maltasmvp_defconfig v4.4 kernel built using GCC 4.9.2 (from a Codescape SDK 2015.06-05 toolchain), with the result being an address exception taken after log messages about the L1 caches (during probe of the L2 cache): Initmem setup node 0 [mem 0x0000000080000000-0x000000009fffffff] VPE topology {2,2} total 4 Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes. Primary data cache 64kB, 4-way, PIPT, no aliases, linesize 32 bytes This is early enough that the kernel exception vectors are not in use, so any further output depends upon the bootloader. This is reproducible in QEMU where no further output occurs - ie. the system hangs here. Given the nature of the bug it may potentially be hit with differing symptoms. The bug is known to affect GCC versions as recent as 7.3, and it is unclear whether GCC 8 fixed it or just happens not to encounter the bug in the testcase found at the link above due to differing optimizations. This bug can be worked around by placing a volatile asm statement, which GCC is prevented from reordering past, prior to the __builtin_unreachable call. That was actually done already for other reasons by commit 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()"), but creates problems for microMIPS builds due to the lack of a .insn directive. The microMIPS ISA allows for interlinking with regular MIPS32 code by repurposing bit 0 of the program counter as an ISA mode bit. To switch modes one changes the value of this bit in the PC. However typical branch instructions encode their offsets as multiples of 2-byte instruction halfwords, which means they cannot change ISA mode - this must be done using either an indirect branch (a jump-register in MIPS terminology) or a dedicated jalx instruction. In order to ensure that regular branches don't attempt to target code in a different ISA which they can't actually switch to, the linker will check that branch targets are code in the same ISA as the branch. Unfortunately our empty asm volatile statements don't qualify as code, and the link for microMIPS builds fails with errors such as: arch/mips/mm/dma-default.s:3265: Error: branch to a symbol in another ISA mode arch/mips/mm/dma-default.s:5027: Error: branch to a symbol in another ISA mode Resolve this by adding a .insn directive within the asm statement which declares that what comes next is code. This may or may not be true, since we don't really know what comes next, but as this code is in an unreachable path anyway that doesn't matter since we won't execute it. Signed-off-by: Paul Burton Fixes: 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()") Cc: James Hogan Cc: Ralf Baechle Cc: Arnd Bergmann Cc: linux-mips@linux-mips.org --- Changes in v8: - Move to asm/compiler_types.h to suit patch 1. - Commit message improvements. - Drop James' SoB since this changed a fair bit since he added it. Changes in v7: - Elaborate on affected GCC versions in comment. Changes in v6: None Changes in v5: - Comment & commit message tweaks. Changes in v4: None Changes in v3: - Forward port to v4.17-rc and update commit message. - Drop stable tag for now. Changes in v2: - Remove generic-y entry. arch/mips/include/asm/compiler_types.h | 39 ++++++++++++++++++++++++++ include/linux/compiler-gcc.h | 2 ++ 2 files changed, 41 insertions(+) create mode 100644 arch/mips/include/asm/compiler_types.h diff --git a/arch/mips/include/asm/compiler_types.h b/arch/mips/include/asm/compiler_types.h new file mode 100644 index 000000000000..cecd5dc48ce2 --- /dev/null +++ b/arch/mips/include/asm/compiler_types.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_COMPILER_TYPES_H__ +#define __ASM_COMPILER_TYPES_H__ + +/* + * With GCC 4.5 onwards we can use __builtin_unreachable to indicate to the + * compiler that a particular code path will never be hit. This allows it to be + * optimised out of the generated binary. + * + * Unfortunately at least GCC 4.6.3 through 7.3.0 inclusive suffer from a bug + * that can lead to instructions from beyond an unreachable statement being + * incorrectly reordered into earlier delay slots if the unreachable statement + * is the only content of a case in a switch statement. This can lead to + * seemingly random behaviour, such as invalid memory accesses from incorrectly + * reordered loads or stores. See this potential GCC fix for details: + * + * https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html + * + * It is unclear whether GCC 8 onwards suffer from the same issue - nothing + * relevant is mentioned in GCC 8 release notes and nothing obviously relevant + * stands out in GCC commit logs, but these newer GCC versions generate very + * different code for the testcase which doesn't exhibit the bug. + * + * GCC also handles stack allocation suboptimally when calling noreturn + * functions or calling __builtin_unreachable(): + * + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 + * + * We work around both of these issues by placing a volatile asm statement, + * which GCC is prevented from reordering past, prior to __builtin_unreachable + * calls. + * + * The .insn statement is required to ensure that any branches to the + * statement, which sadly must be kept due to the asm statement, are known to + * be branches to code and satisfy linker requirements for microMIPS kernels. + */ +#define barrier_before_unreachable() asm volatile(".insn") + +#endif /* __ASM_COMPILER_TYPES_H__ */ diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index f1a7492a5cc8..354d40f7bf80 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -218,7 +218,9 @@ * * Adding an empty inline assembly before it works around the problem */ +#ifndef barrier_before_unreachable #define barrier_before_unreachable() asm volatile("") +#endif /* * Mark a position in code as unreachable. This can be used to