public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Vladimir Oltean <olteanv@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	pabeni@redhat.com, edumazet@google.com, andrew@lunn.ch,
	vivien.didelot@gmail.com, f.fainelli@gmail.com
Subject: Re: [patch net-next RFC] net: dsa: move port_setup/teardown to be called outside devlink port registered area
Date: Tue, 26 Jul 2022 17:57:59 +0200	[thread overview]
Message-ID: <YuAPBwaOjjQBTc6V@nanopsycho> (raw)
In-Reply-To: <20220726152059.bls6gn7ludfutamy@skbuf>

Tue, Jul 26, 2022 at 05:20:59PM CEST, olteanv@gmail.com wrote:
>On Tue, Jul 26, 2022 at 04:45:44PM +0200, Jiri Pirko wrote:
>> Oh yes, could you please try together with following patch? (nevermind
>> chicken-egg problem you may spot now)
>
>Duly ignoring ;)
>
>> Subject: [patch net-next RFC] net: devlink: convert region creation/destroy()
>>  to be forbidden on registered devlink/port
>> 
>> No need to create or destroy region when devlink or devlink ports are
>> registered. Limit the possibility to call the region create/destroy()
>> only for non-registered devlink or devlink port. Benefit from that and
>> avoid need to take devl_lock.
>> 
>> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>> ---
>>  drivers/net/netdevsim/dev.c |  8 ++--
>>  include/net/devlink.h       |  5 ---
>>  net/core/devlink.c          | 78 ++++++++-----------------------------
>>  3 files changed, 20 insertions(+), 71 deletions(-)
>> 
>> diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
>> index 925dc8a5254d..3f0c19e30650 100644
>> --- a/drivers/net/netdevsim/dev.c
>> +++ b/drivers/net/netdevsim/dev.c
>> @@ -557,15 +557,15 @@ static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev,
>>  				      struct devlink *devlink)
>>  {
>>  	nsim_dev->dummy_region =
>> -		devl_region_create(devlink, &dummy_region_ops,
>> -				   NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX,
>> -				   NSIM_DEV_DUMMY_REGION_SIZE);
>> +		devlink_region_create(devlink, &dummy_region_ops,
>> +				      NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX,
>> +				      NSIM_DEV_DUMMY_REGION_SIZE);
>>  	return PTR_ERR_OR_ZERO(nsim_dev->dummy_region);
>>  }
>>  
>>  static void nsim_dev_dummy_region_exit(struct nsim_dev *nsim_dev)
>>  {
>> -	devl_region_destroy(nsim_dev->dummy_region);
>> +	devlink_region_destroy(nsim_dev->dummy_region);
>>  }
>>  
>>  static int
>> diff --git a/include/net/devlink.h b/include/net/devlink.h
>> index 9edb4a28cf30..2416750e050d 100644
>> --- a/include/net/devlink.h
>> +++ b/include/net/devlink.h
>> @@ -1666,10 +1666,6 @@ int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
>>  int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
>>  				       union devlink_param_value init_val);
>>  void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
>> -struct devlink_region *devl_region_create(struct devlink *devlink,
>> -					  const struct devlink_region_ops *ops,
>> -					  u32 region_max_snapshots,
>> -					  u64 region_size);
>>  struct devlink_region *
>>  devlink_region_create(struct devlink *devlink,
>>  		      const struct devlink_region_ops *ops,
>> @@ -1678,7 +1674,6 @@ struct devlink_region *
>>  devlink_port_region_create(struct devlink_port *port,
>>  			   const struct devlink_port_region_ops *ops,
>>  			   u32 region_max_snapshots, u64 region_size);
>> -void devl_region_destroy(struct devlink_region *region);
>>  void devlink_region_destroy(struct devlink_region *region);
>>  void devlink_port_region_destroy(struct devlink_region *region);
>>  
>> diff --git a/net/core/devlink.c b/net/core/devlink.c
>> index 4e0c4f9265e8..15d28aba69fc 100644
>> --- a/net/core/devlink.c
>> +++ b/net/core/devlink.c
>> @@ -5701,8 +5701,7 @@ static void devlink_nl_region_notify(struct devlink_region *region,
>>  	struct sk_buff *msg;
>>  
>>  	WARN_ON(cmd != DEVLINK_CMD_REGION_NEW && cmd != DEVLINK_CMD_REGION_DEL);
>> -	if (!xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED))
>> -		return;
>> +	ASSERT_DEVLINK_REGISTERED(devlink);
>>  
>>  	msg = devlink_nl_region_notify_build(region, snapshot, cmd, 0, 0);
>>  	if (IS_ERR(msg))
>> @@ -11131,21 +11130,22 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id)
>>  EXPORT_SYMBOL_GPL(devlink_param_value_changed);
>>  
>>  /**
>> - * devl_region_create - create a new address region
>> + * devlink_region_create - create a new address region
>>   *
>>   * @devlink: devlink
>>   * @ops: region operations and name
>>   * @region_max_snapshots: Maximum supported number of snapshots for region
>>   * @region_size: size of region
>>   */
>> -struct devlink_region *devl_region_create(struct devlink *devlink,
>> -					  const struct devlink_region_ops *ops,
>> -					  u32 region_max_snapshots,
>> -					  u64 region_size)
>> +struct devlink_region *
>> +devlink_region_create(struct devlink *devlink,
>> +		      const struct devlink_region_ops *ops,
>> +		      u32 region_max_snapshots,
>> +		      u64 region_size)
>>  {
>>  	struct devlink_region *region;
>>  
>> -	devl_assert_locked(devlink);
>> +	ASSERT_DEVLINK_NOT_REGISTERED(devlink);
>>  
>>  	if (WARN_ON(!ops) || WARN_ON(!ops->destructor))
>>  		return ERR_PTR(-EINVAL);
>> @@ -11164,35 +11164,9 @@ struct devlink_region *devl_region_create(struct devlink *devlink,
>>  	INIT_LIST_HEAD(&region->snapshot_list);
>>  	mutex_init(&region->snapshot_lock);
>>  	list_add_tail(&region->list, &devlink->region_list);
>> -	devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW);
>>  
>>  	return region;
>>  }
>> -EXPORT_SYMBOL_GPL(devl_region_create);
>> -
>> -/**
>> - *	devlink_region_create - create a new address region
>> - *
>> - *	@devlink: devlink
>> - *	@ops: region operations and name
>> - *	@region_max_snapshots: Maximum supported number of snapshots for region
>> - *	@region_size: size of region
>> - *
>> - *	Context: Takes and release devlink->lock <mutex>.
>> - */
>> -struct devlink_region *
>> -devlink_region_create(struct devlink *devlink,
>> -		      const struct devlink_region_ops *ops,
>> -		      u32 region_max_snapshots, u64 region_size)
>> -{
>> -	struct devlink_region *region;
>> -
>> -	devl_lock(devlink);
>> -	region = devl_region_create(devlink, ops, region_max_snapshots,
>> -				    region_size);
>> -	devl_unlock(devlink);
>> -	return region;
>> -}
>>  EXPORT_SYMBOL_GPL(devlink_region_create);
>>  
>>  /**
>
>Were you on net-next when you generated this patch? Here's what I have
>at 11164:
>
>devlink_port_region_create:
>	if (devlink_port_region_get_by_name(port, ops->name)) {
>		err = -EEXIST;
>		goto unlock;
>	}
>
>	region = kzalloc(sizeof(*region), GFP_KERNEL);
>	if (!region) {
>
>My end of devl_region_create() and start of devlink_region_create() are
>at 11106, but notice how I lack the mutex_init(&region->snapshot_lock)
>that you have in your context:
>
>	INIT_LIST_HEAD(&region->snapshot_list);
>	list_add_tail(&region->list, &devlink->region_list);
>	devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW);
>
>	return region;
>}
>EXPORT_SYMBOL_GPL(devl_region_create);
>
>Would you mind regenerating this patch rather than letting me bodge it?

Darn, wait. I will fixup a squash for you. Sorry.


  reply	other threads:[~2022-07-26 15:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 12:41 [patch net-next RFC] net: dsa: move port_setup/teardown to be called outside devlink port registered area Jiri Pirko
2022-07-26 13:43 ` Vladimir Oltean
2022-07-26 14:45   ` Jiri Pirko
2022-07-26 15:20     ` Vladimir Oltean
2022-07-26 15:57       ` Jiri Pirko [this message]
2022-07-26 16:13         ` Jiri Pirko
2022-07-26 16:55           ` Vladimir Oltean
2022-07-26 18:27             ` Jiri Pirko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YuAPBwaOjjQBTc6V@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox