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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66FADC3ABA5 for ; Tue, 29 Apr 2025 04:06:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC3626B0022; Tue, 29 Apr 2025 00:06:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B11F86B0025; Tue, 29 Apr 2025 00:06:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 835806B0024; Tue, 29 Apr 2025 00:06:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4D6496B0012 for ; Tue, 29 Apr 2025 00:06:19 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B6F41140869 for ; Tue, 29 Apr 2025 04:06:20 +0000 (UTC) X-FDA: 83385744120.13.D3A52A5 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf28.hostedemail.com (Postfix) with ESMTP id CD227C0004 for ; Tue, 29 Apr 2025 04:06:18 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JE0vEjoK; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of devnull+chenlinxuan.uniontech.com@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=devnull+chenlinxuan.uniontech.com@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745899578; a=rsa-sha256; cv=none; b=j+VonGQwpsPisnuh3q2kUE6NdVuUgMiqSGXxLVuUzpev/Q72ydTxAUjGjHCQk2Q1Yaib9Y wIzbKEM8Nk0MKo0ZuBxLsPFS0AlFdkQV1mvWwR25QQ1D8KUH7v6vd8qfNe1OuX2sdLur82 qWiVJLKpiDdvjadpDQEkVA2eu8pWXQ8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JE0vEjoK; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of devnull+chenlinxuan.uniontech.com@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=devnull+chenlinxuan.uniontech.com@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745899578; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wdxfb83sz64pVXY/N1P48YSO3Ovk6I4U3rA1Q3+Ucd8=; b=2bKU5i4hHSLg6+G55nWeIxGVpFNdoYZ7xuf+rPO2kDuIL8NtlJqzGPHdb1+Gg6P65bZHli LP3eDFulh2ngEnnavBvEkLHXZsCGb/ft044PH3Kio9Lbfl77M3sev4I3SPNsdW+A0A3Lya 5nglOVTQKiFsM2lrYyl04zH1hNCRAzE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id CDFCCA4BB08; Tue, 29 Apr 2025 04:00:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 58FE1C4CEFF; Tue, 29 Apr 2025 04:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745899577; bh=I3qZ450wr0Q9CAPbI9DMJdfFZ5c1+02YMYdsGYpKCO4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=JE0vEjoKdI3aoLXySgz46sIqLxGHS10+ctvdryhzIzUS4HhXuF3Tl298hubpjKFM/ w6TK/WAFgLyiSvmTT0C7btzFR8/sJwuEVJ7dvhLp/FopZjfp4F38JZxjFbjWToxx+2 ZOs3hbeOeMzuD9W/l6w5BjAZ2TP8rnJk5mpj6qfsfebVTmp5WeguGbLar2dJg+54Ta BQeBNnkwOGxnWBYdRi+L77qoR8Ib+Sgt4uGR4FMtkCWkIFE7JcS9361sDdnaf8uzpI 5PpYZSpLvvidhBYF+z1LHu2vN47VszMgmkxuY95ZwPxZ0LohS1hnrc8xtucx7pzmvs 64lF44iLXmi+w== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C8CFC3ABA8; Tue, 29 Apr 2025 04:06:17 +0000 (UTC) From: Chen Linxuan via B4 Relay Date: Tue, 29 Apr 2025 12:06:12 +0800 Subject: [PATCH RFC v3 8/8] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250429-noautoinline-v3-8-4c49f28ea5b5@uniontech.com> References: <20250429-noautoinline-v3-0-4c49f28ea5b5@uniontech.com> In-Reply-To: <20250429-noautoinline-v3-0-4c49f28ea5b5@uniontech.com> To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Andrew Morton , Yishai Hadas , Jason Gunthorpe , Shameer Kolothum , Kevin Tian , Alex Williamson , Peter Huewe , Jarkko Sakkinen , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , Mathieu Desnoyers , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Dmitry Vyukov , Andrey Konovalov , Juergen Gross , Boris Ostrovsky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, linux-integrity@vger.kernel.org, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev, Winston Wen , kasan-dev@googlegroups.com, xen-devel@lists.xenproject.org, Chen Linxuan , Changbin Du X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4279; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=Bd93x7WuEFeV0iOsS3dMjqDGQS+n9awf6aimsKD9UOk=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBoEFA1dN0rUHGv15CSgUAacYmKqLp9Xxxon6yon c7TiGmprM+JAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCaBBQNQAKCRB2HuYUOZmu i55nD/9Z3vTJGmV0EjUhmeI4qXKmcdAMAq1X/bMvCKKqJb8nDqxr3XzOsrgtlGbWtGbSRpAcMRC kIBZwz/EFrXdSky2mgTEfswE2JzuHKo+Mt434POfvbTmTZzfhinHk2rveNLn14K6QQxOZNTHzoq DY3XtiBsr5/6XiSk58sFs0UB2do+v1RDxbRgPVRbwakBRf2EpGtYK+ZkSVPourJzkqG7PrIvHKY FyKSLRcxh2ehQ+zdjfMyhxbXKMW3rLF6KyReLohSbuPnAZH9vBG07d85cT+hlqayZ2VFrTJWayX ogvHBmQbs0jd6kEOOcqxulI9+HLWeFHpLWXkscXCbtKYFnN3of88CFc5dM1NBfTsa2bE/5c69eS TXaS9CEvSaJLZP2bguKxeYXuKMcX7aCIEmkb5ywt+zXQ2sBHHXVo62B2vH+ZEPTvJ0JBvREoDHA Z07bh3e0yi+U/gCk96uDLgnOmSkQUjen6r/WDp03CqP8r46lIU2aWAN8mPN0/bL6Leb+yx3Y5Gf MfHerWdPEqYeBh6stf8GRI22HdoAjnaigM4iGlYaLrvgjiuVjR2tHFFGtnPEviP7O+74W7AnPTn n9vHmKNe5H9AurNLXL/K7j5eRYSPpaBVROMuUUngVLHw7qljfnSQMwRNYonB6pGCO3WTd5AnIHj tq2/DJ+5MgngDcg== X-Developer-Key: i=chenlinxuan@uniontech.com; a=openpgp; fpr=D818ACDD385CAE92D4BAC01A6269794D24791D21 X-Endpoint-Received: by B4 Relay for chenlinxuan@uniontech.com/default with auth_id=380 X-Original-From: Chen Linxuan Reply-To: chenlinxuan@uniontech.com X-Rspam-User: X-Rspamd-Queue-Id: CD227C0004 X-Rspamd-Server: rspam04 X-Stat-Signature: wtcis9it5jbzc1axb1wy711yueq8bjc1 X-HE-Tag: 1745899578-72254 X-HE-Meta: U2FsdGVkX1+zDPDSLfxrpFehdGbUUhhyD05sB2zuOkj4Ht8+Wgb5YnbVZilrniRSCpQND9mP3FacDvwywjBO5Jqsf5dtX4yZ7sQvoBduAeo2culo2+KYLYakMh69XouIBf94VNlGHUIGIsbLLfg4TDCZ/Nu0WH2lUfFQn83gI/ajpVE5JE8NFZXWld0gS2AMTIXV4FsxXrHoinHbojfm05Wm9uBH2c5w3ACt8iORbsQW8QQu82ewkxlKt4abHXKQw0Ibj9kPPVgEShUpvaDiyNg3sNQ8CTUD+VaNjdupjhbGVyAKrEVCNXlWaN9DrzuamZ5maMHb33Nu7CZRpNMmcgM27HbScIC7x0QXcm0Wy6krYirdnz3tST+shCVYPatAn70FU7k12JMSS/PJOChFRFB/AF+UMtad2Awlm8OP8zycAMk6V4hOAzsKs2c32TkrFgRV95G1uDoJArZhhaIToo464dWumLBTDqofJ8DEEbpwdeREYhmfgP4tbPGAsKJVsFyqxZf25NT/4WTiXJ8XNfNZlLiu90Zzt2Jw2TzjVxoMgxV7Wn1xvgqSCIKPnYomwwMQ6zOykXfg/ZCLtjFZ/zmkqnjBVk7Kzo2S2XQkk3aSbKJhxMuVuHcm9Apuus1vS+EoDVUB3C2sVky6xvtGdNh7IlauvTSo8Jy17AEGHjIsXGRMUwjZUNiKc1F4X3wf+nMB7lBfD3khIJebqk9IQQy7HMxdGapz4Xt5sV3FTtjIFe91rJjA/SG2o8rXVLKXzpgcCwXfTUyWcLttuBYwIhVE69wtWm8YBsdXQ2d/Im4CWw+WUSLKRcWAamFnQ7NCs17ituz5DjWyfB32VXZtBR/4dy44sUBmPVCBn+Bgtq9w9yLVi4VHRGfhA6AR8WidWUeNt+TvqPYvvIbDkPnyfEz8pSdWZPb+PEI9ctQHjrX7BzrwcGynhm6Yoq+Nst8gQHyQ4e5C9YtNR26gcnf QuEgHI4t Reg7xBRV9SqOvdAkupwnToZcxPE5tUe71VvSZ2mEqXTkN/5AXn3U6If3FFbgEqhbczZwIuTuJ0Z34aJ8XEKs3L8rdLgcUSuLiZX8CF/bj/J+NWwJH13U0lWNZYTlFYkLSenvZj+nwl5bhzhrTO1+LMXqXy7iK9DC4v8Dng5eUfmymfauLTfj3m02epQpzqXs/q3HAndMVMcaLLb8n8s2bgMRe3YoyGYVUegYcnaYZV8oSAiddk4bzKYTJ4h28T+GpnrfikGlDfwFpGFC+he+gUu5GEBTnUjiX4szEa/zABUwWnTBDp+8AUM5xSuVLVxfhI4VEENKqX6lIoVj6DrVfuRycYXeP3VuvqfCWkpxb/Fs+Ntp5NrjLxerq7qwzxpfLTbKqz7lid64iodsVy080/UPbuUBttE/+bW8H7KNnvp3y2slgSAx3CipwDroFw67wn1jTIJ4S1PPH9MFeJKbSC66nzhAam46yVndxLoAc3DI6cy9nJyMq8ZYPajOPhyKD9x8ggJx3cZKxpz00BUWt8bUwi8t5VFw9F8EL9BloZOEiGAR5MxxczXPkjo/CqRED/tyjcTHwavGk2MynyBI+b9axuQ== 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: List-Subscribe: List-Unsubscribe: From: Chen Linxuan Add a new kernel hacking option CONFIG_NO_AUTO_INLINE that prevents the compiler from auto-inlining functions not explicitly marked with the 'inline' keyword. This enhancement improves function tracer capabilities as it can only trace functions that haven't been inlined by the compiler. Previous discussions: Link: https://lore.kernel.org/all/20181028130945.23581-3-changbin.du@gmail.com/ This patch is modified from commit 917fad29febd ("kernel hacking: add a config option to disable compiler auto-inlining") which can be founded in linux-next-history: Link: https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next-history.git/commit/?id=917fad29febd Cc: Changbin Du Co-developed-by: Winston Wen Signed-off-by: Winston Wen Signed-off-by: Chen Linxuan --- Makefile | 16 ++++++++++++++++ lib/Kconfig.debug | 21 +++++++++++++++++++++ lib/Makefile | 3 +++ 3 files changed, 40 insertions(+) diff --git a/Makefile b/Makefile index 5aa9ee52a765b7aed27f44028cdcc34a90979acb..60dec6c123543150a3332a9a819fa6933e94db4f 100644 --- a/Makefile +++ b/Makefile @@ -1073,6 +1073,22 @@ endif # Ensure compilers do not transform certain loops into calls to wcslen() KBUILD_CFLAGS += -fno-builtin-wcslen +ifdef CONFIG_NO_AUTO_INLINE +# -fno-inline-functions behaves differently between gcc and clang. +# With gcc, it prevents auto-inlining of functions but still considers functions +# explicitly marked with "inline" for inlining. However, with clang, the flag +# prevents inlining of all functions, including those explicitly marked with +# inline. Clang provides the "-finline-hint-functions" option, which +# specifically allows inlining of functions marked with "inline". +# +# In summary, to achieve equivalent behavior across compilers: +# -fno-inline-functions (gcc) = -fno-inline-functions + -finline-hint-functions (clang) +KBUILD_CFLAGS += -fno-inline-functions \ + $(call cc-option, -finline-hint-functions) \ + $(call cc-option, -fno-inline-small-functions) \ + $(call cc-option, -fno-inline-functions-called-once) +endif + # change __FILE__ to the relative path to the source directory ifdef building_out_of_srctree KBUILD_CPPFLAGS += $(call cc-option,-ffile-prefix-map=$(srcroot)/=) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index f9051ab610d54358b21d61c141b737bb345b4cee..56530f0145c885e9846dae1d2f8c6125c610d25b 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -436,8 +436,29 @@ config GDB_SCRIPTS instance. See Documentation/process/debugging/gdb-kernel-debugging.rst for further details. + endif # DEBUG_INFO +config NO_AUTO_INLINE + bool "Disable compiler auto-inline optimizations (EXPERIMENTAL)" + default n + help + This will prevent the compiler from optimizing the kernel by + auto-inlining functions not marked with the inline keyword. + With this option, only functions explicitly marked with + "inline" will be inlined. This will allow the function tracer + to trace more functions because it only traces functions that + the compiler has not inlined. + + Note that Clang with -O2 optimization does not fully support + disabling all inline-related optimizations, + as Clang does not support options like + -fno-inline-small-functions and -fno-inline-functions-called-once + that gcc does. + Some functions without the inline keyword may still be inlined. + + If unsure, select N. + config FRAME_WARN int "Warn for stack frames larger than" range 0 8192 diff --git a/lib/Makefile b/lib/Makefile index f07b24ce1b3f8db28796e461db1324d97133fdd5..2ac97f0856a12f66e6c3825af6aabafa61869262 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -87,6 +87,9 @@ obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy) # FIXME: Clang breaks test_bitmap_const_eval when KASAN and GCOV are enabled GCOV_PROFILE_test_bitmap.o := n +# FIXME: +# Clang breaks test_bitmap_const_eval when NO_AUTO_INLINE and KASAN are enabled +CFLAGS_test_bitmap.o += -finline-functions endif obj-$(CONFIG_TEST_UUID) += test_uuid.o -- 2.43.0