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 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization