Skip to contentSkip to conversation

Ksplice: Rebootless kernel updates

RFC PATCH Superseded Jeffrey Brian Arnold 1 participant 10 messages Sep 13, 2008

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Ksplice: Rebootless kernel updates

(Sorry, I mangled the first patch series. Please disregard those messages.)

These RFC patches add support for Ksplice [1], a rebootless update system, to the kernel. I previously mentioned Ksplice to the LKML a few months ago [2]. The basic idea is that Ksplice can apply an update to a running Linux kernel based only on a source code patch and the original kernel source. The Ksplice technical overview document [3] describes the design of Ksplice and one of the ways that Ksplice has been evaluated.

[1] http://web.mit.edu/ksplice
[2] http://lkml.org/lkml/2008/4/23/330
[3] http://web.mit.edu/ksplice/doc/ksplice.pdf

The interface between the Ksplice kernel component and the userspace utilities is documented in patch 6/9 of this series. The current implementation of the userspace utilities is available from the Ksplice website and the Ksplice git repository [4]. The Ksplice userspace utilities transparently support both "integrated" operation (updating a kernel patched with this patch series) and "standalone" operation (updating a completely unmodified kernel).

[4] http://web.mit.edu/ksplice/ksplice.git

This series of patches depends upon the -ffunction-sections and -fdata-sections patches proposed by Denys Vlasenko (for reasons unrelated to Ksplice) a few weeks ago [5]. Ksplice's 'run-pre matching' process is much simpler if the original kernel was compiled with -ffunction-sections and -fdata-sections, and so we require these compiler options for this patch series. We think that requiring these options in order to build a kernel with integrated Ksplice support is reasonable, but we welcome feedback.

[5] http://lkml.org/lkml/2008/8/24/159

Denys Vlasenko has already submitted patches to the LKML for allowing all architectures to compile with -ffunction-sections and -fdata-sections [5]; he has said that he will later submit patches making it possible to run a kernel with these options [6]. In the meantime, we have a patch that creates a CONFIG_FUNCTION_DATA_SECTIONS option for x86 and ARM [7], but we have not polished this patch since Denys Vlasenko is already preparing a similar change.

[6] http://lkml.org/lkml/2008/8/26/288
[7] http://web.mit.edu/ksplice/tmp/function-data-sections.patch

We're open to suggestions and are available to make whatever changes people would like to see. (Also, I'll be at the Plumbers Conference next week and would be happy to chat with anyone about Ksplice in person).

Jeff Arnold
[email protected]

--

Documentation/ksplice.txt      |  247 +++++
MAINTAINERS                    |   10 +
arch/Kconfig                   |   14 +
arch/arm/Kconfig               |    1 +
arch/arm/kernel/ksplice-arch.c |   79 ++
arch/x86/Kconfig               |    1 +
arch/x86/kernel/ksplice-arch.c |   91 ++
arch/x86/mm/init_32.c          |    7 +-
arch/x86/mm/init_64.c          |    5 +-
include/linux/kallsyms.h       |   13 +
include/linux/ksplice.h        |  202 ++++
include/linux/module.h         |   27 +
kernel/Makefile                |    2 +
kernel/kallsyms.c              |   19 +
kernel/ksplice.c               | 1997 ++++++++++++++++++++++++++++++++++++++++
kernel/module.c                |  144 ++-
kernel/sched.c                 |    1 +
17 files changed, 2810 insertions(+), 50 deletions(-)
#1 lore raw

RFC PATCH v2 1/9 Ksplice: Make find_symbol return a struct kernel_symbol

From: Tim Abbott <[email protected]>

Ksplice needs access to the kernel_symbol structure in order to support modifications to the exported symbol table.

---
 kernel/module.c |   80 ++++++++++++++++++++++++++----------------------------
 1 files changed, 39 insertions(+), 41 deletions(-)
kernel/module.c +39 -41
index 6cedfc7..8954556 100644
@@ -254,7 +254,7 @@ struct find_symbol_arg {
 	/* Output */
 	struct module *owner;
 	const unsigned long *crc;
-	unsigned long value;
+	const struct kernel_symbol *sym;
 };
 
 static bool find_symbol_in_section(const struct symsearch *syms,
@@ -295,17 +295,17 @@ static bool find_symbol_in_section(const struct symsearch *syms,
 
 	fsa->owner = owner;
 	fsa->crc = symversion(syms->crcs, symnum);
-	fsa->value = syms->start[symnum].value;
+	fsa->sym = &syms->start[symnum];
 	return true;
 }
 
-/* Find a symbol, return value, (optional) crc and (optional) module
- * which owns it */
-static unsigned long find_symbol(const char *name,
-				 struct module **owner,
-				 const unsigned long **crc,
-				 bool gplok,
-				 bool warn)
+/* Find a symbol and return it, along with, (optional) crc and
+ * (optional) module which owns it */
+static const struct kernel_symbol *find_symbol(const char *name,
+					       struct module **owner,
+					       const unsigned long **crc,
+					       bool gplok,
+					       bool warn)
 {
 	struct find_symbol_arg fsa;
 
@@ -318,11 +318,11 @@ static unsigned long find_symbol(const char *name,
 			*owner = fsa.owner;
 		if (crc)
 			*crc = fsa.crc;
-		return fsa.value;
+		return fsa.sym;
 	}
 
 	DEBUGP("Failed to find symbol %s\n", name);
-	return -ENOENT;
+	return NULL;
 }
 
 /* Search for module by name: must hold module_mutex. */
@@ -819,7 +819,7 @@ void __symbol_put(const char *symbol)
 	struct module *owner;
 
 	preempt_disable();
-	if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false)))
+	if (find_symbol(symbol, &owner, NULL, true, false) == NULL)
 		BUG();
 	module_put(owner);
 	preempt_enable();
