From patchwork Thu Mar 10 18:19:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 63743 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp595757lbc; Thu, 10 Mar 2016 10:21:45 -0800 (PST) X-Received: by 10.98.79.9 with SMTP id d9mr6936710pfb.46.1457634105082; Thu, 10 Mar 2016 10:21:45 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ry2si7510037pab.159.2016.03.10.10.21.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Mar 2016 10:21:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ae5CB-0002MQ-22; Thu, 10 Mar 2016 18:20:23 +0000 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ae5C7-0001CZ-AY for linux-arm-kernel@lists.infradead.org; Thu, 10 Mar 2016 18:20:21 +0000 Received: by mail-qg0-x236.google.com with SMTP id w104so77697214qge.1 for ; Thu, 10 Mar 2016 10:19:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=HAWjJ6XKomT5bHM/2X1oIrDsGBJAr5hznv5/ZabddrA=; b=K2UnH5Uvz4cj91zXxptlqHM+Zt7QXq0lbi9eX1W2X8CDhJUHy8aMDXK9LcyxMeOgBl 2zJSN8cLndmK7jmbTP4z593pYiPVNVfhXm7jC/LtmrBEFJQuifUTGjG/EK+MYDUEmo+0 czd2ZpHlIf1or1fihFv7Sa6/kd9NrkFmmFSXs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=HAWjJ6XKomT5bHM/2X1oIrDsGBJAr5hznv5/ZabddrA=; b=SlVXTV5tBNM1SbQjwYdgNVZEx2+XLdB0PXyNL+QMgeFwK/aE4Mn0Ss6OTcXUj0Gw92 O8hAac/GklrZBi5ffiesWTKtF/BNMSLQodY9Pd5uCERl0CuMBnSHntMr/a4S0Waf0eQ8 SsFtJSIQW8j0MTI85VwcoBmbST29pdAXz+h/0YJZ0GXBjOTGXOBt70TQ8Mv3nd1OpZW6 vA4/h80iWCu5HHkCsRmuhVpO6CFBOH94Moz0q6CrQhHNf8scw5/4opHfsygotTfRt8yq Vb+FQKhf9eHn5/hDs4mN4bTw589UZg3GQX/kVFx3LOyFxkNcrT96El41KD5GeDNxKfPn Tx+g== X-Gm-Message-State: AD7BkJIgn4W0XGI/pXVEU4f9CRRhG9a47RBQZDnCBmBgeTsjPUJuAv0RUyQz2Y34ED4i//qH X-Received: by 10.140.228.68 with SMTP id y65mr6386146qhb.78.1457633996731; Thu, 10 Mar 2016 10:19:56 -0800 (PST) Received: from xanadu.home ([2607:fa48:6e39:d410:feaa:14ff:fea7:ed77]) by smtp.gmail.com with ESMTPSA id f83sm2190295qkb.25.2016.03.10.10.19.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Mar 2016 10:19:55 -0800 (PST) Date: Fri, 11 Mar 2016 01:19:54 +0700 (ICT) From: Nicolas Pitre To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] harden idiv patching against undefined gcc behavior Message-ID: User-Agent: Alpine 2.20 (LFD 67 2015-01-07) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160310_102019_596958_59DF306E X-CRM114-Status: GOOD ( 12.06 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400d:c04:0:0:0:236 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcin Juszkiewicz , Arnd Bergmann Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org It was reported that a kernel with CONFIG_ARM_PATCH_IDIV=y stopped booting when compiled with the upcoming gcc 6. Turns out that turning a function address into a writable array is undefined and gcc 6 decided it was OK to omit the store to the first word of the function while still preserving the store to the second word. Even though gcc 6 is now fixed to behave more coherently, it is a mystery that gcc 4 and gcc 5 actually produce wanted code in the kernel. And in fact the reduced test case to illustrate the issue does indeed break with gcc < 6 as well. In any case, let's guard the kernel against undefined compiler behavior by hiding the nature of the array location as suggested by gcc developers. Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70128 Signed-off-by: Nicolas Pitre Reported-by: Marcin Juszkiewicz _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 7d0cba6f1c..c86ea8aac2 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -430,11 +430,13 @@ static void __init patch_aeabi_idiv(void) pr_info("CPU: div instructions available: patching division code\n"); fn_addr = ((uintptr_t)&__aeabi_uidiv) & ~1; + asm ("" : "+g" (fn_addr)); ((u32 *)fn_addr)[0] = udiv_instruction(); ((u32 *)fn_addr)[1] = bx_lr_instruction(); flush_icache_range(fn_addr, fn_addr + 8); fn_addr = ((uintptr_t)&__aeabi_idiv) & ~1; + asm ("" : "+g" (fn_addr)); ((u32 *)fn_addr)[0] = sdiv_instruction(); ((u32 *)fn_addr)[1] = bx_lr_instruction(); flush_icache_range(fn_addr, fn_addr + 8);