public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] add jump label support for TILE-Gx
@ 2015-09-30  1:53 Zhigang Lu
  2015-09-30  1:53 ` [PATCH 1/2] tile: define a macro ktext_writable_addr to get writable kernel text address Zhigang Lu
  2015-09-30 13:20 ` [PATCH 0/2] add jump label support for TILE-Gx Chris Metcalf
  0 siblings, 2 replies; 3+ messages in thread
From: Zhigang Lu @ 2015-09-30  1:53 UTC (permalink / raw)
  To: linux-kernel, cmetcalf; +Cc: Zhigang Lu

This patch set adds jump_label support for TILE-Gx architecture. As
jump_label shares some code with ftrace, kgdb and kprobes, we factor
this out into a helper routine as a prequel patch.

Zhigang Lu (2):
  tile: define a macro ktext_writable_addr to get writable kernel text
    address
  tile/jump_label: add jump label support for TILE-Gx

 arch/tile/Kconfig                  |  1 +
 arch/tile/include/asm/insn.h       | 59 +++++++++++++++++++++++++++++++++++
 arch/tile/include/asm/jump_label.h | 58 +++++++++++++++++++++++++++++++++++
 arch/tile/include/asm/page.h       | 10 ++++++
 arch/tile/kernel/Makefile          |  1 +
 arch/tile/kernel/ftrace.c          | 13 ++------
 arch/tile/kernel/jump_label.c      | 63 ++++++++++++++++++++++++++++++++++++++
 arch/tile/kernel/kgdb.c            |  2 +-
 arch/tile/kernel/kprobes.c         |  4 +--
 9 files changed, 197 insertions(+), 14 deletions(-)
 create mode 100644 arch/tile/include/asm/insn.h
 create mode 100644 arch/tile/include/asm/jump_label.h
 create mode 100644 arch/tile/kernel/jump_label.c

-- 
2.1.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] tile: define a macro ktext_writable_addr to get writable kernel text address
  2015-09-30  1:53 [PATCH 0/2] add jump label support for TILE-Gx Zhigang Lu
@ 2015-09-30  1:53 ` Zhigang Lu
  2015-09-30 13:20 ` [PATCH 0/2] add jump label support for TILE-Gx Chris Metcalf
  1 sibling, 0 replies; 3+ messages in thread
From: Zhigang Lu @ 2015-09-30  1:53 UTC (permalink / raw)
  To: linux-kernel, cmetcalf; +Cc: Zhigang Lu

It is used by kgdb, ftrace, kprobe and jump label, so we factor
this out into a helper routine.

Reviewed-by: Chris Metcalf <cmetcalf@ezchip.com>
Signed-off-by: Zhigang Lu <zlu@ezchip.com>
---
 arch/tile/include/asm/page.h | 10 ++++++++++
 arch/tile/kernel/ftrace.c    |  2 +-
 arch/tile/kernel/kgdb.c      |  2 +-
 arch/tile/kernel/kprobes.c   |  4 ++--
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/tile/include/asm/page.h b/arch/tile/include/asm/page.h
index a213a8d..5cee2cb 100644
--- a/arch/tile/include/asm/page.h
+++ b/arch/tile/include/asm/page.h
@@ -319,6 +319,16 @@ static inline int pfn_valid(unsigned long pfn)
 #define virt_to_page(kaddr) pfn_to_page(kaddr_to_pfn((void *)(kaddr)))
 #define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page))
 
+/*
+ * The kernel text is mapped at MEM_SV_START as read-only.  To allow
+ * modifying kernel text, it is also mapped at PAGE_OFFSET as read-write.
+ * This macro converts a kernel address to its writable kernel text mapping,
+ * which is used to modify the text code on a running kernel by kgdb,
+ * ftrace, kprobe, jump label, etc.
+ */
+#define ktext_writable_addr(kaddr) \
+	((unsigned long)(kaddr) - MEM_SV_START + PAGE_OFFSET)
+
 struct mm_struct;
 extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr);
 extern pte_t *virt_to_kpte(unsigned long kaddr);
