From nobody Wed Nov 5 07:52:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533288180040790.8455035202096; Fri, 3 Aug 2018 02:23:00 -0700 (PDT) Received: from localhost ([::1]:49786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flWIM-0008QP-Mm for importer@patchew.org; Fri, 03 Aug 2018 05:22:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flW9t-0001Op-L9 for qemu-devel@nongnu.org; Fri, 03 Aug 2018 05:14:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flW9s-0001Jg-HN for qemu-devel@nongnu.org; Fri, 03 Aug 2018 05:14:05 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:41479) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1flW9s-0001Ih-AR for qemu-devel@nongnu.org; Fri, 03 Aug 2018 05:14:04 -0400 Received: by mail-pg1-x544.google.com with SMTP id z8-v6so2562220pgu.8 for ; Fri, 03 Aug 2018 02:14:04 -0700 (PDT) Received: from VM_120_46_centos.localdomain ([119.28.87.64]) by smtp.gmail.com with ESMTPSA id e21-v6sm7991352pfl.187.2018.08.03.02.14.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 02:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RWIMgk03BRlmqbTHDnYPfsRwdbqRWy3x1CB6C7/BT8U=; b=G1kEGg4U8pxR/FODrvmwCGKxtALOW8R6RAjXi0IjCrr2Kn8k30tQDh1TBbOLEkCjyN PItYE0I+/9eisNtf7Qlthm6RZhJhu2SZehqwlMXepJ1QucLlzbmyoPt0iV9eUZgbZLPI B1aEYQL6DUHRYhhG5wfL8/J+fJdF6utMhtW2awgDbg0zjg3WMEOJZEeDaK/hmADbrwjO fAP4ueNtYTsu7hL6/4Adzqlth33HOf4Ek5cWXadnyfVC/+dTGJGjYia+PMUy1KhT4vou c8U0TEbwzDaMbzNRASnDRDGxbZOL3noziAwOGCFEghpUFhTvzZVM8Vjc+rU6lpfu+Lfe cZiQ== 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:mime-version:content-transfer-encoding; bh=RWIMgk03BRlmqbTHDnYPfsRwdbqRWy3x1CB6C7/BT8U=; b=dIJ0/IdIHmJ0rFY7Z3l9QT7InH/svLtgxfxLh1AtqgWfB+gIpTqAaUnU+MTx65skV2 9oWn2BckVWrT5Ge9/Txr5hUgb1WL1OIU+8NHnDIAyq2qCrnYm76pEMCI/5k7Uy6qJAm7 zVKDBKOs1z8Sj5NVwH6zfn5c+nnyPibMSrPkUHdng2UqI2hWKvU5fyJ9mHTQBbFQg65T p9vTom7dNfgd5mHu6gxZosXi9r2vM+l92lwow2AELMA2KdlkUnNzvEXY6I2VR/buiKhZ oePoCb5jOOMIlHnmobLpBLeKwE/brNJjUwGgm9jn8t5NswQIPceqOphEiKWpNxKxMnyS DmtA== X-Gm-Message-State: AOUpUlEQzb615Du3SOAZVGseA4nSaV+OasEBd+YulCQHNvUvIxn0x3F+ Ghcha3bPnf3tjrEycK+7R5I= X-Google-Smtp-Source: AAOMgpcCjbqsZg7MIqZ0sAB7gIZoQkVYucj1p3oF3G3kesf8t1w4/QBH0x1/huqy+85XrlTH/C94GA== X-Received: by 2002:a65:5004:: with SMTP id f4-v6mr2902535pgo.54.1533287643507; Fri, 03 Aug 2018 02:14:03 -0700 (PDT) From: Lidong Chen X-Google-Original-From: Lidong Chen To: zhang.zhanghailiang@huawei.com, quintela@redhat.com, dgilbert@redhat.com Date: Fri, 3 Aug 2018 17:13:41 +0800 Message-Id: <1533287630-4221-4-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1533287630-4221-1-git-send-email-lidongchen@tencent.com> References: <1533287630-4221-1-git-send-email-lidongchen@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH v6 03/12] migration: avoid concurrent invoke channel_close by different threads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lidong Chen , qemu-devel@nongnu.org, Lidong Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 From: Lidong Chen The channel_close maybe invoked by different threads. For example, source qemu invokes qemu_fclose in main thread, migration thread and return path thread. Destination qemu invokes qemu_fclose in main thread, listen thread and COLO incoming thread. Signed-off-by: Lidong Chen Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/migration.c | 2 ++ migration/migration.h | 7 +++++++ migration/qemu-file.c | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b7d9854..a3a0756 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3200,6 +3200,7 @@ static void migration_instance_finalize(Object *obj) qemu_sem_destroy(&ms->postcopy_pause_sem); qemu_sem_destroy(&ms->postcopy_pause_rp_sem); qemu_sem_destroy(&ms->rp_state.rp_sem); + qemu_mutex_destroy(&ms->qemu_file_close_lock); error_free(ms->error); } =20 @@ -3236,6 +3237,7 @@ static void migration_instance_init(Object *obj) qemu_sem_init(&ms->rp_state.rp_sem, 0); qemu_sem_init(&ms->rate_limit_sem, 0); qemu_mutex_init(&ms->qemu_file_lock); + qemu_mutex_init(&ms->qemu_file_close_lock); } =20 /* diff --git a/migration/migration.h b/migration/migration.h index 64a7b33..a50c2de 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -122,6 +122,13 @@ struct MigrationState QemuMutex qemu_file_lock; =20 /* + * The to_src_file and from_dst_file point to one QIOChannelRDMA, + * And qemu_fclose maybe invoked by different threads. use this lock + * to avoid concurrent invoke channel_close by different threads. + */ + QemuMutex qemu_file_close_lock; + + /* * Used to allow urgent requests to override rate limiting. */ QemuSemaphore rate_limit_sem; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 977b9ae..74c48e0 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -323,12 +323,14 @@ void qemu_update_position(QEMUFile *f, size_t size) */ int qemu_fclose(QEMUFile *f) { - int ret; + int ret, ret2; qemu_fflush(f); ret =3D qemu_file_get_error(f); =20 if (f->ops->close) { - int ret2 =3D f->ops->close(f->opaque); + qemu_mutex_lock(&migrate_get_current()->qemu_file_close_lock); + ret2 =3D f->ops->close(f->opaque); + qemu_mutex_unlock(&migrate_get_current()->qemu_file_close_lock); if (ret >=3D 0) { ret =3D ret2; } --=20 1.8.3.1