From nobody Sun May 3 14:20:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1776974680; cv=none; d=zohomail.com; s=zohoarc; b=Cqpgudkv/KMs7FGujXSM2FJ8WAsY00fZiT6PND7VKXENkj6xdRh1dMGu8gb0js8KJB8H2r+g6lRufrxtnqMHdIYiGG0VV+JbX8/Z3mZT6RYNSGbDZStKGICupI0frfIxLeRGZWTx/j+S4fWaQUaglQiWWJNwXNTDyyFNwRD/ppI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776974680; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XDfhd227o6gGh3k3sHyBHCTFmn0oVFwYEqgY5uwBNT0=; b=ZIBKTJlAF3V5M9c4ZQ7yisrnxFkgcUCXzbzdfZBVXQRX6EWunb2KmkM7NpPRs1e8X7rRNkRJ8jFcYD9zuKitFrPjaxjIMt7dRjgI8m2Jult+Wp1iwKc4krzd9+OpvFiBBj6O+NG+2erLfuwhJsdTgGd4FbKsL1nUOK2TwN7dg8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1776974680522404.65269068924863; Thu, 23 Apr 2026 13:04:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1292626.1570973 (Exim 4.92) (envelope-from ) id 1wG0Hc-0007Sb-3q; Thu, 23 Apr 2026 20:04:20 +0000 Received: by outflank-mailman (output) from mailman id 1292626.1570973; Thu, 23 Apr 2026 20:04:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hc-0007SQ-10; Thu, 23 Apr 2026 20:04:20 +0000 Received: by outflank-mailman (input) for mailman id 1292626; Thu, 23 Apr 2026 20:04:18 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Ha-0007FJ-J6 for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 20:04:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wG0HZ-005MS0-W8 for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 22:04:18 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ea7b40-5cb7-0a2a0a5109dd-0a2a4505d46e-4 for ; Thu, 23 Apr 2026 22:04:17 +0200 Received: from [209.85.221.45] (helo=mail-wr1-f45.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ea7b41-aaa8-0a2a45050019-d155dd2ddde8-3 for ; Thu, 23 Apr 2026 22:04:17 +0200 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43d6fbd0954so5585381f8f.1 for ; Thu, 23 Apr 2026 13:04:17 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a341sm60065442f8f.24.2026.04.23.13.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 13:04:16 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776974657; x=1777579457; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XDfhd227o6gGh3k3sHyBHCTFmn0oVFwYEqgY5uwBNT0=; b=UzRiAQxsJHjx+XfeEt5bh3mMBYBaQJOSfi2ngqVL9QnfRV4+8xp9ZWXTCyDW14tB6H uWhdUXNoXwhgw1iQWN4V00BsYCaSyiPQ/4eSXPGIxpe3qkhpsrHXDxhhsYjgeM3LjNiZ DQkgIFh1AS/TEGND6LpgZtCbLdQ69aoyX7Mu2PJWAx7gepVQb6crg01lOH9kr0mUU2sA f5eaagr5SUv9kgXvBfg+tGF7FL4vvUKjugzn2rROqx6/Uvh81S9myPwT7IFk1sF4i4rm SChvMe7jljMe8qJuxZJMfskoFG37BqNjPxh9HzK47JFIfuCaqqMnSxkopC6BQu5686Wf lqNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776974657; x=1777579457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XDfhd227o6gGh3k3sHyBHCTFmn0oVFwYEqgY5uwBNT0=; b=jc38qOmdrdgCBSdj73jYiOA3egfjFZz1f3CYhlzuLjOWUQ9Gy7skOxT58UuioxXxVY ez5/Mm2dtJKpXlz1VO5bl6fCy8EZuJzXhd7Z3mRAida95WWlDWiL2jF3pz3UTrGcFLX8 Y1LR4Dw+/epgpS050ujjuNS4ALbXCGlAfjkUKNcNLXbsNsmMD1Q1t5e9Mse3qu1HBlp8 +xm8+Hx2X1un7dstYWQRo1IPRqw9f5ZuraJZFrhtJe8XhQ2fX8JBp6EDlgJEKEdifE0x DH1vfsTGFUqbZMhWn79sbfzLuBRNf9FiL9w6zpoGu5dol2Tx8wEFwLFS1lVrB4Z5e8Un D1jA== X-Gm-Message-State: AOJu0YyKqpFfN7A1XC9ElI/uu2U0Uuj6LaZdlHHFp108Ms4kc6kE2yfn aFWuuPTFuMIhH4TVt2W0Wu6vYNHmFBbfhiYn0Fhy12yXxp15qkkMasLj7oRc2+TA X-Gm-Gg: AeBDies2e/ROep9y4NvUDkke8+w+GSz1Ase5+XDCZNXvuBG2vBesKceI+K0KKtD2RyZ uNyzp6dGr24B2RKrRDmqgb94gj8XWupDvsCAPzcyVhQVLTSDWeHAdMJDFUmNXKNwwc/ViWZtI8q zoR1RfPPhTzF5r8JnCwc47hesxC9C2poBSBbaCMoJwfAohAHBPu/kCjc5w6wClh5RxbTIcfKRk6 phPwV6jSwxpTX0u2B3gbelbd0E9dgaIfmmFYGe61t09dceqMZdbx4nRR7eWfK/1NpHMm4NSnjZN ufEVYE8w9hnLrPlY2XcsX8YdAHUuo+OtWZcfLWCfs1nKuRF8Pq3VnsJFU61Uz2rTali7dIjh7fH Gt+aHNogSNTWD3Tla2n2K/kYc9RrSkJOChYt3VieqlaNDVA3gTvz8djQ0FtjDRgBdlaTm6Lfglx lzwuGdrZ+M81joyYMvvIb/OeNYBGNrkBOFlccd38bzvoBLibXvTBWDePUc7Vjr8G31v7rckHM1L UQe X-Received: by 2002:a5d:64c3:0:b0:43d:309b:9c4f with SMTP id ffacd0b85a97d-43fe3db2d1amr41210620f8f.6.1776974657013; Thu, 23 Apr 2026 13:04:17 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH 1/4] xenguest: Reduce number of parts in write_split_record Date: Thu, 23 Apr 2026 21:03:56 +0100 Message-ID: <20260423200406.28178-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260423200406.28178-1-frediano.ziglio@cloud.com> References: <20260423200406.28178-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1776974657-2A374443-FBC3E0F8/0/0 X-purgate-type: clean X-purgate-size: 1576 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1776974682132154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. There's no much sense to split the header in 2 pieces, it will just take more time and space to reassemble them in the final buffer. This also avoids truncating combined_length to 32 bit in case of 64 bit machines potentially avoiding following record_length check. The function become more coherent with following read_record function. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 7ccdc3b1f6..86c148c62f 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -59,11 +59,11 @@ int write_split_record(struct xc_sr_context *ctx, struc= t xc_sr_record *rec, static const char zeroes[(1u << REC_ALIGN_ORDER) - 1] =3D { 0 }; =20 xc_interface *xch =3D ctx->xch; - typeof(rec->length) combined_length =3D rec->length + sz; + size_t combined_length =3D rec->length + sz; size_t record_length =3D ROUNDUP(combined_length, REC_ALIGN_ORDER); + struct xc_sr_rhdr rhdr =3D { rec->type, combined_length }; struct iovec parts[] =3D { - { &rec->type, sizeof(rec->type) }, - { &combined_length, sizeof(combined_length) }, + { &rhdr, sizeof(rhdr) }, { rec->data, rec->length }, { buf, sz }, { (void *)zeroes, record_length - combined_length }, --=20 2.43.0 From nobody Sun May 3 14:20:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1776974695; cv=none; d=zohomail.com; s=zohoarc; b=MgOVf5L7BfqBy5sB18630gstg9g06Lh2f8Pt2VOHTD09JtQOKGc9GoLr1NiexpxKIiwagIck6gP2kxDFsm4BjowHmAUCyurEGEj+gXdFu7d3w8jA90Ot/AkIWedEpEePQd9SIIbc6iITznHWBpIpIVI6WT7MwMEVyXFKWewsFh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776974695; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sVGY1T6hm0/7+FJT6srnaIkpU7DrhVy9HgeD1DDoZUc=; b=jvx6ZnTeebRpKbdRm8pBb3sdreNi6zX+jbZKMEFC3e/J5tRxwOMajPE/+bHbCb/6p1VYlujh8NSW+bhgD5QTmqKM/DVnFbrXT4GuZk2A9+XwfytGsZ82Bul0Npth8qvvCPBJpyVmjorFTB81pm8iEyKt7zzgAFRY2adlE5kTQGM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1776974695027324.2561692068274; Thu, 23 Apr 2026 13:04:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1292627.1570978 (Exim 4.92) (envelope-from ) id 1wG0Hc-0007U9-BY; Thu, 23 Apr 2026 20:04:20 +0000 Received: by outflank-mailman (output) from mailman id 1292627.1570978; Thu, 23 Apr 2026 20:04:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hc-0007Tz-7U; Thu, 23 Apr 2026 20:04:20 +0000 Received: by outflank-mailman (input) for mailman id 1292627; Thu, 23 Apr 2026 20:04:19 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hb-0007Le-Cq for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 20:04:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wG0Ha-008AbV-Pj for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 22:04:18 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ea7b42-bab6-0a2a0a5309dd-0a2a4506bad4-0 for ; Thu, 23 Apr 2026 22:04:18 +0200 Received: from [209.85.221.43] (helo=mail-wr1-f43.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ea7b42-7371-0a2a45060019-d155dd2bf07e-3 for ; Thu, 23 Apr 2026 22:04:18 +0200 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-43d73422431so6043904f8f.2 for ; Thu, 23 Apr 2026 13:04:18 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a341sm60065442f8f.24.2026.04.23.13.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 13:04:17 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776974658; x=1777579458; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sVGY1T6hm0/7+FJT6srnaIkpU7DrhVy9HgeD1DDoZUc=; b=T4zu/hn2SFtlgE2Up/0X7YzE/jxSHDdB47UA9+e5ysZ6+hV/es7vH0dbFsn3QJFP4m q0eiBebPWVIlrPITkRQ3BrdNR5Lu7S3QOILkALHprljTjCVbHLs3nUcYCi7ithhmf4GC dEjUvoYu8iDGJyKvhO7QY7UCqlyRROCE/Yfrz+NWG9JEkVZTxiyB2aRkAjRsPZkKtxwG Q7lL074ih4vXCf2Sl8CMTTVZXSwUCbK+ADirt+5kMTNwH2KJJN+8J02BU+TT5T9okzfy SF3LebeSUwNRT0SX1IDMK3etGD98QiPX2fvoG041jc6f+WK9YmXN7LmfdI9OzCCainUz VKrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776974658; x=1777579458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sVGY1T6hm0/7+FJT6srnaIkpU7DrhVy9HgeD1DDoZUc=; b=IvE6oagXgE0cfqC+4u6ij2ZPEkt348bQoRUpSNpW/WXx2TynYP48NBpI7moy3I+Ydp wAw5Sij/zSJZ/vF76onscfVL5lN0WYE2KDNe7WyiVnmMZQH1pxUJUu1QzXS0U5VxOI5C /TWZ3ZkJp7BY1xuYIOfnVxrOBAclHSMq4DFVwYE0N6olrfu6GZ47yOHSFMdv6nljxEtj W56iIWmtb+Mj8ncKBBQxXTzo9NAJYFHPeMW/TZH2ZRL7q34n8p5A4Qp1dkgw2UVtlPpV BrA4eJAMJzD4tfzkRSlRZu5Ku56gVtWNgBFmoZCX/WxRF2CVg9079OlYPyqFy8GrK2+F ynVw== X-Gm-Message-State: AOJu0YyLqziOJOt5Idsb7MPPkSIKdPrt4JbpQZdEZ7PKbUOmd686ZFgO uitlhvHfRE1IJHImsL9wJ50soh51Ai8+xuIvig+SvKjjwTFYanqWJanZXSLwW0f6 X-Gm-Gg: AeBDievuBla+9X0Ho6A9Q+VFV6T89ZiQEQYgAzFNs99LoA25PV9UuiE5HQlRHKJPCV3 vKuXIfn64YZFlh2+H30KyGuFsnjmLIHRVp0VjTxDHlXxLIF1EjeBRuyhECuoR5CYe5Tj7zoVT29 uFPcSvn561FU377cb2M3HkbtNY4sAs9GV7045QFlQyrvg0ZAXpqn58d/bkKLUZQRcLqdYpyA8xB g0dl5WvWOxjTVlYJ6gPmqAgxGmRr5h5e5SKoB+h3xgCt6NGXTV7rUk+dDQgFfZL6TnNRyDgZrLE DiGVN1xYoHc3HpQ13zjmaenyK7zr4PA4OVPSzECx8oxzQHGxbU5elNqEsXJ2rfZMj+BL4Rgu8W2 gxl97pi9Wt5/ROH6nWCD8Zn7PygMtrz8vTiUNScSEjPFR1W8Ld4Yo+UtDCPPYWYCxHWXto0WAFk wkB+BQlTSE7Em/LXIe/ECfJHA3fK/LEy2hdxG7yCyXNbKooSuZ6zVxMAJoOWCiHzhDsq6UlBHWF R6Y X-Received: by 2002:a05:6000:240e:b0:43d:714:34e5 with SMTP id ffacd0b85a97d-43fe3e0d2e3mr44148983f8f.24.1776974657709; Thu, 23 Apr 2026 13:04:17 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH 2/4] xenguest: Reduce number of I/O vectors in write_batch Date: Thu, 23 Apr 2026 21:03:57 +0100 Message-ID: <20260423200406.28178-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260423200406.28178-1-frediano.ziglio@cloud.com> References: <20260423200406.28178-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-16d1c6/1776974658-52369D75-4AF4319C/0/0 X-purgate-type: clean X-purgate-size: 2569 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1776974695245158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. Reduce number of pieces passed to writev. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_save.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 3b2c5222e4..1700d81905 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -97,9 +97,12 @@ static int write_batch(struct xc_sr_context *ctx) void *page, *orig_page; uint64_t *rec_pfns =3D NULL; struct iovec *iov =3D NULL; int iovcnt =3D 0; - struct xc_sr_rec_page_data_header hdr =3D { 0 }; - struct xc_sr_record rec =3D { - .type =3D REC_TYPE_PAGE_DATA, + struct { + struct xc_sr_rhdr rec; + struct xc_sr_rec_page_data_header page_data; + } hdrs =3D { + { .type =3D REC_TYPE_PAGE_DATA }, + { 0 }, }; =20 assert(nr_pfns !=3D 0); @@ -115,7 +118,7 @@ static int write_batch(struct xc_sr_context *ctx) /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); + iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); =20 if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) { @@ -216,28 +219,22 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } =20 - hdr.count =3D nr_pfns; + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + hdrs.rec.length +=3D nr_pages * PAGE_SIZE; =20 - rec.length =3D sizeof(hdr); - rec.length +=3D nr_pfns * sizeof(*rec_pfns); - rec.length +=3D nr_pages * PAGE_SIZE; + hdrs.page_data.count =3D nr_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; =20 - iov[0].iov_base =3D &rec.type; - iov[0].iov_len =3D sizeof(rec.type); + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); =20 - iov[1].iov_base =3D &rec.length; - iov[1].iov_len =3D sizeof(rec.length); + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); =20 - iov[2].iov_base =3D &hdr; - iov[2].iov_len =3D sizeof(hdr); - - iov[3].iov_base =3D rec_pfns; - iov[3].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 4; + iovcnt =3D 2; =20 if ( nr_pages ) { --=20 2.43.0 From nobody Sun May 3 14:20:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1776974688; cv=none; d=zohomail.com; s=zohoarc; b=oLKdvksy506ZG05TAvIFgKHMGMoWU+qovj8ru4JHJAhTCcGw7b/bxPaJtLE2aCTXkm8WbinAp7Cm2Mccn+m61J/xWg5SUJCg01CyMFvqnELlGabUegTnMrqRYkiih+hhB3q3qUye2areZ0MARaSeJ1xlgOC0drztIJIi1/5gpp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776974688; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Oxg5mCtqQQ6xjPu85ADP9KtAzh/otnbEOWyjQXNEH9o=; b=dVx2lj+4Bn2UbWNuP1h0PpWZWDsbpQnzLPPV44E1cmuQEclz6j996F/d2IqxjwYTj6HksR9Sxb363qCUNzKmVmipVfYAhwFcHXuF32WmRdK0OHecCHlbd53mA72oMM7FjwFH7Awqy6c0jHMzjJsPHwbBd81l5Xg0qh1HFw9CDVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1776974688733836.1274913781011; Thu, 23 Apr 2026 13:04:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1292628.1570991 (Exim 4.92) (envelope-from ) id 1wG0Hd-0007tN-N9; Thu, 23 Apr 2026 20:04:21 +0000 Received: by outflank-mailman (output) from mailman id 1292628.1570991; Thu, 23 Apr 2026 20:04:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hd-0007tG-KF; Thu, 23 Apr 2026 20:04:21 +0000 Received: by outflank-mailman (input) for mailman id 1292628; Thu, 23 Apr 2026 20:04:20 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hc-0007Ru-0Z for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 20:04:20 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wG0Hb-005MUL-Dg for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 22:04:19 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ea7b25-2eae-0a2a0a5409dd-0a2a45019a8a-26 for ; Thu, 23 Apr 2026 22:04:19 +0200 Received: from [209.85.128.47] (helo=mail-wm1-f47.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ea7b43-c1f2-0a2a45010019-d155802fbddc-3 for ; Thu, 23 Apr 2026 22:04:19 +0200 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-488b0046078so63848575e9.1 for ; Thu, 23 Apr 2026 13:04:19 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a341sm60065442f8f.24.2026.04.23.13.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 13:04:18 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776974658; x=1777579458; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oxg5mCtqQQ6xjPu85ADP9KtAzh/otnbEOWyjQXNEH9o=; b=qCDKa/yPJQv3ZglBr2bNQqMrs0XBQKqTQMMm4Te4/N4vZJGk7Aho/USAR7JhajlmAv 7cf4+xGOIdjDxJt9JaT+EDMpZekmKOVkL84gtBSiJqXrAuIhJp21Zyh2w9vD1ATyKtJ/ 2WP0u1MsH6YpzO/p550biFcojXFtMt8WZJh4zyLV8Cxf3+vawZ3KcO6xxtulZ/TYWi7N wePpUfC0zFxEiNr0lbtUjsuzbYaoFvNS62Bqtsfql0TvE1NB0kNcf7kH4EwM4fXYDrJ2 LO/apOpBSaNpLwsvAxC7h/Mid3yJ3NvuLRVn2PhnvsmTaiZmH4e1PF4we9ePQc6KLRzA ho+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776974658; x=1777579458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Oxg5mCtqQQ6xjPu85ADP9KtAzh/otnbEOWyjQXNEH9o=; b=DFYIZ1+BoB+sAOI+jMDWe5mWXW/rQdeu/pFaACQwz2IWYT1b4jdOClLMdelQ2VyiV0 LXFbVTCkRlTtTb7IaNbv05A8rxEvRUXbnREzqvhsOKk3dqD8pIAihIsADZhUopfqjw2b hGP1OsuITNgI5sVvkIgal37WllH7DdaXYD493hVLvsbWLVhZJ+pPYddFsLRSwjmPmx9J nW1uB5/UZWEIph7V1WW3fl/WyJflDNUxP3if4R0M4Wsfsn2hwn/Cqkn951IFtu39YRwJ Ao1Iyf2FJ8k/2cBZ0twxXY3cORu6zGjEY/cgkNrI1HUlGTRpVNnMZtnS4rX1z4U1sflN bQDA== X-Gm-Message-State: AOJu0YzwvUrjMRwSt3/qffGtsDqatH1ADzWDNxnhlNM1pBd5/cUC6N+p tgfLQkyyqSObdtOryXFicgLXb19FU/KV3NacYTbPyxKbbWCENxcqCGoqN6xz0krZ X-Gm-Gg: AeBDievcX8muDa1N3CEYNreH5E5nxFE/eQConsiAITcjfq1XFWjB+LM+BYpiwLjxdwN U+D3Z4NIW/FdQgwF1z4t6gd7MkqqP7zjlq388cvsgegPTxCRtOmLu+evhg+n+wif0L+Pl9Me0a+ qopU8Oo7BnA1+9p0BW75OPHZJdPIVi9SQeRi2RwdiDQQm7PxjfU2qmQdeiG2xxTxxUOoNX2Aznp 2DUHpnLaXkOaUy7/e3TLDcf4dW26eYHyD10VdO+nvkbfa23BztsxqtxTnuwz8oVn0w28tw3o8dw Gt6g0q/f+dMrhkhMIhAmnISaL6DRkZNt28TvF76d+LaxxV+wFbxDM9YNvy0M25lWORCfUvJkIMn /xwampbVlGc3Ml9jDrIC0nNPkZS3CAPWvStL8pXYUF8kI5uM/uy8Bf+xcgbSUMzyQNRke+jRjzb 6N72gTeOr8VxZcOHRTfZe66yQE8hhhm4ouHj1go8Nr1SRJF0GHGdngik+6Cu93AicCja25zCUkV tkb X-Received: by 2002:a05:6000:178b:b0:43d:7946:bae5 with SMTP id ffacd0b85a97d-43fe3e144cbmr44457096f8f.42.1776974658500; Thu, 23 Apr 2026 13:04:18 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH 3/4] xenguest: Allows writev_exact to change iov array Date: Thu, 23 Apr 2026 21:03:58 +0100 Message-ID: <20260423200406.28178-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260423200406.28178-1-frediano.ziglio@cloud.com> References: <20260423200406.28178-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1776974659-B4617FF4-6AF0E027/0/0 X-purgate-type: clean X-purgate-size: 3174 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1776974689425158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Avoid having to allocate and copy the array if a partial write happens. The implementation in tools/libs/store/xs.c already use this signature and method. Signed-off-by: Frediano Ziglio --- tools/libs/ctrl/xc_private.c | 26 +++++--------------------- tools/libs/ctrl/xc_private.h | 2 +- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index bb0f81d6f3..946fc307aa 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -635,7 +635,7 @@ int write_exact(int fd, const void *data, size_t size) /* * MiniOS's libc doesn't know about writev(). Implement it as multiple wri= te()s. */ -int writev_exact(int fd, const struct iovec *iov, int iovcnt) +int writev_exact(int fd, struct iovec *iov, int iovcnt) { int rc, i; =20 @@ -649,9 +649,8 @@ int writev_exact(int fd, const struct iovec *iov, int i= ovcnt) return 0; } #else -int writev_exact(int fd, const struct iovec *iov, int iovcnt) +int writev_exact(int fd, struct iovec *iov, int iovcnt) { - struct iovec *local_iov =3D NULL; int rc =3D 0, iov_idx =3D 0, saved_errno =3D 0; ssize_t len; =20 @@ -686,23 +685,9 @@ int writev_exact(int fd, const struct iovec *iov, int = iovcnt) len -=3D iov[iov_idx++].iov_len; else { - /* Partial write of iov[iov_idx]. Copy iov so we can adjust - * element iov_idx and resubmit the rest. */ - if ( !local_iov ) - { - local_iov =3D malloc(iovcnt * sizeof(*iov)); - if ( !local_iov ) - { - saved_errno =3D ENOMEM; - rc =3D -1; - goto out; - } - - iov =3D memcpy(local_iov, iov, iovcnt * sizeof(*iov)); - } - - local_iov[iov_idx].iov_base +=3D len; - local_iov[iov_idx].iov_len -=3D len; + /* Partial write of iov[iov_idx]. */ + iov[iov_idx].iov_base +=3D len; + iov[iov_idx].iov_len -=3D len; break; } } @@ -711,7 +696,6 @@ int writev_exact(int fd, const struct iovec *iov, int i= ovcnt) saved_errno =3D 0; =20 out: - free(local_iov); errno =3D saved_errno; return rc; } diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index b5892ae8dc..3af996e900 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -383,7 +383,7 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_m= mu *mmu); /* Return 0 on success; -1 on error setting errno. */ int read_exact(int fd, void *data, size_t size); /* EOF =3D> -1, errno=3D0= */ int write_exact(int fd, const void *data, size_t size); -int writev_exact(int fd, const struct iovec *iov, int iovcnt); +int writev_exact(int fd, struct iovec *iov, int iovcnt); =20 int xc_ffs8(uint8_t x); int xc_ffs16(uint16_t x); --=20 2.43.0 From nobody Sun May 3 14:20:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1776974685; cv=none; d=zohomail.com; s=zohoarc; b=IHKj3ZU5b3Zmrl4dFZFhXimxKcDfaq9Vpg8jZLLowvedi8C7mb2QCjxjN7kerFtVeyEBXQvlwDgesA0SNqam+Acf6WpC5nz1sQkGp4iWxw9Bbn7t8pAnXh1DxBJki4IJSO/ZNZSp7eIlc6LcXUctu265/9K7MguJpw17MK4rO8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1776974685; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0sgCfk1ugKuxjrB/yyEc4hgcj8W8SrxyN2ccMLOE0JE=; b=aV3d12R/tCcf+MjTmZWqYxvUfPvwydndWko3zS+yX2FIGSMhXvpOUkO9qfMohKAW4vkxKunDUY77rwsbMANMRvrG29Oh14GIT4cOGSiMeqckfi1n4rDAUfEySHhSvJwfgjBPHKNZPoJzEtW9pMK6qes/K8I5vrPy9cJF+nbTZsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1776974685911807.6692026405391; Thu, 23 Apr 2026 13:04:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1292629.1570997 (Exim 4.92) (envelope-from ) id 1wG0He-0007wY-2O; Thu, 23 Apr 2026 20:04:22 +0000 Received: by outflank-mailman (output) from mailman id 1292629.1570997; Thu, 23 Apr 2026 20:04:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hd-0007wC-TN; Thu, 23 Apr 2026 20:04:21 +0000 Received: by outflank-mailman (input) for mailman id 1292629; Thu, 23 Apr 2026 20:04:21 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wG0Hd-0007ic-3T for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 20:04:21 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wG0Hc-008AbV-GX for xen-devel@lists.xenproject.org; Thu, 23 Apr 2026 22:04:20 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ea7b23-bab6-0a2a0a5309dd-0a2a4507ec64-26 for ; Thu, 23 Apr 2026 22:04:20 +0200 Received: from [209.85.221.42] (helo=mail-wr1-f42.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ea7b44-229c-0a2a45070019-d155dd2aa98d-3 for ; Thu, 23 Apr 2026 22:04:20 +0200 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-43d75312379so5163604f8f.1 for ; Thu, 23 Apr 2026 13:04:20 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a341sm60065442f8f.24.2026.04.23.13.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 13:04:18 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776974660; x=1777579460; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0sgCfk1ugKuxjrB/yyEc4hgcj8W8SrxyN2ccMLOE0JE=; b=e8vzlf144FcZgCJw25hC3LekHi/M5vQK86eIo+5Ri5J6+ZM/NOq1EniM9CWWcjsYNI +nVwxnbQgxBf+KPIObPrP4hwiabdxob7ckTt05ft+hFga4Wrc6s6vgCv75fgH/Jn7kAA spjpWblnr3F4qqaLsLMxnswOvlJNm7P/onx1zvlYUkXZ5KMSdGAadhM6k0Mvx5fTqusO Mr4QLHYJaGmi0t8mlaphAPlGQSs2MGmshM5bWh0Z7lpfOHd2kNjwHV+5vZfAdK4F6pNO Av5tQ9zivigeTfyuU/o48UwgegZzB3s5wTCjei3HLRl7kWg0Ed2zc31lajadmFIw4bvZ LDLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776974660; x=1777579460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0sgCfk1ugKuxjrB/yyEc4hgcj8W8SrxyN2ccMLOE0JE=; b=ZuX4xW/SVb7+mgiu9KAEwLiQjMmeJsuAxeD9LMuW/SVJ4SgZEdv4bHLU/+8luhuaV/ bHhAdMFI7TvKv1dCObbubfByvAxXIKHMqOtmsF+snCi5dxUBWNtLUttWjWnEWeXmBe41 0Q1OPEjahUR70ClIJg3Sgu41qwdBSgDfjFqeFaIs06hvrEMP+BabBzCXi0SPRF49HRBn AEqAevJR9aLkGECdC7PMlz6zT2NoQNJVH4CGbtK5tVn7fY/sc47J2S3rPrM+ujdW7HR4 Rz7lug1LjnSx9ZRDzLmW+4RFoKiV1bQgOriuBEUoptDNl0gk4QBEbbpJywDmUmuPsCWH 7b/g== X-Gm-Message-State: AOJu0YxGdtmx/8cF0hUq5+10+l2Fm6/fzmrYgYtzqcfvKmXi/KH3D92a wTn08L6hq5VymhR6DQBNYUr3J0rbWtawqjy4wmremxXdnQY1DJ2l7Db1N6X6P9i9 X-Gm-Gg: AeBDietqcK95+pCC/g74Hlqo89Y43VRwPp28seX7joM69D56wQoQtQFqzNrD3JEFQ9W fVYEnnlOof9JTyrNRSn1vpziX35n/4MSGIVah2dJ6UQDvznmleF0BjWqLRuUTxZ4qwHFFl9mAwe ne++QlWDeNE03WPVvYUSQ0Iki7T7iC5Szi9UvY2WhlDPiyZo+eutW7vlUiOl+JKmdMoZH0U3snR 713wz9aNCkWLCBTajfOQbIDyVBfraM2Ik2coh3VD/hHcjYk6CsCGkOrQQJ8etc/VQ4UN91WpkiW zQTxqVrV6XvkNhDIUSWbfgI00ST/e/vDKZXJjYhGbCUU0CCyacIcdedLJ3RcRoKLN/5AGoEnpiK OvkOyJ/ccUgYl+5YWgXHOYd6usVU0+T5p854yETyRO3drX41CQzW+8aDIV0RbhEviT6NvWaAIdb LiIIonoCSXmtzUwI5TB0Z7mMHtJq9kHl3mWCRmJpdN+ZKV8Qa8hYfQdepXf/2Em6VIiuA5z0PuI XxeI8AVnnAWfb4= X-Received: by 2002:a05:6000:471a:b0:441:30d8:f023 with SMTP id ffacd0b85a97d-44130d8f040mr2937021f8f.6.1776974659411; Thu, 23 Apr 2026 13:04:19 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH 4/4] tools/libs/guest: allocate various migration arrays just once Date: Thu, 23 Apr 2026 21:03:59 +0100 Message-ID: <20260423200406.28178-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260423200406.28178-1-frediano.ziglio@cloud.com> References: <20260423200406.28178-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1776974660-2BD7FC48-7DD3B721/0/0 X-purgate-type: clean X-purgate-size: 6401 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1776974688015154100 From: Edwin T=C3=B6r=C3=B6k Allocate these array just once at the start of migration, using the maximum batch size, and free them at the end. Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.h | 13 +++++++ tools/libs/guest/xg_sr_save.c | 66 +++++++++++++-------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index f1573aefcb..77312bae9c 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -209,6 +209,18 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct xc_sr_context_save_buffers +{ + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; + xen_pfn_t mfns[MAX_BATCH_SIZE]; + xen_pfn_t types[MAX_BATCH_SIZE]; + int errors[MAX_BATCH_SIZE]; + void *guest_data[MAX_BATCH_SIZE]; + void *local_pages[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE + 2]; /* headers + data */ + uint64_t rec_pfns[MAX_BATCH_SIZE]; +}; + struct xc_sr_context { xc_interface *xch; @@ -244,6 +256,7 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct xc_sr_context_save_buffers *buffers; } save; =20 struct /* Restore data. */ diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 1700d81905..64014dcdbd 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -87,16 +87,16 @@ static int write_checkpoint_record(struct xc_sr_context= *ctx) static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D NULL, *types =3D NULL; + xen_pfn_t *mfns, *types; void *guest_mapping =3D NULL; - void **guest_data =3D NULL; - void **local_pages =3D NULL; - int *errors =3D NULL, rc =3D -1; + void **guest_data; + void **local_pages; + int *errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; void *page, *orig_page; - uint64_t *rec_pfns =3D NULL; - struct iovec *iov =3D NULL; int iovcnt =3D 0; + uint64_t *rec_pfns; + struct iovec *iov; int iovcnt =3D 0; struct { struct xc_sr_rhdr rec; struct xc_sr_rec_page_data_header page_data; @@ -106,26 +106,24 @@ static int write_batch(struct xc_sr_context *ctx) }; =20 assert(nr_pfns !=3D 0); + assert(nr_pfns <=3D MAX_BATCH_SIZE); + assert(ctx->save.buffers); =20 /* Mfns of the batch pfns. */ - mfns =3D malloc(nr_pfns * sizeof(*mfns)); + mfns =3D ctx->save.buffers->mfns; /* Types of the batch pfns. */ - types =3D malloc(nr_pfns * sizeof(*types)); + types =3D ctx->save.buffers->types; /* Errors from attempting to map the gfns. */ - errors =3D malloc(nr_pfns * sizeof(*errors)); + errors =3D ctx->save.buffers->errors; /* Pointers to page data to send. Mapped gfns or local allocations. */ - guest_data =3D calloc(nr_pfns, sizeof(*guest_data)); + guest_data =3D ctx->save.buffers->guest_data; + memset(guest_data, 0, sizeof(*guest_data) * nr_pfns); /* Pointers to locally allocated pages. Need freeing. */ - local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); + local_pages =3D ctx->save.buffers->local_pages; + memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); - - if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) - { - ERROR("Unable to allocate arrays for a batch of %u pages", - nr_pfns); - goto err; - } + iov =3D ctx->save.buffers->iov; + rec_pfns =3D ctx->save.buffers->rec_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) { @@ -211,14 +209,6 @@ static int write_batch(struct xc_sr_context *ctx) } } =20 - rec_pfns =3D malloc(nr_pfns * sizeof(*rec_pfns)); - if ( !rec_pfns ) - { - ERROR("Unable to allocate %zu bytes of memory for page data pfn li= st", - nr_pfns * sizeof(*rec_pfns)); - goto err; - } - hdrs.rec.length =3D sizeof(hdrs.page_data); hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -261,17 +251,13 @@ static int write_batch(struct xc_sr_context *ctx) rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: - free(rec_pfns); if ( guest_mapping ) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i =3D 0; local_pages && i < nr_pfns; ++i ) + { free(local_pages[i]); - free(iov); - free(local_pages); - free(guest_data); - free(errors); - free(types); - free(mfns); + local_pages[i] =3D NULL; + } =20 return rc; } @@ -799,18 +785,18 @@ static int setup(struct xc_sr_context *ctx) =20 dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); - ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); + ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); =20 - if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pag= es ) + if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) { - ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" - " deferred pages"); + ERROR("Unable to allocate memory for dirty bitmaps, deferred pages" + " and various batch buffers"); rc =3D -1; errno =3D ENOMEM; goto err; } + ctx->save.batch_pfns =3D ctx->save.buffers->batch_pfns; =20 rc =3D 0; =20 @@ -834,7 +820,7 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); - free(ctx->save.batch_pfns); + free(ctx->save.buffers); } =20 /* --=20 2.43.0