mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	netdevsim: Forbid devlink reload when adding or deleting ports
In order to remove complexity in devlink core related to devlink_reload_enable/disable, let's rewrite new_port/del_port logic to rely on internal to netdevsim lcok. We should protect only reload_down flow because it destroys nsim_dev, which is needed for nsim_dev_port_add/nsim_dev_port_del to hold port_list_lock. Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									f8b17a0bd9
								
							
						
					
					
						commit
						23809a726c
					
				
					 2 changed files with 11 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -183,8 +183,6 @@ new_port_store(struct device *dev, struct device_attribute *attr,
 | 
			
		|||
	       const char *buf, size_t count)
 | 
			
		||||
{
 | 
			
		||||
	struct nsim_bus_dev *nsim_bus_dev = to_nsim_bus_dev(dev);
 | 
			
		||||
	struct nsim_dev *nsim_dev = dev_get_drvdata(dev);
 | 
			
		||||
	struct devlink *devlink;
 | 
			
		||||
	unsigned int port_index;
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -195,12 +193,10 @@ new_port_store(struct device *dev, struct device_attribute *attr,
 | 
			
		|||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	devlink = priv_to_devlink(nsim_dev);
 | 
			
		||||
	if (!mutex_trylock(&nsim_bus_dev->nsim_bus_reload_lock))
 | 
			
		||||
		return -EBUSY;
 | 
			
		||||
 | 
			
		||||
	mutex_lock(&nsim_bus_dev->nsim_bus_reload_lock);
 | 
			
		||||
	devlink_reload_disable(devlink);
 | 
			
		||||
	ret = nsim_dev_port_add(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index);
 | 
			
		||||
	devlink_reload_enable(devlink);
 | 
			
		||||
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
 | 
			
		||||
	return ret ? ret : count;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -212,8 +208,6 @@ del_port_store(struct device *dev, struct device_attribute *attr,
 | 
			
		|||
	       const char *buf, size_t count)
 | 
			
		||||
{
 | 
			
		||||
	struct nsim_bus_dev *nsim_bus_dev = to_nsim_bus_dev(dev);
 | 
			
		||||
	struct nsim_dev *nsim_dev = dev_get_drvdata(dev);
 | 
			
		||||
	struct devlink *devlink;
 | 
			
		||||
	unsigned int port_index;
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -224,12 +218,10 @@ del_port_store(struct device *dev, struct device_attribute *attr,
 | 
			
		|||
	if (ret)
 | 
			
		||||
		return ret;
 | 
			
		||||
 | 
			
		||||
	devlink = priv_to_devlink(nsim_dev);
 | 
			
		||||
	if (!mutex_trylock(&nsim_bus_dev->nsim_bus_reload_lock))
 | 
			
		||||
		return -EBUSY;
 | 
			
		||||
 | 
			
		||||
	mutex_lock(&nsim_bus_dev->nsim_bus_reload_lock);
 | 
			
		||||
	devlink_reload_disable(devlink);
 | 
			
		||||
	ret = nsim_dev_port_del(nsim_bus_dev, NSIM_DEV_PORT_TYPE_PF, port_index);
 | 
			
		||||
	devlink_reload_enable(devlink);
 | 
			
		||||
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
 | 
			
		||||
	return ret ? ret : count;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -864,16 +864,23 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
 | 
			
		|||
				struct netlink_ext_ack *extack)
 | 
			
		||||
{
 | 
			
		||||
	struct nsim_dev *nsim_dev = devlink_priv(devlink);
 | 
			
		||||
	struct nsim_bus_dev *nsim_bus_dev;
 | 
			
		||||
 | 
			
		||||
	nsim_bus_dev = nsim_dev->nsim_bus_dev;
 | 
			
		||||
	if (!mutex_trylock(&nsim_bus_dev->nsim_bus_reload_lock))
 | 
			
		||||
		return -EOPNOTSUPP;
 | 
			
		||||
 | 
			
		||||
	if (nsim_dev->dont_allow_reload) {
 | 
			
		||||
		/* For testing purposes, user set debugfs dont_allow_reload
 | 
			
		||||
		 * value to true. So forbid it.
 | 
			
		||||
		 */
 | 
			
		||||
		NL_SET_ERR_MSG_MOD(extack, "User forbid the reload for testing purposes");
 | 
			
		||||
		mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
 | 
			
		||||
		return -EOPNOTSUPP;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nsim_dev_reload_destroy(nsim_dev);
 | 
			
		||||
	mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue