Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6540425imm; Wed, 27 Jun 2018 09:10:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKcvado1bKhlmDo+0F0uoe06ia0xF95iW+viq0WROOu9jJblF/zAiyltUj7vwlBfEkLGQI4 X-Received: by 2002:a63:107:: with SMTP id 7-v6mr5621934pgb.289.1530115858517; Wed, 27 Jun 2018 09:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530115858; cv=none; d=google.com; s=arc-20160816; b=rBkBH5Lyy0RGex3MQ2HuuuZQ6gjZFPf6x49xuVB6VKBRCI88dG+dB62P82GiQ1j+86 XNZ/D3HD3SqzXTxaAfZKjSE4ATxvF3+CoIVW/ZRulAytFcg8i+ac78FYW2TpF6J5H7UA cRen15ppXACGIqljjW2zc1UuCuoV+oXzHvMGoRPzkbLxlS069EVVofPRaXqZ80Ml9owV m6DppxZ29AAYUogmmS5eEPgfn6HW+LnKyGU5iYjkkVhYYgUhFXAuMSTUWp/9myZfOYM+ jjH0gvz9aYo8o0gEGfQJhFy9MFyRX0nCvKj8qQ42AzEPN5RvRiYkR4+6ueV0hscKbEC8 MYtA== 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=4S8kZQAvHa84YpWVvxunUgaXp0tuBTi7qepgqm8/+QE=; b=bQlJWoCfGp7jtObY2a1vOdzM5TMm+EYyik0i1c6oEdT0WfEbG9ygvHkqruWMGJ1vtk 4Fa4q6XIzDmBJz578BfLwxLvsGLQs7NcoVYse8ewsMn2ZHwsHqzUUBHcpZ5jIUtCKnZD iOFvrQ4Xt8GxJYOpDHGJR+wmtJP9gmFumJcWY/UxbYmugudhQnZIuv33Bpti+JEDQycO /cSbsGpbdwUqNp6MrTgZjQT/4Er1v77dNGLVLDKuUqPE7vf/VAzSu+xl2TjIapcki/2a UmW9b+IAcJbpt9hAf/Wlbu2E8c0vZn9cEBuW0l8kUu9QmRMPhQdjksPy6KbIG0OOaIBE 4xqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bNVV4EdS; 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 73-v6si3789591pga.99.2018.06.27.09.10.43; Wed, 27 Jun 2018 09:10:58 -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=bNVV4EdS; 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 S935111AbeF0QHe (ORCPT + 99 others); Wed, 27 Jun 2018 12:07:34 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:51973 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934916AbeF0QGL (ORCPT ); Wed, 27 Jun 2018 12:06:11 -0400 Received: by mail-wm0-f68.google.com with SMTP id w137-v6so6477111wmw.1 for ; Wed, 27 Jun 2018 09:06:11 -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=4S8kZQAvHa84YpWVvxunUgaXp0tuBTi7qepgqm8/+QE=; b=bNVV4EdSWbYIG3AcgXqoPrgzHv5IuSt1y79hMVSTqlv4GSE4DswGLrww8OA0uUBI4+ hh5hIMZh3Z4SrdgXjLmiRdIWEOb7HOj5fFV/VFoCLlL0JUQYEYCtPuvMJBX+JQBVx9/G tXDhyhXI8X7QnidEH3SaViXefT2ypauu6Asy8= 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=4S8kZQAvHa84YpWVvxunUgaXp0tuBTi7qepgqm8/+QE=; b=CNjNu8RTQN7s1LlKnevB4oZ2WBjl3rd1ISekPzCzmOqVreRYaWYJio/Fv6BmkX48y2 QACvsMy3hXjtXflQYqSO+91eSY1zQqGy30WiofdMMoToRrlCaUmapVFxl/586kamvJo/ nVUQPwrhBqSkCDmQyJpnyLv63+XLuvaUivpk5tm38jwxsS6LQ36bMYzbnI/IqLa8+g2V 2caT6sp/5CXukE1r3B6PucnwuqeqVO1PT1ybrgUltSi9r0kyM7HK4ab8KW2XYgVYxFu4 cQesd2IK7ibLNXJFaS+L8SlT025fzilRsjCnU4B4N26M6JuYkB7rKcmz21MpQjK2KVxZ pZWA== X-Gm-Message-State: APt69E21Dhq9o6KV1e3FXChPxmy5aUCzFV4/HN+7n7msBNcY8PX5lIbw g+Yku/jUNnrl2a10EJsw5nGzCjAb/rQ= X-Received: by 2002:a1c:8c55:: with SMTP id o82-v6mr5246007wmd.60.1530115570114; Wed, 27 Jun 2018 09:06:10 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:4d04:66e:dea8:5b23]) by smtp.gmail.com with ESMTPSA id s2-v6sm7055000wrn.75.2018.06.27.09.06.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 09:06:09 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Arnd Bergmann , Steven Rostedt , Peter Zijlstra Subject: [PATCH 2/5] kernel/jump_label: implement generic support for relative references Date: Wed, 27 Jun 2018 18:06:01 +0200 Message-Id: <20180627160604.8154-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180627160604.8154-1-ard.biesheuvel@linaro.org> References: <20180627160604.8154-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To reduce the size taken up by absolute references in jump label entries themselves and the associated relocation records in the .init segment, add support for emitting them as 32-bit relative references instead. Note that this requires some extra care in the sorting routine, given that the offsets change when entries are moved around in the jump_entry table. Signed-off-by: Ard Biesheuvel --- arch/Kconfig | 3 +++ include/linux/jump_label.h | 28 ++++++++++++++++++++ kernel/jump_label.c | 20 +++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 2b8b70820002..22fa3792626e 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -348,6 +348,9 @@ config HAVE_PERF_USER_STACK_DUMP config HAVE_ARCH_JUMP_LABEL bool +config HAVE_ARCH_JUMP_LABEL_RELATIVE + bool + config HAVE_RCU_TABLE_FREE bool diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index 86ec0652d3b1..aa203dffe72c 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -121,6 +121,32 @@ struct static_key { #include #ifndef __ASSEMBLY__ +#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE + +struct jump_entry { + int code; + int target; + int key; +}; + +static inline unsigned long jump_entry_code(const struct jump_entry *entry) +{ + return (unsigned long)&entry->code + entry->code; +} + +static inline unsigned long jump_entry_target(const struct jump_entry *entry) +{ + return (unsigned long)&entry->target + entry->target; +} + +static inline struct static_key *jump_entry_key(const struct jump_entry *entry) +{ + unsigned long key = (unsigned long)&entry->key + entry->key; + + return (struct static_key *)(key & ~1UL); +} + +#else struct jump_entry; /* defined by the architecture */ @@ -139,6 +165,8 @@ static inline struct static_key *jump_entry_key(const struct jump_entry *entry) return (struct static_key *)((unsigned long)entry->key & ~1UL); } +#endif + static inline bool jump_entry_is_branch(const struct jump_entry *entry) { return (unsigned long)entry->key & 1UL; diff --git a/kernel/jump_label.c b/kernel/jump_label.c index c3524c9b3004..285eff13ecd1 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -49,6 +49,22 @@ static int jump_label_cmp(const void *a, const void *b) return 0; } +static void jump_label_swap(void *a, void *b, int size) +{ + long delta = (unsigned long)a - (unsigned long)b; + struct jump_entry *jea = a; + struct jump_entry *jeb = b; + struct jump_entry tmp = *jea; + + jea->code = jeb->code - delta; + jea->target = jeb->target - delta; + jea->key = jeb->key - delta; + + jeb->code = tmp.code + delta; + jeb->target = tmp.target + delta; + jeb->key = tmp.key + delta; +} + static void jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) { @@ -56,7 +72,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) size = (((unsigned long)stop - (unsigned long)start) / sizeof(struct jump_entry)); - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL); + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, + IS_ENABLED(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE) ? jump_label_swap + : NULL); } static void jump_label_update(struct static_key *key); -- 2.11.0