From patchwork Sat Aug 19 18:10:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 110455 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2383526qge; Sat, 19 Aug 2017 11:11:01 -0700 (PDT) X-Received: by 10.99.146.67 with SMTP id s3mr11902303pgn.130.1503166261011; Sat, 19 Aug 2017 11:11:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503166261; cv=none; d=google.com; s=arc-20160816; b=R1hkPuEle7QRfEGdIUdrdcZP0XQ7JwbGdZnDJ2HmtlwneNWECYcRIX3Ivdj3cy/MMJ uJNrVlmsaohD5hgYRiYtQLl7bioZFkKZ304OYrMLBK6mShtlrsRm5LHx/2C0HsGfywJD 82UQ5NuL2ISAYZ5r7x3x5ns7jL7XL4tJUWr5t55WI01O3zBOSRkcZVya6E7ONaqAnPJk 3N4Efk49csR5Lr1luDFIMs4qoKHgTK3PPJyUCMxTBYRi/VcXLeVmhKRut4icIscbrf2A brloXv+LNwU8E1o0/JPG7Au5A9RGsykKlB3xOUEDJw6PmvWn68p7q/eH3l7phI1j9gJ4 ABGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=5M82a+RiQwDeizmukchxPAGv3P8d5hC6naLoly22BuM=; b=Hge0zjniDElJuVVSDq0H+CWza+dXtffTDmjo23WuPqpIRmceg9049bfNOHI1e1jOCS 06Hn6xpjN71uzkMFuJ11hdcL4n/XMfvZ/zELFBU6j309m6rD9C0DtN3Ug5wY6+j4FDqw zl4JdmRPeupJT/f2NenlqMKqjMeoUPiCG8wYVQRB1sdsxoBpEUOb8k4o1oXXgJRIq3KQ QzqEupTwvBCmIK3QWKCpdsxclRjKgQlsZUMwQ8wn65IZbOQDXtL6+OSmMhl5ZaNw10Af nAAY4iMxsYCC+DHN1G49f4QbxKMYsyC5KMr7oOlvsu3fpPoBcJY0ALSqcd/BwXGjkNnp Jxjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aV7ARq/Q; 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 c32si5548733plj.478.2017.08.19.11.11.00; Sat, 19 Aug 2017 11:11:00 -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=aV7ARq/Q; 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 S1751849AbdHSSK5 (ORCPT + 26 others); Sat, 19 Aug 2017 14:10:57 -0400 Received: from mail-wr0-f169.google.com ([209.85.128.169]:38052 "EHLO mail-wr0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751204AbdHSSKz (ORCPT ); Sat, 19 Aug 2017 14:10:55 -0400 Received: by mail-wr0-f169.google.com with SMTP id p8so8142491wrf.5 for ; Sat, 19 Aug 2017 11:10:54 -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; bh=5M82a+RiQwDeizmukchxPAGv3P8d5hC6naLoly22BuM=; b=aV7ARq/Qj5XGsgu6sQwP5/brvv/1G3zPKsrqKP+AqR3lg/PZtjC4+RxfYxJqfuDG7A p4PjkVxZuHFnK7WSCXkJyYEKPRrZLowEnYt6Xj7uLs27Fc2lxFFJH8ociC7m2fE2ooEa 6inqKfH5x8ln4VduKDp9GdGVVV9C3W+OCCfx0= 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; bh=5M82a+RiQwDeizmukchxPAGv3P8d5hC6naLoly22BuM=; b=ZvWj3WjWVN+sApBA67ZRXrJPs4ZJRMTUWxwV/ckXdyRNUtds0p3HrWd0sXEpp8gSWU nIgUl1U72Oi9m7O8ncapKhJbl7078TjO2bLo583UsaRIKG1QXeZFBlzd4Dqfh7aU45On sT+nGiAbLCdtwRZ2GeTwPOXuShQTpT8ZKXXmeW6AjDQoF86c6XohQys5fDZG+ysDvA3M b9V2PqDmLHNWsN41REWV8m5S3CZ+c3bKqt9NfRYs3Lb5JNRWQXPifKmuQ+Rm2R83lLQg FRHGXIRBpGpfM8K/i7VW9gl+MXcG9EG+QReqb2sWbgu640wDviA06gAoKpYzW7SpLttT WLeA== X-Gm-Message-State: AHYfb5gf6zMZBriFFxSHL7zCh4lct+wBFwBBkFsrvyCUDZphthpQJHQS SeKjeTee1Pe4ZHRMSRWHUg== X-Received: by 10.223.163.90 with SMTP id d26mr8596121wrb.82.1503166253524; Sat, 19 Aug 2017 11:10:53 -0700 (PDT) Received: from localhost.localdomain ([154.146.161.128]) by smtp.gmail.com with ESMTPSA id m127sm4056261wmm.46.2017.08.19.11.10.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Aug 2017 11:10:50 -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 , Nicolas Pitre , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu Subject: [PATCH v3 0/5] add support for relative references in special sections Date: Sat, 19 Aug 2017 19:10:30 +0100 Message-Id: <20170819181035.969-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 the 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 (with KASLR enabled). Changes since v2: - Revert my slightly misguided attempt to appease checkpatch, which resulted in needless churn and worse code. This v3 is based on v1 with a few tweaks that were actually reasonable checkpatch warnings: unnecessary braces (as pointed out by Ingo) and other minor whitespace misdemeanors. Changes since v1: - Remove checkpatch errors to the extent feasible: in some cases, this involves moving extern declarations into C files, and switching to struct definitions rather than typedefs. Some errors are impossible to fix: please find the remaining ones after the diffstat. - Used 'int' instead if 'signed int' for the various offset fields: there is no ambiguity between architectures regarding its signedness (unlike 'char') - Refactor the different patches to be more uniform in the way they define the section entry type and accessors in the .h file, and avoid the need to add #ifdefs to the C code. Cc: "H. Peter Anvin" Cc: Arnd Bergmann Cc: Heiko Carstens Cc: Kees Cook Cc: Will Deacon Cc: Michael Ellerman Cc: Thomas Garnier Cc: Thomas Gleixner Cc: "Serge E. Hallyn" Cc: Bjorn Helgaas Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Catalin Marinas Cc: Petr Mladek Cc: Ingo Molnar Cc: James Morris Cc: Andrew Morton Cc: Nicolas Pitre Cc: Steven Rostedt Cc: Martin Schwidefsky Cc: Sergey Senozhatsky Cc: Linus Torvalds Cc: Jessica Yu 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 | 45 +++++++++++++++----- 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 | 17 ++++++-- security/security.c | 4 +- 20 files changed, 209 insertions(+), 66 deletions(-) delete mode 100644 arch/x86/include/asm/export.h -- 2.11.0