netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Liu ping fan <kernelfans@gmail.com>
Cc: netdev@vger.kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: vhost-net: is there a race for sock in handle_tx/rx?
Date: Thu, 3 May 2012 11:41:15 +0300	[thread overview]
Message-ID: <20120503084115.GM8266@redhat.com> (raw)
In-Reply-To: <CAFgQCTtKWR6F3D_mPcGe69HvZbYmmAdXreSWLZQrdi+0T3i2ag@mail.gmail.com>

On Thu, May 03, 2012 at 04:33:55PM +0800, Liu ping fan wrote:
> Hi,
> 
> During reading the vhost-net code, I find the following,
> 
> static void handle_tx(struct vhost_net *net)
> {
> 	struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_TX];
> 	unsigned out, in, s;
> 	int head;
> 	struct msghdr msg = {
> 		.msg_name = NULL,
> 		.msg_namelen = 0,
> 		.msg_control = NULL,
> 		.msg_controllen = 0,
> 		.msg_iov = vq->iov,
> 		.msg_flags = MSG_DONTWAIT,
> 	};
> 	size_t len, total_len = 0;
> 	int err, wmem;
> 	size_t hdr_size;
> 	struct socket *sock;
> 	struct vhost_ubuf_ref *uninitialized_var(ubufs);
> 	bool zcopy;
> 
> 	/* TODO: check that we are running from vhost_worker? */
> 	sock = rcu_dereference_check(vq->private_data, 1);
> 	if (!sock)
> 		return;
> 
>            --------------------------------> Qemu calls
> vhost_net_set_backend() to set a new backend fd, and close
> @oldsock->file. And  sock->file refcnt==0.
> 
>                                               Can vhost_worker prevent
> itself from such situation? And how?
> 
> 	wmem = atomic_read(&sock->sk->sk_wmem_alloc);
>        .........................................................................
> 
> Is it a race?
> 
> Thanks and regards,
> pingfan

See comment before void __rcu *private_data in vhost.h

  reply	other threads:[~2012-05-03  8:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-03  8:33 vhost-net: is there a race for sock in handle_tx/rx? Liu ping fan
2012-05-03  8:41 ` Michael S. Tsirkin [this message]
2012-05-03  9:08   ` Liu ping fan

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=20120503084115.GM8266@redhat.com \
    --to=mst@redhat.com \
    --cc=kernelfans@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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).