All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] add support for relative references in special sections
@ 2017-08-14 10:52 ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

This adds support for emitting special sections such as initcall arrays,
PCI fixups and tracepoints as relative references rather than absolute
references. This reduces the size by 50% on 64-bit architectures, but
more importantly, it removes the need for carrying relocation metadata
for these sections in relocatables kernels (e.g., for KASLR) that need
to fix up these absolute references at boot time. On arm64, this reduces
the vmlinux footprint of such a reference by 8x (8 byte absolute reference
+ 24 byte RELA entry vs 4 byte relative reference)

Patch #2 was sent out before as a single patch. This series supersedes
the previous submission. This version makes relative ksymtab entries
dependent on the new Kconfig symbol HAVE_ARCH_PREL32_RELOCATIONS rather
than trying to infer from kbuild test robot replies for which architectures
it should be blacklisted.

Patch #1 introduces the new Kconfig symbol HAVE_ARCH_PREL32_RELOCATIONS,
and sets it for the main architectures that are expected to benefit most
from this feature, i.e., 64-bit architectures, and ones that use runtime
relocation.

Patches #3 - #5 implement relative references for initcallls, PCI fixups
and tracepoints, respectively, all of which produce sections with order
~1000 entries on an arm64 defconfig kernel with tracing enabled. This
means we save about 28 KB of vmlinux space for each of these patches.

For the arm64 kernel, all patches combined reduce the size of vmlinux
by about 300 KB.

Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nicolas Pitre <nico@linaro.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Jessica Yu <jeyu@kernel.org>

Ard Biesheuvel (5):
  arch: enable relative relocations for arm64, power, x86, s390 and x86
  module: use relative references for __ksymtab entries
  init: allow initcall tables to be emitted using relative references
  drivers: pci: add support for relative addressing in quirk tables
  kernel: tracepoints: add support for relative references

 arch/Kconfig                    | 10 +++++
 arch/arm64/Kconfig              |  1 +
 arch/arm64/kernel/vmlinux.lds.S |  2 +-
 arch/powerpc/Kconfig            |  1 +
 arch/s390/Kconfig               |  1 +
 arch/x86/Kconfig                |  1 +
 arch/x86/include/asm/Kbuild     |  1 +
 arch/x86/include/asm/export.h   |  4 --
 drivers/pci/quirks.c            | 13 ++++--
 include/asm-generic/export.h    | 12 ++++-
 include/linux/compiler.h        | 11 +++++
 include/linux/export.h          | 47 +++++++++++++++-----
 include/linux/init.h            | 44 +++++++++++++-----
 include/linux/pci.h             | 20 +++++++++
 include/linux/tracepoint.h      | 19 ++++++--
 init/main.c                     | 32 ++++++-------
 kernel/module.c                 | 33 +++++++++++---
 kernel/printk/printk.c          |  4 +-
 kernel/tracepoint.c             | 19 +++++---
 security/security.c             |  4 +-
 20 files changed, 212 insertions(+), 67 deletions(-)
 delete mode 100644 arch/x86/include/asm/export.h

-- 
2.11.0

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

* [PATCH 0/5] add support for relative references in special sections
@ 2017-08-14 10:52 ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

This adds support for emitting special sections such as initcall arrays,
PCI fixups and tracepoints as relative references rather than absolute
references. This reduces the size by 50% on 64-bit architectures, but
more importantly, it removes the need for carrying relocation metadata
for these sections in relocatables kernels (e.g., for KASLR) that need
to fix up these absolute references at boot time. On arm64, this reduces
the vmlinux footprint of such a reference by 8x (8 byte absolute reference
+ 24 byte RELA entry vs 4 byte relative reference)

Patch #2 was sent out before as a single patch. This series supersedes
the previous submission. This version makes relative ksymtab entries
dependent on the new Kconfig symbol HAVE_ARCH_PREL32_RELOCATIONS rather
than trying to infer from kbuild test robot replies for which architectures
it should be blacklisted.

Patch #1 introduces the new Kconfig symbol HAVE_ARCH_PREL32_RELOCATIONS,
and sets it for the main architectures that are expected to benefit most
from this feature, i.e., 64-bit architectures, and ones that use runtime
relocation.

Patches #3 - #5 implement relative references for initcallls, PCI fixups
and tracepoints, respectively, all of which produce sections with order
~1000 entries on an arm64 defconfig kernel with tracing enabled. This
means we save about 28 KB of vmlinux space for each of these patches.

For the arm64 kernel, all patches combined reduce the size of vmlinux
by about 300 KB.

Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nicolas Pitre <nico@linaro.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Jessica Yu <jeyu@kernel.org>

Ard Biesheuvel (5):
  arch: enable relative relocations for arm64, power, x86, s390 and x86
  module: use relative references for __ksymtab entries
  init: allow initcall tables to be emitted using relative references
  drivers: pci: add support for relative addressing in quirk tables
  kernel: tracepoints: add support for relative references

 arch/Kconfig                    | 10 +++++
 arch/arm64/Kconfig              |  1 +
 arch/arm64/kernel/vmlinux.lds.S |  2 +-
 arch/powerpc/Kconfig            |  1 +
 arch/s390/Kconfig               |  1 +
 arch/x86/Kconfig                |  1 +
 arch/x86/include/asm/Kbuild     |  1 +
 arch/x86/include/asm/export.h   |  4 --
 drivers/pci/quirks.c            | 13 ++++--
 include/asm-generic/export.h    | 12 ++++-
 include/linux/compiler.h        | 11 +++++
 include/linux/export.h          | 47 +++++++++++++++-----
 include/linux/init.h            | 44 +++++++++++++-----
 include/linux/pci.h             | 20 +++++++++
 include/linux/tracepoint.h      | 19 ++++++--
 init/main.c                     | 32 ++++++-------
 kernel/module.c                 | 33 +++++++++++---
 kernel/printk/printk.c          |  4 +-
 kernel/tracepoint.c             | 19 +++++---
 security/security.c             |  4 +-
 20 files changed, 212 insertions(+), 67 deletions(-)
 delete mode 100644 arch/x86/include/asm/export.h

-- 
2.11.0

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

* [PATCH 1/5] arch: enable relative relocations for arm64, power, x86, s390 and x86
  2017-08-14 10:52 ` Ard Biesheuvel
@ 2017-08-14 10:52   ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu, x86

Before updating certain subsystems to use place relative 32-bit
relocations in special sections, to save space  and reduce the
number of absolute relocations that need to be processed at runtime
by relocatable kernels, introduce a new Kconfig symbol and define it
for some architectures that should be able to support and benefit
from it.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/Kconfig                    | 10 ++++++++++
 arch/arm64/Kconfig              |  1 +
 arch/arm64/kernel/vmlinux.lds.S |  2 +-
 arch/powerpc/Kconfig            |  1 +
 arch/s390/Kconfig               |  1 +
 arch/x86/Kconfig                |  1 +
 6 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 21d0089117fe..4e77d8e8697e 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -940,4 +940,14 @@ config REFCOUNT_FULL
 	  against various use-after-free conditions that can be used in
 	  security flaw exploits.
 
+config HAVE_ARCH_PREL32_RELOCATIONS
+	bool
+	help
+	  May be selected by an architecture if it supports place-relative
+	  32-bit relocations, both in the toolchain and in the module loader,
+	  in which case relative references can be used in special sections
+	  for PCI fixup, initcalls etc which are only half the size on 64 bit
+	  architectures, and don't require runtime relocation on relocatable
+	  kernels.
+
 source "kernel/gcov/Kconfig"
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index dfd908630631..ce05d2d8143e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -72,6 +72,7 @@ config ARM64
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_MMAP_RND_BITS
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_ARCH_TRANSPARENT_HUGEPAGE
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 987a00ee446c..5849bd4e2b06 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -171,7 +171,7 @@ SECTIONS
 		CON_INITCALL
 		SECURITY_INITCALL
 		INIT_RAM_FS
-		*(.init.rodata.* .init.bss)	/* from the EFI stub */
+		*(.init.rodata.* .init.bss .init.discard.*)	/* from the EFI stub */
 	}
 	.exit.data : {
 		ARM_EXIT_KEEP(EXIT_DATA)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 36f858c37ca7..f7e60ed5bdd0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -163,6 +163,7 @@ config PPC
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_MMAP_RND_BITS
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS	if COMPAT
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select ARCH_HAS_STRICT_KERNEL_RWX	if (PPC_BOOK3S_64 && !RELOCATABLE && !HIBERNATION)
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 7eeb75d758c1..1206cc7daa0d 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -127,6 +127,7 @@ config S390
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_JUMP_LABEL
 	select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_SOFT_DIRTY
 	select HAVE_ARCH_TRACEHOOK
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 781521b7cf9e..77246125883e 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -112,6 +112,7 @@ config X86
 	select HAVE_ARCH_MMAP_RND_BITS		if MMU
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS	if MMU && COMPAT
 	select HAVE_ARCH_COMPAT_MMAP_BASES	if MMU && COMPAT
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_ARCH_TRANSPARENT_HUGEPAGE
-- 
2.11.0

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

* [PATCH 1/5] arch: enable relative relocations for arm64, power, x86, s390 and x86
@ 2017-08-14 10:52   ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

Before updating certain subsystems to use place relative 32-bit
relocations in special sections, to save space  and reduce the
number of absolute relocations that need to be processed at runtime
by relocatable kernels, introduce a new Kconfig symbol and define it
for some architectures that should be able to support and benefit
from it.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/Kconfig                    | 10 ++++++++++
 arch/arm64/Kconfig              |  1 +
 arch/arm64/kernel/vmlinux.lds.S |  2 +-
 arch/powerpc/Kconfig            |  1 +
 arch/s390/Kconfig               |  1 +
 arch/x86/Kconfig                |  1 +
 6 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 21d0089117fe..4e77d8e8697e 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -940,4 +940,14 @@ config REFCOUNT_FULL
 	  against various use-after-free conditions that can be used in
 	  security flaw exploits.
 
+config HAVE_ARCH_PREL32_RELOCATIONS
+	bool
+	help
+	  May be selected by an architecture if it supports place-relative
+	  32-bit relocations, both in the toolchain and in the module loader,
+	  in which case relative references can be used in special sections
+	  for PCI fixup, initcalls etc which are only half the size on 64 bit
+	  architectures, and don't require runtime relocation on relocatable
+	  kernels.
+
 source "kernel/gcov/Kconfig"
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index dfd908630631..ce05d2d8143e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -72,6 +72,7 @@ config ARM64
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_MMAP_RND_BITS
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_ARCH_TRANSPARENT_HUGEPAGE
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 987a00ee446c..5849bd4e2b06 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -171,7 +171,7 @@ SECTIONS
 		CON_INITCALL
 		SECURITY_INITCALL
 		INIT_RAM_FS
-		*(.init.rodata.* .init.bss)	/* from the EFI stub */
+		*(.init.rodata.* .init.bss .init.discard.*)	/* from the EFI stub */
 	}
 	.exit.data : {
 		ARM_EXIT_KEEP(EXIT_DATA)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 36f858c37ca7..f7e60ed5bdd0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -163,6 +163,7 @@ config PPC
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_MMAP_RND_BITS
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS	if COMPAT
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select ARCH_HAS_STRICT_KERNEL_RWX	if (PPC_BOOK3S_64 && !RELOCATABLE && !HIBERNATION)
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 7eeb75d758c1..1206cc7daa0d 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -127,6 +127,7 @@ config S390
 	select HAVE_ARCH_AUDITSYSCALL
 	select HAVE_ARCH_JUMP_LABEL
 	select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_SOFT_DIRTY
 	select HAVE_ARCH_TRACEHOOK
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 781521b7cf9e..77246125883e 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -112,6 +112,7 @@ config X86
 	select HAVE_ARCH_MMAP_RND_BITS		if MMU
 	select HAVE_ARCH_MMAP_RND_COMPAT_BITS	if MMU && COMPAT
 	select HAVE_ARCH_COMPAT_MMAP_BASES	if MMU && COMPAT
+	select HAVE_ARCH_PREL32_RELOCATIONS
 	select HAVE_ARCH_SECCOMP_FILTER
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_ARCH_TRANSPARENT_HUGEPAGE
-- 
2.11.0

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

* [PATCH 2/5] module: use relative references for __ksymtab entries
  2017-08-14 10:52 ` Ard Biesheuvel
@ 2017-08-14 10:52   ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu, Ingo Molnar

An ordinary arm64 defconfig build has ~64 KB worth of __ksymtab
entries, each consisting of two 64-bit fields containing absolute
references, to the symbol itself and to a char array containing
its name, respectively.

When we build the same configuration with KASLR enabled, we end
up with an additional ~192 KB of relocations in the .init section,
i.e., one 24 byte entry for each absolute reference, which all need
to be processed at boot time.

Given how the struct kernel_symbol that describes each entry is
completely local to module.c (except for the references emitted
by EXPORT_SYMBOL() itself), we can easily modify it to contain
two 32-bit relative references instead. This reduces the size of
the __ksymtab section by 50% for all 64-bit architectures, and
gets rid of the runtime relocations entirely for architectures
implementing KASLR, either via standard PIE linking (arm64) or
using custom host tools (x86).

