Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d21b0e3 authored by Rusty Russell's avatar Rusty Russell
Browse files

module: add new state MODULE_STATE_UNFORMED.



You should never look at such a module, so it's excised from all paths
which traverse the modules list.

We add the state at the end, to avoid gratuitous ABI break (ksplice).

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 52441fa8
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -199,11 +199,11 @@ struct module_use {
	struct module *source, *target;
	struct module *source, *target;
};
};


enum module_state
enum module_state {
{
	MODULE_STATE_LIVE,	/* Normal state. */
	MODULE_STATE_LIVE,
	MODULE_STATE_COMING,	/* Full formed, running module_init. */
	MODULE_STATE_COMING,
	MODULE_STATE_GOING,	/* Going away. */
	MODULE_STATE_GOING,
	MODULE_STATE_UNFORMED,	/* Still setting it up. */
};
};


/**
/**
+2 −0
Original line number Original line Diff line number Diff line
@@ -1970,6 +1970,8 @@ static int kdb_lsmod(int argc, const char **argv)


	kdb_printf("Module                  Size  modstruct     Used by\n");
	kdb_printf("Module                  Size  modstruct     Used by\n");
	list_for_each_entry(mod, kdb_modules, list) {
	list_for_each_entry(mod, kdb_modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;


		kdb_printf("%-20s%8u  0x%p ", mod->name,
		kdb_printf("%-20s%8u  0x%p ", mod->name,
			   mod->core_size, (void *)mod);
			   mod->core_size, (void *)mod);
+52 −5
Original line number Original line Diff line number Diff line
@@ -188,6 +188,7 @@ struct load_info {
   ongoing or failed initialization etc. */
   ongoing or failed initialization etc. */
static inline int strong_try_module_get(struct module *mod)
static inline int strong_try_module_get(struct module *mod)
{
{
	BUG_ON(mod && mod->state == MODULE_STATE_UNFORMED);
	if (mod && mod->state == MODULE_STATE_COMING)
	if (mod && mod->state == MODULE_STATE_COMING)
		return -EBUSY;
		return -EBUSY;
	if (try_module_get(mod))
	if (try_module_get(mod))
@@ -343,6 +344,9 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
#endif
#endif
		};
		};


		if (mod->state == MODULE_STATE_UNFORMED)
			continue;

		if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
		if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
			return true;
			return true;
	}
	}
