Skip to content

Commit f87bcc8

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc mm fixes from Andrew Morton: "2 patches. Subsystems affected by this patch series: mm (userfaultfd and damon)" * akpm: mm/damon/dbgfs: fix 'struct pid' leaks in 'dbgfs_target_ids_write()' userfaultfd/selftests: fix hugetlb area allocations
2 parents e46227b + ebb3f99 commit f87bcc8

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

mm/damon/dbgfs.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
353353
const char __user *buf, size_t count, loff_t *ppos)
354354
{
355355
struct damon_ctx *ctx = file->private_data;
356+
struct damon_target *t, *next_t;
356357
bool id_is_pid = true;
357358
char *kbuf, *nrs;
358359
unsigned long *targets;
@@ -397,8 +398,12 @@ static ssize_t dbgfs_target_ids_write(struct file *file,
397398
goto unlock_out;
398399
}
399400

400-
/* remove targets with previously-set primitive */
401-
damon_set_targets(ctx, NULL, 0);
401+
/* remove previously set targets */
402+
damon_for_each_target_safe(t, next_t, ctx) {
403+
if (targetid_is_pid(ctx))
404+
put_pid((struct pid *)t->id);
405+
damon_destroy_target(t);
406+
}
402407

403408
/* Configure the context for the address space type */
404409
if (id_is_pid)

tools/testing/selftests/vm/userfaultfd.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static bool test_uffdio_minor = false;
8787

8888
static bool map_shared;
8989
static int shm_fd;
90-
static int huge_fd;
90+
static int huge_fd = -1; /* only used for hugetlb_shared test */
9191
static char *huge_fd_off0;
9292
static unsigned long long *count_verify;
9393
static int uffd = -1;
@@ -223,6 +223,9 @@ static void noop_alias_mapping(__u64 *start, size_t len, unsigned long offset)
223223

224224
static void hugetlb_release_pages(char *rel_area)
225225
{
226+
if (huge_fd == -1)
227+
return;
228+
226229
if (fallocate(huge_fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
227230
rel_area == huge_fd_off0 ? 0 : nr_pages * page_size,
228231
nr_pages * page_size))
@@ -235,16 +238,17 @@ static void hugetlb_allocate_area(void **alloc_area)
235238
char **alloc_area_alias;
236239

237240
*alloc_area = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
238-
(map_shared ? MAP_SHARED : MAP_PRIVATE) |
239-
MAP_HUGETLB,
240-
huge_fd, *alloc_area == area_src ? 0 :
241-
nr_pages * page_size);
241+
map_shared ? MAP_SHARED :
242+
MAP_PRIVATE | MAP_HUGETLB |
243+
(*alloc_area == area_src ? 0 : MAP_NORESERVE),
244+
huge_fd,
245+
*alloc_area == area_src ? 0 : nr_pages * page_size);
242246
if (*alloc_area == MAP_FAILED)
243247
err("mmap of hugetlbfs file failed");
244248

245249
if (map_shared) {
246250
area_alias = mmap(NULL, nr_pages * page_size, PROT_READ | PROT_WRITE,
247-
MAP_SHARED | MAP_HUGETLB,
251+
MAP_SHARED,
248252
huge_fd, *alloc_area == area_src ? 0 :
249253
nr_pages * page_size);
250254
if (area_alias == MAP_FAILED)

0 commit comments

Comments
 (0)