@@ -982,7 +982,7 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
 {
 	const unsigned long *crc;
 
-	if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false)))
+	if (find_symbol("struct_module", NULL, &crc, true, false) == NULL)
 		BUG();
 	return check_version(sechdrs, versindex, "struct_module", mod, crc);
 }
@@ -1023,25 +1023,23 @@ static inline int same_magic(const char *amagic, const char *bmagic,
 
 /* Resolve a symbol for this module.  I.e. if we find one, record usage.
    Must be holding module_mutex. */
-static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
-				    unsigned int versindex,
-				    const char *name,
-				    struct module *mod)
+static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
+						  unsigned int versindex,
+						  const char *name,
+						  struct module *mod)
 {
 	struct module *owner;
-	unsigned long ret;
+	const struct kernel_symbol *sym;
 	const unsigned long *crc;
 
-	ret = find_symbol(name, &owner, &crc,
+	sym = find_symbol(name, &owner, &crc,
 			  !(mod->taints & TAINT_PROPRIETARY_MODULE), true);
-	if (!IS_ERR_VALUE(ret)) {
-		/* use_module can fail due to OOM,
-		   or module initialization or unloading */
-		if (!check_version(sechdrs, versindex, name, mod, crc) ||
-		    !use_module(mod, owner))
-			ret = -EINVAL;
-	}
-	return ret;
+	/* use_module can fail due to OOM,
+	   or module initialization or unloading */
+	if (!check_version(sechdrs, versindex, name, mod, crc) ||
+	    !use_module(mod, owner))
+		sym = NULL;
+	return sym;
 }
 
 /*
@@ -1445,17 +1443,15 @@ static void free_module(struct module *mod)
 void *__symbol_get(const char *symbol)
 {
 	struct module *owner;
-	unsigned long value;
+	const struct kernel_symbol *sym;
 
 	preempt_disable();
-	value = find_symbol(symbol, &owner, NULL, true, true);
-	if (IS_ERR_VALUE(value))
-		value = 0;
-	else if (strong_try_module_get(owner))
-		value = 0;
+	sym = find_symbol(symbol, &owner, NULL, true, true);
+	if (sym != NULL && strong_try_module_get(owner))
+		sym = NULL;
 	preempt_enable();
 
-	return (void *)value;
+	return sym == NULL ? (void *)0 : (void *)sym->value;
 }
 EXPORT_SYMBOL_GPL(__symbol_get);
 
@@ -1483,8 +1479,8 @@ static int verify_export_symbols(struct module *mod)
 
 	for (i = 0; i < ARRAY_SIZE(arr); i++) {
 		for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
-			if (!IS_ERR_VALUE(find_symbol(s->name, &owner,
-						      NULL, true, false))) {
+			if (find_symbol(s->name, &owner, NULL, true, false)
+			    != NULL) {
 				printk(KERN_ERR
 				       "%s: exports duplicate symbol %s"
 				       " (owned by %s)\n",
@@ -1508,6 +1504,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
 	unsigned long secbase;
 	unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
 	int ret = 0;
+	const struct kernel_symbol *ksym;
 
 	for (i = 1; i < n; i++) {
 		switch (sym[i].st_shndx) {
@@ -1527,13 +1524,14 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
 			break;
 
 		case SHN_UNDEF:
-			sym[i].st_value
-			  = resolve_symbol(sechdrs, versindex,
-					   strtab + sym[i].st_name, mod);
-
+			ksym = resolve_symbol(sechdrs, versindex,
+					      strtab + sym[i].st_name, mod);
 			/* Ok if resolved.  */
-			if (!IS_ERR_VALUE(sym[i].st_value))
+			if (ksym != NULL) {
+				sym[i].st_value = ksym->value;
 				break;
+			}
+
 			/* Ok if weak.  */
 			if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
 				break;
Signature · 1 line
1.5.4.3
#2 lore raw

RFC PATCH v2 2/9 Ksplice: Add module_data_address (the analogue of module_text_address)

From: Tim Abbott <[email protected]>

Ksplice's run-pre matching process needs to be able to determine the module that contains a particular data address.

---
 include/linux/module.h |    2 ++
 kernel/module.c        |   28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
include/linux/module.h +2 -0
index 68e0955..b7cdfb4 100644
@@ -362,6 +362,8 @@ static inline int module_is_live(struct module *mod)
 /* Is this address in a module? (second is with no locks, for oops) */
 struct module *module_text_address(unsigned long addr);
 struct module *__module_text_address(unsigned long addr);
+struct module *module_data_address(unsigned long addr);
+struct module *__module_data_address(unsigned long addr);
 int is_module_address(unsigned long addr);
 
 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
kernel/module.c +28 -0
index 8954556..dda2f80 100644
@@ -2682,6 +2682,34 @@ struct module *module_text_address(unsigned long addr)
 	return mod;
 }
 
