diff options
author | Jason Wang <jasowang@redhat.com> | 2016-11-30 00:17:51 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-11-30 15:06:01 -0500 |
commit | af1cc7a2b86ddb8668ac38097866bedd7b849a76 (patch) | |
tree | 2bf4382bcca7c8ce0e04e5395436c620cbcd0de2 | |
parent | 4ccfd6383a1a4838ed034120f00d02dbdc681d6f (diff) |
tun: 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.
Reported-by: wangyunjian <wangyunjian@huawei.com>
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>
-rw-r--r-- | drivers/net/tun.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8093e39ae263..db6acecabeaa 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -1246,13 +1246,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, | |||
1246 | 1246 | ||
1247 | if (zerocopy) | 1247 | if (zerocopy) |
1248 | err = zerocopy_sg_from_iter(skb, from); | 1248 | err = zerocopy_sg_from_iter(skb, from); |
1249 | else { | 1249 | else |
1250 | err = skb_copy_datagram_from_iter(skb, 0, from, len); | 1250 | err = skb_copy_datagram_from_iter(skb, 0, from, len); |
1251 | if (!err && msg_control) { | ||
1252 | struct ubuf_info *uarg = msg_control; | ||
1253 | uarg->callback(uarg, false); | ||
1254 | } | ||
1255 | } | ||
1256 | 1251 | ||
1257 | if (err) { | 1252 | if (err) { |
1258 | this_cpu_inc(tun->pcpu_stats->rx_dropped); | 1253 | this_cpu_inc(tun->pcpu_stats->rx_dropped); |
@@ -1298,6 +1293,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, | |||
1298 | skb_shinfo(skb)->destructor_arg = msg_control; | 1293 | skb_shinfo(skb)->destructor_arg = msg_control; |
1299 | skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY; | 1294 | skb_shinfo(skb)->tx_flags |= SKBTX_DEV_ZEROCOPY; |
1300 | skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; | 1295 | skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; |
1296 | } else if (msg_control) { | ||
1297 | struct ubuf_info *uarg = msg_control; | ||
1298 | uarg->callback(uarg, false); | ||
1301 | } | 1299 | } |
1302 | 1300 | ||
1303 | skb_reset_network_header(skb); | 1301 | skb_reset_network_header(skb); |