All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney@caviumnetworks.com>
To: linux-mips@linux-mips.org, ralf@linux-mips.org,
	linux-kernel@vger.kernel.org, rostedt@goodmis.org,
	jbaron@redhat.com
Cc: David Daney <ddaney@caviumnetworks.com>
Subject: [PATCH v2 2/2] jump label: Add MIPS support.
Date: Mon,  4 Oct 2010 11:56:55 -0700	[thread overview]
Message-ID: <1286218615-24011-3-git-send-email-ddaney@caviumnetworks.com> (raw)
In-Reply-To: <1286218615-24011-1-git-send-email-ddaney@caviumnetworks.com>

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      |   50 ++++++++++++++++++++++++++++++++++++
 arch/mips/kernel/module.c          |    5 +++
 5 files changed, 106 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..52d3c70
--- /dev/null
+++ b/arch/mips/kernel/jump_label.c
@@ -0,0 +1,50 @@
+/*
+ * 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();
+}
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


  parent reply	other threads:[~2010-10-04 18:57 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-04 18:56 [PATCH v2 0/2] jump label: Add MIPS architecture support David Daney
2010-10-04 18:56 ` [PATCH v2 1/2] jump label: Make arch_jump_label_text_poke_early() optional David Daney
2010-10-04 18:56 ` David Daney [this message]
2010-10-06 23:00   ` [PATCH v2 2/2] jump label: Add MIPS support Ralf Baechle
2010-10-07  1:26     ` David Daney
2010-10-15 20:09 [PATCH 0/9] [GIT PULL] jump label: various updates Steven Rostedt
2010-10-15 20:09 ` [PATCH 1/9] jump label/x86: Move arch_init_ideal_nop5 later Steven Rostedt
2010-10-15 20:09 ` [PATCH 2/9] tracing/x86: No need to disable interrupts when calling arch_init_ideal_nop5 Steven Rostedt
2010-10-15 20:09 ` [PATCH 3/9] jump label: Fix module __init section race Steven Rostedt
2010-10-16  2:09   ` Steven Rostedt
2010-10-16  6:23     ` Ingo Molnar
2010-10-16 16:23       ` Steven Rostedt
2010-10-18 14:14         ` Jason Baron
2010-10-15 20:09 ` [PATCH 4/9] jump label: Fix deadlock b/w jump_label_mutex vs. text_mutex Steven Rostedt
2010-10-15 20:55   ` Peter Zijlstra
2010-10-16  2:16     ` Steven Rostedt
2010-10-16  2:25     ` Steven Rostedt
2010-10-16  4:21       ` Steven Rostedt
2010-10-15 20:09 ` [PATCH 5/9] jump label: Add register_jump_label_key/unregister_jump_label_key Steven Rostedt
2010-10-15 20:58   ` Peter Zijlstra
2010-10-16  2:11     ` Steven Rostedt
2010-10-15 21:03   ` Peter Zijlstra
2010-10-15 21:09     ` Steven Rostedt
2010-10-15 21:13       ` Peter Zijlstra
2010-10-18 12:05         ` Peter Zijlstra
2010-10-18 14:03           ` Jason Baron
2010-10-18 14:07             ` Peter Zijlstra
2010-10-15 20:09 ` [PATCH 6/9] jump label: Move jump table to r/w section Steven Rostedt
2010-10-15 20:09 ` [PATCH 7/9] jump label: Add docs Steven Rostedt
2010-10-15 20:09 ` [PATCH 8/9] jump label: Make arch_jump_label_text_poke_early() optional Steven Rostedt
2010-10-15 21:06   ` Peter Zijlstra
2010-10-15 21:08     ` Steven Rostedt
2010-10-15 21:22       ` David Daney
2010-10-15 21:35         ` Steven Rostedt
2010-10-15 21:38           ` David Daney
2010-10-16  1:08             ` Steven Rostedt
2010-10-30 10:40   ` [tip:perf/urgent] " tip-bot for Steven Rostedt
2010-10-15 20:09 ` [PATCH 9/9] jump label: Add MIPS support Steven Rostedt
2010-10-15 20:17 ` [PATCH 0/9] [GIT PULL] jump label: various updates Steven Rostedt
2010-10-16  1:10 ` Steven Rostedt

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=1286218615-24011-3-git-send-email-ddaney@caviumnetworks.com \
    --to=ddaney@caviumnetworks.com \
    --cc=jbaron@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.org \
    --cc=rostedt@goodmis.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.