Skip to content

Commit a94b5aa

Browse files
author
Alexei Starovoitov
committed
Merge branch 'sock_map: fix ->poll() and update selftests'
Cong Wang says: ==================== This patchset fixes ->poll() for sockets in sockmap and updates selftests accordingly with select(). Please check each patch for more details. Fixes: c50524e ("Merge branch 'sockmap: add sockmap support for unix datagram socket'") Fixes: 89d69c5 ("Merge branch 'sockmap: introduce BPF_SK_SKB_VERDICT and support UDP'") Acked-by: John Fastabend <[email protected]> --- v4: add a comment in udp_poll() v3: drop sk_psock_get_checked() reuse tcp_bpf_sock_is_readable() v2: rename and reuse ->stream_memory_read() fix a compile error in sk_psock_get_checked() Cong Wang (3): net: rename ->stream_memory_read to ->sock_is_readable skmsg: extract and reuse sk_msg_is_readable() net: implement ->sock_is_readable() for UDP and AF_UNIX ==================== Reviewed-by: Jakub Sitnicki <[email protected]> Acked-by: John Fastabend <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents cd9733f + 67b8215 commit a94b5aa

File tree

13 files changed

+58
-78
lines changed

13 files changed

+58
-78
lines changed

include/linux/skmsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from,
128128
struct sk_msg *msg, u32 bytes);
129129
int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
130130
int len, int flags);
131+
bool sk_msg_is_readable(struct sock *sk);
131132

132133
static inline void sk_msg_check_to_free(struct sk_msg *msg, u32 i, u32 bytes)
133134
{

include/net/sock.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ struct proto {
12081208
#endif
12091209

12101210
bool (*stream_memory_free)(const struct sock *sk, int wake);
1211-
bool (*stream_memory_read)(const struct sock *sk);
1211+
bool (*sock_is_readable)(struct sock *sk);
12121212
/* Memory pressure */
12131213
void (*enter_memory_pressure)(struct sock *sk);
12141214
void (*leave_memory_pressure)(struct sock *sk);
@@ -2820,4 +2820,10 @@ void sock_set_sndtimeo(struct sock *sk, s64 secs);
28202820

28212821
int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len);
28222822

2823+
static inline bool sk_is_readable(struct sock *sk)
2824+
{
2825+
if (sk->sk_prot->sock_is_readable)
2826+
return sk->sk_prot->sock_is_readable(sk);
2827+
return false;
2828+
}
28232829
#endif /* _SOCK_H */

include/net/tls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ void tls_sw_release_resources_rx(struct sock *sk);
375375
void tls_sw_free_ctx_rx(struct tls_context *tls_ctx);
376376
int tls_sw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
377377
int nonblock, int flags, int *addr_len);
378-
bool tls_sw_stream_read(const struct sock *sk);
378+
bool tls_sw_sock_is_readable(struct sock *sk);
379379
ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
380380
struct pipe_inode_info *pipe,
381381
size_t len, unsigned int flags);

net/core/skmsg.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,20 @@ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg,
474474
}
475475
EXPORT_SYMBOL_GPL(sk_msg_recvmsg);
476476

477+
bool sk_msg_is_readable(struct sock *sk)
478+
{
479+
struct sk_psock *psock;
480+
bool empty = true;
481+
482+
rcu_read_lock();
483+
psock = sk_psock(sk);
484+
if (likely(psock))
485+
empty = list_empty(&psock->ingress_msg);
486+
rcu_read_unlock();
487+
return !empty;
488+
}
489+
EXPORT_SYMBOL_GPL(sk_msg_is_readable);
490+
477491
static struct sk_msg *sk_psock_create_ingress_msg(struct sock *sk,
478492
struct sk_buff *skb)
479493
{

net/ipv4/tcp.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,7 @@ static bool tcp_stream_is_readable(struct sock *sk, int target)
486486
{
487487
if (tcp_epollin_ready(sk, target))
488488
return true;
489-
490-
if (sk->sk_prot->stream_memory_read)
491-
return sk->sk_prot->stream_memory_read(sk);
492-
return false;
489+
return sk_is_readable(sk);
493490
}
494491

495492
/*

net/ipv4/tcp_bpf.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,6 @@ int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg,
150150
EXPORT_SYMBOL_GPL(tcp_bpf_sendmsg_redir);
151151

152152
#ifdef CONFIG_BPF_SYSCALL
153-
static bool tcp_bpf_stream_read(const struct sock *sk)
154-
{
155-
struct sk_psock *psock;
156-
bool empty = true;
157-
158-
rcu_read_lock();
159-
psock = sk_psock(sk);
160-
if (likely(psock))
161-
empty = list_empty(&psock->ingress_msg);
162-
rcu_read_unlock();
163-
return !empty;
164-
}
165-
166153
static int tcp_msg_wait_data(struct sock *sk, struct sk_psock *psock,
167154
long timeo)
168155
{
@@ -491,7 +478,7 @@ static void tcp_bpf_rebuild_protos(struct proto prot[TCP_BPF_NUM_CFGS],
491478
prot[TCP_BPF_BASE].unhash = sock_map_unhash;
492479
prot[TCP_BPF_BASE].close = sock_map_close;
493480
prot[TCP_BPF_BASE].recvmsg = tcp_bpf_recvmsg;
494-
prot[TCP_BPF_BASE].stream_memory_read = tcp_bpf_stream_read;
481+
prot[TCP_BPF_BASE].sock_is_readable = sk_msg_is_readable;
495482

496483
prot[TCP_BPF_TX] = prot[TCP_BPF_BASE];
497484
prot[TCP_BPF_TX].sendmsg = tcp_bpf_sendmsg;

net/ipv4/udp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,6 +2867,9 @@ __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait)
28672867
!(sk->sk_shutdown & RCV_SHUTDOWN) && first_packet_length(sk) == -1)
28682868
mask &= ~(EPOLLIN | EPOLLRDNORM);
28692869

2870+
/* psock ingress_msg queue should not contain any bad checksum frames */
2871+
if (sk_is_readable(sk))
2872+
mask |= EPOLLIN | EPOLLRDNORM;
28702873
return mask;
28712874

28722875
}

net/ipv4/udp_bpf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static void udp_bpf_rebuild_protos(struct proto *prot, const struct proto *base)
114114
*prot = *base;
115115
prot->close = sock_map_close;
116116
prot->recvmsg = udp_bpf_recvmsg;
117+
prot->sock_is_readable = sk_msg_is_readable;
117118
}
118119

119120
static void udp_bpf_check_v6_needs_rebuild(struct proto *ops)

net/tls/tls_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,12 +681,12 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
681681

682682
prot[TLS_BASE][TLS_SW] = prot[TLS_BASE][TLS_BASE];
683683
prot[TLS_BASE][TLS_SW].recvmsg = tls_sw_recvmsg;
684-
prot[TLS_BASE][TLS_SW].stream_memory_read = tls_sw_stream_read;
684+
prot[TLS_BASE][TLS_SW].sock_is_readable = tls_sw_sock_is_readable;
685685
prot[TLS_BASE][TLS_SW].close = tls_sk_proto_close;
686686

687687
prot[TLS_SW][TLS_SW] = prot[TLS_SW][TLS_BASE];
688688
prot[TLS_SW][TLS_SW].recvmsg = tls_sw_recvmsg;
689-
prot[TLS_SW][TLS_SW].stream_memory_read = tls_sw_stream_read;
689+
prot[TLS_SW][TLS_SW].sock_is_readable = tls_sw_sock_is_readable;
690690
prot[TLS_SW][TLS_SW].close = tls_sk_proto_close;
691691

692692
#ifdef CONFIG_TLS_DEVICE

net/tls/tls_sw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
20262026
return copied ? : err;
20272027
}
20282028

2029-
bool tls_sw_stream_read(const struct sock *sk)
2029+
bool tls_sw_sock_is_readable(struct sock *sk)
20302030
{
20312031
struct tls_context *tls_ctx = tls_get_ctx(sk);
20322032
struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);

0 commit comments

Comments
 (0)