From patchwork Sun Feb 13 19:32:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12744660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D853C433EF for ; Sun, 13 Feb 2022 19:32:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A92116B0072; Sun, 13 Feb 2022 14:32:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A41086B0073; Sun, 13 Feb 2022 14:32:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 909716B0078; Sun, 13 Feb 2022 14:32:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 81BD46B0072 for ; Sun, 13 Feb 2022 14:32:37 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3FB4E99EB6 for ; Sun, 13 Feb 2022 19:32:37 +0000 (UTC) X-FDA: 79138753554.12.A722634 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf24.hostedemail.com (Postfix) with ESMTP id 9D133180007 for ; Sun, 13 Feb 2022 19:32:36 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4Jxcv65sPzz9sT4; Sun, 13 Feb 2022 20:32:34 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jB2OT5VCQv1o; Sun, 13 Feb 2022 20:32:34 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4Jxcv6545cz9sSV; Sun, 13 Feb 2022 20:32:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9F57D8B76D; Sun, 13 Feb 2022 20:32:34 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id GNJya3KYTDNX; Sun, 13 Feb 2022 20:32:34 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.6.142]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5C1748B763; Sun, 13 Feb 2022 20:32:34 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 21DJWOnx2004700 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 13 Feb 2022 20:32:24 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 21DJWNYC2004699; Sun, 13 Feb 2022 20:32:23 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Andrew Morton Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5] mm: Uninline copy_overflow() Date: Sun, 13 Feb 2022 20:32:23 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1644780742; l=2816; s=20211009; h=from:subject:message-id; bh=S2wykIjhSOi1maIHh3hglOIyFa2WUUwjiHHUCAjkVEw=; b=2MGvuKyMqgh2uS7KHg3fHrFZPoG8+BUo5flYpV0PWJhmLqUew4YH8xQTJRv/PD5WWe9M1UFmTVLY zSTQqpUZB+whg6CpZxh0LlkAcSQyb1U6VvTKwqwvPdnnOMz/Ftab X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 9D133180007 X-Stat-Signature: 17uh3kzyrjydtsjf18dbsn51zc1j35wr Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-HE-Tag: 1644780756-743201 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: While building a small config with CONFIG_CC_OPTIMISE_FOR_SIZE, I ended up with more than 50 times the following function in vmlinux because GCC doesn't honor the 'inline' keyword: c00243bc : c00243bc: 94 21 ff f0 stwu r1,-16(r1) c00243c0: 7c 85 23 78 mr r5,r4 c00243c4: 7c 64 1b 78 mr r4,r3 c00243c8: 3c 60 c0 62 lis r3,-16286 c00243cc: 7c 08 02 a6 mflr r0 c00243d0: 38 63 5e e5 addi r3,r3,24293 c00243d4: 90 01 00 14 stw r0,20(r1) c00243d8: 4b ff 82 45 bl c001c61c <__warn_printk> c00243dc: 0f e0 00 00 twui r0,0 c00243e0: 80 01 00 14 lwz r0,20(r1) c00243e4: 38 21 00 10 addi r1,r1,16 c00243e8: 7c 08 03 a6 mtlr r0 c00243ec: 4e 80 00 20 blr With -Winline, GCC tells: /include/linux/thread_info.h:212:20: warning: inlining failed in call to 'copy_overflow': call is unlikely and code size would grow [-Winline] copy_overflow() is a non conditional warning called by check_copy_size() on an error path. check_copy_size() have to remain inlined in order to benefit from constant folding, but copy_overflow() is not worth inlining. Uninline it when CONFIG_BUG is selected. When CONFIG_BUG is not selected, WARN() does nothing so skip it. This reduces the size of vmlinux by almost 4kbytes. Signed-off-by: Christophe Leroy --- v5: Change to EXPORT_SYMBOL() instead of EXPORT_SYMBOL_GPL() v4: Make copy_overflow() a no-op when CONFIG_BUG is not selected v3: Added missing ; after EXPORT_SYMBOL() v2: Added missing EXPORT_SYMBOL() and enhanced commit message --- include/linux/thread_info.h | 5 ++++- mm/maccess.c | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 73a6f34b3847..9f392ec76f2b 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -209,9 +209,12 @@ __bad_copy_from(void); extern void __compiletime_error("copy destination size is too small") __bad_copy_to(void); +void __copy_overflow(int size, unsigned long count); + static inline void copy_overflow(int size, unsigned long count) { - WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count); + if (IS_ENABLED(CONFIG_BUG)) + __copy_overflow(size, count); } static __always_inline __must_check bool diff --git a/mm/maccess.c b/mm/maccess.c index d3f1a1f0b1c1..a1b2a3a4559e 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -335,3 +335,9 @@ long strnlen_user_nofault(const void __user *unsafe_addr, long count) return ret; } + +void __copy_overflow(int size, unsigned long count) +{ + WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count); +} +EXPORT_SYMBOL(copy_overflow);