From patchwork Tue Jan 2 20:05:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 123217 Delivered-To: patch@linaro.org Received: by 10.80.135.92 with SMTP id 28csp4761215edv; Tue, 2 Jan 2018 12:06:48 -0800 (PST) X-Google-Smtp-Source: ACJfBouts38i+nXF2cDknSDjp4QEaghOYafn4uZV8K/xGEuzBNCbzbkQZxwVq9wFglu16esWVtXW X-Received: by 10.98.36.199 with SMTP id k68mr45735651pfk.236.1514923608336; Tue, 02 Jan 2018 12:06:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514923608; cv=none; d=google.com; s=arc-20160816; b=ZT2fOXErMxJQuZYKJ3uFznSmKcc8/1SwiidmPYvm4pNvE5JpNL8v91Nzacay9crlsr m5kRNwe7JMoXphVuhEuboZfoqogDG8uUpjc6OBi3lUeLjz774bcrlulnaJhOMn9nSSDa edIuVNpOfqg0j/7CgT25upDIE5W3mz1X1F6XHZQEPHDWKv5TBJ9N3Nsw/v9kqzXChmQ2 BrlzRnyyk70NNPcsXR3A4/bsGavKTXcLWsYXLRe+ksw6tjOSW9SdmBFVei5lCuhqM+cL GxSt2k0o5TAZgEZZa6UXo1JxFWbAtOjCwmpZJOXnJO+SMeKtyTj6Cxc51Wvi0GdJtE9a vxtQ== 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=/EOip1AIYHq0lLmjVJhDl5soNaKDqq6XOAGGb6F1q1o=; b=OHP0tBtcaWFiQrO3lIUw8GorQXcRy2J2iuXBxodMNrRgOvy1oR6w8uEIwhPAWnGECs 3tSFIzk6dqvfQZWcSTanouvlOOrCSLQlkFOrvPinX1T8m3Xt/osKw/vNsqGm5KOH884/ lGEeII1gtsRxZBtTDqbHILAd9f3q/7kqatqSxp2GfK4lu6qVl6IVtzDI75W6wqCnuk+S OGPUDQF0oQo9NjWiG1RlJbuF76nv19ZhDfANf2d4KpNiXH9DRiPNCyWp9ogVgZRJtAhu 8s7bTNrpBuJQWTuqKHffsYR241CKg37bAsP4pTJ2l/QHamvOV9rigFsfjJXwLbQiQKHs p21w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MZO1fAVB; 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 e61si7515995plb.524.2018.01.02.12.06.47; Tue, 02 Jan 2018 12:06:48 -0800 (PST) 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=MZO1fAVB; 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 S1751170AbeABUGp (ORCPT + 28 others); Tue, 2 Jan 2018 15:06:45 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:33536 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750787AbeABUGh (ORCPT ); Tue, 2 Jan 2018 15:06:37 -0500 Received: by mail-wr0-f195.google.com with SMTP id v21so38855767wrc.0 for ; Tue, 02 Jan 2018 12:06:36 -0800 (PST) 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=/EOip1AIYHq0lLmjVJhDl5soNaKDqq6XOAGGb6F1q1o=; b=MZO1fAVB5d8JRhoU/dxiG9mAm1vs47AzcIZm005LKWPWqltWMORB0h8IrpNjc6h1yM 3w8IlJB11um83+6PPjZLrCjdybt+umM2Irsf7x405cLMxNqpTDhTjxDr8h/PKA1Z+vnf 9C6rc9lcQI9Zpfy3xhy/B3RqgGlocDfqmj+8I= 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=/EOip1AIYHq0lLmjVJhDl5soNaKDqq6XOAGGb6F1q1o=; b=fWqiJQ1ZaxWFU5FzHSMtHjAopoRxv//A4jZL34OOIwsh5NilMayxAa/WvoBWD2lSBr 72I9ZjiLKhAiNQP7MTlBZWruUvtZvjR9u2I9k8+ySWlryVQnWkVmIcjMXPZB7pM/a5U9 BSMR06FzWP5179gKhxzPqEKOqzbzlvv51KOwA8Lr/3imbIjv4NoMZT8tMi1KIQmr5Eli Jwts7cOJH876A6BAyb+7UngBkMU8g9zb/eMGdT8MKVrdRCGLscc1b+R5ZFD/56Q9pB03 iKLfAkaapw4+viwquHug7WnnGJD30Ko6bKiAJlmc8R3dtGofCtG4EnovF328iAzNBll5 a2ZQ== X-Gm-Message-State: AKGB3mKDb6rxdnFyRqNOtJoEpfeEJFPZpkat+MUeE78pAWGDXW/wpsw2 iYShNjP8FT6HNb7tSwdUdsihQ6K6E0c= X-Received: by 10.223.138.195 with SMTP id z3mr46074806wrz.152.1514923595658; Tue, 02 Jan 2018 12:06:35 -0800 (PST) Received: from localhost.localdomain ([160.89.138.198]) by smtp.gmail.com with ESMTPSA id m70sm19128526wma.36.2018.01.02.12.06.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 12:06:34 -0800 (PST) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: Ard Biesheuvel , "H. Peter Anvin" , Ralf Baechle , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Michael Ellerman , Thomas Garnier , Thomas Gleixner , "Serge E. Hallyn" , Bjorn Helgaas , Benjamin Herrenschmidt , Russell King , Paul Mackerras , Catalin Marinas , "David S. Miller" , Petr Mladek , Ingo Molnar , James Morris , Andrew Morton , Nicolas Pitre , Josh Poimboeuf , Steven Rostedt , Martin Schwidefsky , Sergey Senozhatsky , Linus Torvalds , Jessica Yu , linux-arm-kernel@lists.infradead.org, linux-mips@linux-mips.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v7 04/10] init: allow initcall tables to be emitted using relative references Date: Tue, 2 Jan 2018 20:05:43 +0000 Message-Id: <20180102200549.22984-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180102200549.22984-1-ard.biesheuvel@linaro.org> References: <20180102200549.22984-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.11.0 diff --git a/include/linux/init.h b/include/linux/init.h index ea1b31101d9e..cef8e817e5a5 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -109,8 +109,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 (initcall_t)((unsigned long)entry + *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); @@ -160,9 +176,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. @@ -201,13 +228,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 b9006617710f..0516005261c7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2611,7 +2611,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(); @@ -2622,7 +2622,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++; } }