Message ID | 20170905150559.1739140-1-arnd@arndb.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org> 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 B4E0E604D4 for <patchwork-linux-arm@patchwork.kernel.org>; Tue, 5 Sep 2017 15:07:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6D0A2897F for <patchwork-linux-arm@patchwork.kernel.org>; Tue, 5 Sep 2017 15:07:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BF82289AF; Tue, 5 Sep 2017 15:07:07 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 4CEE428987 for <patchwork-linux-arm@patchwork.kernel.org>; Tue, 5 Sep 2017 15:07:07 +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=UrIdTr9oojraLg/KuohYwWCcdNH1mPkOwOwJ1IQPp7k=; b=jAI 9EH+0dWIeZYy27wciZ7KNHitXGzGoPLxmY0GwRHwqAbrWIYaDcTgw0JdUWv7P3Ro+/9HVSdZFObIe /CNzebetoO2vuxoP0F9nLIfC0UMDEF/GFCcwV1Vs3SxxbbIbSzAcLN9kuoRjsqYr+Gh8CjtsEx1l2 JavDUndUNotIveLgr7xlgZeGYXAjnP58FNxKPpY2xKlE6ZYu3s6iNB7FUZx0WqKuRn0oZ71dR4339 elxam07avKc1uhQDUUBImV7V0WNYi6wSSZ9hGuXk4l7TpNtRWrXIPlivv2Y+X044uMBOhrPrNB6V2 koSNxeUscg8+PZodbWYB8eRyTfpRtJg==; 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 1dpFRN-0008NZ-T2; Tue, 05 Sep 2017 15:07:01 +0000 Received: from mout.kundenserver.de ([212.227.126.187]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dpFQp-0007cp-OG for linux-arm-kernel@lists.infradead.org; Tue, 05 Sep 2017 15:06:54 +0000 Received: from wuerfel.lan ([95.208.190.237]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.129]) with ESMTPA (Nemesis) id 0MaXEr-1e4yrF2Sev-00KBL2; Tue, 05 Sep 2017 17:06:04 +0200 From: Arnd Bergmann <arnd@arndb.de> To: Russell King <linux@armlinux.org.uk> 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== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170905_080628_422412_9E2B5A42 X-CRM114-Status: GOOD ( 14.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: <linux-arm-kernel.lists.infradead.org> List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=unsubscribe> List-Archive: <http://lists.infradead.org/pipermail/linux-arm-kernel/> List-Post: <mailto:linux-arm-kernel@lists.infradead.org> List-Help: <mailto:linux-arm-kernel-request@lists.infradead.org?subject=help> List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-arm-kernel>, <mailto:linux-arm-kernel-request@lists.infradead.org?subject=subscribe> Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann <arnd@arndb.de>, linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" <linux-arm-kernel-bounces@lists.infradead.org> Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP |
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 \
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 <arnd@arndb.de> --- arch/arm/include/asm/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)