Skip to contentSkip to conversation

zerocopy fixes

PATCH In review Willem de Bruijn 3 participants 5 messages Aug 9, 2017 – Aug 10, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover zerocopy fixes

From: Willem de Bruijn <[email protected]>

Fix two issues introduced in the msg_zerocopy patchset.

Willem de Bruijn (2):
sock: fix zerocopy panic in mem accounting
sock: fix zerocopy_success regression with msg_zerocopy

 include/linux/skbuff.h | 9 +++++++--
 net/core/skbuff.c      | 4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.0.434.g98096fd7a8-goog
#1 lore raw

PATCH 1/2 sock: fix zerocopy panic in mem accounting

From: Willem de Bruijn <[email protected]>

Only call mm_unaccount_pinned_pages when releasing a struct ubuf_info that has initialized its field uarg->mmp.

Before this patch, a vhost-net with experimental_zcopytx can crash in

mm_unaccount_pinned_pages
sock_zerocopy_put
skb_zcopy_clear
skb_release_data

Only sock_zerocopy_alloc initializes this field. Move the unaccount call from generic sock_zerocopy_put to its specific callback sock_zerocopy_callback.

Fixes a91dbff551a6 ("sock: ulimit on MSG_ZEROCOPY pages")
---
 net/core/skbuff.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/skbuff.c +2 -2
index 42b62c716a33..cb123590c674 100644
@@ -1044,6 +1044,8 @@ void sock_zerocopy_callback(struct ubuf_info *uarg, bool success)
 	u32 lo, hi;
 	u16 len;
 
+	mm_unaccount_pinned_pages(&uarg->mmp);
+
 	/* if !len, there was only 1 call, and it was aborted
 	 * so do not queue a completion notification
 	 */
@@ -1084,8 +1086,6 @@ EXPORT_SYMBOL_GPL(sock_zerocopy_callback);
 void sock_zerocopy_put(struct ubuf_info *uarg)
 {
 	if (uarg && atomic_dec_and_test(&uarg->refcnt)) {
-		mm_unaccount_pinned_pages(&uarg->mmp);
-
 		if (uarg->callback)
 			uarg->callback(uarg, uarg->zerocopy);
 		else
Signature · 1 line
2.14.0.434.g98096fd7a8-goog
#2 lore raw

PATCH 2/2 sock: fix zerocopy_success regression with msg_zerocopy

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Do not use uarg->zerocopy outside msg_zerocopy. In other paths the field is not explicitly initialized and aliases another field.

Those paths have only one reference so do not need this intermediate variable. Call uarg->callback directly.

Fixes 1f8b977ab32d ("sock: enable MSG_ZEROCOPY")
---
 include/linux/skbuff.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
include/linux/skbuff.h +7 -2
index 8c0708d2e5e6..7594e19bce62 100644
@@ -1273,8 +1273,13 @@ static inline void skb_zcopy_clear(struct sk_buff *skb, bool zerocopy)
 	struct ubuf_info *uarg = skb_zcopy(skb);
 
 	if (uarg) {
-		uarg->zerocopy = uarg->zerocopy && zerocopy;
-		sock_zerocopy_put(uarg);
+		if (uarg->callback == sock_zerocopy_callback) {
+			uarg->zerocopy = uarg->zerocopy && zerocopy;
+			sock_zerocopy_put(uarg);
+		} else {
+			uarg->callback(uarg, zerocopy);
+		}
+
 		skb_shinfo(skb)->tx_flags &= ~SKBTX_ZEROCOPY_FRAG;
 	}
 }
Signature · 1 line
2.14.0.434.g98096fd7a8-goog
#4 lore raw
In reply to Willem de Bruijn
Quoted 4 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Fix two issues introduced in the msg_zerocopy patchset.

Quoted 8 lines

Willem de Bruijn (2):
sock: fix zerocopy panic in mem accounting
sock: fix zerocopy_success regression with msg_zerocopy

 include/linux/skbuff.h | 9 +++++++--
 net/core/skbuff.c      | 4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)

Fixes the problem I reported. Thanks for the quick turn around.