From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751918AbdIEPG5 (ORCPT ); Tue, 5 Sep 2017 11:06:57 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:55526 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750858AbdIEPG4 (ORCPT ); Tue, 5 Sep 2017 11:06:56 -0400 From: Arnd Bergmann To: Russell King Cc: Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] ARM: make memzero optimization smarter Date: Tue, 5 Sep 2017 17:05:37 +0200 Message-Id: <20170905150559.1739140-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:5zgMLCjdk1lKL+xPgQsb3WayIcv04elw3AE5U2B4okTPyxjzdFJ jIr0J1G075p3lSw3/aqC04t+qNFPCy2WJhfMNNPCGKnfjWgBVLymNeQjTrlIi2ReGXJRpCp q1edDRuPp8hpagdjxr8Q6MQygGbHQAmOoxBLI/Amq5nN+xMmEOTRwgprRyndM7qFdwkFj2V f3Cso2dbSPGi3ia2WCQJQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:qhDwZ4SaGFg=:STTpPaKiE8A7gELbiMgpG7 ALbt+ZYgl2ESBEl0OnKJpix1CZBWKvy1btTJ+ZdaXPAqDHoPqMs9urkMy7F2mn5T/l2hFA8lL T0BIqtin1uABp5pbLIoTc5eEux1jzgkuKKbW2bk6QwXe7RXrJDSP3NQzZubZv+w6kMgSgNM1a W5uQz7P+HDqaR9PoDiErwKjffAnp/Md+9NlJYRdxE32SCnsJB2wqrcLMnQ0+gn7Yr7mvumsVE n0pJa0cb3E0MrM97JoDcZROWuYty/kJ2NN6zhUcIDGc1iq+3yNwT38AM4ZyEVa2762KAtEHD3 QotlKb02VngjFUTUpRlJkKkN/4fsBg05Tl1s9+j4DJsHrNj/eH2oUhMfS44r9p0yPesCqqg4p fYH1vBr8Idz+s12txayPJ3cjgVgrmfsE9nN/CAHaS/URZWVNLjC5qMwxEvsYACJ1j8i23u4Us xC+BvO9RrbMgHhyoCKLOesufvAG11GjGJvjN5U7ibPr/tMXZk7IwHAb0DUPQDL6tgIHxJV2Rq YuM0x0fCfMnYmnjHX5kTN48u0xPfGkLYTTDe0vmbaK/F+qCn4eM7WfaSgIU4tYqxxwnJNcrXV HnbTcQCflK43+GVCJVBfjLBZDqm7TLsP/WsgF8PQcl5yYqnpWBuVzJ1Aqhzbkys4ko8O1YgFv tjwqA8Vd8Rafm296+EcJgWtX0pix5XT6OecfmqZZaBFGG069xIRDqTw39+4SZVh4HjSIr07Ip eg1qX976BfnRkr38DD7ZEkC0uTduZlZkLjgunQ== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While testing with a gcc-8.0.0 snapshot, I ran into a harmless build warning: In file included from include/linux/string.h:18:0, ... from drivers/net/ethernet/hisilicon/hns/hns_ethtool.c:10: drivers/net/ethernet/hisilicon/hns/hns_ethtool.c: In function '__lb_other_process': arch/arm/include/asm/string.h:50:5: error: 'memset' specified size 4294967295 exceeds maximum object size 2147483647 [-Werror=stringop-overflow=] memset((__p),(v),(__n)); \ ^~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/hisilicon/hns/hns_ethtool.c:394:3: note: in expansion of macro 'memset' memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); ^~~~~~ I think the warning is unintentional here, and gcc should not actually warn, so I reported this in the gcc bugzilla as pr82103. The problem here is that testing the 'frame_size' variable for non-zero in the first memset() macro invocation leads to a code path in which gcc thinks it may be zero, and that code path would lead to an overly large length for the following memset that is now "(u32)-1". We know this won't happen as the skb len is already guaranteed to be nonzero when we get here (it has just been allocated with a nonzero size). However, we can avoid this class of bogus warnings for the memset() macro by only doing the micro-optimization for zero-length arguments when the length is a compile-time constant. This should also reduce code size by a few bytes, and avoid an extra branch for the cases that a variable-length argument is always nonzero, which is probably the common case anyway. I have made sure that the __memzero implementation can safely handle a zero length argument. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82103 Signed-off-by: Arnd Bergmann --- arch/arm/include/asm/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/include/asm/string.h b/arch/arm/include/asm/string.h index fe1c6af3a1b1..d4f464b46eae 100644 --- a/arch/arm/include/asm/string.h +++ b/arch/arm/include/asm/string.h @@ -43,7 +43,7 @@ extern void __memzero(void *ptr, __kernel_size_t n); #define memset(p,v,n) \ ({ \ void *__p = (p); size_t __n = n; \ - if ((__n) != 0) { \ + if (!__builtin_constant_p(__n) || (__n) != 0) { \ if (__builtin_constant_p((v)) && (v) == 0) \ __memzero((__p),(__n)); \ else \ -- 2.9.0