From patchwork Mon Jul 2 18:11:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 140838 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp246808ljj; Mon, 2 Jul 2018 11:12:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLPtvn0UiYAk/2lRWKJhyPG5+mQgsmPk0k26lbzm9TOHAOkQSgWzzWhyh/NK0UW4XMWfZ8o X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr22694112pgq.21.1530555119886; Mon, 02 Jul 2018 11:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530555119; cv=none; d=google.com; s=arc-20160816; b=UFIFtHKAlIlDPSgCQ4DwHC0jFMSPddH7wctOJ3p+zHezgsxxS3TIgJuZb2c7DKZvyH +mXhk5fSAK5EqzD/J8Vj/XP0ryoeLp13HcJthSG5n2hnqHDOSlTTzA2fqteAcuC8M2ga GyUQGt+2QxQ8nzI/CJEBTiBYTJ+sVAVO953ahlbrSyoHUmRo1owTph7d67vxOnEkztNT hV9ilZxN/Bol80bbNJyXTLTdwk0/sv8ZQtpTQA97fF2AualzxXPKZFUdiylVXRBfw7Kf GjzqCUjMNfxxcBDyFFMar4cG4u8JAsKtVUQPgrX9qMinfwX2kLbeQcyCVkR6kOiv2xD/ DW9w== 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=Wczpy3MovXWNF7ShMlLVscAxwBkNReIA4OC63ioDHCk=; b=qyllotwFWJG32/RXhtFIO2neUda5XNBXnn2XfDQNmMnv0t24xgOEe2qpyFkGCoDWo2 ob1mlHngrs2V+owhCA78ezgbGwkj4YQf5KUKyYzzs6xZ988do3JRLVl1Cc6HOZOeA2Ac qlY2+kZknEhDNmPjrfGG/ycLjAG82gVtor4rR3eQXFapt0rwVdNcZf5sDSqEgOs02GZu YXckMdbIDko5WHauojSnYSqTe2VshC6yAjciRExqNzEPTcQ+6gpxKPOIY5s/8FewEnch 7gonB52xvcLXMwmrhbyGopBagbRol3j+rgeCYmq/STBr4uzml/p6T/kcs0RL4LoxZAKa B+PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fPMqiCOo; 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 r4-v6si6314663pgb.97.2018.07.02.11.11.59; Mon, 02 Jul 2018 11:11:59 -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=fPMqiCOo; 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 S1753353AbeGBSL5 (ORCPT + 31 others); Mon, 2 Jul 2018 14:11:57 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:54371 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753323AbeGBSLw (ORCPT ); Mon, 2 Jul 2018 14:11:52 -0400 Received: by mail-wm0-f68.google.com with SMTP id i139-v6so9940735wmf.4 for ; Mon, 02 Jul 2018 11:11:52 -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=Wczpy3MovXWNF7ShMlLVscAxwBkNReIA4OC63ioDHCk=; b=fPMqiCOoUDfXS1E43H+E5gbSFg7NvicpuSmnrOvnPITvWlXmtmop/OW578exsChdHB glKYpvEX2x7vrbVDKid+ioTxGWgbb3FkBM81jbJhUuUpY0ylST8oZWX1VYifdUfAE6/r 6qVbJ4+Yfsd79TlLyG3Zdy6PkvRXeiwyMIFfY= 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=Wczpy3MovXWNF7ShMlLVscAxwBkNReIA4OC63ioDHCk=; b=XKpMMebvB5qfLizTSx8M0VoDFWar7Zcoe+CT4fBY7mKJiqSLdgh2rA2dkrhi8UxmY0 ajM8he62hl1zYyIZ8Q9j5L5gRwwLQX7cMNubtbbYKc/7RD/SI7dOLFdo6tgCEUUpkvkK D/K4i15dsttnKhPccvPw/X/C2c4uJNLchyWglq6Ri4FjXXxF4Tmt8noRZEyP5fT0XuvT 4aD1AlHQQY3/sZD9pgRlc93U4RzCUCQ905V5Qn4dWw6Iv6Xt8r6Hf11pCoE3EI3DzSE8 bWJgxmFrnWJQe4DwZwKo/L3qq0XuiEQ/6gEfuRuD0eSv83YLRHZyxgrhcahU1mciZXiq un2w== X-Gm-Message-State: APt69E2dE08D7xLvLl3R1i3lIwP9N+mBcUNSGenamIZertfX936Sca2b 1cmDxZ+lYgtV3r9xSt3daEFdnQ== X-Received: by 2002:a1c:568a:: with SMTP id k132-v6mr8641245wmb.89.1530555111446; Mon, 02 Jul 2018 11:11:51 -0700 (PDT) Received: from localhost.localdomain (151.21.90.92.rev.sfr.net. [92.90.21.151]) by smtp.gmail.com with ESMTPSA id 189-v6sm10582822wmd.17.2018.07.02.11.11.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jul 2018 11:11:50 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-arch@vger.kernel.org Cc: Ard Biesheuvel , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Thomas Gleixner , Catalin Marinas , Ingo Molnar , Steven Rostedt , Martin Schwidefsky , Jessica Yu , Peter Zijlstra Subject: [PATCH v2 0/8] add support for relative references in jump tables Date: Mon, 2 Jul 2018 20:11:37 +0200 Message-Id: <20180702181145.4799-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series implements support for emitting the data structures associated with jump tables as 32-bit relative references instead of absolute references, which take up more space on builds that target 64-bit architectures, or implement self relocation [or both]. This series enables it for arm64 and x86, although other architectures might benefit as well. Patch #1 does some preparatory refactoring before patch #2 introduces the generic pieces required for using relative references. Patch #3 wires everything up for arm64. Patch #4 introduces support for handling 64-bit place relative relocations on x86_64 (see 'Changes since v1' below) For x86, patch #5 applies some preparatory changes for the arch specific jump label C code, which is a lot more involved than on arm64, which is why it is split off in this case. Patch #6 wires it up for x86 as well. Patch #7 and #8 implement the changes so that the jump_entry arrays reside in ro_after_init memory rather than remain fully writable all of the time. Changes since v1: - change the relative reference to the static key to a 64-bit wide one on 64 bit architectures; this is necessary on arm64, which allows modules to reside anywhere within a 4 GB window covering the core kernel text, which means a 32-bit signed quantity with its +/- 2 GB range is insufficient. Note that x86_64 changes are in preparation that widen the relocation range as well (using the PIE linker), so I assumed that the same change is appropriate for x86 as well. - add patch #4 to handle the relocations emitted by the compiler as a result of the change above - added patches to move the jump_entry arrays to ro_after_init memory, so that they are not as easily corrupted or manipulated. - add Will's ack to patch #3 Cc: Arnd Bergmann Cc: Heiko Carstens Cc: Kees Cook Cc: Will Deacon Cc: Thomas Gleixner Cc: Catalin Marinas Cc: Ingo Molnar Cc: Steven Rostedt Cc: Martin Schwidefsky Cc: Jessica Yu Cc: Peter Zijlstra Ard Biesheuvel (8): kernel/jump_label: abstract jump_entry member accessors kernel/jump_label: implement generic support for relative references arm64/kernel: jump_label: switch to relative references x86: add support for 64-bit place relative relocations x86: jump_label: switch to jump_entry accessors x86/kernel: jump_table: use relative references jump_label: annotate entries that operate on __init code earlier jump_table: move entries into ro_after_init region arch/Kconfig | 3 + arch/arm/kernel/vmlinux-xip.lds.S | 1 + arch/arm64/Kconfig | 1 + arch/arm64/include/asm/jump_label.h | 36 ++++--- arch/arm64/kernel/jump_label.c | 6 +- arch/s390/kernel/vmlinux.lds.S | 1 + arch/x86/Kconfig | 1 + arch/x86/include/asm/elf.h | 1 + arch/x86/include/asm/jump_label.h | 24 ++--- arch/x86/kernel/jump_label.c | 62 +++++------- arch/x86/kernel/machine_kexec_64.c | 4 + arch/x86/kernel/module.c | 6 ++ arch/x86/tools/relocs.c | 10 ++ include/asm-generic/vmlinux.lds.h | 11 ++- include/linux/jump_label.h | 65 ++++++++++++- init/main.c | 1 - kernel/jump_label.c | 100 +++++++++----------- kernel/module.c | 9 ++ tools/objtool/special.c | 4 +- 19 files changed, 205 insertions(+), 141 deletions(-) -- 2.17.1 Signed-off-by: Heiko Carstens