From patchwork Sun Mar 11 12:38:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131342 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3055500lja; Sun, 11 Mar 2018 05:39:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELuoKjm2i0+PBWy2LVxSplq5EVIWjhISWre8f56RtpJQqeLpasUereSyIAjwVK9jF+Tw+CK7 X-Received: by 2002:a17:902:b58d:: with SMTP id a13-v6mr4797868pls.123.1520771951537; Sun, 11 Mar 2018 05:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520771951; cv=none; d=google.com; s=arc-20160816; b=uYM3Cnl9ZX7lWT/bdT3qzED9E1P66qeoU9Ssvi68f3wt7r9PpaZ6Jrx/eF5I5kY5OP fAsFnGm882IME1QLRe9ODFY2DQHRxlXcV8U2n3/H58H3zuNLScXfEgsfldMh9I1+eiri Iljvq0l8o2Bv3F6Hw1HkCd126GrOOop64LIo1C7FH8Q24bKCc3rCqMIZ6BUg/gNEQIFp FHXomW+40FDPgyMN5ikV5PRMDAseJ0woVanwfLI+dAgoh4zu3jr1zQbkuHoPWXBJkqrB DBTMKTHp+mjFjVG90f5+SXX025+GhGanfyCm8oCANJ6Ua70x8ZBKZvtc1SiMYJyoQJqJ a+Rw== 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=3HFCSW681HuxSyBvNskjwIuHrUczk9OV3UWy2shQ6Oo=; b=wtQdPRJPRPIp8eCBl2byATWXIs7QO8T4UhsDPj9XiWYipySfI7hKDwteN8ZLw7b7Go NxfxpY084XNg6/EggZY14aesGBOKEGb4PZHQaKU6j/L888wp2vdCfuiN+0GHdsy0Ws/y 2sa+MluRoS4Ugdkyo36Uxf+ml+Gq0WzHgRdzPJYvUoclQYltNGHnbwydRgLh/qFVKkhQ aueiS10Gi9rnEhpGhg74U9+Z16Z2w9wI/WNAnVXUEJJdZugve1pQD7M2/1/PpxTXHmjD 0+N44BAS6nDcBiJJ3PCyeOVYUx5x0ZTaJL7Z2HYw3WFAhwevpgaLEjlL2e9ej2VQxaeG AwsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKIk8Yrm; 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 x4si3595555pgo.278.2018.03.11.05.39.10; Sun, 11 Mar 2018 05:39: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=AKIk8Yrm; 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 S932168AbeCKMi5 (ORCPT + 28 others); Sun, 11 Mar 2018 08:38:57 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:35059 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932126AbeCKMiz (ORCPT ); Sun, 11 Mar 2018 08:38:55 -0400 Received: by mail-wr0-f196.google.com with SMTP id n12so1880607wra.2 for ; Sun, 11 Mar 2018 05:38:55 -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=3HFCSW681HuxSyBvNskjwIuHrUczk9OV3UWy2shQ6Oo=; b=AKIk8YrmslekXmAAhl8LKanilqoxmRBpg1ZqTW1K9IDS1eyDZB0jOQVV2pd2tzIqib baocjMr/q1SKBzh0lcPcmwhLlUeKnPJR3CNhZr35GvF8ezbtKCf++p3aZcD5pkEsCdmD qRVzk1YbzfZmuCUy0kOJmsEgDEWM191sIxt8E= 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=3HFCSW681HuxSyBvNskjwIuHrUczk9OV3UWy2shQ6Oo=; b=injEtVNT3/ukgBtofenUdqvM4QFYNGaRowOwvnQHIBt3v/MOOKUQ8eRmS4rIXxd3zD vGLszl8oTFFvSWqFNu/XQYxXuU1LtbnxqfmGugbgwVfGp7Rp+JiWUf61Gf3LeV2ISDCa 2irJ+UG4raNphS/8nl3Jw8bnz8QsFv6irwJxvU8wAgdbmuGdti0mfaT32BrXohZiWVFM RxybGIhF5cBycVhFF+RJa5FkB3+fNl4YQ6bzp31MGH85puM30XRK9VzwZE0/8qKQJJH9 rExsDN/QYE8Jkm3NAMKLZp1V5E1nXKFFfggCaxGx+3KZDlpr9zoN3SkuN0s4UJkHxcOX oSWg== X-Gm-Message-State: AElRT7G7jYvnHuauVhlQz8BK9Gz4MvNrbIV5uSuMIq1sdkMsAFZispNe Co4rZgrp1x/5HP8ZpZaSIoFENA== X-Received: by 10.223.136.217 with SMTP id g25mr480305wrg.203.1520771934332; Sun, 11 Mar 2018 05:38:54 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id h188sm2569103wmf.37.2018.03.11.05.38.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 05:38:52 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v8 0/6] add support for relative references in special sections Date: Sun, 11 Mar 2018 12:38:09 +0000 Message-Id: <20180311123815.17916-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 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 relocatable kernels (e.g., for KASLR) that needs to be fixed up 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 #3 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 or ones that use runtime relocations. Patch #2 add support for #define'ing __DISABLE_EXPORTS to get rid of ksymtab/kcrctab sections in decompressor and EFI stub objects when rebuilding existing C files to run in a different context. Patches #4 - #6 implement relative references for initcalls, 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. [From the v7 series blurb, which included the jump_label patches as well]: For the arm64 kernel, all patches combined reduce the memory footprint of vmlinux by about 1.3 MB (using a config copied from Ubuntu that has KASLR enabled), of which ~1 MB is the size reduction of the RELA section in .init, and the remaining 300 KB is reduction of .text/.data. Branch: git://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git relative-special-sections-v8 Changes since v7: - dropped the jump_label patches, these will be revisited in a separate series - reorder __DISABLE_EXPORTS with __KSYM_DEPS__ check in #2 - use offset_to_ptr() helper function to abstract the relative pointer conversion [int *off -> (ulong)off + *off] (#3 - #6) - rebase onto v4.16-rc3 Changes since v6: - drop S390 from patch #1 introducing HAVE_ARCH_PREL32_RELOCATIONS: kbuild robot threw me some s390 curveballs, and given that s390 does not define CONFIG_RELOCATABLE in the first place, it does not benefit as much from relative references as arm64, x86 and power do - add patch to allow symbol exports to be disabled at compilation unit granularity (#2) - get rid of arm64 vmlinux.lds.S hunk to ensure code generated by __ADDRESSABLE gets discarded from the EFI stub - it is no longer needed after adding #2 (#1) - change _ADDRESSABLE() to emit a data reference, not a code reference - this is another simplification made possible by patch #2 (#3) - add Steven's ack to #6 - split x86 jump_label patch into two (#9, #10) Changes since v5: - add missing jump_label prototypes to s390 jump_label.h (#6) - fix inverted condition in call to jump_entry_is_module_init() (#6) Changes since v4: - add patches to convert x86 and arm64 to use relative references for jump tables (#6 - #8) - rename PCI patch and add Bjorn's ack (#4) - rebase onto v4.15-rc5 Changes since v3: - fix module unload issue in patch #5 reported by Jessica, by reusing the updated routine for_each_tracepoint_range() for the quiescent check at module unload time; this requires this routine to be moved before tracepoint_module_going() in kernel/tracepoint.c - add Jessica's ack to #2 - rebase onto v4.14-rc1 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: Arnd Bergmann 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: Russell King Cc: Paul Mackerras Cc: Catalin Marinas Cc: Petr Mladek Cc: Ingo Molnar Cc: James Morris Cc: Andrew Morton Cc: Nicolas Pitre Cc: Josh Poimboeuf Cc: Steven Rostedt Cc: Sergey Senozhatsky Cc: Linus Torvalds Cc: Jessica Yu Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: x86@kernel.org Ard Biesheuvel (6): arch: enable relative relocations for arm64, power and x86 module: allow symbol exports to be disabled module: use relative references for __ksymtab entries init: allow initcall tables to be emitted using relative references PCI: Add support for relative addressing in quirk tables kernel: tracepoints: add support for relative references arch/Kconfig | 10 ++++ arch/arm64/Kconfig | 1 + arch/powerpc/Kconfig | 1 + arch/x86/Kconfig | 1 + arch/x86/boot/compressed/kaslr.c | 5 +- arch/x86/include/asm/Kbuild | 1 + arch/x86/include/asm/export.h | 5 -- drivers/firmware/efi/libstub/Makefile | 3 +- drivers/pci/quirks.c | 12 +++-- include/asm-generic/export.h | 12 ++++- include/linux/compiler.h | 19 +++++++ include/linux/export.h | 57 +++++++++++++++----- include/linux/init.h | 44 +++++++++++---- include/linux/pci.h | 20 +++++++ include/linux/tracepoint.h | 19 +++++-- init/main.c | 32 +++++------ kernel/module.c | 32 ++++++++--- kernel/printk/printk.c | 4 +- kernel/tracepoint.c | 49 +++++++++-------- security/security.c | 4 +- 20 files changed, 240 insertions(+), 91 deletions(-) delete mode 100644 arch/x86/include/asm/export.h -- 2.15.1