From patchwork Wed Jun 27 16:06:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 140361 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1069124ljj; Wed, 27 Jun 2018 09:06:16 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI9IMqp7juYAZB/nhfwcqvFxopFAEsu6qaefUGdEqjmNQn4Xe0V/xcX7zJzshfIkHt0/axM X-Received: by 2002:a63:4b1f:: with SMTP id y31-v6mr5827007pga.14.1530115576049; Wed, 27 Jun 2018 09:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530115576; cv=none; d=google.com; s=arc-20160816; b=hRVLbf+SUoaSN33VE55hdS4LS7mklnw2/ZOaYy0hLLFUCtRQB6YNll3/3qvH6HLy/n wgihKCxuhoyrzPq5NKg+/BSB5SkOLUtpEBcIsDQtltuqPZp0N8ys33DC9jolYdWkxcth HtmW7hkagefVryVU6qkXNFaUJBpUa3nxtaT5AlrVBRwoKOO3/3xP0sS/g/+TGs1TbzAM Zjh2y8CQG7WypzDOKD/XEeprYDIwq8Qd1NZ60Ce5fmIx0AMkD8zZlq+kV/Hdl1qI0qtF bd4N1+ctJ8AqoT4xXhpzGfDmAfV7qoKQld74rqAPZKFs/hswCinvhDs236tUmMvgLh8+ 65ng== 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=B883F5dmVQG/nVCIvlNlD4L/gAxRvgth0kf0bW+7srI=; b=Mu+x3ue3M6F30wBWP+ZvkGM05b8qqzagnXmAFXG9vHWMmBpfV9J+5Q5/heOiZqf4hl ttbkCcSLJ7APIrGK5dD/kkpGPbgKcY1OV80mruOOBGCYsQO9JV5+GiNUbmqmRfMe+nN5 8r3HMowFTIosg/vXmgdmB/1KAXTEITHxyViIS1W6Ujy9vwTjD/OiZN5BoNH740uWGEm3 jnBYXtcj7NaJXHayBWPpFE4WouzEj35pkMexYco4irqNDC8Un3AviOY9A8188kUWmEwD UbzIuyT9WYjAps/s8dQNeOvdc8FE1gE5ynF7uawpZh2sbWGHDow0dBOPX2Q4Gvw4gv8u pJPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EtvViJLK; 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 o3-v6si3752232pgc.381.2018.06.27.09.06.15; Wed, 27 Jun 2018 09:06:16 -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=EtvViJLK; 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 S935063AbeF0QGN (ORCPT + 31 others); Wed, 27 Jun 2018 12:06:13 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:39275 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934909AbeF0QGK (ORCPT ); Wed, 27 Jun 2018 12:06:10 -0400 Received: by mail-wm0-f66.google.com with SMTP id p11-v6so6049881wmc.4 for ; Wed, 27 Jun 2018 09:06:09 -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=B883F5dmVQG/nVCIvlNlD4L/gAxRvgth0kf0bW+7srI=; b=EtvViJLKEsaJc1tUpkX0Rq3AVPZIsvTnuvmrDdheEm3Cuzmo+BdVFP1GP+C72Vhw/n SCeEF4dtSkdT6YmgeP8veplRNpA8xMUnT5Tlqug5UeQRyKREdWG/heVBFAABnvcyR3/x llqh1uRcU4ZMXTp/TU1Hvqd22ggTAs9RFmXSA= 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=B883F5dmVQG/nVCIvlNlD4L/gAxRvgth0kf0bW+7srI=; b=U6YfIMZJD4bCUg4JrixzH3TNTYKXw5JPhaO/vYp8/PSQEuPchAr6CtjlICVAYU9fF/ lbrCuMyLzV1+OEFMg2M/RsH2IssSJlNXYgTS6HzWH/IJUL9kx8s2DHbT5VC9dnk2suOF K2/y4ve5Sg2ZEzlFflL9ENIdjc79YPToD0TG5elOvvsNUfsAshAwApB01Z6rDXiPMaaI AiN2qauPn/ter9k0P72IgPXrHJx1noKn62V1NZ+JACmUTQwyEWGs/tUJg78vhdPR9mfa sPD9uAgWhvVPBYX2GjpfHS5Q4QBHXEBrurYS5rTfn+S9tp3NBLIC1H8hVhNwaK9m/knw 1/Dg== X-Gm-Message-State: APt69E10b8J3uQhfgsIjLv2whomF3xjEgtqJw2jtoA1QWyl7/8sNmFq6 AFnnePeGGAsB+RMhYmXKFqcg1Ctm4zs= X-Received: by 2002:a1c:5a08:: with SMTP id o8-v6mr5247383wmb.61.1530115568787; Wed, 27 Jun 2018 09:06:08 -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.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 09:06:08 -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 1/5] kernel/jump_label: abstract jump_entry member accessors Date: Wed, 27 Jun 2018 18:06:00 +0200 Message-Id: <20180627160604.8154-2-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 In preparation of allowing architectures to use relative references in jump_label entries [which can dramatically reduce the memory footprint], introduce abstractions for references to the 'code' and 'key' members of struct jump_entry. Signed-off-by: Ard Biesheuvel --- include/linux/jump_label.h | 36 ++++++++++++++++++++ kernel/jump_label.c | 36 ++++++++------------ 2 files changed, 50 insertions(+), 22 deletions(-) -- 2.11.0 diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index b46b541c67c4..86ec0652d3b1 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -119,6 +119,42 @@ struct static_key { #ifdef HAVE_JUMP_LABEL #include + +#ifndef __ASSEMBLY__ + +struct jump_entry; /* defined by the architecture */ + +static inline unsigned long jump_entry_code(const struct jump_entry *entry) +{ + return entry->code; +} + +static inline unsigned long jump_entry_target(const struct jump_entry *entry) +{ + return entry->target; +} + +static inline struct static_key *jump_entry_key(const struct jump_entry *entry) +{ + return (struct static_key *)((unsigned long)entry->key & ~1UL); +} + +static inline bool jump_entry_is_branch(const struct jump_entry *entry) +{ + return (unsigned long)entry->key & 1UL; +} + +static inline bool jump_entry_is_module_init(const struct jump_entry *entry) +{ + return entry->code == 0; +} + +static inline void jump_entry_set_module_init(struct jump_entry *entry) +{ + entry->code = 0; +} + +#endif #endif #ifndef __ASSEMBLY__ diff --git a/kernel/jump_label.c b/kernel/jump_label.c index 01ebdf1f9f40..c3524c9b3004 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -38,10 +38,12 @@ static int jump_label_cmp(const void *a, const void *b) const struct jump_entry *jea = a; const struct jump_entry *jeb = b; - if (jea->key < jeb->key) + if ((unsigned long)jump_entry_key(jea) < + (unsigned long)jump_entry_key(jeb)) return -1; - if (jea->key > jeb->key) + if ((unsigned long)jump_entry_key(jea) > + (unsigned long)jump_entry_key(jeb)) return 1; return 0; @@ -261,8 +263,8 @@ EXPORT_SYMBOL_GPL(jump_label_rate_limit); static int addr_conflict(struct jump_entry *entry, void *start, void *end) { - if (entry->code <= (unsigned long)end && - entry->code + JUMP_LABEL_NOP_SIZE > (unsigned long)start) + if (jump_entry_code(entry) <= (unsigned long)end && + jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE > (unsigned long)start) return 1; return 0; @@ -321,16 +323,6 @@ static inline void static_key_set_linked(struct static_key *key) key->type |= JUMP_TYPE_LINKED; } -static inline struct static_key *jump_entry_key(struct jump_entry *entry) -{ - return (struct static_key *)((unsigned long)entry->key & ~1UL); -} - -static bool jump_entry_branch(struct jump_entry *entry) -{ - return (unsigned long)entry->key & 1UL; -} - /*** * A 'struct static_key' uses a union such that it either points directly * to a table of 'struct jump_entry' or to a linked list of modules which in @@ -355,7 +347,7 @@ static enum jump_label_type jump_label_type(struct jump_entry *entry) { struct static_key *key = jump_entry_key(entry); bool enabled = static_key_enabled(key); - bool branch = jump_entry_branch(entry); + bool branch = jump_entry_is_branch(entry); /* See the comment in linux/jump_label.h */ return enabled ^ branch; @@ -370,8 +362,8 @@ static void __jump_label_update(struct static_key *key, * An entry->code of 0 indicates an entry which has been * disabled because it was in an init text area. */ - if (entry->code) { - if (kernel_text_address(entry->code)) + if (!jump_entry_is_module_init(entry)) { + if (kernel_text_address(jump_entry_code(entry))) arch_jump_label_transform(entry, jump_label_type(entry)); else WARN_ONCE(1, "can't patch jump_label at %pS", @@ -441,7 +433,7 @@ static enum jump_label_type jump_label_init_type(struct jump_entry *entry) { struct static_key *key = jump_entry_key(entry); bool type = static_key_type(key); - bool branch = jump_entry_branch(entry); + bool branch = jump_entry_is_branch(entry); /* See the comment in linux/jump_label.h */ return type ^ branch; @@ -565,7 +557,7 @@ static int jump_label_add_module(struct module *mod) continue; key = iterk; - if (within_module(iter->key, mod)) { + if (within_module((unsigned long)key, mod)) { static_key_set_entries(key, iter); continue; } @@ -615,7 +607,7 @@ static void jump_label_del_module(struct module *mod) key = jump_entry_key(iter); - if (within_module(iter->key, mod)) + if (within_module((unsigned long)key, mod)) continue; /* No memory during module load */ @@ -659,8 +651,8 @@ static void jump_label_invalidate_module_init(struct module *mod) struct jump_entry *iter; for (iter = iter_start; iter < iter_stop; iter++) { - if (within_module_init(iter->code, mod)) - iter->code = 0; + if (within_module_init(jump_entry_code(iter), mod)) + jump_entry_set_module_init(iter); } }