mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeffrey Brian Arnold <jbarnold@MIT.EDU>
To: linux-kernel@vger.kernel.org
Cc: Tim Abbott <tabbott@MIT.EDU>, Anders Kaseorg <andersk@MIT.EDU>,
	Waseem Daher <wdaher@MIT.EDU>,
	Denys Vlasenko <vda.linux@googlemail.com>
Subject: [RFC PATCH 7/9] Ksplice: x86-32 and x86-64 support
Date: Sat, 13 Sep 2008 00:49:55 -0400	[thread overview]
Message-ID: <95a158bee29bdcfa7d2bb537fdfe1e6af21599c7.1221280912.git.jbarnold@mit.edu> (raw)
In-Reply-To: <1400216dcddf0a06152b92b2d0a463097ba6c0e2.1221271644.git.jbarnold@mit.edu>
In-Reply-To: <bfbae790a8f63d8697062036d47e0756e9f3ad5f.1221280912.git.jbarnold@mit.edu>

Add support for Ksplice on x86.

Signed-off-by: Jeffrey Brian Arnold <jbarnold@mit.edu>
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Signed-off-by: Tim Abbott <tabbott@mit.edu>
---
 arch/x86/Kconfig               |    1 +
 arch/x86/kernel/ksplice-arch.c |   91 ++++++++++++++++++++++++++++++++++++++++
 arch/x86/mm/init_32.c          |    6 +-
 arch/x86/mm/init_64.c          |    4 +-
 4 files changed, 97 insertions(+), 5 deletions(-)
 create mode 100644 arch/x86/kernel/ksplice-arch.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ed92864..b5ec2f4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -23,6 +23,7 @@ config X86
 	select HAVE_OPROFILE
 	select HAVE_IOREMAP_PROT
 	select HAVE_KPROBES
+	select HAVE_KSPLICE
 	select ARCH_WANT_OPTIONAL_GPIOLIB
 	select HAVE_KRETPROBES
 	select HAVE_DYNAMIC_FTRACE
diff --git a/arch/x86/kernel/ksplice-arch.c b/arch/x86/kernel/ksplice-arch.c
new file mode 100644
index 0000000..52314c4
--- /dev/null
+++ b/arch/x86/kernel/ksplice-arch.c
@@ -0,0 +1,91 @@
+/*  Copyright (C) 2007-2008  Jeffrey Brian Arnold <jbarnold@mit.edu>
+ *  Copyright (C) 2008  Anders Kaseorg <andersk@mit.edu>,
+ *                      Tim Abbott <tabbott@mit.edu>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License, version 2.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+#define KSPLICE_IP(x) ((x)->thread.ip)
+#define KSPLICE_SP(x) ((x)->thread.sp)
+
+static const struct ksplice_symbol trampoline_symbol = {
+	.name = NULL,
+	.label = "<trampoline>",
+};
+
+static const struct ksplice_reloc trampoline_reloc = {
+	.symbol = &trampoline_symbol,
+	.pcrel = 1,
+	.addend = -4,
+	.size = 4,
+	.dst_mask = 0xffffffffL,
+	.rightshift = 0,
+	.signed_addend = 1,
+};
+
+static abort_t trampoline_target(struct ksplice_pack *pack, unsigned long addr,
+				 unsigned long *new_addr)
+{
+	abort_t ret;
+	unsigned char byte;
+
+	if (probe_kernel_read(&byte, (void *)addr, sizeof(byte)) == -EFAULT)
+		return NO_MATCH;
+
+	if (byte != 0xe9)
+		return NO_MATCH;
+
+	ret = read_reloc_value(pack, &trampoline_reloc, addr + 1, new_addr);
+	if (ret != OK)
+		return ret;
+
+	*new_addr += addr + 1;
+	return OK;
+}
+
+static abort_t prepare_trampoline(struct ksplice_pack *pack,
+				  struct ksplice_trampoline *t)
+{
+	t->size = 5;
+	t->trampoline[0] = 0xe9;
+	return write_reloc_value(pack, &trampoline_reloc,
+				 (unsigned long)t->trampoline + 1,
+				 t->repladdr - (t->oldaddr + 1));
+}
+
+static abort_t handle_paravirt(struct ksplice_pack *pack,
+			       unsigned long pre_addr, unsigned long run_addr,
+			       int *matched)
+{
+	unsigned char run[5], pre[5];
+	*matched = 0;
+
+	if (probe_kernel_read(&run, (void *)run_addr, sizeof(run)) == -EFAULT ||
+	    probe_kernel_read(&pre, (void *)pre_addr, sizeof(pre)) == -EFAULT)
+		return OK;
+
+	if ((run[0] == 0xe8 && pre[0] == 0xe8) ||
+	    (run[0] == 0xe9 && pre[0] == 0xe9))
+		if (run_addr + 1 + *(int32_t *)&run[1] ==
+		    pre_addr + 1 + *(int32_t *)&pre[1])
+			*matched = 5;
+	return OK;
+}
+
+static bool valid_stack_ptr(const struct thread_info *tinfo, const void *p)
+{
+	return p > (const void *)tinfo
+	    && p <= (const void *)tinfo + THREAD_SIZE - sizeof(long);
+}
+
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index d37f293..5998d5c 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -1036,8 +1036,8 @@ void mark_rodata_ro(void)
 	unsigned long start = PFN_ALIGN(_text);
 	unsigned long size = PFN_ALIGN(_etext) - start;
 
-#ifndef CONFIG_DYNAMIC_FTRACE
-	/* Dynamic tracing modifies the kernel text section */
+#if !defined(CONFIG_DYNAMIC_FTRACE) && !defined(CONFIG_KSPLICE)
+	/* Dynamic tracing and Ksplice modify the kernel text section */
 	set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
 	printk(KERN_INFO "Write protecting the kernel text: %luk\n",
 		size >> 10);
