From f901cbd38f0e76d11c21a6088c56b039252b2aa9 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 15 Jan 2024 11:37:43 +0000 Subject: [PATCH] Revert "udp: introduce udp->udp_flags" This reverts commit e2a4392b61f6ddae212dc8a04e58391eb6ce34df which is commit 81b36803ac139827538ac5ce4028e750a3c53f53 upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: Ifd6188fc3dafa78a2c045f1f9c668a2584b2d970 Signed-off-by: Greg Kroah-Hartman --- include/linux/udp.h | 28 +++++++--------------------- net/ipv4/udp.c | 12 ++++++------ net/ipv6/udp.c | 6 +++--- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/include/linux/udp.h b/include/linux/udp.h index 10b56b8231e3..e96da4157d04 100644 --- a/include/linux/udp.h +++ b/include/linux/udp.h @@ -30,20 +30,14 @@ static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask) return (num + net_hash_mix(net)) & mask; } -enum { - UDP_FLAGS_CORK, /* Cork is required */ -}; - struct udp_sock { /* inet_sock has to be the first member */ struct inet_sock inet; #define udp_port_hash inet.sk.__sk_common.skc_u16hashes[0] #define udp_portaddr_hash inet.sk.__sk_common.skc_u16hashes[1] #define udp_portaddr_node inet.sk.__sk_common.skc_portaddr_node - - unsigned long udp_flags; - int pending; /* Any pending frames ? */ + unsigned int corkflag; /* Cork is required */ __u8 encap_type; /* Is this an Encapsulation socket? */ unsigned char no_check6_tx:1,/* Send zero UDP6 checksums on TX? */ no_check6_rx:1,/* Allow zero UDP6 checksums on RX? */ @@ -55,11 +49,6 @@ struct udp_sock { gro_enabled:1, /* Request GRO aggregation */ accept_udp_l4:1, accept_udp_fraglist:1; -/* indicator bits used by pcflag: */ -#define UDPLITE_BIT 0x1 /* set by udplite proto init function */ -#define UDPLITE_SEND_CC 0x2 /* set via udplite setsockopt */ -#define UDPLITE_RECV_CC 0x4 /* set via udplite setsocktopt */ - __u8 pcflag; /* marks socket as UDP-Lite if > 0 */ /* * Following member retains the information to create a UDP header * when the socket is uncorked. @@ -71,6 +60,12 @@ struct udp_sock { */ __u16 pcslen; __u16 pcrlen; +/* indicator bits used by pcflag: */ +#define UDPLITE_BIT 0x1 /* set by udplite proto init function */ +#define UDPLITE_SEND_CC 0x2 /* set via udplite setsockopt */ +#define UDPLITE_RECV_CC 0x4 /* set via udplite setsocktopt */ + __u8 pcflag; /* marks socket as UDP-Lite if > 0 */ + __u8 unused[3]; /* * For encapsulation sockets. */ @@ -94,15 +89,6 @@ struct udp_sock { int forward_deficit; }; -#define udp_test_bit(nr, sk) \ - test_bit(UDP_FLAGS_##nr, &udp_sk(sk)->udp_flags) -#define udp_set_bit(nr, sk) \ - set_bit(UDP_FLAGS_##nr, &udp_sk(sk)->udp_flags) -#define udp_clear_bit(nr, sk) \ - clear_bit(UDP_FLAGS_##nr, &udp_sk(sk)->udp_flags) -#define udp_assign_bit(nr, sk, val) \ - assign_bit(UDP_FLAGS_##nr, &udp_sk(sk)->udp_flags, val) - #define UDP_MAX_SEGMENTS (1 << 6UL) static inline struct udp_sock *udp_sk(const struct sock *sk) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 60a754477efb..e8dd2880ac9a 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1068,7 +1068,7 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) __be16 dport; u8 tos; int err, is_udplite = IS_UDPLITE(sk); - int corkreq = udp_test_bit(CORK, sk) || msg->msg_flags & MSG_MORE; + int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE; int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); struct sk_buff *skb; struct ip_options_data opt_copy; @@ -1337,11 +1337,11 @@ void udp_splice_eof(struct socket *sock) struct sock *sk = sock->sk; struct udp_sock *up = udp_sk(sk); - if (!up->pending || udp_test_bit(CORK, sk)) + if (!up->pending || READ_ONCE(up->corkflag)) return; lock_sock(sk); - if (up->pending && !udp_test_bit(CORK, sk)) + if (up->pending && !READ_ONCE(up->corkflag)) udp_push_pending_frames(sk); release_sock(sk); } @@ -2673,9 +2673,9 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname, switch (optname) { case UDP_CORK: if (val != 0) { - udp_set_bit(CORK, sk); + WRITE_ONCE(up->corkflag, 1); } else { - udp_clear_bit(CORK, sk); + WRITE_ONCE(up->corkflag, 0); lock_sock(sk); push_pending_frames(sk); release_sock(sk); @@ -2800,7 +2800,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname, switch (optname) { case UDP_CORK: - val = udp_test_bit(CORK, sk); + val = READ_ONCE(up->corkflag); break; case UDP_ENCAP: diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 85653e3a04fe..2a65136dca77 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -1351,7 +1351,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int addr_len = msg->msg_namelen; bool connected = false; int ulen = len; - int corkreq = udp_test_bit(CORK, sk) || msg->msg_flags & MSG_MORE; + int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE; int err; int is_udplite = IS_UDPLITE(sk); int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); @@ -1662,11 +1662,11 @@ static void udpv6_splice_eof(struct socket *sock) struct sock *sk = sock->sk; struct udp_sock *up = udp_sk(sk); - if (!up->pending || udp_test_bit(CORK, sk)) + if (!up->pending || READ_ONCE(up->corkflag)) return; lock_sock(sk); - if (up->pending && !udp_test_bit(CORK, sk)) + if (up->pending && !READ_ONCE(up->corkflag)) udp_v6_push_pending_frames(sk); release_sock(sk); }