From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 9DD693EC2F7 for ; Fri, 26 Jun 2026 10:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782468915; cv=none; b=I4ZPwBFRzdFU+PEWtvql+yHFOtG7KNj/f1WRXhvAOPF1Oi1Jd/Tw5sZfhIKQjGt9ugRZewixHb4954tThO78E4rHpeHW1igQQ42D24kxsOE00/nb8Y2WdCiUXAHu3U7xW+DUE66lDs1P4WszWqYzdPDU/CXGohmspsTFjpDIqo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782468915; c=relaxed/simple; bh=NvwkO23ZSQ7iK/s2nsgWCyy8ECg+PgHvkEoBVrUSi2E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LN0r/yUnLZO38oLdBF6jjspN5FxtDIV+OYOuempgDFMAmWNk/Km9y7sxPBb98Z9n4Nq45QYanD7h4MuRcBssEHu2HVLQ5VQho40ViyZ2BoL5ohkHFeB2rdHG9Rn057P7PTBYBo6mRnDsHc1FOwnCa7XQEmjY36xuTcg9vkKu9Tg= 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=DCYvMo6l; arc=none smtp.client-ip=91.218.175.189 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="DCYvMo6l" 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=1782468910; 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=WiFbLQ8tsqd3omAk1iZza0UtLRFQED6Iy1AHSUrbQR8=; b=DCYvMo6lYNQcbGR+Y8G9sGFXzuMI3fZjzbeZMO0jsg5C/JPWsVNGmVXmcbvpZM2pQqiMDu 0+QCg+vMVMcSuyEWdZys7wHlXlnUpm5UNQYtnzipiIjqzdOeS3wrU8/1iZ/DtqM9E+b+dp AqXA/bjATCnE9MXK+6Edf5AuTaHQG/A= 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] x86/kaslr: Remove redundant if checks from address selection Date: Fri, 26 Jun 2026 12:14:12 +0200 Message-ID: <20260626101412.2929-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=NvwkO23ZSQ7iK/s2nsgWCyy8ECg+PgHvkEoBVrUSi2E=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDFl2AV/ZynbkyL7TXJfWcNJWtjDqmLXI6muXF3HY7nJx+ BJqyZjbUcrCIMbFICumyPJg1o8ZvqU1lZtMInbCzGFlAhnCwMUpABN53sPwP3T6+o7/L4Vf18Ux T7YWU7noOn3d69ycA2EqOxrcbj7f+ZHhv6PkoT1WmgKNMz7ofHQ2/XbmqJ6Hfsqh5tpqoc1XzK+ tYwcA 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 71265a0733f7..371a00aba170 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))