kunit: test: Add vm_mmap() allocation resource manager
For tests that need to allocate using vm_mmap() (e.g. usercopy and execve), provide the interface to have the allocation tracked by KUnit itself. This requires bringing up a placeholder userspace mm. This combines my earlier attempt at this with Mark Rutland's version[1]. Normally alloc_mm() and arch_pick_mmap_layout() aren't exported for modules, so export these only for KUnit testing. Link: https://lore.kernel.org/lkml/20230321122514.1743889-2-mark.rutland@arm.com/ [1] Co-developed-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: David Gow <davidgow@google.com> Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
@@ -480,6 +480,23 @@ static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp
|
||||
return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
* kunit_vm_mmap() - Allocate KUnit-tracked vm_mmap() area
|
||||
* @test: The test context object.
|
||||
* @file: struct file pointer to map from, if any
|
||||
* @addr: desired address, if any
|
||||
* @len: how many bytes to allocate
|
||||
* @prot: mmap PROT_* bits
|
||||
* @flag: mmap flags
|
||||
* @offset: offset into @file to start mapping from.
|
||||
*
|
||||
* See vm_mmap() for more information.
|
||||
*/
|
||||
unsigned long kunit_vm_mmap(struct kunit *test, struct file *file,
|
||||
unsigned long addr, unsigned long len,
|
||||
unsigned long prot, unsigned long flag,
|
||||
unsigned long offset);
|
||||
|
||||
void kunit_cleanup(struct kunit *test);
|
||||
|
||||
void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...);
|
||||
|
||||
Reference in New Issue
Block a user