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 'printk-for-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux

Pull printk updates from Petr Mladek:

- Fix printk ring buffer initialization and sanity checks

- Workaround printf kunit test compilation with gcc < 12.1

- Add IPv6 address printf format tests

- Misc code and documentation cleanup

* tag 'printk-for-7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
printf: Compile the kunit test with DISABLE_BRANCH_PROFILING DISABLE_BRANCH_PROFILING
lib/vsprintf: use bool for local decode variable
lib/hexdump: print_hex_dump_bytes() calls print_hex_dump_debug()
printk: ringbuffer: fix errors in comments
printk_ringbuffer: Add sanity check for 0-size data
printk_ringbuffer: Fix get_data() size sanity check
printf: add IPv6 address format tests
printk: Fix _DESCS_COUNT type for 64-bit systems

+46 -18
+3 -2
include/linux/printk.h
··· 815 815 #endif 816 816 817 817 /** 818 - * print_hex_dump_bytes - shorthand form of print_hex_dump() with default params 818 + * print_hex_dump_bytes - shorthand form of print_hex_dump_debug() with default 819 + * params 819 820 * @prefix_str: string to prefix each line with; 820 821 * caller supplies trailing spaces for alignment if desired 821 822 * @prefix_type: controls whether prefix of an offset, address, or none ··· 824 823 * @buf: data blob to dump 825 824 * @len: number of bytes in the @buf 826 825 * 827 - * Calls print_hex_dump(), with log level of KERN_DEBUG, 826 + * Calls print_hex_dump_debug(), with log level of KERN_DEBUG, 828 827 * rowsize of 16, groupsize of 1, and ASCII output included. 829 828 */ 830 829 #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
+15 -12
kernel/printk/printk_ringbuffer.c
··· 14 14 * 15 15 * Data Structure 16 16 * -------------- 17 - * The printk_ringbuffer is made up of 3 internal ringbuffers: 17 + * The printk_ringbuffer is made up of 2 internal ringbuffers: 18 18 * 19 19 * desc_ring 20 20 * A ring of descriptors and their meta data (such as sequence number, ··· 224 224 * 225 225 * prb_rec_init_rd(&r, &info, &text_buf[0], sizeof(text_buf)); 226 226 * 227 - * prb_for_each_record(0, &test_rb, &seq, &r) { 227 + * prb_for_each_record(0, &test_rb, seq, &r) { 228 228 * if (info.seq != seq) 229 229 * pr_warn("lost %llu records\n", info.seq - seq); 230 230 * ··· 1302 1302 return NULL; 1303 1303 } 1304 1304 1305 - /* Sanity check. Data-less blocks were handled earlier. */ 1306 - if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size) || !*data_size)) 1307 - return NULL; 1308 - 1309 1305 /* A valid data block will always be aligned to the ID size. */ 1310 1306 if (WARN_ON_ONCE(blk_lpos->begin != ALIGN(blk_lpos->begin, sizeof(db->id))) || 1311 1307 WARN_ON_ONCE(blk_lpos->next != ALIGN(blk_lpos->next, sizeof(db->id)))) { 1312 1308 return NULL; 1313 1309 } 1314 1310 1315 - /* A valid data block will always have at least an ID. */ 1316 - if (WARN_ON_ONCE(*data_size < sizeof(db->id))) 1311 + /* 1312 + * A regular data block will always have an ID and at least 1313 + * 1 byte of data. Data-less blocks were handled earlier. 1314 + */ 1315 + if (WARN_ON_ONCE(*data_size <= sizeof(db->id))) 1317 1316 return NULL; 1318 1317 1319 1318 /* Subtract block ID space from size to reflect data size. */ 1320 1319 *data_size -= sizeof(db->id); 1320 + 1321 + /* Sanity check the max size of the regular data block. */ 1322 + if (WARN_ON_ONCE(!data_check_size(data_ring, *data_size))) 1323 + return NULL; 1321 1324 1322 1325 return &db->data[0]; 1323 1326 } ··· 1368 1365 * 1369 1366 * WMB from _prb_commit:A to _prb_commit:B 1370 1367 * matching 1371 - * MB If desc_reopen_last:A to prb_reserve_in_last:A 1368 + * MB from desc_reopen_last:A to prb_reserve_in_last:A 1372 1369 */ 1373 1370 if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val, 1374 1371 DESC_SV(id, desc_reserved))) { /* LMM(desc_reopen_last:A) */ ··· 1773 1770 * 1774 1771 * Relies on: 1775 1772 * 1776 - * MB _prb_commit:B to prb_commit:A 1773 + * MB from _prb_commit:B to prb_commit:A 1777 1774 * matching 1778 - * MB desc_reserve:D to desc_make_final:A 1775 + * MB from desc_reserve:D to desc_make_final:A 1779 1776 */ 1780 1777 if (!atomic_long_try_cmpxchg(&d->state_var, &prev_state_val, 1781 1778 DESC_SV(e->id, state_val))) { /* LMM(_prb_commit:B) */ ··· 2038 2035 * 2039 2036 * MB from desc_push_tail:B to desc_reserve:F 2040 2037 * matching 2041 - * RMB prb_first_seq:B to prb_first_seq:A 2038 + * RMB from prb_first_seq:B to prb_first_seq:A 2042 2039 */ 2043 2040 smp_rmb(); /* LMM(prb_first_seq:C) */ 2044 2041 }
+2 -2
kernel/printk/printk_ringbuffer.h
··· 127 127 }; 128 128 129 129 #define _DATA_SIZE(sz_bits) (1UL << (sz_bits)) 130 - #define _DESCS_COUNT(ct_bits) (1U << (ct_bits)) 130 + #define _DESCS_COUNT(ct_bits) (1UL << (ct_bits)) 131 131 #define DESC_SV_BITS BITS_PER_LONG 132 132 #define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2) 133 133 #define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT) ··· 388 388 * 389 389 * This is a macro for conveniently iterating over a ringbuffer. 390 390 * Note that @s may not be the sequence number of the record on each 391 - * iteration. For the sequence number, @r->info->seq should be checked. 391 + * iteration. For the sequence number, @i->seq should be checked. 392 392 * 393 393 * Context: Any context. 394 394 */
+2
lib/tests/Makefile
··· 40 40 obj-$(CONFIG_MIN_HEAP_KUNIT_TEST) += min_heap_kunit.o 41 41 CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare) 42 42 obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o 43 + # GCC < 12.1 can miscompile errptr() test when branch profiling is enabled. 44 + CFLAGS_printf_kunit.o += -DDISABLE_BRANCH_PROFILING 43 45 obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o 44 46 obj-$(CONFIG_RANDSTRUCT_KUNIT_TEST) += randstruct_kunit.o 45 47 obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
+22
lib/tests/printf_kunit.c
··· 17 17 #include <linux/dcache.h> 18 18 #include <linux/socket.h> 19 19 #include <linux/in.h> 20 + #include <linux/in6.h> 20 21 21 22 #include <linux/gfp.h> 22 23 #include <linux/mm.h> ··· 438 437 static void 439 438 ip6(struct kunit *kunittest) 440 439 { 440 + const struct in6_addr addr = { 441 + .s6_addr = { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 442 + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 } 443 + }; 444 + const struct in6_addr single_zero = { 445 + .s6_addr = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 446 + 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 } 447 + }; 448 + struct sockaddr_in6 sa = { 449 + .sin6_family = AF_INET6, 450 + .sin6_port = cpu_to_be16(12345), 451 + .sin6_addr = addr, 452 + }; 453 + 454 + test("00010002000300040005000600070008|0001:0002:0003:0004:0005:0006:0007:0008", 455 + "%pi6|%pI6", &addr, &addr); 456 + test("00010002000300040005000600070008|0001:0002:0003:0004:0005:0006:0007:0008", 457 + "%piS|%pIS", &sa, &sa); 458 + test("1:2:3:4:5:6:7:8", "%pI6c", &addr); 459 + test("1:0:3:4:5:6:7:8", "%pI6c", &single_zero); 460 + test("[1:2:3:4:5:6:7:8]:12345", "%pISpc", &sa); 441 461 } 442 462 443 463 static void
+2 -2
lib/vsprintf.c
··· 1107 1107 2*RSRC_BUF_SIZE + FLAG_BUF_SIZE + RAW_BUF_SIZE)]; 1108 1108 1109 1109 char *p = sym, *pend = sym + sizeof(sym); 1110 - int decode = (fmt[0] == 'R') ? 1 : 0; 1110 + bool decode = fmt[0] == 'R'; 1111 1111 const struct printf_spec *specp; 1112 1112 1113 1113 if (check_pointer(&buf, end, res, spec)) ··· 1132 1132 } else { 1133 1133 p = string_nocheck(p, pend, "??? ", str_spec); 1134 1134 specp = &mem_spec; 1135 - decode = 0; 1135 + decode = false; 1136 1136 } 1137 1137 if (decode && res->flags & IORESOURCE_UNSET) { 1138 1138 p = string_nocheck(p, pend, "size ", str_spec);