From patchwork Sun Apr 26 19:25:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11510975 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 ECF7C92A for ; Sun, 26 Apr 2020 19:34:02 +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 C36EA20700 for ; Sun, 26 Apr 2020 19:34:02 +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="cGSJkMsF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C36EA20700 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]:43704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSn2N-0005PM-7v for patchwork-qemu-devel@patchwork.kernel.org; Sun, 26 Apr 2020 15:34:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47732) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSmum-0001Fo-2G for qemu-devel@nongnu.org; Sun, 26 Apr 2020 15:26:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSmul-0005ys-Gl for qemu-devel@nongnu.org; Sun, 26 Apr 2020 15:26:07 -0400 Received: from mout.web.de ([212.227.17.12]:40077) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jSmuk-0005yb-VS for qemu-devel@nongnu.org; Sun, 26 Apr 2020 15:26:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1587929155; bh=B9XY0V6HG/toYTYIEUFnzTvAwLVvOsgRzhHhxFxq1Xk=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=cGSJkMsFmBDBtdDVqFRt09CcjauLL/Ew0xJl1i9Qi3TVKQNgH/E7ShYSIhW/qUaij VZZXPHREWD3vvxKSJk1VX/jCqBsGFqnysfiz+K171wLwAAMB2Xp0tcqy4icw6DGaak UbenyxpO5zw3ewUtNFVnf7tIcUmFaYHfDS3pwh3E= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([89.247.255.95]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LyDph-1j5CGU14C5-015bYx; Sun, 26 Apr 2020 21:25:55 +0200 Date: Sun, 26 Apr 2020 21:25:54 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v2 5/6] net/colo-compare.c, softmmu/vl.c: Check that colo-compare is active Message-ID: <9cfb9136badd63804dab1331658803cf70d0cc3d.1587927878.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:gTmJjSM3VizveceaIutLKB2t+8lYiqnFCFpGJpxZznR5WCtttvJ AFwabXg/wIsmkDIa4IIg6T15As+NhlAZx1wWMtCXHFn04PhL2SZLe1fJfUID/3GubncPCLJ FfSkq0G9bA54hnR4/Ytuj7/sLc/ZwPugHsTNTbRfTneAxIqtbYFtRBEbVKscQJ3MaUxNDv+ PhBFlxVDpnJ79S5zJJydw== X-UI-Out-Filterresults: notjunk:1;V03:K0:MAonEhhG66E=:LgLEuOyOngMPhKtIwkbRTR SxN6fLCrzJkFj9RaEJ1ySBDFQViFW08BQhRaDjU4Y6QnH10AuO6m/Me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TnIO3xjyNXVaM4UzEYmFSK6PYe06WNDBBzU/U g5AjCK6XJuzZvaqwoJA445RKLuDGcsoKtDDaFA0Y/3EeJZHILN7y0hBeoyTr9AoW50l1gMkjY 2yc1vIHDNMKdwK6HE Received-SPF: pass client-ip=212.227.17.12; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 15:26:05 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.12 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 | 34 ++++++++++++++++++++++++++++------ net/colo-compare.h | 1 + softmmu/vl.c | 2 ++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 6634911770..a82bb27a67 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 = false; 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,17 @@ 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) +{ + 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: ");