* [PATCH net 1/4] i40e: Fix XDP program unloading while removing the driver [not found] <20240611184239.1518418-1-anthony.l.nguyen@intel.com> @ 2024-06-11 18:42 ` Tony Nguyen 2024-06-11 18:57 ` Michal Kubiak 0 siblings, 1 reply; 3+ messages in thread From: Tony Nguyen @ 2024-06-11 18:42 UTC (permalink / raw) To: davem, kuba, pabeni, edumazet, netdev Cc: Michal Kubiak, anthony.l.nguyen, maciej.fijalkowski, magnus.karlsson, ast, daniel, hawk, john.fastabend, bpf, Wojciech Drewek, George Kuruvinakunnel, Simon Horman From: Michal Kubiak <michal.kubiak@intel.com> The commit 6533e558c650 ("i40e: Fix reset path while removing the driver") introduced a new PF state "__I40E_IN_REMOVE" to block modifying the XDP program while the driver is being removed. Unfortunately, such a change is useful only if the ".ndo_bpf()" callback was called out of the rmmod context because unloading the existing XDP program is also a part of driver removing procedure. In other words, from the rmmod context the driver is expected to unload the XDP program without reporting any errors. Otherwise, the kernel warning with callstack is printed out to dmesg. Example failing scenario: 1. Load the i40e driver. 2. Load the XDP program. 3. Unload the i40e driver (using "rmmod" command). Fix this by improving checks in ".ndo_bpf()" to determine if that callback was called from the removing context and if the kernel wants to unload the XDP program. Allow for unloading the XDP program in such a case. Fixes: 6533e558c650 ("i40e: Fix reset path while removing the driver") Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> Signed-off-by: Michal Kubiak <michal.kubiak@intel.com> Tested-by: George Kuruvinakunnel <george.kuruvinakunnel@intel.com> Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> --- drivers/net/ethernet/intel/i40e/i40e_main.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 284c3fad5a6e..2f478edb9f9f 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -13293,6 +13293,20 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog, bool need_reset; int i; + /* Called from netdev unregister context. Unload the XDP program. */ + if (vsi->netdev->reg_state == NETREG_UNREGISTERING) { + xdp_features_clear_redirect_target(vsi->netdev); + old_prog = xchg(&vsi->xdp_prog, NULL); + if (old_prog) + bpf_prog_put(old_prog); + + return 0; + } + + /* VSI shall be deleted in a moment, just return EINVAL */ + if (test_bit(__I40E_IN_REMOVE, pf->state)) + return -EINVAL; + /* Don't allow frames that span over multiple buffers */ if (vsi->netdev->mtu > frame_size - I40E_PACKET_HDR_PAD) { NL_SET_ERR_MSG_MOD(extack, "MTU too large for linear frames and XDP prog does not support frags"); @@ -13301,14 +13315,9 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog, /* When turning XDP on->off/off->on we reset and rebuild the rings. */ need_reset = (i40e_enabled_xdp_vsi(vsi) != !!prog); - if (need_reset) i40e_prep_for_reset(pf); - /* VSI shall be deleted in a moment, just return EINVAL */ - if (test_bit(__I40E_IN_REMOVE, pf->state)) - return -EINVAL; - old_prog = xchg(&vsi->xdp_prog, prog); if (need_reset) { -- 2.41.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net 1/4] i40e: Fix XDP program unloading while removing the driver 2024-06-11 18:42 ` [PATCH net 1/4] i40e: Fix XDP program unloading while removing the driver Tony Nguyen @ 2024-06-11 18:57 ` Michal Kubiak 2024-06-11 19:03 ` Tony Nguyen 0 siblings, 1 reply; 3+ messages in thread From: Michal Kubiak @ 2024-06-11 18:57 UTC (permalink / raw) To: Tony Nguyen Cc: davem, kuba, pabeni, edumazet, netdev, maciej.fijalkowski, magnus.karlsson, ast, daniel, hawk, john.fastabend, bpf, Wojciech Drewek, George Kuruvinakunnel, Simon Horman On Tue, Jun 11, 2024 at 11:42:35AM -0700, Tony Nguyen wrote: > From: Michal Kubiak <michal.kubiak@intel.com> > > The commit 6533e558c650 ("i40e: Fix reset path while removing > the driver") introduced a new PF state "__I40E_IN_REMOVE" to block > modifying the XDP program while the driver is being removed. > Unfortunately, such a change is useful only if the ".ndo_bpf()" > callback was called out of the rmmod context because unloading the > existing XDP program is also a part of driver removing procedure. > In other words, from the rmmod context the driver is expected to > unload the XDP program without reporting any errors. Otherwise, > the kernel warning with callstack is printed out to dmesg. > > Example failing scenario: > 1. Load the i40e driver. > 2. Load the XDP program. > 3. Unload the i40e driver (using "rmmod" command). > > Fix this by improving checks in ".ndo_bpf()" to determine if that > callback was called from the removing context and if the kernel > wants to unload the XDP program. Allow for unloading the XDP program > in such a case. > > Fixes: 6533e558c650 ("i40e: Fix reset path while removing the driver") > Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> > Signed-off-by: Michal Kubiak <michal.kubiak@intel.com> > Tested-by: George Kuruvinakunnel <george.kuruvinakunnel@intel.com> > Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> > Reviewed-by: Simon Horman <horms@kernel.org> > Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> > --- Hi Tony, After my conversation with Kuba in a separate thread, I analyzed that patch one more time and it seems the fix can be implemented in a simpler way, so I am going to send the v2. Therefore, please ignore this patch. Thanks, Michal ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net 1/4] i40e: Fix XDP program unloading while removing the driver 2024-06-11 18:57 ` Michal Kubiak @ 2024-06-11 19:03 ` Tony Nguyen 0 siblings, 0 replies; 3+ messages in thread From: Tony Nguyen @ 2024-06-11 19:03 UTC (permalink / raw) To: Michal Kubiak Cc: davem, kuba, pabeni, edumazet, netdev, maciej.fijalkowski, magnus.karlsson, ast, daniel, hawk, john.fastabend, bpf, Wojciech Drewek, George Kuruvinakunnel, Simon Horman On 6/11/2024 11:57 AM, Michal Kubiak wrote: > Hi Tony, > > After my conversation with Kuba in a separate thread, I analyzed that > patch one more time and it seems the fix can be implemented in a simpler > way, so I am going to send the v2. > Therefore, please ignore this patch. I found that conversation :( I'll drop this and re-send tomorrow. Thanks, Tony --- pw-bot: cr ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-11 19:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240611184239.1518418-1-anthony.l.nguyen@intel.com>
2024-06-11 18:42 ` [PATCH net 1/4] i40e: Fix XDP program unloading while removing the driver Tony Nguyen
2024-06-11 18:57 ` Michal Kubiak
2024-06-11 19:03 ` Tony Nguyen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox