From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 B2337427FBF for ; Tue, 14 Jul 2026 20:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784062757; cv=none; b=RSN6o2sWkOIdyLeA16QIpjR+EhVvdMH3npVvI658KWA/60psRBjidzdfECiCOhnBImBV6dw8QaJJx6+qlOcoYrVioiM2p82EQklsdWM7ZkJIFjtkDZ7Mntd6b9QjLqjp8N/KnJ7I8Fvzl+PnZGREr56e+wtC+mYh9MC3XmxPEWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784062757; c=relaxed/simple; bh=au3OVF8a2CR3rk5Z5xN8t49xAkPH75LpGLaZbNB7LPQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VTu3WllMrxOxEjMQlEiaOjwczJkLFcdAUh6vxEqAH4tWHMRn4weM6xjr+85ad8G3Ae7TXQY8u1fj4ljz5wdTX7sZh4VFrT1Xp38QpiI0dnfvhb740cOSMqnSMMiVxPfeig/ii000EddZ5GFcgUjX7M2llVvICEwJzp/19q/skD4= 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=MV7wqdnn; arc=none smtp.client-ip=95.215.58.179 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="MV7wqdnn" 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=1784062753; 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=MsEdKNmJdAihPpwsnrFEX9fUncAercGMmjLtZTS9bJU=; b=MV7wqdnnFIYuzJTTNlmoqdC/Na+7xQZg+45Nx57P60/LEq0NU1sqwMsY5+wEKgh92TkpE4 8AcryFPTwYWfmcMxkzVgXYFcF28JLjiVLHkEkEEMCQ2ksTNCyCzOF29N/gnW1Cp9Qvuf/F pxcTMrS4o34GLASAwcmGZoXRgIG7ebI= From: Thorsten Blum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Thorsten Blum Cc: linux-kernel@vger.kernel.org Subject: [PATCH RESEND] x86/kaslr: Remove redundant if checks from address selection Date: Tue, 14 Jul 2026 22:57:51 +0200 Message-ID: <20260714205752.133163-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=1563; i=thorsten.blum@linux.dev; h=from:subject; bh=au3OVF8a2CR3rk5Z5xN8t49xAkPH75LpGLaZbNB7LPQ=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFlhiy7M9tV7oH5KTcTKcVnQUpu2hjd3Hc9wf217lPPyj btz0ayzHaUsDGJcDLJiiiwPZv2Y4VtaU7nJJGInzBxWJpAhDFycAjCRd5cZGU5IhNYsmDnx1dKI qkrWJt4Laxw26X14w/v+us9UpzfcalcYGSZned6Zc6twdaem0SOTmLUrYmZ5T2ILf7T4+S3XDB0 nBl4A 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. The if check in choose_random_location() is also unnecessary since commit 8570978ea030 ("x86/boot/compressed/64: Don't pre-map memory in KASLR code"). Remove both if checks. Signed-off-by: Thorsten Blum --- 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 81e21c76cbb8..9fb1d495c688 100644 --- a/arch/x86/boot/compressed/kaslr.c +++ b/arch/x86/boot/compressed/kaslr.c @@ -541,8 +541,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; } @@ -890,14 +889,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))