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.

lib: kunit_iov_iter: improve error detection

In the kunit_iov_iter test prevent the kernel buffer from being a single
physically contiguous region.

Additionally, make sure that the test pattern written to a page in the
buffer depends on the offset of the page within the buffer.

Link: https://lkml.kernel.org/r/20260326214905.818170-5-lk@c--e.de
Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
Cc: David Howells <dhowells@redhat.com>
Cc: David Gow <davidgow@google.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Christian A. Ehrhardt and committed by
Andrew Morton
7278aa84 0b49c7d0

+6 -1
+6 -1
lib/tests/kunit_iov_iter.c
··· 13 13 #include <linux/uio.h> 14 14 #include <linux/bvec.h> 15 15 #include <linux/folio_queue.h> 16 + #include <linux/minmax.h> 16 17 #include <kunit/test.h> 17 18 18 19 MODULE_DESCRIPTION("iov_iter testing"); ··· 38 37 39 38 static inline u8 pattern(unsigned long x) 40 39 { 41 - return x & 0xff; 40 + return (u8)x + (u8)(x >> 8) + (u8)(x >> 16); 42 41 } 43 42 44 43 static void iov_kunit_unmap(void *data) ··· 53 52 struct page **pages; 54 53 unsigned long got; 55 54 void *buffer; 55 + unsigned int i; 56 56 57 57 pages = kzalloc_objs(struct page *, npages, GFP_KERNEL); 58 58 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages); ··· 65 63 kvfree(pages); 66 64 KUNIT_ASSERT_EQ(test, got, npages); 67 65 } 66 + /* Make sure that we don't get a physically contiguous buffer. */ 67 + for (i = 0; i < npages / 4; ++i) 68 + swap(pages[i], pages[i + npages / 2]); 68 69 69 70 buffer = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL); 70 71 if (buffer == NULL) {