From nobody Mon Feb 9 20:36:25 2026 Received: from out28-101.mail.aliyun.com (out28-101.mail.aliyun.com [115.124.28.101]) (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 3243E33A9DB for ; Mon, 26 Jan 2026 13:35:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434553; cv=none; b=Zli/a8hDu7F4r2fKTNx/wglF2SxBxHQ9q8uUL1hJbr2F1dCWtuz8BsnM7iL6Qxk8C/xWemTNU6/+bbFLgKJ0RSgNtmwjUrAjPbdsYdwVJLipzFJAU/C7QsBxSSIhD70QCD/LF5wW5oRDYDGGGMMc2rluSbrjhW08nCDEV6xxb0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434553; c=relaxed/simple; bh=l3ZqqqJnpuxhFrqutBVHWkejBFSWvi439jZl62jfJlA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UchE6FwPNCOX1py+X4FdePScKceC2ntHtMldiMaJt1rG0X9STKizBM9CHFZwXPVYaOotRyhohrgHLn0rM7xck7nYhvCeV1Rh84AwhLateNeLZUrHcLnCDb4bE7rVDJrRUeDRKriFLY8rTvRnQyd/ynJNJJNigidvdQ+63VP8LVo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=W3d8eh/A; arc=none smtp.client-ip=115.124.28.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="W3d8eh/A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1769434541; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=bQUIu00QJ2+sFwDA2G4ty2gRTryfutb78U6Ewkufrgk=; b=W3d8eh/AjA/+E+QruPJhN+ImA9Oc6szREJS7hioI7W2oyz4YWIzDQYKsf+BK+yM9HuF4Bfz5pBNiMWhHNNXqxUCQGkDi7eSiNGm22cfQY+B9bErcAErhDyi5WM5Wv2cjamF4W6hDmju4qzqaGML7oQYvcuFCXVdDsQr7EKKxF50= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.gGHqkb6_1769434540 cluster:ay29) by smtp.aliyun-inc.com; Mon, 26 Jan 2026 21:35:41 +0800 From: Hou Wenlong To: linux-kernel@vger.kernel.org Cc: Lai Jiangshan , Hou Wenlong , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Uros Bizjak , Ard Biesheuvel , Brian Gerst , Pawan Gupta , Guenter Roeck Subject: [RFC PATCH 3/5] x86: Allow to build relocatable uncompressed kernel binary Date: Mon, 26 Jan 2026 21:33:53 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for building a relocatable uncompressed kernel binary, which contains the relocation table generated by the 'relocs' tool and can be used to perform KASLR directly when booting from it instead of a compressed kernel image. To simplify, follow the MIPS implementation to reserve a section to store the relocation table. Signed-off-by: Hou Wenlong --- arch/x86/Kconfig | 20 ++++++++++++++++++++ arch/x86/Makefile.postlink | 33 +++++++++++++++++++++++++++++++++ arch/x86/kernel/vmlinux.lds.S | 20 ++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 arch/x86/Makefile.postlink diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 49ca6e26dffa..f95112b94c6a 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2124,6 +2124,26 @@ config RANDOMIZE_BASE =20 If unsure, say Y. =20 +config RELOCATABLE_UNCOMPRESSED_KERNEL + bool "Build a relocatable uncompressed kernel" + depends on RANDOMIZE_BASE && X86_64 + help + A table of relocation data will be appended to the uncompressed + kernel binary and parsed at boot to do relocation. + +config RELOCATION_TABLE_SIZE + hex "Relocation table size" + depends on RELOCATABLE_UNCOMPRESSED_KERNEL + range 0x0 0x04000000 + default "0x00200000" + help + This option allows the amount of space reserved for the table to be + adjusted, although the default of 1Mb should be ok in most cases. + + The build will fail and a valid size suggested if this is too small. + + If unsure, leave at the default value. + # Relocation on x86 needs some additional build support config X86_NEED_RELOCS def_bool y diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink new file mode 100644 index 000000000000..46497c47b331 --- /dev/null +++ b/arch/x86/Makefile.postlink @@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0 +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D +# Post-link x86 pass +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D +# +# 1. Insert relocations into vmlinux + +PHONY :=3D __archpost +__archpost: + +-include include/config/auto.conf +include $(srctree)/scripts/Kbuild.include + +CMD_RELOCS =3D arch/x86/tools/relocs +quiet_cmd_relocs =3D RELOCS $@ + cmd_relocs =3D $(CMD_RELOCS) --keep $@ + +# `@true` prevents complaint when there is nothing to be done + +vmlinux vmlinux.unstripped: FORCE + @true +ifeq ($(CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL),y) + $(call if_changed,relocs) +endif + +clean: + @true + +PHONY +=3D FORCE clean + +FORCE: + +.PHONY: $(PHONY) diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index d7af4a64c211..99cdcbdbeaab 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -289,6 +289,26 @@ SECTIONS } #endif =20 +#ifdef CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL + . =3D ALIGN(4); + .data.reloc : AT(ADDR(.data.reloc) - LOAD_OFFSET) { + __relocation_start =3D .; + /* + * Space for relocation table + * This needs to be filled so that the + * relocs tool can overwrite the content. + * An invalid value is left at the start of the + * section to abort relocation if the table + * has not been filled in. + */ + LONG(0xFFFFFFFF); + FILL(0); + . +=3D CONFIG_RELOCATION_TABLE_SIZE - 4; + __relocation_end =3D .; + __pi___relocation_end =3D .; + } +#endif + /* * struct alt_inst entries. From the header (alternative.h): * "Alternative instructions for different CPU types or capabilities" --=20 2.31.1