+struct module *__module_data_address(unsigned long addr)
+{
+	struct module *mod;
+
+	if (addr < module_addr_min || addr > module_addr_max)
+		return NULL;
+
+	list_for_each_entry(mod, &modules, list) {
+		if (within(addr, mod->module_core + mod->core_text_size,
+			   mod->core_size - mod->core_text_size) ||
+		    within(addr, mod->module_init + mod->init_text_size,
+			   mod->init_size - mod->init_text_size))
+			return mod;
+	}
+	return NULL;
+}
+
+struct module *module_data_address(unsigned long addr)
+{
+	struct module *mod;
+
+	preempt_disable();
+	mod = __module_data_address(addr);
+	preempt_enable();
+
+	return mod;
+}
+
 /* Don't grab lock, we're oopsing. */
 void print_modules(void)
 {
Signature · 1 line
1.5.4.3
#3 lore raw

RFC PATCH v2 3/9 Ksplice: Add functions for walking kallsyms symbols

From: Anders Kaseorg <[email protected]>

kallsyms_lookup_name only returns the first match that it finds. Ksplice needs information about all symbols with a given name in order to correctly resolve local symbols.

kallsyms_on_each_symbol provides a generic mechanism for iterating over the kallsyms table.

---
 include/linux/kallsyms.h |   13 +++++++++++++
 include/linux/module.h   |   12 ++++++++++++
 kernel/kallsyms.c        |   18 ++++++++++++++++++
 kernel/module.c          |   19 +++++++++++++++++++
 4 files changed, 62 insertions(+), 0 deletions(-)
include/linux/kallsyms.h +13 -0
index b961448..b8ee4d2 100644
@@ -17,6 +17,11 @@
 /* Lookup the address for a symbol. Returns 0 if not found. */
 unsigned long kallsyms_lookup_name(const char *name);
 
+/* Call a function on each kallsyms symbol in the core kernel */
+int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
+				      unsigned long),
+			    void *data);
+
 extern int kallsyms_lookup_size_offset(unsigned long addr,
 				  unsigned long *symbolsize,
 				  unsigned long *offset);
@@ -43,6 +48,14 @@ static inline unsigned long kallsyms_lookup_name(const char *name)
 	return 0;
 }
 
+static inline int kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+						    struct module *,
+						    unsigned long),
+					  void *data)
+{
+	return 0;
+}
+
 static inline int kallsyms_lookup_size_offset(unsigned long addr,
 					      unsigned long *symbolsize,
 					      unsigned long *offset)
include/linux/module.h +12 -0
index b7cdfb4..cd982cd 100644
@@ -374,6 +374,10 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
 /* Look for this name: can be of form module:name. */
 unsigned long module_kallsyms_lookup_name(const char *name);
 
+int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+					     struct module *, unsigned long),
+				   void *data);
+
 extern void __module_put_and_exit(struct module *mod, long code)
 	__attribute__((noreturn));
 #define module_put_and_exit(code) __module_put_and_exit(THIS_MODULE, code);
@@ -539,6 +543,14 @@ static inline unsigned long module_kallsyms_lookup_name(const char *name)
 	return 0;
 }
 
+static inline int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+							   struct module *,
+							   unsigned long),
+						 void *data)
+{
+	return 0;
+}
+
 static inline int register_module_notifier(struct notifier_block * nb)
 {
 	/* no events will happen anyway, so this can always succeed */
kernel/kallsyms.c +18 -0
index 38fc10a..47d3e94 100644
@@ -161,6 +161,24 @@ unsigned long kallsyms_lookup_name(const char *name)
 	return module_kallsyms_lookup_name(name);
 }
 
+int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
+				      unsigned long),
+			    void *data)
+{
+	char namebuf[KSYM_NAME_LEN];
+	unsigned long i;
+	unsigned int off;
+	int ret;
+
+	for (i = 0, off = 0; i < kallsyms_num_syms; i++) {
+		off = kallsyms_expand_symbol(off, namebuf);
+		ret = fn(data, namebuf, NULL, kallsyms_addresses[i]);
+		if (ret != 0)
+			return ret;
+	}
+	return module_kallsyms_on_each_symbol(fn, data);
+}
+
 static unsigned long get_symbol_pos(unsigned long addr,
 				    unsigned long *symbolsize,
 				    unsigned long *offset)
kernel/module.c +19 -0
index dda2f80..343c8f8 100644
@@ -2523,6 +2523,25 @@ unsigned long module_kallsyms_lookup_name(const char *name)
 	preempt_enable();
 	return ret;
 }
