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: 116535 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp2074144qgn; Fri, 20 Oct 2017 13:03:19 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SYCZepzQ0s870GdwXGLHhS8/tspPB5wlQx8N4j+JFiY54wPy6YxI5x1kseYdO+tY8IWDL1 X-Received: by 10.84.165.171 with SMTP id y40mr4979259pla.373.1508529799611; Fri, 20 Oct 2017 13:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508529799; cv=none; d=google.com; s=arc-20160816; b=NwtgHJXdU8xqIEP8Ffnh9PLHasmqAQvZqK+IaWlgdGsjSXIj83cMAhyu6i35zVFy4l IZMTHkvGCiQ8CYwcm2nqc/rh3gJw9MqpTqdsVRGJW+Pd9kUbrS6qHYB5Ze+GMu3leyR3 o16phIu9xNTehX5CTzb3dm+yhbsqASlwZ+h1y5cSK7gPTyhzVXsqLsVmSn2NBsh8iOoy yoWASKsYvTfiX3kc3XVseETbbmo7WXZYZfhLfz+xTAFEDf3uiA/TfBaQ8ULpzPPa0vTW 36E6VNwc/CB0uAMXURdk6r+qXmspYyWaJfgkXeYq3YZllJpy1R1ekzhdrrdSdTr1CN0g 7owg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JeZYFvzJTsell5OehGwasaXESO9hyGYXpeKVpLjZZyc=; b=Nqq0rhDsiuXDwm7BvMOnRIGUfTgdggrTxazlACsimJrC9xFoGAm6Pvnve9a9muEcnh Lw2GLTQqXP820d0zJMmkypiYC+U5/DASpjr6M3AT5Z2mdQa5V3yzVh2vbOf7e+y5ePwB 1h5HT31F0gBOdvJAA8rpB99ZjCETqYN+rVVHf8osNmqPiIzhGATz9aOWrYYFbMOifoZU chTU+DvzBK9SUI3fjYqmIeYhkm1hdb6O0cXiNwglY1zyJlyXdkAGimfAvtZZwgU3XdBj xxkhfLOqjZVeuWNNhp3CmPcX9MLtYBDhnzeDHu0d46Y8cBCS0TPo/mVtDIstEZHmQ59r AZMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si954967plk.126.2017.10.20.13.03.19; Fri, 20 Oct 2017 13:03:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753387AbdJTUDR (ORCPT + 27 others); Fri, 20 Oct 2017 16:03:17 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:63050 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752752AbdJTUDP (ORCPT ); Fri, 20 Oct 2017 16:03:15 -0400 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 Cc: Ard Biesheuvel , Romain Izard , Sven Schmidt <4sschmid@informatik.uni-hamburg.de>, LKML , linux-arm-kernel@lists.infradead.org, Gregory CLEMENT , Petr Cvek , Aaro Koskinen , Andrea Adami , Robert Jarzmik 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== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 -- 2.9.0 Acked-by: Ard Biesheuvel Tested-by: Romain.Izard 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 */