From patchwork Wed Sep 19 06:51:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10605377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3590A112B for ; Wed, 19 Sep 2018 06:52:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21F1E2B618 for ; Wed, 19 Sep 2018 06:52:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 152882B622; Wed, 19 Sep 2018 06:52:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CE5BA2B618 for ; Wed, 19 Sep 2018 06:52:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=wf4j5bBXpqQKPk1PMF6Hn/sP5d0d6WgBqzwYsSZBbX4=; b=TQQ rDUIH1fmV/SiILaKoSQsgB7qMEZj/d/pDu3o6h+2Lp+sHQgdE7DoGYfdYh2fA3pkY+hyLxMb6zvJ0 hdbY75kP10V5msd1iFpDY8HKa89M9muRlwoV3NHoxytwE0DX/Lg9SboNImrUBYhpzfFLbQjdG/s/k jSfaOI3GUtlHvYLpRHXsNQ+lA1S2dDgXtM1BOOPBH+8GF5gJ/jChCnPqFuu4+0Dz7LQG54/Vn5Jnt bLLUSwyZhXVBVTq0kYtERxtQcbz2qUdlqI3vp6s9LSSZsT9yDmeGAItKy7MgJgGRdV4rpqrfJokyP U5tVAGcVXnBxCLYXgDvWoQRZ8MOCljQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2WLX-0001ZJ-Bk; Wed, 19 Sep 2018 06:52:23 +0000 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2WLT-0001Xp-8T for linux-arm-kernel@lists.infradead.org; Wed, 19 Sep 2018 06:52:20 +0000 Received: by mail-it0-x244.google.com with SMTP id j81-v6so6862701ite.0 for ; Tue, 18 Sep 2018 23:52:08 -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=8J6RqrCYqxFTJGEKNKL5VAPGu8G2QxV+5l6IwAhc2Vs=; b=ADm/6+MjVXgAegUp5TVm/hq5rbbVz3gDtj3CZAjLBEjT9zj8k/VwpzY+M0JLvpEv8W CGCIeKWNX0miypBSnGmmDHifkA0iFm8QxoxoDA3169xzWuQhd/37QqRcWYxOAY/by+12 ws1A1r+RXaUCxt4XvuskAO+WLSy3DZ6idt2IQ= 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=8J6RqrCYqxFTJGEKNKL5VAPGu8G2QxV+5l6IwAhc2Vs=; b=CRnFmZFlCGeRyRIHPJHjFDzE/WlJb4ecR1Z5C4pNf9wD6qpBCwE2WfZXThLnu+7JMf tiX3ETE4Jim2gQOjvj9heKwCciXE1A7Fw/7NKYz6FUcSzM0RLARO+aTF32dTDbxDXjnc ODnq6qLuUGLKf8rXbU7F3M+kH39BlLPLnp/FqZOGHAHKu9oc7zzSawk8di3RuhZ1smbq wUppGl48tZT3lgAXMlFuhje/KLRddv9//wTrEk9v9EzuHX4WZABY3hPI5zh//6NwOoZo Z0BAGvvR5ZFcUNr7wKagjmistxq1PXqyKkCT5Jm4UZcYXunHqjBGPykemmjZFOq1qBU6 HBRQ== X-Gm-Message-State: APzg51BkMaykgzzQvjTTQ1ErHP8g7+SEw2rxol3FQghI8MRUZqvhElg3 328cOx2y+XqdigmaY/6NEK0NRQ== X-Google-Smtp-Source: ANB0VdZbnNgHlyjztwE/tFcpbSEae7QHtRHdrfd/pW2ZoFxs0/q7jEor28e3gmlAuyiunPXLtMRWeA== X-Received: by 2002:a24:ad11:: with SMTP id c17-v6mr20577071itf.46.1537339928258; Tue, 18 Sep 2018 23:52:08 -0700 (PDT) Received: from localhost.localdomain ([209.82.80.116]) by smtp.gmail.com with ESMTPSA id x68-v6sm7939477ita.2.2018.09.18.23.52.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 23:52:07 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Subject: [PATCH v3 0/9] add support for relative references in jump tables Date: Tue, 18 Sep 2018 23:51:35 -0700 Message-Id: <20180919065144.25010-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180918_235219_306082_127DA72A X-CRM114-Status: GOOD ( 19.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390@vger.kernel.org, Kees Cook , Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Will Deacon , Jessica Yu , Heiko Carstens , Steven Rostedt , Ingo Molnar , Catalin Marinas , Martin Schwidefsky , Thomas Gleixner , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Patch #9 enables the feature for s390 (contributed by Heiko) Changes since v2: - fix breakage in user mode x86 kernel due to missing definition of the R_X86_64_PC64 symbolic constant - add acks from Jessica and Kees - add s390 enablement patch 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 Heiko Carstens (1): s390/jump_label: switch to relative references arch/Kconfig | 3 + arch/arm64/Kconfig | 1 + arch/arm64/include/asm/jump_label.h | 38 ++++---- arch/arm64/kernel/jump_label.c | 6 +- arch/s390/Kconfig | 1 + arch/s390/include/asm/jump_label.h | 40 ++++---- arch/s390/kernel/jump_label.c | 11 ++- arch/s390/kernel/vmlinux.lds.S | 1 + arch/x86/Kconfig | 1 + arch/x86/include/asm/elf.h | 3 +- arch/x86/include/asm/jump_label.h | 24 ++--- arch/x86/kernel/jump_label.c | 62 +++++------- arch/x86/kernel/module.c | 6 ++ arch/x86/tools/relocs.c | 10 ++ arch/x86/um/asm/elf.h | 3 +- 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 +- 21 files changed, 226 insertions(+), 174 deletions(-) Acked-by: Peter Zijlstra (Intel)