Skip to content

Commit 8eb4b3b

Browse files
committed
Merge tag 'copy-struct-from-user-v5.4-rc4' of gitolite.kernel.org:pub/scm/linux/kernel/git/brauner/linux
Pull usercopy test fixlets from Christian Brauner: "This contains two improvements for the copy_struct_from_user() tests: - a coding style change to get rid of the ugly "if ((ret |= test()))" pointed out when pulling the original patchset. - avoid a soft lockups when running the usercopy tests on machines with large page sizes by scanning only a 1024 byte region" * tag 'copy-struct-from-user-v5.4-rc4' of gitolite.kernel.org:pub/scm/linux/kernel/git/brauner/linux: usercopy: Avoid soft lockups in test_check_nonzero_user() lib: test_user_copy: style cleanup
2 parents 7571438 + f418ddd commit 8eb4b3b

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

lib/test_user_copy.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,35 @@ static bool is_zeroed(void *from, size_t size)
4747
static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size)
4848
{
4949
int ret = 0;
50-
size_t start, end, i;
51-
size_t zero_start = size / 4;
52-
size_t zero_end = size - zero_start;
50+
size_t start, end, i, zero_start, zero_end;
51+
52+
if (test(size < 2 * PAGE_SIZE, "buffer too small"))
53+
return -EINVAL;
54+
55+
/*
56+
* We want to cross a page boundary to exercise the code more
57+
* effectively. We also don't want to make the size we scan too large,
58+
* otherwise the test can take a long time and cause soft lockups. So
59+
* scan a 1024 byte region across the page boundary.
60+
*/
61+
size = 1024;
62+
start = PAGE_SIZE - (size / 2);
63+
64+
kmem += start;
65+
umem += start;
66+
67+
zero_start = size / 4;
68+
zero_end = size - zero_start;
5369

5470
/*
55-
* We conduct a series of check_nonzero_user() tests on a block of memory
56-
* with the following byte-pattern (trying every possible [start,end]
57-
* pair):
71+
* We conduct a series of check_nonzero_user() tests on a block of
72+
* memory with the following byte-pattern (trying every possible
73+
* [start,end] pair):
5874
*
5975
* [ 00 ff 00 ff ... 00 00 00 00 ... ff 00 ff 00 ]
6076
*
61-
* And we verify that check_nonzero_user() acts identically to memchr_inv().
77+
* And we verify that check_nonzero_user() acts identically to
78+
* memchr_inv().
6279
*/
6380

6481
memset(kmem, 0x0, size);
@@ -93,11 +110,13 @@ static int test_copy_struct_from_user(char *kmem, char __user *umem,
93110
size_t ksize, usize;
94111

95112
umem_src = kmalloc(size, GFP_KERNEL);
96-
if ((ret |= test(umem_src == NULL, "kmalloc failed")))
113+
ret = test(umem_src == NULL, "kmalloc failed");
114+
if (ret)
97115
goto out_free;
98116

99117
expected = kmalloc(size, GFP_KERNEL);
100-
if ((ret |= test(expected == NULL, "kmalloc failed")))
118+
ret = test(expected == NULL, "kmalloc failed");
119+
if (ret)
101120
goto out_free;
102121

103122
/* Fill umem with a fixed byte pattern. */

0 commit comments

Comments
 (0)