From nobody Sat Feb 7 12:19:43 2026 Received: from out198-19.us.a.mail.aliyun.com (out198-19.us.a.mail.aliyun.com [47.90.198.19]) (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 4FBF933970F for ; Mon, 26 Jan 2026 13:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.198.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434544; cv=none; b=l8aMHf3czXfZOlamsFHD/wiayAp0ljD4hbPD07CK5hBgfmoswLYDqZ5d3R4s2wlTq1eNV19a8bxfGsKMRLsxYlxXj2bH5jhMgir0SxH3iOWwVKbgvDQQXwVIUi0B952DgC/2C7DJc1DwtgXTNYcuBWGhABWFSKDNgmbPiw85Nf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434544; c=relaxed/simple; bh=b+uDgD8XOMRLrEG7SadJgZY2gBH3dzW52pIhkArgozU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f6JNPAflj0g9/5eon3B6dkunukWLwMnUpAxGk0HvfOG5THfulH2/YBZygduWUvpiITUfjOebrbGhdFpAzNvzfEVV4vryNsxHu4ImVMd3K83GEe7QRRLrXLpE1RyfxThDsBVuUOY5VPjq7Nvp1ZUf+Pi+a2+EB41eUKjrrTcJYH4= 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=YNy/C9df; arc=none smtp.client-ip=47.90.198.19 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="YNy/C9df" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1769434525; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=du9Zf8HObLpUkXiHCA2fdY4IhNvUREwnWUYyYyspdzg=; b=YNy/C9dfOAbwjX00cJmyqV0AzM9I/GviKETYN2jXWDTnzdWWLhWhLVQ9WUufl2F9wzTj3BdKb2LRq0sZgyucnTbGxOkdzrJKuLdvmjc1pw6gQSzIqZ0rH0N+0/0mbRa4ro2OohYAP0yBQbD0faVn5bCoQEbPnm1rZMpgVRDD5tU= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.gGArkxM_1769434524 cluster:ay29) by smtp.aliyun-inc.com; Mon, 26 Jan 2026 21:35:25 +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" , Ard Biesheuvel , Brian Gerst , Uros Bizjak Subject: [RFC PATCH 1/5] x86/relocs: Cleanup cmdline options Date: Mon, 26 Jan 2026 21:33:51 +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" Move all cmdline options to global variables to make code cleaner and to facilitate the addition of new cmdline options. Signed-off-by: Hou Wenlong --- arch/x86/tools/relocs.c | 12 +++++------- arch/x86/tools/relocs.h | 14 ++++++++------ arch/x86/tools/relocs_common.c | 13 +++++-------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index e5a2b9a912d1..945d78c368f7 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -127,7 +127,7 @@ static int is_reloc(enum symtype type, const char *sym_= name) return sym_regex[type] && !regexec(&sym_regex_c[type], sym_name, 0, NULL,= 0); } =20 -static void regex_init(int use_real_mode) +static void regex_init(void) { char errbuf[128]; int err; @@ -950,7 +950,7 @@ static int write32_as_text(uint32_t v, FILE *f) return fprintf(f, "\t.long 0x%08"PRIx32"\n", v) > 0 ? 0 : -1; } =20 -static void emit_relocs(int as_text, int use_real_mode) +static void emit_relocs(void) { int i; int (*write_reloc)(uint32_t, FILE *) =3D write32; @@ -1049,11 +1049,9 @@ static void print_reloc_info(void) # define process process_32 #endif =20 -void process(FILE *fp, int use_real_mode, int as_text, - int show_absolute_syms, int show_absolute_relocs, - int show_reloc_info) +void process(FILE *fp) { - regex_init(use_real_mode); + regex_init(); read_ehdr(fp); read_shdrs(fp); read_strtabs(fp); @@ -1075,5 +1073,5 @@ void process(FILE *fp, int use_real_mode, int as_text, return; } =20 - emit_relocs(as_text, use_real_mode); + emit_relocs(); } diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h index 4c49c82446eb..5ade07ac2754 100644 --- a/arch/x86/tools/relocs.h +++ b/arch/x86/tools/relocs.h @@ -30,10 +30,12 @@ enum symtype { S_NSYMTYPES }; =20 -void process_32(FILE *fp, int use_real_mode, int as_text, - int show_absolute_syms, int show_absolute_relocs, - int show_reloc_info); -void process_64(FILE *fp, int use_real_mode, int as_text, - int show_absolute_syms, int show_absolute_relocs, - int show_reloc_info); +extern int show_absolute_syms; +extern int show_absolute_relocs; +extern int show_reloc_info; +extern int as_text; +extern int use_real_mode; + +void process_32(FILE *fp); +void process_64(FILE *fp); #endif /* RELOCS_H */ diff --git a/arch/x86/tools/relocs_common.c b/arch/x86/tools/relocs_common.c index 6634352a20bc..ee8a9fafcb11 100644 --- a/arch/x86/tools/relocs_common.c +++ b/arch/x86/tools/relocs_common.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include "relocs.h" =20 +int show_absolute_syms, show_absolute_relocs, show_reloc_info; +int as_text, use_real_mode; + void die(char *fmt, ...) { va_list ap; @@ -18,8 +21,6 @@ static void usage(void) =20 int main(int argc, char **argv) { - int show_absolute_syms, show_absolute_relocs, show_reloc_info; - int as_text, use_real_mode; const char *fname; FILE *fp; int i; @@ -73,13 +74,9 @@ int main(int argc, char **argv) } rewind(fp); if (e_ident[EI_CLASS] =3D=3D ELFCLASS64) - process_64(fp, use_real_mode, as_text, - show_absolute_syms, show_absolute_relocs, - show_reloc_info); + process_64(fp); else - process_32(fp, use_real_mode, as_text, - show_absolute_syms, show_absolute_relocs, - show_reloc_info); + process_32(fp); fclose(fp); return 0; } --=20 2.31.1 From nobody Sat Feb 7 12:19:43 2026 Received: from out28-121.mail.aliyun.com (out28-121.mail.aliyun.com [115.124.28.121]) (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 B2D1333A71D for ; Mon, 26 Jan 2026 13:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.121 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434548; cv=none; b=jRMgmoRnsNhbtorM4RuxiVkGZL9BMnQaasEnUZHAGiNmaHFN8J/qu/RP1CkE0oFpFymEXOCLXtjpJgIrrPmsWm8tXwpe5LEaiAgCdNuAaOdjgvaSmsIjc/mMOjA+230ExyMPdX/8I19xikKdBEvPCZMiMjt7mIwDhH8gOoHEz8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434548; c=relaxed/simple; bh=Q9gMrlCKh8ZWb5c0rnpgOpDh4XRPjnnqoTkvA7zhZSQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fi5D1QzHQDINTi1W788+/i0wKyk1xbBIAq8Q1HfYT6HB4iP9LJKaEXWU2tecUyKIhXIGOfLxpF/Mg2fT7fCenzQ8fWIca60BaWOthO5vTAPRd0XMIeFROql75B6IQ25Qt0B/0OqbH/fSPy2uG1DHULNRClYafiEordyUtDfAs5A= 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=AFDZFGNS; arc=none smtp.client-ip=115.124.28.121 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="AFDZFGNS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1769434535; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=mHmek4NXFcLFi3eVAlu6YebZS00+zaM7yiTeiwMD7sU=; b=AFDZFGNShqUJP46zjhyfRwxyKuLiM1so1WfZmynj1e2fJO6nI9js0aNxZAiSt/q1dCIsQeZQpCRoy83ww3YCsjeBqIbM/9EUjDY5OVcVAkPHyXs9yJhnHXvTW2pXhaR9JGXxts3T+WFdWiHVW6BnZKaN9lu+tXgmIYdcCzNoQME= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.gG9Vi2L_1769434534 cluster:ay29) by smtp.aliyun-inc.com; Mon, 26 Jan 2026 21:35:34 +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" , Ard Biesheuvel , Brian Gerst , Uros Bizjak Subject: [RFC PATCH 2/5] x86/relocs: Insert relocations into input file Date: Mon, 26 Jan 2026 21:33:52 +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 a command line option to insert relocations into a reserved section named ".data.reloc" section of the input file. This allows for relocation of the uncompressed kernel and is same as the implementation in MIPS. Signed-off-by: Hou Wenlong --- arch/x86/tools/relocs.c | 56 ++++++++++++++++++++++++++++++---- arch/x86/tools/relocs.h | 1 + arch/x86/tools/relocs_common.c | 13 ++++++-- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 945d78c368f7..4d0f2bd6c35e 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -735,6 +735,17 @@ static void walk_relocs(int (*process)(struct section = *sec, Elf_Rel *rel, } } =20 +static struct section *sec_lookup(const char *name) +{ + int i; + + for (i =3D 0; i < shnum; i++) + if (!strcmp(sec_name(i), name)) + return &secs[i]; + + return NULL; +} + #if ELF_BITS =3D=3D 64 =20 static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, @@ -950,7 +961,7 @@ static int write32_as_text(uint32_t v, FILE *f) return fprintf(f, "\t.long 0x%08"PRIx32"\n", v) > 0 ? 0 : -1; } =20 -static void emit_relocs(void) +static void emit_relocs(FILE *f) { int i; int (*write_reloc)(uint32_t, FILE *) =3D write32; @@ -1001,21 +1012,54 @@ static void emit_relocs(void) for (i =3D 0; i < relocs32.count; i++) write_reloc(relocs32.offset[i], stdout); } else { + FILE *outf =3D stdout; + + if (keep_relocs) { + struct section *sec_reloc; + uint32_t size_needed; + unsigned long offset; + + sec_reloc =3D sec_lookup(".data.reloc"); + if (!sec_reloc) + die("Could not find relocation data section\n"); + + size_needed =3D (1 + relocs32.count) * sizeof(uint32_t); +#if ELF_BITS =3D=3D 64 + size_needed +=3D (1 + relocs64.count) * sizeof(uint32_t); +#endif + if (size_needed > sec_reloc->shdr.sh_size) + die("Relocations overflow available space!\n" \ + "Please adjust CONFIG_RELOCATION_TABLE_SIZE " \ + "to at least 0x%08x\n", (size_needed + 0x1000) & ~0xFFF); + + /* + * Place the relocations at the end of section to ensure + * compatibility with backward traversal during handling + * relocations. + */ + offset =3D sec_reloc->shdr.sh_offset + sec_reloc->shdr.sh_size - + size_needed; + if (fseek(f, offset, SEEK_SET) < 0) + die("Seek to %ld failed: %s\n", offset, strerror(errno)); + + outf =3D f; + } + #if ELF_BITS =3D=3D 64 /* Print a stop */ - write_reloc(0, stdout); + write_reloc(0, outf); =20 /* Now print each relocation */ for (i =3D 0; i < relocs64.count; i++) - write_reloc(relocs64.offset[i], stdout); + write_reloc(relocs64.offset[i], outf); #endif =20 /* Print a stop */ - write_reloc(0, stdout); + write_reloc(0, outf); =20 /* Now print each relocation */ for (i =3D 0; i < relocs32.count; i++) - write_reloc(relocs32.offset[i], stdout); + write_reloc(relocs32.offset[i], outf); } } =20 @@ -1073,5 +1117,5 @@ void process(FILE *fp) return; } =20 - emit_relocs(); + emit_relocs(fp); } diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h index 5ade07ac2754..05a6e80e815a 100644 --- a/arch/x86/tools/relocs.h +++ b/arch/x86/tools/relocs.h @@ -35,6 +35,7 @@ extern int show_absolute_relocs; extern int show_reloc_info; extern int as_text; extern int use_real_mode; +extern int keep_relocs; =20 void process_32(FILE *fp); void process_64(FILE *fp); diff --git a/arch/x86/tools/relocs_common.c b/arch/x86/tools/relocs_common.c index ee8a9fafcb11..66a9a83b7395 100644 --- a/arch/x86/tools/relocs_common.c +++ b/arch/x86/tools/relocs_common.c @@ -2,7 +2,7 @@ #include "relocs.h" =20 int show_absolute_syms, show_absolute_relocs, show_reloc_info; -int as_text, use_real_mode; +int as_text, use_real_mode, keep_relocs; =20 void die(char *fmt, ...) { @@ -15,7 +15,7 @@ void die(char *fmt, ...) =20 static void usage(void) { - die("relocs [--abs-syms|--abs-relocs|--reloc-info|--text|--realmode]" \ + die("relocs [--abs-syms|--abs-relocs|--reloc-info|--text|--realmode|--kee= p]" \ " vmlinux\n"); } =20 @@ -55,6 +55,10 @@ int main(int argc, char **argv) use_real_mode =3D 1; continue; } + if (strcmp(arg, "--keep") =3D=3D 0) { + keep_relocs =3D 1; + continue; + } } else if (!fname) { fname =3D arg; @@ -65,7 +69,10 @@ int main(int argc, char **argv) if (!fname) { usage(); } - fp =3D fopen(fname, "r"); + if (keep_relocs) + fp =3D fopen(fname, "r+"); + else + fp =3D fopen(fname, "r"); if (!fp) { die("Cannot open %s: %s\n", fname, strerror(errno)); } --=20 2.31.1 From nobody Sat Feb 7 12:19:43 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 From nobody Sat Feb 7 12:19:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=antgroup.com ARC-Seal: i=1; a=rsa-sha256; t=1769434587; cv=none; d=zohomail.com; s=zohoarc; b=h1+8mv4yTrDruFjeSs3cd6bOtqWR3MkN0MJppAMn+s2DZa3uTmHcuOXullEgFQE7pwFjHgW2Kg75VqqrdWwWQOM/H1bx/A3km3x1vpaiUfAA5NeBZulINOHDeRHoNYcl+Z2mlCg4PM4UOmYgO3mm31F9x5Pll6I7wgprQWAuSp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769434587; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VyKxMTwvBHUzyW1uTW736L2GPVuIiSygzDpiTrPhWW8=; b=H1roWBvy5x5zgVS3ZG61zf8sLaePTbt9qtur/q/bHZBpSOCtbnhs09yEFPq7sR3XAwUG8gx6IfAGzs4nN3cmIabKy/uZS+xE07Uk3XOOFudKlFlcn55bi8owEvLSncYMxIpPIGqIm3LbmNxgTYCpg9InK3k81Y8EL9wspyhuwzM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1769434587509279.1738565953484; Mon, 26 Jan 2026 05:36:27 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1213720.1524193 (Exim 4.92) (envelope-from ) id 1vkMlK-0003iB-4C; Mon, 26 Jan 2026 13:36:14 +0000 Received: by outflank-mailman (output) from mailman id 1213720.1524193; Mon, 26 Jan 2026 13:36:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vkMlK-0003i4-1A; Mon, 26 Jan 2026 13:36:14 +0000 Received: by outflank-mailman (input) for mailman id 1213720; Mon, 26 Jan 2026 13:36:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vkMlI-0003VU-GW for xen-devel@lists.xenproject.org; Mon, 26 Jan 2026 13:36:12 +0000 Received: from out28-52.mail.aliyun.com (out28-52.mail.aliyun.com [115.124.28.52]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f6e9401c-fabb-11f0-9ccf-f158ae23cfc8; Mon, 26 Jan 2026 14:36:08 +0100 (CET) Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.gGID1nH_1769434562 cluster:ay29) by smtp.aliyun-inc.com; Mon, 26 Jan 2026 21:36:03 +0800 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f6e9401c-fabb-11f0-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1769434565; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=VyKxMTwvBHUzyW1uTW736L2GPVuIiSygzDpiTrPhWW8=; b=Iwk6WT3ax7dZYFr2LpsKXdh+MDYo1dBQLcy/P/FOeFykpsga67y6uySmOjRlnTDyxmC5lxmjJSk/2Od51rVv7fUPF2giChSQbtzJt+N+5JIjJ2zPy9rZ7s6aD0D94AWHj38LoqVTvtjXuabu+x5A7SK1gnAnPP6TJdlH2ci3P0c= 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" , Juergen Gross , Boris Ostrovsky , Ard Biesheuvel , Josh Poimboeuf , Nathan Chancellor , Andrew Morton , Alexander Graf , Joel Granados , Thomas Huth , Uros Bizjak , Brian Gerst , Kiryl Shutsemau , "Xin Li (Intel)" , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , xen-devel@lists.xenproject.org Subject: [RFC PATCH 4/5] x86/boot: Perform virtual address relocation in kernel entry Date: Mon, 26 Jan 2026 21:33:54 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @antgroup.com) X-ZM-MESSAGEID: 1769434589790158500 Content-Type: text/plain; charset="utf-8" Perform virtual address relocation for the uncompressed kernel during booting, which is similar to the relocation during decompression. Signed-off-by: Hou Wenlong --- arch/x86/boot/startup/Makefile | 1 + arch/x86/boot/startup/kaslr.c | 116 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/setup.h | 1 + arch/x86/kernel/head_64.S | 7 ++ arch/x86/lib/cmdline.c | 6 ++ arch/x86/lib/kaslr.c | 5 ++ arch/x86/platform/pvh/head.S | 15 ++++- 7 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 arch/x86/boot/startup/kaslr.c diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile index 5e499cfb29b5..eeaefa4e25fb 100644 --- a/arch/x86/boot/startup/Makefile +++ b/arch/x86/boot/startup/Makefile @@ -20,6 +20,7 @@ KCOV_INSTRUMENT :=3D n =20 obj-$(CONFIG_X86_64) +=3D gdt_idt.o map_kernel.o obj-$(CONFIG_AMD_MEM_ENCRYPT) +=3D sme.o sev-startup.o +obj-$(CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL) +=3D kaslr.o pi-objs :=3D $(patsubst %.o,$(obj)/%.o,$(obj-y)) =20 lib-$(CONFIG_X86_64) +=3D la57toggle.o diff --git a/arch/x86/boot/startup/kaslr.c b/arch/x86/boot/startup/kaslr.c new file mode 100644 index 000000000000..fb07c31e21b3 --- /dev/null +++ b/arch/x86/boot/startup/kaslr.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +/* A hack to avoid non-static declaration for kaslr_get_random_long(). */ +#define _ASM_KASLR_H_ +#include +#include +#include + +extern char __relocation_end[]; + +static struct boot_params *boot_params_ptr __initdata; + +static inline void debug_putstr(const char *str) +{ +} + +static inline bool has_cpuflag(int flag) +{ + u32 reg =3D 0; + u32 level =3D native_cpuid_eax(0x0); + + if (level >=3D 0x00000001) { + if (flag =3D=3D X86_FEATURE_RDRAND) + reg =3D native_cpuid_edx(0x1); + else if (flag =3D=3D X86_FEATURE_TSC) + reg =3D native_cpuid_ecx(0x1); + } + + return test_bit(flag & 31, (unsigned long *)®); +} + +static unsigned long __init rotate_xor(unsigned long hash, const void *are= a, + size_t size) +{ + size_t i; + unsigned long *ptr =3D (unsigned long *)area; + + for (i =3D 0; i < size / sizeof(hash); i++) { + /* Rotate by odd number of bits and XOR. */ + hash =3D (hash << ((sizeof(hash) * 8) - 7)) | (hash >> 7); + hash ^=3D ptr[i]; + } + + return hash; +} + +/* Attempt to create a simple but unpredictable starting entropy. */ +static unsigned long get_boot_seed(void) +{ + unsigned long hash =3D 0; + + hash =3D rotate_xor(hash, boot_params_ptr, sizeof(*boot_params_ptr)); + + return hash; +} + +#define KASLR_COMPRESSED_BOOT +#define KASLR_FUNC_PREFIX static __init +#include "../../lib/kaslr.c" + +/* A hack to avoid non-static declaration for cmdline_find_option_bool(). = */ +#define _ASM_X86_CMDLINE_H +#undef CONFIG_CMDLINE_BOOL +#define builtin_cmdline NULL +#define CMDLINE_FUNC_PREFIX static __maybe_unused __init +#include "../../lib/cmdline.c" + +static unsigned long __init find_random_virt_addr(unsigned long minimum, + unsigned long image_size) +{ + unsigned long slots, random_addr; + + /* + * There are how many CONFIG_PHYSICAL_ALIGN-sized slots + * that can hold image_size within the range of minimum to + * KERNEL_IMAGE_SIZE? + */ + slots =3D 1 + (KERNEL_IMAGE_SIZE - minimum - image_size) / CONFIG_PHYSICA= L_ALIGN; + + random_addr =3D kaslr_get_random_long("Virtual") % slots; + + return random_addr * CONFIG_PHYSICAL_ALIGN + minimum; +} + +void __init __relocate_kernel(unsigned long p2v_offset, struct boot_params= *bp) +{ + int *reloc =3D (int *)rip_rel_ptr(__relocation_end); + unsigned long image_size =3D rip_rel_ptr(_end) - rip_rel_ptr(_text); + unsigned long ptr, virt_addr, delta; + unsigned long cmd_line_ptr; + + /* If relocation has occurred during decompression, simply skip it. */ + if (bp->hdr.loadflags & KASLR_FLAG) + return; + + cmd_line_ptr =3D bp->hdr.cmd_line_ptr | ((u64)bp->ext_cmd_line_ptr << 32); + if (cmdline_find_option_bool((char *)cmd_line_ptr, "nokaslr")) + return; + + boot_params_ptr =3D bp; + virt_addr =3D find_random_virt_addr(LOAD_PHYSICAL_ADDR, image_size); + delta =3D virt_addr - LOAD_PHYSICAL_ADDR; + + for (reloc--; *reloc; reloc--) { + ptr =3D (unsigned long)(*reloc + p2v_offset); + *(uint32_t *)ptr +=3D delta; + } + + for (reloc--; *reloc; reloc--) { + ptr =3D (unsigned long)(*reloc + p2v_offset); + *(uint64_t *)ptr +=3D delta; + } +} diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h index 914eb32581c7..86a715a255a5 100644 --- a/arch/x86/include/asm/setup.h +++ b/arch/x86/include/asm/setup.h @@ -56,6 +56,7 @@ extern void startup_64_load_idt(void *vc_handler); extern void __pi_startup_64_load_idt(void *vc_handler); extern void early_setup_idt(void); extern void __init do_early_exception(struct pt_regs *regs, int trapnr); +extern void __init __relocate_kernel(unsigned long p2v_offset, struct boot= _params *bp); =20 #ifdef CONFIG_X86_INTEL_MID extern void x86_intel_mid_early_setup(void); diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 21816b48537c..868d8fdd59df 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -97,6 +97,13 @@ SYM_CODE_START_NOALIGN(startup_64) /* Sanitize CPU configuration */ call verify_cpu =20 +#ifdef CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL + leaq common_startup_64(%rip), %rdi + subq .Lcommon_startup_64(%rip), %rdi + movq %r15, %rsi + call __pi___relocate_kernel +#endif + /* * Derive the kernel's physical-to-virtual offset from the physical and * virtual addresses of common_startup_64(). diff --git a/arch/x86/lib/cmdline.c b/arch/x86/lib/cmdline.c index c65cd5550454..07c4398b9e67 100644 --- a/arch/x86/lib/cmdline.c +++ b/arch/x86/lib/cmdline.c @@ -11,6 +11,10 @@ #include #include =20 +#ifndef CMDLINE_FUNC_PREFIX +#define CMDLINE_FUNC_PREFIX +#endif + static inline int myisspace(u8 c) { return c <=3D ' '; /* Close enough approximation */ @@ -205,6 +209,7 @@ __cmdline_find_option(const char *cmdline, int max_cmdl= ine_size, return len; } =20 +CMDLINE_FUNC_PREFIX int cmdline_find_option_bool(const char *cmdline, const char *option) { int ret; @@ -219,6 +224,7 @@ int cmdline_find_option_bool(const char *cmdline, const= char *option) return ret; } =20 +CMDLINE_FUNC_PREFIX int cmdline_find_option(const char *cmdline, const char *option, char *buf= fer, int bufsize) { diff --git a/arch/x86/lib/kaslr.c b/arch/x86/lib/kaslr.c index 8c7cd115b484..711a19729e20 100644 --- a/arch/x86/lib/kaslr.c +++ b/arch/x86/lib/kaslr.c @@ -13,6 +13,10 @@ #include #include =20 +#ifndef KASLR_FUNC_PREFIX +#define KASLR_FUNC_PREFIX +#endif + /* * When built for the regular kernel, several functions need to be stubbed= out * or changed to their regular kernel equivalent. @@ -46,6 +50,7 @@ static inline u16 i8254(void) return timer; } =20 +KASLR_FUNC_PREFIX unsigned long kaslr_get_random_long(const char *purpose) { #ifdef CONFIG_X86_64 diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 344030c1a81d..94832930b0a2 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -103,6 +103,17 @@ SYM_CODE_START(pvh_start_xen) btsl $_EFER_LME, %eax wrmsr =20 + /* + * Fill the identity mapping entries instead of preconstructing them, + * as later relocations in __relocation_kernel() would modify them and + * break the mapping if they are prefilled, due to the generation of + * relocation entries. + */ + leal rva(pvh_init_top_pgt)(%ebp), %edi + addl $(pvh_level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC), = (%edi) + leal rva(pvh_level3_ident_pgt)(%ebp), %edi + addl $(pvh_level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC), = (%edi) + /* * Reuse the non-relocatable symbol emitted for the ELF note to * subtract the build time physical address of pvh_start_xen() from @@ -254,7 +265,6 @@ SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stac= k_end) * startup_64 transitions to init_top_pgt. */ SYM_DATA_START_PAGE_ALIGNED(pvh_init_top_pgt) - .quad pvh_level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .org pvh_init_top_pgt + L4_PAGE_OFFSET * 8, 0 .quad pvh_level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC .org pvh_init_top_pgt + L4_START_KERNEL * 8, 0 @@ -263,8 +273,7 @@ SYM_DATA_START_PAGE_ALIGNED(pvh_init_top_pgt) SYM_DATA_END(pvh_init_top_pgt) =20 SYM_DATA_START_PAGE_ALIGNED(pvh_level3_ident_pgt) - .quad pvh_level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE_NOENC - .fill 511, 8, 0 + .fill 512, 8, 0 SYM_DATA_END(pvh_level3_ident_pgt) SYM_DATA_START_PAGE_ALIGNED(pvh_level2_ident_pgt) /* --=20 2.31.1 From nobody Sat Feb 7 12:19:43 2026 Received: from out28-97.mail.aliyun.com (out28-97.mail.aliyun.com [115.124.28.97]) (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 43EFF33ADB2 for ; Mon, 26 Jan 2026 13:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434581; cv=none; b=BAGCquD0i7mjB/f6RNuFM6cMGlSUF7mywm2KxuSDcAVMdFum1LSYsvygq0TA2syJlIsD527EcNRrtNhWqMPE2pNvNTu5YGdOapZ0BUVae7Snf7pYj3Zfmwvq8ZLR3VAWeIMH2iV6KdTPJ9gHD5tEezEbeLC9blkh9JzqWB0UYxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769434581; c=relaxed/simple; bh=eitQmKmktSPddAH9FvI4GgY8d+k4Pzcc/yLI7Jl1LWY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JPwowZkST7rubVMM6nj5Yxvj+XeVy3aTC+4cp0OPhVNYePKsfGCkUzXl70rL9WvEGORqKZBhf1eIAlg1IPsflfVu3uOwaFmnoWi85U9OsTlGrAytAAT0JBcXqfFVk9Ea/dGYZHhOL9fATZjjJ+NzXSAE8hMR7sEhGvc3MVX058c= 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=dNYdgYKx; arc=none smtp.client-ip=115.124.28.97 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="dNYdgYKx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1769434570; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=shvguEnBCnFDBN82Kkm3tKbFDhvQGxkda3Bv+csdOx0=; b=dNYdgYKxr1tKHVhn1lLEdocnTa6K5VfxFC/23mdn1Pei1RrFBm8jPnCHlGby9yybO3h2n7XkduDozKYtpuUxFrOcmsipQX73pyKWWemRckZ+ffUTgk+oxZTrNZibm6mrMj97u27EvCtMCKFGUWSt0E/6TJAub5OasXKlsDyMGXM= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.gGBjWoK_1769434569 cluster:ay29) by smtp.aliyun-inc.com; Mon, 26 Jan 2026 21:36:09 +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" , Ard Biesheuvel , Nathan Chancellor , Masahiro Yamada , Vitaly Kuznetsov , =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= , Brian Gerst Subject: [RFC PATCH 5/5] x86/boot: Use '.data.relocs' section for performing relocations during decompression Date: Mon, 26 Jan 2026 21:33:55 +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" When CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL is enabled, all the relocations are already in the '.data.relocs' section of the kernel binary, so there is no need to generate 'vmlinux.relocs' again. Use it directly for performing relocations during decompression. Signed-off-by: Hou Wenlong --- arch/x86/boot/compressed/Makefile | 6 ++++-- arch/x86/boot/compressed/misc.c | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index 68f9d7a1683b..ca629a9b9bce 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -12,7 +12,7 @@ # vmlinux.bin is: # vmlinux stripped of debugging and comments # vmlinux.bin.all is: -# vmlinux.bin + vmlinux.relocs +# vmlinux.bin + vmlinux.relocs (CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL=3Dn) # vmlinux.bin.(gz|bz2|lzma|...) is: # (see scripts/Makefile.lib size_append) # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all @@ -76,7 +76,7 @@ LDFLAGS_vmlinux +=3D -T hostprogs :=3D mkpiggy HOST_EXTRACFLAGS +=3D -I$(srctree)/tools/include =20 -sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|_sinittext\|__inittext_end\|__bss_start\|_end\)$$/\#define VO_\2 _AC= (0x\1,UL)/p' +sed-voffset :=3D -e 's/^\([0-9a-fA-F]*\) [ABbCDGRSTtVW] \(_text\|__start_r= odata\|_sinittext\|__inittext_end\|__bss_start\|_end\|__relocation_end\)$$/= \#define VO_\2 _AC(0x\1,UL)/p' =20 quiet_cmd_voffset =3D VOFFSET $@ cmd_voffset =3D $(NM) $< | sed -n $(sed-voffset) > $@ @@ -132,7 +132,9 @@ $(obj)/vmlinux.relocs: vmlinux.unstripped FORCE $(call if_changed,relocs) =20 vmlinux.bin.all-y :=3D $(obj)/vmlinux.bin +ifndef CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL vmlinux.bin.all-$(CONFIG_X86_NEED_RELOCS) +=3D $(obj)/vmlinux.relocs +endif =20 $(obj)/vmlinux.bin.gz: $(vmlinux.bin.all-y) FORCE $(call if_changed,gzip) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index 0f41ca0e52c0..d0f4e8302276 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -232,6 +232,14 @@ static void handle_relocations(void *output, unsigned = long output_len, } debug_putstr("Performing relocations... "); =20 +#ifdef CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL + /* + * If CONFIG_RELOCATABLE_UNCOMPRESSED_KERNEL is enabled, the relocations = is in + * '.data.reloc' section of kernel binary. + */ + output_len =3D VO___relocation_end - VO__text; +#endif + /* * Process relocations: 32 bit relocations first then 64 bit after. * Two sets of binary relocations are added to the end of the kernel --=20 2.31.1