From patchwork Tue Jan 16 16:28:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 124739 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1070450lje; Tue, 16 Jan 2018 08:29:38 -0800 (PST) X-Google-Smtp-Source: ACJfBotvbizFn3Hz1JPjt+hf0I5Er1o044Ws5DABE5P+GT5mtf59Kr3YnlXKloYrY1kFOyk9nppI X-Received: by 10.84.210.79 with SMTP id z73mr20581747plh.313.1516120178219; Tue, 16 Jan 2018 08:29:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516120178; cv=none; d=google.com; s=arc-20160816; b=OwDCi2yr5VuseGGvhuTzx7Dj2DY65KhpvxNPQjXlseloFw1i9f3QSO6l7NaXfstTGu 9PtBYx77oiqXN1u2Zk0r6OsjMBU56SnatS9ej4Q5t0DtEBAd2KHFFDaf/kRhKIR/qe09 zlSPdEIVTuUgOzp3Y11kM+N23ipf/AgrAfVEl37Fgi4zbRgMM+X714GZcJp6uApB7sy/ KaYoagMcJppEPtvHmfRdoiftYyMTZdHj1Dk4VjB4lXKaX7haIWPbIdsvvj3piSD2JlNY 2GyK20AaLfeKJKNCSEFHQXaibPyo5vBLXby2RbVQkMLoeYa2VcaXajNCcYS7kTV/trUS B3KA== 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=jdVvFXSwg/D9+ptiHsLvjamnkGIOBv3JK11iDjXKU4o=; b=A0HyyDL+xL6f9a6/xPem0upEcj/vmXl3/3U+E3H+IihU52WlUReWh/zBRw1xVEkmK/ Bjq9AFYDz5xYKmh9JuUIFKBSYp+UWvaw9hMKeFRtrCLtzVQNF0UmhhMUkTXva8DM3B2A AFdm8cjVISn0Xry7DIJ37vfXjdwDXnd6LJJU+8MTcORrm89hdriGPZGHVr9qdBCA81Wv AJ/m4GAcgjZNiT621tHF1y7/OaYkmdZXUFidtNnYv27roKcxym+XivAZyrkzFr9bQTDl tdd4UBbFyu0S7HYe5nNN1kdqpxIVDopZPysxcnqR7pmGU3uJKSMRqskOJokj1tGwoe3N F9fw== 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 63si1902873pgg.392.2018.01.16.08.29.37; Tue, 16 Jan 2018 08:29:38 -0800 (PST) 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 S1751195AbeAPQ3g (ORCPT + 28 others); Tue, 16 Jan 2018 11:29:36 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:55288 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750811AbeAPQ3e (ORCPT ); Tue, 16 Jan 2018 11:29:34 -0500 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0LySz0-1ew1rx48jG-015n6f; Tue, 16 Jan 2018 17:29:08 +0100 From: Arnd Bergmann To: Russell King Cc: Ard Biesheuvel , Zhichang Yuan , Nicolas Pitre , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] ARM: make memzero optimization smarter Date: Tue, 16 Jan 2018 17:28:43 +0100 Message-Id: <20180116162905.1404585-1-arnd@arndb.de>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DVM8TfM73xmiHvHwAg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk 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. From the discussion there, it seems unlikely that this gets addressed in the compiler. 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 --- Originally sent in September 2017, but then forgot about it as nobody replied. I slightly updated the change text now to reflect that the gcc developers treat it as an invalid bug. --- arch/arm/include/asm/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.9.0 diff --git a/arch/arm/include/asm/string.h b/arch/arm/include/asm/string.h index f54a3136aac6..a8b90e33cc87 100644 --- a/arch/arm/include/asm/string.h +++ b/arch/arm/include/asm/string.h @@ -44,7 +44,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 \