linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>,
	"the arch/x86 maintainers" <x86@kernel.org>
Subject: [PATCH] x86-64: Force linker to use 2MB page size
Date: Mon, 19 Mar 2018 13:57:46 -0700	[thread overview]
Message-ID: <CAMe9rOp4_=_8twdpTyAP2DhONOCeaTOsniJLoppzhoNptL8xzA@mail.gmail.com> (raw)

[-- 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


             reply	other threads:[~2018-03-19 20:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-19 20:57 H.J. Lu [this message]
2018-03-20 11:03 ` [tip:x86/pti] x86/build/64: Force the linker to use 2MB page size tip-bot for H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOp4_=_8twdpTyAP2DhONOCeaTOsniJLoppzhoNptL8xzA@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).