From patchwork Mon Dec 25 20:54:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 122702 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp225814qgn; Mon, 25 Dec 2017 12:55:47 -0800 (PST) X-Google-Smtp-Source: ACJfBosxLI4sGSuo4wD//cydXuWYflXHQjbHRtrqqrMMXwUVBvxj9Rk9+HD2doSPAfNNht6wRjLt X-Received: by 10.99.111.206 with SMTP id k197mr20110729pgc.182.1514235347254; Mon, 25 Dec 2017 12:55:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514235347; cv=none; d=google.com; s=arc-20160816; b=VhF5w/XYynh59p6hGMYpLGhwaGQDDGsOT3rHx9veEoNOHJvhZ2SQDtqN6sLCdgaAs7 qCjbwyJJzofbL5RZZPyCbYmi1RnatVTvEo3l3d1OUE5XDEQ31XmE3OrgtLDBW+6fVOeC Gdeqt/00dSO3oJzmj85VmoBQ79+xehBAhFcg2s07yiQIcmmPDw3TdR4RO3TZFrQWGmAp l/E6ztQfBZx1cBi/SUMcfrRIJskRP0JuJTtGqg3iTncxR/+PqxPTpxL/WMfaIL8HPWg+ W/QGiezaDbATpZtQXc5UfWvA3EDC3pDLAUgc4PqRSjOFjHsGfWJ9ljX0UY5zQceWlqbK rjaQ== 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=lwLLrS7mueZ/zWj6YdhKL1lPIayLUTMzei7H77VCkQk=; b=hePPy8lEMguhFNRAx15UASV2uSqTWb4b0PCJ+T9ALKsnhzuyZCYhAMh6XOTJmRGulr 5vSBWCvJ1oX+4Il5ZV0dTu444sCs70gMu+cSAjZRVAmelWvLByLFeh6LgVG8WBxiPJUM ZQ/dOJN2aUpXU+Ql9HOUYBDPtMJndqjt+pPWfiaAB+htJvefel+L6dAaR3BvgELL0WCZ rhBciu2dlVTyumdZXRo58iY0ydwnaSjhEe745CPahjMUvKRjLG3wBdNBnCIdqrmw/WxX ZXwSjT8gmd4NQ4BdT0J06DygZYbt6pg+gdtr1FIrRDXgVu5Vh5AF2LlRT12HHJLghoO1 OesA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jcUuSxDj; 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 d12si21505668plo.388.2017.12.25.12.55.47; Mon, 25 Dec 2017 12:55:47 -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=jcUuSxDj; 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 S1753144AbdLYUzj (ORCPT + 28 others); Mon, 25 Dec 2017 15:55:39 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37293 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753222AbdLYUza (ORCPT ); Mon, 25 Dec 2017 15:55:30 -0500 Received: by mail-wr0-f195.google.com with SMTP id f8so22633173wre.4 for ; Mon, 25 Dec 2017 12:55:29 -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=lwLLrS7mueZ/zWj6YdhKL1lPIayLUTMzei7H77VCkQk=; b=jcUuSxDjV6qUlFZNfjkwkooWeBRAhtuALdqXGpiYFN0qh/ik9DBdMQ/0X349oC23d0 3JjZFTNGenNghv+0eehfkXmrQl6pGeZ09YoXEr87h7h+7jtcTJyn0YJkqPrZ8ebqVGvB Bmo1HnZgSr2zEZjku2OZ+nZZWCzvV0gwm31pg= 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=lwLLrS7mueZ/zWj6YdhKL1lPIayLUTMzei7H77VCkQk=; b=JMHhhTPzS6Z7qGzDKpLxEE0gVjge0IgFGU9LVvbQQBRa2yrhxdcBV466Y1Rrw31a9H n9N6GYK5fJWu9yLDJ3UnCm5G9O9jd7MN1QcRMqeJ48fLlh2YCInbmDv0UkJbUQV5y36S 28UlqVOe1BUSRaRpn5EsDrKbvP/nvcDlaUuF7LjNwys5KTAIG6o0AYBj8my8SSEQ6W/A 1T2VorXqsEk5W+6mezPGZ9GabjW46S8QXts8v4LyYnc2hhZalIplhuOZn+MY523nNr4h dKssCu3tveWh+wFH3b5dlHp2i429i0/LbXvPcsDtySG09YFVqEEOfiUnWrzf6aPOZs3L wRag== X-Gm-Message-State: AKGB3mItodgGEb3B+/D01phIypGTmhlrWyI9YiZWAxMRxCYOaNAXpFK5 oKmLccYS2H/nLHMEucNRwiZaBp17+L8= X-Received: by 10.223.128.9 with SMTP id 9mr15934739wrk.70.1514235328837; Mon, 25 Dec 2017 12:55:28 -0800 (PST) Received: from localhost.localdomain ([160.171.216.245]) by smtp.gmail.com with ESMTPSA id y42sm39552441wrc.96.2017.12.25.12.55.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Dec 2017 12:55:28 -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 v5 3/8] init: allow initcall tables to be emitted using relative references Date: Mon, 25 Dec 2017 20:54:35 +0000 Message-Id: <20171225205440.14575-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171225205440.14575-1-ard.biesheuvel@linaro.org> References: <20171225205440.14575-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..125bbea99c6b 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 signed 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 7b606fc48482..2cbe3c2804ab 100644 --- a/init/main.c +++ b/init/main.c @@ -845,18 +845,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, @@ -882,7 +882,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], @@ -892,7 +892,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) @@ -923,10 +923,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++; } }