From nobody Mon Jun 8 07:24:34 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=1780491996; cv=none; d=zohomail.com; s=zohoarc; b=Fq5c9KC1VRIbNkauKcdArCu8nVaBSMDSvSAhBRPsqXSAdhzEieTRtnXpckT2n6cEiPwGPCSnxehrwBvDN/Lxb3gCZmmL/LP1uqQ0xw6pMJrcf0ZSf7LHimm571I3AsXeCL6XpIF8eOmn0cLpW8Ny5N7p6aHOsjInqQ+nJqB6Tw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780491996; 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=/H+CjEBJpsrZPsr1tA2Dr4sF8Rh9SLgca+SlhR+hbSM=; b=XZZSdjDwYsz1E4KtS5LBJpydeAtPO9L6G/bCtMcmXt8T85pACt+gTXaZC+76jPNAouTDBu4kxhJhHUzG1RZ8q0zUoYTftjOuKA8QHth85HPlziXxUPwK3P7Aqcz3ReDDELW7VtM7n9/WihjJ/ClBHC14TDz1Gea/6fcQyu3Y7Qs= 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 1780491996769380.8671196653743; Wed, 3 Jun 2026 06:06:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326224.1591660 (Exim 4.92) (envelope-from ) id 1wUlIb-0005DA-6H; Wed, 03 Jun 2026 13:06:21 +0000 Received: by outflank-mailman (output) from mailman id 1326224.1591660; Wed, 03 Jun 2026 13:06: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 1wUlIb-0005D1-2y; Wed, 03 Jun 2026 13:06:21 +0000 Received: by outflank-mailman (input) for mailman id 1326224; Wed, 03 Jun 2026 13:06:19 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIZ-000501-C1 for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIY-006lQ8-Ok for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:18 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026c5-e002-0a2a0a5209dd-0a2a45058c04-12 for ; Wed, 03 Jun 2026 15:06:18 +0200 Received: from [209.85.128.54] (helo=mail-wm1-f54.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026ca-aaa8-0a2a45050019-d1558036d569-3 for ; Wed, 03 Jun 2026 15:06:18 +0200 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-49068493267so75582595e9.1 for ; Wed, 03 Jun 2026 06:06:18 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491978; x=1781096778; 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=/H+CjEBJpsrZPsr1tA2Dr4sF8Rh9SLgca+SlhR+hbSM=; b=cH/Dp2PzmOoFWwbjHSc5MOnndbvy/sldZmb95J6kVSSWpMQh5ns3c8HPTmEZlv4v38 60IAICO71d1TTd+pzd1qZCvVNYDju9Ho/YCg4xQVIMojRlFvfxT2yprsWKKZGqBZ8CXS i7bc0VS6e7hpmUxouOBdveDeYxQ5pSyEGmvVTKbcoEP0kMRWPMxue9fMQdLhDzhv4xav KG5gW0MGzZWD85U2EvBMA7OML1kiqAHlQRaiUGgjAxj5FE6qhVrGNjnnp9QDT75eeioe d5867S3T0Ib4PRJMbAu6L1K+e6WAGfJA72KMOxWfkxx+FmI5mDKWZKm+owIUf/erh9Cy /0MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491978; x=1781096778; 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=/H+CjEBJpsrZPsr1tA2Dr4sF8Rh9SLgca+SlhR+hbSM=; b=Rz4nFDNd66hCwC+btgBDbKRPU/fKDrJVq9nYn4Uys4X3E7YeEmRYicoMuPa1cXKMyN WC6YGP5yej4Q4lphXmKQG1M+w+1clCmWnH3GBIkIkg4IvXghcX7xWaQPy84XX9QpsVX8 KI/6z6ZdxJY4rgUGedzXWCKIAasDZkYTHyWUNW1hsOfLTTOq94GCr8dAppeQ5X8LjwFY iaqUAVepP4qnTqha25l/gu817YtRD/Om0TXpfRf41lkwr88gyICOv9W/XnW8vMzo2jUJ uV5jK/EZ+mRhlpDxuuUIjt7ZqPVcdmbrAeHdQfeVpkhxutNQ3IAT/8HDJRKMjzSiegQ8 PYYQ== X-Gm-Message-State: AOJu0YzGWn1DkVwPaUyzAtPJr4YWNS+TtWDbV6cDO5OX+OQDJgOP/LwV tgBxexUHj98kzvrWb6RFfUfucAjITDJB7PnZVfZitfgYpZL7d/Gru6c5n8crDHmX X-Gm-Gg: Acq92OEM7v7l/INcdMHdxrtpAv8ULrIvmD2GotgxMlZxdqDHPH0EwMjyU6sD2Crr415 lZmr9KFDIrS20I8TVNCSQohvlvdX5+b9qkvBnLzu0K9ccZuvoKdjdTJXtpkWjXDY4/7tyoCMFeZ iqMq+NpcmqOxXmVd5A6tDRGJ/lg/8z1sItIb5cEtC0pDE9e71RrsosS3oHm1eG7VoTzmA88FgTM Wd19pCGKlnir0jwQv3IUkSxhF6g/rxbDuUUHu8y/llWuvZ63uzbo5YpmZNCmOlb92Kl28cZcACd B7qXfoMUoz+yie3MmZ6eAe7CrZv8h0s89UfQL/LqQamjGZ0KgmeS5k49dHjTAng4W7alpfpvIdj x2Z7sWCBkCEeW2U2S/u1mZjp5UgUbqmdHPKY2RcHKZqWode8pRzqGhEdmimPIFC+cyGGmeA1EMk pZF3devaQ9INatoPPLuMsyW6KQcNjRL6F3g1s0aF4eeJhPmjTyN6824vX+0Ulas+Noro8CCt+Pq L6wZN0Xbq04ysEDKJUzwXZHYXTOhsh1o/m/ X-Received: by 2002:a05:600c:c10e:b0:485:3abe:ab86 with SMTP id 5b1f17b1804b1-490b5e839bdmr49022045e9.4.1780491977829; Wed, 03 Jun 2026 06:06:17 -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 v4 01/16] libs/guest: Reduce number of parts in write_split_record Date: Wed, 3 Jun 2026 14:05:48 +0100 Message-ID: <20260603130603.776452-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1780491978-DA175443-10456DE8/0/0 X-purgate-type: clean X-purgate-size: 1781 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780491999531154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. There's no much sense to split the header in 2 pieces, it will just take more time and space to reassemble them in the final buffer. This also avoids truncating combined_length to 32 bit in case of 64 bit machines potentially avoiding following record_length check (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 -- Changes since v2: - change prefix in subject. Changes since v3: - clarify commit message. --- tools/libs/guest/xg_sr_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 7ccdc3b1f6..86c148c62f 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -59,11 +59,11 @@ int write_split_record(struct xc_sr_context *ctx, struc= t xc_sr_record *rec, static const char zeroes[(1u << REC_ALIGN_ORDER) - 1] =3D { 0 }; =20 xc_interface *xch =3D ctx->xch; - typeof(rec->length) combined_length =3D rec->length + sz; + size_t combined_length =3D rec->length + sz; size_t record_length =3D ROUNDUP(combined_length, REC_ALIGN_ORDER); + struct xc_sr_rhdr rhdr =3D { rec->type, combined_length }; struct iovec parts[] =3D { - { &rec->type, sizeof(rec->type) }, - { &combined_length, sizeof(combined_length) }, + { &rhdr, sizeof(rhdr) }, { rec->data, rec->length }, { buf, sz }, { (void *)zeroes, record_length - combined_length }, --=20 2.54.0 From nobody Mon Jun 8 07:24:34 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=1780492006; cv=none; d=zohomail.com; s=zohoarc; b=P9qzavdnRscueWWnoh8Yz9QJvqhd7LaaFJRYptAf6S4t+h0qhkVWdhoccFkKzLMspAch1LP8MZLAh7z84GEpItg1ru92molcOe/0lHBFdjJsBADeK15hLz8CVa0dRStFY/M3Nm85tg3ml1+/DwZwKG1vGuZVztMGZjjY2AgFOSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492006; 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=YRDIkYEFhAoyg2vrbD/w/bb4Chd8wbV0BhcfXDreNEc=; b=g6GGgw7k4Q+DL/HMcFXmigs4MhNbLmwJzqvCds7/CnKo4JkdKWi2kVdb0RmT/m3CpWA2j6Cx5FNNnXdz/MPc+oOiqYhD3s26iNzd7Rlonm3NR88XI7fpGl5eaSLisc41wuRfSBt2CKl8LJ2uqghygH3IGGJOnnQvJFovYbbS6uw= 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 178049200695369.88378109264363; Wed, 3 Jun 2026 06:06:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326225.1591669 (Exim 4.92) (envelope-from ) id 1wUlIc-0005RK-Gr; Wed, 03 Jun 2026 13:06:22 +0000 Received: by outflank-mailman (output) from mailman id 1326225.1591669; Wed, 03 Jun 2026 13:06: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 1wUlIc-0005RB-CY; Wed, 03 Jun 2026 13:06:22 +0000 Received: by outflank-mailman (input) for mailman id 1326225; Wed, 03 Jun 2026 13:06:20 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIa-000569-ES for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:20 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIZ-007IV7-RI for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:19 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026c8-bab6-0a2a0a5309dd-0a2a4509cd16-24 for ; Wed, 03 Jun 2026 15:06:19 +0200 Received: from [209.85.221.51] (helo=mail-wr1-f51.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026cb-2497-0a2a45090019-d155dd33a82f-3 for ; Wed, 03 Jun 2026 15:06:19 +0200 Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-45ef5146b56so454628f8f.0 for ; Wed, 03 Jun 2026 06:06:19 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:18 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780491979; x=1781096779; 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=YRDIkYEFhAoyg2vrbD/w/bb4Chd8wbV0BhcfXDreNEc=; b=kVYcBR52fQcUI6cy9IRMPpDCSQMBdjMZez2Yq+EJpXXHEGaSdsvJrdHsUTx0MfO3xY ijGrlIIOy0pZcIHmV/pem0jC7vL5YTDUaBTLn3rE8Y2DdN0WGveWUeKvIEVEqd/Zax23 wM0uXmc5o7yl0puzvtWEn3aRsD0GI/Och4YsvlVh0+OxlxJ3p5ZxML8h8Rm7juY4eMZs 6wVHZS4tMHspwu87Tmu5feBmACrSd61Lx5xgUW3IOzUcCNCcPJUaX352LzJd9E5N5ioK MsbQKkB5ezLpv7l6TUBjJh+X7MQnhuo9x8N1+ds2iAB5yVr0bzBNWQ95AquXvLqDafJq g7ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491979; x=1781096779; 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=YRDIkYEFhAoyg2vrbD/w/bb4Chd8wbV0BhcfXDreNEc=; b=inErtMQEgsJdiAwC5YvOMqtEJmqX0abNLUhd6Dmds5jYtOPPZVsrkkav2UTFcQ4Da8 5cp6Xw9nqzOYNtEw7iAtcAXpIEEPm6RTVbHe9oIo6nZ/+Ke80JkQK2h7zRFA8y/aCgEY 2FKNZHQBV/VXh51oS14HwJuBojGTSkA6Qjpk9PJ75a8bwuqI1OR1Xoe7hklEMNB8znqR x5IX+JrFRTVq3jfvbT2VcVQDoVI1Eh4qEtL9DnfLRrSDvf3V+KMEtz+WIUcO2IdqFHbm 4tYCTnzC2ElMnmSadmVt+ldlLElmYoMbTn7MT0yOjJJetkZOil87ayMAELGMWqUXvOu8 6Qtg== X-Gm-Message-State: AOJu0YzZ0t/6xzVX7SwFaKKlBQAw21tzj5EEECqccXqYucLgy54d96dW oExqfs+JOAYQ+e/KJINY8lq5xmlVGDlHQNF4GkMe4Gfs1qauFYlmTe9K/4lvgPP+ X-Gm-Gg: Acq92OHKchBif1sW9xVhYXRUvD3xtcIn5i4f9ZqnIn/cmaCOtNpZxo3XzNPp48SQdMj GPZI/MzMqSJeLyhbRSYzBV8su2Tss/XDMvQGruM3ydPbx5BS/OOn71PX6o47ZJ1eEE3WtLk3g4J vlU7D/G7ipudkR3EnhKmiV9/o+MTKUQqxhRz6A7iXLhG9qtFdlzrIstQYapQQnaIVQkS8WCC8vv rfn7H6+/1acqpNsqZ1r77LrHOfsnJBxnLn7NOBkEaOpnKHsb2gsHYKkw+reWineX5TkO2tIqMw2 p4Vs0vn7XJcNWsrMGiBsWbbCuY0aJek+aSsJeLVYidY6y3bn3D3FzKsYjGhJKCz+tvekqtx3kRi Xb7MckmqVvc1JlESVrlbBrRDfhCqXQWkPif/iPQlMhDBFVpZdfNGrT07qea7BAajphMKAVuE5tZ dFKB8a7lSMbtnN9CuMats3I+paSvWIUWZx8K72WsdzoMOtAXyTG2U0hJFKn4mIkkwGi+al8Gs/K vNAnPM+1u9gIOjyh88KfAAjjMbesVYqiPW9 X-Received: by 2002:a05:6000:124c:b0:460:1c93:6eb6 with SMTP id ffacd0b85a97d-4602131fbdemr3055480f8f.20.1780491978817; Wed, 03 Jun 2026 06:06: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 v4 02/16] libs/guest: Reduce number of I/O vectors in write_batch Date: Wed, 3 Jun 2026 14:05:49 +0100 Message-ID: <20260603130603.776452-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-bad1c0/1780491979-41F6EA53-F63CB1A6/0/0 X-purgate-type: clean X-purgate-size: 2621 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492009507154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. Reduce number of pieces passed to writev. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_save.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 3b2c5222e4..1700d81905 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -97,9 +97,12 @@ static int write_batch(struct xc_sr_context *ctx) void *page, *orig_page; uint64_t *rec_pfns =3D NULL; struct iovec *iov =3D NULL; int iovcnt =3D 0; - struct xc_sr_rec_page_data_header hdr =3D { 0 }; - struct xc_sr_record rec =3D { - .type =3D REC_TYPE_PAGE_DATA, + struct { + struct xc_sr_rhdr rec; + struct xc_sr_rec_page_data_header page_data; + } hdrs =3D { + { .type =3D REC_TYPE_PAGE_DATA }, + { 0 }, }; =20 assert(nr_pfns !=3D 0); @@ -115,7 +118,7 @@ static int write_batch(struct xc_sr_context *ctx) /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); + iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); =20 if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) { @@ -216,28 +219,22 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } =20 - hdr.count =3D nr_pfns; + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + hdrs.rec.length +=3D nr_pages * PAGE_SIZE; =20 - rec.length =3D sizeof(hdr); - rec.length +=3D nr_pfns * sizeof(*rec_pfns); - rec.length +=3D nr_pages * PAGE_SIZE; + hdrs.page_data.count =3D nr_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; =20 - iov[0].iov_base =3D &rec.type; - iov[0].iov_len =3D sizeof(rec.type); + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); =20 - iov[1].iov_base =3D &rec.length; - iov[1].iov_len =3D sizeof(rec.length); + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); =20 - iov[2].iov_base =3D &hdr; - iov[2].iov_len =3D sizeof(hdr); - - iov[3].iov_base =3D rec_pfns; - iov[3].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 4; + iovcnt =3D 2; =20 if ( nr_pages ) { --=20 2.54.0 From nobody Mon Jun 8 07:24:34 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=1780492004; cv=none; d=zohomail.com; s=zohoarc; b=AVvFdEXGFL/o5AWiDXOv8Afr7sStN1xbec0MLLd471Ue+OPtE5GKd1odL6nHjFF5OnsZkV8IlatOJQVaX2ozmKqzg7Jjuas13vJ/949dWGbMjArARabIgFS+uTqPhQzONZc7Auj1HJJYwQMfA0Aa/X74kUIgBobujTPX2F34vwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492004; 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=NqFYUY4LLWBRQq7NSsaodrilUaXJC/aM45b33pOy+8Y=; b=SWiK2U4UEnshTI6Ykg1/z+xrDOC8ChRtIasK1RrSP7qC2hv85ldh2UwnzQQAN1psfTGfwOUz1mUYUcRTVDq0ugVHoLd9VM3WRhhJHZ3HqdpLPb5LioelxA8OIWgtYqhHqJMG0H9lNAlKKkjmQRzxJoztERIpzYGuSguSDDMwqTU= 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 1780492004859275.8344475275371; Wed, 3 Jun 2026 06:06:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326226.1591673 (Exim 4.92) (envelope-from ) id 1wUlIc-0005TX-OG; Wed, 03 Jun 2026 13:06:22 +0000 Received: by outflank-mailman (output) from mailman id 1326226.1591673; Wed, 03 Jun 2026 13:06: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 1wUlIc-0005S9-K4; Wed, 03 Jun 2026 13:06:22 +0000 Received: by outflank-mailman (input) for mailman id 1326226; Wed, 03 Jun 2026 13:06:21 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIb-0005DG-CG for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:21 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIa-00Fz1h-Oz for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:20 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026c5-5cb7-0a2a0a5109dd-0a2a4504cb46-20 for ; Wed, 03 Jun 2026 15:06:20 +0200 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026cc-1dec-0a2a45040019-d155dd31e574-3 for ; Wed, 03 Jun 2026 15:06:20 +0200 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-45ee6d32402so3660716f8f.1 for ; Wed, 03 Jun 2026 06:06:20 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491980; x=1781096780; 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=NqFYUY4LLWBRQq7NSsaodrilUaXJC/aM45b33pOy+8Y=; b=IKWctpKYbAKP9veP3t90mlK5BPpK9SdK8WE36hycjpQXKR1dPpUoCn/W04RMznElso 24Sb7YkKyPrtByWMDPDnLHFGvX58pMLsTgU5qLFcbBuFVtTS2vKmM6YSuyzAqaR3IpYZ 29ddcPVjFKH52rLCbAPX+Wf+UZFi4zYSY/YA3MysAeP+A/b++baGXdvaWWkixMpf+AyP 1DOfNI4qpNQ/52FLFD5aoKffmrkgCEurUiCVy2ooOw4NnOyHNJVwuau1gz053Jkwgfm9 Y2XtQUTPyFbKApBeO3kz8w4M6/21wzUWmu5cHhEo80Iiatv3ia4XqqWhiVHfUeV8rcXt teXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491980; x=1781096780; 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=NqFYUY4LLWBRQq7NSsaodrilUaXJC/aM45b33pOy+8Y=; b=fan7yccUNFKeonjGulq6vBVp443Ei5iPIv4Bnq1OrAR0WVZUdbLutxmZJKizgSuM6/ BpR85QhzwsR4z76yVoYOhJw73OPnaxD6Rcunzc9XWNm0DJzZqE7Ypp2Dmwt74NOv6q3q PEpfEY14Y1QpLI5d2mHXHEJ6R4oEsla+LdI9KMSRNuwq98VAzT0QqG8LPiZ6sGIzUnzJ g/W5k9j0NZoJI7/IZqxXdeq7sbm4nAwQhYmKZ121FxRdXgqACT7mBKnEpeKPaBlAOuTn VmG5RkzHrIaDUGIUECHrwBj11kVlJh74Wnkrgv9B9xwZVXLnZhhS7Y6wtlPXnoNk1Fd6 5dtQ== X-Gm-Message-State: AOJu0YxkMX/dBGm2yt1b0/EX3yQWR0HYtvknxhhekHqrU6xB7twK2JRX pL9I5D0SHB0tW+cR6JuHZHuDWbKHoeBa1cu5Pvx7LrnqxO6mguJRBnbtWtShi69v X-Gm-Gg: Acq92OGrBd4Op4FipnqWCxmWsSnDf9Mr6EDyS/wvoOgXAAGlAVGTk7aydiMyHKFkV8C 3Y0a+q6r26Rk9eJtCht9CzgRDH5D8Kczu/MY9rAcUcTo9xQDvPasq1IxKnMuxIguQAVCcoDR98M xBrjeYPfjh9hJ7Q8agjbqkxY/Zho7SSLQ9hmAKLH2Et70GIwb3J5mdPdt2pBapXIa5/R/qYUXYS 4USawKWqlnD7DURKJQcXtjPsJAQD8wyHXZLsj2cVaUTW+apBTWJj1X6L10836Wl62jQg/d+nKub 7aVCV+29aDS4PC7BGYaf3m3To41W5nsAqPiAseTHm8RSSilETutb6QR7CEBNotyiafzP+Y+9nZ/ KJE3IATxKzZpgdIAqZFSRNizjQSORhLn9JC7vLnMG0G9cqqB2S7rZPI7NEtwcjFw3txFQIPh9kE CIfUrLL7h3z2tSBDF4wGi1KqZhsHXQx2yPvvAI97S60Ll4oFWercjvZgfees0w5c8QbQnVZ+vzh gEhCPOsi4S31sXKtABtI9MWnGCz7RkexZnmTJlGF7gnpwI= X-Received: by 2002:a5d:4a02:0:b0:44a:2cb3:b633 with SMTP id ffacd0b85a97d-46021794f73mr3643466f8f.12.1780491979837; Wed, 03 Jun 2026 06:06:19 -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 v4 03/16] libs/guest: Reduce number of I/O vectors in write_batch Date: Wed, 3 Jun 2026 14:05:50 +0100 Message-ID: <20260603130603.776452-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ebf023/1780491980-2B1663FF-29F4062E/0/0 X-purgate-type: clean X-purgate-size: 1324 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492007259154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Each page was sent using a different iovec item. This potentially exceed Linux maximum (1024). Also some implementation (MiniOS) emulate writev with multiple write calls. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_save.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 1700d81905..62a39dfecc 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -240,13 +240,20 @@ 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492003; cv=none; d=zohomail.com; s=zohoarc; b=kQksK+0k5+j5nwiZfjtz2ESIRJQuJWQIsFFvk3p0hIFd8VVunKru1wt+GWF5YmRhnPytzDjXwT5qi3aa2UsvQqudgymASGvhbeg2VJCQkTid5M4U5VDKEKrM/pQWJ2fsM+VQ4JlwTrbqHrtCWW4OtWgSl1yJv3xdUalfEgbJjGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492003; 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=spxFWbMOGnCr2GX6kZF6sxvh96pd56+K0G0G5gXpfUs=; b=jEicIgklHqkcr4hwkK5zrTU4E6rgcBl/Fk2mKi9DyQcPw8czIaCthlFILtR0jEX0WdxahWQQVhvN64kxWRgwDkydEswegFdNCg7zMJtDa3pb7zyD3IxLzvIUcd13R5cygEUz/m3w9yAumZlal9p5kZ+Yey7HNCcMVUzm6t60qr8= 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 1780492003803814.1861327001571; Wed, 3 Jun 2026 06:06:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326227.1591678 (Exim 4.92) (envelope-from ) id 1wUlId-0005at-2r; Wed, 03 Jun 2026 13:06:23 +0000 Received: by outflank-mailman (output) from mailman id 1326227.1591678; Wed, 03 Jun 2026 13:06:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIc-0005Z4-Ug; Wed, 03 Jun 2026 13:06:22 +0000 Received: by outflank-mailman (input) for mailman id 1326227; Wed, 03 Jun 2026 13:06:22 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIc-0005NC-0J for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:22 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIb-00Fz1h-Cq for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:21 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026cc-5cb7-0a2a0a5109dd-0a2a45078556-8 for ; Wed, 03 Jun 2026 15:06:21 +0200 Received: from [209.85.221.51] (helo=mail-wr1-f51.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026cd-229c-0a2a45070019-d155dd33b0e8-3 for ; Wed, 03 Jun 2026 15:06:21 +0200 Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-45ef4223be7so3230548f8f.2 for ; Wed, 03 Jun 2026 06:06:21 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:20 -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=1780491981; x=1781096781; 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=spxFWbMOGnCr2GX6kZF6sxvh96pd56+K0G0G5gXpfUs=; b=QnBhjFEkDWqOVpaED0ZYZslpN+wG86yQtnJ12fUWNvxz00W7FqzkAWLVr8c2LA0qUG KAcUpJ1ThT6DghAOkfqa82mSu4UsZxHOMcZmEgbrp57kmm+ewW9fhnICWPn2yV4wzFcV rgQ8R70MEZ2mZcbRHAr07ZPWx/FDd9ReRAz1sHSAitMpKPbqcTuSZ3OGeTczSOFvXmlP rer0LBU0RMSx06e8fZTd3RfTy/CYl+HLe3LaFQfgM7t+QFGuzO4MU17jG1vP3GGerB3E 73X/nta6aZE1tSgv8/tg0pjLS4D8y3Ipr70nx2BNGhHeFRpvvfrShsa2Y8X5l4XuX5WU A9gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491981; x=1781096781; 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=spxFWbMOGnCr2GX6kZF6sxvh96pd56+K0G0G5gXpfUs=; b=W16ewW9uLXGkJST+EchZrsmuYDdCGkga+IIgL6Onk+2lN6yMiTj930CdsGLqR8qeWR X+6w6pEhxGpsB69IHy9XWQibwvXAP2VYIWQ45zIDKTp59SXn+sEnJhTdXSoOZ9XyZ/L7 fzC09pM0cMzkGXn1kecvSWhrGhkZD7gKJuxmi7Csf20AMil5B3WQ1LXwQ90Zr2cdwSGk Ek8GWy8n9stEW82ewP2K1pzZGAXhHUyVRXtV5VCn9grykRHarbvzzlbXnv1l7GhpmYdt OQcVYSJxx3uDf6O5zak+AMmwPxxWp5VxX/PJhmpxdlWZjUIakLapKmwO22zwZ+rl15Yq +t8A== X-Gm-Message-State: AOJu0YwMY3YAiP14aL1HYNzoH4ItCSU4Q4HFlc7EvinwdORTQZ4qCZ3e pOGLufg552lryJ/w46LeCIR8HzBYa6qyqR4+/vaMwCjW3RjYEIECEn1GQIdxABty X-Gm-Gg: Acq92OENraSQefWv3hV0Wt7P3OPNt753L7VGkaW/zls29vpCeJ1foD/oFzStq9NqCac 2Q3WBJ2lTkqNSp8m2vxha52puDIZVkIvjmAmGtUYs6YStethT9mi4MfnObg9Ox8U2JvXYtaX5nE 2d7QO6ix9UceVLNaAOHBsvPX3SJNH2wFXcNCp5xR9XyzTm/gYYkA9qwOH/AELxF1yyoovWxPzBH IcNdzEAGo3Ekm2Nb3/ttuf2yAN3PKcNK2So1kVJbrIUplcK159FhmW5fsTh1ySX5hYrTeIpM//R l4G5i9hlv3Rx83nvVP5dU+ncrMMRYZn9MlzF2t0vOs+V9Pg9P4tLPJRPgLYkGp0ckQsLx02s24x 4u0vG52tbT8NzIVlSLxKy5PcbyYXp84VjFvpkgnnKauegUsolSzCdp4yY1fK6ZocYiVBRQ5mdMa KheFNsmnd2lmrMtb7kPly0+TYuZU44t6+LetfP/+O3AJ0LZJMQfUgVM1zXanMyBf0+0Sh0PGJdR BtEVsc8C/K/Mno5S7HiT+CI0NSM36whaZRZ X-Received: by 2002:adf:f202:0:b0:460:18cb:8f9e with SMTP id ffacd0b85a97d-460217a78acmr3663962f8f.12.1780491980670; Wed, 03 Jun 2026 06:06: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 v4 04/16] libs/guest: Use a single write_exact in write_headers Date: Wed, 3 Jun 2026 14:05:51 +0100 Message-ID: <20260603130603.776452-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1780491981-2887FC48-E54190EC/0/0 X-purgate-type: clean X-purgate-size: 2250 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492005260154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Reduce number of syscalls. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- 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 62a39dfecc..8c4e760f8d 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492007; cv=none; d=zohomail.com; s=zohoarc; b=OvF8068usR0xY/KGmsnckbBGY7SpsYAYUebdH1EXXkTsieq0fDzeNdB/lC7D8IOITUd7sIuhFwnzwY7YV0J8wnDjixqIPIXeE5MtQ7RWb+ZIx6LnuCFK3zE9baFCtCKG5zSHWvogEnMeBQj6DybKRCPrT5cLJ4yOAiL4kks96RE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492007; 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=ngHaiXVcIZgsSzheol0Gqpgp4lQa4ltKlhodC4+DNtk=; b=LhW1n2UW34ZnbLdSVLcArpkdN/Kg5yNY2iR9/ufIZdtY0NbQ5vqQiOiQYtQ6dSZFfI5S2fg6hG6q1Cq57hazqD4M4natPcZqZI/pMsE6vuTGuw6XmGTft96Bp6PihyYfgs8cCuaWZi9EBAFX9kydvZOaH572mWBlb2cFHOcaWP0= 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 1780492007058791.8499724913902; Wed, 3 Jun 2026 06:06:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326228.1591695 (Exim 4.92) (envelope-from ) id 1wUlIf-00068y-DD; Wed, 03 Jun 2026 13:06:25 +0000 Received: by outflank-mailman (output) from mailman id 1326228.1591695; Wed, 03 Jun 2026 13:06: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 1wUlIf-00068o-9x; Wed, 03 Jun 2026 13:06:25 +0000 Received: by outflank-mailman (input) for mailman id 1326228; Wed, 03 Jun 2026 13:06:23 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlId-0005fU-Ft for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:23 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIc-007IYC-St for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:22 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026c8-bab6-0a2a0a5309dd-0a2a4509cd16-40 for ; Wed, 03 Jun 2026 15:06:22 +0200 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026ce-2497-0a2a45090019-d155dd31e4ad-3 for ; Wed, 03 Jun 2026 15:06:22 +0200 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-45ef372c58aso2818108f8f.0 for ; Wed, 03 Jun 2026 06:06:22 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491982; x=1781096782; 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=ngHaiXVcIZgsSzheol0Gqpgp4lQa4ltKlhodC4+DNtk=; b=gbcqRJTbXZ/KrrbJsX0qctBQVUa8KUGVs4wXZ9ZbMcWuCz+Nut92FaxVXL9lF3F2K3 yo7kQfqE8W2Ck8NqiFlvfhaIi+xVs0G5lAd++Gqr3l00nTJuuyYXJHIiwi3XFdJtsZGK FgXJ/dp7yliq8W07cWeeiCQYujwwaDn1VlgViLGt6eOd6cLyO6evO8B4yJ+cWQoMXaMX AmW6Mj2TWiRGtHbQrr6t5VHigP7P9Ue/o6uNp3Pu/+DGACyo9cJdndQ3gPL20UpF3yVK cVry8ddG3E2+UtUi13HrsOn/STW00AIOHIVOb1T9JwV//9iOA7gpDFa63CJ++PoRGWj/ HE7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491982; x=1781096782; 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=ngHaiXVcIZgsSzheol0Gqpgp4lQa4ltKlhodC4+DNtk=; b=TXW7IglQiFOjji7KvQwyudstIBndwHX3f5Y/0pxGCGeGWFfeWPZhssdDrB2TWRtEo1 vKRDSy3Lf13uB5gwuf80CtJdBUwjdCCLytWYa0N7ziFGIynCKqE9B6ZCgXG4HYKaHtF/ 6Ve8Tyg3rSlq9rpM33iBV4aR8bytK7uSZv7EF/1Tm/BSdgaUUEtxFrvHo9S7HYVNLqMg KBrIp5/caRfzVPb/u5/W1GL9cl4Jcq1o4GVUnBBiQLHwsKNt0KiO0PZeT+8L9sKo/Y8+ ZuSifTB24wMMHiTFA2yT3zRvW/0impAjYpTy8l0ZUxwIBNHFCxAgWlj3rV9OyINmtKJ/ MoQQ== X-Gm-Message-State: AOJu0YxzUneePm39btn0yT12YS2rFOIR3n+/sGFT9H97/kC4GW8sGloP G+mA9EQmCtqPcQmatevEoARILCnOxchTlAu1k2jt466MVwTOqxvYmvYLgXIXcK5t X-Gm-Gg: Acq92OE+mf5Ggrwfy5jeZTnrS/fogo1YUzhjE09RtOWGk0azIuYmf/qx/Y4FRoD8Zfq cWnuJbeOGXHBkzPjsVFLgVvk8zxFj2p00YnKRvaa+hfGqfsBPjRoqp//h7gaaYS7dN1h87lfUyB Pksglqh6t9Lf0QE1oj8ua020jSpA4FRU8iudVN0tyfuCSn+lYVFE67sWhRZJ8TZF/IpGWSfk9vL A7mveFu/JvK5HMUBPBYmOVXEiEtOe3sqXpB8Tfwc3M41jFXo6R3VaJhv5odZhQBlsCUU1V2haID SqdNPH30KY25Fw4Tc86BBBPjSXUBPn7YYU5IqinlEBxGPh+ivORIsOEJMSWbqskPytzmrZ2JwXG k8kKpoqA8U3q+F7U/9hpDgt59/zmyAsxYd/U7hCmwJWIIDxBeZSMwGFquFnyIxWD0CKOWlu+lZj IzlrqEpWiRzO1lPXgtzDNJOZWXbHPMK3336b8IfrrZ1kQm1x+W9/50Ys5Ge08vhjNs2aio1aiPD CzD2vuWAGs1ujzdvbEH6DiYIgGrxJCCY5JK X-Received: by 2002:a5d:5989:0:b0:45e:eef5:b51e with SMTP id ffacd0b85a97d-4602181fafdmr5032385f8f.23.1780491981925; Wed, 03 Jun 2026 06:06:21 -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 v4 05/16] libs/guest: allocate various migration arrays just once Date: Wed, 3 Jun 2026 14:05:52 +0100 Message-ID: <20260603130603.776452-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-bad1c0/1780491982-89D85A53-6F8A59D2/0/0 X-purgate-type: clean X-purgate-size: 6496 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492009599154100 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 --- 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..82549b5589 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -209,6 +209,18 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct xc_sr_context_save_buffers +{ + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; + xen_pfn_t mfns[MAX_BATCH_SIZE]; + xen_pfn_t types[MAX_BATCH_SIZE]; + int errors[MAX_BATCH_SIZE]; + void *guest_data[MAX_BATCH_SIZE]; + void *local_pages[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */ + uint64_t rec_pfns[MAX_BATCH_SIZE]; +}; + struct xc_sr_context { xc_interface *xch; @@ -244,6 +256,7 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct xc_sr_context_save_buffers *buffers; } save; =20 struct /* Restore data. */ diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 8c4e760f8d..7d8055a3f9 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; @@ -105,26 +105,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 ) { @@ -210,14 +208,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; } @@ -805,18 +791,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 @@ -840,7 +826,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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492018; cv=none; d=zohomail.com; s=zohoarc; b=KI+QD3WRGRAQDGtLCgfcm3OZZGgGr0K2KyDukllG27UYa/9v3v5DnZ53NRaUjljpUkA6p/2Nbbc4yebZ/XDif2KAKsKXhGFIjgL/5r4fCRi1plLig940omeDgnu0TRg3+OkjPPf/+GJqspC/tZq0/qqDDU5aa//Xz0bv6D145lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492018; 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=E0qnwksAnVibKLEOmCRSNsa6uG3n6snRRRntsiizK/M=; b=Awmwe4dO5Ml9uhf0vRrWeTd65b4FAAUruqk/XUwcyqpdzBncnTdDf7Vo7X+IitSbceJR0RtU2LyOB26ZznvDuTa1VXCEOySt8VKQhXbvJGTayOjrQI2qnRznD2dkHQH01NaaaGkyWbjglD/Txx2gb8ypLodoW8Hko0CGx1bLlRY= 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 1780492018679332.3633526368453; Wed, 3 Jun 2026 06:06:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326229.1591702 (Exim 4.92) (envelope-from ) id 1wUlIg-0006GR-0r; Wed, 03 Jun 2026 13:06:26 +0000 Received: by outflank-mailman (output) from mailman id 1326229.1591702; Wed, 03 Jun 2026 13:06: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 1wUlIf-0006F2-Px; Wed, 03 Jun 2026 13:06:25 +0000 Received: by outflank-mailman (input) for mailman id 1326229; Wed, 03 Jun 2026 13:06:24 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIe-00061k-Er for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:24 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlId-000siy-Rv for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:23 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026cf-e002-0a2a0a5209dd-0a2a450cc1bc-6 for ; Wed, 03 Jun 2026 15:06:23 +0200 Received: from [209.85.221.42] (helo=mail-wr1-f42.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026cf-62f1-0a2a450c0019-d155dd2abc2d-3 for ; Wed, 03 Jun 2026 15:06:23 +0200 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-4601949975dso194027f8f.0 for ; Wed, 03 Jun 2026 06:06:23 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491983; x=1781096783; 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=E0qnwksAnVibKLEOmCRSNsa6uG3n6snRRRntsiizK/M=; b=eQx3LonuUXFrPzTyJAaIk/3pbaBYDEEpcxmhIYjJny+3+3mQcZ07V90CwONr13OaRX 2RIfC0Ze2KXTAi9SdlaVTjkCgS1LxlAREJij80ZXMrfVDSo7d0X7zljF8UffnN7Tqshv 3q2UQDJfaUFxhFO+ZHTTQvhfmyjgGa5wyQ5kah3qRs4yflJ8wiJz1JSv4qRY2S49DraQ R0ySKf8q9mrzXbgiq+p6sG+ckBQNg3RnjP0at48eXPg2LkEEfXRzGKX0FcvsLrxTNWFh 8cPJ9ebAL/7KhX5mSPsdFLwXhm5ZufV6X1Jc7gfVFKSOyDSIveTk5gm1B1MI6sinRZG5 SSKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491983; x=1781096783; 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=E0qnwksAnVibKLEOmCRSNsa6uG3n6snRRRntsiizK/M=; b=AP9RO2TNm8HIR8IUMHloCr9ceI2c6PulGxct+VJvR4qfse3h0Il8WbSe1Plvb/TOpF aWs8u96AM4s8LmHDfyrLtIjGWRx7PelySm7n5D1bPjA1MT1LC8Pp+VpRSFtpVXFFGG9X VdZ0DEr+AkFksG0NqCCMTjUjde87Jc1eFfPmcPy3UC+MYCLxoy7VGE9URB45wztjZUvF cgviu9dZwxlcuwqN/IzaOeWAT4MQRErcmsT4pRb3Qypmk+y6AB5t5h9bvKP4LOq3kouI HqN/nZP7F8AdfzpsnFd+wh7PX9NCg5y+5f3A467Sfp7+m06gv9SJVcyvd6ma+UwiDT/X eKsg== X-Gm-Message-State: AOJu0Yzv0sltLaPDeirgh6/nrESO6SGD3CVCunzJmafMsiQjaKyiNoV0 TgDKAphpcO7rUyUP0YNqsu2YNmSSJe8wtNxkYpfq2CGF/BaYut0ajImlVziA5UWW X-Gm-Gg: Acq92OHFEPQOpTGsmjzcyAcCPlfkvi0cEM7ZgCn/bCMEjiAj1/3xD7OxIiUa9e0L8sZ bhCwrfQCQPkk/Z4ApDiCENPUW8e6nnU+7Ire4QhN2stKzDYIMTbMnAuqBuRbAGBu71rBBe0jHCc +OiVktEPDR4vOO7etWG+Wz6DzY7K+mvN1uPbmF5mXXD74SHXR4GqUbNT27jcVSnAvAS2iFQEnZo x6e+mduoMnggaAkONs7S7Pt4lY6c4SwTVT5Fe+EfePnr6eKGkGQ3kJgO4IH8pKmPiyXd3NE6LUw AGbZTvN+zcn0zr6mVpcZFoC8mlDGtFErz4nW26YfU1k5ZuhQgtU8sohUs9wMjoVeQS78Gz/n+uM Te85IOa1ZexIVmSXx75zHXD66QT+nfCYg7B3XneRLGoJTkI6DRlPtozhHXHB3yXbUjrxw0pAZJD gHCx0c71Xmo55hs5teW5LHorjq7lrUugBcLeXuxO4O40wgIdmbUTgW/x7mhTlNos02spezJ0Jb5 /2Pu0vXdOGxH4D6OQmbgcymxb1vPlfsPv6L X-Received: by 2002:a5d:4987:0:b0:451:3b12:9bca with SMTP id ffacd0b85a97d-46021831001mr3701447f8f.25.1780491983000; Wed, 03 Jun 2026 06:06: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 v4 06/16] libs/call: cache up to 4 pages in hypercall bounce buffers Date: Wed, 3 Jun 2026 14:05:53 +0100 Message-ID: <20260603130603.776452-7-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1780491983-DAF72CF5-257ED0B1/0/0 X-purgate-type: clean X-purgate-size: 4973 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492019010158500 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. --- tools/libs/call/buffer.c | 28 +++++++++++++++++----------- tools/libs/call/core.c | 3 ++- tools/libs/call/private.h | 8 +++++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c index 2579b8c719..15d2f98a6b 100644 --- a/tools/libs/call/buffer.c +++ b/tools/libs/call/buffer.c @@ -56,13 +56,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 +84,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 < 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 +108,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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492005; cv=none; d=zohomail.com; s=zohoarc; b=XannNWb79R92T9VjdrhNbIIyE2xH5UJqiv4ivf/khmLzc8ZTNC6YnSkbvGAQPrtr00eQ8J0xHJ5U4gxeR8/l0KtAP1nQmg6BMvx9tqA7nZyStd+dluHfJmvX5tG9IAE7qkLJVxgKwn13IppI14TGQG69NWpXlzaclq9sFzZZTWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492005; 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=u6wvxilFElIaNb/mhD1JtaMC/n+2767zKlkc9WwKCUs=; b=EZ09WvFZSXCmp/JreMladuy2WTqJ+mk0QKImiiLKGT33QBqYyNl6PvLbDDJbrl1ydxPYad4RkENHo8FFYlOJBHlESWsKfwn1N4KWG+hdpqPMc5VDNUEDmbbCRznHRfqxROUqfVVZW9esV/9KLOCJKqVSi4jVDxEVOYirJ+l2v18= 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 1780492005051548.5186683907169; Wed, 3 Jun 2026 06:06:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326230.1591715 (Exim 4.92) (envelope-from ) id 1wUlIh-0006cE-DX; Wed, 03 Jun 2026 13:06:27 +0000 Received: by outflank-mailman (output) from mailman id 1326230.1591715; Wed, 03 Jun 2026 13:06: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 1wUlIh-0006bl-5h; Wed, 03 Jun 2026 13:06:27 +0000 Received: by outflank-mailman (input) for mailman id 1326230; Wed, 03 Jun 2026 13:06:26 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIf-0006FT-WF for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:26 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIf-00Fz4z-Cy for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:25 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026cf-5cb7-0a2a0a5109dd-0a2a4502ac02-4 for ; Wed, 03 Jun 2026 15:06:25 +0200 Received: from [209.85.221.43] (helo=mail-wr1-f43.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d1-af86-0a2a45020019-d155dd2bd859-3 for ; Wed, 03 Jun 2026 15:06:25 +0200 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-460166910e6so1763531f8f.2 for ; Wed, 03 Jun 2026 06:06:25 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491985; x=1781096785; 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=u6wvxilFElIaNb/mhD1JtaMC/n+2767zKlkc9WwKCUs=; b=B6KWT8YYvNT/86fFNBxYbgpp+DIjAS7E4DZTxmmn2VZeupP2hB8teYDo2zwRcXN8AN Jd6tpCrfs/H4/pZ+w2cL4McH3TDQ/CDvUElwbmAZ/bp5ZRhg1i4p3FtN0gE4sCiRMhoS 7ud9KqzPpojWHo9olAoVwaqKp1cCxq1gCRavThRKe2Jx20qZdlYQXh/1pa7qedN9FgEx Cta/ecM7QEtlWDD/x81UNurIlED515KvSLl2fOVwjXz2K8lG2F3nLJL2zzciGzWUeHWY jSBA6K+q7ypkJSohpyVk3ieJkkKwgCIClJML58MKl2pJM0CMj1L1nDDRLLV79oeeum9f AyfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491985; x=1781096785; 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=u6wvxilFElIaNb/mhD1JtaMC/n+2767zKlkc9WwKCUs=; b=nnHla83vIvwz4Y/IhXpsTEOarB1ssH0YfK7y37gERoixdnqpC+bmbvnLl3uIROcHlM L2jmy4Gmmm0O4b9RBVLX3Nhm9j0hVe5d1otaTV2VhHnlYKgtna55YQLUBWAi/wIHdEjF +4ckTxkVOeu4kaOq5Fr3oDnVrrqkDJo19DN0yUJMrSjg9kCT9b1mRi85kIy4RG2TZLrr Xj1TG4gp+7PFXk/kcuJ9TTF12CxMZKfhKSYuzsoGJYNRHkj1dIRbeAhU7lPfp8L3Qf8c hJFSEEjiXU9WmcJqrTLXNoGP/v9UNo27u9PWdEjNRn6BfNKt0dLU8LriegZOz0yvjHTh 8bvg== X-Gm-Message-State: AOJu0YwDLPH0jUkXvbmyM7ED5CzEMWO12JPyX6cPW7uEGBlNVXHmN0RS T+QvkenckMsu9aoBqZ3NrT67g84RqBgq/dp1x/wrQ0OnezCoiit+pf2TKpKlJ+F6 X-Gm-Gg: Acq92OG2UYCw9AYx3+wj7HWxS+EuOZr3tYoPSnZh/MCgT6nYpX1VUekrdyYXomlrx7g 73NISl0RzeHm3OtD3NhbmzhMHpobXd9eqN/jM3J1k4GTa6wLibn/M8uMPzxgIp1YhUMY0HIILTQ 6p/OCsBkELbb3kekHrgKAF76WrEusDmhfmydy0NijtNSBvRRNzoYM9x8sM2cN5W9KFxj2oPF4Be HajTAea+GM1BoDStF1QtawAey17Z8C8dDmOnMhpDQpv51Q6b1peIuEwnIIYmVZ+YL0YkNqC3bK0 Fgh8AQHShLYp+/wA139442Ru1bv+Ti/b4owMpXCFOj4ND4LjWDF3OBzW+En1rrMKooWGhkmd8Rn FDRxlvayaZYyDI7Q3w08aVd6Q1t0ppaHVN69l04ig/kG3/O2COGaHwZyanixk+Ag6ZeEFxhTw9P MQVlS8tAydHwsSTg+FSdtmsHNOILvPodAUHrR4Ul/DWewe2fq5+XXBUmzpOKLf8g/1fUr/jW5zz S8IFeBU5w9KMM0zmFTkCZRDSIu6SOxTCvFpKl3Q83LyjO4= X-Received: by 2002:a05:600c:154f:b0:490:af90:f9c2 with SMTP id 5b1f17b1804b1-490b5eae33dmr56963585e9.12.1780491984397; Wed, 03 Jun 2026 06:06: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 Subject: [PATCH v4 07/16] libs/guest: avoids using 2 indexes Date: Wed, 3 Jun 2026 14:05:54 +0100 Message-ID: <20260603130603.776452-8-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1780491985-A8B78161-F865556A/0/0 X-purgate-type: clean X-purgate-size: 2684 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492007000158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio 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 --- 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492031; cv=none; d=zohomail.com; s=zohoarc; b=afHp5r5ZUrKb0OAg0ptX58R/XXS12F9abiurW1nU/l0sI7XcRMf6ytCIpTVRKfMNgcoq0IAYZLCOmdrsEmROO/ZaX6fvfo/5LAImhdFO4DdS7EA/NBHXUbUku9xqtbbXmZS26ZKcPyL2urhbxNvaXcHpwgL3r0bQbdZwuiLjOzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492031; 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=ga8NUbQdyZJ7AuIJzNxg+MgQvikeNA0e9nhxhm+dxDo=; b=bgZf/vT8aqThjoC+EUqfBPyNBdMxC3x9M31ASgHXlSJoNsMUvTV/CfDJs0kHF8IOYtUs91yOgMu7oLezJEUdlJC7LfoD/eejAB/kFdSwUqtg/QHNfBIlAknL/vVGt1ukNLY8VgabbetC+++mlyuPkFZL0EPnBXDkkSOIpQIEbEw= 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 1780492031733314.1755646423219; Wed, 3 Jun 2026 06:07:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326232.1591723 (Exim 4.92) (envelope-from ) id 1wUlIi-0006uM-QX; Wed, 03 Jun 2026 13:06:28 +0000 Received: by outflank-mailman (output) from mailman id 1326232.1591723; Wed, 03 Jun 2026 13:06:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIi-0006uD-MF; Wed, 03 Jun 2026 13:06:28 +0000 Received: by outflank-mailman (input) for mailman id 1326232; Wed, 03 Jun 2026 13:06:27 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIh-0006Yj-7X for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:27 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIg-00Fz4z-KI for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:26 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026cc-5cb7-0a2a0a5109dd-0a2a45078556-42 for ; Wed, 03 Jun 2026 15:06:26 +0200 Received: from [209.85.221.54] (helo=mail-wr1-f54.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d2-229c-0a2a45070019-d155dd36ddaa-3 for ; Wed, 03 Jun 2026 15:06:26 +0200 Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-45ef779c1c2so3566860f8f.1 for ; Wed, 03 Jun 2026 06:06:26 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491986; x=1781096786; 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=ga8NUbQdyZJ7AuIJzNxg+MgQvikeNA0e9nhxhm+dxDo=; b=C9mAA7oCwVS19b6k/gIZJx+pWIb8o0GCXMnwMC3AJtZacp1vJeqeeKClOAHEC2tEhG nHt1n+24GQN0hrg5LpjMSgmVEKL6Vdhe+C1gPbyRWChERBw5sw8qKdLAKEDv9YdESP2B EvkSw5OHRTLXJ/C2jJlb4F4Po957LCrJ/SH+YEioIN+U7+puysHptHTKRkLBw30RiX2u rwTfcg853qmsthuv1ma5lON0tJgUJu80fOShsB7g9JmWSQvqzxRC/VHGwSrn90keZyuw 7pIUrkmLb+xGvmeaxD+V25ITj2mcX+PMNRcrtSxO5Q7CcHkHuB1DqmjA/TQGyKt34qqX xHwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491986; x=1781096786; 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=ga8NUbQdyZJ7AuIJzNxg+MgQvikeNA0e9nhxhm+dxDo=; b=IE2vPeXc5JB+Jzuh7B46yPx00iwC21yvjFJjIy62OJHksfaTadpEwVmkpYyhdARtZh NCNaStEU4GEo0Drc5l8m4VhxFjd/Ib34h7vAqKAAkrNBKceDJWSO8KOHzl3eT6DnscqQ 3S6gfyBtjX4GR+Nn6hnG4v8iZv3faku8izMc+FSu2UAJvaYRoV74wUceyPUaGVcRccm4 330zQH93SGUpgjUNiiYtiEhrnXzOkp9/y7/aPYGsTf29bZh1JFDP3cIRnz9RSNXR+se0 pkI/x0f4W0GDZDHhwNPrWJs+RlMnVjSxv+4O7xHme63d5hzqAgfYjRRK1dAyDPnzt8bc D5zA== X-Gm-Message-State: AOJu0YyPcfgCDFnyNL2CbQz05vFYDuyisCnRbzPxxUAn2Mhm2erX+Pah 0BSTyM8aX08IR08Q8+t/8qe9/Ipl04zpuxzeCHahXgSidb287GvFvl7OS0dPobBh X-Gm-Gg: Acq92OEy98SgewwPXtMpSnQVO8x5zr90ATUiSASQ6/+Cqj80S69XXJncx1lVr/BM3kg Lyn9IH3mdEk0E3QFBpWpB588tU1TXHRmBWWQry4AJ3SWUFtf5JahkmKvZy2Am4Jbbm0gikjrq4L QDA/bhTgDxm0lYTk5g0UHsWQvMxw+c0+LBPjI4QpVQiH2adXmw4z7xU+0T4t3UquQM2g3vnUbOb MzTFw+jEEhj20PE5vbHng7Dgt7K2DS/4kyEb3sWT7cnZylzB11cIntkRprEIDZQlotK/CW0Mr7C RA1ha1aHM86NT1FBYov8EzC6oDt9lAMkEnEBSdYoGBnzGeasC5L2fonU1cfVmpRVcaiR3hKvfSk 68WrEA5g5QgOPzpSSmNxoYwCg0gUl3Nk5Muq/24CbHRXwaVx7B1yaUp+kr/gBRU49ZMCHulO2gb kMW41uNTNS/eGoHXLiPQt0lG6OuouCUFmPyusgQhQri9VY8Xzh4OPTxLFMz5i/vXc0yHrGUN9Z2 r9Ss0HyoET0K5LuzQp2c5EPbJ9t3r2we/xY X-Received: by 2002:adf:eed2:0:b0:452:6aaf:76cb with SMTP id ffacd0b85a97d-4602178b717mr3700601f8f.1.1780491985582; Wed, 03 Jun 2026 06:06: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 v4 08/16] libs/guest: fill directly iov structure Date: Wed, 3 Jun 2026 14:05:55 +0100 Message-ID: <20260603130603.776452-9-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1780491986-22971C48-3311927E/0/0 X-purgate-type: clean X-purgate-size: 4533 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492033838154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio 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 | 62 ++++++++++++--------------------- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 82549b5589..e8452746e4 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -215,7 +215,6 @@ struct xc_sr_context_save_buffers xen_pfn_t mfns[MAX_BATCH_SIZE]; xen_pfn_t types[MAX_BATCH_SIZE]; int errors[MAX_BATCH_SIZE]; - void *guest_data[MAX_BATCH_SIZE]; void *local_pages[MAX_BATCH_SIZE]; struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */ uint64_t rec_pfns[MAX_BATCH_SIZE]; diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 7d8055a3f9..593268f176 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; @@ -114,9 +113,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); @@ -159,6 +155,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( @@ -200,60 +209,33 @@ 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492008; cv=none; d=zohomail.com; s=zohoarc; b=as+lvHtnGeeFAg2HL/aXDynBkwXFe8Bfpm8x5zQ6eJxOrAH5tyP660D7snEMyO7vUZkgLGnsLdotKHJpT/Qoh96gXHgz5GxPQXJRYaFfCre1NMI8Uq+yEZSzgx/o/LL+NDzq1//CTGHwfzYOo1XGlDzzvCt60I+7RHI8rDTW1fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492008; 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=KKuxb0CO6/FH9FO7YOyiSG4lQEpi75NZF/ea4dVESjo=; b=j8pCBBRecYb/uJ+0QxtQX21+7/iFYTxlsPpXkGg2FxB5PY7POyrYRLIlyuepTqR63JV8OORGvKPcTV/6IKL4jBBQbB01kss+FejIw6N6PMqBPVDPZpC0gOO60tx+rJQ4ByguQV7yGKC/kWhNkc2cucb+COfDuUnE8FqWsHSV8R4= 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 1780492008967182.4365978440385; Wed, 3 Jun 2026 06:06:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326233.1591727 (Exim 4.92) (envelope-from ) id 1wUlIj-0006zf-C7; Wed, 03 Jun 2026 13:06:29 +0000 Received: by outflank-mailman (output) from mailman id 1326233.1591727; Wed, 03 Jun 2026 13:06: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 1wUlIj-0006yP-3L; Wed, 03 Jun 2026 13:06:29 +0000 Received: by outflank-mailman (input) for mailman id 1326233; Wed, 03 Jun 2026 13:06:28 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIh-0006iZ-VH for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:27 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIh-000siy-C1 for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:27 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026d2-e002-0a2a0a5209dd-0a2a450586e0-6 for ; Wed, 03 Jun 2026 15:06:27 +0200 Received: from [209.85.221.52] (helo=mail-wr1-f52.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d3-aaa8-0a2a45050019-d155dd34e827-3 for ; Wed, 03 Jun 2026 15:06:27 +0200 Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-46013161068so1771657f8f.2 for ; Wed, 03 Jun 2026 06:06:27 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491987; x=1781096787; 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=KKuxb0CO6/FH9FO7YOyiSG4lQEpi75NZF/ea4dVESjo=; b=R7CadIYOXVRN06F/q298zH4BwvFlN3f4EIUJtWn0O50i4Msa5sZwKpx1VAOcAFzAHQ uBwKPJ4l0XFWRMZLEgqkx5yJTNFON2PNjEulVKkvIJwEhMsxdkm6jLRf57d9HrTNhXAj 8cFSLthmZJYYc4Ee9363x2bE8ShIiv5AsS5NUugA7lwjNKerzCot1VlmxXwK7DNocCZa VbweOIjBw+xl1bEPc/MZHFKfv4n/aEtBckYsT2eCOd8Pd/7QLTqdT/+4ZykfxZvUfVP4 2C/p4hfWbSL0ulDtQAAUxR5aZS12F93jV5Y9oGNGD+oQT09W/AlNVg418fhyA98UCQCC vWlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491987; x=1781096787; 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=KKuxb0CO6/FH9FO7YOyiSG4lQEpi75NZF/ea4dVESjo=; b=db3bqgEzawlC3cXepOgHSwcJl/Xvynju6tTfaqdhvUyMbI58waiyv9ZYLN2qzoD9V/ c5z2zBseVB3H1lj/sErUocUVFvI1OfSZ75rx4Rf5aKrDvxevQs/bzpKz5UHCGQ4ESomn F6BPFQXFGemlSFb43nJd/kRUL385mDuVKBXdsjSL7EL79hLfvqJEE+t2G6DrvTJ/rwOY ZprqgsBqP5C/9RnL1yGSPZdGAduYGbJhRvIhpL7U6AA9VXSOAHbm/R+Vp/fv8nm87oUW Llvqoe572wh3G2m2C6frG6Gi60zHfpQoNf32mPOWwH/mrMINIYNo0aQfwDS6/AnOyjbP D/ug== X-Gm-Message-State: AOJu0YxJnjJGNt/lg5GH1ZzbrbAPYxQuMMsKqF15IzzDBSTOmRu0w+A9 o1thAZbH6f5JtfAFk8caC5WBYRsZYkwBW1wTwT+BJjpyWxTLZq58TFPB0IlXnoxD X-Gm-Gg: Acq92OGqwRtrYcjaWEf118twonHy7HvbWNXA1gqBiuYYIwnU2YQ52W8jeF5erk8yZdZ uLUKDUQsSJfFYyXls/lmKK3fAKcydtWWSqW+9ZneEOSAw8tRbQC5VZdvVXtHJWwvuuPi9RG4co3 y9XOJxZZYSOYksFCV9rKbYAx4/vdl0pY2Fu62092Ab5jcyPAPIL3XR6b7Vqvrg47SvN3YnPhalH 18Be3xGIzVU/7fwwMcM3UdEgM42m7sFjgYQsEbqEpPDkhllJIFkNNZaBSV3V7DMJ/pOAfY1CtRT Nq18kIxO/KaRbvEXsprhjIBDBOgzIJjYygkelxB0q9wUPdUpK9hsOa2l6Kman4MbUAgh+hBwQ4b JBkcOYgDJOAKX+FFibo9BPytW6DToSh4djOd7zdUnNMfs4O1Y5lYbxq2U1mn854ElX1vGGfmQI6 cw5qeXeUeC2aEbDB+xTYWxkkE1r1Qyso37MHQFWXO7k01k0bxvy/vFcajrlXwSZHMw2YWHRYxfG rSEvIKA49b5xxJb3vb5h8mhw1p8BcJAnAEz X-Received: by 2002:a05:6000:2905:b0:460:ff2:63e5 with SMTP id ffacd0b85a97d-4602181e60fmr4559736f8f.18.1780491986609; Wed, 03 Jun 2026 06:06:26 -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 v4 09/16] libs/ctrl: Allows writev_exact to change iov array Date: Wed, 3 Jun 2026 14:05:56 +0100 Message-ID: <20260603130603.776452-10-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-c201ff/1780491987-E3589443-1145D8E2/0/0 X-purgate-type: clean X-purgate-size: 3226 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492010895158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Avoid having to allocate and copy the array if a partial write happens. The implementation in tools/libs/store/xs.c already use this signature and method. Signed-off-by: Frediano Ziglio -- 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492034; cv=none; d=zohomail.com; s=zohoarc; b=iZcdBg2131Xjg4apLX0BzoD9r5Yq99+F1sXzOyJW6r35zO78ZabKiiofAFdZ6q7SHXlIueWtEDzmqfq8hj4xEut7fR5PXpLxqKfEsE1e+tzGbVBRWSK5sEKmLtg5HSO1yKOITn2ptXmUbU0pzxs/4+2CpoFDpYW8/p3/zshZYMI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492034; 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=qCpz3u+0gUwl9boMIWgHEbNmxOn2zYt5frimeVUxE30=; b=FtjuCMMNHkvf+GkvxJd+7BCv5oM6aGFNjWOo1BGCaPq4fqd+O3kCqduIEQrQxmRmC68tTo3Fg9H6cXIaSBmYMwePXsjySDIZEViKnp2LRhIJy4dYYp2ynXwNcgW+zlimrK2fXUvgpixC1v+GQsBtXglEO3MMmEvAHfHVhQpKhb4= 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 1780492034282882.040889110798; Wed, 3 Jun 2026 06:07:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326234.1591740 (Exim 4.92) (envelope-from ) id 1wUlIl-0007Pw-Iw; Wed, 03 Jun 2026 13:06:31 +0000 Received: by outflank-mailman (output) from mailman id 1326234.1591740; Wed, 03 Jun 2026 13:06: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 1wUlIl-0007Nk-0w; Wed, 03 Jun 2026 13:06:31 +0000 Received: by outflank-mailman (input) for mailman id 1326234; Wed, 03 Jun 2026 13:06:29 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIj-0006v4-0i for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIi-007IYC-DT for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:28 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026ce-bab6-0a2a0a5309dd-0a2a450bebbe-16 for ; Wed, 03 Jun 2026 15:06:28 +0200 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d4-212f-0a2a450b0019-d155dd35c909-3 for ; Wed, 03 Jun 2026 15:06:28 +0200 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-45efb698ef2so2358935f8f.3 for ; Wed, 03 Jun 2026 06:06:28 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491988; x=1781096788; 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=qCpz3u+0gUwl9boMIWgHEbNmxOn2zYt5frimeVUxE30=; b=SFTj4CkyWPLhWvQnyVU354cMkyeKw4D4lz868LH3uwj9eHzXbikRBJmSOsrp6HKY/t 44pe3ujaDfi7egx246K33OqK+Qs7A/Q74MTZezlZfF94VdfZaRjDPC7hNgM1+hKUhQD1 D4NGuDG6A7cgyAF8bOCMZ+3uNAnGAIrVlGeQ7O1LgEiZFarULuKBXqr/+DQMv6YrhQPF thftdE6+a6EN7i1EPF/fCImenp0h3YjkRpCbHN0Yl6WgpubXw4OE4yiDriz3E+k/SPnP WGxcMNezwh1G1lAGS3FVHxEDeqrdkMaizlebVCX1pS2HGalRAOMzxECsuNkBdizcN0Hm xCUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491988; x=1781096788; 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=qCpz3u+0gUwl9boMIWgHEbNmxOn2zYt5frimeVUxE30=; b=hAimnwfNJbu9wu8rBuNqLuxiofqN01ih4Q12CD7O5WkHHNrRQ+jICO7uYl6gIyzJ7N Rg7z0nk5GPUcKErFmd7BntWCMCiDT3W8TjqY9tQemXnq9GlxUMlBbv4EkiEW8XJjcT5b LrIES73UlpI7o/r+qv1qCj6me0unAyC3u+A/kst390E/2WNAItVsrYo6eTTQnTbp+9F5 +AU3QdFq9HuRfzMBdmdJ9Qs6RyM6C8yQAfN6ubDZk5mk8Hijj+hoynm+AyE/vVHCj6ta R+9EGxH1RjXNlRv2EysMO092po9HpGGkN9R5eV6CIroGD0b/CRXM20A/J0HWylz2Rt1p iUJQ== X-Gm-Message-State: AOJu0Ywf2YmdrYU6oIml7Yk5tUzrzujnwTIBpjtdyj3lZPl8RrBLKj3g 8urzn68ksftvzRFhcOxn/qS0w5uWkXfFqnc04AN3VMog9VWjIQJkOskNlJlq7wA3 X-Gm-Gg: Acq92OGmh9h0qevPNXYjs3MYvQezkCqpHdcOxJXvqrYHKoHhvUOjfYVwwBe2JexhwGw 4gvGHenINGkDHmlbglUstkFG26oRVr6EooN0fr+2rFb+onZugymYR+VoMGETTSyt1A+VHiea3LX xHfffplSRkW+C/mD1TwmvM5schIZMptUVS2TKVPxlcc742c1o3NOLh4vvyNmqpGnuFFKt1CmyZA JgTbmN5QhOUE2wBAR+mx2VvOBuPMBvFumC6YyHF/aRrybfCHspw4sYR94DO+DEMnu/U5EOkIFda 8xQOlpXnpuc67PveEgRsSFfrfIolhhzQLQajU0tXKutniRRnEzcLvv4Q/DB4nsfJVLRDmxC5eEw W+L9Ulk4D2CEkqhdjueGPp0JLsitTRrtv7I8EPMYy5dvq33S9jdghJxA5BAblWEWhB7b+yFCbrX LuGPK8i74s/I7d2mCPB7weaqzGiApeyBSKWSuVP++RdQv+xWiwUrySJJD3teyvT+ApT2yR4V6dV n4dcxJMEI/PJo8Tr1zasbH3XbxpUR1N4B+g X-Received: by 2002:a05:6000:299c:20b0:460:1223:a044 with SMTP id ffacd0b85a97d-46021612545mr3590294f8f.0.1780491987578; Wed, 03 Jun 2026 06:06: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 v4 10/16] libs/guest: add xg_foreignmemory_copy_{from,to} Date: Wed, 3 Jun 2026 14:05:57 +0100 Message-ID: <20260603130603.776452-11-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1780491988-18762F3B-CCFB2C11/0/0 X-purgate-type: clean X-purgate-size: 3485 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492035854154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio 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 --- tools/libs/guest/xg_sr_common.c | 60 +++++++++++++++++++++++++++++++++ tools/libs/guest/xg_sr_common.h | 8 +++++ 2 files changed, 68 insertions(+) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 86c148c62f..a94e9dfbff 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -156,6 +156,66 @@ 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 ) + { + errno =3D EINVAL; + 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 e8452746e4..72c9511f38 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492046; cv=none; d=zohomail.com; s=zohoarc; b=YB0SOcgmD2wEC3wVHWnp+1YCIT+TlxeJ0/yrUMahK0vVjIDezlZLfjLSzT5LjNABYWK83QweRkrNHRyejG/C+LrCNNLAtAsrHjYzkhvBUggWjeI9tCilcrQZ8dGt4+gLlmguvI4APLb9rhinksPqpe7XsbKxBWG+UozMF76fUTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492046; 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=wwnZlaNynVBSXMUBTGRaz5p9t0WwZCVY/lkJngWndkM=; b=hD67pT6xTRRlpPLXspGq7WWt04w8EX6po5KvoijOCrHLdLcrEzCMbol/w+GFu4XyghEjCXqp5bacolx+fA3Uy5Gp1pAvsvS00KppAAJIbNXokyBhyJ4ITMxOO0JeDS7qQRfbhMh+WDs2wMsN0otKKv8glAFe2rQfAXeBtxcQ93Q= 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 1780492046415323.7003798283995; Wed, 3 Jun 2026 06:07:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326240.1591755 (Exim 4.92) (envelope-from ) id 1wUlIo-00081P-Cn; Wed, 03 Jun 2026 13:06:34 +0000 Received: by outflank-mailman (output) from mailman id 1326240.1591755; Wed, 03 Jun 2026 13:06:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIo-00080a-4w; Wed, 03 Jun 2026 13:06:34 +0000 Received: by outflank-mailman (input) for mailman id 1326240; Wed, 03 Jun 2026 13:06:32 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIm-0007UU-00 for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:32 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIl-000siy-C9 for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:31 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026cf-e002-0a2a0a5209dd-0a2a450cc1bc-30 for ; Wed, 03 Jun 2026 15:06:31 +0200 Received: from [209.85.221.53] (helo=mail-wr1-f53.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d7-62f1-0a2a450c0019-d155dd35e4b0-3 for ; Wed, 03 Jun 2026 15:06:31 +0200 Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-45ef372c58aso2818198f8f.0 for ; Wed, 03 Jun 2026 06:06:31 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06: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=1780491991; x=1781096791; 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=wwnZlaNynVBSXMUBTGRaz5p9t0WwZCVY/lkJngWndkM=; b=o28oC+EssQ43Q0lbdMTetPeq6VinXKVV/lwahvhOfWcOGTqWYobjj5OMgiFDcWkmLs awHpPKNwiOSybJ7H7wQlupNrf1OIcdBaL7LsG+ZMknZr2iJU92KAMPtNdSlRzFxiCNfP tL6K1reY5Vlnu+i7VomW4vkIPo/v4FIc0adpsjGBxmNVsbAAwdzYPYFOx8OE62Q7lE6k ez0oEtrn4tvqqYiLIlgSSwZWmk/P2SJAbvRYHtPdsbT/EN4ELzJ9aINBhwfgu7PJpflI l4aJ6c8xbmqmU6ehWwXdgwaGH/W5SCSPTm1zwH9+66m6q08QIjC0+qn3PmkrQY2Lp2TB VeEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491991; x=1781096791; 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=wwnZlaNynVBSXMUBTGRaz5p9t0WwZCVY/lkJngWndkM=; b=TC4/Z8qRpU0/UznLi/okcIBXWzvoE/nQuJT9PpcHsvyGG8XWWWrtftOtMYq9rzQgl+ Zo7zpp1t0vxyK6AZCh8MFyEfZJLZDXCY97RPImMY/1tjXcxlYyboL7MLJmkhFBACy8z6 qrizztEED9+gUTSSdyR2lHAjVfrhG7PrTcenaDy5iLL/VrlybOr+Nl5/TpWEhXqwfSlm X176Lvyve5Y0JNRc2u5Uc/P6ZuMSZ3V/dGlIIKaF4dT0H+xUAsDi/FzbLyLrPkXXV1GP lwdgMKoudHqGJd1ulU4CBrZ63RyGYZE1BMwiDg+XySwGMhcOMRKSWas04yW56tsP7g4S 0geQ== X-Gm-Message-State: AOJu0YzJFZR4Wde8w8wEHxKMeXvjRlC6xerOHajF+FtCWMR6i+vLAMcA eY/wf72kH2Bk9dlQaateIvosMJ706Xrn9DoisMznsZp9Lv5lvRBNaw9uM4Jkt6tF X-Gm-Gg: Acq92OHNHPIUj+srUzxJjDzWU0tzhW5vxM1oQbSd+BDmvZyr/A7TQwH6OBewOi57ceU ISF4j8VhPjn6y75uM47ndGlYI6xYXMDpoxZZob3tMaTTiknSgJz2aTZ/tGTdFUs6nr5ao9ztUZQ kJ1znG6AcyszSRJx2hNQa7Ur7yAbLfhBdxNPGl6aIXFl94KMWAFLy8zOV4HhrKy6qae8ScVPo7H ipH8+Mnqmu9r+PCg5lcV3aJBCAOcssZwPSBZB7weQAfsD2FWzUofa32g9DH2pBICJIJ5oIFtWmJ wIQnsnZ42b0VbSACjGYt2CHD52uL4lg3NAJ8XaYj5zMHtRRx3MW2EmLW9ZhJhWDlrwG9sZknf8N EsuuCMZKFvL9M8mAYEy8jRcf8tBpRzdgqkc/ija5/gspiZgM8prja1cK3gXPo4LpiJqu5mk4prF bS2Bxw6mdoMKUi19SLZgZhP+B0PiGnAdASzMKIup5MrV11CY/AYSPEw+NANiv+v70DO7SUOA1u9 JViD9NUaEB6hjJZUonZ99FWU5zA3fOlJheRXWJYZwGCK7Q= X-Received: by 2002:a05:600c:350c:b0:48f:e230:c3fb with SMTP id 5b1f17b1804b1-490b5e95f97mr56158965e9.33.1780491988654; Wed, 03 Jun 2026 06:06:28 -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 v4 11/16] PoC: libs/guest: use foreign copy during migration Date: Wed, 3 Jun 2026 14:05:58 +0100 Message-ID: <20260603130603.776452-12-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1780491991-DBB7CCF5-220DC120/0/0 X-purgate-type: clean X-purgate-size: 8537 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492048141154100 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 | 42 +++-------------- tools/libs/guest/xg_sr_save.c | 81 +++++++++----------------------- 3 files changed, 30 insertions(+), 94 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 72c9511f38..0e0e279ae1 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..b589f0397d 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -259,7 +259,6 @@ 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; =20 if ( !mfns || !map_errs ) @@ -295,27 +294,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 +305,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, p= age_data); + 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 593268f176..ae61f97a47 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 { @@ -168,61 +166,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 +194,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]); @@ -764,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 @@ -775,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) { @@ -809,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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492007; cv=none; d=zohomail.com; s=zohoarc; b=fgeXAUL930KrC53qA3P6G10/i4A5waqzW2MnQd3YO+HirttwGxqAylfUILVJsBhWpvQ/1sY7jN9l0lGctHZ/2bnSJezQHxzMfsuEe8kPbPy83VZ42PKsG16Qs8F6HdoYi1/dOJcEXSrsO5Gtiuf/u3Gw7OFs1TzIn8UFPQhF7bc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492007; 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=UL0N3KKHtVrvo4ntoGJtN+QrR4yck3sAmYsmSdPB7So=; b=EFbAWSB17ElUTvT7qurW3XSvw6sasBLz1i0jpuEHlLAEvgq/myGvFAnvj/i1PgqAi7bxKsqbUi0+x2qexNWJO+IXSvpBaefU0FS6/HjsggQQvCv1aTQkRq7RCjAVm2EE2dRa8zzwyMT2WTpB1wdNP8wtBmfJPYniDXqG64Q4ZVY= 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 1780492007693331.4625863253169; Wed, 3 Jun 2026 06:06:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326238.1591748 (Exim 4.92) (envelope-from ) id 1wUlIn-0007iZ-2x; Wed, 03 Jun 2026 13:06:33 +0000 Received: by outflank-mailman (output) from mailman id 1326238.1591748; Wed, 03 Jun 2026 13:06:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIm-0007h7-Lz; Wed, 03 Jun 2026 13:06:32 +0000 Received: by outflank-mailman (input) for mailman id 1326238; Wed, 03 Jun 2026 13:06:31 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIl-0007Kr-1A for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:31 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIk-00Fz4z-Dt for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:30 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026d4-5cb7-0a2a0a5109dd-0a2a4507892e-12 for ; Wed, 03 Jun 2026 15:06:30 +0200 Received: from [209.85.128.51] (helo=mail-wm1-f51.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d6-229c-0a2a45070019-d1558033b1f0-3 for ; Wed, 03 Jun 2026 15:06:30 +0200 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-490b613a17bso9395445e9.3 for ; Wed, 03 Jun 2026 06:06:30 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:29 -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=1780491990; x=1781096790; 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=UL0N3KKHtVrvo4ntoGJtN+QrR4yck3sAmYsmSdPB7So=; b=sq+qKER79/oD4gYV7VydoZGgdzu+oAKmQCr1Uzgvv7ngbZ7Shg4EfpPBKkcG7dFG10 keA0372FZkxS16s8wfM44cJ3UkDP3OzFgrwfW0QolTXb2lcPZZ71BpF7x2EWAbjYpIJz /WZtJJbgEqcqKgM+XNQYamNrelCuItvoEwX3qnk0q7wJgYPwCyTtAk9jvtNgZSHNfXCM pF7s+v2eqfMKdMFIm8CgDtt21LijlLnJ7XrRSF4170zxe/nx1pPOjhzeuHRI+1eZqrNh m+y5fi0g4F2TdgK4zLBxeeaigy9WipA2LVSInj632z/HRADkqwWanyqteNLXh9q+ge9e k1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491990; x=1781096790; 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=UL0N3KKHtVrvo4ntoGJtN+QrR4yck3sAmYsmSdPB7So=; b=ef8N16gpnizmKNe+gGs07fdHE2q+f8FhCWRzOm3WFO1tItva+PFGoRcxOv9hMLhHn7 pCqogIIGELNk3v35aZ7RYErbkTWN3DA0XjggpC+45ljTZHEFctlQzZ1m14JlLiSSphdm DNbE/CCnPp+GmR6uMJRJ0QhAbdX7aPohCcLYBsXihH1dzWTIPnd7+Y2Lm508EOQjyLJL XhYtWqIzySamTWIbR4XlThGcR+PVXJvpA0y3zTmOFhd4bWap54MU4rv2bLEm2r2yqqr+ LZVcJHbIR2wC96u9s3ElKum0H4o3+ghld+yRcjAvNBMIg4IW4SBK0fjj2mPwjAHHQhnO a5+g== X-Gm-Message-State: AOJu0YyPieG9VXnSOjSBh/rCLeXYLLyTC0/WZPAmyU4aJ+CL3pAkNwOV HO4g87pMIzHhxMX8iYXPSErqCI94NWF5QNaRdCTe2X6UPAoTLBu4YTRxVoejdJjQ X-Gm-Gg: Acq92OHVpmSiawF9NKbWnk3jv+uryUqtaxb9+YI195IjnZwF9zgY8xLZL8wlZgQEgnK ObNnFEB/7xqOooLZoCOax/+VT4plFFWvcRUCmdf04GziX1YvFzSI4zC12Sq8tVxb6u15MYUQVwv mjznohvTc0qISnmIrfdZDA3KpeijiCsX4ik9iUirQ4nIaTy/LRFuW+wUs4M25HJeAdiU1uCXVJ6 NsA0MPi748lAHloK0f8XwhaulrzWqG8ACtBKjj3LwlRU+vKbgfM9LMVuFaGtUtZYp4sFSDDIkOE 2SPAbMXwVuyelYjqYaAzsu48uWOb2KHR8WT6WpNu7bWzseDwOUmqJoFtxMFYTOjqm4yP/coD+aD A+RRvjzUqPgwv7UIVp/dAeQHchYrd4Jzwg5QpJm9rv7tHcEzJzWUHc8nKXrnblYg0SsLB+zgPq8 YtuZR5Isux4DAqyKWq9EWIpDZRquMO1Pbip/9jjipOHqKja9gWDyZU+iQCB9vQCDzG0uJWfG3oO c4eZDVO2z/9ip3IS5e+UL5UA8U0f4pXlPeS X-Received: by 2002:a05:600c:810c:b0:490:47e3:929a with SMTP id 5b1f17b1804b1-490b5e7961fmr59382775e9.6.1780491989710; Wed, 03 Jun 2026 06:06: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 v4 12/16] xen: implement new foreign copy hypercall Date: Wed, 3 Jun 2026 14:05:59 +0100 Message-ID: <20260603130603.776452-13-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1780491990-0AD77C48-08B014AF/0/0 X-purgate-type: clean X-purgate-size: 6426 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492009034158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Add a sub hypercall to __HYPERVISOR_memory_op to allow to read/write memory from/to a foreign domain. Signed-off-by: Frediano Ziglio --- xen/common/memory.c | 133 ++++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 40 ++++++++++- 2 files changed, 172 insertions(+), 1 deletion(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 3672bda025..6a2d9c3190 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1545,6 +1545,132 @@ static int acquire_resource( return rc; } =20 +/* + * The "noinline" qualifier avoid 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 ( !arch_acquire_resource_check(currd) ) + return -EACCES; + + if ( copy_from_guest(©, arg, 1) ) + return -EFAULT; + + if ( copy.flags & ~1u ) + return -EINVAL; + + direction =3D copy.flags & XENMEM_foreigncopy_direction; + + if ( copy.nr_frames =3D=3D 0 ) + return 0; + + rc =3D rcu_lock_remote_domain_by_id(copy.domid, &d); + if ( rc ) + return rc; + + /* + * 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 i =3D 0; i < todo; i++ ) + { + struct page_info *foreign_page; + void *foreign; + p2m_type_t p2mt; + + foreign_page =3D get_page_from_gfn(d, gfn_list[i], &p2mt, P2M_= ALLOC); + + if ( unlikely(p2mt !=3D p2m_ram_rw +#ifdef CONFIG_X86 + && p2mt !=3D p2m_ram_logdirty +#endif + ) && foreign_page ) + { + put_page(foreign_page); + foreign_page =3D NULL; + } + if ( unlikely(!foreign_page) ) + { + gdprintk(XENLOG_WARNING, + "Error accessing foreign mfn %" PRI_mfn "\n", + gfn_list[i]); + rc =3D -EINVAL; + copy.nr_frames -=3D i; + guest_handle_add_offset(copy.frame_list, i); + goto out; + } + + /* A page is dirtied when it's being copied to. */ + if ( direction =3D=3D XENMEM_foreigncopy_to ) + paging_mark_dirty(d, page_to_mfn(foreign_page)); + + foreign =3D map_domain_page(page_to_mfn(foreign_page)); + 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 copying to mfn %" PRI_mfn "\n", 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 -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 +2138,13 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDL= E_PARAM(void) arg) start_extent); break; =20 + case XENMEM_foreigncopy: + 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..b48d1f378f 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -740,7 +740,45 @@ 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. + */ +#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. + */ + 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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492017; cv=none; d=zohomail.com; s=zohoarc; b=k2lpCqVTUjACpp4dfqw8YDZyZD+2gk0djEop31pJ2bH4X6/OE9FXfGOcOoadBokPPrG8Mw/+vIK9GJS4rYOLHBp9V4xW1xtOkDBznuqWU/SBr/t7gWQQW1bAIYmNcj4k5p4Drg2Zt2zfODvHbMOz4FxQpUrX+AcykMnODyFw8XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492017; 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=0qWQaaxuAbn2KGJsbhAAbGu8valGFsAq0ZGefI0obWI=; b=T0cylGwtZijO8sRTy4DA9DiU/13NR2PiufsQ/HynC+8I/HxT+9bKsd7OuBn82Jc0jwi8r/ftEe7c0imxN9+1AVThsUkzL9MamAzS2KcNzXDFGB499OY5KaAyeZw/4yf6/DMNorK/h8AgiVZ0QO5cRISroPkR70Mdx9Xt9rU/pqQ= 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 178049201781384.88123286791154; Wed, 3 Jun 2026 06:06:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326242.1591762 (Exim 4.92) (envelope-from ) id 1wUlIp-00086S-Cx; Wed, 03 Jun 2026 13:06:35 +0000 Received: by outflank-mailman (output) from mailman id 1326242.1591762; Wed, 03 Jun 2026 13:06:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIo-00083x-JN; Wed, 03 Jun 2026 13:06:34 +0000 Received: by outflank-mailman (input) for mailman id 1326242; Wed, 03 Jun 2026 13:06:32 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIm-0007ZQ-AO for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:32 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIl-000siy-NM for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:31 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026cf-e002-0a2a0a5209dd-0a2a450cc1bc-34 for ; Wed, 03 Jun 2026 15:06:31 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d7-62f1-0a2a450c0019-d1558030a999-3 for ; Wed, 03 Jun 2026 15:06:31 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-49041e84237so6558925e9.1 for ; Wed, 03 Jun 2026 06:06:31 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:30 -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=1780491991; x=1781096791; 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=0qWQaaxuAbn2KGJsbhAAbGu8valGFsAq0ZGefI0obWI=; b=hICqtXaZgBdxmoN4hr9MTDgE0TnSGLWTDPJ8zGvMfuxD7OTuYsMnaySasJewnUwjll xQ1ajeY7xP1Xub4/8BGEBMEtkfiideKAleToVuc8eb0FhjPmFrACyWOm5zygUIGNLu9z 8e08JsWlr1KbLxH5QVLQpzrLMylh2r/wbkf3EzPHLOksYz7DINw5GDwaRjydO3TZsP8s P+KAZ+cb+bWTxO80fCx9QtH5zXmqgF+PLUyIc8hE8Fh0uQfHCTNtUUJRjD8nnmzx6gPk M5HyEz9jK0rXfYsXOEEnbrYLKe5invGLecw7Xf3rZob2GZS+lWQKCnjwiNAWz1lC+nIZ la+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491991; x=1781096791; 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=0qWQaaxuAbn2KGJsbhAAbGu8valGFsAq0ZGefI0obWI=; b=OUWWyHf3r9Z8zvUL7paylbNpmRwyjj8wJY+R81HoeM6lBWLljWsYMipm3mjtbhAmQJ psb3F5Q03sxjLJnS23fuU8R8RUC9ZU/nRHE5AAeQ49gm7zWs41rkkVuADt2hTQDGHG69 fVs6aWf02mqXHjgr7jf9fxs6UjsP+lrD02yN1mJPhq0Q8nqZey3dh7p73EGv93wUw68N mH3nmju8IQscaSwW8s3Gfd0kY4hNhPSHTy7vUcRZzYDm/axoUrg49J/NeNkmMm2O4ert OYiNP6VdR6SbB/sqV9b96T01QTujAEXokAipeEMXQ0TI1hOQAkT0x7atyrIG31GEQFa9 QCEA== X-Gm-Message-State: AOJu0YzCJJ41fzAK4GCfitMbkQ37WPUaOt1VTkpSmNlS1Xw9qjE1PSJr ullSmB7SXFR/rNbjbD4Gmg3bPwUxnbmWh8RZQBB7APjY22ivAN1tYqx8x3QSkta9 X-Gm-Gg: Acq92OGAiBhyS8LfQkU2m+pl7C5PqXII1Q0HBqgrwZYOpPLbAYpAyr5qKwXvqi5OvpJ EaCq++hU0VLpulOsG/zovg2uQqPDFWey6i8Znb9IOP2jzSIP7ik2q+2ZIVqAtLYwl2Zxkw9cL4F StVyGTlUMI/kD0mrXMtF422VvuJOyQKfAyuwLYoNzMf+UHFIY89fV6quYmidXPXchhZ5e9kLtw1 S6EfclcgQPxZsDQSPC0i58OVDsWpWiz//D+Z0I2NO0wZO2DT/jndxoHceIR76b9D1kKBC0cPs19 FsMKpY4RimXCVERHLIaQw/erDu5pUICKH5l5kvdf5mf+u6C7o8n2IoX5Wn5ZhhrtAzhppTsC6Tz wfi50oPubBFXX2sTneBIQaJ59YJW5IbBKAeJys7qXpCOajMi12A9aQct8MmoL2xVUAnU9PLLpDZ ht2HBQ+pvKaM5CEAcdaA9VvRx/bdW+GMsUlbzedDdEJAW3PZ47Jj92xNeHI80QzMLFjQ48kmXY8 soYZQH7LMAhBsACDbxoVeCYJSHMG+pKGEvH X-Received: by 2002:a05:600c:3e19:b0:490:8b0b:d3b1 with SMTP id 5b1f17b1804b1-490b614c9demr51876955e9.12.1780491990938; Wed, 03 Jun 2026 06:06:30 -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 v4 13/16] privcmd: Add definition for new Linux privcmd to access new Xen hypercall Date: Wed, 3 Jun 2026 14:06:00 +0100 Message-ID: <20260603130603.776452-14-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1780491991-E0766CF5-32E95B89/0/0 X-purgate-type: clean X-purgate-size: 1452 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492018888158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Userspace should use new ioctl to access new hypercall. Signed-off-by: Frediano Ziglio --- 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..4b80eeae06 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, must be page aligned. */ +} 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 \ + _IOC(_IOC_NONE, 'P', 11, sizeof(privcmd_foreigncopy_t)) #define IOCTL_PRIVCMD_UNIMPLEMENTED \ _IOC(_IOC_NONE, 'P', 0xFF, 0) =20 --=20 2.54.0 From nobody Mon Jun 8 07:24:34 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=1780492026; cv=none; d=zohomail.com; s=zohoarc; b=AT6W2aGq2/uEIPIu2H2DaC3bHBn/Zgw0SKldAoCb2GlmXaFyi1vajjNuKhizTlFHkD3jKyDtB3JBi6+vWjmdtjFtaMr+GqnzbmBCEUrDp57uPJAmw+GI7MblqkeO8Pl3xBsyzIJUXcCFKRuH8LnqOLcwnYR0uV5ldVAG5HuH5Ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492026; 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=D8RZoFNdKBiiJYSE0JveF3xGCWq95UHsjjlw2XdGNa0=; b=m1ZK+7qtv4OgyNsnGNyZHUhuVIcPtSDSZ0GXlaOUiBJ1k+fyqeEycXEKUGPc0y/EDs5JAx/sAVtiUpeK/nM34lFICYhUcLQVcoQaXRxbnrg4T1njl3yQMzrLbipWVVsCGyRYf3SVOGrFe7uvyrtDq3sDTvE+uSqHBZwEvXpZfV0= 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 1780492026161426.6340176933039; Wed, 3 Jun 2026 06:07:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326243.1591767 (Exim 4.92) (envelope-from ) id 1wUlIq-0008PQ-Rl; Wed, 03 Jun 2026 13:06:36 +0000 Received: by outflank-mailman (output) from mailman id 1326243.1591767; Wed, 03 Jun 2026 13:06:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIq-0008MC-6z; Wed, 03 Jun 2026 13:06:36 +0000 Received: by outflank-mailman (input) for mailman id 1326243; Wed, 03 Jun 2026 13:06:34 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIo-0007zb-7M for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:34 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIn-007IbY-KK for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:33 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026d5-bab6-0a2a0a5309dd-0a2a4501d2b8-20 for ; Wed, 03 Jun 2026 15:06:33 +0200 Received: from [209.85.221.43] (helo=mail-wr1-f43.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026d9-c1f2-0a2a45010019-d155dd2bf17d-3 for ; Wed, 03 Jun 2026 15:06:33 +0200 Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-45ef616daf6so5237396f8f.3 for ; Wed, 03 Jun 2026 06:06:33 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:32 -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=1780491993; x=1781096793; 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=D8RZoFNdKBiiJYSE0JveF3xGCWq95UHsjjlw2XdGNa0=; b=ntX164dlsdTP2a/qG9cLPEdns+B041zFXJ1Xk8091DZKWHG6AjeWYsQ9Dugmt1Rm8A LW6cmdw3sYl1sb3q0MrYJBf9cLduLmFBbgitq8mZDlGkFOLdFriF8XBwPyHZwKzzOGXp wEYvRX7aqcU9Dmjg22eHu+YeKfPALDx9SV5h5NwEkzvY6SksQWxGZriCT9mNVQN7L3Pe 9p4NAmE9LbA2wrYyteooV9Wq9DsFJdSS0U+Qbjxxk41LtpGXH6935aSIGtNo25DvMdaS oWsCAcktDrKQ/av6r0OgPHzioiUpQs6IUZOzxqbU6/nbJbOYBa5+iJjIXWXEYzjyfM2q Wt6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491993; x=1781096793; 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=D8RZoFNdKBiiJYSE0JveF3xGCWq95UHsjjlw2XdGNa0=; b=AmwwjCtLp0Nvk3pUOcRmh+kl0adfKYO3hre9V6Vi76sK7XwY+Y47Zgl9S894gGcULa dqKzT74I8v3dWGHkx2MXIFsPc0WhaoGl5FmTZWhSD2AnADxEKqYXgGCf9D1X+5oRGCgB NKLXNnFOEqwPw3i2zB1A+VlAgz9hYFfjhKsDAWyrT0/z+bKSE26LPEvkaEN0g2bTnn8B ljW4rDM42AMBnShUkAZW/dii22Wgvm9WLbC5p3xOTWXwMFdnSiIwLeHBeUMhuRlELXda OAZ1zMEOq+VUp4bR2ZiHMcK3kpm2a8cwrq/yUIZ4Tmh8L5xWUuOCptP6lpOtLiMkcuDx KGjg== X-Gm-Message-State: AOJu0YxxJqtUSnby8yCRaBoS2kRZxYBnnn8XQ+ghz021q/hTazkbcbpB KcHIJsoONULjGN0iGFvtukhqopLmRGoO5b3CsZxvY0ZvVe7kRXw3dlVEGAO9koqe X-Gm-Gg: Acq92OFQkjbCtUwoe1+da7E/aVrMnnSeCDx1DeoIDJpWCE507OqymAxVGBDfP4vzTU3 T8MfzU9gTjAkAbVGBNlWvu52qyF6xzRmZrPlo9sZtQKOuKRUzVzxyGmT/oq8uiqLL6UY35ENKFP L5LZEbF4qWNbC09gLMRM3vpgBCy311Qbm+nJx6jJM2V7xT/eGrzx+FofGb0iUPfpTY5AqxhoZ/G LLV4yVwRXy/5r4A3HPklDAIBocWzJ1MPccQ8IqRUmuioQ/CMbpO/n2ONgqwuNZZADge1bkWmr70 LyCq9XfRSSFGApvXUc2Q3kXz8YdGoCg1U6GDfjvi7gGipyTSf+X8PSYKptYJfeQ6h5YyE1gprbi 9XjDKUggjHu84sk3S2MYemxy0K/Q3iwtum9/rieK0OQFKqYES8bQNzp4xXpAWiitnVCut6j9pAm lyHL+jczjQlSnMf0QFWJw/dy6lGd+Nvgaf9zWbvEcWTApmY8xJ6I5mbon+o6uiURtHApGdCbtGr kXMnz2iyiIafmdM+EMD3zCIQ7fQZi+Ky3Bx X-Received: by 2002:a5d:624a:0:b0:45e:ce28:666a with SMTP id ffacd0b85a97d-46021781a64mr3654744f8f.1.1780491992881; Wed, 03 Jun 2026 06:06:32 -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 v4 14/16] libs/guest: use new hypercall if available Date: Wed, 3 Jun 2026 14:06:01 +0100 Message-ID: <20260603130603.776452-15-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1780491993-AC851FF4-E346FA30/0/0 X-purgate-type: clean X-purgate-size: 3587 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492029734154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Use new hypercall if available, otherwise fall back to map+copy+unmap sequence. Signed-off-by: Frediano Ziglio --- 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 a94e9dfbff..cb3e6a5658 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 char 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 ) @@ -192,7 +221,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); @@ -204,7 +233,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 @@ -212,7 +241,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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492015; cv=none; d=zohomail.com; s=zohoarc; b=HnG+ERooxO09fkXaGCeiajgRAoGDBHeciLE01W0BZgv7JwirGNY8tQLjspKLT3tw9z8MJtNtfaRfBaRYYPkxtjl7uGInMs3nXfYXXPT1v3Ig7Xs/uu9T+4WjR+keCBEpyP9oAnXKXGpA3Av/xPJRRMrC0Nvtkbeea8UXySg5WqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492015; 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=rW1WV99Hkic2EY+4V0AfPPFzJ+ncY9UKbR4cY6w6JcU=; b=S6tNs7gBBgosSr7RORkwOUTvyzjnwosNM/ji+JqoSqgTEMETRm9TMNduA0QT6yaL3PX333bh6R+wdo56MFh0SVqZXAZX+82iftY3WVz/o6VzKmNdYeVj03jMt9wtv92GcjdxfXanPMXhGvxtVDio/lQcdJhx5nnqAbcMdXkD2p4= 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 1780492015494371.1988393835859; Wed, 3 Jun 2026 06:06:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326245.1591779 (Exim 4.92) (envelope-from ) id 1wUlIs-0000QC-Sg; Wed, 03 Jun 2026 13:06:38 +0000 Received: by outflank-mailman (output) from mailman id 1326245.1591779; Wed, 03 Jun 2026 13:06:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIr-0000Mk-W9; Wed, 03 Jun 2026 13:06:37 +0000 Received: by outflank-mailman (input) for mailman id 1326245; Wed, 03 Jun 2026 13:06:35 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIp-00088p-6X for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:35 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIo-006lUv-Ib for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:34 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026d9-5cb7-0a2a0a5109dd-0a2a450cb872-10 for ; Wed, 03 Jun 2026 15:06:34 +0200 Received: from [209.85.221.45] (helo=mail-wr1-f45.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026da-62f1-0a2a450c0019-d155dd2dd117-3 for ; Wed, 03 Jun 2026 15:06:34 +0200 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-46019b190b6so1727727f8f.3 for ; Wed, 03 Jun 2026 06:06:34 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:33 -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=1780491994; x=1781096794; 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=rW1WV99Hkic2EY+4V0AfPPFzJ+ncY9UKbR4cY6w6JcU=; b=OobR68dVHycE5zvua5oij7gGnac7TNZr2QbBuRZE8A5vpdLo7udrk8byiNDyR2zU5W fc0929oSAUrDrzB9eEe/5et8M56qU1QTxdlwUUTvNwP6/7/9ic7uNALaRs1NPTSQ3rnH 2io6ICApuy4YhRVAhnx3Dw+ubDzH1eUoXYKcwOBxlLDSEhiChKSpCIj4CddjTcO48bi1 FDavynaN/EzTgzSuVXdFWKt/gRo2o2Nmt8a+AVjU7nTfobI+t0FEs+fLVAtphVINWbTG 7XIsYKXA481YmOWsW0pdOackAR/wSfwEADPe1rwwp3/pOUkMgAIbgaaW5kGVOxmgcuxL +lhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491994; x=1781096794; 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=rW1WV99Hkic2EY+4V0AfPPFzJ+ncY9UKbR4cY6w6JcU=; b=oc3eMMGZ2K8HicI9xwinpX5BehgiDKD5u9SPYU7foUMVV2pxYzyjD+2DvL2LX8RcIY hoGCP4CdsNe0JsdLX4Uj+9Rn7ApJH68mTIJtvpyVDnZMtdwlZtT9so7wEsHSGnAVq6XI 6AuIwo9g6M7SEyPkmvwnQKv87obuz12LYTxMhrbSWL8JXeUVmWuKQ65/IYb8mQ8+FlmC leGi1pArztaJx97ORVclRcRHolcQukQ8DIMroLOOpMhG9YdYIBns3XWjD4S7BWo0krrX IA9zlUacVlgExj/JeCPl6iNKIBUMp6FfSyTkXgYaBU6roiSrPymMXIy4aMmGtbvdsBvy BLHA== X-Gm-Message-State: AOJu0YxFQCw6lK73kjH01yJD2CotpMSTh8TJGJSaZxV4UUPRBaDeh1BK rP51dL8B6A+8wKGcpaxUozHGMupP2D5w8E2UfH5EhqGUf3pTBfohUdYpuQcGjkWe X-Gm-Gg: Acq92OF/fpa7Tejv5DM0BNuneMajkEAW39mjpTOGTkgnIU7oFoAcCCa4pNj4tQVZoeF Ni6CMKCsy9jhWf+5msoX6TUdyjnyHn6QFVFaW9pfaN3t5yYUF8q11y1fn79Vn8M6eLmfYWk7FHw EjrMF+QUhNPTfN4wSTHVPkbBEcj7FusmVsMa+YQqfRZ4DUB8T1SeiaGtZvGMcAx9+CTJUSXUkKW To29mY6jQY0MAoop2L9OLq4gw4tJRC1lHUiMEoAzAg6tlOotCXSLLj80Rfi3CfkVYKuvf+pjyQx KLPUYvaAlas9X1b8GfnmB5Rw7ArYXNuy/OIcwmKtCJwb4//pHEwmpZe/6+cRdrwBLdpiFNm5yuK emyZyW0NzR7iXKaDMfnGZ3wkLQyTo2dZaq0RxJttedCuoom6yZ5JRX4+xmlaQ9Z0I29FeeeQBar FsVe0O5lhnO0jNe8+o5weNWAYvjCBtfcPph3WJIDv36QtP86IvRrhM7vTktVhZO74rTQqmx3BIf FxiOseyJL6L1Xv9/WwDXd7FC9jc714sBp1q X-Received: by 2002:a05:6000:41e6:b0:45e:739b:3e43 with SMTP id ffacd0b85a97d-46021808437mr4787756f8f.0.1780491993808; Wed, 03 Jun 2026 06:06:33 -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 v4 15/16] libs/guest: finalize PoC Date: Wed, 3 Jun 2026 14:06:02 +0100 Message-ID: <20260603130603.776452-16-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1780491994-F4E78CF5-98893108/0/0 X-purgate-type: clean X-purgate-size: 10902 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492017023158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio 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 | 48 +++++++++++++++--- tools/libs/guest/xg_sr_save.c | 83 +++++++++++++++++++++----------- 3 files changed, 100 insertions(+), 35 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 0e0e279ae1..cd562f028a 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]; - int errors[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]; @@ -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 b589f0397d..b2df36c6f6 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -257,15 +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 @@ -309,17 +309,37 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, } if ( !ctx->restore.verify ) { - rc =3D xg_foreignmemory_copy_to(xch, ctx->domid, nr_pages, mfns, p= age_data); + rc =3D xg_foreignmemory_copy_to(xch, ctx->domid, nr_pages, mfns, s= ource); 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; @@ -709,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 ) { @@ -757,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); @@ -765,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 ae61f97a47..514ca4be63 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; @@ -109,8 +109,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); @@ -166,18 +164,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; @@ -188,6 +222,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.54.0 From nobody Mon Jun 8 07:24:34 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=1780492031; cv=none; d=zohomail.com; s=zohoarc; b=HotEbiXNuPlfM5wwDmuEavamZUr9Dssw++O64HjBneYLIgRYBRgHB44cIlq/cBraU3fCIx0ify3o4V0PpQGoqawozx8OyqMtvUWyB6wbg0rLeSffyK/NmTENaVHUDWd49S8h6qMuqDHAEZyfrtPVj7XtJiALqZJUm6w8fpY8J4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780492031; 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=IwEW/VMKmm9UVqRykzUd/eww6iX340aEt+2QQIC/NsI=; b=J+NIxi3q2ZXyXfTB9KTFSfEXiz+trxokU7yG9uW+TE4XE9z60zYgEz2xnlzudTNplBrn1TI+mV/h00RX433+Jv7I74VHO4Ce2GQY72Yej8fepd2LVANE/L6tWcQ3JF4C4JLp5pxwXSl/FRpQctGdS86RGa2D0v+YkULz8IFJI44= 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 1780492031973859.0464505906554; Wed, 3 Jun 2026 06:07:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1326247.1591782 (Exim 4.92) (envelope-from ) id 1wUlIt-0000aL-SU; Wed, 03 Jun 2026 13:06:39 +0000 Received: by outflank-mailman (output) from mailman id 1326247.1591782; Wed, 03 Jun 2026 13:06:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIt-0000X2-1c; Wed, 03 Jun 2026 13:06:39 +0000 Received: by outflank-mailman (input) for mailman id 1326247; Wed, 03 Jun 2026 13:06:36 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wUlIq-0008Ok-GR for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 13:06:36 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wUlIp-006lUv-T9 for xen-devel@lists.xenproject.org; Wed, 03 Jun 2026 15:06:35 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2026d4-5cb7-0a2a0a5109dd-0a2a4507892e-46 for ; Wed, 03 Jun 2026 15:06:35 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2026db-229c-0a2a45070019-d155dd2ea5a9-3 for ; Wed, 03 Jun 2026 15:06:35 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4600cbb06deso435021f8f.1 for ; Wed, 03 Jun 2026 06:06:35 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4601f2ec711sm7254825f8f.12.2026.06.03.06.06.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 06:06:34 -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=1780491995; x=1781096795; 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=IwEW/VMKmm9UVqRykzUd/eww6iX340aEt+2QQIC/NsI=; b=rnmrL8LSOdnFSUD53twbT3zQUc9Q1d0nIhlhJzw67U4BB8VBtVGtBmLne+xiLL4v+i 0MRKr0xpN3+46B29fyU9d1FC7WQDQhQ7Zm0Ubx8FmpJbHt/RvW4pJiKWWddxdEma3N+v TZdnnY6TxWZMDGJExsb9AebxdDpRXrc9KRSk2W/32C7SYYOSY4y952Pi260Vrv6LeVpd 1JB5Jn8cg8XR1zGsUoH2okB2TbKrdbtA3Gk1jEiYtq+xifOKHxm/HxPov94sAByz3jdz SACQXl14+v039AHS7pl59VDxodWlNA7YNHh9fufIWKgNpuy7CKLx1KriMkSawA54roMg a9zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780491995; x=1781096795; 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=IwEW/VMKmm9UVqRykzUd/eww6iX340aEt+2QQIC/NsI=; b=LwZY+RfeQlZWNJYHLVf1FCqWI0cb/bbIm1j4HV2Dwr3ryAmNU9Od+i/i++GnFplpy/ xnPlJyc+FT2aUT1hK7w+2Xqx575QNEB5pdYbKXWoLX8WSsGlLerTAsIIEbVGOijptbrx nlQouInhmeRpvCaP82SM9fGAN+vbi4hbptuv8iLUJfioSEUnj5ac0SkotNzxOIoc6Kbh cuiidQdod56Rj4EKPJxtB6TlMBtxmMcFkLGgNinv/HLUaevb3Y0G5lkpMj4G0A6BpcQd RyOqhdtNEtFbFOtAf4rqmlPYc0QioIH7KtzVA1S9k7r+ub87SuotwEPb+LnUl24DT0T3 DtIA== X-Gm-Message-State: AOJu0YwCN25UXAXO7DyrBfr6CXD2JWN7AZiWNQCiJPNpWru1qySwVS1R upDwoBK2NXheGa+tEGKJXt96rVExvxh+QUDA0956PwRor/dhjYViCFqASVsWBsLc X-Gm-Gg: Acq92OEH7WrPnmzOopCwzt1KxqpzBelRqP+ovZwAmOMubdRGJqDLNms1Vtg4tMRbtIz YbzbrAD5wJU0ZU9QGOeLJ36cD6/dm2S9H43Fu4315Tvcuc7mUGcrYc3xBlSMMNYAWt5csg9igG0 y5SUggFXnONRsEeR8Vyfl+vdR9tXdQ8SwxRELU5FZmIfiLwP74yBMLltHSPevToezqW4XQUPUzd UUfj41BpKVof/VMZ/DYoOlFIQQfiJ0b6A9nk3h0vmz7+55DO99rxuG4JQ2it+tb+MYZvV+ndCc9 57bIgCB8f+fQgIdDwsHXl1LV/33eG5uuicekybj9Oqo+Jsri+P9CFM2q5Erc59uDumDGtefXc/c u/v3TbFRIFWdqysIvPKQVofXmaa6FEBh8GITPTGuS7k/PhRzmz0ogXhw2GYe9z+aztX3fDpaN5f gJH3Q81seZMjCzz33+qmGKWuG+aGJUYZwLzym+RsuwRRKXzWoqg5InpQEsJzvXEvcZWnn7GPvPo 2zH2G7YwoIc3VGArRRRKLxfYApSOTtI6L+KPIaGE+/Z4Vo= X-Received: by 2002:a5d:524f:0:b0:452:bc74:b129 with SMTP id ffacd0b85a97d-46021346390mr3198279f8f.16.1780491994917; Wed, 03 Jun 2026 06:06:34 -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 v4 16/16] xen/privcmd: Add new ABI to allow copying foreign memory Date: Wed, 3 Jun 2026 14:06:03 +0100 Message-ID: <20260603130603.776452-17-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603130603.776452-1-frediano.ziglio@cloud.com> References: <20260603130603.776452-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1780491995-0B979C48-D518846D/0/0 X-purgate-type: clean X-purgate-size: 5352 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1780492033862154101 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio 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 --- arch/x86/include/asm/xen/interface.h | 1 + drivers/xen/privcmd.c | 51 ++++++++++++++++++++++++++++ include/uapi/xen/privcmd.h | 10 ++++++ include/xen/interface/memory.h | 37 ++++++++++++++++++++ 4 files changed, 99 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..4ae9138dd314 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -62,6 +62,10 @@ MODULE_LICENSE("GPL"); =20 #define PRIV_VMA_LOCKED ((void *)1) =20 +#ifndef UINT32_MAX +#define UINT32_MAX ((uint32_t)~0U) +#endif + static unsigned int privcmd_dm_op_max_num =3D 16; module_param_named(dm_op_max_nr_bufs, privcmd_dm_op_max_num, uint, 0644); MODULE_PARM_DESC(dm_op_max_nr_bufs, @@ -1522,6 +1526,49 @@ 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 UINT32_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; + xcopy.frame_list =3D (void *) copy.pfns; + xcopy.buffer =3D copy.buffer; + + ret =3D HYPERVISOR_memory_op(XENMEM_foreigncopy, &xcopy); + + /* copy values back in case of error */ + if (ret) { + copy.num =3D xcopy.nr_frames =3D copy.num; + 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 +1616,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..786d769ad4f8 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 \ + _IOC(_IOC_NONE, 'P', 11, sizeof(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