Skip to content

Commit 69ca929

Browse files
Dave Watsondavem330
Dave Watson
authored andcommitted
tls: Generalize zerocopy_from_iter
Refactor zerocopy_from_iter to take arguments for pages and size, such that it can be used for both tx and rx. RX will also support zerocopy direct to output iter, as long as the full message can be copied at once (a large enough userspace buffer was provided). Signed-off-by: Dave Watson <davejwatson@fb.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ae06c70 commit 69ca929

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

net/tls/tls_sw.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,24 @@ static int tls_sw_push_pending_record(struct sock *sk, int flags)
226226
}
227227

228228
static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from,
229-
int length)
229+
int length, int *pages_used,
230+
unsigned int *size_used,
231+
struct scatterlist *to, int to_max_pages,
232+
bool charge)
230233
{
231-
struct tls_context *tls_ctx = tls_get_ctx(sk);
232-
struct tls_sw_context *ctx = tls_sw_ctx(tls_ctx);
233234
struct page *pages[MAX_SKB_FRAGS];
234235

235236
size_t offset;
236237
ssize_t copied, use;
237238
int i = 0;
238-
unsigned int size = ctx->sg_plaintext_size;
239-
int num_elem = ctx->sg_plaintext_num_elem;
239+
unsigned int size = *size_used;
240+
int num_elem = *pages_used;
240241
int rc = 0;
241242
int maxpages;
242243

243244
while (length > 0) {
244245
i = 0;
245-
maxpages = ARRAY_SIZE(ctx->sg_plaintext_data) - num_elem;
246+
maxpages = to_max_pages - num_elem;
246247
if (maxpages == 0) {
247248
rc = -EFAULT;
248249
goto out;
@@ -262,10 +263,11 @@ static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from,
262263
while (copied) {
263264
use = min_t(int, copied, PAGE_SIZE - offset);
264265

265-
sg_set_page(&ctx->sg_plaintext_data[num_elem],
266+
sg_set_page(&to[num_elem],
266267
pages[i], use, offset);
267-
sg_unmark_end(&ctx->sg_plaintext_data[num_elem]);
268-
sk_mem_charge(sk, use);
268+
sg_unmark_end(&to[num_elem]);
269+
if (charge)
270+
sk_mem_charge(sk, use);
269271

270272
offset = 0;
271273
copied -= use;
@@ -276,8 +278,9 @@ static int zerocopy_from_iter(struct sock *sk, struct iov_iter *from,
276278
}
277279

278280
out:
279-
ctx->sg_plaintext_size = size;
280-
ctx->sg_plaintext_num_elem = num_elem;
281+
*size_used = size;
282+
*pages_used = num_elem;
283+
281284
return rc;
282285
}
283286

@@ -374,7 +377,11 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
374377

375378
if (full_record || eor) {
376379
ret = zerocopy_from_iter(sk, &msg->msg_iter,
377-
try_to_copy);
380+
try_to_copy, &ctx->sg_plaintext_num_elem,
381+
&ctx->sg_plaintext_size,
382+
ctx->sg_plaintext_data,
383+
ARRAY_SIZE(ctx->sg_plaintext_data),
384+
true);
378385
if (ret)
379386
goto fallback_to_reg_send;
380387

0 commit comments

Comments
 (0)