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

* [tip:x86/pti] x86/build/64: Force the linker to use 2MB page size
  2018-03-19 20:57 [PATCH] x86-64: Force linker to use 2MB page size H.J. Lu
@ 2018-03-20 11:03 ` tip-bot for H.J. Lu
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for H.J. Lu @ 2018-03-20 11:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jgross, mingo, kirill.shutemov, tglx, torvalds, andy.shevchenko,
	ebiederm, keescook, hpa, linux-kernel, hjl.tools, peterz

Commit-ID:  e3d03598e8ae7d195af5d3d049596dec336f569f
Gitweb:     https://git.kernel.org/tip/e3d03598e8ae7d195af5d3d049596dec336f569f
Author:     H.J. Lu <hjl.tools@gmail.com>
AuthorDate: Mon, 19 Mar 2018 13:57:46 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 20 Mar 2018 08:03:03 +0100

x86/build/64: Force the 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>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/CAMe9rOp4_%3D_8twdpTyAP2DhONOCeaTOsniJLoppzhoNptL8xzA@mail.gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 498c1b812300..1c4d012550ec 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -223,6 +223,15 @@ KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr)
 
 LDFLAGS := -m elf_$(UTS_MACHINE)
 
+#
+# The 64-bit kernel must be aligned to 2MB.  Pass -z max-page-size=0x200000 to
+# the linker to force 2MB page size regardless of the default page size used
+# by the linker.
+#
+ifdef CONFIG_X86_64
+LDFLAGS += $(call ld-option, -z max-page-size=0x200000)
+endif
+
 # Speed up the build
 KBUILD_CFLAGS += -pipe
 # Workaround for a gcc prelease that unfortunately was shipped in a suse release

^ 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).