virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Sjur Brændeland" <sjur@brendeland.net>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	virtualization@lists.linux-foundation.org,
	"Sjur Brændeland" <sjur.brandeland@stericsson.com>
Subject: Re: [RFCv2 00/12] Introduce host-side virtio queue and CAIF Virtio.
Date: Thu, 6 Dec 2012 12:27:50 +0200	[thread overview]
Message-ID: <20121206102750.GF10837@redhat.com> (raw)
In-Reply-To: <1354718230-4486-1-git-send-email-sjur@brendeland.net>

On Wed, Dec 05, 2012 at 03:36:58PM +0100, Sjur Brændeland wrote:
> Feedback on this patch-set is appreciated, particularly on structure
> and code-reuse between vhost.c and the host-side virtio-queue.
> I'd also like some suggestions on how to handle the build configuration
> better - currently there are some unnecessary build dependencies.

Rusty seems to disagree but one of the concerns people have about vhost
is security; so I value getting as much static checking as we can.  This
discards __user annotations so this doesn't work for me.

I also have concerns about how much overhead an indirect function
call on each 2 byte access would have.

After thinking about this I think there's no way without using a
preprocessor. But using a preprocessor it's not very bad: we'll have to
make everything inline in header but that's not terrible as the
functions are pretty short: it's less about code size and more about
avoiding code duplication.

Basically like this:

/* Legal values for VIRTIO_HOST_MODE */
#define VIRTIO_HOST_KERNEL 0
#define VIRTIO_HOST_USER 1

#if defined(VIRTIO_HOST_H) && VIRTIO_HOST_H != VIRTIO_HOST_MODE
#error "Header included twice with VIRTIO_HOST_MODE redefined"
#endif

#ifndef VIRTIO_HOST_H
/* Besides serving as a double inclusion guard, this
 * verifies that multiple inclusions define VIRTIO_HOST_MODE
 * consistently.
 */
#define VIRTIO_HOST_H VIRTIO_HOST_MODE

#ifndef VIRTIO_HOST_MODE
#error "Must define VIRTIO_HOST_MODE to VIRTIO_HOST_KERNEL or VIRTIO_HOST_USER"
#endif

#if VIRTIO_HOST_MODE == VIRTIO_HOST_KERNEL
#define __virtio_host_user
#define __virtio_host_put_user(x, ptr) ({*(ptr) = (__typeof__(*(ptr)))(x); 0;})
#else
#define __virtio_host_user __user
#define __virtio_host_put_user(x, ptr) __put_user(x, ptr)
#endif

