From patchwork Wed Jul 4 08:36:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141024 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp543283ljj; Wed, 4 Jul 2018 01:41:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcSZo8N4pwh3LoKq+PQsx6KFGhcZEsKM9PEzFixISbFGdeeL12/MWWMl3/9hpsQ/EL8UnqX X-Received: by 2002:a63:4857:: with SMTP id x23-v6mr1114415pgk.30.1530693677729; Wed, 04 Jul 2018 01:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530693677; cv=none; d=google.com; s=arc-20160816; b=WJGNYiX9Dj7viKw0453AA6DdURnoJQWgjdMc+CiJvSRNwozw0Ac8+M1FCWxjwuQ3CK lx5AWNqPdaazWDDNHlAZmhCt5LZnc2+bEvjM7tPHxwY/X0dV+abnh4bIUzZazRwFwZts WdXPPxO2MRURwpa2v89ikD5WP7q5Ovd9952BOU3dxD4uNWGZRTWVozyKDM8r045IJLIY 5DjrD/2QrMsn7RGuVHj3SJPOqCvbgZHcZdxSa4+kH0yZceKRx9ruxkRbtftNyFaUeNS8 WnzttfJ40nFfQ0o2YjmYYvCaDAR1ha/9ERC+3OnU+tUni7Qg308w9dHQHndjjdsSUi1z vpqg== 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=p91lF12qdUvsqqUYIEbuayY71r/VOTp9g79ZDtfXMw4=; b=dfjQR5v1RmP0wq00ctZLVKjuIawGRd3Dws/Cs9drIMiTu1hvresJxitxyEb7Hcc5LI 84txOKb+E8MDsxFpzTJufHLzM8KTszGwZ9t6comhgv/DslgKvnUpRwhWENSUh1MpifR0 OWQ6mkl2GF8ajHqG89Otd2zruk9CX7WwM9LGPTber6W8ETruFXn3jvKWqSHm1KugxWTU 5Af70BmAcEyxDv3N6LHS5H3Bone3TYiLsH5Alt+5hsovpjpnOQe6KmbdDs3jD3WRqyw5 xfv//2KnMqx/oMKtUZoYwA4HT8hqO64sOVtxSJwiMzUPL7lbCAUwVrfsvkD3luJ7GzOr 9SIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kgpSJneX; 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 u21-v6si2896156pgn.86.2018.07.04.01.41.17; Wed, 04 Jul 2018 01:41:17 -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=kgpSJneX; 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 S934235AbeGDIlO (ORCPT + 31 others); Wed, 4 Jul 2018 04:41:14 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:34112 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933594AbeGDIiy (ORCPT ); Wed, 4 Jul 2018 04:38:54 -0400 Received: by mail-ed1-f66.google.com with SMTP id d3-v6so3477576edi.1 for ; Wed, 04 Jul 2018 01:38:53 -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=p91lF12qdUvsqqUYIEbuayY71r/VOTp9g79ZDtfXMw4=; b=kgpSJneXTy3GRlY2BU7xjQ+bRlydSilw80tXvVnEVaWwXQI+TFsnpzI0JyI9LBD98Q rEe3fOpCQYrHoDDfnTTwLOsvJB+d5nPG7lPNq1tpVD10Ef1cKgEVU2W9i5hCEpwSqoVB 64fmJQGBVdEfTVY8Fnpgs1HzzqFjctVDmUD3U= 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=p91lF12qdUvsqqUYIEbuayY71r/VOTp9g79ZDtfXMw4=; b=V5pBjITg5x3CH0l4XGej9azb3lm0IYi9ssLYPbN5z90gVacEypdY2hwt2bO84wNCSC zVfG3kfmpC/15heqznExPw4Tv0PIFydarq4sivMAluOqRYA5hvW0iMoH4sbaS9lTUWW9 Uuu5MdAyYuyCORDY1SxY0PP01GtqPyB8SDZndDsOL0kMsapL7Sbng03UOj/uK3VOjtwu dfWLWj9QmhoWpGOnJhayeNjJJD0rMeSNONDA+5xSbV6Z5PsjpaTvjPjHuzYh2XAD/t6a tfNp0RTQvBkwIbO8czg9Ll282RB+VTUMf18jap6QFX35gq+9taRh6GpvOETn+ft02QQz jTqg== X-Gm-Message-State: APt69E1dS+YrgX09dHd1NG2BBSHCgwpnhVxo+DU84pOnhH7ZUAq9HIjB qIvUgohZJ1ToIoApjydxmRJmQFrYcSY= X-Received: by 2002:a50:f4d2:: with SMTP id v18-v6mr1758005edm.162.1530693532907; Wed, 04 Jul 2018 01:38:52 -0700 (PDT) Received: from ards-mac-mini.arnhem.chello.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id k13-v6sm1821740edj.55.2018.07.04.01.38.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 01:38:52 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.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-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v10 4/6] init: allow initcall tables to be emitted using relative references Date: Wed, 4 Jul 2018 10:36:49 +0200 Message-Id: <20180704083651.24360-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180704083651.24360-1-ard.biesheuvel@linaro.org> References: <20180704083651.24360-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. Acked-by: James Morris Acked-by: Sergey Senozhatsky Acked-by: Petr Mladek Acked-by: Michael Ellerman Acked-by: Ingo Molnar Signed-off-by: Ard Biesheuvel --- include/linux/init.h | 44 +++++++++++++++----- init/main.c | 32 +++++++------- kernel/printk/printk.c | 16 +++---- security/security.c | 17 ++++---- 4 files changed, 68 insertions(+), 41 deletions(-) -- 2.17.1 diff --git a/include/linux/init.h b/include/linux/init.h index bc27cf03c41e..2538d176dd1f 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 " #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 3b4ada11ed52..e59a01f163d6 100644 --- a/init/main.c +++ b/init/main.c @@ -901,18 +901,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, @@ -938,7 +938,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], @@ -949,7 +949,7 @@ static void __init do_initcall_level(int level) trace_initcall_level(initcall_level_names[level]); 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) @@ -980,11 +980,11 @@ static void __init do_basic_setup(void) static void __init do_pre_smp_initcalls(void) { - initcall_t *fn; + initcall_entry_t *fn; trace_initcall_level("early"); 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 247808333ba4..688a27b0888c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2772,7 +2772,8 @@ EXPORT_SYMBOL(unregister_console); void __init console_init(void) { int ret; - initcall_t *call; + initcall_t call; + initcall_entry_t *ce; /* Setup the default TTY line discipline. */ n_tty_init(); @@ -2781,13 +2782,14 @@ void __init console_init(void) * set up the console device so that later boot sequences can * inform about problems etc.. */ - call = __con_initcall_start; + ce = __con_initcall_start; trace_initcall_level("console"); - while (call < __con_initcall_end) { - trace_initcall_start((*call)); - ret = (*call)(); - trace_initcall_finish((*call), ret); - call++; + while (ce < __con_initcall_end) { + call = initcall_from_entry(ce); + trace_initcall_start(call); + ret = call(); + trace_initcall_finish(call, ret); + ce++; } } diff --git a/security/security.c b/security/security.c index 68f46d849abe..1e7b1486d82a 100644 --- a/security/security.c +++ b/security/security.c @@ -48,14 +48,17 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] = static void __init do_security_initcalls(void) { int ret; - initcall_t *call; - call = __security_initcall_start; + initcall_t call; + initcall_entry_t *ce; + + ce = __security_initcall_start; trace_initcall_level("security"); - while (call < __security_initcall_end) { - trace_initcall_start((*call)); - ret = (*call) (); - trace_initcall_finish((*call), ret); - call++; + while (ce < __security_initcall_end) { + call = initcall_from_entry(ce); + trace_initcall_start(call); + ret = call(); + trace_initcall_finish(call, ret); + ce++; } }