[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250121095739.986006-5-rppt@kernel.org>
Date: Tue, 21 Jan 2025 11:57:33 +0200
From: Mike Rapoport <rppt@...nel.org>
To: x86@...nel.org
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Andy Lutomirski <luto@...nel.org>,
Anton Ivanov <anton.ivanov@...bridgegreys.com>,
Borislav Petkov <bp@...en8.de>,
Brendan Higgins <brendan.higgins@...ux.dev>,
Daniel Gomez <da.gomez@...sung.com>,
Daniel Thompson <danielt@...nel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
David Gow <davidgow@...gle.com>,
Douglas Anderson <dianders@...omium.org>,
Ingo Molnar <mingo@...hat.com>,
Jason Wessel <jason.wessel@...driver.com>,
Jiri Kosina <jikos@...nel.org>,
Joe Lawrence <joe.lawrence@...hat.com>,
Johannes Berg <johannes@...solutions.net>,
Josh Poimboeuf <jpoimboe@...nel.org>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Luis Chamberlain <mcgrof@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mike Rapoport <rppt@...nel.org>,
Miroslav Benes <mbenes@...e.cz>,
"H. Peter Anvin" <hpa@...or.com>,
Peter Zijlstra <peterz@...radead.org>,
Petr Mladek <pmladek@...e.com>,
Petr Pavlu <petr.pavlu@...e.com>,
Rae Moar <rmoar@...gle.com>,
Richard Weinberger <richard@....at>,
Sami Tolvanen <samitolvanen@...gle.com>,
Shuah Khan <shuah@...nel.org>,
Song Liu <song@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
Thomas Gleixner <tglx@...utronix.de>,
kgdb-bugreport@...ts.sourceforge.net,
kunit-dev@...glegroups.com,
linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org,
linux-mm@...ck.org,
linux-modules@...r.kernel.org,
linux-trace-kernel@...r.kernel.org,
linux-um@...ts.infradead.org,
live-patching@...r.kernel.org
Subject: [PATCH v2 04/10] execmem: don't remove ROX cache from the direct map
From: "Mike Rapoport (Microsoft)" <rppt@...nel.org>
The memory allocated for the ROX cache was removed from the direct map to
reduce amount of direct map updates, however this cannot be tolerated by
/proc/kcore that accesses module memory using vread_iter() and the latter
does vmalloc_to_page() and copy_page_to_iter_nofault().
Instead of removing ROX cache memory from the direct map and mapping it as
ROX in vmalloc space, simply call set_memory_rox() that will take care of
proper permissions on both vmalloc and in the direct map.
Signed-off-by: Mike Rapoport (Microsoft) <rppt@...nel.org>
---
mm/execmem.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/mm/execmem.c b/mm/execmem.c
index 317b6a8d35be..04b0bf1b5025 100644
--- a/mm/execmem.c
+++ b/mm/execmem.c
@@ -257,7 +257,6 @@ static void *__execmem_cache_alloc(struct execmem_range *range, size_t size)
static int execmem_cache_populate(struct execmem_range *range, size_t size)
{
unsigned long vm_flags = VM_ALLOW_HUGE_VMAP;
- unsigned long start, end;
struct vm_struct *vm;
size_t alloc_size;
int err = -ENOMEM;
@@ -275,26 +274,18 @@ static int execmem_cache_populate(struct execmem_range *range, size_t size)
/* fill memory with instructions that will trap */
execmem_fill_trapping_insns(p, alloc_size, /* writable = */ true);
- start = (unsigned long)p;
- end = start + alloc_size;
-
- vunmap_range(start, end);
-
- err = execmem_set_direct_map_valid(vm, false);
- if (err)
- goto err_free_mem;
-
- err = vmap_pages_range_noflush(start, end, range->pgprot, vm->pages,
- PMD_SHIFT);
+ err = set_memory_rox((unsigned long)p, vm->nr_pages);
if (err)
goto err_free_mem;
err = execmem_cache_add(p, alloc_size);
if (err)
- goto err_free_mem;
+ goto err_reset_direct_map;
return 0;
+err_reset_direct_map:
+ execmem_set_direct_map_valid(vm, true);
err_free_mem:
vfree(p);
return err;
--
2.45.2
Powered by blists - more mailing lists