Re: [PATCH 1/1] x86: fix text_poke

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Linus Torvalds <torvalds@...>
Cc: Andi Kleen <andi@...>, Jiri Slaby <jirislaby@...>, David Miller <davem@...>, <zdenek.kabelac@...>, <rjw@...>, <paulmck@...>, <akpm@...>, <linux-ext4@...>, <herbert@...>, <penberg@...>, <clameter@...>, <linux-kernel@...>, Mathieu Desnoyers <mathieu.desnoyers@...>, <pageexec@...>, H. Peter Anvin <hpa@...>, Jeremy Fitzhardinge <jeremy@...>
Date: Friday, April 25, 2008 - 12:52 pm

* Linus Torvalds <torvalds@linux-foundation.org> wrote:


clear_fixmap() is OK. I've made a tree with all these fixlets, in the 
proper order and with the commit logs tidied up:

  git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-x86-fixes3.git for-linus

[ i integrated Jiri's commit to before your fix because he really 
  deserves that commit (and more) for his relentless debugging effort. ]

below is the full shortlog and diff. Minimally tested on 64-bit so far.

	Ingo

------------------>

Ingo Molnar (3):
      x86: make clear_fixmap() available on 64-bit as well
      x86: make __set_fixmap() non-init
      x86: harden kernel code patching

Jiri Slaby (1):
      x86: fix text_poke()

