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 branch 'compiler_types-add-endianness-dependent-__counted_by_-le-be'

Alexander Lobakin says:

====================
compiler_types: add Endianness-dependent __counted_by_{le,be}

Some structures contain flexible arrays at the end and the counter for
them, but the counter has explicit Endianness and thus __counted_by()
can't be used directly.

To increase test coverage for potential problems without breaking
anything, introduce __counted_by_{le,be} defined depending on platform's
Endianness to either __counted_by() when applicable or noop otherwise.
The first user will be virtchnl2.h from idpf just as example with 9 flex
structures having Little Endian counters.

Maybe it would be a good idea to introduce such attributes on compiler
level if possible, but for now let's stop on what we have.
====================

Link: https://lore.kernel.org/r/20240327142241.1745989-1-aleksander.lobakin@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+28 -12
+2
Documentation/conf.py
··· 75 75 "__rcu", 76 76 "__user", 77 77 "__force", 78 + "__counted_by_le", 79 + "__counted_by_be", 78 80 79 81 # include/linux/compiler_attributes.h: 80 82 "__alias",
+2
drivers/net/ethernet/intel/idpf/idpf_txrx.h
··· 8 8 #include <net/tcp.h> 9 9 #include <net/netdev_queues.h> 10 10 11 + #include "virtchnl2_lan_desc.h" 12 + 11 13 #define IDPF_LARGE_MAX_Q 256 12 14 #define IDPF_MAX_Q 16 13 15 #define IDPF_MIN_Q 2
+12 -12
drivers/net/ethernet/intel/idpf/virtchnl2.h
··· 4 4 #ifndef _VIRTCHNL2_H_ 5 5 #define _VIRTCHNL2_H_ 6 6 7 + #include <linux/if_ether.h> 8 + 7 9 /* All opcodes associated with virtchnl2 are prefixed with virtchnl2 or 8 10 * VIRTCHNL2. Any future opcodes, offloads/capabilities, structures, 9 11 * and defines must be prefixed with virtchnl2 or VIRTCHNL2 to avoid confusion. ··· 18 16 * This is an interface definition file where existing enums and their values 19 17 * must remain unchanged over time, so we specify explicit values for all enums. 20 18 */ 21 - 22 - #include "virtchnl2_lan_desc.h" 23 19 24 20 /* This macro is used to generate compilation errors if a structure 25 21 * is not exactly the correct length. ··· 555 555 struct virtchnl2_queue_reg_chunks { 556 556 __le16 num_chunks; 557 557 u8 pad[6]; 558 - struct virtchnl2_queue_reg_chunk chunks[]; 558 + struct virtchnl2_queue_reg_chunk chunks[] __counted_by_le(num_chunks); 559 559 }; 560 560 VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_reg_chunks); 561 561 ··· 703 703 __le32 vport_id; 704 704 __le16 num_qinfo; 705 705 u8 pad[10]; 706 - struct virtchnl2_txq_info qinfo[]; 706 + struct virtchnl2_txq_info qinfo[] __counted_by_le(num_qinfo); 707 707 }; 708 708 VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_config_tx_queues); 709 709 ··· 782 782 __le32 vport_id; 783 783 __le16 num_qinfo; 784 784 u8 pad[18]; 785 - struct virtchnl2_rxq_info qinfo[]; 785 + struct virtchnl2_rxq_info qinfo[] __counted_by_le(num_qinfo); 786 786 }; 787 787 VIRTCHNL2_CHECK_STRUCT_LEN(24, virtchnl2_config_rx_queues); 788 788 ··· 868 868 struct virtchnl2_vector_chunks { 869 869 __le16 num_vchunks; 870 870 u8 pad[14]; 871 - struct virtchnl2_vector_chunk vchunks[]; 871 + struct virtchnl2_vector_chunk vchunks[] __counted_by_le(num_vchunks); 872 872 }; 873 873 VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_vector_chunks); 874 874 ··· 912 912 __le16 lut_entries_start; 913 913 __le16 lut_entries; 914 914 u8 pad[4]; 915 - __le32 lut[]; 915 + __le32 lut[] __counted_by_le(lut_entries); 916 916 }; 917 917 VIRTCHNL2_CHECK_STRUCT_LEN(12, virtchnl2_rss_lut); 918 918 ··· 977 977 u8 ptype_id_8; 978 978 u8 proto_id_count; 979 979 __le16 pad; 980 - __le16 proto_id[]; 980 + __le16 proto_id[] __counted_by(proto_id_count); 981 981 } __packed __aligned(2); 982 982 VIRTCHNL2_CHECK_STRUCT_LEN(6, virtchnl2_ptype); 983 983 ··· 1104 1104 __le32 vport_id; 1105 1105 __le16 key_len; 1106 1106 u8 pad; 1107 - u8 key_flex[]; 1107 + u8 key_flex[] __counted_by_le(key_len); 1108 1108 } __packed; 1109 1109 VIRTCHNL2_CHECK_STRUCT_LEN(7, virtchnl2_rss_key); 1110 1110 ··· 1131 1131 struct virtchnl2_queue_chunks { 1132 1132 __le16 num_chunks; 1133 1133 u8 pad[6]; 1134 - struct virtchnl2_queue_chunk chunks[]; 1134 + struct virtchnl2_queue_chunk chunks[] __counted_by_le(num_chunks); 1135 1135 }; 1136 1136 VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_chunks); 1137 1137 ··· 1195 1195 __le32 vport_id; 1196 1196 __le16 num_qv_maps; 1197 1197 u8 pad[10]; 1198 - struct virtchnl2_queue_vector qv_maps[]; 1198 + struct virtchnl2_queue_vector qv_maps[] __counted_by_le(num_qv_maps); 1199 1199 }; 1200 1200 VIRTCHNL2_CHECK_STRUCT_LEN(16, virtchnl2_queue_vector_maps); 1201 1201 ··· 1247 1247 __le32 vport_id; 1248 1248 __le16 num_mac_addr; 1249 1249 u8 pad[2]; 1250 - struct virtchnl2_mac_addr mac_addr_list[]; 1250 + struct virtchnl2_mac_addr mac_addr_list[] __counted_by_le(num_mac_addr); 1251 1251 }; 1252 1252 VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_mac_addr_list); 1253 1253
+11
include/linux/compiler_types.h
··· 282 282 #define __no_sanitize_or_inline __always_inline 283 283 #endif 284 284 285 + /* 286 + * Apply __counted_by() when the Endianness matches to increase test coverage. 287 + */ 288 + #ifdef __LITTLE_ENDIAN 289 + #define __counted_by_le(member) __counted_by(member) 290 + #define __counted_by_be(member) 291 + #else 292 + #define __counted_by_le(member) 293 + #define __counted_by_be(member) __counted_by(member) 294 + #endif 295 + 285 296 /* Do not trap wrapping arithmetic within an annotated function. */ 286 297 #ifdef CONFIG_UBSAN_SIGNED_WRAP 287 298 # define __signed_wrap __attribute__((no_sanitize("signed-integer-overflow")))
+1
scripts/kernel-doc
··· 1143 1143 $members =~ s/\s*$attribute/ /gi; 1144 1144 $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 1145 1145 $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos; 1146 + $members =~ s/\s*__counted_by_(le|be)\s*\([^;]*\)/ /gos; 1146 1147 $members =~ s/\s*__packed\s*/ /gos; 1147 1148 $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1148 1149 $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;