netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Ira W. Snyder" <iws@ovro.caltech.edu>
Cc: Arnd Bergmann <arnd@arndb.de>,
	virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] vhost_net: a kernel-level virtio server
Date: Wed, 12 Aug 2009 20:31:04 +0300	[thread overview]
Message-ID: <20090812173104.GB29966@redhat.com> (raw)
In-Reply-To: <20090812171921.GC24151@ovro.caltech.edu>

On Wed, Aug 12, 2009 at 10:19:22AM -0700, Ira W. Snyder wrote:
> On Wed, Aug 12, 2009 at 07:03:22PM +0200, Arnd Bergmann wrote:
> > On Monday 10 August 2009, Michael S. Tsirkin wrote:
> > 
> > > +struct workqueue_struct *vhost_workqueue;
> > 
> > [nitpicking] This could be static. 
> > 
> > > +/* The virtqueue structure describes a queue attached to a device. */
> > > +struct vhost_virtqueue {
> > > +	struct vhost_dev *dev;
> > > +
> > > +	/* The actual ring of buffers. */
> > > +	struct mutex mutex;
> > > +	unsigned int num;
> > > +	struct vring_desc __user *desc;
> > > +	struct vring_avail __user *avail;
> > > +	struct vring_used __user *used;
> > > +	struct file *kick;
> > > +	struct file *call;
> > > +	struct file *error;
> > > +	struct eventfd_ctx *call_ctx;
> > > +	struct eventfd_ctx *error_ctx;
> > > +
> > > +	struct vhost_poll poll;
> > > +
> > > +	/* The routine to call when the Guest pings us, or timeout. */
> > > +	work_func_t handle_kick;
> > > +
> > > +	/* Last available index we saw. */
> > > +	u16 last_avail_idx;
> > > +
> > > +	/* Last index we used. */
> > > +	u16 last_used_idx;
> > > +
> > > +	/* Outstanding buffers */
> > > +	unsigned int inflight;
> > > +
> > > +	/* Is this blocked? */
> > > +	bool blocked;
> > > +
> > > +	struct iovec iov[VHOST_NET_MAX_SG];
> > > +
> > > +} ____cacheline_aligned;
> > 
> > We discussed this before, and I still think this could be directly derived
> > from struct virtqueue, in the same way that vring_virtqueue is derived from
> > struct virtqueue. That would make it possible for simple device drivers
> > to use the same driver in both host and guest, similar to how Ira Snyder
> > used virtqueues to make virtio_net run between two hosts running the
> > same code [1].
> > 
> > Ideally, I guess you should be able to even make virtio_net work in the
> > host if you do that, but that could bring other complexities.
> 
> I have no comments about the vhost code itself, I haven't reviewed it.
> 
> It might be interesting to try using a virtio-net in the host kernel to
> communicate with the virtio-net running in the guest kernel. The lack of
> a management interface is the biggest problem you will face (setting MAC
> addresses, negotiating features, etc. doesn't work intuitively).

That was one of the reasons I decided to move most of code out to
userspace. My kernel driver only handles datapath,
it's much smaller than virtio net.

> Getting
> the network interfaces talking is relatively easy.
> 
> Ira

Tried this, but
- guest memory isn't pinned, so copy_to_user
  to access it, errors need to be handled in a sane way
- used/available roles are reversed
- kick/interrupt roles are reversed

So most of the code then looks like

	if (host) {
	} else {
	}
	return


The only common part is walking the descriptor list,
but that's like 10 lines of code.

At which point it's better to keep host/guest code separate, IMO.

-- 
MST

  reply	other threads:[~2009-08-12 17:31 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1249930169.git.mst@redhat.com>
2009-08-10 18:53 ` [PATCH 1/2] export cpu_tlbstate to modules Michael S. Tsirkin
2009-08-10 21:56   ` H. Peter Anvin
2009-08-10 22:06     ` Michael S. Tsirkin
2009-08-10 22:24       ` H. Peter Anvin
2009-08-11 11:19         ` Michael S. Tsirkin
2009-08-10 18:53 ` [PATCH 2/2] vhost_net: a kernel-level virtio server Michael S. Tsirkin
2009-08-10 19:51   ` Arnd Bergmann
2009-08-10 20:10     ` Michael S. Tsirkin
2009-08-10 22:16       ` Arnd Bergmann
2009-08-12 17:03   ` Arnd Bergmann
2009-08-12 17:19     ` Ira W. Snyder
2009-08-12 17:31       ` Michael S. Tsirkin [this message]
2009-08-12 17:48         ` Ira W. Snyder
2009-08-13  5:55           ` Michael S. Tsirkin
2009-08-12 17:21     ` Michael S. Tsirkin
2009-08-12 17:59       ` Arnd Bergmann
2009-08-12 19:27         ` Anthony Liguori
2009-08-13  6:31           ` Michael S. Tsirkin
2009-08-13  6:06         ` Michael S. Tsirkin
2009-08-13 13:38           ` Arnd Bergmann
2009-08-13 13:48             ` Arnd Bergmann
2009-08-13 14:41               ` Michael S. Tsirkin
2009-08-13 14:53                 ` Arnd Bergmann
2009-08-13 15:37                   ` Avi Kivity
2009-08-20  7:25                   ` Rusty Russell
2009-08-13 14:39             ` Michael S. Tsirkin
2009-08-13 14:58               ` Arnd Bergmann
2009-08-13 15:03                 ` Michael S. Tsirkin
2009-08-12 19:22       ` Anthony Liguori
2009-08-13  8:45         ` Michael S. Tsirkin
2009-08-13 13:45         ` Arnd Bergmann
2009-08-12 19:58   ` Paul E. McKenney

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=20090812173104.GB29966@redhat.com \
    --to=mst@redhat.com \
    --cc=arnd@arndb.de \
    --cc=iws@ovro.caltech.edu \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.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).