ice: Add support for XDP multi-buffer on Tx side
Hello Maciej Fijalkowski,
The patch 3246a10752a7: "ice: Add support for XDP multi-buffer on Tx side" from Jan 31, 2023, leads to the following Smatch static checker warning:
drivers/net/ethernet/intel/ice/ice_txrx.c:1323 ice_clean_rx_irq() error: uninitialized symbol 'cached_ntu'.
drivers/net/ethernet/intel/ice/ice_txrx.c
1150 int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)
1151 {
1152 unsigned int total_rx_bytes = 0, total_rx_pkts = 0;
1153 unsigned int offset = rx_ring->rx_offset;
1154 struct xdp_buff *xdp = &rx_ring->xdp;
1155 struct ice_tx_ring *xdp_ring = NULL;
1156 struct bpf_prog *xdp_prog = NULL;
1157 u32 ntc = rx_ring->next_to_clean;
1158 u32 cnt = rx_ring->count;
1159 u32 cached_ntc = ntc;
1160 u32 xdp_xmit = 0;
1161 u32 cached_ntu;
1162 bool failure;
1163 u32 first;
1164
1165 /* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
1166 #if (PAGE_SIZE < 8192)
1167 xdp->frame_sz = ice_rx_frame_truesize(rx_ring, 0);
1168 #endif
1169
1170 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
1171 if (xdp_prog) {
1172 xdp_ring = rx_ring->xdp_ring;
1173 cached_ntu = xdp_ring->next_to_use;
1174 }cached_ntu not initialized on else path.
1175
1176 /* start the loop to process Rx packets bounded by 'budget' */
1177 while (likely(total_rx_pkts < (unsigned int)budget)) {
1178 union ice_32b_rx_flex_desc *rx_desc;
1179 struct ice_rx_buf *rx_buf;
1180 struct sk_buff *skb;
1181 unsigned int size;
1182 u16 stat_err_bits;
1183 u16 vlan_tag = 0;
1184 u16 rx_ptype;
1185
1186 /* get the Rx desc from Rx ring based on 'next_to_clean' */
1187 rx_desc = ICE_RX_DESC(rx_ring, ntc);
1188
1189 /* status_error_len will always be zero for unused descriptors
1190 * because it's cleared in cleanup, and overlaps with hdr_addr
1191 * which is always zero because packet split isn't used, if the
1192 * hardware wrote DD then it will be non-zero
1193 */
1194 stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S);
1195 if (!ice_test_staterr(rx_desc->wb.status_error0, stat_err_bits))
1196 break;
1197
1198 /* This memory barrier is needed to keep us from reading
1199 * any other fields out of the rx_desc until we know the
1200 * DD bit is set.
1201 */
1202 dma_rmb();
1203
1204 ice_trace(clean_rx_irq, rx_ring, rx_desc);
1205 if (rx_desc->wb.rxdid == FDIR_DESC_RXDID || !rx_ring->netdev) {
1206 struct ice_vsi *ctrl_vsi = rx_ring->vsi;
1207
1208 if (rx_desc->wb.rxdid == FDIR_DESC_RXDID &&
1209 ctrl_vsi->vf)
1210 ice_vc_fdir_irq_handler(ctrl_vsi, rx_desc);
1211 if (++ntc == cnt)
1212 ntc = 0;
1213 continue;
1214 }
1215
1216 size = le16_to_cpu(rx_desc->wb.pkt_len) &
1217 ICE_RX_FLX_DESC_PKT_LEN_M;
1218
1219 /* retrieve a buffer from the ring */
1220 rx_buf = ice_get_rx_buf(rx_ring, size, ntc);
1221
1222 if (!xdp->data) {
1223 void *hard_start;
1224
1225 hard_start = page_address(rx_buf->page) + rx_buf->page_offset -
1226 offset;
1227 xdp_prepare_buff(xdp, hard_start, offset, size, !!offset);
1228 #if (PAGE_SIZE > 4096)
1229 /* At larger PAGE_SIZE, frame_sz depend on len size */
1230 xdp->frame_sz = ice_rx_frame_truesize(rx_ring, size);
1231 #endif
1232 xdp_buff_clear_frags_flag(xdp);
1233 } else if (ice_add_xdp_frag(rx_ring, xdp, rx_buf, size)) {
1234 break;
1235 }
1236 if (++ntc == cnt)
1237 ntc = 0;
1238
1239 /* skip if it is NOP desc */
1240 if (ice_is_non_eop(rx_ring, rx_desc))
1241 continue;
1242
1243 ice_run_xdp(rx_ring, xdp, xdp_prog, xdp_ring, rx_buf);
1244 if (rx_buf->act == ICE_XDP_PASS)
1245 goto construct_skb;
1246 total_rx_bytes += xdp_get_buff_len(xdp);
1247 total_rx_pkts++;
1248
1249 xdp->data = NULL;
1250 rx_ring->first_desc = ntc;
1251 continue;
1252 construct_skb:
1253 if (likely(ice_ring_uses_build_skb(rx_ring)))
1254 skb = ice_build_skb(rx_ring, xdp);
1255 else
1256 skb = ice_construct_skb(rx_ring, xdp);
1257 /* exit if we failed to retrieve a buffer */
1258 if (!skb) {
1259 rx_ring->ring_stats->rx_stats.alloc_page_failed++;
1260 rx_buf->act = ICE_XDP_CONSUMED;
1261 if (unlikely(xdp_buff_has_frags(xdp)))
1262 ice_set_rx_bufs_act(xdp, rx_ring,
1263 ICE_XDP_CONSUMED);
1264 xdp->data = NULL;
1265 rx_ring->first_desc = ntc;
1266 break;
1267 }
1268 xdp->data = NULL;
1269 rx_ring->first_desc = ntc;
1270
1271 stat_err_bits = BIT(ICE_RX_FLEX_DESC_STATUS0_RXE_S);
1272 if (unlikely(ice_test_staterr(rx_desc->wb.status_error0,
1273 stat_err_bits))) {
1274 dev_kfree_skb_any(skb);
1275 continue;
1276 }
1277
1278 vlan_tag = ice_get_vlan_tag_from_rx_desc(rx_desc);
1279
1280 /* pad the skb if needed, to make a valid ethernet frame */
1281 if (eth_skb_pad(skb))
1282 continue;
1283
1284 /* probably a little skewed due to removing CRC */
1285 total_rx_bytes += skb->len;
1286
1287 /* populate checksum, VLAN, and protocol */
1288 rx_ptype = le16_to_cpu(rx_desc->wb.ptype_flex_flags0) &
1289 ICE_RX_FLEX_DESC_PTYPE_M;
1290
1291 ice_process_skb_fields(rx_ring, rx_desc, skb, rx_ptype);
1292
1293 ice_trace(clean_rx_irq_indicate, rx_ring, rx_desc, skb);
1294 /* send completed skb up the stack */
1295 ice_receive_skb(rx_ring, skb, vlan_tag);
1296
1297 /* update budget accounting */
1298 total_rx_pkts++;
1299 }
1300
1301 first = rx_ring->first_desc;
1302 while (cached_ntc != first) {
1303 struct ice_rx_buf *buf = &rx_ring->rx_buf[cached_ntc];
1304
1305 if (buf->act & (ICE_XDP_TX | ICE_XDP_REDIR)) {
1306 ice_rx_buf_adjust_pg_offset(buf, xdp->frame_sz);
1307 xdp_xmit |= buf->act;
1308 } else if (buf->act & ICE_XDP_CONSUMED) {
1309 buf->pagecnt_bias++;
1310 } else if (buf->act == ICE_XDP_PASS) {
1311 ice_rx_buf_adjust_pg_offset(buf, xdp->frame_sz);
1312 }
1313
1314 ice_put_rx_buf(rx_ring, buf);
1315 if (++cached_ntc >= cnt)
1316 cached_ntc = 0;
1317 }
1318 rx_ring->next_to_clean = ntc;
1319 /* return up to cleaned_count buffers to hardware */
1320 failure = ice_alloc_rx_bufs(rx_ring, ICE_RX_DESC_UNUSED(rx_ring));
1321
1322 if (xdp_xmit)
--> 1323 ice_finalize_xdp_rx(xdp_ring, xdp_xmit, cached_ntu);
1324
1325 if (rx_ring->ring_stats)
1326 ice_update_rx_ring_stats(rx_ring, total_rx_pkts,
1327 total_rx_bytes);
1328
1329 /* guarantee a trip back through this routine if there was a failure */
1330 return failure ? budget : (int)total_rx_pkts;
1331 }regards,
dan carpenter
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan