From nobody Sun Feb 8 22:50:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592393586; cv=none; d=zohomail.com; s=zohoarc; b=DD9oo32/oXr4qeYKm6zMPqQWwx/vadh0NbGxl9ZbjlqSFhyusFnb1DzYZk1NsUVmse/xC+kl9t20z4PJzXu7yQMuao3ezADpiWMRgNQj2xaEJxZZgovddRz2JqL97Lz+eu6SsP8VvQbEq3ki0pHn4BTYvDrRVag9k3gso4+zc+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592393586; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=mW5lgnVH430AFxF+uNuE8NXPJ763+5rhCUne925yUkU=; b=btREnMT5WNdun9H2V5+gCRaBrEg8dC1B6jCcJ9MZrtcAuxIIBqSmotMIkIK9PivVg9FfNTGYpMTAwgpaQD0cYjCnT8yYaFHPERqZL31o8yjBCM9Lk3pS5iVsMOPxW8NeAhG+Y5chIX5LUUkd1Vlbr7U9KJXdm5OXGdJZbQILD3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592393586142114.56375462816243; Wed, 17 Jun 2020 04:33:06 -0700 (PDT) Received: from localhost ([::1]:37344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jlWJU-0003MU-Uo for importer@patchew.org; Wed, 17 Jun 2020 07:33:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlWIY-0002Y4-Uf for qemu-devel@nongnu.org; Wed, 17 Jun 2020 07:32:06 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:46610 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jlWIV-0001ID-12 for qemu-devel@nongnu.org; Wed, 17 Jun 2020 07:32:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-wVA8V_7KPICWRC84qqM6yA-1; Wed, 17 Jun 2020 07:31:58 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42A1810AB64B for ; Wed, 17 Jun 2020 11:31:57 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-71.ams2.redhat.com [10.36.112.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4296660BF4; Wed, 17 Jun 2020 11:31:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592393519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mW5lgnVH430AFxF+uNuE8NXPJ763+5rhCUne925yUkU=; b=dUD/bFn/dZjMrQp+79XYOWzXB6LxS0HzRKakrVRATi2KITD2y4GrVeL1v2sxG9qw+u+v5Q Y/3NWLWhScoiQCwYg1FWrXNBYfoIkrpnjpUg1KQSkq3oJ44TZjM/4MaAooXXkXYwdYngaH WZ2YmJhuAnN/QXHu9rkA4eyftiYQfyM= X-MC-Unique: wVA8V_7KPICWRC84qqM6yA-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH] migration: fix multifd_send_pages() next channel Date: Wed, 17 Jun 2020 13:31:54 +0200 Message-Id: <20200617113154.593233-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/17 01:42:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" multifd_send_pages() loops around the available channels, the next channel to use between two calls to multifd_send_pages() is stored inside a local static variable, next_channel. It works well, except if the number of channels decreases between two calls to multifd_send_pages(). In this case, the loop can try to access the data of a channel that doesn't exist anymore. The problem can be triggered if we start a migration with a given number of channels and then we cancel the migration to restart it with a lower number. This ends generally with an error like: qemu-system-ppc64: .../util/qemu-thread-posix.c:77: qemu_mutex_lock_impl: A= ssertion `mutex->initialized' failed. This patch fixes the error by capping next_channel with the current number of channels before using it. Signed-off-by: Laurent Vivier Reviewed-by: Juan Quintela --- migration/multifd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/migration/multifd.c b/migration/multifd.c index 5a3e4d0d46d1..d0441202aae9 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -415,6 +415,12 @@ static int multifd_send_pages(QEMUFile *f) } =20 qemu_sem_wait(&multifd_send_state->channels_ready); + /* + * next_channel can remain from a previous migration that was + * using more channels, so ensure it doesn't overflow if the + * limit is lower now. + */ + next_channel %=3D migrate_multifd_channels(); for (i =3D next_channel;; i =3D (i + 1) % migrate_multifd_channels()) { p =3D &multifd_send_state->params[i]; =20 --=20 2.26.2