linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Andi Kleen <ak@linux.intel.com>,
	"Van De Ven, Arjan" <arjan.van.de.ven@intel.com>
Cc: Paul Turner <pjt@google.com>, LKML <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linux-foundation.org>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Dave Hansen <dave.hansen@intel.com>,
	tglx@linutronix.de, Kees Cook <keescook@google.com>,
	Rik van Riel <riel@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Jiri Kosina <jikos@kernel.org>,
	gnomes@lxorguk.ukuu.org.uk
Subject: [RFC PATCH 13/12] Retpoline vs. CONFIG_TRIM_UNUSED_SYMBOLS
Date: Sun, 07 Jan 2018 00:10:24 +0000	[thread overview]
Message-ID: <1515283824.29312.288.camel@infradead.org> (raw)
In-Reply-To: <1515239374-23361-1-git-send-email-dwmw@amazon.co.uk>

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

Arjan pointed out that CONFIG_TRIM_UNUSED_SYMBOLS *really* doesn't like
the dot in the symbols that GCC uses for the thunks.

This seems to work, although my eyes are bleeding just a little bit.

Given this, and the hack we already needed for MODVERSIONS, I wonder if
a better approach might be to export the thunks using underscores in
place of the dots, which is a relatively simple abuse of
__EXPORT_SYMBOL(__x86_indirect_thunk_foo,__x86.indirect_thunk.foo,),
and then have a hack either when generating or loading modules to do
the same replacement.

diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index ccb117a4588b..64d7a45ea954 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -8,7 +8,13 @@
 #include <asm/export.h>
 #include <asm/nospec-branch.h>
 
-.macro THUNK reg
+#ifdef CONFIG_TRIM_UNUSED_KSYMS
+#define EXPORT_REG(reg) __is_defined(__KSYM___x86_indirect_thunk_ ## reg)
+#else
+#define EXPORT_REG(reg)	1
+#endif
+
+.macro THUNK reg export
 	.section .text.__x86.indirect_thunk.\reg
 
 ENTRY(__x86.indirect_thunk.\reg)
@@ -16,15 +22,33 @@ ENTRY(__x86.indirect_thunk.\reg)
 	NOSPEC_JMP %\reg
 	CFI_ENDPROC
 ENDPROC(__x86.indirect_thunk.\reg)
-EXPORT_SYMBOL(__x86.indirect_thunk.\reg)
+
+.if \export
+	EXPORT_SYMBOL_FORCE(__x86.indirect_thunk.\reg)
+.endif
 .endm
 
-#ifdef CONFIG_64BIT
-.irp reg rax rbx rcx rdx rsi rdi rbp r8 r9 r10 r11 r12 r13 r14 r15
-	THUNK \reg
-.endr
+#ifdef __KSYM_DEPS__
+#define GENERATE_THUNK(reg) EXPORT_SYMBOL(__x86.indirect_thunk. ## reg)
 #else
-.irp reg eax ebx ecx edx esi edi ebp
-	THUNK \reg
-.endr
+#define GENERATE_THUNK(reg) THUNK reg EXPORT_REG(reg)
+#endif
+
+GENERATE_THUNK(_ASM_AX)
+GENERATE_THUNK(_ASM_BX)
+GENERATE_THUNK(_ASM_CX)
+GENERATE_THUNK(_ASM_DX)
+GENERATE_THUNK(_ASM_SI)
+GENERATE_THUNK(_ASM_DI)
+GENERATE_THUNK(_ASM_BP)
+GENERATE_THUNK(_ASM_SP)
+#ifdef CONFIG_64BIT
+GENERATE_THUNK(r8)
+GENERATE_THUNK(r9)
+GENERATE_THUNK(r10)
+GENERATE_THUNK(r11)
+GENERATE_THUNK(r12)
+GENERATE_THUNK(r13)
+GENERATE_THUNK(r14)
+GENERATE_THUNK(r15)
 #endif
diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index 719db1968d81..b13bb65e2530 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -63,33 +63,33 @@ KSYM(__kcrctab_\name):
 
 #if defined(__KSYM_DEPS__)
 
-#define __EXPORT_SYMBOL(sym, val, sec)	=== __KSYM_##sym ===
+#define __EXPORT_SYMBOL(sym, val, sec, force)	=== __KSYM_##sym ===
 
 #elif defined(CONFIG_TRIM_UNUSED_KSYMS)
 
 #include <linux/kconfig.h>
 #include <generated/autoksyms.h>
 
-#define __EXPORT_SYMBOL(sym, val, sec)				\
-	__cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym))
+#define __EXPORT_SYMBOL(sym, val, sec, force)			\
+	 __cond_export_sym(sym, val, sec, __or(force, __is_defined(__KSYM_##sym)))
 #define __cond_export_sym(sym, val, sec, conf)			\
 	___cond_export_sym(sym, val, sec, conf)
 #define ___cond_export_sym(sym, val, sec, enabled)		\
 	__cond_export_sym_##enabled(sym, val, sec)
 #define __cond_export_sym_1(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
 #define __cond_export_sym_0(sym, val, sec) /* nothing */
-
 #else
-#define __EXPORT_SYMBOL(sym, val, sec) ___EXPORT_SYMBOL sym, val, sec
+#define __EXPORT_SYMBOL(sym, val, sec, force)	___EXPORT_SYMBOL sym, val, sec
 #endif
 
 #define EXPORT_SYMBOL(name)					\
-	__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)),)
+	__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)), , 0)
 #define EXPORT_SYMBOL_GPL(name) 				\
