From patchwork Wed Sep 20 15:18:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 9961697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F7C560208 for ; Wed, 20 Sep 2017 15:25:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6086D28D8F for ; Wed, 20 Sep 2017 15:25:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 538FA28DB9; Wed, 20 Sep 2017 15:25:12 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D9D3E28D8F for ; Wed, 20 Sep 2017 15:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=fYyIqpghujYP3yK2QvGxvHbxTAezgDFBbvCN7oQCdBU=; b=TyB Dg1WfTR+ccIDYyPRANOnyqfsjr1+BTT+oKCiMtGSOAUmjJV/F0rmqEJDl7VaJTALIfF1oenyynVk/ tEx8Kg3BnW63GIFzGh6XJ9iSt6ZsCvh/aQJkvDDgYBbtP9o/2yIzAMhL2z08c3jg0jTNvPqxMQ1rr LtI0IYB0gQ6tWT3EjVke1vmxt/AFhNz0lxPDCB1yYW34iT1Os1L6mSXjN5Fa7FVgAI0lMzIOOdNc+ 2v8oHLzW8G0kqEBiLPzgjDF/KgQHDMh3DV8106sXLvcB7GAHvwLSU6qXS5nracsCYP1NQCrk2d7Da 0vM/fwNaNlbs5L3V4DIISkaTtGDKsCA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dugsB-0008EE-Hl; Wed, 20 Sep 2017 15:25:11 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1duglx-0002fT-4P for linux-arm-kernel@lists.infradead.org; Wed, 20 Sep 2017 15:18:48 +0000 Received: by mail-wm0-x244.google.com with SMTP id r136so2740829wmf.3 for ; Wed, 20 Sep 2017 08:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=9K2fyt8KDBZyA6uQXNzA/h9wbpoCRw4SkwZyi1CWiSg=; b=lWiBq1jETLKYkHzbSZQtvKp6psMg00SOrJfiweZOeRkeLTQwosG407+M1Ix40KuAGC E+8s6gq9/Hd5Pf3RiQDyKf9cwOqIe94zJTi7GM0k1Lp/P+PjAOnzuBpRhP3vk2ZeOq8D OlKM9xdAtehOGz3qfl5RX5o6ImSUnPmYeO7n7WpddHWAT0XVtYs0AnzDpx2NNLuapyNu 8y+CEs95kUy1oJgEdCSNbNU4g0/IbgAGz6aRYT9W6DyQSPAz+odTr+LiVCxU+/8IFmMJ Ct3EsktjL4aapAdCyONfomobXWETZAnrzCSJvs0M3q3l0dZqqUnhtSBsiAjEyTbdeE/6 hAjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9K2fyt8KDBZyA6uQXNzA/h9wbpoCRw4SkwZyi1CWiSg=; b=MkLNnoc0klLQ2O5MZ+oH4jEhrmH1KL2dAk3w9om6N3vLWqXBbhphXgGke46SlF/U1W vWIdilZXQ+XQNDB+w/qcK8OcXvAZ3hXXkSulUn9kJNHPVpwxEM44Urlw7Wg4BgFAWrVb 4Zyp54XpP1xrCxKTvjLu13wXbRj+xLZGfH9Bvkme9M0ael8dlvjfNk17SxqXPC3dtkIG sh3bZ/LZqdzTO+5+0LCPO45m02Qp+2nOfPO9kOTxmfBsk6hsZ57dfZ1aFP0ewN+PQWlg 9ZJKszRTWHSLSKJKbIUlazLXtl9+IIzEFhTeirQvAP51tHxbciWYHStAm8u2mP0uE2sz aooA== X-Gm-Message-State: AHPjjUjP07gkLXOlDTKi5WHsfRhy6K/BvofS2R3bsTHgxKiB+NFeu811 2qfNhjIAH1WZ+GqpE7dPcWo= X-Google-Smtp-Source: AOwi7QB1VumqEfuOpfb/+vkSwUvbC2a+32zEg3Mneo0VIZnN0Rl1duKQH3mWXHKyhwrxeEK26zeYHg== X-Received: by 10.28.217.73 with SMTP id q70mr4605609wmg.9.1505920702880; Wed, 20 Sep 2017 08:18:22 -0700 (PDT) Received: from localhost.localdomain (146.187.3.109.rev.sfr.net. [109.3.187.146]) by smtp.gmail.com with ESMTPSA id z108sm2140113wrc.49.2017.09.20.08.18.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Sep 2017 08:18:22 -0700 (PDT) From: Romain Izard To: Russell King , Al Viro , Ard Biesheuvel , Arnd Bergmann Subject: [PATCH] ARM: unaligned.h: Use an arch-specific version Date: Wed, 20 Sep 2017 17:18:02 +0200 Message-Id: <20170920151802.7609-1-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170920_081845_575451_A730C31D X-CRM114-Status: GOOD ( 16.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Izard , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For the 32-bit ARM architecture, unaligned access support is variable. On a chip without a MMU, an unaligned access returns a rotated data word and must be avoided. When a MMU is available, it can be trapped. On ARMv6 or ARMv7, it can also be handled by the hardware, depending on the type of access instruction. Unaligned access of 32 bits or less are corrected, while larger access provoke a trap. Unfortunately, the compiler is able to merge two 32-bit access that would generate a LDR instruction, that works on unaligned access, into a single LDM access that will not work. This is not a common situation, but it has been observed in the LZ4 decompression code. To prevent this type of optimization, it is necessary to change the explicit accessors for unaligned addresses from those defined in the access_ok.h header, to those defined in the packed_struct.h header. Add an arch-specific header to ARM, to retain other optimizations that rely on HAVE_EFFICIENT_UNALIGNED_ACCESS, while making sure that access that explicitly rely on the unaligned accessors are correctly handled by the compiler. Signed-off-by: Romain Izard Acked-by: Ard Biesheuvel --- This is a follow-up to this discussion: HAVE_EFFICIENT_UNALIGNED_ACCESS on ARM32 https://lkml.org/lkml/2017/9/4/359 arch/arm/include/asm/Kbuild | 1 - arch/arm/include/asm/unaligned.h | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 arch/arm/include/asm/unaligned.h +#endif /* __ASM_ARM_UNALIGNED_H */ diff --git a/arch/arm/include/asm/Kbuild b/arch/arm/include/asm/Kbuild index 721ab5ecfb9b..0f2c8a2a8131 100644 --- a/arch/arm/include/asm/Kbuild +++ b/arch/arm/include/asm/Kbuild @@ -20,7 +20,6 @@ generic-y += simd.h generic-y += sizes.h generic-y += timex.h generic-y += trace_clock.h -generic-y += unaligned.h generated-y += mach-types.h generated-y += unistd-nr.h diff --git a/arch/arm/include/asm/unaligned.h b/arch/arm/include/asm/unaligned.h new file mode 100644 index 000000000000..394227f24b77 --- /dev/null +++ b/arch/arm/include/asm/unaligned.h @@ -0,0 +1,22 @@ +#ifndef __ASM_ARM_UNALIGNED_H +#define __ASM_ARM_UNALIGNED_H + +#include + +#if defined(__LITTLE_ENDIAN) +#include +#include +#include +#define get_unaligned __get_unaligned_le +#define put_unaligned __put_unaligned_le +#elif defined(__BIG_ENDIAN) +#include :q +#include +#include +#define get_unaligned __get_unaligned_be +#define put_unaligned __put_unaligned_be +#else +#error need to define endianness +#endif +