Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH] arm64: Fix transient negative image size observed by the linker
@ 2026-11-30 17:51 Ard Biesheuvel
  2026-12-01  8:52 ` Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-11-30 17:51 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: catalin.marinas, will, llvm, arnd, Ard Biesheuvel,
	kernel test robot

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-11-30 17:51 [PATCH] arm64: Fix transient negative image size observed by the linker Ard Biesheuvel
@ 2026-12-01  8:52 ` Arnd Bergmann
  2026-12-01 13:17 ` Catalin Marinas
  2026-12-01 14:13 ` Catalin Marinas
  2 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2026-12-01  8:52 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-arm-kernel
  Cc: Catalin Marinas, Will Deacon, llvm, Ard Biesheuvel,
	kernel test robot

On Mon, Nov 30, 2026, at 18:51, Ard Biesheuvel wrote:
> 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>

Hi Ard,

I've successfully tested one known instance of the bug being fixed by
this. I'll keep my randconfig tests running to ensure there are no
remaining corner cases that still run into the same symptom. If you
don't hear back from my by tomorrow:

Tested-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-11-30 17:51 [PATCH] arm64: Fix transient negative image size observed by the linker Ard Biesheuvel
  2026-12-01  8:52 ` Arnd Bergmann
@ 2026-12-01 13:17 ` Catalin Marinas
  2026-12-01 13:29   ` Ard Biesheuvel
  2026-12-01 14:13 ` Catalin Marinas
  2 siblings, 1 reply; 9+ messages in thread
From: Catalin Marinas @ 2026-12-01 13:17 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-arm-kernel, will, llvm, arnd, Ard Biesheuvel,
	kernel test robot

Hi Ard,

On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
> 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/

Is this happening with your efi-zboot-elf branch only or mainline as
well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
what Arnd tested on.

Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
inside the sections and they depend on _end. IIUC, they become part of
the section size and moving '.' backwards is an error. I found another
report on your branch, not sure it's related but it looks like it's
caused by wrapped values:

https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/

> 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.

Nit: it's probably implied but the negative result is actually a very
big uint64_t number. Not sure it needs any clarification.

> + *
> + * 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)

This looks correct.

> 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);

dc0a08394804 ("arm64: Work around convergence issue with LLD linker")
was about the circular dependency (_end -> INIT_IDMAP_DIR_SIZE -> _end).
Does that earlier problem go away with your patch here?

-- 
Catalin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-12-01 13:17 ` Catalin Marinas
@ 2026-12-01 13:29   ` Ard Biesheuvel
  2026-12-01 13:50     ` Ard Biesheuvel
  0 siblings, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2026-12-01 13:29 UTC (permalink / raw)
  To: Catalin Marinas, Ard Biesheuvel
  Cc: linux-arm-kernel, Will Deacon, llvm, Arnd Bergmann,
	kernel test robot


On Tue, 1 Dec 2026, at 14:17, Catalin Marinas wrote:
> Hi Ard,
>
> On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
>> 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/
>
> Is this happening with your efi-zboot-elf branch only or mainline as
> well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
> what Arnd tested on.
>
> Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
> inside the sections and they depend on _end. IIUC, they become part of
> the section size and moving '.' backwards is an error. I found another
> report on your branch, not sure it's related but it looks like it's
> caused by wrapped values:
>
> https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/
>

That just happens to be the branch where it was found this time, but
it is not related to any of those changes.

Arnd's testing should be entirely unrelated to any of this.

>> 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.
>
> Nit: it's probably implied but the negative result is actually a very
> big uint64_t number. Not sure it needs any clarification.
>

Essentially, yes.

>> + *
>> + * 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)
>
> This looks correct.
>
>> 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);
>
> dc0a08394804 ("arm64: Work around convergence issue with LLD linker")
> was about the circular dependency (_end -> INIT_IDMAP_DIR_SIZE -> _end).
> Does that earlier problem go away with your patch here?
>

Yes. The earlier problem was not as well understood as it is today :-)

dc0a08394804 failed to update both occurrences of _end (it missed INIT_DIR_SIZE)
or the issue wouldn't have happened again, as far as I can tell. But simply
avoiding the wraparound in SPAN_NR_ENTRIES() is sufficient.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-12-01 13:29   ` Ard Biesheuvel
@ 2026-12-01 13:50     ` Ard Biesheuvel
  2026-12-01 14:14       ` Catalin Marinas
  0 siblings, 1 reply; 9+ messages in thread
