Skip to content

Commit efe99fa

Browse files
Pu Lehuiakpm00
authored andcommitted
selftests/mm: add test about uprobe pte be orphan during vma merge
Add test about uprobe pte be orphan during vma merge. [akpm@linux-foundation.org: include sys/syscall.h, per Lorenzo] Link: https://lkml.kernel.org/r/20250529155650.4017699-5-pulehui@huaweicloud.com Signed-off-by: Pu Lehui <pulehui@huawei.com> Cc: Jann Horn <jannh@google.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 6fb6223 commit efe99fa

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tools/testing/selftests/mm/merge.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
#define _GNU_SOURCE
44
#include "../kselftest_harness.h"
5+
#include <fcntl.h>
56
#include <stdio.h>
67
#include <stdlib.h>
78
#include <unistd.h>
89
#include <sys/mman.h>
10+
#include <sys/syscall.h>
911
#include <sys/wait.h>
12+
#include <linux/perf_event.h>
1013
#include "vm_util.h"
1114

1215
FIXTURE(merge)
@@ -452,4 +455,44 @@ TEST_F(merge, forked_source_vma)
452455
ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr2 + 5 * page_size);
453456
}
454457

458+
TEST_F(merge, handle_uprobe_upon_merged_vma)
459+
{
460+
const size_t attr_sz = sizeof(struct perf_event_attr);
461+
unsigned int page_size = self->page_size;
462+
const char *probe_file = "./foo";
463+
char *carveout = self->carveout;
464+
struct perf_event_attr attr;
465+
unsigned long type;
466+
void *ptr1, *ptr2;
467+
int fd;
468+
469+
fd = open(probe_file, O_RDWR|O_CREAT, 0600);
470+
ASSERT_GE(fd, 0);
471+
472+
ASSERT_EQ(ftruncate(fd, page_size), 0);
473+
ASSERT_EQ(read_sysfs("/sys/bus/event_source/devices/uprobe/type", &type), 0);
474+
475+
memset(&attr, 0, attr_sz);
476+
attr.size = attr_sz;
477+
attr.type = type;
478+
attr.config1 = (__u64)(long)probe_file;
479+
attr.config2 = 0x0;
480+
481+
ASSERT_GE(syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0), 0);
482+
483+
ptr1 = mmap(&carveout[page_size], 10 * page_size, PROT_EXEC,
484+
MAP_PRIVATE | MAP_FIXED, fd, 0);
485+
ASSERT_NE(ptr1, MAP_FAILED);
486+
487+
ptr2 = mremap(ptr1, page_size, 2 * page_size,
488+
MREMAP_MAYMOVE | MREMAP_FIXED, ptr1 + 5 * page_size);
489+
ASSERT_NE(ptr2, MAP_FAILED);
490+
491+
ASSERT_NE(mremap(ptr2, page_size, page_size,
492+
MREMAP_MAYMOVE | MREMAP_FIXED, ptr1), MAP_FAILED);
493+
494+
close(fd);
495+
remove(probe_file);
496+
}
497+
455498
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)