Skip to content

Commit 0c87b54

Browse files
bstaszxkuba-moo
authored andcommitted
i40e: Fix the inability to attach XDP program on downed interface
Whenever trying to load XDP prog on downed interface, function i40e_xdp was passing vsi->rx_buf_len field to i40e_xdp_setup() which was equal 0. i40e_open() calls i40e_vsi_configure_rx() which configures that field, but that only happens when interface is up. When it is down, i40e_open() is not being called, thus vsi->rx_buf_len is not set. Solution for this is calculate buffer length in newly created function - i40e_calculate_vsi_rx_buf_len() that return actual buffer length. Buffer length is being calculated based on the same rules applied previously in i40e_vsi_configure_rx() function. Fixes: 613142b ("i40e: Log error for oversized MTU on device") Fixes: 0c8493d ("i40e: add XDP support for pass and drop actions") Signed-off-by: Bartosz Staszewski <[email protected]> Signed-off-by: Mateusz Palczewski <[email protected]> Tested-by: Shwetha Nagaraju <[email protected]> Reviewed-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Reviewed-by: Saeed Mahameed <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ede5a38 commit 0c87b54

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,6 +3693,24 @@ static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
36933693
return err;
36943694
}
36953695

3696+
/**
3697+
* i40e_calculate_vsi_rx_buf_len - Calculates buffer length
3698+
*
3699+
* @vsi: VSI to calculate rx_buf_len from
3700+
*/
3701+
static u16 i40e_calculate_vsi_rx_buf_len(struct i40e_vsi *vsi)
3702+
{
3703+
if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
3704+
return I40E_RXBUFFER_2048;
3705+
3706+
#if (PAGE_SIZE < 8192)
3707+
if (!I40E_2K_TOO_SMALL_WITH_PADDING && vsi->netdev->mtu <= ETH_DATA_LEN)
3708+
return I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3709+
#endif
3710+
3711+
return PAGE_SIZE < 8192 ? I40E_RXBUFFER_3072 : I40E_RXBUFFER_2048;
3712+
}
3713+
36963714
/**
36973715
* i40e_vsi_configure_rx - Configure the VSI for Rx
36983716
* @vsi: the VSI being configured
@@ -3704,20 +3722,14 @@ static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
37043722
int err = 0;
37053723
u16 i;
37063724

3707-
if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
3708-
vsi->max_frame = I40E_MAX_RXBUFFER;
3709-
vsi->rx_buf_len = I40E_RXBUFFER_2048;
3725+
vsi->max_frame = I40E_MAX_RXBUFFER;
3726+
vsi->rx_buf_len = i40e_calculate_vsi_rx_buf_len(vsi);
3727+
37103728
#if (PAGE_SIZE < 8192)
3711-
} else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
3712-
(vsi->netdev->mtu <= ETH_DATA_LEN)) {
3729+
if (vsi->netdev && !I40E_2K_TOO_SMALL_WITH_PADDING &&
3730+
vsi->netdev->mtu <= ETH_DATA_LEN)
37133731
vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
3714-
vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
37153732
#endif
3716-
} else {
3717-
vsi->max_frame = I40E_MAX_RXBUFFER;
3718-
vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
3719-
I40E_RXBUFFER_2048;
3720-
}
37213733

37223734
/* set up individual rings */
37233735
for (i = 0; i < vsi->num_queue_pairs && !err; i++)
@@ -13282,7 +13294,7 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog,
1328213294
int i;
1328313295

1328413296
/* Don't allow frames that span over multiple buffers */
13285-
if (frame_size > vsi->rx_buf_len) {
13297+
if (frame_size > i40e_calculate_vsi_rx_buf_len(vsi)) {
1328613298
NL_SET_ERR_MSG_MOD(extack, "MTU too large to enable XDP");
1328713299
return -EINVAL;
1328813300
}

0 commit comments

Comments
 (0)