Skip to content

Commit 7278aa8

Browse files
Christian A. Ehrhardtakpm00
authored andcommitted
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>
1 parent 0b49c7d commit 7278aa8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/tests/kunit_iov_iter.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/uio.h>
1414
#include <linux/bvec.h>
1515
#include <linux/folio_queue.h>
16+
#include <linux/minmax.h>
1617
#include <kunit/test.h>
1718

1819
MODULE_DESCRIPTION("iov_iter testing");
@@ -37,7 +38,7 @@ static const struct kvec_test_range kvec_test_ranges[] = {
3738

3839
static inline u8 pattern(unsigned long x)
3940
{
40-
return x & 0xff;
41+
return (u8)x + (u8)(x >> 8) + (u8)(x >> 16);
4142
}
4243

4344
static void iov_kunit_unmap(void *data)
@@ -52,6 +53,7 @@ static void *__init iov_kunit_create_buffer(struct kunit *test,
5253
struct page **pages;
5354
unsigned long got;
5455
void *buffer;
56+
unsigned int i;
5557

5658
pages = kzalloc_objs(struct page *, npages, GFP_KERNEL);
5759
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pages);
@@ -63,6 +65,9 @@ static void *__init iov_kunit_create_buffer(struct kunit *test,
6365
kvfree(pages);
6466
KUNIT_ASSERT_EQ(test, got, npages);
6567
}
68+
/* Make sure that we don't get a physically contiguous buffer. */
69+
for (i = 0; i < npages / 4; ++i)
70+
swap(pages[i], pages[i + npages / 2]);
6671

6772
buffer = vmap(pages, npages, VM_MAP | VM_MAP_PUT_PAGES, PAGE_KERNEL);
6873
if (buffer == NULL) {

0 commit comments

Comments
 (0)