From: Ard Biesheuvel @ 2026-12-01 13:50 UTC (permalink / raw)
  To: Catalin Marinas, Ard Biesheuvel
  Cc: linux-arm-kernel, Will Deacon, llvm, Arnd Bergmann,
	kernel test robot



On Tue, 1 Dec 2026, at 14:29, Ard Biesheuvel wrote:
> On Tue, 1 Dec 2026, at 14:17, Catalin Marinas wrote:
>> Hi Ard,
>>
>> On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
>>> 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/
>>
>> Is this happening with your efi-zboot-elf branch only or mainline as
>> well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
>> what Arnd tested on.
>>
>> Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
>> inside the sections and they depend on _end. IIUC, they become part of
>> the section size and moving '.' backwards is an error. I found another
>> report on your branch, not sure it's related but it looks like it's
>> caused by wrapped values:
>>
>> https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/
>>
>
> That just happens to be the branch where it was found this time, but
> it is not related to any of those changes.
>
> Arnd's testing should be entirely unrelated to any of this.
>

I double checked: the randconfig from the linked report fails in a
similar way with v7.4-rc1 (but on a different symbol)

ld.lld-22: error: address (0xfffffff882fb4000) of section '.init.data' does not converge
ld.lld-22: error: assignment to symbol __init_end does not converge



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-11-30 17:51 [PATCH] arm64: Fix transient negative image size observed by the linker Ard Biesheuvel
  2026-12-01  8:52 ` Arnd Bergmann
  2026-12-01 13:17 ` Catalin Marinas
@ 2026-12-01 14:13 ` Catalin Marinas
  2026-12-01 14:19   ` Catalin Marinas
  2 siblings, 1 reply; 9+ messages in thread
From: Catalin Marinas @ 2026-12-01 14:13 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-arm-kernel, will, llvm, arnd, Ard Biesheuvel,
	kernel test robot

Hi Ard,

On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
> 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/

Is this happening with your efi-zboot-elf branch only or mainline as
well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
what Arnd tested on.

Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
inside the sections and they depend on _end. IIUC, they become part of
the section size and moving '.' backwards is an error. I found another
report on your branch, not sure it's related but it looks like it's
caused by wrapped values:

https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/

> 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.

Nit: it's probably implied but the negative result is actually a very
big uint64_t number. Not sure it needs any clarification.

> + *
> + * 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)

This looks correct.

> 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);

dc0a08394804 ("arm64: Work around convergence issue with LLD linker")
was about the circular dependency (_end -> INIT_IDMAP_DIR_SIZE -> _end).
Does that earlier problem go away with your patch here?

-- 
Catalin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-12-01 13:50     ` Ard Biesheuvel
@ 2026-12-01 14:14       ` Catalin Marinas
  2026-12-01 14:26         ` Ard Biesheuvel
  0 siblings, 1 reply; 9+ messages in thread
From: Catalin Marinas @ 2026-12-01 14:14 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Ard Biesheuvel, linux-arm-kernel, Will Deacon, llvm,
	Arnd Bergmann, kernel test robot

On Tue, Dec 01, 2026 at 02:50:15PM +0100, Ard Biesheuvel wrote:
> On Tue, 1 Dec 2026, at 14:29, Ard Biesheuvel wrote:
> > On Tue, 1 Dec 2026, at 14:17, Catalin Marinas wrote:
> >> On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
> >>> 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/
> >>
> >> Is this happening with your efi-zboot-elf branch only or mainline as
> >> well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
> >> what Arnd tested on.
> >>
> >> Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
> >> inside the sections and they depend on _end. IIUC, they become part of
> >> the section size and moving '.' backwards is an error. I found another
> >> report on your branch, not sure it's related but it looks like it's
> >> caused by wrapped values:
> >>
> >> https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/
> >
> > That just happens to be the branch where it was found this time, but
> > it is not related to any of those changes.
> >
> > Arnd's testing should be entirely unrelated to any of this.
> 
> I double checked: the randconfig from the linked report fails in a
> similar way with v7.4-rc1 (but on a different symbol)
> 
> ld.lld-22: error: address (0xfffffff882fb4000) of section '.init.data' does not converge
> ld.lld-22: error: assignment to symbol __init_end does not converge

Thanks for confirming. Happy to pick it up as a fix but do we need a cc
stable and Fixes? There's the early 0370b31e4845 ("arm64: Extend early
page table code to allow for larger kernels") which added this linker
script dependency on _end. I guess we could also add dc0a08394804
("arm64: Work around convergence issue with LLD linker") as we are
practically reverting it (or just mention it in the commit log, as you
did).

-- 
Catalin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-12-01 14:13 ` Catalin Marinas
@ 2026-12-01 14:19   ` Catalin Marinas
  0 siblings, 0 replies; 9+ messages in thread
From: Catalin Marinas @ 2026-12-01 14:19 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-arm-kernel, will, llvm, arnd, Ard Biesheuvel,
	kernel test robot

Ignore this duplicate, our smtp server is playing up and I just resent
the wrong reply.

On Tue, Dec 01, 2026 at 02:13:36PM +0000, Catalin Marinas wrote:
> Hi Ard,
> 
> On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
> > 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/
> 
> Is this happening with your efi-zboot-elf branch only or mainline as
> well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
> what Arnd tested on.
> 
> Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
> inside the sections and they depend on _end. IIUC, they become part of
> the section size and moving '.' backwards is an error. I found another
> report on your branch, not sure it's related but it looks like it's
> caused by wrapped values:
> 
> https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/
> 
> > 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.
> 
> Nit: it's probably implied but the negative result is actually a very
> big uint64_t number. Not sure it needs any clarification.
> 
> > + *
> > + * 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)
> 
> This looks correct.
> 
> > 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);
> 
> dc0a08394804 ("arm64: Work around convergence issue with LLD linker")
> was about the circular dependency (_end -> INIT_IDMAP_DIR_SIZE -> _end).
> Does that earlier problem go away with your patch here?
> 
> -- 
> Catalin

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] arm64: Fix transient negative image size observed by the linker
  2026-12-01 14:14       ` Catalin Marinas
