From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (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 3E7497262B for ; Sun, 2 Aug 2026 09:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785663406; cv=none; b=KRUBusJ7zX9nDu8E5hs+wR0l7dcd+YjlsIIw50xLKJT/C6XiMmfrXWo2xki/Qt+6Ih9JjyWhVIeFsxojahYsVOKsGYgM7t4Qkv1IX77LoAunq63XZ+pdEPx5+nbvVQcDJ10/1Ji7YutPBLZIBD2+PlFwqr4265s2dLE4sr1oUcw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785663406; c=relaxed/simple; bh=liPm7hOWW4v7NiRgAZTe0eXSJGmQVYDSNxieoPc/Q2c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ITxm+AEJZgaX9yzpVxEPmcvksdOzNdMmsht3LkLVF1sdzzREXe6rkTtv3ebLrFkmEHC7dluJprw9fFzSpd0qx4mPZxdNWHOyFuUASFmrEO06Ylk3Fj5p9aNkKY9cAUJzI5dDQBIqM7foM8Jl0zcngmzc0RzwPSTRLpqq5/sQEAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VGeOiO7a; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VGeOiO7a" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1785663402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/cU0vDUbtAE1XRwlN0khaMKVewPdPVpOHFuwf93H2Ok=; b=VGeOiO7aOvt+OowxmAoUVUmgnFriBpPGUsQInvBOimAuw6uxNxrSqv4qXQTDabv4Ljm8kg dc2KLJdpuRiNJxT4K2ojNPTDfbK723nBxZ1RPaM5mOPCrhGIPQpYjMSszQrdsGIGVFH2qI rOP/Sz/l6lEO916RFCPfU5FNJ+8e28U= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Mike Rapoport (Microsoft)" , "Pratyush Yadav (Google)" , Thorsten Blum Cc: linux-kernel@vger.kernel.org Subject: [PATCH v3] x86/kaslr: Remove two redundant if checks Date: Sun, 2 Aug 2026 11:35:30 +0200 Message-ID: <20260802093531.7165-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1855; i=thorsten.blum@linux.dev; h=from:subject; bh=liPm7hOWW4v7NiRgAZTe0eXSJGmQVYDSNxieoPc/Q2c=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFn5/MmZayRW21n1cX9aJ/DsiXNe90G+lY1KcdMZOqsO6 VadbvjVUcrCIMbFICumyPJg1o8ZvqU1lZtMInbCzGFlAhnCwMUpABO5YszwV2YbWw3zj79fthrU PJ1cljQ70Jp1YkRD41P93fqeNjxKrgz/641ufjUtY3F83ngpoyt5qZamohVrnALXEm2dpoJLW+o 5AQ== X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 --- 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; }