yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-Avoid-embedding-struct-mbuf-in-other-structures.patch

5d360b
From fba60972ebac4bd02238c9ecb101b24b1e7a8a51 Mon Sep 17 00:00:00 2001
5d360b
From: Xiao Wang <jasowang@redhat.com>
5d360b
Date: Mon, 27 Nov 2017 07:07:55 +0100
5d360b
Subject: [PATCH 4/9] Avoid embedding struct mbuf in other structures
5d360b
5d360b
RH-Author: Xiao Wang <jasowang@redhat.com>
5d360b
Message-id: <1511766477-29559-3-git-send-email-jasowang@redhat.com>
5d360b
Patchwork-id: 77900
5d360b
O-Subject: [RHEL7.5 qemu-kvm PATCH 2/4] Avoid embedding struct mbuf in other structures
5d360b
Bugzilla: 1508745
5d360b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
5d360b
RH-Acked-by: wexu@redhat.com
5d360b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
5d360b
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
5d360b
5d360b
struct mbuf uses a C99 open char array to allow inlining data. Inlining
5d360b
this in another structure is however a GNU extension. The inlines used
5d360b
so far in struct Slirp were actually only needed as head of struct
5d360b
mbuf lists. This replaces these inline with mere struct quehead,
5d360b
and use casts as appropriate.
5d360b
5d360b
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
5d360b
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5d360b
(cherry picked from commit 67e3eee45460129cbc5a90fb9f74eb52594281cd)
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 slirp/if.c    | 27 ++++++++++++++-------------
5d360b
 slirp/mbuf.c  | 19 ++++++++++---------
5d360b
 slirp/misc.c  |  5 -----
5d360b
 slirp/misc.h  |  5 +++++
5d360b
 slirp/slirp.h |  8 +++++---
5d360b
 5 files changed, 34 insertions(+), 30 deletions(-)
5d360b
5d360b
diff --git a/slirp/if.c b/slirp/if.c
5d360b
index dcd5faf..5e14761 100644
5d360b
--- a/slirp/if.c
5d360b
+++ b/slirp/if.c
5d360b
@@ -27,9 +27,9 @@ ifs_remque(struct mbuf *ifm)
5d360b
 void
5d360b
 if_init(Slirp *slirp)
5d360b
 {
5d360b
-    slirp->if_fastq.ifq_next = slirp->if_fastq.ifq_prev = &slirp->if_fastq;
5d360b
-    slirp->if_batchq.ifq_next = slirp->if_batchq.ifq_prev = &slirp->if_batchq;
5d360b
-    slirp->next_m = &slirp->if_batchq;
5d360b
+    slirp->if_fastq.qh_link = slirp->if_fastq.qh_rlink = &slirp->if_fastq;
5d360b
+    slirp->if_batchq.qh_link = slirp->if_batchq.qh_rlink = &slirp->if_batchq;
5d360b
+    slirp->next_m = (struct mbuf *) &slirp->if_batchq;
5d360b
 }
5d360b
 
5d360b
 /*
5d360b
@@ -73,7 +73,8 @@ if_output(struct socket *so, struct mbuf *ifm)
5d360b
 	 * We mustn't put this packet back on the fastq (or we'll send it out of order)
5d360b
 	 * XXX add cache here?
5d360b
 	 */
5d360b
-	for (ifq = slirp->if_batchq.ifq_prev; ifq != &slirp->if_batchq;
5d360b
+	for (ifq = (struct mbuf *) slirp->if_batchq.qh_rlink;
5d360b
+	     (struct quehead *) ifq != &slirp->if_batchq;
5d360b
 	     ifq = ifq->ifq_prev) {
5d360b
 		if (so == ifq->ifq_so) {
5d360b
 			/* A match! */
5d360b
@@ -85,7 +86,7 @@ if_output(struct socket *so, struct mbuf *ifm)
5d360b
 
5d360b
 	/* No match, check which queue to put it on */
5d360b
 	if (so && (so->so_iptos & IPTOS_LOWDELAY)) {
5d360b
-		ifq = slirp->if_fastq.ifq_prev;
5d360b
+		ifq = (struct mbuf *) slirp->if_fastq.qh_rlink;
5d360b
 		on_fastq = 1;
5d360b
 		/*
5d360b
 		 * Check if this packet is a part of the last
5d360b
@@ -97,9 +98,9 @@ if_output(struct socket *so, struct mbuf *ifm)
5d360b
 			goto diddit;
5d360b
 		}
5d360b
         } else {
5d360b
-		ifq = slirp->if_batchq.ifq_prev;
5d360b
+		ifq = (struct mbuf *) slirp->if_batchq.qh_rlink;
5d360b
                 /* Set next_m if the queue was empty so far */
5d360b
-                if (slirp->next_m == &slirp->if_batchq) {
5d360b
+                if ((struct quehead *) slirp->next_m == &slirp->if_batchq) {
5d360b
                     slirp->next_m = ifm;
5d360b
                 }
5d360b
         }
5d360b
@@ -165,10 +166,10 @@ void if_start(Slirp *slirp)
5d360b
     }
5d360b
     slirp->if_start_busy = true;
5d360b
 
5d360b
-    if (slirp->if_fastq.ifq_next != &slirp->if_fastq) {
5d360b
-        ifm_next = slirp->if_fastq.ifq_next;
5d360b
+    if (slirp->if_fastq.qh_link != &slirp->if_fastq) {
5d360b
+        ifm_next = (struct mbuf *) slirp->if_fastq.qh_link;
5d360b
         next_from_batchq = false;
5d360b
-    } else if (slirp->next_m != &slirp->if_batchq) {
5d360b
+    } else if ((struct quehead *) slirp->next_m != &slirp->if_batchq) {
5d360b
         /* Nothing on fastq, pick up from batchq via next_m */
5d360b
         ifm_next = slirp->next_m;
5d360b
         next_from_batchq = true;
5d360b
@@ -181,12 +182,12 @@ void if_start(Slirp *slirp)
5d360b
         from_batchq = next_from_batchq;
5d360b
 
5d360b
         ifm_next = ifm->ifq_next;
5d360b
-        if (ifm_next == &slirp->if_fastq) {
5d360b
+        if ((struct quehead *) ifm_next == &slirp->if_fastq) {
5d360b
             /* No more packets in fastq, switch to batchq */
5d360b
             ifm_next = slirp->next_m;
5d360b
             next_from_batchq = true;
5d360b
         }
5d360b
-        if (ifm_next == &slirp->if_batchq) {
5d360b
+        if ((struct quehead *) ifm_next == &slirp->if_batchq) {
5d360b
             /* end of batchq */
5d360b
             ifm_next = NULL;
5d360b
         }
5d360b
@@ -217,7 +218,7 @@ void if_start(Slirp *slirp)
5d360b
                 /* Next packet in fastq is from the same session */
5d360b
                 ifm_next = next;
5d360b
                 next_from_batchq = false;
5d360b
-            } else if (slirp->next_m == &slirp->if_batchq) {
5d360b
+            } else if ((struct quehead *) slirp->next_m == &slirp->if_batchq) {
5d360b
                 /* Set next_m and ifm_next if the session packet is now the
5d360b
                  * only one on batchq */
5d360b
                 slirp->next_m = ifm_next = next;
5d360b
diff --git a/slirp/mbuf.c b/slirp/mbuf.c
5d360b
index 4fefb04..5565fd1 100644
5d360b
--- a/slirp/mbuf.c
5d360b
+++ b/slirp/mbuf.c
5d360b
@@ -28,16 +28,16 @@
5d360b
 void
5d360b
 m_init(Slirp *slirp)
5d360b
 {
5d360b
-    slirp->m_freelist.m_next = slirp->m_freelist.m_prev = &slirp->m_freelist;
5d360b
-    slirp->m_usedlist.m_next = slirp->m_usedlist.m_prev = &slirp->m_usedlist;
5d360b
+    slirp->m_freelist.qh_link = slirp->m_freelist.qh_rlink = &slirp->m_freelist;
5d360b
+    slirp->m_usedlist.qh_link = slirp->m_usedlist.qh_rlink = &slirp->m_usedlist;
5d360b
 }
5d360b
 
5d360b
 void m_cleanup(Slirp *slirp)
5d360b
 {
5d360b
     struct mbuf *m, *next;
5d360b
 
5d360b
-    m = slirp->m_usedlist.m_next;
5d360b
-    while (m != &slirp->m_usedlist) {
5d360b
+    m = (struct mbuf *) slirp->m_usedlist.qh_link;
5d360b
+    while ((struct quehead *) m != &slirp->m_usedlist) {
5d360b
         next = m->m_next;
5d360b
         if (m->m_flags & M_EXT) {
5d360b
             free(m->m_ext);
5d360b
@@ -45,8 +45,8 @@ void m_cleanup(Slirp *slirp)
5d360b
         free(m);
5d360b
         m = next;
5d360b
     }
5d360b
-    m = slirp->m_freelist.m_next;
5d360b
-    while (m != &slirp->m_freelist) {
5d360b
+    m = (struct mbuf *) slirp->m_freelist.qh_link;
5d360b
+    while ((struct quehead *) m != &slirp->m_freelist) {
5d360b
         next = m->m_next;
5d360b
         free(m);
5d360b
         m = next;
5d360b
@@ -69,7 +69,7 @@ m_get(Slirp *slirp)
5d360b
 
5d360b
 	DEBUG_CALL("m_get");
5d360b
 
5d360b
-	if (slirp->m_freelist.m_next == &slirp->m_freelist) {
5d360b
+	if (slirp->m_freelist.qh_link == &slirp->m_freelist) {
5d360b
 		m = (struct mbuf *)malloc(SLIRP_MSIZE);
5d360b
 		if (m == NULL) goto end_error;
5d360b
 		slirp->mbuf_alloced++;
5d360b
@@ -77,7 +77,7 @@ m_get(Slirp *slirp)
5d360b
 			flags = M_DOFREE;
5d360b
 		m->slirp = slirp;
5d360b
 	} else {
5d360b
-		m = slirp->m_freelist.m_next;
5d360b
+		m = (struct mbuf *) slirp->m_freelist.qh_link;
5d360b
 		remque(m);
5d360b
 	}
5d360b
 
5d360b
@@ -224,7 +224,8 @@ dtom(Slirp *slirp, void *dat)
5d360b
 	DEBUG_ARG("dat = %lx", (long )dat);
5d360b
 
5d360b
 	/* bug corrected for M_EXT buffers */
5d360b
-	for (m = slirp->m_usedlist.m_next; m != &slirp->m_usedlist;
5d360b
+	for (m = (struct mbuf *) slirp->m_usedlist.qh_link;
5d360b
+	     (struct quehead *) m != &slirp->m_usedlist;
5d360b
 	     m = m->m_next) {
5d360b
 	  if (m->m_flags & M_EXT) {
5d360b
 	    if( (char *)dat>=m->m_ext && (char *)dat<(m->m_ext + m->m_size) )
5d360b
diff --git a/slirp/misc.c b/slirp/misc.c
5d360b
index 8ecced5..d353d08 100644
5d360b
--- a/slirp/misc.c
5d360b
+++ b/slirp/misc.c
5d360b
@@ -14,11 +14,6 @@
5d360b
 int slirp_debug = DBG_CALL|DBG_MISC|DBG_ERROR;
5d360b
 #endif
5d360b
 
5d360b
-struct quehead {
5d360b
-	struct quehead *qh_link;
5d360b
-	struct quehead *qh_rlink;
5d360b
-};
5d360b
-
5d360b
 inline void
5d360b
 insque(void *a, void *b)
5d360b
 {
5d360b
diff --git a/slirp/misc.h b/slirp/misc.h
5d360b
index ba8beb1..eb451c4 100644
5d360b
--- a/slirp/misc.h
5d360b
+++ b/slirp/misc.h
5d360b
@@ -49,6 +49,11 @@ struct emu_t {
5d360b
     struct emu_t *next;
5d360b
 };
5d360b
 
5d360b
+struct slirp_quehead {
5d360b
+    struct slirp_quehead *qh_link;
5d360b
+    struct slirp_quehead *qh_rlink;
5d360b
+};
5d360b
+
5d360b
 void slirp_insque(void *, void *);
5d360b
 void slirp_remque(void *);
5d360b
 int add_exec(struct ex_list **, int, char *, struct in_addr, int);
5d360b
diff --git a/slirp/slirp.h b/slirp/slirp.h
5d360b
index fe0e65d..d050ede 100644
5d360b
--- a/slirp/slirp.h
5d360b
+++ b/slirp/slirp.h
5d360b
@@ -126,6 +126,7 @@ void free(void *ptr);
5d360b
    have different prototypes. */
5d360b
 #define insque slirp_insque
5d360b
 #define remque slirp_remque
5d360b
+#define quehead slirp_quehead
5d360b
 
5d360b
 #ifdef HAVE_SYS_STROPTS_H
5d360b
 #include <sys/stropts.h>
5d360b
@@ -218,12 +219,13 @@ struct Slirp {
5d360b
     struct ex_list *exec_list;
5d360b
 
5d360b
     /* mbuf states */
5d360b
-    struct mbuf m_freelist, m_usedlist;
5d360b
+    struct quehead m_freelist;
5d360b
+    struct quehead m_usedlist;
5d360b
     int mbuf_alloced;
5d360b
 
5d360b
     /* if states */
5d360b
-    struct mbuf if_fastq;   /* fast queue (for interactive data) */
5d360b
-    struct mbuf if_batchq;  /* queue for non-interactive data */
5d360b
+    struct quehead if_fastq;   /* fast queue (for interactive data) */
5d360b
+    struct quehead if_batchq;  /* queue for non-interactive data */
5d360b
     struct mbuf *next_m;    /* pointer to next mbuf to output */
5d360b
     bool if_start_busy;     /* avoid if_start recursion */
5d360b
 
5d360b
-- 
5d360b
1.8.3.1
5d360b