Re: [RFC PATCH 1/4] vhost: add VHOST_VRING_F_BYTESWAP flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 29, 2014 at 09:38:42AM +0100, Cédric Le Goater wrote:
> The VHOST_VRING_F_BYTESWAP flag will be used by the host to byteswap
> the vring data when the guest and the host have a different endian
> order.
> 
> Signed-off-by: Cédric Le Goater <clg@xxxxxxxxxx>

I don't think it's a good API.
You should ask for specific header format, not for a swap.

> ---
>  drivers/vhost/vhost.c      |    5 ++++-
>  drivers/vhost/vhost.h      |    1 +
>  include/uapi/linux/vhost.h |    3 +++
>  3 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index c90f4374442a..72c21b790ba3 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -199,6 +199,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
>  	vq->call = NULL;
>  	vq->log_ctx = NULL;
>  	vq->memory = NULL;
> +	vq->byteswap = 0;
>  }
>  
>  static int vhost_worker(void *data)
> @@ -701,7 +702,8 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
>  			r = -EFAULT;
>  			break;
>  		}
> -		if (a.flags & ~(0x1 << VHOST_VRING_F_LOG)) {
> +		if (a.flags & ~(0x1 << VHOST_VRING_F_LOG |
> +				0x1 << VHOST_VRING_F_BYTESWAP)) {
>  			r = -EOPNOTSUPP;
>  			break;
>  		}
> @@ -747,6 +749,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
>  		vq->avail = (void __user *)(unsigned long)a.avail_user_addr;
>  		vq->log_addr = a.log_guest_addr;
>  		vq->used = (void __user *)(unsigned long)a.used_user_addr;
> +		vq->byteswap = !!(a.flags & (0x1 << VHOST_VRING_F_BYTESWAP));
>  		break;
>  	case VHOST_SET_VRING_KICK:
>  		if (copy_from_user(&f, argp, sizeof f)) {
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index 3eda654b8f5a..ab25b7d0720d 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -110,6 +110,7 @@ struct vhost_virtqueue {
>  	/* Log write descriptors */
>  	void __user *log_base;
>  	struct vhost_log *log;
> +	bool byteswap;
>  };
>  
>  struct vhost_dev {
> diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
> index bb6a5b4cb3c5..6a8c2b325c44 100644
> --- a/include/uapi/linux/vhost.h
> +++ b/include/uapi/linux/vhost.h
> @@ -34,6 +34,9 @@ struct vhost_vring_addr {
>  	/* Flag values: */
>  	/* Whether log address is valid. If set enables logging. */
>  #define VHOST_VRING_F_LOG 0
> +	/* Whether vring memory accesses should be byte-swapped.
> +	 * required when the guest has a different endianness */
> +#define VHOST_VRING_F_BYTESWAP 1
>  
>  	/* Start of array of descriptors (virtually contiguous) */
>  	__u64 desc_user_addr;
> -- 
> 1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux