From patchwork Sun Apr 26 21:18:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11511003 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 E2B4515AB for ; Sun, 26 Apr 2020 21:25:39 +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 42882206BF for ; Sun, 26 Apr 2020 21:25:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="gYBWYSW4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42882206BF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSomP-0007ME-VX for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 17:25:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33784) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSog6-0004Dv-EN for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSofy-0005Lo-JR for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:06 -0400 Received: from mout.web.de ([212.227.15.4]:40645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSofy-0005JI-0f for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:18:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587935925; bh=KlCniyLWMcP5meR1EMfh+9J/dqnOAwFcyGmWU0KJCdg=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=gYBWYSW4FDWXgautvwygWZODJtfrNr0R0Vx6CaKYyt7jdBckgm6yYjwuR5PPRG27O qVThMIi3HQDGf5ukXHqtmRbedo2yBPVNhq5nmBuRKzTQ/CdEKNltoO91ix28MYCx1R EpsIc6rpWutyYobkFedpl1v7wzEyKPnnR2te2lpg= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([94.134.180.69]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MTPjb-1jaguA08sp-00SOp0; Sun, 26 Apr 2020 23:18:45 +0200 Date: Sun, 26 Apr 2020 23:18:43 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v3 1/6] net/colo-compare.c: Create event_bh with the right AioContext Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:Y+e1XuD7bAxwd1lKicD6/cC+P9/ujCZvW4cX1iaIzwlQeyBnK6W IKBMQxWOtnu8ulz0AQDdf584Rt+MF2Stj+53kkw/3W52vo4pnyq2hWvswPNL9SZE+A8skyS ohOV47+rjqHoZTSA1HS89//qqoHzWT0CwUComk5GJ3VtZVRLQgFUdaVmLAS0URtriydswMz MvVYXy8Bnp7+DW4308gdg== X-UI-Out-Filterresults: notjunk:1;V03:K0:QSlz2Tr0d38=:Qdg/N1F122ByJ4TikGf1d6 2wrnaqWPxWYZ9B8QUtTC9oJZtd/jrFcQvZMShc/mCmuBdHI1VmxJ4UVL32tPG6PZ8cTmjhr8Y pnqrl3z3PhSYPZBVYuxsij8nupdhm1PxB0RxXJSdxnAK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zUnKu/4qj99EhPoM+BVGyBT9bR+vE1vWDsBUH0AFA1A18K2CmCYEmz 08wmAp72Es6tMlGbz Received-SPF: pass client-ip=212.227.15.4; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 15:25:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.4 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 , Jason Wang , Paolo Bonzini , Li Zhijian , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" qemu_bh_new will set the bh to be executed in the main loop. This causes crashes as colo_compare_handle_event assumes that it has exclusive access the queues, which are also concurrently accessed in the iothread. Create the bh with the AioContext of the iothread to fulfill these assumptions and fix the crashes. This is safe, because the bh already takes the appropriate locks. Signed-off-by: Lukas Straub Reviewed-by: Zhang Chen Reviewed-by: Derek Su Tested-by: Derek Su --- net/colo-compare.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 10c0239f9d..1de4220fe2 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -890,6 +890,7 @@ static void colo_compare_handle_event(void *opaque) static void colo_compare_iothread(CompareState *s) { + AioContext *ctx = iothread_get_aio_context(s->iothread); object_ref(OBJECT(s->iothread)); s->worker_context = iothread_get_g_main_context(s->iothread); @@ -906,7 +907,7 @@ static void colo_compare_iothread(CompareState *s) } colo_compare_timer_init(s); - s->event_bh = qemu_bh_new(colo_compare_handle_event, s); + s->event_bh = aio_bh_new(ctx, colo_compare_handle_event, s); } static char *compare_get_pri_indev(Object *obj, Error **errp) From patchwork Sun Apr 26 21:18:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11511007 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 B6F2D15AB for ; Sun, 26 Apr 2020 21:26:04 +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 8CAFF206BF for ; Sun, 26 Apr 2020 21:26:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="jQlV5Efb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CAFF206BF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSomp-0007Qk-7u for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 17:26:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33780) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSog5-0004Dp-Tj for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSog5-0005kg-HL for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:05 -0400 Received: from mout.web.de ([217.72.192.78]:38289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSog4-0005fS-W9 for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587935930; bh=NSu8R6ZArrzXlpc/YQzMnC4LGGAot9bFFDtDweoB8DM=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=jQlV5Efb5XeABlgz3+G/xMcRlmb0rWJRxrJrdIZqrJbuovN4ZHZpBAcqlRdFmVO85 Dptlyc0A+XjZkQre1yYzXxWwXhqNiHaEudEntWUiAhTOI5yQiyKJJ010l+WSHCn+jn NfQx0AVTSh4IHCa828zIl8ZAQLk3twcn6a56kU/I= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([94.134.180.69]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MbQOe-1jjFd81LGO-00IkEX; Sun, 26 Apr 2020 23:18:50 +0200 Date: Sun, 26 Apr 2020 23:18:47 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v3 2/6] chardev/char.c: Use qemu_co_sleep_ns if in coroutine Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:TWcJqsNDhHaXFF3bGcMiCZL6a7b89w6jWKkxntDSDR57yfyTP9Q /Jx0UBWCRj1Tg7/JSi7QNTwnjl5dkwGGLVAdP/WicIYKZSaS9zoIxiMpgaUGaSksa57rrXt tQAXwjqgu2zE8g4sKWB32X5I2rkFSnZZRyjhat9Pu66udi3Ugu2JW6rtOzDWHeCQgcIPhN2 O00mY14bOAGyT5O78haCg== X-UI-Out-Filterresults: notjunk:1;V03:K0:P1M7rcbPO9I=:OYWJasBOQgAyquCnJPVacW iN1ivLI3uDlipIr+O3y70hPsb63to3h7AKYWibPH7u4Mt1P2Phj/vGCNUCGJVQG/zYJh+2Ndm XLssiD0RQCtMwAjrRNXBhs9UjqIB+WIYRw41iaElA29bm/Dgm25lw5bYD1YAOXZ6D/G5i/hyy BSzc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mpxbArO1QUebLghDNhk1 rYPN8xqE/j2Odai8/ Received-SPF: pass client-ip=217.72.192.78; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 15:25:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.78 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 , Jason Wang , Paolo Bonzini , Li Zhijian , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This will be needed in the next patch. Signed-off-by: Lukas Straub Reviewed-by: Marc-André Lureau Reviewed-by: Zhang Chen --- chardev/char.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chardev/char.c b/chardev/char.c index e77564060d..5c8014199f 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -38,6 +38,7 @@ #include "qemu/module.h" #include "qemu/option.h" #include "qemu/id.h" +#include "qemu/coroutine.h" #include "chardev/char-mux.h" @@ -119,7 +120,11 @@ static int qemu_chr_write_buffer(Chardev *s, retry: res = cc->chr_write(s, buf + *offset, len - *offset); if (res < 0 && errno == EAGAIN && write_all) { - g_usleep(100); + if (qemu_in_coroutine()) { + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000); + } else { + g_usleep(100); + } goto retry; } From patchwork Sun Apr 26 21:18:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11511011 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 D62BA13B2 for ; Sun, 26 Apr 2020 21:40:15 +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 9A1AF2070A for ; Sun, 26 Apr 2020 21:40:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="mIOXcZzx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A1AF2070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSp0X-0005Hy-IF for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 17:40:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33794) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSog7-0004EV-OU for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSog6-0005nf-QY for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:07 -0400 Received: from mout.web.de ([212.227.15.4]:50979) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSog6-0005iQ-8b for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587935934; bh=DbBCGA89qghzmKJshXtYixm26XJWPI1lsyRXXQJ6Hzg=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=mIOXcZzxkWZ+6Tr7MnJWMHQ0VqibjZCKbs5Lw+NyIj/8WIgzrPVgqHkhLdet4AUwV XI1rdaq+dhX/1ySYz3E9JqCDTrOLqUeG/DBxL/fl8UcQKSvS/R5LhEO4RrX0tVfsQS lKufhUJQm5vxVMc4e6R3L+3sFDcIuYzWeDZ4FVuk= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([94.134.180.69]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LiUF2-1iuZmc0evU-00ceZU; Sun, 26 Apr 2020 23:18:54 +0200 Date: Sun, 26 Apr 2020 23:18:53 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v3 3/6] net/colo-compare.c: Fix deadlock in compare_chr_send Message-ID: <6f3906393aaaf0adf21d45a5bf7a41536c7de205.1587935686.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:eFAd8kcejpfNtS48sFy+HEPplL8gzQ6b/cjw3YoMaIshyqMFucT 4cRuWDd4st6sjGatdofpYodrVABSIu4eEikHzBpAjpR23pVahS3dgJxiC83J7s7bYs8sbtK aCZ3Rclzy/zs5vUrAb1NdwQDoBnziOPLYwVq0zLybvLIqhsQ7qLeMDkIDVvWW2ihf6WUN4o oCFrZ+dlhIwOUYxwNw17Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:bjHEhnFY1bY=:UgdkhxZNqlaW1H7qgKnzsi OwqrnH9SdeFklxW154/hyFJ/fyNLNlXaDVUD8lCq5F3hC4o1RBNG5OR/YH2hvPHSjmtzkKKTs WuGqScDfLj0wJDEldMRH2ksscA1qPcmZZf7/bKqN6peELuJp0uDX1HGlqOmXKAjs5PyUQOG2x 7FLqIewYiWSYM6d/IcieCUxus/JLIHUtQSszwqxZOy3ZWLXY4XbcabE+vRcal+1SzAMIsRnn9 x0nKU1XAjtXLqRJSIK8SYsNAi+M9eDKYkMnGihGt17Ge+rGvnO9vd2SB0sXwL7+GSGHHH5nPY i0BWJ9U6Ykb1qFPqy897eNeWTDTlqvCAXzZcIQmm9Fe73sMby3IKu544/JzfqEqlZd0mVStsH A+0rByxkZqEXb9ackOk7pPgAL4uxhuICZwilWBQCO5kakMPqP0Qqczja7XRFbPt54sM1o5pWh rZ6hWbZBkEG+xCPuDjeNCRiX9uaH+fKNIxx04A0VjbDuwrFkkpBvNgbgp5lKPktPKjBlL4N0I 60+nhaCmchU73b12OXldHWZ0dzQYXTegGsnsp6JvAGPzgRJANxhXOwsdL4UGo+0Hysw433ft8 LIwlT2TgRKu1uRCuzIzXT9/WEM0bNfH1WbUkHf6buclv+gTY3Bgbiv3Mgc8aMeR1ZXojQC3N9 M2AcNAVO9SSly9cuNJxdEEqcpwTHg0yT4Q82U67v3L/DXgRaaeePcdzAYqxW/VzKqVESYJLCM lRc81+LxG+vL4B4IstEyYg3xEFZN9xzeFiRkpu4V36hair08EVuniiOFl5zU/8zsNZLg+Ob6s Ow1bvRK1+1dE9CDstYt6rbJhW4IYR755ELn55U9Of56ZSFA7EvKvAJnsiBuKNUo44bMP5HeTk dI39T99ysNq7Xq82hFe7yIdN2Z9c9MVbTewfU8Vz8A36OM7jB06OU/n6bFnW/KOfPij5BT9E4 YV8fEgH8oWfEgfWOtY9q1JA0eOcyHEMTVe5YYEeIUP36sZwUqNCW2LTAg17I7eSe2UTo9xw7D vUTEU/9EgvoD/1OntDKWoDeJdoAgv04QW8KWkSkXP6Sk032PReNYX0RcqnX2w86FzADZG6IOx zarKn+mKooLd9VaUcTOPu8VddDqXQtyDUcJWm+IvRGYqCAYAHuJM0N4sR1mF1c+pZzlkDib9m UcKoaYjT/alkrdPpimm3Tku1yJGMrHiyBrMvffhLyaaq1++uYRfkd2StMnOPBeSVDVSC+0Wa5 X3K3UK+A+mEUcdAJ/ Received-SPF: pass client-ip=212.227.15.4; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 15:25:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.4 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 , Jason Wang , Paolo Bonzini , Li Zhijian , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The chr_out chardev is connected to a filter-redirector running in the main loop. qemu_chr_fe_write_all might block here in compare_chr_send if the (socket-)buffer is full. If another filter-redirector in the main loop want's to send data to chr_pri_in it might also block if the buffer is full. This leads to a deadlock because both event loops get blocked. Fix this by converting compare_chr_send to a coroutine and putting the packets in a send queue. Also create a new function notify_chr_send, since that should be independend. Signed-off-by: Lukas Straub --- net/colo-compare.c | 173 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 130 insertions(+), 43 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 1de4220fe2..ff6a740284 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -32,6 +32,9 @@ #include "migration/migration.h" #include "util.h" +#include "block/aio-wait.h" +#include "qemu/coroutine.h" + #define TYPE_COLO_COMPARE "colo-compare" #define COLO_COMPARE(obj) \ OBJECT_CHECK(CompareState, (obj), TYPE_COLO_COMPARE) @@ -77,6 +80,20 @@ static int event_unhandled_count; * |packet | |packet + |packet | |packet + * +--------+ +--------+ +--------+ +--------+ */ + +typedef struct SendCo { + Coroutine *co; + GQueue send_list; + bool done; + int ret; +} SendCo; + +typedef struct SendEntry { + uint32_t size; + uint32_t vnet_hdr_len; + uint8_t buf[]; +} SendEntry; + typedef struct CompareState { Object parent; @@ -91,6 +108,7 @@ typedef struct CompareState { SocketReadState pri_rs; SocketReadState sec_rs; SocketReadState notify_rs; + SendCo sendco; bool vnet_hdr; uint32_t compare_timeout; uint32_t expired_scan_cycle; @@ -126,8 +144,11 @@ enum { static int compare_chr_send(CompareState *s, const uint8_t *buf, uint32_t size, - uint32_t vnet_hdr_len, - bool notify_remote_frame); + uint32_t vnet_hdr_len); + +static int notify_chr_send(CompareState *s, + const uint8_t *buf, + uint32_t size); static bool packet_matches_str(const char *str, const uint8_t *buf, @@ -145,7 +166,7 @@ static void notify_remote_frame(CompareState *s) char msg[] = "DO_CHECKPOINT"; int ret = 0; - ret = compare_chr_send(s, (uint8_t *)msg, strlen(msg), 0, true); + ret = notify_chr_send(s, (uint8_t *)msg, strlen(msg)); if (ret < 0) { error_report("Notify Xen COLO-frame failed"); } @@ -271,8 +292,7 @@ static void colo_release_primary_pkt(CompareState *s, Packet *pkt) ret = compare_chr_send(s, pkt->data, pkt->size, - pkt->vnet_hdr_len, - false); + pkt->vnet_hdr_len); if (ret < 0) { error_report("colo send primary packet failed"); } @@ -699,63 +719,123 @@ static void colo_compare_connection(void *opaque, void *user_data) } } -static int compare_chr_send(CompareState *s, - const uint8_t *buf, - uint32_t size, - uint32_t vnet_hdr_len, - bool notify_remote_frame) +static void coroutine_fn _compare_chr_send(void *opaque) { + CompareState *s = opaque; + SendCo *sendco = &s->sendco; int ret = 0; - uint32_t len = htonl(size); - if (!size) { - return 0; - } + while (!g_queue_is_empty(&sendco->send_list)) { + SendEntry *entry = g_queue_pop_tail(&sendco->send_list); + uint32_t len = htonl(entry->size); - if (notify_remote_frame) { - ret = qemu_chr_fe_write_all(&s->chr_notify_dev, - (uint8_t *)&len, - sizeof(len)); - } else { ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); - } - if (ret != sizeof(len)) { - goto err; - } + if (ret != sizeof(len)) { + g_free(entry); + goto err; + } - if (s->vnet_hdr) { - /* - * We send vnet header len make other module(like filter-redirector) - * know how to parse net packet correctly. - */ - len = htonl(vnet_hdr_len); + if (s->vnet_hdr) { + /* + * We send vnet header len make other module(like filter-redirector) + * know how to parse net packet correctly. + */ + len = htonl(entry->vnet_hdr_len); - if (!notify_remote_frame) { ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); + + if (ret != sizeof(len)) { + g_free(entry); + goto err; + } } - if (ret != sizeof(len)) { + ret = qemu_chr_fe_write_all(&s->chr_out, + (uint8_t *)entry->buf, + entry->size); + + if (ret != entry->size) { + g_free(entry); goto err; } + + g_free(entry); } - if (notify_remote_frame) { - ret = qemu_chr_fe_write_all(&s->chr_notify_dev, - (uint8_t *)buf, - size); - } else { - ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); + sendco->ret = 0; + goto out; + +err: + while (!g_queue_is_empty(&sendco->send_list)) { + SendEntry *entry = g_queue_pop_tail(&sendco->send_list); + g_free(entry); } + sendco->ret = ret < 0 ? ret : -EIO; +out: + sendco->co = NULL; + sendco->done = true; + aio_wait_kick(); +} + +static int compare_chr_send(CompareState *s, + const uint8_t *buf, + uint32_t size, + uint32_t vnet_hdr_len) +{ + SendCo *sendco = &s->sendco; + SendEntry *entry; + + if (!size) { + return 0; + } + + entry = g_malloc(sizeof(SendEntry) + size); + entry->size = size; + entry->vnet_hdr_len = vnet_hdr_len; + memcpy(entry->buf, buf, size); + g_queue_push_head(&sendco->send_list, entry); + + if (sendco->done) { + sendco->co = qemu_coroutine_create(_compare_chr_send, s); + sendco->done = false; + qemu_coroutine_enter(sendco->co); + if (sendco->done) { + /* report early errors */ + return sendco->ret; + } + } + + /* assume success */ + return 0; +} + +static int notify_chr_send(CompareState *s, + const uint8_t *buf, + uint32_t size) +{ + int ret = 0; + uint32_t len = htonl(size); + + ret = qemu_chr_fe_write_all(&s->chr_notify_dev, + (uint8_t *)&len, + sizeof(len)); + + if (ret != sizeof(len)) { + goto err; + } + + ret = qemu_chr_fe_write_all(&s->chr_notify_dev, + (uint8_t *)buf, + size); if (ret != size) { goto err; } return 0; - err: return ret < 0 ? ret : -EIO; } @@ -1062,8 +1142,7 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) compare_chr_send(s, pri_rs->buf, pri_rs->packet_len, - pri_rs->vnet_hdr_len, - false); + pri_rs->vnet_hdr_len); } else { /* compare packet in the specified connection */ colo_compare_connection(conn, s); @@ -1093,7 +1172,7 @@ static void compare_notify_rs_finalize(SocketReadState *notify_rs) if (packet_matches_str("COLO_USERSPACE_PROXY_INIT", notify_rs->buf, notify_rs->packet_len)) { - ret = compare_chr_send(s, (uint8_t *)msg, strlen(msg), 0, true); + ret = notify_chr_send(s, (uint8_t *)msg, strlen(msg)); if (ret < 0) { error_report("Notify Xen COLO-frame INIT failed"); } @@ -1199,6 +1278,9 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) QTAILQ_INSERT_TAIL(&net_compares, s, next); + s->sendco.done = true; + g_queue_init(&s->sendco.send_list); + g_queue_init(&s->conn_list); qemu_mutex_init(&event_mtx); @@ -1224,8 +1306,7 @@ static void colo_flush_packets(void *opaque, void *user_data) compare_chr_send(s, pkt->data, pkt->size, - pkt->vnet_hdr_len, - false); + pkt->vnet_hdr_len); packet_destroy(pkt, NULL); } while (!g_queue_is_empty(&conn->secondary_list)) { @@ -1281,6 +1362,11 @@ static void colo_compare_finalize(Object *obj) CompareState *s = COLO_COMPARE(obj); CompareState *tmp = NULL; + AioContext *ctx = iothread_get_aio_context(s->iothread); + aio_context_acquire(ctx); + AIO_WAIT_WHILE(ctx, !s->sendco.done); + aio_context_release(ctx); + qemu_chr_fe_deinit(&s->chr_pri_in, false); qemu_chr_fe_deinit(&s->chr_sec_in, false); qemu_chr_fe_deinit(&s->chr_out, false); @@ -1305,6 +1391,7 @@ static void colo_compare_finalize(Object *obj) g_queue_foreach(&s->conn_list, colo_flush_packets, s); g_queue_clear(&s->conn_list); + g_queue_clear(&s->sendco.send_list); if (s->connection_track_table) { g_hash_table_destroy(s->connection_track_table); From patchwork Sun Apr 26 21:18:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11511041 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 E3B2A15AB for ; Sun, 26 Apr 2020 21:54:18 +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 B99BA2071C for ; Sun, 26 Apr 2020 21:54:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="T3rLQyUX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B99BA2071C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSpE9-0002QG-Me for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 17:54:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33878) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSogY-0004OB-7T for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSogJ-0006UX-29 for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:34 -0400 Received: from mout.web.de ([212.227.17.11]:39057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSogI-0006Rj-C6 for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587935938; bh=RrNnM3VAiZMXdLeP1/sr9CeC+WSjjrizzc8RS1g9EpE=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=T3rLQyUXwU8fROMdEWL4KF3YgV9mr164LQkajiC4CQ40xWZfd8YC9m9apXRUICB1L g5M0fNzotd323zXbDAxxmaWGulTNlMHdlKeB/906yeh2ctJRPTbE2H5f6kVTZZdrH8 ys6Diarez3dn5HbBM1H4QGVTFveaaZINfd64gLhQ= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([94.134.180.69]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MA5v3-1jLtrn1Nij-00BHS0; Sun, 26 Apr 2020 23:18:58 +0200 Date: Sun, 26 Apr 2020 23:18:57 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v3 4/6] net/colo-compare.c: Only hexdump packets if tracing is enabled Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:lDz6X3ZU7pODbf1VA2Si+YHMF7AJQJE01nMe/5ffIrgm8FjiFaG o5LK6IbOaWzz0b0V7j6sR6VGQBpbZAdIwOLPhGrA3UXhhn7gzlXTpb2MPG71RUkHyYN3sla JdcyFcd0L987Lz/P+rfJmS5RjETTPyg+T3PqoVZtIwQKb6lgyZHxN6+orXgeWxV79su68WO XBHz1XiGJo0+wxRUjWpOw== X-UI-Out-Filterresults: notjunk:1;V03:K0:pXqqKDTcxHY=:JABBwYcb1o9fbA/cfFpkvV veUwx9TWFRO+o6Vd2ba2m8bvmUgP5whadWLgzKh7PS/uI6wVNYJnaKL4CjjChYglrjw3uSsJn gTZkeJirGo2CzoTJsSYm17fdyWGsbmZsQcDg8TBmL7MVgiO+8mXdqZiNracesZqmcOVWXen+/ l/CwlnHaH6k8ngXqRtaFLLP6CedVioEvhJvXo8v+XxV86JXX6ZY485avXUeUQwIBVp9dDPp9m ndjb8AZp0jf3CYT1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o=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 17:18:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.11 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 , Jason Wang , Paolo Bonzini , Li Zhijian , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Else the log will be flooded if there is a lot of network traffic. Signed-off-by: Lukas Straub Reviewed-by: Zhang Chen --- net/colo-compare.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index ff6a740284..6634911770 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -479,10 +479,12 @@ sec: g_queue_push_head(&conn->primary_list, ppkt); g_queue_push_head(&conn->secondary_list, spkt); - qemu_hexdump((char *)ppkt->data, stderr, - "colo-compare ppkt", ppkt->size); - qemu_hexdump((char *)spkt->data, stderr, - "colo-compare spkt", spkt->size); + if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) { + qemu_hexdump((char *)ppkt->data, stderr, + "colo-compare ppkt", ppkt->size); + qemu_hexdump((char *)spkt->data, stderr, + "colo-compare spkt", spkt->size); + } colo_compare_inconsistency_notify(s); } From patchwork Sun Apr 26 21:19:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11511009 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 7B578112C for ; Sun, 26 Apr 2020 21:40:00 +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 48B7C2070A for ; Sun, 26 Apr 2020 21:40:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="as2t8rGx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48B7C2070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSp0H-0005D3-5c for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 17:39:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33836) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSogH-0004Hn-DR for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSogG-0006Ol-Jz for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:17 -0400 Received: from mout.web.de ([212.227.15.3]:34949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jSogF-0006Jt-Vq for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587935944; bh=v2Q48Pm+/yCuuYhe8oHV9FjEBrga9YLYBk3qMRI8HgU=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=as2t8rGxoJwg7aJU+ubbiN1761Gd4peU+KAAYHVrdGgefEL+HsJ8dAnyD/4OnK4dk ZUxytoElnZDLiwKbFV7dG3lNLzg3tkBxW7trSmXSYnzqzLWIFT0pDY2CkZsTZ00/Mc v/Kopz/Rf+HxlxS1zgpq4eEV03UVELnmAjMb05YY= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([94.134.180.69]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LkPRz-1ivwhP00lf-00cSqY; Sun, 26 Apr 2020 23:19:04 +0200 Date: Sun, 26 Apr 2020 23:19:02 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v3 5/6] net/colo-compare.c, softmmu/vl.c: Check that colo-compare is active Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:llL/+uvtLCZWp63V8/ykZa9fER6BWDPZOT0FhR+pxpKFWOPVh2w crQKxDAQX5mZKh81dZsEXArBorBcf1L5py1ksOS44WHAEsGarYwKrMBz+7pWbmVKaXKvKwM AzfJgZZ7vU8pb4IMbPuD7UOjDxDngPHLtK4nXlJwnDVRcFZ06saLumROXfjDkQ/hdzlmRD3 AAqGS4xnhL2GQbu3gKbQQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:AtAt9V8m+EQ=:nXmvzuByTsGwcmghQuGjMh ash9UnW/jxVbALYFieXPXSc44y87D+rNaeRwkV0IHl9cqWxmu9+21SvZKtKPyY8LKtralwcCN QWh6o6XwW9UXjb3waPvEjHXty38w1gbWCY68Xr5blq4iK+sH54mRwiXwR3tbjKKnYykKgfPYR dpcrExhpya5f64LLpudw2032j50s9HOVQW1YvXTX7ai9WabK7cJKa08zNnL/3cnidenT8//7z wtA1/khr1JRegaPl32IBSZ/SVthNnLev8opeSBxXwlFpxIVeOmsLXybhD1/rEkldwyBbWn/b/ nYAFbij28BpytRF7kg6S3Uny8XTqrN/vo1lZ5eNlqxtZx4h3HYwNewMCCvoqKX1fT9qnAwQo4 gC2GW7zP3NQYfDwmMJLBjkf2jFzglQQFz+o0ipDvK8AOSKRzBLwGm2+qWlvYN+u1pOs0AjEYR p3RAZNbPwK3xJpgyfAyEnY/KRZ7HtEhv1wG5vlxQMhUU+rPNXBRQK111pR3PBAHlsYFwipKEf EQQvEDIwoXhG2OPM9ppmKYewzwc/tCKrDx11w1Mlf4uHpObFC/WzzHWZeJFj+iqzuckbiRBQh nIYO+sU1z3usdntRTwDGqcyJcTUVF5+OArT0dXUGFrwINBxEQIkA70bgHjgYeoPzcHVC+vaiW BuVEVQIrs/LIV3TGa5HxDzkbgW6hgtE8LshQgYw0XpSWjc81vjDs6YvHbvXfPHyzUVUVVNjFc aNuZSGU1R5zSlTvnTKT5AT2Oge6Ld+8kAWDHVWiuBDbuwJv9SNQlx2DIPalxV5/PTMegHam/f 81uyS++/eNSEnbrtHR4ZhPumMN61l+YLGmTgfXFs0ITcBdIh3A6zs+UXiQQBTUqQsbWfFHX4X X0x2DPQiyEHnwnNJKaxNNLGcZI6A13tZXjr+tyrJ+Ner75P0WqF+kp3jWOACr6I914EZbnDbc KaajQFtjwKML5sRtahPny1lhnPpbj8Oioou5oyWV14lJoQ3MuPhVozNcRc1/nmp3JZUr6GLLD 4Wc36M7wJCQ+eSZZj4GRh+AlIcapsebTaD2Q0PtQnCoAO9JQRxz8QUOtXg4BuFTiiMsQ+v5am P4VZxHX8Uh7z/GwZTtftG5uFRujaDGelfJ9j+StZcbDig9g52GrPEJfSUlLLx7NXXcFyRuGc8 NYMWJ9nHeRFmZeQBO5Y1nnfSKc91uZBMeS5TatejV4MXhNdZ0j2Ee2vl/G5d/dXZyYM4u3T2T oGJuqjl7YZZoIdCNQ Received-SPF: pass client-ip=212.227.15.3; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 15:25:46 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Received-From: 212.227.15.3 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 , Jason Wang , Paolo Bonzini , Li Zhijian , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" If the colo-compare object is removed before failover and a checkpoint happens, qemu crashes because it tries to lock the destroyed event_mtx in colo_notify_compares_event. Fix this by checking if everything is initialized by introducing a new variable colo_compare_active which is protected by a new mutex colo_compare_mutex. The new mutex also protects against concurrent access of the net_compares list and makes sure that colo_notify_compares_event isn't active while we destroy event_mtx and event_complete_cond. With this it also is again possible to use colo without colo-compare (periodic mode) and to use multiple colo-compare for multiple network interfaces. Signed-off-by: Lukas Straub --- net/colo-compare.c | 35 +++++++++++++++++++++++++++++------ net/colo-compare.h | 1 + softmmu/vl.c | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 6634911770..f3074ee3ff 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -54,6 +54,8 @@ static NotifierList colo_compare_notifiers = #define REGULAR_PACKET_CHECK_MS 3000 #define DEFAULT_TIME_OUT_MS 3000 +static QemuMutex colo_compare_mutex; +static bool colo_compare_active; static QemuMutex event_mtx; static QemuCond event_complete_cond; static int event_unhandled_count; @@ -912,6 +914,12 @@ static void check_old_packet_regular(void *opaque) void colo_notify_compares_event(void *opaque, int event, Error **errp) { CompareState *s; + qemu_mutex_lock(&colo_compare_mutex); + + if (!colo_compare_active) { + qemu_mutex_unlock(&colo_compare_mutex); + return; + } qemu_mutex_lock(&event_mtx); QTAILQ_FOREACH(s, &net_compares, next) { @@ -925,6 +933,7 @@ void colo_notify_compares_event(void *opaque, int event, Error **errp) } qemu_mutex_unlock(&event_mtx); + qemu_mutex_unlock(&colo_compare_mutex); } static void colo_compare_timer_init(CompareState *s) @@ -1278,16 +1287,20 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) s->vnet_hdr); } + qemu_mutex_lock(&colo_compare_mutex); + if (!colo_compare_active) { + qemu_mutex_init(&event_mtx); + qemu_cond_init(&event_complete_cond); + colo_compare_active = true; + } QTAILQ_INSERT_TAIL(&net_compares, s, next); + qemu_mutex_unlock(&colo_compare_mutex); s->sendco.done = true; g_queue_init(&s->sendco.send_list); g_queue_init(&s->conn_list); - qemu_mutex_init(&event_mtx); - qemu_cond_init(&event_complete_cond); - s->connection_track_table = g_hash_table_new_full(connection_key_hash, connection_key_equal, g_free, @@ -1382,12 +1395,19 @@ static void colo_compare_finalize(Object *obj) qemu_bh_delete(s->event_bh); + qemu_mutex_lock(&colo_compare_mutex); QTAILQ_FOREACH(tmp, &net_compares, next) { if (tmp == s) { QTAILQ_REMOVE(&net_compares, s, next); break; } } + if (QTAILQ_EMPTY(&net_compares)) { + colo_compare_active = false; + qemu_mutex_destroy(&event_mtx); + qemu_cond_destroy(&event_complete_cond); + } + qemu_mutex_unlock(&colo_compare_mutex); /* Release all unhandled packets after compare thead exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s); @@ -1403,15 +1423,18 @@ static void colo_compare_finalize(Object *obj) object_unref(OBJECT(s->iothread)); } - qemu_mutex_destroy(&event_mtx); - qemu_cond_destroy(&event_complete_cond); - g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev); g_free(s->notify_dev); } +void colo_compare_init_globals(void) +{ + colo_compare_active = false; + qemu_mutex_init(&colo_compare_mutex); +} + static const TypeInfo colo_compare_info = { .name = TYPE_COLO_COMPARE, .parent = TYPE_OBJECT, diff --git a/net/colo-compare.h b/net/colo-compare.h index 22ddd512e2..eb483ac586 100644 --- a/net/colo-compare.h +++ b/net/colo-compare.h @@ -17,6 +17,7 @@ #ifndef QEMU_COLO_COMPARE_H #define QEMU_COLO_COMPARE_H +void colo_compare_init_globals(void); void colo_notify_compares_event(void *opaque, int event, Error **errp); void colo_compare_register_notifier(Notifier *notify); void colo_compare_unregister_notifier(Notifier *notify); diff --git a/softmmu/vl.c b/softmmu/vl.c index 32c0047889..a913ed5469 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -112,6 +112,7 @@ #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" #include "qemu/guest-random.h" +#include "net/colo-compare.h" #define MAX_VIRTIO_CONSOLES 1 @@ -2906,6 +2907,7 @@ void qemu_init(int argc, char **argv, char **envp) precopy_infrastructure_init(); postcopy_infrastructure_init(); monitor_init_globals(); + colo_compare_init_globals(); if (qcrypto_init(&err) < 0) { error_reportf_err(err, "cannot initialize crypto: "); From patchwork Sun Apr 26 21:19:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11511039 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 E9FBD92A for ; Sun, 26 Apr 2020 21:53:09 +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 62CBC20700 for ; Sun, 26 Apr 2020 21:53:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="K7gTE+N0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62CBC20700 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSpD2-00025w-3p for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 17:53:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33880) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSogY-0004OC-78 for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSogI-0006Tj-Rb for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:34 -0400 Received: from mout.web.de ([212.227.17.11]:49365) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSogI-0006R1-9k for qemu-devel@nongnu.org; Sun, 26 Apr 2020 17:19:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587935947; bh=OKrJYPQYFYSKUAa7NoCdFf6KnsK6PjCuDGPnWMhKDbI=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=K7gTE+N0eYE/937499J09aZUvMxMfdMVgR7+HGSHNAY7xYR8LGXJ2tuxF5y1f0IfI ao5BF4SVDwje+tccA+uCAXWHkRR7vipnFIMAbBbm0xVbriePPzNQzY/ZE1nkCdlPWD VYrf50KQyzFUjPyoYL7Xh4Q1b4cbwuIBLTJg7aNs= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([94.134.180.69]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MWjAd-1jiMOu151n-00Xp7P; Sun, 26 Apr 2020 23:19:07 +0200 Date: Sun, 26 Apr 2020 23:19:06 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v3 6/6] net/colo-compare.c: Correct ordering in complete and finalize Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:e97cc28SczBHZR8grl3MOyvXZzNnq2oWlTt0IbCvnTy8wj5F3ib p/83W/QzgWr14jkbMe42CIo4uidz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QerXeuhZx A6HHkyydstK+ByhZJwBfAb/iEYHHY7FI7r9NoWpKIAFWOLQkTJu9GZqEqBm8UihaNRTT6iSEj lBQMrVEPA7st/fWCpuCYz/RvrdDd+RC7dvSTbtif1c7wKcLZRU27ZtN5ATKPbaCdlb6zYyFVP A0/nzEVxo87ToeppxgdpNE0fJ8Q4mLDUll696HDL0bEF12MjRH4Aup6zw00VdVa5o1Jw6GH5Q fZdDqdRq6rNka1kVsbNmCg2Lkm65TGS0MoCJbTSp6Yab3F23IhLSGHF86lrCSNl8auGxMSqkf aIvStvoqQmcLFVL756eIF8P0DbjUE5aqcZUDuNmBrIz72c0TrBRgj7TpKRtU292e3qCYMZ7GD V+0ZC6TJBkV+L8zNX Received-SPF: pass client-ip=212.227.17.11; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 17:18:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.11 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 , Jason Wang , Paolo Bonzini , Li Zhijian , =?utf-8?q?Marc-Andr=C3=A9?= Lureau Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" In colo_compare_complete, insert CompareState into net_compares only after everything has been initialized. In colo_compare_finalize, remove CompareState from net_compares before anything is deinitialized. Signed-off-by: Lukas Straub --- net/colo-compare.c | 47 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index f3074ee3ff..e86dd72f02 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -1287,15 +1287,6 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) s->vnet_hdr); } - qemu_mutex_lock(&colo_compare_mutex); - if (!colo_compare_active) { - qemu_mutex_init(&event_mtx); - qemu_cond_init(&event_complete_cond); - colo_compare_active = true; - } - QTAILQ_INSERT_TAIL(&net_compares, s, next); - qemu_mutex_unlock(&colo_compare_mutex); - s->sendco.done = true; g_queue_init(&s->sendco.send_list); @@ -1307,6 +1298,16 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) connection_destroy); colo_compare_iothread(s); + + qemu_mutex_lock(&colo_compare_mutex); + if (!colo_compare_active) { + qemu_mutex_init(&event_mtx); + qemu_cond_init(&event_complete_cond); + colo_compare_active = true; + } + QTAILQ_INSERT_TAIL(&net_compares, s, next); + qemu_mutex_unlock(&colo_compare_mutex); + return; } @@ -1377,6 +1378,20 @@ static void colo_compare_finalize(Object *obj) CompareState *s = COLO_COMPARE(obj); CompareState *tmp = NULL; + qemu_mutex_lock(&colo_compare_mutex); + QTAILQ_FOREACH(tmp, &net_compares, next) { + if (tmp == s) { + QTAILQ_REMOVE(&net_compares, s, next); + break; + } + } + if (QTAILQ_EMPTY(&net_compares)) { + colo_compare_active = false; + qemu_mutex_destroy(&event_mtx); + qemu_cond_destroy(&event_complete_cond); + } + qemu_mutex_unlock(&colo_compare_mutex); + AioContext *ctx = iothread_get_aio_context(s->iothread); aio_context_acquire(ctx); AIO_WAIT_WHILE(ctx, !s->sendco.done); @@ -1395,20 +1410,6 @@ static void colo_compare_finalize(Object *obj) qemu_bh_delete(s->event_bh); - qemu_mutex_lock(&colo_compare_mutex); - QTAILQ_FOREACH(tmp, &net_compares, next) { - if (tmp == s) { - QTAILQ_REMOVE(&net_compares, s, next); - break; - } - } - if (QTAILQ_EMPTY(&net_compares)) { - colo_compare_active = false; - qemu_mutex_destroy(&event_mtx); - qemu_cond_destroy(&event_complete_cond); - } - qemu_mutex_unlock(&colo_compare_mutex); - /* Release all unhandled packets after compare thead exited */ g_queue_foreach(&s->conn_list, colo_flush_packets, s);