linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86-64: Force linker to use 2MB page size
@ 2018-03-19 20:57 H.J. Lu
  2018-03-20 11:03 ` [tip:x86/pti] x86/build/64: Force the " tip-bot for H.J. Lu
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2018-03-19 20:57 UTC (permalink / raw)
  To: LKML, the arch/x86 maintainers

[-- Attachment #1: Type: text/plain, Size: 513 bytes --]

Binutils 2.31 will enable -z separate-code by default for x86 to avoid
mixing code pages with data to improve cache performance as well as
security.  To reduce x86-64 executable and shared object sizes, the
maximum page size is reduced from 2MB to 4KB.  But x86-64 kernel must
be aligned to 2MB.  Pass -z max-page-size=0x200000 to linker to force
2MB page size regardless of the default page size used by linker.

Tested with Linux kernel 4.15.6 on x86-64.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

-- 
H.J.

[-- Attachment #2: 0001-x86-64-Force-linker-to-use-2MB-page-size.patch --]
[-- Type: text/x-patch, Size: 1510 bytes --]

From c5c27b82d2e19add5372a6b2eaa00119e896d9ff Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 16 Feb 2018 14:07:38 -0800
Subject: [PATCH] x86-64: Force linker to use 2MB page size

Binutils 2.31 will enable -z separate-code by default for x86 to avoid
mixing code pages with data to improve cache performance as well as
security.  To reduce x86-64 executable and shared object sizes, the
maximum page size is reduced from 2MB to 4KB.  But x86-64 kernel must
be aligned to 2MB.  Pass -z max-page-size=0x200000 to linker to force
2MB page size regardless of the default page size used by linker.

Tested with Linux kernel 4.15.6 on x86-64.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 arch/x86/Makefile | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 68f4963501ae..dc2419883c97 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -229,6 +229,12 @@ KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr)
 KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
 
 LDFLAGS := -m elf_$(UTS_MACHINE)
+ifdef CONFIG_X86_64
+# X86-64 kernel must be aligned to 2MB.  Pass -z max-page-size=0x200000 to
+# linker to force 2MB page size regardless of the default page size used
+# by linker.
+LDFLAGS += $(call ld-option, -z max-page-size=0x200000)
+endif
 
 # Speed up the build
 KBUILD_CFLAGS += -pipe
-- 
2.14.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-20 11:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-19 20:57 [PATCH] x86-64: Force linker to use 2MB page size H.J. Lu
2018-03-20 11:03 ` [tip:x86/pti] x86/build/64: Force the " tip-bot for H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).