+
+int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
+					     struct module *, unsigned long),
+				   void *data)
+{
+	struct module *mod;
+	unsigned int i;
+	int ret;
+
+	list_for_each_entry(mod, &modules, list) {
+		for (i = 0; i < mod->num_symtab; i++) {
+			ret = fn(data, mod->strtab + mod->symtab[i].st_name,
+				 mod, mod->symtab[i].st_value);
+			if (ret != 0)
+				return ret;
+		}
+	}
+	return 0;
+}
 #endif /* CONFIG_KALLSYMS */
 
 /* Called by the /proc file system to return a list of modules. */
Signature · 1 line
1.5.4.3
#4 lore raw

RFC PATCH v2 4/9 Ksplice: Make needed symbol and module functions global

From: Tim Abbott <[email protected]>

Make module_mutex, find_module(), find_symbol(), and use_module() global. Ksplice needs access to these functions from module.c in order to resolve symbols and implement dependency handling.

---
 include/linux/module.h |   13 +++++++++++++
 kernel/module.c        |   18 +++++++++---------
 2 files changed, 22 insertions(+), 9 deletions(-)
include/linux/module.h +13 -0
index cd982cd..6ae0fc9 100644
@@ -351,6 +351,8 @@ struct module
 #define MODULE_ARCH_INIT {}
 #endif
 
+extern struct mutex module_mutex;
+
 /* FIXME: It'd be nice to isolate modules during init, too, so they
    aren't used before they (may) fail.  But presently too much code
    (IDE & SCSI) require entry into the module during init.*/
@@ -366,6 +368,16 @@ struct module *module_data_address(unsigned long addr);
 struct module *__module_data_address(unsigned long addr);
 int is_module_address(unsigned long addr);
 
+/* Search for module by name: must hold module_mutex. */
+struct module *find_module(const char *name);
+
+/* Search for an exported symbol by name. */
+const struct kernel_symbol *find_symbol(const char *name,
+					struct module **owner,
+					const unsigned long **crc,
+					bool gplok,
+					bool warn);
+
 /* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
    symnum out of range. */
 int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
@@ -431,6 +443,7 @@ static inline void __module_get(struct module *module)
 #define symbol_put_addr(p) do { } while(0)
 
 #endif /* CONFIG_MODULE_UNLOAD */
+int use_module(struct module *a, struct module *b);
 
 /* This is a #define so the string doesn't get put in every .o file */
 #define module_name(mod)			\
kernel/module.c +9 -9
index 343c8f8..2acb646 100644
@@ -62,7 +62,7 @@
 
 /* List of modules, protected by module_mutex or preempt_disable
  * (add/delete uses stop_machine). */
-static DEFINE_MUTEX(module_mutex);
+DEFINE_MUTEX(module_mutex);
 static LIST_HEAD(modules);
 
 /* Waiting for a module to finish initializing? */
