From patchwork Fri Oct 20 20:01:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 10020923 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 2648160224 for ; Fri, 20 Oct 2017 20:03:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1709028F4B for ; Fri, 20 Oct 2017 20:03:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BAEE28F51; Fri, 20 Oct 2017 20:03:23 +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=-3.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM 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 8BB9A28F4B for ; Fri, 20 Oct 2017 20:03:22 +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=TTCnQ0C+momWnXRRHtcVgfEgjL08rg9LxC+Y/BQZq6o=; b=l4/ 6Fe5FTq6ugeyvNgcDq03wu/7uoQlaBAsCq3MyYoOCTIs2AkCwS0HkOxv7tBycVsErv5FjfzFOEcrQ THVHRe3JWVrfp2GoDT6KYUDmbocPdoMx2GHEudufCquQILrWBbcrCfZDlmJIKl9ssTlcK1ikCXssj cvkZ6rq1URltUAg9fLsHA+8yuQkV65Sfm8O7vzISjxogdNtYDkWUO/RaYo/N3J3CwGQ7u6u8+nv5v M5+usNfS7OAuS+jtUystziM/6OzLoF/CvtCi75Wml60cVk10jVXGOjO5Ls6jT1Uhy4fynhDIBWx76 1Wo/ZLCTTZacDpbPggSvVVCtE4EDyQA==; 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 1e5dVj-0003iJ-95; Fri, 20 Oct 2017 20:03:15 +0000 Received: from mout.kundenserver.de ([212.227.17.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e5dVf-0003fF-TY for linux-arm-kernel@lists.infradead.org; Fri, 20 Oct 2017 20:03:14 +0000 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0LkjTw-1dXfjA3cfM-00aUEJ; Fri, 20 Oct 2017 22:02:33 +0200 From: Arnd Bergmann To: Russell King , Arnd Bergmann Subject: [PATCH] ARM: add a private asm/unaligned.h Date: Fri, 20 Oct 2017 22:01:56 +0200 Message-Id: <20171020200231.1355569-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:p8C8NYNMw3KxMfBG7uUrUI46wnc7+WlVQtc06vC5rIY3XEPhb5l VltAztfl6nCQko83yHOUdDiLPzyvsylV3+8s53K2ziPBPIr307RqkpyUQd7NCID6fEZQWKT OeB73UKNCq+jCgrMmDPa79n5rk8VuyKCwNvboBDFu9FDCYvx9Wlfz5KtwotDJrKKEjJR+DC usKKFWNV1oQAUUe6iSq8w== X-UI-Out-Filterresults: notjunk:1; V01:K0:TsDHYPdKAr8=:oCGH0leazWg4e8uwS666Uc a5FhsE4Q7Nfu/qFY0DY2yg6M81nodDCGFAIXNrMnILSIEJypUCYHK2bfV3gLBu5bnS3u6ehdH xzWUibaDMLS9AxWFA5MKtQW1fT/u/CBWqGEWCxaOBizo/LEc6Zzy82D/EoBSaQVhbC/eCjz47 Z92vlIDpOShzdL1HmSICuu2vY/iQ/JWlKsLiSin7LpjzvANiyHJAJ1nQUnlegCZmcOwBexdX2 epKDFYkeA8O6GnSp73lmIIcRgPIgJ6xe+lzB2IcgeoiFBwlLnIz4eP9wVfCCSv+8amT8xr25F 8ri5lgyoRAB1pUuM9BSzSUQcZs18B4r0aR2dy4XP6Lv0zqilSyH/Zk7B1nhh/mEyNy3ksyMPx xTWRYSKdFg0UITlg39Ud7OhWaGcfUDJEbCmzWF3j0jqxYSjo/os1czQ/UG8x2qwNN1TueRIJj PQA1Pnr5/xML+8tpAw8hLsbpc85nqxu4p6fVltK2RBCx88Wl0VCtrRATNuDwn79DrHNprNHKy GDqGoU7VBMTa+C9qKz0jljpjjVx1ovQ4nkX/QmA/yODgvVcc3bTcwiLyk4d2IWJa0BYpTPeO+ hNsrxPedfis5dZWmPOJcmWWvabzKP8NVlkvxe6U4G7ukbMz+MLNnb2A22Ej8JWnpOXBZz1PTD nWbzHsITQ+ZHIawcT7DDKImq8dWc4N54rux9nqr4hCvVVfhJQzCLlEsJrPlQbhDnJyGm1Q/Wl YOiYn1I1KxwD//gwyRSsk8eO28yglWVQvisXAQ== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171020_130312_296950_FEAE8606 X-CRM114-Status: GOOD ( 20.56 ) 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: Ard Biesheuvel , Robert Jarzmik , Aaro Koskinen , LKML , Andrea Adami , Gregory CLEMENT , Romain Izard , Sven Schmidt <4sschmid@informatik.uni-hamburg.de>, Petr Cvek , 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 The asm-generic/unaligned.h header provides two different implementations for accessing unaligned variables: the access_ok.h version used when CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is set pretends that all pointers are in fact aligned, while the le_struct.h version convinces gcc that the alignment of a pointer is '1', to make it issue the correct load/store instructions depending on the architecture flags. On ARMv5 and older, we always use the second version, to let the compiler use byte accesses. On ARMv6 and newer, we currently use the access_ok.h version, so the compiler can use any instruction including stm/ldm and ldrd/strd that will cause an alignment trap. This trap can significantly impact performance when we have to do a lot of fixups and, worse, has led to crashes in the LZ4 decompressor code that does not have a trap handler. This adds an ARM specific version of asm/unaligned.h that uses the le_struct.h/be_struct.h implementation unconditionally. This should lead to essentially the same code on ARMv6+ as before, with the exception of using regular load/store instructions instead of the trapping instructions multi-register variants. The crash in the LZ4 decompressor code was probably introduced by the patch replacing the LZ4 implementation, commit 4e1a33b105dd ("lib: update LZ4 compressor module"), so linux-4.11 and higher would be affected most. However, we probably want to have this backported to all older stable kernels as well, to help with the performance issues. There are two follow-ups that I think we should also work on, but not backport to stable kernels, first to change the asm-generic version of the header to remove the ARM special case, and second to review all other uses of CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS to see if they might be affected by the same problem on ARM. Cc: stable@vger.kernel.org Signed-off-by: Arnd Bergmann Acked-by: Ard Biesheuvel Tested-by: Romain.Izard --- Untested so far, please verify that this fixes all the known problems with the alignment traps. --- arch/arm/include/asm/Kbuild | 1 - arch/arm/include/asm/unaligned.h | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 arch/arm/include/asm/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..ab905ffcf193 --- /dev/null +++ b/arch/arm/include/asm/unaligned.h @@ -0,0 +1,27 @@ +#ifndef __ASM_ARM_UNALIGNED_H +#define __ASM_ARM_UNALIGNED_H + +/* + * We generally want to set CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS on ARMv6+, + * but we don't want to use linux/unaligned/access_ok.h since that can lead + * to traps on unaligned stm/ldm or strd/ldrd. + */ +#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 +# include +# include +# define get_unaligned __get_unaligned_be +# define put_unaligned __put_unaligned_be +#else +# error need to define endianess +#endif + +#endif /* __ASM_ARM_UNALIGNED_H */