From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102169; cv=none; d=zohomail.com; s=zohoarc; b=P38fr2ldhxgCptOONEj3p1GzjWKidrMqeZkQRhV4AJGx+bnyGfNrj0keLY7hrfXIEIWKyA1YfAWvGCB6AUNaSWZyXkaCUnybZ7o051jfRm3NUVy/zjxh7vm/1dqzSbr3LRaZ1jMVDCJ6/wkjqSSo2ZLj9kEXxVnvzcQDCrFB+2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102169; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tYd/FuZSv5qtUD4kEa/eP6UgqMgevIiY56njdGnB7yo=; b=Sf5vMz4YQlu219rMMLznpIFB2gxpUoQmfZ6vxAKHVgycNkigWeCqeYxjMiVyaqQ3BwB3E+RLueEoVuL8GMGO0/EALjA5a5Mne6sI66NoeHYilDbR4WTfX1O3Sud9gqT1MRDhdA92bFxHYBD3XMBP7qfYbTfNungV7z+AEVgSIsE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102169890820.2408408087582; Mon, 18 May 2026 04:02:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOvj1-0006au-QG; Mon, 18 May 2026 07:01:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviw-0006YP-QL for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOvit-0005hR-4P for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X38-omx_1779102073 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:14 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102075; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=tYd/FuZSv5qtUD4kEa/eP6UgqMgevIiY56njdGnB7yo=; b=nf9C0YFArSlbYaI+dVZCOqA6jJm0XRWGuOT3ZdEkfe1EGmlDv1R6EK9SaqWBKG6crEf+Ql2P159p/mXjzNxZ+ItNhEBiHm7EDR2e/Et4priMUS9aA6OHx/Tq+UCmJxfpk92S9IJ52xNhKCK1f+AmEqm29HliRbFO2FF1iF3RY8E= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R131e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033045133197; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X38-omx_1779102073; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 1/8] migration/fd: collapse migration_fd_valid into single boolean expression Date: Mon, 18 May 2026 19:01:05 +0800 Message-ID: <20260518110112.21395-2-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.131; envelope-from=guobin@linux.alibaba.com; helo=out30-131.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102171004154100 Content-Type: text/plain; charset="utf-8" Two if/return-true blocks followed by a final return false are equivalent to a single OR-expression and easier to scan. Signed-off-by: Bin Guo --- migration/fd.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index f05f95992f..939cdda4e1 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -39,15 +39,7 @@ static bool fd_is_pipe(int fd) =20 static bool migration_fd_valid(int fd) { - if (fd_is_socket(fd)) { - return true; - } - - if (fd_is_pipe(fd)) { - return true; - } - - return false; + return fd_is_socket(fd) || fd_is_pipe(fd); } =20 QIOChannel *fd_connect_outgoing(MigrationState *s, const char *fdname, --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102094; cv=none; d=zohomail.com; s=zohoarc; b=M06UXRP4LEWb4iNhQvI7TK2GfFK31ZCfLYYzrEXcjFuRMv8AGYF7ffl9Cl4YcCWuac0SiSzjrV0Qq12YG3SfBQ+aqzZ++wU+wDbu1Uv8ABg9oU0FCmhDGEWOOlC09JJT1rTBj3ab40IZW7kbgvr+ipnUflx4QPTaoI36JiCSFwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102094; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+hgx9+P/bk9g/hlGdeeb4w+pdmwgio+VTmgH9idLe9M=; b=lhXvSNrSY7jLZbO/B3JKwecRBgzMniVKHBya8y/ChrOfEx1RSJRoZS6Mcd4F+499bI1MGaE/ZSqYCtIdoQHb5ljq0VJzY+WN3jcQuWQEnAYw/bivhuAIpPt4WNqyGSGRYiIVJAUH2LQJFHMFyoZ9p61xoMsB4/MgEm/O3PduebM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102094056855.4381338682974; Mon, 18 May 2026 04:01:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOviw-0006YH-Vw; Mon, 18 May 2026 07:01:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviv-0006Y1-6s for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:25 -0400 Received: from out30-119.freemail.mail.aliyun.com ([115.124.30.119]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOvis-0005ha-MM for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:24 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X38-on4_1779102074 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:15 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102075; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=+hgx9+P/bk9g/hlGdeeb4w+pdmwgio+VTmgH9idLe9M=; b=Pc9ZsKMttFh+iFs3Ubsz/6ATYRBi/8B5NrqDquT1rRiS1LRxdiJmu1MkDXaenmwCFKskWkwPrejR4YHIbMnNTVKM82Ajy/vWgrRT5RTF+4tCjAku+DwAENORJYBV42dKlkBCQDh4NOYq3fjgQ4qX7LurkoKledb7uR+zHXL4+zs= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R121e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam011083073210; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X38-on4_1779102074; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 2/8] migration/global_state: replace strcpy("") with explicit NUL termination Date: Mon, 18 May 2026 19:01:06 +0800 Message-ID: <20260518110112.21395-3-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.119; envelope-from=guobin@linux.alibaba.com; helo=out30-119.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102094987158500 Content-Type: text/plain; charset="utf-8" Drop the unnecessary strcpy of an empty literal (and its spurious (char *)& cast) in favor of a direct NUL store, which avoids the libc call and hides no bugs behind a cast. Signed-off-by: Bin Guo Reviewed-by: Fabiano Rosas --- migration/global_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/global_state.c b/migration/global_state.c index c1f90fce0f..91fefdf525 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -148,7 +148,7 @@ static const VMStateDescription vmstate_globalstate =3D= { void register_global_state(void) { /* We would use it independently that we receive it */ - strcpy((char *)&global_state.runstate, ""); + global_state.runstate[0] =3D '\0'; global_state.received =3D false; vmstate_register(NULL, 0, &vmstate_globalstate, &global_state); } --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102113; cv=none; d=zohomail.com; s=zohoarc; b=hFex4h2ixFFP8dbvbtJneMc6DEs+kS8g9jmyN3nU6PYF/ROd97zA3+0h4uUfHHPqz+wTJfuFNUrd8pbs0BOop38xvXFeafj15HsGB3z8wkFwPyM2jicjpXljGq12bsPf1SvmtSxq/grliMYavH4ABzaw5uTob+3vP2bIXUDSxB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102113; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oli3TV2O+h3vqz3L6ihhLNIlHjx7t0sun6devc9rBO4=; b=RmGp1zcZprolCLKOxM2dK6umEOYT0m3ZpcAwyI72Zoqrw4EWAQET5n4++lC1zbyK15rOTyLE/o9C77Gsd4yHuW56hsfF66LLnzNKDjFGf87YbrqJv7Y680GWiJTJ64mvy8CTYxkRhK8hLNhanRfrZcRVaUcBRCS/HnISSB24T1A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102113222566.4171430238034; Mon, 18 May 2026 04:01:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOvj0-0006ah-L1; Mon, 18 May 2026 07:01:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviw-0006YN-PL for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from out30-119.freemail.mail.aliyun.com ([115.124.30.119]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOvit-0005hy-6x for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X38-onF_1779102075 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:15 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102076; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=oli3TV2O+h3vqz3L6ihhLNIlHjx7t0sun6devc9rBO4=; b=SlROCCkpTXB3cWLe+QK3+vix5MHdCuPJn4bs9kztoLoxPkQOFnEQDdVz4craM+66mxKiT97pHxJPooORf4FWJAOhjnZ2oc0rECCs6k/4Zab5v31XNS9KYHtpF5S424SPD/6a1vgjTOXI22A5RUGbTdbphfviS8WeQtPotyMr3p8= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X38-onF_1779102075; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 3/8] migration/vmstate: avoid per-element heap churn in vmsd ptr marker field Date: Mon, 18 May 2026 19:01:07 +0800 Message-ID: <20260518110112.21395-4-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.119; envelope-from=guobin@linux.alibaba.com; helo=out30-119.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102115303158500 Content-Type: text/plain; charset="utf-8" For every NULL slot in a VMS_ARRAY_OF_POINTER (or every entry of a dynamic array), the saver allocates a 1-element fake VMStateField via g_new0 and frees it again right after the save. For arrays of thousands of entries this is thousands of malloc/free pairs on the hot save path. Replace the heap-allocated marker with a stack-resident field populated by an init helper. The caller passes a pointer to a local VMStateField, the helper fills it in (still asserting the precondition), and no g_free is needed. Signed-off-by: Bin Guo Reviewed-by: Fabiano Rosas --- migration/vmstate.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 2f13b48a37..9ced78532f 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -59,29 +59,23 @@ vmstate_field_exists(const VMStateDescription *vmsd, co= nst VMStateField *field, * array of a VMS_ARRAY_OF_POINTER VMSD field. It's needed because we * can't dereference the NULL pointer. */ -static const VMStateField * -vmsd_create_ptr_marker_field(const VMStateField *field) +static void +vmsd_init_ptr_marker_field(VMStateField *fake, const VMStateField *field) { - VMStateField *fake =3D g_new0(VMStateField, 1); - /* It can only happen on an array of pointers! */ assert(field->flags & VMS_ARRAY_OF_POINTER); =20 - /* Some of fake's properties should match the original's */ - fake->name =3D field->name; - fake->version_id =3D field->version_id; - - /* Do not need "field_exists" check as it always exists */ - fake->field_exists =3D NULL; - - /* See vmstate_info_ptr_marker - use 1 byte to represent ptr status */ - fake->size =3D 1; - fake->info =3D &vmstate_info_ptr_marker; - fake->flags =3D VMS_SINGLE; - - /* All the rest fields shouldn't matter.. */ - - return (const VMStateField *)fake; + /* See vmstate_info_ptr_marker - 1 byte represents ptr status */ + *fake =3D (VMStateField) { + .name =3D field->name, + .version_id =3D field->version_id, + /* Marker always exists, no field_exists callback needed */ + .field_exists =3D NULL, + .size =3D 1, + .info =3D &vmstate_info_ptr_marker, + .flags =3D VMS_SINGLE, + /* All other fields stay zero-initialised */ + }; } =20 static int vmstate_n_elems(void *opaque, const VMStateField *field) @@ -680,6 +674,7 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, for (i =3D 0; i < n_elems; i++) { void *curr_elem =3D first_elem + size * i; const VMStateField *inner_field; + VMStateField marker_field; /* maximum number of elements to compress in the JSON blob= */ int max_elems =3D vmsd_can_compress(field) ? (n_elems - i)= : 1; bool use_marker_field, is_null =3D false; @@ -693,7 +688,8 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMSt= ateDescription *vmsd, use_marker_field =3D use_dynamic_array || is_null; =20 if (use_marker_field) { - inner_field =3D vmsd_create_ptr_marker_field(field); + vmsd_init_ptr_marker_field(&marker_field, field); + inner_field =3D &marker_field; } else { inner_field =3D field; } @@ -730,11 +726,6 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const VMS= tateDescription *vmsd, inner_field, vmdesc_lo= op, i, max_elems, errp); =20 - /* If we used a fake temp field.. free it now */ - if (use_marker_field) { - g_clear_pointer((gpointer *)&inner_field, g_free); - } - if (!ok) { goto out; } --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102158; cv=none; d=zohomail.com; s=zohoarc; b=B3J8Cd6zp8fTBTKKmWqoFPalvvxP3xAuuc1vAqgn1Ak/Kh7nQVI0IQOwklP17Z8hv8sOOuSjfSOwl2tfaU6SYM0hKp3qllhQQa5sFZawXyFgqAM0TWi6jGGNwH5rniVl7daQxas2BD/6YvsjaKohwUKf87I9ozwWrrJ0xaB7tUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102158; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/Hf9bNk5euKjuZd4SN8a7/rLYdpLWK+prrB/RupffPk=; b=UXdR/dWYze+miV/ferDlTv0qIwELE8nVDUoJSQzxSQPrMUyOHXokKTlOMltUg7OzLAcb6/jvaKBvquNS6yWb3eFvWgM2W/URU0lomzYuiMJxx02G4SeV10Bmm93dCW24sWb60HrwegvAtcp1oCrTO4ozGqYcgxYsH/V1tZ9/bEA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102158867271.5262787846033; Mon, 18 May 2026 04:02:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOvj0-0006ad-FK; Mon, 18 May 2026 07:01:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviy-0006Za-1D for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:28 -0400 Received: from out30-111.freemail.mail.aliyun.com ([115.124.30.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviu-0005iO-5E for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:27 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X382z.a_1779102076 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:16 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102078; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=/Hf9bNk5euKjuZd4SN8a7/rLYdpLWK+prrB/RupffPk=; b=uFndEFNu9MfosrdLoTNwjdDueA4IGJ2L2kWcANcZb6WMK730m0nIqqL3AThgc2dTAIGPLy3rvOA950VIB3m2voiKNPwY0bU/6swyhKDK5P6Xd23aMMhM9tQTcxDzllzd+KzKd6E3+zAiflQKSg+YExdHxBV75np61iDL5bRqbjI= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037033178; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X382z.a_1779102076; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 4/8] migration/savevm: use stack-allocated bitmap in configuration_validate_capabilities Date: Mon, 18 May 2026 19:01:08 +0800 Message-ID: <20260518110112.21395-5-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.111; envelope-from=guobin@linux.alibaba.com; helo=out30-111.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102161014154100 Content-Type: text/plain; charset="utf-8" configuration_validate_capabilities() allocates a bitmap on the heap to track source capabilities via bitmap_new()/g_free(). Since MIGRATION_CAPABILITY__MAX is a small compile-time constant (< 64), a heap allocation for a bitmap this small is wasteful: it adds malloc/free overhead and a potential cache miss for a transient 8-byte allocation. Replace with DECLARE_BITMAP() on the stack and bitmap_zero() to initialize. This eliminates the heap round-trip entirely. Signed-off-by: Bin Guo Reviewed-by: Fabiano Rosas --- migration/savevm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index d1dd696c17..23adaf9dd9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -347,10 +347,10 @@ static bool configuration_validate_capabilities(SaveS= tate *state) { bool ret =3D true; MigrationState *s =3D migrate_get_current(); - unsigned long *source_caps_bm; + DECLARE_BITMAP(source_caps_bm, MIGRATION_CAPABILITY__MAX); int i; =20 - source_caps_bm =3D bitmap_new(MIGRATION_CAPABILITY__MAX); + bitmap_zero(source_caps_bm, MIGRATION_CAPABILITY__MAX); for (i =3D 0; i < state->caps_count; i++) { MigrationCapability capability =3D state->capabilities[i]; set_bit(capability, source_caps_bm); @@ -373,7 +373,6 @@ static bool configuration_validate_capabilities(SaveSta= te *state) } } =20 - g_free(source_caps_bm); return ret; } =20 --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102145; cv=none; d=zohomail.com; s=zohoarc; b=fq6ENYnEzZ4rTuc6D5vgR9vyTwfeF2dtTl7kA7s7z2hocp30tTzfn77xqMmzhavC5Dv2sKQGHYQ49Hv6ujiVcm87Gfw1kfQYvu97IHB4bvMx5EK2Vz0s70RFh8w7I+yIESPSF+3Ttodh9bMx6cit4O61CAStVh3KErY2gobfpj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102145; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=in4Q+1qeG1MAXIiZjKRIDZMBVwfkTU/oNDsy/TkG1Ks=; b=h97LKlF+t7vCFSciphexDJYpu6+MuckicrzZtZ/8RmZypYOkPZL7NlXWKRuLs0XeXE0r2icp6lIEz1os4wu9OJgIZBaqt5jfM2JGp1fCmMCejs+7MjP9NzLwFSBGxhp1PGcFsV8rYtwQpXwU4cX2OB+NdtiznuOCp8Usoiev9UQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177910214519043.71186044119304; Mon, 18 May 2026 04:02:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOvj2-0006bD-HR; Mon, 18 May 2026 07:01:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviw-0006YS-VM for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from out30-99.freemail.mail.aliyun.com ([115.124.30.99]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOvit-0005i8-O7 for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X38AAVB_1779102076 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:17 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102077; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=in4Q+1qeG1MAXIiZjKRIDZMBVwfkTU/oNDsy/TkG1Ks=; b=gbygNqVTM+ZnWRdDupFRgfUDrFUB/cMM0lpVJcXQhV+dAK50HuefUp+N2Oa/QZCgQieAxjzOmd+U4FSBInQuMxmJPkgDufuC+Y4sVGRMhxzG7d8nA8SRKgB5yak2vA1Ns5DHWzM00p4DrIPyvsDC/TDqjo9/Frdg9Pkb1Rck1bA= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X38AAVB_1779102076; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 5/8] migration/multifd: fix off-by-one in recv channel ID validation Date: Mon, 18 May 2026 19:01:09 +0800 Message-ID: <20260518110112.21395-6-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.99; envelope-from=guobin@linux.alibaba.com; helo=out30-99.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102146764154100 Content-Type: text/plain; charset="utf-8" multifd_recv_initial_packet() validates the channel ID received from the source against the configured number of channels. The current check uses '>' which allows msg.id =3D=3D N to pass through. This ID is then used to index multifd_recv_state->params[msg.id], which was allocated with g_new0(MultiFDRecvParams, N) -- an out-of-bounds access. A malicious or buggy source could send id =3D=3D N and cause heap corruption on the destination. Fix by changing '>' to '>=3D'. Also fix the error message to say "exceeds channel count" for accuracy. Signed-off-by: Bin Guo Reviewed-by: Fabiano Rosas --- migration/multifd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 035cb70f7b..b3eef875cc 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -210,9 +210,9 @@ static int multifd_recv_initial_packet(QIOChannel *c, E= rror **errp) return -1; } =20 - if (msg.id > migrate_multifd_channels()) { - error_setg(errp, "multifd: received channel id %u is greater than " - "number of channels %u", msg.id, migrate_multifd_channe= ls()); + if (msg.id >=3D migrate_multifd_channels()) { + error_setg(errp, "multifd: received channel id %u exceeds " + "channel count %u", msg.id, migrate_multifd_channels()); return -1; } =20 --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102161; cv=none; d=zohomail.com; s=zohoarc; b=aOQstVoCgAK+seERTcBoMR4ICE3mDyf+6Yk/54/tnm1/8P5R9q/L9pu7Wf4xUgBHK3LIUmDzDVb3pjQEsEoWfFnKT249UiCgmv3tIs4Gi6RI+TCEKa61rHw1+I2NN+V5OByBP6h74pgOh4Xalf4cDMFptJjfP96gYo8v2F/bD5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102161; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8+8p3ol65rhq0ecDJNkEpWpx97Ua/BIn3MGtDEFk66o=; b=jo+X9JLCcTpKjzLq2VEGbwS7CLVO0hlcH/K2JzAdNckTFciTqHgBseTaGp3TClvkG0HsiAglfQAMSAjmXGM4TykWJCjv6U3mgTfT28VFDVMVCvTAs09Bjjj2eoZ1+TBBviIbiPw5eWDXrO+D5ieAxOX0TkFp9Ebd5Uq/6LSZMGU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102161248720.6830651246095; Mon, 18 May 2026 04:02:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOviy-0006ZK-SG; Mon, 18 May 2026 07:01:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviv-0006Y2-8H for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:25 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOvis-0005iH-MA for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:24 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X38AAVS_1779102077 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:17 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102078; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=8+8p3ol65rhq0ecDJNkEpWpx97Ua/BIn3MGtDEFk66o=; b=VE8pr4T2zcC3NhtjIeg/k1V75viX6qFg3FZtioHxW3E7QAkiCaNSzxU5Ze5TxmJwmI30LMs8RZaEfzAOKyrIuhdnAwSSRYBj1LFHUVdJ5crwd+wVCWC8KXxdw1CKIPGhABsMVAk8qmXMzOgTIh/wSsntZkq/mfWlCeHowf+esms= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R201e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037026112; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X38AAVS_1779102077; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 6/8] migration/multifd: merge thread-join and cleanup loops in multifd_recv_cleanup Date: Mon, 18 May 2026 19:01:10 +0800 Message-ID: <20260518110112.21395-7-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.131; envelope-from=guobin@linux.alibaba.com; helo=out30-131.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102162985154100 Content-Type: text/plain; charset="utf-8" multifd_recv_cleanup() iterates over all receive channels twice: one loop to join threads and another to clean up each channel. Unlike the send side where all threads must be signalled before any is joined (to avoid deadlock), on the receive side the threads are already terminated by multifd_recv_terminate_threads(). Each join simply waits for an already-terminated thread, so the join and cleanup for channel i are independent of channel j, and the two loops can safely be merged into one. This cuts the iteration count in half and improves locality: the thread's resources are freed immediately after its join. Signed-off-by: Bin Guo --- migration/multifd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index b3eef875cc..67ee9bdf5e 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1153,15 +1153,14 @@ void multifd_recv_cleanup(void) return; } multifd_recv_terminate_threads(NULL); + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 if (p->thread_created) { qemu_thread_join(&p->thread); } - } - for (i =3D 0; i < migrate_multifd_channels(); i++) { - multifd_recv_cleanup_channel(&multifd_recv_state->params[i]); + multifd_recv_cleanup_channel(p); } multifd_recv_cleanup_state(); } --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102168; cv=none; d=zohomail.com; s=zohoarc; b=iGHA8PmROOniZfOnhzigPBCF0UHIyw8fg6QlPcrte/DEbYiNXbj/kdcvYrxztjA5v9FNZ5V30S21W6L0BSDoLe1iLgV+OECrt0+X6sYldrfE/dG2O06ZhYvXLHuZ2S8AijRdSLMtkfzp4GvBwtfdodHr8PnAfcRuxL/KF7UEZng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102168; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6zpWYZsxVFc8HgF8nKU7F6t6On57u4ibzgThAGNU7gQ=; b=Qy6ZE3Qi+iwSyuc7s37q+ged7YPtn/4fFV1On/6uERptvREw4VFL0tGEDg2Mzw2dQfo31zgFT5a01AJ0d/9G/cu97P1ZxL6Xa8aLpyHreorSqxEf0zF/HKO9O3NJhN+GLpbu48L9krgQ8Fu9CuHbJrH3rQVgIdbAOYU4V03h2L0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102168086972.2325736627965; Mon, 18 May 2026 04:02:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOvj1-0006at-AX; Mon, 18 May 2026 07:01:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviw-0006YK-OU for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from out30-97.freemail.mail.aliyun.com ([115.124.30.97]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOvit-0005iY-Ds for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:26 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X382z02_1779102078 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:18 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102079; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=6zpWYZsxVFc8HgF8nKU7F6t6On57u4ibzgThAGNU7gQ=; b=HaU9Lpd+hVndttqzpvaSdniV98Nrh0ax64CqHRITEYTYqgEQZ5TZANnKSS7fruULLEIzardLC1/boRdk8BjPWVkCOVu7Lo60yBDpDo2zLl+MmEWQaAISg1mkg18Mtc836mTvqQeRMe8S0I5pR64JTt/yX6kP37c4I5vrXC/fUGM= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R581e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X382z02_1779102078; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 7/8] migration/multifd: cache migrate_multifd_channels() in send/recv hot paths Date: Mon, 18 May 2026 19:01:11 +0800 Message-ID: <20260518110112.21395-8-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.97; envelope-from=guobin@linux.alibaba.com; helo=out30-97.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102169066154100 Content-Type: text/plain; charset="utf-8" multifd_send() and multifd_recv() are on the per-page-batch hot path of live migration. Both functions call migrate_multifd_channels() multiple times (3-4 calls each) for modulo arithmetic in the round-robin channel selection loop. Each call goes through migrate_get_current() -> dereference MigrationState -> read parameters.multifd_channels. While each individual call is cheap, these functions execute for every page batch during the entire migration, easily millions of times. Cache the return value in a local variable at function entry. The channel count is fixed for the duration of a migration and cannot change mid-flight. For multifd_send(): 3 calls reduced to 1. For multifd_recv(): 4 calls reduced to 1. Signed-off-by: Bin Guo Reviewed-by: Fabiano Rosas --- migration/multifd.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 67ee9bdf5e..cc2fa90204 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -362,13 +362,15 @@ bool multifd_send(MultiFDSendData **send_data) /* We wait here, until at least one channel is ready */ qemu_sem_wait(&multifd_send_state->channels_ready); =20 + int thread_count =3D migrate_multifd_channels(); + /* * 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()) { + next_channel %=3D thread_count; + for (i =3D next_channel;; i =3D (i + 1) % thread_count) { if (multifd_send_should_exit()) { return false; } @@ -378,7 +380,7 @@ bool multifd_send(MultiFDSendData **send_data) * sender thread can clear it. */ if (qatomic_read(&p->pending_job) =3D=3D false) { - next_channel =3D (i + 1) % migrate_multifd_channels(); + next_channel =3D (i + 1) % thread_count; break; } } @@ -998,6 +1000,7 @@ bool multifd_recv(void) int i; static int next_recv_channel; MultiFDRecvParams *p =3D NULL; + int thread_count =3D migrate_multifd_channels(); MultiFDRecvData *data =3D multifd_recv_state->data; =20 /* @@ -1005,8 +1008,8 @@ bool multifd_recv(void) * using more channels, so ensure it doesn't overflow if the * limit is lower now. */ - next_recv_channel %=3D migrate_multifd_channels(); - for (i =3D next_recv_channel;; i =3D (i + 1) % migrate_multifd_channel= s()) { + next_recv_channel %=3D thread_count; + for (i =3D next_recv_channel;; i =3D (i + 1) % thread_count) { if (multifd_recv_should_exit()) { return false; } @@ -1014,7 +1017,7 @@ bool multifd_recv(void) p =3D &multifd_recv_state->params[i]; =20 if (qatomic_read(&p->pending_job) =3D=3D false) { - next_recv_channel =3D (i + 1) % migrate_multifd_channels(); + next_recv_channel =3D (i + 1) % thread_count; break; } } --=20 2.50.1 (Apple Git-155) From nobody Sat May 30 18:34:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linux.alibaba.com ARC-Seal: i=1; a=rsa-sha256; t=1779102105; cv=none; d=zohomail.com; s=zohoarc; b=GuYwH8R2wqWiBIKrnuZoZsofQfssytXf0qJ8lWfpFigaq74XZzUPYGj27ll99SQWXzKMC/49bRM/QDEpuHAoD9V1x8fkzPmbU0DJV40+xqo32m9v/1iGFlRR2KMnRcRC5M0W7GclEL/Tmlp95lJLQNvLO0yy08ihcGYCds/cLzM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779102105; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GazgXwplieYD1E3kZIynTm21GjivhQWz7Fa/Q3ZVKPM=; b=JnDHpEmD40X7YcX1a8KICeXXXOGNs4PSUFjFTnZFGWxOB/zG/JKIcNjmD1bFFY8tBU9oaShDEKi8dTRIulceEkiR0Ks5oLZYohnnPlm/lzRv0i2FsjM5R+RpiZhIn2H5W49PdMRbplpiPhGJmVchBwFKX8Gnf1hp8+gbilzl1GE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779102105071472.34055484275905; Mon, 18 May 2026 04:01:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wOvj3-0006dO-CE; Mon, 18 May 2026 07:01:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviy-0006Zc-2r for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:28 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wOviu-0005ia-QW for qemu-devel@nongnu.org; Mon, 18 May 2026 07:01:27 -0400 Received: from localhost(mailfrom:guobin@linux.alibaba.com fp:SMTPD_---0X38-ooA_1779102078 cluster:ay36) by smtp.aliyun-inc.com; Mon, 18 May 2026 19:01:19 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1779102079; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=GazgXwplieYD1E3kZIynTm21GjivhQWz7Fa/Q3ZVKPM=; b=lm3hx3GQdoJ8ovvNAcwKAkxxJan5a5qNVdlJRzY0Gn7XRl7NEVuXc0+7A8+OuNaO8mZnYCFy4dfta3c8Z1vo2Lt+G4KjXWvicF4SizvbB3YAMM4Hlq0Uz4gRlhJ4mh3Qm/VSjFUKYdFtNa0asWgBrqgKLSAsP+LWNOZ7oPeD20w= X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R121e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=maildocker-contentspam033037009110; MF=guobin@linux.alibaba.com; NM=1; PH=DS; RN=3; SR=0; TI=SMTPD_---0X38-ooA_1779102078; From: Bin Guo To: qemu-devel@nongnu.org Cc: peterx@redhat.com, farosas@suse.de Subject: [PATCH 8/8] migration/multifd: cache channel count in multifd_send_sync_main Date: Mon, 18 May 2026 19:01:12 +0800 Message-ID: <20260518110112.21395-9-guobin@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260518110112.21395-1-guobin@linux.alibaba.com> References: <20260518110112.21395-1-guobin@linux.alibaba.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=115.124.30.130; envelope-from=guobin@linux.alibaba.com; helo=out30-130.freemail.mail.aliyun.com X-Spam_score_int: -174 X-Spam_score: -17.5 X-Spam_bar: ----------------- X-Spam_report: (-17.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_DKIM_WL=-7.5, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.alibaba.com) X-ZM-MESSAGEID: 1779102107221158500 Content-Type: text/plain; charset="utf-8" multifd_send_sync_main() is called once per RAM synchronization round during live migration. It iterates over all multifd channels twice (signal loop + wait loop), calling migrate_multifd_channels() independently in each loop header. Cache migrate_multifd_channels() in a local thread_count variable at function entry, matching the pattern already used in multifd_send_setup() and multifd_recv_setup(). This eliminates 2 redundant config lookups per sync call. Signed-off-by: Bin Guo Reviewed-by: Fabiano Rosas --- migration/multifd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index cc2fa90204..bc8aacd660 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -611,13 +611,15 @@ static int multifd_zero_copy_flush(QIOChannel *c) int multifd_send_sync_main(MultiFDSyncReq req) { int i; + int thread_count; bool flush_zero_copy; =20 assert(req !=3D MULTIFD_SYNC_NONE); =20 + thread_count =3D migrate_multifd_channels(); flush_zero_copy =3D migrate_zero_copy_send(); =20 - for (i =3D 0; i < migrate_multifd_channels(); i++) { + for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 if (multifd_send_should_exit()) { @@ -634,7 +636,7 @@ int multifd_send_sync_main(MultiFDSyncReq req) qatomic_set(&p->pending_sync, req); qemu_sem_post(&p->sem); } - for (i =3D 0; i < migrate_multifd_channels(); i++) { + for (i =3D 0; i < thread_count; i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 if (multifd_send_should_exit()) { --=20 2.50.1 (Apple Git-155)