inet: move inet->is_icsk to inet->inet_flags
authorEric Dumazet <edumazet@google.com>
Wed, 16 Aug 2023 08:15:42 +0000 (08:15 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 16 Aug 2023 10:09:17 +0000 (11:09 +0100)
We move single bit fields to inet->inet_flags to avoid races.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/inet_connection_sock.h
include/net/inet_sock.h
net/ipv4/af_inet.c
net/ipv4/cipso_ipv4.c
net/ipv4/inet_diag.c
net/ipv4/ip_sockglue.c
net/ipv6/af_inet6.c
net/ipv6/ipv6_sockglue.c

index be3c858..5d2fcc1 100644 (file)
@@ -342,9 +342,9 @@ static inline bool inet_csk_in_pingpong_mode(struct sock *sk)
        return inet_csk(sk)->icsk_ack.pingpong >= TCP_PINGPONG_THRESH;
 }
 
-static inline bool inet_csk_has_ulp(struct sock *sk)
+static inline bool inet_csk_has_ulp(const struct sock *sk)
 {
-       return inet_sk(sk)->is_icsk && !!inet_csk(sk)->icsk_ulp_ops;
+       return inet_test_bit(IS_ICSK, sk) && !!inet_csk(sk)->icsk_ulp_ops;
 }
 
 #endif /* _INET_CONNECTION_SOCK_H */
index cefd9a6..38f7fc1 100644 (file)
@@ -201,7 +201,6 @@ struct rtable;
  * @inet_id - ID counter for DF pkts
  * @tos - TOS
  * @mc_ttl - Multicasting TTL
- * @is_icsk - is this an inet_connection_sock?
  * @uc_index - Unicast outgoing device index
  * @mc_index - Multicast device index
  * @mc_list - Group array
@@ -230,8 +229,7 @@ struct inet_sock {
        __u8                    min_ttl;
        __u8                    mc_ttl;
        __u8                    pmtudisc;
-       __u8                    is_icsk:1,
-                               nodefrag:1;
+       __u8                    nodefrag:1;
        __u8                    bind_address_no_port:1,
                                defer_connect:1; /* Indicates that fastopen_connect is set
                                                  * and cookie exists so we defer connect
@@ -271,6 +269,7 @@ enum {
        INET_FLAGS_MC_LOOP      = 13,
        INET_FLAGS_MC_ALL       = 14,
        INET_FLAGS_TRANSPARENT  = 15,
+       INET_FLAGS_IS_ICSK      = 16,
 };
 
 /* cmsg flags for inet */
index 47c9cdd..0f46b71 100644 (file)
@@ -331,7 +331,7 @@ lookup_protocol:
                sk->sk_reuse = SK_CAN_REUSE;
 
        inet = inet_sk(sk);
-       inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
+       inet_assign_bit(IS_ICSK, sk, INET_PROTOSW_ICSK & answer_flags);
 
        inet->nodefrag = 0;
 
index 79ae720..d048aa8 100644 (file)
@@ -1881,7 +1881,7 @@ int cipso_v4_sock_setattr(struct sock *sk,
 
        old = rcu_dereference_protected(sk_inet->inet_opt,
                                        lockdep_sock_is_held(sk));
-       if (sk_inet->is_icsk) {
+       if (inet_test_bit(IS_ICSK, sk)) {
                sk_conn = inet_csk(sk);
                if (old)
                        sk_conn->icsk_ext_hdr_len -= old->opt.optlen;
@@ -2051,7 +2051,7 @@ void cipso_v4_sock_delattr(struct sock *sk)
        sk_inet = inet_sk(sk);
 
        hdr_delta = cipso_v4_delopt(&sk_inet->inet_opt);
-       if (sk_inet->is_icsk && hdr_delta > 0) {
+       if (inet_test_bit(IS_ICSK, sk) && hdr_delta > 0) {
                struct inet_connection_sock *sk_conn = inet_csk(sk);
                sk_conn->icsk_ext_hdr_len -= hdr_delta;
                sk_conn->icsk_sync_mss(sk, sk_conn->icsk_pmtu_cookie);
index 45fefd2..ada198f 100644 (file)
@@ -183,7 +183,7 @@ int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
 
        memset(&inet_sockopt, 0, sizeof(inet_sockopt));
        inet_sockopt.recverr    = inet_test_bit(RECVERR, sk);
-       inet_sockopt.is_icsk    = inet->is_icsk;
+       inet_sockopt.is_icsk    = inet_test_bit(IS_ICSK, sk);
        inet_sockopt.freebind   = inet_test_bit(FREEBIND, sk);
        inet_sockopt.hdrincl    = inet_test_bit(HDRINCL, sk);
        inet_sockopt.mc_loop    = inet_test_bit(MC_LOOP, sk);
index 3f5323a..dac471e 100644 (file)
@@ -1034,7 +1034,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
                        break;
                old = rcu_dereference_protected(inet->inet_opt,
                                                lockdep_sock_is_held(sk));
-               if (inet->is_icsk) {
+               if (inet_test_bit(IS_ICSK, sk)) {
                        struct inet_connection_sock *icsk = inet_csk(sk);
 #if IS_ENABLED(CONFIG_IPV6)
                        if (sk->sk_family == PF_INET ||
@@ -1209,7 +1209,7 @@ int do_ip_setsockopt(struct sock *sk, int level, int optname,
                struct ip_mreqn mreq;
 
                err = -EPROTO;
-               if (inet_sk(sk)->is_icsk)
+               if (inet_test_bit(IS_ICSK, sk))
                        break;
 
                if (optlen < sizeof(struct ip_mreq))
index 8e9d4c1..d8c56c7 100644 (file)
@@ -200,7 +200,7 @@ lookup_protocol:
                sk->sk_reuse = SK_CAN_REUSE;
 
        inet = inet_sk(sk);
-       inet->is_icsk = (INET_PROTOSW_ICSK & answer_flags) != 0;
+       inet_assign_bit(IS_ICSK, sk, INET_PROTOSW_ICSK & answer_flags);
 
        if (SOCK_RAW == sock->type) {
                inet->inet_num = protocol;
index eb33412..d19577a 100644 (file)
@@ -102,7 +102,7 @@ int ip6_ra_control(struct sock *sk, int sel)
 struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
                                           struct ipv6_txoptions *opt)
 {
-       if (inet_sk(sk)->is_icsk) {
+       if (inet_test_bit(IS_ICSK, sk)) {
                if (opt &&
                    !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
                    inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) {
@@ -831,7 +831,7 @@ done:
                        goto e_inval;
 
                retv = -EPROTO;
-               if (inet_sk(sk)->is_icsk)
+               if (inet_test_bit(IS_ICSK, sk))
                        break;
 
                retv = -EFAULT;