From patchwork Thu Oct 28 09:05:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 12589617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF5F4C433EF for ; Thu, 28 Oct 2021 09:23:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 47D6160E78 for ; Thu, 28 Oct 2021 09:23:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 47D6160E78 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg1cv-0003Mw-Cj for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 05:23:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg1bf-0001Is-Ks for qemu-devel@nongnu.org; Thu, 28 Oct 2021 05:21:55 -0400 Received: from mga11.intel.com ([192.55.52.93]:39002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg1be-0005oG-04 for qemu-devel@nongnu.org; Thu, 28 Oct 2021 05:21:55 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10150"; a="227819643" X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="227819643" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 02:15:16 -0700 X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="498301889" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 02:15:14 -0700 From: Zhang Chen To: Jason Wang Subject: [PATCH V5 1/3] net/filter: Optimize transfer protocol for filter-mirror/redirector Date: Thu, 28 Oct 2021 17:05:54 +0800 Message-Id: <20211028090556.3168043-2-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028090556.3168043-1-chen.zhang@intel.com> References: <20211028090556.3168043-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.55.52.93; envelope-from=chen.zhang@intel.com; helo=mga11.intel.com X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , qemu-dev , Li Zhijian , Markus Armbruster Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Make the vnet header a necessary part of filter transfer protocol. It make other modules(like another filter-redirector,colo-compare...) know how to parse net packet correctly. If local device is not the virtio-net-pci, vnet_hdr_len will be 0. Signed-off-by: Zhang Chen --- net/filter-mirror.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index f20240cc9f..24d3e498e9 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -39,6 +39,7 @@ struct MirrorState { CharBackend chr_in; CharBackend chr_out; SocketReadState rs; + /* Keep compatibility for the management layer */ bool vnet_hdr; }; @@ -48,7 +49,7 @@ static int filter_send(MirrorState *s, { NetFilterState *nf = NETFILTER(s); int ret = 0; - ssize_t size = 0; + ssize_t size = 0, vnet_hdr_len = 0; uint32_t len = 0; char *buf; @@ -63,21 +64,18 @@ static int filter_send(MirrorState *s, goto err; } - if (s->vnet_hdr) { - /* - * If vnet_hdr = on, we send vnet header len to make other - * module(like colo-compare) know how to parse net - * packet correctly. - */ - ssize_t vnet_hdr_len; - - vnet_hdr_len = nf->netdev->vnet_hdr_len; + /* + * The vnet header is the necessary part of filter transfer protocol. + * It make other module(like colo-compare) know how to parse net + * packet correctly. If device is not the virtio-net-pci, + * vnet_hdr_len will be 0. + */ + vnet_hdr_len = nf->netdev->vnet_hdr_len; - len = htonl(vnet_hdr_len); - ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); - if (ret != sizeof(len)) { - goto err; - } + len = htonl(vnet_hdr_len); + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); + if (ret != sizeof(len)) { + goto err; } buf = g_malloc(size); @@ -252,7 +250,7 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) } } - net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr); + net_socket_rs_init(&s->rs, redirector_rs_finalize, true); if (s->indev) { chr = qemu_chr_find(s->indev); @@ -406,14 +404,14 @@ static void filter_mirror_init(Object *obj) { MirrorState *s = FILTER_MIRROR(obj); - s->vnet_hdr = false; + s->vnet_hdr = true; } static void filter_redirector_init(Object *obj) { MirrorState *s = FILTER_REDIRECTOR(obj); - s->vnet_hdr = false; + s->vnet_hdr = true; } static void filter_mirror_fini(Object *obj) From patchwork Thu Oct 28 09:05:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 12589613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 772EEC433EF for ; Thu, 28 Oct 2021 09:23:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C75260E78 for ; Thu, 28 Oct 2021 09:23:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2C75260E78 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:35220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg1cs-0003FA-0E for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 05:23:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg1bd-0001E2-MR for qemu-devel@nongnu.org; Thu, 28 Oct 2021 05:21:53 -0400 Received: from mga11.intel.com ([192.55.52.93]:39002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg1bb-0005oG-Oh for qemu-devel@nongnu.org; Thu, 28 Oct 2021 05:21:53 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10150"; a="227819647" X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="227819647" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 02:15:17 -0700 X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="498301906" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 02:15:16 -0700 From: Zhang Chen To: Jason Wang Subject: [PATCH V5 2/3] net/filter: Optimize transfer protocol for filter-rewriter Date: Thu, 28 Oct 2021 17:05:55 +0800 Message-Id: <20211028090556.3168043-3-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028090556.3168043-1-chen.zhang@intel.com> References: <20211028090556.3168043-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.55.52.93; envelope-from=chen.zhang@intel.com; helo=mga11.intel.com X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , qemu-dev , Li Zhijian , Markus Armbruster Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Make the vnet header a necessary part of filter transfer protocol. Signed-off-by: Zhang Chen --- net/filter-rewriter.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index cb3a96cde1..70fa71583a 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -266,9 +266,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, iov_to_buf(iov, iovcnt, 0, buf, size); - if (s->vnet_hdr) { - vnet_hdr_len = nf->netdev->vnet_hdr_len; - } + vnet_hdr_len = nf->netdev->vnet_hdr_len; pkt = packet_new_nocopy(buf, size, vnet_hdr_len); @@ -415,7 +413,7 @@ static void filter_rewriter_init(Object *obj) { RewriterState *s = FILTER_REWRITER(obj); - s->vnet_hdr = false; + s->vnet_hdr = true; s->failover_mode = FAILOVER_MODE_OFF; } From patchwork Thu Oct 28 09:05:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 12589619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED11DC433F5 for ; Thu, 28 Oct 2021 09:25:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96E0660E78 for ; Thu, 28 Oct 2021 09:25:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 96E0660E78 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:40380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg1ei-0006jZ-OJ for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 05:25:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg1be-0001FR-9U for qemu-devel@nongnu.org; Thu, 28 Oct 2021 05:21:54 -0400 Received: from mga11.intel.com ([192.55.52.93]:39012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg1bc-0005oz-HM for qemu-devel@nongnu.org; Thu, 28 Oct 2021 05:21:54 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10150"; a="227819651" X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="227819651" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 02:15:19 -0700 X-IronPort-AV: E=Sophos;i="5.87,189,1631602800"; d="scan'208";a="498301919" Received: from unknown (HELO localhost.localdomain) ([10.239.13.19]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 02:15:17 -0700 From: Zhang Chen To: Jason Wang Subject: [PATCH V5 3/3] net/colo-compare.c: Optimize transfer protocol for colo-compare Date: Thu, 28 Oct 2021 17:05:56 +0800 Message-Id: <20211028090556.3168043-4-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211028090556.3168043-1-chen.zhang@intel.com> References: <20211028090556.3168043-1-chen.zhang@intel.com> MIME-Version: 1.0 Received-SPF: pass client-ip=192.55.52.93; envelope-from=chen.zhang@intel.com; helo=mga11.intel.com X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , qemu-dev , Li Zhijian , Markus Armbruster Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Enable vnet_hdr in payload by default. Make it easier to find module communication configuration errors. Signed-off-by: Zhang Chen --- net/colo-compare.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index b100e7b51f..fb61b0eea9 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -119,7 +119,9 @@ struct CompareState { SocketReadState notify_rs; SendCo out_sendco; SendCo notify_sendco; + /* Keep compatibility for the management layer */ bool vnet_hdr; + int local_vnet_hdr_len; uint64_t compare_timeout; uint32_t expired_scan_cycle; @@ -725,7 +727,6 @@ static void colo_compare_connection(void *opaque, void *user_data) static void coroutine_fn _compare_chr_send(void *opaque) { SendCo *sendco = opaque; - CompareState *s = sendco->s; int ret = 0; while (!g_queue_is_empty(&sendco->send_list)) { @@ -740,7 +741,7 @@ static void coroutine_fn _compare_chr_send(void *opaque) goto err; } - if (!sendco->notify_remote_frame && s->vnet_hdr) { + if (!sendco->notify_remote_frame) { /* * We send vnet header len make other module(like filter-redirector) * know how to parse net packet correctly. @@ -1157,6 +1158,9 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) CompareState *s = container_of(pri_rs, CompareState, pri_rs); Connection *conn = NULL; + /* Update colo-compare local vnet_hdr_len */ + s->local_vnet_hdr_len = pri_rs->vnet_hdr_len; + if (packet_enqueue(s, PRIMARY_IN, &conn)) { trace_colo_compare_main("primary: unsupported packet in"); compare_chr_send(s, @@ -1176,6 +1180,12 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs) CompareState *s = container_of(sec_rs, CompareState, sec_rs); Connection *conn = NULL; + /* Check the secondary vnet_hdr_len to ensure parse packet correctly */ + if (s->local_vnet_hdr_len != sec_rs->vnet_hdr_len) { + error_report("colo-compare got a different packet vnet_hdr_len" + " from local, please check the nodes -device configuration"); + } + if (packet_enqueue(s, SECONDARY_IN, &conn)) { trace_colo_compare_main("secondary: unsupported packet in"); } else { @@ -1289,8 +1299,8 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr); - net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr); + net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, true); + net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, true); /* Try to enable remote notify chardev, currently just for Xen COLO */ if (s->notify_dev) { @@ -1299,8 +1309,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } - net_socket_rs_init(&s->notify_rs, compare_notify_rs_finalize, - s->vnet_hdr); + net_socket_rs_init(&s->notify_rs, compare_notify_rs_finalize, false); } s->out_sendco.s = s; @@ -1397,7 +1406,8 @@ static void colo_compare_init(Object *obj) get_max_queue_size, set_max_queue_size, NULL, NULL); - s->vnet_hdr = false; + s->vnet_hdr = true; + s->local_vnet_hdr_len = 0; object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr, compare_set_vnet_hdr); }