From nobody Tue Sep 9 03:17:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1746541058; cv=none; d=zohomail.com; s=zohoarc; b=fnHNRVzIPo4sbHV0MK4bIY18eoHdSueD/4wn4alQPj1n4uBqnLKvyJYk5jMge2fxMaj3YoAvhtsYsYa59GpfDKE+7SFjpl8GW5sLPLu1udwyz8zl7Hw5uyyF2GhuKFze3scXhDkDmwWCkGYaEltQWqHpaRegNmTeXEcbxpFogBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1746541058; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id; bh=2YeYEzjeFlJjSSlE7lxLZx2Vq0NrSjJRlwBFYfwgBFQ=; b=TKpPsmM0E6E9vJymGdAbt8HmddNLOoxotscRyVQBH11ALrWNWLxhzM2ePY8xtxGGOvICcY++KCexdiQDfZIFTEpQJX2dQU3blkFhHt6vengTtjy+Q+TsYQ8E285yLMPOMAtasnHiA+y3hTw4kI2tgUokkPLbpi0YrJ0GFOXqHys= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1746541058391676.705732030534; Tue, 6 May 2025 07:17:38 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6C9CB1464; Tue, 6 May 2025 10:17:37 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EB0151424; Tue, 6 May 2025 10:17:16 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C510713C9; Tue, 6 May 2025 10:17:11 -0400 (EDT) Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7A67A13B6 for ; Tue, 6 May 2025 10:17:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-Greylist: delayed 484 seconds by postgrey-1.37 at lists.libvirt.org; Tue, 06 May 2025 10:17:10 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1746540541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5A24Tp2gvKv+W/lz40y0ILZ3EafGhtq4telpJoAUD0c=; b=UPo0GO7SmsOG7VnDSi/4LagnWH08aEInzgdfrxD+F8PMfp95hi5qhcOlfrdE7YPUF22Vf2 Vax+9B64go1HMtL5NQGSoezxcWltvaaxLqN7yaGLLrLtrPihIs/pABYlNYMEjfV6Xiuzw0 exol6qhKXZWCShclsGfka+ddiWQtQNY= To: devel@lists.libvirt.org Subject: [PATCH] qemu: fix qemuMigrationCapability enum Date: Tue, 6 May 2025 17:08:18 +0300 Message-Id: <20250506140817.888543-1-frolov@swemel.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AOKDXKZ2CNISBRB6JIETC4BDRXMEG4N7 X-Message-ID-Hash: AOKDXKZ2CNISBRB6JIETC4BDRXMEG4N7 X-MailFrom: frolov@swemel.ru X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: sdl.libvirt@linuxtesting.org, Dmitry Frolov X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Dmitry Frolov via Devel Reply-To: Dmitry Frolov X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1746541059392116600 Content-Type: text/plain; charset="utf-8" Enum variable of type qemuMigrationCapability is checked for zero in src/qemu/qemu_migration_params.c:729. "if (item->optional) { ..." Actualy, QEMU_MIGRATION_CAP_XBZRLE enum constant has value 0. Thus, all uninitialized .optinnal fields of the static array qemuMigrationParamsFlagMap[] will be implicitly initialized with value 0 (QEMU_MIGRATION_CAP_XBZRLE). To my opinion, introducing a separate enum for optional capabilities, would be a better solution. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Dmitry Frolov --- src/qemu/qemu_migration_params.c | 16 +++++++++++----- src/qemu/qemu_migration_params.h | 12 ++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index c10660d6f2..23c463dbbb 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -104,6 +104,11 @@ VIR_ENUM_IMPL(qemuMigrationCapability, "dirty-bitmaps", "return-path", "zero-copy-send", +); + +VIR_ENUM_IMPL(qemuMigrationOptCap, + QEMU_MIGRATION_OPTCAP_LAST, + "none", "postcopy-preempt", "switchover-ack", ); @@ -152,7 +157,7 @@ struct _qemuMigrationParamsFlagMapItem { /* An optional capability to set in addition to @cap in case it is * supported. Depending on @part either one or both sides of migration * has to support the optional capability to be enabled. */ - qemuMigrationCapability optional; + qemuMigrationOptCap optional; /* Bit-wise OR of qemuMigrationParty. Determines whether the capabilit= y has * to be enabled on the source, on the destination, or on both sides of * migration. */ @@ -200,7 +205,7 @@ static const qemuMigrationParamsFlagMapItem qemuMigrati= onParamsFlagMap[] =3D { {.match =3D QEMU_MIGRATION_FLAG_REQUIRED, .flag =3D VIR_MIGRATE_POSTCOPY, .cap =3D QEMU_MIGRATION_CAP_POSTCOPY, - .optional =3D QEMU_MIGRATION_CAP_POSTCOPY_PREEMPT, + .optional =3D QEMU_MIGRATION_OPTCAP_POSTCOPY_PREEMPT, .party =3D QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION}, =20 {.match =3D QEMU_MIGRATION_FLAG_REQUIRED, @@ -211,7 +216,7 @@ static const qemuMigrationParamsFlagMapItem qemuMigrati= onParamsFlagMap[] =3D { {.match =3D QEMU_MIGRATION_FLAG_FORBIDDEN, .flag =3D VIR_MIGRATE_TUNNELLED, .cap =3D QEMU_MIGRATION_CAP_RETURN_PATH, - .optional =3D QEMU_MIGRATION_CAP_SWITCHOVER_ACK, + .optional =3D QEMU_MIGRATION_OPTCAP_SWITCHOVER_ACK, .party =3D QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION}, =20 {.match =3D QEMU_MIGRATION_FLAG_REQUIRED, @@ -725,8 +730,9 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr param= s, qemuMigrationCapabilityTypeToString(item->cap)); ignore_value(virBitmapSetBit(migParams->caps, item->cap)); =20 - if (item->optional) { - qemuMigrationCapability opt =3D item->optional; + if (item->optional > QEMU_MIGRATION_OPTCAP_NONE && + item->optional < QEMU_MIGRATION_OPTCAP_LAST) { + qemuMigrationOptCap opt =3D item->optional; ignore_value(virBitmapSetBit(migParams->optional, opt)); if (item->party !=3D party) ignore_value(virBitmapSetBit(migParams->remoteOptional= , opt)); diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_par= ams.h index 17fc63f527..3246b8487e 100644 --- a/src/qemu/qemu_migration_params.h +++ b/src/qemu/qemu_migration_params.h @@ -40,13 +40,21 @@ typedef enum { QEMU_MIGRATION_CAP_BLOCK_DIRTY_BITMAPS, QEMU_MIGRATION_CAP_RETURN_PATH, QEMU_MIGRATION_CAP_ZERO_COPY_SEND, - QEMU_MIGRATION_CAP_POSTCOPY_PREEMPT, - QEMU_MIGRATION_CAP_SWITCHOVER_ACK, =20 QEMU_MIGRATION_CAP_LAST } qemuMigrationCapability; VIR_ENUM_DECL(qemuMigrationCapability); =20 +typedef enum { + QEMU_MIGRATION_OPTCAP_NONE, + QEMU_MIGRATION_OPTCAP_POSTCOPY_PREEMPT, + QEMU_MIGRATION_OPTCAP_SWITCHOVER_ACK, + + QEMU_MIGRATION_OPTCAP_LAST +} qemuMigrationOptCap; +VIR_ENUM_DECL(qemuMigrationOptCap); + + typedef enum { QEMU_MIGRATION_PARAM_COMPRESS_LEVEL, QEMU_MIGRATION_PARAM_COMPRESS_THREADS, --=20 2.34.1