vxlan: mdb: Add an internal flag to indicate MDB usage
authorIdo Schimmel <idosch@nvidia.com>
Wed, 15 Mar 2023 13:11:52 +0000 (15:11 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 17 Mar 2023 08:05:49 +0000 (08:05 +0000)
Add an internal flag to indicate whether MDB entries are configured or
not. Set the flag after installing the first MDB entry and clear it
before deleting the last one.

The flag will be consulted by the data path which will only perform an
MDB lookup if the flag is set, thereby keeping the MDB overhead to a
minimum when the MDB is not used.

Another option would have been to use a static key, but it is global and
not per-device, unlike the current approach.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/vxlan/vxlan_mdb.c
include/net/vxlan.h

index 129692b..b32b1fb 100644 (file)
@@ -1185,6 +1185,9 @@ vxlan_mdb_entry_get(struct vxlan_dev *vxlan,
        if (err)
                goto err_free_entry;
 
+       if (hlist_is_singular_node(&mdb_entry->mdb_node, &vxlan->mdb_list))
+               vxlan->cfg.flags |= VXLAN_F_MDB;
+
        return mdb_entry;
 
 err_free_entry:
@@ -1199,6 +1202,9 @@ static void vxlan_mdb_entry_put(struct vxlan_dev *vxlan,
        if (!list_empty(&mdb_entry->remotes))
                return;
 
+       if (hlist_is_singular_node(&mdb_entry->mdb_node, &vxlan->mdb_list))
+               vxlan->cfg.flags &= ~VXLAN_F_MDB;
+
        rhashtable_remove_fast(&vxlan->mdb_tbl, &mdb_entry->rhnode,
                               vxlan_mdb_rht_params);
        hlist_del(&mdb_entry->mdb_node);
@@ -1336,6 +1342,7 @@ int vxlan_mdb_init(struct vxlan_dev *vxlan)
 void vxlan_mdb_fini(struct vxlan_dev *vxlan)
 {
        vxlan_mdb_entries_flush(vxlan);
+       WARN_ON_ONCE(vxlan->cfg.flags & VXLAN_F_MDB);
        rhashtable_free_and_destroy(&vxlan->mdb_tbl, vxlan_mdb_check_empty,
                                    NULL);
 }
index 110b703..b7b2e9a 100644 (file)
@@ -327,6 +327,7 @@ struct vxlan_dev {
 #define VXLAN_F_IPV6_LINKLOCAL         0x8000
 #define VXLAN_F_TTL_INHERIT            0x10000
 #define VXLAN_F_VNIFILTER               0x20000
+#define VXLAN_F_MDB                    0x40000
 
 /* Flags that are used in the receive path. These flags must match in
  * order for a socket to be shareable