@ 2026-12-01 14:26         ` Ard Biesheuvel
  0 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2026-12-01 14:26 UTC (permalink / raw)
  To: Catalin Marinas
  Cc: Ard Biesheuvel, linux-arm-kernel, Will Deacon, llvm,
	Arnd Bergmann, kernel test robot



On Tue, 1 Dec 2026, at 15:14, Catalin Marinas wrote:
> On Tue, Dec 01, 2026 at 02:50:15PM +0100, Ard Biesheuvel wrote:
>> On Tue, 1 Dec 2026, at 14:29, Ard Biesheuvel wrote:
>> > On Tue, 1 Dec 2026, at 14:17, Catalin Marinas wrote:
>> >> On Mon, Nov 30, 2026 at 06:51:22PM +0100, Ard Biesheuvel wrote:
>> >>> 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/
>> >>
>> >> Is this happening with your efi-zboot-elf branch only or mainline as
>> >> well? If the latter, we'd need a Fixes tag and cc stable. I'm not sure
>> >> what Arnd tested on.
>> >>
>> >> Your branch moves the INIT_IDMAP_DIR_SIZE and INIT_DIR_SIZE reservations
>> >> inside the sections and they depend on _end. IIUC, they become part of
>> >> the section size and moving '.' backwards is an error. I found another
>> >> report on your branch, not sure it's related but it looks like it's
>> >> caused by wrapped values:
>> >>
>> >> https://lore.kernel.org/all/20261120005637.8iy6yHZU-lkp@intel.com/
>> >
>> > That just happens to be the branch where it was found this time, but
>> > it is not related to any of those changes.
>> >
>> > Arnd's testing should be entirely unrelated to any of this.
>> 
>> I double checked: the randconfig from the linked report fails in a
>> similar way with v7.4-rc1 (but on a different symbol)
>> 
>> ld.lld-22: error: address (0xfffffff882fb4000) of section '.init.data' does not converge
>> ld.lld-22: error: assignment to symbol __init_end does not converge
>
> Thanks for confirming. Happy to pick it up as a fix but do we need a cc
> stable and Fixes? There's the early 0370b31e4845 ("arm64: Extend early
> page table code to allow for larger kernels") which added this linker
> script dependency on _end. I guess we could also add dc0a08394804
> ("arm64: Work around convergence issue with LLD linker") as we are
> practically reverting it (or just mention it in the commit log, as you
> did).
>

Maybe Fixes:dc0a08394804 so it gets taken back into v6.18, where it should
apply unmodified? We can always backport it further if there is a need,
but that seems unlikely to me.




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-01 14:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 17:51 [PATCH] arm64: Fix transient negative image size observed by the linker Ard Biesheuvel
2026-12-01  8:52 ` Arnd Bergmann
2026-12-01 13:17 ` Catalin Marinas
2026-12-01 13:29   ` Ard Biesheuvel
2026-12-01 13:50     ` Ard Biesheuvel
2026-12-01 14:14       ` Catalin Marinas
2026-12-01 14:26         ` Ard Biesheuvel
2026-12-01 14:13 ` Catalin Marinas
2026-12-01 14:19   ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox