Skip to content

Commit 7463d3a

Browse files
Boris Pismennydavem330
authored andcommitted
tls: Fix write space handling
TLS device cannot use the sw context. This patch returns the original tls device write space handler and moves the sw/device specific portions to the relevant files. Also, we remove the write_space call for the tls_sw flow, because it handles partial records in its delayed tx work handler. Fixes: a42055e ("net/tls: Add support for async encryption of records for performance") Signed-off-by: Boris Pismenny <borisp@mellanox.com> Reviewed-by: Eran Ben Elisha <eranbe@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9485025 commit 7463d3a

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

include/net/tls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ static inline bool tls_sw_has_ctx_tx(const struct sock *sk)
519519
return !!tls_sw_ctx_tx(ctx);
520520
}
521521

522+
void tls_sw_write_space(struct sock *sk, struct tls_context *ctx);
523+
void tls_device_write_space(struct sock *sk, struct tls_context *ctx);
524+
522525
static inline struct tls_offload_context_rx *
523526
tls_offload_ctx_rx(const struct tls_context *tls_ctx)
524527
{

net/tls/tls_device.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,23 @@ static int tls_device_push_pending_record(struct sock *sk, int flags)
546546
return tls_push_data(sk, &msg_iter, 0, flags, TLS_RECORD_TYPE_DATA);
547547
}
548548

549+
void tls_device_write_space(struct sock *sk, struct tls_context *ctx)
550+
{
551+
int rc = 0;
552+
553+
if (!sk->sk_write_pending && tls_is_partially_sent_record(ctx)) {
554+
gfp_t sk_allocation = sk->sk_allocation;
555+
556+
sk->sk_allocation = GFP_ATOMIC;
557+
rc = tls_push_partial_record(sk, ctx,
558+
MSG_DONTWAIT | MSG_NOSIGNAL);
559+
sk->sk_allocation = sk_allocation;
560+
}
561+
562+
if (!rc)
563+
ctx->sk_write_space(sk);
564+
}
565+
549566
void handle_device_resync(struct sock *sk, u32 seq, u64 rcd_sn)
550567
{
551568
struct tls_context *tls_ctx = tls_get_ctx(sk);

net/tls/tls_main.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ int tls_push_partial_record(struct sock *sk, struct tls_context *ctx,
212212
static void tls_write_space(struct sock *sk)
213213
{
214214
struct tls_context *ctx = tls_get_ctx(sk);
215-
struct tls_sw_context_tx *tx_ctx = tls_sw_ctx_tx(ctx);
216215

217216
/* If in_tcp_sendpages call lower protocol write space handler
218217
* to ensure we wake up any waiting operations there. For example
@@ -223,14 +222,12 @@ static void tls_write_space(struct sock *sk)
223222
return;
224223
}
225224

226-
/* Schedule the transmission if tx list is ready */
227-
if (is_tx_ready(tx_ctx) && !sk->sk_write_pending) {
228-
/* Schedule the transmission */
229-
if (!test_and_set_bit(BIT_TX_SCHEDULED, &tx_ctx->tx_bitmask))
230-
schedule_delayed_work(&tx_ctx->tx_work.work, 0);
231-
}
232-
233-
ctx->sk_write_space(sk);
225+
#ifdef CONFIG_TLS_DEVICE
226+
if (ctx->tx_conf == TLS_HW)
227+
tls_device_write_space(sk, ctx);
228+
else
229+
#endif
230+
tls_sw_write_space(sk, ctx);
234231
}
235232

236233
static void tls_ctx_free(struct tls_context *ctx)

net/tls/tls_sw.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,19 @@ static void tx_work_handler(struct work_struct *work)
21262126
release_sock(sk);
21272127
}
21282128

2129+
void tls_sw_write_space(struct sock *sk, struct tls_context *ctx)
2130+
{
2131+
struct tls_sw_context_tx *tx_ctx = tls_sw_ctx_tx(ctx);
2132+
2133+
/* Schedule the transmission if tx list is ready */
2134+
if (is_tx_ready(tx_ctx) && !sk->sk_write_pending) {
2135+
/* Schedule the transmission */
2136+
if (!test_and_set_bit(BIT_TX_SCHEDULED,
2137+
&tx_ctx->tx_bitmask))
2138+
schedule_delayed_work(&tx_ctx->tx_work.work, 0);
2139+
}
2140+
}
2141+
21292142
int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx)
21302143
{
21312144
struct tls_context *tls_ctx = tls_get_ctx(sk);

0 commit comments

Comments
 (0)