bpf: Move offload initialization into late_initcall
authorStanislav Fomichev <sdf@google.com>
Thu, 19 Jan 2023 22:15:22 +0000 (14:15 -0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Mon, 23 Jan 2023 17:38:10 +0000 (09:38 -0800)
So we don't have to initialize it manually from several paths.

Cc: John Fastabend <john.fastabend@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Anatoly Burakov <anatoly.burakov@intel.com>
Cc: Alexander Lobakin <alexandr.lobakin@intel.com>
Cc: Magnus Karlsson <magnus.karlsson@gmail.com>
Cc: Maryam Tahhan <mtahhan@redhat.com>
Cc: xdp-hints@xdp-project.net
Cc: netdev@vger.kernel.org
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230119221536.3349901-4-sdf@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/offload.c

index f5769a8ecbeede7800cbd6be61d545c1c7c36635..621e8738f304f19b7b549c7746ae0a2104061f23 100644 (file)
@@ -56,7 +56,6 @@ static const struct rhashtable_params offdevs_params = {
 };
 
 static struct rhashtable offdevs;
-static bool offdevs_inited;
 
 static int bpf_dev_offload_check(struct net_device *netdev)
 {
@@ -72,8 +71,6 @@ bpf_offload_find_netdev(struct net_device *netdev)
 {
        lockdep_assert_held(&bpf_devs_lock);
 
-       if (!offdevs_inited)
-               return NULL;
        return rhashtable_lookup_fast(&offdevs, &netdev, offdevs_params);
 }
 
@@ -673,18 +670,6 @@ struct bpf_offload_dev *
 bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops, void *priv)
 {
        struct bpf_offload_dev *offdev;
-       int err;
-
-       down_write(&bpf_devs_lock);
-       if (!offdevs_inited) {
-               err = rhashtable_init(&offdevs, &offdevs_params);
-               if (err) {
-                       up_write(&bpf_devs_lock);
-                       return ERR_PTR(err);
-               }
-               offdevs_inited = true;
-       }
-       up_write(&bpf_devs_lock);
 
        offdev = kzalloc(sizeof(*offdev), GFP_KERNEL);
        if (!offdev)
@@ -710,3 +695,10 @@ void *bpf_offload_dev_priv(struct bpf_offload_dev *offdev)
        return offdev->priv;
 }
 EXPORT_SYMBOL_GPL(bpf_offload_dev_priv);
+
+static int __init bpf_offload_init(void)
+{
+       return rhashtable_init(&offdevs, &offdevs_params);
+}
+
+late_initcall(bpf_offload_init);