From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 C61FC3A450F for ; Fri, 31 Jul 2026 07:40:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785483617; cv=none; b=majEFR2cvuDWcc+atyxncWXZo2agHOvpWX0dnHGUqDz7VXk84TFFgBSo4Vk/caBMWrzoErngO9XVKj9ANyzv9vyqThrJRNIY1aebjWukotnX0LmmwNaT3THZ8C+MB2lNM/Y35PdjxA+UhHumiggCTG8AFoGSl8m0Ll7gGJmeO9o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785483617; c=relaxed/simple; bh=KFLsyjgVTKKZ7uIDYbB1GoHLhi1FPOQv6QsVonPC4yA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=h6iiw0tmShhWDBDSXMNCropPlcl9y8TdP+YmY+nLnsCT1sWAhddnc0a4c3rvWIWp8Hu7LfxS5Td4ONnZE01XQXJmCaaWysgxZzkPg8iiIPudC6aC1s6LL2fEvqD5C9wPOiIAoFMQWqVP8sJ7zVzG8Q0VaLRAqgJXc2CWUj6L8aM= 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=GHtrRCMh; arc=none smtp.client-ip=95.215.58.181 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="GHtrRCMh" 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=1785483610; 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=JCeBsNNQiC2GMf7XmUi0uSfpVFuIAaJ2WyfVHHhc7bg=; b=GHtrRCMh9E6NErc1seV/ofBmXhwFTux2Zu65ySdanMfhQf47j4Me7eCH4TgNv15dxbLccp HDQH+5+jwGJGuehbdm/A4c6DbTSfKCYW0c8rTXa5VYzhIa3Mab9i3mGsYw8MLzghVC/ZMd KhES1F2l8QvZYmwWKJEYJOYGyyfOnqE= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Pratyush Yadav (Google)" , Thorsten Blum , "Mike Rapoport (Microsoft)" Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2] x86/kaslr: Remove two redundant if checks Date: Fri, 31 Jul 2026 09:39:34 +0200 Message-ID: <20260731073933.685882-3-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=1882; i=thorsten.blum@linux.dev; h=from:subject; bh=KFLsyjgVTKKZ7uIDYbB1GoHLhi1FPOQv6QsVonPC4yA=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFk5gaZBCoKx97/VChwterXqatSqtB0flL//UH/IIDRXv Xm5icmpjlIWBjEuBlkxRZYHs37M8C2tqdxkErETZg4rE8gQBi5OAZiIoxDDX5nnOZ8Y25rbGKo6 Z53s/jZZcqqdknC+nYfAxDdrCydtEGJkOOiwIerMuZJjrXe+BQt7Tjuy64bixjLP+u3zvkoZaMV V8wIA 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. In choose_random_location(), the if (*output != random_addr) check used to guard an add_identity_map() call. Commit 8570978ea030 ("x86/boot/compressed/64: Don't pre-map memory in KASLR code") removed that call and the check now only guards an assignment. Remove it. No functional change. Signed-off-by: Thorsten Blum --- 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 | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c index 8e4bf5365ac6..181257a6e0aa 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; } @@ -893,14 +892,10 @@ void choose_random_location(unsigned long input, /* Walk available memory entries to find a random address. */ random_addr = find_random_phys_addr(min_addr, output_size); - if (!random_addr) { + if (!random_addr) warn("Physical KASLR disabled: no suitable memory region!"); - } else { - /* Update the new physical address location. */ - if (*output != random_addr) - *output = random_addr; - } - + else + *output = random_addr; /* Pick random virtual address starting from LOAD_PHYSICAL_ADDR. */ if (IS_ENABLED(CONFIG_X86_64))