static inline
int vhost_add_used(struct virtio_host_vq *vq, unsigned int head, int len)
{
        struct vring_used_elem __virtio_host_user *used;

        /* The virtqueue contains a ring of used buffers.  Get a pointer to the
         * next entry in that used ring. */
        used = &vq->used->ring[vq->last_used_idx % vq->num];
        if (__virtio_host_put_user(head, &used->id)) {


...


#endif

Users will have to

#define VIRTIO_HOST_MODE VIRTIO_HOST_USER
#include "linux/virtio_host.h"

or

#define VIRTIO_HOST_MODE VIRTIO_HOST_KERNEL
#include "linux/virtio_host.h"

-- 
MST

  parent reply	other threads:[~2012-12-06 10:27 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-31 22:46 [RFC virtio-next 0/4] Introduce CAIF Virtio and reversed Vrings Sjur Brændeland
2012-10-31 22:46 ` [RFC virtio-next 1/4] virtio: Move definitions to header file vring.h Sjur Brændeland
2012-10-31 22:46 ` [RFC virtio-next 2/4] include/vring.h: Add support for reversed vritio rings Sjur Brændeland
2012-10-31 22:46 ` [RFC virtio-next 3/4] virtio_ring: Call callback function even when used ring is empty Sjur Brændeland
2012-10-31 22:46 ` [RFC virtio-next 4/4] caif_virtio: Add CAIF over virtio Sjur Brændeland
2012-11-01  7:41 ` [RFC virtio-next 0/4] Introduce CAIF Virtio and reversed Vrings Rusty Russell
2012-11-05 12:12   ` Sjur Brændeland
     [not found]   ` <CANHm3PgrsTD4uYuXN0AMuZFX794CJmmus4AST=G0+nP1ha3VyQ@mail.gmail.com>
2012-11-06  2:09     ` Rusty Russell
2012-12-05 14:36       ` [RFCv2 00/12] Introduce host-side virtio queue and CAIF Virtio Sjur Brændeland
2012-12-05 14:36         ` [RFCv2 01/12] vhost: Use struct vring in vhost_virtqueue Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 02/12] vhost: Isolate reusable vring related functions Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 03/12] virtio-ring: Introduce file virtio_ring_host Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 04/12] virtio-ring: Refactor out the functions accessing user memory Sjur Brændeland
2012-12-06  9:52           ` Michael S. Tsirkin
2012-12-06 11:03             ` Sjur BRENDELAND
2012-12-06 11:15               ` Michael S. Tsirkin
2012-12-07 11:05                 ` Sjur BRENDELAND
2012-12-07 12:40                   ` Michael S. Tsirkin
2012-12-07 13:02                     ` Sjur BRENDELAND
2012-12-07 14:05                       ` Michael S. Tsirkin
2012-12-05 14:37         ` [RFCv2 05/12] virtio-ring: Refactor move attributes to struct virtqueue Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 06/12] virtio_ring: Move SMP macros to virtio_ring.h Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 07/12] virtio-ring: Add Host side virtio-ring implementation Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 08/12] virtio: Update vring_interrupt for host-side virtio queues Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 09/12] virtio-ring: Add BUG_ON checking on host/guest ring type Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 10/12] virtio: Add argument reversed to function find_vqs() Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 11/12] remoteproc: Add support for host-virtqueues Sjur Brændeland
2012-12-05 14:37         ` [RFCv2 12/12] caif_virtio: Introduce caif over virtio Sjur Brændeland
2012-12-06 10:27         ` Michael S. Tsirkin [this message]
2012-12-21  6:11           ` [RFCv2 00/12] Introduce host-side virtio queue and CAIF Virtio Rusty Russell
2013-01-08  8:04             ` Sjur Brændeland
2013-01-08 23:17               ` Rusty Russell
2013-01-10 10:30                 ` Rusty Russell
2013-01-10 11:11                   ` Michael S. Tsirkin
2013-01-10 22:48                     ` Rusty Russell
2013-01-11  7:31                       ` Michael S. Tsirkin
     [not found]                       ` <20130111073155.GA13315@redhat.com>
2013-01-12  0:20                         ` Rusty Russell
2013-01-14 16:54                           ` Michael S. Tsirkin
2013-01-10 18:39                   ` Sjur Brændeland
2013-01-10 23:35                     ` Rusty Russell
2013-01-11  6:37                       ` Rusty Russell
2013-01-11 15:02                         ` Sjur Brændeland
2013-01-12  0:26                           ` Rusty Russell
2013-01-14 17:39                         ` Michael S. Tsirkin
2013-01-16  3:13                           ` Rusty Russell
2013-01-16  8:16                             ` Michael S. Tsirkin
2013-01-17  2:10                               ` Rusty Russell
     [not found]                               ` <87k3rcy2y2.fsf@rustcorp.com.au>
2013-01-17  9:58                                 ` Michael S. Tsirkin
2013-01-21 11:55                                   ` Rusty Russell
2013-01-17 10:35                                 ` Rusty Russell
2013-01-11 14:52                       ` Sjur Brændeland

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=20121206102750.GF10837@redhat.com \
    --to=mst@redhat.com \
    --cc=linus.walleij@linaro.org \
    --cc=sjur.brandeland@stericsson.com \
    --cc=sjur@brendeland.net \
    --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).