]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fou: Store struct sock in struct fou.
authorKuniyuki Iwashima <kuniyu@google.com>
Sat, 2 May 2026 03:13:04 +0000 (03:13 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 6 May 2026 00:47:05 +0000 (17:47 -0700)
fou does not need to access struct socket itself in the fast
path; it only reads struct sock, and struct socket is only used
for tunnel setup and teardown.

Let's store struct sock directly in struct fou.

fou_release() frees struct fou with kfree_rcu(), so fou no
longer needs synchronize_rcu() in udp_tunnel_sock_release().

Note that the error path in fou_create() looks buggy; once the
tunnel is set up and fou_add_to_port_list() fails, struct fou
should be freed with kfree_rcu() _after_ udp_tunnel_sock_release().

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260502031401.3557229-12-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/fou_core.c

index 6bed0e1dbe0e9a2f59f7193428e1f85197fb5541..865bd7205122d20c16fa17ee5518571653d6d12d 100644 (file)
@@ -22,7 +22,7 @@
 #include "fou_nl.h"
 
 struct fou {
-       struct socket *sock;
+       struct sock *sk;
        u8 protocol;
        u8 flags;
        __be16 port;
@@ -508,8 +508,8 @@ out:
 
 static bool fou_cfg_cmp(struct fou *fou, struct fou_cfg *cfg)
 {
-       struct sock *sk = fou->sock->sk;
        struct udp_port_cfg *udp_cfg = &cfg->udp_config;
+       struct sock *sk = fou->sk;
 
        if (fou->family != udp_cfg->family ||
            fou->port != udp_cfg->local_udp_port ||
@@ -559,7 +559,7 @@ static int fou_add_to_port_list(struct net *net, struct fou *fou,
 static void fou_release(struct fou *fou)
 {
        list_del(&fou->list);
-       udp_tunnel_sock_release(fou->sock->sk);
+       udp_tunnel_sock_release(fou->sk);
        kfree_rcu(fou, rcu);
 }
 
@@ -590,7 +590,7 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
        fou->family = cfg->udp_config.family;
        fou->flags = cfg->flags;
        fou->type = cfg->type;
-       fou->sock = sock;
+       fou->sk = sk;
 
        memset(&tunnel_cfg, 0, sizeof(tunnel_cfg));
        tunnel_cfg.encap_type = 1;
@@ -776,9 +776,9 @@ int fou_nl_del_doit(struct sk_buff *skb, struct genl_info *info)
 
 static int fou_fill_info(struct fou *fou, struct sk_buff *msg)
 {
-       struct sock *sk = fou->sock->sk;
+       struct sock *sk = fou->sk;
 
-       if (nla_put_u8(msg, FOU_ATTR_AF, fou->sock->sk->sk_family) ||
+       if (nla_put_u8(msg, FOU_ATTR_AF, sk->sk_family) ||
            nla_put_be16(msg, FOU_ATTR_PORT, fou->port) ||
            nla_put_be16(msg, FOU_ATTR_PEER_PORT, sk->sk_dport) ||
            nla_put_u8(msg, FOU_ATTR_IPPROTO, fou->protocol) ||
@@ -790,7 +790,7 @@ static int fou_fill_info(struct fou *fou, struct sk_buff *msg)
                if (nla_put_flag(msg, FOU_ATTR_REMCSUM_NOPARTIAL))
                        return -1;
 
-       if (fou->sock->sk->sk_family == AF_INET) {
+       if (sk->sk_family == AF_INET) {
                if (nla_put_in_addr(msg, FOU_ATTR_LOCAL_V4, sk->sk_rcv_saddr))
                        return -1;