From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14887780197046.014589455528835; Sun, 5 Mar 2017 21:26:59 -0800 (PST) Received: from localhost ([::1]:41769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAg-0007eg-DO for importer@patchew.org; Mon, 06 Mar 2017 00:26:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckl9n-0007dk-4Z for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckl9m-0000y6-9z for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckl9m-0000xm-3k for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:02 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 495233DD47; Mon, 6 Mar 2017 05:26:02 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvtt031786; Mon, 6 Mar 2017 00:26:00 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:36 +0800 Message-Id: <1488777954-4578-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 06 Mar 2017 05:26:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 01/19] net: Remove useless local var pkt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Fam Zheng Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng This has been pointless since commit 605d52e62, which was a search-and-replace, overlooked the redundancy. Signed-off-by: Fam Zheng Reviewed-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/net_rx_pkt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 1019b50..7f928d7 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -159,7 +159,6 @@ void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt, void net_rx_pkt_dump(struct NetRxPkt *pkt) { #ifdef NET_RX_PKT_DEBUG - NetRxPkt *pkt =3D (NetRxPkt *)pkt; assert(pkt); =20 printf("RX PKT: tot_len: %d, vlan_stripped: %d, vlan_tag: %d\n", --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778154668577.9106109637798; Sun, 5 Mar 2017 21:29:14 -0800 (PST) Received: from localhost ([::1]:41781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklCr-00015y-EL for importer@patchew.org; Mon, 06 Mar 2017 00:29:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckl9q-0007f1-6o for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckl9p-0000zN-5U for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckl9o-0000ym-Sf; Mon, 06 Mar 2017 00:26:05 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9700C0467CE; Mon, 6 Mar 2017 05:26:04 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvtu031786; Mon, 6 Mar 2017 00:26:02 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:37 +0800 Message-Id: <1488777954-4578-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 02/19] eth: Extend vlan stripping functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Dmitry Fleytman Make VLAN stripping functions return number of bytes copied to given Ethernet header buffer. This information should be used to re-compose packet IOV after VLAN stripping. Cc: qemu-stable@nongnu.org Signed-off-by: Dmitry Fleytman Signed-off-by: Jason Wang --- include/net/eth.h | 4 ++-- net/eth.c | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/net/eth.h b/include/net/eth.h index 2013175..afeb45b 100644 --- a/include/net/eth.h +++ b/include/net/eth.h @@ -331,12 +331,12 @@ eth_get_pkt_tci(const void *p) } } =20 -bool +size_t eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci); =20 -bool +size_t eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, uint16_t vet, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci); diff --git a/net/eth.c b/net/eth.c index df81efb..5b9ba26 100644 --- a/net/eth.c +++ b/net/eth.c @@ -232,7 +232,7 @@ void eth_get_protocols(const struct iovec *iov, int iov= cnt, } } =20 -bool +size_t eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci) @@ -244,7 +244,7 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, siz= e_t iovoff, new_ehdr, sizeof(*new_ehdr)); =20 if (copied < sizeof(*new_ehdr)) { - return false; + return 0; } =20 switch (be16_to_cpu(new_ehdr->h_proto)) { @@ -254,7 +254,7 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, siz= e_t iovoff, &vlan_hdr, sizeof(vlan_hdr)); =20 if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } =20 new_ehdr->h_proto =3D vlan_hdr.h_proto; @@ -268,18 +268,21 @@ eth_strip_vlan(const struct iovec *iov, int iovcnt, s= ize_t iovoff, PKT_GET_VLAN_HDR(new_ehdr), sizeof(vlan_hd= r)); =20 if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } =20 *payload_offset +=3D sizeof(vlan_hdr); + + return sizeof(struct eth_header) + sizeof(struct vlan_header); + } else { + return sizeof(struct eth_header); } - return true; default: - return false; + return 0; } } =20 -bool +size_t eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, uint16_t vet, uint8_t *new_ehdr_buf, uint16_t *payload_offset, uint16_t *tci) @@ -291,7 +294,7 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, = size_t iovoff, new_ehdr, sizeof(*new_ehdr)); =20 if (copied < sizeof(*new_ehdr)) { - return false; + return 0; } =20 if (be16_to_cpu(new_ehdr->h_proto) =3D=3D vet) { @@ -299,17 +302,17 @@ eth_strip_vlan_ex(const struct iovec *iov, int iovcnt= , size_t iovoff, &vlan_hdr, sizeof(vlan_hdr)); =20 if (copied < sizeof(vlan_hdr)) { - return false; + return 0; } =20 new_ehdr->h_proto =3D vlan_hdr.h_proto; =20 *tci =3D be16_to_cpu(vlan_hdr.h_tci); *payload_offset =3D iovoff + sizeof(*new_ehdr) + sizeof(vlan_hdr); - return true; + return sizeof(struct eth_header); } =20 - return false; + return 0; } =20 void --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778151056729.1361683276159; Sun, 5 Mar 2017 21:29:11 -0800 (PST) Received: from localhost ([::1]:41780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklCn-00011G-GY for importer@patchew.org; Mon, 06 Mar 2017 00:29:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckl9v-0007jM-Ce for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckl9s-00010i-1X for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckl9r-00010M-PV; Mon, 06 Mar 2017 00:26:07 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8EF0C0467F0; Mon, 6 Mar 2017 05:26:07 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvtv031786; Mon, 6 Mar 2017 00:26:05 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:38 +0800 Message-Id: <1488777954-4578-4-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 03/19] NetRxPkt: Fix memory corruption on VLAN header stripping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Dmitry Fleytman This patch fixed a problem that was introduced in commit eb700029. When net_rx_pkt_attach_iovec() calls eth_strip_vlan() this can result in pkt->ehdr_buf being overflowed, because ehdr_buf is only sizeof(struct eth_header) bytes large but eth_strip_vlan() can write sizeof(struct eth_header) + sizeof(struct vlan_header) bytes into it. Devices affected by this problem: vmxnet3. Cc: qemu-stable@nongnu.org Reported-by: Peter Maydell Signed-off-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/net_rx_pkt.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 7f928d7..3361d7e 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -23,13 +23,13 @@ =20 struct NetRxPkt { struct virtio_net_hdr virt_hdr; - uint8_t ehdr_buf[sizeof(struct eth_header)]; + uint8_t ehdr_buf[sizeof(struct eth_header) + sizeof(struct vlan_header= )]; struct iovec *vec; uint16_t vec_len_total; uint16_t vec_len; uint32_t tot_len; uint16_t tci; - bool vlan_stripped; + size_t ehdr_buf_len; bool has_virt_hdr; eth_pkt_types_e packet_type; =20 @@ -88,15 +88,13 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, const struct iovec *iov, int iovcnt, size_t ploff) { - if (pkt->vlan_stripped) { + if (pkt->ehdr_buf_len) { net_rx_pkt_iovec_realloc(pkt, iovcnt + 1); =20 pkt->vec[0].iov_base =3D pkt->ehdr_buf; - pkt->vec[0].iov_len =3D sizeof(pkt->ehdr_buf); - - pkt->tot_len =3D - iov_size(iov, iovcnt) - ploff + sizeof(struct eth_header); + pkt->vec[0].iov_len =3D pkt->ehdr_buf_len; =20 + pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, iov, iovcnt, ploff, pkt->tot_len); } else { @@ -123,11 +121,12 @@ void net_rx_pkt_attach_iovec(struct NetRxPkt *pkt, uint16_t tci =3D 0; uint16_t ploff =3D iovoff; assert(pkt); - pkt->vlan_stripped =3D false; =20 if (strip_vlan) { - pkt->vlan_stripped =3D eth_strip_vlan(iov, iovcnt, iovoff, pkt->eh= dr_buf, - &ploff, &tci); + pkt->ehdr_buf_len =3D eth_strip_vlan(iov, iovcnt, iovoff, pkt->ehd= r_buf, + &ploff, &tci); + } else { + pkt->ehdr_buf_len =3D 0; } =20 pkt->tci =3D tci; @@ -143,12 +142,13 @@ void net_rx_pkt_attach_iovec_ex(struct NetRxPkt *pkt, uint16_t tci =3D 0; uint16_t ploff =3D iovoff; assert(pkt); - pkt->vlan_stripped =3D false; =20 if (strip_vlan) { - pkt->vlan_stripped =3D eth_strip_vlan_ex(iov, iovcnt, iovoff, vet, - pkt->ehdr_buf, - &ploff, &tci); + pkt->ehdr_buf_len =3D eth_strip_vlan_ex(iov, iovcnt, iovoff, vet, + pkt->ehdr_buf, + &ploff, &tci); + } else { + pkt->ehdr_buf_len =3D 0; } =20 pkt->tci =3D tci; @@ -161,8 +161,8 @@ void net_rx_pkt_dump(struct NetRxPkt *pkt) #ifdef NET_RX_PKT_DEBUG assert(pkt); =20 - printf("RX PKT: tot_len: %d, vlan_stripped: %d, vlan_tag: %d\n", - pkt->tot_len, pkt->vlan_stripped, pkt->tci); + printf("RX PKT: tot_len: %d, ehdr_buf_len: %lu, vlan_tag: %d\n", + pkt->tot_len, pkt->ehdr_buf_len, pkt->tci); #endif } =20 @@ -425,7 +425,7 @@ bool net_rx_pkt_is_vlan_stripped(struct NetRxPkt *pkt) { assert(pkt); =20 - return pkt->vlan_stripped; + return pkt->ehdr_buf_len ? true : false; } =20 bool net_rx_pkt_has_virt_hdr(struct NetRxPkt *pkt) --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778106061568.8500085752992; Sun, 5 Mar 2017 21:28:26 -0800 (PST) Received: from localhost ([::1]:41778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklC4-0000L4-DH for importer@patchew.org; Mon, 06 Mar 2017 00:28:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckl9v-0007jL-Ce for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckl9u-00012e-Cp for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckl9u-000120-7G; Mon, 06 Mar 2017 00:26:10 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DAFB83F46; Mon, 6 Mar 2017 05:26:10 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvtw031786; Mon, 6 Mar 2017 00:26:08 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:39 +0800 Message-Id: <1488777954-4578-5-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 06 Mar 2017 05:26:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 04/19] NetRxPkt: Do not try to pull more data than present X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Dmitry Fleytman In case of VLAN stripping, ETH header put into a separate buffer, therefore amont of data copied from original IOV should be smaller. Cc: qemu-stable@nongnu.org Signed-off-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/net_rx_pkt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 3361d7e..0003a0e 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -96,7 +96,8 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, =20 pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, - iov, iovcnt, ploff, pkt->tot_len); + iov, iovcnt, ploff, + pkt->tot_len - pkt->ehdr_buf_len); } else { net_rx_pkt_iovec_realloc(pkt, iovcnt); =20 --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778278288677.0825303419356; Sun, 5 Mar 2017 21:31:18 -0800 (PST) Received: from localhost ([::1]:41794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklEr-0002ui-05 for importer@patchew.org; Mon, 06 Mar 2017 00:31:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckl9z-0007oH-8j for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckl9y-000146-D3 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckl9y-00013c-6e; Mon, 06 Mar 2017 00:26:14 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57A11C049D5B; Mon, 6 Mar 2017 05:26:14 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvtx031786; Mon, 6 Mar 2017 00:26:12 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:40 +0800 Message-Id: <1488777954-4578-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 05/19] NetRxPkt: Account buffer with ETH header in IOV length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Dmitry Fleytman In case of VLAN stripping ETH header is stored in a separate chunk and length of IOV should take this into account. This patch fixes checksum validation for RX packets with VLAN header. Devices affected by this problem: e1000e and vmxnet3. Cc: qemu-stable@nongnu.org Signed-off-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/net_rx_pkt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 0003a0e..2649d40 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -97,7 +97,7 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, iov, iovcnt, ploff, - pkt->tot_len - pkt->ehdr_buf_len); + pkt->tot_len - pkt->ehdr_buf_len) + 1; } else { net_rx_pkt_iovec_realloc(pkt, iovcnt); =20 --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778292079837.1139524941722; Sun, 5 Mar 2017 21:31:32 -0800 (PST) Received: from localhost ([::1]:41797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklF4-00036d-P3 for importer@patchew.org; Mon, 06 Mar 2017 00:31:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklA1-0007qR-Jb for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklA0-00015Z-Sr for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklA0-00014x-My for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:16 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE8AB61B84; Mon, 6 Mar 2017 05:26:16 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu0031786; Mon, 6 Mar 2017 00:26:14 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:41 +0800 Message-Id: <1488777954-4578-7-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 06 Mar 2017 05:26:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 06/19] NetRxPkt: Remove code duplication in net_rx_pkt_pull_data() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Fleytman , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Dmitry Fleytman This is a refactoring commit that does not change behavior. Signed-off-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/net_rx_pkt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c index 2649d40..cef1c2e 100644 --- a/hw/net/net_rx_pkt.c +++ b/hw/net/net_rx_pkt.c @@ -88,20 +88,21 @@ net_rx_pkt_pull_data(struct NetRxPkt *pkt, const struct iovec *iov, int iovcnt, size_t ploff) { + uint32_t pllen =3D iov_size(iov, iovcnt) - ploff; + if (pkt->ehdr_buf_len) { net_rx_pkt_iovec_realloc(pkt, iovcnt + 1); =20 pkt->vec[0].iov_base =3D pkt->ehdr_buf; pkt->vec[0].iov_len =3D pkt->ehdr_buf_len; =20 - pkt->tot_len =3D iov_size(iov, iovcnt) - ploff + pkt->ehdr_buf_len; + pkt->tot_len =3D pllen + pkt->ehdr_buf_len; pkt->vec_len =3D iov_copy(pkt->vec + 1, pkt->vec_len_total - 1, - iov, iovcnt, ploff, - pkt->tot_len - pkt->ehdr_buf_len) + 1; + iov, iovcnt, ploff, pllen) + 1; } else { net_rx_pkt_iovec_realloc(pkt, iovcnt); =20 - pkt->tot_len =3D iov_size(iov, iovcnt) - ploff; + pkt->tot_len =3D pllen; pkt->vec_len =3D iov_copy(pkt->vec, pkt->vec_len_total, iov, iovcnt, ploff, pkt->tot_len); } --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778287537194.47790421257355; Sun, 5 Mar 2017 21:31:27 -0800 (PST) Received: from localhost ([::1]:41796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklF0-00033W-5C for importer@patchew.org; Mon, 06 Mar 2017 00:31:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklA4-0007tF-QD for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklA3-00016e-JE for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41854) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklA3-00016S-AH for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:19 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E863C04B317; Mon, 6 Mar 2017 05:26:19 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu1031786; Mon, 6 Mar 2017 00:26:17 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:42 +0800 Message-Id: <1488777954-4578-8-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 07/19] colo-compare: use g_timeout_source_new() to process the stale packets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , zhanghailiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang Instead of using qemu timer to process the stale packets, We re-use the colo compare thread to process these packets by creating a new timeout coroutine. Besides, since we process all the same vNIC's net connection/packets in one thread, it is safe to remove the timer_check_lock. Signed-off-by: zhanghailiang Signed-off-by: Jason Wang --- net/colo-compare.c | 62 +++++++++++++++++++-------------------------------= ---- 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 162fd6a..fdde788 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -83,9 +83,6 @@ typedef struct CompareState { GHashTable *connection_track_table; /* compare thread, a thread for each NIC */ QemuThread thread; - /* Timer used on the primary to find packets that are never matched */ - QEMUTimer *timer; - QemuMutex timer_check_lock; } CompareState; =20 typedef struct CompareClass { @@ -374,9 +371,7 @@ static void colo_compare_connection(void *opaque, void = *user_data) =20 while (!g_queue_is_empty(&conn->primary_list) && !g_queue_is_empty(&conn->secondary_list)) { - qemu_mutex_lock(&s->timer_check_lock); pkt =3D g_queue_pop_tail(&conn->primary_list); - qemu_mutex_unlock(&s->timer_check_lock); switch (conn->ip_proto) { case IPPROTO_TCP: result =3D g_queue_find_custom(&conn->secondary_list, @@ -411,9 +406,7 @@ static void colo_compare_connection(void *opaque, void = *user_data) * until next comparison. */ trace_colo_compare_main("packet different"); - qemu_mutex_lock(&s->timer_check_lock); g_queue_push_tail(&conn->primary_list, pkt); - qemu_mutex_unlock(&s->timer_check_lock); /* TODO: colo_notify_checkpoint();*/ break; } @@ -486,11 +479,26 @@ static void compare_sec_chr_in(void *opaque, const ui= nt8_t *buf, int size) } } =20 +/* + * Check old packet regularly so it can watch for any packets + * that the secondary hasn't produced equivalents of. + */ +static gboolean check_old_packet_regular(void *opaque) +{ + CompareState *s =3D opaque; + + /* if have old packet we will notify checkpoint */ + colo_old_packet_check(s); + + return TRUE; +} + static void *colo_compare_thread(void *opaque) { GMainContext *worker_context; GMainLoop *compare_loop; CompareState *s =3D opaque; + GSource *timeout_source; =20 worker_context =3D g_main_context_new(); =20 @@ -501,8 +509,15 @@ static void *colo_compare_thread(void *opaque) =20 compare_loop =3D g_main_loop_new(worker_context, FALSE); =20 + /* To kick any packets that the secondary doesn't match */ + timeout_source =3D g_timeout_source_new(REGULAR_PACKET_CHECK_MS); + g_source_set_callback(timeout_source, + (GSourceFunc)check_old_packet_regular, s, NULL); + g_source_attach(timeout_source, worker_context); + g_main_loop_run(compare_loop); =20 + g_source_unref(timeout_source); g_main_loop_unref(compare_loop); g_main_context_unref(worker_context); return NULL; @@ -604,26 +619,6 @@ static int find_and_check_chardev(Chardev **chr, } =20 /* - * Check old packet regularly so it can watch for any packets - * that the secondary hasn't produced equivalents of. - */ -static void check_old_packet_regular(void *opaque) -{ - CompareState *s =3D opaque; - - timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - REGULAR_PACKET_CHECK_MS); - /* if have old packet we will notify checkpoint */ - /* - * TODO: Make timer handler run in compare thread - * like qemu_chr_add_handlers_full. - */ - qemu_mutex_lock(&s->timer_check_lock); - colo_old_packet_check(s); - qemu_mutex_unlock(&s->timer_check_lock); -} - -/* * Called from the main thread on the primary * to setup colo-compare. */ @@ -665,7 +660,6 @@ static void colo_compare_complete(UserCreatable *uc, Er= ror **errp) net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); =20 g_queue_init(&s->conn_list); - qemu_mutex_init(&s->timer_check_lock); =20 s->connection_track_table =3D g_hash_table_new_full(connection_key_has= h, connection_key_equal, @@ -678,12 +672,6 @@ static void colo_compare_complete(UserCreatable *uc, E= rror **errp) QEMU_THREAD_JOINABLE); compare_id++; =20 - /* A regular timer to kick any packets that the secondary doesn't matc= h */ - s->timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, /* Only when guest runs = */ - check_old_packet_regular, s); - timer_mod(s->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - REGULAR_PACKET_CHECK_MS); - return; } =20 @@ -723,12 +711,6 @@ static void colo_compare_finalize(Object *obj) qemu_thread_join(&s->thread); } =20 - if (s->timer) { - timer_del(s->timer); - } - - qemu_mutex_destroy(&s->timer_check_lock); - g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev); --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778423832207.69953012552378; Sun, 5 Mar 2017 21:33:43 -0800 (PST) Received: from localhost ([::1]:41809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklHC-000554-Fs for importer@patchew.org; Mon, 06 Mar 2017 00:33:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklA6-0007vB-Ug for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklA6-00017l-0u for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklA5-00017J-O1 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:21 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E432981F07; Mon, 6 Mar 2017 05:26:21 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu2031786; Mon, 6 Mar 2017 00:26:19 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:43 +0800 Message-Id: <1488777954-4578-9-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 06 Mar 2017 05:26:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 08/19] colo-compare: kick compare thread to exit after some cleanup in finalization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , zhanghailiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang We should call g_main_loop_quit() to notify colo compare thread to exit, Or it will run in g_main_loop_run() forever. Besides, the finalizing process can't happen in context of colo thread, it is reasonable to remove the 'if (qemu_thread_is_self(&s->thread))' branch. Before compare thead exits, some cleanup works need to be done, All unhandled packets need to be released and connection_track_table needs to be freed, or there will be memory leak. Signed-off-by: zhanghailiang Reviewed-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index fdde788..37ce75c 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -83,6 +83,8 @@ typedef struct CompareState { GHashTable *connection_track_table; /* compare thread, a thread for each NIC */ QemuThread thread; + + GMainLoop *compare_loop; } CompareState; =20 typedef struct CompareClass { @@ -496,7 +498,6 @@ static gboolean check_old_packet_regular(void *opaque) static void *colo_compare_thread(void *opaque) { GMainContext *worker_context; - GMainLoop *compare_loop; CompareState *s =3D opaque; GSource *timeout_source; =20 @@ -507,7 +508,7 @@ static void *colo_compare_thread(void *opaque) qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read, compare_sec_chr_in, NULL, s, worker_context, = true); =20 - compare_loop =3D g_main_loop_new(worker_context, FALSE); + s->compare_loop =3D g_main_loop_new(worker_context, FALSE); =20 /* To kick any packets that the secondary doesn't match */ timeout_source =3D g_timeout_source_new(REGULAR_PACKET_CHECK_MS); @@ -515,10 +516,10 @@ static void *colo_compare_thread(void *opaque) (GSourceFunc)check_old_packet_regular, s, NULL); g_source_attach(timeout_source, worker_context); =20 - g_main_loop_run(compare_loop); + g_main_loop_run(s->compare_loop); =20 g_source_unref(timeout_source); - g_main_loop_unref(compare_loop); + g_main_loop_unref(s->compare_loop); g_main_context_unref(worker_context); return NULL; } @@ -675,6 +676,23 @@ static void colo_compare_complete(UserCreatable *uc, E= rror **errp) return; } =20 +static void colo_flush_packets(void *opaque, void *user_data) +{ + CompareState *s =3D user_data; + Connection *conn =3D opaque; + Packet *pkt =3D NULL; + + while (!g_queue_is_empty(&conn->primary_list)) { + pkt =3D g_queue_pop_head(&conn->primary_list); + compare_chr_send(&s->chr_out, pkt->data, pkt->size); + packet_destroy(pkt, NULL); + } + while (!g_queue_is_empty(&conn->secondary_list)) { + pkt =3D g_queue_pop_head(&conn->secondary_list); + packet_destroy(pkt, NULL); + } +} + static void colo_compare_class_init(ObjectClass *oc, void *data) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); @@ -703,14 +721,15 @@ static void colo_compare_finalize(Object *obj) qemu_chr_fe_deinit(&s->chr_sec_in); qemu_chr_fe_deinit(&s->chr_out); =20 - g_queue_free(&s->conn_list); + g_main_loop_quit(s->compare_loop); + qemu_thread_join(&s->thread); =20 - if (qemu_thread_is_self(&s->thread)) { - /* compare connection */ - g_queue_foreach(&s->conn_list, colo_compare_connection, s); - qemu_thread_join(&s->thread); - } + /* Release all unhandled packets after compare thead exited */ + g_queue_foreach(&s->conn_list, colo_flush_packets, s); + + g_queue_free(&s->conn_list); =20 + g_hash_table_destroy(s->connection_track_table); g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev); --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778052677855.9765761508665; Sun, 5 Mar 2017 21:27:32 -0800 (PST) Received: from localhost ([::1]:41773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklBD-00081i-0X for importer@patchew.org; Mon, 06 Mar 2017 00:27:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAA-0007xS-Dz for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklA9-00019F-6w for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38548) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklA8-00018x-UM for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:25 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1330C61B84; Mon, 6 Mar 2017 05:26:25 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu3031786; Mon, 6 Mar 2017 00:26:22 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:44 +0800 Message-Id: <1488777954-4578-10-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 06 Mar 2017 05:26:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 09/19] char: remove the right fd been watched in qemu_chr_fe_set_handlers() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Jason Wang , zhanghailiang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang We can call qemu_chr_fe_set_handlers() to add/remove fd been watched in 'context' which can be either default main context or other explicit context. But the original logic is not correct, we didn't remove the right fd because we call g_main_context_find_source_by_id(NULL, tag) which always try to find the Gsource from default context. Fix it by passing the right context to g_main_context_find_source_by_id(). Cc: Paolo Bonzini Cc: Marc-Andr=C3=A9 Lureau Signed-off-by: zhanghailiang Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Jason Wang --- chardev/char-fd.c | 6 +++--- chardev/char-io.c | 8 ++++---- chardev/char-io.h | 2 +- chardev/char-pty.c | 2 +- chardev/char-socket.c | 4 ++-- chardev/char-udp.c | 6 +++--- chardev/char.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/chardev/char-fd.c b/chardev/char-fd.c index fb51ab4..548dd4c 100644 --- a/chardev/char-fd.c +++ b/chardev/char-fd.c @@ -58,7 +58,7 @@ static gboolean fd_chr_read(QIOChannel *chan, GIOConditio= n cond, void *opaque) ret =3D qio_channel_read( chan, (gchar *)buf, len, NULL); if (ret =3D=3D 0) { - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); qemu_chr_be_event(chr, CHR_EVENT_CLOSED); return FALSE; } @@ -89,7 +89,7 @@ static void fd_chr_update_read_handler(Chardev *chr, { FDChardev *s =3D FD_CHARDEV(chr); =20 - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); if (s->ioc_in) { chr->fd_in_tag =3D io_add_watch_poll(chr, s->ioc_in, fd_chr_read_poll, @@ -103,7 +103,7 @@ static void char_fd_finalize(Object *obj) Chardev *chr =3D CHARDEV(obj); FDChardev *s =3D FD_CHARDEV(obj); =20 - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); if (s->ioc_in) { object_unref(OBJECT(s->ioc_in)); } diff --git a/chardev/char-io.c b/chardev/char-io.c index 7dfc3f2..b4bb094 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -127,14 +127,14 @@ guint io_add_watch_poll(Chardev *chr, return tag; } =20 -static void io_remove_watch_poll(guint tag) +static void io_remove_watch_poll(guint tag, GMainContext *context) { GSource *source; IOWatchPoll *iwp; =20 g_return_if_fail(tag > 0); =20 - source =3D g_main_context_find_source_by_id(NULL, tag); + source =3D g_main_context_find_source_by_id(context, tag); g_return_if_fail(source !=3D NULL); =20 iwp =3D io_watch_poll_from_source(source); @@ -146,10 +146,10 @@ static void io_remove_watch_poll(guint tag) g_source_destroy(&iwp->parent); } =20 -void remove_fd_in_watch(Chardev *chr) +void remove_fd_in_watch(Chardev *chr, GMainContext *context) { if (chr->fd_in_tag) { - io_remove_watch_poll(chr->fd_in_tag); + io_remove_watch_poll(chr->fd_in_tag, context); chr->fd_in_tag =3D 0; } } diff --git a/chardev/char-io.h b/chardev/char-io.h index d7ae5f1..842be56 100644 --- a/chardev/char-io.h +++ b/chardev/char-io.h @@ -36,7 +36,7 @@ guint io_add_watch_poll(Chardev *chr, gpointer user_data, GMainContext *context); =20 -void remove_fd_in_watch(Chardev *chr); +void remove_fd_in_watch(Chardev *chr, GMainContext *context); =20 int io_channel_send(QIOChannel *ioc, const void *buf, size_t len); =20 diff --git a/chardev/char-pty.c b/chardev/char-pty.c index ecf2c7a..a6337be 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -199,7 +199,7 @@ static void pty_chr_state(Chardev *chr, int connected) g_source_remove(s->open_tag); s->open_tag =3D 0; } - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); s->connected =3D 0; /* (re-)connect poll interval for idle guests: once per second. * We check more frequently in case the guests sends data to diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 865c527..d7e92e1 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -328,7 +328,7 @@ static void tcp_chr_free_connection(Chardev *chr) } =20 tcp_set_msgfds(chr, NULL, 0); - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); object_unref(OBJECT(s->sioc)); s->sioc =3D NULL; object_unref(OBJECT(s->ioc)); @@ -498,7 +498,7 @@ static void tcp_chr_update_read_handler(Chardev *chr, return; } =20 - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); if (s->ioc) { chr->fd_in_tag =3D io_add_watch_poll(chr, s->ioc, tcp_chr_read_poll, diff --git a/chardev/char-udp.c b/chardev/char-udp.c index 2c6c7dd..804bd22 100644 --- a/chardev/char-udp.c +++ b/chardev/char-udp.c @@ -81,7 +81,7 @@ static gboolean udp_chr_read(QIOChannel *chan, GIOConditi= on cond, void *opaque) ret =3D qio_channel_read( s->ioc, (char *)s->buf, sizeof(s->buf), NULL); if (ret <=3D 0) { - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); return FALSE; } s->bufcnt =3D ret; @@ -101,7 +101,7 @@ static void udp_chr_update_read_handler(Chardev *chr, { UdpChardev *s =3D UDP_CHARDEV(chr); =20 - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); if (s->ioc) { chr->fd_in_tag =3D io_add_watch_poll(chr, s->ioc, udp_chr_read_poll, @@ -115,7 +115,7 @@ static void char_udp_finalize(Object *obj) Chardev *chr =3D CHARDEV(obj); UdpChardev *s =3D UDP_CHARDEV(obj); =20 - remove_fd_in_watch(chr); + remove_fd_in_watch(chr, NULL); if (s->ioc) { object_unref(OBJECT(s->ioc)); } diff --git a/chardev/char.c b/chardev/char.c index 54cd5f4..3df1163 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -560,7 +560,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, cc =3D CHARDEV_GET_CLASS(s); if (!opaque && !fd_can_read && !fd_read && !fd_event) { fe_open =3D 0; - remove_fd_in_watch(s); + remove_fd_in_watch(s, context); } else { fe_open =3D 1; } --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148877839650056.121965305710205; Sun, 5 Mar 2017 21:33:16 -0800 (PST) Received: from localhost ([::1]:41805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklGk-0004jh-Ut for importer@patchew.org; Mon, 06 Mar 2017 00:33:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAD-000807-Ks for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAB-0001AT-ML for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAB-0001AI-Dj for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:27 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9180285363; Mon, 6 Mar 2017 05:26:27 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu4031786; Mon, 6 Mar 2017 00:26:25 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:45 +0800 Message-Id: <1488777954-4578-11-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 06 Mar 2017 05:26:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 10/19] colo-compare: Fix removing fds been watched incorrectly in finalization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , zhanghailiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang We will catch the bellow error report while try to delete compare object by qmp command: chardev/char-io.c:91: io_watch_poll_finalize: Assertion `iwp->src =3D=3D ((= void *)0)' failed. This is caused by failing to remove the right fd been watched while call qemu_chr_fe_set_handlers(); Fix it by pass the worker_context parameter to qemu_chr_fe_set_handlers(). Signed-off-by: zhanghailiang Reviewed-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 37ce75c..a6fc2ff 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -84,6 +84,7 @@ typedef struct CompareState { /* compare thread, a thread for each NIC */ QemuThread thread; =20 + GMainContext *worker_context; GMainLoop *compare_loop; } CompareState; =20 @@ -497,30 +498,29 @@ static gboolean check_old_packet_regular(void *opaque) =20 static void *colo_compare_thread(void *opaque) { - GMainContext *worker_context; CompareState *s =3D opaque; GSource *timeout_source; =20 - worker_context =3D g_main_context_new(); + s->worker_context =3D g_main_context_new(); =20 qemu_chr_fe_set_handlers(&s->chr_pri_in, compare_chr_can_read, - compare_pri_chr_in, NULL, s, worker_context, = true); + compare_pri_chr_in, NULL, s, s->worker_context, = true); qemu_chr_fe_set_handlers(&s->chr_sec_in, compare_chr_can_read, - compare_sec_chr_in, NULL, s, worker_context, = true); + compare_sec_chr_in, NULL, s, s->worker_context, = true); =20 - s->compare_loop =3D g_main_loop_new(worker_context, FALSE); + s->compare_loop =3D g_main_loop_new(s->worker_context, FALSE); =20 /* To kick any packets that the secondary doesn't match */ timeout_source =3D g_timeout_source_new(REGULAR_PACKET_CHECK_MS); g_source_set_callback(timeout_source, (GSourceFunc)check_old_packet_regular, s, NULL); - g_source_attach(timeout_source, worker_context); + g_source_attach(timeout_source, s->worker_context); =20 g_main_loop_run(s->compare_loop); =20 g_source_unref(timeout_source); g_main_loop_unref(s->compare_loop); - g_main_context_unref(worker_context); + g_main_context_unref(s->worker_context); return NULL; } =20 @@ -717,8 +717,10 @@ static void colo_compare_finalize(Object *obj) { CompareState *s =3D COLO_COMPARE(obj); =20 - qemu_chr_fe_deinit(&s->chr_pri_in); - qemu_chr_fe_deinit(&s->chr_sec_in); + qemu_chr_fe_set_handlers(&s->chr_pri_in, NULL, NULL, NULL, NULL, + s->worker_context, true); + qemu_chr_fe_set_handlers(&s->chr_sec_in, NULL, NULL, NULL, NULL, + s->worker_context, true); qemu_chr_fe_deinit(&s->chr_out); =20 g_main_loop_quit(s->compare_loop); --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778516064247.57325573281582; Sun, 5 Mar 2017 21:35:16 -0800 (PST) Received: from localhost ([::1]:41816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklIg-0006Qh-TY for importer@patchew.org; Mon, 06 Mar 2017 00:35:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAF-00081Q-5y for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAE-0001Bd-AO for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37994) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAE-0001BG-4N for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:30 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 551A53B712; Mon, 6 Mar 2017 05:26:30 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu5031786; Mon, 6 Mar 2017 00:26:28 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:46 +0800 Message-Id: <1488777954-4578-12-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 06 Mar 2017 05:26:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 11/19] net/colo-compare: Fix memory free error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen We use g_queue_init() to init s->conn_list, so we should use g_queue_clear() to instead of g_queue_free(). Signed-off-by: Zhang Chen Reviewed-by: zhanghailiang Signed-off-by: Jason Wang --- net/colo-compare.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index a6fc2ff..300f017 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -729,7 +729,7 @@ static void colo_compare_finalize(Object *obj) /* Release all unhandled packets after compare thead exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); =20 - g_queue_free(&s->conn_list); + g_queue_clear(&s->conn_list); =20 g_hash_table_destroy(s->connection_track_table); g_free(s->pri_indev); --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778495881907.3162479447469; Sun, 5 Mar 2017 21:34:55 -0800 (PST) Received: from localhost ([::1]:41813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklIM-00068u-HH for importer@patchew.org; Mon, 06 Mar 2017 00:34:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAH-00083l-NN for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAG-0001DP-W8 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42884) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAG-0001CT-QA for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:32 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1BE163144; Mon, 6 Mar 2017 05:26:32 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu6031786; Mon, 6 Mar 2017 00:26:30 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:47 +0800 Message-Id: <1488777954-4578-13-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 06 Mar 2017 05:26:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 12/19] vmxnet3: Convert ring values to uint32_t's X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" The index's in the Vmxnet3Ring were migrated as 32bit ints yet are declared as size_t's. They appear to be derived from 32bit values loaded from guest memory, so actually store them as that. Signed-off-by: Dr. David Alan Gilbert Acked-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/vmxnet3.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index e13a798..224c109 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -141,17 +141,17 @@ typedef struct VMXNET3Class { /* Cyclic ring abstraction */ typedef struct { hwaddr pa; - size_t size; - size_t cell_size; - size_t next; + uint32_t size; + uint32_t cell_size; + uint32_t next; uint8_t gen; } Vmxnet3Ring; =20 static inline void vmxnet3_ring_init(PCIDevice *d, Vmxnet3Ring *ring, hwaddr pa, - size_t size, - size_t cell_size, + uint32_t size, + uint32_t cell_size, bool zero_region) { ring->pa =3D pa; @@ -166,7 +166,7 @@ static inline void vmxnet3_ring_init(PCIDevice *d, } =20 #define VMXNET3_RING_DUMP(macro, ring_name, ridx, r) = \ - macro("%s#%d: base %" PRIx64 " size %zu cell_size %zu gen %d next %zu"= , \ + macro("%s#%d: base %" PRIx64 " size %u cell_size %u gen %d next %u", \ (ring_name), (ridx), = \ (r)->pa, (r)->size, (r)->cell_size, (r)->gen, (r)->next) =20 --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778187588463.31077734959865; Sun, 5 Mar 2017 21:29:47 -0800 (PST) Received: from localhost ([::1]:41783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklDO-0001Zq-6j for importer@patchew.org; Mon, 06 Mar 2017 00:29:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAM-00088G-On for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAJ-0001FZ-L9 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAJ-0001FK-CD for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:35 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F6063DD47; Mon, 6 Mar 2017 05:26:35 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu7031786; Mon, 6 Mar 2017 00:26:33 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:48 +0800 Message-Id: <1488777954-4578-14-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 06 Mar 2017 05:26:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 13/19] vmxnet3: VMStatify rx/tx q_descr and int_state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Fairly simple mechanical conversion of all fields. TODO!!!! The problem is vmxnet3-ring size/cell_size/next are declared as size_t but written as 32bit. Signed-off-by: Dr. David Alan Gilbert Acked-by: Dmitry Fleytman Signed-off-by: Jason Wang --- hw/net/vmxnet3.c | 272 ++++++++++++++++++---------------------------------= ---- 1 file changed, 90 insertions(+), 182 deletions(-) diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 224c109..8b1fab2 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -2403,155 +2403,87 @@ static const VMStateDescription vmxstate_vmxnet3_m= cast_list =3D { } }; =20 -static void vmxnet3_get_ring_from_file(QEMUFile *f, Vmxnet3Ring *r) -{ - r->pa =3D qemu_get_be64(f); - r->size =3D qemu_get_be32(f); - r->cell_size =3D qemu_get_be32(f); - r->next =3D qemu_get_be32(f); - r->gen =3D qemu_get_byte(f); -} - -static void vmxnet3_put_ring_to_file(QEMUFile *f, Vmxnet3Ring *r) -{ - qemu_put_be64(f, r->pa); - qemu_put_be32(f, r->size); - qemu_put_be32(f, r->cell_size); - qemu_put_be32(f, r->next); - qemu_put_byte(f, r->gen); -} - -static void vmxnet3_get_tx_stats_from_file(QEMUFile *f, - struct UPT1_TxStats *tx_stat) -{ - tx_stat->TSOPktsTxOK =3D qemu_get_be64(f); - tx_stat->TSOBytesTxOK =3D qemu_get_be64(f); - tx_stat->ucastPktsTxOK =3D qemu_get_be64(f); - tx_stat->ucastBytesTxOK =3D qemu_get_be64(f); - tx_stat->mcastPktsTxOK =3D qemu_get_be64(f); - tx_stat->mcastBytesTxOK =3D qemu_get_be64(f); - tx_stat->bcastPktsTxOK =3D qemu_get_be64(f); - tx_stat->bcastBytesTxOK =3D qemu_get_be64(f); - tx_stat->pktsTxError =3D qemu_get_be64(f); - tx_stat->pktsTxDiscard =3D qemu_get_be64(f); -} - -static void vmxnet3_put_tx_stats_to_file(QEMUFile *f, - struct UPT1_TxStats *tx_stat) -{ - qemu_put_be64(f, tx_stat->TSOPktsTxOK); - qemu_put_be64(f, tx_stat->TSOBytesTxOK); - qemu_put_be64(f, tx_stat->ucastPktsTxOK); - qemu_put_be64(f, tx_stat->ucastBytesTxOK); - qemu_put_be64(f, tx_stat->mcastPktsTxOK); - qemu_put_be64(f, tx_stat->mcastBytesTxOK); - qemu_put_be64(f, tx_stat->bcastPktsTxOK); - qemu_put_be64(f, tx_stat->bcastBytesTxOK); - qemu_put_be64(f, tx_stat->pktsTxError); - qemu_put_be64(f, tx_stat->pktsTxDiscard); -} - -static int vmxnet3_get_txq_descr(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - Vmxnet3TxqDescr *r =3D pv; - - vmxnet3_get_ring_from_file(f, &r->tx_ring); - vmxnet3_get_ring_from_file(f, &r->comp_ring); - r->intr_idx =3D qemu_get_byte(f); - r->tx_stats_pa =3D qemu_get_be64(f); - - vmxnet3_get_tx_stats_from_file(f, &r->txq_stats); - - return 0; -} - -static int vmxnet3_put_txq_descr(QEMUFile *f, void *pv, size_t size, - VMStateField *field, QJSON *vmdesc) -{ - Vmxnet3TxqDescr *r =3D pv; - - vmxnet3_put_ring_to_file(f, &r->tx_ring); - vmxnet3_put_ring_to_file(f, &r->comp_ring); - qemu_put_byte(f, r->intr_idx); - qemu_put_be64(f, r->tx_stats_pa); - vmxnet3_put_tx_stats_to_file(f, &r->txq_stats); - - return 0; -} - -static const VMStateInfo txq_descr_info =3D { - .name =3D "txq_descr", - .get =3D vmxnet3_get_txq_descr, - .put =3D vmxnet3_put_txq_descr +static const VMStateDescription vmstate_vmxnet3_ring =3D { + .name =3D "vmxnet3-ring", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT64(pa, Vmxnet3Ring), + VMSTATE_UINT32(size, Vmxnet3Ring), + VMSTATE_UINT32(cell_size, Vmxnet3Ring), + VMSTATE_UINT32(next, Vmxnet3Ring), + VMSTATE_UINT8(gen, Vmxnet3Ring), + VMSTATE_END_OF_LIST() + } }; =20 -static void vmxnet3_get_rx_stats_from_file(QEMUFile *f, - struct UPT1_RxStats *rx_stat) -{ - rx_stat->LROPktsRxOK =3D qemu_get_be64(f); - rx_stat->LROBytesRxOK =3D qemu_get_be64(f); - rx_stat->ucastPktsRxOK =3D qemu_get_be64(f); - rx_stat->ucastBytesRxOK =3D qemu_get_be64(f); - rx_stat->mcastPktsRxOK =3D qemu_get_be64(f); - rx_stat->mcastBytesRxOK =3D qemu_get_be64(f); - rx_stat->bcastPktsRxOK =3D qemu_get_be64(f); - rx_stat->bcastBytesRxOK =3D qemu_get_be64(f); - rx_stat->pktsRxOutOfBuf =3D qemu_get_be64(f); - rx_stat->pktsRxError =3D qemu_get_be64(f); -} - -static void vmxnet3_put_rx_stats_to_file(QEMUFile *f, - struct UPT1_RxStats *rx_stat) -{ - qemu_put_be64(f, rx_stat->LROPktsRxOK); - qemu_put_be64(f, rx_stat->LROBytesRxOK); - qemu_put_be64(f, rx_stat->ucastPktsRxOK); - qemu_put_be64(f, rx_stat->ucastBytesRxOK); - qemu_put_be64(f, rx_stat->mcastPktsRxOK); - qemu_put_be64(f, rx_stat->mcastBytesRxOK); - qemu_put_be64(f, rx_stat->bcastPktsRxOK); - qemu_put_be64(f, rx_stat->bcastBytesRxOK); - qemu_put_be64(f, rx_stat->pktsRxOutOfBuf); - qemu_put_be64(f, rx_stat->pktsRxError); -} - -static int vmxnet3_get_rxq_descr(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - Vmxnet3RxqDescr *r =3D pv; - int i; - - for (i =3D 0; i < VMXNET3_RX_RINGS_PER_QUEUE; i++) { - vmxnet3_get_ring_from_file(f, &r->rx_ring[i]); +static const VMStateDescription vmstate_vmxnet3_tx_stats =3D { + .name =3D "vmxnet3-tx-stats", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT64(TSOPktsTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(TSOBytesTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(ucastPktsTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(ucastBytesTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(mcastPktsTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(mcastBytesTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(bcastPktsTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(bcastBytesTxOK, struct UPT1_TxStats), + VMSTATE_UINT64(pktsTxError, struct UPT1_TxStats), + VMSTATE_UINT64(pktsTxDiscard, struct UPT1_TxStats), + VMSTATE_END_OF_LIST() } +}; =20 - vmxnet3_get_ring_from_file(f, &r->comp_ring); - r->intr_idx =3D qemu_get_byte(f); - r->rx_stats_pa =3D qemu_get_be64(f); - - vmxnet3_get_rx_stats_from_file(f, &r->rxq_stats); - - return 0; -} - -static int vmxnet3_put_rxq_descr(QEMUFile *f, void *pv, size_t size, - VMStateField *field, QJSON *vmdesc) -{ - Vmxnet3RxqDescr *r =3D pv; - int i; - - for (i =3D 0; i < VMXNET3_RX_RINGS_PER_QUEUE; i++) { - vmxnet3_put_ring_to_file(f, &r->rx_ring[i]); +static const VMStateDescription vmstate_vmxnet3_txq_descr =3D { + .name =3D "vmxnet3-txq-descr", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_STRUCT(tx_ring, Vmxnet3TxqDescr, 0, vmstate_vmxnet3_ring, + Vmxnet3Ring), + VMSTATE_STRUCT(comp_ring, Vmxnet3TxqDescr, 0, vmstate_vmxnet3_ring, + Vmxnet3Ring), + VMSTATE_UINT8(intr_idx, Vmxnet3TxqDescr), + VMSTATE_UINT64(tx_stats_pa, Vmxnet3TxqDescr), + VMSTATE_STRUCT(txq_stats, Vmxnet3TxqDescr, 0, vmstate_vmxnet3_tx_s= tats, + struct UPT1_TxStats), + VMSTATE_END_OF_LIST() } +}; =20 - vmxnet3_put_ring_to_file(f, &r->comp_ring); - qemu_put_byte(f, r->intr_idx); - qemu_put_be64(f, r->rx_stats_pa); - vmxnet3_put_rx_stats_to_file(f, &r->rxq_stats); +static const VMStateDescription vmstate_vmxnet3_rx_stats =3D { + .name =3D "vmxnet3-rx-stats", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT64(LROPktsRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(LROBytesRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(ucastPktsRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(ucastBytesRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(mcastPktsRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(mcastBytesRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(bcastPktsRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(bcastBytesRxOK, struct UPT1_RxStats), + VMSTATE_UINT64(pktsRxOutOfBuf, struct UPT1_RxStats), + VMSTATE_UINT64(pktsRxError, struct UPT1_RxStats), + VMSTATE_END_OF_LIST() + } +}; =20 - return 0; -} +static const VMStateDescription vmstate_vmxnet3_rxq_descr =3D { + .name =3D "vmxnet3-rxq-descr", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_STRUCT_ARRAY(rx_ring, Vmxnet3RxqDescr, + VMXNET3_RX_RINGS_PER_QUEUE, 0, + vmstate_vmxnet3_ring, Vmxnet3Ring), + VMSTATE_STRUCT(comp_ring, Vmxnet3RxqDescr, 0, vmstate_vmxnet3_ring, + Vmxnet3Ring), + VMSTATE_UINT8(intr_idx, Vmxnet3RxqDescr), + VMSTATE_UINT64(rx_stats_pa, Vmxnet3RxqDescr), + VMSTATE_STRUCT(rxq_stats, Vmxnet3RxqDescr, 0, vmstate_vmxnet3_rx_s= tats, + struct UPT1_RxStats), + VMSTATE_END_OF_LIST() + } +}; =20 static int vmxnet3_post_load(void *opaque, int version_id) { @@ -2577,40 +2509,15 @@ static int vmxnet3_post_load(void *opaque, int vers= ion_id) return 0; } =20 -static const VMStateInfo rxq_descr_info =3D { - .name =3D "rxq_descr", - .get =3D vmxnet3_get_rxq_descr, - .put =3D vmxnet3_put_rxq_descr -}; - -static int vmxnet3_get_int_state(QEMUFile *f, void *pv, size_t size, - VMStateField *field) -{ - Vmxnet3IntState *r =3D pv; - - r->is_masked =3D qemu_get_byte(f); - r->is_pending =3D qemu_get_byte(f); - r->is_asserted =3D qemu_get_byte(f); - - return 0; -} - -static int vmxnet3_put_int_state(QEMUFile *f, void *pv, size_t size, - VMStateField *field, QJSON *vmdesc) -{ - Vmxnet3IntState *r =3D pv; - - qemu_put_byte(f, r->is_masked); - qemu_put_byte(f, r->is_pending); - qemu_put_byte(f, r->is_asserted); - - return 0; -} - -static const VMStateInfo int_state_info =3D { - .name =3D "int_state", - .get =3D vmxnet3_get_int_state, - .put =3D vmxnet3_put_int_state +static const VMStateDescription vmstate_vmxnet3_int_state =3D { + .name =3D "vmxnet3-int-state", + .version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_BOOL(is_masked, Vmxnet3IntState), + VMSTATE_BOOL(is_pending, Vmxnet3IntState), + VMSTATE_BOOL(is_asserted, Vmxnet3IntState), + VMSTATE_END_OF_LIST() + } }; =20 static bool vmxnet3_vmstate_need_pcie_device(void *opaque) @@ -2667,14 +2574,15 @@ static const VMStateDescription vmstate_vmxnet3 =3D= { VMSTATE_UINT64(drv_shmem, VMXNET3State), VMSTATE_UINT64(temp_shared_guest_driver_memory, VMXNET3State), =20 - VMSTATE_ARRAY(txq_descr, VMXNET3State, - VMXNET3_DEVICE_MAX_TX_QUEUES, 0, txq_descr_info, + VMSTATE_STRUCT_ARRAY(txq_descr, VMXNET3State, + VMXNET3_DEVICE_MAX_TX_QUEUES, 0, vmstate_vmxnet3_txq_descr, Vmxnet3TxqDescr), - VMSTATE_ARRAY(rxq_descr, VMXNET3State, - VMXNET3_DEVICE_MAX_RX_QUEUES, 0, rxq_descr_info, + VMSTATE_STRUCT_ARRAY(rxq_descr, VMXNET3State, + VMXNET3_DEVICE_MAX_RX_QUEUES, 0, vmstate_vmxnet3_rxq_descr, Vmxnet3RxqDescr), - VMSTATE_ARRAY(interrupt_states, VMXNET3State, VMXNET3_MAX_INTR= S, - 0, int_state_info, Vmxnet3IntState), + VMSTATE_STRUCT_ARRAY(interrupt_states, VMXNET3State, + VMXNET3_MAX_INTRS, 0, vmstate_vmxnet3_int_state, + Vmxnet3IntState), =20 VMSTATE_END_OF_LIST() }, --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778599203358.29833443027746; Sun, 5 Mar 2017 21:36:39 -0800 (PST) Received: from localhost ([::1]:41829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklK2-0007Rt-10 for importer@patchew.org; Mon, 06 Mar 2017 00:36:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAM-00088K-SL for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAM-0001Gz-6M for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47566) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAM-0001GP-0Q for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:38 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C3E180461; Mon, 6 Mar 2017 05:26:38 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu8031786; Mon, 6 Mar 2017 00:26:36 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:49 +0800 Message-Id: <1488777954-4578-15-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 06 Mar 2017 05:26:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 14/19] net/colo: fix memory double free error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , zhanghailiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang The 'primary_list' and 'secondary_list' members of struct Connection is not allocated through dynamically g_queue_new(), but we free it by using g_queue_free(), which will lead to a double-free bug. Reviewed-by: Zhang Chen Signed-off-by: zhanghailiang Signed-off-by: Jason Wang --- net/colo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/colo.c b/net/colo.c index 6a6eacd..8cc166b 100644 --- a/net/colo.c +++ b/net/colo.c @@ -147,9 +147,9 @@ void connection_destroy(void *opaque) Connection *conn =3D opaque; =20 g_queue_foreach(&conn->primary_list, packet_destroy, NULL); - g_queue_free(&conn->primary_list); + g_queue_clear(&conn->primary_list); g_queue_foreach(&conn->secondary_list, packet_destroy, NULL); - g_queue_free(&conn->secondary_list); + g_queue_clear(&conn->secondary_list); g_slice_free(Connection, conn); } =20 --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778403935310.9315108155964; Sun, 5 Mar 2017 21:33:23 -0800 (PST) Received: from localhost ([::1]:41806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklGs-0004pa-LW for importer@patchew.org; Mon, 06 Mar 2017 00:33:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAR-0008D1-MD for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAQ-0001JF-Ta for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAQ-0001IN-Nk for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:42 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A255081F01; Mon, 6 Mar 2017 05:26:41 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265Pvu9031786; Mon, 6 Mar 2017 00:26:38 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:50 +0800 Message-Id: <1488777954-4578-16-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 06 Mar 2017 05:26:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 15/19] filter-rewriter: skip net_checksum_calculate() while offset = 0 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , zhanghailiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: zhanghailiang While the offset of packets's sequence for primary side and secondary side is zero, it is unnecessary to call net_checksum_calculate() to recalculate the checksume value of packets. Signed-off-by: zhanghailiang Signed-off-by: Jason Wang --- net/filter-rewriter.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index c4ab91c..afa06e8 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -93,10 +93,12 @@ static int handle_primary_tcp_pkt(NetFilterState *nf, conn->offset -=3D (ntohl(tcp_pkt->th_ack) - 1); conn->syn_flag =3D 0; } - /* handle packets to the secondary from the primary */ - tcp_pkt->th_ack =3D htonl(ntohl(tcp_pkt->th_ack) + conn->offset); + if (conn->offset) { + /* handle packets to the secondary from the primary */ + tcp_pkt->th_ack =3D htonl(ntohl(tcp_pkt->th_ack) + conn->offse= t); =20 - net_checksum_calculate((uint8_t *)pkt->data, pkt->size); + net_checksum_calculate((uint8_t *)pkt->data, pkt->size); + } } =20 return 0; @@ -129,10 +131,13 @@ static int handle_secondary_tcp_pkt(NetFilterState *n= f, } =20 if ((tcp_pkt->th_flags & (TH_ACK | TH_SYN)) =3D=3D TH_ACK) { - /* handle packets to the primary from the secondary*/ - tcp_pkt->th_seq =3D htonl(ntohl(tcp_pkt->th_seq) - conn->offset); + /* Only need to adjust seq while offset is Non-zero */ + if (conn->offset) { + /* handle packets to the primary from the secondary*/ + tcp_pkt->th_seq =3D htonl(ntohl(tcp_pkt->th_seq) - conn->offse= t); =20 - net_checksum_calculate((uint8_t *)pkt->data, pkt->size); + net_checksum_calculate((uint8_t *)pkt->data, pkt->size); + } } =20 return 0; --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778752803737.1693103881024; Sun, 5 Mar 2017 21:39:12 -0800 (PST) Received: from localhost ([::1]:41843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklMU-0000m3-SV for importer@patchew.org; Mon, 06 Mar 2017 00:39:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAV-0008Gq-GB for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAS-0001KZ-D5 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42938) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAS-0001Jz-4F for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:44 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BC0F6197C; Mon, 6 Mar 2017 05:26:44 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265PvuA031786; Mon, 6 Mar 2017 00:26:42 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:51 +0800 Message-Id: <1488777954-4578-17-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 06 Mar 2017 05:26:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 16/19] COLO-compare: Rename compare function and remove duplicate codes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Rename colo_packet_compare() to colo_packet_compare_common() that make tcp_compare udp_compare icmp_compare reuse this function. Remove minimum packet size check in icmp_compare, because we have check this in parse_packet_early(). Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 300f017..602a758 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -180,7 +180,7 @@ static int packet_enqueue(CompareState *s, int mode) * return: 0 means packet same * > 0 || < 0 means packet different */ -static int colo_packet_compare(Packet *ppkt, Packet *spkt) +static int colo_packet_compare_common(Packet *ppkt, Packet *spkt) { trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src), inet_ntoa(ppkt->ip->ip_dst), spkt->size, @@ -190,6 +190,7 @@ static int colo_packet_compare(Packet *ppkt, Packet *sp= kt) if (ppkt->size =3D=3D spkt->size) { return memcmp(ppkt->data, spkt->data, spkt->size); } else { + trace_colo_compare_main("Net packet size are not the same"); return -1; } } @@ -205,6 +206,7 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet= *ppkt) int res; =20 trace_colo_compare_main("compare tcp"); + if (ppkt->size !=3D spkt->size) { if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { trace_colo_compare_main("pkt size not same"); @@ -263,7 +265,8 @@ static int colo_packet_compare_udp(Packet *spkt, Packet= *ppkt) int ret; =20 trace_colo_compare_main("compare udp"); - ret =3D colo_packet_compare(ppkt, spkt); + + ret =3D colo_packet_compare_common(ppkt, spkt); =20 if (ret) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); @@ -281,16 +284,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packe= t *ppkt) */ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt) { - int network_length; - trace_colo_compare_main("compare icmp"); - network_length =3D ppkt->ip->ip_hl * 4; - if (ppkt->size !=3D spkt->size || - ppkt->size < network_length + ETH_HLEN) { - return -1; - } =20 - if (colo_packet_compare(ppkt, spkt)) { + if (colo_packet_compare_common(ppkt, spkt)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", @@ -316,7 +312,7 @@ static int colo_packet_compare_other(Packet *spkt, Pack= et *ppkt) inet_ntoa(ppkt->ip->ip_dst), spkt->size, inet_ntoa(spkt->ip->ip_src), inet_ntoa(spkt->ip->ip_dst)); - return colo_packet_compare(ppkt, spkt); + return colo_packet_compare_common(ppkt, spkt); } =20 static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time) --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778825039866.0073431913119; Sun, 5 Mar 2017 21:40:25 -0800 (PST) Received: from localhost ([::1]:41847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklNf-0001i1-Li for importer@patchew.org; Mon, 06 Mar 2017 00:40:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAV-0008HG-V5 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAU-0001Mm-Or for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41956) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAU-0001MG-GA for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:46 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7D30C04B31F; Mon, 6 Mar 2017 05:26:46 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265PvuB031786; Mon, 6 Mar 2017 00:26:44 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:52 +0800 Message-Id: <1488777954-4578-18-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 17/19] COLO-compare: Optimize compare_common and compare_tcp X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Add offset args for colo_packet_compare_common, optimize colo_packet_compare_icmp() and colo_packet_compare_udp() just compare the IP payload. Before compare all tcp packet, we compare tcp checksum firstly, this function can get better performance. Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 602a758..9f5968d 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -180,7 +180,7 @@ static int packet_enqueue(CompareState *s, int mode) * return: 0 means packet same * > 0 || < 0 means packet different */ -static int colo_packet_compare_common(Packet *ppkt, Packet *spkt) +static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offs= et) { trace_colo_compare_ip_info(ppkt->size, inet_ntoa(ppkt->ip->ip_src), inet_ntoa(ppkt->ip->ip_dst), spkt->size, @@ -188,7 +188,8 @@ static int colo_packet_compare_common(Packet *ppkt, Pac= ket *spkt) inet_ntoa(spkt->ip->ip_dst)); =20 if (ppkt->size =3D=3D spkt->size) { - return memcmp(ppkt->data, spkt->data, spkt->size); + return memcmp(ppkt->data + offset, spkt->data + offset, + spkt->size - offset); } else { trace_colo_compare_main("Net packet size are not the same"); return -1; @@ -207,13 +208,6 @@ static int colo_packet_compare_tcp(Packet *spkt, Packe= t *ppkt) =20 trace_colo_compare_main("compare tcp"); =20 - if (ppkt->size !=3D spkt->size) { - if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { - trace_colo_compare_main("pkt size not same"); - } - return -1; - } - ptcp =3D (struct tcphdr *)ppkt->transport_header; stcp =3D (struct tcphdr *)spkt->transport_header; =20 @@ -231,8 +225,11 @@ static int colo_packet_compare_tcp(Packet *spkt, Packe= t *ppkt) spkt->ip->ip_sum =3D ppkt->ip->ip_sum; } =20 - res =3D memcmp(ppkt->data + ETH_HLEN, spkt->data + ETH_HLEN, - (spkt->size - ETH_HLEN)); + if (ptcp->th_sum =3D=3D stcp->th_sum) { + res =3D colo_packet_compare_common(ppkt, spkt, ETH_HLEN); + } else { + res =3D -1; + } =20 if (res !=3D 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)= ) { trace_colo_compare_pkt_info_src(inet_ntoa(ppkt->ip->ip_src), @@ -263,10 +260,22 @@ static int colo_packet_compare_tcp(Packet *spkt, Pack= et *ppkt) static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt) { int ret; + int network_header_length =3D ppkt->ip->ip_hl * 4; =20 trace_colo_compare_main("compare udp"); =20 - ret =3D colo_packet_compare_common(ppkt, spkt); + /* + * Because of ppkt and spkt are both in the same connection, + * The ppkt's src ip, dst ip, src port, dst port, ip_proto all are + * same with spkt. In addition, IP header's Identification is a random + * field, we can handle it in IP fragmentation function later. + * COLO just concern the response net packet payload from primary guest + * and secondary guest are same or not, So we ignored all IP header in= clude + * other field like TOS,TTL,IP Checksum. we only need to compare + * the ip payload here. + */ + ret =3D colo_packet_compare_common(ppkt, spkt, + network_header_length + ETH_HLEN); =20 if (ret) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); @@ -284,9 +293,22 @@ static int colo_packet_compare_udp(Packet *spkt, Packe= t *ppkt) */ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt) { + int network_header_length =3D ppkt->ip->ip_hl * 4; + trace_colo_compare_main("compare icmp"); =20 - if (colo_packet_compare_common(ppkt, spkt)) { + /* + * Because of ppkt and spkt are both in the same connection, + * The ppkt's src ip, dst ip, src port, dst port, ip_proto all are + * same with spkt. In addition, IP header's Identification is a random + * field, we can handle it in IP fragmentation function later. + * COLO just concern the response net packet payload from primary guest + * and secondary guest are same or not, So we ignored all IP header in= clude + * other field like TOS,TTL,IP Checksum. we only need to compare + * the ip payload here. + */ + if (colo_packet_compare_common(ppkt, spkt, + network_header_length + ETH_HLEN)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", @@ -312,7 +334,7 @@ static int colo_packet_compare_other(Packet *spkt, Pack= et *ppkt) inet_ntoa(ppkt->ip->ip_dst), spkt->size, inet_ntoa(spkt->ip->ip_src), inet_ntoa(spkt->ip->ip_dst)); - return colo_packet_compare_common(ppkt, spkt); + return colo_packet_compare_common(ppkt, spkt, 0); } =20 static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time) --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 14887788802121011.9734227732391; Sun, 5 Mar 2017 21:41:20 -0800 (PST) Received: from localhost ([::1]:41854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklOY-0002Gl-VO for importer@patchew.org; Mon, 06 Mar 2017 00:41:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAY-0008JP-3E for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAX-0001QC-1p for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAW-0001On-S2 for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:48 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D64CC05678C; Mon, 6 Mar 2017 05:26:49 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265PvuC031786; Mon, 6 Mar 2017 00:26:47 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:53 +0800 Message-Id: <1488777954-4578-19-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 06 Mar 2017 05:26:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 18/19] COLO-compare: Fix icmp and udp compare different packet always dump bug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/colo-compare.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 9f5968d..282727b 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -279,9 +279,13 @@ static int colo_packet_compare_udp(Packet *spkt, Packe= t *ppkt) =20 if (ret) { trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size); - qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", ppkt->siz= e); trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size= ); - qemu_hexdump((char *)spkt->data, stderr, "colo-compare", spkt->siz= e); + if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { + qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt= ", + ppkt->size); + qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt= ", + spkt->size); + } } =20 return ret; @@ -311,12 +315,14 @@ static int colo_packet_compare_icmp(Packet *spkt, Pac= ket *ppkt) network_header_length + ETH_HLEN)) { trace_colo_compare_icmp_miscompare("primary pkt size", ppkt->size); - qemu_hexdump((char *)ppkt->data, stderr, "colo-compare", - ppkt->size); trace_colo_compare_icmp_miscompare("Secondary pkt size", spkt->size); - qemu_hexdump((char *)spkt->data, stderr, "colo-compare", - spkt->size); + if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) { + qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt= ", + ppkt->size); + qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt= ", + spkt->size); + } return -1; } else { return 0; --=20 2.7.4 From nobody Sun Apr 28 18:43:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488778579105843.4053915073172; Sun, 5 Mar 2017 21:36:19 -0800 (PST) Received: from localhost ([::1]:41827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklJh-0007DQ-U5 for importer@patchew.org; Mon, 06 Mar 2017 00:36:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cklAa-0008LV-7A for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cklAZ-0001TW-EP for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cklAZ-0001SF-9C for qemu-devel@nongnu.org; Mon, 06 Mar 2017 00:26:51 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70816C04B924; Mon, 6 Mar 2017 05:26:51 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-5-134.pek2.redhat.com [10.72.5.134]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v265PvuD031786; Mon, 6 Mar 2017 00:26:49 -0500 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Mon, 6 Mar 2017 13:25:54 +0800 Message-Id: <1488777954-4578-20-git-send-email-jasowang@redhat.com> In-Reply-To: <1488777954-4578-1-git-send-email-jasowang@redhat.com> References: <1488777954-4578-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 06 Mar 2017 05:26:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL RESEND 19/19] net/filter-mirror: Follow CODING_STYLE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhang Chen Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- net/filter-mirror.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index aa0aa98..72fa7c2 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -49,7 +49,7 @@ static int filter_mirror_send(CharBackend *chr_out, { int ret =3D 0; ssize_t size =3D 0; - uint32_t len =3D 0; + uint32_t len =3D 0; char *buf; =20 size =3D iov_size(iov, iovcnt); @@ -77,8 +77,9 @@ err: return ret < 0 ? ret : -EIO; } =20 -static void -redirector_to_filter(NetFilterState *nf, const uint8_t *buf, int len) +static void redirector_to_filter(NetFilterState *nf, + const uint8_t *buf, + int len) { struct iovec iov =3D { .iov_base =3D (void *)buf, --=20 2.7.4