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