Skip to content

Commit 921df80

Browse files
committed
Merge: Update MM Selftests for 9.5
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/4786 Update kselftests mm to include new tests and fixes. This update is larger than usual, due to having to backport a lot of build related changes in `tools/testing/selftests/kselftest*` Omitted-fix: f1227dc Omitted-fix: a525405 Omitted-fix: 2bfed7d JIRA: https://issues.redhat.com/browse/RHEL-39306 Signed-off-by: Nico Pache <npache@redhat.com> Approved-by: Marcelo Ricardo Leitner <mleitner@redhat.com> Approved-by: Chris von Recklinghausen <crecklin@redhat.com> Approved-by: Jan Stancek <jstancek@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 332e9f3 + 303ddb6 commit 921df80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5732
-2956
lines changed

Documentation/admin-guide/mm/userfaultfd.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ newer kernels, one can also detect the feature UFFD_FEATURE_WP_UNPOPULATED
238238
and set the feature bit in advance to make sure none ptes will also be
239239
write protected even upon anonymous memory.
240240

241+
When using ``UFFDIO_REGISTER_MODE_WP`` in combination with either
242+
``UFFDIO_REGISTER_MODE_MISSING`` or ``UFFDIO_REGISTER_MODE_MINOR``, when
243+
resolving missing / minor faults with ``UFFDIO_COPY`` or ``UFFDIO_CONTINUE``
244+
respectively, it may be desirable for the new page / mapping to be
245+
write-protected (so future writes will also result in a WP fault). These ioctls
246+
support a mode flag (``UFFDIO_COPY_MODE_WP`` or ``UFFDIO_CONTINUE_MODE_WP``
247+
respectively) to configure the mapping this way.
248+
241249
QEMU/KVM
242250
========
243251

Documentation/dev-tools/kselftest.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ assist writing kernel modules that are for use with kselftest:
265265
- ``tools/testing/selftests/kselftest_module.h``
266266
- ``tools/testing/selftests/kselftest/module.sh``
267267

268+
Note that test modules should taint the kernel with TAINT_TEST. This will
269+
happen automatically for modules which are in the ``tools/testing/``
270+
directory, or for modules which use the ``kselftest_module.h`` header above.
271+
Otherwise, you'll need to add ``MODULE_INFO(test, "Y")`` to your module
272+
source. selftests which do not load modules typically should not taint the
273+
kernel, but in cases where a non-test module is loaded, TEST_TAINT can be
274+
applied from userspace by writing to ``/proc/sys/kernel/tainted``.
275+
268276
How to use
269277
----------
270278

@@ -323,6 +331,7 @@ A bare bones test module might look like this:
323331
KSTM_MODULE_LOADERS(test_foo);
324332
MODULE_AUTHOR("John Developer <jd@fooman.org>");
325333
MODULE_LICENSE("GPL");
334+
MODULE_INFO(test, "Y");
326335
327336
Example test script
328337
-------------------

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14439,6 +14439,7 @@ F: Documentation/ABI/testing/sysfs-firmware-ofw
1443914439
F: drivers/of/
1444014440
F: include/linux/of*.h
1444114441
F: scripts/dtc/
14442+
F: tools/testing/selftests/dt/
1444214443

1444314444
OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS
1444414445
M: Rob Herring <robh+dt@kernel.org>

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,10 +1440,10 @@ tools/%: FORCE
14401440
# Kernel selftest
14411441

14421442
PHONY += kselftest
1443-
kselftest:
1443+
kselftest: headers_install
14441444
$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
14451445

1446-
kselftest-%: FORCE
1446+
kselftest-%: headers_install FORCE
14471447
$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
14481448

14491449
PHONY += kselftest-merge