diff --git a/arch/tile/kernel/ftrace.c b/arch/tile/kernel/ftrace.c
index 0c09961..4180ccdf 100644
--- a/arch/tile/kernel/ftrace.c
+++ b/arch/tile/kernel/ftrace.c
@@ -117,7 +117,7 @@ static int ftrace_modify_code(unsigned long pc, unsigned long old,
 		return -EINVAL;
 
 	/* Operate on writable kernel text mapping. */
-	pc_wr = pc - MEM_SV_START + PAGE_OFFSET;
+	pc_wr = ktext_writable_addr(pc);
 
 	if (probe_kernel_write((void *)pc_wr, &new, MCOUNT_INSN_SIZE))
 		return -EPERM;
diff --git a/arch/tile/kernel/kgdb.c b/arch/tile/kernel/kgdb.c
index ff5335a..a506c2c 100644
--- a/arch/tile/kernel/kgdb.c
+++ b/arch/tile/kernel/kgdb.c
@@ -164,7 +164,7 @@ static unsigned long writable_address(unsigned long addr)
 	unsigned long ret = 0;
 
 	if (core_kernel_text(addr))
-		ret = addr - MEM_SV_START + PAGE_OFFSET;
+		ret = ktext_writable_addr(addr);
 	else if (is_module_text_address(addr))
 		ret = addr;
 	else
diff --git a/arch/tile/kernel/kprobes.c b/arch/tile/kernel/kprobes.c
index f8a45c5..c68694b 100644
--- a/arch/tile/kernel/kprobes.c
+++ b/arch/tile/kernel/kprobes.c
@@ -116,7 +116,7 @@ void __kprobes arch_arm_kprobe(struct kprobe *p)
 	unsigned long addr_wr;
 
 	/* Operate on writable kernel text mapping. */
-	addr_wr = (unsigned long)p->addr - MEM_SV_START + PAGE_OFFSET;
+	addr_wr = ktext_writable_addr(p->addr);
 
 	if (probe_kernel_write((void *)addr_wr, &breakpoint_insn,
 		sizeof(breakpoint_insn)))
@@ -131,7 +131,7 @@ void __kprobes arch_disarm_kprobe(struct kprobe *kp)
 	unsigned long addr_wr;
 
 	/* Operate on writable kernel text mapping. */
-	addr_wr = (unsigned long)kp->addr - MEM_SV_START + PAGE_OFFSET;
+	addr_wr = ktext_writable_addr(kp->addr);
 
 	if (probe_kernel_write((void *)addr_wr, &kp->opcode,
 		sizeof(kp->opcode)))
-- 
2.1.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 0/2] add jump label support for TILE-Gx
  2015-09-30  1:53 [PATCH 0/2] add jump label support for TILE-Gx Zhigang Lu
  2015-09-30  1:53 ` [PATCH 1/2] tile: define a macro ktext_writable_addr to get writable kernel text address Zhigang Lu
@ 2015-09-30 13:20 ` Chris Metcalf
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Metcalf @ 2015-09-30 13:20 UTC (permalink / raw)
  To: Zhigang Lu, linux-kernel

On 9/29/2015 9:53 PM, Zhigang Lu wrote:
> This patch set adds jump_label support for TILE-Gx architecture. As
> jump_label shares some code with ftrace, kgdb and kprobes, we factor
> this out into a helper routine as a prequel patch.
>
> Zhigang Lu (2):
>    tile: define a macro ktext_writable_addr to get writable kernel text
>      address
>    tile/jump_label: add jump label support for TILE-Gx

Thanks, taken into the tile tree.

-- 
Chris Metcalf, EZChip Semiconductor
http://www.ezchip.com


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-30 13:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-30  1:53 [PATCH 0/2] add jump label support for TILE-Gx Zhigang Lu
2015-09-30  1:53 ` [PATCH 1/2] tile: define a macro ktext_writable_addr to get writable kernel text address Zhigang Lu
2015-09-30 13:20 ` [PATCH 0/2] add jump label support for TILE-Gx Chris Metcalf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox