diff --git a/contrib/ivshmem-client/ivshmem-client.c b/contrib/ivshmem-client/ivshmem-client.c
index 3f6ca98..ce3a5d2 100644
--- a/contrib/ivshmem-client/ivshmem-client.c
+++ b/contrib/ivshmem-client/ivshmem-client.c
@@ -14,12 +14,13 @@
 #include <signal.h>
 #include <unistd.h>
 #include <inttypes.h>
-#include <sys/queue.h>
 
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include "qemu/queue.h"
+
 #include "ivshmem-client.h"
 
 /* log a message on stdout if verbose=1 */
@@ -84,7 +85,7 @@ free_peer(IvshmemClient *client, IvshmemClientPeer *peer)
 {
     unsigned vector;
 
-    TAILQ_REMOVE(&client->peer_list, peer, next);
+    QTAILQ_REMOVE(&client->peer_list, peer, next);
     for (vector = 0; vector < peer->vectors_count; vector++) {
         close(peer->vectors[vector]);
     }
@@ -131,7 +132,7 @@ handle_server_msg(IvshmemClient *client)
         memset(peer, 0, sizeof(*peer));
         peer->id = peer_id;
         peer->vectors_count = 0;
-        TAILQ_INSERT_TAIL(&client->peer_list, peer, next);
+        QTAILQ_INSERT_TAIL(&client->peer_list, peer, next);
         debug_log(client, "new peer id = %ld\n", peer_id);
     }
 
@@ -161,7 +162,7 @@ ivshmem_client_init(IvshmemClient *client, const char *unix_sock_path,
         client->local.vectors[i] = -1;
     }
 
-    TAILQ_INIT(&client->peer_list);
+    QTAILQ_INIT(&client->peer_list);
     client->local.id = -1;
 
     client->notif_cb = notif_cb;
@@ -230,7 +231,7 @@ ivshmem_client_close(IvshmemClient *client)
 
     debug_log(client, "close client\n");
 
