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.

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

+28 -9
+28 -9
lib/test_user_copy.c
··· 47 47 static int test_check_nonzero_user(char *kmem, char __user *umem, size_t size) 48 48 { 49 49 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; 53 54 54 55 /* 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): 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; 69 + 70 + /* 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): 58 74 * 59 75 * [ 00 ff 00 ff ... 00 00 00 00 ... ff 00 ff 00 ] 60 76 * 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(). 62 79 */ 63 80 64 81 memset(kmem, 0x0, size); ··· 110 93 size_t ksize, usize; 111 94 112 95 umem_src = kmalloc(size, GFP_KERNEL); 113 - if ((ret |= test(umem_src == NULL, "kmalloc failed"))) 96 + ret = test(umem_src == NULL, "kmalloc failed"); 97 + if (ret) 114 98 goto out_free; 115 99 116 100 expected = kmalloc(size, GFP_KERNEL); 117 - if ((ret |= test(expected == NULL, "kmalloc failed"))) 101 + ret = test(expected == NULL, "kmalloc failed"); 102 + if (ret) 118 103 goto out_free; 119 104 120 105 /* Fill umem with a fixed byte pattern. */