Skip to content

Commit a95a4d9

Browse files
magnus-karlssonAlexei Starovoitov
authored andcommitted
xsk: Do not write NULL in SW ring at allocation failure
For the case when xp_alloc_batch() is used but the batched allocation cannot be used, there is a slow path that uses the non-batched xp_alloc(). When it fails to allocate an entry, it returns NULL. The current code wrote this NULL into the entry of the provided results array (pointer to the driver SW ring usually) and returned. This might not be what the driver expects and to make things simpler, just write successfully allocated xdp_buffs into the SW ring,. The driver might have information in there that is still important after an allocation failure. Note that at this point in time, there are no drivers using xp_alloc_batch() that could trigger this slow path. But one might get added. Fixes: 47e4075 ("xsk: Batched buffer allocation for the pool") Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220328142123.170157-2-maciej.fijalkowski@intel.com
1 parent 7df482e commit a95a4d9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

net/xdp/xsk_buff_pool.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,13 @@ u32 xp_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp, u32 max)
591591
u32 nb_entries1 = 0, nb_entries2;
592592

593593
if (unlikely(pool->dma_need_sync)) {
594+
struct xdp_buff *buff;
595+
594596
/* Slow path */
595-
*xdp = xp_alloc(pool);
596-
return !!*xdp;
597+
buff = xp_alloc(pool);
598+
if (buff)
599+
*xdp = buff;
600+
return !!buff;
597601
}
598602

599603
if (unlikely(pool->free_list_cnt)) {

0 commit comments

Comments
 (0)