mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	vxlan: Create wrappers for FDB lookup
__vxlan_find_mac() is called from both the data path (e.g., during learning) and the control path (e.g., when replacing an entry). The function is missing lockdep annotations to make sure that the FDB hash lock is held during FDB updates. Rename __vxlan_find_mac() to vxlan_find_mac_rcu() to reflect the fact that it should be called from an RCU read-side critical section and call it from vxlan_find_mac() which checks that the FDB hash lock is held. Change callers to invoke the appropriate function. Reviewed-by: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20250415121143.345227-13-idosch@nvidia.com Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
		
							parent
							
								
									5cde39ea38
								
							
						
					
					
						commit
						ebe6420674
					
				
					 1 changed files with 24 additions and 10 deletions
				
			
		|  | @ -409,8 +409,8 @@ static inline struct hlist_head *vxlan_fdb_head(struct vxlan_dev *vxlan, | |||
| } | ||||
| 
 | ||||
| /* Look up Ethernet address in forwarding table */ | ||||
| static struct vxlan_fdb *__vxlan_find_mac(struct vxlan_dev *vxlan, | ||||
| 					  const u8 *mac, __be32 vni) | ||||
| static struct vxlan_fdb *vxlan_find_mac_rcu(struct vxlan_dev *vxlan, | ||||
| 					    const u8 *mac, __be32 vni) | ||||
| { | ||||
| 	struct hlist_head *head = vxlan_fdb_head(vxlan, mac, vni); | ||||
| 	struct vxlan_fdb *f; | ||||
|  | @ -434,7 +434,7 @@ static struct vxlan_fdb *vxlan_find_mac_tx(struct vxlan_dev *vxlan, | |||
| { | ||||
| 	struct vxlan_fdb *f; | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, mac, vni); | ||||
| 	f = vxlan_find_mac_rcu(vxlan, mac, vni); | ||||
| 	if (f) { | ||||
| 		unsigned long now = jiffies; | ||||
| 
 | ||||
|  | @ -445,6 +445,20 @@ static struct vxlan_fdb *vxlan_find_mac_tx(struct vxlan_dev *vxlan, | |||
| 	return f; | ||||
| } | ||||
| 
 | ||||
| static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan, | ||||
| 					const u8 *mac, __be32 vni) | ||||
| { | ||||
| 	struct vxlan_fdb *f; | ||||
| 
 | ||||
| 	lockdep_assert_held_once(&vxlan->hash_lock); | ||||
| 
 | ||||
| 	rcu_read_lock(); | ||||
| 	f = vxlan_find_mac_rcu(vxlan, mac, vni); | ||||
| 	rcu_read_unlock(); | ||||
| 
 | ||||
| 	return f; | ||||
| } | ||||
| 
 | ||||
| /* caller should hold vxlan->hash_lock */ | ||||
| static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f, | ||||
| 					      union vxlan_addr *ip, __be16 port, | ||||
|  | @ -480,7 +494,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni, | |||
| 
 | ||||
| 	rcu_read_lock(); | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, eth_addr, vni); | ||||
| 	f = vxlan_find_mac_rcu(vxlan, eth_addr, vni); | ||||
| 	if (!f) { | ||||
| 		rc = -ENOENT; | ||||
| 		goto out; | ||||
|  | @ -1117,7 +1131,7 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan, | |||
| { | ||||
| 	struct vxlan_fdb *f; | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, mac, src_vni); | ||||
| 	f = vxlan_find_mac(vxlan, mac, src_vni); | ||||
| 	if (f) { | ||||
| 		if (flags & NLM_F_EXCL) { | ||||
| 			netdev_dbg(vxlan->dev, | ||||
|  | @ -1286,7 +1300,7 @@ int __vxlan_fdb_delete(struct vxlan_dev *vxlan, | |||
| 	struct vxlan_fdb *f; | ||||
| 	int err = -ENOENT; | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, addr, src_vni); | ||||
| 	f = vxlan_find_mac(vxlan, addr, src_vni); | ||||
| 	if (!f) | ||||
| 		return err; | ||||
| 
 | ||||
|  | @ -1409,7 +1423,7 @@ static int vxlan_fdb_get(struct sk_buff *skb, | |||
| 
 | ||||
| 	rcu_read_lock(); | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, addr, vni); | ||||
| 	f = vxlan_find_mac_rcu(vxlan, addr, vni); | ||||
| 	if (!f) { | ||||
| 		NL_SET_ERR_MSG(extack, "Fdb entry not found"); | ||||
| 		err = -ENOENT; | ||||
|  | @ -1445,7 +1459,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev, | |||
| 		ifindex = src_ifindex; | ||||
| #endif | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, src_mac, vni); | ||||
| 	f = vxlan_find_mac_rcu(vxlan, src_mac, vni); | ||||
| 	if (likely(f)) { | ||||
| 		struct vxlan_rdst *rdst = first_remote_rcu(f); | ||||
| 		unsigned long now = jiffies; | ||||
|  | @ -4727,7 +4741,7 @@ vxlan_fdb_offloaded_set(struct net_device *dev, | |||
| 
 | ||||
| 	spin_lock_bh(&vxlan->hash_lock); | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); | ||||
| 	f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); | ||||
| 	if (!f) | ||||
| 		goto out; | ||||
| 
 | ||||
|  | @ -4779,7 +4793,7 @@ vxlan_fdb_external_learn_del(struct net_device *dev, | |||
| 
 | ||||
| 	spin_lock_bh(&vxlan->hash_lock); | ||||
| 
 | ||||
| 	f = __vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); | ||||
| 	f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); | ||||
| 	if (!f) | ||||
| 		err = -ENOENT; | ||||
| 	else if (f->flags & NTF_EXT_LEARNED) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Ido Schimmel
						Ido Schimmel