Skip to content

Commit 121dca7

Browse files
kuba-moodavem330
authored andcommitted
tls: suppress wakeups unless we have a full record
TLS does not override .poll() so TLS-enabled socket will generate an event whenever data arrives at the TCP socket. This leads to unnecessary wakeups on slow connections. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a395b8d commit 121dca7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

net/tls/tls_main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,39 @@ static void tls_sk_proto_close(struct sock *sk, long timeout)
358358
tls_ctx_free(sk, ctx);
359359
}
360360

361+
static __poll_t tls_sk_poll(struct file *file, struct socket *sock,
362+
struct poll_table_struct *wait)
363+
{
364+
struct tls_sw_context_rx *ctx;
365+
struct tls_context *tls_ctx;
366+
struct sock *sk = sock->sk;
367+
struct sk_psock *psock;
368+
__poll_t mask = 0;
369+
u8 shutdown;
370+
int state;
371+
372+
mask = tcp_poll(file, sock, wait);
373+
374+
state = inet_sk_state_load(sk);
375+
shutdown = READ_ONCE(sk->sk_shutdown);
376+
if (unlikely(state != TCP_ESTABLISHED || shutdown & RCV_SHUTDOWN))
377+
return mask;
378+
379+
tls_ctx = tls_get_ctx(sk);
380+
ctx = tls_sw_ctx_rx(tls_ctx);
381+
psock = sk_psock_get(sk);
382+
383+
if (skb_queue_empty_lockless(&ctx->rx_list) &&
384+
!tls_strp_msg_ready(ctx) &&
385+
sk_psock_queue_empty(psock))
386+
mask &= ~(EPOLLIN | EPOLLRDNORM);
387+
388+
if (psock)
389+
sk_psock_put(sk, psock);
390+
391+
return mask;
392+
}
393+
361394
static int do_tls_getsockopt_conf(struct sock *sk, char __user *optval,
362395
int __user *optlen, int tx)
363396
{
@@ -928,9 +961,11 @@ static void build_proto_ops(struct proto_ops ops[TLS_NUM_CONFIG][TLS_NUM_CONFIG]
928961

929962
ops[TLS_BASE][TLS_SW ] = ops[TLS_BASE][TLS_BASE];
930963
ops[TLS_BASE][TLS_SW ].splice_read = tls_sw_splice_read;
964+
ops[TLS_BASE][TLS_SW ].poll = tls_sk_poll;
931965

932966
ops[TLS_SW ][TLS_SW ] = ops[TLS_SW ][TLS_BASE];
933967
ops[TLS_SW ][TLS_SW ].splice_read = tls_sw_splice_read;
968+
ops[TLS_SW ][TLS_SW ].poll = tls_sk_poll;
934969

935970
#ifdef CONFIG_TLS_DEVICE
936971
ops[TLS_HW ][TLS_BASE] = ops[TLS_BASE][TLS_BASE];

0 commit comments

Comments
 (0)