From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_RED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3395C43461 for ; Tue, 18 May 2021 15:42:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F89A6117A for ; Tue, 18 May 2021 15:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350276AbhERPnb (ORCPT ); Tue, 18 May 2021 11:43:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:57606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350273AbhERPna (ORCPT ); Tue, 18 May 2021 11:43:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6CCB6117A; Tue, 18 May 2021 15:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621352532; bh=6/AZpMiQsWIzehSS0pf9F1Zsz6DBuPBxPZHPFBj/4IQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dBATrxKUo+9lJRDkt+z44QyPpRbXGotCZKr7AmmONwoFikB5osIBfIBVRceLC+s/H SnW6BZd5EWBLhwSeaBwmfz9S9R8szJaAPokYGPoP0Sg3PvdU8nUbhobryrwFPpHPjj WDSdsEjeVms2eWWsQhljQoKhKdJJHTNo+d+VuzQHT+eYfpnRA63htHOOF6C8X3qOXW zYp59xGkk5LpZ3cB4qalJMDfXTkHjIURbL0mO/WL4hQJ8zQ21Mp4TI1PG9RaxcLTJQ 88Vbl26D+hVKhJoZAT00KFXyQSCrnezmlZH8yEIZbeUgB+85RWqyMFt+TuDRB0nYHE FLRjzLcNwCCEg== Received: by mail-wr1-f44.google.com with SMTP id z17so10720406wrq.7; Tue, 18 May 2021 08:42:12 -0700 (PDT) X-Gm-Message-State: AOAM533T1vQOgqjSit4dvrHcbMwWDUiMrpxij7qU0lIMnorKE9t+uj7d bEpjVjtl9TYFCjCMjvPBiTTuOHmP24v8205+YRw= X-Google-Smtp-Source: ABdhPJyqM7bHu1qcSQI74/RObeZl1HWDfzmYNgspCaVb1ZNRDA2D4kfkWRWH7fq0f6j61Y5yW03ZTIhOATwfLihnHPY= X-Received: by 2002:a05:6000:18a:: with SMTP id p10mr7805910wrx.99.1621352531347; Tue, 18 May 2021 08:42:11 -0700 (PDT) MIME-Version: 1.0 References: <20210514100106.3404011-1-arnd@kernel.org> <20210514100106.3404011-8-arnd@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Tue, 18 May 2021 17:41:00 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 07/13] asm-generic: unaligned always use struct helpers To: Linus Torvalds Cc: Eric Biggers , linux-arch , Vineet Gupta , Russell King , Herbert Xu , "David S. Miller" , Thomas Bogendoerfer , Linux ARM , Linux Kernel Mailing List , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "open list:BROADCOM NVRAM DRIVER" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Tue, May 18, 2021 at 4:56 PM Linus Torvalds wrote: > > On Tue, May 18, 2021 at 12:27 AM Arnd Bergmann wrote: > > > > > > I wonder if the kernel should do the same, or whether there are still cases > > > where memcpy() isn't compiled optimally. armv6/7 used to be one such case, but > > > it was fixed in gcc 6. > > > > It would have to be memmove(), not memcpy() in this case, right? > > No, it would simply be something like > > #define __get_unaligned_t(type, ptr) \ > ({ type __val; memcpy(&__val, ptr, sizeof(type)); __val; }) > > #define get_unaligned(ptr) \ > __get_unaligned_t(typeof(*(ptr)), ptr) > > but honestly, the likelihood that the compiler generates something > horrible (possibly because of KASAN etc) is uncomfortably high. > > I'd prefer the __packed thing. We don't actually use -O3, and it's > considered a bad idea, and the gcc bug is as such less likely than > just the above generating unacceptable code (we have several cases > where "bad code generation" ends up being an actual bug, since we > depend on inlining and depend on some code sequences not generating > calls etc). I think the important question is whether we know that the bug that Eric pointed to can only happen with -O3, or whether it is something in gcc-10.1 that got triggered by -O3 -msse on x86-64 but could equally well get triggered on some other architecture without -O3 or vector instructions enabled. >From the gcc fix at https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=9fa5b473b5b8e289b it looks like this code path is entered when compiling with -ftree-loop-vectorize, which is documented as '-ftree-loop-vectorize' Perform loop vectorization on trees. This flag is enabled by default at '-O3' and by '-ftree-vectorize', '-fprofile-use', and '-fauto-profile'. -ftree-vectorize is set in arch/arm/lib/xor-neon.c -O3 is set for the lz4 and zstd compression helpers and for wireguard. To be on the safe side, we could pass -fno-tree-loop-vectorize along with -O3 on the affected gcc versions, or use a bigger hammer (not use -O3 at all, always set -fno-tree-loop-vectorize, ...). Arnd From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55B52C433ED for ; Tue, 18 May 2021 15:44:18 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D06AA6117A for ; Tue, 18 May 2021 15:44:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D06AA6117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QVLRaWUD2ZaeX4cjXHwmLjCJVx2pXrH6xtyZJAS0My8=; b=McNSe6PcOwEN6PusFqPBkwjpE Hv32Pss34mOG8Zu9OhMYzsGDbSu7fL0sfwbnnZh/oMpRg0i7udy/VGxtQ/h/LTJYq59NAkEpkBY6F ivguiR+/hNdxt1xkQGI/n7hmNitCY3wg7tVHt/7944rQQCzeNQ66AVG+d5nNhHWJBxm5PB0maUijz hV8OQVhc3hcCMJJEtS8mGyRE/hPtnVog5+xZBgP9SG0ip/XXPveLdc0quvOTDDio8kbZOgrf+CcA/ nWOQ6kxXC25u9lJ3ZxieXvHDEQOcI+LO4IvtmWjnKRitLheLLxi0o68PuoCYjVRwFT8FbG668rq8H /9/wKwg2w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lj1rP-001Cus-A0; Tue, 18 May 2021 15:42:19 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lj1rM-001CuV-8D for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 15:42:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GIWF2f41zowbzA+KElWsJwYcbN4t97gWRd0V+pUK+Fw=; b=HT270Jt3Hbqj0msXAoL4VKEDFn TdyIPtUqubUsuHKbkwGj5hpheVKIY1qDsupp8gb4FD0kawFSZchU+Wlee2r8k4uacqtrTlsLOdStB wab/JDYpQTnyjPaYyCNDVY+G1ZeA+ewLc1Ywm+1qOCqD2YrWq3v2R+qD4yRuVq6RYl3+GVUanzE91 9reHKJBW4btkBNfow5SyLC4zN0t7SDo7mYzGGrk+b3GIn0TT8nnuezIPB4vfw80XVK1dWkYuqNpVh OX1ofBs6fFUJAIXuWwLxmZg70qbD1VR3LZdmBTTq3uXVkh1/jqLDqiYthwoD1lr7ADbFHC/GsiwOi cDAv3pcA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lj1rJ-00Elxd-4D for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 15:42:15 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B80FE61261 for ; Tue, 18 May 2021 15:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621352532; bh=6/AZpMiQsWIzehSS0pf9F1Zsz6DBuPBxPZHPFBj/4IQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dBATrxKUo+9lJRDkt+z44QyPpRbXGotCZKr7AmmONwoFikB5osIBfIBVRceLC+s/H SnW6BZd5EWBLhwSeaBwmfz9S9R8szJaAPokYGPoP0Sg3PvdU8nUbhobryrwFPpHPjj WDSdsEjeVms2eWWsQhljQoKhKdJJHTNo+d+VuzQHT+eYfpnRA63htHOOF6C8X3qOXW zYp59xGkk5LpZ3cB4qalJMDfXTkHjIURbL0mO/WL4hQJ8zQ21Mp4TI1PG9RaxcLTJQ 88Vbl26D+hVKhJoZAT00KFXyQSCrnezmlZH8yEIZbeUgB+85RWqyMFt+TuDRB0nYHE FLRjzLcNwCCEg== Received: by mail-wr1-f48.google.com with SMTP id v12so10747912wrq.6 for ; Tue, 18 May 2021 08:42:12 -0700 (PDT) X-Gm-Message-State: AOAM531OcsCu6jfCNQw1hl4BfbpJw75aujbkZhQLzHqWyGp4wED6Gc42 opotKefqNvzkfsOfLYRL20rGZ3tdvPoYXDmE7mA= X-Google-Smtp-Source: ABdhPJyqM7bHu1qcSQI74/RObeZl1HWDfzmYNgspCaVb1ZNRDA2D4kfkWRWH7fq0f6j61Y5yW03ZTIhOATwfLihnHPY= X-Received: by 2002:a05:6000:18a:: with SMTP id p10mr7805910wrx.99.1621352531347; Tue, 18 May 2021 08:42:11 -0700 (PDT) MIME-Version: 1.0 References: <20210514100106.3404011-1-arnd@kernel.org> <20210514100106.3404011-8-arnd@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Tue, 18 May 2021 17:41:00 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 07/13] asm-generic: unaligned always use struct helpers To: Linus Torvalds Cc: Eric Biggers , linux-arch , Vineet Gupta , Russell King , Herbert Xu , "David S. Miller" , Thomas Bogendoerfer , Linux ARM , Linux Kernel Mailing List , "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , "open list:BROADCOM NVRAM DRIVER" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_084213_241597_50962A7A X-CRM114-Status: GOOD ( 24.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, May 18, 2021 at 4:56 PM Linus Torvalds wrote: > > On Tue, May 18, 2021 at 12:27 AM Arnd Bergmann wrote: > > > > > > I wonder if the kernel should do the same, or whether there are still cases > > > where memcpy() isn't compiled optimally. armv6/7 used to be one such case, but > > > it was fixed in gcc 6. > > > > It would have to be memmove(), not memcpy() in this case, right? > > No, it would simply be something like > > #define __get_unaligned_t(type, ptr) \ > ({ type __val; memcpy(&__val, ptr, sizeof(type)); __val; }) > > #define get_unaligned(ptr) \ > __get_unaligned_t(typeof(*(ptr)), ptr) > > but honestly, the likelihood that the compiler generates something > horrible (possibly because of KASAN etc) is uncomfortably high. > > I'd prefer the __packed thing. We don't actually use -O3, and it's > considered a bad idea, and the gcc bug is as such less likely than > just the above generating unacceptable code (we have several cases > where "bad code generation" ends up being an actual bug, since we > depend on inlining and depend on some code sequences not generating > calls etc). I think the important question is whether we know that the bug that Eric pointed to can only happen with -O3, or whether it is something in gcc-10.1 that got triggered by -O3 -msse on x86-64 but could equally well get triggered on some other architecture without -O3 or vector instructions enabled. >From the gcc fix at https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=9fa5b473b5b8e289b it looks like this code path is entered when compiling with -ftree-loop-vectorize, which is documented as '-ftree-loop-vectorize' Perform loop vectorization on trees. This flag is enabled by default at '-O3' and by '-ftree-vectorize', '-fprofile-use', and '-fauto-profile'. -ftree-vectorize is set in arch/arm/lib/xor-neon.c -O3 is set for the lz4 and zstd compression helpers and for wireguard. To be on the safe side, we could pass -fno-tree-loop-vectorize along with -O3 on the affected gcc versions, or use a bigger hammer (not use -O3 at all, always set -fno-tree-loop-vectorize, ...). Arnd _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel