Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit: test: Export kunit_attach_mm()

Tests can allocate from virtual memory using kunit_vm_mmap(), which
transparently creates and attaches an mm_struct to the test runner if
one is not already attached. This is suitable for most cases, except for
when the code under test must access a task's mm before performing an
mmap. Expose kunit_attach_mm() as part of the interface for those
cases. This does not change the existing behavior.

Cc: David Gow <davidgow@google.com>
Signed-off-by: Tiffany Yang <ynaffit@google.com>
Reviewed-by: Carlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20250714185321.2417234-4-ynaffit@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tiffany Yang and committed by
Greg Kroah-Hartman
bdfa89c4 4328a526

+14 -2
+12
include/kunit/test.h
··· 532 532 const char *kunit_kstrdup_const(struct kunit *test, const char *str, gfp_t gfp); 533 533 534 534 /** 535 + * kunit_attach_mm() - Create and attach a new mm if it doesn't already exist. 536 + * 537 + * Allocates a &struct mm_struct and attaches it to @current. In most cases, call 538 + * kunit_vm_mmap() without calling kunit_attach_mm() directly. Only necessary when 539 + * code under test accesses the mm before executing the mmap (e.g., to perform 540 + * additional initialization beforehand). 541 + * 542 + * Return: 0 on success, -errno on failure. 543 + */ 544 + int kunit_attach_mm(void); 545 + 546 + /** 535 547 * kunit_vm_mmap() - Allocate KUnit-tracked vm_mmap() area 536 548 * @test: The test context object. 537 549 * @file: struct file pointer to map from, if any
+2 -2
lib/kunit/user_alloc.c
··· 22 22 unsigned long offset; 23 23 }; 24 24 25 - /* Create and attach a new mm if it doesn't already exist. */ 26 - static int kunit_attach_mm(void) 25 + int kunit_attach_mm(void) 27 26 { 28 27 struct mm_struct *mm; 29 28 ··· 48 49 49 50 return 0; 50 51 } 52 + EXPORT_SYMBOL_GPL(kunit_attach_mm); 51 53 52 54 static int kunit_vm_mmap_init(struct kunit_resource *res, void *context) 53 55 {