From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cornelia Huck Subject: Re: [RFC PATCH 3/4] vhost: byteswap virtqueue attributes Date: Mon, 3 Nov 2014 17:02:33 +0100 Message-ID: <20141103170233.71f6dfa2.cornelia.huck@de.ibm.com> References: <1414571925-16918-1-git-send-email-clg@fr.ibm.com> <1414571925-16918-4-git-send-email-clg@fr.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: "Michael S. Tsirkin" , kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, agraf@suse.de, paulus@samba.org, gkurz@linux.vnet.ibm.com, aik@ozlabs.ru To: =?UTF-8?B?Q8OpZHJpYw==?= Le Goater Return-path: In-Reply-To: <1414571925-16918-4-git-send-email-clg@fr.ibm.com> Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Wed, 29 Oct 2014 09:38:44 +0100 C=C3=A9dric Le Goater wrote: > The virtqueue structure shares a few attributes with the guest OS > which need to be byteswapped when the endian order of the host is > different. >=20 > This patch uses the vq->byteswap attribute to decide whether to > byteswap or not data being accessed in the guest memory. >=20 > Signed-off-by: C=C3=A9dric Le Goater > --- > drivers/vhost/vhost.c | 52 +++++++++++++++++++++++++++++++++++++--= ---------- > 1 file changed, 40 insertions(+), 12 deletions(-) >=20 > +static int __copyhead_to_user(struct vhost_virtqueue *vq, > + struct vring_used_elem *heads, > + struct vring_used_elem __user *used, > + unsigned count) __copy_used_elems_to_user() ? > +{ > + int i; > + > + for (i =3D 0; i < count; i++) { > + if (__vq_put_user(vq, heads[i].id, &used[i].id)) { > + vq_err(vq, "Failed to write used id"); > + return -EFAULT; > + } > + if (__vq_put_user(vq, heads[i].len, &used[i].len)) { > + vq_err(vq, "Failed to write used len"); > + return -EFAULT; > + } > + } Is there a number of elements where it would be more efficient to byteswap the used elements first and then do __copy_to_user() in one go? Depends on the backend, I guess. > + return 0; > +} > +