netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: wangyunjian <wangyunjian@huawei.com>,
	"mst@redhat.com" <mst@redhat.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: caihe <caihe@huawei.com>
Subject: Re: The ubufs->refcount maybe be subtracted twice when tun_get_user failed
Date: Wed, 30 Nov 2016 10:53:47 +0800	[thread overview]
Message-ID: <fad5d47a-96ee-1afc-b10c-cb2a6d5dc784@redhat.com> (raw)
In-Reply-To: <34EFBCA9F01B0748BEB6B629CE643AE60B0A5826@szxeml561-mbx.china.huawei.com>



On 2016年11月29日 21:27, wangyunjian wrote:
> Sorry, I didn't describe it clearly. In fact, the second subtraction happens in the function handle_tx,
> when tun_get_user fails and zcopy_used is ture. Fllowing the steps:

I get your meaning. Thanks for the reporting. Will post patches (since 
macvtap has similar issue).


>
> static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
>                                    void *msg_control, struct iov_iter *from,
>                                    int noblock) {
>             ...
>
>             if (zerocopy)
>                       err = zerocopy_sg_from_iter(skb, from);
>             else {
>                       err = skb_copy_datagram_from_iter(skb, 0, from, len);
>                       if (!err && msg_control) {
>                                struct ubuf_info *uarg = msg_control;
>                                uarg->callback(uarg, false);                       --> step 1, the ubufs->refcount is subtracted frist.
>                       }
>             }
>
>             if (err) {
>                       this_cpu_inc(tun->pcpu_stats->rx_dropped);
>                       kfree_skb(skb);
>                       return -EFAULT;
>             }
>
>             err = virtio_net_hdr_to_skb(skb, &gso, tun_is_little_endian(tun));
>             if (err) {
>                       this_cpu_inc(tun->pcpu_stats->rx_frame_errors);
>                       kfree_skb(skb);
>                       return -EINVAL;                                         -->step 2, return err.
>             }
> }
>
> static void handle_tx(struct vhost_net *net)
> {
> 	...
> 	/* TODO: Check specific error and bomb out unless ENOBUFS? */
> 	err = sock->ops->sendmsg(sock, &msg, len);
> 	if (unlikely(err < 0)) {
> 		if (zcopy_used) {
> 			vhost_net_ubuf_put(ubufs);                                        --> step 3, the ubufs->refcount will be subtracted twice, when sendmsg execution err.
> 			nvq->upend_idx = ((unsigned)nvq->upend_idx - 1)
> 				% UIO_MAXIOV;
> 		}
> 		vhost_discard_vq_desc(vq, 1);
> 		break;
> 	}
> 	...
> }
>
> -----Original Message-----

  reply	other threads:[~2016-11-30  2:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29  9:30 The ubufs->refcount maybe be subtracted twice when tun_get_user failed wangyunjian
2016-11-29 10:06 ` Jason Wang
2016-11-29 13:27   ` wangyunjian
2016-11-30  2:53     ` Jason Wang [this message]
2016-11-30  5:24       ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fad5d47a-96ee-1afc-b10c-cb2a6d5dc784@redhat.com \
    --to=jasowang@redhat.com \
    --cc=caihe@huawei.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=wangyunjian@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).