From patchwork Sat Mar 28 12:46:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Su X-Patchwork-Id: 1263214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=qnap.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=qnap.com header.i=@qnap.com header.a=rsa-sha256 header.s=google header.b=V+PthXT5; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48qJRb33vlz9sSM for ; Sat, 28 Mar 2020 23:48:10 +1100 (AEDT) Received: from localhost ([::1]:52892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIAsi-00069n-Gx for incoming@patchwork.ozlabs.org; Sat, 28 Mar 2020 08:48:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52025) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIAsE-00066z-2K for qemu-devel@nongnu.org; Sat, 28 Mar 2020 08:47:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIAsC-00080u-4n for qemu-devel@nongnu.org; Sat, 28 Mar 2020 08:47:37 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:36696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIAsB-0007zK-To for qemu-devel@nongnu.org; Sat, 28 Mar 2020 08:47:36 -0400 Received: by mail-pj1-x1042.google.com with SMTP id nu11so4964145pjb.1 for ; Sat, 28 Mar 2020 05:47:35 -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=V+PthXT5425UqxL3Iyb7u+MuFT/1qyDC4VEI7WAJkcUS5sCXa8WJMlQ+TckLaDZ9Gl 8qpCz5L3y01bstdFWJVPcQtpHYTsjMCAvlOE+EWNAxmzMy/DflfT7WrfIVhRurLLuL+8 GQ2FoSIQt452sOGcL9IKso5afMwHVWVAtiXmU= 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=XdhVw1qfwNBTe3ekkMAglhG9cjtoto6ig0I5eMkMLCOigVCfYohpzcLh7CJHgqGp1S 360YZf84jKMimNLjkNRWuHF260fRCPEfLRdF+Q2PLxV269Noa+tp7R1kQ8lcixiVL+rq IwYWafcy/baS69ueON1Bcoc8em9VzZUfq/t7u0zJ3YhPsPfbddF4wdgjdSeXH6FVUvp7 dcU25zy/7XEFhK1t5kijPieMIsCbVOGBEA7R8woQLT9bxG1O3z36ZYC+pUsubY2zhdHP PITdbXMucd4qyJlzK+mgXkn1Y2OdO5jdMQh7nmaVcXJAw/Qhm8hO1C5NW86hKlsdOHSs JHig== X-Gm-Message-State: ANhLgQ3fNZQ2qB45xQTYEJ06qOPgww+rs4hcC4UpKyFD9Y/PC1SQalfr CMkEaRI1k8YGmh9ZC0XZ/mi6b/lriXE= X-Google-Smtp-Source: ADFU+vvcAzMXVZg5KK5zNV297YuZai/Gy3pV0AwtLkAmtAG9rjvxCzE2rQaglmhvLkDVVzw7mVkU5A== X-Received: by 2002:a17:90a:bb92:: with SMTP id v18mr4914763pjr.103.1585399653765; Sat, 28 Mar 2020 05:47:33 -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 k14sm10176468pje.3.2020.03.28.05.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 05:47:33 -0700 (PDT) From: Derek Su To: qemu-devel@nongnu.org Subject: [PATCH v4 1/2] net/colo-compare.c: Fix memory leak in packet_enqueue() Date: Sat, 28 Mar 2020 20:46:45 +0800 Message-Id: <20200328124646.7778-2-dereksu@qnap.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328124646.7778-1-dereksu@qnap.com> References: <20200328124646.7778-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+incoming=patchwork.ozlabs.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 Reviewed-by: Zhang Chen Reviewed-by: Lukas Straub Tested-by: Lukas Straub --- 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 Sat Mar 28 12:46:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Su X-Patchwork-Id: 1263216 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=qnap.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=qnap.com header.i=@qnap.com header.a=rsa-sha256 header.s=google header.b=Qt55up7/; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48qJTK6gXtz9sPk for ; Sat, 28 Mar 2020 23:49:41 +1100 (AEDT) Received: from localhost ([::1]:52902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIAuB-0007oZ-Sp for incoming@patchwork.ozlabs.org; Sat, 28 Mar 2020 08:49:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52037) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jIAsH-00067p-QW for qemu-devel@nongnu.org; Sat, 28 Mar 2020 08:47:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jIAsF-00082g-Qy for qemu-devel@nongnu.org; Sat, 28 Mar 2020 08:47:41 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:44552) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jIAsE-00081t-QX for qemu-devel@nongnu.org; Sat, 28 Mar 2020 08:47:38 -0400 Received: by mail-pf1-x443.google.com with SMTP id b72so5924348pfb.11 for ; Sat, 28 Mar 2020 05:47:38 -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=muXHoLZL0Cd7IjD57+5HkvVOZyFuGtQkFYQQmjWk/0I=; b=Qt55up7/sYJX4Ga7+hPIVe4j0FGRom9MXq9TcoTVhqIrmJGrY/eAYT+r/+QYyZkaU4 O6DX9OCQt7NijTuUAXNV/QbakezK7xpS7Pf9SRjL/ULA+YMQapQPGwZZEJ5fmRSFV2t0 Kcc2x6be5CzxMMzuswI2+m9zupmarZOKAnHqY= 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=muXHoLZL0Cd7IjD57+5HkvVOZyFuGtQkFYQQmjWk/0I=; b=hS+ZBpKv28NuNGA9cho4+DKChmrFH6P910D+iDjfoiBN8+gwg69U6+z5C69Jg61Ay8 qkbAGbUk137ZRjPzl6pFESMYSEAkE4HfUbhOdcP0ZKGf4UqRiemK4/ZGvZz62KU5qvpy SjS6eVCo5hB7tc4LKPDTThYFRYlYfh4zCKjymXeK865hTiK6az/gqzfE77IuH1f7nukd CBMRiAJjuR9ftJsw/oac2YcBi9Q+qeGzHt+qUzJCYcDJgWOVZ26dFB9HkibJ48vkxHU9 TI7ZEPOLRRWwkDV6m2erpO8kpbotfjaDyzrTGrNLLurfcXzT1IoxQfRMo/5q/Th9Yg07 UkBA== X-Gm-Message-State: ANhLgQ0x47n54mGt5Qhy8St+M/xAR+o9YVA2wkKs71B8Ym/1xm6N1sbR kjMxeLlEGmSNI2x30OczJco+DXgQsrY= X-Google-Smtp-Source: ADFU+vvjPIth6UyxZv8q/Rv+GQPcweGBpJ2fgqHxj4p3WXQCXe5EjVCfPv+tgYqdHSzNEin76vOX5A== X-Received: by 2002:a62:1bd6:: with SMTP id b205mr4301220pfb.242.1585399657493; Sat, 28 Mar 2020 05:47:37 -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 k14sm10176468pje.3.2020.03.28.05.47.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 05:47:36 -0700 (PDT) From: Derek Su To: qemu-devel@nongnu.org Subject: [PATCH v4 2/2] net/colo-compare.c: handling of the full primary or secondary queue Date: Sat, 28 Mar 2020 20:46:46 +0800 Message-Id: <20200328124646.7778-3-dereksu@qnap.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328124646.7778-1-dereksu@qnap.com> References: <20200328124646.7778-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::443 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+incoming=patchwork.ozlabs.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, do checkpoint and flush packets. Signed-off-by: Derek Su Reviewed-by: Zhang Chen Reviewed-by: Lukas Straub Tested-by: Lukas Straub --- net/colo-compare.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index cdd87b2aa8..fe8779cf2d 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,21 @@ 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) { + 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 +1026,16 @@ 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) { + colo_compare_inconsistency_notify(s); + } else { + trace_colo_compare_main("secondary: unsupported packet in"); } }