From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: arnd@kernel.org, arnd@arndb.de, rppt@kernel.org,
pasha.tatashin@soleen.com, mcgrof@kernel.org, song@kernel.org,
mhiramat@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, surenb@google.com,
kernel test robot <lkp@intel.com>
Subject: [PATCH 1/1] alloc_tag: avoid execmem_vmap() when !MMU
Date: Mon, 28 Oct 2024 13:29:35 -0700 [thread overview]
Message-ID: <20241028202935.1047017-1-surenb@google.com> (raw)
With CONFIG_MMU=n __get_vm_area_node() is not available and memory for the
allocation tags cannot be populated as needed. For this case, populate the
required memory at initialization time.
Fixes: 57bc3834fb6f ("alloc_tag: populate memory for module tags as needed")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202410250808.dQGyYjlk-lkp@intel.com/
Closes: https://lore.kernel.org/oe-lkp/202410251525.9f85854d-oliver.sang@intel.com
Closes: https://lore.kernel.org/oe-kbuild-all/202410261016.IO7C6Cml-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202410270919.LebQlmxD-lkp@intel.com/
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
include/linux/execmem.h | 2 ++
lib/alloc_tag.c | 23 ++++++++++++++++++++++-
mm/execmem.c | 32 ++++++++++++++++----------------
3 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/include/linux/execmem.h b/include/linux/execmem.h
index 5a5e2917f870..64130ae19690 100644
--- a/include/linux/execmem.h
+++ b/include/linux/execmem.h
@@ -139,6 +139,7 @@ void *execmem_alloc(enum execmem_type type, size_t size);
*/
void execmem_free(void *ptr);
+#ifdef CONFIG_MMU
/**
* execmem_vmap - create virtual mapping for EXECMEM_MODULE_DATA memory
* @size: size of the virtual mapping in bytes
@@ -148,6 +149,7 @@ void execmem_free(void *ptr);
* Return: the area descriptor on success or %NULL on failure.
*/
struct vm_struct *execmem_vmap(size_t size);
+#endif
/**
* execmem_update_copy - copy an update to executable memory
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index c1ddac2d29f0..1c74942e6dfd 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -268,7 +268,6 @@ void __init alloc_tag_sec_init(void)
#ifdef CONFIG_MODULES
static struct maple_tree mod_area_mt = MTREE_INIT(mod_area_mt, MT_FLAGS_ALLOC_RANGE);
-static struct vm_struct *vm_module_tags;
/* A dummy object used to indicate an unloaded module */
static struct module unloaded_mod;
/* A dummy object used to indicate a module prepended area */
@@ -391,6 +390,9 @@ static bool find_aligned_area(struct ma_state *mas, unsigned long section_size,
return false;
}
+#ifdef CONFIG_MMU
+static struct vm_struct *vm_module_tags;
+
static int vm_module_tags_populate(void)
{
unsigned long phys_size = vm_module_tags->nr_pages << PAGE_SHIFT;
@@ -417,6 +419,13 @@ static int vm_module_tags_populate(void)
return 0;
}
+#else
+static int vm_module_tags_populate(void)
+{
+ /* Memory was already allocated */
+ return 0;
+}
+#endif
static void *reserve_module_tags(struct module *mod, unsigned long size,
unsigned int prepend, unsigned long align)
@@ -561,6 +570,7 @@ static void replace_module(struct module *mod, struct module *new_mod)
static int __init alloc_mod_tags_mem(void)
{
+#ifdef CONFIG_MMU
/* Map space to copy allocation tags */
vm_module_tags = execmem_vmap(MODULE_ALLOC_TAG_VMAP_SIZE);
if (!vm_module_tags) {
@@ -578,6 +588,13 @@ static int __init alloc_mod_tags_mem(void)
}
module_tags.start_addr = (unsigned long)vm_module_tags->addr;
+#else
+ /* Allocate space to copy allocation tags */
+ module_tags.start_addr = (unsigned long)execmem_alloc(EXECMEM_MODULE_DATA,
+ MODULE_ALLOC_TAG_VMAP_SIZE);
+ if (!module_tags.start_addr)
+ return -ENOMEM;
+#endif
module_tags.end_addr = module_tags.start_addr + MODULE_ALLOC_TAG_VMAP_SIZE;
/* Ensure the base is alloc_tag aligned when required for indexing */
module_tags.start_addr = alloc_tag_align(module_tags.start_addr);
@@ -587,6 +604,7 @@ static int __init alloc_mod_tags_mem(void)
static void __init free_mod_tags_mem(void)
{
+#ifdef CONFIG_MMU
int i;
module_tags.start_addr = 0;
@@ -594,6 +612,9 @@ static void __init free_mod_tags_mem(void)
__free_page(vm_module_tags->pages[i]);
kfree(vm_module_tags->pages);
free_vm_area(vm_module_tags);
+#else
+ execmem_free((void *)module_tags.start_addr);
+#endif
}
#else /* CONFIG_MODULES */
diff --git a/mm/execmem.c b/mm/execmem.c
index 5c0f9f2d6f83..317b6a8d35be 100644
--- a/mm/execmem.c
+++ b/mm/execmem.c
@@ -64,6 +64,22 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,
return p;
}
+
+struct vm_struct *execmem_vmap(size_t size)
+{
+ struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
+ struct vm_struct *area;
+
+ area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
+ range->start, range->end, NUMA_NO_NODE,
+ GFP_KERNEL, __builtin_return_address(0));
+ if (!area && range->fallback_start)
+ area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
+ range->fallback_start, range->fallback_end,
+ NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
+
+ return area;
+}
#else
static void *execmem_vmalloc(struct execmem_range *range, size_t size,
pgprot_t pgprot, unsigned long vm_flags)
@@ -368,22 +384,6 @@ void execmem_free(void *ptr)
vfree(ptr);
}
-struct vm_struct *execmem_vmap(size_t size)
-{
- struct execmem_range *range = &execmem_info->ranges[EXECMEM_MODULE_DATA];
- struct vm_struct *area;
-
- area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
- range->start, range->end, NUMA_NO_NODE,
- GFP_KERNEL, __builtin_return_address(0));
- if (!area && range->fallback_start)
- area = __get_vm_area_node(size, range->alignment, PAGE_SHIFT, VM_ALLOC,
- range->fallback_start, range->fallback_end,
- NUMA_NO_NODE, GFP_KERNEL, __builtin_return_address(0));
-
- return area;
-}
-
void *execmem_update_copy(void *dst, const void *src, size_t size)
{
return text_poke_copy(dst, src, size);
base-commit: 92409df3e00a17d6fd5bb27732fa186749725ed5
--
2.47.0.163.g1226f6d8fa-goog
next reply other threads:[~2024-10-28 20:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 20:29 Suren Baghdasaryan [this message]
2024-10-29 17:09 ` Mike Rapoport
2024-10-29 20:03 ` Suren Baghdasaryan
2024-10-30 12:43 ` Mike Rapoport
2024-10-30 23:42 ` Suren Baghdasaryan
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=20241028202935.1047017-1-surenb@google.com \
--to=surenb@google.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=pasha.tatashin@soleen.com \
--cc=rppt@kernel.org \
--cc=song@kernel.org \
/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