From patchwork Tue Jun 26 18:27:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 935058 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41FZPL3T4Xz9s01 for ; Wed, 27 Jun 2018 04:31:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="josTfnd+"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41FZPL1w1GzF1HG for ; Wed, 27 Jun 2018 04:31:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="josTfnd+"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=linaro.org (client-ip=2a00:1450:400c:c0c::242; helo=mail-wr0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="josTfnd+"; dkim-atps=neutral Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41FZLN4tk5zF1Gt for ; Wed, 27 Jun 2018 04:28:43 +1000 (AEST) Received: by mail-wr0-x242.google.com with SMTP id a12-v6so18234720wro.1 for ; Tue, 26 Jun 2018 11:28:43 -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=h/uH5uFPgIYctKtBHMqt1daYgUmBFyfBNK679IqD3Gs=; b=josTfnd+C5MIScuq0oMZ9FaB0tVijFFrF9itzRljgDF8hlQBicyYObkrR92Qhw3a9V N7RRPDVjG2mYrptx9lwbOA5EsrbevIp6d295sJfKttzJ3uxE8mPpLQfnnpJuONF7jczU PPg5Ey51g4WW4Y2KoNW5cT0Jk9YYuZNDmkCGA= 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=h/uH5uFPgIYctKtBHMqt1daYgUmBFyfBNK679IqD3Gs=; b=pneodrPfoLO6XIGUzyIjOl4C+q6yKdmWqYtUzD8yASffRem1TP3BojxeGEl2qy/+AU q0ntQ5oR0Qdb2Sd8LN8++K2PQlUFpKJuDIxRa8KpsSMytnYtGCqnTfXfM/awBNi195yJ MxpfgLm9HLM4rInLbiFnclYpTUfxz5akVHa9PlE6p/MxuBawiAXoGGRUD7wyCoUP32va rornJjmJRedjNkWahMnSIUKLyIOim2vt0g0MGO+r7I5DaTzJzoU1jTKi+JVUkXChT4AI 6F/dYX+gRVrxoKtFcXbNbR7hWCBabBr7xN+pWCUKcsNs1LYGhCkVGBHc9irHU8oogTRJ J09w== X-Gm-Message-State: APt69E3IwqNf9pzMoCbrz85dagrScXDa0D9YipRwNAYehXxjUc+f7WLP O94ArZM6ZVXvmUTlQ/LBf+cRtw== X-Google-Smtp-Source: AAOMgpcf9bTmHZr2JbFP8gHSS5gfuOuce76u4yt3TCcYhKavo2GSTjzJ/EYBsXZBuHqzQA/GlwFTxw== X-Received: by 2002:adf:9d93:: with SMTP id p19-v6mr2507676wre.12.1530037720726; Tue, 26 Jun 2018 11:28:40 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:d037:e907:f0a2:a5ea]) by smtp.gmail.com with ESMTPSA id s17-v6sm1707664wmc.34.2018.06.26.11.28.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 11:28:39 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Subject: [PATCH v9 0/6] add support for relative references in special sections Date: Tue, 26 Jun 2018 20:27:55 +0200 Message-Id: <20180626182802.19932-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Catalin Marinas , Will Deacon , James Morris , Paul Mackerras , Nicolas Pitre , x86@kernel.org, Russell King , Ingo Molnar , "Serge E. Hallyn" , Petr Mladek , Kees Cook , Arnd Bergmann , Steven Rostedt , Josh Poimboeuf , Bjorn Helgaas , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , linuxppc-dev@lists.ozlabs.org, Sergey Senozhatsky , Jessica Yu , Andrew Morton , Linus Torvalds , Thomas Garnier Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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-v9 Changes since v8: - add Nico's ack (#2) - drop 'const' qualifier from __ADDRESSABLE(sym) to prevent mismatching attributes for the .discard section (#3) - drop all uses of VMLINUX_SYMBOL_STR(), which is on its way out (#3 - #6) 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 | 16 +++--- kernel/tracepoint.c | 49 +++++++++-------- security/security.c | 17 +++--- 20 files changed, 255 insertions(+), 101 deletions(-) delete mode 100644 arch/x86/include/asm/export.h Reviewed-by: Will Deacon Acked-by: Ingo Molnar