The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v3] x86/kaslr: Remove two redundant if checks
@ 2026-08-02  9:35 Thorsten Blum
  2026-08-02 17:24 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-08-02  9:35 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Mike Rapoport (Microsoft),
	Pratyush Yadav (Google), Thorsten Blum
  Cc: linux-kernel

The loop in slots_fetch_random() either returns the slot address or
exits with i == slot_area_index, making the if check redundant. Drop it.

Commit 8391c73c96f2 ("x86/KASLR: Randomize virtual address separately")
added the *output != random_addr check because add_identity_map() was
only needed when the physical address changed. Commit 8570978ea030
("x86/boot/compressed/64: Don't pre-map memory in KASLR code") removed
that call. Unconditionally assign random_addr and remove the if check.

No functional change.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v3:
- Name commit 8391c73c96f2 that added the check (Boris)
- Keep the comment (Boris)
- v2: https://lore.kernel.org/r/20260731073933.685882-3-thorsten.blum@linux.dev/

Changes in v2:
- Explain why the check in choose_random_location() is redundant (Boris)
- Reword subject
- v1: https://lore.kernel.org/r/20260714205752.133163-2-thorsten.blum@linux.dev/
---
 arch/x86/boot/compressed/kaslr.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 8e4bf5365ac6..bb35f76cd3cf 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -544,8 +544,7 @@ static u64 slots_fetch_random(void)
 		return slot_areas[i].addr + ((u64)slot * CONFIG_PHYSICAL_ALIGN);
 	}
 
-	if (i == slot_area_index)
-		debug_putstr("slots_fetch_random() failed!?\n");
+	debug_putstr("slots_fetch_random() failed!?\n");
 	return 0;
 }
 
@@ -897,8 +896,7 @@ void choose_random_location(unsigned long input,
 		warn("Physical KASLR disabled: no suitable memory region!");
 	} else {
 		/* Update the new physical address location. */
-		if (*output != random_addr)
-			*output = random_addr;
+		*output = random_addr;
 	}
 
 

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

* Re: [PATCH v3] x86/kaslr: Remove two redundant if checks
  2026-08-02  9:35 [PATCH v3] x86/kaslr: Remove two redundant if checks Thorsten Blum
@ 2026-08-02 17:24 ` Borislav Petkov
  2026-08-02 23:42   ` Thorsten Blum
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2026-08-02 17:24 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
	Mike Rapoport (Microsoft), Pratyush Yadav (Google), linux-kernel

On Sun, Aug 02, 2026 at 11:35:30AM +0200, Thorsten Blum wrote:
> added the *output != random_addr check because add_identity_map() was
> only needed when the physical address changed.

The check is there to update *output in case a new random address has been
generated.

add_identity_map() was simply called to make sure that the new address is
mapped in the page table.

Are you sure you understand the code you're touching?

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

* Re: [PATCH v3] x86/kaslr: Remove two redundant if checks
  2026-08-02 17:24 ` Borislav Petkov
@ 2026-08-02 23:42   ` Thorsten Blum
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-08-02 23:42 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Thomas Gleixner, Ingo Molnar, Dave Hansen, x86, H. Peter Anvin,
	Mike Rapoport (Microsoft), Pratyush Yadav (Google), linux-kernel

On Sun, Aug 02, 2026 at 10:24:02AM -0700, Borislav Petkov wrote:
> On Sun, Aug 02, 2026 at 11:35:30AM +0200, Thorsten Blum wrote:
> > added the *output != random_addr check because add_identity_map() was
> > only needed when the physical address changed.
> 
> The check is there to update *output in case a new random address has been
> generated.
> 
> add_identity_map() was simply called to make sure that the new address is
> mapped in the page table.
> 
> Are you sure you understand the code you're touching?

Are you objecting to the reasoning in the commit message, or to removing
the if check itself?

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

end of thread, other threads:[~2026-08-02 23:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-02  9:35 [PATCH v3] x86/kaslr: Remove two redundant if checks Thorsten Blum
2026-08-02 17:24 ` Borislav Petkov
2026-08-02 23:42   ` Thorsten Blum

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