* [PATCH net-next] tls: Skip zerocopy path for ITER_KVEC
@ 2018-07-20 18:19 Doron Roberts-Kedes
2018-07-24 21:38 ` David Miller
2018-07-25 21:48 ` [PATCH net-next v2] " Doron Roberts-Kedes
0 siblings, 2 replies; 4+ messages in thread
From: Doron Roberts-Kedes @ 2018-07-20 18:19 UTC (permalink / raw)
To: David S . Miller; +Cc: Dave Watson, netdev, Doron Roberts-Kedes
The zerocopy path ultimately calls iov_iter_get_pages, which defines the
step function for ITER_KVECs as simply, return -EFAULT. Taking the
non-zerocopy path for ITER_KVECs avoids the unnecessary fallback.
See https://lore.kernel.org/lkml/20150401023311.GL29656@ZenIV.linux.org.uk/T/#u
for a discussion of why zerocopy for vmalloc data is not a good idea.
Discovered while testing NBD traffic encrypted with ktls.
Fixes: c46234ebb4d1 ("tls: RX path for ktls")
Signed-off-by: Doron Roberts-Kedes <doronrk@fb.com>
---
net/tls/tls_sw.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 4618f1c31137..ef15e35232dd 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -426,7 +426,8 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
full_record = true;
}
- if (full_record || eor) {
+ bool iskvec = msg->msg_iter.type & ITER_KVEC;
+ if (!iskvec && (full_record || eor)) {
ret = zerocopy_from_iter(sk, &msg->msg_iter,
try_to_copy, &ctx->sg_plaintext_num_elem,
&ctx->sg_plaintext_size,
@@ -804,7 +805,8 @@ int tls_sw_recvmsg(struct sock *sk,
page_count = iov_iter_npages(&msg->msg_iter,
MAX_SKB_FRAGS);
to_copy = rxm->full_len - tls_ctx->rx.overhead_size;
- if (to_copy <= len && page_count < MAX_SKB_FRAGS &&
+ bool iskvec = msg->msg_iter.type & ITER_KVEC;
+ if (!iskvec && to_copy <= len && page_count < MAX_SKB_FRAGS &&
likely(!(flags & MSG_PEEK))) {
struct scatterlist sgin[MAX_SKB_FRAGS + 1];
int pages = 0;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] tls: Skip zerocopy path for ITER_KVEC
2018-07-20 18:19 [PATCH net-next] tls: Skip zerocopy path for ITER_KVEC Doron Roberts-Kedes
@ 2018-07-24 21:38 ` David Miller
2018-07-24 21:40 ` David Miller
2018-07-25 21:48 ` [PATCH net-next v2] " Doron Roberts-Kedes
1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2018-07-24 21:38 UTC (permalink / raw)
To: doronrk; +Cc: davejwatson, netdev
From: Doron Roberts-Kedes <doronrk@fb.com>
Date: Fri, 20 Jul 2018 11:19:00 -0700
> The zerocopy path ultimately calls iov_iter_get_pages, which defines the
> step function for ITER_KVECs as simply, return -EFAULT. Taking the
> non-zerocopy path for ITER_KVECs avoids the unnecessary fallback.
>
> See https://lore.kernel.org/lkml/20150401023311.GL29656@ZenIV.linux.org.uk/T/#u
> for a discussion of why zerocopy for vmalloc data is not a good idea.
>
> Discovered while testing NBD traffic encrypted with ktls.
>
> Fixes: c46234ebb4d1 ("tls: RX path for ktls")
> Signed-off-by: Doron Roberts-Kedes <doronrk@fb.com>
Applied to net-next, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] tls: Skip zerocopy path for ITER_KVEC
2018-07-24 21:38 ` David Miller
@ 2018-07-24 21:40 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-24 21:40 UTC (permalink / raw)
To: doronrk; +Cc: davejwatson, netdev
From: David Miller <davem@davemloft.net>
Date: Tue, 24 Jul 2018 14:38:02 -0700 (PDT)
> From: Doron Roberts-Kedes <doronrk@fb.com>
> Date: Fri, 20 Jul 2018 11:19:00 -0700
>
>> The zerocopy path ultimately calls iov_iter_get_pages, which defines the
>> step function for ITER_KVECs as simply, return -EFAULT. Taking the
>> non-zerocopy path for ITER_KVECs avoids the unnecessary fallback.
>>
>> See https://lore.kernel.org/lkml/20150401023311.GL29656@ZenIV.linux.org.uk/T/#u
>> for a discussion of why zerocopy for vmalloc data is not a good idea.
>>
>> Discovered while testing NBD traffic encrypted with ktls.
>>
>> Fixes: c46234ebb4d1 ("tls: RX path for ktls")
>> Signed-off-by: Doron Roberts-Kedes <doronrk@fb.com>
>
> Applied to net-next, thanks.
Actually, I reverted. Please fix this warning:
net/tls/tls_sw.c: In function ‘tls_sw_sendmsg’:
net/tls/tls_sw.c:414:3: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
bool iskvec = msg->msg_iter.type & ITER_KVEC;
^~~~
net/tls/tls_sw.c: In function ‘tls_sw_recvmsg’:
net/tls/tls_sw.c:823:4: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
bool iskvec = msg->msg_iter.type & ITER_KVEC;
^~~~
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next v2] tls: Skip zerocopy path for ITER_KVEC
2018-07-20 18:19 [PATCH net-next] tls: Skip zerocopy path for ITER_KVEC Doron Roberts-Kedes
2018-07-24 21:38 ` David Miller
@ 2018-07-25 21:48 ` Doron Roberts-Kedes
1 sibling, 0 replies; 4+ messages in thread
From: Doron Roberts-Kedes @ 2018-07-25 21:48 UTC (permalink / raw)
To: David S . Miller; +Cc: Dave Watson, netdev, Doron Roberts-Kedes
The zerocopy path ultimately calls iov_iter_get_pages, which defines the
step function for ITER_KVECs as simply, return -EFAULT. Taking the
non-zerocopy path for ITER_KVECs avoids the unnecessary fallback.
See https://lore.kernel.org/lkml/20150401023311.GL29656@ZenIV.linux.org.uk/T/#u
for a discussion of why zerocopy for vmalloc data is not a good idea.
Discovered while testing NBD traffic encrypted with ktls.
Fixes: c46234ebb4d1 ("tls: RX path for ktls")
Signed-off-by: Doron Roberts-Kedes <doronrk@fb.com>
---
net/tls/tls_sw.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 1f3d9789af30..da584dc7d633 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -377,6 +377,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
int record_room;
bool full_record;
int orig_size;
+ bool is_kvec = msg->msg_iter.type & ITER_KVEC;
if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL))
return -ENOTSUPP;
@@ -425,8 +426,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
try_to_copy -= required_size - ctx->sg_encrypted_size;
full_record = true;
}
-
- if (full_record || eor) {
+ if (!is_kvec && (full_record || eor)) {
ret = zerocopy_from_iter(sk, &msg->msg_iter,
try_to_copy, &ctx->sg_plaintext_num_elem,
&ctx->sg_plaintext_size,
@@ -764,6 +764,7 @@ int tls_sw_recvmsg(struct sock *sk,
bool cmsg = false;
int target, err = 0;
long timeo;
+ bool is_kvec = msg->msg_iter.type & ITER_KVEC;
flags |= nonblock;
@@ -807,7 +808,7 @@ int tls_sw_recvmsg(struct sock *sk,
page_count = iov_iter_npages(&msg->msg_iter,
MAX_SKB_FRAGS);
to_copy = rxm->full_len - tls_ctx->rx.overhead_size;
- if (to_copy <= len && page_count < MAX_SKB_FRAGS &&
+ if (!is_kvec && to_copy <= len && page_count < MAX_SKB_FRAGS &&
likely(!(flags & MSG_PEEK))) {
struct scatterlist sgin[MAX_SKB_FRAGS + 1];
int pages = 0;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-25 23:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-20 18:19 [PATCH net-next] tls: Skip zerocopy path for ITER_KVEC Doron Roberts-Kedes
2018-07-24 21:38 ` David Miller
2018-07-24 21:40 ` David Miller
2018-07-25 21:48 ` [PATCH net-next v2] " Doron Roberts-Kedes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).