@@ -301,11 +301,11 @@ static bool find_symbol_in_section(const struct symsearch *syms,
 
 /* Find a symbol and return it, along with, (optional) crc and
  * (optional) module which owns it */
-static const struct kernel_symbol *find_symbol(const char *name,
-					       struct module **owner,
-					       const unsigned long **crc,
-					       bool gplok,
-					       bool warn)
+const struct kernel_symbol *find_symbol(const char *name,
+					struct module **owner,
+					const unsigned long **crc,
+					bool gplok,
+					bool warn)
 {
 	struct find_symbol_arg fsa;
 
@@ -326,7 +326,7 @@ static const struct kernel_symbol *find_symbol(const char *name,
 }
 
 /* Search for module by name: must hold module_mutex. */
-static struct module *find_module(const char *name)
+struct module *find_module(const char *name)
 {
 	struct module *mod;
 
@@ -579,7 +579,7 @@ static int already_uses(struct module *a, struct module *b)
 }
 
 /* Module a uses b */
-static int use_module(struct module *a, struct module *b)
+int use_module(struct module *a, struct module *b)
 {
 	struct module_use *use;
 	int no_warn, err;
@@ -874,7 +874,7 @@ static inline void module_unload_free(struct module *mod)
 {
 }
 
-static inline int use_module(struct module *a, struct module *b)
+int use_module(struct module *a, struct module *b)
 {
 	return strong_try_module_get(b) == 0;
 }
Signature · 1 line
1.5.4.3
#5 lore raw

RFC PATCH v2 5/9 Ksplice: Architecture-independent core

The architecture-independent core of Ksplice. Ksplice makes it possible to apply certain kinds of patches to the kernel without having to reboot.

---
 MAINTAINERS             |   10 +
 arch/Kconfig            |   14 +
 include/linux/ksplice.h |  202 +++++
 kernel/Makefile         |    2 +
 kernel/ksplice.c        | 1997 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 2225 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/ksplice.h
 create mode 100644 kernel/ksplice.c
MAINTAINERS +10 -0
index 186be3b..bdc6dd7 100644
@@ -2476,6 +2476,16 @@ W:	http://miguelojeda.es/auxdisplay.htm
 W:	http://jair.lab.fi.uva.es/~migojed/auxdisplay.htm
 S:	Maintained
 
+KSPLICE:
+P:	Jeffrey Brian Arnold
+M:	[email protected]
+P:	Anders Kaseorg
+M:	[email protected]
+P:	Tim Abbott
+M:	[email protected]
+W:	http://web.mit.edu/ksplice
+S:	Maintained
+
 LAPB module
 L:	[email protected]
 S:	Orphan
arch/Kconfig +14 -0
index 364c6da..9d5a843 100644
@@ -27,6 +27,17 @@ config KPROBES
 	  for kernel debugging, non-intrusive instrumentation and testing.
 	  If in doubt, say "N".
 
+config KSPLICE
+	bool "Ksplice rebootless kernel updates"
+	depends on KALLSYMS_ALL && MODULE_UNLOAD && SYSFS && \
+		   FUNCTION_DATA_SECTIONS
+	depends on HAVE_KSPLICE
+	help
+          Say Y here if you want to be able to apply certain kinds of
+          patches to your running kernel, without rebooting.
+
+          If unsure, say N.
+
 config HAVE_EFFICIENT_UNALIGNED_ACCESS
 	def_bool n
 	help
@@ -56,6 +67,9 @@ config HAVE_IOREMAP_PROT
 config HAVE_KPROBES
 	def_bool n
 
+config HAVE_KSPLICE
+	def_bool n
+
 config HAVE_KRETPROBES
 	def_bool n
 
include/linux/ksplice.h new file +202 -0

202 lines not on this page · raw message

kernel/Makefile +2 -0
index 4e1d7df..26077f5 100644
@@ -12,6 +12,7 @@ obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
 	    notifier.o ksysfs.o pm_qos_params.o sched_clock.o
 
 CFLAGS_REMOVE_sched.o = -mno-spe
+CFLAGS_ksplice.o += -Iarch/$(SRCARCH)/kernel
 
 ifdef CONFIG_FTRACE
 # Do not trace debug files and internal ftrace files
@@ -68,6 +69,7 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KSPLICE) += ksplice.o
 obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
kernel/ksplice.c new file +1997 -0

1,997 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#6 lore raw

RFC PATCH v2 6/9 Ksplice: Documentation

This document assumes familiarity with the Ksplice design and describes notable implementation details and the interface between the Ksplice kernel component and the Ksplice user space component.

---
 Documentation/ksplice.txt |  247 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 247 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ksplice.txt
Documentation/ksplice.txt new file +247 -0
new file mode 100644
index 0000000..a8fb0ba
@@ -0,0 +1,247 @@
+Ksplice
+-------
+
+CONTENTS:
+
+1. Concepts: Updates, packs, helper modules, primary modules
+2. What changes can Ksplice handle?
+3. Dependency model
+4. Locking model
+5. altinstructions, smplocks, and parainstructions
+6. sysfs interface
+7. debugfs interface
+
+0. Design Description
+---------------------
+
+For a description of the Ksplice design, please see the Ksplice technical
+overview document: <http://web.mit.edu/ksplice/doc/ksplice.pdf>.  For usage
+examples and the Ksplice man pages, please see <http://web.mit.edu/ksplice/>.
+
+The document below assumes familiarity with the Ksplice design and describes
+notable implementation details and the interface between the Ksplice kernel
+component and the Ksplice user space component.
+
+1. Concepts: Updates, packs, helper modules, primary modules
+------------------------------------------------------------
+
+A Ksplice update (struct update) contains one or more Ksplice packs, one for
+each target kernel module that should be changed by the update.  Ksplice packs
+are grouped together into a Ksplice update in order to allow multiple
+compilation units to be changed atomically.
+
+The contents of a Ksplice pack are documented via kernel-doc in
+include/linux/ksplice.h.  To construct a new Ksplice update to be performed
+atomically, one needs to:
+  1. Populate the fields of one or more ksplice_pack structures.
+  2. Call the Ksplice function init_ksplice_pack() on each pack to register
+     the packs with the Ksplice kernel component.  When init_ksplice_pack()
+     is called on a pack, that pack will be associated with the other packs
+     that share the same Ksplice identifier (KID) field.
+  3. After all of the packs intended for a particular Ksplice update have
+     been loaded, that update can be applied via the sysfs interface
+     (described in Section 7 below).
+
+In order to save memory, each Ksplice pack has a "helper" module and a "primary"
+module associated with it.
+
+The pack's "helper" module contains materials needed only for preparing for the
+update.  Specifically, the helper module contains a copy of the pre-patch
+version of each of the compilation units changed by the Ksplice pack.  The
+helper module can be unloaded after the update has been applied.
+
+The pack's "primary" module contains the new sections to be inserted by the
+update; it needs to remain loaded for as long as the update is applied.
+
+Here's an example:
+
+Let's say that the Ksplice user space component wants to update the core kernel
+and the isdn module.  The user space component will select a KID for this update
+(let's say 123abc) and generate four modules:
+
+ksplice_123abc_vmlinux (the "primary" module for the vmlinux pack)
+ksplice_123abc_vmlinux_helper (the "helper" module for the vmlinux pack)
+ksplice_123abc_isdn (the "primary" module for the vmlinux pack)
+ksplice_123abc_isdn_helper (the "helper" module for the vmlinux pack)
+
+Once both of the vmlinux modules have been loaded, one of the modules calls
+init_ksplice_pack on a pack corresponding to the desired vmlinux changes.
+
+Similarly, once both of the isdn modules have been loaded, one of the modules
+calls init_ksplice_pack on a pack corresponding to the desired isdn changes.
+
+Once all modules are loaded (in this example, four modules), the update can be
+applied atomically using the Ksplice sysfs interface.  Once the update has been
+applied, the helper modules can be unloaded safely to save memory.
+
+2. What changes can Ksplice handle?
+-----------------------------------
+
+The Ksplice user space component takes a source code patch and uses it to
+construct appropriate Ksplice packs for an update.  Ksplice can handle source
+code patches that add new functions, modify the text or arguments of existing
+functions, delete functions, change functions from local to global (or vice
+versa), add exported symbols, rename exported symbols, and delete exported
+symbols.  Ksplice can handle patches that modify either C code or assembly code.
+
+As described in the Ksplice technical overview document, Ksplice cannot handle
+semantic changes to kernel data structures.  Some other limitations also apply:
+
+Ksplice does not support changes to __init functions that been unloaded from
+kernel memory.  Ksplice also does not support changes to functions in .exit.text
+sections since Ksplice currently requires that all Ksplice updates affecting a
+module be reversed before that module can be unloaded.
+
+The Ksplice user space implementation does not currently support moving
+functions between compilation units, changes to weak symbols, and changes to
+global read-only data structures (changes to read-only data structures that are
+local to a compilation unit are fine).
+
+Exported symbols:
+
+Ksplice can handle arbitrary changes to exported symbols in the source code
+patch.
+
+Ksplice deletes exported symbols by looking up the relevant struct kernel_symbol
+in the kernel's exported symbol table and replacing the name field with a
+pointer to a string that begins with DISABLED.
+
+Ksplice adds new exported symbols through the same mechanism; the relevant
+primary module will have a ksymtab entry containing a symbol with a name
+beginning with DISABLED, and Ksplice will replace that with the name of the
+symbol to be exported when the update is atomically applied.
+
+Because the struct kernel_symbol for a newly exported symbol is contained in the
+Ksplice primary module, if a module using one of the newly exported symbols is
+loaded, that module will correctly depend on the Ksplice primary module that
+exported the symbol.
+
+3. Dependency model
+-------------------
+
+Because Ksplice resolves symbols used in the post code using Ksplice
+relocations, Ksplice must enforce additional dependencies.  Ksplice uses the
+use_module function to directly add dependencies on all the modules that the
+post code references.
+
+4. Locking model
+----------------
+
+From a locking perspective, Ksplice treats applying or removing a Ksplice update
+as analogous to loading or unloading a new version of the kernel modules patched
+by the update.  Ksplice uses module_mutex to protect against a variety of race
+conditions related to modules being loaded or unloaded while Ksplice is applying
+or reversing an update; this approach also protects against race conditions
+involving multiple Ksplice updates being loaded or unloaded simultaneously as
+well.
+
+5. altinstructions, smplocks, and parainstructions
+--------------------------------------------------
+
+There are currently several mechanisms through which the Linux kernel will
+modify executable code at runtime.
+
+These mechanisms sometimes overwrite the storage unit of a relocation, which
+would cause problems if not handled properly by Ksplice.
+
+Ksplice solves this problem by writing "canary" bytes (e.g., 0x77777777) in the
+storage unit of the relocation in user space.  Ksplice then checks whether the
+canary has been overwritten before using a Ksplice relocation to detect symbol
+values or to write a value to the storage unit of a Ksplice relocation.
+
+6. sysfs interface
+------------------
+
+Ksplice exports four sysfs files per Ksplice update in order to communicate with
+user space.  For each update, these four files are located in a directory of the
+form /sys/kernel/ksplice/$kid, with $kid replaced by the KID of the Ksplice
+update.
+
+A.  /sys/kernel/ksplice/$kid/stage (mode 0600)
+
+This file contains one of three strings:
+preparing: Indicates that this update has not yet been applied
+applied:   Indicates that this update has been applied and has not been reversed
+reversed:  Indicates that this update has been reversed
+
+When the stage is "preparing", the superuser can write "applied" to the stage
+file in order to instruct Ksplice to apply the update.  When the stage is
+"applied", the superuser can write "reversed" to the stage file in order to
+instruct Ksplice to reverse the update.  After an update has been reversed, its
+stage cannot change again (although the update can be removed from the kernel
+entirely, in which case its $kid directory will be removed).
+
+B.  /sys/kernel/ksplice/$kid/debug (mode 0600)
+
+The file contains a single number: 1 if debugging is enabled for this Ksplice
+update and 0 otherwise.
+
+The superuser can write a new value to this file to enable or disable debugging.
+
+C.  /sys/kernel/ksplice/$kid/abort_cause (mode 0400)
+
+This file contains a value indicating either 1) that Ksplice successfully
+completed the most recently requested stage transition or 2) why Ksplice aborted
+the most recently requested stage transition.
+
+Each abort_code string is described below, along with the stage transitions that
+might potentially trigger each possible abort code.  The stage transitions are
+abbreviated as follows: preparing->applied (P->A), applied->reversed (A->R).
+
+ok (P->A, A->R): The most recent stage transition succeeded.
+
+no_match (P->A): Ksplice aborted the update because Ksplice was unable to match
+the helper module's object code against the running kernel's object code.
+
+failed_to_find (P->A): Ksplice aborted the update because Ksplice was unable to
+resolve some of the symbols used in the update.
+
+missing_export (P->A): Ksplice aborted the update because the symbols exported
+by the kernel did not match Ksplice's expectations based on the ksplice_export
+structures provided to Ksplice.
+
+already_reversed (P->A): Ksplice aborted the update because once an update has
+been reversed, it cannot be applied again (without first being cleaned up and
+reinitialized).
+
+module_busy (A->R): Ksplice aborted the undo operation because the target
+Ksplice update is in use by another kernel module; specifically, either the
+target Ksplice update exports a symbol that is in use by another module or
+another Ksplice update depends on this Ksplice update.
+
+out_of_memory (P->A, A->R): Ksplice aborted the operation because a call to
+kmalloc or vmalloc failed.
+
+code_busy (P->A, A->R): Ksplice aborted the operation because Ksplice was
+unable to find a moment when one or more of the to-be-patched functions was not
+a thread's kernel stack.
+
+unexpected_running_task (P->A, A->R): Ksplice aborted the operation because
+Ksplice observed a running task during the kernel stack check, at a time when
+Ksplice expected all tasks to be stopped by stop_machine.
+
+unexpected (P->A, A->R): Ksplice aborted the operation because it encountered
+an unspecified internal error.  This condition can only be caused by an invalid
+input to Ksplice or a bug in Ksplice.
+
+D.  /sys/kernel/ksplice/$kid/conflicts (mode 0400)
+
+This file is empty until Ksplice aborts an operation because of a code_busy
+condition (see "abort_code" above).  This conflicts file then contains
+information about the process(es) that caused the stack check failure.
+
+Specifically, each line of this file consists of three space-separated values,
+describing a single conflict:
+
+$program_name $program_pid $conflict_label
+
+$program_name is the name of the program with the conflict.
+$program_pid is the pid of the program with the conflict.
+$conflict_label is the Ksplice label of the function with the conflict.
+
+7. debugfs interface
+--------------------
+
+Ksplice exports a single file to debugfs for each Ksplice update.  The file has
+a name of the form ksplice_KID, where KID is the unique identifier of the
+Ksplice update.  It contains debugging information in a human-readable format.
Signature · 1 line
1.5.4.3
#7 lore raw

RFC PATCH v2 7/9 Ksplice: x86-32 and x86-64 support

Add support for Ksplice on x86.

---
 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
arch/x86/Kconfig +1 -0
index ed92864..b5ec2f4 100644
@@ -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
arch/x86/kernel/ksplice-arch.c new file +91 -0

91 lines not on this page · raw message

arch/x86/mm/init_32.c +3 -3
index d37f293..5998d5c 100644
@@ -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;
arch/x86/mm/init_64.c +2 -2
index d3746ef..31db657 100644
@@ -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
 
Signature · 1 line
1.5.4.3
#8 lore raw

RFC PATCH v2 8/9 Ksplice: ARM support

Add support for Ksplice on ARM.

---
 arch/arm/Kconfig               |    1 +
 arch/arm/kernel/ksplice-arch.c |   79 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/kernel/ksplice-arch.c
arch/arm/Kconfig +1 -0
index 70dba16..e73f205 100644
@@ -14,6 +14,7 @@ config ARM
 	select HAVE_OPROFILE
 	select HAVE_ARCH_KGDB
 	select HAVE_KPROBES if (!XIP_KERNEL)
+	select HAVE_KSPLICE if (!XIP_KERNEL)
 	select HAVE_KRETPROBES if (HAVE_KPROBES)
 	select HAVE_FTRACE if (!XIP_KERNEL)
 	select HAVE_DYNAMIC_FTRACE if (HAVE_FTRACE)
arch/arm/kernel/ksplice-arch.c new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#9 lore raw

RFC PATCH v2 9/9 Ksplice: Add support for building Ksplice as a module

From: Tim Abbott <[email protected]>

Export the symbols needed to build Ksplice as a module.

---
 arch/Kconfig          |    2 +-
 arch/x86/mm/init_32.c |    5 +++--
 arch/x86/mm/init_64.c |    3 ++-
 kernel/kallsyms.c     |    1 +
 kernel/module.c       |    9 +++++++++
 kernel/sched.c        |    1 +
 6 files changed, 17 insertions(+), 4 deletions(-)
arch/Kconfig +1 -1
index 9d5a843..cfbbcf3 100644
@@ -28,7 +28,7 @@ config KPROBES
 	  If in doubt, say "N".
 
 config KSPLICE
-	bool "Ksplice rebootless kernel updates"
+	tristate "Ksplice rebootless kernel updates"
 	depends on KALLSYMS_ALL && MODULE_UNLOAD && SYSFS && \
 		   FUNCTION_DATA_SECTIONS
 	depends on HAVE_KSPLICE
arch/x86/mm/init_32.c +3 -2
index 5998d5c..549b021 100644
@@ -1036,7 +1036,8 @@ void mark_rodata_ro(void)
 	unsigned long start = PFN_ALIGN(_text);
 	unsigned long size = PFN_ALIGN(_etext) - start;
 
-#if !defined(CONFIG_DYNAMIC_FTRACE) && !defined(CONFIG_KSPLICE)
+#if !defined(CONFIG_DYNAMIC_FTRACE) && \
+    !defined(CONFIG_KSPLICE) && !defined(CONFIG_KSPLICE_MODULE)
 	/* 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",
@@ -1050,7 +1051,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 && !CONFIG_KSPLICE */
+#endif /* !CONFIG_DYNAMIC_FTRACE && !CONFIG_KSPLICE && !CONFIG_KSPLICE_MODULE */
 
 	start += size;
 	size = (unsigned long)__end_rodata - start;
arch/x86/mm/init_64.c +2 -1
index 31db657..dec6325 100644
@@ -857,7 +857,8 @@ void mark_rodata_ro(void)
 	unsigned long rodata_start =
 		((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
 
-#if defined(CONFIG_DYNAMIC_FTRACE) || defined(CONFIG_KSPLICE)
+#if defined(CONFIG_DYNAMIC_FTRACE) || \
+    defined(CONFIG_KSPLICE) || defined(CONFIG_KSPLICE_MODULE)
 	/* Dynamic tracing and Ksplice modify the kernel text section */
 	start = rodata_start;
 #endif
kernel/kallsyms.c +1 -0
index 47d3e94..ef47021 100644
@@ -178,6 +178,7 @@ int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
 	}
 	return module_kallsyms_on_each_symbol(fn, data);
 }
+EXPORT_SYMBOL_GPL(kallsyms_on_each_symbol);
 
 static unsigned long get_symbol_pos(unsigned long addr,
 				    unsigned long *symbolsize,
kernel/module.c +9 -0
index 2acb646..d2fa540 100644
@@ -63,6 +63,7 @@
 /* List of modules, protected by module_mutex or preempt_disable
  * (add/delete uses stop_machine). */
 DEFINE_MUTEX(module_mutex);
+EXPORT_SYMBOL_GPL(module_mutex);
 static LIST_HEAD(modules);
 
 /* Waiting for a module to finish initializing? */
@@ -324,6 +325,7 @@ const struct kernel_symbol *find_symbol(const char *name,
 	DEBUGP("Failed to find symbol %s\n", name);
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(find_symbol);
 
 /* Search for module by name: must hold module_mutex. */
 struct module *find_module(const char *name)
@@ -336,6 +338,7 @@ struct module *find_module(const char *name)
 	}
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(find_module);
 
 #ifdef CONFIG_SMP
 /* Number of blocks used and allocated. */
@@ -612,6 +615,7 @@ int use_module(struct module *a, struct module *b)
 	no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name);
 	return 1;
 }
+EXPORT_SYMBOL_GPL(use_module);
 
 /* Clear the unload stuff of the module. */
 static void module_unload_free(struct module *mod)
@@ -878,6 +882,7 @@ int use_module(struct module *a, struct module *b)
 {
 	return strong_try_module_get(b) == 0;
 }
+EXPORT_SYMBOL_GPL(use_module);
 
 static inline void module_unload_init(struct module *mod)
 {
@@ -2689,6 +2694,7 @@ struct module *__module_text_address(unsigned long addr)
 			return mod;
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(__module_text_address);
 
 struct module *module_text_address(unsigned long addr)
 {
@@ -2700,6 +2706,7 @@ struct module *module_text_address(unsigned long addr)
 
 	return mod;
 }
+EXPORT_SYMBOL_GPL(module_text_address);
 
 struct module *__module_data_address(unsigned long addr)
 {
@@ -2717,6 +2724,7 @@ struct module *__module_data_address(unsigned long addr)
 	}
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(__module_data_address);
 
 struct module *module_data_address(unsigned long addr)
 {
@@ -2728,6 +2736,7 @@ struct module *module_data_address(unsigned long addr)
 
 	return mod;
 }
+EXPORT_SYMBOL_GPL(module_data_address);
 
 /* Don't grab lock, we're oopsing. */
 void print_modules(void)
kernel/sched.c +1 -0
index cc1f81b..bd385b6 100644
@@ -1736,6 +1736,7 @@ inline int task_curr(const struct task_struct *p)
 {
 	return cpu_curr(task_cpu(p)) == p;
 }
+EXPORT_SYMBOL_GPL(task_curr);
 
 static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
 {
Signature · 1 line
1.5.4.3