* [PATCH] jump label: Add MIPS support.
@ 2010-09-28 18:10 David Daney
2010-10-01 21:49 ` Steven Rostedt
2010-10-03 18:15 ` Rabin Vincent
0 siblings, 2 replies; 7+ messages in thread
From: David Daney @ 2010-09-28 18:10 UTC (permalink / raw)
To: linux-mips, ralf, linux-kernel, rostedt, jbaron; +Cc: David Daney
When in Rome...
In order not to be left behind, we add jump label support for MIPS.
Tested on 64-bit big endian (Octeon), and 32-bit little endian
(malta/qemu).
Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
---
arch/mips/Kconfig | 1 +
arch/mips/include/asm/jump_label.h | 48 ++++++++++++++++++++++++++++
arch/mips/kernel/Makefile | 3 +-
arch/mips/kernel/jump_label.c | 60 ++++++++++++++++++++++++++++++++++++
arch/mips/kernel/module.c | 5 +++
5 files changed, 116 insertions(+), 1 deletions(-)
create mode 100644 arch/mips/include/asm/jump_label.h
create mode 100644 arch/mips/kernel/jump_label.c
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 3ad59dd..6b3bdb5 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -13,6 +13,7 @@ config MIPS
select HAVE_KPROBES
select HAVE_KRETPROBES
select RTC_LIB if !MACH_LOONGSON
+ select HAVE_ARCH_JUMP_LABEL
mainmenu "Linux/MIPS Kernel Configuration"
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
new file mode 100644
index 0000000..7622ccf
--- /dev/null
+++ b/arch/mips/include/asm/jump_label.h
@@ -0,0 +1,48 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (c) 2010 Cavium Networks, Inc.
+ */
+#ifndef _ASM_MIPS_JUMP_LABEL_H
+#define _ASM_MIPS_JUMP_LABEL_H
+
+#include <linux/types.h>
+
+#ifdef __KERNEL__
+
+#define JUMP_LABEL_NOP_SIZE 4
+
+#ifdef CONFIG_64BIT
+#define WORD_INSN ".dword"
+#else
+#define WORD_INSN ".word"
+#endif
+
+#define JUMP_LABEL(key, label) \
+ do { \
+ asm goto("1:\tnop\n\t" \
+ "nop\n\t" \
+ ".pushsection __jump_table, \"a\"\n\t" \
+ WORD_INSN " 1b, %l[" #label "], %0\n\t" \
+ ".popsection\n\t" \
+ : : "i" (key) : : label); \
+ } while (0)
+
+
+#endif /* __KERNEL__ */
+
+#ifdef CONFIG_64BIT
+typedef u64 jump_label_t;
+#else
+typedef u32 jump_label_t;
+#endif
+
+struct jump_entry {
+ jump_label_t code;
+ jump_label_t target;
+ jump_label_t key;
+};
+
+#endif /* _ASM_MIPS_JUMP_LABEL_H */
diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
index 06f8482..db4feb9 100644
--- a/arch/mips/kernel/Makefile
+++ b/arch/mips/kernel/Makefile
@@ -6,7 +6,8 @@ extra-y := head.o init_task.o vmlinux.lds
obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \
ptrace.o reset.o setup.o signal.o syscall.o \
- time.o topology.o traps.o unaligned.o watch.o vdso.o
+ time.o topology.o traps.o unaligned.o watch.o vdso.o \
+ jump_label.o
ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_ftrace.o = -pg
diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
new file mode 100644
index 0000000..3c145a8
--- /dev/null
+++ b/arch/mips/kernel/jump_label.c
@@ -0,0 +1,60 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (c) 2010 Cavium Networks, Inc.
+ */
+
+#include <linux/jump_label.h>
+#include <linux/kernel.h>
+#include <linux/memory.h>
+#include <linux/mutex.h>
+#include <linux/types.h>
+#include <linux/cpu.h>
+
+#include <asm/cacheflush.h>
+#include <asm/inst.h>
+
+#define J_RANGE_MASK ((1ul << 28) - 1)
+
+void arch_jump_label_transform(struct jump_entry *e,
+ enum jump_label_type type)
+{
+ union mips_instruction insn;
+ union mips_instruction *insn_p =
+ (union mips_instruction *)(unsigned long)e->code;
+
+ /* Jump only works within a 256MB aligned region. */
+ BUG_ON((e->target & ~J_RANGE_MASK) != (e->code & ~J_RANGE_MASK));
+
+ /* Target must have 4 byte alignment. */
+ BUG_ON((e->target & 3) != 0);
+
+ if (type == JUMP_LABEL_ENABLE) {
+ insn.j_format.opcode = j_op;
+ insn.j_format.target = (e->target & J_RANGE_MASK) >> 2;
+ } else {
+ insn.word = 0; /* nop */
+ }
+
+ get_online_cpus();
+ mutex_lock(&text_mutex);
+ *insn_p = insn;
+
+ flush_icache_range((unsigned long)insn_p,
+ (unsigned long)insn_p + sizeof(*insn_p));
+
+ mutex_unlock(&text_mutex);
+ put_online_cpus();
+}
+
+void arch_jump_label_text_poke_early(jump_label_t addr)
+{
+ union mips_instruction *insn_p =
+ (union mips_instruction *)(unsigned long)addr;
+
+ insn_p->word = 0; /* nop */
+ flush_icache_range((unsigned long)insn_p,
+ (unsigned long)insn_p + sizeof(*insn_p));
+}
diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
index 6f51dda..bb9cde4 100644
--- a/arch/mips/kernel/module.c
+++ b/arch/mips/kernel/module.c
@@ -30,6 +30,8 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/spinlock.h>
+#include <linux/jump_label.h>
+
#include <asm/pgtable.h> /* MODULE_START */
struct mips_hi16 {
@@ -390,6 +392,9 @@ int module_finalize(const Elf_Ehdr *hdr,
const Elf_Shdr *s;
char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
+ /* Make jump label nops. */
+ jump_label_apply_nops(me);
+
INIT_LIST_HEAD(&me->arch.dbe_list);
for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
if (strcmp("__dbe_table", secstrings + s->sh_name) != 0)
--
1.7.2.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] jump label: Add MIPS support.
2010-09-28 18:10 [PATCH] jump label: Add MIPS support David Daney
@ 2010-10-01 21:49 ` Steven Rostedt
2010-10-02 1:54 ` Ralf Baechle
2010-10-03 18:15 ` Rabin Vincent
1 sibling, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2010-10-01 21:49 UTC (permalink / raw)
To: David Daney; +Cc: linux-mips, ralf, linux-kernel, jbaron
On Tue, 2010-09-28 at 11:10 -0700, David Daney wrote:
> When in Rome...
>
> In order not to be left behind, we add jump label support for MIPS.
>
> Tested on 64-bit big endian (Octeon), and 32-bit little endian
> (malta/qemu).
>
> Signed-off-by: David Daney <ddaney@caviumnetworks.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Jason Baron <jbaron@redhat.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
I can pull this into tip with an Acked-by from Ralf. He was just in
Tokyo with me, and I don't know when he'll be available to do so.
-- Steve
> ---
> arch/mips/Kconfig | 1 +
> arch/mips/include/asm/jump_label.h | 48 ++++++++++++++++++++++++++++
> arch/mips/kernel/Makefile | 3 +-
> arch/mips/kernel/jump_label.c | 60 ++++++++++++++++++++++++++++++++++++
> arch/mips/kernel/module.c | 5 +++
> 5 files changed, 116 insertions(+), 1 deletions(-)
> create mode 100644 arch/mips/include/asm/jump_label.h
> create mode 100644 arch/mips/kernel/jump_label.c
>
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index 3ad59dd..6b3bdb5 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -13,6 +13,7 @@ config MIPS
> select HAVE_KPROBES
> select HAVE_KRETPROBES
> select RTC_LIB if !MACH_LOONGSON
> + select HAVE_ARCH_JUMP_LABEL
>
> mainmenu "Linux/MIPS Kernel Configuration"
>
> diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
> new file mode 100644
> index 0000000..7622ccf
> --- /dev/null
> +++ b/arch/mips/include/asm/jump_label.h
> @@ -0,0 +1,48 @@
> +/*
> + * This file is subject to the terms and conditions of the GNU General Public
> + * License. See the file "COPYING" in the main directory of this archive
> + * for more details.
> + *
> + * Copyright (c) 2010 Cavium Networks, Inc.
> + */
> +#ifndef _ASM_MIPS_JUMP_LABEL_H
> +#define _ASM_MIPS_JUMP_LABEL_H
> +
> +#include <linux/types.h>
> +
> +#ifdef __KERNEL__
> +
> +#define JUMP_LABEL_NOP_SIZE 4
> +
> +#ifdef CONFIG_64BIT
> +#define WORD_INSN ".dword"
> +#else
> +#define WORD_INSN ".word"
> +#endif
> +
> +#define JUMP_LABEL(key, label) \
> + do { \
> + asm goto("1:\tnop\n\t" \
> + "nop\n\t" \
> + ".pushsection __jump_table, \"a\"\n\t" \
> + WORD_INSN " 1b, %l[" #label "], %0\n\t" \
> + ".popsection\n\t" \
> + : : "i" (key) : : label); \
> + } while (0)
> +
> +
> +#endif /* __KERNEL__ */
> +
> +#ifdef CONFIG_64BIT
> +typedef u64 jump_label_t;
> +#else
> +typedef u32 jump_label_t;
> +#endif
> +
> +struct jump_entry {
> + jump_label_t code;
> + jump_label_t target;
> + jump_label_t key;
> +};
> +
> +#endif /* _ASM_MIPS_JUMP_LABEL_H */
> diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile
> index 06f8482..db4feb9 100644
> --- a/arch/mips/kernel/Makefile
> +++ b/arch/mips/kernel/Makefile
> @@ -6,7 +6,8 @@ extra-y := head.o init_task.o vmlinux.lds
>
> obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \
> ptrace.o reset.o setup.o signal.o syscall.o \
> - time.o topology.o traps.o unaligned.o watch.o vdso.o
> + time.o topology.o traps.o unaligned.o watch.o vdso.o \
> + jump_label.o
>
> ifdef CONFIG_FUNCTION_TRACER
> CFLAGS_REMOVE_ftrace.o = -pg
> diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
> new file mode 100644
> index 0000000..3c145a8
> --- /dev/null
> +++ b/arch/mips/kernel/jump_label.c
> @@ -0,0 +1,60 @@
> +/*
> + * This file is subject to the terms and conditions of the GNU General Public
> + * License. See the file "COPYING" in the main directory of this archive
> + * for more details.
> + *
> + * Copyright (c) 2010 Cavium Networks, Inc.
> + */
> +
> +#include <linux/jump_label.h>
> +#include <linux/kernel.h>
> +#include <linux/memory.h>
> +#include <linux/mutex.h>
> +#include <linux/types.h>
> +#include <linux/cpu.h>
> +
> +#include <asm/cacheflush.h>
> +#include <asm/inst.h>
> +
> +#define J_RANGE_MASK ((1ul << 28) - 1)
> +
> +void arch_jump_label_transform(struct jump_entry *e,
> + enum jump_label_type type)
> +{
> + union mips_instruction insn;
> + union mips_instruction *insn_p =
> + (union mips_instruction *)(unsigned long)e->code;
> +
> + /* Jump only works within a 256MB aligned region. */
> + BUG_ON((e->target & ~J_RANGE_MASK) != (e->code & ~J_RANGE_MASK));
> +
> + /* Target must have 4 byte alignment. */
> + BUG_ON((e->target & 3) != 0);
> +
> + if (type == JUMP_LABEL_ENABLE) {
> + insn.j_format.opcode = j_op;
> + insn.j_format.target = (e->target & J_RANGE_MASK) >> 2;
> + } else {
> + insn.word = 0; /* nop */
> + }
> +
> + get_online_cpus();
> + mutex_lock(&text_mutex);
> + *insn_p = insn;
> +
> + flush_icache_range((unsigned long)insn_p,
> + (unsigned long)insn_p + sizeof(*insn_p));
> +
> + mutex_unlock(&text_mutex);
> + put_online_cpus();
> +}
> +
> +void arch_jump_label_text_poke_early(jump_label_t addr)
> +{
> + union mips_instruction *insn_p =
> + (union mips_instruction *)(unsigned long)addr;
> +
> + insn_p->word = 0; /* nop */
> + flush_icache_range((unsigned long)insn_p,
> + (unsigned long)insn_p + sizeof(*insn_p));
> +}
> diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
> index 6f51dda..bb9cde4 100644
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -30,6 +30,8 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/spinlock.h>
> +#include <linux/jump_label.h>
> +
> #include <asm/pgtable.h> /* MODULE_START */
>
> struct mips_hi16 {
> @@ -390,6 +392,9 @@ int module_finalize(const Elf_Ehdr *hdr,
> const Elf_Shdr *s;
> char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
>
> + /* Make jump label nops. */
> + jump_label_apply_nops(me);
> +
> INIT_LIST_HEAD(&me->arch.dbe_list);
> for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
> if (strcmp("__dbe_table", secstrings + s->sh_name) != 0)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] jump label: Add MIPS support.
2010-10-01 21:49 ` Steven Rostedt
@ 2010-10-02 1:54 ` Ralf Baechle
0 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2010-10-02 1:54 UTC (permalink / raw)
To: Steven Rostedt; +Cc: David Daney, linux-mips, linux-kernel, jbaron
On Fri, Oct 01, 2010 at 05:49:46PM -0400, Steven Rostedt wrote:
> On Tue, 2010-09-28 at 11:10 -0700, David Daney wrote:
> > When in Rome...
> >
> > In order not to be left behind, we add jump label support for MIPS.
> >
> > Tested on 64-bit big endian (Octeon), and 32-bit little endian
> > (malta/qemu).
> >
> > Signed-off-by: David Daney <ddaney@caviumnetworks.com>
> > Cc: Steven Rostedt <rostedt@goodmis.org>
> > Cc: Jason Baron <jbaron@redhat.com>
> > Cc: Ralf Baechle <ralf@linux-mips.org>
>
> I can pull this into tip with an Acked-by from Ralf. He was just in
> Tokyo with me, and I don't know when he'll be available to do so.
Monday probably. Just packing up for the airport.
Ralf
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] jump label: Add MIPS support.
2010-09-28 18:10 [PATCH] jump label: Add MIPS support David Daney
2010-10-01 21:49 ` Steven Rostedt
@ 2010-10-03 18:15 ` Rabin Vincent
2010-10-04 17:43 ` David Daney
1 sibling, 1 reply; 7+ messages in thread
From: Rabin Vincent @ 2010-10-03 18:15 UTC (permalink / raw)
To: David Daney; +Cc: linux-mips, ralf, linux-kernel, rostedt, jbaron
On Tue, Sep 28, 2010 at 11:40 PM, David Daney <ddaney@caviumnetworks.com> wrote:
> +void arch_jump_label_text_poke_early(jump_label_t addr)
> +{
> + union mips_instruction *insn_p =
> + (union mips_instruction *)(unsigned long)addr;
> +
> + insn_p->word = 0; /* nop */
> + flush_icache_range((unsigned long)insn_p,
> + (unsigned long)insn_p + sizeof(*insn_p));
> +}
Can't this function be a no-op on MIPS? This seems to be
used on x86 to patch in the optimal nop instruction, but
on MIPS the optimal/only nop instruction should already
be in place at build time. Same thing for the SPARC
implementation.
Rabin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] jump label: Add MIPS support.
2010-10-03 18:15 ` Rabin Vincent
@ 2010-10-04 17:43 ` David Daney
2010-10-04 17:50 ` Jason Baron
0 siblings, 1 reply; 7+ messages in thread
From: David Daney @ 2010-10-04 17:43 UTC (permalink / raw)
To: Rabin Vincent
Cc: linux-mips, ralf, linux-kernel, rostedt, jbaron, David Miller
On 10/03/2010 11:15 AM, Rabin Vincent wrote:
> On Tue, Sep 28, 2010 at 11:40 PM, David Daney<ddaney@caviumnetworks.com> wrote:
>> +void arch_jump_label_text_poke_early(jump_label_t addr)
>> +{
>> + union mips_instruction *insn_p =
>> + (union mips_instruction *)(unsigned long)addr;
>> +
>> + insn_p->word = 0; /* nop */
>> + flush_icache_range((unsigned long)insn_p,
>> + (unsigned long)insn_p + sizeof(*insn_p));
>> +}
>
> Can't this function be a no-op on MIPS? This seems to be
> used on x86 to patch in the optimal nop instruction, but
> on MIPS the optimal/only nop instruction should already
> be in place at build time. Same thing for the SPARC
> implementation.
>
Yes, I think you are correct.
On MIPS the NOP is already optimal. I will respin the MIPS patch to
make arch_jump_label_text_poke_early() be empty.
davem wasn't CCed on the original message, so I added him. I would
defer to him on the SPARC version.
Thanks,
David Daney
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] jump label: Add MIPS support.
2010-10-04 17:43 ` David Daney
@ 2010-10-04 17:50 ` Jason Baron
2010-10-04 19:06 ` David Daney
0 siblings, 1 reply; 7+ messages in thread
From: Jason Baron @ 2010-10-04 17:50 UTC (permalink / raw)
To: David Daney
Cc: Rabin Vincent, linux-mips, ralf, linux-kernel, rostedt,
David Miller
On Mon, Oct 04, 2010 at 10:43:07AM -0700, David Daney wrote:
> On 10/03/2010 11:15 AM, Rabin Vincent wrote:
>> On Tue, Sep 28, 2010 at 11:40 PM, David Daney<ddaney@caviumnetworks.com> wrote:
>>> +void arch_jump_label_text_poke_early(jump_label_t addr)
>>> +{
>>> + union mips_instruction *insn_p =
>>> + (union mips_instruction *)(unsigned long)addr;
>>> +
>>> + insn_p->word = 0; /* nop */
>>> + flush_icache_range((unsigned long)insn_p,
>>> + (unsigned long)insn_p + sizeof(*insn_p));
>>> +}
>>
>> Can't this function be a no-op on MIPS? This seems to be
>> used on x86 to patch in the optimal nop instruction, but
>> on MIPS the optimal/only nop instruction should already
>> be in place at build time. Same thing for the SPARC
>> implementation.
>>
>
> Yes, I think you are correct.
>
> On MIPS the NOP is already optimal. I will respin the MIPS patch to
> make arch_jump_label_text_poke_early() be empty.
>
> davem wasn't CCed on the original message, so I added him. I would
> defer to him on the SPARC version.
>
>
that's right, arch_jump_label_text_poke_early() can probably be a no-op
for most arches.
We can also look at adding an empty definition into the generic
header. So that arches don't have to provide an empty definition.
thanks,
-Jason
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] jump label: Add MIPS support.
2010-10-04 17:50 ` Jason Baron
@ 2010-10-04 19:06 ` David Daney
0 siblings, 0 replies; 7+ messages in thread
From: David Daney @ 2010-10-04 19:06 UTC (permalink / raw)
To: Jason Baron
Cc: Rabin Vincent, linux-mips, ralf, linux-kernel, rostedt,
David Miller
On 10/04/2010 10:50 AM, Jason Baron wrote:
> On Mon, Oct 04, 2010 at 10:43:07AM -0700, David Daney wrote:
>> On 10/03/2010 11:15 AM, Rabin Vincent wrote:
>>> On Tue, Sep 28, 2010 at 11:40 PM, David Daney<ddaney@caviumnetworks.com> wrote:
>>>> +void arch_jump_label_text_poke_early(jump_label_t addr)
>>>> +{
>>>> + union mips_instruction *insn_p =
>>>> + (union mips_instruction *)(unsigned long)addr;
>>>> +
>>>> + insn_p->word = 0; /* nop */
>>>> + flush_icache_range((unsigned long)insn_p,
>>>> + (unsigned long)insn_p + sizeof(*insn_p));
>>>> +}
>>>
>>> Can't this function be a no-op on MIPS? This seems to be
>>> used on x86 to patch in the optimal nop instruction, but
>>> on MIPS the optimal/only nop instruction should already
>>> be in place at build time. Same thing for the SPARC
>>> implementation.
>>>
>>
>> Yes, I think you are correct.
>>
>> On MIPS the NOP is already optimal. I will respin the MIPS patch to
>> make arch_jump_label_text_poke_early() be empty.
>>
>> davem wasn't CCed on the original message, so I added him. I would
>> defer to him on the SPARC version.
>>
>>
>
> that's right, arch_jump_label_text_poke_early() can probably be a no-op
> for most arches.
>
> We can also look at adding an empty definition into the generic
> header. So that arches don't have to provide an empty definition.
>
I just sent the patch that does that. It should be showing up in an
In-Box near you soon.
David Daney
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-10-04 19:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-28 18:10 [PATCH] jump label: Add MIPS support David Daney
2010-10-01 21:49 ` Steven Rostedt
2010-10-02 1:54 ` Ralf Baechle
2010-10-03 18:15 ` Rabin Vincent
2010-10-04 17:43 ` David Daney
2010-10-04 17:50 ` Jason Baron
2010-10-04 19:06 ` David Daney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox