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 'bitmap-for-6.20' of https://github.com/norov/linux

Pull bitmap updates from Yury Norov:

- more rust helpers (Alice)

- more bitops tests (Ryota)

- FIND_NTH_BIT() uninitialized variable fix (Lee Yongjun)

- random cleanups (Andy, H. Peter)

* tag 'bitmap-for-6.20' of https://github.com/norov/linux:
lib/tests: extend KUnit test for bitops with more cases
bitops: Add more files to the MAINTAINERS
lib/find_bit: fix uninitialized variable use in FIND_NTH_BIT
lib/tests: add KUnit test for bitops
rust: cpumask: add __rust_helper to helpers
rust: bitops: add __rust_helper to helpers
rust: bitmap: add __rust_helper to helpers
linux/bitfield.h: replace __auto_type with auto

+243 -3
+2
MAINTAINERS
··· 4472 4472 F: include/asm-generic/bitops 4473 4473 F: include/asm-generic/bitops.h 4474 4474 F: include/linux/bitops.h 4475 + F: include/linux/count_zeros.h 4475 4476 F: lib/hweight.c 4476 4477 F: lib/test_bitops.c 4478 + F: lib/tests/bitops_kunit.c 4477 4479 F: tools/*/bitops* 4478 4480 4479 4481 BITOPS API BINDINGS [RUST]
+3 -2
include/linux/bitfield.h
··· 8 8 #define _LINUX_BITFIELD_H 9 9 10 10 #include <linux/build_bug.h> 11 + #include <linux/compiler.h> 11 12 #include <linux/typecheck.h> 12 13 #include <asm/byteorder.h> 13 14 ··· 244 243 245 244 #define __field_prep(mask, val) \ 246 245 ({ \ 247 - __auto_type __mask = (mask); \ 246 + auto __mask = (mask); \ 248 247 typeof(__mask) __val = (val); \ 249 248 unsigned int __shift = BITS_PER_TYPE(__mask) <= 32 ? \ 250 249 __ffs(__mask) : __ffs64(__mask); \ ··· 253 252 254 253 #define __field_get(mask, reg) \ 255 254 ({ \ 256 - __auto_type __mask = (mask); \ 255 + auto __mask = (mask); \ 257 256 typeof(__mask) __reg = (reg); \ 258 257 unsigned int __shift = BITS_PER_TYPE(__mask) <= 32 ? \ 259 258 __ffs(__mask) : __ffs64(__mask); \
+13
lib/Kconfig.debug
··· 2647 2647 2648 2648 If unsure, say N. 2649 2649 2650 + config BITOPS_KUNIT 2651 + tristate "KUnit test for bitops" if !KUNIT_ALL_TESTS 2652 + depends on KUNIT 2653 + default KUNIT_ALL_TESTS 2654 + help 2655 + This option enables the KUnit test for the bitops library 2656 + which provides functions for bit operations. 2657 + 2658 + Note that this is derived from the original test_bitops module. 2659 + For micro-benchmarks and compiler warning checks, enable TEST_BITOPS. 2660 + 2661 + If unsure, say N. 2662 + 2650 2663 config BITFIELD_KUNIT 2651 2664 tristate "KUnit test bitfield functions at runtime" if !KUNIT_ALL_TESTS 2652 2665 depends on KUNIT
+1 -1
lib/find_bit.c
··· 71 71 72 72 #define FIND_NTH_BIT(FETCH, size, num) \ 73 73 ({ \ 74 - unsigned long sz = (size), nr = (num), idx, w, tmp; \ 74 + unsigned long sz = (size), nr = (num), idx, w, tmp = 0; \ 75 75 \ 76 76 for (idx = 0; (idx + 1) * BITS_PER_LONG <= sz; idx++) { \ 77 77 if (idx * BITS_PER_LONG + nr >= sz) \
+1
lib/tests/Makefile
··· 5 5 # KUnit tests 6 6 CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN) 7 7 obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o 8 + obj-$(CONFIG_BITOPS_KUNIT) += bitops_kunit.o 8 9 obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o 9 10 obj-$(CONFIG_BITS_TEST) += test_bits.o 10 11 obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
+205
lib/tests/bitops_kunit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2020 Intel Corporation 4 + * Copyright (C) 2026 Ryota Sakamoto <sakamo.ryota@gmail.com> 5 + */ 6 + 7 + #include <linux/bitops.h> 8 + #include <linux/module.h> 9 + #include <kunit/test.h> 10 + 11 + /* use an enum because that's the most common BITMAP usage */ 12 + enum bitops_fun { 13 + BITOPS_4 = 4, 14 + BITOPS_7 = 7, 15 + BITOPS_11 = 11, 16 + BITOPS_31 = 31, 17 + BITOPS_88 = 88, 18 + BITOPS_LENGTH = 256 19 + }; 20 + 21 + struct bitops_test_case { 22 + const char *str; 23 + const long nr; 24 + }; 25 + 26 + static struct bitops_test_case bitops_cases[] = { 27 + { 28 + .str = "BITOPS_4", 29 + .nr = BITOPS_4, 30 + }, 31 + { 32 + .str = "BITOPS_7", 33 + .nr = BITOPS_7, 34 + }, 35 + { 36 + .str = "BITOPS_11", 37 + .nr = BITOPS_11, 38 + }, 39 + { 40 + .str = "BITOPS_31", 41 + .nr = BITOPS_31, 42 + }, 43 + { 44 + .str = "BITOPS_88", 45 + .nr = BITOPS_88, 46 + }, 47 + }; 48 + 49 + KUNIT_ARRAY_PARAM_DESC(bitops, bitops_cases, str); 50 + 51 + static void test_set_bit_clear_bit(struct kunit *test) 52 + { 53 + const struct bitops_test_case *params = test->param_value; 54 + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); 55 + int bit_set; 56 + 57 + bitmap_zero(bitmap, BITOPS_LENGTH); 58 + 59 + set_bit(params->nr, bitmap); 60 + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); 61 + 62 + clear_bit(params->nr, bitmap); 63 + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); 64 + 65 + bit_set = find_first_bit(bitmap, BITOPS_LENGTH); 66 + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); 67 + } 68 + 69 + static void test_change_bit(struct kunit *test) 70 + { 71 + const struct bitops_test_case *params = test->param_value; 72 + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); 73 + int bit_set; 74 + 75 + bitmap_zero(bitmap, BITOPS_LENGTH); 76 + 77 + change_bit(params->nr, bitmap); 78 + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); 79 + 80 + change_bit(params->nr, bitmap); 81 + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); 82 + 83 + bit_set = find_first_bit(bitmap, BITOPS_LENGTH); 84 + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); 85 + } 86 + 87 + static void test_test_and_set_bit_test_and_clear_bit(struct kunit *test) 88 + { 89 + const struct bitops_test_case *params = test->param_value; 90 + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); 91 + int bit_set; 92 + 93 + bitmap_zero(bitmap, BITOPS_LENGTH); 94 + 95 + KUNIT_EXPECT_FALSE(test, test_and_set_bit(params->nr, bitmap)); 96 + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); 97 + 98 + KUNIT_EXPECT_TRUE(test, test_and_set_bit(params->nr, bitmap)); 99 + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); 100 + 101 + KUNIT_EXPECT_TRUE(test, test_and_clear_bit(params->nr, bitmap)); 102 + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); 103 + 104 + KUNIT_EXPECT_FALSE(test, test_and_clear_bit(params->nr, bitmap)); 105 + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); 106 + 107 + bit_set = find_first_bit(bitmap, BITOPS_LENGTH); 108 + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); 109 + } 110 + 111 + static void test_test_and_change_bit(struct kunit *test) 112 + { 113 + const struct bitops_test_case *params = test->param_value; 114 + DECLARE_BITMAP(bitmap, BITOPS_LENGTH); 115 + int bit_set; 116 + 117 + bitmap_zero(bitmap, BITOPS_LENGTH); 118 + 119 + KUNIT_EXPECT_FALSE(test, test_and_change_bit(params->nr, bitmap)); 120 + KUNIT_EXPECT_TRUE(test, test_bit(params->nr, bitmap)); 121 + 122 + KUNIT_EXPECT_TRUE(test, test_and_change_bit(params->nr, bitmap)); 123 + KUNIT_EXPECT_FALSE(test, test_bit(params->nr, bitmap)); 124 + 125 + bit_set = find_first_bit(bitmap, BITOPS_LENGTH); 126 + KUNIT_EXPECT_EQ(test, bit_set, BITOPS_LENGTH); 127 + } 128 + 129 + struct order_test_case { 130 + const char *str; 131 + const unsigned int count; 132 + const int expected; 133 + }; 134 + 135 + static struct order_test_case order_test_cases[] = { 136 + {"0x00000003", 0x00000003, 2}, 137 + {"0x00000004", 0x00000004, 2}, 138 + {"0x00001fff", 0x00001fff, 13}, 139 + {"0x00002000", 0x00002000, 13}, 140 + {"0x50000000", 0x50000000, 31}, 141 + {"0x80000000", 0x80000000, 31}, 142 + {"0x80003000", 0x80003000, 32}, 143 + }; 144 + 145 + KUNIT_ARRAY_PARAM_DESC(order, order_test_cases, str); 146 + 147 + static void test_get_count_order(struct kunit *test) 148 + { 149 + const struct order_test_case *params = test->param_value; 150 + 151 + KUNIT_EXPECT_EQ(test, get_count_order(params->count), params->expected); 152 + KUNIT_EXPECT_EQ(test, get_count_order_long(params->count), params->expected); 153 + } 154 + 155 + #ifdef CONFIG_64BIT 156 + struct order_long_test_case { 157 + const char *str; 158 + const unsigned long count; 159 + const int expected; 160 + }; 161 + 162 + static struct order_long_test_case order_long_test_cases[] = { 163 + {"0x0000000300000000", 0x0000000300000000, 34}, 164 + {"0x0000000400000000", 0x0000000400000000, 34}, 165 + {"0x00001fff00000000", 0x00001fff00000000, 45}, 166 + {"0x0000200000000000", 0x0000200000000000, 45}, 167 + {"0x5000000000000000", 0x5000000000000000, 63}, 168 + {"0x8000000000000000", 0x8000000000000000, 63}, 169 + {"0x8000300000000000", 0x8000300000000000, 64}, 170 + }; 171 + 172 + KUNIT_ARRAY_PARAM_DESC(order_long, order_long_test_cases, str); 173 + 174 + static void test_get_count_order_long(struct kunit *test) 175 + { 176 + const struct order_long_test_case *params = test->param_value; 177 + 178 + KUNIT_EXPECT_EQ(test, get_count_order_long(params->count), params->expected); 179 + } 180 + #endif 181 + 182 + static struct kunit_case bitops_test_cases[] = { 183 + KUNIT_CASE_PARAM(test_set_bit_clear_bit, bitops_gen_params), 184 + KUNIT_CASE_PARAM(test_change_bit, bitops_gen_params), 185 + KUNIT_CASE_PARAM(test_test_and_set_bit_test_and_clear_bit, bitops_gen_params), 186 + KUNIT_CASE_PARAM(test_test_and_change_bit, bitops_gen_params), 187 + KUNIT_CASE_PARAM(test_get_count_order, order_gen_params), 188 + #ifdef CONFIG_64BIT 189 + KUNIT_CASE_PARAM(test_get_count_order_long, order_long_gen_params), 190 + #endif 191 + {}, 192 + }; 193 + 194 + static struct kunit_suite bitops_test_suite = { 195 + .name = "bitops", 196 + .test_cases = bitops_test_cases, 197 + }; 198 + 199 + kunit_test_suite(bitops_test_suite); 200 + 201 + MODULE_AUTHOR("Jesse Brandeburg <jesse.brandeburg@intel.com>"); 202 + MODULE_AUTHOR("Wei Yang <richard.weiyang@gmail.com>"); 203 + MODULE_AUTHOR("Ryota Sakamoto <sakamo.ryota@gmail.com>"); 204 + MODULE_LICENSE("GPL"); 205 + MODULE_DESCRIPTION("Bit testing module");
+1
rust/helpers/bitmap.c
··· 2 2 3 3 #include <linux/bitmap.h> 4 4 5 + __rust_helper 5 6 void rust_helper_bitmap_copy_and_extend(unsigned long *to, const unsigned long *from, 6 7 unsigned int count, unsigned int size) 7 8 {
+4
rust/helpers/bitops.c
··· 3 3 #include <linux/bitops.h> 4 4 #include <linux/find.h> 5 5 6 + __rust_helper 6 7 void rust_helper___set_bit(unsigned long nr, unsigned long *addr) 7 8 { 8 9 __set_bit(nr, addr); 9 10 } 10 11 12 + __rust_helper 11 13 void rust_helper___clear_bit(unsigned long nr, unsigned long *addr) 12 14 { 13 15 __clear_bit(nr, addr); 14 16 } 15 17 18 + __rust_helper 16 19 void rust_helper_set_bit(unsigned long nr, volatile unsigned long *addr) 17 20 { 18 21 set_bit(nr, addr); 19 22 } 20 23 24 + __rust_helper 21 25 void rust_helper_clear_bit(unsigned long nr, volatile unsigned long *addr) 22 26 { 23 27 clear_bit(nr, addr);
+13
rust/helpers/cpumask.c
··· 2 2 3 3 #include <linux/cpumask.h> 4 4 5 + __rust_helper 5 6 void rust_helper_cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp) 6 7 { 7 8 cpumask_set_cpu(cpu, dstp); 8 9 } 9 10 11 + __rust_helper 10 12 void rust_helper___cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp) 11 13 { 12 14 __cpumask_set_cpu(cpu, dstp); 13 15 } 14 16 17 + __rust_helper 15 18 void rust_helper_cpumask_clear_cpu(int cpu, struct cpumask *dstp) 16 19 { 17 20 cpumask_clear_cpu(cpu, dstp); 18 21 } 19 22 23 + __rust_helper 20 24 void rust_helper___cpumask_clear_cpu(int cpu, struct cpumask *dstp) 21 25 { 22 26 __cpumask_clear_cpu(cpu, dstp); 23 27 } 24 28 29 + __rust_helper 25 30 bool rust_helper_cpumask_test_cpu(int cpu, struct cpumask *srcp) 26 31 { 27 32 return cpumask_test_cpu(cpu, srcp); 28 33 } 29 34 35 + __rust_helper 30 36 void rust_helper_cpumask_setall(struct cpumask *dstp) 31 37 { 32 38 cpumask_setall(dstp); 33 39 } 34 40 41 + __rust_helper 35 42 bool rust_helper_cpumask_empty(struct cpumask *srcp) 36 43 { 37 44 return cpumask_empty(srcp); 38 45 } 39 46 47 + __rust_helper 40 48 bool rust_helper_cpumask_full(struct cpumask *srcp) 41 49 { 42 50 return cpumask_full(srcp); 43 51 } 44 52 53 + __rust_helper 45 54 unsigned int rust_helper_cpumask_weight(struct cpumask *srcp) 46 55 { 47 56 return cpumask_weight(srcp); 48 57 } 49 58 59 + __rust_helper 50 60 void rust_helper_cpumask_copy(struct cpumask *dstp, const struct cpumask *srcp) 51 61 { 52 62 cpumask_copy(dstp, srcp); 53 63 } 54 64 65 + __rust_helper 55 66 bool rust_helper_alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 56 67 { 57 68 return alloc_cpumask_var(mask, flags); 58 69 } 59 70 71 + __rust_helper 60 72 bool rust_helper_zalloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) 61 73 { 62 74 return zalloc_cpumask_var(mask, flags); 63 75 } 64 76 65 77 #ifndef CONFIG_CPUMASK_OFFSTACK 78 + __rust_helper 66 79 void rust_helper_free_cpumask_var(cpumask_var_t mask) 67 80 { 68 81 free_cpumask_var(mask);