From patchwork Wed Apr 16 09:44:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Linxuan X-Patchwork-Id: 14053591 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21EB9236421; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; cv=none; b=MMXUDDfAbzMNGebvyDPFy60k4NUIZvq5F43Bu6Sl0hNG+J504Soc16EoKYbmrc8FO2PzZH6rcVbPP6MDj37jGoibGHrpt5WWYCxOEMpPM1XiYnkz56C6mMPwXbL8Z1/znqvAMOA2Ku+X+hswD/0gxQv5vF+jcoELx9Vpsmo13zY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; c=relaxed/simple; bh=Yv+kifpgtaJLLbyR4rAn27RlbXnINX7O4xl+RP8J8Ps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VgRVEp2sZGCjELve5cK7CflNS8wzSwNIOwmcaJNskzC7fjULShYnIIrefT8YaiG1HUcKjvyNNZRKXB00/8LX/OIgUEOUYkHvwYoEQV5hnYZh57BsLmiSyB6dL+3ierpoKovyWd+eTbENv6WIcRpf4ZVRpnVfZKQ5W13TjGNg7Cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lach4qKY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Lach4qKY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 94480C4CEEF; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744796700; bh=Yv+kifpgtaJLLbyR4rAn27RlbXnINX7O4xl+RP8J8Ps=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Lach4qKYDtR1r2uJIArcYnjlMTOKDb0ehkvd5UN0MlTPQ66miK+ydvERbEHHi1kFA tBpf9tUwVubeot9VKKHdObFIhyHr/l51RlJxsTRZ8oj+g4/BdRuPjSBNuldgQBVM+9 UvX2qv3N66+SaIbevmpj0dgd+m8BxLNLtkxxA8hz1nsdQQLysQx6/OlU0DrTjpN/i1 pfOB/R/QsgyA7x4qHvwXeyAh6EW9/Zr4yPpm4MGoXjLe/CsH00SkVm2vlbMhQ71VT6 zbEXJXdUkgPzB0m6KeyasjYLeU/Lt3gTqLYOSq30P+a2Ew9wGYWT/leA7ITiHM3RxA LyZSn/JD5X2vw== 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 79C67C369BD; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Date: Wed, 16 Apr 2025 17:44:47 +0800 Subject: [PATCH RFC v2 1/5] nvme: add __always_inline for nvme_pci_npages_prp Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-noautoinline-v2-1-e69a2717530f@uniontech.com> References: <20250416-noautoinline-v2-0-e69a2717530f@uniontech.com> In-Reply-To: <20250416-noautoinline-v2-0-e69a2717530f@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 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 , Chen Linxuan , Changbin Du X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2975; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=sGDh7M1GW9E/6Y/0K/CCKXvss9WxUze9tBDMdqLrW6k=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBn/3wVG003JQmokzL+qRyfJcdxP60RFA0LrONcP OK5orjrbTuJAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCZ/98FQAKCRB2HuYUOZmu i8TED/0fmsPVnspcWh0W6L0ZSZOLbCvbFNwkSR8ln0sclXUOPtKwmyiPlZa4zJmx7OcofjIaLD/ r/WJyI8YJpl735QY3QIBTbrps+iGTDVaqLw8NMv1GsgSn5r61K4TxGHIfCjlSFoamR3OMWdNCrS WgKkuDC2E6ay6dA0WfzSP78maBTAvxztzt0mrFpxZQijD5Ky6gSFVQAeztouTp6ootKC9gvMeO5 +gtRmuu9R5kMvmwGyagr3VY9mc0otVIg2xlYhJiaVOu4CfRoc0oOpQcaFGlds7Ffe9vB6Apy562 0ADyZ/DVMUzU4vli0sb0ABqeWUWJvQn0/PvNjTUSDE7ohfpIGMasSJ4U4pGTk2h2Uup4lO1Qk5Y itpYWcQQWcxZirZzGnfIAEsscrdlIW1hfEPHbAAmbwUCKwM4mYIvIvT4jVx7V8WAsDJybp72ugL sSHbcb/PohzAsREiVXj+ctQfKvFssyCqeC4QmvrsOAIySwTmvnVd/kmriXFtFBV32jCCFt1yrzy DHcdVAGXK0AEbs+63WGWuWrlpIqyutFQpNNkxOFaL3DlLSgZdNLg8Z6TeBEpltgoSrnRHWSN6KK 2We5DBjR8F7GIDWR3F/H9QRYE/Z0BaE7a9oEZKSwd3QL13ItpXVkjs4ZYIJ497+OIimgPtSzbF9 Tn7aHUXUKD2PLjg== 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 From: Chen Linxuan From: Winston Wen On x86_64 with gcc version 13.3.0, I build drivers/nvme/host/pci.c with: make defconfig ./scripts/kconfig/merge_config.sh .config <( echo CONFIG_BLK_DEV_NVME=m ) make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \ drivers/nvme/host/pci.o Then I get a compile error: CALL scripts/checksyscalls.sh DESCEND objtool INSTALL libsubcmd_headers CC drivers/nvme/host/pci.o In file included from : drivers/nvme/host/pci.c: In function 'nvme_init': ././include/linux/compiler_types.h:557:45: error: call to '__compiletime_assert_878' declared with attribute error: BUILD_BUG_ON failed: nvme_pci_npages_prp() > NVME_MAX_NR_ALLOCATIONS 557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^ ././include/linux/compiler_types.h:538:25: note: in definition of macro '__compiletime_assert' 538 | prefix ## suffix(); \ | ^~~~~~ ././include/linux/compiler_types.h:557:9: note: in expansion of macro '_compiletime_assert' 557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert' 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG' 50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) | ^~~~~~~~~~~~~~~~ drivers/nvme/host/pci.c:3804:9: note: in expansion of macro 'BUILD_BUG_ON' 3804 | BUILD_BUG_ON(nvme_pci_npages_prp() > NVME_MAX_NR_ALLOCATIONS); | ^~~~~~~~~~~~ Mark nvme_pci_npages_prp() with __always_inline make it can be computed at compile time. Co-developed-by: Chen Linxuan Signed-off-by: Chen Linxuan Signed-off-by: Winston Wen --- drivers/nvme/host/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index b178d52eac1b7f7286e217226b9b3686d07b7b6c..9ab070a9f0372bc6595c29a884ee9f2ffe5ae8e9 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -390,7 +390,7 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, __le32 *dbbuf_db, * as it only leads to a small amount of wasted memory for the lifetime of * the I/O. */ -static int nvme_pci_npages_prp(void) +static __always_inline int nvme_pci_npages_prp(void) { unsigned max_bytes = (NVME_MAX_KB_SZ * 1024) + NVME_CTRL_PAGE_SIZE; unsigned nprps = DIV_ROUND_UP(max_bytes, NVME_CTRL_PAGE_SIZE); From patchwork Wed Apr 16 09:44:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Linxuan X-Patchwork-Id: 14053593 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21F9B236426; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; cv=none; b=HIyqgFbkgmpTSAA2DoqDY+IF83smhFWBSssq31PFs00cw5eVmfqSaCuAuszthnbfOjEFG/5FzOYRhBKyVuqBaHpYEflzOKauTf8w9UbymQWFezYRRWuS/YOT4i1E2dUcJaEifTVbDJ3AIRfZCoH+D5cOJPYioIF+js0kFOB+YcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; c=relaxed/simple; bh=yYZIxP4eDVftHS+35Bjf5qEDsqvjLlou31P6uZ50WKA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N6z9elceUNg5dEnc6QYXe6SkajH8FC0gN41KYgmEX/W7UaiLEbNMskKfeRyfBcX7FiqA/uIJo5xzEIpOa6Ot06kJHRDtbI2ntoZu7sCd437G4fAtBByMf6suJX7EOOLom2voNacJJk1eV2dHaThwWclh3Bi8EOMS/N1plpCtiB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TCGReCd0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TCGReCd0" Received: by smtp.kernel.org (Postfix) with ESMTPS id A0A10C4CEEE; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744796700; bh=yYZIxP4eDVftHS+35Bjf5qEDsqvjLlou31P6uZ50WKA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=TCGReCd0cEKmjkNtA7we6hJ+GgtymTTF7EuDFkMlXZKe5wQlwsumnY9tZSo8n/zc0 21ZWbI5r6KRGErwMi/dDmuJtq6LOYx5KnF6rQAkObQzUH1wnEbvHi1QdVsGZGj66Wc iY9cZAuM2Paaseb0Z1i6tZQ+1dTavp5c1wjtPZ/oqgkQnPRfMz+OnjllQ1rcVro0rM VZh5ZWbJHfGbIG4RrEM0zxtOdldbySwtzy9Ww0oal39Ur7u7wrd+xv6m+0weZFe85Y psks7hifOw+5lMCNPBDniJkrqtuqj68pw832qf0OXJZFFUQ3CdlwVaxWsWotQ1vOR1 c3GCbBPLxVB7w== 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 8D974C369C4; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Date: Wed, 16 Apr 2025 17:44:48 +0800 Subject: [PATCH RFC v2 2/5] mm: add __always_inline for page_contains_unaccepted Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-noautoinline-v2-2-e69a2717530f@uniontech.com> References: <20250416-noautoinline-v2-0-e69a2717530f@uniontech.com> In-Reply-To: <20250416-noautoinline-v2-0-e69a2717530f@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 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 , Chen Linxuan , Changbin Du X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2614; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=ttFdjRheVD1OZ/EkBldHAgXU1FfcO+q/qyDgNDO6xxA=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBn/3wWMkdWR1YmxGEaQM5rETmyOEwb9WgsyzPib 4h8ODg1HWCJAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCZ/98FgAKCRB2HuYUOZmu i+cdEADNT/9txgL8kjyC/wPjKEbB4hl/RFInpiCxVodRBNIWw5wpfvJ5vsG8gnTV28kQFDiRMbh hKll+Yo1pN1WQwmBS3d0F7h/e18CCNShQvLvfLAloblN1i7M1UgnmKeKL76XXDUKRxxqrQeTHDP CUMus0UtivuKibqn8CLVq6e5fbJ1RhwPsbv7D70xVHOM74/icwjmj1dPZu6DpYDfV5l00GYGS2b RsSbfDKkS9Y3H0ZIRiS3VMyQ2uK/1lqDTRcNw69OTDtKzeRDqUXkzTmAkZ1yo+XWJbU05MQnvN9 95PO/4u9U8yOzdSEY/JzzWE8B1jzPggCyIQR3AoEtU8sfvLzO8U1ro3Jw17/wQxZ0LL4csNqfmo fMDkPLMBwX4axRH3oyhhJpWNuOne+5V4FZe7ofqs5chLYTiWmguAJff7K3CLwNjtYf9wekUajng MeEUFOGz9PS4je56fpstwRPl0osMBPmAQhMUflHy8jGVX4Ai+mMmo72HfvLkq7gg2eqgpyQBohN pVdOVMQI8YGR2JwWxAFHXkIHE7b4wdHwN4V18J30GXbYxJ/TDPKqwiiNz0eQmx1nF4kWUuws9WK FifDNoUxHM5cv3Bi8sey0k3QP5FiIx0iDAMhW+1X3ikwX72hN0Whkhv84Sn5/keiJ0X/R0RCmo5 d/FA4FSNrATMSUg== 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 From: Chen Linxuan From: Winston Wen On x86_64 with gcc version 13.3.0, I compile mm/page_alloc.c with: make defconfig make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \ mm/page_alloc.o Then I get a compile error: CALL scripts/checksyscalls.sh DESCEND objtool INSTALL libsubcmd_headers CC mm/page_alloc.o In file included from : mm/page_alloc.c: In function '__free_unaccepted.isra': ././include/linux/compiler_types.h:557:45: error: call to '__compiletime_assert_1013' declared with attribute error: BUILD_BUG failed 557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^ ././include/linux/compiler_types.h:538:25: note: in definition of macro '__compiletime_assert' 538 | prefix ## suffix(); \ | ^~~~~~ ././include/linux/compiler_types.h:557:9: note: in expansion of macro '_compiletime_assert' 557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert' 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:59:21: note: in expansion of macro 'BUILD_BUG_ON_MSG' 59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") | ^~~~~~~~~~~~~~~~ mm/page_alloc.c:7301:9: note: in expansion of macro 'BUILD_BUG' 7301 | BUILD_BUG(); | ^~~~~~~~~ Marking page_contains_unaccepted with __always_inline and let dead code elimination remove reference to __free_unaccepted() here. Co-developed-by: Chen Linxuan Signed-off-by: Chen Linxuan Signed-off-by: Winston Wen --- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fd6b865cb1abfbd3d2ebd67cdaa5f86d92a62e14..7c0934c818ddc719c2dcb813599708f47d56352c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7286,7 +7286,7 @@ static bool __free_unaccepted(struct page *page) #else -static bool page_contains_unaccepted(struct page *page, unsigned int order) +static __always_inline bool page_contains_unaccepted(struct page *page, unsigned int order) { return false; } From patchwork Wed Apr 16 09:44:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Linxuan X-Patchwork-Id: 14053594 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 551A1236442; Wed, 16 Apr 2025 09:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; cv=none; b=QV4JJyH2sAsx65lqPoDnxw0GWI+MbNA/bNenl0GQ066U0cAh1bF/ay11oXQ6ZofXL9gNwnq5SpLs8eqXxGsYCb5Sy7YcwF8cywSmWCb9pdjDqmJtx7N7phFq8pea5NMB83WL3Bb6CZPLrZSrLWkg75BJPegQz4qLEURAm/N5amI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; c=relaxed/simple; bh=GjcjBI58OgkVj8A5MLEXwdxEl+hceaKdCujeEc2HSq8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=akFCK2VeBxlIiLLKBQ7IyVtVqdFIBoY6XIFCn+nvb5VcQzlmMnPUALb+mrRW1dIhzGSFZyzqX/e15PE1DraI5BYR7Aods0YO5rzqbBzZ5bRL/WCqnbUPNVbLRAr+1yDFHi7Fw8IxcDdDAWLvm+e8ekwkgbeWN4YmGNpdL5ujfwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Hpeeedmw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Hpeeedmw" Received: by smtp.kernel.org (Postfix) with ESMTPS id B9C51C4AF0C; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744796700; bh=GjcjBI58OgkVj8A5MLEXwdxEl+hceaKdCujeEc2HSq8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HpeeedmwxModiIUGwGODlYHdZ5Ouui4lrihbjt5fwrYe1597/V78+LnWA5mkeCTZR yYWR/bI5vYw5OTg+APj7OOunCrZ0+KiD1AziH2HhopWV/3/3kYz/j8VDF8mjvKZgJ0 bWS2lBz/6K8LzgX/DRzlbN7IrXUzZP+Ndnd0A6QeduGQFdXj1cRRvygc7fH46VvN6g NR8bXb9VlE1fhkapaO/1mzub3KaJ6u8Ddqeo5IQj9uHkP9HLJ0783ZMLVV4SLrHfpZ IZnt2hxhV4YuTZ0a4owR7onUEWfN2tBfeGHRAdZFAE63b3ZNNwdxv67/Yubkt0pnya ExIwjPbPhRTvg== 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 9FE6AC369C5; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Date: Wed, 16 Apr 2025 17:44:49 +0800 Subject: [PATCH RFC v2 3/5] vfio/virtio: add __always_inline for virtiovf_get_device_config_size Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-noautoinline-v2-3-e69a2717530f@uniontech.com> References: <20250416-noautoinline-v2-0-e69a2717530f@uniontech.com> In-Reply-To: <20250416-noautoinline-v2-0-e69a2717530f@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 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 , Chen Linxuan , Changbin Du X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3264; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=PuGcJxOd8DayapVsQ7YIhWxmF6aRHfRlTC8JQBmNN9k=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBn/3wXtW1weup2hT4Z+Yi7yoKEwnZs3b7CyORfq Xvvrwno7P2JAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCZ/98FwAKCRB2HuYUOZmu i1tpD/9a1TgfBtJrQZp06BwLsq7szJqErUQ8zTs0NqXhMPs3oGvshKi5/TpP/fH2XNZsqCCmTrz EtRpJ6f358wwfWUO6ys8nznwN7yNLcVVL8/qeEfHcZNbaRmoB1xRQ6GKvyJG7BAWR8uH4oub3GH bpSELAUuBC3xjihAlngAnlycH8/MAHxYjAXaQKGfcFsHCmx8GsshG2zAyRxH1CwrPxy5cfE4plC Zv3YiC8Ee4UmznjWnqVs31WWKs//iFnwfYHrFvo97dOU4PNCv/ZWRp+HoExOd5x863v/jYnOH9B F1c0lU4TGvUiOghX8v6ULJ1QofhSuWfJq5oYZSRc0o94MVpVjkfbuJqrfLHtF/6MgvoN0ne1h/T yx3KItyQEYvUgfT/sQ+bbN2s8pTQL4MI0qI9F/p04Tgp9N4R58vkOYKqdP6Dqet6tIhX3SdxrgX BY4XhL0HxUUfpgPjp3pykTxv03TG+ETBHlrNzbYrz5iaIFt3XUqFkDT3hCXVj16IDA4ilqjHn5R KaBpzLHTr5Q80Ao7V14YGMflufW3NFQXMu+pw22boy/8lsiFcKKmdzoM+giVIGfVUXS5ObqO3+i EktURcgQB8LRFDMgM7DfcJEzzT9XXuThlEfmJQ33+OMZ0B9S+kEvpXTSBUSiLuOA/4AtnAZNhse DjYNXNAakI/Vl6A== 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 From: Chen Linxuan From: Winston Wen Presume that kernel is compiled for x86_64 with gcc version 13.3.0: make defconfig ./scripts/kconfig/merge_config.sh .config <( echo CONFIG_VFIO=m echo CONFIG_VIRTIO_PCI=y echo CONFIG_VIRTIO_PCI_LIB_LEGACY=y echo CONFIG_VIRTIO_VFIO_PCI=m echo CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY=y ) make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" \ drivers/vfio/pci/virtio/legacy_io.o This results a compile error: CALL scripts/checksyscalls.sh DESCEND objtool INSTALL libsubcmd_headers CC drivers/vfio/pci/virtio/legacy_io.o In file included from : drivers/vfio/pci/virtio/legacy_io.c: In function 'virtiovf_init_legacy_io': ././include/linux/compiler_types.h:557:45: error: call to '__compiletime_assert_889' declared with attribute error: BUILD_BUG_ON failed: !is_power_of_2(virtvdev->bar0_virtual_buf_size) 557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^ ././include/linux/compiler_types.h:538:25: note: in definition of macro '__compiletime_assert' 538 | prefix ## suffix(); \ | ^~~~~~ ././include/linux/compiler_types.h:557:9: note: in expansion of macro '_compiletime_assert' 557 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert' 39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) | ^~~~~~~~~~~~~~~~~~ ./include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG' 50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) | ^~~~~~~~~~~~~~~~ drivers/vfio/pci/virtio/legacy_io.c:401:9: note: in expansion of macro 'BUILD_BUG_ON' 401 | BUILD_BUG_ON(!is_power_of_2(virtvdev->bar0_virtual_buf_size)); | ^~~~~~~~~~~~ BUILD_BUG_ON needs virtvdev->bar0_virtual_buf_size to be computed at compile time. So we should mark virtiovf_get_device_config_size() with __always_inline here. Co-developed-by: Chen Linxuan Signed-off-by: Chen Linxuan Signed-off-by: Winston Wen --- drivers/vfio/pci/virtio/legacy_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vfio/pci/virtio/legacy_io.c b/drivers/vfio/pci/virtio/legacy_io.c index 832af5ba267c49a079009cfe0fa93c15ba7a490f..b6871d50b9f9e278ef3c49a9cb2baf474b8271c6 100644 --- a/drivers/vfio/pci/virtio/legacy_io.c +++ b/drivers/vfio/pci/virtio/legacy_io.c @@ -350,7 +350,7 @@ int virtiovf_open_legacy_io(struct virtiovf_pci_core_device *virtvdev) return virtiovf_set_notify_addr(virtvdev); } -static int virtiovf_get_device_config_size(unsigned short device) +static __always_inline int virtiovf_get_device_config_size(unsigned short device) { /* Network card */ return offsetofend(struct virtio_net_config, status); From patchwork Wed Apr 16 09:44:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Linxuan X-Patchwork-Id: 14053595 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55142236441; Wed, 16 Apr 2025 09:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; cv=none; b=nx3RUg73RehQFrl3TlPSXoj1GsLYuHk34ISAUrUBaw6Hr0jgxmzd/kmXE1xRkc2yoXyLolC2jcKE/a98AsSgZAivjeb3xHBkmaH3zUmA58n8oAcD9zAPiTsrrnbc6HDjIPtHWM5+y6RB1GWNn9Mw3F3EI+A0OayZQsbQ1guJIcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; c=relaxed/simple; bh=pRU6wLgxXnLL1nq6ekG3r0pNLgbdqaE3J4O9xny8g9g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u1BGpr8kGLvNxhgHeEvxIWZY2YL740+jmQfknJzaBVEWTARjSXKbgKkQn3DgDZn0pCegSZDJbbJLdAyObn9sJPNKft2Y+p+q882yESNWBDs/vM5P9VSkREkvx+5Wy8U+eaR4C2kbIW9nadLNjnp+qHgu4cN3aOKYrrN5EQvaCkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ekqj+Gu/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ekqj+Gu/" Received: by smtp.kernel.org (Postfix) with ESMTPS id C2A3BC4CEF3; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744796700; bh=pRU6wLgxXnLL1nq6ekG3r0pNLgbdqaE3J4O9xny8g9g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ekqj+Gu/0hKmxeU3sm6q1f2ryuXtUFna6ArZ7i8VRK8suIQwaNNKThLw6ImaKsr5K t0mZIWV5XLpX6VHLck+gcTnsQVTrinH9PM7QVd9oguTIrn7SNyEEyk6GhQt2eCE+Xq 58clWQAoWoEdCiRa24pVL33ZaWLNOUUCVE8PHQl6gKwS4H+pAlXWIgRnzBmqWeoxZ+ STzsWCztCoWIdguL6ckBQtCF9551uC+sBRoMfvnJNK5FFrkWClkz563175vEhlF9nU B+hfAzBO8AkYTDIbAad2roMX8GONH0N9cvXRru8OFUGmGo3obvCkayvcukwGaF4p/D zk8QiATZhVaGQ== 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 B12E6C369C1; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Date: Wed, 16 Apr 2025 17:44:50 +0800 Subject: [PATCH RFC v2 4/5] tpm: add __always_inline for tpm_is_hwrng_enabled Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-noautoinline-v2-4-e69a2717530f@uniontech.com> References: <20250416-noautoinline-v2-0-e69a2717530f@uniontech.com> In-Reply-To: <20250416-noautoinline-v2-0-e69a2717530f@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 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 , Chen Linxuan , Changbin Du X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3892; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=eVMGMErwkSKVlhFsRXd5VgFhkcLZ6sQRGgY0l5PVv8Q=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBn/3wYTeAxxXYaBDNq6MoKT5/qwja5tvQJEZiWQ VjsA0MmYHeJAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCZ/98GAAKCRB2HuYUOZmu i72UEAD2OIFAhd0YqHWxRgTYgam80CB7jU1JXtFVmnHuEVb2fZKwu3HLJvvNPTdU488rihW29Gv a7Mp25dYGsmpP7Y94+fu8UZ4WFHadCc8hD/JMAHf9TYKA/QHF305zxqKfWDFsh45+9l/9GyxUGx pn9FPSvodZ2un0zqttouu2KSsIVrqiSaWsJ/CJMWPUymTUQtgjhjTQYRpNgPD1Hgzy1NLg7qFn2 xXZ8H66IWPbH/UYx8FYT4u1nexNR8phuoDm1tbZgVG2reCPwbE7aqnvbp4nvOni6Ry75bTal19f 1ph+O4sFDpacQ3l/zIvqqWbja+D5nbtDyeljbPTOLtO9BiUunxTtWzxx1jP9pZ+AfthSYLHtP6i Fw0i6kS/FCH2vL86HtHiWMVhZLa2TB0sXTxz8IG1a5F+Ws6KUU8ATsuG7kYv/CVgO4uMR3caLvt 9ZmjawH5WNd8M6YqYA9gX4OzOGn9BJL5MYTQQNg6vbx6UpzwWXxG1m/96VBePk+auO80b2gyVcW kLoKOHVePJDYSgmqibXWCc2BQIEjkqDF1/bZgB/tuqmreGPUjrxR2RtT0xRLlh2K1fSFHUjMV26 wpWwKRlygPJbqNOMeoSfRl7qf5jn3XSxZvex19Soc7LaN/0iI+vfTTCYk/j6PbihEFAmhkJ92r1 +J10jZUB46Z8qgg== 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 From: Chen Linxuan From: Winston Wen Presume that kernel is compiled for x86_64 with gcc version 13.3.0: make defconfig ./scripts/kconfig/merge_config.sh .config <( echo CONFIG_TCG_TPM=y echo CONFIG_HW_RANDOM=m ) make KCFLAGS="-fno-inline-small-functions -fno-inline-functions-called-once" This results a link error: ld: vmlinux.o: in function `tpm_add_hwrng': tpm-chip.c:(.text+0x6c5924): undefined reference to `hwrng_register' ld: vmlinux.o: in function `tpm_chip_unregister': (.text+0x6c5bc9): undefined reference to `hwrng_unregister' ld: vmlinux.o: in function `tpm_chip_register': (.text+0x6c5c9b): undefined reference to `hwrng_unregister' With `CONFIG_TCG_TPM=y` and `CONFIG_HW_RANDOM=m`, the functions `tpm_add_hwrng`, `tpm_chip_unregister`, and `tpm_chip_register` are compiled into `vmlinux.o` and reference the symbols `hwrng_register` and `hwrng_unregister`. These symbols, however, are compiled into `rng-core.ko`, which results in the linking error. I am not sure but I think this weird linking error only arises when auto inlining is disabled because of some dead code elimination. `CONFIG_TCG_TPM=y` and `CONFIG_HW_RANDOM=m` set `CONFIG_HW_RANDOM_TPM=n`. This causes the function `tpm_is_hwrng_enabled` to always return `false`, as shown below: static bool tpm_is_hwrng_enabled(struct tpm_chip *chip) { if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM)) return false; if (tpm_is_firmware_upgrade(chip)) return false; if (chip->flags & TPM_CHIP_FLAG_HWRNG_DISABLED) return false; return true; } When `tpm_is_hwrng_enabled` is inlined, dead code elimination optimizations are applied and the reference to the `hwrng_*` functions will been removed. For instance, in the `tpm_chip_unregister` function: void tpm_chip_unregister(struct tpm_chip *chip) { #ifdef CONFIG_TCG_TPM2_HMAC int rc; rc = tpm_try_get_ops(chip); if (!rc) { tpm2_end_auth_session(chip); tpm_put_ops(chip); } #endif tpm_del_legacy_sysfs(chip); if (tpm_is_hwrng_enabled(chip)) hwrng_unregister(&chip->hwrng); tpm_bios_log_teardown(chip); if (chip->flags & TPM_CHIP_FLAG_TPM2 && !tpm_is_firmware_upgrade(chip)) tpm_devs_remove(chip); tpm_del_char_device(chip); } When `tpm_is_hwrng_enabled` is inlined and always returns `false`, the call to `hwrng_unregister` is effectively part of a `if (false)` block, which I guess that will be then optimized out. However, when the `-fno-inline-small-functions` and `-fno-inline-functions-called-once` flags are used, tpm_is_hwrng_enabled is not inline. And this optimization some how cannot occur, leading to the undefined reference errors during linking. Adding the `__always_inline` attribute ensures that `tpm_is_hwrng_enabled` is inlined regardless of the compiler flags. This allows the dead code elimination to proceed as expected, resolving the linking issue. Co-developed-by: Chen Linxuan Signed-off-by: Chen Linxuan Signed-off-by: Winston Wen Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index e25daf2396d37bcaeae8a96267764df0861ad1be..48cc74d84247e258a39f2118e03aa10d0cbb066a 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -534,7 +534,7 @@ static int tpm_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) return tpm_get_random(chip, data, max); } -static bool tpm_is_hwrng_enabled(struct tpm_chip *chip) +static __always_inline bool tpm_is_hwrng_enabled(struct tpm_chip *chip) { if (!IS_ENABLED(CONFIG_HW_RANDOM_TPM)) return false; From patchwork Wed Apr 16 09:44:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Linxuan X-Patchwork-Id: 14053596 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96B2D2376EF; Wed, 16 Apr 2025 09:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; cv=none; b=skXX7rICUQDQMn8RTC06fCbrmgB6JmMmJNPL2HZcIQkeNRp+eQU0H9lf2Xqd5AiGOZnn4DNIkUY49ZnXv+wl2fuPbcA1FlBmjbx+smgJcwX+UnRQQOgAyDSwBnmvee19mOInXecc/E/U4ITkdWyAYvUAtiTXu5sS9dS3YFGIUfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744796701; c=relaxed/simple; bh=y6sNLqLklzVcWeo9kuxbWWkQNColAUNOTv6uOnth8tc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CMKoR5IQXVvvhnLqlzRBzelAuYVUqbkyQKjIHlc3IVaSChpZg8fkvAGeu83BYI7KusZAjyLZ4xF5Zt/sbXxLdy/oJppMGaC8Co9mZKFpdClQZp75wV33IBmZ3AtY0noWxqJaZlBQG7qYRvIRS7DGryeuWR9rmI9J2ju1pZnlsZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HH1A403b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HH1A403b" Received: by smtp.kernel.org (Postfix) with ESMTPS id CF0A4C4CEF6; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744796700; bh=y6sNLqLklzVcWeo9kuxbWWkQNColAUNOTv6uOnth8tc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HH1A403b+hjSeYH0fFnCcyVe3XGHSUQPNkSJexeBqDpRrGhcBviUoIMSx55nUSPHc 7E2bOgl3XRblTUkvQiIH3j+Oe8tYXl5itG/R260Ckf+vjYlbDGm9wnykwHav/jGvKd HKOmMs2makfVltunNUFav5U7lB3/aGHP2iQg+tG8XV9j8NVptMijlodBYp274h10Cm BUhJ8Awo0UtY3JBapaSwGpz7v9nob885b8E6Z8m8POQmCnCiNWmTs7kYV44HgkQ8DK rSelb4535t5KDJhZldmuN2v5BTflT4lwrpvUUjKvvz/eihiQ1oVQQkCbAeza8o1QKM AvZp8tmlNMiLA== 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 BFE19C369C7; Wed, 16 Apr 2025 09:45:00 +0000 (UTC) Date: Wed, 16 Apr 2025 17:44:51 +0800 Subject: [PATCH RFC v2 5/5] lib/Kconfig.debug: introduce CONFIG_NO_AUTO_INLINE Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250416-noautoinline-v2-5-e69a2717530f@uniontech.com> References: <20250416-noautoinline-v2-0-e69a2717530f@uniontech.com> In-Reply-To: <20250416-noautoinline-v2-0-e69a2717530f@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 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 , Chen Linxuan , Changbin Du X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3064; i=chenlinxuan@uniontech.com; h=from:subject:message-id; bh=F+1qLaqiauypU+BRTQYkrjZEyIF0AG4hvaXQhsgJYk8=; b=owEBbQKS/ZANAwAKAXYe5hQ5ma6LAcsmYgBn/3wZT3NWiI2S8hRz1pjrEUmLoC/gt8RZUtPaC lubpf4A4hyJAjMEAAEKAB0WIQTO1VElAk6xdvy0ZVp2HuYUOZmuiwUCZ/98GQAKCRB2HuYUOZmu izAIEACY38ESmIVOjDr7Iwh8UUrW7TzIcDjdsV2Gz25pzxNRYt2UN7F1ih++IU0mVKuCRE8VqsZ COqv1koPLnaC5FnVtv40PZwIiMbk1JDsa2ErGt5FBgb7ada1ai8OVfO05xZmtLjDLu0LBYqJs20 54Nx0HAjECSeFJB7FsRxoyck9coB80nqWw4d6BRS0UG3/nsZJYJ5zvs3iEpL5BtNePBanOqbBao ey+EM2gyLwiAvD/x7pkIaPnvF9Y35X4eRaTm8+SYc48zK0Q/+9L5Vg2bmyyF9Up8vdoPVfNYD49 zE1q9RpL992v3uSn4Uh+/XGggbgTV+nw1SXRZH1NcwML9S5Tk7czniyVD1h4KFXKUZpvkZvhQi/ eU5K9FTQedxVsK+gma+7I3bWAbm0Yn5SZ9gUzZHGIHWSMNM6aByhX3QVbVGcrvz9uBgzJLA6G2v blyyctLKffNf5k3i4oGfEufOigeC2JeVcreJ8YcvZos9m3zQ9f+SWCKtvtlFdNpgcm8q7SgYEOi Vs4lmIBCBb2MgxZbCKfiz5qnt49ANDdBLL+6jGfnsSCdSR9yiHKDzItW4XHG62rQaZ/UgtnvTqP guR1IhGM9mQRv0qGS8ujapIi7oqfU995Jy3XGAG6t4uHwd0t7yItMqwthqHQwNxtgOzeuuclW/d ThVxVEEuZANNvYg== 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 From: Chen Linxuan From: Winston Wen 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 Unlike the original implementation, this patch: 1. Make it depends on CC_IS_GCC, as Clang 18.1.3 break test_bitmap_const_eval() in lib/test_bitmap.c 2. Make it depends on X86 and LOONGARCH, as I haven't test other architectures 3. Removes unnecessary cc-option checks per commit 7d73c3e9c514 ("Makefile: remove stale cc-option checks"). 4. Update help information. Cc: Changbin Du Co-developed-by: Chen Linxuan Signed-off-by: Chen Linxuan Signed-off-by: Winston Wen --- Makefile | 6 ++++++ lib/Kconfig.debug | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Makefile b/Makefile index c91afd55099ea6bc7ed89bc3ef9cf58a498596d4..52da2c27f94167d2d2892a67c065e5df15efbde0 100644 --- a/Makefile +++ b/Makefile @@ -1071,6 +1071,12 @@ endif # Ensure compilers do not transform certain loops into calls to wcslen() KBUILD_CFLAGS += -fno-builtin-wcslen +ifdef CONFIG_NO_AUTO_INLINE +KBUILD_CFLAGS += -fno-inline-functions \ + -fno-inline-small-functions \ + -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 9fe4d8dfe5782981cc0b2b6614106aac570bd229..2ebb4802886ab4a48841dbdd8973b7d9883548b9 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -436,8 +436,23 @@ 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 + depends on CC_IS_GCC && (X86 || LOONGARCH) + 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. + + If unsure, select N. + config FRAME_WARN int "Warn for stack frames larger than" range 0 8192