Note that the binary search involving __ksymtab contents relies
on each section being sorted by symbol name. This is implemented
based on the input section names, not the names in the ksymtab
entries, so this patch does not interfere with that.

Given that the use of place-relative relocations requires support
both in the toolchain and in the module loader, we cannot enable
this feature for all architectures. So make it dependend on whether
CONFIG_HAVE_ARCH_PREL32_RELOCATIONS is defined.

Cc: Jessica Yu <jeyu@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/include/asm/Kbuild   |  1 +
 arch/x86/include/asm/export.h |  4 --
 include/asm-generic/export.h  | 12 ++++-
 include/linux/compiler.h      | 11 +++++
 include/linux/export.h        | 47 +++++++++++++++-----
 kernel/module.c               | 33 +++++++++++---
 6 files changed, 85 insertions(+), 23 deletions(-)

diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 5d6a53fd7521..3e8a88dcaa1d 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -9,5 +9,6 @@ generated-y += xen-hypercalls.h
 generic-y += clkdev.h
 generic-y += dma-contiguous.h
 generic-y += early_ioremap.h
+generic-y += export.h
 generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
diff --git a/arch/x86/include/asm/export.h b/arch/x86/include/asm/export.h
deleted file mode 100644
index 138de56b13eb..000000000000
--- a/arch/x86/include/asm/export.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifdef CONFIG_64BIT
-#define KSYM_ALIGN 16
-#endif
-#include <asm-generic/export.h>
diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index 719db1968d81..97ce606459ae 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -5,12 +5,10 @@
 #define KSYM_FUNC(x) x
 #endif
 #ifdef CONFIG_64BIT
-#define __put .quad
 #ifndef KSYM_ALIGN
 #define KSYM_ALIGN 8
 #endif
 #else
-#define __put .long
 #ifndef KSYM_ALIGN
 #define KSYM_ALIGN 4
 #endif
@@ -25,6 +23,16 @@
 #define KSYM(name) name
 #endif
 
+.macro __put, val, name
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	.long	\val - ., \name - .
+#elif defined(CONFIG_64BIT)
+	.quad	\val, \name
+#else
+	.long	\val, \name
+#endif
+.endm
+
 /*
  * note on .section use: @progbits vs %progbits nastiness doesn't matter,
  * since we immediately emit into those sections anyway.
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index eca8ad75e28b..5644d2e653f0 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -590,4 +590,15 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 	(_________p1); \
 })
 
+/*
+ * Force the compiler to emit 'sym' as a symbol, so that we can reference
+ * it from inline assembler. Necessary in case 'sym' could be inlined
+ * otherwise, or eliminated entirely due to lack of references that are
+ * visibile to the compiler.
+ */
+#define __ADDRESSABLE(sym) \
+	static void * __attribute__((section(".discard.text"), used))	\
+		__PASTE(__discard_##sym,__LINE__)(void)			\
+			{ return (void *)&sym; }			\
+
 #endif /* __LINUX_COMPILER_H */
diff --git a/include/linux/export.h b/include/linux/export.h
index 1a1dfdb2a5c6..986d02e57253 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -24,12 +24,6 @@
 #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x)
 
 #ifndef __ASSEMBLY__
-struct kernel_symbol
-{
-	unsigned long value;
-	const char *name;
-};
-
 #ifdef MODULE
 extern struct module __this_module;
 #define THIS_MODULE (&__this_module)
@@ -60,17 +54,48 @@ extern struct module __this_module;
 #define __CRC_SYMBOL(sym, sec)
 #endif
 
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+/*
+ * Emit the ksymtab entry as a pair of relative references: this reduces
+ * the size by half on 64-bit architectures, and eliminates the need for
+ * absolute relocations that require runtime processing on relocatable
+ * kernels.
+ */
+#define __KSYMTAB_ENTRY(sym, sec)					\
+	__ADDRESSABLE(sym)						\
+	asm("	.section \"___ksymtab" sec "+" #sym "\", \"a\"	\n"	\
+	    "	.balign	8					\n"	\
+	    VMLINUX_SYMBOL_STR(__ksymtab_##sym) ":		\n"	\
+	    "	.long "	VMLINUX_SYMBOL_STR(sym) "- .		\n"	\
+	    "	.long "	VMLINUX_SYMBOL_STR(__kstrtab_##sym) "- .\n"	\
+	    "	.previous					\n")
+
+struct kernel_symbol
+{
+	signed int value_offset;
+	signed int name_offset;
+};
+#else
+#define __KSYMTAB_ENTRY(sym, sec)					\
+	static const struct kernel_symbol __ksymtab_##sym		\
+	__attribute__((section("___ksymtab" sec "+" #sym), used))	\
+	= { (unsigned long)&sym, __kstrtab_##sym }
+
+struct kernel_symbol
+{
+	unsigned long value;
+	const char *name;
+};
+#endif
+
 /* For every exported symbol, place a struct in the __ksymtab section */
 #define ___EXPORT_SYMBOL(sym, sec)					\
 	extern typeof(sym) sym;						\
 	__CRC_SYMBOL(sym, sec)						\
 	static const char __kstrtab_##sym[]				\
-	__attribute__((section("__ksymtab_strings"), aligned(1)))	\
+	__attribute__((section("__ksymtab_strings"), used, aligned(1)))	\
 	= VMLINUX_SYMBOL_STR(sym);					\
-	static const struct kernel_symbol __ksymtab_##sym		\
-	__used								\
-	__attribute__((section("___ksymtab" sec "+" #sym), used))	\
-	= { (unsigned long)&sym, __kstrtab_##sym }
+	__KSYMTAB_ENTRY(sym, sec)
 
 #if defined(__KSYM_DEPS__)
 
diff --git a/kernel/module.c b/kernel/module.c
index 40f983cbea81..a45423dcc32d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -539,12 +539,31 @@ static bool check_symbol(const struct symsearch *syms,
 	return true;
 }
 
+static unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
+{
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	return (unsigned long)&sym->value_offset + sym->value_offset;
+#else
+	return sym->value;
+#endif
+}
+
+static const char *kernel_symbol_name(const struct kernel_symbol *sym)
+{
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	return (const char *)((unsigned long)&sym->name_offset +
+			      sym->name_offset);
+#else
+	return sym->name;
+#endif
+}
+
 static int cmp_name(const void *va, const void *vb)
 {
 	const char *a;
 	const struct kernel_symbol *b;
 	a = va; b = vb;
-	return strcmp(a, b->name);
+	return strcmp(a, kernel_symbol_name(b));
 }
 
 static bool find_symbol_in_section(const struct symsearch *syms,
@@ -2190,7 +2209,7 @@ void *__symbol_get(const char *symbol)
 		sym = NULL;
 	preempt_enable();
 
-	return sym ? (void *)sym->value : NULL;
+	return sym ? (void *)kernel_symbol_value(sym) : NULL;
 }
 EXPORT_SYMBOL_GPL(__symbol_get);
 
@@ -2220,10 +2239,12 @@ static int verify_export_symbols(struct module *mod)
 
 	for (i = 0; i < ARRAY_SIZE(arr); i++) {
 		for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
-			if (find_symbol(s->name, &owner, NULL, true, false)) {
+			if (find_symbol(kernel_symbol_name(s), &owner, NULL,
+					true, false)) {
 				pr_err("%s: exports duplicate symbol %s"
 				       " (owned by %s)\n",
-				       mod->name, s->name, module_name(owner));
+				       mod->name, kernel_symbol_name(s),
+				       module_name(owner));
 				return -ENOEXEC;
 			}
 		}
@@ -2272,7 +2293,7 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 			ksym = resolve_symbol_wait(mod, info, name);
 			/* Ok if resolved.  */
 			if (ksym && !IS_ERR(ksym)) {
-				sym[i].st_value = ksym->value;
+				sym[i].st_value = kernel_symbol_value(ksym);
 				break;
 			}
 
@@ -2532,7 +2553,7 @@ static int is_exported(const char *name, unsigned long value,
 		ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
 	else
 		ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
-	return ks != NULL && ks->value == value;
+	return ks != NULL && kernel_symbol_value(ks) == value;
 }
 
 /* As per nm */
-- 
2.11.0

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

* [PATCH 2/5] module: use relative references for __ksymtab entries
@ 2017-08-14 10:52   ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

An ordinary arm64 defconfig build has ~64 KB worth of __ksymtab
entries, each consisting of two 64-bit fields containing absolute
references, to the symbol itself and to a char array containing
its name, respectively.

When we build the same configuration with KASLR enabled, we end
up with an additional ~192 KB of relocations in the .init section,
i.e., one 24 byte entry for each absolute reference, which all need
to be processed at boot time.

Given how the struct kernel_symbol that describes each entry is
completely local to module.c (except for the references emitted
by EXPORT_SYMBOL() itself), we can easily modify it to contain
two 32-bit relative references instead. This reduces the size of
the __ksymtab section by 50% for all 64-bit architectures, and
gets rid of the runtime relocations entirely for architectures
implementing KASLR, either via standard PIE linking (arm64) or
using custom host tools (x86).

Note that the binary search involving __ksymtab contents relies
on each section being sorted by symbol name. This is implemented
based on the input section names, not the names in the ksymtab
entries, so this patch does not interfere with that.

Given that the use of place-relative relocations requires support
both in the toolchain and in the module loader, we cannot enable
this feature for all architectures. So make it dependend on whether
CONFIG_HAVE_ARCH_PREL32_RELOCATIONS is defined.

Cc: Jessica Yu <jeyu@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Nicolas Pitre <nico@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/include/asm/Kbuild   |  1 +
 arch/x86/include/asm/export.h |  4 --
 include/asm-generic/export.h  | 12 ++++-
 include/linux/compiler.h      | 11 +++++
 include/linux/export.h        | 47 +++++++++++++++-----
 kernel/module.c               | 33 +++++++++++---
 6 files changed, 85 insertions(+), 23 deletions(-)

diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 5d6a53fd7521..3e8a88dcaa1d 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -9,5 +9,6 @@ generated-y += xen-hypercalls.h
 generic-y += clkdev.h
 generic-y += dma-contiguous.h
 generic-y += early_ioremap.h
+generic-y += export.h
 generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
diff --git a/arch/x86/include/asm/export.h b/arch/x86/include/asm/export.h
deleted file mode 100644
index 138de56b13eb..000000000000
--- a/arch/x86/include/asm/export.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifdef CONFIG_64BIT
-#define KSYM_ALIGN 16
-#endif
-#include <asm-generic/export.h>
diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index 719db1968d81..97ce606459ae 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -5,12 +5,10 @@
 #define KSYM_FUNC(x) x
 #endif
 #ifdef CONFIG_64BIT
-#define __put .quad
 #ifndef KSYM_ALIGN
 #define KSYM_ALIGN 8
 #endif
 #else
-#define __put .long
 #ifndef KSYM_ALIGN
 #define KSYM_ALIGN 4
 #endif
@@ -25,6 +23,16 @@
 #define KSYM(name) name
 #endif
 
+.macro __put, val, name
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	.long	\val - ., \name - .
+#elif defined(CONFIG_64BIT)
+	.quad	\val, \name
+#else
+	.long	\val, \name
+#endif
+.endm
+
 /*
  * note on .section use: @progbits vs %progbits nastiness doesn't matter,
  * since we immediately emit into those sections anyway.
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index eca8ad75e28b..5644d2e653f0 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -590,4 +590,15 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 	(_________p1); \
 })
 
+/*
+ * Force the compiler to emit 'sym' as a symbol, so that we can reference
+ * it from inline assembler. Necessary in case 'sym' could be inlined
+ * otherwise, or eliminated entirely due to lack of references that are
+ * visibile to the compiler.
+ */
+#define __ADDRESSABLE(sym) \
+	static void * __attribute__((section(".discard.text"), used))	\
+		__PASTE(__discard_##sym,__LINE__)(void)			\
+			{ return (void *)&sym; }			\
+
 #endif /* __LINUX_COMPILER_H */
diff --git a/include/linux/export.h b/include/linux/export.h
index 1a1dfdb2a5c6..986d02e57253 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -24,12 +24,6 @@
 #define VMLINUX_SYMBOL_STR(x) __VMLINUX_SYMBOL_STR(x)
 
 #ifndef __ASSEMBLY__
-struct kernel_symbol
-{
-	unsigned long value;
-	const char *name;
-};
-
 #ifdef MODULE
 extern struct module __this_module;
 #define THIS_MODULE (&__this_module)
@@ -60,17 +54,48 @@ extern struct module __this_module;
 #define __CRC_SYMBOL(sym, sec)
 #endif
 
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+/*
+ * Emit the ksymtab entry as a pair of relative references: this reduces
+ * the size by half on 64-bit architectures, and eliminates the need for
+ * absolute relocations that require runtime processing on relocatable
+ * kernels.
+ */
+#define __KSYMTAB_ENTRY(sym, sec)					\
+	__ADDRESSABLE(sym)						\
+	asm("	.section \"___ksymtab" sec "+" #sym "\", \"a\"	\n"	\
+	    "	.balign	8					\n"	\
+	    VMLINUX_SYMBOL_STR(__ksymtab_##sym) ":		\n"	\
+	    "	.long "	VMLINUX_SYMBOL_STR(sym) "- .		\n"	\
+	    "	.long "	VMLINUX_SYMBOL_STR(__kstrtab_##sym) "- .\n"	\
+	    "	.previous					\n")
+
+struct kernel_symbol
+{
+	signed int value_offset;
+	signed int name_offset;
+};
+#else
+#define __KSYMTAB_ENTRY(sym, sec)					\
+	static const struct kernel_symbol __ksymtab_##sym		\
+	__attribute__((section("___ksymtab" sec "+" #sym), used))	\
+	= { (unsigned long)&sym, __kstrtab_##sym }
+
+struct kernel_symbol
+{
+	unsigned long value;
+	const char *name;
+};
+#endif
+
 /* For every exported symbol, place a struct in the __ksymtab section */
 #define ___EXPORT_SYMBOL(sym, sec)					\
 	extern typeof(sym) sym;						\
 	__CRC_SYMBOL(sym, sec)						\
 	static const char __kstrtab_##sym[]				\
-	__attribute__((section("__ksymtab_strings"), aligned(1)))	\
+	__attribute__((section("__ksymtab_strings"), used, aligned(1)))	\
 	= VMLINUX_SYMBOL_STR(sym);					\
-	static const struct kernel_symbol __ksymtab_##sym		\
-	__used								\
-	__attribute__((section("___ksymtab" sec "+" #sym), used))	\
-	= { (unsigned long)&sym, __kstrtab_##sym }
+	__KSYMTAB_ENTRY(sym, sec)
 
 #if defined(__KSYM_DEPS__)
 
diff --git a/kernel/module.c b/kernel/module.c
index 40f983cbea81..a45423dcc32d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -539,12 +539,31 @@ static bool check_symbol(const struct symsearch *syms,
 	return true;
 }
 
+static unsigned long kernel_symbol_value(const struct kernel_symbol *sym)
+{
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	return (unsigned long)&sym->value_offset + sym->value_offset;
+#else
+	return sym->value;
+#endif
+}
+
+static const char *kernel_symbol_name(const struct kernel_symbol *sym)
+{
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	return (const char *)((unsigned long)&sym->name_offset +
+			      sym->name_offset);
+#else
+	return sym->name;
+#endif
+}
+
 static int cmp_name(const void *va, const void *vb)
 {
 	const char *a;
 	const struct kernel_symbol *b;
 	a = va; b = vb;
-	return strcmp(a, b->name);
+	return strcmp(a, kernel_symbol_name(b));
 }
 
 static bool find_symbol_in_section(const struct symsearch *syms,
@@ -2190,7 +2209,7 @@ void *__symbol_get(const char *symbol)
 		sym = NULL;
 	preempt_enable();
 
-	return sym ? (void *)sym->value : NULL;
+	return sym ? (void *)kernel_symbol_value(sym) : NULL;
 }
 EXPORT_SYMBOL_GPL(__symbol_get);
 
@@ -2220,10 +2239,12 @@ static int verify_export_symbols(struct module *mod)
 
 	for (i = 0; i < ARRAY_SIZE(arr); i++) {
 		for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
-			if (find_symbol(s->name, &owner, NULL, true, false)) {
+			if (find_symbol(kernel_symbol_name(s), &owner, NULL,
+					true, false)) {
 				pr_err("%s: exports duplicate symbol %s"
 				       " (owned by %s)\n",
-				       mod->name, s->name, module_name(owner));
+				       mod->name, kernel_symbol_name(s),
+				       module_name(owner));
 				return -ENOEXEC;
 			}
 		}
@@ -2272,7 +2293,7 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 			ksym = resolve_symbol_wait(mod, info, name);
 			/* Ok if resolved.  */
 			if (ksym && !IS_ERR(ksym)) {
-				sym[i].st_value = ksym->value;
+				sym[i].st_value = kernel_symbol_value(ksym);
 				break;
 			}
 
@@ -2532,7 +2553,7 @@ static int is_exported(const char *name, unsigned long value,
 		ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab);
 	else
 		ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms);
-	return ks != NULL && ks->value == value;
+	return ks != NULL && kernel_symbol_value(ks) == value;
 }
 
 /* As per nm */
-- 
2.11.0

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

* [PATCH 3/5] init: allow initcall tables to be emitted using relative references
  2017-08-14 10:52 ` Ard Biesheuvel
@ 2017-08-14 10:52   ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

Allow the initcall tables to be emitted using relative references that
are only half the size on 64-bit architectures and don't require fixups
at runtime on relocatable kernels.

Cc: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: James Morris <james.l.morris@oracle.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 include/linux/init.h   | 44 +++++++++++++++-----
 init/main.c            | 32 +++++++-------
 kernel/printk/printk.c |  4 +-
 security/security.c    |  4 +-
 4 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 94769d687cf0..a65628998ce3 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -110,8 +110,24 @@
 typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
-extern initcall_t __con_initcall_start[], __con_initcall_end[];
-extern initcall_t __security_initcall_start[], __security_initcall_end[];
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+typedef signed int initcall_entry_t;
+
+static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
+{
+	return (initcall_t)((unsigned long)entry + *entry);
+}
+#else
+typedef initcall_t initcall_entry_t;
+
+static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
+{
+	return *entry;
+}
+#endif
+
+extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
+extern initcall_entry_t __security_initcall_start[], __security_initcall_end[];
 
 /* Used for contructor calls. */
 typedef void (*ctor_fn_t)(void);
@@ -161,9 +177,20 @@ extern bool initcall_debug;
  * as KEEP() in the linker script.
  */
 
-#define __define_initcall(fn, id) \
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+#define ___define_initcall(fn, id, __sec)			\
+	__ADDRESSABLE(fn)					\
+	asm(".section	\"" #__sec ".init\", \"a\"	\n"	\
+	"__initcall_" #fn #id ":			\n"	\
+	    ".long "	VMLINUX_SYMBOL_STR(fn) " - .	\n"	\
+	    ".previous					\n");
+#else
+#define ___define_initcall(fn, id, __sec) \
 	static initcall_t __initcall_##fn##id __used \
-	__attribute__((__section__(".initcall" #id ".init"))) = fn;
+		__attribute__((__section__(#__sec ".init"))) = fn;
+#endif
+
+#define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
 
 /*
  * Early initcalls run before initializing SMP.
@@ -202,13 +229,8 @@ extern bool initcall_debug;
 #define __exitcall(fn)						\
 	static exitcall_t __exitcall_##fn __exit_call = fn
 
-#define console_initcall(fn)					\
-	static initcall_t __initcall_##fn			\
-	__used __section(.con_initcall.init) = fn
-
-#define security_initcall(fn)					\
-	static initcall_t __initcall_##fn			\
-	__used __section(.security_initcall.init) = fn
+#define console_initcall(fn)	___define_initcall(fn,, .con_initcall)
+#define security_initcall(fn)	___define_initcall(fn,, .security_initcall)
 
 struct obs_kernel_param {
 	const char *str;
diff --git a/init/main.c b/init/main.c
index 052481fbe363..ac2a91f71107 100644
--- a/init/main.c
+++ b/init/main.c
@@ -833,18 +833,18 @@ int __init_or_module do_one_initcall(initcall_t fn)
 }
 
 
-extern initcall_t __initcall_start[];
-extern initcall_t __initcall0_start[];
-extern initcall_t __initcall1_start[];
-extern initcall_t __initcall2_start[];
-extern initcall_t __initcall3_start[];
-extern initcall_t __initcall4_start[];
-extern initcall_t __initcall5_start[];
-extern initcall_t __initcall6_start[];
-extern initcall_t __initcall7_start[];
-extern initcall_t __initcall_end[];
-
-static initcall_t *initcall_levels[] __initdata = {
+extern initcall_entry_t __initcall_start[];
+extern initcall_entry_t __initcall0_start[];
+extern initcall_entry_t __initcall1_start[];
+extern initcall_entry_t __initcall2_start[];
+extern initcall_entry_t __initcall3_start[];
+extern initcall_entry_t __initcall4_start[];
+extern initcall_entry_t __initcall5_start[];
+extern initcall_entry_t __initcall6_start[];
+extern initcall_entry_t __initcall7_start[];
+extern initcall_entry_t __initcall_end[];
+
+static initcall_entry_t *initcall_levels[] __initdata = {
 	__initcall0_start,
 	__initcall1_start,
 	__initcall2_start,
@@ -870,7 +870,7 @@ static char *initcall_level_names[] __initdata = {
 
 static void __init do_initcall_level(int level)
 {
-	initcall_t *fn;
+	initcall_entry_t *fn;
 
 	strcpy(initcall_command_line, saved_command_line);
 	parse_args(initcall_level_names[level],
@@ -880,7 +880,7 @@ static void __init do_initcall_level(int level)
 		   NULL, &repair_env_string);
 
 	for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
-		do_one_initcall(*fn);
+		do_one_initcall(initcall_from_entry(fn));
 }
 
 static void __init do_initcalls(void)
@@ -911,10 +911,10 @@ static void __init do_basic_setup(void)
 
 static void __init do_pre_smp_initcalls(void)
 {
-	initcall_t *fn;
+	initcall_entry_t *fn;
 
 	for (fn = __initcall_start; fn < __initcall0_start; fn++)
-		do_one_initcall(*fn);
+		do_one_initcall(initcall_from_entry(fn));
 }
 
 /*
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fc47863f629c..39d343c1c4b2 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2623,7 +2623,7 @@ EXPORT_SYMBOL(unregister_console);
  */
 void __init console_init(void)
 {
-	initcall_t *call;
+	initcall_entry_t *call;
 
 	/* Setup the default TTY line discipline. */
 	n_tty_init();
@@ -2634,7 +2634,7 @@ void __init console_init(void)
 	 */
 	call = __con_initcall_start;
 	while (call < __con_initcall_end) {
-		(*call)();
+		initcall_from_entry(call)();
 		call++;
 	}
 }
diff --git a/security/security.c b/security/security.c
index 30132378d103..63b5f52bb098 100644
--- a/security/security.c
+++ b/security/security.c
@@ -44,10 +44,10 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
 
 static void __init do_security_initcalls(void)
 {
-	initcall_t *call;
+	initcall_entry_t *call;
 	call = __security_initcall_start;
 	while (call < __security_initcall_end) {
-		(*call) ();
+		initcall_from_entry(call)();
 		call++;
 	}
 }
-- 
2.11.0

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

* [PATCH 3/5] init: allow initcall tables to be emitted using relative references
@ 2017-08-14 10:52   ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

Allow the initcall tables to be emitted using relative references that
are only half the size on 64-bit architectures and don't require fixups
at runtime on relocatable kernels.

Cc: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: James Morris <james.l.morris@oracle.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 include/linux/init.h   | 44 +++++++++++++++-----
 init/main.c            | 32 +++++++-------
 kernel/printk/printk.c |  4 +-
 security/security.c    |  4 +-
 4 files changed, 53 insertions(+), 31 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 94769d687cf0..a65628998ce3 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -110,8 +110,24 @@
 typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
-extern initcall_t __con_initcall_start[], __con_initcall_end[];
-extern initcall_t __security_initcall_start[], __security_initcall_end[];
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+typedef signed int initcall_entry_t;
+
+static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
+{
+	return (initcall_t)((unsigned long)entry + *entry);
+}
+#else
+typedef initcall_t initcall_entry_t;
+
+static inline initcall_t initcall_from_entry(initcall_entry_t *entry)
+{
+	return *entry;
+}
+#endif
+
+extern initcall_entry_t __con_initcall_start[], __con_initcall_end[];
+extern initcall_entry_t __security_initcall_start[], __security_initcall_end[];
 
 /* Used for contructor calls. */
 typedef void (*ctor_fn_t)(void);
@@ -161,9 +177,20 @@ extern bool initcall_debug;
  * as KEEP() in the linker script.
  */
 
-#define __define_initcall(fn, id) \
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+#define ___define_initcall(fn, id, __sec)			\
+	__ADDRESSABLE(fn)					\
+	asm(".section	\"" #__sec ".init\", \"a\"	\n"	\
+	"__initcall_" #fn #id ":			\n"	\
+	    ".long "	VMLINUX_SYMBOL_STR(fn) " - .	\n"	\
+	    ".previous					\n");
+#else
+#define ___define_initcall(fn, id, __sec) \
 	static initcall_t __initcall_##fn##id __used \
-	__attribute__((__section__(".initcall" #id ".init"))) = fn;
+		__attribute__((__section__(#__sec ".init"))) = fn;
+#endif
+
+#define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
 
 /*
  * Early initcalls run before initializing SMP.
@@ -202,13 +229,8 @@ extern bool initcall_debug;
 #define __exitcall(fn)						\
 	static exitcall_t __exitcall_##fn __exit_call = fn
 
-#define console_initcall(fn)					\
-	static initcall_t __initcall_##fn			\
-	__used __section(.con_initcall.init) = fn
-
-#define security_initcall(fn)					\
-	static initcall_t __initcall_##fn			\
-	__used __section(.security_initcall.init) = fn
+#define console_initcall(fn)	___define_initcall(fn,, .con_initcall)
+#define security_initcall(fn)	___define_initcall(fn,, .security_initcall)
 
 struct obs_kernel_param {
 	const char *str;
diff --git a/init/main.c b/init/main.c
index 052481fbe363..ac2a91f71107 100644
--- a/init/main.c
+++ b/init/main.c
@@ -833,18 +833,18 @@ int __init_or_module do_one_initcall(initcall_t fn)
 }
 
 
-extern initcall_t __initcall_start[];
-extern initcall_t __initcall0_start[];
-extern initcall_t __initcall1_start[];
-extern initcall_t __initcall2_start[];
-extern initcall_t __initcall3_start[];
-extern initcall_t __initcall4_start[];
-extern initcall_t __initcall5_start[];
-extern initcall_t __initcall6_start[];
-extern initcall_t __initcall7_start[];
-extern initcall_t __initcall_end[];
-
-static initcall_t *initcall_levels[] __initdata = {
+extern initcall_entry_t __initcall_start[];
+extern initcall_entry_t __initcall0_start[];
+extern initcall_entry_t __initcall1_start[];
+extern initcall_entry_t __initcall2_start[];
+extern initcall_entry_t __initcall3_start[];
+extern initcall_entry_t __initcall4_start[];
+extern initcall_entry_t __initcall5_start[];
+extern initcall_entry_t __initcall6_start[];
+extern initcall_entry_t __initcall7_start[];
+extern initcall_entry_t __initcall_end[];
+
+static initcall_entry_t *initcall_levels[] __initdata = {
 	__initcall0_start,
 	__initcall1_start,
 	__initcall2_start,
@@ -870,7 +870,7 @@ static char *initcall_level_names[] __initdata = {
 
 static void __init do_initcall_level(int level)
 {
-	initcall_t *fn;
+	initcall_entry_t *fn;
 
 	strcpy(initcall_command_line, saved_command_line);
 	parse_args(initcall_level_names[level],
@@ -880,7 +880,7 @@ static void __init do_initcall_level(int level)
 		   NULL, &repair_env_string);
 
 	for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
-		do_one_initcall(*fn);
+		do_one_initcall(initcall_from_entry(fn));
 }
 
 static void __init do_initcalls(void)
@@ -911,10 +911,10 @@ static void __init do_basic_setup(void)
 
 static void __init do_pre_smp_initcalls(void)
 {
-	initcall_t *fn;
+	initcall_entry_t *fn;
 
 	for (fn = __initcall_start; fn < __initcall0_start; fn++)
-		do_one_initcall(*fn);
+		do_one_initcall(initcall_from_entry(fn));
 }
 
 /*
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fc47863f629c..39d343c1c4b2 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2623,7 +2623,7 @@ EXPORT_SYMBOL(unregister_console);
  */
 void __init console_init(void)
 {
-	initcall_t *call;
+	initcall_entry_t *call;
 
 	/* Setup the default TTY line discipline. */
 	n_tty_init();
@@ -2634,7 +2634,7 @@ void __init console_init(void)
 	 */
 	call = __con_initcall_start;
 	while (call < __con_initcall_end) {
-		(*call)();
+		initcall_from_entry(call)();
 		call++;
 	}
 }
diff --git a/security/security.c b/security/security.c
index 30132378d103..63b5f52bb098 100644
--- a/security/security.c
+++ b/security/security.c
@@ -44,10 +44,10 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
 
 static void __init do_security_initcalls(void)
 {
-	initcall_t *call;
+	initcall_entry_t *call;
 	call = __security_initcall_start;
 	while (call < __security_initcall_end) {
-		(*call) ();
+		initcall_from_entry(call)();
 		call++;
 	}
 }
-- 
2.11.0

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

* [PATCH 4/5] drivers: pci: add support for relative addressing in quirk tables
  2017-08-14 10:52 ` Ard Biesheuvel
@ 2017-08-14 10:52   ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

Allow the PCI quirk tables to be emitted in a way that avoids absolute
references to the hook functions. This reduces the size of the entries,
and, more importantly, makes them invariant under runtime relocation
(e.g., for KASLR)

Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/pci/quirks.c | 13 ++++++++++---
 include/linux/pci.h  | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 6967c6b4cf6b..10126612e342 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3547,9 +3547,16 @@ static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
 		     f->vendor == (u16) PCI_ANY_ID) &&
 		    (f->device == dev->device ||
 		     f->device == (u16) PCI_ANY_ID)) {
-			calltime = fixup_debug_start(dev, f->hook);
-			f->hook(dev);
-			fixup_debug_report(dev, calltime, f->hook);
+			void (*hook)(struct pci_dev *dev);
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+			hook = (void *)((unsigned long)&f->hook_offset +
+					f->hook_offset);
+#else
+			hook = f->hook;
+#endif
+			calltime = fixup_debug_start(dev, hook);
+			hook(dev);
+			fixup_debug_report(dev, calltime, hook);
 		}
 }
 
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 4869e66dd659..203544f33345 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1734,7 +1734,11 @@ struct pci_fixup {
 	u16 device;		/* You can use PCI_ANY_ID here of course */
 	u32 class;		/* You can use PCI_ANY_ID here too */
 	unsigned int class_shift;	/* should be 0, 8, 16 */
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	signed int hook_offset;
+#else
 	void (*hook)(struct pci_dev *dev);
+#endif
 };
 
 enum pci_fixup_pass {
@@ -1748,12 +1752,28 @@ enum pci_fixup_pass {
 	pci_fixup_suspend_late,	/* pci_device_suspend_late() */
 };
 
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+#define __DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,	\
+				    class_shift, hook)			\
+	__ADDRESSABLE(hook)						\
+	asm(".section "	#sec ", \"a\"				\n"	\
+	    ".balign	16					\n"	\
+	    ".short "	#vendor ", " #device "			\n"	\
+	    ".long "	#class ", " #class_shift "		\n"	\
+	    ".long "	VMLINUX_SYMBOL_STR(hook) " - .		\n"	\
+	    ".previous						\n");
+#define DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,	\
+				  class_shift, hook)			\
+	__DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,	\
+				  class_shift, hook)
+#else
 /* Anonymous variables would be nice... */
 #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class,	\
 				  class_shift, hook)			\
 	static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used	\
 	__attribute__((__section__(#section), aligned((sizeof(void *)))))    \
 		= { vendor, device, class, class_shift, hook };
+#endif
 
 #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class,		\
 					 class_shift, hook)		\
-- 
2.11.0

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

* [PATCH 4/5] drivers: pci: add support for relative addressing in quirk tables
@ 2017-08-14 10:52   ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

Allow the PCI quirk tables to be emitted in a way that avoids absolute
references to the hook functions. This reduces the size of the entries,
and, more importantly, makes them invariant under runtime relocation
(e.g., for KASLR)

Cc: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/pci/quirks.c | 13 ++++++++++---
 include/linux/pci.h  | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 6967c6b4cf6b..10126612e342 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -3547,9 +3547,16 @@ static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
 		     f->vendor == (u16) PCI_ANY_ID) &&
 		    (f->device == dev->device ||
 		     f->device == (u16) PCI_ANY_ID)) {
-			calltime = fixup_debug_start(dev, f->hook);
-			f->hook(dev);
-			fixup_debug_report(dev, calltime, f->hook);
+			void (*hook)(struct pci_dev *dev);
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+			hook = (void *)((unsigned long)&f->hook_offset +
+					f->hook_offset);
+#else
+			hook = f->hook;
+#endif
+			calltime = fixup_debug_start(dev, hook);
+			hook(dev);
+			fixup_debug_report(dev, calltime, hook);
 		}
 }
 
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 4869e66dd659..203544f33345 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1734,7 +1734,11 @@ struct pci_fixup {
 	u16 device;		/* You can use PCI_ANY_ID here of course */
 	u32 class;		/* You can use PCI_ANY_ID here too */
 	unsigned int class_shift;	/* should be 0, 8, 16 */
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	signed int hook_offset;
+#else
 	void (*hook)(struct pci_dev *dev);
+#endif
 };
 
 enum pci_fixup_pass {
@@ -1748,12 +1752,28 @@ enum pci_fixup_pass {
 	pci_fixup_suspend_late,	/* pci_device_suspend_late() */
 };
 
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+#define __DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,	\
+				    class_shift, hook)			\
+	__ADDRESSABLE(hook)						\
+	asm(".section "	#sec ", \"a\"				\n"	\
+	    ".balign	16					\n"	\
+	    ".short "	#vendor ", " #device "			\n"	\
+	    ".long "	#class ", " #class_shift "		\n"	\
+	    ".long "	VMLINUX_SYMBOL_STR(hook) " - .		\n"	\
+	    ".previous						\n");
+#define DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,	\
+				  class_shift, hook)			\
+	__DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class,	\
+				  class_shift, hook)
+#else
 /* Anonymous variables would be nice... */
 #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class,	\
 				  class_shift, hook)			\
 	static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used	\
 	__attribute__((__section__(#section), aligned((sizeof(void *)))))    \
 		= { vendor, device, class, class_shift, hook };
+#endif
 
 #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class,		\
 					 class_shift, hook)		\
-- 
2.11.0

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

* [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-14 10:52 ` Ard Biesheuvel
@ 2017-08-14 10:52   ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

To avoid the need for relocating absolute references to tracepoint
structures at boot time when running relocatable kernels (which may
take a disproportionate amount of space), add the option to emit
these tables as relative references instead.

Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 include/linux/tracepoint.h | 19 +++++++++++++++----
 kernel/tracepoint.c        | 19 ++++++++++++++-----
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index a26ffbe09e71..d02bf1a695e8 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -228,6 +228,19 @@ extern void syscall_unregfunc(void);
 		return static_key_false(&__tracepoint_##name.key);	\
 	}
 
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+#define __TRACEPOINT_ENTRY(name)					 \
+	asm("	.section \"__tracepoints_ptrs\", \"a\"		     \n" \
+	    "	.balign 4					     \n" \
+	    "	.long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \
+	    "	.previous					     \n")
+#else
+#define __TRACEPOINT_ENTRY(name)					 \
+	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
+	__attribute__((section("__tracepoints_ptrs"))) =		 \
+		&__tracepoint_##name
+#endif
+
 /*
  * We have no guarantee that gcc and the linker won't up-align the tracepoint
  * structures, so we create an array of pointers that will be used for iteration
@@ -237,11 +250,9 @@ extern void syscall_unregfunc(void);
 	static const char __tpstrtab_##name[]				 \
 	__attribute__((section("__tracepoints_strings"))) = #name;	 \
 	struct tracepoint __tracepoint_##name				 \
-	__attribute__((section("__tracepoints"))) =			 \
+	__attribute__((section("__tracepoints"), used)) =		 \
 		{ __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
-	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
-	__attribute__((section("__tracepoints_ptrs"))) =		 \
-		&__tracepoint_##name;
+	__TRACEPOINT_ENTRY(name);
 
 #define DEFINE_TRACE(name)						\
 	DEFINE_TRACE_FN(name, NULL, NULL);
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 685c50ae6300..1c6689603764 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -28,8 +28,8 @@
 #include <linux/sched/task.h>
 #include <linux/static_key.h>
 
-extern struct tracepoint * const __start___tracepoints_ptrs[];
-extern struct tracepoint * const __stop___tracepoints_ptrs[];
+extern const unsigned char __start___tracepoints_ptrs[];
+extern const unsigned char __stop___tracepoints_ptrs[];
 
 /* Set to 1 to enable tracepoint debug output */
 static const int tracepoint_debug;
@@ -503,17 +503,26 @@ static __init int init_tracepoints(void)
 __initcall(init_tracepoints);
 #endif /* CONFIG_MODULES */
 
-static void for_each_tracepoint_range(struct tracepoint * const *begin,
-		struct tracepoint * const *end,
+static void for_each_tracepoint_range(const void *begin, const void *end,
 		void (*fct)(struct tracepoint *tp, void *priv),
 		void *priv)
 {
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	const signed int *iter;
+
+	if (!begin)
+		return;
+	for (iter = begin; iter < (signed int *)end; iter++) {
+		fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
+	}
+#else
 	struct tracepoint * const *iter;
 
 	if (!begin)
 		return;
-	for (iter = begin; iter < end; iter++)
+	for (iter = begin; iter < (struct tracepoint * const *)end; iter++)
 		fct(*iter, priv);
+#endif
 }
 
 /**
-- 
2.11.0

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

* [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-14 10:52   ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 10:52 UTC (permalink / raw)
  To: linux-kernel, linux-arch
  Cc: Ard Biesheuvel, H. Peter Anvin, Arnd Bergmann, Heiko Carstens,
	Kees Cook, Will Deacon, Michael Ellerman, Thomas Garnier,
	Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

To avoid the need for relocating absolute references to tracepoint
structures at boot time when running relocatable kernels (which may
take a disproportionate amount of space), add the option to emit
these tables as relative references instead.

Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 include/linux/tracepoint.h | 19 +++++++++++++++----
 kernel/tracepoint.c        | 19 ++++++++++++++-----
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
index a26ffbe09e71..d02bf1a695e8 100644
--- a/include/linux/tracepoint.h
+++ b/include/linux/tracepoint.h
@@ -228,6 +228,19 @@ extern void syscall_unregfunc(void);
 		return static_key_false(&__tracepoint_##name.key);	\
 	}
 
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+#define __TRACEPOINT_ENTRY(name)					 \
+	asm("	.section \"__tracepoints_ptrs\", \"a\"		     \n" \
+	    "	.balign 4					     \n" \
+	    "	.long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \
+	    "	.previous					     \n")
+#else
+#define __TRACEPOINT_ENTRY(name)					 \
+	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
+	__attribute__((section("__tracepoints_ptrs"))) =		 \
+		&__tracepoint_##name
+#endif
+
 /*
  * We have no guarantee that gcc and the linker won't up-align the tracepoint
  * structures, so we create an array of pointers that will be used for iteration
@@ -237,11 +250,9 @@ extern void syscall_unregfunc(void);
 	static const char __tpstrtab_##name[]				 \
 	__attribute__((section("__tracepoints_strings"))) = #name;	 \
 	struct tracepoint __tracepoint_##name				 \
-	__attribute__((section("__tracepoints"))) =			 \
+	__attribute__((section("__tracepoints"), used)) =		 \
 		{ __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
-	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
-	__attribute__((section("__tracepoints_ptrs"))) =		 \
-		&__tracepoint_##name;
+	__TRACEPOINT_ENTRY(name);
 
 #define DEFINE_TRACE(name)						\
 	DEFINE_TRACE_FN(name, NULL, NULL);
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 685c50ae6300..1c6689603764 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -28,8 +28,8 @@
 #include <linux/sched/task.h>
 #include <linux/static_key.h>
 
-extern struct tracepoint * const __start___tracepoints_ptrs[];
-extern struct tracepoint * const __stop___tracepoints_ptrs[];
+extern const unsigned char __start___tracepoints_ptrs[];
+extern const unsigned char __stop___tracepoints_ptrs[];
 
 /* Set to 1 to enable tracepoint debug output */
 static const int tracepoint_debug;
@@ -503,17 +503,26 @@ static __init int init_tracepoints(void)
 __initcall(init_tracepoints);
 #endif /* CONFIG_MODULES */
 
-static void for_each_tracepoint_range(struct tracepoint * const *begin,
-		struct tracepoint * const *end,
+static void for_each_tracepoint_range(const void *begin, const void *end,
 		void (*fct)(struct tracepoint *tp, void *priv),
 		void *priv)
 {
+#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
+	const signed int *iter;
+
+	if (!begin)
+		return;
+	for (iter = begin; iter < (signed int *)end; iter++) {
+		fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
+	}
+#else
 	struct tracepoint * const *iter;
 
 	if (!begin)
 		return;
-	for (iter = begin; iter < end; iter++)
+	for (iter = begin; iter < (struct tracepoint * const *)end; iter++)
 		fct(*iter, priv);
+#endif
 }
 
 /**
-- 
2.11.0

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-14 10:52   ` Ard Biesheuvel
@ 2017-08-14 15:23     ` Steven Rostedt
  -1 siblings, 0 replies; 34+ messages in thread
From: Steven Rostedt @ 2017-08-14 15:23 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Martin Schwidefsky, Sergey Senozhatsky,
	Jessica Yu

On Mon, 14 Aug 2017 11:52:31 +0100
Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> To avoid the need for relocating absolute references to tracepoint
> structures at boot time when running relocatable kernels (which may
> take a disproportionate amount of space), add the option to emit
> these tables as relative references instead.
> 
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  include/linux/tracepoint.h | 19 +++++++++++++++----
>  kernel/tracepoint.c        | 19 ++++++++++++++-----
>  2 files changed, 29 insertions(+), 9 deletions(-)
> 
> diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
> index a26ffbe09e71..d02bf1a695e8 100644
> --- a/include/linux/tracepoint.h
> +++ b/include/linux/tracepoint.h
> @@ -228,6 +228,19 @@ extern void syscall_unregfunc(void);
>  		return static_key_false(&__tracepoint_##name.key);	\
>  	}
>  
> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> +#define __TRACEPOINT_ENTRY(name)					 \
> +	asm("	.section \"__tracepoints_ptrs\", \"a\"		     \n" \
> +	    "	.balign 4					     \n" \
> +	    "	.long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \
> +	    "	.previous					     \n")
> +#else
> +#define __TRACEPOINT_ENTRY(name)					 \
> +	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
> +	__attribute__((section("__tracepoints_ptrs"))) =		 \
> +		&__tracepoint_##name
> +#endif
> +
>  /*
>   * We have no guarantee that gcc and the linker won't up-align the tracepoint
>   * structures, so we create an array of pointers that will be used for iteration
> @@ -237,11 +250,9 @@ extern void syscall_unregfunc(void);
>  	static const char __tpstrtab_##name[]				 \
>  	__attribute__((section("__tracepoints_strings"))) = #name;	 \
>  	struct tracepoint __tracepoint_##name				 \
> -	__attribute__((section("__tracepoints"))) =			 \
> +	__attribute__((section("__tracepoints"), used)) =		 \
>  		{ __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
> -	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
> -	__attribute__((section("__tracepoints_ptrs"))) =		 \
> -		&__tracepoint_##name;
> +	__TRACEPOINT_ENTRY(name);
>  
>  #define DEFINE_TRACE(name)						\
>  	DEFINE_TRACE_FN(name, NULL, NULL);
> diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
> index 685c50ae6300..1c6689603764 100644
> --- a/kernel/tracepoint.c
> +++ b/kernel/tracepoint.c
> @@ -28,8 +28,8 @@
>  #include <linux/sched/task.h>
>  #include <linux/static_key.h>
>  
> -extern struct tracepoint * const __start___tracepoints_ptrs[];
> -extern struct tracepoint * const __stop___tracepoints_ptrs[];
> +extern const unsigned char __start___tracepoints_ptrs[];
> +extern const unsigned char __stop___tracepoints_ptrs[];

Does this have to be converted to a char array?

>  
>  /* Set to 1 to enable tracepoint debug output */
>  static const int tracepoint_debug;
> @@ -503,17 +503,26 @@ static __init int init_tracepoints(void)
>  __initcall(init_tracepoints);
>  #endif /* CONFIG_MODULES */
>  
> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
> -		struct tracepoint * const *end,
> +static void for_each_tracepoint_range(const void *begin, const void *end,
>  		void (*fct)(struct tracepoint *tp, void *priv),
>  		void *priv)
>  {
> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> +	const signed int *iter;
> +
> +	if (!begin)
> +		return;
> +	for (iter = begin; iter < (signed int *)end; iter++) {

Isn't the typecasts here sufficient, even if the above end is defined
as a tracepoint * const *?

-- Steve

> +		fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
> +	}
> +#else
>  	struct tracepoint * const *iter;
>  
>  	if (!begin)
>  		return;
> -	for (iter = begin; iter < end; iter++)
> +	for (iter = begin; iter < (struct tracepoint * const *)end; iter++)
>  		fct(*iter, priv);
> +#endif
>  }
>  
>  /**

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-14 15:23     ` Steven Rostedt
  0 siblings, 0 replies; 34+ messages in thread
From: Steven Rostedt @ 2017-08-14 15:23 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre

On Mon, 14 Aug 2017 11:52:31 +0100
Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> To avoid the need for relocating absolute references to tracepoint
> structures at boot time when running relocatable kernels (which may
> take a disproportionate amount of space), add the option to emit
> these tables as relative references instead.
> 
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  include/linux/tracepoint.h | 19 +++++++++++++++----
>  kernel/tracepoint.c        | 19 ++++++++++++++-----
>  2 files changed, 29 insertions(+), 9 deletions(-)
> 
> diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
> index a26ffbe09e71..d02bf1a695e8 100644
> --- a/include/linux/tracepoint.h
> +++ b/include/linux/tracepoint.h
> @@ -228,6 +228,19 @@ extern void syscall_unregfunc(void);
>  		return static_key_false(&__tracepoint_##name.key);	\
>  	}
>  
> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> +#define __TRACEPOINT_ENTRY(name)					 \
> +	asm("	.section \"__tracepoints_ptrs\", \"a\"		     \n" \
> +	    "	.balign 4					     \n" \
> +	    "	.long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \
> +	    "	.previous					     \n")
> +#else
> +#define __TRACEPOINT_ENTRY(name)					 \
> +	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
> +	__attribute__((section("__tracepoints_ptrs"))) =		 \
> +		&__tracepoint_##name
> +#endif
> +
>  /*
>   * We have no guarantee that gcc and the linker won't up-align the tracepoint
>   * structures, so we create an array of pointers that will be used for iteration
> @@ -237,11 +250,9 @@ extern void syscall_unregfunc(void);
>  	static const char __tpstrtab_##name[]				 \
>  	__attribute__((section("__tracepoints_strings"))) = #name;	 \
>  	struct tracepoint __tracepoint_##name				 \
> -	__attribute__((section("__tracepoints"))) =			 \
> +	__attribute__((section("__tracepoints"), used)) =		 \
>  		{ __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
> -	static struct tracepoint * const __tracepoint_ptr_##name __used	 \
> -	__attribute__((section("__tracepoints_ptrs"))) =		 \
> -		&__tracepoint_##name;
> +	__TRACEPOINT_ENTRY(name);
>  
>  #define DEFINE_TRACE(name)						\
>  	DEFINE_TRACE_FN(name, NULL, NULL);
> diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
> index 685c50ae6300..1c6689603764 100644
> --- a/kernel/tracepoint.c
> +++ b/kernel/tracepoint.c
> @@ -28,8 +28,8 @@
>  #include <linux/sched/task.h>
>  #include <linux/static_key.h>
>  
> -extern struct tracepoint * const __start___tracepoints_ptrs[];
> -extern struct tracepoint * const __stop___tracepoints_ptrs[];
> +extern const unsigned char __start___tracepoints_ptrs[];
> +extern const unsigned char __stop___tracepoints_ptrs[];

Does this have to be converted to a char array?

>  
>  /* Set to 1 to enable tracepoint debug output */
>  static const int tracepoint_debug;
> @@ -503,17 +503,26 @@ static __init int init_tracepoints(void)
>  __initcall(init_tracepoints);
>  #endif /* CONFIG_MODULES */
>  
> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
> -		struct tracepoint * const *end,
> +static void for_each_tracepoint_range(const void *begin, const void *end,
>  		void (*fct)(struct tracepoint *tp, void *priv),
>  		void *priv)
>  {
> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> +	const signed int *iter;
> +
> +	if (!begin)
> +		return;
> +	for (iter = begin; iter < (signed int *)end; iter++) {

Isn't the typecasts here sufficient, even if the above end is defined
as a tracepoint * const *?

-- Steve

> +		fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
> +	}
> +#else
>  	struct tracepoint * const *iter;
>  
>  	if (!begin)
>  		return;
> -	for (iter = begin; iter < end; iter++)
> +	for (iter = begin; iter < (struct tracepoint * const *)end; iter++)
>  		fct(*iter, priv);
> +#endif
>  }
>  
>  /**

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-14 15:23     ` Steven Rostedt
@ 2017-08-14 15:29       ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 15:29 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Martin Schwidefsky, Sergey Senozhatsky,
	Jessica Yu

On 14 August 2017 at 16:23, Steven Rostedt <rostedt@goodmis.org> wrote:
> On Mon, 14 Aug 2017 11:52:31 +0100
> Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
>> To avoid the need for relocating absolute references to tracepoint
>> structures at boot time when running relocatable kernels (which may
>> take a disproportionate amount of space), add the option to emit
>> these tables as relative references instead.
>>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>  include/linux/tracepoint.h | 19 +++++++++++++++----
>>  kernel/tracepoint.c        | 19 ++++++++++++++-----
>>  2 files changed, 29 insertions(+), 9 deletions(-)
>>
>> diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
>> index a26ffbe09e71..d02bf1a695e8 100644
>> --- a/include/linux/tracepoint.h
>> +++ b/include/linux/tracepoint.h
>> @@ -228,6 +228,19 @@ extern void syscall_unregfunc(void);
>>               return static_key_false(&__tracepoint_##name.key);      \
>>       }
>>
>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> +#define __TRACEPOINT_ENTRY(name)                                      \
>> +     asm("   .section \"__tracepoints_ptrs\", \"a\"               \n" \
>> +         "   .balign 4                                            \n" \
>> +         "   .long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \
>> +         "   .previous                                            \n")
>> +#else
>> +#define __TRACEPOINT_ENTRY(name)                                      \
>> +     static struct tracepoint * const __tracepoint_ptr_##name __used  \
>> +     __attribute__((section("__tracepoints_ptrs"))) =                 \
>> +             &__tracepoint_##name
>> +#endif
>> +
>>  /*
>>   * We have no guarantee that gcc and the linker won't up-align the tracepoint
>>   * structures, so we create an array of pointers that will be used for iteration
>> @@ -237,11 +250,9 @@ extern void syscall_unregfunc(void);
>>       static const char __tpstrtab_##name[]                            \
>>       __attribute__((section("__tracepoints_strings"))) = #name;       \
>>       struct tracepoint __tracepoint_##name                            \
>> -     __attribute__((section("__tracepoints"))) =                      \
>> +     __attribute__((section("__tracepoints"), used)) =                \
>>               { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
>> -     static struct tracepoint * const __tracepoint_ptr_##name __used  \
>> -     __attribute__((section("__tracepoints_ptrs"))) =                 \
>> -             &__tracepoint_##name;
>> +     __TRACEPOINT_ENTRY(name);
>>
>>  #define DEFINE_TRACE(name)                                           \
>>       DEFINE_TRACE_FN(name, NULL, NULL);
>> diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
>> index 685c50ae6300..1c6689603764 100644
>> --- a/kernel/tracepoint.c
>> +++ b/kernel/tracepoint.c
>> @@ -28,8 +28,8 @@
>>  #include <linux/sched/task.h>
>>  #include <linux/static_key.h>
>>
>> -extern struct tracepoint * const __start___tracepoints_ptrs[];
>> -extern struct tracepoint * const __stop___tracepoints_ptrs[];
>> +extern const unsigned char __start___tracepoints_ptrs[];
>> +extern const unsigned char __stop___tracepoints_ptrs[];
>
> Does this have to be converted to a char array?
>
>>
>>  /* Set to 1 to enable tracepoint debug output */
>>  static const int tracepoint_debug;
>> @@ -503,17 +503,26 @@ static __init int init_tracepoints(void)
>>  __initcall(init_tracepoints);
>>  #endif /* CONFIG_MODULES */
>>
>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> -             struct tracepoint * const *end,
>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>>               void (*fct)(struct tracepoint *tp, void *priv),
>>               void *priv)
>>  {
>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> +     const signed int *iter;
>> +
>> +     if (!begin)
>> +             return;
>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>
> Isn't the typecasts here sufficient, even if the above end is defined
> as a tracepoint * const *?
>

As long as iter's type is of the right size (4 bytes even on 64-bit
arches), then it does not really matter what type we use to define the
start and and of the array. It could be confusing, though, if anyone
tries to use those section markers elsewhere so perhaps I should move
them into the function in that case? Your call.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-14 15:29       ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-14 15:29 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton

On 14 August 2017 at 16:23, Steven Rostedt <rostedt@goodmis.org> wrote:
> On Mon, 14 Aug 2017 11:52:31 +0100
> Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
>> To avoid the need for relocating absolute references to tracepoint
>> structures at boot time when running relocatable kernels (which may
>> take a disproportionate amount of space), add the option to emit
>> these tables as relative references instead.
>>
>> Cc: Steven Rostedt <rostedt@goodmis.org>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>  include/linux/tracepoint.h | 19 +++++++++++++++----
>>  kernel/tracepoint.c        | 19 ++++++++++++++-----
>>  2 files changed, 29 insertions(+), 9 deletions(-)
>>
>> diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
>> index a26ffbe09e71..d02bf1a695e8 100644
>> --- a/include/linux/tracepoint.h
>> +++ b/include/linux/tracepoint.h
>> @@ -228,6 +228,19 @@ extern void syscall_unregfunc(void);
>>               return static_key_false(&__tracepoint_##name.key);      \
>>       }
>>
>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> +#define __TRACEPOINT_ENTRY(name)                                      \
>> +     asm("   .section \"__tracepoints_ptrs\", \"a\"               \n" \
>> +         "   .balign 4                                            \n" \
>> +         "   .long " VMLINUX_SYMBOL_STR(__tracepoint_##name) " - .\n" \
>> +         "   .previous                                            \n")
>> +#else
>> +#define __TRACEPOINT_ENTRY(name)                                      \
>> +     static struct tracepoint * const __tracepoint_ptr_##name __used  \
>> +     __attribute__((section("__tracepoints_ptrs"))) =                 \
>> +             &__tracepoint_##name
>> +#endif
>> +
>>  /*
>>   * We have no guarantee that gcc and the linker won't up-align the tracepoint
>>   * structures, so we create an array of pointers that will be used for iteration
>> @@ -237,11 +250,9 @@ extern void syscall_unregfunc(void);
>>       static const char __tpstrtab_##name[]                            \
>>       __attribute__((section("__tracepoints_strings"))) = #name;       \
>>       struct tracepoint __tracepoint_##name                            \
>> -     __attribute__((section("__tracepoints"))) =                      \
>> +     __attribute__((section("__tracepoints"), used)) =                \
>>               { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
>> -     static struct tracepoint * const __tracepoint_ptr_##name __used  \
>> -     __attribute__((section("__tracepoints_ptrs"))) =                 \
>> -             &__tracepoint_##name;
>> +     __TRACEPOINT_ENTRY(name);
>>
>>  #define DEFINE_TRACE(name)                                           \
>>       DEFINE_TRACE_FN(name, NULL, NULL);
>> diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
>> index 685c50ae6300..1c6689603764 100644
>> --- a/kernel/tracepoint.c
>> +++ b/kernel/tracepoint.c
>> @@ -28,8 +28,8 @@
>>  #include <linux/sched/task.h>
>>  #include <linux/static_key.h>
>>
>> -extern struct tracepoint * const __start___tracepoints_ptrs[];
>> -extern struct tracepoint * const __stop___tracepoints_ptrs[];
>> +extern const unsigned char __start___tracepoints_ptrs[];
>> +extern const unsigned char __stop___tracepoints_ptrs[];
>
> Does this have to be converted to a char array?
>
>>
>>  /* Set to 1 to enable tracepoint debug output */
>>  static const int tracepoint_debug;
>> @@ -503,17 +503,26 @@ static __init int init_tracepoints(void)
>>  __initcall(init_tracepoints);
>>  #endif /* CONFIG_MODULES */
>>
>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> -             struct tracepoint * const *end,
>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>>               void (*fct)(struct tracepoint *tp, void *priv),
>>               void *priv)
>>  {
>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> +     const signed int *iter;
>> +
>> +     if (!begin)
>> +             return;
>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>
> Isn't the typecasts here sufficient, even if the above end is defined
> as a tracepoint * const *?
>

As long as iter's type is of the right size (4 bytes even on 64-bit
arches), then it does not really matter what type we use to define the
start and and of the array. It could be confusing, though, if anyone
tries to use those section markers elsewhere so perhaps I should move
them into the function in that case? Your call.

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

* Re: [PATCH 0/5] add support for relative references in special sections
  2017-08-14 10:52 ` Ard Biesheuvel
@ 2017-08-18  5:56   ` Sergey Senozhatsky
  -1 siblings, 0 replies; 34+ messages in thread
From: Sergey Senozhatsky @ 2017-08-18  5:56 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

On (08/14/17 11:52), Ard Biesheuvel wrote:
> This adds support for emitting special sections such as initcall arrays,
> PCI fixups and tracepoints as relative references rather than absolute
> references. This reduces the size by 50% on 64-bit architectures, but
> more importantly, it removes the need for carrying relocation metadata
> for these sections in relocatables kernels (e.g., for KASLR) that need
> to fix up these absolute references at boot time. On arm64, this reduces
> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
> + 24 byte RELA entry vs 4 byte relative reference)
[..]

a side note,
checkpatch complaints quite a lot.

	-ss

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

* Re: [PATCH 0/5] add support for relative references in special sections
@ 2017-08-18  5:56   ` Sergey Senozhatsky
  0 siblings, 0 replies; 34+ messages in thread
From: Sergey Senozhatsky @ 2017-08-18  5:56 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt

On (08/14/17 11:52), Ard Biesheuvel wrote:
> This adds support for emitting special sections such as initcall arrays,
> PCI fixups and tracepoints as relative references rather than absolute
> references. This reduces the size by 50% on 64-bit architectures, but
> more importantly, it removes the need for carrying relocation metadata
> for these sections in relocatables kernels (e.g., for KASLR) that need
> to fix up these absolute references at boot time. On arm64, this reduces
> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
> + 24 byte RELA entry vs 4 byte relative reference)
[..]

a side note,
checkpatch complaints quite a lot.

	-ss

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

* Re: [PATCH 0/5] add support for relative references in special sections
  2017-08-18  5:56   ` Sergey Senozhatsky
@ 2017-08-18  6:12     ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  6:12 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

Hi Sergey,

Thanks for taking a look

On 18 August 2017 at 06:56, Sergey Senozhatsky
<sergey.senozhatsky.work@gmail.com> wrote:
> On (08/14/17 11:52), Ard Biesheuvel wrote:
>> This adds support for emitting special sections such as initcall arrays,
>> PCI fixups and tracepoints as relative references rather than absolute
>> references. This reduces the size by 50% on 64-bit architectures, but
>> more importantly, it removes the need for carrying relocation metadata
>> for these sections in relocatables kernels (e.g., for KASLR) that need
>> to fix up these absolute references at boot time. On arm64, this reduces
>> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
>> + 24 byte RELA entry vs 4 byte relative reference)
> [..]
>
> a side note,
> checkpatch complaints quite a lot.
>

Yeah, fair point. Many of them are debatable or completely bogus, though:

ERROR: "foo * bar" should be "foo *bar"
#114: FILE: include/linux/compiler.h:600:
+ static void * __attribute__((section(".discard.text"), used)) \

I think it is rather common to keep whitespace between * and what
follows if it is not the identifier.

ERROR: Macros with complex values should be enclosed in parentheses
#147: FILE: include/linux/export.h:64:
+#define __KSYMTAB_ENTRY(sym, sec) \
+ __ADDRESSABLE(sym) \
+ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
+    " .balign 8 \n" \
+    VMLINUX_SYMBOL_STR(__ksymtab_##sym) ": \n" \
+    " .long " VMLINUX_SYMBOL_STR(sym) "- . \n" \
+    " .long " VMLINUX_SYMBOL_STR(__kstrtab_##sym) "- .\n" \
+    " .previous \n")

WARNING: do not add new typedefs
#29: FILE: include/linux/init.h:114:
+typedef signed int initcall_entry_t;

WARNING: do not add new typedefs
#36: FILE: include/linux/init.h:121:
+typedef initcall_t initcall_entry_t;

This is a typedef that accompanies the existing typedef for
initcall_t, and it is the only way to parameterise this code without a
ton of changes to duplicate all extern declarations of initcall
arrays.

ERROR: Macros with multiple statements should be enclosed in a do - while loop
#55: FILE: include/linux/init.h:181:
+#define ___define_initcall(fn, id, __sec) \
+ __ADDRESSABLE(fn) \
+ asm(".section \"" #__sec ".init\", \"a\" \n" \
+ "__initcall_" #fn #id ": \n" \
+    ".long " VMLINUX_SYMBOL_STR(fn) " - . \n" \
+    ".previous \n");

This one is bogus. This macro is only used in file scope.

WARNING: externs should be avoided in .c files
#109: FILE: init/main.c:837:
+extern initcall_entry_t __initcall0_start[];

This changes the type of the existing initcall array declarations, and
I don't think moving them to a .h file for no other reason than to
appease checkpatch is pointless.

WARNING: unnecessary whitespace before a quoted newline
#63: FILE: include/linux/pci.h:1759:
+ asm(".section " #sec ", \"a\" \n" \

WARNING: unnecessary whitespace before a quoted newline
#64: FILE: include/linux/pci.h:1760:
+    ".balign 16 \n" \

WARNING: unnecessary whitespace before a quoted newline
#65: FILE: include/linux/pci.h:1761:
+    ".short " #vendor ", " #device " \n" \

These are not newlines that end up as strings in the program, and I
think it makes little sense to make the inline asm less readable by
putting the \n right after the text.

WARNING: braces {} are not necessary for single statement blocks
#83: FILE: kernel/tracepoint.c:515:
+ for (iter = begin; iter < (signed int *)end; iter++) {
+ fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
+ }

This simply mirrors the existing code in the other branch of the if ()

I will clean up the meaningful ones in v2, but please don't expect
this series to be checkpatch clean: it simply doesn't deal with inline
asm very well, and some of this code predates checkpatch by a decade,
and I'd rather not mix up rather tricky functional changes with
checkpatch cleanup duty.

-- 
Ard.

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

* Re: [PATCH 0/5] add support for relative references in special sections
@ 2017-08-18  6:12     ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  6:12 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton

Hi Sergey,

Thanks for taking a look

On 18 August 2017 at 06:56, Sergey Senozhatsky
<sergey.senozhatsky.work@gmail.com> wrote:
> On (08/14/17 11:52), Ard Biesheuvel wrote:
>> This adds support for emitting special sections such as initcall arrays,
>> PCI fixups and tracepoints as relative references rather than absolute
>> references. This reduces the size by 50% on 64-bit architectures, but
>> more importantly, it removes the need for carrying relocation metadata
>> for these sections in relocatables kernels (e.g., for KASLR) that need
>> to fix up these absolute references at boot time. On arm64, this reduces
>> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
>> + 24 byte RELA entry vs 4 byte relative reference)
> [..]
>
> a side note,
> checkpatch complaints quite a lot.
>

Yeah, fair point. Many of them are debatable or completely bogus, though:

ERROR: "foo * bar" should be "foo *bar"
#114: FILE: include/linux/compiler.h:600:
+ static void * __attribute__((section(".discard.text"), used)) \

I think it is rather common to keep whitespace between * and what
follows if it is not the identifier.

ERROR: Macros with complex values should be enclosed in parentheses
#147: FILE: include/linux/export.h:64:
+#define __KSYMTAB_ENTRY(sym, sec) \
+ __ADDRESSABLE(sym) \
+ asm(" .section \"___ksymtab" sec "+" #sym "\", \"a\" \n" \
+    " .balign 8 \n" \
+    VMLINUX_SYMBOL_STR(__ksymtab_##sym) ": \n" \
+    " .long " VMLINUX_SYMBOL_STR(sym) "- . \n" \
+    " .long " VMLINUX_SYMBOL_STR(__kstrtab_##sym) "- .\n" \
+    " .previous \n")

WARNING: do not add new typedefs
#29: FILE: include/linux/init.h:114:
+typedef signed int initcall_entry_t;

WARNING: do not add new typedefs
#36: FILE: include/linux/init.h:121:
+typedef initcall_t initcall_entry_t;

This is a typedef that accompanies the existing typedef for
initcall_t, and it is the only way to parameterise this code without a
ton of changes to duplicate all extern declarations of initcall
arrays.

ERROR: Macros with multiple statements should be enclosed in a do - while loop
#55: FILE: include/linux/init.h:181:
+#define ___define_initcall(fn, id, __sec) \
+ __ADDRESSABLE(fn) \
+ asm(".section \"" #__sec ".init\", \"a\" \n" \
+ "__initcall_" #fn #id ": \n" \
+    ".long " VMLINUX_SYMBOL_STR(fn) " - . \n" \
+    ".previous \n");

This one is bogus. This macro is only used in file scope.

WARNING: externs should be avoided in .c files
#109: FILE: init/main.c:837:
+extern initcall_entry_t __initcall0_start[];

This changes the type of the existing initcall array declarations, and
I don't think moving them to a .h file for no other reason than to
appease checkpatch is pointless.

WARNING: unnecessary whitespace before a quoted newline
#63: FILE: include/linux/pci.h:1759:
+ asm(".section " #sec ", \"a\" \n" \

WARNING: unnecessary whitespace before a quoted newline
#64: FILE: include/linux/pci.h:1760:
+    ".balign 16 \n" \

WARNING: unnecessary whitespace before a quoted newline
#65: FILE: include/linux/pci.h:1761:
+    ".short " #vendor ", " #device " \n" \

These are not newlines that end up as strings in the program, and I
think it makes little sense to make the inline asm less readable by
putting the \n right after the text.

WARNING: braces {} are not necessary for single statement blocks
#83: FILE: kernel/tracepoint.c:515:
+ for (iter = begin; iter < (signed int *)end; iter++) {
+ fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
+ }

This simply mirrors the existing code in the other branch of the if ()

I will clean up the meaningful ones in v2, but please don't expect
this series to be checkpatch clean: it simply doesn't deal with inline
asm very well, and some of this code predates checkpatch by a decade,
and I'd rather not mix up rather tricky functional changes with
checkpatch cleanup duty.

-- 
Ard.

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

* Re: [PATCH 0/5] add support for relative references in special sections
  2017-08-18  6:12     ` Ard Biesheuvel
@ 2017-08-18  6:29       ` Sergey Senozhatsky
  -1 siblings, 0 replies; 34+ messages in thread
From: Sergey Senozhatsky @ 2017-08-18  6:29 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Sergey Senozhatsky, linux-kernel, linux-arch, H. Peter Anvin,
	Arnd Bergmann, Heiko Carstens, Kees Cook, Will Deacon,
	Michael Ellerman, Thomas Garnier, Thomas Gleixner,
	Serge E. Hallyn, Bjorn Helgaas, Benjamin Herrenschmidt,
	Paul Mackerras, Catalin Marinas, Petr Mladek, Ingo Molnar,
	James Morris, Andrew Morton, Nicolas Pitre, Steven Rostedt,
	Martin Schwidefsky, Sergey Senozhatsky, Jessica Yu

Hi Ard,

On (08/18/17 07:12), Ard Biesheuvel wrote:
> Hi Sergey,
> 
> Thanks for taking a look
> 
> On 18 August 2017 at 06:56, Sergey Senozhatsky
> <sergey.senozhatsky.work@gmail.com> wrote:
> > On (08/14/17 11:52), Ard Biesheuvel wrote:
> >> This adds support for emitting special sections such as initcall arrays,
> >> PCI fixups and tracepoints as relative references rather than absolute
> >> references. This reduces the size by 50% on 64-bit architectures, but
> >> more importantly, it removes the need for carrying relocation metadata
> >> for these sections in relocatables kernels (e.g., for KASLR) that need
> >> to fix up these absolute references at boot time. On arm64, this reduces
> >> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
> >> + 24 byte RELA entry vs 4 byte relative reference)
> > [..]
> >
> > a side note,
> > checkpatch complaints quite a lot.
> >
[..]
> I will clean up the meaningful ones in v2, but please don't expect
> this series to be checkpatch clean: it simply doesn't deal with inline
> asm very well, and some of this code predates checkpatch by a decade,
> and I'd rather not mix up rather tricky functional changes with
> checkpatch cleanup duty.

sure. thanks.

I'm running two x86 boxes with the patch set applied, for
several days, with no issues being observed. it does save
some memory (well, several pages in my case) even on "tiny"
kernels configs.

	-ss

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

* Re: [PATCH 0/5] add support for relative references in special sections
@ 2017-08-18  6:29       ` Sergey Senozhatsky
  0 siblings, 0 replies; 34+ messages in thread
From: Sergey Senozhatsky @ 2017-08-18  6:29 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Sergey Senozhatsky, linux-kernel, linux-arch, H. Peter Anvin,
	Arnd Bergmann, Heiko Carstens, Kees Cook, Will Deacon,
	Michael Ellerman, Thomas Garnier, Thomas Gleixner,
	Serge E. Hallyn, Bjorn Helgaas, Benjamin Herrenschmidt,
	Paul Mackerras, Catalin Marinas, Petr Mladek, Ingo Molnar,
	James Morris

Hi Ard,

On (08/18/17 07:12), Ard Biesheuvel wrote:
> Hi Sergey,
> 
> Thanks for taking a look
> 
> On 18 August 2017 at 06:56, Sergey Senozhatsky
> <sergey.senozhatsky.work@gmail.com> wrote:
> > On (08/14/17 11:52), Ard Biesheuvel wrote:
> >> This adds support for emitting special sections such as initcall arrays,
> >> PCI fixups and tracepoints as relative references rather than absolute
> >> references. This reduces the size by 50% on 64-bit architectures, but
> >> more importantly, it removes the need for carrying relocation metadata
> >> for these sections in relocatables kernels (e.g., for KASLR) that need
> >> to fix up these absolute references at boot time. On arm64, this reduces
> >> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
> >> + 24 byte RELA entry vs 4 byte relative reference)
> > [..]
> >
> > a side note,
> > checkpatch complaints quite a lot.
> >
[..]
> I will clean up the meaningful ones in v2, but please don't expect
> this series to be checkpatch clean: it simply doesn't deal with inline
> asm very well, and some of this code predates checkpatch by a decade,
> and I'd rather not mix up rather tricky functional changes with
> checkpatch cleanup duty.

sure. thanks.

I'm running two x86 boxes with the patch set applied, for
several days, with no issues being observed. it does save
some memory (well, several pages in my case) even on "tiny"
kernels configs.

	-ss

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

* Re: [PATCH 0/5] add support for relative references in special sections
  2017-08-18  6:29       ` Sergey Senozhatsky
@ 2017-08-18  6:33         ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  6:33 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

On 18 August 2017 at 07:29, Sergey Senozhatsky
<sergey.senozhatsky.work@gmail.com> wrote:
> Hi Ard,
>
> On (08/18/17 07:12), Ard Biesheuvel wrote:
>> Hi Sergey,
>>
>> Thanks for taking a look
>>
>> On 18 August 2017 at 06:56, Sergey Senozhatsky
>> <sergey.senozhatsky.work@gmail.com> wrote:
>> > On (08/14/17 11:52), Ard Biesheuvel wrote:
>> >> This adds support for emitting special sections such as initcall arrays,
>> >> PCI fixups and tracepoints as relative references rather than absolute
>> >> references. This reduces the size by 50% on 64-bit architectures, but
>> >> more importantly, it removes the need for carrying relocation metadata
>> >> for these sections in relocatables kernels (e.g., for KASLR) that need
>> >> to fix up these absolute references at boot time. On arm64, this reduces
>> >> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
>> >> + 24 byte RELA entry vs 4 byte relative reference)
>> > [..]
>> >
>> > a side note,
>> > checkpatch complaints quite a lot.
>> >
> [..]
>> I will clean up the meaningful ones in v2, but please don't expect
>> this series to be checkpatch clean: it simply doesn't deal with inline
>> asm very well, and some of this code predates checkpatch by a decade,
>> and I'd rather not mix up rather tricky functional changes with
>> checkpatch cleanup duty.
>
> sure. thanks.
>
> I'm running two x86 boxes with the patch set applied, for
> several days, with no issues being observed. it does save
> some memory (well, several pages in my case) even on "tiny"
> kernels configs.
>

That is good to hear. Thanks.

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

* Re: [PATCH 0/5] add support for relative references in special sections
@ 2017-08-18  6:33         ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  6:33 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton

On 18 August 2017 at 07:29, Sergey Senozhatsky
<sergey.senozhatsky.work@gmail.com> wrote:
> Hi Ard,
>
> On (08/18/17 07:12), Ard Biesheuvel wrote:
>> Hi Sergey,
>>
>> Thanks for taking a look
>>
>> On 18 August 2017 at 06:56, Sergey Senozhatsky
>> <sergey.senozhatsky.work@gmail.com> wrote:
>> > On (08/14/17 11:52), Ard Biesheuvel wrote:
>> >> This adds support for emitting special sections such as initcall arrays,
>> >> PCI fixups and tracepoints as relative references rather than absolute
>> >> references. This reduces the size by 50% on 64-bit architectures, but
>> >> more importantly, it removes the need for carrying relocation metadata
>> >> for these sections in relocatables kernels (e.g., for KASLR) that need
>> >> to fix up these absolute references at boot time. On arm64, this reduces
>> >> the vmlinux footprint of such a reference by 8x (8 byte absolute reference
>> >> + 24 byte RELA entry vs 4 byte relative reference)
>> > [..]
>> >
>> > a side note,
>> > checkpatch complaints quite a lot.
>> >
> [..]
>> I will clean up the meaningful ones in v2, but please don't expect
>> this series to be checkpatch clean: it simply doesn't deal with inline
>> asm very well, and some of this code predates checkpatch by a decade,
>> and I'd rather not mix up rather tricky functional changes with
>> checkpatch cleanup duty.
>
> sure. thanks.
>
> I'm running two x86 boxes with the patch set applied, for
> several days, with no issues being observed. it does save
> some memory (well, several pages in my case) even on "tiny"
> kernels configs.
>

That is good to hear. Thanks.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-14 10:52   ` Ard Biesheuvel
@ 2017-08-18  8:26     ` Ingo Molnar
  -1 siblings, 0 replies; 34+ messages in thread
From: Ingo Molnar @ 2017-08-18  8:26 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu


* Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
> -		struct tracepoint * const *end,
> +static void for_each_tracepoint_range(const void *begin, const void *end,
>  		void (*fct)(struct tracepoint *tp, void *priv),
>  		void *priv)
>  {
> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> +	const signed int *iter;
> +
> +	if (!begin)
> +		return;
> +	for (iter = begin; iter < (signed int *)end; iter++) {
> +		fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
> +	}

I think checkpatch is correct here to complain about the unnecessary curly braces 
here.

Plus why the heavy use of 'signed int' here and elsewhere in the patches - why 
not 'int' ?

Plus #2, the heavy use of type casts looks pretty ugly to begin with - is there no 
way to turn this into more natural code?

Thanks,

	Ingo

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-18  8:26     ` Ingo Molnar
  0 siblings, 0 replies; 34+ messages in thread
From: Ingo Molnar @ 2017-08-18  8:26 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt


* Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
> -		struct tracepoint * const *end,
> +static void for_each_tracepoint_range(const void *begin, const void *end,
>  		void (*fct)(struct tracepoint *tp, void *priv),
>  		void *priv)
>  {
> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> +	const signed int *iter;
> +
> +	if (!begin)
> +		return;
> +	for (iter = begin; iter < (signed int *)end; iter++) {
> +		fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
> +	}

I think checkpatch is correct here to complain about the unnecessary curly braces 
here.

Plus why the heavy use of 'signed int' here and elsewhere in the patches - why 
not 'int' ?

Plus #2, the heavy use of type casts looks pretty ugly to begin with - is there no 
way to turn this into more natural code?

Thanks,

	Ingo

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-18  8:26     ` Ingo Molnar
@ 2017-08-18  8:36       ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  8:36 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
>
> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> -             struct tracepoint * const *end,
>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>>               void (*fct)(struct tracepoint *tp, void *priv),
>>               void *priv)
>>  {
>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> +     const signed int *iter;
>> +
>> +     if (!begin)
>> +             return;
>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
>> +     }
>
> I think checkpatch is correct here to complain about the unnecessary curly braces
> here.
>

Fair enough. I will clean up to the extent feasible.

> Plus why the heavy use of 'signed int' here and elsewhere in the patches - why
> not 'int' ?
>

Yes, just 'int' should be sufficient. Force of habit, I suppose, given
that unqualified 'char' is ambiguous between architectures, but this
does not apply to 'int' of course.

> Plus #2, the heavy use of type casts looks pretty ugly to begin with - is there no
> way to turn this into more natural code?
>

Actually, Steven requested to keep the tracepoint section markers as
they are, and cast them to (int *) in the conditionally compiled
PREL32 case. So I guess it is a matter of taste, but because the types
are fundamentally incompatible when this code is in effect (and the
size of the pointed-to type differs on 64-bit architectures), there is
always some mangling required.

The initcall patch is probably the cleanest in this regard, but
involves typedefs, which are frowned upon as well.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-18  8:36       ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  8:36 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton

On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
>
> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> -             struct tracepoint * const *end,
>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>>               void (*fct)(struct tracepoint *tp, void *priv),
>>               void *priv)
>>  {
>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> +     const signed int *iter;
>> +
>> +     if (!begin)
>> +             return;
>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
>> +     }
>
> I think checkpatch is correct here to complain about the unnecessary curly braces
> here.
>

Fair enough. I will clean up to the extent feasible.

> Plus why the heavy use of 'signed int' here and elsewhere in the patches - why
> not 'int' ?
>

Yes, just 'int' should be sufficient. Force of habit, I suppose, given
that unqualified 'char' is ambiguous between architectures, but this
does not apply to 'int' of course.

> Plus #2, the heavy use of type casts looks pretty ugly to begin with - is there no
> way to turn this into more natural code?
>

Actually, Steven requested to keep the tracepoint section markers as
they are, and cast them to (int *) in the conditionally compiled
PREL32 case. So I guess it is a matter of taste, but because the types
are fundamentally incompatible when this code is in effect (and the
size of the pointed-to type differs on 64-bit architectures), there is
always some mangling required.

The initcall patch is probably the cleanest in this regard, but
involves typedefs, which are frowned upon as well.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-18  8:36       ` Ard Biesheuvel
@ 2017-08-18  9:24         ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  9:24 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

On 18 August 2017 at 09:36, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
>>
>> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>
>>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>>> -             struct tracepoint * const *end,
>>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>>>               void (*fct)(struct tracepoint *tp, void *priv),
>>>               void *priv)
>>>  {
>>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>>> +     const signed int *iter;
>>> +
>>> +     if (!begin)
>>> +             return;
>>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
>>> +     }
>>
>> I think checkpatch is correct here to complain about the unnecessary curly braces
>> here.
>>
>
> Fair enough. I will clean up to the extent feasible.
>

OK, in an honest attempt to at least remove as many of the checkpatch
errors as I can, I am running into the paradoxical situation where I
either get

ERROR: space required after that ',' (ctx:VxO)
#83: FILE: include/linux/init.h:232:
+#define console_initcall(fn) ___define_initcall(fn,, .con_initcall)

or

ERROR: space prohibited before that ',' (ctx:WxW)
#156: FILE: include/linux/init.h:232:
+#define console_initcall(fn) ___define_initcall(fn, , .con_initcall)
                                                    ^
which I think may be checkpatch trying to give me a hint that I have
done enough work for the week, and should spend some time by the pool
instead.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-18  9:24         ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18  9:24 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton

On 18 August 2017 at 09:36, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
>>
>> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>
>>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>>> -             struct tracepoint * const *end,
>>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>>>               void (*fct)(struct tracepoint *tp, void *priv),
>>>               void *priv)
>>>  {
>>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>>> +     const signed int *iter;
>>> +
>>> +     if (!begin)
>>> +             return;
>>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
>>> +     }
>>
>> I think checkpatch is correct here to complain about the unnecessary curly braces
>> here.
>>
>
> Fair enough. I will clean up to the extent feasible.
>

OK, in an honest attempt to at least remove as many of the checkpatch
errors as I can, I am running into the paradoxical situation where I
either get

ERROR: space required after that ',' (ctx:VxO)
#83: FILE: include/linux/init.h:232:
+#define console_initcall(fn) ___define_initcall(fn,, .con_initcall)

or

ERROR: space prohibited before that ',' (ctx:WxW)
#156: FILE: include/linux/init.h:232:
+#define console_initcall(fn) ___define_initcall(fn, , .con_initcall)
                                                    ^
which I think may be checkpatch trying to give me a hint that I have
done enough work for the week, and should spend some time by the pool
instead.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-18  9:24         ` Ard Biesheuvel
@ 2017-08-18 17:58           ` Ingo Molnar
  -1 siblings, 0 replies; 34+ messages in thread
From: Ingo Molnar @ 2017-08-18 17:58 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu


* Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> On 18 August 2017 at 09:36, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> > On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
> >>
> >> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> >>
> >>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
> >>> -             struct tracepoint * const *end,
> >>> +static void for_each_tracepoint_range(const void *begin, const void *end,
> >>>               void (*fct)(struct tracepoint *tp, void *priv),
> >>>               void *priv)
> >>>  {
> >>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> >>> +     const signed int *iter;
> >>> +
> >>> +     if (!begin)
> >>> +             return;
> >>> +     for (iter = begin; iter < (signed int *)end; iter++) {
> >>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
> >>> +     }
> >>
> >> I think checkpatch is correct here to complain about the unnecessary curly braces
> >> here.
> >>
> >
> > Fair enough. I will clean up to the extent feasible.
> >
> 
> OK, in an honest attempt to at least remove as many of the checkpatch
> errors as I can,  [...]

Note that I actually agreed with your list of checkpatch bogosities - the one I 
commented on was the only thing that needed fixing, IMHO.

Thanks,

	Ingo

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-18 17:58           ` Ingo Molnar
  0 siblings, 0 replies; 34+ messages in thread
From: Ingo Molnar @ 2017-08-18 17:58 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton


* Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:

> On 18 August 2017 at 09:36, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> > On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
> >>
> >> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> >>
> >>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
> >>> -             struct tracepoint * const *end,
> >>> +static void for_each_tracepoint_range(const void *begin, const void *end,
> >>>               void (*fct)(struct tracepoint *tp, void *priv),
> >>>               void *priv)
> >>>  {
> >>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
> >>> +     const signed int *iter;
> >>> +
> >>> +     if (!begin)
> >>> +             return;
> >>> +     for (iter = begin; iter < (signed int *)end; iter++) {
> >>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
> >>> +     }
> >>
> >> I think checkpatch is correct here to complain about the unnecessary curly braces
> >> here.
> >>
> >
> > Fair enough. I will clean up to the extent feasible.
> >
> 
> OK, in an honest attempt to at least remove as many of the checkpatch
> errors as I can,  [...]

Note that I actually agreed with your list of checkpatch bogosities - the one I 
commented on was the only thing that needed fixing, IMHO.

Thanks,

	Ingo

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
  2017-08-18 17:58           ` Ingo Molnar
@ 2017-08-18 18:17             ` Ard Biesheuvel
  -1 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18 18:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton,
	Nicolas Pitre, Steven Rostedt, Martin Schwidefsky,
	Sergey Senozhatsky, Jessica Yu

On 18 August 2017 at 18:58, Ingo Molnar <mingo@kernel.org> wrote:
>
> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
>> On 18 August 2017 at 09:36, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>> > On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
>> >>
>> >> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>> >>
>> >>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> >>> -             struct tracepoint * const *end,
>> >>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>> >>>               void (*fct)(struct tracepoint *tp, void *priv),
>> >>>               void *priv)
>> >>>  {
>> >>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> >>> +     const signed int *iter;
>> >>> +
>> >>> +     if (!begin)
>> >>> +             return;
>> >>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>> >>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
>> >>> +     }
>> >>
>> >> I think checkpatch is correct here to complain about the unnecessary curly braces
>> >> here.
>> >>
>> >
>> > Fair enough. I will clean up to the extent feasible.
>> >
>>
>> OK, in an honest attempt to at least remove as many of the checkpatch
>> errors as I can,  [...]
>
> Note that I actually agreed with your list of checkpatch bogosities - the one I
> commented on was the only thing that needed fixing, IMHO.
>

Ah ok. Well, I think the code has improved slightly in some ways as a
result, so I will just back out the bogus changes for v3.

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

* Re: [PATCH 5/5] kernel: tracepoints: add support for relative references
@ 2017-08-18 18:17             ` Ard Biesheuvel
  0 siblings, 0 replies; 34+ messages in thread
From: Ard Biesheuvel @ 2017-08-18 18:17 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, linux-arch, H. Peter Anvin, Arnd Bergmann,
	Heiko Carstens, Kees Cook, Will Deacon, Michael Ellerman,
	Thomas Garnier, Thomas Gleixner, Serge E. Hallyn, Bjorn Helgaas,
	Benjamin Herrenschmidt, Paul Mackerras, Catalin Marinas,
	Petr Mladek, Ingo Molnar, James Morris, Andrew Morton

On 18 August 2017 at 18:58, Ingo Molnar <mingo@kernel.org> wrote:
>
> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>
>> On 18 August 2017 at 09:36, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>> > On 18 August 2017 at 09:26, Ingo Molnar <mingo@kernel.org> wrote:
>> >>
>> >> * Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>> >>
>> >>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> >>> -             struct tracepoint * const *end,
>> >>> +static void for_each_tracepoint_range(const void *begin, const void *end,
>> >>>               void (*fct)(struct tracepoint *tp, void *priv),
>> >>>               void *priv)
>> >>>  {
>> >>> +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
>> >>> +     const signed int *iter;
>> >>> +
>> >>> +     if (!begin)
>> >>> +             return;
>> >>> +     for (iter = begin; iter < (signed int *)end; iter++) {
>> >>> +             fct((struct tracepoint *)((unsigned long)iter + *iter), priv);
>> >>> +     }
>> >>
>> >> I think checkpatch is correct here to complain about the unnecessary curly braces
>> >> here.
>> >>
>> >
>> > Fair enough. I will clean up to the extent feasible.
>> >
>>
>> OK, in an honest attempt to at least remove as many of the checkpatch
>> errors as I can,  [...]
>
> Note that I actually agreed with your list of checkpatch bogosities - the one I
> commented on was the only thing that needed fixing, IMHO.
>

Ah ok. Well, I think the code has improved slightly in some ways as a
result, so I will just back out the bogus changes for v3.

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

end of thread, other threads:[~2017-08-18 18:18 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-14 10:52 [PATCH 0/5] add support for relative references in special sections Ard Biesheuvel
2017-08-14 10:52 ` Ard Biesheuvel
2017-08-14 10:52 ` [PATCH 1/5] arch: enable relative relocations for arm64, power, x86, s390 and x86 Ard Biesheuvel
2017-08-14 10:52   ` Ard Biesheuvel
2017-08-14 10:52 ` [PATCH 2/5] module: use relative references for __ksymtab entries Ard Biesheuvel
2017-08-14 10:52   ` Ard Biesheuvel
2017-08-14 10:52 ` [PATCH 3/5] init: allow initcall tables to be emitted using relative references Ard Biesheuvel
2017-08-14 10:52   ` Ard Biesheuvel
2017-08-14 10:52 ` [PATCH 4/5] drivers: pci: add support for relative addressing in quirk tables Ard Biesheuvel
2017-08-14 10:52   ` Ard Biesheuvel
2017-08-14 10:52 ` [PATCH 5/5] kernel: tracepoints: add support for relative references Ard Biesheuvel
2017-08-14 10:52   ` Ard Biesheuvel
2017-08-14 15:23   ` Steven Rostedt
2017-08-14 15:23     ` Steven Rostedt
2017-08-14 15:29     ` Ard Biesheuvel
2017-08-14 15:29       ` Ard Biesheuvel
2017-08-18  8:26   ` Ingo Molnar
2017-08-18  8:26     ` Ingo Molnar
2017-08-18  8:36     ` Ard Biesheuvel
2017-08-18  8:36       ` Ard Biesheuvel
2017-08-18  9:24       ` Ard Biesheuvel
2017-08-18  9:24         ` Ard Biesheuvel
2017-08-18 17:58         ` Ingo Molnar
2017-08-18 17:58           ` Ingo Molnar
2017-08-18 18:17           ` Ard Biesheuvel
2017-08-18 18:17             ` Ard Biesheuvel
2017-08-18  5:56 ` [PATCH 0/5] add support for relative references in special sections Sergey Senozhatsky
2017-08-18  5:56   ` Sergey Senozhatsky
2017-08-18  6:12   ` Ard Biesheuvel
2017-08-18  6:12     ` Ard Biesheuvel
2017-08-18  6:29     ` Sergey Senozhatsky
2017-08-18  6:29       ` Sergey Senozhatsky
2017-08-18  6:33       ` Ard Biesheuvel
2017-08-18  6:33         ` Ard Biesheuvel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.