@@ -450,16 +454,24 @@ const struct kernel_symbol *find_symbol(const char *name,
EXPORT_SYMBOL_GPL(find_symbol);
EXPORT_SYMBOL_GPL(find_symbol);


/* Search for module by name: must hold module_mutex. */
/* Search for module by name: must hold module_mutex. */
struct module *find_module(const char *name)
static struct module *find_module_all(const char *name,
				      bool even_unformed)
{
{
	struct module *mod;
	struct module *mod;


	list_for_each_entry(mod, &modules, list) {
	list_for_each_entry(mod, &modules, list) {
		if (!even_unformed && mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (strcmp(mod->name, name) == 0)
		if (strcmp(mod->name, name) == 0)
			return mod;
			return mod;
	}
	}
	return NULL;
	return NULL;
}
}

struct module *find_module(const char *name)
{
	return find_module_all(name, false);
}
EXPORT_SYMBOL_GPL(find_module);
EXPORT_SYMBOL_GPL(find_module);


#ifdef CONFIG_SMP
#ifdef CONFIG_SMP
@@ -525,6 +537,8 @@ bool is_module_percpu_address(unsigned long addr)
	preempt_disable();
	preempt_disable();


	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (!mod->percpu_size)
		if (!mod->percpu_size)
			continue;
			continue;
		for_each_possible_cpu(cpu) {
		for_each_possible_cpu(cpu) {
@@ -1048,6 +1062,8 @@ static ssize_t show_initstate(struct module_attribute *mattr,
	case MODULE_STATE_GOING:
	case MODULE_STATE_GOING:
		state = "going";
		state = "going";
		break;
		break;
	default:
		BUG();
	}
	}
	return sprintf(buffer, "%s\n", state);
	return sprintf(buffer, "%s\n", state);
}
}
@@ -1786,6 +1802,8 @@ void set_all_modules_text_rw(void)


	mutex_lock(&module_mutex);
	mutex_lock(&module_mutex);
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if ((mod->module_core) && (mod->core_text_size)) {
		if ((mod->module_core) && (mod->core_text_size)) {
			set_page_attributes(mod->module_core,
			set_page_attributes(mod->module_core,
						mod->module_core + mod->core_text_size,
						mod->module_core + mod->core_text_size,
@@ -1807,6 +1825,8 @@ void set_all_modules_text_ro(void)


	mutex_lock(&module_mutex);
	mutex_lock(&module_mutex);
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if ((mod->module_core) && (mod->core_text_size)) {
		if ((mod->module_core) && (mod->core_text_size)) {
			set_page_attributes(mod->module_core,
			set_page_attributes(mod->module_core,
						mod->module_core + mod->core_text_size,
						mod->module_core + mod->core_text_size,
@@ -2998,7 +3018,8 @@ static bool finished_loading(const char *name)


	mutex_lock(&module_mutex);
	mutex_lock(&module_mutex);
	mod = find_module(name);
	mod = find_module(name);
	ret = !mod || mod->state != MODULE_STATE_COMING;
	ret = !mod || mod->state == MODULE_STATE_LIVE
		|| mod->state == MODULE_STATE_GOING;
	mutex_unlock(&module_mutex);
	mutex_unlock(&module_mutex);


	return ret;
	return ret;
@@ -3361,6 +3382,8 @@ const char *module_address_lookup(unsigned long addr,


	preempt_disable();
	preempt_disable();
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (within_module_init(addr, mod) ||
		if (within_module_init(addr, mod) ||
		    within_module_core(addr, mod)) {
		    within_module_core(addr, mod)) {
			if (modname)
			if (modname)
@@ -3384,6 +3407,8 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)


	preempt_disable();
	preempt_disable();
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (within_module_init(addr, mod) ||
		if (within_module_init(addr, mod) ||
		    within_module_core(addr, mod)) {
		    within_module_core(addr, mod)) {
			const char *sym;
			const char *sym;
@@ -3408,6 +3433,8 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,


	preempt_disable();
	preempt_disable();
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (within_module_init(addr, mod) ||
		if (within_module_init(addr, mod) ||
		    within_module_core(addr, mod)) {
		    within_module_core(addr, mod)) {
			const char *sym;
			const char *sym;
@@ -3435,6 +3462,8 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,


	preempt_disable();
	preempt_disable();
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (symnum < mod->num_symtab) {
		if (symnum < mod->num_symtab) {
			*value = mod->symtab[symnum].st_value;
			*value = mod->symtab[symnum].st_value;
			*type = mod->symtab[symnum].st_info;
			*type = mod->symtab[symnum].st_info;
@@ -3477,10 +3506,13 @@ unsigned long module_kallsyms_lookup_name(const char *name)
			ret = mod_find_symname(mod, colon+1);
			ret = mod_find_symname(mod, colon+1);
		*colon = ':';
		*colon = ':';
	} else {
	} else {
		list_for_each_entry_rcu(mod, &modules, list)
		list_for_each_entry_rcu(mod, &modules, list) {
			if (mod->state == MODULE_STATE_UNFORMED)
				continue;
			if ((ret = mod_find_symname(mod, name)) != 0)
			if ((ret = mod_find_symname(mod, name)) != 0)
				break;
				break;
		}
		}
	}
	preempt_enable();
	preempt_enable();
	return ret;
	return ret;
}
}
@@ -3494,6 +3526,8 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
	int ret;
	int ret;


	list_for_each_entry(mod, &modules, list) {
	list_for_each_entry(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		for (i = 0; i < mod->num_symtab; i++) {
		for (i = 0; i < mod->num_symtab; i++) {
			ret = fn(data, mod->strtab + mod->symtab[i].st_name,
			ret = fn(data, mod->strtab + mod->symtab[i].st_name,
				 mod, mod->symtab[i].st_value);
				 mod, mod->symtab[i].st_value);
@@ -3509,6 +3543,7 @@ static char *module_flags(struct module *mod, char *buf)
{
{
	int bx = 0;
	int bx = 0;


	BUG_ON(mod->state == MODULE_STATE_UNFORMED);
	if (mod->taints ||
	if (mod->taints ||
	    mod->state == MODULE_STATE_GOING ||
	    mod->state == MODULE_STATE_GOING ||
	    mod->state == MODULE_STATE_COMING) {
	    mod->state == MODULE_STATE_COMING) {
@@ -3550,6 +3585,10 @@ static int m_show(struct seq_file *m, void *p)
	struct module *mod = list_entry(p, struct module, list);
	struct module *mod = list_entry(p, struct module, list);
	char buf[8];
	char buf[8];


	/* We always ignore unformed modules. */
	if (mod->state == MODULE_STATE_UNFORMED)
		return 0;

	seq_printf(m, "%s %u",
	seq_printf(m, "%s %u",
		   mod->name, mod->init_size + mod->core_size);
		   mod->name, mod->init_size + mod->core_size);
	print_unload_info(m, mod);
	print_unload_info(m, mod);
@@ -3610,6 +3649,8 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)


	preempt_disable();
	preempt_disable();
	list_for_each_entry_rcu(mod, &modules, list) {
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (mod->num_exentries == 0)
		if (mod->num_exentries == 0)
			continue;
			continue;


@@ -3658,10 +3699,13 @@ struct module *__module_address(unsigned long addr)
	if (addr < module_addr_min || addr > module_addr_max)
	if (addr < module_addr_min || addr > module_addr_max)
		return NULL;
		return NULL;


	list_for_each_entry_rcu(mod, &modules, list)
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		if (within_module_core(addr, mod)
		if (within_module_core(addr, mod)
		    || within_module_init(addr, mod))
		    || within_module_init(addr, mod))
			return mod;
			return mod;
	}
	return NULL;
	return NULL;
}
}
EXPORT_SYMBOL_GPL(__module_address);
EXPORT_SYMBOL_GPL(__module_address);
@@ -3714,8 +3758,11 @@ void print_modules(void)
	printk(KERN_DEFAULT "Modules linked in:");
	printk(KERN_DEFAULT "Modules linked in:");
	/* Most callers should already have preempt disabled, but make sure */
	/* Most callers should already have preempt disabled, but make sure */
	preempt_disable();
	preempt_disable();
	list_for_each_entry_rcu(mod, &modules, list)
	list_for_each_entry_rcu(mod, &modules, list) {
		if (mod->state == MODULE_STATE_UNFORMED)
			continue;
		printk(" %s%s", mod->name, module_flags(mod, buf));
		printk(" %s%s", mod->name, module_flags(mod, buf));
	}
	preempt_enable();
	preempt_enable();
	if (last_unloaded_module[0])
	if (last_unloaded_module[0])
		printk(" [last unloaded: %s]", last_unloaded_module);
		printk(" [last unloaded: %s]", last_unloaded_module);