Skip to content

Commit aa196ee

Browse files
jasowangdavem330
authored andcommitted
macvtap: handle ubuf refcount correctly when meet errors
We trigger uarg->callback() immediately after we decide do datacopy even if caller want to do zerocopy. This will cause the callback (vhost_net_zerocopy_callback) decrease the refcount. But when we meet an error afterwards, the error handling in vhost handle_tx() will try to decrease it again. This is wrong and fix this by delay the uarg->callback() until we're sure there's no errors. Signed-off-by: Jason Wang <jasowang@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent af1cc7a commit aa196ee

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

drivers/net/macvtap.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
742742

743743
if (zerocopy)
744744
err = zerocopy_sg_from_iter(skb, from);
745-
else {
745+
else
746746
err = skb_copy_datagram_from_iter(skb, 0, from, len);
747-
if (!err && m && m->msg_control) {
748-
struct ubuf_info *uarg = m->msg_control;
749-
uarg->callback(uarg, false);
750-
}
751-
}
752747

753748
if (err)
754749
goto err_kfree;
@@ -779,7 +774,11 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
779774
skb_shinfo(skb)->destructor_arg = m->msg_control;
780775
skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY;
781776
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
777+
} else if (m && m->msg_control) {
778+
struct ubuf_info *uarg = m->msg_control;
779+
uarg->callback(uarg, false);
782780
}
781+
783782
if (vlan) {
784783
skb->dev = vlan->dev;
785784
dev_queue_xmit(skb);

0 commit comments

Comments
 (0)