From patchwork Mon Jul 2 18:11:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10502267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BA54B6035E for ; Mon, 2 Jul 2018 18:22:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB68425826 for ; Mon, 2 Jul 2018 18:22:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F47126E96; Mon, 2 Jul 2018 18:22:01 +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 autolearn=unavailable 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 4719225826 for ; Mon, 2 Jul 2018 18:22:01 +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:References: In-Reply-To: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:List-Owner; bh=cFQhvL1QRZ2f4wt/MXDhKZG6csSa75hAuVuUjPiVW0Q=; b=HwZbVbHe4gFc3Mpcj0p8SBZHb0 mEOhR5WxW9cFKbMYKxdEKTK+tUMboY1RSvOw5DV2B7qv2wdiTbzUxtqRe3orU/jQTauXMwco5dVM4 Mt7cDOhkZyO4FYP1MQoAVV+iKq8OvsYZbI2oZMxpBdV0zauiKtE+nz5LaIGOnyBNEK2QJL4zx8jGS zTJDIRi0/6kjPOTuJ+Pd66uqNLP5CMvySCg+TemfQfNJZa3ynEZ6m80Y4r2o2lCC44GcGpcm8aCM7 zzlvL0PIOYHU0U/2ItQ3PrmZRBW5HD/oQwZFWbbOdUVQFABMUQPYvC4G+QSMXcg02SUZZju/PUs6n neVNbCGQ==; 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 1fa3SW-0004ZG-OC; Mon, 02 Jul 2018 18:21:56 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fa3J7-0007s9-6L for linux-arm-kernel@lists.infradead.org; Mon, 02 Jul 2018 18:12:45 +0000 Received: by mail-wr0-x243.google.com with SMTP id s11-v6so7188194wra.13 for ; Mon, 02 Jul 2018 11:12:02 -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:in-reply-to:references; bh=6nUyftJQHbn4ADCDRiHDYhO9k2WDA48zRvsOuVLWFCc=; b=MH9B829VsTLGEaymnuo3lvDs2YlPFP+tCJ4WAiPdSGavKSbuibs/57DY2V9s64nv+N Wu5/hzTyQX4OgnsjUsQWylcvIfyPpRPM9ImXRgbF/Vb7Wo4c3RDzobRfDcLQNlFTvAD/ CtHAKlxbhonAXmdbn45KBkVYQlAigW8Nd+8/0= 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:in-reply-to :references; bh=6nUyftJQHbn4ADCDRiHDYhO9k2WDA48zRvsOuVLWFCc=; b=Yj+1b3xIq4T8r3LRQXRL7zvKQPLc5HmHNfYe91AIAM1ZBGoqjBBgekrXjjnSPq8cnw a4p35uGMxMWgxUMDuk4IbxdF2wq2l/eqUrmsUbOzR/pdnUq+1tgXrlW/xjdmczMOrhlw umOST0vqH7wejhuH2xa6OfjCU7yjQq9xqNEnB/27cPwfrqOCAxybuKOeqYtOAc4gSfmi NtKJBmeZ0UukyGeoFEla2mEYaN90v+UY1zJDzpJN7g9t/znXT0HpC/ZvTL793+nTIGJS MgbN0oh2RuxCoUfiT9VR5okaVKZR5sHwPuPvn1IJpeIqqh86Ds2JynMYsiXdR1fXOtIp iQdA== X-Gm-Message-State: APt69E3HsExiGyz3ZlZZ5ZffWyFBbCX7XuPsVHigoz3qhs7Ve9H+gCir 479vCo8nRmAs9dEOf82ypyQ7LWhOPXA= X-Google-Smtp-Source: AAOMgpesmv2Ba2zn6vBjDDOjkc3I5zkakY1L5X6Xcu1PloSX8qsLRii6h5H9YlmxuLvr4fT2wRktjQ== X-Received: by 2002:adf:f50e:: with SMTP id q14-v6mr76852wro.241.1530555121138; Mon, 02 Jul 2018 11:12:01 -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.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jul 2018 11:12:00 -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 Subject: [PATCH v2 4/8] x86: add support for 64-bit place relative relocations Date: Mon, 2 Jul 2018 20:11:41 +0200 Message-Id: <20180702181145.4799-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180702181145.4799-1-ard.biesheuvel@linaro.org> References: <20180702181145.4799-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180702_111213_401118_C2C5A965 X-CRM114-Status: GOOD ( 15.70 ) 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: Kees Cook , Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Heiko Carstens , Jessica Yu , Will Deacon , Steven Rostedt , Ingo Molnar , Catalin Marinas , Martin Schwidefsky , Thomas Gleixner 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 Add support for R_X86_64_PC64 relocations, which operate on 64-bit quantities holding a relative symbol reference. This allows jump table entries to be emitted in a way that makes them invariant under runtime relocation, which means that no metadata needs to be emitted into the kernel image to describe such data structures, resulting in a size reduction. Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/elf.h | 1 + arch/x86/kernel/machine_kexec_64.c | 4 ++++ arch/x86/kernel/module.c | 6 ++++++ arch/x86/tools/relocs.c | 10 ++++++++++ 4 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 0d157d2a1e2a..d3925d684296 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -62,6 +62,7 @@ typedef struct user_fxsr_struct elf_fpxregset_t; #define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ #define R_X86_64_8 14 /* Direct 8 bit sign extended */ #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ +#define R_X86_64_PC64 24 /* Place relative 64-bit signed */ #define R_X86_64_NUM 16 diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c index 4c8acdfdc5a7..6638d1edb2be 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -496,6 +496,10 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi, value -= (u64)address; *(u32 *)location = value; break; + case R_X86_64_PC64: + value -= (u64)address; + *(u64 *)location = value; + break; default: pr_err("Unknown rela relocation: %llu\n", ELF64_R_TYPE(rel[i].r_info)); diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index f58336af095c..b052e883dd8c 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -201,6 +201,12 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, goto overflow; #endif break; + case R_X86_64_PC64: + if (*(u64 *)loc != 0) + goto invalid_relocation; + val -= (u64)loc; + *(u64 *)loc = val; + break; default: pr_err("%s: Unknown rela relocation: %llu\n", me->name, ELF64_R_TYPE(rel[i].r_info)); diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 220e97841e49..a4075bc37e8f 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -195,6 +195,7 @@ static const char *rel_type(unsigned type) #if ELF_BITS == 64 REL_TYPE(R_X86_64_NONE), REL_TYPE(R_X86_64_64), + REL_TYPE(R_X86_64_PC64), REL_TYPE(R_X86_64_PC32), REL_TYPE(R_X86_64_GOT32), REL_TYPE(R_X86_64_PLT32), @@ -781,6 +782,15 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, add_reloc(&relocs32neg, offset); break; + case R_X86_64_PC64: + /* + * Only used by jump labels + */ + if (is_percpu_sym(sym, symname)) + die("Invalid R_X86_64_PC64 relocation against per-CPU symbol %s\n", + symname); + break; + case R_X86_64_32: case R_X86_64_32S: case R_X86_64_64: