linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Will Deacon <will.deacon@arm.com>
Subject: [PATCH 4.14 34/95] arm64: ftrace: emit ftrace-mod.o contents through code
Date: Mon,  4 Dec 2017 16:59:58 +0100	[thread overview]
Message-ID: <20171204160047.545387281@linuxfoundation.org> (raw)
In-Reply-To: <20171204160046.206920966@linuxfoundation.org>

4.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Ard Biesheuvel <ard.biesheuvel@linaro.org>

commit be0f272bfc83797f70d44faca86954df62e2bbc0 upstream.

When building the arm64 kernel with both CONFIG_ARM64_MODULE_PLTS and
CONFIG_DYNAMIC_FTRACE enabled, the ftrace-mod.o object file is built
with the kernel and contains a trampoline that is linked into each
module, so that modules can be loaded far away from the kernel and
still reach the ftrace entry point in the core kernel with an ordinary
relative branch, as is emitted by the compiler instrumentation code
dynamic ftrace relies on.

In order to be able to build out of tree modules, this object file
needs to be included into the linux-headers or linux-devel packages,
which is undesirable, as it makes arm64 a special case (although a
precedent does exist for 32-bit PPC).

Given that the trampoline essentially consists of a PLT entry, let's
not bother with a source or object file for it, and simply patch it
in whenever the trampoline is being populated, using the existing
PLT support routines.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/arm64/Makefile             |    3 ---
 arch/arm64/include/asm/module.h |    2 +-
 arch/arm64/kernel/Makefile      |    3 ---
 arch/arm64/kernel/ftrace-mod.S  |   18 ------------------
 arch/arm64/kernel/ftrace.c      |   14 ++++++++------
 arch/arm64/kernel/module-plts.c |   12 ++++++++++++
 arch/arm64/kernel/module.lds    |    1 +
 7 files changed, 22 insertions(+), 31 deletions(-)

--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -77,9 +77,6 @@ endif
 
 ifeq ($(CONFIG_ARM64_MODULE_PLTS),y)
 KBUILD_LDFLAGS_MODULE	+= -T $(srctree)/arch/arm64/kernel/module.lds
-ifeq ($(CONFIG_DYNAMIC_FTRACE),y)
-KBUILD_LDFLAGS_MODULE	+= $(objtree)/arch/arm64/kernel/ftrace-mod.o
-endif
 endif
 
 # Default value
--- a/arch/arm64/include/asm/module.h
+++ b/arch/arm64/include/asm/module.h
@@ -32,7 +32,7 @@ struct mod_arch_specific {
 	struct mod_plt_sec	init;
 
 	/* for CONFIG_DYNAMIC_FTRACE */
-	void			*ftrace_trampoline;
+	struct plt_entry 	*ftrace_trampoline;
 };
 #endif
 
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -63,6 +63,3 @@ extra-y					+= $(head-y) vmlinux.lds
 ifeq ($(CONFIG_DEBUG_EFI),y)
 AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\""
 endif
-
-# will be included by each individual module but not by the core kernel itself
-extra-$(CONFIG_DYNAMIC_FTRACE) += ftrace-mod.o
--- a/arch/arm64/kernel/ftrace-mod.S
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright (C) 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/linkage.h>
-#include <asm/assembler.h>
-
-	.section	".text.ftrace_trampoline", "ax"
-	.align		3
-0:	.quad		0
-__ftrace_trampoline:
-	ldr		x16, 0b
-	br		x16
-ENDPROC(__ftrace_trampoline)
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -76,7 +76,7 @@ int ftrace_make_call(struct dyn_ftrace *
 
 	if (offset < -SZ_128M || offset >= SZ_128M) {
 #ifdef CONFIG_ARM64_MODULE_PLTS
-		unsigned long *trampoline;
+		struct plt_entry trampoline;
 		struct module *mod;
 
 		/*
@@ -104,22 +104,24 @@ int ftrace_make_call(struct dyn_ftrace *
 		 * is added in the future, but for now, the pr_err() below
 		 * deals with a theoretical issue only.
 		 */
-		trampoline = (unsigned long *)mod->arch.ftrace_trampoline;
-		if (trampoline[0] != addr) {
-			if (trampoline[0] != 0) {
+		trampoline = get_plt_entry(addr);
+		if (!plt_entries_equal(mod->arch.ftrace_trampoline,
+				       &trampoline)) {
+			if (!plt_entries_equal(mod->arch.ftrace_trampoline,
+					       &(struct plt_entry){})) {
 				pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n");
 				return -EINVAL;
 			}
 
 			/* point the trampoline to our ftrace entry point */
 			module_disable_ro(mod);
-			trampoline[0] = addr;
+			*mod->arch.ftrace_trampoline = trampoline;
 			module_enable_ro(mod, true);
 
 			/* update trampoline before patching in the branch */
 			smp_wmb();
 		}
-		addr = (unsigned long)&trampoline[1];
+		addr = (unsigned long)(void *)mod->arch.ftrace_trampoline;
 #else /* CONFIG_ARM64_MODULE_PLTS */
 		return -EINVAL;
 #endif /* CONFIG_ARM64_MODULE_PLTS */
--- a/arch/arm64/kernel/module-plts.c
+++ b/arch/arm64/kernel/module-plts.c
@@ -120,6 +120,7 @@ int module_frob_arch_sections(Elf_Ehdr *
 	unsigned long core_plts = 0;
 	unsigned long init_plts = 0;
 	Elf64_Sym *syms = NULL;
+	Elf_Shdr *tramp = NULL;
 	int i;
 
 	/*
@@ -131,6 +132,10 @@ int module_frob_arch_sections(Elf_Ehdr *
 			mod->arch.core.plt = sechdrs + i;
 		else if (!strcmp(secstrings + sechdrs[i].sh_name, ".init.plt"))
 			mod->arch.init.plt = sechdrs + i;
+		else if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) &&
+			 !strcmp(secstrings + sechdrs[i].sh_name,
+				 ".text.ftrace_trampoline"))
+			tramp = sechdrs + i;
 		else if (sechdrs[i].sh_type == SHT_SYMTAB)
 			syms = (Elf64_Sym *)sechdrs[i].sh_addr;
 	}
@@ -181,5 +186,12 @@ int module_frob_arch_sections(Elf_Ehdr *
 	mod->arch.init.plt_num_entries = 0;
 	mod->arch.init.plt_max_entries = init_plts;
 
+	if (tramp) {
+		tramp->sh_type = SHT_NOBITS;
+		tramp->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
+		tramp->sh_addralign = __alignof__(struct plt_entry);
+		tramp->sh_size = sizeof(struct plt_entry);
+	}
+
 	return 0;
 }
--- a/arch/arm64/kernel/module.lds
+++ b/arch/arm64/kernel/module.lds
@@ -1,4 +1,5 @@
 SECTIONS {
 	.plt (NOLOAD) : { BYTE(0) }
 	.init.plt (NOLOAD) : { BYTE(0) }
+	.text.ftrace_trampoline (NOLOAD) : { BYTE(0) }
 }

  parent reply	other threads:[~2017-12-04 16:17 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04 15:59 [PATCH 4.14 00/95] 4.14.4-stable review Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 02/95] mm, memory_hotplug: do not back off draining pcp free pages from kworker context Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 03/95] mm, oom_reaper: gather each vma to prevent leaking TLB entry Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 04/95] mm, thp: Do not make page table dirty unconditionally in touch_p[mu]d() Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 05/95] mm/cma: fix alloc_contig_range ret code/potential leak Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 06/95] mm: fix device-dax pud write-faults triggered by get_user_pages() Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 07/95] mm, hugetlbfs: introduce ->split() to vm_operations_struct Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 08/95] device-dax: implement ->split() to catch invalid munmap attempts Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 09/95] mm: introduce get_user_pages_longterm Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 10/95] mm: fail get_vaddr_frames() for filesystem-dax mappings Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 11/95] v4l2: disable filesystem-dax mapping support Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 12/95] IB/core: disable memory registration of filesystem-dax vmas Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 13/95] exec: avoid RLIMIT_STACK races with prlimit() Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 14/95] mm/madvise.c: fix madvise() infinite loop under special circumstances Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 16/95] mm, memcg: fix mem_cgroup_swapout() for THPs Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 17/95] fs/fat/inode.c: fix sb_rdonly() change Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 18/95] autofs: revert "autofs: take more care to not update last_used on path walk" Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 19/95] autofs: revert "autofs: fix AT_NO_AUTOMOUNT not being honored" Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 20/95] mm/hugetlb: fix NULL-pointer dereference on 5-level paging machine Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 21/95] btrfs: clear space cache inode generation always Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 22/95] nfsd: Fix stateid races between OPEN and CLOSE Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 23/95] nfsd: Fix another OPEN stateid race Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 24/95] nfsd: fix panic in posix_unblock_lock called from nfs4_laundromat Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 25/95] crypto: algif_aead - skip SGL entries with NULL page Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 26/95] crypto: af_alg - remove locking in async callback Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 28/95] lockd: lost rollback of set_grace_period() in lockd_down_net() Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 29/95] s390: revert ELF_ET_DYN_BASE base changes Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 30/95] drm: omapdrm: Fix DPI on platforms using the DSI VDDS Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 31/95] omapdrm: hdmi4: Correct the SoC revision matching Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 32/95] apparmor: fix oops in audit_signal_cb hook Greg Kroah-Hartman
2017-12-04 15:59 ` [PATCH 4.14 33/95] arm64: module-plts: factor out PLT generation code for ftrace Greg Kroah-Hartman
2017-12-04 15:59 ` Greg Kroah-Hartman [this message]
2017-12-04 15:59 ` [PATCH 4.14 35/95] powerpc/powernv: Fix kexec crashes caused by tlbie tracing Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 36/95] powerpc/kexec: Fix kexec/kdump in P9 guest kernels Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 40/95] KVM: lapic: Split out x2apic ldr calculation Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 41/95] KVM: lapic: Fixup LDR on load in x2apic Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 42/95] mmc: sdhci: Avoid swiotlb buffer being full Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 43/95] mmc: block: Fix missing blk_put_request() Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 44/95] mmc: block: Check return value of blk_get_request() Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 45/95] mmc: core: Do not leave the block driver in a suspended state Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 46/95] mmc: block: Ensure that debugfs files are removed Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 47/95] mmc: core: prepend 0x to pre_eol_info entry in sysfs Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 48/95] mmc: core: prepend 0x to OCR " Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 49/95] ACPI / EC: Fix regression related to PM ops support in ECDT device Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 50/95] eeprom: at24: fix reading from 24MAC402/24MAC602 Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 51/95] eeprom: at24: correctly set the size for at24mac402 Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 52/95] eeprom: at24: check at24_read/write arguments Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 53/95] i2c: i801: Fix Failed to allocate irq -2147483648 error Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 54/95] cxl: Check if vphb exists before iterating over AFU devices Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 55/95] bcache: Fix building error on MIPS Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 56/95] bcache: only permit to recovery read error when cache device is clean Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 57/95] bcache: recover data from backing when data " Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 58/95] hwmon: (jc42) optionally try to disable the SMBUS timeout Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 59/95] nvme-pci: add quirk for delay before CHK RDY for WDC SN200 Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 63/95] drm/amdgpu: correct reference clock value on vega10 Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 65/95] drm/amdgpu: Properly allocate VM invalidate eng v2 Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 66/95] drm/amdgpu: Remove check which is not valid for certain VBIOS Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 73/95] drm/tilcdc: Precalculate total frametime in tilcdc_crtc_set_mode() Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 74/95] drm/radeon: fix atombios on big endian Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 75/95] drm/panel: simple: Add missing panel_simple_unprepare() calls Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 76/95] drm/hisilicon: Ensure LDI regs are properly configured Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 78/95] drm/amd/pp: fix typecast error in powerplay Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 79/95] drm/fb_helper: Disable all crtcs when initial setup fails Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 80/95] drm/fsl-dcu: Dont set connector DPMS property Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 84/95] include/linux/compiler-clang.h: handle randomizable anonymous structs Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 85/95] IB/core: Do not warn on lid conversions for OPA Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 86/95] IB/hfi1: " Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 87/95] e1000e: fix the use of magic numbers for buffer overrun issue Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 88/95] md: forbid a RAID5 from having both a bitmap and a journal Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 89/95] drm/i915: Fix false-positive assert_rpm_wakelock_held in i915_pmic_bus_access_notifier v2 Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 90/95] drm/i915: Re-register PMIC bus access notifier on runtime resume Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 91/95] drm/i915/fbdev: Serialise early hotplug events with async fbdev config Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 92/95] drm/i915/gvt: Correct ADDR_4K/2M/1G_MASK definition Greg Kroah-Hartman
2017-12-04 16:00 ` [PATCH 4.14 95/95] Revert "x86/entry/64: Add missing irqflags tracing to native_load_gs_index()" Greg Kroah-Hartman
2017-12-04 20:29 ` [PATCH 4.14 00/95] 4.14.4-stable review Shuah Khan
2017-12-05  6:25   ` Greg Kroah-Hartman
2017-12-04 21:12 ` Tom Gall
2017-12-05  6:24   ` Greg Kroah-Hartman
2017-12-05 21:45     ` Tom Gall
2017-12-06  6:49       ` Greg Kroah-Hartman
2017-12-06  6:51         ` Greg Kroah-Hartman
2017-12-06 18:01         ` Tom Gall
2017-12-07  7:49           ` Greg Kroah-Hartman
2017-12-06 14:41     ` Sumit Semwal
2017-12-06 15:33       ` Greg Kroah-Hartman
2017-12-06 15:39         ` Sumit Semwal
2017-12-04 23:46 ` Guenter Roeck
2017-12-05  6:24   ` Greg Kroah-Hartman
2017-12-05  7:01 ` Naresh Kamboju
2017-12-05  7:50   ` Greg Kroah-Hartman

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20171204160047.545387281@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).