public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: devicetree@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
	Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH v2 1/3] modpost: check section mismatch in reference to .dtb.init.rodata
Date: Tue, 10 Sep 2024 18:44:52 +0900	[thread overview]
Message-ID: <20240910094459.352572-1-masahiroy@kernel.org> (raw)

Built-in DTB files are discarded because KERNEL_DTB() is a part of
INIT_DATA, as defined in include/asm-generic/vmlinux.lds.h.

Currently, modpost warns about mismatched section references to init
data only when the destination section is prefixed with ".init.".
However, ".dtb.init.rodata" is also discarded.

This commit has revealed some missing annotations.

overlays[] references builtin DTBs, which become dangling pointers
after early boot.

testdrv_probe() is not an __init function, yet it holds a reference to
overlays[]. The assumption is that this function is executed only at
the boot time even though it remains in memory. I annotated it as __ref
because otherwise I do not know how to suppress the modpost warning.

I marked the dtb_start as __initdata in the Xtensa boot code, although
modpost does not warn about it because __dtb_start is not yet defined
at the time of modpost.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

Changes in v2:
  - New patch

 arch/xtensa/kernel/setup.c | 2 +-
 drivers/of/unittest.c      | 5 +++--
 scripts/mod/modpost.c      | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index bdec4a773af0..d9f290cf726e 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -55,7 +55,7 @@ extern int initrd_below_start_ok;
 #endif
 
 #ifdef CONFIG_USE_OF
-void *dtb_start = __dtb_start;
+static __initdata void *dtb_start = __dtb_start;
 #endif
 
 extern unsigned long loops_per_jiffy;
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index fd8cb931b1cc..56516bf4171d 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -3585,7 +3585,7 @@ OVERLAY_INFO_EXTERN(overlay_bad_symbol);
 OVERLAY_INFO_EXTERN(overlay_bad_unresolved);
 
 /* entries found by name */
-static struct overlay_info overlays[] = {
+static __initdata struct overlay_info overlays[] = {
 	OVERLAY_INFO(overlay_base, -9999, 0),
 	OVERLAY_INFO(overlay, 0, 0),
 	OVERLAY_INFO(overlay_0, 0, 0),
@@ -4054,7 +4054,8 @@ static const struct pci_device_id testdrv_pci_ids[] = {
 	{ 0, }
 };
 
-static int testdrv_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+/* testdrv_probe() references overlays[], which is discarded data  */
+static int __ref testdrv_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	struct overlay_info *info;
 	struct device_node *dn;
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 107393a8c48a..2e4b0816fdc1 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -776,7 +776,7 @@ static void check_section(const char *modname, struct elf_info *elf,
 	".pci_fixup_enable", ".pci_fixup_resume", \
 	".pci_fixup_resume_early", ".pci_fixup_suspend"
 
-#define ALL_INIT_SECTIONS ".init.*"
+#define ALL_INIT_SECTIONS ".init.*", ".dtb.init.rodata"
 #define ALL_EXIT_SECTIONS ".exit.*"
 
 #define DATA_SECTIONS ".data", ".data.rel"
-- 
2.43.0


             reply	other threads:[~2024-09-10  9:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-10  9:44 Masahiro Yamada [this message]
2024-09-10  9:44 ` [PATCH v2 2/3] kbuild: move non-boot builtin DTBs to .init.rodata section Masahiro Yamada
2024-09-10  9:44 ` [PATCH v2 3/3] kbuild: add generic support for built-in boot DTBs Masahiro Yamada
2024-09-11 17:32 ` [PATCH v2 1/3] modpost: check section mismatch in reference to .dtb.init.rodata Rob Herring (Arm)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240910094459.352572-1-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox