From patchwork Fri Aug 18 11:26:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110372 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780323qge; Fri, 18 Aug 2017 04:26:55 -0700 (PDT) X-Received: by 10.98.16.14 with SMTP id y14mr8651140pfi.64.1503055615097; Fri, 18 Aug 2017 04:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055615; cv=none; d=google.com; s=arc-20160816; b=ZaHAHESR05YT4J4wpUn8ouhI46OheuxUEj1To/y/YxTl6GFsfsVXqVErFmZ0SxV1xT Y8nRDnJns8ySQTqDiB+7Ww7ata4baPLKrX+0H9xLI3uM2AAMUKJNicGj6Gx1M4NpOekp vuWiv2uzn9OJYB27Nk/pIOfUlhdRIfpirWLPBBKwE5t4/7cALZbt6PNtEk/MdVh6lvf6 WQpdQGufNZPJLp2qTCn7NkBjGCIFlj6+p5UgD6Wes3wX3kMoJvkyFgVq2+l8SIcYaIWK DwkKzWkz5oshVHKF+szyFlnJPr87nAbkc5O5VfKCGdyx6ZVdpySR5NI01Ck4vlV4I7xp 0iow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=WpAB7m7CyEA9tmJ5QoBPu6wS8zGT6hzTjbT0E6oPCtY=; b=Qrqv22ZEcg0yub9/8R1l9QoRrR2Nra85QO61iHX8XDa+XR3E5DNM8h5VJCPUFwfMoQ tDodUgHr7EBYWmgrJhSsHklUy67uFu91my4Iky6gnrM2RgWUxSQdc4aEl1pCnzzeaOe1 UX21tIbs9iz94xgoQCmuTtKO1/oEOMhx3LidSDxIKistczpkgm2K0+081K8o4/qEp9XT afbeaj9jgRhzfCf4T8OIq6qFp0baQpIcBSvauCUVl9H9OQRwLF1BUv0nMaNgLTdC/7JT Ip51i3McjP3PQ/1ymsvlrMz+Tlc5iJyVO5DXfMfQ2y9gkeJF0TSOhFHL5pNHEsxbEnwZ 1bZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M7YV+VPL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o4si3189095pgq.683.2017.08.18.04.26.54; Fri, 18 Aug 2017 04:26:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M7YV+VPL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751693AbdHRL0v (ORCPT + 26 others); Fri, 18 Aug 2017 07:26:51 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:33207 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751045AbdHRL0s (ORCPT ); Fri, 18 Aug 2017 07:26:48 -0400 Received: by mail-wr0-f174.google.com with SMTP id b65so67580745wrd.0 for ; Fri, 18 Aug 2017 04:26:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WpAB7m7CyEA9tmJ5QoBPu6wS8zGT6hzTjbT0E6oPCtY=; b=M7YV+VPLf+2zy4rnn9XewPaAcF16bB9bQqgdD/i3nwC7O5G5dtOixfEz4nH0TlOkU9 u2o5qI7xdWyilAWVxgFGRFg3jReCh+bN2t8xZisGNWewgmq8Nrj7bSmWyP2ggNoo1kR1 sOOTP0WNlCOTD5AS+FGtWOGGmHhA/pKxeFgsU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WpAB7m7CyEA9tmJ5QoBPu6wS8zGT6hzTjbT0E6oPCtY=; b=t/Ckle/5QY0PvrI8uZYRF7KfHYk4+oJ+aJ6eQMRrDr7U7m8OEcpbtZGjtmM2GQyVNe jOdS9d9weVCFvGT+Q1QqUdnj7CXENKDvEpT3lwm/fsSMaluK9gF1f9wI4bF2xHWa7crz 43PAg1q6c/v4PVmcuIQCMnzeIePsXDIcRnX/EorB5nS4lIWdb6A+vYTY1juafFV5Uuaj jFwGoBbOpSZhJZNgJ5mHe6ZpwdSsm7BtgnCOZ9ajK3BjiRahxkV++8MXzFMLwZ7ZxR2G 3tTyRS4/7Y8t1SYqv7WfFBJP4cxBd6/go8MzHOLUN8i4OeJ9jb84vbsgWQaDAF0HHXtN dFqA== X-Gm-Message-State: AHYfb5hW8dHIfMTzOQoq5LbM3TTjApy36GvAx3JN4WxQTksYIjC6+/1w 038Al89hb1WTpmAOEHvj9Q== X-Received: by 10.28.232.221 with SMTP id f90mr797259wmi.40.1503055606993; Fri, 18 Aug 2017 04:26:46 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.26.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:26:46 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org 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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu , x86@kernel.org Subject: [PATCH v2 1/6] arch: enable relative relocations for arm64, power, x86, s390 and x86 Date: Fri, 18 Aug 2017 12:26:19 +0100 Message-Id: <20170818112624.24991-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 the Kconfig symbol and define it for some architectures that should be able to support and benefit from it. Cc: Catalin Marinas Cc: Will Deacon Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Michael Ellerman Cc: Martin Schwidefsky Cc: Heiko Carstens Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: x86@kernel.org Signed-off-by: Ard Biesheuvel --- 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(-) -- 2.11.0 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..b6d8e6504896 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.*) /* 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 From patchwork Fri Aug 18 11:26:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110373 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780465qge; Fri, 18 Aug 2017 04:27:02 -0700 (PDT) X-Received: by 10.101.70.65 with SMTP id k1mr8273253pgr.39.1503055622885; Fri, 18 Aug 2017 04:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055622; cv=none; d=google.com; s=arc-20160816; b=Kwfk3M0wB0ENirbA3ZUec4nYfdvbDIjrBwyj2TjWuwtdP1wrVeDoQth3HjRRhBhLuF tiH1sSo23EcNqB8FmPuDJCOPNJ90bnHOy8Ws376y+KhitUVsucUb6SvZT4LdiZ8RFiG8 sdslphe5u1UckPrrLWdWffXKMQWTy2CFvO+tbSe9Vci0fSumfI713d99GkuvfnqBQVKp Va90UutIea0WR0Um4KjV8i3gSBf/lusf4q76h6Dk1Cn1WzanrxY33Jw/LOpz1GWfRkGT klhUjIppsjdcUyhxQTMbhOFl4hYe0sCgpyFBJCHZgYv7YaquJi9I2iw8BPxUzcR4uZwg rUNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=zCfiGBBgVMmB6o1MlGFOpJc/LA60dRcsP4ljxd8qPQY=; b=YrdMxS2lOnItFfezLDH4VTFe4itYPLZlYnKaiO8pJY+RgoVO5aWDkqoCsDLdYz1qiY 3V/dRXEHnV0WHkEgHN6Eomu6H+k8moHDMkSPoagbZd3ww1Cg3I1oOpiT5B77jggRscwF /ifWuTmSj/zIHIMGGjVHJxjs6Jjk2/9j2H+3AjPCIlLKoW2zpIHdr+5TlmDge/TX0iUY UZS6obmSDwLSzrK/KN5XB+pOj+HrMVQCL76Dw2BCLCX8UcDjK/BB96QKCuhoVhRdYbwy daEL/k8RgcixzZN7jRupqjJP6nEgrEVQE4yU/4OnJHyjksLTISC7+lAQ8qIajrTEucoJ +x0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B0NGrNxk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o4si3189095pgq.683.2017.08.18.04.27.02; Fri, 18 Aug 2017 04:27:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B0NGrNxk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751807AbdHRL1A (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:00 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:36677 "EHLO mail-wr0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751695AbdHRL0x (ORCPT ); Fri, 18 Aug 2017 07:26:53 -0400 Received: by mail-wr0-f170.google.com with SMTP id f8so24198440wrf.3 for ; Fri, 18 Aug 2017 04:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zCfiGBBgVMmB6o1MlGFOpJc/LA60dRcsP4ljxd8qPQY=; b=B0NGrNxkeyc8wHuNM9jhlpQCo2Qqp2fNysqVxjqNUoqD7eCioCKgMP8KVjBywEURJk TD5+wspa7bS+f7bvxF8Bi2ykUqenethPOJKZqki2tD4aK7KCl36+2lXYca58QWjDZLbc ZY5mZerj+7FM7EGGhGT5dGVvpKl+pDPAPJ92U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zCfiGBBgVMmB6o1MlGFOpJc/LA60dRcsP4ljxd8qPQY=; b=eV42a/Z2bQwHk4wHilMiTTlI/xnSTEZyG4AIe0XoIi4h9H4ygjF7mzxSZDyh1/nbVT agDWnEPt5vOWkfUuNB6PGnkzKUqhnWHRKd1i7wbaFzPa4SfqKmN+ma/g14j52avoKtwl xWAhRxsa6tsHSgr+rTKyBg+2QJCv1DACEue5aQgbvG0R5Xku8yHVTu/u7u6IDX0SnvAJ QadlrFnn7spbWnUgG5JMx1yLEaBLE+0dYYzo0Uu8gas6nTP1tc+bDn8ue3g/vWabKxvt 0yrjmuLorxnxTo5CUepuTuyAKQnNEwZ9pCjcaoNDjUdhqJL+pnXbLsHcNEW0o6+PXhUr l/Nw== X-Gm-Message-State: AHYfb5iBPOoZ2CiWud1nylO885L2VLvD8oqF+aynEkVEqV0LC/WCrtu8 ElpL37oPgyDXlh1cyYepTw== X-Received: by 10.28.164.66 with SMTP id n63mr1192008wme.82.1503055612271; Fri, 18 Aug 2017 04:26:52 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.26.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:26:51 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org 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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu , Ingo Molnar Subject: [PATCH v2 2/6] module: use relative references for __ksymtab entries Date: Fri, 18 Aug 2017 12:26:20 +0100 Message-Id: <20170818112624.24991-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Arnd Bergmann Cc: Andrew Morton Cc: Ingo Molnar Cc: Kees Cook Cc: Thomas Garnier Cc: Nicolas Pitre Signed-off-by: Ard Biesheuvel --- 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 | 68 ++++++++++++++++---- kernel/module.c | 14 ++-- 6 files changed, 86 insertions(+), 24 deletions(-) -- 2.11.0 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 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..3e0b707664b1 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..896883a44be3 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,67 @@ 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 { + int value_offset; + int name_offset; +}; + +static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym) +{ + return (unsigned long)&sym->value_offset + sym->value_offset; +} + +static inline const char *kernel_symbol_name(const struct kernel_symbol *sym) +{ + return (const char *)((unsigned long)&sym->name_offset + + sym->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; +}; + +static inline unsigned long kernel_symbol_value(const struct kernel_symbol *sym) +{ + return sym->value; +} + +static inline const char *kernel_symbol_name(const struct kernel_symbol *sym) +{ + return sym->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))) \ + static const char __kstrtab_##sym[] __used __aligned(1) \ + __attribute__((section("__ksymtab_strings"))) \ = 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..904c3634fdd0 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -544,7 +544,7 @@ 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 +2190,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 +2220,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 +2274,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 +2534,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 */ From patchwork Fri Aug 18 11:26:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110377 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp781386qge; Fri, 18 Aug 2017 04:27:58 -0700 (PDT) X-Received: by 10.84.231.206 with SMTP id g14mr9481038pln.394.1503055678060; Fri, 18 Aug 2017 04:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055678; cv=none; d=google.com; s=arc-20160816; b=iRMarTxfkdNHRWsGP7frryr7WuFuBWD0ELs81huBp7Qb+i8gwtxQh8cPE1Wp2dbZ02 qvrK0YQl5erk96N8NFnKNEEF5nlWpcv0JFZR3BWNRnZEz9+QObc3a1mX2ug3WuRbNExA ot0VLIVamtymxScn86Q5AU32nuBS2y/m6Lvc69sGF8BVrR0QHvMmKpHozGAUaaG67vfr E7/kENTlCtB84eAP3PPUZXmGoqNf3NZvL6rxKvaQGv7Ifjiq1xeM80xM+Ko+kDG63yzP k3NjP+oyP0IGTr2TuTl/miLKIhaQPsTTVehZ6i3PuekupzwxrQgCViGERFLUBSqZeE4l hyxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=PkEJvp4YAwG7ObOv3lYsdyRlvlNMbFjavxLS4X/roJk=; b=zZiKh3+7gISAT+q0hG72l0YHx5UmZmePKKH/7OEuQ7AWfx2SSFqwKSjhtWYna7s1NS Fera4PYaJslnzUR/0xcxDZ/U95ELrO3n5rzWjObG4ggD4orTOt/q1MU6t6VS9DKb0D3i 0sEF3VYNwR2rg3b39/YTHy6gDVSzcbfcMY0HGZ1odyK2S4KeVEnRHenl5Btk7spPcLWg MVxK1bNdGKTTzilDhhPFwYXnpHPCSYiWsCvLNn2RbMNPlQVuBBWPINyE5BuhLJ0HCCX1 hnKot0KCedpz7oUZ+H2Ft+f9ZYHvWK2mhSMKr1b2YEIeKsZyH+27GWPrlUDMU/Z9VVqn HVUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QjbKZGkc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x188si3352751pgb.776.2017.08.18.04.27.57; Fri, 18 Aug 2017 04:27:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QjbKZGkc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752185AbdHRL1y (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:54 -0400 Received: from mail-wr0-f178.google.com ([209.85.128.178]:38090 "EHLO mail-wr0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751740AbdHRL07 (ORCPT ); Fri, 18 Aug 2017 07:26:59 -0400 Received: by mail-wr0-f178.google.com with SMTP id 5so43967100wrz.5 for ; Fri, 18 Aug 2017 04:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PkEJvp4YAwG7ObOv3lYsdyRlvlNMbFjavxLS4X/roJk=; b=QjbKZGkc2W91skA6bXXbAQqLmZswGrLdiQAfL2Lu1ELW5yr6crY2SKHhbPM65et4db s1djjzYtmYIzKeycpD9TaekMovPTJ5EySUeFDjhEi3LVpvh+KndCHs7aPUXFNL5c7No1 24G/sN2chsYcDslT/WW0p5/2T1B5Sy1rebP+I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PkEJvp4YAwG7ObOv3lYsdyRlvlNMbFjavxLS4X/roJk=; b=ebwftDyc6u0jQEJUzk76+JeTGf96fwe53XngOykRO8IJ0rRdIRc3n6Lo2tgyyHicCf l4nTEyer5//dvNHgBeXFfNTw/NvOHKyowC/i7rXmPtRWub0LKQWNimjqle5GOBmsheZi vDT+EjtbdEL8Dv6tp0SylGDReI+W/7vkcvLcIXq4foTFcHXf2JkKOz9iLvE/J4WT/Bz1 2xAVgjdoHut4+Mo4UJodRLXLah5tM0GMjlHGy9fdPU9eGikDRfvxSUTMJ2XLE7JL2O/H Q10OkoAnLyj21zYRQoo8l/o2gVXTvv1bZ3fsf/AI4gV6Lokz1K7+LFtK2Gj893sGDTWP Stvg== X-Gm-Message-State: AHYfb5iY/tKmXnMsoNKX9iiiw9w3iThzR31Z4brUk689P+VBfgJMKqrC O8svaYoz6MXslo+IwK5w4g== X-Received: by 10.28.221.86 with SMTP id u83mr1541786wmg.143.1503055618048; Fri, 18 Aug 2017 04:26:58 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.26.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:26:57 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org 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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu Subject: [PATCH v2 3/6] treewide: add missing trailing semicolons to initcall() invocations Date: Fri, 18 Aug 2017 12:26:21 +0100 Message-Id: <20170818112624.24991-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before modifying the initcall() code to add support for relative references in the initcall sections, fix the existing code that lacks the required trailing semicolon so we can remove it from the macros. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/perf_event.c | 2 +- arch/s390/hypfs/inode.c | 2 +- arch/x86/events/intel/core.c | 2 +- drivers/net/cris/eth_v10.c | 2 +- drivers/net/dsa/dsa_loop_bdinfo.c | 2 +- drivers/parport/procfs.c | 4 ++-- drivers/perf/arm_pmu_acpi.c | 2 +- drivers/platform/x86/intel_turbo_max_3.c | 2 +- fs/hugetlbfs/inode.c | 2 +- mm/compaction.c | 2 +- mm/oom_kill.c | 2 +- mm/page_alloc.c | 2 +- mm/page_owner.c | 2 +- net/core/lwt_bpf.c | 2 +- net/sched/sch_blackhole.c | 2 +- sound/core/seq_device.c | 4 ++-- 16 files changed, 18 insertions(+), 18 deletions(-) -- 2.11.0 diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index b5798ba21189..b8e866f08d27 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -1172,4 +1172,4 @@ static int __init armv8_pmu_driver_init(void) else return arm_pmu_acpi_probe(armv8_pmuv3_init); } -device_initcall(armv8_pmu_driver_init) +device_initcall(armv8_pmu_driver_init); diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c index cf8a2d92467f..0876f49ff6e9 100644 --- a/arch/s390/hypfs/inode.c +++ b/arch/s390/hypfs/inode.c @@ -498,4 +498,4 @@ static int __init hypfs_init(void) pr_err("Initialization of hypfs failed with rc=%i\n", rc); return rc; } -device_initcall(hypfs_init) +device_initcall(hypfs_init); diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 98b0f0729527..2510b00aa152 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -4340,4 +4340,4 @@ static __init int fixup_ht_bug(void) pr_info("PMU erratum BJ122, BV98, HSD29 workaround disabled, HT off\n"); return 0; } -subsys_initcall(fixup_ht_bug) +subsys_initcall(fixup_ht_bug); diff --git a/drivers/net/cris/eth_v10.c b/drivers/net/cris/eth_v10.c index 017f48cdcab9..2494b2d47210 100644 --- a/drivers/net/cris/eth_v10.c +++ b/drivers/net/cris/eth_v10.c @@ -408,7 +408,7 @@ etrax_ethernet_init(void) led_next_time = jiffies; return 0; } -device_initcall(etrax_ethernet_init) +device_initcall(etrax_ethernet_init); /* set MAC address of the interface. called from the core after a * SIOCSIFADDR ioctl, and from the bootup above. diff --git a/drivers/net/dsa/dsa_loop_bdinfo.c b/drivers/net/dsa/dsa_loop_bdinfo.c index fb8d5dc71013..62c2c2d60752 100644 --- a/drivers/net/dsa/dsa_loop_bdinfo.c +++ b/drivers/net/dsa/dsa_loop_bdinfo.c @@ -29,6 +29,6 @@ static int __init dsa_loop_bdinfo_init(void) { return mdiobus_register_board_info(&bdinfo, 1); } -arch_initcall(dsa_loop_bdinfo_init) +arch_initcall(dsa_loop_bdinfo_init); MODULE_LICENSE("GPL"); diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index 8ee44a104ac4..ae7ecc27da97 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -617,5 +617,5 @@ static void __exit parport_default_proc_unregister (void) } #endif -subsys_initcall(parport_default_proc_register) -module_exit(parport_default_proc_unregister) +subsys_initcall(parport_default_proc_register); +module_exit(parport_default_proc_unregister); diff --git a/drivers/perf/arm_pmu_acpi.c b/drivers/perf/arm_pmu_acpi.c index 0a9b78705ee8..3798bc2461f8 100644 --- a/drivers/perf/arm_pmu_acpi.c +++ b/drivers/perf/arm_pmu_acpi.c @@ -264,4 +264,4 @@ static int arm_pmu_acpi_init(void) return ret; } -subsys_initcall(arm_pmu_acpi_init) +subsys_initcall(arm_pmu_acpi_init); diff --git a/drivers/platform/x86/intel_turbo_max_3.c b/drivers/platform/x86/intel_turbo_max_3.c index 4f60d8e32a0a..fbcface26d94 100644 --- a/drivers/platform/x86/intel_turbo_max_3.c +++ b/drivers/platform/x86/intel_turbo_max_3.c @@ -148,4 +148,4 @@ static int __init itmt_legacy_init(void) return 0; } -late_initcall(itmt_legacy_init) +late_initcall(itmt_legacy_init); diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 28d2753be094..501481383ec7 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1423,4 +1423,4 @@ static int __init init_hugetlbfs_fs(void) out2: return error; } -fs_initcall(init_hugetlbfs_fs) +fs_initcall(init_hugetlbfs_fs); diff --git a/mm/compaction.c b/mm/compaction.c index fb548e4c7bd4..9d456d62c6ef 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2125,6 +2125,6 @@ static int __init kcompactd_init(void) kcompactd_run(nid); return 0; } -subsys_initcall(kcompactd_init) +subsys_initcall(kcompactd_init); #endif /* CONFIG_COMPACTION */ diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 9e8b4f030c1c..5e82359cb58f 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -634,7 +634,7 @@ static int __init oom_init(void) } return 0; } -subsys_initcall(oom_init) +subsys_initcall(oom_init); #else static inline void wake_oom_reaper(struct task_struct *tsk) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 6d00f746c2fd..5fc71b3155dd 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7073,7 +7073,7 @@ int __meminit init_per_zone_wmark_min(void) return 0; } -core_initcall(init_per_zone_wmark_min) +core_initcall(init_per_zone_wmark_min); /* * min_free_kbytes_sysctl_handler - just a wrapper around proc_dointvec() so diff --git a/mm/page_owner.c b/mm/page_owner.c index 0fd9dcf2c5dc..dfc22d5e3dba 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -624,4 +624,4 @@ static int __init pageowner_init(void) return 0; } -late_initcall(pageowner_init) +late_initcall(pageowner_init); diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index 1307731ddfe4..6e416c781682 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -396,4 +396,4 @@ static int __init bpf_lwt_init(void) return lwtunnel_encap_add_ops(&bpf_encap_ops, LWTUNNEL_ENCAP_BPF); } -subsys_initcall(bpf_lwt_init) +subsys_initcall(bpf_lwt_init); diff --git a/net/sched/sch_blackhole.c b/net/sched/sch_blackhole.c index c98a61e980ba..3fe322bd1e05 100644 --- a/net/sched/sch_blackhole.c +++ b/net/sched/sch_blackhole.c @@ -42,4 +42,4 @@ static int __init blackhole_init(void) { return register_qdisc(&blackhole_qdisc_ops); } -device_initcall(blackhole_init) +device_initcall(blackhole_init); diff --git a/sound/core/seq_device.c b/sound/core/seq_device.c index c4acf17e9f5e..4e859e4a0356 100644 --- a/sound/core/seq_device.c +++ b/sound/core/seq_device.c @@ -311,5 +311,5 @@ static void __exit alsa_seq_device_exit(void) bus_unregister(&snd_seq_bus_type); } -subsys_initcall(alsa_seq_device_init) -module_exit(alsa_seq_device_exit) +subsys_initcall(alsa_seq_device_init); +module_exit(alsa_seq_device_exit); From patchwork Fri Aug 18 11:26:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110374 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780609qge; Fri, 18 Aug 2017 04:27:11 -0700 (PDT) X-Received: by 10.84.224.135 with SMTP id s7mr9422474plj.238.1503055631424; Fri, 18 Aug 2017 04:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055631; cv=none; d=google.com; s=arc-20160816; b=CfARluKuNcRMXRuLozccW+8q0Gung6zeic+H46XXPWYPQFdtUqIpOT8VCMpkJO0S4H ycQzfMfnO/mYYaTo6muzgXO4/UacYjzg6ssow/JZyTbYr/VaD4UCbEGP9/FVuxUqmYkr 44ZiD3NFSx/ibmIJxfjh2rESlWJV2bvu4wqdbfNR2wHhJJ2ZjWFVF/br7DnfE1asPJvu klm9YjDlk4TKfC908Z3A4D9mlO8vD0Wl9tPZ0izrbHYVoenK3B367TZvr1uvd33AoD5i +DCQW0L+gMBGW/01DLbaHtbrxSTkoBAuR355z3scn7m05rT4uzw/Quabispc0K2BZ/Wk 9RIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Zd+uUf6jlLiM5kkgnO0BGfxwJmYQmdGUiH2aEjP9gHE=; b=qbfBT00pR4ogVi4Qf+tK8jzlIEyh1CpUkvqQyCCv96QG58n2ADddzWTbsnMr8nmj29 ineSF5IWSmzIjV1KL0WPISuclMB5FIjUlKgXncKvocjxBxnr1rQAodhwdVXOb111Zbhs jEBQE9ZsoO3nMpAJTypi21FwyBpKU0u9yVQN3pX+4WdWrL7LZt2PKkgJQaUO/CdfAyem PilQErg+ro5ln3FczypRi87ykDgve9VbFIRfgG1XZ24MaVGfn6PPd6w4SnWOgACeVv0H mkT4sxY8FufLJCZFB2R2OjHl2pNFbhAEgWAcQPyvTe78/TOmZTEoo5ZF5uBTzRBEnqSw n3dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQEZBnSH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si3767189pld.315.2017.08.18.04.27.11; Fri, 18 Aug 2017 04:27:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQEZBnSH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbdHRL1J (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:09 -0400 Received: from mail-wr0-f178.google.com ([209.85.128.178]:37134 "EHLO mail-wr0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751814AbdHRL1D (ORCPT ); Fri, 18 Aug 2017 07:27:03 -0400 Received: by mail-wr0-f178.google.com with SMTP id z91so59499088wrc.4 for ; Fri, 18 Aug 2017 04:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Zd+uUf6jlLiM5kkgnO0BGfxwJmYQmdGUiH2aEjP9gHE=; b=GQEZBnSHL4TDOD+TWyrNP1aJVU1W/jpRZbO/d/zdJu6Rm4gUR+Z6GZDRfHtGXu0jvs JwuXMsfLivSkPFclSBcHaPXrI2C0gkEjvsVdIVXnHbR0HwBny6F2Va7C+HXY/tLkzgTg sctb0yZR/LU5Drrinj00xSxuDEG5wZLDeCjKI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Zd+uUf6jlLiM5kkgnO0BGfxwJmYQmdGUiH2aEjP9gHE=; b=P4fE0sTNSbjGw+sK8GDsySGEemc79O/6uFHdPmHvWVdkPXHFvndU2PkuUXBdNzeFRK eV3pfHCc2Iz+eODsRfBBgPX+T0FATnBNmcV4jZa8b6OMXKQLYUAjw26H+W6bw9cSxMXm Jntk/YFtmuQ/0uCuAuyQV+mNVVmGO3XYitPNAspik+PC8y8KtwISxaKYtsyrPLrJHoL7 Y55WvkFHXHWuPozj99WBFwyJh8vfHXRX6e9z6RTdsA/RqPNS8IAw8G3Wvt3DFJCxUMlr Rw9puEDwCh7cE8owUG1dXTyF0xKAm6exZYH8K3aXfGbuHI+NuIbskxse99OWD4X0p2dt uWxw== X-Gm-Message-State: AHYfb5jGa69rr+sbSkECaAoz9gMJKj049Rsgs3FhIFuPgvlBqTyMRuUj 9VaFP0dDP8LN79G0NrRwQA== X-Received: by 10.28.127.138 with SMTP id a132mr1397664wmd.91.1503055622381; Fri, 18 Aug 2017 04:27:02 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.26.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:27:01 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org 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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu Subject: [PATCH v2 4/6] init: allow initcall tables to be emitted using relative references Date: Fri, 18 Aug 2017 12:26:22 +0100 Message-Id: <20170818112624.24991-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Sergey Senozhatsky Cc: Steven Rostedt Cc: James Morris Cc: "Serge E. Hallyn" Signed-off-by: Ard Biesheuvel --- include/linux/init.h | 64 ++++++++++++++++---- init/main.c | 22 ++----- kernel/printk/printk.c | 4 +- security/security.c | 6 +- 4 files changed, 62 insertions(+), 34 deletions(-) -- 2.11.0 diff --git a/include/linux/init.h b/include/linux/init.h index 94769d687cf0..61022aec47ea 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -110,9 +110,6 @@ 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[]; - /* Used for contructor calls. */ typedef void (*ctor_fn_t)(void); @@ -161,9 +158,57 @@ 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") + +struct initcall_entry_t { + int offset; +}; + +static inline +initcall_t initcall_from_entry(const struct initcall_entry_t *entry) +{ + return (initcall_t)((unsigned long)entry + entry->offset); +} +#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 + +struct initcall_entry_t { + initcall_t call; +}; + +static inline +initcall_t initcall_from_entry(const struct initcall_entry_t *entry) +{ + return entry->call; +} +#endif + +extern struct initcall_entry_t __initcall_start[]; +extern struct initcall_entry_t __initcall0_start[]; +extern struct initcall_entry_t __initcall1_start[]; +extern struct initcall_entry_t __initcall2_start[]; +extern struct initcall_entry_t __initcall3_start[]; +extern struct initcall_entry_t __initcall4_start[]; +extern struct initcall_entry_t __initcall5_start[]; +extern struct initcall_entry_t __initcall6_start[]; +extern struct initcall_entry_t __initcall7_start[]; +extern struct initcall_entry_t __initcall_end[]; + +extern struct initcall_entry_t __con_initcall_start[]; +extern struct initcall_entry_t __con_initcall_end[]; + +extern struct initcall_entry_t __security_initcall_start[]; +extern struct initcall_entry_t __security_initcall_end[]; + +#define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id) /* * Early initcalls run before initializing SMP. @@ -202,13 +247,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..174a68ee85c4 100644 --- a/init/main.c +++ b/init/main.c @@ -832,19 +832,7 @@ int __init_or_module do_one_initcall(initcall_t fn) return ret; } - -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 = { +static struct initcall_entry_t *initcall_levels[] __initdata = { __initcall0_start, __initcall1_start, __initcall2_start, @@ -870,7 +858,7 @@ static char *initcall_level_names[] __initdata = { static void __init do_initcall_level(int level) { - initcall_t *fn; + struct initcall_entry_t *fn; strcpy(initcall_command_line, saved_command_line); parse_args(initcall_level_names[level], @@ -880,7 +868,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 +899,10 @@ static void __init do_basic_setup(void) static void __init do_pre_smp_initcalls(void) { - initcall_t *fn; + struct 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..95a964592dc6 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; + struct 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..e878b6f5ce9c 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; - call = __security_initcall_start; + struct initcall_entry_t *call = __security_initcall_start; + while (call < __security_initcall_end) { - (*call) (); + initcall_from_entry(call)(); call++; } } From patchwork Fri Aug 18 11:26:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110375 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780696qge; Fri, 18 Aug 2017 04:27:16 -0700 (PDT) X-Received: by 10.84.217.206 with SMTP id d14mr2884730plj.319.1503055636551; Fri, 18 Aug 2017 04:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055636; cv=none; d=google.com; s=arc-20160816; b=YN8oa04HFddYrXXWFFLRD/uTi7HuDWnAl5smb7D4Vlq5tLVC8bSJY2QQHNAYovqcwT uxnNB1ZvmfaFPZzdwuVFDKwv+ra/kzaScYhVYw9gl55iem8e9bD9P6iIBCBut87j80Qw ZNevYXkIrk3WBY17f6+Rb3UGpBRmSTeKgbzxMjEIuLIwbu3w4Iwds3MUSJ9u+94VQMEh 3XxKUk8ARkDa+poNVJ8vhKEZOJAYT2Te1LQQFvR9VJ7Rehii3uSrkoKGBjIWZJaywLk3 jqheUwaXnrggt1jnvDok579drZAVgvt9gQDNDWgjh9U/tuQFEP91es9vWFOYU4OGCXn8 0GHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=sFVtzTun5xTiJYGGxiun2ScLBv7r6A52dK4isjQD32I=; b=C+nRSJOIqFRatKx19OKyUzIs/laktZSJqC6D1nVSA7rksXq+BaNvIO9iuUQ3DqDBAG 1mP1aMZATJKSbWxcGC700o0lAfJ1U6MTCGwxnhxm0w7Z+xHCq87jqONL7cI4daFyeqfE 6wsqMwnGTZ2vxR3MP1N3govX8Y5anW2vGWfhWpZJaZYNoctqdGoGgkqh3MIsy10sdubY X3uSrzk5dGovQLWQgcey1wITSH5sfmZVZVmOMylvGeZRV8mOcp5CaZLitdZZ0flFqRoR WiLxww/Q8BxKPUyRyKnnTcyXonKmfQxI2g1L3Pa1f0nc80CMJuYX8rMx5LD06S0wmnMP nGAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fyAAAwes; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si3767189pld.315.2017.08.18.04.27.16; Fri, 18 Aug 2017 04:27:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fyAAAwes; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752029AbdHRL1O (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:14 -0400 Received: from mail-wr0-f174.google.com ([209.85.128.174]:35799 "EHLO mail-wr0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751892AbdHRL1J (ORCPT ); Fri, 18 Aug 2017 07:27:09 -0400 Received: by mail-wr0-f174.google.com with SMTP id 49so58879998wrw.2 for ; Fri, 18 Aug 2017 04:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sFVtzTun5xTiJYGGxiun2ScLBv7r6A52dK4isjQD32I=; b=fyAAAwes2jRWmKqtL36vTtlqafyjIhd2PVauB/+8w6rImAM1MwUR40xWLU94dL5qDp q5vF5C/vhfjS1/jKE/YlMqLtM2s7WRd1coIIp7UPphPqKYvBKa2kiqPn/Ecw7GdUz/cf BDEB8llk2XiaSP9Ij6gzLYk1N6vfDxM+lX27U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sFVtzTun5xTiJYGGxiun2ScLBv7r6A52dK4isjQD32I=; b=PUDwaJudJf3ISazs9V73LuyQOIcWAyrmezfc6hhP9+OqIJH5mQxWuyc8AZnqDSrqcV dJ6jsLP/JLw/qvsNegn5X9AngmiG0+V/UkQMYhNF+97z2cKcytvNeB3uVwOLhB6mk8RV pSnznNWo+PGnxaeJC/TU8/8tzPGaSKO3ZOSg+57nafUMLq2g0cFH2IBPXMboXv0xsD1E CZnQvwRsJ3fTgWVXAKEgfD12O51PFh9001sQSXzXi72QE080zT+W3W9l0CduiRXnKasY mCNEfm922VPgRYB4PC+zh2DaSL9u8wJhY/Vrdc2vSv6qMTZ+ZZ2KUJR+d9iL85Nn5ND2 Q6Eg== X-Gm-Message-State: AHYfb5hbZj3RzRWeMspn1bhfT966vXAql/rJ4js4Xwhj4PnUG4rK/o1X uMDUrlG0jhEfnoZ+qbXkeg== X-Received: by 10.28.236.67 with SMTP id k64mr1179002wmh.128.1503055628183; Fri, 18 Aug 2017 04:27:08 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.27.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:27:07 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org 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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu Subject: [PATCH v2 5/6] drivers: pci: add support for relative addressing in quirk tables Date: Fri, 18 Aug 2017 12:26:23 +0100 Message-Id: <20170818112624.24991-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Ard Biesheuvel --- drivers/pci/quirks.c | 6 ++-- include/linux/pci.h | 32 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) -- 2.11.0 diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 6967c6b4cf6b..0a7ba8c7f1f6 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3547,9 +3547,9 @@ 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); + calltime = fixup_debug_start(dev, pci_fixup_hook(f)); + pci_fixup_hook(f)(dev); + fixup_debug_report(dev, calltime, pci_fixup_hook(f)); } } diff --git a/include/linux/pci.h b/include/linux/pci.h index a75c13673852..58eb4e7a15c3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1735,7 +1735,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 + int hook_offset; +#else void (*hook)(struct pci_dev *dev); +#endif }; enum pci_fixup_pass { @@ -1749,6 +1753,27 @@ 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) + +static inline +void (*pci_fixup_hook(const struct pci_fixup *f))(struct pci_dev *) +{ + return (void *)((unsigned long)&f->hook_offset + f->hook_offset); +} +#else /* Anonymous variables would be nice... */ #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \ class_shift, hook) \ @@ -1756,6 +1781,13 @@ enum pci_fixup_pass { __attribute__((__section__(#section), aligned((sizeof(void *))))) \ = { vendor, device, class, class_shift, hook }; +static inline +void (*pci_fixup_hook(const struct pci_fixup *f))(struct pci_dev *) +{ + return f->hook; +} +#endif + #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class, \ class_shift, hook) \ DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \ From patchwork Fri Aug 18 11:26:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110376 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp780796qge; Fri, 18 Aug 2017 04:27:22 -0700 (PDT) X-Received: by 10.98.245.6 with SMTP id n6mr8398031pfh.113.1503055642182; Fri, 18 Aug 2017 04:27:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503055642; cv=none; d=google.com; s=arc-20160816; b=C4WDSYjLNFT2b2Tbbor3ox2zU7UZ0BTSaXE4JOzb5Mp/kNPPA7Xu3o4RoXCs9xyyzG 96IzfV1drguESo5whVTSYlUgalPWcqBQh50PlCr5Oo0GYd0taneivA/WhfyOt4pXZDCZ yvfO/NWr4BaBtw3knQEayyx1r86T2C4UbjG2xwgzCS1DZz8aveKkdqB4qtmeY+B+uGyS t9DlZBkyy7G6sD3uGbfWciYJbcYeUfiSkWO8isiLlsyXD1aOpcM3ebnLj+7+pnMciRDW w2Fe5LX/rk+j/Yi1wflMeU9ejgS+LxSCraViPOZsGpRzd2G19yM65ahk/0t7mFuUiZFZ 7/fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=x7SeoIU5D9NbCpDRoojAmu77Dw7Y+/0EtgpjZyyQq8k=; b=gEB40pEDQTEko2K2n5KYtb1pCaDavb0pYmx2iNlTWRsvrU5bBcs0Kmdh+A9kT0ZkHq bPOwlYlxTV/hK3iWBXr9C5JRPeZEHZp8tp7KFoXezX+nLYD6t99sBrnWqTcNIlqgcBgq kxbYjJanWoY+x/brQTotR2qZJ5LKVWqi8KN0EDlpES1ntUiDs83vR7Uig6jyIfQBFSlv +nx+K/QC1yLHfzv8i6FAFZ8EbX1nG/3sdjlO7m0YewCiXlvOFz3kVIvBWXsoQeIS1ny+ k59K8JMt3Cc9N83kKgKAXKt1JdozkVcKtOeWQvHYexURUfSXCetFvY2SWjLB8Lh472x2 ko/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZNWP6V8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si3367492pgc.316.2017.08.18.04.27.21; Fri, 18 Aug 2017 04:27:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZNWP6V8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752115AbdHRL1S (ORCPT + 26 others); Fri, 18 Aug 2017 07:27:18 -0400 Received: from mail-wr0-f173.google.com ([209.85.128.173]:37227 "EHLO mail-wr0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751969AbdHRL1O (ORCPT ); Fri, 18 Aug 2017 07:27:14 -0400 Received: by mail-wr0-f173.google.com with SMTP id z91so59503198wrc.4 for ; Fri, 18 Aug 2017 04:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x7SeoIU5D9NbCpDRoojAmu77Dw7Y+/0EtgpjZyyQq8k=; b=gZNWP6V8BxN9lo07RMzktpO8GaHrGskbjZII8bl6wwL/Qtf7hR0yVEdVx9e5jCDdqL JG1nf3nr7XJDRFC+6Z5cIzHLgDT16l4LmtZhXIdq6vZEPCfmfnN+eg4AnpzAv3FsemJM 1qyJtd2JYam1aTM0pqJxTUa14rRZtk0PSma5o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x7SeoIU5D9NbCpDRoojAmu77Dw7Y+/0EtgpjZyyQq8k=; b=qXukE0GdFkALnFc4FYB8NiwWCmnH9IRLhwrBzBoDl8CG7vv00NaIICucfYRpAaSAKP Y8zfS0ScAEJpwFG8xvgR4jB2QMeVGmJ1o+Zc37yFpk2Hx8LCOaFtmJTagFY3GdBcjxY5 9Haoyg88RN0t/BIGd5h6+FoiG67ftWwg/MmntCQa3EO4uYVUv1bo6ZnaaqS1Fpat5vV1 z6yb1/5to13VPT42fjaSnFdJwtrnvaMNzgLXKbmgj00ToI+d8XT4ZPxIvCkkd1LfWr/y 0RE7cAenUfP2x/J867oXhZ1hhngZClhAZ0BW+1SR9VFuPedOUEa1TYC3uFXtMkzjPF9N /jGw== X-Gm-Message-State: AHYfb5jqo92WSxuaElznhUrnV6jOtV80i3VIew/FzbdoiUjmXeteTCXG cINDciQFCYmOVBA4NdvZwg== X-Received: by 10.28.196.12 with SMTP id u12mr1130658wmf.165.1503055633317; Fri, 18 Aug 2017 04:27:13 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id f4sm1047111wmh.28.2017.08.18.04.27.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 04:27:12 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org 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 , Joe Perches , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Andy Whitcroft , Jessica Yu Subject: [PATCH v2 6/6] kernel: tracepoints: add support for relative references Date: Fri, 18 Aug 2017 12:26:24 +0100 Message-Id: <20170818112624.24991-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170818112624.24991-1-ard.biesheuvel@linaro.org> References: <20170818112624.24991-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Ingo Molnar Signed-off-by: Ard Biesheuvel --- include/linux/tracepoint.h | 42 ++++++++++++++++++-- kernel/tracepoint.c | 7 +--- 2 files changed, 40 insertions(+), 9 deletions(-) -- 2.11.0 diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index a26ffbe09e71..68701821933a 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -228,6 +228,42 @@ 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") + +struct tracepoint_entry_t { + int tp_offset; +}; + +static inline +struct tracepoint *tracepoint_from_entry(const struct tracepoint_entry_t *ent) +{ + return (struct tracepoint *)((unsigned long)ent + ent->tp_offset); +} +#else +#define __TRACEPOINT_ENTRY(name) \ + static struct tracepoint * const __tracepoint_ptr_##name __used \ + __attribute__((section("__tracepoints_ptrs"))) = \ + &__tracepoint_##name + +struct tracepoint_entry_t { + struct tracepoint *tp; +}; + +static inline +struct tracepoint *tracepoint_from_entry(const struct tracepoint_entry_t *ent) +{ + return ent->tp; +} +#endif + +extern struct tracepoint_entry_t const __start___tracepoints_ptrs[]; +extern struct tracepoint_entry_t const __stop___tracepoints_ptrs[]; + /* * 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 +273,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..21bc41454fd6 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -28,9 +28,6 @@ #include #include -extern struct tracepoint * const __start___tracepoints_ptrs[]; -extern struct tracepoint * const __stop___tracepoints_ptrs[]; - /* Set to 1 to enable tracepoint debug output */ static const int tracepoint_debug; @@ -508,12 +505,12 @@ static void for_each_tracepoint_range(struct tracepoint * const *begin, void (*fct)(struct tracepoint *tp, void *priv), void *priv) { - struct tracepoint * const *iter; + struct tracepoint_entry_t const *iter; if (!begin) return; for (iter = begin; iter < end; iter++) - fct(*iter, priv); + fct(tracepoint_from_entry(iter), priv); } /**