From: "Michael S. Tsirkin" <mst-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Cornelia Huck <cornelia.huck-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Bjarke Istrup Pedersen"
<gurligebis-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>,
"Anup Patel" <anup.patel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
"Greg Kroah-Hartman"
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
"Geert Uytterhoeven"
<geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>,
"Sakari Ailus"
<sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"David S. Miller" <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>,
"Piotr Król" <piotr.krol-zILERgsGILsAvxtiuMwx3w@public.gmane.org>,
"Alexei Starovoitov"
<ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH RFC v3 01/16] virtio: memory access APIs
Date: Thu, 23 Oct 2014 12:15:02 +0300 [thread overview]
Message-ID: <20141023091502.GA7028@redhat.com> (raw)
In-Reply-To: <20141023095405.6bdd5a1a.cornelia.huck-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
On Thu, Oct 23, 2014 at 09:54:05AM +0200, Cornelia Huck wrote:
> On Wed, 22 Oct 2014 21:44:08 +0300
> "Michael S. Tsirkin" <mst-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>
> > virtio 1.0 makes all memory structures LE, so
> > we need APIs to conditionally do a byteswap on BE
> > architectures.
> >
> > To make it easier to check code statically,
> > add virtio specific types for multi-byte integers
> > in memory.
> >
> > Add low level wrappers that do a byteswap conditionally, these will be
> > useful e.g. for vhost. Add high level wrappers that will (in the
> > future) query device endian-ness and act accordingly.
> >
> > At the moment, stub them out and assume native endian-ness everywhere.
> >
> > Signed-off-by: Michael S. Tsirkin <mst-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> > ---
> > include/linux/virtio_byteorder.h | 29 ++++++++++++++++++++++++
> > include/linux/virtio_config.h | 16 +++++++++++++
> > include/uapi/linux/virtio_ring.h | 49 ++++++++++++++++++++--------------------
> > include/uapi/linux/Kbuild | 1 +
> > 4 files changed, 71 insertions(+), 24 deletions(-)
> > create mode 100644 include/linux/virtio_byteorder.h
> >
> > diff --git a/include/linux/virtio_byteorder.h b/include/linux/virtio_byteorder.h
> > new file mode 100644
> > index 0000000..7afdd8a
> > --- /dev/null
> > +++ b/include/linux/virtio_byteorder.h
> > @@ -0,0 +1,29 @@
> > +#ifndef _LINUX_VIRTIO_BYTEORDER_H
> > +#define _LINUX_VIRTIO_BYTEORDER_H
> > +#include <linux/types.h>
> > +#include <uapi/linux/virtio_types.h>
> > +
> > +/* Memory accessors for handling virtio in modern little endian and in
> > + * compatibility big endian format. */
>
> s/big/native/
Thanks.
> > +
> > +#define __DEFINE_VIRTIO_XX_TO_CPU(bits) \
> > +static inline u##bits __virtio##bits##_to_cpu(bool little_endian, __virtio##bits val) \
> > +{ \
> > + if (little_endian) \
> > + return le##bits##_to_cpu((__force __le##bits)val); \
> > + else \
> > + return (__force u##bits)val; \
> > +} \
> > +static inline __virtio##bits __cpu_to_virtio##bits(bool little_endian, u##bits val) \
> > +{ \
> > + if (little_endian) \
> > + return (__force __virtio##bits)cpu_to_le##bits(val); \
> > + else \
> > + return val; \
> > +}
> > +
> > +__DEFINE_VIRTIO_XX_TO_CPU(16)
> > +__DEFINE_VIRTIO_XX_TO_CPU(32)
> > +__DEFINE_VIRTIO_XX_TO_CPU(64)
>
> ...although I'm still not too happy with macro-generated helpers.
I'm fine with open-coding them.
> > +
> > +#endif /* _LINUX_VIRTIO_BYTEORDER */
>
> > diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h
> > index a99f9b7..6c00632 100644
> > --- a/include/uapi/linux/virtio_ring.h
> > +++ b/include/uapi/linux/virtio_ring.h
>
> > @@ -61,32 +62,32 @@
> > /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
> > struct vring_desc {
> > /* Address (guest-physical). */
> > - __u64 addr;
> > + __virtio64 addr;
> > /* Length. */
> > - __u32 len;
> > + __virtio32 len;
> > /* The flags as indicated above. */
> > - __u16 flags;
> > + __virtio16 flags;
> > /* We chain unused descriptors via this, too */
> > - __u16 next;
> > + __virtio16 next;
> > };
>
> I think all of these __virtio types need an explanation somewhere as to
> what they mean, e.g.:
>
> /*
> * __virtio{16,32,64} have the following meaning:
> * - __u{16,32,64} for virtio devices in legacy mode,
> * accessed in native endian
> * - __le{16,32,64} for standard-compliant virtio devices
> */
Will do.
--
MST
WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: linux-kernel@vger.kernel.org,
"Bjarke Istrup Pedersen" <gurligebis@gentoo.org>,
"Anup Patel" <anup.patel@linaro.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
virtualization@lists.linux-foundation.org,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
linux-api@vger.kernel.org,
"David S. Miller" <davem@davemloft.net>,
"Piotr Król" <piotr.krol@3mdeb.com>,
"Alexei Starovoitov" <ast@plumgrid.com>
Subject: Re: [PATCH RFC v3 01/16] virtio: memory access APIs
Date: Thu, 23 Oct 2014 12:15:02 +0300 [thread overview]
Message-ID: <20141023091502.GA7028@redhat.com> (raw)
In-Reply-To: <20141023095405.6bdd5a1a.cornelia.huck@de.ibm.com>
On Thu, Oct 23, 2014 at 09:54:05AM +0200, Cornelia Huck wrote:
> On Wed, 22 Oct 2014 21:44:08 +0300
> "Michael S. Tsirkin" <mst@redhat.com> wrote:
>
> > virtio 1.0 makes all memory structures LE, so
> > we need APIs to conditionally do a byteswap on BE
> > architectures.
> >
> > To make it easier to check code statically,
> > add virtio specific types for multi-byte integers
> > in memory.
> >
> > Add low level wrappers that do a byteswap conditionally, these will be
> > useful e.g. for vhost. Add high level wrappers that will (in the
> > future) query device endian-ness and act accordingly.
> >
> > At the moment, stub them out and assume native endian-ness everywhere.
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> > include/linux/virtio_byteorder.h | 29 ++++++++++++++++++++++++
> > include/linux/virtio_config.h | 16 +++++++++++++
> > include/uapi/linux/virtio_ring.h | 49 ++++++++++++++++++++--------------------
> > include/uapi/linux/Kbuild | 1 +
> > 4 files changed, 71 insertions(+), 24 deletions(-)
> > create mode 100644 include/linux/virtio_byteorder.h
> >
> > diff --git a/include/linux/virtio_byteorder.h b/include/linux/virtio_byteorder.h
> > new file mode 100644
> > index 0000000..7afdd8a
> > --- /dev/null
> > +++ b/include/linux/virtio_byteorder.h
> > @@ -0,0 +1,29 @@
> > +#ifndef _LINUX_VIRTIO_BYTEORDER_H
> > +#define _LINUX_VIRTIO_BYTEORDER_H
> > +#include <linux/types.h>
> > +#include <uapi/linux/virtio_types.h>
> > +
> > +/* Memory accessors for handling virtio in modern little endian and in
> > + * compatibility big endian format. */
>
> s/big/native/
Thanks.
> > +
> > +#define __DEFINE_VIRTIO_XX_TO_CPU(bits) \
> > +static inline u##bits __virtio##bits##_to_cpu(bool little_endian, __virtio##bits val) \
> > +{ \
> > + if (little_endian) \
> > + return le##bits##_to_cpu((__force __le##bits)val); \
> > + else \
> > + return (__force u##bits)val; \
> > +} \
> > +static inline __virtio##bits __cpu_to_virtio##bits(bool little_endian, u##bits val) \
> > +{ \
> > + if (little_endian) \
> > + return (__force __virtio##bits)cpu_to_le##bits(val); \
> > + else \
> > + return val; \
> > +}
> > +
> > +__DEFINE_VIRTIO_XX_TO_CPU(16)
> > +__DEFINE_VIRTIO_XX_TO_CPU(32)
> > +__DEFINE_VIRTIO_XX_TO_CPU(64)
>
> ...although I'm still not too happy with macro-generated helpers.
I'm fine with open-coding them.
> > +
> > +#endif /* _LINUX_VIRTIO_BYTEORDER */
>
> > diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h
> > index a99f9b7..6c00632 100644
> > --- a/include/uapi/linux/virtio_ring.h
> > +++ b/include/uapi/linux/virtio_ring.h
>
> > @@ -61,32 +62,32 @@
> > /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */
> > struct vring_desc {
> > /* Address (guest-physical). */
> > - __u64 addr;
> > + __virtio64 addr;
> > /* Length. */
> > - __u32 len;
> > + __virtio32 len;
> > /* The flags as indicated above. */
> > - __u16 flags;
> > + __virtio16 flags;
> > /* We chain unused descriptors via this, too */
> > - __u16 next;
> > + __virtio16 next;
> > };
>
> I think all of these __virtio types need an explanation somewhere as to
> what they mean, e.g.:
>
> /*
> * __virtio{16,32,64} have the following meaning:
> * - __u{16,32,64} for virtio devices in legacy mode,
> * accessed in native endian
> * - __le{16,32,64} for standard-compliant virtio devices
> */
Will do.
--
MST
next prev parent reply other threads:[~2014-10-23 9:15 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-22 18:44 [PATCH RFC v3 00/16] linux: towards virtio-1 guest support Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 01/16] virtio: memory access APIs Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-23 7:54 ` Cornelia Huck
2014-10-23 7:54 ` Cornelia Huck
[not found] ` <20141023095405.6bdd5a1a.cornelia.huck-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2014-10-23 9:15 ` Michael S. Tsirkin [this message]
2014-10-23 9:15 ` Michael S. Tsirkin
2014-10-23 9:15 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 02/16] virtio_ring: switch to new " Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 03/16] virtio: use u32, not bitmap for struct virtio_device's features Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 04/16] virtio: add support for 64 bit features Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 05/16] virtio: add virtio 1.0 feature bit Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-23 11:57 ` Cornelia Huck
2014-10-23 11:57 ` Cornelia Huck
2014-10-22 18:44 ` [PATCH RFC v3 06/16] virtio: make endian-ness depend on virtio 1.0 Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-23 12:06 ` Cornelia Huck
2014-10-22 18:44 ` [PATCH RFC v3 07/16] virtio_config: endian conversion for v1.0 Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 08/16] virtio: allow transports to get avail/used addresses Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 09/16] virtio: set FEATURES_OK Michael S. Tsirkin
2014-10-23 12:28 ` Cornelia Huck
[not found] ` <1414003404-505-10-git-send-email-mst-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2014-10-23 12:28 ` Cornelia Huck
2014-10-23 12:28 ` Cornelia Huck
2014-10-23 12:51 ` Michael S. Tsirkin
2014-10-23 12:51 ` Michael S. Tsirkin
2014-10-23 13:30 ` Cornelia Huck
2014-10-23 13:30 ` Cornelia Huck
2014-10-23 14:03 ` Michael S. Tsirkin
2014-10-23 14:03 ` Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 10/16] virtio_net: use v1.0 endian Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 11/16] virtio_blk: use virtio " Michael S. Tsirkin
2014-10-22 18:44 ` Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 12/16] KVM: s390: Set virtio-ccw transport revision Michael S. Tsirkin
2014-10-22 18:44 ` [PATCH RFC v3 13/16] KVM: s390: virtio-ccw revision 1 SET_VQ Michael S. Tsirkin
2014-10-22 18:45 ` [PATCH RFC v3 14/16] KVM: s390: enable virtio-ccw revision 1 Michael S. Tsirkin
2014-10-22 18:45 ` [PATCH RFC v3 15/16] virtio_net: fix types for in memory structures Michael S. Tsirkin
2014-10-22 18:45 ` Michael S. Tsirkin
2014-10-22 18:45 ` [PATCH RFC v3 16/16] virtio_blk: " Michael S. Tsirkin
2014-10-22 18:45 ` Michael S. Tsirkin
2014-10-23 12:17 ` [PATCH RFC v3 00/16] linux: towards virtio-1 guest support Michael S. Tsirkin
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=20141023091502.GA7028@redhat.com \
--to=mst-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=anup.patel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org \
--cc=cornelia.huck-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=gurligebis-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org \
--cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=piotr.krol-zILERgsGILsAvxtiuMwx3w@public.gmane.org \
--cc=sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.