fs/hugetlbfs/inode.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
239239
unsigned long flags)
240240
{
241241
struct mm_struct *mm = current->mm;
242-
struct vm_area_struct *vma;
242+
struct vm_area_struct *vma, *prev;
243243
struct hstate *h = hstate_file(file);
244244
const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
245245

246246
if (len & ~huge_page_mask(h))
247247
return -EINVAL;
248-
if (len > TASK_SIZE)
248+
if (len > mmap_end - mmap_min_addr)
249249
return -ENOMEM;
250250

251251
if (flags & MAP_FIXED) {
@@ -256,9 +256,10 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
256256

257257
if (addr) {
258258
addr = ALIGN(addr, huge_page_size(h));
259-
vma = find_vma(mm, addr);
260-
if (mmap_end - len >= addr &&
261-
(!vma || addr + len <= vm_start_gap(vma)))
259+
vma = find_vma_prev(mm, addr, &prev);
260+
if (mmap_end - len >= addr && addr >= mmap_min_addr &&
261+
(!vma || addr + len <= vm_start_gap(vma)) &&
262+
(!prev || addr >= vm_end_gap(prev)))
262263
return addr;
263264
}
264265

fs/userfaultfd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,7 @@ static int userfaultfd_continue(struct userfaultfd_ctx *ctx, unsigned long arg)
19001900
struct uffdio_continue uffdio_continue;
19011901
struct uffdio_continue __user *user_uffdio_continue;
19021902
struct userfaultfd_wake_range range;
1903+
uffd_flags_t flags = 0;
19031904

19041905
user_uffdio_continue = (struct uffdio_continue __user *)arg;
19051906

@@ -1924,13 +1925,16 @@ static int userfaultfd_continue(struct userfaultfd_ctx *ctx, unsigned long arg)
19241925
uffdio_continue.range.start) {
19251926
goto out;
19261927
}
1927-
if (uffdio_continue.mode & ~UFFDIO_CONTINUE_MODE_DONTWAKE)
1928+
if (uffdio_continue.mode & ~(UFFDIO_CONTINUE_MODE_DONTWAKE |
1929+
UFFDIO_CONTINUE_MODE_WP))
19281930
goto out;
1931+
if (uffdio_continue.mode & UFFDIO_CONTINUE_MODE_WP)
1932+
flags |= MFILL_ATOMIC_WP;
19291933

19301934
if (mmget_not_zero(ctx->mm)) {
19311935
ret = mfill_atomic_continue(ctx->mm, uffdio_continue.range.start,
19321936
uffdio_continue.range.len,
1933-
&ctx->mmap_changing);
1937+
&ctx->mmap_changing, flags);
19341938
mmput(ctx->mm);
19351939
} else {
19361940
return -ESRCH;

include/linux/userfaultfd_k.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ extern ssize_t mfill_atomic_zeropage(struct mm_struct *dst_mm,
8383
unsigned long len,
8484
atomic_t *mmap_changing);
8585
extern ssize_t mfill_atomic_continue(struct mm_struct *dst_mm, unsigned long dst_start,
86-
unsigned long len, atomic_t *mmap_changing);
86+
unsigned long len, atomic_t *mmap_changing,
87+
uffd_flags_t flags);
8788
extern int mwriteprotect_range(struct mm_struct *dst_mm,
8889
unsigned long start, unsigned long len,
8990
bool enable_wp, atomic_t *mmap_changing);

include/uapi/linux/userfaultfd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ struct uffdio_writeprotect {
305305
struct uffdio_continue {
306306
struct uffdio_range range;
307307
#define UFFDIO_CONTINUE_MODE_DONTWAKE ((__u64)1<<0)
308+
/*
309+
* UFFDIO_CONTINUE_MODE_WP will map the page write protected on
310+
* the fly. UFFDIO_CONTINUE_MODE_WP is available only if the
311+
* write protected ioctl is implemented for the range
312+
* according to the uffdio_register.ioctls.
313+
*/
314+
#define UFFDIO_CONTINUE_MODE_WP ((__u64)1<<1)
308315
__u64 mode;
309316

310317
/*

mm/hugetlb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5688,6 +5688,13 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma,
56885688
/*
56895689
* If no-one else is actually using this page, we're the exclusive
56905690
* owner and can reuse this page.
5691+
*
5692+
* Note that we don't rely on the (safer) folio refcount here, because
5693+
* copying the hugetlb folio when there are unexpected (temporary)
5694+
* folio references could harm simple fork()+exit() users when
5695+
* we run out of free hugetlb folios: we would have to kill processes
5696+
* in scenarios that used to work. As a side effect, there can still
5697+
* be leaks between processes, for example, with FOLL_GET users.
56915698
*/
56925699
if (page_mapcount(old_page) == 1 && PageAnon(old_page)) {
56935700
if (!PageAnonExclusive(old_page))

mm/userfaultfd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,11 @@ ssize_t mfill_atomic_zeropage(struct mm_struct *dst_mm, unsigned long start,
705705
}
706706

707707
ssize_t mfill_atomic_continue(struct mm_struct *dst_mm, unsigned long start,
708-
unsigned long len, atomic_t *mmap_changing)
708+
unsigned long len, atomic_t *mmap_changing,
709+
uffd_flags_t flags)
709710
{
710711
return mfill_atomic(dst_mm, start, 0, len, mmap_changing,
711-
uffd_flags_set_mode(0, MFILL_ATOMIC_CONTINUE));
712+
uffd_flags_set_mode(flags, MFILL_ATOMIC_CONTINUE));
712713
}
713714

714715
long uffd_wp_range(struct vm_area_struct *dst_vma,

0 commit comments

Comments
 (0)