]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: Add net_passive_inc() and net_passive_dec().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Mon, 17 Feb 2025 19:11:27 +0000 (11:11 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 19 Feb 2025 02:33:29 +0000 (18:33 -0800)
net_drop_ns() is NULL when CONFIG_NET_NS is disabled.

The next patch introduces a function that increments
and decrements net->passive.

As a prep, let's rename and export net_free() to
net_passive_dec() and add net_passive_inc().

Suggested-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/netdev/CANn89i+oUCt2VGvrbrweniTendZFEh+nwS=uonc004-aPkWy-Q@mail.gmail.com/
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250217191129.19967-2-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/net_namespace.h
net/core/net_namespace.c

index 7ba1402ca7796663bed3373b1a0c6a0249cd1599..f467a66abc6b16b690a99037a3dea2e355910661 100644 (file)
@@ -297,6 +297,7 @@ static inline int check_net(const struct net *net)
 }
 
 void net_drop_ns(void *);
+void net_passive_dec(struct net *net);
 
 #else
 
@@ -326,8 +327,18 @@ static inline int check_net(const struct net *net)
 }
 
 #define net_drop_ns NULL
+
+static inline void net_passive_dec(struct net *net)
+{
+       refcount_dec(&net->passive);
+}
 #endif
 
+static inline void net_passive_inc(struct net *net)
+{
+       refcount_inc(&net->passive);
+}
+
 /* Returns true if the netns initialization is completed successfully */
 static inline bool net_initialized(const struct net *net)
 {
index cb39a12b2f8295c605f08b5589932932150a1644..4303f2a4926243e2c0ff0c0387383cd8e0658019 100644 (file)
@@ -464,7 +464,7 @@ static void net_complete_free(void)
 
 }
 
-static void net_free(struct net *net)
+void net_passive_dec(struct net *net)
 {
        if (refcount_dec_and_test(&net->passive)) {
                kfree(rcu_access_pointer(net->gen));
@@ -482,7 +482,7 @@ void net_drop_ns(void *p)
        struct net *net = (struct net *)p;
 
        if (net)
-               net_free(net);
+               net_passive_dec(net);
 }
 
 struct net *copy_net_ns(unsigned long flags,
@@ -523,7 +523,7 @@ put_userns:
                key_remove_domain(net->key_domain);
 #endif
                put_user_ns(user_ns);
-               net_free(net);
+               net_passive_dec(net);
 dec_ucounts:
                dec_net_namespaces(ucounts);
                return ERR_PTR(rv);
@@ -672,7 +672,7 @@ static void cleanup_net(struct work_struct *work)
                key_remove_domain(net->key_domain);
 #endif
                put_user_ns(net->user_ns);
-               net_free(net);
+               net_passive_dec(net);
        }
        cleanup_net_task = NULL;
 }