diff mbox series

[v2,3/7] ice: move devlink locking outside the port creation

Message ID 20240605-next-2024-06-03-intel-next-batch-v2-3-39c23963fa78@intel.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Intel Wired LAN Driver Updates 2024-06-03 | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 901 this patch: 901
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 7 maintainers not CCed: przemyslaw.kitszel@intel.com pabeni@redhat.com edumazet@google.com anthony.l.nguyen@intel.com piotr.raczynski@intel.com jesse.brandeburg@intel.com intel-wired-lan@lists.osuosl.org
netdev/build_clang success Errors and warnings before: 905 this patch: 905
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 905 this patch: 905
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 78 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 33 this patch: 33
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-07--00-00 (tests: 1040)

Commit Message

Jacob Keller June 5, 2024, 8:40 p.m. UTC
From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

In case of subfunction lock will be taken for whole port creation. Do
the same in VF case.

Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tested-by: Sujai Buvaneswaran <sujai.buvaneswaran@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
 drivers/net/ethernet/intel/ice/devlink/devlink.c      | 2 --
 drivers/net/ethernet/intel/ice/devlink/devlink_port.c | 4 ++--
 drivers/net/ethernet/intel/ice/ice_eswitch.c          | 9 +++++++--
 drivers/net/ethernet/intel/ice/ice_repr.c             | 2 --
 4 files changed, 9 insertions(+), 8 deletions(-)

Comments

Jakub Kicinski June 7, 2024, 12:56 a.m. UTC | #1
On Wed, 05 Jun 2024 13:40:43 -0700 Jacob Keller wrote:
> From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> 
> In case of subfunction lock will be taken for whole port creation. Do
> the same in VF case.

No interactions with other locks worth mentioning?

> diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c
> index 704e9ad5144e..f774781ab514 100644
> --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c
> +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c
> @@ -794,10 +794,8 @@ int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *v
>  
>  	tc_node = pi->root->children[0];
>  	mutex_lock(&pi->sched_lock);
> -	devl_lock(devlink);
>  	for (i = 0; i < tc_node->num_children; i++)
>  		ice_traverse_tx_tree(devlink, tc_node->children[i], tc_node, pf);
> -	devl_unlock(devlink);
>  	mutex_unlock(&pi->sched_lock);

Like this didn't use to cause a deadlock?

Seems ice_devlink_rate_node_del() takes this lock and it's already
holding the devlink instance lock.
Michal Swiatkowski June 7, 2024, 5:10 a.m. UTC | #2
On Thu, Jun 06, 2024 at 05:56:34PM -0700, Jakub Kicinski wrote:
> On Wed, 05 Jun 2024 13:40:43 -0700 Jacob Keller wrote:
> > From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> > 
> > In case of subfunction lock will be taken for whole port creation. Do
> > the same in VF case.
> 
> No interactions with other locks worth mentioning?
> 

You right, I could have mentioned also removing path. The patch is only
about devlink lock during port representor creation / removing.

> > diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c
> > index 704e9ad5144e..f774781ab514 100644
> > --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c
> > +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c
> > @@ -794,10 +794,8 @@ int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *v
> >  
> >  	tc_node = pi->root->children[0];
> >  	mutex_lock(&pi->sched_lock);
> > -	devl_lock(devlink);
> >  	for (i = 0; i < tc_node->num_children; i++)
> >  		ice_traverse_tx_tree(devlink, tc_node->children[i], tc_node, pf);
> > -	devl_unlock(devlink);
> >  	mutex_unlock(&pi->sched_lock);
> 
> Like this didn't use to cause a deadlock?
> 
> Seems ice_devlink_rate_node_del() takes this lock and it's already
> holding the devlink instance lock.

ice_devlink_rate_init_tx_topology() wasn't (till now) called with
devlink lock, because it is called from port representor creation flow,
not from the devlink.

Thanks,
Michal
Jacob Keller June 7, 2024, 9:20 p.m. UTC | #3
On 6/6/2024 10:10 PM, Michal Swiatkowski wrote:
> On Thu, Jun 06, 2024 at 05:56:34PM -0700, Jakub Kicinski wrote:
>> On Wed, 05 Jun 2024 13:40:43 -0700 Jacob Keller wrote:
>>> From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
>>>
>>> In case of subfunction lock will be taken for whole port creation. Do
>>> the same in VF case.
>>
>> No interactions with other locks worth mentioning?
>>
> 
> You right, I could have mentioned also removing path. The patch is only
> about devlink lock during port representor creation / removing.
> 
>>> diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c
>>> index 704e9ad5144e..f774781ab514 100644
>>> --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c
>>> +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c
>>> @@ -794,10 +794,8 @@ int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *v
>>>  
>>>  	tc_node = pi->root->children[0];
>>>  	mutex_lock(&pi->sched_lock);
>>> -	devl_lock(devlink);
>>>  	for (i = 0; i < tc_node->num_children; i++)
>>>  		ice_traverse_tx_tree(devlink, tc_node->children[i], tc_node, pf);
>>> -	devl_unlock(devlink);
>>>  	mutex_unlock(&pi->sched_lock);
>>
>> Like this didn't use to cause a deadlock?
>>
>> Seems ice_devlink_rate_node_del() takes this lock and it's already
>> holding the devlink instance lock.
> 
> ice_devlink_rate_init_tx_topology() wasn't (till now) called with
> devlink lock, because it is called from port representor creation flow,
> not from the devlink.
> 
> Thanks,
> Michal

I take it you will make a respin of the 4 subfunction patches in this
series then?
Michal Swiatkowski June 10, 2024, 7:20 a.m. UTC | #4
On Fri, Jun 07, 2024 at 02:20:01PM -0700, Jacob Keller wrote:
> 
> 
> On 6/6/2024 10:10 PM, Michal Swiatkowski wrote:
> > On Thu, Jun 06, 2024 at 05:56:34PM -0700, Jakub Kicinski wrote:
> >> On Wed, 05 Jun 2024 13:40:43 -0700 Jacob Keller wrote:
> >>> From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> >>>
> >>> In case of subfunction lock will be taken for whole port creation. Do
> >>> the same in VF case.
> >>
> >> No interactions with other locks worth mentioning?
> >>
> > 
> > You right, I could have mentioned also removing path. The patch is only
> > about devlink lock during port representor creation / removing.
> > 
> >>> diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c
> >>> index 704e9ad5144e..f774781ab514 100644
> >>> --- a/drivers/net/ethernet/intel/ice/devlink/devlink.c
> >>> +++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c
> >>> @@ -794,10 +794,8 @@ int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *v
> >>>  
> >>>  	tc_node = pi->root->children[0];
> >>>  	mutex_lock(&pi->sched_lock);
> >>> -	devl_lock(devlink);
> >>>  	for (i = 0; i < tc_node->num_children; i++)
> >>>  		ice_traverse_tx_tree(devlink, tc_node->children[i], tc_node, pf);
> >>> -	devl_unlock(devlink);
> >>>  	mutex_unlock(&pi->sched_lock);
> >>
> >> Like this didn't use to cause a deadlock?
> >>
> >> Seems ice_devlink_rate_node_del() takes this lock and it's already
> >> holding the devlink instance lock.
> > 
> > ice_devlink_rate_init_tx_topology() wasn't (till now) called with
> > devlink lock, because it is called from port representor creation flow,
> > not from the devlink.
> > 
> > Thanks,
> > Michal
> 
> I take it you will make a respin of the 4 subfunction patches in this
> series then?

Ok, I will send.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink.c b/drivers/net/ethernet/intel/ice/devlink/devlink.c
index 704e9ad5144e..f774781ab514 100644
--- a/drivers/net/ethernet/intel/ice/devlink/devlink.c
+++ b/drivers/net/ethernet/intel/ice/devlink/devlink.c
@@ -794,10 +794,8 @@  int ice_devlink_rate_init_tx_topology(struct devlink *devlink, struct ice_vsi *v
 
 	tc_node = pi->root->children[0];
 	mutex_lock(&pi->sched_lock);
-	devl_lock(devlink);
 	for (i = 0; i < tc_node->num_children; i++)
 		ice_traverse_tx_tree(devlink, tc_node->children[i], tc_node, pf);
-	devl_unlock(devlink);
 	mutex_unlock(&pi->sched_lock);
 
 	return 0;
diff --git a/drivers/net/ethernet/intel/ice/devlink/devlink_port.c b/drivers/net/ethernet/intel/ice/devlink/devlink_port.c
index 13e6790d3cae..c9fbeebf7fb9 100644
--- a/drivers/net/ethernet/intel/ice/devlink/devlink_port.c
+++ b/drivers/net/ethernet/intel/ice/devlink/devlink_port.c
@@ -407,7 +407,7 @@  int ice_devlink_create_vf_port(struct ice_vf *vf)
 	devlink_port_attrs_set(devlink_port, &attrs);
 	devlink = priv_to_devlink(pf);
 
-	err = devlink_port_register(devlink, devlink_port, vsi->idx);
+	err = devl_port_register(devlink, devlink_port, vsi->idx);
 	if (err) {
 		dev_err(dev, "Failed to create devlink port for VF %d, error %d\n",
 			vf->vf_id, err);
@@ -426,5 +426,5 @@  int ice_devlink_create_vf_port(struct ice_vf *vf)
 void ice_devlink_destroy_vf_port(struct ice_vf *vf)
 {
 	devl_rate_leaf_destroy(&vf->devlink_port);
-	devlink_port_unregister(&vf->devlink_port);
+	devl_port_unregister(&vf->devlink_port);
 }
diff --git a/drivers/net/ethernet/intel/ice/ice_eswitch.c b/drivers/net/ethernet/intel/ice/ice_eswitch.c
index b102db8b829a..7b57a6561a5a 100644
--- a/drivers/net/ethernet/intel/ice/ice_eswitch.c
+++ b/drivers/net/ethernet/intel/ice/ice_eswitch.c
@@ -423,6 +423,7 @@  static void ice_eswitch_start_reprs(struct ice_pf *pf)
 int
 ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
 {
+	struct devlink *devlink = priv_to_devlink(pf);
 	struct ice_repr *repr;
 	int err;
 
@@ -437,7 +438,9 @@  ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
 
 	ice_eswitch_stop_reprs(pf);
 
+	devl_lock(devlink);
 	repr = ice_repr_add_vf(vf);
+	devl_unlock(devlink);
 	if (IS_ERR(repr)) {
 		err = PTR_ERR(repr);
 		goto err_create_repr;
@@ -460,7 +463,9 @@  ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf)
 err_xa_alloc:
 	ice_eswitch_release_repr(pf, repr);
 err_setup_repr:
+	devl_lock(devlink);
 	ice_repr_rem_vf(repr);
+	devl_unlock(devlink);
 err_create_repr:
 	if (xa_empty(&pf->eswitch.reprs))
 		ice_eswitch_disable_switchdev(pf);
@@ -484,6 +489,7 @@  void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf)
 		ice_eswitch_disable_switchdev(pf);
 
 	ice_eswitch_release_repr(pf, repr);
+	devl_lock(devlink);
 	ice_repr_rem_vf(repr);
 
 	if (xa_empty(&pf->eswitch.reprs)) {
@@ -491,12 +497,11 @@  void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf)
 		 * no point in keeping the nodes
 		 */
 		ice_devlink_rate_clear_tx_topology(ice_get_main_vsi(pf));
-		devl_lock(devlink);
 		devl_rate_nodes_destroy(devlink);
-		devl_unlock(devlink);
 	} else {
 		ice_eswitch_start_reprs(pf);
 	}
+	devl_unlock(devlink);
 }
 
 /**
diff --git a/drivers/net/ethernet/intel/ice/ice_repr.c b/drivers/net/ethernet/intel/ice/ice_repr.c
index fe83f305cc7d..35a6ac8c0466 100644
--- a/drivers/net/ethernet/intel/ice/ice_repr.c
+++ b/drivers/net/ethernet/intel/ice/ice_repr.c
@@ -285,9 +285,7 @@  ice_repr_reg_netdev(struct net_device *netdev)
 
 static void ice_repr_remove_node(struct devlink_port *devlink_port)
 {
-	devl_lock(devlink_port->devlink);
 	devl_rate_leaf_destroy(devlink_port);
-	devl_unlock(devlink_port->devlink);
 }
 
 /**