-	__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)), _gpl)
+	__EXPORT_SYMBOL(name, KSYM_FUNC(KSYM(name)), _gpl, 0)
 #define EXPORT_DATA_SYMBOL(name)				\
-	__EXPORT_SYMBOL(name, KSYM(name),)
+	__EXPORT_SYMBOL(name, KSYM(name), , 0)
 #define EXPORT_DATA_SYMBOL_GPL(name)				\
-	__EXPORT_SYMBOL(name, KSYM(name),_gpl)
-
+	__EXPORT_SYMBOL(name, KSYM(name), _gpl, 0)
+#define EXPORT_SYMBOL_FORCE(name)				\
+	__EXPORT_SYMBOL(name, KSYM(name), , 1)
 #endif
diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh
index 513da1a4a2da..991cd136291b 100755
--- a/scripts/adjust_autoksyms.sh
+++ b/scripts/adjust_autoksyms.sh
@@ -60,7 +60,7 @@ cat > "$new_ksyms_file" << EOT
 
 EOT
 [ "$(ls -A "$MODVERDIR")" ] &&
-sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u |
+sed -ns -e '3{s/ /\n/g;/^$/!p;}' "$MODVERDIR"/*.mod | sort -u | tr . _ |
 while read sym; do
 	if [ -n "$CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX" ]; then
 		sym="${sym#_}"

[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5213 bytes --]

  parent reply	other threads:[~2018-01-07  0:10 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-06 11:49 [PATCH v5 00/12] Retpoline: Avoid speculative indirect calls in kernel David Woodhouse
2018-01-06 11:49 ` [PATCH v5 01/12] x86/spectre: Add X86_BUG_SPECTRE_V[12] David Woodhouse
2018-01-06 21:05   ` [tip:x86/pti] x86/cpufeatures: " tip-bot for David Woodhouse
2018-01-06 11:49 ` [PATCH v5 02/12] x86/retpoline: Add initial retpoline support David Woodhouse
2018-01-06 17:32   ` David Woodhouse
2018-01-06 18:05   ` [PATCH v5.1 " David Woodhouse
2018-01-06 18:35   ` [PATCH v5 " Eric Biggers
2018-01-06 19:17     ` David Woodhouse
2018-01-06 21:16   ` Andrew Cooper
2018-01-06 21:21     ` Woodhouse, David
2018-01-07  1:44       ` Tom Lendacky
2018-01-06 21:23     ` Thomas Gleixner
2018-01-06 21:34       ` Andrew Cooper
2018-01-06 21:49         ` Woodhouse, David
2018-01-06 11:49 ` [PATCH v5 03/12] x86/retpoline/crypto: Convert crypto assembler indirect jumps David Woodhouse
2018-01-06 11:49 ` [PATCH v5 04/12] x86/retpoline/entry: Convert entry " David Woodhouse
2018-01-06 11:49 ` [PATCH v5 05/12] x86/retpoline/ftrace: Convert ftrace " David Woodhouse
2018-01-06 18:13   ` Linus Torvalds
2018-01-06 19:53     ` Thomas Gleixner
2018-01-07  1:27       ` Linus Torvalds
2018-01-06 11:49 ` [PATCH v5 06/12] x86/retpoline/hyperv: Convert " David Woodhouse
2018-01-06 11:49 ` [PATCH v5 07/12] x86/retpoline/xen: Convert Xen hypercall " David Woodhouse
2018-01-06 11:49 ` [PATCH v5 08/12] x86/retpoline/checksum32: Convert assembler " David Woodhouse
2018-01-06 11:49 ` [PATCH v5 09/12] x86/retpoline/irq32: " David Woodhouse
2018-01-06 11:49 ` [PATCH v5 10/12] x86/retpoline: Add boot time option to disable retpoline David Woodhouse
2018-01-06 11:49 ` [PATCH v5 11/12] x86/retpoline: Exclude objtool with retpoline David Woodhouse
2018-01-06 11:49 ` [PATCH v5 12/12] retpoline/modpost: Quieten MODVERSION retpoline build David Woodhouse
2018-01-07  0:10 ` David Woodhouse [this message]
2018-01-07  8:03   ` [RFC PATCH 13/12] Retpoline vs. CONFIG_TRIM_UNUSED_SYMBOLS David Woodhouse
2018-01-07 15:09     ` Lu, Hongjiu
2018-01-07 17:32       ` David Woodhouse
2018-01-07 17:57         ` Lu, Hongjiu
2018-01-07 18:18           ` Thomas Gleixner
2018-01-07 18:32             ` Lu, Hongjiu
2018-01-07 20:57               ` David Woodhouse
2018-01-07 22:16               ` David Woodhouse

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=1515283824.29312.288.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=arjan.van.de.ven@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linux-foundation.org \
    --cc=jikos@kernel.org \
    --cc=keescook@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.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).