From patchwork Mon Mar 20 17:13:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 665199 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp1234244wrv; Mon, 20 Mar 2023 10:13:47 -0700 (PDT) X-Google-Smtp-Source: AK7set/HXLkZJ+E9g+Ay17nU1W4+hPlWtyYtWtSv54Y8Y+QBHIsCU58RkvLoHMV7g9nipy3ZpeCy X-Received: by 2002:a05:6214:21c1:b0:5cc:75c7:8f19 with SMTP id d1-20020a05621421c100b005cc75c78f19mr6963159qvh.10.1679332427288; Mon, 20 Mar 2023 10:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679332427; cv=none; d=google.com; s=arc-20160816; b=C4mGcRES7xWjnkxsF6YzoU7PuE9uvnVVO84aldgzTYcL4SpKLF5667EY7pEQVKjfdb LB22QsRUx5LkjAF72sXPLR02ndgPs8dUBRgCUpIoCo2mV9xCfa5otL0riKjBUagL7/Sz XjcP9w7ymN8qu4OoXTh3sNQjczQ8Y7Z0MDAhywUqxBL/s/iKI7lC+Oh/Z0Q8XDXDeubD UAGuS1S7OMPIFi1oSOhP5s5vw3fNNKBNxOyFvnLWWcu6vgyGDpx0piL6AR0HmnzxS1g3 kI47vbSv9TJFnCEDWY9blUrbn4K5vPi/4bJOUz7vVCTMmDYRgFyZ/FGmU+wej7r9bwwc 5J3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=RMGJ0kZNHVXsEyG+3KNgrxT7AzMfDOjfUPQQSdgBG/E=; b=xy/Hq5W2pixnWGUVMS7AIaK+mkahM7Xc72yvYmmz/RAnHELdTxQgSctCPEzQAL/xaj Z+rKRIxrTQp5kxxz4iUsKP3fxgr/Z9GJx6v/nJx9SumYYNBWthJV7DSnotyY15E0me71 deZiWaZrLpWbFhsqG5hASjKBjlEH6kTuWJGwAwNNlUGJHJ+95O3t6EvHxHM8NBaxgBZW xsigVXrC/5FZyeB0wt3NVKtQkIl6atk+2pNN9gIR8A79ZJR4xTYjkVaV7p5aFCT50s7w wRX4XV23sCvYqGM5B6W64tGJc5OebgaL3gOyqr+pzPG7H1JwyfUOX8N2H8s9CoiLfPsG LhiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YZNf7VVf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id y8-20020a05620a44c800b00742cd14db50si6975544qkp.261.2023.03.20.10.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 10:13:47 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YZNf7VVf; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D4F8185900; Mon, 20 Mar 2023 18:13:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YZNf7VVf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D473084EC7; Mon, 20 Mar 2023 18:13:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E028385AEC for ; Mon, 20 Mar 2023 18:13:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x534.google.com with SMTP id r11so49617020edd.5 for ; Mon, 20 Mar 2023 10:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679332418; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RMGJ0kZNHVXsEyG+3KNgrxT7AzMfDOjfUPQQSdgBG/E=; b=YZNf7VVfBn3QFwm7GKvK3MG+0ejL6dxE+hDH8exImLlj1xQjKgPs5yuSdWOBXGV0+6 PnzruhUz8XqSRuzKKlQJAaSiYCd8rckV3eY4mP7LYhR9wU7Zfatyy2b6CZATyzHexot9 vdoaEwMraQwASAn7Phf63lz3H+fSk90pbz9sJK5iCllMSprm2P7RNQYUaQvoxQlIli7j MhuOlnizHYCJw6Wmz4lr2GubGUu6jfpZpvVQHxgkrMVUUUwvhaqhMHzzlH2t2trQc3NZ eP5LtlFILLZET7teZSDON4dOmI3dDyKoILppnIjl88vTZ7hLidKOWyB+2bBdG8VWON7Z NGAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679332418; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RMGJ0kZNHVXsEyG+3KNgrxT7AzMfDOjfUPQQSdgBG/E=; b=weeUH9wZybMaFgSMW5mT0wdUJMX7iW6pP8uFjMitlFKf2CLAQTA0sOfzGg73opSOqJ 6tU6Jk0R/NgXDWjO9T9L+ZksublyQDdvcPjsRJVSiXjujKBXVOSqixaauc9AdLEDwsCz a26ZI3wNnBjtHyBhxNx66nsOe1C/cfS0uxJX6PeHKZEvc6CXn9QjFnRhjca0MBEZE2hP XTnjznvpe6ftv0nRM+t90JRxEqFf3VJKimxh/Jmrb9MTs+O3CjrUkMK7RlAfFzqW9KWd LTrFpbdO6E87MM7JoKMLmwLyimNDINTh/5uJgAdtUl/ZlZqUc/KIaIO4BbHFvj1NipIt TGmA== X-Gm-Message-State: AO0yUKXytKtbJUQHabmoD2XHaDxDgiWlVu0o6VBQp/o94dps5x6UL6Il K8wnf6E11veQkSrcY+oVszXIcSYh4wRGdgbYvs8= X-Received: by 2002:a17:906:22d2:b0:8bf:e95c:467b with SMTP id q18-20020a17090622d200b008bfe95c467bmr10062475eja.63.1679332418422; Mon, 20 Mar 2023 10:13:38 -0700 (PDT) Received: from localhost.localdomain (ppp176092130041.access.hol.gr. [176.92.130.41]) by smtp.gmail.com with ESMTPSA id q7-20020a170906b28700b00931c887372dsm4541121ejz.107.2023.03.20.10.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 10:13:38 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: heinrich.schuchardt@canonical.com, Ilias Apalodimas , Tom Rini , Simon Glass Subject: [PATCH] efi_loader: define allow_unaligned as 'asm volatile' Date: Mon, 20 Mar 2023 19:13:34 +0200 Message-Id: <20230320171335.1368308-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Tom reports that compiling with LTO & EFI breaks armv7 and arm11* builds. The reason is that LTO (maybe a binutils bug?) replaces the asm version of allow_unaligned() with the __weak definition of the function. As a result EFI code ends up running with unaligned accesses disabled and eventually crashes. allow_unaligned() hardware specific variants are usually defined in .S files. Switching those to inline assembly fixes the problem and the linker keeps the correct version in the final binary Reported-by: Tom Rini Signed-off-by: Ilias Apalodimas --- This is an alternative approach to https://lore.kernel.org/u-boot/ZBRy1oSZ5iVFqrdV@hera/ since enabling unaligned accesses by default has been rejected in the past arch/arm/cpu/arm11/Makefile | 4 ---- arch/arm/cpu/arm11/cpu.c | 13 +++++++++++++ arch/arm/cpu/arm11/sctlr.S | 25 ------------------------- arch/arm/cpu/armv7/Makefile | 1 - arch/arm/cpu/armv7/cpu.c | 11 +++++++++++ arch/arm/cpu/armv7/sctlr.S | 22 ---------------------- 6 files changed, 24 insertions(+), 52 deletions(-) delete mode 100644 arch/arm/cpu/arm11/sctlr.S delete mode 100644 arch/arm/cpu/armv7/sctlr.S -- 2.39.2 diff --git a/arch/arm/cpu/arm11/Makefile b/arch/arm/cpu/arm11/Makefile index 5dfa01ae8d05..5d721fce12b5 100644 --- a/arch/arm/cpu/arm11/Makefile +++ b/arch/arm/cpu/arm11/Makefile @@ -4,7 +4,3 @@ # Wolfgang Denk, DENX Software Engineering, wd@denx.de. obj-y = cpu.o - -ifneq ($(CONFIG_SPL_BUILD),y) -obj-$(CONFIG_EFI_LOADER) += sctlr.o -endif diff --git a/arch/arm/cpu/arm11/cpu.c b/arch/arm/cpu/arm11/cpu.c index ffe35111d589..b19c4fc4a6c2 100644 --- a/arch/arm/cpu/arm11/cpu.c +++ b/arch/arm/cpu/arm11/cpu.c @@ -111,3 +111,16 @@ void enable_caches(void) #endif } #endif + +#if !IS_ENABLED(CONFIG_SPL_BUILD) +void allow_unaligned(void) +{ + asm volatile( + "mrc p15, 0, r0, c1, c0, 0\n" //load system control register + "orr r0, r0, #1 << 22\n" //set unaligned data support flag + "bic r0, r0, #2\n" //clear aligned flag + "mcr p15, 0, r0, c1, c0, 0\n" // write system control register + "bx lr\n" //return + ); +} +#endif diff --git a/arch/arm/cpu/arm11/sctlr.S b/arch/arm/cpu/arm11/sctlr.S deleted file mode 100644 index 74a7fc4a25b6..000000000000 --- a/arch/arm/cpu/arm11/sctlr.S +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Routines to access the system control register - * - * Copyright (c) 2019 Heinrich Schuchardt - */ - -#include - -/* - * void allow_unaligned(void) - allow unaligned access - * - * This routine sets the enable unaligned data support flag and clears the - * aligned flag in the system control register. - * After calling this routine unaligned access does no longer leads to a - * data abort or undefined behavior but is handled by the CPU. - * For details see the "ARM Architecture Reference Manual" for ARMv6. - */ -ENTRY(allow_unaligned) - mrc p15, 0, r0, c1, c0, 0 @ load system control register - orr r0, r0, #1 << 22 @ set unaligned data support flag - bic r0, r0, #2 @ clear aligned flag - mcr p15, 0, r0, c1, c0, 0 @ write system control register - bx lr @ return -ENDPROC(allow_unaligned) diff --git a/arch/arm/cpu/armv7/Makefile b/arch/arm/cpu/armv7/Makefile index 653eef8ad79e..ca50f6e93e10 100644 --- a/arch/arm/cpu/armv7/Makefile +++ b/arch/arm/cpu/armv7/Makefile @@ -13,7 +13,6 @@ obj-y += syslib.o obj-$(CONFIG_SYS_ARM_MPU) += mpu_v7r.o ifneq ($(CONFIG_SPL_BUILD),y) -obj-$(CONFIG_EFI_LOADER) += sctlr.o obj-$(CONFIG_ARMV7_NONSEC) += exception_level.o endif diff --git a/arch/arm/cpu/armv7/cpu.c b/arch/arm/cpu/armv7/cpu.c index 68807d209978..9742fa65e3cf 100644 --- a/arch/arm/cpu/armv7/cpu.c +++ b/arch/arm/cpu/armv7/cpu.c @@ -83,3 +83,14 @@ int cleanup_before_linux(void) { return cleanup_before_linux_select(CBL_ALL); } + +#if !IS_ENABLED(CONFIG_SPL_BUILD) +void allow_unaligned(void) +{ + asm volatile( + "mrc p15, 0, r0, c1, c0, 0\n" //load system control register + "bic r0, r0, #2\n" //clear aligned flag + "mcr p15, 0, r0, c1, c0, 0\n" //write system control register + ); +} +#endif diff --git a/arch/arm/cpu/armv7/sctlr.S b/arch/arm/cpu/armv7/sctlr.S deleted file mode 100644 index bd56e41afe18..000000000000 --- a/arch/arm/cpu/armv7/sctlr.S +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Routines to access the system control register - * - * Copyright (c) 2018 Heinrich Schuchardt - */ - -#include - -/* - * void allow_unaligned(void) - allow unaligned access - * - * This routine clears the aligned flag in the system control register. - * After calling this routine unaligned access does no longer lead to a - * data abort but is handled by the CPU. - */ -ENTRY(allow_unaligned) - mrc p15, 0, r0, c1, c0, 0 @ load system control register - bic r0, r0, #2 @ clear aligned flag - mcr p15, 0, r0, c1, c0, 0 @ write system control register - bx lr @ return -ENDPROC(allow_unaligned)