Skip to content

Commit 6d27a31

Browse files
oleg-nesterovakpm00
authored andcommitted
uprobes: introduce the global struct vm_special_mapping xol_mapping
Currently each xol_area has its own instance of vm_special_mapping, this is suboptimal and ugly. Kill xol_area->xol_mapping and add a single global instance of vm_special_mapping, the ->fault() method can use area->pages rather than xol_mapping->pages. As a side effect this fixes the problem introduced by the recent commit 223febc ("mm: add optional close() to struct vm_special_mapping"), if special_mapping_close() is called from the __mmput() paths, it will use vma->vm_private_data = &area->xol_mapping freed by uprobe_clear_state(). Link: https://lkml.kernel.org/r/20240911131407.GB3448@redhat.com Fixes: 223febc ("mm: add optional close() to struct vm_special_mapping") Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reported-by: Sven Schnelle <svens@linux.ibm.com> Closes: https://lore.kernel.org/all/yt9dy149vprr.fsf@linux.ibm.com/ Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent ed8d5b0 commit 6d27a31

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

kernel/events/uprobes.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ struct xol_area {
9999
atomic_t slot_count; /* number of in-use slots */
100100
unsigned long *bitmap; /* 0 = free slot */
101101

102-
struct vm_special_mapping xol_mapping;
103102
struct page *pages[2];
104103
/*
105104
* We keep the vma's vm_start rather than a pointer to the vma
@@ -1433,6 +1432,21 @@ void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned lon
14331432
set_bit(MMF_RECALC_UPROBES, &vma->vm_mm->flags);
14341433
}
14351434

1435+
static vm_fault_t xol_fault(const struct vm_special_mapping *sm,
1436+
struct vm_area_struct *vma, struct vm_fault *vmf)
1437+
{
1438+
struct xol_area *area = vma->vm_mm->uprobes_state.xol_area;
1439+
1440+
vmf->page = area->pages[0];
1441+
get_page(vmf->page);
1442+
return 0;
1443+
}
1444+
1445+
static const struct vm_special_mapping xol_mapping = {
1446+
.name = "[uprobes]",
1447+
.fault = xol_fault,
1448+
};
1449+
14361450
/* Slot allocation for XOL */
14371451
static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
14381452
{
@@ -1459,7 +1473,7 @@ static int xol_add_vma(struct mm_struct *mm, struct xol_area *area)
14591473

14601474
vma = _install_special_mapping(mm, area->vaddr, PAGE_SIZE,
14611475
VM_EXEC|VM_MAYEXEC|VM_DONTCOPY|VM_IO,
1462-
&area->xol_mapping);
1476+
&xol_mapping);
14631477
if (IS_ERR(vma)) {
14641478
ret = PTR_ERR(vma);
14651479
goto fail;
@@ -1498,9 +1512,6 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
14981512
if (!area->bitmap)
14991513
goto free_area;
15001514

1501-
area->xol_mapping.name = "[uprobes]";
1502-
area->xol_mapping.fault = NULL;
1503-
area->xol_mapping.pages = area->pages;
15041515
area->pages[0] = alloc_page(GFP_HIGHUSER);
15051516
if (!area->pages[0])
15061517
goto free_bitmap;

0 commit comments

Comments
 (0)