From: peterz@infradead.org (Peter Zijlstra)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/5] kernel/jump_label: implement generic support for relative references
Date: Thu, 28 Jun 2018 10:50:03 +0200 [thread overview]
Message-ID: <20180628085003.GA2494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20180627160604.8154-3-ard.biesheuvel@linaro.org>
On Wed, Jun 27, 2018 at 06:06:01PM +0200, Ard Biesheuvel wrote:
> 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 <asm/jump_label.h>
>
> #ifndef __ASSEMBLY__
> +#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE
> +
> +struct jump_entry {
> + int code;
> + int target;
> + int key;
> +};
I much prefer you use 'u32' there.
> +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);
> }
That will result in jump_label_swap being an unused symbol for some
compile options.
Would it not be much nicer to write that like:
static void jump_label_swap(void *a, void *b, int size)
{
struct jump_entry *jea = a, *jeb = b;
#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE
long delta = a - b;
jea->code += delta;
jea->target += delta;
jea->key += delta;
jeb->code -= delta;
jeb->target -= delta;
jeb->key -= delta;
#else
swap(*jea, *jeb);
}
And then unconditionally use jump_label_swap().
next prev parent reply other threads:[~2018-06-28 8:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-27 16:05 [PATCH 0/5] add support for relative references in jump tables Ard Biesheuvel
2018-06-27 16:06 ` [PATCH 1/5] kernel/jump_label: abstract jump_entry member accessors Ard Biesheuvel
2018-06-28 8:40 ` Peter Zijlstra
2018-06-27 16:06 ` [PATCH 2/5] kernel/jump_label: implement generic support for relative references Ard Biesheuvel
2018-06-28 8:50 ` Peter Zijlstra [this message]
2018-06-28 9:02 ` Ard Biesheuvel
2018-06-28 9:04 ` Ard Biesheuvel
2018-06-28 9:25 ` Peter Zijlstra
2018-06-28 9:29 ` Ard Biesheuvel
2018-06-28 9:37 ` Peter Zijlstra
2018-06-27 16:06 ` [PATCH 3/5] arm64/kernel: jump_label: switch to " Ard Biesheuvel
2018-06-28 9:17 ` Will Deacon
2018-06-27 16:06 ` [PATCH 4/5] x86: jump_label: switch to jump_entry accessors Ard Biesheuvel
2018-06-28 9:11 ` Peter Zijlstra
2018-06-28 9:14 ` Ard Biesheuvel
2018-06-27 16:06 ` [PATCH 5/5] x86/kernel: jump_table: use relative references Ard Biesheuvel
2018-06-28 8:31 ` Peter Zijlstra
2018-06-28 8:34 ` Ard Biesheuvel
2018-06-28 9:28 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180628085003.GA2494@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).