Skip to content

Commit ebe6420

Browse files
idoschPaolo Abeni
authored andcommitted
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 <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 5cde39e commit ebe6420

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ static inline struct hlist_head *vxlan_fdb_head(struct vxlan_dev *vxlan,
409409
}
410410

411411
/* Look up Ethernet address in forwarding table */
412-
static struct vxlan_fdb *__vxlan_find_mac(struct vxlan_dev *vxlan,
413-
const u8 *mac, __be32 vni)
412+
static struct vxlan_fdb *vxlan_find_mac_rcu(struct vxlan_dev *vxlan,
413+
const u8 *mac, __be32 vni)
414414
{
415415
struct hlist_head *head = vxlan_fdb_head(vxlan, mac, vni);
416416
struct vxlan_fdb *f;
@@ -434,7 +434,7 @@ static struct vxlan_fdb *vxlan_find_mac_tx(struct vxlan_dev *vxlan,
434434
{
435435
struct vxlan_fdb *f;
436436

437-
f = __vxlan_find_mac(vxlan, mac, vni);
437+
f = vxlan_find_mac_rcu(vxlan, mac, vni);
438438
if (f) {
439439
unsigned long now = jiffies;
440440

@@ -445,6 +445,20 @@ static struct vxlan_fdb *vxlan_find_mac_tx(struct vxlan_dev *vxlan,
445445
return f;
446446
}
447447

448+
static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan,
449+
const u8 *mac, __be32 vni)
450+
{
451+
struct vxlan_fdb *f;
452+
453+
lockdep_assert_held_once(&vxlan->hash_lock);
454+
455+
rcu_read_lock();
456+
f = vxlan_find_mac_rcu(vxlan, mac, vni);
457+
rcu_read_unlock();
458+
459+
return f;
460+
}
461+
448462
/* caller should hold vxlan->hash_lock */
449463
static struct vxlan_rdst *vxlan_fdb_find_rdst(struct vxlan_fdb *f,
450464
union vxlan_addr *ip, __be16 port,
@@ -480,7 +494,7 @@ int vxlan_fdb_find_uc(struct net_device *dev, const u8 *mac, __be32 vni,
480494

481495
rcu_read_lock();
482496

483-
f = __vxlan_find_mac(vxlan, eth_addr, vni);
497+
f = vxlan_find_mac_rcu(vxlan, eth_addr, vni);
484498
if (!f) {
485499
rc = -ENOENT;
486500
goto out;
@@ -1117,7 +1131,7 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan,
11171131
{
11181132
struct vxlan_fdb *f;
11191133

1120-
f = __vxlan_find_mac(vxlan, mac, src_vni);
1134+
f = vxlan_find_mac(vxlan, mac, src_vni);
11211135
if (f) {
11221136
if (flags & NLM_F_EXCL) {
11231137
netdev_dbg(vxlan->dev,
@@ -1286,7 +1300,7 @@ int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
12861300
struct vxlan_fdb *f;
12871301
int err = -ENOENT;
12881302

1289-
f = __vxlan_find_mac(vxlan, addr, src_vni);
1303+
f = vxlan_find_mac(vxlan, addr, src_vni);
12901304
if (!f)
12911305
return err;
12921306

@@ -1409,7 +1423,7 @@ static int vxlan_fdb_get(struct sk_buff *skb,
14091423

14101424
rcu_read_lock();
14111425

1412-
f = __vxlan_find_mac(vxlan, addr, vni);
1426+
f = vxlan_find_mac_rcu(vxlan, addr, vni);
14131427
if (!f) {
14141428
NL_SET_ERR_MSG(extack, "Fdb entry not found");
14151429
err = -ENOENT;
@@ -1445,7 +1459,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev,
14451459
ifindex = src_ifindex;
14461460
#endif
14471461

1448-
f = __vxlan_find_mac(vxlan, src_mac, vni);
1462+
f = vxlan_find_mac_rcu(vxlan, src_mac, vni);
14491463
if (likely(f)) {
14501464
struct vxlan_rdst *rdst = first_remote_rcu(f);
14511465
unsigned long now = jiffies;
@@ -4727,7 +4741,7 @@ vxlan_fdb_offloaded_set(struct net_device *dev,
47274741

47284742
spin_lock_bh(&vxlan->hash_lock);
47294743

4730-
f = __vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni);
4744+
f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni);
47314745
if (!f)
47324746
goto out;
47334747

@@ -4779,7 +4793,7 @@ vxlan_fdb_external_learn_del(struct net_device *dev,
47794793

47804794
spin_lock_bh(&vxlan->hash_lock);
47814795

4782-
f = __vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni);
4796+
f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni);
47834797
if (!f)
47844798
err = -ENOENT;
47854799
else if (f->flags & NTF_EXT_LEARNED)

0 commit comments

Comments
 (0)