From patchwork Fri Mar 17 13:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 664542 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp406298wrv; Fri, 17 Mar 2023 06:43:13 -0700 (PDT) X-Google-Smtp-Source: AK7set+KDTEhSU6OxJwMpeA95hbqd57lKH14Mk8YLtuR0k0He/r54QpymByl6pwicu47lP1f0zrZ X-Received: by 2002:a05:622a:30d:b0:3bf:c407:10ca with SMTP id q13-20020a05622a030d00b003bfc40710camr12690923qtw.10.1679060593673; Fri, 17 Mar 2023 06:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679060593; cv=none; d=google.com; s=arc-20160816; b=AbY8cK4WRBJA47+DA5p9SZG7ZARIRAz+YiMLcwuO+UQRXw8tfrlaSxDu8aPpr0tVUW BZqG9kKxkHdJ0J3f3bDo3FuIMi0SZ+4hsV+EdTUf4SuFcTNe6AvtLwosTBc6hupkoTeX eWoEw9zvItGu1D6fc4MfDqdXEXm6/O27e6ykCRpqKvkysrWCblNoAFKQIkoJEM4iGmjA hlY9cBQ3oQxdayusWMKal6JL8M/FsoSNJ420mKUjzGj2R1YWBOFNaWrBYU5MB3MaMTXG IbXfxFFadc1uxOZ8Iyv95ch8KicfzMyNC74y7vEt4Q8OxR1/oUsEJkndm0KI1CMvdpuj TUGw== 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=aD1/8bSMBk3BUuwBWCNuvnn4qHTFeSoGD7JKCn9/RXM=; b=ZVCcVuqrb+iaEBu+2g1H98HbC0k3okQFuQv2wrPrziYHfqakgh+so9ldnr8RxXuqsO c9QmoiGx0bFAM2SQI32+tSeo3ukJO/Hqw2kQ0ua1cQE038VuDQZk8TQWZSrVOvKbHqMv +XcQvHm3TIUdMabhBFhjdOAu+zWBA0cRFlmwZf4oXDnM/efIJx0ttVssGClnNC0WIomg eKClZ6/0IM9j/Vy/9zcu2uoEjCFjHrKJiFuyz8XprVEElv8xZQsrSBq3obQuearnQVgS 9HvRMgc6XfpWUdIJCy+0wF/aPy0MaNerVmm0rLcN/PlHFfL6H+4QSfrtp4Zod6nqESiQ Tn3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJkdFRXl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id y78-20020a376451000000b0073ede8b345dsi1530051qkb.642.2023.03.17.06.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 06:43:13 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AJkdFRXl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 441DD85A9C; Fri, 17 Mar 2023 14:43:09 +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="AJkdFRXl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C963A85A5F; Fri, 17 Mar 2023 14:43:07 +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-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (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 594B185B2A for ; Fri, 17 Mar 2023 14:43:04 +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-x536.google.com with SMTP id x3so20467166edb.10 for ; Fri, 17 Mar 2023 06:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1679060584; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=aD1/8bSMBk3BUuwBWCNuvnn4qHTFeSoGD7JKCn9/RXM=; b=AJkdFRXljuifz2G+sIJJh9YPLNeChEKpk9d2fO3EGuv/Q8ladTDjYA2+ZgnN7SZMNX 9WFoM6Vuc4KP7+G+r2jjE5yq2VpUtcTNaDuvfRJ+C8d9ONNjbPl3IZDL6dDYu6Y2dkPY nSp4k9igh01TICOImRVev9UkhDk2CsgEejjM/VIwZjnuQHpnbWsfi3lLZZCZp6X7P/em lIgBxdMfzoX0RKTFgdQOvpffL+bP2foQKKDhF0OZ45HNHwDwkCTbeTPWXA9FXh6AgT9w 6NtVPKWmfa8h3eYL4xV5b6uNp18YbfYaBilq5vG6MfPDsVloGwihnUOm12rgqS/FOcnW wdWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679060584; 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=aD1/8bSMBk3BUuwBWCNuvnn4qHTFeSoGD7JKCn9/RXM=; b=7McGYb7X5hKBmUbLo80AVTJ1UZF/foTpsiYcibGlDTys2mFUvUru7tfzd7ZEGGAONh VlV5dreEYxEF96NyvRORsGOXJK3ISk3Nq8fy9EVu5hZ6fWyygJGTA8U/NAvbFquUTuY6 9qzSsU7NmZaowK0jtyFlZjVfmyPFKYQCbuVqUwTDM/UOpRpTnqxW4EftDtHNJtzUn1II A88bhFETAofC+q0GeVOYv7qwlZcA2D7jwUzhXMMY103QWWLUQvhph9VDktnzT3PwtF5/ 6upbHcQQufnXwEIaCvPiwua7i1SCuksrZY3W/vX55vdacqqI2ki6YfshEj8wlpoldpjG YeeA== X-Gm-Message-State: AO0yUKV/ZXTdtxMOufBFf5fm3ebbo0dhEChryTpkw8KPmUcchc17wa0z TDOK4siBwcDucoJbKbVczxA4+IZ+4ieHs3mHXdw= X-Received: by 2002:a17:906:c155:b0:930:7183:f2ea with SMTP id dp21-20020a170906c15500b009307183f2eamr8910413ejc.48.1679060583822; Fri, 17 Mar 2023 06:43:03 -0700 (PDT) Received: from localhost.localdomain (ppp176092130041.access.hol.gr. [176.92.130.41]) by smtp.gmail.com with ESMTPSA id k8-20020a17090627c800b008d1693c212csm990002ejc.8.2023.03.17.06.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 06:43:03 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Heinrich Schuchardt , Simon Glass , =?utf-8?q?Pali_Roh=C3=A1r?= Subject: [PATCH] arm: enable unaligned accesses by default if EFI is configured Date: Fri, 17 Mar 2023 15:42:57 +0200 Message-Id: <20230317134257.1057261-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 Heinrich 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. So let's enable unaligned access for those architectures during our start.S routines and avoid the linker issues. Reported-by: Heinrich Schuchardt Signed-off-by: Ilias Apalodimas --- arch/arm/cpu/arm11/Makefile | 4 ---- arch/arm/cpu/arm11/sctlr.S | 25 ------------------------- arch/arm/cpu/arm1136/start.S | 3 +++ arch/arm/cpu/arm1176/start.S | 3 +++ arch/arm/cpu/armv7/Makefile | 1 - arch/arm/cpu/armv7/sctlr.S | 22 ---------------------- arch/arm/cpu/armv7/start.S | 3 +++ include/asm-generic/unaligned.h | 4 ---- lib/efi_loader/efi_device_path.c | 7 ------- lib/efi_loader/efi_setup.c | 12 ------------ 10 files changed, 9 insertions(+), 75 deletions(-) delete mode 100644 arch/arm/cpu/arm11/sctlr.S delete mode 100644 arch/arm/cpu/armv7/sctlr.S 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/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/arm1136/start.S b/arch/arm/cpu/arm1136/start.S index 4bc27f637366..f2a18d8f3423 100644 --- a/arch/arm/cpu/arm1136/start.S +++ b/arch/arm/cpu/arm1136/start.S @@ -77,7 +77,10 @@ cpu_init_crit: mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) +#if !CONFIG_IS_ENABLED(EFI_LOADER) + /* allow unaligned accesses since EFI requires it */ orr r0, r0, #0x00000002 @ set bit 1 (A) Align +#endif orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache mcr p15, 0, r0, c1, c0, 0 diff --git a/arch/arm/cpu/arm1176/start.S b/arch/arm/cpu/arm1176/start.S index 78a9cc173a39..0c80160702ba 100644 --- a/arch/arm/cpu/arm1176/start.S +++ b/arch/arm/cpu/arm1176/start.S @@ -79,7 +79,10 @@ cpu_init_crit: mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) +#if !CONFIG_IS_ENABLED(EFI_LOADER) + /* allow unailgned accesses since EFI requires it */ orr r0, r0, #0x00000002 @ set bit 1 (A) Align +#endif orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache /* Prepare to disable the MMU */ 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/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) diff --git a/arch/arm/cpu/armv7/start.S b/arch/arm/cpu/armv7/start.S index 7d7aac021e22..abb89efb9ed5 100644 --- a/arch/arm/cpu/armv7/start.S +++ b/arch/arm/cpu/armv7/start.S @@ -197,7 +197,10 @@ ENTRY(cpu_init_cp15) mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #0x00002000 @ clear bits 13 (--V-) bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) +#if !CONFIG_IS_ENABLED(EFI_LOADER) + /* allow unaligned accesses since EFI requires it */ orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align +#endif orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB #if CONFIG_IS_ENABLED(SYS_ICACHE_OFF) bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache diff --git a/include/asm-generic/unaligned.h b/include/asm-generic/unaligned.h index 3d33a5a063e8..cf032ce1d4cc 100644 --- a/include/asm-generic/unaligned.h +++ b/include/asm-generic/unaligned.h @@ -19,8 +19,4 @@ #else #error invalid endian #endif - -/* Allow unaligned memory access */ -void allow_unaligned(void); - #endif diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 3b267b713e98..bbaaf626d9cb 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -954,13 +954,6 @@ static void path_to_uefi(void *uefi, const char *src) { u16 *pos = uefi; - /* - * efi_set_bootdev() calls this routine indirectly before the UEFI - * subsystem is initialized. So we cannot assume unaligned access to be - * enabled. - */ - allow_unaligned(); - while (*src) { s32 code = utf8_get(&src); diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 58d4e1340233..bd17db61c697 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -17,15 +17,6 @@ efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED; -/* - * Allow unaligned memory access. - * - * This routine is overridden by architectures providing this feature. - */ -void __weak allow_unaligned(void) -{ -} - /** * efi_init_platform_lang() - define supported languages * @@ -191,9 +182,6 @@ int efi_init_early(void) { efi_status_t ret; - /* Allow unaligned memory access */ - allow_unaligned(); - /* Initialize root node */ ret = efi_root_node_register(); if (ret != EFI_SUCCESS)