Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp272272imm; Mon, 2 Jul 2018 11:14:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpePhPot1NIlUs7mNZy6VM2FtSXTz0c2EmEQNtmIT3s7/Jirh9K2rinSabl4YjbfH+NAKx4C X-Received: by 2002:a65:6143:: with SMTP id o3-v6mr9715882pgv.52.1530555293055; Mon, 02 Jul 2018 11:14:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530555293; cv=none; d=google.com; s=arc-20160816; b=Ct4edRn3Zl2lxCo5u/mzMk+ANafIOTyRw7YnajvzfBLAAsublLDffkRjve8fSQGrkK 9vA8vj7daHPm4dfK7UF5SpmCVUNDnQ8Xz+chBHG7ux+1v84oGdEFdPJgMr7gik4V6UeH H0WkSB1GaaIYUsH4U7rckKSKh96rtSBAFmGIdjEX+wdwVSlHRK1G2Ll9HnyrdrMtvuPr aFbPokEh8DiBETFOvaNomDJjEhIp51DyirrQ6XTuRx7bMTCh/SjtJuN0g+glpUIfxc2j +27+sE5BT/9Adtbyzhh38+EbKWTjgYCxJ928Yg4xfz9ah8BwDH0Zj+1HLUhC8mflb/Q+ KQyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=6nUyftJQHbn4ADCDRiHDYhO9k2WDA48zRvsOuVLWFCc=; b=LiIPbqbDW5n+7PYPzUQDZBkom+YCHE9Hi4QhxahRPoEheANcMuhkM8Knw/M3tZ/wKu XSGK0r6cV49A59X5ZREPCJS3mkMBfk9BR/RcLADeUmIsokC5V5Ck+7f1F+G3fV28CytX nIGiUKiHS5jzCPTAJa1Ca9OC0MCo/a7xbxy3ta87woDV3v+enMV4hPYzvOQD/QLEAMzJ h9Ys1/uhJl2rdm3Id/Wi8omPz07K/Ckgk4IRpWQF2oIZBsoRyUrk+zsbliB5f8krdqoL 3VuZ+l14n9wiT6dFZdRcYvTAyjl5hQt8gJaV10JjWkujTWCrDgFNdoCkMC7muL5hSPyK x8kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MH9B829V; 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 11-v6si16883246plc.466.2018.07.02.11.14.37; Mon, 02 Jul 2018 11:14:53 -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=MH9B829V; 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 S1753403AbeGBSMI (ORCPT + 99 others); Mon, 2 Jul 2018 14:12:08 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:32779 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753348AbeGBSMD (ORCPT ); Mon, 2 Jul 2018 14:12:03 -0400 Received: by mail-wr0-f196.google.com with SMTP id k7-v6so12933931wrq.0 for ; Mon, 02 Jul 2018 11:12:01 -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=lhPa5z6jjIW2ecI0Fd/lKeCuqszsob0JyGsjzMzWuSNSy5oAe5ws3HVQDAeM/ZYA9i osF8wQshF4FnOrFtzDVhwm6Z8WX4bNEWRRlOMD/7bsk6zAuUeTWAsQYjH3EZxWGMvKYT noh3w2tLf9lTQ//s9Ec4UEcPqQ0mKqA2hvZNXPaVgW3DPkpP6Wycb+dSvr12Lx6XkExT pvDZhccisdUaSVOMhvb0qsTdlUisjBWxBI9FWZ6wCeU2jqvvwPW5Jo8PetbjQ3MqUw7a IopNMmvg6BclOt9cppJzunsA8uRlJTUGgqIkp/ASTPo4+UoQmU2hjLv6uKN38pQz4XYD 5T8g== X-Gm-Message-State: APt69E0mohtSR+B41t5k93SxrL+WfnzSKq0WRicnM7McMNeWHEvp0/f6 N+GjXyk8W4P3wRL8FiRlVhVuSQ== 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 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 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: -- 2.17.1