All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <claudio.fontana@huawei.com>
To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, drjones@redhat.com, cam@cs.ualberta.ca,
	stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v4 47/47] ivshmem: use little-endian int64_t for the protocol
Date: Tue, 29 Sep 2015 16:28:17 +0200	[thread overview]
Message-ID: <560AA001.9050208@huawei.com> (raw)
In-Reply-To: <1443094669-4144-48-git-send-email-marcandre.lureau@redhat.com>

On 24.09.2015 13:37, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> The current ivshmem protocol uses 'long' for integers. But the
> sizeof(long) depends on the host and the endianess is not defined, which
> may cause portability troubles.
> 
> Instead, switch to using little-endian int64_t. This breaks the
> protocol, except on x64 little-endian host where this change
> should be compatible.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  contrib/ivshmem-client/ivshmem-client.c | 11 ++++++-----
>  contrib/ivshmem-client/ivshmem-client.h |  4 ++--
>  contrib/ivshmem-server/ivshmem-server.c |  5 +++--
>  contrib/ivshmem-server/ivshmem-server.h |  4 ++--
>  docs/specs/ivshmem_device_spec.txt      |  2 +-
>  hw/misc/ivshmem.c                       | 29 +++++++++++++++++++----------
>  6 files changed, 33 insertions(+), 22 deletions(-)
> 
> diff --git a/contrib/ivshmem-client/ivshmem-client.c b/contrib/ivshmem-client/ivshmem-client.c
> index a8477d8..4b5786c 100644
> --- a/contrib/ivshmem-client/ivshmem-client.c
> +++ b/contrib/ivshmem-client/ivshmem-client.c
> @@ -24,7 +24,7 @@
>  
>  /* read message from the unix socket */
>  static int
> -ivshmem_client_read_one_msg(IvshmemClient *client, long *index, int *fd)
> +ivshmem_client_read_one_msg(IvshmemClient *client, int64_t *index, int *fd)
>  {
>      int ret;
>      struct msghdr msg;
> @@ -45,7 +45,7 @@ ivshmem_client_read_one_msg(IvshmemClient *client, long *index, int *fd)
>      msg.msg_controllen = sizeof(msg_control);
>  
>      ret = recvmsg(client->sock_fd, &msg, 0);
> -    if (ret < 0) {
> +    if (ret < sizeof(*index)) {
>          IVSHMEM_CLIENT_DEBUG(client, "cannot read message: %s\n",
>                               strerror(errno));
>          return -1;
> @@ -55,6 +55,7 @@ ivshmem_client_read_one_msg(IvshmemClient *client, long *index, int *fd)
>          return -1;
>      }
>  
> +    *index = GINT64_FROM_LE(*index);
>      *fd = -1;
>  
>      for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
> @@ -91,7 +92,7 @@ static int
>  ivshmem_client_handle_server_msg(IvshmemClient *client)
>  {
>      IvshmemClientPeer *peer;
> -    long peer_id;
> +    int64_t peer_id;
>      int ret, fd;
>  
>      ret = ivshmem_client_read_one_msg(client, &peer_id, &fd);
> @@ -179,7 +180,7 @@ ivshmem_client_connect(IvshmemClient *client)
>  {
>      struct sockaddr_un sun;
>      int fd, ret;
> -    long tmp;
> +    int64_t tmp;
>  
>      IVSHMEM_CLIENT_DEBUG(client, "connect to client %s\n",
>                           client->unix_sock_path);
> @@ -401,7 +402,7 @@ ivshmem_client_notify_broadcast(const IvshmemClient *client)
>  
>  /* lookup peer from its id */
>  IvshmemClientPeer *
> -ivshmem_client_search_peer(IvshmemClient *client, long peer_id)
> +ivshmem_client_search_peer(IvshmemClient *client, int64_t peer_id)
>  {
>      IvshmemClientPeer *peer;
>  
> diff --git a/contrib/ivshmem-client/ivshmem-client.h b/contrib/ivshmem-client/ivshmem-client.h
> index 9215f34..3a4f809 100644
> --- a/contrib/ivshmem-client/ivshmem-client.h
> +++ b/contrib/ivshmem-client/ivshmem-client.h
> @@ -43,7 +43,7 @@
>   */
>  typedef struct IvshmemClientPeer {
>      QTAILQ_ENTRY(IvshmemClientPeer) next;    /**< next in list*/
> -    long id;                                 /**< the id of the peer */
> +    int64_t id;                              /**< the id of the peer */
>      int vectors[IVSHMEM_CLIENT_MAX_VECTORS]; /**< one fd per vector */
>      unsigned vectors_count;                  /**< number of vectors */
>  } IvshmemClientPeer;
> @@ -198,7 +198,7 @@ int ivshmem_client_notify_broadcast(const IvshmemClient *client);
>   * Returns:  The peer structure, or NULL if not found
>   */
>  IvshmemClientPeer *
> -ivshmem_client_search_peer(IvshmemClient *client, long peer_id);
> +ivshmem_client_search_peer(IvshmemClient *client, int64_t peer_id);
>  
>  /**
>   * Dump information of this ivshmem client on stdout
> diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
> index 060f414..3742a78 100644
> --- a/contrib/ivshmem-server/ivshmem-server.c
> +++ b/contrib/ivshmem-server/ivshmem-server.c
> @@ -33,7 +33,7 @@
>  
>  /* send message to a client unix socket */
>  static int
> -ivshmem_server_send_one_msg(int sock_fd, long peer_id, int fd)
> +ivshmem_server_send_one_msg(int sock_fd, int64_t peer_id, int fd)
>  {
>      int ret;
>      struct msghdr msg;
> @@ -44,6 +44,7 @@ ivshmem_server_send_one_msg(int sock_fd, long peer_id, int fd)
>      } msg_control;
>      struct cmsghdr *cmsg;
>  
> +    peer_id = GINT64_TO_LE(peer_id);
>      iov[0].iov_base = &peer_id;
>      iov[0].iov_len = sizeof(peer_id);
>  
> @@ -448,7 +449,7 @@ ivshmem_server_handle_fds(IvshmemServer *server, fd_set *fds, int maxfd)
>  
>  /* lookup peer from its id */
>  IvshmemServerPeer *
> -ivshmem_server_search_peer(IvshmemServer *server, long peer_id)
> +ivshmem_server_search_peer(IvshmemServer *server, int64_t peer_id)
>  {
>      IvshmemServerPeer *peer;
>  
> diff --git a/contrib/ivshmem-server/ivshmem-server.h b/contrib/ivshmem-server/ivshmem-server.h
> index 65b3c2d..d179f22 100644
> --- a/contrib/ivshmem-server/ivshmem-server.h
> +++ b/contrib/ivshmem-server/ivshmem-server.h
> @@ -50,7 +50,7 @@
>  typedef struct IvshmemServerPeer {
>      QTAILQ_ENTRY(IvshmemServerPeer) next;    /**< next in list*/
>      int sock_fd;                             /**< connected unix sock */
> -    long id;                                 /**< the id of the peer */
> +    int64_t id;                              /**< the id of the peer */
>      int vectors[IVSHMEM_SERVER_MAX_VECTORS]; /**< one fd per vector */
>      unsigned vectors_count;                  /**< number of vectors */
>  } IvshmemServerPeer;
> @@ -154,7 +154,7 @@ int ivshmem_server_handle_fds(IvshmemServer *server, fd_set *fds, int maxfd);
>   * Returns:  The peer structure, or NULL if not found
>   */
>  IvshmemServerPeer *
> -ivshmem_server_search_peer(IvshmemServer *server, long peer_id);
> +ivshmem_server_search_peer(IvshmemServer *server, int64_t peer_id);
>  
>  /**
>   * Dump information of this ivshmem server and its peers on stdout
> diff --git a/docs/specs/ivshmem_device_spec.txt b/docs/specs/ivshmem_device_spec.txt
> index 3435116..d318d65 100644
> --- a/docs/specs/ivshmem_device_spec.txt
> +++ b/docs/specs/ivshmem_device_spec.txt
> @@ -61,7 +61,7 @@ This server code is available in qemu.git/contrib/ivshmem-server.
>  
>  The server must be started on the host before any guest.
>  It creates a shared memory object then waits for clients to connect on a unix
> -socket.
> +socket. All the messages are little-endian int64_t integer.
>  
>  For each client (QEMU process) that connects to the server:
>  - the server sends a protocol version, if client does not support it, the client
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index 39c0791..71e58b8 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -276,7 +276,7 @@ static void ivshmem_receive(void *opaque, const uint8_t *buf, int size)
>  
>  static int ivshmem_can_receive(void * opaque)
>  {
> -    return sizeof(long);
> +    return sizeof(int64_t);
>  }
>  
>  static void ivshmem_event(void *opaque, int event)
> @@ -516,7 +516,7 @@ static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size,
>      const uint8_t *p;
>      uint32_t num;
>  
> -    assert(len <= sizeof(long)); /* limitation of the fifo */
> +    assert(len <= sizeof(int64_t)); /* limitation of the fifo */
>      if (fifo8_is_empty(&s->incoming_fifo) && size == len) {
>          memcpy(data, buf, size);
>          return true;
> @@ -524,7 +524,7 @@ static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size,
>  
>      IVSHMEM_DPRINTF("short read of %d bytes\n", size);
>  
> -    num = MIN(size, sizeof(long) - fifo8_num_used(&s->incoming_fifo));
> +    num = MIN(size, sizeof(int64_t) - fifo8_num_used(&s->incoming_fifo));
>      fifo8_push_all(&s->incoming_fifo, buf, num);
>  
>      if (fifo8_num_used(&s->incoming_fifo) < len) {
> @@ -546,6 +546,17 @@ static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size,
>      return true;
>  }
>  
> +static bool fifo_update_and_get_i64(IVShmemState *s,
> +                                    const uint8_t *buf, int size, int64_t *i64)
> +{
> +    if (fifo_update_and_get(s, buf, size, i64, sizeof(*i64))) {
> +        *i64 = GINT64_FROM_LE(*i64);
> +        return true;
> +    }
> +
> +    return false;
> +}
> +
>  static int ivshmem_add_kvm_msi_virq(IVShmemState *s, int vector)
>  {
>      PCIDevice *pdev = PCI_DEVICE(s);
> @@ -598,12 +609,11 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size)
>      IVShmemState *s = opaque;
>      int incoming_fd;
>      int new_eventfd;
> -    long incoming_posn;
> +    int64_t incoming_posn;
>      Error *err = NULL;
>      Peer *peer;
>  
> -    if (!fifo_update_and_get(s, buf, size,
> -                             &incoming_posn, sizeof(incoming_posn))) {
> +    if (!fifo_update_and_get_i64(s, buf, size, &incoming_posn)) {
>          return;
>      }
>  
> @@ -711,10 +721,9 @@ static void ivshmem_check_version(void *opaque, const uint8_t * buf, int size)
>  {
>      IVShmemState *s = opaque;
>      int tmp;
> -    long version;
> +    int64_t version;
>  
> -    if (!fifo_update_and_get(s, buf, size,
> -                             &version, sizeof(version))) {
> +    if (!fifo_update_and_get_i64(s, buf, size, &version)) {
>          return;
>      }
>  
> @@ -869,7 +878,7 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error **errp)
>          s->ivshmem_size = size;
>      }
>  
> -    fifo8_create(&s->incoming_fifo, sizeof(long));
> +    fifo8_create(&s->incoming_fifo, sizeof(int64_t));
>  
>      /* IRQFD requires MSI */
>      if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD) &&
> 

Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>

      reply	other threads:[~2015-09-29 14:28 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-24 11:37 [Qemu-devel] [PATCH v4 00/47] ivshmem improvements marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 01/47] char: add qemu_chr_free() marcandre.lureau
2015-09-29 13:13   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 02/47] msix: add VMSTATE_MSIX_TEST marcandre.lureau
2015-09-29 13:14   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 03/47] ivhsmem: read do not accept more than sizeof(long) marcandre.lureau
2015-09-29 13:15   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 04/47] ivshmem: fix number of bytes to push to fifo marcandre.lureau
2015-09-29 12:40   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 05/47] ivshmem: factor out the incoming fifo handling marcandre.lureau
2015-09-29 12:41   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 06/47] ivshmem: remove unnecessary dup() marcandre.lureau
2015-09-29 12:41   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 07/47] ivshmem: remove superflous ivshmem_attr field marcandre.lureau
2015-09-29 12:42   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 08/47] ivshmem: remove useless doorbell field marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 09/47] ivshmem: more qdev conversion marcandre.lureau
2015-09-29 12:42   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 10/47] ivshmem: remove last exit(1) marcandre.lureau
2015-09-29 12:43   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 11/47] ivshmem: limit maximum number of peers to G_MAXUINT16 marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 12/47] ivshmem: simplify around increase_dynamic_storage() marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 13/47] ivshmem: allocate eventfds in resize_peers() marcandre.lureau
2015-09-29 12:44   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 14/47] ivshmem: remove useless ivshmem_update_irq() val argument marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 15/47] ivshmem: initialize max_peer to -1 marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 16/47] ivshmem: remove max_peer field marcandre.lureau
2015-09-29 12:44   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 17/47] ivshmem: improve debug messages marcandre.lureau
2015-09-29 13:00   ` Claudio Fontana
2015-09-29 13:12     ` Marc-André Lureau
2015-09-29 13:21       ` Claudio Fontana
2015-09-29 13:24         ` Marc-André Lureau
2015-09-29 13:36           ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 18/47] ivshmem: improve error handling marcandre.lureau
2015-09-29 13:01   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 19/47] ivshmem: print error on invalid peer id marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 20/47] ivshmem: simplify a bit the code marcandre.lureau
2015-09-29 13:04   ` Claudio Fontana
2015-09-29 13:06     ` Marc-André Lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 21/47] ivshmem: use common return marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 22/47] ivshmem: use common is_power_of_2() marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 23/47] ivshmem: migrate with VMStateDescription marcandre.lureau
2015-09-29 13:28   ` Claudio Fontana
2015-09-29 13:39     ` Marc-André Lureau
2015-09-29 14:15       ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 24/47] ivshmem: shmfd can be 0 marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 25/47] ivshmem: check shm isn't already initialized marcandre.lureau
2015-09-29 13:32   ` Claudio Fontana
2015-09-29 13:34     ` Marc-André Lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 26/47] ivshmem: add device description marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 27/47] ivshmem: fix pci_ivshmem_exit() marcandre.lureau
2015-09-29 13:38   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 28/47] ivshmem: replace 'guest' for 'peer' appropriately marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 29/47] ivshmem: error on too many eventfd received marcandre.lureau
2015-09-29 13:39   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 30/47] ivshmem: reset mask on device reset marcandre.lureau
2015-09-29 13:40   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 31/47] contrib: add ivshmem client and server marcandre.lureau
2015-09-30  8:37   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 32/47] ivshmem-client: check the number of vectors marcandre.lureau
2015-09-29 13:47   ` Claudio Fontana
2015-09-29 14:01     ` Marc-André Lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 33/47] ivshmem-server: use a uint16 for client ID marcandre.lureau
2015-09-29 13:51   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 34/47] ivshmem-server: fix hugetlbfs support marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 35/47] docs: update ivshmem device spec marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 36/47] ivshmem: add check on protocol version in QEMU marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 37/47] contrib: remove unnecessary strdup() marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 38/47] msix: implement pba write (but read-only) marcandre.lureau
2015-10-02 13:47   ` Paolo Bonzini
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 39/47] qtest: add qtest_add_abrt_handler() marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 40/47] tests: add ivshmem qtest marcandre.lureau
2015-09-29 15:05   ` Claudio Fontana
2015-09-29 15:30     ` Marc-André Lureau
2015-09-30 11:38   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 41/47] ivshmem: do not keep shm_fd open marcandre.lureau
2015-09-29 15:10   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 42/47] ivshmem: use strtosz() marcandre.lureau
2015-09-24 12:13   ` Marc-André Lureau
2015-09-24 12:33     ` Marc-André Lureau
2015-09-29 14:34   ` Claudio Fontana
2015-09-29 14:51     ` Marc-André Lureau
2015-09-30  8:39   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 43/47] ivshmem: add hostmem backend marcandre.lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 44/47] ivshmem: remove EventfdEntry.vector marcandre.lureau
2015-09-29 14:32   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 45/47] ivshmem: rename MSI eventfd_table marcandre.lureau
2015-09-29 15:11   ` Claudio Fontana
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 46/47] ivshmem: use kvm irqfd for msi notifications marcandre.lureau
2015-09-30 11:47   ` Claudio Fontana
2015-10-02 13:29     ` Marc-André Lureau
2015-09-24 11:37 ` [Qemu-devel] [PATCH v4 47/47] ivshmem: use little-endian int64_t for the protocol marcandre.lureau
2015-09-29 14:28   ` Claudio Fontana [this message]

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=560AA001.9050208@huawei.com \
    --to=claudio.fontana@huawei.com \
    --cc=cam@cs.ualberta.ca \
    --cc=drjones@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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.