Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb+git@google.com>
To: linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, will@kernel.org, llvm@lists.linux.dev,
	 arnd@arndb.de, Ard Biesheuvel <ardb@kernel.org>,
	kernel test robot <lkp@intel.com>
Subject: [PATCH] arm64: Fix transient negative image size observed by the linker
Date: Mon, 30 Nov 2026 18:51:22 +0100	[thread overview]
Message-ID: <20261130175121.1358891-2-ardb+git@google.com> (raw)

From: Ard Biesheuvel <ardb@kernel.org>

LLD occasionally errors out with a mysterious 'assignment to symbol foo
does not converge', usually with a 16k page size kernel config.

This turns out to be caused by the evaluation of the SPAN_NR_ENTRIES()
macro using a preliminary value for _end that is below KIMAGE_VADDR,
resulting in the difference to become negative. Subsequent passes
usually recover from this, but not always, hence the config-dependent
error.

So ensure that SPAN_NR_ENTRIES() returns 1 for spans where the end
address is smaller than or equal to the start address. This never
occurs on the linker passes that matter, but prevents the iterative
algorithm that LLD implements from diverging.

This reverts commit dc0a08394804 ("arm64: Work around convergence
issue with LLD linker"), which is superseded by this change.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/20261129124345.eiR8unSx-lkp@intel.com/
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/include/asm/kernel-pgtable.h | 13 +++++++++++--
 arch/arm64/kernel/image-vars.h          | 11 -----------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index 229ee7976f69..929b5ac39981 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -42,8 +42,17 @@
  */
 #define EXTRA_PAGE	__is_defined(CONFIG_RELOCATABLE)
 
+/*
+ * LLD may evaluate SPAN_NR_ENTRIES() before _end has assumed its final value,
+ * and if the chosen preliminary value happens to be below KIMAGE_VADDR, the
+ * linker may go off into the weeds due to the negative result, ultimately
+ * leading to a 'assignment to symbol foo does not converge' error.
+ *
+ * Work around this by ensuring that SPAN_NR_ENTRIES() returns '1' in such
+ * transient cases. The final pass will observe the correct result.
+ */
 #define SPAN_NR_ENTRIES(vstart, vend, shift) \
-	((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1)
+	((vend) <= (vstart) ? 1 : (((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1)
 
 #define EARLY_ENTRIES(lvl, vstart, vend) \
 	SPAN_NR_ENTRIES(vstart, vend, SWAPPER_BLOCK_SHIFT + lvl * PTDESC_TABLE_SHIFT)
@@ -58,7 +67,7 @@
 #define INIT_DIR_SIZE (PAGE_SIZE * (EARLY_PAGES(SWAPPER_PGTABLE_LEVELS, KIMAGE_VADDR, _end, EXTRA_PAGE) \
 				    + EARLY_SEGMENT_EXTRA_PAGES))
 
-#define INIT_IDMAP_DIR_PAGES	(EARLY_PAGES(INIT_IDMAP_PGTABLE_LEVELS, KIMAGE_VADDR, kimage_limit, 1))
+#define INIT_IDMAP_DIR_PAGES	(EARLY_PAGES(INIT_IDMAP_PGTABLE_LEVELS, KIMAGE_VADDR, _end, 1))
 #define INIT_IDMAP_DIR_SIZE	((INIT_IDMAP_DIR_PAGES + EARLY_IDMAP_EXTRA_PAGES) * PAGE_SIZE)
 
 #define INIT_IDMAP_FDT_PAGES	(EARLY_PAGES(INIT_IDMAP_PGTABLE_LEVELS, 0UL, UL(MAX_FDT_SIZE), 1) - 1)
diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h
index 19d602e45523..7fc1417aab14 100644
--- a/arch/arm64/kernel/image-vars.h
+++ b/arch/arm64/kernel/image-vars.h
@@ -154,17 +154,6 @@ KVM_NVHE_ALIAS(kvm_protected_mode_initialized);
 _kernel_codesize = ABSOLUTE(__inittext_end - _text);
 #endif
 
-/*
- * LLD will occasionally error out with a '__init_end does not converge' error
- * if INIT_IDMAP_DIR_SIZE is defined in terms of _end, as this results in a
- * circular dependency. Counter this by dimensioning the initial IDMAP page
- * tables based on kimage_limit, which is defined such that its value should
- * not change as a result of the initdata segment being pushed over a 64k
- * segment boundary due to changes in INIT_IDMAP_DIR_SIZE, provided that its
- * value doesn't change by more than 2M between linker passes.
- */
-kimage_limit = ALIGN(ABSOLUTE(_end + SZ_64K), SZ_2M);
-
 #undef ASSERT
 
 #endif /* __ARM64_KERNEL_IMAGE_VARS_H */
-- 
2.56.1.839.g22a8290db9-goog



                 reply	other threads:[~2026-11-30 17:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130175121.1358891-2-ardb+git@google.com \
    --to=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=will@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