-    while ((peer = TAILQ_FIRST(&client->peer_list)) != NULL) {
+    while ((peer = QTAILQ_FIRST(&client->peer_list)) != NULL) {
         free_peer(client, peer);
     }
 
@@ -363,7 +364,7 @@ ivshmem_client_notify_broadcast(const IvshmemClient *client)
     IvshmemClientPeer *peer;
     int ret = 0;
 
-    TAILQ_FOREACH(peer, &client->peer_list, next) {
+    QTAILQ_FOREACH(peer, &client->peer_list, next) {
         if (ivshmem_client_notify_all_vects(client, peer) < 0) {
             ret = -1;
         }
@@ -382,7 +383,7 @@ ivshmem_client_search_peer(IvshmemClient *client, long peer_id)
         return &client->local;
     }
 
-    TAILQ_FOREACH(peer, &client->peer_list, next) {
+    QTAILQ_FOREACH(peer, &client->peer_list, next) {
         if (peer->id == peer_id) {
             return peer;
         }
@@ -406,7 +407,7 @@ ivshmem_client_dump(const IvshmemClient *client)
     }
 
     /* dump peers */
-    TAILQ_FOREACH(peer, &client->peer_list, next) {
+    QTAILQ_FOREACH(peer, &client->peer_list, next) {
         printf("peer_id = %ld\n", peer->id);
 
         for (vector = 0; vector < peer->vectors_count; vector++) {
diff --git a/contrib/ivshmem-client/ivshmem-client.h b/contrib/ivshmem-client/ivshmem-client.h
index 0fe0c94..e3b284d 100644
--- a/contrib/ivshmem-client/ivshmem-client.h
+++ b/contrib/ivshmem-client/ivshmem-client.h
@@ -21,7 +21,8 @@
 
 #include <limits.h>
 #include <sys/select.h>
-#include <sys/queue.h>
+
+#include "qemu/queue.h"
 
 /**
  * Maximum number of notification vectors supported by the client
@@ -40,12 +41,12 @@
  * client in (IvshmemClient)->local.
  */
 typedef struct IvshmemClientPeer {
-    TAILQ_ENTRY(IvshmemClientPeer) next;     /**< next in list*/
+    QTAILQ_ENTRY(IvshmemClientPeer) next;    /**< next in list*/
     long id;                                 /**< the id of the peer */
     int vectors[IVSHMEM_CLIENT_MAX_VECTORS]; /**< one fd per vector */
     unsigned vectors_count;                  /**< number of vectors */
 } IvshmemClientPeer;
-TAILQ_HEAD(IvshmemClientPeerList, IvshmemClientPeer);
+QTAILQ_HEAD(IvshmemClientPeerList, IvshmemClientPeer);
 
 typedef struct IvshmemClientPeerList IvshmemClientPeerList;
 typedef struct IvshmemClient IvshmemClient;
diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
index 20fbac0..e58864d 100644
--- a/contrib/ivshmem-server/ivshmem-server.c
+++ b/contrib/ivshmem-server/ivshmem-server.c
@@ -16,7 +16,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 
-#include <sys/queue.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -24,6 +23,8 @@
 #include <sys/un.h>
 #include <sys/eventfd.h>
 
+#include "qemu/queue.h"
+
 #include "ivshmem-server.h"
 
 /* log a message on stdout if verbose=1 */
@@ -33,14 +34,6 @@
         }                                \
     } while (0)
 
-/* browse the queue, allowing to remove/free the current element */
-#define    TAILQ_FOREACH_SAFE(var, var2, head, field)            \
-    for ((var) = TAILQ_FIRST((head)),                            \
-             (var2) = ((var) ? TAILQ_NEXT((var), field) : NULL); \
-         (var);                                                  \
-         (var) = (var2),                                         \
-             (var2) = ((var2) ? TAILQ_NEXT((var2), field) : NULL))
-
 /** maximum size of a huge page, used by ivshmem_ftruncate() */
 #define MAX_HUGEPAGE_SIZE (1024 * 1024 * 1024)
 
@@ -96,10 +89,10 @@ free_peer(IvshmemServer *server, IvshmemServerPeer *peer)
 
     debug_log(server, "free peer %ld\n", peer->id);
     close(peer->sock_fd);
-    TAILQ_REMOVE(&server->peer_list, peer, next);
+    QTAILQ_REMOVE(&server->peer_list, peer, next);
 
     /* advertise the deletion to other peers */
-    TAILQ_FOREACH(other_peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(other_peer, &server->peer_list, next) {
         send_one_msg(other_peer->sock_fd, peer->id, -1);
     }
 
@@ -188,14 +181,14 @@ handle_new_conn(IvshmemServer *server)
     }
 
     /* advertise the new peer to others */
-    TAILQ_FOREACH(other_peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(other_peer, &server->peer_list, next) {
         for (i = 0; i < peer->vectors_count; i++) {
             send_one_msg(other_peer->sock_fd, peer->id, peer->vectors[i]);
         }
     }
 
     /* advertise the other peers to the new one */
-    TAILQ_FOREACH(other_peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(other_peer, &server->peer_list, next) {
         for (i = 0; i < peer->vectors_count; i++) {
             send_one_msg(peer->sock_fd, other_peer->id, other_peer->vectors[i]);
         }
@@ -206,7 +199,7 @@ handle_new_conn(IvshmemServer *server)
         send_one_msg(peer->sock_fd, peer->id, peer->vectors[i]);
     }
 
-    TAILQ_INSERT_TAIL(&server->peer_list, peer, next);
+    QTAILQ_INSERT_TAIL(&server->peer_list, peer, next);
     debug_log(server, "new peer id = %ld\n", peer->id);
     return 0;
 
@@ -266,7 +259,7 @@ ivshmem_server_init(IvshmemServer *server, const char *unix_sock_path,
     server->n_vectors = n_vectors;
     server->verbose = verbose;
 
-    TAILQ_INIT(&server->peer_list);
+    QTAILQ_INIT(&server->peer_list);
 
     return 0;
 }
@@ -333,7 +326,7 @@ ivshmem_server_close(IvshmemServer *server)
 
     debug_log(server, "close server\n");
 
-    TAILQ_FOREACH(peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(peer, &server->peer_list, next) {
         free_peer(server, peer);
     }
 
@@ -354,7 +347,7 @@ ivshmem_server_get_fds(const IvshmemServer *server, fd_set *fds, int *maxfd)
         *maxfd = server->sock_fd + 1;
     }
 
-    TAILQ_FOREACH(peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(peer, &server->peer_list, next) {
         FD_SET(peer->sock_fd, fds);
         if (peer->sock_fd >= *maxfd) {
             *maxfd = peer->sock_fd + 1;
@@ -374,7 +367,7 @@ ivshmem_server_handle_fds(IvshmemServer *server, fd_set *fds, int maxfd)
         return -1;
     }
 
-    TAILQ_FOREACH_SAFE(peer, peer_next, &server->peer_list, next) {
+    QTAILQ_FOREACH_SAFE(peer, &server->peer_list, next, peer_next) {
         /* any message from a peer socket result in a close() */
         debug_log(server, "peer->sock_fd=%d\n", peer->sock_fd);
         if (peer->sock_fd < maxfd && FD_ISSET(peer->sock_fd, fds)) {
@@ -391,7 +384,7 @@ ivshmem_server_search_peer(IvshmemServer *server, long peer_id)
 {
     IvshmemServerPeer *peer;
 
-    TAILQ_FOREACH(peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(peer, &server->peer_list, next) {
         if (peer->id == peer_id) {
             return peer;
         }
@@ -407,7 +400,7 @@ ivshmem_server_dump(const IvshmemServer *server)
     unsigned vector;
 
     /* dump peers */
-    TAILQ_FOREACH(peer, &server->peer_list, next) {
+    QTAILQ_FOREACH(peer, &server->peer_list, next) {
         printf("peer_id = %ld\n", peer->id);
 
         for (vector = 0; vector < peer->vectors_count; vector++) {
diff --git a/contrib/ivshmem-server/ivshmem-server.h b/contrib/ivshmem-server/ivshmem-server.h
index 42736e4..acd17a8 100644
--- a/contrib/ivshmem-server/ivshmem-server.h
+++ b/contrib/ivshmem-server/ivshmem-server.h
@@ -28,7 +28,8 @@
 
 #include <limits.h>
 #include <sys/select.h>
-#include <sys/queue.h>
+
+#include "qemu/queue.h"
 
 /**
  * Maximum number of notification vectors supported by the server
@@ -44,13 +45,13 @@
  * unix sockets.
  */
 typedef struct IvshmemServerPeer {
-    TAILQ_ENTRY(IvshmemServerPeer) next;     /**< next in list*/
+    QTAILQ_ENTRY(IvshmemServerPeer) next;    /**< next in list*/
     int sock_fd;                             /**< connected unix sock */
     long id;                                 /**< the id of the peer */
     int vectors[IVSHMEM_SERVER_MAX_VECTORS]; /**< one fd per vector */
     unsigned vectors_count;                  /**< number of vectors */
 } IvshmemServerPeer;
-TAILQ_HEAD(IvshmemServerPeerList, IvshmemServerPeer);
+QTAILQ_HEAD(IvshmemServerPeerList, IvshmemServerPeer);
 
 typedef struct IvshmemServerPeerList IvshmemServerPeerList;
 
