From patchwork Wed Mar 25 09:43:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Su X-Patchwork-Id: 11457285 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B36214B4 for ; Wed, 25 Mar 2020 09:47:44 +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 7281C20771 for ; Wed, 25 Mar 2020 09:47:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=qnap.com header.i=@qnap.com header.b="dAKNpkhH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7281C20771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=qnap.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:32888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jH2dT-0000ys-Jx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Mar 2020 05:47:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55158) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jH2aV-0005ba-Rd for qemu-devel@nongnu.org; Wed, 25 Mar 2020 05:44:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jH2aT-0005MY-Ne for qemu-devel@nongnu.org; Wed, 25 Mar 2020 05:44:39 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:40912) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jH2aS-0005LX-IJ for qemu-devel@nongnu.org; Wed, 25 Mar 2020 05:44:37 -0400 Received: by mail-pj1-x1042.google.com with SMTP id kx8so787616pjb.5 for ; Wed, 25 Mar 2020 02:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qnap.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f6sHN97Z5k0H0NePRruYOF0pxNWEQGvMVIWCmlh8Qaw=; b=dAKNpkhHdKFwwtJD9gHiZzoTaadLQLebbglx8HullToL1uXLMEoz4cLRvpwjWv2Zxp BqxOoqfmXf8F4W7exCLa/WjIzOovj76YrfmnXSbuQX68EylHcnvrMCf/zogat7uFRTmU oh0EfOhed3x3nQ+gML6gDpKQZIe/vsClv7ud0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=f6sHN97Z5k0H0NePRruYOF0pxNWEQGvMVIWCmlh8Qaw=; b=LtK+PHf+I74nAqPEN2KZiv4bqFxFn3N0shX2HC/IRDu4ZSVahGpxWxYq6dziSgtDAa hnURVO+ImF7Xyw2F9iYrXqaWsoHDDTbrdGh7Mf/fQ8VxpyHSb5ZOTaYrTK9ZykFW0Fel qsUucYAPsxj75rIz683gE6IL2yxr5Ptsn3LovRb4Ye7HZEYrdfmEbhVTxYreBkhfdY23 VJOPGCvWgLHBU71dtcT/9Uq8DIWFUWeUgLIp+Mz+mtXVXka2XAn7TX/siW/B4sD8j0rH ugiFXaU31qUy/pP2bsU5MpATSDJfFgMRe6bJHEg5QSvf0vqgr1cr5PXCnynPLrCFQFPn 57Fg== X-Gm-Message-State: ANhLgQ3BnvzurtwIAHJWlX3l4CWOrAPxkurQ/EIlY2rsl0XqfDepuvWE nYUcjL+KDoRaIUiWl3eFfC+hSR99hsA= X-Google-Smtp-Source: ADFU+vtoQJmpC+bfRDfoaXivYNCSAIXN1tlvpZQTZDB4ZFuLcvnCl2EEE4zgKo6F3QgUHlW+jOeYxw== X-Received: by 2002:a17:90a:8403:: with SMTP id j3mr2787213pjn.8.1585129475007; Wed, 25 Mar 2020 02:44:35 -0700 (PDT) Received: from localhost.localdomain (202-39-79-13.HINET-IP.hinet.net. [202.39.79.13]) by smtp.gmail.com with ESMTPSA id j126sm18090602pfg.60.2020.03.25.02.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 02:44:34 -0700 (PDT) From: Derek Su To: qemu-devel@nongnu.org Subject: [PATCH v3 1/2] net/colo-compare.c: Fix memory leak in packet_enqueue() Date: Wed, 25 Mar 2020 17:43:53 +0800 Message-Id: <20200325094354.19677-2-dereksu@qnap.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200325094354.19677-1-dereksu@qnap.com> References: <20200325094354.19677-1-dereksu@qnap.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1042 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: lizhijian@cn.fujitsu.com, chyang@qnap.com, Derek Su , jasowang@redhat.com, ctcheng@qnap.com, chen.zhang@intel.com, jwsu1986@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The patch is to fix the "pkt" memory leak in packet_enqueue(). The allocated "pkt" needs to be freed if the colo compare primary or secondary queue is too big. Signed-off-by: Derek Su --- net/colo-compare.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 7ee17f2cf8..cdd87b2aa8 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -120,6 +120,10 @@ enum { SECONDARY_IN, }; +static const char *colo_mode[] = { + [PRIMARY_IN] = "primary", + [SECONDARY_IN] = "secondary", +}; static int compare_chr_send(CompareState *s, const uint8_t *buf, @@ -215,6 +219,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) ConnectionKey key; Packet *pkt = NULL; Connection *conn; + int ret; if (mode == PRIMARY_IN) { pkt = packet_new(s->pri_rs.buf, @@ -243,16 +248,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) } if (mode == PRIMARY_IN) { - if (!colo_insert_packet(&conn->primary_list, pkt, &conn->pack)) { - error_report("colo compare primary queue size too big," - "drop packet"); - } + ret = colo_insert_packet(&conn->primary_list, pkt, &conn->pack); } else { - if (!colo_insert_packet(&conn->secondary_list, pkt, &conn->sack)) { - error_report("colo compare secondary queue size too big," - "drop packet"); - } + ret = colo_insert_packet(&conn->secondary_list, pkt, &conn->sack); } + + if (!ret) { + error_report("colo compare %s queue size too big," + "drop packet", colo_mode[mode]); + packet_destroy(pkt, NULL); + pkt = NULL; + } + *con = conn; return 0; From patchwork Wed Mar 25 09:43:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Su X-Patchwork-Id: 11457337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD11D14B4 for ; Wed, 25 Mar 2020 09:49:57 +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 A503620772 for ; Wed, 25 Mar 2020 09:49:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=qnap.com header.i=@qnap.com header.b="iIi0HB8n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A503620772 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=qnap.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:32916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jH2fc-0003mh-O0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Mar 2020 05:49:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55182) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jH2aX-0005fE-A7 for qemu-devel@nongnu.org; Wed, 25 Mar 2020 05:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jH2aW-0005OI-3n for qemu-devel@nongnu.org; Wed, 25 Mar 2020 05:44:41 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:33060) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jH2aV-0005Nm-UY for qemu-devel@nongnu.org; Wed, 25 Mar 2020 05:44:40 -0400 Received: by mail-pj1-x1043.google.com with SMTP id jz1so2166443pjb.0 for ; Wed, 25 Mar 2020 02:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qnap.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZETUdq7dbeFyJSuB/tOC54IXqXsZmOKkkHBOPGbf4yg=; b=iIi0HB8nH6ErjWqdZlH8cxuBvlq4YPChdlwHFw9yylTueYfsGmqJHdTYhvtrDSVK04 LhECckheUUvZG4UhPs0WMb8qFTRY28TMs/bTzIUxihaxvh4t0J6v6vewY11KH/nUVQEU 9ALt5uewqipBD8GDEcQuhainOmm/aglWJD5a0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZETUdq7dbeFyJSuB/tOC54IXqXsZmOKkkHBOPGbf4yg=; b=P+PS5LbpxomO7m+nlUSp3WLJQwlwYP3/MO90kMqk+HULuIdoA6LzcLvax/3pXLhDz9 cV1anVJuXfGY6utS/0uotunQ1x2c7l86CvlvFIAhVzM7IeJxSFbZxMF1wQcF/GfimhLA gsiz8uaWGlscR99YS093E6uLT8j3DfwHz5dXsyXKcpSH0BGWsR7o1yUF/O9VzxDKRY8q A6xCUsfUYzTid2vz67RdGBI13zlzD/mpG7/ZpIZQgBuPQlMAFY+75YqphvhwnLfx8m4y E4AmCE0+EZGybI/zdpiAW5uEPf1SEeyJffMl+zsbdPf0FpqVgYNC0gEzSODWF/Tl5cC7 +OZA== X-Gm-Message-State: ANhLgQ1mhLs8bHoCdtf0SD9rV3+W2IL3jkxY3nvDUgexFX82iJisKCAt vTabBmIJScGN6E8I6zLOq5FLFPHcbQk= X-Google-Smtp-Source: ADFU+vukktLx4dwA4TBPfxn1qanseJe1HFAnR67E5VDoDAV98ECbPGhyR2mC2PNCMIQsXCyF3OHMGg== X-Received: by 2002:a17:90a:350d:: with SMTP id q13mr2614185pjb.171.1585129478505; Wed, 25 Mar 2020 02:44:38 -0700 (PDT) Received: from localhost.localdomain (202-39-79-13.HINET-IP.hinet.net. [202.39.79.13]) by smtp.gmail.com with ESMTPSA id j126sm18090602pfg.60.2020.03.25.02.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Mar 2020 02:44:37 -0700 (PDT) From: Derek Su To: qemu-devel@nongnu.org Subject: [PATCH v3 2/2] net/colo-compare.c: handling of the full primary or secondary queue Date: Wed, 25 Mar 2020 17:43:54 +0800 Message-Id: <20200325094354.19677-3-dereksu@qnap.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200325094354.19677-1-dereksu@qnap.com> References: <20200325094354.19677-1-dereksu@qnap.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1043 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: lizhijian@cn.fujitsu.com, chyang@qnap.com, Derek Su , jasowang@redhat.com, ctcheng@qnap.com, chen.zhang@intel.com, jwsu1986@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The pervious handling of the full primary or queue is only dropping the packet. If there are lots of clients to the guest VM, the "drop" will lead to the lost of the networking connection until next checkpoint. To address the issue, this patch drops the packet firstly. Then, send all queued primary packets, remove all queued secondary packets and do checkpoint. Signed-off-by: Derek Su --- net/colo-compare.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index cdd87b2aa8..1a52f50fbe 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -125,6 +125,12 @@ static const char *colo_mode[] = { [SECONDARY_IN] = "secondary", }; +enum { + QUEUE_INSERT_ERR = -1, + QUEUE_INSERT_OK = 0, + QUEUE_INSERT_FULL = 1, +}; + static int compare_chr_send(CompareState *s, const uint8_t *buf, uint32_t size, @@ -211,8 +217,10 @@ static int colo_insert_packet(GQueue *queue, Packet *pkt, uint32_t *max_ack) } /* - * Return 0 on success, if return -1 means the pkt - * is unsupported(arp and ipv6) and will be sent later + * Return QUEUE_INSERT_OK on success. + * If return QUEUE_INSERT_FULL means list is full, and + * QUEUE_INSERT_ERR means the pkt is unsupported(arp and ipv6) and + * will be sent later */ static int packet_enqueue(CompareState *s, int mode, Connection **con) { @@ -234,7 +242,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) if (parse_packet_early(pkt)) { packet_destroy(pkt, NULL); pkt = NULL; - return -1; + return QUEUE_INSERT_ERR; } fill_connection_key(pkt, &key); @@ -258,11 +266,12 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) "drop packet", colo_mode[mode]); packet_destroy(pkt, NULL); pkt = NULL; + return QUEUE_INSERT_FULL; } *con = conn; - return 0; + return QUEUE_INSERT_OK; } static inline bool after(uint32_t seq1, uint32_t seq2) @@ -995,17 +1004,22 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) { CompareState *s = container_of(pri_rs, CompareState, pri_rs); Connection *conn = NULL; + int ret; - if (packet_enqueue(s, PRIMARY_IN, &conn)) { + ret = packet_enqueue(s, PRIMARY_IN, &conn); + if (ret == QUEUE_INSERT_OK) { + /* compare packet in the specified connection */ + colo_compare_connection(conn, s); + } else if (ret == QUEUE_INSERT_FULL) { + g_queue_foreach(&s->conn_list, colo_flush_packets, s); + colo_compare_inconsistency_notify(s); + } else { trace_colo_compare_main("primary: unsupported packet in"); compare_chr_send(s, pri_rs->buf, pri_rs->packet_len, pri_rs->vnet_hdr_len, false); - } else { - /* compare packet in the specified connection */ - colo_compare_connection(conn, s); } } @@ -1013,12 +1027,17 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs) { CompareState *s = container_of(sec_rs, CompareState, sec_rs); Connection *conn = NULL; + int ret; - if (packet_enqueue(s, SECONDARY_IN, &conn)) { - trace_colo_compare_main("secondary: unsupported packet in"); - } else { + ret = packet_enqueue(s, SECONDARY_IN, &conn); + if (ret == QUEUE_INSERT_OK) { /* compare packet in the specified connection */ colo_compare_connection(conn, s); + } else if (ret == QUEUE_INSERT_FULL) { + g_queue_foreach(&s->conn_list, colo_flush_packets, s); + colo_compare_inconsistency_notify(s); + } else { + trace_colo_compare_main("secondary: unsupported packet in"); } }