Skip to content

Commit 924ad65

Browse files
jrfastabAlexei Starovoitov
authored andcommitted
tls: replace poll implementation with read hook
Instead of re-implementing poll routine use the poll callback to trigger read from kTLS, we reuse the stream_memory_read callback which is simpler and achieves the same. This helps to align sockmap and kTLS so we can more easily embed BPF in kTLS. Joint work with Daniel. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent d829e9c commit 924ad65

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

include/net/tls.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ struct tls_sw_context_rx {
142142

143143
struct strparser strp;
144144
void (*saved_data_ready)(struct sock *sk);
145-
unsigned int (*sk_poll)(struct file *file, struct socket *sock,
146-
struct poll_table_struct *wait);
145+
147146
struct sk_buff *recv_pkt;
148147
u8 control;
149148
bool decrypted;
@@ -272,8 +271,7 @@ void tls_sw_free_resources_rx(struct sock *sk);
272271
void tls_sw_release_resources_rx(struct sock *sk);
273272
int tls_sw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
274273
int nonblock, int flags, int *addr_len);
275-
unsigned int tls_sw_poll(struct file *file, struct socket *sock,
276-
struct poll_table_struct *wait);
274+
bool tls_sw_stream_read(const struct sock *sk);
277275
ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
278276
struct pipe_inode_info *pipe,
279277
size_t len, unsigned int flags);

net/tls/tls_main.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,14 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG],
620620
prot[TLS_SW][TLS_BASE].sendpage = tls_sw_sendpage;
621621

622622
prot[TLS_BASE][TLS_SW] = prot[TLS_BASE][TLS_BASE];
623-
prot[TLS_BASE][TLS_SW].recvmsg = tls_sw_recvmsg;
624-
prot[TLS_BASE][TLS_SW].close = tls_sk_proto_close;
623+
prot[TLS_BASE][TLS_SW].recvmsg = tls_sw_recvmsg;
624+
prot[TLS_BASE][TLS_SW].stream_memory_read = tls_sw_stream_read;
625+
prot[TLS_BASE][TLS_SW].close = tls_sk_proto_close;
625626

626627
prot[TLS_SW][TLS_SW] = prot[TLS_SW][TLS_BASE];
627-
prot[TLS_SW][TLS_SW].recvmsg = tls_sw_recvmsg;
628-
prot[TLS_SW][TLS_SW].close = tls_sk_proto_close;
628+
prot[TLS_SW][TLS_SW].recvmsg = tls_sw_recvmsg;
629+
prot[TLS_SW][TLS_SW].stream_memory_read = tls_sw_stream_read;
630+
prot[TLS_SW][TLS_SW].close = tls_sk_proto_close;
629631

630632
#ifdef CONFIG_TLS_DEVICE
631633
prot[TLS_HW][TLS_BASE] = prot[TLS_BASE][TLS_BASE];
@@ -724,7 +726,6 @@ static int __init tls_register(void)
724726
build_protos(tls_prots[TLSV4], &tcp_prot);
725727

726728
tls_sw_proto_ops = inet_stream_ops;
727-
tls_sw_proto_ops.poll = tls_sw_poll;
728729
tls_sw_proto_ops.splice_read = tls_sw_splice_read;
729730

730731
#ifdef CONFIG_TLS_DEVICE

net/tls/tls_sw.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,23 +1352,15 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
13521352
return copied ? : err;
13531353
}
13541354

1355-
unsigned int tls_sw_poll(struct file *file, struct socket *sock,
1356-
struct poll_table_struct *wait)
1355+
bool tls_sw_stream_read(const struct sock *sk)
13571356
{
1358-
unsigned int ret;
1359-
struct sock *sk = sock->sk;
13601357
struct tls_context *tls_ctx = tls_get_ctx(sk);
13611358
struct tls_sw_context_rx *ctx = tls_sw_ctx_rx(tls_ctx);
13621359

1363-
/* Grab POLLOUT and POLLHUP from the underlying socket */
1364-
ret = ctx->sk_poll(file, sock, wait);
1365-
1366-
/* Clear POLLIN bits, and set based on recv_pkt */
1367-
ret &= ~(POLLIN | POLLRDNORM);
13681360
if (ctx->recv_pkt)
1369-
ret |= POLLIN | POLLRDNORM;
1361+
return true;
13701362

1371-
return ret;
1363+
return false;
13721364
}
13731365

13741366
static int tls_read_size(struct strparser *strp, struct sk_buff *skb)
@@ -1686,8 +1678,6 @@ int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
16861678
sk->sk_data_ready = tls_data_ready;
16871679
write_unlock_bh(&sk->sk_callback_lock);
16881680

1689-
sw_ctx_rx->sk_poll = sk->sk_socket->ops->poll;
1690-
16911681
strp_check_rcv(&sw_ctx_rx->strp);
16921682
}
16931683

0 commit comments

Comments
 (0)