Linus Torvalds (1):
      x86: clean up text_poke()

 arch/x86/kernel/alternative.c |   35 +++++++++++++++++++----------------
 arch/x86/mm/init_64.c         |    5 ++---
 include/asm-x86/fixmap.h      |    8 ++++++++
 include/asm-x86/fixmap_32.h   |    8 +++-----
 include/asm-x86/fixmap_64.h   |    5 +++--
 5 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index df4099d..2e39830 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -508,24 +508,27 @@ void *text_poke_early(void *addr, const void *opcode, size_t len)
  */
 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
 {
-	unsigned long flags;
-	char *vaddr;
-	int nr_pages = 2;
+	static DEFINE_SPINLOCK(poke_lock);
+	unsigned long flags, bits;
 
+	bits = (unsigned long) addr;
 	BUG_ON(len > sizeof(long));
-	BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1))
-		- ((long)addr & ~(sizeof(long) - 1)));
-	if (kernel_text_address((unsigned long)addr)) {
-		struct page *pages[2] = { virt_to_page(addr),
-			virt_to_page(addr + PAGE_SIZE) };
-		if (!pages[1])
-			nr_pages = 1;
-		vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
-		BUG_ON(!vaddr);
-		local_irq_save(flags);
-		memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
-		local_irq_restore(flags);
-		vunmap(vaddr);
+	BUG_ON(len & (len-1));
+	BUG_ON(bits & (len-1));
+
+	if (core_kernel_text(bits)) {
+		unsigned long phys = __pa(addr);
+		unsigned long offset = phys & ~PAGE_MASK;
+		unsigned long virt = fix_to_virt(FIX_POKE);
+		phys &= PAGE_MASK;
+
+		WARN_ON(!PageReserved(virt_to_page(addr)));
+
+		spin_lock_irqsave(&poke_lock, flags);
+		set_fixmap(FIX_POKE, phys);
+		memcpy((void *)(virt + offset), opcode, len);
+		clear_fixmap(FIX_POKE);
+		spin_unlock_irqrestore(&poke_lock, flags);
 	} else {
 		/*
 		 * modules are in vmalloc'ed memory, always writable.
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 1ff7906..7a81dd0 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -135,7 +135,7 @@ static __init void *spp_getpage(void)
 	return ptr;
 }
 
-static __init void
+static void
 set_pte_phys(unsigned long vaddr, unsigned long phys, pgprot_t prot)
 {
 	pgd_t *pgd;
@@ -214,8 +214,7 @@ void __init cleanup_highmap(void)
 }
 
 /* NOTE: this is meant to be run only at boot */
-void __init
-__set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
+void __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
 {
 	unsigned long address = __fix_to_virt(idx);
 
diff --git a/include/asm-x86/fixmap.h b/include/asm-x86/fixmap.h
index 382eb27..5bd2069 100644
--- a/include/asm-x86/fixmap.h
+++ b/include/asm-x86/fixmap.h
@@ -1,5 +1,13 @@
+#ifndef _ASM_FIXMAP_H
+#define _ASM_FIXMAP_H
+
 #ifdef CONFIG_X86_32
 # include "fixmap_32.h"
 #else
 # include "fixmap_64.h"
 #endif
+
+#define clear_fixmap(idx)			\
+	__set_fixmap(idx, 0, __pgprot(0))
+
+#endif
diff --git a/include/asm-x86/fixmap_32.h b/include/asm-x86/fixmap_32.h
index eb16651..e5db7d5 100644
--- a/include/asm-x86/fixmap_32.h
+++ b/include/asm-x86/fixmap_32.h
@@ -10,8 +10,8 @@
  * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  */
 
-#ifndef _ASM_FIXMAP_H
-#define _ASM_FIXMAP_H
+#ifndef _ASM_FIXMAP_32_H
+#define _ASM_FIXMAP_32_H
 
 
 /* used by vmalloc.c, vsyscall.lds.S.
@@ -55,6 +55,7 @@ enum fixed_addresses {
 	FIX_HOLE,
 	FIX_VDSO,
 	FIX_DBGP_BASE,
+	FIX_POKE,
 	FIX_EARLYCON_MEM_BASE,
 #ifdef CONFIG_X86_LOCAL_APIC
 	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
@@ -121,9 +122,6 @@ extern void reserve_top_address(unsigned long reserve);
 #define set_fixmap_nocache(idx, phys)			\
 	__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
 
-#define clear_fixmap(idx)			\
-	__set_fixmap(idx, 0, __pgprot(0))
-
 #define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
 
 #define __FIXADDR_SIZE	(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
diff --git a/include/asm-x86/fixmap_64.h b/include/asm-x86/fixmap_64.h
index f3d7685..ba80e6b 100644
--- a/include/asm-x86/fixmap_64.h
+++ b/include/asm-x86/fixmap_64.h
@@ -8,8 +8,8 @@
  * Copyright (C) 1998 Ingo Molnar
  */
 
-#ifndef _ASM_FIXMAP_H
-#define _ASM_FIXMAP_H
+#ifndef _ASM_FIXMAP_64_H
+#define _ASM_FIXMAP_64_H
 
 #include <linux/kernel.h>
 #include <asm/apicdef.h>
@@ -37,6 +37,7 @@ enum fixed_addresses {
 	VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE
 			    + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1,
 	VSYSCALL_HPET,
+	FIX_POKE,
 	FIX_DBGP_BASE,
 	FIX_EARLYCON_MEM_BASE,
 	FIX_HPET_BASE,
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.25-git1: Solid hang on HP nx6325 (64-bit), Rafael J. Wysocki, (Sat Apr 19, 9:22 am)
2.6.25-git2: BUG: unable to handle kernel paging request at ..., Rafael J. Wysocki, (Sun Apr 20, 3:04 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 12:12 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 2:22 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 1:19 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 8:54 pm)
[PATCH 1/1] x86: fix text_poke, Jiri Slaby, (Sun Apr 27, 8:51 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 11:03 am)
Re: [PATCH 1/1] x86: fix text_poke, David Miller, (Fri Apr 25, 4:18 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 11:19 am)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Fri Apr 25, 11:27 am)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 11:26 am)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 11:33 am)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 11:54 am)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 11:59 am)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 12:11 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 11:50 am)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 12:11 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 11:57 am)
Re: [PATCH 1/1] x86: fix text_poke, Pavel Machek, (Fri Apr 25, 2:53 pm)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Fri Apr 25, 11:48 am)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 12:06 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 12:22 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 12:37 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 12:52 pm)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Fri Apr 25, 12:56 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 12:45 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 12:51 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 1:02 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 1:13 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 1:53 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 2:13 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 2:09 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 2:19 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 2:56 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 2:04 pm)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Fri Apr 25, 1:26 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 1:29 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 12:43 pm)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Fri Apr 25, 12:19 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 12:24 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Fri Apr 25, 2:13 pm)
Re: [PATCH 1/1] x86: fix text_poke, Nick Piggin, (Sun May 4, 10:36 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 12:33 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 12:30 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 12:42 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 1:09 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 2:37 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 4:18 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 4:37 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 4:41 pm)
Re: [PATCH 1/1] x86: fix text_poke, David Miller, (Fri Apr 25, 5:02 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 5:11 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 4:51 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 5:12 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Sat Apr 26, 2:50 am)
Re: [PATCH 1/1] x86: fix text_poke, Masami Hiramatsu, (Sun Apr 27, 8:49 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 6:04 pm)
Re: [PATCH 1/1] x86: fix text_poke, Frank Ch. Eigler, (Thu Jun 5, 1:44 pm)
Re: [PATCH 1/1] x86: fix text_poke, Frank Ch. Eigler, (Fri Apr 25, 10:12 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 7:00 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Fri Apr 25, 7:13 pm)
Re: [PATCH 1/1] x86: fix text_poke, Masami Hiramatsu, (Fri Apr 25, 7:34 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Sat Apr 26, 2:21 am)
Re: [PATCH 1/1] x86: fix text_poke, Arnaldo Carvalho de Melo, (Sat Apr 26, 7:56 am)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Sat Apr 26, 7:38 pm)
Re: [PATCH 1/1] x86: fix text_poke, Arnaldo Carvalho de Melo, (Sat Apr 26, 9:00 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 5:15 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 5:47 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 6:07 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 6:30 pm)
Re: [PATCH 1/1] x86: fix text_poke, Linus Torvalds, (Fri Apr 25, 6:36 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Mon Apr 28, 4:43 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Mon Apr 28, 5:02 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Sun May 4, 11:03 am)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Sun May 4, 12:18 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Mon Apr 28, 4:21 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jeremy Fitzhardinge, (Mon Apr 28, 4:55 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Mon Apr 28, 5:01 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Mon Apr 28, 6:42 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 6:38 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 3:19 pm)
Re: [PATCH 1/1] x86: fix text_poke, Mathieu Desnoyers, (Fri Apr 25, 4:04 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 4:09 pm)
Re: [PATCH 1/1] x86: fix text_poke, H. Peter Anvin, (Fri Apr 25, 2:47 pm)
Re: [PATCH 1/1] x86: fix text_poke, Ingo Molnar, (Fri Apr 25, 11:32 am)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Fri Apr 25, 11:17 am)
Re: [PATCH 1/1] x86: fix text_poke, Christoph Lameter, (Fri Apr 25, 3:36 pm)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Sat Apr 26, 5:59 am)
VIRTUAL_BUG_ON(), Christoph Lameter, (Mon Apr 28, 4:24 pm)
[RFC 1/1] mm: add virt to phys debug, Jiri Slaby, (Thu May 1, 3:22 pm)
Re: [RFC 1/1] mm: add virt to phys debug, Christoph Lameter, (Thu May 1, 4:18 pm)
Re: [RFC 1/1] mm: add virt to phys debug, Jiri Slaby, (Tue May 13, 10:38 am)
Re: [RFC 1/1] mm: add virt to phys debug, Jiri Slaby, (Tue May 6, 5:54 pm)
Re: [RFC 1/1] mm: add virt to phys debug, Christoph Lameter, (Wed May 7, 1:30 pm)
Re: [PATCH 1/1] x86: fix text_poke, Jiri Slaby, (Sat Apr 26, 7:16 am)
Re: [PATCH 1/1] x86: fix text_poke, Andi Kleen, (Sat Apr 26, 7:34 am)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Fri Apr 25, 11:30 am)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Christoph Lameter, (Wed Apr 23, 3:05 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Christoph Lameter, (Wed Apr 23, 3:28 pm)
device_pm_add (was: Re: 2.6.25-git2: BUG: unable to handle k..., Rafael J. Wysocki, (Tue Apr 22, 4:34 pm)
Re: device_pm_add (was: Re: 2.6.25-git2: BUG: unable to hand..., Rafael J. Wysocki, (Tue Apr 22, 8:50 pm)
Re: device_pm_add (was: Re: 2.6.25-git2: BUG: unable to hand..., Rafael J. Wysocki, (Tue Apr 22, 6:48 pm)
Re: device_pm_add (was: Re: 2.6.25-git2: BUG: unable to hand..., Rafael J. Wysocki, (Tue Apr 22, 4:57 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Tue Apr 22, 5:46 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 9:30 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 9:15 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Paul E. McKenney, (Sun Apr 20, 10:08 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Paul E. McKenney, (Mon Apr 21, 12:59 am)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 12:24 pm)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Mon Apr 21, 9:35 am)
Re: 2.6.25-git2: BUG: unable to handle kernel paging request..., Rafael J. Wysocki, (Sun Apr 20, 3:14 pm)