Commit 9496f2a
ice: fix Rx page leak on multi-buffer frames
The ice_put_rx_mbuf() function handles calling ice_put_rx_buf() for each
buffer in the current frame. This function was introduced as part of
handling multi-buffer XDP support in the ice driver.
It works by iterating over the buffers from first_desc up to 1 plus the
total number of fragments in the frame, cached from before the XDP program
was executed.
If the hardware posts a descriptor with a size of 0, the logic used in
ice_put_rx_mbuf() breaks. Such descriptors get skipped and don't get added
as fragments in ice_add_xdp_frag. Since the buffer isn't counted as a
fragment, we do not iterate over it in ice_put_rx_mbuf(), and thus we don't
call ice_put_rx_buf().
Because we don't call ice_put_rx_buf(), we don't attempt to re-use the
page or free it. This leaves a stale page in the ring, as we don't
increment next_to_alloc.
The ice_reuse_rx_page() assumes that the next_to_alloc has been incremented
properly, and that it always points to a buffer with a NULL page. Since
this function doesn't check, it will happily recycle a page over the top
of the next_to_alloc buffer, losing track of the old page.
Note that this leak only occurs for multi-buffer frames. The
ice_put_rx_mbuf() function always handles at least one buffer, so a
single-buffer frame will always get handled correctly. It is not clear
precisely why the hardware hands us descriptors with a size of 0 sometimes,
but it happens somewhat regularly with "jumbo frames" used by 9K MTU.
To fix ice_put_rx_mbuf(), we need to make sure to call ice_put_rx_buf() on
all buffers between first_desc and next_to_clean. Borrow the logic of a
similar function in i40e used for this same purpose. Use the same logic
also in ice_get_pgcnts().
Instead of iterating over just the number of fragments, use a loop which
iterates until the current index reaches to the next_to_clean element just
past the current frame. Check the current number of fragments (post XDP
program). For all buffers up 1 more than the number of fragments, we'll
update the pagecnt_bias. For any buffers past this, pagecnt_bias is left
as-is. This ensures that fragments released by the XDP program, as well as
any buffers with zero-size won't have their pagecnt_bias updated
incorrectly. Unlike i40e, the ice_put_rx_mbuf() function does call
ice_put_rx_buf() on the last buffer of the frame indicating end of packet.
The xdp_xmit value only needs to be updated if an XDP program is run, and
only once per packet. Drop the xdp_xmit pointer argument from
ice_put_rx_mbuf(). Instead, set xdp_xmit in the ice_clean_rx_irq() function
directly. This avoids needing to pass the argument and avoids an extra
bit-wise OR for each buffer in the frame.
Move the increment of the ntc local variable to ensure its updated *before*
all calls to ice_get_pgcnts() or ice_put_rx_mbuf(), as the loop logic
requires the index of the element just after the current frame.
This has the advantage that we also no longer need to track or cache the
number of fragments in the rx_ring, which saves a few bytes in the ring.
Cc: Christoph Petrausch <christoph.petrausch@deepl.com>
Reported-by: Jaroslav Pulchart <jaroslav.pulchart@gooddata.com>
Closes: https://lore.kernel.org/netdev/CAK8fFZ4hY6GUJNENz3wY9jaYLZXGfpr7dnZxzGMYoE44caRbgw@mail.gmail.com/
Fixes: 743bbd9 ("ice: put Rx buffers after being done with current frame")
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>1 parent 467d3a9 commit 9496f2a
2 files changed
+33
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
894 | 894 | | |
895 | 895 | | |
896 | 896 | | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | 897 | | |
902 | 898 | | |
903 | 899 | | |
| |||
968 | 964 | | |
969 | 965 | | |
970 | 966 | | |
| 967 | + | |
971 | 968 | | |
972 | 969 | | |
973 | 970 | | |
974 | 971 | | |
975 | 972 | | |
976 | 973 | | |
977 | | - | |
| 974 | + | |
978 | 975 | | |
979 | | - | |
980 | 976 | | |
981 | 977 | | |
982 | 978 | | |
983 | 979 | | |
984 | | - | |
| 980 | + | |
985 | 981 | | |
986 | 982 | | |
987 | 983 | | |
| |||
1154 | 1150 | | |
1155 | 1151 | | |
1156 | 1152 | | |
1157 | | - | |
| 1153 | + | |
1158 | 1154 | | |
1159 | 1155 | | |
1160 | | - | |
1161 | | - | |
| 1156 | + | |
1162 | 1157 | | |
1163 | 1158 | | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1167 | 1165 | | |
1168 | 1166 | | |
1169 | | - | |
| 1167 | + | |
1170 | 1168 | | |
1171 | | - | |
| 1169 | + | |
1172 | 1170 | | |
1173 | 1171 | | |
1174 | | - | |
1175 | 1172 | | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
1179 | | - | |
| 1173 | + | |
1180 | 1174 | | |
1181 | | - | |
| 1175 | + | |
1182 | 1176 | | |
| 1177 | + | |
| 1178 | + | |
1183 | 1179 | | |
1184 | | - | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
1185 | 1186 | | |
1186 | | - | |
1187 | | - | |
| 1187 | + | |
1188 | 1188 | | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | 1189 | | |
1193 | 1190 | | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
1206 | | - | |
1207 | | - | |
1208 | 1191 | | |
1209 | 1192 | | |
1210 | 1193 | | |
1211 | 1194 | | |
1212 | | - | |
1213 | 1195 | | |
1214 | 1196 | | |
1215 | 1197 | | |
| |||
1317 | 1299 | | |
1318 | 1300 | | |
1319 | 1301 | | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
1320 | 1306 | | |
1321 | 1307 | | |
1322 | 1308 | | |
| |||
1325 | 1311 | | |
1326 | 1312 | | |
1327 | 1313 | | |
1328 | | - | |
| 1314 | + | |
1329 | 1315 | | |
1330 | 1316 | | |
1331 | | - | |
1332 | | - | |
1333 | 1317 | | |
1334 | 1318 | | |
1335 | 1319 | | |
1336 | 1320 | | |
1337 | 1321 | | |
1338 | | - | |
| 1322 | + | |
1339 | 1323 | | |
1340 | 1324 | | |
1341 | 1325 | | |
1342 | 1326 | | |
1343 | 1327 | | |
1344 | 1328 | | |
1345 | | - | |
| 1329 | + | |
| 1330 | + | |
1346 | 1331 | | |
1347 | 1332 | | |
1348 | 1333 | | |
| |||
1355 | 1340 | | |
1356 | 1341 | | |
1357 | 1342 | | |
1358 | | - | |
| 1343 | + | |
1359 | 1344 | | |
1360 | 1345 | | |
1361 | 1346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
362 | 361 | | |
363 | 362 | | |
364 | 363 | | |
| |||
0 commit comments