From nobody Thu Jul 23 22:26:30 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=1781874352; cv=none; d=zohomail.com; s=zohoarc; b=FoL+MCTDrLfrkLxQrlOoh0Fw6WgJeVPFZbXlMcFyUf9st3lsV5Ze3GrNGULLrn/l7kIpxaWeSp1MUWq4IPMWJMUjmUhGww+ChJ7qHZK1UYV6TJ85Em7sf7GTJHmTve+xuxasgSS0pwDoTBq3kuRtQR8NVCpwi3NBSBUMcskJI98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874352; 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=eks+QTXUKxWGNd1IHclIX8XrRU2no0CF3MdEPRLJw+0=; b=idQ37c+ptG1TLDycCZ1iMnrQ2kEfv+FWIMwInWmFayNptccEmt9ZNB5AaLixuZjyMoDDCuE3TFRt3jhOnrZ4HOo1+BMN82UixuGmnGgRlDinyLv8JCxCo+w6QYuWMMhMKH3YlMfvfWDy/bI7vCKpagtyn/f4qJPKcFZKlHNNv+s= 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 178187435259851.21661949290501; Fri, 19 Jun 2026 06:05:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342198.1602409 (Exim 4.92) (envelope-from ) id 1waYuI-0000VO-V3; Fri, 19 Jun 2026 13:05:14 +0000 Received: by outflank-mailman (output) from mailman id 1342198.1602409; Fri, 19 Jun 2026 13:05:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuI-0000VE-PY; Fri, 19 Jun 2026 13:05:14 +0000 Received: by outflank-mailman (input) for mailman id 1342198; Fri, 19 Jun 2026 13:05:14 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuI-0000SM-4c for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:14 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuH-00D4ah-Hk for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:13 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e84-2eae-0a2a0a5409dd-0a2a4501e918-36 for ; Fri, 19 Jun 2026 15:05:13 +0200 Received: from [209.85.167.44] (helo=mail-lf1-f44.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e89-e031-0a2a45010019-d155a72cb5df-3 for ; Fri, 19 Jun 2026 15:05:13 +0200 Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5aa7a7ad475so2320038e87.1 for ; Fri, 19 Jun 2026 06:05:13 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:11 -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=1781874313; x=1782479113; 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=eks+QTXUKxWGNd1IHclIX8XrRU2no0CF3MdEPRLJw+0=; b=CUF82vpzrIRaM67u6h/5yG19LfjFrnadlta1l82k8XXooMzgV3Tyt4pGdZjwck2t0e 2lZCLPFSlAr2bz/wq3JqMWAYryFBx6oINnacAI0+Il+N/WruN9m8t5uIrmuf7sPU5gg8 YVLCY+AU5MkkqerwbgwF925MqeZQgmF7yUQsGibOcgfwgGG0OHjhvKXM7YJPiMvCzmnl WHh7sVrsCsqBpQktlAsv3CYKhwcb1ZrZ8qNU04zy1O2RfB+aKC76er34383ZQEkUJrv6 LeDtxQj4xeydGj40cy7nEtn+wniPPjCJkYQ+ogikbGG12ANsesbgiuQnQ0ZerUcaduOF SQuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874313; x=1782479113; 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=eks+QTXUKxWGNd1IHclIX8XrRU2no0CF3MdEPRLJw+0=; b=a1ouH964rDB7CN1Gjt6QXsmPiuQcNFGnOS+3scoJWFvND3VbnJtlXu2zzmE7VyGZ06 jkBAe3oBnr6UyhAY/8R6BM+KUrMt/Pp39crwVSH7S6QCLalCdmyYRE6e/EZK8nvjlyXI 31wh398mjjS8zKsswc+qreyAosMsHUJjvW8+swNa52PTwqo/UxEfElALMxGmlouvHTla xUTFLIOEgW/bL2SQf9SorZQA5eKyEAP7lx2ImQnKqZrH5bfQmO070HZPD6IW0Ew5tvI8 QbUzLyyYRTNTih1MFhazx9XsDabk4RwPSA+EgonhQDboFv0Ke/BsqEAqgjn0zq/fMTXe /NMA== X-Gm-Message-State: AOJu0YzZ6JEbR8m7TILparin0QXlX3z7QpfoKqZemHsfMqqeGZMrMfgn mBVh4Dt9srwLbnYoYgF3lVa03dEdH79XYSq3RWGfxfp8SwW4dQNjMUnDLhraELMRLR4= X-Gm-Gg: AfdE7ckahCQg7bXZRvMvyYZCgCNrBbpezLBMD5iw2YDYD0g3XYrXuy2fVbtRNwgg1ex DKea+KNbKXFLTtldzNXoFnWdNCMCB02N+oilvpkx/cI3FQ6MbimxK9N6PvKgl11qGS9dGkXAX/L Mzmr/FKklwtpVj3MDM4LL7eE4VAW85JLC34lVapCwJK6uzlh9l5FHARp8aOygwg/bo/GnUZxAMf T+QVeCTyXTrvvXdngEefTrvJH0BuxZ6nj4rdXE/AQdabDe3nbawgHmn0aHb8lZ1e1m4mgjnn8IQ FQOMGpWQjJ+ioOJluEOZsCxwOj2hT7W/jI4DGsCiOISYxzFSfjaEqQZawrVp9YQrGZpYY/sOIQY tXGG46rxq2uaW5B+6lg9zY+sGTU7CrHvphiJO7m9i0USokghoe2kSYUr2v1md4yP4Nt5dWqB2OP vzEn91u9syntj5dWGQXeEyt0Dhl5Qq9/X51Gu9Eu0oADmEGWV+KI3r2Z2vM/kaWlsOBs0Kd8VxM Acq+eG0 X-Received: by 2002:a05:6512:3a93:b0:5ad:4cd2:9baa with SMTP id 2adb3069b0e04-5ad58f32ea5mr705257e87.27.1781874312427; Fri, 19 Jun 2026 06:05:12 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 01/16] libs/guest: Reduce number of parts in write_split_record Date: Fri, 19 Jun 2026 14:04:46 +0100 Message-ID: <20260619130501.272832-2-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1781874313-4B3A8E30-43106F80/0/0 X-purgate-type: clean X-purgate-size: 1825 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874353695158501 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 (it could still be truncated writing it in xc_sr_rhdr structure but the following check will catch it). The function become more coherent with following read_record function. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v3: - clarify commit message. Changes since v4: - added Reviewed-by; - improved commit message. Acked-by: Anthony PERARD --- 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 c7b3c6f3bc..9b2782b5cf 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[REC_ALIGN] =3D {}; =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); + 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 Thu Jul 23 22:26:30 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=1781874343; cv=none; d=zohomail.com; s=zohoarc; b=eadC9UcMgG8Z+VYc4pqq25Bh3mcycyUR1IiVJusKWXyqiV4sMbVAH2skjj1AieFguPBvxJOTsXFTjPjkWTvraf1bbK0NFiVT1h3urc2jJbnAy+Ay5q6xaHYV6+/36r3BP1ebo5brthdI4ikqcO+W1GrLLcXvLF+9f9M1jVS5Y9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874343; 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=KRsqYy5FIagth3/bGJe2ZNcz/9luhK+GkHhdLVALu50=; b=PFOmJdpcICoQZ93oXyqbRw7ZT4Wqfi0eHOWWkT9/2Y5dAsH1n8VTQLrAN4O7LEfM8zr3bYcwMc+FI38BCDoQXJ5JVMbVw6U5P6Mpj4/NfQD2h211w0qxK38xRxhIFJ4y2KhHnpEfrKlEwwtpuKgO5Q0FnKpAcRbNhZL+IfRelXY= 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 1781874343508199.26788217041747; Fri, 19 Jun 2026 06:05:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342199.1602421 (Exim 4.92) (envelope-from ) id 1waYuK-0000s3-21; Fri, 19 Jun 2026 13:05:16 +0000 Received: by outflank-mailman (output) from mailman id 1342199.1602421; Fri, 19 Jun 2026 13:05:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuJ-0000rw-Vo; Fri, 19 Jun 2026 13:05:15 +0000 Received: by outflank-mailman (input) for mailman id 1342199; Fri, 19 Jun 2026 13:05:15 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuI-0000Uh-Ud for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:14 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuI-00D4ah-BQ for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:14 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e89-2eae-0a2a0a5409dd-0a2a450ba98e-2 for ; Fri, 19 Jun 2026 15:05:14 +0200 Received: from [209.85.221.43] (helo=mail-wr1-f43.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e8a-5e53-0a2a450b0019-d155dd2bc807-3 for ; Fri, 19 Jun 2026 15:05:14 +0200 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-45f3cf907ceso1063197f8f.2 for ; Fri, 19 Jun 2026 06:05:14 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:12 -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=1781874314; x=1782479114; 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=KRsqYy5FIagth3/bGJe2ZNcz/9luhK+GkHhdLVALu50=; b=T3QGMsHtEAeaBPGJ5cPRb3HtTnEY8GXodqE4MMKEiLV9ETuolHi2aMQWk7I+4aiGsR tPWVNr/4ImgYypc6LVeze3gMKH0uvJ2AGKPAITt0NTLC1sVAa9DCtEfNiG+vp4AuB98Q nHqI4xeLFO5jzoW4cGiTs7KF3h5ka7gUYDVBdwu3rgprdRbuaCLxwk95DLUW0g4uPn9R MdnPTO+FOUK96wYeFh5EBfpEY5enH+oRKrOaNt2v9pN+SXSND9YpU+VcSA5kojARGhy3 E9xIJKOMMvs5bcZNLNY9QXFMj5K83kNrrSMv8LRSlmE+DR1c8zcrQovT871GECLQrZCs R4JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874314; x=1782479114; 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=KRsqYy5FIagth3/bGJe2ZNcz/9luhK+GkHhdLVALu50=; b=ZwDDoHaNyaHmBwJk43UJMBNtjDQ8As9L+t3Bp1CobUk/d6pWF3poDXD2COGr1wOXNs ygPEzbLd1kvKIA1dqzs2nQtjScYS7NqyPSdScFJJ3z5aBFpq5w7hg3AlYjC/X55N6fNT EF15CDh0wL+YwUnnHSqQqKJhijERQh1LbogJoO0iqpTUq9KYvxQ4S+VZjEZEkD7T4Hgc 1vQAQTsdnqaX7McV0FiAuM2o2NCSdBo1/Qadw+6YqaQmAXh3qFhgmDKqLGDwu9M5xMG9 1H4loOcludX0G4wgODw29VCjU+2Ipkr6FOkuazS5UJKOJKeP29+ysu8eOl4lDTEJPoGH tgrw== X-Gm-Message-State: AOJu0Yw7s2MeeSq58KFnVn0BzMsJC4XgsF4qtQwCZVE6hHM3gUNHgHq8 UUrZe7wiuFm/bwp84wF7wPTtLQXoRe5qIqSLNADNOE1rmweu+quTQhCuIDfXpittclk= X-Gm-Gg: AfdE7cmmaTbpLSE/Hx6/qBM/8VxmvLXy9e3GMTYJPg5s71ghk0/yncfEX9O4KkKpDEM +uO+JmTbwfnNNqWrHcReGSEy+dGcE36Mmig3ClVwJzT9Sz0c8qdKahoaTmruk++HkxurCr1pzvd 9jyg1EpGyNPxM5ajOjN5r/BQYXlm/Kvb27PlO3edyqwiX0rtqCcC7TMUYs1vpw9Ony4FfqzWHwY yyvae/zaOTFTrtvdEUAvq3cUz5iZXeCVo57T4ZUwkdORHh7W09FU67tk37OqVmMG85DQwTWE8TW f3oHFb/t+QDS8Q7x4zLyN7dhRplVBS2XJ+cGT/iWHLhh/EkD57sXrfT5jxQteMONr/02mS1LGBN UCoW43Fe5IC4AX+WdNEPQuyiN/2eyN4xtwlSD775uBGTIIKTi5YiT+gUZgBGpW514kQruLi6HJ/ Klc17Z6iUsW5uMNT5Kb8PVUJBTDht/5DbBD3ptR1bRiMt2zOgYoBrzB2J2THrWH3cyXTcmFSvKP Av1geBl X-Received: by 2002:a05:6000:2284:b0:441:1fa5:457c with SMTP id ffacd0b85a97d-464fff65dcdmr7069984f8f.5.1781874313503; Fri, 19 Jun 2026 06:05:13 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 02/16] libs/guest: Reduce number of I/O vectors in write_batch Date: Fri, 19 Jun 2026 14:04:47 +0100 Message-ID: <20260619130501.272832-3-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1781874314-4C1CA00E-B0ABB76E/0/0 X-purgate-type: clean X-purgate-size: 2646 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874345500158500 Small optimization. Reduce number of pieces passed to writev. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v4: - added Reviewed-by. --- tools/libs/guest/xg_sr_save.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index fdbceab52e..68ce1aeb98 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -97,9 +97,11 @@ 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 }, }; =20 assert(nr_pfns !=3D 0); @@ -115,7 +117,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 +218,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 Thu Jul 23 22:26:30 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=1781874356; cv=none; d=zohomail.com; s=zohoarc; b=nOKXTbYPje+jGWuUSWpx/Xr78aGvjDAitx/zeJCtDpt231dOM/exYVb3OzygG24R9vw1fBkHuzAil1wiikTj+QHA2rRykOj+0qPUL19ToKP44/nwjerLe4WCrEKjo10L71+Lmu2HEcnJPoJ6NVwKIT0kCbVaQTOOv6JBhCf+LRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874356; 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=YoUZP7EcTD3rMLem/j1Uq6cYO1SbjM2Ab1ems5g9aQQ=; b=VnZwf5P9m9MY3DR7AIaIzaRwMrf93+zUym5gUl0K8NxAcI/9L2mea7mG8AlAGhaR5Y6lMgC/PJYBiEgIJLMyvk4SGBVgIpGapBb8hI+AA2zif4zBgKZ2jnbs5F7T9p+uiQKU7nYWMt+KoJ+ewBqVeGyx57PjG28ZAHZr1MpVwLU= 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 1781874356249311.04359154564327; Fri, 19 Jun 2026 06:05:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342200.1602432 (Exim 4.92) (envelope-from ) id 1waYuL-00015B-Aa; Fri, 19 Jun 2026 13:05:17 +0000 Received: by outflank-mailman (output) from mailman id 1342200.1602432; Fri, 19 Jun 2026 13:05:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuL-000150-5w; Fri, 19 Jun 2026 13:05:17 +0000 Received: by outflank-mailman (input) for mailman id 1342200; Fri, 19 Jun 2026 13:05:15 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuJ-0000ko-Mz for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:15 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuJ-002qjr-3j for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:15 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e83-5cb7-0a2a0a5109dd-0a2a45059ba6-46 for ; Fri, 19 Jun 2026 15:05:15 +0200 Received: from [209.85.221.50] (helo=mail-wr1-f50.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e8a-ef3d-0a2a45050019-d155dd32b062-3 for ; Fri, 19 Jun 2026 15:05:15 +0200 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-4633193af19so1587922f8f.2 for ; Fri, 19 Jun 2026 06:05:15 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:13 -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=1781874314; x=1782479114; 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=YoUZP7EcTD3rMLem/j1Uq6cYO1SbjM2Ab1ems5g9aQQ=; b=gDrtqXYS9JD8WO7AefvaC6RIA1OQ+4djOF+Ysp6NwaiGn2NQXjcClwJise1zdMCgj8 1BKwSLsSXrbjqzkdCxpkphja63gg0Zt2TYgR2iHYA0cWrLrzCVxAwkhCLXdJ2AflE7L2 RDHh7ZIzXI57+eyYCfGgbAWJekpW6T5fOBmu+2eA5QcyDtGShJH9mi3cQ4OmJvWgLs1Q L4MfZiUmkiAEqqkPjmshyyH3SEuNCx/UFxwqsQfy+LcPXJKQ2bRRRRjNkASv+edsr9Bg NjXyf+3k34p1w2xVuL9/OF2MX8iMgFXyEX1cgli/CbX7mc8PyOEaoQh49otFonDcFz0i i7Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874314; x=1782479114; 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=YoUZP7EcTD3rMLem/j1Uq6cYO1SbjM2Ab1ems5g9aQQ=; b=CwdzG5/ws97yexHhXIvm3jyMVranlQMNppqZvJyuJltrKbO0FbvqEjg5MZuSVRD5vE b+4b9PUQr3dvz4Bt74HjPApw1Y+6TBVsniqDt0swi7kXqBSnn3clpBGDmyrWWvexLNcC vJvS9KIjQabxJGXe04Y54Ymclils2eeLBUO9zXI2U+sSeBn1NHfmXidcxNdfAzIjAtSk 6gnmqGXtcnJcHqpWOZrLyLI1I8ldqTwkM4FN3rZj1PDr5KIOvqZZbFzW44oH9vzHJL6F MLJdfBtOty3kt2mAVto/3uya0asMoy9ncgCeF2VArYiZeKKO0qZcy8cnyp4W29Gx02dI uJBQ== X-Gm-Message-State: AOJu0Yy2is9VDBF86Nc0fbLM9DcXZ4Ej36HNlfJdofFo06x+0O3grOgU kJUx9uyoUYwp3Ky6a02WlO2SaUUQwGhagRZ7+xne3N80ocNTTRLLqXsWilrTxTUfnkc= X-Gm-Gg: AfdE7ck5Qwr7JMn0WKWFoKk0daM41B2h3d0NsrBj8nc8h3X3UP1YVp7QVrQgs1bZmwt ZVtsNIvUKIwlMPTNw6ByDNV33jSRwsQ6guUm20fx5fl5vUmWd3vP8dJAjMVh+ndf3EPhv3GSl71 cXN76iIEJR69622p5g/dQ0OHd0Iz4J9jFP0XWnkPCB1WEBupoF95HETmPi0r5lGhnM3N962Y7kZ T8lTYSGJZ/mPpyloHWgAjLXMG9t5gECOi6W4hkK4n5NhQ+kWomT+jjl7k2wmYuJDzjWDpawRmN4 tvg70ctHyiIKD1KQBaahI1OieUluToyL0WMIw8dn0uf9N/WiXasB3LhgCj+IDuSDvxMDFd2s5mw TI6ZqDT/k+hZHp1JZEmVqo1p9aN9CjeNYHGZRr9Obv1qWBbXHSK5ZiGf/GyPWIiGHxK5353GPVf 2K3ZqYsmiKwI3o4lo9vS8FBLfPtvMWdzQh7ujm9wIRReuSZ6p7UESqtAMQCLOwIW5XxsPVNGWBW mOlgrG5 X-Received: by 2002:adf:f9c4:0:b0:45e:edc8:d440 with SMTP id ffacd0b85a97d-464ffa95327mr4426620f8f.1.1781874314412; Fri, 19 Jun 2026 06:05:14 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 03/16] libs/guest: Reduce number of I/O vectors in write_batch Date: Fri, 19 Jun 2026 14:04:48 +0100 Message-ID: <20260619130501.272832-4-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1781874315-F55C7127-4A357F92/0/0 X-purgate-type: clean X-purgate-size: 1555 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874357648158500 Each page was sent using a different iovec item. This potentially exceed Linux maximum (1024). Coalesce adjacent IO vector elements to attempt to reduce the number of overall IO vectors for each operation. Also some implementation (MiniOS) emulate writev with multiple write calls. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v4: - added Reviewed-by; - improved commit message; - minor style fix. --- tools/libs/guest/xg_sr_save.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 68ce1aeb98..eba33f861a 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -239,13 +239,21 @@ static int write_batch(struct xc_sr_context *ctx) { for ( i =3D 0; i < nr_pfns; ++i ) { - if ( guest_data[i] ) + if ( !guest_data[i] ) + continue; + + if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len !=3D + guest_data[i] ) { iov[iovcnt].iov_base =3D guest_data[i]; iov[iovcnt].iov_len =3D PAGE_SIZE; iovcnt++; - --nr_pages; } + else + { + iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; + } + --nr_pages; } } =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874347; cv=none; d=zohomail.com; s=zohoarc; b=apQytz6Na63hfMCKeEIICGNLXmZRwSjUbG7yLQltvrTotX+WNUbRlNszNfAYIbiLNAO5HOFfaOI3/3TmWRyRpkqURgFiOMwoc4rew+OxJcYh3zJPZRBrlN3hT4hblPTQtiMeh+oEX6qNa99ejoR8lj5rm6MrIcFEl8035wU18HM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874347; 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=qiBtoR80avPCt1Z1nhixmjeXxAuRwAb8Srdl+oua2xY=; b=ZaUtkFNjIPm/e5CNBSmlmw+kyBwkilVCMqRz/ZQN1qCEQ4HjuvIpH0/+QwAPtO7V7h4DfuPfJ8XRQxh1cdhwq841Oh7oCVCX0Erx9wn+xYS7usQJxVyISiij/7Y5gTn2vq0/Kl+7Te0ddZ+jMdyOoKdgMvAG6KuLBim6lJ678Tc= 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 1781874346896310.5608362289196; Fri, 19 Jun 2026 06:05:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342201.1602440 (Exim 4.92) (envelope-from ) id 1waYuM-0001Ib-FF; Fri, 19 Jun 2026 13:05:18 +0000 Received: by outflank-mailman (output) from mailman id 1342201.1602440; Fri, 19 Jun 2026 13:05:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuM-0001IP-Bj; Fri, 19 Jun 2026 13:05:18 +0000 Received: by outflank-mailman (input) for mailman id 1342201; Fri, 19 Jun 2026 13:05:16 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuK-00010L-QY for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:16 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuK-002SWY-7E for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:16 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e81-e002-0a2a0a5209dd-0a2a450cb548-30 for ; Fri, 19 Jun 2026 15:05:16 +0200 Received: from [209.85.128.54] (helo=mail-wm1-f54.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e8c-94a4-0a2a450c0019-d1558036a8d0-3 for ; Fri, 19 Jun 2026 15:05:16 +0200 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490b8ac62baso30805015e9.0 for ; Fri, 19 Jun 2026 06:05:16 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:14 -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=1781874316; x=1782479116; 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=qiBtoR80avPCt1Z1nhixmjeXxAuRwAb8Srdl+oua2xY=; b=RRVipjTU7RYi/Ez12IBJ7rRmLwtoz8Z8zGgAv0jVbxt1y0obdx7037lkq28051VvI4 pvGWJp4rW6Gix9noY6qBhwyVgK+JBJwYAcju1zg3Y+T9cmEMd8fJEaMu1O8TqyI+ULQ7 UWeaAFTT+pz+9zbbRi3bgu6/iz+rYgmKfmvCM4bnFpPuyiajeQMkKPRZSp+hfAGrmiOE N7N4IOPM4u/n0abi+8NsxjCj4ebLy80LzPXY85AvN6wGXkH3KDrBtNaT4yYNpmCZvtZY fRAP0GZU9TJGi03kIjI/obSOa+AvDU/1IPI54wcv2KptrfPsxlrSZRqsFN7DfrYIl4gM HZAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874316; x=1782479116; 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=qiBtoR80avPCt1Z1nhixmjeXxAuRwAb8Srdl+oua2xY=; b=PRxWGHJS6izsb+7yfcGYisx3UA5w1a5HciMmXJEk9Nl7EzqV7y6N+IKYLI96/LU1CD /zmtlj42V2NUx0MFJykqeTrx57ncz/wJA5bXjsZ1N4/YDKEmfXYYMa/3sOG2grjR5h6u zn+fUUvtIqF14gW7t/bWGkw9HWLXHoijVJgnQMDJRmv/ixw2IUbOCLSQFMJkjKrYa8rH 62hnkSiFVHeUMbE0xE0hJuijH0BKf8LVDGklz5dB9tyvIX3iQd3DpoesXrv0bpnELNiv eyQi6i0AinFnbbhJQrgY826/vlSI/1/+WO+E39pA0vbtAnRvzGtoW5+63WBPgP3bGQaL l2uA== X-Gm-Message-State: AOJu0YwIPTyqFdFL3lydK7eu6EEDDiwMLlSxGGAzM7pVhKMul/j7N1+z xYxv1lrOPrdJGVl9Np5o6J8Q8zE444R463JGFpQ+EtRq5W7YFfxEUcwq2e/FyNe1vLg= X-Gm-Gg: AfdE7ck4hAwddxVgXwcMACLGTGzTqTnNlhd58G+NYLSuOYKw8oeO2aJYUYFEFSJxvVd gtYs5PLxpEQ8VUFVMPgmqaRFWzsTcFce5N0YPRHyj0BBd4IHgnNW3rFCzNjc2vUCFnzqHhCsERj D6oviK7sqgvDKAewSgShTOOZgabFtIeXypbgrH+QjIi4w202zswn6jfrE565nUKVoAHKlhULVsm 5STQZVXm1jD3FG7EWzPmFNND8WyeyCyUG5V+dK15X+VZKnCq2JdwSyw69z1hlS015m/Bsz7q4uu O3hu2oYv/kDZDVeNoAqzA4FK9iU/rc4vXJa0n7BXWV0JLZR322NhrGMMgsKagoLwwvnXThYdFMC he8HYWJ55IsYn1/l+6grZ4s36/4bEOzPVS2i1OPJYgdgxWopxvX5RPDFlX6CAR9kJQh474UK37q hADwlgbFFy2nF0Hgqs0G1TJPkE+DJrLA8PSN7wTZNSEYXTbjCtppfdaRhlUZgb8Cg9T8FgqoxjL UXXHyC0 X-Received: by 2002:a05:600c:c04b:10b0:492:2ffd:8a74 with SMTP id 5b1f17b1804b1-49240a38ba5mr37619195e9.12.1781874315336; Fri, 19 Jun 2026 06:05:15 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 04/16] libs/guest: Use a single write_exact in write_headers Date: Fri, 19 Jun 2026 14:04:49 +0100 Message-ID: <20260619130501.272832-5-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1781874316-D85F8ABF-855B8CF3/0/0 X-purgate-type: clean X-purgate-size: 2400 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874347748158500 Reduce number of syscalls by coalescing the image and the domain headers into a single I/O vector array. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v4: - added Reviewed-by; - improved commit message. --- tools/libs/guest/xg_sr_save.c | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index eba33f861a..8c31f9f86c 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -10,17 +10,22 @@ static int write_headers(struct xc_sr_context *ctx, uin= t16_t guest_type) { xc_interface *xch =3D ctx->xch; int32_t xen_version =3D xc_version(xch, XENVER_version, NULL); - struct xc_sr_ihdr ihdr =3D { - .marker =3D IHDR_MARKER, - .id =3D htonl(IHDR_ID), - .version =3D htonl(3), - .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), - }; - struct xc_sr_dhdr dhdr =3D { - .type =3D guest_type, - .page_shift =3D XC_PAGE_SHIFT, - .xen_major =3D (xen_version >> 16) & 0xffff, - .xen_minor =3D (xen_version) & 0xffff, + struct { + struct xc_sr_ihdr ihdr; + struct xc_sr_dhdr dhdr; + } hdrs =3D { + { + .marker =3D IHDR_MARKER, + .id =3D htonl(IHDR_ID), + .version =3D htonl(3), + .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), + }, + { + .type =3D guest_type, + .page_shift =3D XC_PAGE_SHIFT, + .xen_major =3D (xen_version >> 16) & 0xffff, + .xen_minor =3D (xen_version) & 0xffff, + }, }; =20 if ( xen_version < 0 ) @@ -29,15 +34,9 @@ static int write_headers(struct xc_sr_context *ctx, uint= 16_t guest_type) return -1; } =20 - if ( write_exact(ctx->fd, &ihdr, sizeof(ihdr)) ) - { - PERROR("Unable to write Image Header to stream"); - return -1; - } - - if ( write_exact(ctx->fd, &dhdr, sizeof(dhdr)) ) + if ( write_exact(ctx->fd, &hdrs, sizeof(hdrs)) ) { - PERROR("Unable to write Domain Header to stream"); + PERROR("Unable to write Headers to stream"); return -1; } =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874353; cv=none; d=zohomail.com; s=zohoarc; b=FPEXWDGZ5zkA8vVwhsr6Ay3sdz8B52rCx1fA9EEx+w+iyCz+Mfm0IOpN5gGjQl22VW7XKhcBbQddkI4srZy7afXvN1UmxNNFgKJakk64BXpzshcsjUbReq2z6x3xQlF5xe6Msb+/Jz3RPSOT1uVLL88EkFKMwy1oCIfVl3f0cbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874353; 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=aDpOdhu2pX3r4tDQzsxVRLFNGhGBpjSsL2fSh51Ah0k=; b=RqfmFJ0mDJEISlKNf74H+AsG5ce4Xo2fN/mwnxK2fmwHu6QIaxUQX+My+O7mQ4vc5lhUhRg2DChiRQTIT9qtWfj0PwEPYjoyzP8d3+9cGEPM+/0gokrQyiD4M3RreRpY1IADL/bEMjkvwhnk0233FfRaqvNVHiMvXfaqbEfngBU= 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 1781874353903498.15208437455135; Fri, 19 Jun 2026 06:05:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342202.1602449 (Exim 4.92) (envelope-from ) id 1waYuN-0001Wq-Py; Fri, 19 Jun 2026 13:05:19 +0000 Received: by outflank-mailman (output) from mailman id 1342202.1602449; Fri, 19 Jun 2026 13:05:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuN-0001Wj-Lu; Fri, 19 Jun 2026 13:05:19 +0000 Received: by outflank-mailman (input) for mailman id 1342202; Fri, 19 Jun 2026 13:05:17 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuL-000193-Lm for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:17 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuL-002SWY-2V for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:17 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e8c-e002-0a2a0a5209dd-0a2a4503d912-8 for ; Fri, 19 Jun 2026 15:05:17 +0200 Received: from [209.85.221.41] (helo=mail-wr1-f41.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e8c-a3da-0a2a45030019-d155dd29bdb9-3 for ; Fri, 19 Jun 2026 15:05:17 +0200 Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-45fe59255beso1163686f8f.1 for ; Fri, 19 Jun 2026 06:05:16 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:15 -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=1781874316; x=1782479116; 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=aDpOdhu2pX3r4tDQzsxVRLFNGhGBpjSsL2fSh51Ah0k=; b=OoMvaPy+r5KQU10hGeOBLQ2OcyB7PQesJW1S0QFhZOW1NFXlytoa8+z0buRhYpOyk2 4ALW/4l1cVg/Dc/7BJ4v/aEcunQkS6DCL6srtziD2649FI4yrQRJmsbrBCsOgvrliz09 qBf/7P0cB7+pr+pdx6ejZLAXwj+jwe5IuKEW5fV7cADidRgFiX3474/lyJFjFpTYCDiR d15xDjbWOXZ+ZKQI5r1hSdTGx1ViPiJw3FuzqVIpqK7Iz7PfjI7LJ3H3+eo5DSz/q8oa 1YGXyt5c2ZTfZEQeMAojdiE3uUzAmwXu9p0AyrX3H0D+w+b1g81bjRsRVLOalxN3IaIv egFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874316; x=1782479116; 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=aDpOdhu2pX3r4tDQzsxVRLFNGhGBpjSsL2fSh51Ah0k=; b=YMP+HoitVa3f7ovgDyOVhqiyI1nr9tNNNM8IYOS9D5hjU/sETuCmgS2lrfY1DuVfW7 0CZrkmfCB6Gc0//zJG10++PlI14F6oMqdD+JWMPLIMIVmp/FQ/Lvz1AKw8NDT04lAK7q Bjva92ZHGCyJs8JPqDfPdDtjgOZ5jm8q6xSYpylQSF1QU3P9toVcSYVEGgV5rFsFIkvr TYikmlHOFDKeCBxVtb66z2h3ZZlko8IyAhzNZUG6I1EdaIpdT4/NVMbbW5Qeaft0bX54 MD6zRZzcmdHPH7Isx92c11HvfyzDKm243Va+LcfFTNaoJ1k4jj+/xObEmxyxXumdfxPl LsaQ== X-Gm-Message-State: AOJu0Ywgn7AKzuJs2gyT4MK886pN5iFJX9gwsFY3mk1QU5pnZJswdccP 7ejUltwygoKde4YgjHNyaDyWFRmmJnD+dvt+UM4Inp4KYQULpoo4A3CI9zrbTHW26mg= X-Gm-Gg: AfdE7ckDbYm2/eo0Izmklok/Rlw1YJE8HpuuadBLxWPk5C09Miq8DQ8LAW/h5csI6mm IXv1lMeLph5W0RaNpBW5p5kk3s18NhAByGcnOIGGswVRRDHo/izgqevhLU237Hzc/qNcU+bKoEK IeN9j+8eMF/pOUNrNxSFLP0u+oRZe11rWTZl9gOqDRjCVS1B2+D6OMjAGD10RRNeLW+NAfaOSNG Mzyzs+wNErxrFjQ6ef8daAnwWox1ZLLlCulkUvFySYvYa17xKfPz7YwvbhrFTidXGecCpnZlAtS dtctD5iw+R7zx/etd61NkHKYdA6ASG2/n416GCtPGazxLSEtYXeBE/6dcc8DB09oZUbD4bAkUfv oY5+1yelFAVIlZyVQTnp2ESmY72ZVr9fky5DRbt4pOUNwmfmusrUjRbDGJJfan+JtyK+EhWL7aY x8l948sFmSyEGylVgbqcpjeiVMP21upjXXoiOV+n0edf5BflnZTbXWKhdjA+LqWHtcNXoGtyYg/ J3/HoDsJb+WlSG9+D4= X-Received: by 2002:a05:6000:1888:b0:45e:df46:ba30 with SMTP id ffacd0b85a97d-4656fe28662mr3677057f8f.34.1781874316343; Fri, 19 Jun 2026 06:05:16 -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?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v6 05/16] libs/guest: allocate various migration arrays just once Date: Fri, 19 Jun 2026 14:04:50 +0100 Message-ID: <20260619130501.272832-6-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1781874317-E31DDD84-B3F682C0/0/0 X-purgate-type: clean X-purgate-size: 6557 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874355744158500 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 -- Changes since v2: - change prefix in subject. Changes since v3: - fix comment style Changes since v4: - change order of fields in structure. --- 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..95b0564e5c 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]; + 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]; + int errors[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 8c31f9f86c..4988d8040b 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -86,16 +86,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; @@ -104,26 +104,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 ) { @@ -209,14 +207,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; @@ -267,17 +257,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; } @@ -806,18 +792,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 @@ -841,7 +827,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 From nobody Thu Jul 23 22:26:30 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=1781874352; cv=none; d=zohomail.com; s=zohoarc; b=Hu7aZxVlTuXwDetJuPpluQCyR8DOJEeqWjvH5m8KV9W7Vrx/SWPjMjkdu+yQ5IbkQEaLF7nfPSZ5jEMGAn09TGg4uo6pz7XHYl8mXJwE1xoDfXLvLfsIgGT3PWWy7Z/QP7N6JYAkLgT1tkNyVQCXqZ+fbaLGEzTVFJDsFCjsQjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874352; 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=LON6WS/7+ITaf2v0md0IGTaQ3vNjQONNtUw2wlhSSko=; b=k9VPz4pgIWdsEBCLUQe7lUebRb9qqNbtb3fzdmhaylonNR5PvcWvDX7NDeRvhQvxCLTJaWPtooXufs42zHSXggferLeNVTzbXC9doeQF+bREgYxXw7cJrVeZplr2RVkYGCQiuN4ORNs3eLA1bf5MrJY9wEJ173VDz11CDgbEOyo= 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 178187435256697.83706480463559; Fri, 19 Jun 2026 06:05:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342203.1602454 (Exim 4.92) (envelope-from ) id 1waYuO-0001Zl-4s; Fri, 19 Jun 2026 13:05:20 +0000 Received: by outflank-mailman (output) from mailman id 1342203.1602454; Fri, 19 Jun 2026 13:05: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 1waYuN-0001Z9-TJ; Fri, 19 Jun 2026 13:05:19 +0000 Received: by outflank-mailman (input) for mailman id 1342203; Fri, 19 Jun 2026 13:05:18 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuM-0001IY-IX for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuL-00D4ah-VO for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:17 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e89-2eae-0a2a0a5409dd-0a2a450ba98e-20 for ; Fri, 19 Jun 2026 15:05:17 +0200 Received: from [209.85.218.51] (helo=mail-ej1-f51.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e8d-5e53-0a2a450b0019-d155da33d157-3 for ; Fri, 19 Jun 2026 15:05:17 +0200 Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-bf046d4da1fso238465566b.3 for ; Fri, 19 Jun 2026 06:05:17 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05: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=1781874317; x=1782479117; 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=LON6WS/7+ITaf2v0md0IGTaQ3vNjQONNtUw2wlhSSko=; b=Dm5jFFQVU/eqX19fhC+wCPrEtf4W8zqXGuZ9Cm5aWsyPEJDfgfWO82XN1bLMqrTFTl PDbKTql8gX42EngAIccDxbaKUDs1eWQnoefr+fEvuoN5ljcWKgBkRdiG22Mkzwqy1IPN u/j8WgAgn9sbiyyA5qlk9b279JjtQRz66VMH6igHA0Ap4ro+KvphSbBYf4Hj0Q14Veas kh9AIkjTBwGe6LywNQSVYZKFymc7EWQTU5mpmijLP/B+HUX4SpMtlcWMi/ry92mAJhwS 7GsjiCfKNRcXpK5io6xYLPe4QK7EbM7bC/0j3FYrVL+7EOQrkc1viwDPBy/jdv2v6hV+ ByLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874317; x=1782479117; 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=LON6WS/7+ITaf2v0md0IGTaQ3vNjQONNtUw2wlhSSko=; b=DOXUuL9igFzyN/yMxKeZa3lQHMVvLte0KEveQMKymCijxd9/j8KGIHOavtw0znnFI8 zq7JkSsphJLzl2k5w13i5b0TnENBq6Dnngh/8eT2d5/L4K7av2ChlDrjjDkvdt/JDWSu ESJoGSKZnlAcSpHHcGdVd/3p9skUTcEm9sd89P5PsitdQHqyKzOcQeECwEJR0lok7Axq LH0GVlxsDhFyHh/btjygtFqznItnFiMDeN7FCKAVzSGbv9meDApmhrsGOUl5DhScDlPT 6UV8NMkAZOUUM7zzYX9r2KTi3vltRCUuiTe2mb3usz14nlwpIRsOnc84mddZZk+iQUXO tscg== X-Gm-Message-State: AOJu0YyXug9FrIqMBqdcXhm6w/PFyu4M99mbcUfdqe9mWU88gh63bDIt 8B9gk/VYJ0GMswxLeJN11g5xpXdEx4ew7ZHLclqfz4bGSg7L7KTEGvPmjR5kJ37CFOo= X-Gm-Gg: AfdE7cnOWngltfRQCBPquYKCtOKq1CRiRlDF25d8s2BdiQpSad4e83pwcXMrqIQQdTJ 4VWsb3b7khkujy0oekF8xVKZMV1JljXQogHuEQKdqJQWPE7661Z8Sv7gMvIJRoWdrBJj/3cjw3c 7mnUTb/MimpwbF+tIVE6aznMi6GDqZrhNGnl3YxNvCBEPkksEHUp4J3VTKtBJzdgz6LiGG/Pmi5 /U1gld8e37OeIZTYZo64sKusunpdwlwcVebaChF3OSYXbD5OP3dygY/hfPoby73fCh2EAzeY8Pz t4DPScLPU5a/agtcJVtXrz6hx3vAzW7i7JOPXctNjw7Us8GWTLaP3IL8Ej87eMuiQiRUR8P+lny ynpL3Zs2hXUnkDkEspiSYylAbKYQEBAZdjs1QoOb6SF+69QrvSum+upQlpTthJBWssnGNLGi1ch 26pQW52/MoSrnuZ8Mw/XEIVJS1Dy8Z5ePsA02xzmwS09kc+XXL/pt2zgwRXHW4GAm6JhI/wkKJA Agb5GRu X-Received: by 2002:a17:907:c01c:b0:bec:687f:6603 with SMTP id a640c23a62f3a-c097c0af677mr190225066b.28.1781874317370; Fri, 19 Jun 2026 06:05:17 -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?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v6 06/16] libs/call: cache up to 4 pages in hypercall bounce buffers Date: Fri, 19 Jun 2026 14:04:51 +0100 Message-ID: <20260619130501.272832-7-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1781874317-47BEF00E-F9EDC5F9/0/0 X-purgate-type: clean X-purgate-size: 5352 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874353712158500 From: Edwin T=C3=B6r=C3=B6k During migration there are a lot of mmap/munmap calls, because `xc_get_pfn_type_batch` exceeds the default hypercall bounce buffer cache size, and needs to allocate every time it is called. `munmap` is slow, especially in a PV Dom0 (takes an emulation fault), so is best avoided. Eventually it'd be good if the memory pool from xmalloc_tlsf.c was reused here, but for now make it handle the commonly encountered sizes (so far up to 4 pages). Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. Changes since v4: - fix off-by-one bug. Changes since v5: - avoids potential buffer underflow if nr_pages is 0 calling cache_alloc. --- tools/libs/call/buffer.c | 31 ++++++++++++++++++++----------- tools/libs/call/core.c | 3 ++- tools/libs/call/private.h | 8 +++++--- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c index 155e4f9d43..2f0515c273 100644 --- a/tools/libs/call/buffer.c +++ b/tools/libs/call/buffer.c @@ -49,6 +49,9 @@ static void *cache_alloc(xencall_handle *xcall, size_t nr= _pages) { void *p =3D NULL; =20 + if ( nr_pages =3D=3D 0 ) + return NULL; + cache_lock(xcall); =20 xcall->buffer_total_allocations++; @@ -56,13 +59,13 @@ static void *cache_alloc(xencall_handle *xcall, size_t = nr_pages) if ( xcall->buffer_current_allocations > xcall->buffer_maximum_allocat= ions ) xcall->buffer_maximum_allocations =3D xcall->buffer_current_alloca= tions; =20 - if ( nr_pages > 1 ) + if ( nr_pages > ARRAY_SIZE(xcall->buffer_cache) ) { xcall->buffer_cache_toobig++; } - else if ( xcall->buffer_cache_nr > 0 ) + else if ( xcall->buffer_cache_nr[nr_pages-1] > 0 ) { - p =3D xcall->buffer_cache[--xcall->buffer_cache_nr]; + p =3D xcall->buffer_cache[nr_pages-1][--xcall->buffer_cache_nr[nr_= pages-1]]; xcall->buffer_cache_hits++; } else @@ -84,10 +87,10 @@ static int cache_free(xencall_handle *xcall, void *p, s= ize_t nr_pages) xcall->buffer_total_releases++; xcall->buffer_current_allocations--; =20 - if ( nr_pages =3D=3D 1 && - xcall->buffer_cache_nr < BUFFER_CACHE_SIZE ) + if ( nr_pages && nr_pages <=3D ARRAY_SIZE(xcall->buffer_cache) && + xcall->buffer_cache_nr[nr_pages-1] < BUFFER_CACHE_SIZE ) { - xcall->buffer_cache[xcall->buffer_cache_nr++] =3D p; + xcall->buffer_cache[nr_pages-1][xcall->buffer_cache_nr[nr_pages-1]= ++] =3D p; rc =3D 1; } =20 @@ -108,17 +111,23 @@ void buffer_release_cache(xencall_handle *xcall) DBGPRINTF("current allocations:%d maximum allocations:%d", xcall->buffer_current_allocations, xcall->buffer_maximum_allocations); - DBGPRINTF("cache current size:%d", - xcall->buffer_cache_nr); + for ( unsigned i =3D 0; i < ARRAY_SIZE(xcall->buffer_cache_nr); ++i ) + { + DBGPRINTF("cache current size[%u pages]:%d", i+1, + xcall->buffer_cache_nr[i]); + } DBGPRINTF("cache hits:%d misses:%d toobig:%d", xcall->buffer_cache_hits, xcall->buffer_cache_misses, xcall->buffer_cache_toobig); =20 - while ( xcall->buffer_cache_nr > 0 ) + for ( unsigned i =3D 0; i < ARRAY_SIZE(xcall->buffer_cache_nr); ++i ) { - p =3D xcall->buffer_cache[--xcall->buffer_cache_nr]; - osdep_free_pages(xcall, p, 1); + while ( xcall->buffer_cache_nr[i] > 0 ) + { + p =3D xcall->buffer_cache[i][--xcall->buffer_cache_nr[i]]; + osdep_free_pages(xcall, p, i + 1); + } } =20 cache_unlock(xcall); diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c index 02c4f8e1ae..dd8877c1a0 100644 --- a/tools/libs/call/core.c +++ b/tools/libs/call/core.c @@ -14,6 +14,7 @@ */ =20 #include +#include =20 #include "private.h" =20 @@ -44,7 +45,7 @@ xencall_handle *xencall_open(xentoollog_logger *logger, u= nsigned open_flags) xentoolcore__register_active_handle(&xcall->tc_ah); =20 xcall->flags =3D open_flags; - xcall->buffer_cache_nr =3D 0; + memset(xcall->buffer_cache_nr, 0, sizeof(xcall->buffer_cache_nr)); =20 xcall->buffer_total_allocations =3D 0; xcall->buffer_total_releases =3D 0; diff --git a/tools/libs/call/private.h b/tools/libs/call/private.h index 9c3aa432ef..8e6a208975 100644 --- a/tools/libs/call/private.h +++ b/tools/libs/call/private.h @@ -31,13 +31,15 @@ struct xencall_handle { Xentoolcore__Active_Handle tc_ah; =20 /* - * A simple cache of unused, single page, hypercall buffers + * A simple cache of unused, small, hypercall buffers + * buffer_cache[i]'s size is (i+1) pages * * Protected by a global lock. */ #define BUFFER_CACHE_SIZE 4 - int buffer_cache_nr; - void *buffer_cache[BUFFER_CACHE_SIZE]; +#define BUFFER_CACHE_NRPAGES 4 + int buffer_cache_nr[BUFFER_CACHE_NRPAGES]; + void *buffer_cache[BUFFER_CACHE_NRPAGES][BUFFER_CACHE_SIZE]; =20 /* * Hypercall buffer statistics. All protected by the global --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874341; cv=none; d=zohomail.com; s=zohoarc; b=iP7VZQIMR4wJUqiW4FluyELHwZwpExwh7g84S6UpisiU49BMkn2lUNU3UwTaGDk9cd1b+ERuk3RHi1G+Zjx52RAvGOGEYuuZ8rrmDi/69QrVD9Bdy8WLRw2pHPjph71DWpMCT0q9+yMWZnLfGUKm3tzvbt8RUMk4wtZeybdzAzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874341; 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=ZidMZWTCYLyL5ufIMI3PcR9yOlOw9e9GMi8xqFKVOr8=; b=aXe1sBeN3IsYyaVzxlXEeyq7KF244a4IesTzP+wcCmWZwUvlo2Pib37WgazNKNMbMET0SvPIrlarPpEK/c9j2eDkv6r159yVewWaePr2Kiva/+L6UCVr3lojy8Ja0x49/T07Qp+MP8YHkSiLhhgsUHM7d5kn5pJft2IxJwji3Xg= 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 1781874341528979.6633534256043; Fri, 19 Jun 2026 06:05:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342204.1602466 (Exim 4.92) (envelope-from ) id 1waYuP-0001w1-As; Fri, 19 Jun 2026 13:05:21 +0000 Received: by outflank-mailman (output) from mailman id 1342204.1602466; Fri, 19 Jun 2026 13:05: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 1waYuP-0001ud-5q; Fri, 19 Jun 2026 13:05:21 +0000 Received: by outflank-mailman (input) for mailman id 1342204; Fri, 19 Jun 2026 13:05:20 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuN-0001Wt-U6 for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuN-00D4ah-Ac for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:19 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e89-2eae-0a2a0a5409dd-0a2a450ba98e-22 for ; Fri, 19 Jun 2026 15:05:19 +0200 Received: from [209.85.208.50] (helo=mail-ed1-f50.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e8f-5e53-0a2a450b0019-d155d032bc5e-3 for ; Fri, 19 Jun 2026 15:05:19 +0200 Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-69532288224so3950688a12.0 for ; Fri, 19 Jun 2026 06:05:19 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05: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=1781874319; x=1782479119; 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=ZidMZWTCYLyL5ufIMI3PcR9yOlOw9e9GMi8xqFKVOr8=; b=RH5ZaNnXnutl+59wVjGfXnwseXaNH71z440zvKQe11I1Lh6XZQdY+3K2Nvd94978YG SXJa/a6Z86ruc2KHdI9Uaivgf8YWIvPi+u/8CM14RJk80l+XnSPSPonntrqi8pxjCja7 Co4WqUPxztOfngUlFWLOIX0xaDPOy+Zf7JzImoM7N1LSFybwTUMj8/fnbaFwLYyqD1gP K82oqUl2vaz2VjhFTZEa3PxVf4zafFB3bszCLG3WmGwfVmcmQ4OHUi4p0lkRtCwjvSSC vVaepIkR8CUNXEm+BC9D7nq/sJfHa25c63BXK8cqxvD2PaMsJ7oCp8Fb9t0UIGSEClMs xCRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874319; x=1782479119; 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=ZidMZWTCYLyL5ufIMI3PcR9yOlOw9e9GMi8xqFKVOr8=; b=gflDynSKdOYtRT8mDCn9MIENdrTeZerJ+U21n40haK/VNuWS4wsAyOCozEVuPZthXY LUK8rqO6PVUDxVwaVni4mapLBbfDqaoR+bOIr4gTTRBcdm1EzEUgt1zUX+u+R3dnxsH4 /Dam9QhtOz4QJvIi9bUW/rOeYsTQm1dFbiG0KdD+3Aa0rKEIh7HFdKqdUgIe4H3piZAr wfhpcu0jxYdE/z4RPrZ0mZhAnH59Qg5l9DEw87X8EBNsYyPEhAbgYCMXg9hJ5cZ6XBBq kLv3QFigNJm57X+AnCdiCpcp3xPUMGzdkGqjB4TKlSNqR3oZ7S1ooKOBblVSqRDiSj9v i4lA== X-Gm-Message-State: AOJu0Yx4lJt5vJI9t5LNj0KaJlJzIZkzLRDAk7FAFxSvxHgjfjiRrfCG hqJKjhyZkNhm/tiOIRY3RBqS7vN5ne7MafoW0Pqd2/l5ExP7mv32O4KMX634FT6jMgI= X-Gm-Gg: AfdE7cnrUQPhU4NE1ORbLVjYO0+a4DriMFIVwM7oBPPtJgSPE7/bJJxNMI+s7FmIN0i sVyS+g9ffMaJSC6bwOl5lA8RvLbgBB2DXcG6Szdppk8p2trTZ5qv6NxQC5ocDuhqK1BSqcFac20 l/6JPCliauEbPp7SfROvS5MADLKVj3bmNehplC0O6YNCrlgi0Jgu4GvBCwZqhLK7PC7YO3aQCYO 0cRNdQRAc1CkYrYugKLwutimrAeKmh1yBup2+JxEogMDJ+aKIcu8mG/4UguXIoNLkwepZ8f8Vx7 c41daUJ7HGZlx3gJ3ORjtT40mxMopWdYfjpFL12S+5lx9cqSiM/IKsTXQElpzQfYM6irOL/375T SFzmqzwEs8GcuaMfnmM4qfPFzxW1uvo7BvIkMIqdlc3OZfTm/qGM+A/B3enflEel691oW+/fTIW 5hRtJ8PHM6cXwTG23Eyzr7Mwa2sbE3t4idOJH/nIEnzmmdADWGHIeJVaL9quvDCzuRJxKblMZaQ 2ppBHVf X-Received: by 2002:a17:907:724e:b0:c08:3409:b747 with SMTP id a640c23a62f3a-c0b62137c57mr133369766b.33.1781874318503; Fri, 19 Jun 2026 06:05:18 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 07/16] libs/guest: avoids using 2 indexes Date: Fri, 19 Jun 2026 14:04:52 +0100 Message-ID: <20260619130501.272832-8-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1781874319-45DF800E-D2DF68FF/0/0 X-purgate-type: clean X-purgate-size: 2731 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874343762158500 Content-Type: text/plain; charset="utf-8" Simplify code, after the first scan of the various arrays we don't need to keep original types and PFNs but only the ones having data. Signed-off-by: Frediano Ziglio Reviewed-by: Andrew Cooper -- Changes since v4: - added Reviewed-by. Acked-by: Anthony PERARD --- tools/libs/guest/xg_sr_restore.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index e148fc594a..fb46142d87 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -260,9 +260,7 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; void *mapping =3D NULL, *guest_page =3D NULL; - unsigned int i, /* i indexes the pfns from the record. */ - j, /* j indexes the subset of pfns we decide to map. */ - nr_pages =3D 0; + unsigned nr_pages; =20 if ( !mfns || !map_errs ) { @@ -279,12 +277,18 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - for ( i =3D 0; i < count; ++i ) + nr_pages =3D 0; + for ( unsigned i =3D 0; i < count; ++i ) { ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); =20 - if ( page_type_has_stream_data(types[i]) ) - mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); + if ( !page_type_has_stream_data(types[i]) ) + continue; + + mfns[nr_pages] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); + pfns[nr_pages] =3D pfns[i]; + types[nr_pages] =3D types[i]; + nr_pages++; } =20 /* Nothing to do? */ @@ -302,16 +306,13 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - for ( i =3D 0, j =3D 0; i < count; ++i ) + for ( unsigned i =3D 0; i < nr_pages; ++i ) { - if ( !page_type_has_stream_data(types[i]) ) - continue; - - if ( map_errs[j] ) + if ( map_errs[i] ) { rc =3D -1; ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[j], types[i], map_errs[j]); + pfns[i], mfns[i], types[i], map_errs[i]); goto err; } =20 @@ -337,7 +338,6 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, memcpy(guest_page, page_data, PAGE_SIZE); } =20 - ++j; guest_page +=3D PAGE_SIZE; page_data +=3D PAGE_SIZE; } --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874358; cv=none; d=zohomail.com; s=zohoarc; b=DJZ7k026N2w4fVANcbcYlcHaqC3H3gFxJcTXB7X/ghiQV9rlb06W6+T+hQ+SrxKk3NXsxGRyv27oz5axW8V5ET8irkRzEGSWrx7B6y4A7d2iNutv86Ku5fVEzzfO8XEMrW6y1D/LqY6FV0wA8kIVAOy4KLF4acRo4Q2KtEzRXqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874358; 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=yXzH0W3KjNNVT2/fbradMnP12nKpXvhtoDr3wKrOgVQ=; b=fcRZtnnCBryTGYf2lTnbXK31gMxXCAfW7Bs5076hWByxBAxWV782tNnpCIDR0jNmF9bpHDtOMVAgentFFLwYDo9YR97bxPCEJpcFb2aMG+T1vBy6EPf2W8G+FsSHyqayrRuxz27BIWJ++NiZ2WnFJMVWdiBceFbQOyo7DCMcmJk= 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 1781874358404282.26318532848245; Fri, 19 Jun 2026 06:05:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342205.1602475 (Exim 4.92) (envelope-from ) id 1waYuQ-0002FV-Qe; Fri, 19 Jun 2026 13:05:22 +0000 Received: by outflank-mailman (output) from mailman id 1342205.1602475; Fri, 19 Jun 2026 13:05: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 1waYuQ-0002F9-MP; Fri, 19 Jun 2026 13:05:22 +0000 Received: by outflank-mailman (input) for mailman id 1342205; Fri, 19 Jun 2026 13:05:21 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuP-0001ty-9a for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:21 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuO-002qlM-Mf for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:20 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e8f-bab6-0a2a0a5309dd-0a2a450cd1de-6 for ; Fri, 19 Jun 2026 15:05:20 +0200 Received: from [209.85.221.52] (helo=mail-wr1-f52.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e90-94a4-0a2a450c0019-d155dd34bdf9-3 for ; Fri, 19 Jun 2026 15:05:20 +0200 Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-45fe59255beso1163723f8f.1 for ; Fri, 19 Jun 2026 06:05:20 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:19 -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=1781874320; x=1782479120; 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=yXzH0W3KjNNVT2/fbradMnP12nKpXvhtoDr3wKrOgVQ=; b=FLwa72QNj+LfYEW6VuuKVRRfvYZdlApd0XVX2DE8jY1f7FYLNdHxyVe5vYtMUnEYWp pap3RVxPJIJOO+DiPOHuligm8bX8EUG9jgjpBRr0hKUlcvJm5ohXb5w6M0+jiUMaI1Ot 4uvLh6G0KteIPTeacnbSvz24mYRwu3eCW0vmTEvkNuNgUwbB5crTabPuZuF84P38zVj6 XvH1/pr5D1mTj4hORCqkXfWJ2AEWslq218kW7v6LsDWOcdZJcH2CqExbPshPyAPeLy7r PZdVw3/08+8DEqrjaClbnFWf3KRC6bgxzmp3plPkxUHenXQgl5vMbiEtwkqOwLwG4jEW N5qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874320; x=1782479120; 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=yXzH0W3KjNNVT2/fbradMnP12nKpXvhtoDr3wKrOgVQ=; b=W2zyC7ahZiEHwm+qhDVDBrKEtcx+rTYI5Uhyju7p2GZcEmq4CXALC+DzHc8KlM3dbQ 4bd/J4ZiXFnaqfxzLwGcJT0Px5d7gAescXRdS1D4K7zvtRMU0HZOBW8zmin6eWshSKhH GHKXqFrwO2TFG9wuZc3oTSd8HXUwj6Pih5Vgzh+c0Pjccs7tYNkrd7565j8jocvUP6hB p8fsaCBFyRJ6tkc1rhPfnngMrn57lcupXOvwgJ1/fe8sIgAzHYOoRAIcUg+8JV6bElu9 sUNnchv60RjOPzDVfkp4AqmmFxUzoKdhaUKCFM1uOHyr17JSBsGRItEmDBOVm6hoj3BH JHlw== X-Gm-Message-State: AOJu0YzMKEEJDIL/SnsSxVALSsVs3eCGmxdMWiuOWrHayJ3ZbrAb7udW Wj/H5y+VHNJI6yzcZPd+wg+Xq57hbsk0Yf67eEuU8YtnwXN9Pqy5qlxbTjMGKp0r10c= X-Gm-Gg: AfdE7ckV3IshFRbZnSx8Umz+xS8Nw/8hHr7tH3DPyiYMdBB/eaiftfuLCshj36yIgk4 DMats7+fkAQkytvNAFhRxMRyoT/xGTs57V7rH+/IszO3CWvcBPHAswBD/ok4nTKAEcN0RTrq14w 2clR0z9wOld19vWqTqwwajSAtzFcDLenvixg7tAqSW6AKPNUlTJRz1kaRAI3lkzVHow3cEjiOi+ bRZOjqiBMKqYk5eR9Kf7S62fq9lVkOCCU8GZTnlPjiYtNGv6jw0gujenyJY7SPvt7OMcueMfk/2 Wu4iWTYBcekb+6nPjEmng1EK0R5a9oMsAm5DQM2cZOH29Oh1KPftSMR+FXV6FluF2oXCGyVNTe6 7Q236Qa2avUYj75QAveLqY1ZnaOU/XP7qOTJXsY0x9FbxaimHaGc/mXhEju/gl8PEl1NSUD8sIy nuLAvIQqL+N/Y5xkOy2D6HDUlfQGtl8zqTyJun6ZepZfgyC6e5MUqWPmUbe4mkSV2JLisELUHjX nhPM+R9 X-Received: by 2002:a5d:5f96:0:b0:462:6aa1:4393 with SMTP id ffacd0b85a97d-4656d643c3fmr3720824f8f.4.1781874320011; Fri, 19 Jun 2026 06:05:20 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 08/16] libs/guest: fill directly iov structure Date: Fri, 19 Jun 2026 14:04:53 +0100 Message-ID: <20260619130501.272832-9-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1781874320-DA7E9ABF-3082923D/0/0 X-purgate-type: clean X-purgate-size: 4544 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874359700158500 Content-Type: text/plain; charset="utf-8" Instead of storing page pointers into an array and lately adding to iov vector add the pages directly to iov to avoid "guest_data" array. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.h | 1 - tools/libs/guest/xg_sr_save.c | 64 ++++++++++++--------------------- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 95b0564e5c..b2c441b644 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -214,7 +214,6 @@ 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]; - 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]; diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 4988d8040b..8a22267fdf 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -88,7 +88,6 @@ static int write_batch(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; void *guest_mapping =3D NULL; - void **guest_data; void **local_pages; int *errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; @@ -113,9 +112,6 @@ static int write_batch(struct xc_sr_context *ctx) types =3D ctx->save.buffers->types; /* Errors from attempting to map the gfns. */ errors =3D ctx->save.buffers->errors; - /* Pointers to page data to send. Mapped gfns or local allocations. */ - 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 ctx->save.buffers->local_pages; memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); @@ -158,6 +154,19 @@ static int write_batch(struct xc_sr_context *ctx) mfns[nr_pages++] =3D mfns[i]; } =20 + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + + hdrs.page_data.count =3D nr_pfns; + + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); + + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); + + iovcnt =3D 2; + if ( nr_pages > 0 ) { guest_mapping =3D xenforeignmemory_map( @@ -199,61 +208,34 @@ static int write_batch(struct xc_sr_context *ctx) else goto err; } + else if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len != =3D + page ) + { + iov[iovcnt].iov_base =3D page; + iov[iovcnt].iov_len =3D PAGE_SIZE; + iovcnt++; + } else - guest_data[i] =3D page; + { + iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; + } =20 rc =3D -1; ++p; } } =20 - 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 - hdrs.page_data.count =3D nr_pfns; - 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 &hdrs; - iov[0].iov_len =3D sizeof(hdrs); - - iov[1].iov_base =3D rec_pfns; - iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 2; - - if ( nr_pages ) - { - for ( i =3D 0; i < nr_pfns; ++i ) - { - if ( !guest_data[i] ) - continue; - - if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len !=3D - guest_data[i] ) - { - iov[iovcnt].iov_base =3D guest_data[i]; - iov[iovcnt].iov_len =3D PAGE_SIZE; - iovcnt++; - } - else - { - iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; - } - --nr_pages; - } - } - if ( writev_exact(ctx->fd, iov, iovcnt) ) { PERROR("Failed to write page data to stream"); goto err; } =20 - /* Sanity check we have sent all the pages we expected to. */ - assert(nr_pages =3D=3D 0); rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874352; cv=none; d=zohomail.com; s=zohoarc; b=h3/FUljZEmpNT1lvul3o/Z3V3yAsNWh71c5lByMs2rcriXokgXk1s7fJWaEurBRcPcbjDrOOD6CGHKsMb1YAvsTv9jeEhh1UL3z8OlPKdPz0kqBDLBPtnk5/6dZ1QjTQzO5SMn/clq5T88wGP3LaxfsmXcOGcMH5gBNvlstTznA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874352; 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=rq+qhmTPgKBhNpU+5cysMmMVcR/5yZiixTBKuWIy3R4=; b=Et0FYycB+LGYk6xr/IXtXEfLC4OAjN37kca+FDkdYs5/tmcGrAkGqSk8lTvsn1oVSB3BWrGcH+sRCiUvcNxlSrcNvp7neLJRdSEQDr8ioNZDxE4omLkrFVHGA7WlPQt7Ie1K2RA/LH/q3TNXjt2kedKvGOyofpQKSARirjCqafo= 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 1781874352461211.57679871070968; Fri, 19 Jun 2026 06:05:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342206.1602485 (Exim 4.92) (envelope-from ) id 1waYuT-0002ao-5N; Fri, 19 Jun 2026 13:05:25 +0000 Received: by outflank-mailman (output) from mailman id 1342206.1602485; Fri, 19 Jun 2026 13:05:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuS-0002aU-VW; Fri, 19 Jun 2026 13:05:24 +0000 Received: by outflank-mailman (input) for mailman id 1342206; Fri, 19 Jun 2026 13:05:23 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuR-0002GD-4O for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:23 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuQ-002qp2-FT for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:22 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e8c-5cb7-0a2a0a5109dd-0a2a4501e924-32 for ; Fri, 19 Jun 2026 15:05:22 +0200 Received: from [209.85.128.43] (helo=mail-wm1-f43.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e92-e031-0a2a45010019-d155802bb4ce-3 for ; Fri, 19 Jun 2026 15:05:22 +0200 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4908b92904fso26773065e9.0 for ; Fri, 19 Jun 2026 06:05:22 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:21 -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=1781874322; x=1782479122; 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=rq+qhmTPgKBhNpU+5cysMmMVcR/5yZiixTBKuWIy3R4=; b=BSpDRh9uqp4Oz4Q1KNTRN3xMV0HZxqvCgMpaYpwutUmO52n/WYVqzBqXOTiINbIr/V ve8VJwXvnXJHFypZszDtPo/psyHY9i/In43TBFyAsBphTrs93ez9ZPDkqbupFv7QuA/X 7EgHASp/yvZ5qn6XhY5DTG/QynExHn67ASMt5LYUPRSG2F8nhQn5YuGoh2OQBGS43rXl U+FazrtkrOF34jD8vxCi2Gkf8cGISYYbO3dkkZPO2XSPx81YfipIQsBS9pOR5i3q9zSn Ya7kQunYGYKLploGTUVZh1tCZR0iDZuXNShVYK17fLN5EjunDP1NvJXrOgI8t8tiWKcR Pvlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874322; x=1782479122; 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=rq+qhmTPgKBhNpU+5cysMmMVcR/5yZiixTBKuWIy3R4=; b=W/++0ZtdzLDddF1PR9DZQXaY1Zi7bY5V1Om/nc8Hrkud88oHnrg0MP2j9CAx3oDARY aIyesLRaPPaekrbP5izIuUTR2VzmzvLVSAi9DsgFuPd0Vcvu2psJaCd4eVB7ktdRFu+o +54tdpi4cVbyhjhM0XOhOZhQrlN/HmBWuHZQ+BxFsend6Ir0pN5nqyKb01KkVjTGAXEC JjXQx7Tnry1zyinyRwYgDqJYz5iIt2Z6LGX5kYszOImYAVB7C8xXRjtIEK4UUPAEq2JP wsJ/a1xFyf/bbUItGjRqdz1gCSDDau6MOUgPoTnJ7Rs1EtUnjjzSr2M6gOjFjXZHqNJa qr/A== X-Gm-Message-State: AOJu0YzVBDKmH7zzSwo7hnaZUu5r9c1mWiiCz6YsScGa/tmPDt/4jS5f kGjKBOuT3PrWJSH6VNqmfsD+5+WIrc7maA8yhyw/5sUWG1oEWKG3rD9V0dYJJBcIP1g= X-Gm-Gg: AfdE7clIeOh4C17TEthyVoii78rGe8P5nSTV24bezkacmOuq/fcaA8r4xpWRw94AJAL e30m72Xptg/3m195YNbHG6Z7CfnIH9AhhPVNZ0MTgKfuS+iajlj3pqFnMrc/q0yxe6kDAWOcBol 5AgbhhEci7RjZX7h5NPTc2hH8Q4Zqt4MGMOndgwlF3kJ37fNmQWQZSpM8lk/WxEZlZOpF0FbDJJ ncaKyqAtT11T/cJKGTHJAkTe/QC9xlsS55dBWrqRboK8zw9Ncl9M/Etv4/vxf7Ctq4LP+jCHg82 Fs3MdqI5GYODSVrGSQDpHcCSYMmVZJy29odrQbnQMLFJPejVVoed9QNJTO3z0EmwvXooh06pBHi i7GDfCGbyJazjanqw66i7MtCVybN6l1mDriCM7+oinDa0S4XIlbeSkzqOf3akBXY6tkeJhlojQ3 UZlccbZb8FmWcBWXR+dIfM5mCQ2pAeYNxDjSrrlL2icAMOgj4cYse1iwBHHwH6zAB2bW/AQvPNd 8TIkEbl X-Received: by 2002:a05:600c:810c:b0:490:d3ef:fa4a with SMTP id 5b1f17b1804b1-4924233f9fcmr37363585e9.14.1781874321616; Fri, 19 Jun 2026 06:05:21 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 09/16] libs/ctrl: Allows writev_exact to change iov array Date: Fri, 19 Jun 2026 14:04:54 +0100 Message-ID: <20260619130501.272832-10-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1781874322-711F3E30-ECB58022/0/0 X-purgate-type: clean X-purgate-size: 3172 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874353675158500 Content-Type: text/plain; charset="utf-8" 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 -- Changes since v2: - change prefix in subject. --- 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 Thu Jul 23 22:26:30 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=1781874354; cv=none; d=zohomail.com; s=zohoarc; b=l8EtE2CQZdSEugMQAVAP4qZY4+abN2/7xlPeRLYuQzw7aCd9GwGBATxCBL/0Lqa7s2aXmO9xj2HWNOGT+oxIoj5iaRBysMSdPLklt3yCIQtXvkBr/djkLPobc8TdZ916Ynj4VS4A0ICUmTvSL5BrLeugDXEh72afGCAviE5CPl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874354; 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=LmIH1fxngC6S436VPRvPDb1Farbh0pJpGks2ZI7BB0I=; b=moLF9WOzoxm4nl4y3jOgZ0FKMKEHH6S95UgNpEIEIssqbnyr/M4qDDKXxYex03JAHrqjPUW/2QysMmiLUXVztuW3GA1+veHVdbDFghF4MvAhkmzeBw5X7d+H5iNJ0NTF6r7EgQ78Evn7mXBRaT906pOGZBht4zcoQ32s/j06aZ4= 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 1781874354953998.5782745856249; Fri, 19 Jun 2026 06:05:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342208.1602489 (Exim 4.92) (envelope-from ) id 1waYuT-0002d5-JN; Fri, 19 Jun 2026 13:05:25 +0000 Received: by outflank-mailman (output) from mailman id 1342208.1602489; Fri, 19 Jun 2026 13:05:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuT-0002c9-Be; Fri, 19 Jun 2026 13:05:25 +0000 Received: by outflank-mailman (input) for mailman id 1342208; Fri, 19 Jun 2026 13:05:23 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuR-0002OB-Jc for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:23 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuQ-00D4eo-WD for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:23 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e8d-2eae-0a2a0a5409dd-0a2a4505a48c-30 for ; Fri, 19 Jun 2026 15:05:22 +0200 Received: from [209.85.208.47] (helo=mail-ed1-f47.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e92-ef3d-0a2a45050019-d155d02fa493-3 for ; Fri, 19 Jun 2026 15:05:22 +0200 Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-6870ad8072eso2168987a12.0 for ; Fri, 19 Jun 2026 06:05:22 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:22 -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=1781874322; x=1782479122; 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=LmIH1fxngC6S436VPRvPDb1Farbh0pJpGks2ZI7BB0I=; b=l8objaQXtlIcc4shebAIzaTriizRuahQ1gWsPhAsBZVNYILVJx1Q+ctp6lTtc/trh0 FwnbT9ksV32ZoC74BcbkQ6mjjElKewN6w4hYb9mO3Jtpt2C3owxHcS25uDlNgtyQO8Ok cvsPgQY3/oet6dgXUya8TKSlCsea+LKL6+8UfJnd3lTcFTyi3xPX025BsZA9UB8UTFUR NCvMsNqVQH1x57be/Yet+WaBbymvBp5dGj+oIdjb1qsiufGONykNO6RbO2aBVeVBoqQw wJGkMkQlCicIoEZPzb2lUFdIXqU5uioSg+waIaHTgfSD3UOSXB00LPkKDGKCSr9MTiKO KItw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874322; x=1782479122; 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=LmIH1fxngC6S436VPRvPDb1Farbh0pJpGks2ZI7BB0I=; b=SmmSUPNBg3Uo4c3q8TusbeVXCDo2i7U6hFPIDnV5KyFoz4GfsnfujJrGsJsv3EY4TT GCYGRNBCPszywDlMT1RnQ+qPWQqDX9bYWtYFi+x+QyvXVB4DZQplmv2kD5RjkM4iRk+Q zjtVImndo6lNyNTAYyyCYSHaDVrP26SIZTC8VIRMV7vFxnGCsalsLb3p1gN7cRaNe7tw xwGoN+IOr1tZu4DrBp4ROT/+co4xaCDzgE/76MjtNrVfrOXS021+tL2jq9WDzUX0DG7E 4bs3KOJPFPnqkN7BW852lhSM33QwrnK/3S2v9nncvP3G9uwyzX1uvhYn5pKAmK99/YyY Nf4A== X-Gm-Message-State: AOJu0YxYlMxsBYK923Ark+oYdqD0SRW4UD7Cc99AR/AeopdzKGHhB7GA GDXDPJ1/r53SBJ4l+KxEIAWB4zT3UdgI1ZfK/sGuHF/4u+SLCkzM1ciC44LVhsDoSgs= X-Gm-Gg: AfdE7cmxQo/7Lu8GkCC+SGIv21vUWF4zgcUfujRRG2jG5zfDAW4taUrYak1BoI5GQXC 2NNHGshTghRmy7If4qegFjl9Mg4StMsyirjMhVmye4CI8Tm2eowNQ3wLyOUoj4QNzAQMnPW3hl1 g4oB7E2xi6+F6RvED7xz6jGsQF7hI+nJtnbJa0yOqDzH+o4WKBhge623K2InJmXlvv/AF9jHwqi hmcvoan11ewTEoIDpIYePWxAFHpXyCJD9vyRDLo871XYp9Md3jfVnqj1BMi2+YKP/p9bANvOlmo JCoEU6zXvK8kjjL8jDlcMjoS+rbL4NT7xzOjCov4RFBscCZfTkcXYBgtixr66d1f7gi5BDN0YWI bYz8N+9a/Og+RzZi4Mb9hIwH/iUMYZMp4Y9HlTNPFWRM5sJFNypNd6de7aguzpqfnEZnBJhAm/x LVtaS4NNUFj2ya/ymTYG5IRw0Rcc05/QwNTMPblnv0F+r7hbX40oOjZ3GND/0uqSXaXXMiOLJlB 2NXUxLv X-Received: by 2002:aa7:c58b:0:b0:697:641b:11fc with SMTP id 4fb4d7f45d1cf-697641b13a4mr615235a12.16.1781874322377; Fri, 19 Jun 2026 06:05:22 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 10/16] libs/guest: add xg_foreignmemory_copy_{from,to} Date: Fri, 19 Jun 2026 14:04:55 +0100 Message-ID: <20260619130501.272832-11-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1781874322-9C1F1127-70E27644/0/0 X-purgate-type: clean X-purgate-size: 3469 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874355679158501 Content-Type: text/plain; charset="utf-8" This change prepare code to use a new "foreign copy" hypercall. The new hypercall will copy memory from/to a foreign domain. The new hypercall can be emulated with a sequence of: - map foreign memory; - copy memory; - unmap foreign memory. Signed-off-by: Frediano Ziglio -- Changes since v5: - Do not overwrite errno if xenforeignmemory_map fails. --- tools/libs/guest/xg_sr_common.c | 57 +++++++++++++++++++++++++++++++++ tools/libs/guest/xg_sr_common.h | 8 +++++ 2 files changed, 65 insertions(+) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 9b2782b5cf..90da21c35f 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -156,6 +156,63 @@ static void __attribute__((unused)) build_assertions(v= oid) BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params) !=3D 8); } =20 +enum { + foreigncopy_from, + foreigncopy_to +}; + +static int xg_foreignmemory_copy(xc_interface *xch, domid_t domid, + int dir, size_t nr_pages, void *buffer, + const xen_pfn_t foreign_pfns[nr_pages]) +{ + if ( nr_pages =3D=3D 0 ) + return 0; + + if ( !buffer || !foreign_pfns ) + { + errno =3D EINVAL; + return -1; + } + + int err[nr_pages]; + const int prot =3D (dir =3D=3D foreigncopy_from) ? PROT_READ : PROT_RE= AD|PROT_WRITE; + + void *p =3D xenforeignmemory_map(xch->fmem, domid, prot, nr_pages, for= eign_pfns, err); + if ( !p ) + return -1; + + for ( size_t n =3D 0; n < nr_pages; ++n ) + if ( err[n] ) + { + xenforeignmemory_unmap(xch->fmem, p, nr_pages); + errno =3D -err[n]; + return -1; + } + + if ( dir =3D=3D foreigncopy_from ) + memcpy(buffer, p, nr_pages * XC_PAGE_SIZE); + else + memcpy(p, buffer, nr_pages * XC_PAGE_SIZE); + + return xenforeignmemory_unmap(xch->fmem, p, nr_pages); +} + +int xg_foreignmemory_copy_from(xc_interface *xch, domid_t dom, + size_t nr_pages, void *dest, + const xen_pfn_t source[nr_pages]) +{ + return xg_foreignmemory_copy(xch, dom, foreigncopy_from, + nr_pages, dest, source); +} + +int xg_foreignmemory_copy_to(xc_interface *xch, domid_t dom, + size_t nr_pages, const xen_pfn_t dest[nr_page= s], + const void *source) +{ + return xg_foreignmemory_copy(xch, dom, foreigncopy_to, + nr_pages, (void *) source, dest); +} + /* * Local variables: * mode: C diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index b2c441b644..e37f805240 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -553,6 +553,14 @@ static inline bool page_type_has_stream_data(uint32_t = type) } } =20 +int xg_foreignmemory_copy_from(xc_interface *xch, domid_t dom, + size_t nr_pages, void *dest, + const xen_pfn_t source[nr_pages]); + +int xg_foreignmemory_copy_to(xc_interface *xch, domid_t dom, + size_t nr_pages, const xen_pfn_t dest[nr_page= s], + const void *source); + #endif /* * Local variables: --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874354; cv=none; d=zohomail.com; s=zohoarc; b=d8NPelf1f823lvnZUPRcURunkVsX7c9Fpud3b3RDkr5oPvgrWEVcXj/rzcVwR3yBu9O5GPlwSk8pXqg1jyzL1HwZQFi8XeBxUS5HaBZhlzvIcAgy6n30AM/6n37ouaf4FdACqSgUoMRxC3KCwaWLzccCI7v2oLtWdmFEUjhFDrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874354; 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=nZbBEu1yumZubA+jdFXfLBNW/6vA9c6a3PhaM+0TpSU=; b=IU928aQFIZ4NhIHYFTPZRHl8ao2LV2cRpWacyBDZEQdx0kIRP7BN+WVq81vriuIAgVZT65+Df6usFOkH0qVst6CfR/Isa8n6dckDCC0HyTk4tjrOx1IvkQ6Lw2BK1dnjf7QMC1zpA4Zhig8+pVe0flt8rWD+cXgLfOUUKP6NlwE= 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 1781874354051927.4450904476556; Fri, 19 Jun 2026 06:05:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342209.1602495 (Exim 4.92) (envelope-from ) id 1waYuU-0002kM-18; Fri, 19 Jun 2026 13:05:26 +0000 Received: by outflank-mailman (output) from mailman id 1342209.1602495; Fri, 19 Jun 2026 13:05:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuT-0002ix-QT; Fri, 19 Jun 2026 13:05:25 +0000 Received: by outflank-mailman (input) for mailman id 1342209; Fri, 19 Jun 2026 13:05:24 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuS-0002XV-PQ for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:24 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuS-002qqj-6K for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:24 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e84-bab6-0a2a0a5309dd-0a2a4508d34e-32 for ; Fri, 19 Jun 2026 15:05:24 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e94-9ee7-0a2a45080019-d155dd2ec9ad-3 for ; Fri, 19 Jun 2026 15:05:24 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-46255b269c2so1614727f8f.3 for ; Fri, 19 Jun 2026 06:05:24 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:23 -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=1781874323; x=1782479123; 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=nZbBEu1yumZubA+jdFXfLBNW/6vA9c6a3PhaM+0TpSU=; b=EaudtYhR4fS7Y0nffC/v9yU2aL2ur/r90rSp5ky7NqMdzNV7WBrfTxXr2WXzm08uqR pVbCyNN8Px6/yPnEphqEseOiIlH0QakCnKLd84DhhaEJITnV61h9BxTkTFiL7I+9KyYF FwK7IDLmcgZdu9d6Ez9eTlMH/RbQ9oMjJo9rupqHk2br7H7cMmHm0tZMb1uP2zdMap7x wJgaMXlxNGaszbnkMR3dd0bALh6+y98hhlmRQXgq0UhpHUTgIpWUHm8pwCALQPzGVvSh /bsORKla+PRoyHdpGqIlaOuxr1Ki/0T7drM6XmhwaeEq06ZLVZuxSNN7JgSh0+D1S0wt MCPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874323; x=1782479123; 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=nZbBEu1yumZubA+jdFXfLBNW/6vA9c6a3PhaM+0TpSU=; b=PjoDV+ob3NKCc1IDTWOovoo6hlJLvBKCS1QnTrl+1fYc+JRjOKlJUdeB5AHReN/aE1 +s8lK0G7X7QEh7U5BpujZV2OJGkPzwTj0swyR6GPZNgIH3biGK4sOeSyGKSGU5xGLKcn /jqwOTiyoWQrSuom45OrAGfiVDdyYnR0q2JWtVy3MpVRw8AAKTVrvE2CWeYbbzMQepaL H0v8byCayommqb2RPIQrhv4gttazbTAvmqmQTVS/eioadLkfpAbpOnS3Uovi/X+eHwj5 E/d53VNxTFFVgPPsos8aOn3AnxkrAj+0EBlP2iWLYZY1Bll/nFAbHIpmIw0pHK5fBgoQ qkUg== X-Gm-Message-State: AOJu0YzsbA0JpVza4dZnNh1lmSCu3IHhL+xQVJcz2mCs51G1xoOtxNXg pYp2Ud62NxKGIhgbR0oDo6E8sqHqSeREMQ4mwhJ896W4IR3ApyYlIdGwNKYPRskUWjw= X-Gm-Gg: AfdE7clcQMJTNUzyNzzwP0ux+bxCEKUAVBPPwNNTw2EaOKpTJ6WL94e1/0/p9IKZ5UI ssCnYCdPVSuwEEjCaiLZ7kW5GZtXsve5dxYxD+9fXZ6ofwdAqJt/Ce6iDU/3MZluxVpe2yTRF70 a5MlS9fFVCafHR6CD947XpYxMgDGqG5WSpNSf0snAQXuJxdNnTlK/q7I3uPWtM318YHsLQdfhH9 Gw26os9b6UJ3+4QApI15zpvegtgKzQt8LY4K7zKJxL3kPLm1XHl/lPsI47bxo4+sbH3X9RCOgcr EJIHJG6xgIRx7amS7zytX3geJRRu7vjT00z8OGT9bv08MXfBgzFKlKiBj6oUVmYcuru+0R4WntM 7mgadQLw0mKKX9dF2Iop+nr+x7K36mv5BMH/5heZ3tEq1AmQIeUu8cTAGnrGwdyQAgeGbP1vOVA W1RDGgjlztRbj4os6PzEVXLz53swWXj5cb2F4dzqsXuL740oMzKnQFV6zvFQlbGkP0BJ7uRTeKU xv4uLfN2LjB77NxNXM= X-Received: by 2002:adf:f54f:0:b0:461:a161:8102 with SMTP id ffacd0b85a97d-46501d45833mr5100565f8f.28.1781874323465; Fri, 19 Jun 2026 06:05:23 -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?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v6 11/16] PoC: libs/guest: use foreign copy during migration Date: Fri, 19 Jun 2026 14:04:56 +0100 Message-ID: <20260619130501.272832-12-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c1860d/1781874324-674500FA-6918EB8D/0/0 X-purgate-type: clean X-purgate-size: 8610 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874355795158500 From: Edwin T=C3=B6r=C3=B6k ministat confirms the improvement: ``` x baseline + foreigncopy N Min Max Median Avg Stddev x 20 1.1306997 1.1447931 1.1356569 1.1365742 0.003242175 + 20 0.4311504 0.44180303 0.43616705 0.43600089 0.0031094689 Difference at 95.0% confidence -0.700573 +/- 0.00203311 -61.639% +/- 0.133355% (Student's t, pooled s =3D 0.00317652) ``` The tests pass too, which means that it has correctly migrated all guest memory. Frediano: This PoC was adapted to be included in a final series. Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 43 +++-------------- tools/libs/guest/xg_sr_save.c | 82 +++++++++----------------------- 3 files changed, 31 insertions(+), 95 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index e37f805240..d8d8a0f9f7 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -256,6 +256,7 @@ struct xc_sr_context unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; struct xc_sr_context_save_buffers *buffers; + void *dest_buf; } save; =20 struct /* Restore data. */ diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index fb46142d87..ff27560ff7 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -259,8 +259,8 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)); int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; - void *mapping =3D NULL, *guest_page =3D NULL; unsigned nr_pages; + void *const source =3D page_data; =20 if ( !mfns || !map_errs ) { @@ -295,27 +295,8 @@ static int process_page_data(struct xc_sr_context *ctx= , unsigned int count, if ( nr_pages =3D=3D 0 ) goto done; =20 - mapping =3D guest_page =3D xenforeignmemory_map( - xch->fmem, ctx->domid, PROT_READ | PROT_WRITE, - nr_pages, mfns, map_errs); - if ( !mapping ) - { - rc =3D -1; - PERROR("Unable to map %u mfns for %u pages of data", - nr_pages, count); - goto err; - } - for ( unsigned i =3D 0; i < nr_pages; ++i ) { - if ( map_errs[i] ) - { - rc =3D -1; - ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[i], types[i], map_errs[i]); - goto err; - } - /* Undo page normalisation done by the saver. */ rc =3D ctx->restore.ops.localise_page(ctx, types[i], page_data); if ( rc ) @@ -325,29 +306,19 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - if ( ctx->restore.verify ) - { - /* Verify mode - compare incoming data to what we already have= . */ - if ( memcmp(guest_page, page_data, PAGE_SIZE) ) - ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", - pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); - } - else - { - /* Regular mode - copy incoming data into place. */ - memcpy(guest_page, page_data, PAGE_SIZE); - } - - guest_page +=3D PAGE_SIZE; page_data +=3D PAGE_SIZE; } + if ( !ctx->restore.verify ) + { + rc =3D xg_foreignmemory_copy_to(xch, ctx->domid, nr_pages, mfns, s= ource); + if ( rc < 0 ) + goto err; + } =20 done: rc =3D 0; =20 err: - if ( mapping ) - xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); =20 free(map_errs); free(mfns); diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 8a22267fdf..7a48f6b0a3 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -87,12 +87,10 @@ static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; - void *guest_mapping =3D NULL; void **local_pages; int *errors, rc =3D -1; - unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; + unsigned int i, nr_pages =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; - void *page, *orig_page; uint64_t *rec_pfns; struct iovec *iov; int iovcnt =3D 0; struct { @@ -167,62 +165,18 @@ static int write_batch(struct xc_sr_context *ctx) =20 iovcnt =3D 2; =20 - if ( nr_pages > 0 ) + rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, ctx->save= .dest_buf, mfns); + if ( rc < 0 ) { - guest_mapping =3D xenforeignmemory_map( - xch->fmem, ctx->domid, PROT_READ, nr_pages, mfns, errors); - if ( !guest_mapping ) - { - PERROR("Failed to map guest pages"); - goto err; - } - nr_pages_mapped =3D nr_pages; - - for ( i =3D 0, p =3D 0; i < nr_pfns; ++i ) - { - if ( !page_type_has_stream_data(types[i]) ) - continue; - - if ( errors[p] ) - { - ERROR("Mapping of pfn %#"PRIpfn" (mfn %#"PRIpfn") failed %= d", - ctx->save.batch_pfns[i], mfns[p], errors[p]); - goto err; - } - - orig_page =3D page =3D guest_mapping + (p * PAGE_SIZE); - rc =3D ctx->save.ops.normalise_page(ctx, types[i], &page); - - if ( orig_page !=3D page ) - local_pages[i] =3D page; - - if ( rc ) - { - if ( rc =3D=3D -1 && errno =3D=3D EAGAIN ) - { - set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pa= ges); - ++ctx->save.nr_deferred_pages; - types[i] =3D XEN_DOMCTL_PFINFO_XTAB; - --nr_pages; - } - else - goto err; - } - else if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len != =3D - page ) - { - iov[iovcnt].iov_base =3D page; - iov[iovcnt].iov_len =3D PAGE_SIZE; - iovcnt++; - } - else - { - iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; - } + ERROR("xg_foreignmemory_copy_from failed"); + goto err; + } =20 - rc =3D -1; - ++p; - } + if ( nr_pages ) + { + iov[iovcnt].iov_base =3D ctx->save.dest_buf; + iov[iovcnt].iov_len =3D nr_pages << XC_PAGE_SHIFT; + iovcnt++; } =20 hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -239,8 +193,6 @@ static int write_batch(struct xc_sr_context *ctx) rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: - 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]); @@ -765,6 +717,7 @@ static int setup(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; int rc; + const unsigned dest_buf_len =3D MAX_BATCH_SIZE * XC_PAGE_SIZE; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); =20 @@ -776,6 +729,16 @@ static int setup(struct xc_sr_context *ctx) xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); + ctx->save.dest_buf =3D NULL; + + rc =3D posix_memalign(&ctx->save.dest_buf, XC_PAGE_SIZE, dest_buf_len); + if ( rc ) + { + ERROR("Unable to allocate %u bytes of buffer", dest_buf_len); + errno =3D rc; + rc =3D -1; + goto err; + } =20 if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) { @@ -810,6 +773,7 @@ static void cleanup(struct xc_sr_context *ctx) NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); free(ctx->save.buffers); + free(ctx->save.dest_buf); } =20 /* --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874359; cv=none; d=zohomail.com; s=zohoarc; b=lmB3Q5zNMCuepYM7eDlrUePMMMOz6DpnT852FpPHISNINcYvm6830IoKXrZN4/JUGiLkoFCnBsch5aru9vTj+m/DkHNkjD96q+BjcQyukVZUmdD2uWh/gL00jkvCYDhTxaBzL/Bz5hhoxWBB4JVkC34nmW1mRoh/f207rdaQzzA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874359; 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=i4GbNTJWWlsCX/SdHZdLeLVQ6qJfL6Y1RCmWUuA0EmY=; b=HlN+Bie0cNslF9WY2FqKHJqtDz0iEuReeGq2EzaWGbHNhkaCENtiL3yyq7NRGgqaOhBRIgZXketm7Pydbcy4SEmhHTkYmRW7pIyZLfa9fAKS2KZfq70Vg/ZlBax1F0E982vzb1ZaSq0Co+IUaMaF0+3k+PINqiA/6MjzjBN1bms= 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 1781874359187278.288214578164; Fri, 19 Jun 2026 06:05:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342210.1602507 (Exim 4.92) (envelope-from ) id 1waYuV-0003DC-UY; Fri, 19 Jun 2026 13:05:27 +0000 Received: by outflank-mailman (output) from mailman id 1342210.1602507; Fri, 19 Jun 2026 13:05:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuV-0003AG-MW; Fri, 19 Jun 2026 13:05:27 +0000 Received: by outflank-mailman (input) for mailman id 1342210; Fri, 19 Jun 2026 13:05:26 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuT-0002g9-Sb for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:25 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuT-00D4eo-8R for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:25 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e89-2eae-0a2a0a5409dd-0a2a450ba98e-42 for ; Fri, 19 Jun 2026 15:05:25 +0200 Received: from [209.85.208.49] (helo=mail-ed1-f49.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e95-5e53-0a2a450b0019-d155d031d165-3 for ; Fri, 19 Jun 2026 15:05:25 +0200 Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-691c5776f35so3063436a12.3 for ; Fri, 19 Jun 2026 06:05:25 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:24 -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=1781874325; x=1782479125; 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=i4GbNTJWWlsCX/SdHZdLeLVQ6qJfL6Y1RCmWUuA0EmY=; b=EJ8dzguCRr6U8zSKQmMMdzyLHRyT2qiVRwecqJV3Zd6o4phmjfmw18EDCwfkpwmS95 9X4C723tFtgvnohIFXUkBWuqx0Kh29842nBLhtPTP9zTB+qppxU9+4km/hDcJ1z9KBey bUXLLS4EThkhpBfyJGpISxitIQJTWn4HpsT6ZwBjAVeL6XvxJOFbESTfYnCwC4Bwsi4d HXg/BoGNOfQ4rHqK40RUy5Km2vS5UhnLcgv8DsmWyrKvdxwO33v2Gpv551aaKGMFeRlO Hj0QWurEG0PONphN1k4jUMCMIEMO+IUdP3x/9c1GK5EDbL4qYS7DvXOYfRm0y00riIrj cvXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874325; x=1782479125; 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=i4GbNTJWWlsCX/SdHZdLeLVQ6qJfL6Y1RCmWUuA0EmY=; b=Ohb7a4O3SPd5iv1dxs1+ZMt/YmfRMr2BE5CUNk6VeIM0eDkINoNSefvVnwK2BqPfVO VZExhF0R4C/L4u8SaPjTYRZG89SYidc4IBFPzt8pk+yJqWb4hJRvsAcwUFUurZwlhEj2 ARlZ88hB43q0+W8KsCT2vkZX5hig/Xlg9xlpEFWBGnNAT7/7oiGSrIr/XsTgEHruVEH2 NbZOXJPtT52g0xxT5DGn5m+z7NW+vWpKeVA2HxMMYz+xBU5RqQUUtPMvblqAj4jfdQZ6 T+r4cODWP2Yd+HPKzdrlE15lunlyldCcgerR6hF6NyVUr4yXlrieOjIQbQGqnAfVaEjo KvcQ== X-Gm-Message-State: AOJu0YwIeerq7fAxRWAWC8UtfwSu8ebwFG2TxZCp8xYOcX9TWXy4zKib EE2yaUZsrjjppUAxYkzJ211ldwhA9weWqhUb8bc0xxFXRu8lOONTz1crGWNAg678nJM= X-Gm-Gg: AfdE7cnjmDDqxCC2pjBmbNCGL+O8arH2a9joeyqC3O28Ax/S8gkEgie+SAfeG0DvwA7 xLYKr991M9jra1Uj6JstuJVxQI9EuydT4Vcj2/eE5hsk0CCevLEE5CHRKikb5brI8TT5ioEP0cU FtR8iDhJ2CTGoSRj3dC+emARBwk+uBvIMortbh4vYMgBxbTEPwPhxkVpUaIIxwcsIL/l/U3XmMg g5buaw032wVZYNqjHNfBoclyjzcrfP2ectzD3NJICs5ti7VTGmbd/NcVEJCeCrJhoqbUP4WkJFo UfT9ty16b5xNGzjsPByeqITnRfH0KTdEW3tbCPjRRLDH8cmbBwvXfAxrnLgzb1fgeD8pq9ObZE3 Rmc1PL3wEoCpsJp1TVMF3zvpuIhO2skPGNuUe93VLZffr1WxayHPMoUunkt5Ou+hzvv+PCJ+TLC Jt8xDTtWvaXif0DbE3OW4lmpzl9vPuyxfS/445O2NCQNXfoEe4NtSimpotYpcQFXpOeNimeUCzY lMfJWU6 X-Received: by 2002:a17:907:d01:b0:bfe:ed06:5a14 with SMTP id a640c23a62f3a-c0986e2ad05mr195244766b.50.1781874324572; Fri, 19 Jun 2026 06:05:24 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross , "Daniel P . Smith" Subject: [PATCH v6 12/16] xen: implement new foreign copy hypercall Date: Fri, 19 Jun 2026 14:04:57 +0100 Message-ID: <20260619130501.272832-13-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1781874325-4FBEF00E-1715F220/0/0 X-purgate-type: clean X-purgate-size: 7582 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874359765158500 Content-Type: text/plain; charset="utf-8" Add a sub hypercall to __HYPERVISOR_memory_op to allow to read/write memory from/to a foreign domain. Extending MMUEXT_COPY_PAGE seems better on first sight but considering that MMUEXT is meant for PV only and trying to change that sub-op this solution is better. Signed-off-by: Frediano Ziglio -- Changes since v4: - Fix typo in comment. Changes since v5: - update xen_foreigncopy structure comments; - move check for no frames after checking the domain; - use mnemonic instead of 1U; - fix page type checks; - do not overwrite error copying back structure; - latch MFN value; - improved commit message. --- xen/common/memory.c | 145 ++++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 44 ++++++++++- 2 files changed, 188 insertions(+), 1 deletion(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 3672bda025..98726766bf 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1545,6 +1545,139 @@ static int acquire_resource( return rc; } =20 +/* + * The "noinline" qualifier avoids the compiler to create a large function + * consuming quite a lot of stack. + */ +static int noinline mem_foreigncopy( + XEN_GUEST_HANDLE_PARAM(xen_foreigncopy_t) arg) +{ + struct domain *d, *const currd =3D current->domain; + xen_foreigncopy_t copy; + int rc, direction; + + if ( copy_from_guest(©, arg, 1) ) + return -EFAULT; + + if ( copy.flags & ~XENMEM_foreigncopy_direction ) + return -EINVAL; + + direction =3D copy.flags & XENMEM_foreigncopy_direction; + + rc =3D rcu_lock_remote_domain_by_id(copy.domid, &d); + if ( rc ) + return rc; + + if ( copy.nr_frames =3D=3D 0 ) + { + rcu_unlock_domain(d); + return 0; + } + + /* + * Check we are allowed to map and access these foreign pages. + */ + rc =3D xsm_map_gmfn_foreign(XSM_TARGET, currd, d); + if ( rc ) + goto out; + + do { + /* + * Arbitrary size. Not too much stack space, and a reasonable str= ide + * for continuation checks. + */ + xen_pfn_t gfn_list[32]; + unsigned int todo =3D MIN(ARRAY_SIZE(gfn_list), copy.nr_frames); + + rc =3D -EFAULT; + if ( copy_from_guest(gfn_list, copy.frame_list, todo) ) + goto out; + + for ( unsigned int i =3D 0; i < todo; i++ ) + { + struct page_info *foreign_page; + mfn_t foreign_mfn; + void *foreign; + p2m_type_t p2mt; + const unsigned long valid_mask =3D +#ifdef CONFIG_X86 + p2m_to_mask(p2m_ram_rw) | p2m_to_mask(p2m_ram_logdirty); +#else + p2m_to_mask(p2m_ram_rw); +#endif + + foreign_page =3D get_page_from_gfn(d, gfn_list[i], &p2mt, P2M_= ALLOC); + + if ( unlikely(!(p2m_to_mask(p2mt) & valid_mask)) && foreign_pa= ge ) + { + put_page(foreign_page); + foreign_page =3D NULL; + } + if ( unlikely(!foreign_page) ) + { + gdprintk(XENLOG_WARNING, + "Error accessing foreign gfn %" PRI_gfn "\n", + gfn_list[i]); + rc =3D -EINVAL; + copy.nr_frames -=3D i; + guest_handle_add_offset(copy.frame_list, i); + goto out; + } + + foreign_mfn =3D page_to_mfn(foreign_page); + + /* A page is dirtied when it's being copied to. */ + if ( direction =3D=3D XENMEM_foreigncopy_to ) + paging_mark_dirty(d, foreign_mfn); + + foreign =3D map_domain_page(foreign_mfn); + if ( direction =3D=3D XENMEM_foreigncopy_from ) + rc =3D copy_to_guest(copy.buffer, foreign, PAGE_SIZE); + else + rc =3D copy_from_guest(foreign, copy.buffer, PAGE_SIZE); + unmap_domain_page(foreign); + put_page(foreign_page); + + if ( unlikely(rc) ) + { + gdprintk(XENLOG_WARNING, + "Error %d copying gfn %" PRI_gfn "\n", + -rc, gfn_list[i]); + copy.nr_frames -=3D i; + guest_handle_add_offset(copy.frame_list, i); + goto out; + } + + guest_handle_add_offset(copy.buffer, PAGE_SIZE); + } + + copy.nr_frames -=3D todo; + guest_handle_add_offset(copy.frame_list, todo); + + if ( copy.nr_frames && hypercall_preempt_check() ) + { + rc =3D hypercall_create_continuation( + __HYPERVISOR_memory_op, "lh", XENMEM_foreigncopy, arg); + goto out; + } + } while ( copy.nr_frames ); + + rc =3D 0; + + out: + rcu_unlock_domain(d); + + /* + * Update in all cases, it allows the caller to know how many + * frames were successfully copied and the continuation to + * continue correctly. + */ + if ( __copy_to_guest(arg, ©, 1) && rc >=3D 0 ) + rc =3D -EFAULT; + + return rc; +} + long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { struct domain *d, *curr_d =3D current->domain; @@ -2012,6 +2145,18 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDL= E_PARAM(void) arg) start_extent); break; =20 + case XENMEM_foreigncopy: + /* + * Instead of using "start_extent" we update the structure back, + * we update it back in anyway to tell caller were the copy + * stopped. + */ + if ( unlikely(start_extent) ) + return -EINVAL; + + rc =3D mem_foreigncopy(guest_handle_cast(arg, xen_foreigncopy_t)); + break; + default: rc =3D arch_memory_op(cmd, arg); break; diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index bd9fc37b52..dbf86fd595 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -740,7 +740,49 @@ struct xen_vnuma_topology_info { typedef struct xen_vnuma_topology_info xen_vnuma_topology_info_t; DEFINE_XEN_GUEST_HANDLE(xen_vnuma_topology_info_t); =20 -/* Next available subop number is 29 */ +/* + * Copy memory from/to a given domain. + * As this call requires target access and guest with target access won't = be + * compat guests supported for compat guests this is not implemented. + */ +#define XENMEM_foreigncopy 29 +struct xen_foreigncopy { + /* IN - The domain whose memory is to be copied. */ + domid_t domid; + + /* IN - Flags. */ +#define XENMEM_foreigncopy_from 0 +#define XENMEM_foreigncopy_to 1 +#define XENMEM_foreigncopy_direction 1 + uint16_t flags; + + /* + * IN/OUT + * + * As an IN parameter number of frames of the domain to be copied. + * On output on error updated number of frames left. + */ + uint32_t nr_frames; + + /* + * IN/OUT + * + * Frames to be copied. + * On output on error updated to point to first frame unhandled. + */ + XEN_GUEST_HANDLE(xen_pfn_t) frame_list; + + /* + * IN/OUT + * + * Userspace buffer to read/write from. + */ + XEN_GUEST_HANDLE(uint8) buffer; +}; +typedef struct xen_foreigncopy xen_foreigncopy_t; +DEFINE_XEN_GUEST_HANDLE(xen_foreigncopy_t); + +/* Next available subop number is 30 */ =20 #endif /* __XEN_PUBLIC_MEMORY_H__ */ =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874355; cv=none; d=zohomail.com; s=zohoarc; b=mb5i1L3Ee/yRJZIKFXpFW2DcrTMgf/wUrtX85OSzFGG3LoLPeZPQmxmYe6nqQ0xWPoWthHDF9PuTXnBzPRb26RlxCmytd66tnnPbha9SXFt6bznqCx2jhoEKIr4bcJwYQYKZF4efFFhR1HgoMDR+IZxKQy5Bl78VCJb/aOnq0gU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874355; 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=HooZdhgBaCiFwgXUzAForDPKGFGx999vnsqrg/7EOTU=; b=YejX8Y0c3+PP5GABlfDQ8YUtTdkY98v1DMVt8zkTElIbj+/9uAfQ+6XOm+vP7dObJqmxBCVrlFRNFnPwZJh339p3eKR9AAyhSBmrHtJ0pk2eu9RUdQJ3gDNEpuBj5cAc+1jHwyDDbzvs+3ZnkmRVVYfKDjD2IIpH/0kfPCZ+aqc= 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 1781874355956321.48465141268207; Fri, 19 Jun 2026 06:05:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342211.1602518 (Exim 4.92) (envelope-from ) id 1waYuX-0003aE-H0; Fri, 19 Jun 2026 13:05:29 +0000 Received: by outflank-mailman (output) from mailman id 1342211.1602518; Fri, 19 Jun 2026 13:05:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuX-0003Z5-6I; Fri, 19 Jun 2026 13:05:29 +0000 Received: by outflank-mailman (input) for mailman id 1342211; Fri, 19 Jun 2026 13:05:27 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuV-00031s-51 for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:27 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuU-002qp2-Hr for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:26 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e96-5cb7-0a2a0a5109dd-0a2a4502961a-0 for ; Fri, 19 Jun 2026 15:05:26 +0200 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e96-fdf1-0a2a45020019-d155dd35a441-3 for ; Fri, 19 Jun 2026 15:05:26 +0200 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-462cdb88d01so1443655f8f.0 for ; Fri, 19 Jun 2026 06:05:26 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:25 -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=1781874326; x=1782479126; 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=HooZdhgBaCiFwgXUzAForDPKGFGx999vnsqrg/7EOTU=; b=o9PkIc9rKjlwHGgrhjXNjAqIE0Ya6wZhJjbcMKufWV9ZZzq47BgD7DbXhhATvULc25 b/m2L+M5BJV71ZGkUytii0YBt0cwJZcp4jl4VoiTA6zfTZWtkxGzfUzUcRCrKAlFZ2ko 59NZtGaTJJld5oR4a/SkHySok3gEH1sIVwLUeVqEnO+ag0kUS6AOhkUmGKeeThcT8fl0 tplCTCrZ15//eA4L3T1US3ULa5O/6pyAZRKA1j1OOW2lQWuuNoP7Ez1TRJLMxhXoJbNi y2/5sGKsspJOeYB6+9mRCUN+w7rGhX+RdsQurJ7JIezprXwx2U9l+d8YiWY7OmN74oyk NMSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874326; x=1782479126; 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=HooZdhgBaCiFwgXUzAForDPKGFGx999vnsqrg/7EOTU=; b=BHInXD6cO4VbZJ+0bFXNQcF67PSrvTjBIPd2hc/2g+H3fAeYM4GB/j7cGkEss/BxnH jS1bep3dbvzyj+xNEPum5PbCMvjSbRTn7H60ZYcFNQlqf+RfO20SCcMZgB5dDLi8bF9P xSWShDfAkTBiYUl/DrqkJ+5UMurjEN1RlPFfBmmX20dI5LliX624tSxcA6zmttBry+mD KnNc8fQETJIwRqNY/5zg4Bb6JEWLcNxDjqLZq36niakliTSn4GvirZ8WmxEphhoq8m0e /nVuT4qmXvB+6kyaT8frYfq5gajGnjMTWIm/XrZWNxmImDzVl1p2LEgPND7z9TDLeqMC 3oqg== X-Gm-Message-State: AOJu0Ywpocim+Y+jKyUd5o5UbG8b0NEymCkQAAbC3EcWmwu7eHIPnIKX +GJ01miABBsaI7EF5/KRL1CW+Vj4PfiwKABJo9iHxc8FIEUC3JSUTtDeNeKI8Yk479U= X-Gm-Gg: AfdE7cmCF+2yUVEX+vU4ODjaOg2nc508xB+r5gS6vAkcpHB3M/TJnRZ/bIwHOm8FAwM nH3qsfXbvKsS6TrFwldu6Y5ACJYeTK4OPn6XMT621VXslfUIKBZ+dsSlMshxWBL1JCAn/dnHpd/ ysdjVdFRXuN4fLJ9UmAwFBPFKRCqTOnf0VNMZKTApbrMkNm8fb8st4TyRPxIkwTnrf1BiJEplO0 L6jyaJfozgai4fT4Cmv8oWkYJqyXxyH2ZvNiJKRFwOt/0LInQHk5oJZLYRORf1QvJvGzRKw/b6C Pd9gVFc6mTSbn9gLhftZF6uRdRrzM3lvI/TfNEwp2vzZZw7n2CB9Zry28CPV0eSE6yAjpcmeX8t ireDex2W7+xTLfJSK9PYWdBdh7qDRSI1Gw36/iPOgfQYvEoR1Qi5DHP9SmAzX4acqH+MrH6Hbya OjYh+g1bOe5bnNG1EorRuEQ9G01Bn2L6+jZLhwLT4uw5SQopTbO5TKpTF8dcD/XCGlZGVzgsbkP dMIY6gH6oeX7/I5wN4= X-Received: by 2002:a5d:5f47:0:b0:460:2d57:6923 with SMTP id ffacd0b85a97d-4651da3bf5bmr4733595f8f.10.1781874325651; Fri, 19 Jun 2026 06:05:25 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 13/16] privcmd: Add definition for new Linux privcmd to access new Xen hypercall Date: Fri, 19 Jun 2026 14:04:58 +0100 Message-ID: <20260619130501.272832-14-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1781874326-47E773F3-106676AE/0/0 X-purgate-type: clean X-purgate-size: 1400 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874357653158500 Content-Type: text/plain; charset="utf-8" Userspace should use new ioctl to access new hypercall. Signed-off-by: Frediano Ziglio -- Changes since v4: - update comment. --- tools/include/xen-sys/Linux/privcmd.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/include/xen-sys/Linux/privcmd.h b/tools/include/xen-sys/= Linux/privcmd.h index 607dfa2287..7a3c41308b 100644 --- a/tools/include/xen-sys/Linux/privcmd.h +++ b/tools/include/xen-sys/Linux/privcmd.h @@ -100,6 +100,14 @@ typedef struct privcmd_pcidev_get_gsi { __u32 gsi; } privcmd_pcidev_get_gsi_t; =20 +typedef struct privcmd_foreigncopy { + domid_t dom; /* Foreign domain. */ + __u16 dir; /* Direction, 0 from, 1 to. */ + __u32 num; /* Number of pages to copy. */ + const xen_pfn_t __user *pfns; /* Array of pfns. */ + void __user *buffer; /* Buffer to copy to/from. */ +} privcmd_foreigncopy_t; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -121,6 +129,8 @@ typedef struct privcmd_pcidev_get_gsi { _IOC(_IOC_NONE, 'P', 7, sizeof(privcmd_mmap_resource_t)) #define IOCTL_PRIVCMD_PCIDEV_GET_GSI \ _IOC(_IOC_NONE, 'P', 10, sizeof(privcmd_pcidev_get_gsi_t)) +#define IOCTL_PRIVCMD_FOREIGNCOPY \ + _IOWR('P', 11, privcmd_foreigncopy_t) #define IOCTL_PRIVCMD_UNIMPLEMENTED \ _IOC(_IOC_NONE, 'P', 0xFF, 0) =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874362; cv=none; d=zohomail.com; s=zohoarc; b=A5ZxidvhHlFt/CwRZxnkgnzuuoYQzE9x7Sl0AsE5jGyDZD4C7TKdt02z8+DXqSS/Hafaguy48T+J2v2aEUH/tUQRowUIXX9kNIqRLyKSjC3dcepaxuuU7kM45bEbO0de8aG+UTR06zuOFxAcsaSdrzOfXm6LqxywGMppwnEDWH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874362; 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=Hgv7ktFS+jLe873S6Sbh6nVqNabtaLtoEOjsXoZuzKo=; b=k2y7JxodFNsyHvHrR1PkrE/hel+ewM1zxvzXtN7e+JV4B740XfPMQ5hsR0KFVIKKssnkowmjau/psinThg0crZf7zoL7WoWGikhxVAwMwCvWCqu7upjGL5qCH9iYLH0bvIRPdu9TSI1TFk0cGqzO55Vsk3i3KXMf21Uqpyy0Jqs= 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 1781874362473430.34278079621754; Fri, 19 Jun 2026 06:06:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342215.1602527 (Exim 4.92) (envelope-from ) id 1waYuY-0003s2-W7; Fri, 19 Jun 2026 13:05:30 +0000 Received: by outflank-mailman (output) from mailman id 1342215.1602527; Fri, 19 Jun 2026 13:05:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuY-0003pd-KX; Fri, 19 Jun 2026 13:05:30 +0000 Received: by outflank-mailman (input) for mailman id 1342215; Fri, 19 Jun 2026 13:05:29 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuW-0003Oi-Ns for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:28 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuW-00D4eo-4h for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:28 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e89-2eae-0a2a0a5409dd-0a2a450ba98e-48 for ; Fri, 19 Jun 2026 15:05:27 +0200 Received: from [209.85.218.45] (helo=mail-ej1-f45.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e97-5e53-0a2a450b0019-d155da2dc847-3 for ; Fri, 19 Jun 2026 15:05:27 +0200 Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-c0c2cd63abcso8619666b.2 for ; Fri, 19 Jun 2026 06:05:27 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:26 -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=1781874327; x=1782479127; 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=Hgv7ktFS+jLe873S6Sbh6nVqNabtaLtoEOjsXoZuzKo=; b=cdF3yC64Ce+D2emYuDcoHFM5+ae2GJUS0BVu93IaDgZgKkfbdlvVmIUMWDPEXU2yKt aJ3LG3kqxqVOiQ8xXlb/13q+pDZgSHsUisa+tzdVPsE6EQSxppnT4ScMJmBiG3J9Unvl CVLwp6jnXDe2BQNggOp5f7WNAaW309SbYawfsNZ9n1lAyISG9rzAz8GTaPw2CDiPjIet EagKKo331Upge06Bwo9NG6pVk/QAEqmERcsueksX2BoViJToFOPL7xXzFeLLNZ/YkqCt YHHqTNB16M+kw+cuk/TCkjt+yb62YKdHZJ56+BjwyW6qdvPxDCoBfzpYS2ebZrcdrqo/ 3Wbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874327; x=1782479127; 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=Hgv7ktFS+jLe873S6Sbh6nVqNabtaLtoEOjsXoZuzKo=; b=Z0qZ73yyCPp6sDuM4BtkKNCJGtz7vQpK+//EQrI8QVlVtDLzb6hDbBdPdt8g7K9WA8 nZVNR1HxqsHy2qlHc1FViwLAbQCx5Cgcb3V4QNnREidBtQej2nZ5e2xiX5jZ24qsVx7X tPJayUUOklqrkFXQ95H8ehMFKzkLYzfJLQyw83anx/qe5Q4VNoUKKuswB+SfOHsCrBf3 5MoMaiHb4lshhHRD5IvucD+FhzoHYTUUUAD3TbeRdkBThb7eebHvwWL0f0sG/gJhVqsI QM9WPPN8LhQGw1FSJairXW1CzQfXLW84b7e8ag961M/1I/8uRsSohSvbwo9NYX8igGKj t/hA== X-Gm-Message-State: AOJu0Yz4aBokVz73Wf0RuTPDWROioDvJUmerFh+N7G5i5E8wjKTgVy43 41By5h8+A4ydHu9MLjqINCXvIQaV3uja6Yzn5ZFqaV57s3dmgHySxpw3ctEqLU+51B4= X-Gm-Gg: AfdE7clDC+oS9/ug9q9uiMzydQ2/tAeZgyzLwvUZV+3lnPNJYE5F6/t1o8P7euK85sf sqahgFta3VliebONgRs5EIuilETtCNzX+g1uwsd+tTe6wMTxQCQ+B6nRjQdmv9WPlvFZ005pTOt x5mTQF16ekS8icSNxyWv4yaHA/9EyeRiZArELwdlzWowKDLpe4hWicDptZjgTSNXL7rUmD/vyX6 8RiCUKYDYnKOr8uxBrnYQmwxRavEDiY+8Dg9DmUnsRGXqsANLLOc7PfwH5PKXXrS7SJV9D5vHaz 4AOLPlEC6fm8Nm8PLit3wcfDQNvwbV/rYEUAKzSygvQgiRBcWUs9wYCMvhv/i8pRwxkupOrtS2O NFntO5xAP9JttzlSb1DIymAycymJ2K/VHoZFAsBgIBPcgf/xNb3PU4Xnvm10OvGxI2v2UJKYBZf W1W32KX5oHqbEyFZu8GR0QtloTJDykB9IOyLiHLvIW8YHTcm8kWgLmL0rALdMVPBBI6zj9qxpNy pyHyufc X-Received: by 2002:a17:907:25c1:b0:bee:1e36:876c with SMTP id a640c23a62f3a-c097cbca770mr174465366b.41.1781874327127; Fri, 19 Jun 2026 06:05:27 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 14/16] libs/guest: use new hypercall if available Date: Fri, 19 Jun 2026 14:04:59 +0100 Message-ID: <20260619130501.272832-15-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1781874327-473E300E-1732FAA3/0/0 X-purgate-type: clean X-purgate-size: 3605 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874363723158500 Content-Type: text/plain; charset="utf-8" Use new hypercall if available, otherwise fall back to map+copy+unmap sequence. Signed-off-by: Frediano Ziglio -- Changes since v4: - use int8_t instead of char for signed type. --- tools/libs/guest/xg_sr_common.c | 47 ++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 90da21c35f..c2e7d78e33 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -156,11 +156,6 @@ static void __attribute__((unused)) build_assertions(v= oid) BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params) !=3D 8); } =20 -enum { - foreigncopy_from, - foreigncopy_to -}; - static int xg_foreignmemory_copy(xc_interface *xch, domid_t domid, int dir, size_t nr_pages, void *buffer, const xen_pfn_t foreign_pfns[nr_pages]) @@ -174,8 +169,42 @@ static int xg_foreignmemory_copy(xc_interface *xch, do= mid_t domid, return -1; } =20 + /* + * If foreign copy is supported, -1 not initialized, 0 not supported, + * 1 supported. + */ + static int8_t foreign_copy_supported =3D -1; + + if ( foreign_copy_supported ) + { + int rc; + privcmd_foreigncopy_t copy =3D { + .dom =3D domid, + .dir =3D dir, + .num =3D nr_pages, + .buffer =3D buffer, + }; + DECLARE_HYPERCALL_BOUNCE_IN(foreign_pfns, nr_pages * sizeof(xen_pf= n_t)); + + if ( xc_hypercall_bounce_pre(xch, foreign_pfns) ) + return -1; + + copy.pfns =3D foreign_pfns; + + rc =3D ioctl(xencall_fd(xch->xcall), IOCTL_PRIVCMD_FOREIGNCOPY, &c= opy); + if ( foreign_copy_supported < 0 ) + foreign_copy_supported =3D + (!rc || (errno !=3D ENOTTY && errno !=3D ENOSYS)); + + xc_hypercall_bounce_post(xch, foreign_pfns); + + if ( foreign_copy_supported ) + return rc; + } + + /* Fallback, emulate. */ int err[nr_pages]; - const int prot =3D (dir =3D=3D foreigncopy_from) ? PROT_READ : PROT_RE= AD|PROT_WRITE; + const int prot =3D (dir =3D=3D XENMEM_foreigncopy_from) ? PROT_READ : = PROT_READ|PROT_WRITE; =20 void *p =3D xenforeignmemory_map(xch->fmem, domid, prot, nr_pages, for= eign_pfns, err); if ( !p ) @@ -189,7 +218,7 @@ static int xg_foreignmemory_copy(xc_interface *xch, dom= id_t domid, return -1; } =20 - if ( dir =3D=3D foreigncopy_from ) + if ( dir =3D=3D XENMEM_foreigncopy_from ) memcpy(buffer, p, nr_pages * XC_PAGE_SIZE); else memcpy(p, buffer, nr_pages * XC_PAGE_SIZE); @@ -201,7 +230,7 @@ int xg_foreignmemory_copy_from(xc_interface *xch, domid= _t dom, size_t nr_pages, void *dest, const xen_pfn_t source[nr_pages]) { - return xg_foreignmemory_copy(xch, dom, foreigncopy_from, + return xg_foreignmemory_copy(xch, dom, XENMEM_foreigncopy_from, nr_pages, dest, source); } =20 @@ -209,7 +238,7 @@ int xg_foreignmemory_copy_to(xc_interface *xch, domid_t= dom, size_t nr_pages, const xen_pfn_t dest[nr_page= s], const void *source) { - return xg_foreignmemory_copy(xch, dom, foreigncopy_to, + return xg_foreignmemory_copy(xch, dom, XENMEM_foreigncopy_to, nr_pages, (void *) source, dest); } =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874354; cv=none; d=zohomail.com; s=zohoarc; b=UXUuOV2Y5er7/clE9P0RJ4PXLuTXPi/WKkYox1PDz2lnX2x6Epi5VxYBgMtO3zKtlxUFwUVLZWAmuLCrYL8u542sWjCo27W3IDHkhmUgaI+Y2BP4YjUzBAMM+b/h8ec3+Kmb7tl8OZG18pQTn/Uc0GTIV1p0zmXmD/CZNqGr1bg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874354; 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=3Ff5kZpJnZoWVUEHvo6/yv/R6ViOZwYTEyBjzyp1uSE=; b=Asv4Gce1BJoPiyFnuUv5NjIoF9lLMZMI6SN0yDOtcCnhmWC0zrvefAJc+y7Hhkk5dgSGb8y10wUP1gxh6FtGVjNUUSWmFPjh0brggCfL9oMMqRvmK5P7LSICwNNAHydUNNh6B6L0n+t8fEbvSd3R5PJ71qMueryZhg3tdnPvURY= 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 1781874354616134.34018537888187; Fri, 19 Jun 2026 06:05:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342219.1602533 (Exim 4.92) (envelope-from ) id 1waYuZ-0003xh-KO; Fri, 19 Jun 2026 13:05:31 +0000 Received: by outflank-mailman (output) from mailman id 1342219.1602533; Fri, 19 Jun 2026 13:05:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuZ-0003vZ-8m; Fri, 19 Jun 2026 13:05:31 +0000 Received: by outflank-mailman (input) for mailman id 1342219; Fri, 19 Jun 2026 13:05:29 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuX-0003ba-Lv for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuX-002qp2-2J for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:29 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e87-5cb7-0a2a0a5109dd-0a2a450a86f4-30 for ; Fri, 19 Jun 2026 15:05:29 +0200 Received: from [209.85.128.43] (helo=mail-wm1-f43.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e98-93a5-0a2a450a0019-d155802ba851-3 for ; Fri, 19 Jun 2026 15:05:29 +0200 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-490b8ac62baso30807175e9.0 for ; Fri, 19 Jun 2026 06:05:28 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:27 -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=1781874328; x=1782479128; 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=3Ff5kZpJnZoWVUEHvo6/yv/R6ViOZwYTEyBjzyp1uSE=; b=M+9bZ9dFnC/aotkPpIaQ1S4sdXPxRunS+rfJMaTzmKItzK5xrOLCnYMsGSqOW+KTYj A1fdLytdOpDoHnxgQeAVZl4R5gA4VxZDNul5cy427tiol9CxMViIOM/5GUL2q+q2Sf/d Mn6f766VoL2/kFy3ZuqzbPQUlAnBM8ltNrq/6oDs09ZlwIw8VaczrS5Zpy5FUPrio4AG tX0Wa7ksOmHIWZD+R2QzK9OwLRvj3fzhoHJ31vKm/vUfToifVJhU40sIIs5V8LtuoCYk k5Kqtq2Y7bHxeOko0zk4TT3tSLzLSZgtnX5/oyLYSi0iKwMz1IrmX1jRDcOrbB9RUIvO /ztQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874328; x=1782479128; 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=3Ff5kZpJnZoWVUEHvo6/yv/R6ViOZwYTEyBjzyp1uSE=; b=c/HCH3tOTBmAkMX1RDhjG0QLf1QWGiubreidA279+uvkk/o3mZkoO6D78tMJkFC7Ve PjUiYzD9a9/H+x+MurItNNHrdsW8tsZklH83wFtADnASWiBp2yNDRxllDl8dlEZxLSTt sBfkXA1pEwayJnt+9y5XrVYJVReMr8L3Hp4tIGXOYKuJ8y029dqaLLZ+Mj14OZDFwHaH ZH2L4P/R+HsvOSbzDNnEjSeuonTJccJnZLrXAyMNChUT6LZGs6ZkmmKaglCkZoWdcFnZ wUJopPxBtM3Q3DJ9jM22A9Bek6CpTnlaWH9K2Jo92yOwIE8ufKpUhxmb45y9e5YbmsG3 1rMA== X-Gm-Message-State: AOJu0YzLHHFwcFmxOiReVO2ajGVG3YguudPNVrg8OV6fF6mjes1IdXsO rLjYEPqDZCmBRJG0ygP2dIaLEs8GaDB76M7sMtd5LFhEcgrJdZFiyjiEEPLVnfQFjHg= X-Gm-Gg: AfdE7clI5yvliIWvvP8MWzSYUaQfS/yvt2ViiH1T/zi32YUnGHUkcjSqgm9O6H8uTgJ +Cp42ePA6+tHIv8RPr7LD8oM4Z2B5zughRSZTCTL0XP0XFWzCyOvGWJGkN2ACDL5lhvfrHwZAdZ zYyw0KShAZKnMPp9bkHB2I7CzFxU53ayrLI5TylxZNKLvfOKS3JRnqrKqls42k/48sY8dxqPBAl MCBVo+pBPIEGocVdzxbz8KRIIQvanhpJ7+w0tu6630ygm74ovzDzMvaw6OU4zpsRkAhayhHQYs1 pDeAKl3bFaaoowpk3bGC5JcYnE8QP6JXdNA0XU2cEQxvs0r8TnFCD0Xl8vk4UfNHgXcXZymGJCV 004rd3vG2sPzQ0HNQXqjeNawP2inCMC7DRi2MI1pRbGtAGIDgQURXjGmj0rU+W5yeiUaQHkhr14 YVuQ1+BOCzXigz4I9hzm2S0qLMJyY5VOhnNofenOeWnzhPp0sR6sXY3h89IkD1OO27N9ToDvztb hAe6DRn X-Received: by 2002:a05:600c:42d3:b0:48e:8eb0:4957 with SMTP id 5b1f17b1804b1-49240a00dacmr34007335e9.2.1781874328194; Fri, 19 Jun 2026 06:05:28 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v6 15/16] libs/guest: finalize PoC Date: Fri, 19 Jun 2026 14:05:00 +0100 Message-ID: <20260619130501.272832-16-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1781874329-B05F8DB8-08FF7610/0/0 X-purgate-type: clean X-purgate-size: 10539 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874355796158500 Content-Type: text/plain; charset="utf-8" Remove now unused map_errs array. Test and restore verification code. Report correctly errors from writev_exact. Allocate verification buffer using hypercall buffer to avoid errors using hypercall. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.h | 4 +- tools/libs/guest/xg_sr_restore.c | 45 +++++++++++++++-- tools/libs/guest/xg_sr_save.c | 83 +++++++++++++++++++++----------- 3 files changed, 98 insertions(+), 34 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index d8d8a0f9f7..cd562f028a 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -217,7 +217,6 @@ struct xc_sr_context_save_buffers void *local_pages[MAX_BATCH_SIZE]; struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */ uint64_t rec_pfns[MAX_BATCH_SIZE]; - int errors[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context @@ -255,8 +254,8 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + xc_hypercall_buffer_t dest_buf; struct xc_sr_context_save_buffers *buffers; - void *dest_buf; } save; =20 struct /* Restore data. */ @@ -267,6 +266,7 @@ struct xc_sr_context int send_back_fd; unsigned long p2m_size; xc_hypercall_buffer_t dirty_bitmap_hbuf; + xc_hypercall_buffer_t verify_buf; =20 /* From Image Header. */ uint32_t format_version; diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index ff27560ff7..b2df36c6f6 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -257,16 +257,15 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, { xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)); - int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; unsigned nr_pages; void *const source =3D page_data; =20 - if ( !mfns || !map_errs ) + if ( !mfns ) { rc =3D -1; ERROR("Failed to allocate %zu bytes to process page data", - count * (sizeof(*mfns) + sizeof(*map_errs))); + count * sizeof(*mfns)); goto err; } =20 @@ -314,13 +313,33 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, if ( rc < 0 ) goto err; } + else + { + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, verify_buf, + &ctx->restore.verify_buf); + + rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, verif= y_buf, mfns); + if ( rc < 0 ) + goto err; + + void *guest_page =3D verify_buf; + page_data =3D source; + for ( unsigned i =3D 0; i < nr_pages; ++i ) + { + /* Verify mode - compare incoming data to what we already have= . */ + if ( memcmp(guest_page, page_data, PAGE_SIZE) ) + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + + guest_page +=3D PAGE_SIZE; + page_data +=3D PAGE_SIZE; + } + } =20 done: rc =3D 0; =20 err: - - free(map_errs); free(mfns); =20 return rc; @@ -710,6 +729,18 @@ static int setup(struct xc_sr_context *ctx) int rc; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->restore.dirty_bitmap_hbuf); + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, verify_buf, + &ctx->restore.verify_buf); + + verify_buf =3D xc_hypercall_buffer_alloc_pages( + xch, verify_buf, MAX_BATCH_SIZE); + + if ( !verify_buf ) + { + ERROR("Unable to allocate memory for test buffer"); + rc =3D -1; + goto err; + } =20 if ( ctx->stream_type =3D=3D XC_STREAM_COLO ) { @@ -758,6 +789,8 @@ static void cleanup(struct xc_sr_context *ctx) unsigned int i; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->restore.dirty_bitmap_hbuf); + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, verify_buf, + &ctx->restore.verify_buf); =20 for ( i =3D 0; i < ctx->restore.buffered_rec_num; i++ ) free(ctx->restore.buffered_records[i].data); @@ -766,6 +799,8 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size))= ); =20 + xc_hypercall_buffer_free_pages(xch, verify_buf, MAX_BATCH_SIZE); + free(ctx->restore.buffered_records); free(ctx->restore.populated_pfns); =20 diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 7a48f6b0a3..f6ada3152d 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -88,7 +88,7 @@ static int write_batch(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; void **local_pages; - int *errors, rc =3D -1; + int rc =3D -1; unsigned int i, nr_pages =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; uint64_t *rec_pfns; @@ -108,8 +108,6 @@ static int write_batch(struct xc_sr_context *ctx) mfns =3D ctx->save.buffers->mfns; /* Types of the batch pfns. */ types =3D ctx->save.buffers->types; - /* Errors from attempting to map the gfns. */ - errors =3D ctx->save.buffers->errors; /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D ctx->save.buffers->local_pages; memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); @@ -165,18 +163,54 @@ static int write_batch(struct xc_sr_context *ctx) =20 iovcnt =3D 2; =20 - rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, ctx->save= .dest_buf, mfns); - if ( rc < 0 ) - { - ERROR("xg_foreignmemory_copy_from failed"); - goto err; - } - if ( nr_pages ) { - iov[iovcnt].iov_base =3D ctx->save.dest_buf; - iov[iovcnt].iov_len =3D nr_pages << XC_PAGE_SHIFT; - iovcnt++; + int p; + void *page, *orig_page; + + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, dest_buf, + &ctx->save.dest_buf); + + rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, dest_= buf, mfns); + if ( rc < 0 ) + { + ERROR("xg_foreignmemory_copy_from failed"); + goto err; + } + + for ( i =3D 0, p =3D 0; i < nr_pfns; ++i ) + { + if ( !page_type_has_stream_data(types[i]) ) + continue; + + orig_page =3D page =3D dest_buf + (p * PAGE_SIZE); + rc =3D ctx->save.ops.normalise_page(ctx, types[i], &page); + + if ( orig_page !=3D page ) + local_pages[i] =3D page; + + if ( rc ) + { + if ( rc !=3D -1 || errno !=3D EAGAIN ) + goto err; + + set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pages); + ++ctx->save.nr_deferred_pages; + types[i] =3D XEN_DOMCTL_PFINFO_XTAB; + --nr_pages; + } + else if ( iov[iovcnt-1].iov_base + iov[iovcnt-1].iov_len =3D= =3D page ) + { + iov[iovcnt-1].iov_len +=3D PAGE_SIZE; + } + else + { + iov[iovcnt].iov_base =3D page; + iov[iovcnt].iov_len =3D PAGE_SIZE; + iovcnt++; + } + ++p; + } } =20 hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -187,6 +221,7 @@ static int write_batch(struct xc_sr_context *ctx) if ( writev_exact(ctx->fd, iov, iovcnt) ) { PERROR("Failed to write page data to stream"); + rc =3D -1; goto err; } =20 @@ -717,30 +752,23 @@ static int setup(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; int rc; - const unsigned dest_buf_len =3D MAX_BATCH_SIZE * XC_PAGE_SIZE; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, dest_buf, + &ctx->save.dest_buf); =20 rc =3D ctx->save.ops.setup(ctx); if ( rc ) goto err; =20 + dest_buf =3D xc_hypercall_buffer_alloc_pages( + xch, dest_buf, MAX_BATCH_SIZE); dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); - ctx->save.dest_buf =3D NULL; - - rc =3D posix_memalign(&ctx->save.dest_buf, XC_PAGE_SIZE, dest_buf_len); - if ( rc ) - { - ERROR("Unable to allocate %u bytes of buffer", dest_buf_len); - errno =3D rc; - rc =3D -1; - goto err; - } =20 - if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) + if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers = || !dest_buf ) { ERROR("Unable to allocate memory for dirty bitmaps, deferred pages" " and various batch buffers"); @@ -761,7 +789,8 @@ static void cleanup(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); - + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, dest_buf, + &ctx->save.dest_buf); =20 xc_shadow_control(xch, ctx->domid, XEN_DOMCTL_SHADOW_OP_OFF, NULL, 0); @@ -771,9 +800,9 @@ static void cleanup(struct xc_sr_context *ctx) =20 xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); + xc_hypercall_buffer_free_pages(xch, dest_buf, MAX_BATCH_SIZE); free(ctx->save.deferred_pages); free(ctx->save.buffers); - free(ctx->save.dest_buf); } =20 /* --=20 2.43.0 From nobody Thu Jul 23 22:26:30 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=1781874364; cv=none; d=zohomail.com; s=zohoarc; b=VEjX3+LBreoUUI/J7SMNaUmB3BfazRng59U4ZP3VhQ50dvZlllLBFQGLraSjdmNjlier1UpMj45lJxY8iaAAqLPgwuW5DYvcfEVDnOa7OLYRI4cnvJxLg2AO1jMSKtJCwh2GN4R933duuRKwA3Ufl0PXW7ekizo+fXFU72ccNPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781874364; 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=in4wc4RHuN4wnGlvZnYvNPCqhNJf+PX4+zFEttlP3cI=; b=NEZoSxoQWPT70qWCXnJvMwVzxrcokHS9QdrjxwYSIWqpuj15+guODhDpWX3NmoYORgcMNd6HOOlRgQVqcFot1XUPzvBmDV674zhX5Fgi4VwT4PLxoT5eSYIJiB9UbLeseF1h9wC/FlyW5VwRdLTWqLdqla8ziD/6c85efoqqWf0= 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 1781874364718162.18097947180092; Fri, 19 Jun 2026 06:06:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1342221.1602541 (Exim 4.92) (envelope-from ) id 1waYub-0004HM-2r; Fri, 19 Jun 2026 13:05:33 +0000 Received: by outflank-mailman (output) from mailman id 1342221.1602541; Fri, 19 Jun 2026 13:05:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYua-0004Dt-Ic; Fri, 19 Jun 2026 13:05:32 +0000 Received: by outflank-mailman (input) for mailman id 1342221; Fri, 19 Jun 2026 13:05:30 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1waYuY-0003mE-HX for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 13:05:30 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1waYuX-005gIU-U0 for xen-devel@lists.xenproject.org; Fri, 19 Jun 2026 15:05:29 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a353e99-e002-0a2a0a5209dd-0a2a4505c468-4 for ; Fri, 19 Jun 2026 15:05:29 +0200 Received: from [209.85.221.54] (helo=mail-wr1-f54.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.0) (envelope-from ) id 6a353e99-ef3d-0a2a45050019-d155dd36c15d-3 for ; Fri, 19 Jun 2026 15:05:29 +0200 Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-4626fdc829aso1606309f8f.3 for ; Fri, 19 Jun 2026 06:05:29 -0700 (PDT) Received: from localhost.localdomain (8.17.6.51.dyn.plus.net. [51.6.17.8]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4650bc428d9sm7960088f8f.27.2026.06.19.06.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2026 06:05:28 -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=1781874329; x=1782479129; 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=in4wc4RHuN4wnGlvZnYvNPCqhNJf+PX4+zFEttlP3cI=; b=dXImFdDFQuNiev9VsBsxGovO5HEkkliS+48AqyRwEQ/IZcbjzEQQZhdP+VWyfW03gv Xm8q6+xO+/2YChLTvYvTdQYr21yyZGZIo3dJiVsxvpKHFMU29hPEH4f2RDCQWB1k19N2 fUEShwyiYx5Qd9ZcBAJ6NVU6VjYl8GkkT/cNos5HEH/enGef2ccrtK9c3I+7CApXngvw plE3WS1qfe0+8GvIW7gsG9kpRNCkrqqajn3Kz5mE/Jaib9ei8fp5HjhaCDii2lKq2A5H hJBEUZeoTo/bXDiKofh0ihoFH3IyhM0OnGCAvBsbgUH7+KHLbRRldCOelZzLavu6xcbo 6x6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781874329; x=1782479129; 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=in4wc4RHuN4wnGlvZnYvNPCqhNJf+PX4+zFEttlP3cI=; b=AvXcwSX22UBLFMr2sjadPwkA1/0x1XmpF9IsXsLNbKmGgl4Bs1PaymOBj3lU3NjY3k rRTfIb9bUOD9bbXpnZPt/T4fEZD8IILfy7SP4GYz4nH6oNYZUEzuev/gXAYY3csppHno TzMItJL9PLevgCatdtBPKFyjHy1rpDlWBGy4arFu5zRfcfa3RzP0YZjSVrSE4FE1tOhi gZ51e2W5bWoucEX45fMsYbe306XdCdxP08bNnx261rnS0vF9tMKP7tIFXLJSyKS+aXWm aHCXJ7yOMM6i6qu+lFrIurt+Dr0Ati+TaxW6H7Grn+i/XxBlh4blRYGsnLwnHUcHTF6E v4xQ== X-Gm-Message-State: AOJu0YxAhAYGsm7GamwO5FTPHYNqX7YSvRqhbFhzXiCqXjzmGPTfg+4O GOETafrsHq/BlZbKjXmhJv3UBKkIjpTUOXs+45GIHtYZutmN/yhkhiDc04Uh6K9w5OA= X-Gm-Gg: AfdE7clCsAHT1kK05Uko6Aa5701JROmBmq1chYJmgejV6vsbkq7bHwM7joRU4e0fBTM b9kFreJFe1R2j/RBnO81b+/mWMr8wS6LdImi9LHi9fTfZyTZNHEf+mA5xvu7fGCAsjb15C1vtou Jzdwao1lYPHlH/vS7RBCm4t7UX3I5AZYFvUrUiE+Og5DRluHslF9ds8BeWckpCGyVzgaxyp3y9v n7owdX8+SbrNcZGOeI1URi7fThU+axplyz9pP5eQ9baE03rCLTZbq5tQl98kDIV0QYd2lhktk6O Ly16r5Uq6gr0yySbjx/eIF/6oCo5w6g/O4TKfaijxKTKIHd/6EGevjro/0ItXu5nv1i3UM5DEBt YvUQ1TyM9D6BjUcbY5YLIWktEQyZNAeHABevfw6xVG7ass2mE77jeD7FI7yVK6HJKj1dYVtJD52 59Q3j6C6yfAL3vtWYxkNfshmbuMbT2tS0JSiYOjy3KSi9KNZrYtR4WV9vWCxesrq+y8PrfAoGOm GMz8znT X-Received: by 2002:a5d:5d10:0:b0:462:4b98:3c83 with SMTP id ffacd0b85a97d-4656f4704a9mr3496293f8f.23.1781874329118; Fri, 19 Jun 2026 06:05:29 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH Linux v6 16/16] xen/privcmd: Add new ABI to allow copying foreign memory Date: Fri, 19 Jun 2026 14:05:01 +0100 Message-ID: <20260619130501.272832-17-frediano.ziglio@citrix.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260619130501.272832-1-frediano.ziglio@citrix.com> References: <20260619130501.272832-1-frediano.ziglio@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1781874329-9FFD2127-5BD508FC/0/0 X-purgate-type: clean X-purgate-size: 5338 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781874365975158500 Content-Type: text/plain; charset="utf-8" This new ABI allows to copy foreign domain memory to/from a buffer. This avoids having to map/copy/unmap foreign memory which is expensive. This operation is done particularly when migrating VMs. Signed-off-by: Frediano Ziglio -- Changes since v4: - fix wrong assign; - use set_xen_guest_handle to set handle; - wrap slow hypercall with xen_preemptible_hcall_{begin,end}; - use _IOWR for ioctl code to be more specific; - use __copy_to_user if buffer already checked. Reviewed-by: Juergen Gross --- arch/x86/include/asm/xen/interface.h | 1 + drivers/xen/privcmd.c | 49 ++++++++++++++++++++++++++++ include/uapi/xen/privcmd.h | 10 ++++++ include/xen/interface/memory.h | 37 +++++++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/arch/x86/include/asm/xen/interface.h b/arch/x86/include/asm/xe= n/interface.h index a078a2b0f032..bac3c3bc60fd 100644 --- a/arch/x86/include/asm/xen/interface.h +++ b/arch/x86/include/asm/xen/interface.h @@ -91,6 +91,7 @@ DEFINE_GUEST_HANDLE(int); DEFINE_GUEST_HANDLE(void); DEFINE_GUEST_HANDLE(uint64_t); DEFINE_GUEST_HANDLE(uint32_t); +DEFINE_GUEST_HANDLE(uint8_t); DEFINE_GUEST_HANDLE(xen_pfn_t); DEFINE_GUEST_HANDLE(xen_ulong_t); #endif diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 725a49a0eee7..67bf085d91e1 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -1522,6 +1522,51 @@ static inline void privcmd_ioeventfd_exit(void) } #endif /* CONFIG_XEN_PRIVCMD_EVENTFD */ =20 +static long privcmd_ioctl_foreigncopy( + struct file *file, void __user *udata) +{ + const struct privcmd_data *const data =3D file->private_data; + long ret; + struct privcmd_foreigncopy copy; + struct xen_foreigncopy xcopy; + + if (copy_from_user(©, udata, sizeof(copy))) + return -EFAULT; + if (copy.dir & ~1u) + return -EINVAL; + if (copy.num >=3D U32_MAX >> PAGE_SHIFT) + return -EINVAL; + if (!access_ok(copy.pfns, copy.num * sizeof(*copy.pfns))) + return -EFAULT; + if (!access_ok(copy.buffer, copy.num << PAGE_SHIFT)) + return -EFAULT; + + /* If restriction is in place, check the domid matches */ + if (data->domid !=3D DOMID_INVALID && data->domid !=3D copy.dom) + return -EPERM; + + xcopy.domid =3D copy.dom; + xcopy.flags =3D copy.dir; + xcopy.nr_frames =3D copy.num; + set_xen_guest_handle(xcopy.frame_list, (__force xen_pfn_t *)copy.pfns); + set_xen_guest_handle(xcopy.buffer, (__force uint8_t *)copy.buffer); + + xen_preemptible_hcall_begin(); + ret =3D HYPERVISOR_memory_op(XENMEM_foreigncopy, &xcopy); + xen_preemptible_hcall_end(); + + /* copy values back in case of error */ + if (ret) { + copy.num =3D xcopy.nr_frames; + copy.pfns =3D xcopy.frame_list; + copy.buffer =3D xcopy.buffer; + if (__copy_to_user(udata, ©, sizeof(copy))) + ret =3D -EFAULT; + } + + return ret; +} + static long privcmd_ioctl(struct file *file, unsigned int cmd, unsigned long data) { @@ -1569,6 +1614,10 @@ static long privcmd_ioctl(struct file *file, ret =3D privcmd_ioctl_pcidev_get_gsi(file, udata); break; =20 + case IOCTL_PRIVCMD_FOREIGNCOPY: + ret =3D privcmd_ioctl_foreigncopy(file, udata); + break; + default: break; } diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index 8e2c8fd44764..993b501e35bf 100644 --- a/include/uapi/xen/privcmd.h +++ b/include/uapi/xen/privcmd.h @@ -131,6 +131,14 @@ struct privcmd_pcidev_get_gsi { __u32 gsi; }; =20 +struct privcmd_foreigncopy { + domid_t dom; /* foreign domain */ + __u16 dir; /* direction, 0 from, 1 to */ + __u32 num; /* number of pages to copy */ + const xen_pfn_t __user *pfns; /* array of pfns */ + void __user *buffer; /* buffer to copy to/from */ +}; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -164,5 +172,7 @@ struct privcmd_pcidev_get_gsi { _IOW('P', 9, struct privcmd_ioeventfd) #define IOCTL_PRIVCMD_PCIDEV_GET_GSI \ _IOC(_IOC_NONE, 'P', 10, sizeof(struct privcmd_pcidev_get_gsi)) +#define IOCTL_PRIVCMD_FOREIGNCOPY \ + _IOWR('P', 11, struct privcmd_foreigncopy) =20 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h index 1a371a825c55..5981402fccde 100644 --- a/include/xen/interface/memory.h +++ b/include/xen/interface/memory.h @@ -325,4 +325,41 @@ struct xen_mem_acquire_resource { }; DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource); =20 +/* + * Copy memory from/to a given domain. + */ +#define XENMEM_foreigncopy 29 +struct xen_foreigncopy { + /* IN - The domain whose resource is to be copied */ + domid_t domid; + + /* IN - Flags */ +#define XENMEM_foreigncopy_from 0 +#define XENMEM_foreigncopy_to 1 +#define XENMEM_foreigncopy_direction 1 + uint16_t flags; + + /* + * IN + * + * As an IN parameter number of frames of the domain to be copied. + */ + uint32_t nr_frames; + + /* + * IN + * + * Frames to be copied. + */ + GUEST_HANDLE(xen_pfn_t) frame_list; + + /* + * IN/OUT + * + * Userspace buffer to read/write from. + */ + GUEST_HANDLE(uint8_t) buffer; +}; +DEFINE_GUEST_HANDLE_STRUCT(xen_foreigncopy); + #endif /* __XEN_PUBLIC_MEMORY_H__ */ --=20 2.54.0