From patchwork Sun Mar 11 12:38:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 131347 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3055986lja; Sun, 11 Mar 2018 05:39:56 -0700 (PDT) X-Google-Smtp-Source: AG47ELu/xuCBXH2LYPrQgreSJpOynh6KraFJeBXSJPdcV9EQY6+NVEj68VnP5mgukfFiKY0baHF2 X-Received: by 10.99.126.24 with SMTP id z24mr1511442pgc.110.1520771996408; Sun, 11 Mar 2018 05:39:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520771996; cv=none; d=google.com; s=arc-20160816; b=MA7rSQeEntTLytQSj7yr+LoBEyp3cqQzShBiclzxvKVqipscGW9kzSnCgDPLeyHv+h HhRO+tWRyiErBvqmfim2vo4TZwgOoWC2A3C4HqK/b5oeDZasi9zGf3CTM8wSDbvvW0Cc MkmCAQv8O3BVsJ9b79rxq3AhyjOIH53TOjXXcu2OxwsuyYZyj3okdDiKWFo+yPhCuRQE fXiTH3Z9br2L/D+V9xyJtwub4/7QMhpfanQqueCRZ2yl4r8VxJcIMLkRoTS2hcXomu1m DPUfpMrO5jrJ1wJPLqkEJCOyI0LCLQ+qc58xEN2NN/orUhXINHyOqMz2moB9nS12x/FA 4aUw== 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=A6CdKGtcFxvkcJyprZ73SqXJmQeUMwPknEJEYW8ClQg=; b=iPW00e8k6kW1ltw7SHl+SiWE3b2iO2OO00lr3dRY3Z8t/7uMJp9tJZSNpVZn+dCs74 MhCJKoiIRWZG0YMPINqE7DEyVbvzU1QO08lv41yEfyr/cL51sFDJ/Z9lYK6Pd8RAjZ5w B+UNXCKGlFJkdTK+NGRXDYXAkHnNaxCat524ACw54eEBb35MJvAQQBFFnvDiyU8b36lw 2bYX9leoO7nmkRe9iEy0xKTD6VS170lAofKs6C6lkhqyR2azGZsknP9IjxG7bXW41nAn EG92VFq4Q8WaZt9p5VllrwKUYf1i2uKes4p/qsp2hp9yd3vaWdcNL5JbFEzJrkwoUq3y VcRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HDlfrQqh; 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 q10si4171017pfc.183.2018.03.11.05.39.56; Sun, 11 Mar 2018 05:39:56 -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=HDlfrQqh; 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 S932344AbeCKMjw (ORCPT + 28 others); Sun, 11 Mar 2018 08:39:52 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37230 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932242AbeCKMjL (ORCPT ); Sun, 11 Mar 2018 08:39:11 -0400 Received: by mail-wm0-f65.google.com with SMTP id 139so11288630wmn.2 for ; Sun, 11 Mar 2018 05:39:10 -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=A6CdKGtcFxvkcJyprZ73SqXJmQeUMwPknEJEYW8ClQg=; b=HDlfrQqhCKNaq81bcQzsRKbMg/kFKS4+WUFlfWP3mLAJ0D7fn0+BT5VP8f0NnXiG0y RjHQxTnnDpFm9AHfDdaCSxP1NdV5nP2tR+JkXE1RnBk5lt8sqndIQZCaxjElFMxdSv0H Yt4YnZyueus1wuWYfSgP2/JilnSM9JC+n0J5s= 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=A6CdKGtcFxvkcJyprZ73SqXJmQeUMwPknEJEYW8ClQg=; b=gl3TkHG23IwFtWIMek8ShOzKu1DD1qpupechsq3hQX4yhdB3Pl6L/lnoDeaevwBabV Hd5g7iUBeAf1VzM5qhqAhmf8fZqUkgNnsCCiOphFVpmxK7cMPvGG+dKmVrMUxZcuouR9 g7evQV9430moCCuoiBp0hbD6PLZX1El6ELD4XXxB8GPP7VU9VQp7t9vZ4Zf9UAJI52Dh oTjp0CUCOSIU9Js5/n177KWaqYVd/J5Q2KJ6HoUgCaL2//6iake9lXhXSgLMmRth5euR hD2hQ/zdjQOw8zKxRFSLVoyskCbTXdmV6BtbctM/RsnTVBOGFlAAO5HXQ7l90pD+PO+7 6l5Q== X-Gm-Message-State: AElRT7EK6oJW5p//lBMvTzD71Ll//vxlvn35WXc47A1CsxlYqS8mFrQ5 +DDP6jx/tFDalb8IU9LGw0+hSw== X-Received: by 10.28.217.205 with SMTP id q196mr3300150wmg.149.1520771950287; Sun, 11 Mar 2018 05:39:10 -0700 (PDT) Received: from localhost.localdomain ([105.148.128.186]) by smtp.gmail.com with ESMTPSA id h188sm2569103wmf.37.2018.03.11.05.39.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 05:39:09 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Arnd Bergmann , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v8 4/6] init: allow initcall tables to be emitted using relative references Date: Sun, 11 Mar 2018 12:38:13 +0000 Message-Id: <20180311123815.17916-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180311123815.17916-1-ard.biesheuvel@linaro.org> References: <20180311123815.17916-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow the initcall tables to be emitted using relative references that are only half the size on 64-bit architectures and don't require fixups at runtime on relocatable kernels. Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Steven Rostedt Cc: James Morris Cc: "Serge E. Hallyn" Signed-off-by: Ard Biesheuvel --- include/linux/init.h | 44 +++++++++++++++----- init/main.c | 32 +++++++------- kernel/printk/printk.c | 4 +- security/security.c | 4 +- 4 files changed, 53 insertions(+), 31 deletions(-) -- 2.15.1 diff --git a/include/linux/init.h b/include/linux/init.h index 506a98151131..cca0f76bf4a6 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -116,8 +116,24 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); -extern initcall_t __con_initcall_start[], __con_initcall_end[]; -extern initcall_t __security_initcall_start[], __security_initcall_end[]; +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS +typedef int initcall_entry_t; + +static inline initcall_t initcall_from_entry(initcall_entry_t *entry) +{ + return offset_to_ptr(entry); +} +#else +typedef initcall_t initcall_entry_t; + +static inline initcall_t initcall_from_entry(initcall_entry_t *entry) +{ + return *entry; +} +#endif + +extern initcall_entry_t __con_initcall_start[], __con_initcall_end[]; +extern initcall_entry_t __security_initcall_start[], __security_initcall_end[]; /* Used for contructor calls. */ typedef void (*ctor_fn_t)(void); @@ -167,9 +183,20 @@ extern bool initcall_debug; * as KEEP() in the linker script. */ -#define __define_initcall(fn, id) \ +#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS +#define ___define_initcall(fn, id, __sec) \ + __ADDRESSABLE(fn) \ + asm(".section \"" #__sec ".init\", \"a\" \n" \ + "__initcall_" #fn #id ": \n" \ + ".long " VMLINUX_SYMBOL_STR(fn) " - . \n" \ + ".previous \n"); +#else +#define ___define_initcall(fn, id, __sec) \ static initcall_t __initcall_##fn##id __used \ - __attribute__((__section__(".initcall" #id ".init"))) = fn; + __attribute__((__section__(#__sec ".init"))) = fn; +#endif + +#define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id) /* * Early initcalls run before initializing SMP. @@ -208,13 +235,8 @@ extern bool initcall_debug; #define __exitcall(fn) \ static exitcall_t __exitcall_##fn __exit_call = fn -#define console_initcall(fn) \ - static initcall_t __initcall_##fn \ - __used __section(.con_initcall.init) = fn - -#define security_initcall(fn) \ - static initcall_t __initcall_##fn \ - __used __section(.security_initcall.init) = fn +#define console_initcall(fn) ___define_initcall(fn,, .con_initcall) +#define security_initcall(fn) ___define_initcall(fn,, .security_initcall) struct obs_kernel_param { const char *str; diff --git a/init/main.c b/init/main.c index a8100b954839..d81487cc126d 100644 --- a/init/main.c +++ b/init/main.c @@ -848,18 +848,18 @@ int __init_or_module do_one_initcall(initcall_t fn) } -extern initcall_t __initcall_start[]; -extern initcall_t __initcall0_start[]; -extern initcall_t __initcall1_start[]; -extern initcall_t __initcall2_start[]; -extern initcall_t __initcall3_start[]; -extern initcall_t __initcall4_start[]; -extern initcall_t __initcall5_start[]; -extern initcall_t __initcall6_start[]; -extern initcall_t __initcall7_start[]; -extern initcall_t __initcall_end[]; - -static initcall_t *initcall_levels[] __initdata = { +extern initcall_entry_t __initcall_start[]; +extern initcall_entry_t __initcall0_start[]; +extern initcall_entry_t __initcall1_start[]; +extern initcall_entry_t __initcall2_start[]; +extern initcall_entry_t __initcall3_start[]; +extern initcall_entry_t __initcall4_start[]; +extern initcall_entry_t __initcall5_start[]; +extern initcall_entry_t __initcall6_start[]; +extern initcall_entry_t __initcall7_start[]; +extern initcall_entry_t __initcall_end[]; + +static initcall_entry_t *initcall_levels[] __initdata = { __initcall0_start, __initcall1_start, __initcall2_start, @@ -885,7 +885,7 @@ static char *initcall_level_names[] __initdata = { static void __init do_initcall_level(int level) { - initcall_t *fn; + initcall_entry_t *fn; strcpy(initcall_command_line, saved_command_line); parse_args(initcall_level_names[level], @@ -895,7 +895,7 @@ static void __init do_initcall_level(int level) NULL, &repair_env_string); for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) - do_one_initcall(*fn); + do_one_initcall(initcall_from_entry(fn)); } static void __init do_initcalls(void) @@ -926,10 +926,10 @@ static void __init do_basic_setup(void) static void __init do_pre_smp_initcalls(void) { - initcall_t *fn; + initcall_entry_t *fn; for (fn = __initcall_start; fn < __initcall0_start; fn++) - do_one_initcall(*fn); + do_one_initcall(initcall_from_entry(fn)); } /* diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index fc1123583fa6..0be1e8524873 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2780,7 +2780,7 @@ EXPORT_SYMBOL(unregister_console); */ void __init console_init(void) { - initcall_t *call; + initcall_entry_t *call; /* Setup the default TTY line discipline. */ n_tty_init(); @@ -2791,7 +2791,7 @@ void __init console_init(void) */ call = __con_initcall_start; while (call < __con_initcall_end) { - (*call)(); + initcall_from_entry(call)(); call++; } } diff --git a/security/security.c b/security/security.c index 1cd8526cb0b7..f648eeff06de 100644 --- a/security/security.c +++ b/security/security.c @@ -45,10 +45,10 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] = static void __init do_security_initcalls(void) { - initcall_t *call; + initcall_entry_t *call; call = __security_initcall_start; while (call < __security_initcall_end) { - (*call) (); + initcall_from_entry(call)(); call++; } }