@@ -96,6 +96,10 @@ static struct jit_alloc_params jit_alloc_params = {
struct jit_alloc_params *jit_alloc_arch_params(void)
{
+ /*
+ * BOOK3S_32 and 8xx define MODULES_VADDR for text allocations and
+ * allow allocating data in the entire vmalloc space
+ */
#ifdef MODULES_VADDR
pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
unsigned long limit = (unsigned long)_etext - SZ_32M;
@@ -112,6 +116,10 @@ struct jit_alloc_params *jit_alloc_arch_params(void)
jit_alloc_params.text.start = MODULES_VADDR;
jit_alloc_params.text.end = MODULES_END;
}
+
+ jit_alloc_params.data.pgprot = PAGE_KERNEL;
+ jit_alloc_params.data.start = VMALLOC_START;
+ jit_alloc_params.data.end = VMALLOC_END;
#else
jit_alloc_params.text.start = VMALLOC_START;
jit_alloc_params.text.end = VMALLOC_END;
@@ -45,6 +45,7 @@ struct jit_address_space {
*/
struct jit_alloc_params {
struct jit_address_space text;
+ struct jit_address_space data;
enum jit_alloc_flags flags;
unsigned int alignment;
};
@@ -53,6 +54,7 @@ struct jit_alloc_params *jit_alloc_arch_params(void);
void jit_free(void *buf);
void *jit_text_alloc(size_t len);
+void *jit_data_alloc(size_t len);
#ifdef CONFIG_JIT_ALLOC
void jit_alloc_init(void);
@@ -1195,25 +1195,16 @@ void __weak module_arch_freeing_init(struct module *mod)
{
}
-static bool mod_mem_use_vmalloc(enum mod_mem_type type)
-{
- return IS_ENABLED(CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC) &&
- mod_mem_type_is_core_data(type);
-}
-
static void *module_memory_alloc(unsigned int size, enum mod_mem_type type)
{
- if (mod_mem_use_vmalloc(type))
- return vzalloc(size);
+ if (mod_mem_type_is_data(type))
+ return jit_data_alloc(size);
return jit_text_alloc(size);
}
static void module_memory_free(void *ptr, enum mod_mem_type type)
{
- if (mod_mem_use_vmalloc(type))
- vfree(ptr);
- else
- jit_free(ptr);
+ jit_free(ptr);
}
static void free_mod_mem(struct module *mod)
@@ -72,6 +72,20 @@ void *jit_text_alloc(size_t len)
fallback_start, fallback_end, kasan);
}
+void *jit_data_alloc(size_t len)
+{
+ unsigned int align = jit_alloc_params.alignment;
+ pgprot_t pgprot = jit_alloc_params.data.pgprot;
+ unsigned long start = jit_alloc_params.data.start;
+ unsigned long end = jit_alloc_params.data.end;
+ unsigned long fallback_start = jit_alloc_params.data.fallback_start;
+ unsigned long fallback_end = jit_alloc_params.data.fallback_end;
+ bool kasan = jit_alloc_params.flags & JIT_ALLOC_KASAN_SHADOW;
+
+ return jit_alloc(len, align, pgprot, start, end,
+ fallback_start, fallback_end, kasan);
+}
+
struct jit_alloc_params * __weak jit_alloc_arch_params(void)
{
return NULL;
@@ -88,6 +102,23 @@ static bool jit_alloc_validate_params(struct jit_alloc_params *p)
return true;
}
+static void jit_alloc_init_missing(struct jit_alloc_params *p)
+{
+ if (!pgprot_val(jit_alloc_params.data.pgprot))
+ jit_alloc_params.data.pgprot = PAGE_KERNEL;
+
+ if (!jit_alloc_params.data.start) {
+ jit_alloc_params.data.start = p->text.start;
+ jit_alloc_params.data.end = p->text.end;
+ }
+
+ if (!jit_alloc_params.data.fallback_start &&
+ jit_alloc_params.text.fallback_start) {
+ jit_alloc_params.data.fallback_start = p->text.fallback_start;
+ jit_alloc_params.data.fallback_end = p->text.fallback_end;
+ }
+}
+
void jit_alloc_init(void)
{
struct jit_alloc_params *p = jit_alloc_arch_params();
@@ -97,6 +128,8 @@ void jit_alloc_init(void)
return;
jit_alloc_params = *p;
+ jit_alloc_init_missing(p);
+
return;
}
@@ -105,4 +138,7 @@ void jit_alloc_init(void)
jit_alloc_params.text.pgprot = PAGE_KERNEL_EXEC;
jit_alloc_params.text.start = VMALLOC_START;
jit_alloc_params.text.end = VMALLOC_END;
+ jit_alloc_params.data.pgprot = PAGE_KERNEL;
+ jit_alloc_params.data.start = VMALLOC_START;
+ jit_alloc_params.data.end = VMALLOC_END;
}