@@ -1050,7 +1050,7 @@ void mark_rodata_ro(void)
 	printk(KERN_INFO "Testing CPA: write protecting again\n");
 	set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
 #endif
-#endif /* CONFIG_DYNAMIC_FTRACE */
+#endif /* !CONFIG_DYNAMIC_FTRACE && !CONFIG_KSPLICE */
 
 	start += size;
 	size = (unsigned long)__end_rodata - start;
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index d3746ef..31db657 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -857,8 +857,8 @@ void mark_rodata_ro(void)
 	unsigned long rodata_start =
 		((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
 
-#ifdef CONFIG_DYNAMIC_FTRACE
-	/* Dynamic tracing modifies the kernel text section */
+#if defined(CONFIG_DYNAMIC_FTRACE) || defined(CONFIG_KSPLICE)
+	/* Dynamic tracing and Ksplice modify the kernel text section */
 	start = rodata_start;
 #endif
 
-- 
1.5.4.3


  reply	other threads:[~2008-09-13  4:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13  4:49 [RFC PATCH 0/9] Ksplice: Rebootless kernel updates Jeffrey Brian Arnold
2008-09-13  4:49 ` [RFC PATCH 1/9] Ksplice: Make find_symbol return a struct kernel_symbol Jeffrey Brian Arnold
2008-09-13  4:49   ` [RFC PATCH 2/9] Ksplice: Add module_data_address (the analogue of module_text_address) Jeffrey Brian Arnold
2008-09-13  4:49     ` [RFC PATCH 3/9] Ksplice: Add functions for walking kallsyms symbols Jeffrey Brian Arnold
2008-09-13  4:49       ` [RFC PATCH 4/9] Ksplice: Make needed symbol and module functions global Jeffrey Brian Arnold
2008-09-13  4:49         ` [RFC PATCH 5/9] Ksplice: Architecture-independent core Jeffrey Brian Arnold
     [not found]           ` <8d86b7714a1012014ce3533aa24dc88704fe14a6.1221271644.git.jbarnold@mit.edu>
2008-09-13  4:49             ` [RFC PATCH 5/9] Ksplice core (architecture independent) Jeffrey Brian Arnold
2008-09-13  4:49               ` [RFC PATCH 6/9] Ksplice: Documentation Jeffrey Brian Arnold
2008-09-13  4:49             ` [RFC PATCH 6/9] Ksplice documentation Jeffrey Brian Arnold
2008-09-13  4:49               ` Jeffrey Brian Arnold [this message]
2008-09-13  4:49                 ` [RFC PATCH 8/9] Ksplice: ARM support Jeffrey Brian Arnold
2008-09-13  4:49                   ` [RFC PATCH 9/9] Ksplice: Add support for building Ksplice as a module Jeffrey Brian Arnold
2008-09-13  5:12 ` [RFC PATCH 0/9] Ksplice: Rebootless kernel updates Alexey Dobriyan
2008-09-14 20:24   ` Jeff Arnold

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=95a158bee29bdcfa7d2bb537fdfe1e6af21599c7.1221280912.git.jbarnold@mit.edu \
    --to=jbarnold@mit.edu \
    --cc=andersk@MIT.EDU \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tabbott@MIT.EDU \
    --cc=vda.linux@googlemail.com \
    --cc=wdaher@MIT.EDU \
    /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

all inboxes | Powered by JetHome®