From patchwork Mon Sep 25 22:35:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398522 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 917F1E6FE31 for ; Mon, 25 Sep 2023 22:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AuRO0olmjkoZKEzKSNjKANZWNlxATUzGwnfZVMFCCXs=; b=hOT5UN1HmpNREF s7ngxbiziYtC0MU7LrLd8Un3dnjNA2VNUkXeLUZ47HisWoUfT8CSdclYgsdaof4fnuQ+3Hw8QCTEh /FierRqNxjW49AtXMKB4V9/9Cb8FueUKCSGtvHM2s9iWtXbm+SKLaDqeUzjzyA3RGwzPB8MBEyXJg ioxLHMRqyqf9u+3hmi3TDGETVNjpjrq7LIO7daZ5ntef23Zq476H8k8WcDtDsm4b5OvHIbutK6cDx TgnDTfCn4EQ2wUBbTZf1HLudAcw+XpjK3hC8bi6WOBzkVRY6wMbIz9SMG/VxEXPpt85cLnk+ok8pW DJ59tztKoPoZuNgvCnew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuAt-00F96X-04; Mon, 25 Sep 2023 22:35:31 +0000 Received: from bg4.exmail.qq.com ([43.155.67.158]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuAq-00F95q-0U for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:35:29 +0000 X-QQ-mid: bizesmtp69t1695681314trhnno76 Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:35:13 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: 5q30pvLz2ifym5SLIzsh144Znm6wRlu+bPV0w9peTQtfsIPVYY0hXdp41PdCD qNzUX3VU0ZbZvFxqzdl781ox5Wff3pzWuKKNI6Te1Y8Odq1dErSA2qLbFA/SMI2cKUrzOVs JqSkwphfZ1OdgeG+SXhsqzaC3EdPtZ01WiX3xWijTjjHsIaAgg69GAJkp+9VvBK+LXtqy1j nrLN7pG00O3beVVn6nNJXOacEGL+QVJsdzrevmusz0g8QdKt9Gmkrc6JmfWCThmyuCXGiVh gjxq5yWAioV+s2WgKuEpfsGOozhlcqRN+oC8EBu5Z9jN5LH+6xf8e1VBtfxSu4YLC8kyaQi XdE5S4RGw+7MohBQiYCuUk9wCwPZJByKg1RLiR97lDnE03vxkhVdJMeJFQ4NQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1656431424344420643 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 1/7] DCE: add debug support Date: Tue, 26 Sep 2023 06:35:11 +0800 Message-Id: <36d7ee5122e3a9c2b307cf6ab1a9508860fd7710.1695679700.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_153528_521702_E5869623 X-CRM114-Status: UNSURE ( 7.15 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Enable --print-gc-sections for --gc-sections to monitor which sections are really eliminated. Signed-off-by: Zhangjin Wu --- Makefile | 3 +++ init/Kconfig | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/Makefile b/Makefile index 57698d048e2c..a4e522b747cb 100644 --- a/Makefile +++ b/Makefile @@ -938,6 +938,9 @@ ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y LDFLAGS_vmlinux += --gc-sections +ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION_DEBUG +LDFLAGS_vmlinux += --print-gc-sections +endif endif ifdef CONFIG_SHADOW_CALL_STACK diff --git a/init/Kconfig b/init/Kconfig index 6d35728b94b2..4350d8ba7db4 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1404,6 +1404,13 @@ config LD_DEAD_CODE_DATA_ELIMINATION present. This option is not well tested yet, so use at your own risk. +config LD_DEAD_CODE_DATA_ELIMINATION_DEBUG + bool "Debug dead code and data elimination (EXPERIMENTAL)" + depends on LD_DEAD_CODE_DATA_ELIMINATION + default n + help + Enable --print-gc-sections for --gc-sections + config LD_ORPHAN_WARN def_bool y depends on ARCH_WANT_LD_ORPHAN_WARN From patchwork Mon Sep 25 22:36:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398523 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1EE4E6FE31 for ; Mon, 25 Sep 2023 22:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KNsa/86afP87iHvrven4IvAt5j48z2qj/v6a1W04ac4=; b=Dzkz+jIo/G/Y3g y0ZuMwfJ3sn0q0x126l3YdqYG2nFfeZxGS5HFURSzW0het7qPS+j+7nalyafgeLEDhveiwXEE3IVn Xwct1DKxiEZTyimAq58RXLw5rVIkCZhKPNAyQYwPFZnD/+EqqXPY0O9Sv9hlQ8Srl6MtRK7MhhDGZ WqZdMa/YcwzZo7hdxoq0vmIV4s1OcwNXw8LewjajWZYSQAbYZfLePBOo5ZAROcRe7Pe/4BZVo9sHQ bDmxs8b7DtXhZWZAiM/Gvt5OYxuYanJ6WVEdeOIr+Nsj6GdagfF6oOZCzVX6fd+dTfTsqxi3N2Vfg CsPu4yrjxK5LShupF6Xw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuC7-00F9Fc-1x; Mon, 25 Sep 2023 22:36:47 +0000 Received: from bg2.exmail.qq.com ([114.132.224.180]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuC4-00F9Eb-0M for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:36:45 +0000 X-QQ-mid: bizesmtp66t1695681384tmochcm2 Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:36:22 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: TVZM0Uoyj00JUk8OvUcLIPa/EY8r7PpEQ1C4lcN0OuATw0N34N96kW+oYTtBN Jaai4dDH6wtD7ZkDRGpxrDXJs8kGC6i0K1xINYbt7WEradLvwu7MjA6BcfUnB7FQ28vLUNE oQHy3mNLduqnMVzzsi6WBKxgK0AAM3INML+mLcNbhvWg2TzhqPZTKPUYjS11nZRjvZcUiuD NRW/R54I/WUXENzteFZ23F0t6lmXK5Gg+8WdV//S+i7xLiuIrZryziyd/4peU2qgsix+rev 4q/4iJniLeeMCnq1PbhyWM3hk3jVoJGyF2rmv3i3bq3HesUqB4dLD5mRubDvLJZ1TV80lce ETiR3coFd9RGXByeptpmtL7fTDNYSIbW6nDutyAuvYsEvMnBnNwa0HvNQHDPey2/Yz4tq+W X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16786486805464770233 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 2/7] DCE/DSE: add unused syscalls elimination configure support Date: Tue, 26 Sep 2023 06:36:21 +0800 Message-Id: <3f0eaf5fcb19f1c70cab075a97f067846f36f736.1695679700.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_153644_488837_4E907509 X-CRM114-Status: GOOD ( 11.64 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org A minimal embedded Linux system may only has a very few of functions and only uses a minimal subset of the posix syscalls, the unused syscalls will never be used and eventually in a dead status, that also means disk storage and memory footprint waste. Based on dead code elimination support, it is able to further eliminate the above dead or unused syscalls. Firstly, both a new common CONFIG_TRIM_UNUSED_SYSCALLS option and a new architecture specific HAVE_TRIM_UNUSED_SYSCALLS are added to enable or disable such feature. Secondly, a new CONFIG_USED_SYSCALLS option is added to allow configure the syscalls used in a target system. CONFIG_USED_SYSCALLS can be a list of the used syscalls or a file to store such a list. Based on the above options, it is able to only reserve the used syscalls and let CONFIG_LD_DEAD_CODE_DATA_ELIMINATION trim the unused ones for us automatically. Signed-off-by: Zhangjin Wu --- init/Kconfig | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index 4350d8ba7db4..aa648ce8bca1 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1457,6 +1457,11 @@ config BPF bool select CRYPTO_LIB_SHA1 +config HAVE_TRIM_UNUSED_SYSCALLS + bool + depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION + default n + menuconfig EXPERT bool "Configure standard kernel features (expert users)" # Unhide debug options, to make the on-by-default options visible @@ -1683,6 +1688,43 @@ config MEMBARRIER If unsure, say Y. +config TRIM_UNUSED_SYSCALLS + bool "Trim unused syscalls (EXPERIMENTAL)" if EXPERT + default n + depends on HAVE_TRIM_UNUSED_SYSCALLS + depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION + select LD_DEAD_CODE_DATA_ELIMINATION + help + Say Y here to trim all of the unused syscalls for a target system. + + Note, this is only for minimal embedded systems, please don't use it + for generic Linux distributions. + + If unsure, say N. + +config USED_SYSCALLS + string "Configure used syscalls (EXPERIMENTAL)" if EXPERT + depends on TRIM_UNUSED_SYSCALLS + default "" + help + This option allows to configure the syscalls used in a target system, + the unused ones will be disabled and trimmed by TRIM_UNUSED_SYSCALLS. + + The used syscalls should be listed one by one like this: + + write exit reboot + + Or put them into a file specified by this option, one syscall per + line is recommended for such a config file: + + write + exit + reboot + + Note, If keep this empty, all of the syscalls will be trimmed. + + If unsure, please disable TRIM_UNUSED_SYSCALLS. + config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EXPERT default y From patchwork Mon Sep 25 22:38:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398533 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27C80CE79A7 for ; Mon, 25 Sep 2023 22:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HgwYniHy1beTFfxgwn2awde6yAHVwFXkEYRd3VbMtFk=; b=oajy0lxsBMEhlG nfNoF0lXoqK5ATZASbLlhSHOdlgA1mf8qOfpiQ/SzhVuosOKUL1dKDclSVG43z8lAs8ZbDgNPpK3y 43kqkux12eDqoxlrpGGpAwHNPiWi40RSk+nj4gZHJSHKWFNE7qlqZGohcBkVpRkG9zSRYL3ynrrwP 7Xky8+c4q9L6SQ6PI5Op2PkxZHvjzyIrfkZz54OXn9NF4FbwTVM9jeKVSkcV1BmMHgih2pxJHut+M laswpD8t3SoO9yZfpbBzXjlfY75Iy5Zp1j6thikvDArFf3wzd+bJGlE3yoVfVXIaYR5QtdaK3Dj46 zTf5lQ9Ebd1NHi7mJNKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuEa-00F9ZK-13; Mon, 25 Sep 2023 22:39:20 +0000 Received: from bg2.exmail.qq.com ([114.132.224.180]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuEX-00F9Xs-1j for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:39:19 +0000 X-QQ-mid: bizesmtp62t1695681542tdrh3qq7 Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:38:56 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: SFhf6fKhx//PtbsvyVYEL/gCYQ5xMD8J6LwaCKhulpVEfmJppGRkMmjMj3Bxv 8wdytKPzLVFJlPA82FjC2Ti02tsIHXGhP+Tb7KY7NXZeQX14PHTRUwY1uNtWxj7nVvdw5N8 ypB+bBYPZTiHwLTOfPVZ2o3kvUQu/slgqaqTTvxwiXKKuRoubwr8vyOsZC+zpBmOn8ghMQm AG5bLu8EeQJF77jcZcCDh8tBPzUgxyBcq+ybkOO584JaaHxdkRqP9QMqdLVLQkwKUzkpjRx 8jfcH0gidHmiUdV76m98gNAlJ0swOV9yXGIUaa85PdpJ4c+AiLAPLqrLnY0hvGmFDffugib /YpU8n7ZB5APg72lHoVQhLN1V/LOaRguiP/XLXevf0Z/Nx5UZypKAyBjtff2CMVyBvswmd1 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11640928319628299727 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 3/7] DCE/DSE: Add a new scripts/Makefile.syscalls Date: Tue, 26 Sep 2023 06:38:56 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_153917_911667_8C9C54E0 X-CRM114-Status: GOOD ( 12.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When CONFIG_TRIM_UNUSED_SYSCALLS is enabled, get used syscalls from CONFIG_USED_SYSCALLS. CONFIG_USED_SYSCALLS may be a list of used syscalls or a file to store such a list. If CONFIG_USED_SYSCALLS is configured as a list of the used syscalls, directly record them in a used_syscalls variable, if it is a file to store the list, record the file name to the used_syscalls_file variable and put its content to the used_syscalls variable. Signed-off-by: Zhangjin Wu --- scripts/Makefile.syscalls | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/Makefile.syscalls diff --git a/scripts/Makefile.syscalls b/scripts/Makefile.syscalls new file mode 100644 index 000000000000..5864d3a85996 --- /dev/null +++ b/scripts/Makefile.syscalls @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: GPL-2.0 + +ifndef SCRIPTS_MAKEFILE_SYSCALLS + SCRIPTS_MAKEFILE_SYSCALLS = 1 + + ifdef CONFIG_TRIM_UNUSED_SYSCALLS + ifneq ($(wildcard $(CONFIG_USED_SYSCALLS)),) + used_syscalls_file = $(CONFIG_USED_SYSCALLS) + ifeq ($(shell test -s $(used_syscalls_file); echo $$?),0) + used_syscalls != cat $(CONFIG_USED_SYSCALLS) + endif + else + ifeq ($(subst /,,$(CONFIG_USED_SYSCALLS)),$(CONFIG_USED_SYSCALLS)) + used_syscalls = $(CONFIG_USED_SYSCALLS) + else + $(error No such file: $(CONFIG_USED_SYSCALLS)) + endif + endif + + ifneq ($(used_syscalls),) + used_syscalls := $(subst $(space),|,$(strip $(used_syscalls))) + endif + + used_syscalls_deps = $(used_syscalls_file) $(objtree)/.config + + export used_syscalls used_syscalls_deps + endif # CONFIG_TRIM_UNUSED_SYSCALLS + +endif # SCRIPTS_MAKEFILE_SYSCALLS From patchwork Mon Sep 25 22:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398534 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E5FDE6FE31 for ; Mon, 25 Sep 2023 22:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0PbmP4aLSnF/mTTsBnbG0GcNSxOQvN0dyplAYHvdvoI=; b=SLvEHO4WRzEXwk 9wp9onRy0CJF/41dUeNoSbHeSqpkJnjXyYDqveqHFfhJsAXyp09WvvZt+66Awh2b2FmAzy8Xi8WKp m7XjuX+zbRhyKMQuXthLdM6L9Y44HIzany7nwy22QVpxw/59tLMg9DZDb4VLN5irV9/Qk1NVU+7CM lHYtk8aWUxlf+cdqynvCOylKrDGzNMuDD4KXPU6D76u6WauRnS/8mIBZurukWf+SRBDht+k2OwDmI l6RVuxtWoPoXnKNE9tfbL7Pn1ZsXmOko+azbV7fORB6ARlmlKpdjOeAjujSRGBksgRBgzCTYHHWPf 71CL2MwzOWMNVEZNJPog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuFn-00F9hq-2f; Mon, 25 Sep 2023 22:40:35 +0000 Received: from bg2.exmail.qq.com ([114.132.224.180]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuFk-00F9gv-0i for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:40:33 +0000 X-QQ-mid: bizesmtp71t1695681610tqhm377b Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:40:09 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: ILHsT53NKPin+kzqQGfU4qqx5molDA0iqJ3SZWTXpJi8+ENQI9pVCgAqlBSkC SjaN45XpIk1N9BymYSuAA4tz+X2z3zeBDA68WsFY96RT+Gd5cHXvtB6jom5TT127giJhM/5 NYjRyHFFjFr7/hKz8hqmz7lUIJCz8p8INNxMNWVVYxrjS0fuOZ5lBCOitOCifwkKQ2qkq/I nFPp5yuzK7Fnnkzj05IDOOvyimA3DAoPmo/UDJuESVDQxMoEe1bta55YWtBEQh2u0eRdKYa CcWdvrTVxLfhg/EvuGTLSB6+7PHrTRo028EKuirSNFGWhIltAikvPVrYhLU+GAeDrJileEI B81pLKgvY0EFjP/WeutX5VCs8Rl7koPFER6fhRF5u0+6q2v/AytMFxAeFoecYN84j7q+8BB X-QQ-GoodBg: 0 X-BIZMAIL-ID: 17594093605146210017 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 4/7] DCE/DSE: mips: add HAVE_TRIM_UNUSED_SYSCALLS support Date: Tue, 26 Sep 2023 06:40:08 +0800 Message-Id: <3042b32a13aecbf8f3c8bedee34a4ca8c7d7cb2e.1695679700.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_154032_599987_C1C5B1BE X-CRM114-Status: GOOD ( 10.49 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org For HAVE_TRIM_UNUSED_SYSCALLS, the syscall tables are hacked with the input used syscalls. Based on the used syscalls information, a new version of tbl file is generated from the original tbl file and named with a 'used' suffix. With this new tbl file, both unistd_nr_*.h and syscall_table_*.h files are updated to only include the used syscalls. $ grep _Linux_syscalls -ur arch/mips/include/generated/asm/ arch/mips/include/generated/asm/unistd_nr_n64.h:#define __NR_64_Linux_syscalls 165 arch/mips/include/generated/asm/unistd_nr_n32.h:#define __NR_N32_Linux_syscalls 165 arch/mips/include/generated/asm/unistd_nr_o32.h:#define __NR_O32_Linux_syscalls 89 $ grep -vr sys_ni_syscall arch/mips/include/generated/asm/syscall_table_*.h arch/mips/include/generated/asm/syscall_table_n32.h:__SYSCALL(58, sys_exit) arch/mips/include/generated/asm/syscall_table_n32.h:__SYSCALL(164, sys_reboot) arch/mips/include/generated/asm/syscall_table_n64.h:__SYSCALL(58, sys_exit) arch/mips/include/generated/asm/syscall_table_n64.h:__SYSCALL(164, sys_reboot) arch/mips/include/generated/asm/syscall_table_o32.h:__SYSCALL(1, sys_exit) arch/mips/include/generated/asm/syscall_table_o32.h:__SYSCALL(88, sys_reboot) Signed-off-by: Zhangjin Wu --- arch/mips/Kconfig | 1 + arch/mips/kernel/syscalls/Makefile | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index bc8421859006..8a6927eff23d 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -89,6 +89,7 @@ config MIPS select HAVE_SPARSE_SYSCALL_NR select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS + select HAVE_TRIM_UNUSED_SYSCALLS if HAVE_LD_DEAD_CODE_DATA_ELIMINATION select HAVE_VIRT_CPU_ACCOUNTING_GEN if 64BIT || !SMP select IRQ_FORCED_THREADING select ISA if EISA diff --git a/arch/mips/kernel/syscalls/Makefile b/arch/mips/kernel/syscalls/Makefile index e6b21de65cca..1e292a9f84a0 100644 --- a/arch/mips/kernel/syscalls/Makefile +++ b/arch/mips/kernel/syscalls/Makefile @@ -26,10 +26,29 @@ sysnr_pfx_unistd_nr_n32 := N32 sysnr_pfx_unistd_nr_n64 := 64 sysnr_pfx_unistd_nr_o32 := O32 -$(kapi)/unistd_nr_%.h: $(src)/syscall_%.tbl $(sysnr) FORCE +ifndef CONFIG_TRIM_UNUSED_SYSCALLS +tbl = $(src)/syscall_%.tbl +else + +include $(srctree)/scripts/Makefile.syscalls + +orig_tbl = $(src)/syscall_%.tbl + tbl_dir = arch/$(SRCARCH)/include/generated/tbl + tbl = $(tbl_dir)/syscall_used_%.tbl + +quiet_cmd_used = USED $@ + cmd_used = sed -E -e "/^[0-9]*[[:space:]]/{/(^($(used_syscalls))[[:space:]]|[[:space:]]($(used_syscalls))[[:space:]]|[[:space:]]($(used_syscalls))$$)/!{s/^/\#/g}}" $< > $@; + +$(tbl): $(orig_tbl) $(used_syscalls_deps) FORCE + $(Q)mkdir -p $(tbl_dir) + $(call cmd,used) + +endif + +$(kapi)/unistd_nr_%.h: $(tbl) $(sysnr) FORCE $(call if_changed,sysnr) -$(kapi)/syscall_table_%.h: $(src)/syscall_%.tbl $(systbl) FORCE +$(kapi)/syscall_table_%.h: $(tbl) $(systbl) FORCE $(call if_changed,systbl) uapisyshdr-y += unistd_n32.h \ From patchwork Mon Sep 25 22:41:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398535 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A771FE6FE31 for ; Mon, 25 Sep 2023 22:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=feJCgwH5tNYJU1N3L6y1yo/t5e/gEpNPiejjze98x68=; b=VLb8uTo5id8xqB T2iyXn22eEKn3yC/uh/ZIDh+xLFcVJH3R2SMEIE7mw6OTZOrhZ+71u930zSb3wpp/mTtiQ2AIkhJb xw7vvHifjPxxVVTsqA/mUhUccgzt5hxVkNq32yUrZlo/vMArbnYgXbWBio3U7CWwXqaHaLIh/p10k wHN6HDoePcXSAmFn3ir0FBsd2Fq6ipVHnO1Re1zmyw5WprUMMtJNTjKMThnFs2rmeHiN9EZ7XnCrQ QwgrMY9CwqEjaOz29EhtWUdLBlrol333eySw7YoaWgYS/L0orRqSDT0Ck9NH1mRI1E3NrdNsoBy43 oxEjmiZ8hLDc6pMAUXqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuGq-00F9ox-0A; Mon, 25 Sep 2023 22:41:40 +0000 Received: from bg2.exmail.qq.com ([114.132.197.227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuGn-00F9nb-30 for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:41:39 +0000 X-QQ-mid: bizesmtp64t1695681678tnvf3nwx Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:41:16 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: 3M0okmaRx3gfsSflpNrVeZ3sLICSqSaF1U3sraXTLgAlViLSauDfSqqDtpoNW SpJ9yhtzh6PzBUapWeOX0uRrrOAx/YDjuGcAV/ElqISXdLVJrgKYLDHpCpA9o8pTr1UJmAp TZpLJKkg5BgsLqXJA7AyPqGQd4uo4wJ9kG/PcrwaYQDKWoXQAHmyI48DbJyB9TrgDn6MwV1 xAbDs/bktubgubuWpp3z5BZzxdTfsdxIyMEd653QAHjXk0VSw0QgkTt/ZwID4tddHr20MU5 IBenNgCrBRJGf1SYzfyD/v+sJ8AofWpCIgALXUucwYI6Z1XoKE8OaZJ5OVSdOUqOPo7jhE0 8L83kEBlrjALbS9Xe1VQFAawPyge85zIGnGGzgYOddDAkAAqjslJdveiZm9lYGNaojrQbrE X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2541803507469492191 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 5/7] DCE/DSE: riscv: move syscall tables to syscalls/ Date: Tue, 26 Sep 2023 06:41:16 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_154138_291874_0D656C03 X-CRM114-Status: GOOD ( 10.65 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Both syscall table and compat syscall table share some dead syscalls elimination code, to avoid cluttering the main RISC-V kernel Makefile, let's move these tables and the corresponding compile settings to syscalls/. Signed-off-by: Zhangjin Wu --- arch/riscv/kernel/Makefile | 5 +---- arch/riscv/kernel/syscalls/Makefile | 10 ++++++++++ .../riscv/kernel/{ => syscalls}/compat_syscall_table.c | 0 arch/riscv/kernel/{ => syscalls}/syscall_table.c | 0 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 arch/riscv/kernel/syscalls/Makefile rename arch/riscv/kernel/{ => syscalls}/compat_syscall_table.c (100%) rename arch/riscv/kernel/{ => syscalls}/syscall_table.c (100%) diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 95cf25d48405..40aebbf06880 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -8,8 +8,6 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_patch.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_sbi.o = $(CC_FLAGS_FTRACE) endif -CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) -CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) ifdef CONFIG_KEXEC AFLAGS_kexec_relocate.o := -mcmodel=medany $(call cc-option,-mno-relax) @@ -48,7 +46,7 @@ obj-y += ptrace.o obj-y += reset.o obj-y += setup.o obj-y += signal.o -obj-y += syscall_table.o +obj-y += syscalls/ obj-y += sys_riscv.o obj-y += time.o obj-y += traps.o @@ -95,7 +93,6 @@ obj-$(CONFIG_JUMP_LABEL) += jump_label.o obj-$(CONFIG_CFI_CLANG) += cfi.o obj-$(CONFIG_EFI) += efi.o -obj-$(CONFIG_COMPAT) += compat_syscall_table.o obj-$(CONFIG_COMPAT) += compat_signal.o obj-$(CONFIG_COMPAT) += compat_vdso/ diff --git a/arch/riscv/kernel/syscalls/Makefile b/arch/riscv/kernel/syscalls/Makefile new file mode 100644 index 000000000000..65abd0871ee5 --- /dev/null +++ b/arch/riscv/kernel/syscalls/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the RISC-V syscall tables +# + +CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) +CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) + +obj-y += syscall_table.o +obj-$(CONFIG_COMPAT) += compat_syscall_table.o diff --git a/arch/riscv/kernel/compat_syscall_table.c b/arch/riscv/kernel/syscalls/compat_syscall_table.c similarity index 100% rename from arch/riscv/kernel/compat_syscall_table.c rename to arch/riscv/kernel/syscalls/compat_syscall_table.c diff --git a/arch/riscv/kernel/syscall_table.c b/arch/riscv/kernel/syscalls/syscall_table.c similarity index 100% rename from arch/riscv/kernel/syscall_table.c rename to arch/riscv/kernel/syscalls/syscall_table.c From patchwork Mon Sep 25 22:42:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398536 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3DD60CE79A7 for ; Mon, 25 Sep 2023 22:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=h+WYZgDW1hJVPHFonKFcomQ6ifLAd43Gv6yan0KOX44=; b=HtV3+TWMZFr0lw PGDk3ZBAWbwyCluj2BIbTKGlO03jIKFYw1Lpzyn1VtTeCaHBOG1kWo3Ff19CeqsK4aANaPZfginBN GcCs1Kl1jZvY1piAwGOX0YdyVfNGlbZ7ggJUBo8Pel2ZvW+ono4nALAerAnR1uKTjYx+PSyA08a44 PjqOQ44m5+SAemmIQJkLtUFYbnoz/S8rGl62n2LQG8J44aalsvzr9HM0LsxtgB0iYPiQ/rG7J15xn hSGZ9NlQdedcwJ29Jhzmnt4XEATMq+EyV5CVEPYcWLDZKPYSgS3NqjXTAh9a08t8EDg3p75dkJHEG k9oBhpz9WN7oXxpti8Aw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuHt-00F9xI-1J; Mon, 25 Sep 2023 22:42:45 +0000 Received: from bg2.exmail.qq.com ([114.132.197.227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuHq-00F9wc-0m for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:42:43 +0000 X-QQ-mid: bizesmtp62t1695681747tvn9b2gn Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:42:25 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: QityeSR92A0MQJVv5nuCC9DWB6NqRLzb0Nt00+7+ZdZFXtQd+tI7WSyL9WNOC fnkFG8BxSL4z+x4KtcNrcR8seOIuPOURUulAxrpJmjQqP1LnskZEYIQeAh7TqLbJQrlD4li 3VuACOa9fnkngcsF3KIGbIynUc0D2IWpUdjKYODzIYUXgIz+zmPiduG6OYqUjSeaFRhNVQi R0HbuNW/24Z5vZZir3noOwSkUHoulzJ2+O4FYOOXwupxn1hyjRia4sJ2NT5RJM4nXc0e8Iv 7hAGFtYtbhAxrGb58x8hDMLmYTvcInpLmnftQdn3m6DI7DS6SGVCJU/ULhGp1PpyhutLM3N Q/G4gGWqnZP9rqGdHPsdsDiBO/RURWwjE7Drreilih2jBFRvf5O1ZdfOFTpH5AMIwzf0aLr X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2348411404682298682 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 6/7] DCE/DSE: riscv: add HAVE_TRIM_UNUSED_SYSCALLS support Date: Tue, 26 Sep 2023 06:42:23 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_154242_590388_0B2885FD X-CRM114-Status: UNSURE ( 8.97 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org For HAVE_TRIM_UNUSED_SYSCALLS, the syscall tables are hacked with the inputing unused_syscalls. Firstly, the intermediate preprocessed .i files are generated from the original C version of syscall tables respectively, and named with a 'used' suffix: syscall_table_used.i, compat_syscall_table_used.i. Secondly, all of the unused syscalls are commented. At last, two new objective files sufixed with 'used' are generated from the hacked .i files and they are linked into the eventual kernel image. Signed-off-by: Zhangjin Wu --- arch/riscv/Kconfig | 1 + arch/riscv/kernel/syscalls/Makefile | 37 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d607ab0f7c6d..b5e726b49a6f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -140,6 +140,7 @@ config RISCV select HAVE_RSEQ select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS + select HAVE_TRIM_UNUSED_SYSCALLS if HAVE_LD_DEAD_CODE_DATA_ELIMINATION select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU select IRQ_DOMAIN select IRQ_FORCED_THREADING diff --git a/arch/riscv/kernel/syscalls/Makefile b/arch/riscv/kernel/syscalls/Makefile index 65abd0871ee5..3b5969aaa9e8 100644 --- a/arch/riscv/kernel/syscalls/Makefile +++ b/arch/riscv/kernel/syscalls/Makefile @@ -3,8 +3,45 @@ # Makefile for the RISC-V syscall tables # +ifndef CONFIG_TRIM_UNUSED_SYSCALLS + CFLAGS_syscall_table.o += $(call cc-option,-Wno-override-init,) CFLAGS_compat_syscall_table.o += $(call cc-option,-Wno-override-init,) obj-y += syscall_table.o obj-$(CONFIG_COMPAT) += compat_syscall_table.o +else # CONFIG_TRIM_UNUSED_SYSCALLS + +include $(srctree)/scripts/Makefile.syscalls + +CFLAGS_syscall_table_used.o += $(call cc-option,-Wno-override-init,) +CFLAGS_compat_syscall_table_used.o += $(call cc-option,-Wno-override-init,) + +obj-y += syscall_table_used.o +obj-$(CONFIG_COMPAT) += compat_syscall_table_used.o + +# comment the unused syscalls +quiet_cmd_used = USED $@ + cmd_used = sed -E -e '/^\[([0-9]+|\([0-9]+ \+ [0-9]+\))\] = /{/= *__riscv_(__sys_|sys_|compat_)*($(used_syscalls)),/!{s%^%/* %g;s%$$% */%g}}' -i $@; + +$(obj)/syscall_table_used.c: $(src)/syscall_table.c + $(Q)cp $< $@ + +$(obj)/syscall_table_used.i: $(src)/syscall_table_used.c $(used_syscalls_deps) FORCE + $(call if_changed_dep,cpp_i_c) + $(call cmd,used) + +$(obj)/syscall_table_used.o: $(obj)/syscall_table_used.i FORCE + $(call if_changed,cc_o_c) + +$(obj)/compat_syscall_table_used.c: $(src)/compat_syscall_table.c + $(Q)cp $< $@ + +$(obj)/compat_syscall_table_used.i: $(src)/compat_syscall_table_used.c $(used_syscalls_deps) FORCE + $(call if_changed_dep,cpp_i_c) + $(call cmd,used) + +$(obj)/compat_syscall_table_used.o: $(obj)/compat_syscall_table_used.i FORCE + $(call if_changed,cc_o_c) + +endif # CONFIG_TRIM_UNUSED_SYSCALLS From patchwork Mon Sep 25 22:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13398537 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C380DCE79A7 for ; Mon, 25 Sep 2023 22:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hldLgqSIJYcziFC1ofBHzJdk0lkETL/YwhWuqBhJAow=; b=hn9jOfN26vUANX ydDK8HPRChAvX1nRtsJrEnWXIqKgw1xu5s3SAEAfwKgC4g5BIADlJwZb52ITYXpzMcoEuI2TsASto bTn6Uk01KGKN8L12SzOzrT04/snvBvOlSZatapK4jiIxUtX28JxVAPE0T5rFojfHlR/GUCxcvHNim 91iqtC5Fqg37KaLbYU9RkSsOPSiA1lLzLd6XLb/GBu6cK4Aha14r+zoLHRlfaWxMOI50HMGKn6gXi Sys+z6bi4gPsIVS7bB8lQ4jxdgPW+G1jNNy21Uzj4Im7CzTpjtndHUHpydNcuM0bjoahpaCt9bO9N CJ8fS0gyZhBobnrAXLcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qkuIw-00FA54-28; Mon, 25 Sep 2023 22:43:50 +0000 Received: from bg4.exmail.qq.com ([43.155.67.158]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qkuIt-00FA48-2w for linux-riscv@lists.infradead.org; Mon, 25 Sep 2023 22:43:49 +0000 X-QQ-mid: bizesmtp81t1695681815tls4ddg5 Received: from linux-lab-host.localdomain ( [116.30.124.152]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 26 Sep 2023 06:43:33 +0800 (CST) X-QQ-SSF: 01200000002000E0Y000B00A0000000 X-QQ-FEAT: aBJFcW+uBGYffXzygR0k5C/WLWWZcLSCd2TbMPG0O7Tlzn1m+5D3uZe31rmrB aujFQULia5dBlILNDRUyEjx57EpMsxaL6Hz0UfpOimP01EPYwODfLNDt/08+rViZ0kDvJPS c/l6PK5eg6fwnuRPIEYFxcxK83ddGI9AWtGlJq/Ee72+sNa4MrAQ3EN8Qe34Np4jqLArABG JS2WsLg0nT+US7V5b/8yFqpM/D3X+G29I8CLiztdDhT1Y7JbtyMwz8ftGBL0fuh92PguYE4 IKeAjeoyg3J6mOYoYZE003kMKygyo6u/CV03ypKigE7GsLxTYVFe5MpxCrKElLULeYxae/d HtHN7uvHgeUIKpoUbjQ3Dfq7OGBezfWvX3+if5KLWzLVYk17ZVHC2GUJSVYzHQJ1NQ/1p5y X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4775298546958751858 From: Zhangjin Wu To: linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, Arnd Bergmann Cc: falcon@tinylab.org, palmer@rivosinc.com, paul.walmsley@sifive.com, paulburton@kernel.org, paulmck@kernel.org, tsbogend@alpha.franken.de, w@1wt.eu, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Tim Bird Subject: [PATCH v1 7/7] DCE/DSE: riscv: trim syscall tables Date: Tue, 26 Sep 2023 06:43:32 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230925_154348_279332_3F5A81F2 X-CRM114-Status: GOOD ( 11.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When the maximum nr of the used syscalls is smaller than __NR_syscalls (original syscalls total). It is able to update __NR_syscalls to (maximum nr + 1) and further trim the '>= (maximum nr + 1)' part of the syscall tables: For example: sys_call_table [143] = { [0 ... 143 - 1] = sys_ni_syscall, [64] = sys_write, [93] = sys_exit, [142] = sys_reboot, } The >= 143 part of the syscall tables can be trimmed. At the same time, the syscall >= 143 from user space must be ignored from do_trap_ecall_u() of traps.c. Signed-off-by: Zhangjin Wu --- arch/riscv/include/asm/unistd.h | 2 ++ arch/riscv/kernel/Makefile | 2 ++ arch/riscv/kernel/syscalls/Makefile | 22 +++++++++++++++++++ .../kernel/syscalls/compat_syscall_table.c | 4 ++-- arch/riscv/kernel/syscalls/syscall_table.c | 4 ++-- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/unistd.h b/arch/riscv/include/asm/unistd.h index 221630bdbd07..4d8e41f446ff 100644 --- a/arch/riscv/include/asm/unistd.h +++ b/arch/riscv/include/asm/unistd.h @@ -23,4 +23,6 @@ #include +#ifndef NR_syscalls #define NR_syscalls (__NR_syscalls) +#endif diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 40aebbf06880..e75424c10729 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -49,7 +49,9 @@ obj-y += signal.o obj-y += syscalls/ obj-y += sys_riscv.o obj-y += time.o +ifneq ($(CONFIG_TRIM_UNUSED_SYSCALLS),y) obj-y += traps.o +endif obj-y += riscv_ksyms.o obj-y += stacktrace.o obj-y += cacheinfo.o diff --git a/arch/riscv/kernel/syscalls/Makefile b/arch/riscv/kernel/syscalls/Makefile index 3b5969aaa9e8..f1a0597c8b24 100644 --- a/arch/riscv/kernel/syscalls/Makefile +++ b/arch/riscv/kernel/syscalls/Makefile @@ -14,9 +14,18 @@ else # CONFIG_TRIM_UNUSED_SYSCALLS include $(srctree)/scripts/Makefile.syscalls +# calculate syscalls total from $(obj)/syscall_table_used.i +ifneq ($(used_syscalls),) + NR_syscalls := $$(($$(sed -E -n -e '/^\[([0-9]+|\([0-9]+ \+ [0-9]+\))\] = /{s/^\[(.*)\].*/\1/gp}' $(obj)/syscall_table_used.i | bc | sort -g | tail -1 | grep '[0-9]' || echo -1) + 1)) +else + NR_syscalls := 0 +endif + +CFLAGS_traps_used.o += -DNR_syscalls=$(NR_syscalls) CFLAGS_syscall_table_used.o += $(call cc-option,-Wno-override-init,) CFLAGS_compat_syscall_table_used.o += $(call cc-option,-Wno-override-init,) +obj-y += traps_used.o obj-y += syscall_table_used.o obj-$(CONFIG_COMPAT) += compat_syscall_table_used.o @@ -24,15 +33,26 @@ obj-$(CONFIG_COMPAT) += compat_syscall_table_used.o quiet_cmd_used = USED $@ cmd_used = sed -E -e '/^\[([0-9]+|\([0-9]+ \+ [0-9]+\))\] = /{/= *__riscv_(__sys_|sys_|compat_)*($(used_syscalls)),/!{s%^%/* %g;s%$$% */%g}}' -i $@; +# update the syscalls total +quiet_cmd_snr = SNR $@ + cmd_snr = snr=$(NR_syscalls); if [ $$snr -ne 0 ]; then \ + sed -i -e "s/sys_call_table\[.*\] =/sys_call_table[($$snr)] =/g;s/\[0 ... (.*) - 1\] = __riscv_sys_ni_syscall/[0 ... ($$snr) - 1] = __riscv_sys_ni_syscall/g" $@; \ + fi; + +$(obj)/traps_used.c: $(src)/../traps.c $(obj)/syscall_table_used.i FORCE + $(Q)cp $< $@ + $(obj)/syscall_table_used.c: $(src)/syscall_table.c $(Q)cp $< $@ $(obj)/syscall_table_used.i: $(src)/syscall_table_used.c $(used_syscalls_deps) FORCE $(call if_changed_dep,cpp_i_c) $(call cmd,used) + $(call cmd,snr) $(obj)/syscall_table_used.o: $(obj)/syscall_table_used.i FORCE $(call if_changed,cc_o_c) + $(call cmd,force_checksrc) $(obj)/compat_syscall_table_used.c: $(src)/compat_syscall_table.c $(Q)cp $< $@ @@ -40,8 +60,10 @@ $(obj)/compat_syscall_table_used.c: $(src)/compat_syscall_table.c $(obj)/compat_syscall_table_used.i: $(src)/compat_syscall_table_used.c $(used_syscalls_deps) FORCE $(call if_changed_dep,cpp_i_c) $(call cmd,used) + $(call cmd,snr) $(obj)/compat_syscall_table_used.o: $(obj)/compat_syscall_table_used.i FORCE $(call if_changed,cc_o_c) + $(call cmd,force_checksrc) endif # CONFIG_TRIM_UNUSED_SYSCALLS diff --git a/arch/riscv/kernel/syscalls/compat_syscall_table.c b/arch/riscv/kernel/syscalls/compat_syscall_table.c index ad7f2d712f5f..4756b6858eac 100644 --- a/arch/riscv/kernel/syscalls/compat_syscall_table.c +++ b/arch/riscv/kernel/syscalls/compat_syscall_table.c @@ -17,7 +17,7 @@ asmlinkage long compat_sys_rt_sigreturn(void); -void * const compat_sys_call_table[__NR_syscalls] = { - [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall, +void * const compat_sys_call_table[NR_syscalls] = { + [0 ... NR_syscalls - 1] = __riscv_sys_ni_syscall, #include }; diff --git a/arch/riscv/kernel/syscalls/syscall_table.c b/arch/riscv/kernel/syscalls/syscall_table.c index dda913764903..d2b3233ae5d4 100644 --- a/arch/riscv/kernel/syscalls/syscall_table.c +++ b/arch/riscv/kernel/syscalls/syscall_table.c @@ -16,7 +16,7 @@ #undef __SYSCALL #define __SYSCALL(nr, call) [nr] = __riscv_##call, -void * const sys_call_table[__NR_syscalls] = { - [0 ... __NR_syscalls - 1] = __riscv_sys_ni_syscall, +void * const sys_call_table[NR_syscalls] = { + [0 ... NR_syscalls - 1] = __riscv_sys_ni_syscall, #include };