From patchwork Mon Sep 23 07:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13809362 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 43C2E47772; Mon, 23 Sep 2024 07:57:14 +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=1727078235; cv=none; b=d+gJAHjm0vB4UWmrqsbRvtUmE1MMNTRwFq7FIrZpFETFf8knSp+l7pqYfRM78KEbbYjgTZJpXb3ZQW562tpzMvAR0M39uyXjNDOHfw4ml6Gf8XQAZGCKmupyWydln3m6vk0BuLlWQYSh9M9ImmV7e3a/beeckpkrB4ux2PalpSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727078235; c=relaxed/simple; bh=/67wU+xu3DRRRzxut6ybxR6VskXWX3/R07CWLjzgkcg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=d/Mxquwi73RSj9+vGKNIvDcmkVeScI5Ytr/WbGKu8dlp+gFStxrmPug9C4WyH1IxM5Ma9yXxRpSTNOAw7m6B/cIu1x/mcyeFoavN9DoN6wq97qo8xFGJFm5Se31vr5HicYYm7sKHrUddnoTWXhrn/SAsgnwMLTT5c+Hy9nLgFSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ru76ufvX; 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="Ru76ufvX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E2EEC4CEC4; Mon, 23 Sep 2024 07:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727078234; bh=/67wU+xu3DRRRzxut6ybxR6VskXWX3/R07CWLjzgkcg=; h=From:To:Cc:Subject:Date:From; b=Ru76ufvX2yyZa4cxQbZARKV6kv+IPZvCz+FKw4j7EdLS/TkMhGh7gqHwYGAph3ree oBmOuXwf8RdlpcXWrixZDcJMxwZi0unAnef9huV8RG0DJlMekWGXZ5c6iRvhTra8s7 AGSlDInfPbp/saAMisCU4wQrv7puSpEX/U3JKyXEecoy2XoAcsQB1Xde5d+M0/znFc KVvfRpwBuizmL7hTnnQjRjI5X/pIWLjy2O61WyBl6VSYAuR05r7XGIHm9wlN5lacYg T+icvrqkf4tbzMvn91PtD3cK63Yb6NC1PXI8z05k6vY/lW/Uv94a9qV1F2CKfQR1zV lNqmT0qaYpWMw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrea della Porta , linux-clk@vger.kernel.org, Stephen Boyd , Brendan Higgins , Rob Herring , devicetree@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nicolas Schier Subject: [PATCH v3 1/2] kbuild: move non-boot built-in DTBs to .rodata section Date: Mon, 23 Sep 2024 16:56:02 +0900 Message-ID: <20240923075704.3567313-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit aab94339cd85 ("of: Add support for linking device tree blobs into vmlinux") introduced a mechanism to embed DTBs into vmlinux. Initially, it was used for wrapping boot DTBs in arch/*/boot/dts/, but it is now reused for more generic purposes, such as testing. Built-in DTBs are discarded because KERNEL_DTB() is part of INIT_DATA, as defined in include/asm-generic/vmlinux.lds.h. This has not been an issue so far because OF unittests are triggered during boot, as defined by late_initcall(of_unittest). However, the recent clk KUnit test additions have caused problems because KUnit can execute test suites after boot. For example: # echo > /sys/kernel/debug/kunit/clk_register_clk_parent_data_device/run This command triggers a stack trace because built-in DTBs have already been freed. While it is possible to move such test suites from kunit_test_suites to kunit_test_init_section_suites, it would be preferable to avoid usage limitations. This commit moves non-boot built-in DTBs to the .rodata section. Since these generic DTBs are looked up by name, they do not need to be placed in the special .dtb.init.rodata section. Boot DTBs should remain in .dtb.init.rodata because the arch boot code generally does not know the DT name, thus it uses the __dtb_start symbol to locate it. This separation also ensures that the __dtb_start symbol references the boot DTB. Currently, the .dtb.init.rodata is a mixture of both boot and non-boot DTBs. The __dtb_start symbol must be followed by the boot DTB, but we currently rely on the link order (i.e., the order in Makefiles), which is very fragile. Fixes: 5c9dd72d8385 ("of: Add a KUnit test for overlays and test managed APIs") Fixes: 5776526beb95 ("clk: Add KUnit tests for clk fixed rate basic type") Fixes: 274aff8711b2 ("clk: Add KUnit tests for clks registered with struct clk_parent_data") Signed-off-by: Masahiro Yamada Acked-by: Rob Herring (Arm) --- Changes in v3: - Move to .rodata section instead of .init.rodata scripts/Makefile.dtbs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/Makefile.dtbs b/scripts/Makefile.dtbs index 46009d5f1486..3e81cca6f68a 100644 --- a/scripts/Makefile.dtbs +++ b/scripts/Makefile.dtbs @@ -34,12 +34,14 @@ $(obj)/dtbs-list: $(dtb-y) FORCE # Assembly file to wrap dtb(o) # --------------------------------------------------------------------------- +builtin-dtb-section = $(if $(filter arch/%, $(obj)),.dtb.init.rodata,.rodata) + # Generate an assembly file to wrap the output of the device tree compiler quiet_cmd_wrap_S_dtb = WRAP $@ cmd_wrap_S_dtb = { \ symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \ echo '\#include '; \ - echo '.section .dtb.init.rodata,"a"'; \ + echo '.section $(builtin-dtb-section),"a"'; \ echo '.balign STRUCT_ALIGNMENT'; \ echo ".global $${symbase}_begin"; \ echo "$${symbase}_begin:"; \ From patchwork Mon Sep 23 07:56:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13809363 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 134D147772; Mon, 23 Sep 2024 07:57:18 +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=1727078239; cv=none; b=VCUg8lsoO1WCzDkEnAPYACidQE5gaqE7dMNsEKPIc9s3STFCk5FeTpmjEs//zBLEgioz1UCFWn4T3Kk/a2qRlTzbXQP3jhSC3pvLmXohW4dP+vfI+GCVqMnyAntsO/WJwfMq+cbe8vmBBMYFHTOCljl0gaELpI2lOFrvC0Kqt3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727078239; c=relaxed/simple; bh=TWkMdFBTmQmqmpC+xZ/pwB45UvOXbJoKSGnpNu/GFSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IML/M4b/EyCEgSVnOITXYnHFFlvUM0upEEvwaovlolRV9DDd8SHN4DrhAuNxU8oIUXCi+sEQOEhxXqPtejsQF+T5EcWxBDe3NcGwPUMYFWVd5Ck6TPshvFvPl68WJlEhsasu0Nf3N5bZ/q7lwdah3yoHdNAGsO35OkzjcIydPQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YTPTb9+j; 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="YTPTb9+j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41952C4CECE; Mon, 23 Sep 2024 07:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727078238; bh=TWkMdFBTmQmqmpC+xZ/pwB45UvOXbJoKSGnpNu/GFSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YTPTb9+jxBilMY8haTRI1bORDb8Vh7bjneQOb1eNaKcr5uHJyV75WZtqhwX/Q98Xr jz8r5Ys+2gIJMjFPFeMl9pGMkqEIcSQtMOvIxiJVbXAEEJSmlXkd/utqFoO+8+B+B3 BIOBnVVRKPYxS+ctVP7ZnHFDqZrrhAaoBE8Olndp84ZMyaD1NdZft66XZn5dyAPWZc BXuOBYUX2BEjx+xd+bkU4jST8PrUZqG5jmglLdSfqzY9rZNGjPUygD33afhGyv2Ejp JsSUBBY6iQX9ISTkI2ZF8sXUlB2OzHt6dC6MXwvi5OrPs7RARbRqiL4S4KSXADEVGJ o9N6hW+VTtRew== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Andrea della Porta , linux-clk@vger.kernel.org, Stephen Boyd , Brendan Higgins , Rob Herring , devicetree@vger.kernel.org, Masahiro Yamada , Alex Gaynor , Alice Ryhl , Andreas Hindborg , Benno Lossin , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Boqun Feng , Gary Guo , Miguel Ojeda , Nathan Chancellor , Nicolas Schier , Saravana Kannan , Wedson Almeida Filho , rust-for-linux@vger.kernel.org Subject: [PATCH v3 2/2] kbuild: add generic support for built-in boot DTBs Date: Mon, 23 Sep 2024 16:56:03 +0900 Message-ID: <20240923075704.3567313-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240923075704.3567313-1-masahiroy@kernel.org> References: <20240923075704.3567313-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Some architectures embed boot DTBs in vmlinux. A potential issue for these architectures is a race condition during parallel builds because Kbuild descends into arch/*/boot/dts/ twice. One build thread is initiated by the 'dtbs' target, which is a prerequisite of the 'all' target in the top-level Makefile: ifdef CONFIG_OF_EARLY_FLATTREE all: dtbs endif For architectures that support the built-in boot dtb, arch/*/boot/dts/ is visited also during the ordinary directory traversal in order to build obj-y objects that wrap DTBs. Since these build threads are unaware of each other, they can run simultaneously during parallel builds. This commit introduces a generic build rule to scripts/Makefile.vmlinux to support embedded boot DTBs in a race-free way. Architectures that want to use this rule need to select CONFIG_GENERIC_BUILTIN_DTB. After the migration, Makefiles under arch/*/boot/dts/ will be visited only once to build only *.dtb files. This change also aims to unify the CONFIG options used for built-in DTBs support. Currently, different architectures use different CONFIG options for the same purposes. With this commit, the CONFIG options will be unified as follows: - CONFIG_GENERIC_BUILTIN_DTB This enables the generic rule for built-in boot DTBs. This will be renamed to CONFIG_BUILTIN_DTB after all architectures migrate to the generic rule. - CONFIG_BUILTIN_DTB_NAME This specifies the path to the embedded DTB. (relative to arch/*/boot/dts/) - CONFIG_BUILTIN_DTB_ALL If this is enabled, all DTB files compiled under arch/*/boot/dts/ are embedded into vmlinux. Only used by MIPS. Signed-off-by: Masahiro Yamada --- (no changes since v1) Makefile | 7 ++++++- drivers/of/Kconfig | 6 ++++++ scripts/Makefile.vmlinux | 44 ++++++++++++++++++++++++++++++++++++++++ scripts/link-vmlinux.sh | 4 ++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0d3d45a88a71..35b8392d2bef 100644 --- a/Makefile +++ b/Makefile @@ -1413,6 +1413,10 @@ ifdef CONFIG_OF_EARLY_FLATTREE all: dtbs endif +ifdef CONFIG_GENERIC_BUILTIN_DTB +vmlinux: dtbs +endif + endif PHONY += scripts_dtc @@ -1480,7 +1484,8 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ modules.builtin.ranges vmlinux.o.map \ compile_commands.json rust/test \ - rust-project.json .vmlinux.objs .vmlinux.export.c + rust-project.json .vmlinux.objs .vmlinux.export.c \ + .builtin-dtbs-list .builtin-dtb.S # Directories & files removed with 'make mrproper' MRPROPER_FILES += include/config include/generated \ diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index dd726c7056bf..5142e7d7fef8 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -2,6 +2,12 @@ config DTC bool +config GENERIC_BUILTIN_DTB + bool + +config BUILTIN_DTB_ALL + bool + menuconfig OF bool "Device Tree and Open Firmware support" help diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 1284f05555b9..9ef0480ed755 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -17,6 +17,50 @@ quiet_cmd_cc_o_c = CC $@ %.o: %.c FORCE $(call if_changed_dep,cc_o_c) +quiet_cmd_as_o_S = AS $@ + cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< + +%.o: %.S FORCE + $(call if_changed_dep,as_o_S) + +# Built-in dtb +# --------------------------------------------------------------------------- + +quiet_cmd_wrap_dtbs = WRAP $@ + cmd_wrap_dtbs = { \ + echo '\#include '; \ + echo '.section .dtb.init.rodata,"a"'; \ + while read dtb; do \ + symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ + echo '.balign STRUCT_ALIGNMENT'; \ + echo ".global $${symbase}_begin"; \ + echo "$${symbase}_begin:"; \ + echo '.incbin "'$$dtb'" '; \ + echo ".global $${symbase}_end"; \ + echo "$${symbase}_end:"; \ + done < $<; \ + } > $@ + +.builtin-dtbs.S: .builtin-dtbs-list FORCE + $(call if_changed,wrap_dtbs) + +quiet_cmd_gen_dtbs_list = GEN $@ + cmd_gen_dtbs_list = \ + $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ + +.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE + $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) + +targets += .builtin-dtbs-list + +ifdef CONFIG_GENERIC_BUILTIN_DTB +targets += .builtin-dtbs.S .builtin-dtbs.o +vmlinux: .builtin-dtbs.o +endif + +# vmlinux +# --------------------------------------------------------------------------- + ifdef CONFIG_MODULES targets += .vmlinux.export.o vmlinux: .vmlinux.export.o diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index c27b4e969f20..bd196944e350 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -68,6 +68,10 @@ vmlinux_link() libs="${KBUILD_VMLINUX_LIBS}" fi + if is_enabled CONFIG_GENERIC_BUILTIN_DTB; then + objs="${objs} .builtin-dtbs.o" + fi + if is_enabled CONFIG_MODULES; then objs="${objs} .vmlinux.export.o" fi