From nobody Thu Jul 23 22:26:19 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=1781387327; cv=none; d=zohomail.com; s=zohoarc; b=Y50XGQU3IYu355sfuZO8erLuhfc9MJWm17KQIHDpNJLrcWF1znvO5lZ/P+UpLipall5OlmbWaBHyWsih9+MfELfc0GONPMAu9/E3RNL/zuh8jdybCy2l4CPMONjoB4otCpOoGinQISmfg9TIQ9U4PCRLSHKaXGWJBSJyme3hnsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387327; 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=tveinKkdLcmjhqS/kzPOX7fy7Jx+F9+BOrd+vNDtpvg=; b=SOCazpjPfVOBj8NXEsnnH1vkFuCerPSNeaBpwKYG/8o1JKxsQLVj1EPSwB1TYTZDLG+GCVjaXhzCG/r9TpSTzcirPGRhSNfHqsfqJIn21qbSoDiUxvOYtbfI1ZyCiTnct0WD6xHmblMG4V1qY1dnngBEwmc6KdgiPiXihnfRmy4= 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 1781387327914309.83696252419213; Sat, 13 Jun 2026 14:48:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337553.1598828 (Exim 4.92) (envelope-from ) id 1wYWD7-0001Kn-Oy; Sat, 13 Jun 2026 21:48:13 +0000 Received: by outflank-mailman (output) from mailman id 1337553.1598828; Sat, 13 Jun 2026 21:48:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD7-0001Jb-LB; Sat, 13 Jun 2026 21:48:13 +0000 Received: by outflank-mailman (input) for mailman id 1337553; Sat, 13 Jun 2026 21:48:11 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD5-0001Bb-QO for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:11 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD3-00DVVl-Rp for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:09 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcf9c-2eae-0a2a0a5409dd-0a2a4507e990-32 for ; Sat, 13 Jun 2026 23:48:09 +0200 Received: from [209.85.128.52] (helo=mail-wm1-f52.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd019-229c-0a2a45070019-d1558034a55a-3 for ; Sat, 13 Jun 2026 23:48:09 +0200 Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-490b3e03939so16301755e9.1 for ; Sat, 13 Jun 2026 14:48:09 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:08 -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=1781387289; x=1781992089; 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=tveinKkdLcmjhqS/kzPOX7fy7Jx+F9+BOrd+vNDtpvg=; b=XrkGWS8BiIbjByWP/bNX8NsrFao1xU+Gw6bBX+QM9aepnX+zzIjLenK/9ctU4iiGH6 tGCb38u203o411r8Q/x+O1wosqxfHPMJC2yMIgYgXNzdCEXWfZsySvA0txDoqcIlXp+o 2wpmDwJW7Ay+jP5MSPu01GTWKY9zeXNCNXhxp5sUfw2+cUDe8XE9DJj09wnkvS27Lthe /+jWADoH7D3uY8e43AQ99m8KxxIQW/U86LktI77hxHfylHyPGVpFaEcaX5mXyb96QXKn e7QyZwsHGs7VZQiftMuqX1zizSTTmGSUsiCCPtBvaXd4ceXn3HzUY58brqrcUTkaHtb7 chuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387289; x=1781992089; 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=tveinKkdLcmjhqS/kzPOX7fy7Jx+F9+BOrd+vNDtpvg=; b=p/7K2ThCUi0ArC0mk6kXgmCncH1GsjbmaZog8fI1JngUiMSItQdOLQvqxk8Fd4RYfx gh+pZohdij3/WOOe8li3Rn7ImVbkN4wbYmH9dVv/lrSi7dOJCv169+gkJ4OZMi7xV3Tr yyAIsNprKWs2pRRSg5km5u9bSCZavETgSwi5M9k9bjHN/WK3BTyl+dr2dxoqTNxaKM8w geICQubiG1/DblrSIqfFBe7AYjAMO8rxEzk9/FlTDZx7HPWpm4yMBVYXJSMNxPD3ZF3p vQnu2mccDG8dGFrmtvph2w+2489GQn6HsL4SAG4EyvMB43JoKfUsQ3mD/NbsVM0MaukH TqFg== X-Gm-Message-State: AOJu0Ywxr6Q7SUUJUSp8lQX0iO6ceX9rrdKdqKfIHzNVyBPnSURySEiA 0JkcqQ/131nGSO1vLx1cUUL9xLnzUoD+E+n3ZdHgCCHLLBJCNZW+wrwHs6RfQdxcdJ4= X-Gm-Gg: Acq92OHu4l9IU+2WfqsGuwf+RfZ+wQyZuBDBxmRqN0pHJeYPnDJWwfmXCTdCdnhCktB +M3km5iztb4OjNb269HhNNIJduSoqcRrcEUzdN25CElqgbxh00Wuk80O4Oygs2FhLfb+2grVv03 vvq8NVmxVX/84BuIlNa2CkMQQEJN9gx+CGFI9eOLqfCm6uPZMQ0oBE3MYKAD1f5hYXYNJM7Xfr5 jDUvGZGr1Xi2nd35/YSA+tFC1kQeuMOIZQY7UM+0ec+6kz9da0YNwNRRl1U5h7xmp3fR0RoP8jt bFyocU3gEg53YwksrfjVw7NvOcTUwfnn5fuIswriBSNg6Oz63orBiy4h5Gwu03rwkziZuLvKt5C F8tOE5gDxQA45dCNB7+6Exwr9tRYROQ0sKeprSRcE2blDnoWV8w2+4KnS9HLOB7oHXEEntXY46g 7m635lnQiFXeud5Xo+9oYv2EYSUjwwYnOHAbt9F1yLDCs/Sb2QOu2eAgIRYlgOXxI1478tcpDcb CbMU0kTx78bPYMXQkdbAs6mIg== X-Received: by 2002:a05:600d:6451:20b0:490:e180:2e0 with SMTP id 5b1f17b1804b1-490ec481088mr62001335e9.3.1781387289119; Sat, 13 Jun 2026 14:48:09 -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 v5 01/16] libs/guest: Reduce number of parts in write_split_record Date: Sat, 13 Jun 2026 22:47:34 +0100 Message-ID: <20260613214749.20620-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1781387289-09D6FC48-AECF335D/0/0 X-purgate-type: clean X-purgate-size: 1879 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387329902158500 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 Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v3: - clarify commit message. Changes since v4: - added Reviewed-by; - improved commit message. --- tools/libs/guest/xg_sr_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index c7b3c6f3bc..9b2782b5cf 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -59,11 +59,11 @@ int write_split_record(struct xc_sr_context *ctx, struc= t xc_sr_record *rec, static const char zeroes[REC_ALIGN] =3D {}; =20 xc_interface *xch =3D ctx->xch; - typeof(rec->length) combined_length =3D rec->length + sz; + size_t combined_length =3D rec->length + sz; size_t record_length =3D ROUNDUP(combined_length, REC_ALIGN); + struct xc_sr_rhdr rhdr =3D { rec->type, combined_length }; struct iovec parts[] =3D { - { &rec->type, sizeof(rec->type) }, - { &combined_length, sizeof(combined_length) }, + { &rhdr, sizeof(rhdr) }, { rec->data, rec->length }, { buf, sz }, { (void *)zeroes, record_length - combined_length }, --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387330; cv=none; d=zohomail.com; s=zohoarc; b=c5EzoSvLOwfYgrgHbz9exqCwZi1iY7S1gcsWxYkHY1Yi7DNB9KyJRghcH/eH6XTRflogvnYmz053g0Qfs4oeJkO6ytPWwv35pj/gdyb78HCG3uv5BczPT4YjIr2N/0g1tUyBbNipmeOlrk0nzGrocokgXHcC60ecz7ewzsyfH0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387330; 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=eBOu2SGy5SEMj/LwC45bjJ4tbAJiMm9h5HCYGlaqv40=; b=d9oRjJ5UvC8jn90j3dxwr2nAHwtmzpJ1sax8+WsQkje1RZ7A5mA3Qv/MNrvVEC4AlUhoOCQ1v568LQcvpBFrEeCMY5SnWRX9ypn601TexpNPmtJcs83YodtkwJ58cta6OSamx9bDFol9hcslwwzqv+ucRi4rt20uzbE2CMMB4c8= 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 1781387330141643.2450964196838; Sat, 13 Jun 2026 14:48:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337551.1598818 (Exim 4.92) (envelope-from ) id 1wYWD7-0001CC-AT; Sat, 13 Jun 2026 21:48:13 +0000 Received: by outflank-mailman (output) from mailman id 1337551.1598818; Sat, 13 Jun 2026 21:48:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD7-0001C5-7h; Sat, 13 Jun 2026 21:48:13 +0000 Received: by outflank-mailman (input) for mailman id 1337551; Sat, 13 Jun 2026 21:48:11 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD5-0001Bc-QP for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:11 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD4-00DVVl-Cj for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:10 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcf9c-2eae-0a2a0a5409dd-0a2a4507e990-34 for ; Sat, 13 Jun 2026 23:48:10 +0200 Received: from [209.85.128.42] (helo=mail-wm1-f42.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd01a-229c-0a2a45070019-d155802ad0b6-3 for ; Sat, 13 Jun 2026 23:48:10 +0200 Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4903d730b1fso26447545e9.2 for ; Sat, 13 Jun 2026 14:48:10 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:09 -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=1781387290; x=1781992090; 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=eBOu2SGy5SEMj/LwC45bjJ4tbAJiMm9h5HCYGlaqv40=; b=AGOLf/ZLvAHsmFgXExBZ0B+cg3h3l2EUW4MVpS0Ylff0GYr4001WberXK+ybHsS81t 2AKW2trREj5/8qukzJW/HQfp5iw6RrukPIYofsuvyZ7dVYYccYMe3qMPBmxaXeD+W9o2 E4l4Ir4S5PY0yK3VgLVkdYmxumBrJHOUdRdjuoHWwESjCHuXK76kmEjqmg707KWxW+mc m4CqyFvjSOuJPMVISTCfjDSo0YTgipejOQuaT1BAsfu5JqMQjY0SV3cxdr5H3JlMXP4/ 0ZnUNP4DXYSXbGGnJhqVNK1xzUaCNpdH0DpZyoFKADuXdiCiq+qWqAJeaHEvqXUQvQ4Z bTmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387290; x=1781992090; 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=eBOu2SGy5SEMj/LwC45bjJ4tbAJiMm9h5HCYGlaqv40=; b=Y8pY8fHB2IMszSy2WpnalvsvmdwSO0laloqJcAGwdTyMU/tgDwP0Fi/ueBzqcmJUIb NxWDDvlGrZqX0+sAnoZkXNYyBHAk0I2Mi2yr+2M22yPFZd7bkWtK2xm0d4XafK2hQysV PhCfxsnxM7XdVluIK9lI9zoZbVtMExFEKQW9csiws0X+K/hms2sAfYwweBgiOCDc4JNA 1rwoDLOfRLyNK7JheDref68bML4deX0fB44xuz6EdO+3RKUxp8IapQ4PZOc60npnaEd6 gipi4YGqddPFYj7/qs+uwrlqThhTmJnp/NlV1iRgI/W4EvpCVwePQSOSEo28aHRnpEbM +37g== X-Gm-Message-State: AOJu0YyyvxPY9Bf9U4R0mGVoEdXSa5sENl4CKOXGmYkkznIlo6SdHv7M Rif2rZUjsZCXDGtcdZqQ5x2DrnlVhkAp82sEi6xfxvHoib8z/SMMD9ClJh45ZFXWRd0= X-Gm-Gg: Acq92OH74X1HKB+UT8Wsiybpp3OpdUGlBi/e7ST5F8LdMGnGMcJ5liwBWN3ZxVvPuaW sHVi7rg3AsYcpfPUAuUEAgtOWHkB6ZzdXICHdXb+8x1utoEQfmrFWFw7o/3yblObAqsr5c+upJ7 1ABEZ7iT5Io/d/r7eUJ9eHFICRCj95gZE7J4LCRoqLnNuQ19i97DaJvZsREmI+zjEdhg0Pes/R7 EfkaCWsaLMagEEOu/ms4jLr+EZzYpmfPl8w6Jk2DuLzREoYm6Dnh05oVB8Up9k7s6LN7ZDfICZj ZOijKZ7MVw554eMQhUKLsjT6jB6JTlU1hNQMitnvCx4RzGw6cMPFM3MAgUQn4cJbbWkgz55Dmx0 hGX9PqyAk/Xvr9zqNnFa3Pgvrhr2fp/Ldl6sFzYy1cDLY4MHayjiPvt7ae5ZB0GTfP/PWIRjg02 nwQXs4ABZqANw7BcTsu6jKOJw1pGUllsi99+zso/Me0tiq/KLevS/jBzfxOqw7YXCSHkyM7z/W+ nmtqhKC+z0A2I7c8LJoV4fXFQ== X-Received: by 2002:a05:600c:695:b0:490:bd1d:4732 with SMTP id 5b1f17b1804b1-492200dcaebmr34522575e9.23.1781387289825; Sat, 13 Jun 2026 14:48:09 -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 v5 02/16] libs/guest: Reduce number of I/O vectors in write_batch Date: Sat, 13 Jun 2026 22:47:35 +0100 Message-ID: <20260613214749.20620-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1781387290-2216DC48-B05047EE/0/0 X-purgate-type: clean X-purgate-size: 2700 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387331927158500 From: Frediano Ziglio Small optimization. Reduce number of pieces passed to writev. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v4: - added Reviewed-by. --- tools/libs/guest/xg_sr_save.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index fdbceab52e..68ce1aeb98 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -97,9 +97,11 @@ static int write_batch(struct xc_sr_context *ctx) void *page, *orig_page; uint64_t *rec_pfns =3D NULL; struct iovec *iov =3D NULL; int iovcnt =3D 0; - struct xc_sr_rec_page_data_header hdr =3D { 0 }; - struct xc_sr_record rec =3D { - .type =3D REC_TYPE_PAGE_DATA, + struct { + struct xc_sr_rhdr rec; + struct xc_sr_rec_page_data_header page_data; + } hdrs =3D { + { .type =3D REC_TYPE_PAGE_DATA }, }; =20 assert(nr_pfns !=3D 0); @@ -115,7 +117,7 @@ static int write_batch(struct xc_sr_context *ctx) /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); + iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); =20 if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) { @@ -216,28 +218,22 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } =20 - hdr.count =3D nr_pfns; + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + hdrs.rec.length +=3D nr_pages * PAGE_SIZE; =20 - rec.length =3D sizeof(hdr); - rec.length +=3D nr_pfns * sizeof(*rec_pfns); - rec.length +=3D nr_pages * PAGE_SIZE; + hdrs.page_data.count =3D nr_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; =20 - iov[0].iov_base =3D &rec.type; - iov[0].iov_len =3D sizeof(rec.type); + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); =20 - iov[1].iov_base =3D &rec.length; - iov[1].iov_len =3D sizeof(rec.length); + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); =20 - iov[2].iov_base =3D &hdr; - iov[2].iov_len =3D sizeof(hdr); - - iov[3].iov_base =3D rec_pfns; - iov[3].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 4; + iovcnt =3D 2; =20 if ( nr_pages ) { --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387337; cv=none; d=zohomail.com; s=zohoarc; b=DKzKcGcbd9rSz3LCcqeq4t6g55wRV33s4tMA27jZYTUH9JiCr6Hr3JjohrDNLvcKlSZ2itNqLsuiWmFqvDjtmnRn7gOeG5qAldaGY0/kJ/jzlex/3ij6ZXpu5eHIjI2727vaa6jlChZgVn1AkRc7pvKJeMU1CZEvSamKmIMOGy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387337; 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=U0X1FdY41+Cjrz6QWLlOKKWLZuKlvYQpTdBJUqPk0yo=; b=RizqTIYdvms7eHc9y7+yk/MAICCIsU7SQaBR/Tws7Ks6LaTRW5ozJOVZwkYs0gDVoG4YXaaUUQGqjRV65GobS+wXxODQl86VdUAmg7lpydY22kcDB8YjUZy9DXpM4y2ZO/arBgpfY8zS0T9VRS/NNS0FNxwqLLBr6x4ZSDyznrE= 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 1781387337799111.45445532620886; Sat, 13 Jun 2026 14:48:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337554.1598838 (Exim 4.92) (envelope-from ) id 1wYWD8-0001Sn-8g; Sat, 13 Jun 2026 21:48:14 +0000 Received: by outflank-mailman (output) from mailman id 1337554.1598838; Sat, 13 Jun 2026 21:48:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD7-0001Rl-VU; Sat, 13 Jun 2026 21:48:13 +0000 Received: by outflank-mailman (input) for mailman id 1337554; Sat, 13 Jun 2026 21:48:12 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD6-0001Bd-1p for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:12 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD5-00DVVl-F2 for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:11 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcf4e-2eae-0a2a0a5409dd-0a2a4506b662-28 for ; Sat, 13 Jun 2026 23:48:11 +0200 Received: from [209.85.128.53] (helo=mail-wm1-f53.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd01b-7371-0a2a45060019-d1558035e9ae-3 for ; Sat, 13 Jun 2026 23:48:11 +0200 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-490aebf33e9so9222165e9.3 for ; Sat, 13 Jun 2026 14:48:11 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:10 -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=1781387291; x=1781992091; 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=U0X1FdY41+Cjrz6QWLlOKKWLZuKlvYQpTdBJUqPk0yo=; b=sgezM7xDgbMt2nAmE2xrL89o/8xjVPvAxSj14nymZf9HEZ1ejks7AjEED95SNKY2EM Em/Gql+fMLz0at3Atj5TFDyfAkB9liYt0RzKWYjtC6fwZyGIIMJzi+N0xcI+F6OFr3Yl xEoSotwFDr4TzS6IC6yn/jkzsG1pa7am+brMIjgNv77lzESm/Nx9F+9ufXw6HGr8sH6/ fMDFUwRnCXh0OmQeim92V0nz3VC28P7G/ECj2ayrPnraZ8CAGUvL56rxxmBGUYYmWcnw 7JxFvuQGyx/qsxS/cWb4y2lFhYu9eSj8onueNAqzQprKeF2mc7wdvWPLdiRg2JoJqM9s DxEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387291; x=1781992091; 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=U0X1FdY41+Cjrz6QWLlOKKWLZuKlvYQpTdBJUqPk0yo=; b=rBAlYUPmh1g4fUeXaworPqSmsuK+TxcLKK9iQaufQPl3WGuGX9DHkSHKxb/Zl99hly 8P+Dmub7yyVtK+1Jji0ji5e0z7dxAFxiiGxR9iipNE9O0ax3kmHyuCSsTBHjbhQAF3PP QbnjJtGDyPI4IMQ7JmNtySz97tNW4H9IJv0NRjuJTtWrK8yq8Z7XRPzj5yLK15hec8HO XXNCwyrXRCNHTxGHloWxDOYFlwg6H0YM9YSeJ5AcBXOmRratHUIW3ZyVSiJz6tDTl4xQ iJ8Gri7xf6LGu0jb4LXGbrFRbj8ZeFM3SJzAe5a9gAFVjJT4RHTGMCF99mbx4Ezz3/+e QqSA== X-Gm-Message-State: AOJu0YxnJonZs5HbZcR8qBPsjubK6+xXNh4EJ2paxA4QdiQ0kzaEXqKC DZ47Tq8hJrmrWdPMDdMoWWudfvDt0WRIRRugYUn8H9EOCH0uyJLYRVYqc6zva5IW9Sg= X-Gm-Gg: Acq92OH8OmOUTIyOhsftNFYTrs4nCfAdADkQj+2Whh8acs+IvIWF+AXAbfjxj2EhisO /Iz2sKxYU6QNQIjtz96wbH166mhYGdvjvL2Ps6FVppxs38p1DBbVoyM8g8xeAgNjiMO+gtJxbFn NZdpsy8cPHFMdOjGUwP5evMprNz51ZyIu2Ng/19+GWpe4JjznB3MOn3oGiiavKezmq5B9GRigBf Wp4we/dwV5KJ3Dtz4P3/eBkO6+AWRqLpCyCen+NzHq4GNgASLHeauaxf5uotOG9as52XWUF3kFl 1bdVpnzoi85whcfz98I3/aJWNW6f8KB9WWf+moHrj/O4r1/O2ltXZMcIYxKC5Q8Qam2h9VCfwCB Ny9NOAK+VMo0XDXWLxT+gFvMvlHgM8TazjRbkeMeImmC9F5HMvDvAy2cORiuwCG9DYFHAwg4hBi 00gumbmg/sIRPwW8gomNbLThTF99TVJKy1133QL0sN1kQZSpIZdNSYUDB5gZDfIu0kmJgZpMjt9 9ufslWPStwtuS7qVjMIqroeqQ== X-Received: by 2002:a05:600c:4595:b0:48f:d5b8:5b07 with SMTP id 5b1f17b1804b1-490ec4fb683mr105962455e9.20.1781387290817; Sat, 13 Jun 2026 14:48:10 -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 v5 03/16] libs/guest: Reduce number of I/O vectors in write_batch Date: Sat, 13 Jun 2026 22:47:36 +0100 Message-ID: <20260613214749.20620-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-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-16d1c6/1781387291-8EB8BD75-75A58380/0/0 X-purgate-type: clean X-purgate-size: 1609 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387337929158500 From: Frediano Ziglio Each page was sent using a different iovec item. This potentially exceed Linux maximum (1024). Coalesce adjacent IO vector elements to attempt to reduce the number of overall IO vectors for each operation. Also some implementation (MiniOS) emulate writev with multiple write calls. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v4: - added Reviewed-by; - improved commit message; - minor style fix. --- tools/libs/guest/xg_sr_save.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 68ce1aeb98..eba33f861a 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -239,13 +239,21 @@ static int write_batch(struct xc_sr_context *ctx) { for ( i =3D 0; i < nr_pfns; ++i ) { - if ( guest_data[i] ) + if ( !guest_data[i] ) + continue; + + if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len !=3D + guest_data[i] ) { iov[iovcnt].iov_base =3D guest_data[i]; iov[iovcnt].iov_len =3D PAGE_SIZE; iovcnt++; - --nr_pages; } + else + { + iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; + } + --nr_pages; } } =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387322; cv=none; d=zohomail.com; s=zohoarc; b=Mizi5dPxHTh18LaCH62gpUQAJsxsAGu3NsA/F60rVHBfLsIjsdfoHoVjU3H04fz39QzFC2MmrD/E1EXT5Scg9w16Uxlu6XkusRMDcA+VmZw4a6SUUWURLXFUcuQ6fURvhfIIjPX9kACd6y4eMhJjUohksxJp1SO2qyeqW8fbwf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387322; 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=D4nbEc3Hba3N2KI3dfDDijdsISWgf8o8baaY4LyLZGQ=; b=jPF812yQH+n4+kDcL++fcubZUGeT90WXm2CkurbqFEcSb3BfTN/QlFSrFOAb3CLhZdnb+HiAFxkLqLQ8BUoz1WTQ5jWrADjQ5f/0wWWrJFVqteWybr7+qQMrwQcOwSLdknr8Z7nvmeKL8zUyFJgKATYRda9AXa7bZYjBjhzGKyc= 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 1781387322705451.32338536317275; Sat, 13 Jun 2026 14:48:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337555.1598842 (Exim 4.92) (envelope-from ) id 1wYWD8-0001Vb-F6; Sat, 13 Jun 2026 21:48:14 +0000 Received: by outflank-mailman (output) from mailman id 1337555.1598842; Sat, 13 Jun 2026 21:48:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD8-0001UA-7r; Sat, 13 Jun 2026 21:48:14 +0000 Received: by outflank-mailman (input) for mailman id 1337555; Sat, 13 Jun 2026 21:48:12 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD6-0001By-R5 for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:12 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD6-008PGn-8A for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:12 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dd008-5cb7-0a2a0a5109dd-0a2a4503cafc-6 for ; Sat, 13 Jun 2026 23:48:12 +0200 Received: from [209.85.128.54] (helo=mail-wm1-f54.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd01c-672d-0a2a45030019-d1558036c0a3-3 for ; Sat, 13 Jun 2026 23:48:12 +0200 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490c1915793so17459295e9.2 for ; Sat, 13 Jun 2026 14:48:12 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:11 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781387292; x=1781992092; 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=D4nbEc3Hba3N2KI3dfDDijdsISWgf8o8baaY4LyLZGQ=; b=TKYyiPfEpiOm1eXe2WqqNcTigQxahHZW5RUxQZC7S6C1E0LPVmUn7ILQ+lZaAFhhTM Xq/lYPY2xxRO2GVYZDSlR5+aIy3rbjVlxawcSs66X0/jU2HxCmCGK8TiaccSL320jTV3 QjRzGMRazvHVUyPQD41G+HBRrlZOVIb/cHxnfYNc/LrUPn7rW3q+GQvPujgu1ord8Bbv Nh5MvHYrBQSnDD4tOE5MEV0E7wL7DSKos3OtoWL3pFewREYprE5tgLIZYylsorSGU0X3 YLhmOFbheW6+99OxJIfqkGO4Mffrb0xOK9hmPslXbTNWaMh2a1IOV1TiX2sK3gMgqCe7 Ck/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387292; x=1781992092; 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=D4nbEc3Hba3N2KI3dfDDijdsISWgf8o8baaY4LyLZGQ=; b=CR/LllSrXC2RhOqO9iiR3f8KBaQKj7db4uPes6az2RXnTSPW2xNH4jS8jz5MhVVgEl khT0nzaRVvSzvGetq+vPhoavTxpNjSYXawzjcE0cOrnlKuExb5HLsM5RT+KX80KeVytg rWIWoIlJpSCeAbbIrzCVmN1Y8ZWG4U0iDzErK8LNHyx+8jEpL61q9Mvk0RfmBuMsvdbL 8SvFSpzfgdLcA9pNv9ostsI+JgSkdW1jjTfQDAa1toJeusqGg+liRpR2VAwFzm2UYOJe qBuBXR93b34ZyJ2vAb5pnK4HOMXKq/iXxNsH4lWvtW/Jvjf/V/rorjcK4RAKrQxUK4Ok DVsQ== X-Gm-Message-State: AOJu0YxwydD7i/r/uFbPCyTzoqgUw0p3il7/ZUkYcQiCRu5ExCr8Y1TP MmTefZlgfBjIZx+WIiJBoVg/7OgcLeCoGQEzmL8gNYb/3D3/gC8KvAIH+nIIIzEHsE4= X-Gm-Gg: Acq92OEp5r4i3siKypzU/5F33jC6ftsQ5XOKi3eSx+a9P+QWJSPTQDKMVnoEzMxpCs4 v4p9yEHzgLFFLQAuJIaWgAjBvvrXR+sfr3tSUZXUmHPo61hUX0/3/Lx3jLeQ/SDxtlA0enHLy8v bvWF2ulIdqf4+FX8L2fy/vSQknCYFmfCuyUlZJh5A1O5R8gva9e1yuhZ1v46ptbUXilfcPRHALI eM19oKyQ0sEh09O3PPs3twwCTeBBRG4TATxzp0HwOMjjX4RCFK+3g2202toswD+UoNiX2HXt0wg QY9Jv5VLzB+RE6UmtsFCaQHHw7qDzh6v81P3vDwTCWDPCbE2ODNRNsGNuFvaNb0ml+KCGHJdxFa Jy8vbUbRQdXO9ogf6lAeHnzYrRWUBIhfuz/ZTH3j6cL8puh48LwA9mI1RcrvZN67J2umuD7eF8q y5uvPaFBMkqFeKjRncicJOodHPTahSrQuATXxYzuupY4I7wzmeRPDMxKixvp0vTPtxVaUZlUuca DvySXK378U1NaF0HyoTMgjetQ== X-Received: by 2002:a05:600c:3585:b0:490:b642:ce29 with SMTP id 5b1f17b1804b1-490ec4d4f71mr110120395e9.8.1781387291641; Sat, 13 Jun 2026 14:48:11 -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 v5 04/16] libs/guest: Use a single write_exact in write_headers Date: Sat, 13 Jun 2026 22:47:37 +0100 Message-ID: <20260613214749.20620-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-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-33051d/1781387292-40E68938-4E91282B/0/0 X-purgate-type: clean X-purgate-size: 2454 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387324204158500 From: Frediano Ziglio Reduce number of syscalls by coalescing the image and the domain headers into a single I/O vector array. Signed-off-by: Frediano Ziglio Reviewed-by: Roger Pau Monn=C3=A9 -- Changes since v2: - change prefix in subject. Changes since v4: - added Reviewed-by; - improved commit message. --- tools/libs/guest/xg_sr_save.c | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index eba33f861a..8c31f9f86c 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -10,17 +10,22 @@ static int write_headers(struct xc_sr_context *ctx, uin= t16_t guest_type) { xc_interface *xch =3D ctx->xch; int32_t xen_version =3D xc_version(xch, XENVER_version, NULL); - struct xc_sr_ihdr ihdr =3D { - .marker =3D IHDR_MARKER, - .id =3D htonl(IHDR_ID), - .version =3D htonl(3), - .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), - }; - struct xc_sr_dhdr dhdr =3D { - .type =3D guest_type, - .page_shift =3D XC_PAGE_SHIFT, - .xen_major =3D (xen_version >> 16) & 0xffff, - .xen_minor =3D (xen_version) & 0xffff, + struct { + struct xc_sr_ihdr ihdr; + struct xc_sr_dhdr dhdr; + } hdrs =3D { + { + .marker =3D IHDR_MARKER, + .id =3D htonl(IHDR_ID), + .version =3D htonl(3), + .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), + }, + { + .type =3D guest_type, + .page_shift =3D XC_PAGE_SHIFT, + .xen_major =3D (xen_version >> 16) & 0xffff, + .xen_minor =3D (xen_version) & 0xffff, + }, }; =20 if ( xen_version < 0 ) @@ -29,15 +34,9 @@ static int write_headers(struct xc_sr_context *ctx, uint= 16_t guest_type) return -1; } =20 - if ( write_exact(ctx->fd, &ihdr, sizeof(ihdr)) ) - { - PERROR("Unable to write Image Header to stream"); - return -1; - } - - if ( write_exact(ctx->fd, &dhdr, sizeof(dhdr)) ) + if ( write_exact(ctx->fd, &hdrs, sizeof(hdrs)) ) { - PERROR("Unable to write Domain Header to stream"); + PERROR("Unable to write Headers to stream"); return -1; } =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387347; cv=none; d=zohomail.com; s=zohoarc; b=c/Sg4ddJMgDXqeCIyGkHA7bnrXvwalQCBDzgWWMx4KLY9QyNOSg5GIlbNVwTXPLpY8FJt+cs9i/yZpttyzYLGt1M7er7/rJJIJ+O9wOaF3ILvk+X9oEjKSlNT5N7kKqvkuT/Ugjks1cJMCHfvqVrkDiPVozHs5xbNS2g3by4jlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387347; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aDpOdhu2pX3r4tDQzsxVRLFNGhGBpjSsL2fSh51Ah0k=; b=I9V9aGx+8+0sqcllxqm1AiMYyDHWidHlZZzAUhG+58hgqOkB86k7C8SMgLLSWH+LgJJ52gAcEFQwpUeF9+byzxUVOF01PeHVObehBjmrvSTaGHrtqyzaFcUMYJeFtLjfR5/vPTObqVIRKL7tFZTXo2apafDRh2n0FB53wXBS9j0= 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 1781387347375856.627618625946; Sat, 13 Jun 2026 14:49:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337556.1598864 (Exim 4.92) (envelope-from ) id 1wYWD9-0002Df-Nj; Sat, 13 Jun 2026 21:48:15 +0000 Received: by outflank-mailman (output) from mailman id 1337556.1598864; Sat, 13 Jun 2026 21:48:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD9-0002Ck-K3; Sat, 13 Jun 2026 21:48:15 +0000 Received: by outflank-mailman (input) for mailman id 1337556; Sat, 13 Jun 2026 21:48:13 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD7-0001F7-N6 for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:13 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD7-00DVVl-3I for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:13 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcf18-2eae-0a2a0a5409dd-0a2a450bc4b2-28 for ; Sat, 13 Jun 2026 23:48:13 +0200 Received: from [209.85.128.43] (helo=mail-wm1-f43.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd01c-212f-0a2a450b0019-d155802ba569-3 for ; Sat, 13 Jun 2026 23:48:13 +0200 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-490b3e03939so16301845e9.1 for ; Sat, 13 Jun 2026 14:48:13 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:12 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781387292; x=1781992092; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aDpOdhu2pX3r4tDQzsxVRLFNGhGBpjSsL2fSh51Ah0k=; b=XK54b7VKjEMIbTH28aN8AuBcp2Y0NKIMry5JrJ2oQvFGwQ/5Yi+g/fbuOnWmfO3Yo7 P3KOOpXL+36LHzgrmLivPdVvJJvhoSb81B52UozAwsVFaneUlynnCCBvJrsLeoG5GxWs usC2CTsjHPYDrfazfUAW3bJSbL/aoDWNMbw/HhrYKyUA5JA15ByUnfyTvyZbUdTyz3U+ U4aKqjnQXU9SHn33aJgQSbx5GYIRmCYNsAsmWX3jHlpShCYVW/kPuTiEgvyLc/t1rstq Bvni69xVNlD6SrFoTC6Fj68W+iq/XpSZpbxW0gXjqmSQSzKmnLOySYKatxhnEfwbARzx aaig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387292; x=1781992092; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aDpOdhu2pX3r4tDQzsxVRLFNGhGBpjSsL2fSh51Ah0k=; b=BYRVprisdZgo+Ut0ovjxukA5ZvQJ478Zo20v5NYT3KAp9OAN0ITwc9cZS2VUK01I/B PQjzdfnpKuMtyxb9Owl+HETvOFdt+7hUc1ohm6wIDUJagz2coQfTLOYNIbIlyVMjLU5r OYY1wFb+murzAC+++auBqoo+g2ZEErrYzvdWCXB/knBcqVFAQSRKNtdqXM11Dd35nFUa KU+uUwj6QIwK/Q99TgLrxaa/YWELM+Q8dXTQWpGtWQGOT1ZeJBxZjEezFQdssOvEwSBg ZpjccZaDFE63C4geo7y6PtGS8nTeqCr/ulNw5H6BW5AQv4pDSxJLCfBsdxlDQmK9EgXt JLRw== X-Gm-Message-State: AOJu0Yxsxw6z6kx7PrhR0FLzg2KWSrRaIUTwDLE1cXPccPqrYC/SN2Hw A+ipgYSCr8MlID58LMjYEJKi9MWiNaUmK9C55o6KFnhUE92JSi3B3WCJFah6lOhwK+8= X-Gm-Gg: Acq92OErA8rAZlIlb7m1aaRM7kBVc0VYaUTeZxIFd0/+7xrBrkOAYbG4nm/vQUPHu/l mFu4FmRDFQc2PtMdUJAd/RSb2FigqvS0Yv/LBAf6nis8im6pUx954IGFhFAN9ZJmOkkEWrqKJRo VpbF/L1YNyz6R7y2qF4VUzizF2lI0+iMMa/E9/F+1ePGD133fpmWQ3yfJAGvLL2vQL79ljR+D5w r9GKUeuRNjxn+Pa7QoFHl9TUkoDlgG1o/zHwplsHsiS27Tj9mqUCNa8vQSp8rzCEw0ip8q/V6Fh Xz40NR5J7MHbvGaa6gIsayuDkY9/+nYFI5tEow1oaclqOmaMQbkwB+vkf54KR1pFFDC7lxbh0/P 5r68XWMImX4F0HE3NwQOM4RnW1xjU6XF+/Z+jlz077plWeBSWjRiXwNeQYbgzYQnCwmZKardwk7 BHqXKuSNgPK9odHRs34HHpVResHVKOtetfyP3Dd2H+Elqdu3BO0k1UqfVNrRN/k9CVfzrtrKRg3 m98tFqyEZu2rNYrNwLFbl+sWA== X-Received: by 2002:a05:600c:698c:b0:48f:e230:29f5 with SMTP id 5b1f17b1804b1-490ec4e9147mr79639675e9.16.1781387292459; Sat, 13 Jun 2026 14:48:12 -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 v5 05/16] libs/guest: allocate various migration arrays just once Date: Sat, 13 Jun 2026 22:47:38 +0100 Message-ID: <20260613214749.20620-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-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-42698a/1781387293-1A36CF3B-6CE8E2E1/0/0 X-purgate-type: clean X-purgate-size: 6557 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387348251158500 From: Edwin T=C3=B6r=C3=B6k Allocate these array just once at the start of migration, using the maximum batch size, and free them at the end. Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. Changes since v3: - fix comment style Changes since v4: - change order of fields in structure. --- tools/libs/guest/xg_sr_common.h | 13 +++++++ tools/libs/guest/xg_sr_save.c | 66 +++++++++++++-------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index f1573aefcb..95b0564e5c 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -209,6 +209,18 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct xc_sr_context_save_buffers +{ + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; + xen_pfn_t mfns[MAX_BATCH_SIZE]; + xen_pfn_t types[MAX_BATCH_SIZE]; + void *guest_data[MAX_BATCH_SIZE]; + void *local_pages[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */ + uint64_t rec_pfns[MAX_BATCH_SIZE]; + int errors[MAX_BATCH_SIZE]; +}; + struct xc_sr_context { xc_interface *xch; @@ -244,6 +256,7 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct xc_sr_context_save_buffers *buffers; } save; =20 struct /* Restore data. */ diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 8c31f9f86c..4988d8040b 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -86,16 +86,16 @@ static int write_checkpoint_record(struct xc_sr_context= *ctx) static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D NULL, *types =3D NULL; + xen_pfn_t *mfns, *types; void *guest_mapping =3D NULL; - void **guest_data =3D NULL; - void **local_pages =3D NULL; - int *errors =3D NULL, rc =3D -1; + void **guest_data; + void **local_pages; + int *errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; void *page, *orig_page; - uint64_t *rec_pfns =3D NULL; - struct iovec *iov =3D NULL; int iovcnt =3D 0; + uint64_t *rec_pfns; + struct iovec *iov; int iovcnt =3D 0; struct { struct xc_sr_rhdr rec; struct xc_sr_rec_page_data_header page_data; @@ -104,26 +104,24 @@ static int write_batch(struct xc_sr_context *ctx) }; =20 assert(nr_pfns !=3D 0); + assert(nr_pfns <=3D MAX_BATCH_SIZE); + assert(ctx->save.buffers); =20 /* Mfns of the batch pfns. */ - mfns =3D malloc(nr_pfns * sizeof(*mfns)); + mfns =3D ctx->save.buffers->mfns; /* Types of the batch pfns. */ - types =3D malloc(nr_pfns * sizeof(*types)); + types =3D ctx->save.buffers->types; /* Errors from attempting to map the gfns. */ - errors =3D malloc(nr_pfns * sizeof(*errors)); + errors =3D ctx->save.buffers->errors; /* Pointers to page data to send. Mapped gfns or local allocations. */ - guest_data =3D calloc(nr_pfns, sizeof(*guest_data)); + guest_data =3D ctx->save.buffers->guest_data; + memset(guest_data, 0, sizeof(*guest_data) * nr_pfns); /* Pointers to locally allocated pages. Need freeing. */ - local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); + local_pages =3D ctx->save.buffers->local_pages; + memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); - - if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) - { - ERROR("Unable to allocate arrays for a batch of %u pages", - nr_pfns); - goto err; - } + iov =3D ctx->save.buffers->iov; + rec_pfns =3D ctx->save.buffers->rec_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) { @@ -209,14 +207,6 @@ static int write_batch(struct xc_sr_context *ctx) } } =20 - rec_pfns =3D malloc(nr_pfns * sizeof(*rec_pfns)); - if ( !rec_pfns ) - { - ERROR("Unable to allocate %zu bytes of memory for page data pfn li= st", - nr_pfns * sizeof(*rec_pfns)); - goto err; - } - hdrs.rec.length =3D sizeof(hdrs.page_data); hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -267,17 +257,13 @@ static int write_batch(struct xc_sr_context *ctx) rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: - free(rec_pfns); if ( guest_mapping ) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i =3D 0; local_pages && i < nr_pfns; ++i ) + { free(local_pages[i]); - free(iov); - free(local_pages); - free(guest_data); - free(errors); - free(types); - free(mfns); + local_pages[i] =3D NULL; + } =20 return rc; } @@ -806,18 +792,18 @@ static int setup(struct xc_sr_context *ctx) =20 dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); - ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); + ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); =20 - if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pag= es ) + if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) { - ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" - " deferred pages"); + ERROR("Unable to allocate memory for dirty bitmaps, deferred pages" + " and various batch buffers"); rc =3D -1; errno =3D ENOMEM; goto err; } + ctx->save.batch_pfns =3D ctx->save.buffers->batch_pfns; =20 rc =3D 0; =20 @@ -841,7 +827,7 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); - free(ctx->save.batch_pfns); + free(ctx->save.buffers); } =20 /* --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387329; cv=none; d=zohomail.com; s=zohoarc; b=lZ9jLJPYj9p5IuO5MQWgEarabsAJSkW7HyMhaqjSU6XnYhSnqKnjvtwlc9JscSthUYq8pTxAEgHUFn3bcv4Lx+Ap3XGNQBGtv7H0ovrl8S4hC+957obKuQvn9aooIxUIYpreO1D5CvK8eD26AhIhnUN8q4Tc+JohplNQbXFWpmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387329; 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=7om3qzciu7p1Hjf//vy/GA8MoXg6EtRp3ssDnE4xjCc=; b=V/gzgPHnMAsTI6yj51aiFF74lLb2CV4YAmjhzzLg6SIwxzmWCmc2Gqq/U+eNRuuIDsUGBH0bXkjcXCzvstPZ+mup5PWASJPwU0Ah6vt82qGyu/h5+m7wA4T2hea2sM/Is3Hj7JqtqP6EcYt8hRHwy9GqtGDlmgL04jHhac6mNFE= 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 1781387329887881.4152818139995; Sat, 13 Jun 2026 14:48:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337557.1598873 (Exim 4.92) (envelope-from ) id 1wYWDA-0002SM-V6; Sat, 13 Jun 2026 21:48:16 +0000 Received: by outflank-mailman (output) from mailman id 1337557.1598873; Sat, 13 Jun 2026 21:48:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDA-0002SE-R2; Sat, 13 Jun 2026 21:48:16 +0000 Received: by outflank-mailman (input) for mailman id 1337557; Sat, 13 Jun 2026 21:48:15 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWD9-0001un-7N for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:15 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD8-00DVVl-KQ for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:14 +0200 Received: from [10.42.69.8] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcfd6-2eae-0a2a0a5409dd-0a2a4508ddf0-2 for ; Sat, 13 Jun 2026 23:48:14 +0200 Received: from [209.85.128.41] (helo=mail-wm1-f41.google.com) by tlsNG-c1860d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd01e-63b5-0a2a45080019-d1558029d029-3 for ; Sat, 13 Jun 2026 23:48:14 +0200 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4903d730b1fso26448045e9.2 for ; Sat, 13 Jun 2026 14:48:14 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:13 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781387294; x=1781992094; 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=7om3qzciu7p1Hjf//vy/GA8MoXg6EtRp3ssDnE4xjCc=; b=U0W11znpk0ZdDBxXXs2NqOpVpghdC6+lHSJOEp5R5jc4OLigDqfhJusEEmdXl8Ml8N SEefZHJQx/q/Za9Sg8fBv+mugq5zH0eRNJN3COHKwGOsakl+6U4KvvFHwhxZhoHXOARL RrcyrXZXpmBpNahVEifR6GFtUKYLuisoYQh01cwYDJ/ft9zPbyXw3o1EC3o5TJaYjhsr tT+V465X58W2oXANUC8Ca6SwEqS8t7/yjBFhpTwfx2X5FInMgEkKpWAds03PULw1N542 fN/KWW6F8hAHrPirSMKxZOx+kGgFUf3b3+U+qY6ai6RpIJrIZXbmF8hzMXso16GvbFkU y4nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387294; x=1781992094; 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=7om3qzciu7p1Hjf//vy/GA8MoXg6EtRp3ssDnE4xjCc=; b=qFYJjOLKHf8lQvZ0P+TwIMdsQOORDEtkTFbs1xizqXgbitM6a4qtInfCLM29d1KDY/ 3df4MeDZuiAgKjWH3SuTvhCOm3wTWIk4CB2hx/xoXWx5DbZA6mhz4mGjlJ6OoID1C/e0 iUm3Oznede0TYNHObPUooAORLYSvvl4OlIxzB3WSzDsmBLj3J71iY82Tn4INsM0DPFhD A6LEDo5diPiiEFrnTKjjwjBqa+tPE5PXfW/8vBEhnLZRiagujyRHlmHG9/DxfoNtlNm2 WauU9S4u1CG3Aw1p5MRhiDPL3ApWHmop/tZUNEVreEEacwC0WD3hKsgciF6kIkkmj0Xz MsYA== X-Gm-Message-State: AOJu0Yx4ZDFHdKZWGxq8r+9WB0c3Iz+KR+WAD4ucWheW8YZIBP8RXmBI PmbpEGRSzNiDYQ7rYahwnbdw5jSxTxmksR8J+oO+mTbrA5yaQcbhmLjG/ym6ulCRTnc= X-Gm-Gg: Acq92OFmDyl1M1aND/UYkrrk8uhPzjDp3SCrg4tggFf+2wr7hHawwVXUqIh2tGDrpRs vcwpHkgAJK4vH/zMrgQOPcMefVWxAWcwhHYJY9B5MMAJvVRHjc72NCsJdYeXBZ2GNhhD0XVaWUw Xdz0wXcUZxEG5PMcfh9TB5qSE+U2JFI+/bJSedkKB36DJ5v+s+NuIKuv7cfagTAauoCV8A3wR8d c3IoPOZ4AfIkLtg+pnwSC5mSlzsO6xVnKeHU6/sGrdRbz4ZXHIzkfOCFgz8luA06rILy0HGqpAT 0/fSkQbShmLeIWf5vaeuft0IP8tAZTWlJqcuHBF/h+x++arwZoVEdznn4PX28GE7JvrZVjGoGlh XDQfoz2PFupP1GVYB+aEhWRrsPeHh1zd1sW5pWsezUGvW0Zx4awbcwol++9m2j8smovCzJhjdP7 jiUrP4JbzHRiTnYF6say0g2bd0GWM6t9kKKx5RWtwfPZ+aSg+/mUid4bGeMxv/VLzsoE7gicbXR xr0j+B44XBdn876V/YXbMg6Ng== X-Received: by 2002:a05:600c:4709:b0:490:5057:f5f7 with SMTP id 5b1f17b1804b1-4922007472cmr57482665e9.11.1781387293908; Sat, 13 Jun 2026 14:48:13 -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 v5 06/16] libs/call: cache up to 4 pages in hypercall bounce buffers Date: Sat, 13 Jun 2026 22:47:39 +0100 Message-ID: <20260613214749.20620-7-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-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-c1860d/1781387294-BF57FDB1-4A758F25/0/0 X-purgate-type: clean X-purgate-size: 5018 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387331961158500 From: Edwin T=C3=B6r=C3=B6k During migration there are a lot of mmap/munmap calls, because `xc_get_pfn_type_batch` exceeds the default hypercall bounce buffer cache size, and needs to allocate every time it is called. `munmap` is slow, especially in a PV Dom0 (takes an emulation fault), so is best avoided. Eventually it'd be good if the memory pool from xmalloc_tlsf.c was reused here, but for now make it handle the commonly encountered sizes (so far up to 4 pages). Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. Changes since v4: - fix off-by-one bug. --- 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 155e4f9d43..bde780c32c 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 <=3D ARRAY_SIZE(xcall->buffer_cache) && + xcall->buffer_cache_nr[nr_pages-1] < BUFFER_CACHE_SIZE ) { - xcall->buffer_cache[xcall->buffer_cache_nr++] =3D p; + xcall->buffer_cache[nr_pages-1][xcall->buffer_cache_nr[nr_pages-1]= ++] =3D p; rc =3D 1; } =20 @@ -108,17 +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.43.0 From nobody Thu Jul 23 22:26:19 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=1781387324; cv=none; d=zohomail.com; s=zohoarc; b=VesMPlelMRJr/HjbFSr8XdLCbpQHDyR0Enllk2du9uYz8FluGkX9A0GxeWQAStxxyl07GJnSPY3yyKAx4RR9H7mSw+qLd+yZPTM1nTKFQsjhTd8xZb7UjpL6rqtvnz3cssw6HYScwthWhApGN3itYV7UQPD+UGeMg13OzBA54mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387324; 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=9UNO2xI/wOnyoP+fG/GB8NiqXOoc6f8puz6dKt7oyRY=; b=A2dAoHMjRftJZF/4VIUouaQEvUxYqrgPaW8TUP9XpAeD8QfElxTPF5DkrG6djm7V6fDm4xzaQMi3YAA3RRlBR39eZR1KyY8GGIR+az2S0lvAcgUPzmtD/as67Td6s8wES21CMZvYQO7Q24fqVvWjFCMNLJOURhx/3u/U4j3zH2Q= 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 1781387324480671.3418097479827; Sat, 13 Jun 2026 14:48:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337558.1598879 (Exim 4.92) (envelope-from ) id 1wYWDB-0002VN-B1; Sat, 13 Jun 2026 21:48:17 +0000 Received: by outflank-mailman (output) from mailman id 1337558.1598879; Sat, 13 Jun 2026 21:48:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDB-0002V3-2r; Sat, 13 Jun 2026 21:48:17 +0000 Received: by outflank-mailman (input) for mailman id 1337558; Sat, 13 Jun 2026 21:48:16 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDA-0002Fc-06 for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:16 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWD9-008PGn-DM for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:15 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dd008-5cb7-0a2a0a5109dd-0a2a4503cafc-10 for ; Sat, 13 Jun 2026 23:48:15 +0200 Received: from [209.85.128.47] (helo=mail-wm1-f47.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd01f-672d-0a2a45030019-d155802fcd23-3 for ; Sat, 13 Jun 2026 23:48:15 +0200 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-490aaeabdb4so13454655e9.1 for ; Sat, 13 Jun 2026 14:48:15 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:14 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781387295; x=1781992095; 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=9UNO2xI/wOnyoP+fG/GB8NiqXOoc6f8puz6dKt7oyRY=; b=FB7z/d0Rl5zZzspY/NwsGBFMNJU3eyRQUQl05HoEb3F4KvfPb/iOGJE2U0a9wMtqAK HcUbL+Injiggz2zSkkVrivx7dxhmvA1GnZJc+HIYgpQkVLjSTSQ7lj4xXEF8fOrK1rIE BwkUK97TSF/1OnJri+GWuQ/3VYYFxgPaFIsQqllx9FaTDTN9xqI6FAXSsOMspyC9vfZ9 dhrAwXpghxjPlfT1iuEOIBWwOUXId99vyiY7hlZjzyHAix5z/R3xVqTl/kVkS2AWqkpD 38IEMN55HkFZeVt0pzNJKHpVCAX9B0H5ws9od7F6p6+PgMaACZNJ7c6c+0+RKL2+8n0F n5Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387295; x=1781992095; 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=9UNO2xI/wOnyoP+fG/GB8NiqXOoc6f8puz6dKt7oyRY=; b=nPlsWg8eA/mS8qy8y+PFxN+AutJrge+GwuVDQSCO7acyrNM0I+/foyM4zq380oV2dF FSDYT8SlpNBmg3keCwDoL7V1MPGb1VmqjaYOlOAw3vZsi1MS3DkqDpxjZ6TBm+L/eNRV plXAvJMbpfADAWrXy8bJKqWEHC4DggO8Z6uuXDi+U3B7k3PNv9sbi0+vPI9AuoXCMxgl PHzQc8Xs+Oa0izVqV0yy4ZjFuiFkHGANcwYZjHahN7EyJY1X6KXeG0w8XEKfmWm8jbbj 8qQSEcZdugUrKO5Z6XxdMDfYs3+PQNVBb/UCYSwCtM2HX8q9ELUovFxjnnaQjiuUE+qm 2bHQ== X-Gm-Message-State: AOJu0Yxf09d9UCkuzq8nPuD7vpHQ3yzkMiimJtz63rxYm0xQF32kFWl3 hMzgD5dGDGqoamUFLpRtNo6abONb5N/D0HHk287if0qNLOMjYW6/F7OE4Kc6a34Mcu8= X-Gm-Gg: Acq92OEf2b0FZUEllk10sKMVv3zf56ORnh0CFVVm5VhEsRcDRjBv3yh4n1uby5xTFNe ioqx8yzE5Jqc27Z38SdFE67+BkJEKQTvbMrLs1vLzrRdeGgi/KEijTSdg0vL7glecXEaaghKx50 fo7DsyRzFSPZKlb7SWe0EmVU7TPcszkIJ1U3Snwsh3ehY6GnBkLqkIgB2ZYbKKQMGmpvoiywgbf 9/Ek1D9/Vu0xfwYr0fiZuVGrE7n/zVRYQhTxei4RWzw4vAnKyE4fh41RI4LJpEVy2u+gtpjGdsE 2goN/PtFLVsCnh7id9d0ceWt48ollh6ZA3ng2gUW4faLo9djlpTn3voVsqOan1g+Xec2ZybKwSd Ffqd/TBlRMhl0SGULx1Qqr3PzGdP/jQbgW96Z4jlkQNWCAkp4V/fjGcLqsbyMxRkALCNMDG4ode 5pyPwNwYWEVachoU9uIpximrd989UYQRIcJhD26h0XA46bp/JDRYAZCrG8fEj+0J+9pKHM2wO9y LysgI5FCXJs1r/2h+HwBLQKFQ== X-Received: by 2002:a05:600c:17d5:b0:490:b4e5:ce7e with SMTP id 5b1f17b1804b1-49220104e46mr35997485e9.25.1781387294695; Sat, 13 Jun 2026 14:48:14 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v5 07/16] libs/guest: avoids using 2 indexes Date: Sat, 13 Jun 2026 22:47:40 +0100 Message-ID: <20260613214749.20620-8-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1781387295-3957F938-350FC35E/0/0 X-purgate-type: clean X-purgate-size: 2785 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387325913158503 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 Reviewed-by: Andrew Cooper -- Changes since v4: - added Reviewed-by. --- tools/libs/guest/xg_sr_restore.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index e148fc594a..fb46142d87 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -260,9 +260,7 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; void *mapping =3D NULL, *guest_page =3D NULL; - unsigned int i, /* i indexes the pfns from the record. */ - j, /* j indexes the subset of pfns we decide to map. */ - nr_pages =3D 0; + unsigned nr_pages; =20 if ( !mfns || !map_errs ) { @@ -279,12 +277,18 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - for ( i =3D 0; i < count; ++i ) + nr_pages =3D 0; + for ( unsigned i =3D 0; i < count; ++i ) { ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); =20 - if ( page_type_has_stream_data(types[i]) ) - mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); + if ( !page_type_has_stream_data(types[i]) ) + continue; + + mfns[nr_pages] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); + pfns[nr_pages] =3D pfns[i]; + types[nr_pages] =3D types[i]; + nr_pages++; } =20 /* Nothing to do? */ @@ -302,16 +306,13 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - for ( i =3D 0, j =3D 0; i < count; ++i ) + for ( unsigned i =3D 0; i < nr_pages; ++i ) { - if ( !page_type_has_stream_data(types[i]) ) - continue; - - if ( map_errs[j] ) + if ( map_errs[i] ) { rc =3D -1; ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[j], types[i], map_errs[j]); + pfns[i], mfns[i], types[i], map_errs[i]); goto err; } =20 @@ -337,7 +338,6 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, memcpy(guest_page, page_data, PAGE_SIZE); } =20 - ++j; guest_page +=3D PAGE_SIZE; page_data +=3D PAGE_SIZE; } --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387330; cv=none; d=zohomail.com; s=zohoarc; b=KYMQ7KaI6x8yBw77ZqmHVAyWRLtIK7/lACdvohoQ+heojha3hZy/EOcVtAUznZXj01n8OHpS+0tBT7tW1JtR9daavAWVOGJYIGuTUwafpyZ+JYAw3wU0pm3i00UtdUbUbM7VXzx3IsOG7RJSglekS+7EeGunLmZGZ4h5+jR3uYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387330; 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=MlYBrPHimuR3p/Sg0YcSFuof0r06EXv6/scdT04tUH0=; b=dSy3WaZinpgPZDa3JbzxoD3vt7WFBYPE72FRDLmWXfSIheuIsHKZpAEIbbWShtwAG0oJBWih8zJy75054iNaj8seDdiwa6mbEt23tQq5Pqy+2FJDorDKs3lmYi76j3tneOjxOipYCPA/4gho4E8hneBxlY7rcbDq0ePAWUrd6LY= 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 178138733051722.62298173263207; Sat, 13 Jun 2026 14:48:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337559.1598891 (Exim 4.92) (envelope-from ) id 1wYWDC-0002vs-RG; Sat, 13 Jun 2026 21:48:18 +0000 Received: by outflank-mailman (output) from mailman id 1337559.1598891; Sat, 13 Jun 2026 21:48:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDC-0002vV-NN; Sat, 13 Jun 2026 21:48:18 +0000 Received: by outflank-mailman (input) for mailman id 1337559; Sat, 13 Jun 2026 21:48:17 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDB-0002Zz-Iv for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:17 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDA-008PGn-Vy for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:16 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dd008-5cb7-0a2a0a5109dd-0a2a4503cafc-14 for ; Sat, 13 Jun 2026 23:48:16 +0200 Received: from [209.85.128.51] (helo=mail-wm1-f51.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd020-672d-0a2a45030019-d1558033c11e-3 for ; Sat, 13 Jun 2026 23:48:16 +0200 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-49222b6e871so6073465e9.3 for ; Sat, 13 Jun 2026 14:48:16 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:15 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781387296; x=1781992096; 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=MlYBrPHimuR3p/Sg0YcSFuof0r06EXv6/scdT04tUH0=; b=VgZ3Kp2B3lPAfjILM8ZA1bRzi6dd2UYOp76SRqMyJxComo4gfbb2Gt6i/LH67tbGW2 XF9gvojQ9a0XH0D6N2i8Wfrhfz2DrwGXgeqfCcosnZVldWuusGOOzu3SKQLqSRpxA6EA KjAV1W/EokYl/5sBOltvzFc6keeL1wqpuXaYD4c5/5MiEXLRtVg84n5edMf0lXHQ+Wki 2LiO1o3nipj4Qo8EkhQQ+25Si07A6Q5E/iLYFSzBP6OLfIUmafclth4WLr+ETWragyPW 52+dC0Vxxt1mIiXvlJ0V7fSzE5jITPjHYN9nxqW+WGXsipBWXOLlfvecI/vxD6DSB71H lGag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387296; x=1781992096; 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=MlYBrPHimuR3p/Sg0YcSFuof0r06EXv6/scdT04tUH0=; b=AKxtZUnhBX9L/3TZXdj92TZcU91ExP4R2v0EwdEzsVcNCuwgD7c/ookMNL43w3tJgu SOtWCiIoSU7fZxkQ9jq8ujQNou37Ur3MU2vWcagITSI8uphlDOjxjwJGHVBE6fRh6w+B kfG/GmBpLqZHxl6NNmdN89tjlCxoLTLyEDjiUrDhnyJCHYapI+r7M2HjK9R5Ub/LlpB+ am5RYkLOQgnhhqhIDm2XDyjJYxFNyA2D6cdZj8iLvU5r0Q4g0TLX9Bq6Ja/KJ16Qdv+k CSYUE54LacQ4EwAsfvY4zfYp9a+0GBiGydGcyVIx1bOnns2CL6xX4UCQdnW4IqVOayF+ odMw== X-Gm-Message-State: AOJu0YyluiBuILgMkZu341EvvGJHa8m7ZBNyg0t+oYzd8OZNfQwegQ/X qDjD9NPMbMeuo3g8XQRBn96qsqUib75VzksmUzJtXCbyx6EngSRT4HoMJbeEGCFsSKs= X-Gm-Gg: Acq92OFqWxBg4A2SDj6wv5nKhhWpCxLmqdrUwllkiL2RjBwnj3oK6XiRiQ6WtsLegV3 2542kUtUy9sYLE4c2g90NgYDCIBVOYgg52hPW/wp8ST/DimaKtHe0MXsQu7PAG1eH5eP61g3xV2 +ObAV1QoJWIHSzkMPGsBA6q8d2F+6yFeJcvRWYCCQWx6K1zTc3x+2RXJeqxksbhH8+ErJ6qdylp Vv5JsYiIR/ziHyoItO79dhdTP1LPWwKwyn0yc2+jEMUJa60zuNSSWO7zWqF/eByXxaxxRKjQYMx s9aPXSqIu0QGDoKWXYmQ1Xc/5LubYGF7dce7FRUitTjW5n6Lr8PEq6gDBcKD1rcTppdu0GBVH1V /uyYGWfIaaqupQ9YGHLZMDimQA+W2JzlYbwb/J99tr0XP9F9daRLTG7P9ksPyyVozmjM94CDrPA E5pBy5UTv1G+MglPM/1Ugje5a1OAhJuS8X1VXdh9XLfJZeMG6WULVtR+/6zq9lUe9AeHpd4bZ+9 eyRpaF61+oD2STDR7D2V1PyJGqaYsrsIAPo X-Received: by 2002:a05:600c:4685:b0:490:bad8:329c with SMTP id 5b1f17b1804b1-490ec4d4f64mr121404065e9.12.1781387296170; Sat, 13 Jun 2026 14:48:16 -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 v5 08/16] libs/guest: fill directly iov structure Date: Sat, 13 Jun 2026 22:47:41 +0100 Message-ID: <20260613214749.20620-9-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1781387296-3A378938-1D97C0B6/0/0 X-purgate-type: clean X-purgate-size: 4598 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387331940158500 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 | 64 ++++++++++++--------------------- 2 files changed, 23 insertions(+), 42 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 95b0564e5c..b2c441b644 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -214,7 +214,6 @@ struct xc_sr_context_save_buffers xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; xen_pfn_t mfns[MAX_BATCH_SIZE]; xen_pfn_t types[MAX_BATCH_SIZE]; - void *guest_data[MAX_BATCH_SIZE]; void *local_pages[MAX_BATCH_SIZE]; struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */ uint64_t rec_pfns[MAX_BATCH_SIZE]; diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 4988d8040b..8a22267fdf 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -88,7 +88,6 @@ static int write_batch(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; void *guest_mapping =3D NULL; - void **guest_data; void **local_pages; int *errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; @@ -113,9 +112,6 @@ static int write_batch(struct xc_sr_context *ctx) types =3D ctx->save.buffers->types; /* Errors from attempting to map the gfns. */ errors =3D ctx->save.buffers->errors; - /* Pointers to page data to send. Mapped gfns or local allocations. */ - guest_data =3D ctx->save.buffers->guest_data; - memset(guest_data, 0, sizeof(*guest_data) * nr_pfns); /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D ctx->save.buffers->local_pages; memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); @@ -158,6 +154,19 @@ static int write_batch(struct xc_sr_context *ctx) mfns[nr_pages++] =3D mfns[i]; } =20 + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + + hdrs.page_data.count =3D nr_pfns; + + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); + + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); + + iovcnt =3D 2; + if ( nr_pages > 0 ) { guest_mapping =3D xenforeignmemory_map( @@ -199,61 +208,34 @@ static int write_batch(struct xc_sr_context *ctx) else goto err; } + else if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len != =3D + page ) + { + iov[iovcnt].iov_base =3D page; + iov[iovcnt].iov_len =3D PAGE_SIZE; + iovcnt++; + } else - guest_data[i] =3D page; + { + iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; + } =20 rc =3D -1; ++p; } } =20 - hdrs.rec.length =3D sizeof(hdrs.page_data); - hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); hdrs.rec.length +=3D nr_pages * PAGE_SIZE; =20 - hdrs.page_data.count =3D nr_pfns; - for ( i =3D 0; i < nr_pfns; ++i ) rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; =20 - iov[0].iov_base =3D &hdrs; - iov[0].iov_len =3D sizeof(hdrs); - - iov[1].iov_base =3D rec_pfns; - iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 2; - - if ( nr_pages ) - { - for ( i =3D 0; i < nr_pfns; ++i ) - { - if ( !guest_data[i] ) - continue; - - if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len !=3D - guest_data[i] ) - { - iov[iovcnt].iov_base =3D guest_data[i]; - iov[iovcnt].iov_len =3D PAGE_SIZE; - iovcnt++; - } - else - { - iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; - } - --nr_pages; - } - } - if ( writev_exact(ctx->fd, iov, iovcnt) ) { PERROR("Failed to write page data to stream"); goto err; } =20 - /* Sanity check we have sent all the pages we expected to. */ - assert(nr_pages =3D=3D 0); rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387328; cv=none; d=zohomail.com; s=zohoarc; b=GjrXm9i1Z+1mbRx0k035HpntoP8BzEUS1KT+bmbzsmMGykvlVfb9n3sj7lu3G/Z+TPDSpuhYS1X3DjO+a6XhdnjbSzFCB9XKcSoHgT6ANFaFbwnbChWFVuTSYy21AJ8Rytvh6m24n15Qx0CYGogTg5ayQXtmR2tkibr5hoWKe4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387328; 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=9MhL+IoB2npTTdx+dYewd7GvfekT0Xac13RwRFw6zgo=; b=ijniISoSvvyFHL1ccD5KHF8WPPhw0z+CzwdeGWs3qaMqOGAD1Op121totZ91XEy0t+6vWw+yLgEMZKSmimU/2LyAkTiNvS1V1rJZlpHUbzREq2BoArkUVpDZd+J1R8Xm6tWtgP1Z1yK4c8+eLKVXiLBZdNMbEgbSpIIINmvbseA= 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 1781387328041167.55391040328232; Sat, 13 Jun 2026 14:48:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337560.1598900 (Exim 4.92) (envelope-from ) id 1wYWDE-0003Bu-8e; Sat, 13 Jun 2026 21:48:20 +0000 Received: by outflank-mailman (output) from mailman id 1337560.1598900; Sat, 13 Jun 2026 21:48:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDE-0003Aw-0q; Sat, 13 Jun 2026 21:48:20 +0000 Received: by outflank-mailman (input) for mailman id 1337560; Sat, 13 Jun 2026 21:48:18 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDC-0002jU-4a for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDB-00DVVl-Hj for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:17 +0200 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcf18-2eae-0a2a0a5409dd-0a2a450bc4b2-32 for ; Sat, 13 Jun 2026 23:48:17 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd021-212f-0a2a450b0019-d1558030c84f-3 for ; Sat, 13 Jun 2026 23:48:17 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-490a76757e5so14953915e9.2 for ; Sat, 13 Jun 2026 14:48:17 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48:16 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781387297; x=1781992097; 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=9MhL+IoB2npTTdx+dYewd7GvfekT0Xac13RwRFw6zgo=; b=NTvVG6dNhC3mEpRfBD2njqws/hYIb+dx6lb09jaYgR9Xog+3Gb+aiXxRjnqz1NcI9I 5sub9RwrS36/DeXf3MIAVBQzOhx/ltjqsHMuqvOKNKRe9WuTN4/iRMY6djAhtL4hvCr/ tfoQlKDYbsZCYOD2VTW5h0j6YL/HCXINYQmYuDbX1f0I5CBmq+3/78f6/GRnvgHiT0Sn 2pZaG1yk2VU6ns7S2DDYo2Qru7fUL5cXwD3xs4Gv++YgU2vUejR0Xa74zmIHDKeeTfBO g+kujPjSY2wsObeL3mGAvy4sUjWOucwXHr4C652njY7kEVvONCtMxg+DhQDCVeTl+95I fZrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387297; x=1781992097; 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=9MhL+IoB2npTTdx+dYewd7GvfekT0Xac13RwRFw6zgo=; b=NrWlriWDq7P8X7RyhayyksPXYhvMPsBxmrRpFmuT9PhghsNjkqBOjXWXOmjxjzmd2r 4LIyKHtEIgQ3y8VmfGYcSM597v8+Npzv8gvAJXEbieiCLaVf7H+XF8Iq1i2fBzaihaHn oB+syRMVusRG4KpyjnJX24L6Ub0x8q2I/4qMnPqAfgdFwm9UYaqJdCAT090qjZwsqJKN vyBksQmo6+sms8n1GAcbs1ENYtvNEGlY3HRm8eeaOhvGpeV8PDSmUVtvLtvk5AhPVo/j K9jON2994n428CKVJ3ykIT/hJ1OwdcUlQIgi+H5IJdpBsFCityUGqoyKBfBI+TIuGRwN cruA== X-Gm-Message-State: AOJu0Yyl9ugs5D5L4rwCw+OqRAfZocNFOtiCnXPk4Ilcg84DpfrBAuo8 H2QCuXfC7eUr4C8jS8au3tIWlGEOgD3gq+WhO8JqwKoQBB7/fWZnTiNjZjmTa1n4xP4= X-Gm-Gg: Acq92OF+YuwiyllxGNHF1ULVEiTS2VNQ+LBpTQrIOhiiccULuvmRC+Pi7FBs1Jzwbzd BHc64kfasStyD8ME0G3GxexhKTa6sky1I14VA3CBTORXO5JI4D5Lh2ucbEMw/5U6h3XR1E4HlFH FZvLg2Kohq6dA1cm9g1650smWU1zMja5o1wbk2a4a3yOjwawknc9KMi9OKRKonjUTszI5WS59s6 j05D34ISAF5ihXrbgMiTjgYzo5AQ9Eaz+S9zwR3ZC5eTnArjFaOOsRJRCkiqSiqGEpfmIMtRSKr sYlszc79MHDp4DjuZElsa98xVnX3EU4T6JKb027s8H9R8t1eZ9jzKCPCUtHKG1Y1ohYIHPCUxw7 stiDlPBNNouB2UxJPig8o/IGE2rx9+865wXa4tn7O5kViO41+J9YZN/8BG0dZ1jDksrWIDmU6wY Za4NLfODq11Tnc1h6wBEndy6r1gO+iLvdzGbzBpP8pfFpwp64PyBNhWvJ28MQOVO1muEHREexBE 0T71jMW0Q2e0YEOW0KFatYRUQ== X-Received: by 2002:a05:600c:4e4e:b0:490:e196:e8df with SMTP id 5b1f17b1804b1-492200bb228mr56160055e9.23.1781387296918; Sat, 13 Jun 2026 14:48:16 -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 v5 09/16] libs/ctrl: Allows writev_exact to change iov array Date: Sat, 13 Jun 2026 22:47:42 +0100 Message-ID: <20260613214749.20620-10-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-42698a/1781387297-13F7EF3B-2B28A7F9/0/0 X-purgate-type: clean X-purgate-size: 3226 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387329925158500 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.43.0 From nobody Thu Jul 23 22:26:19 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=1781387323; cv=none; d=zohomail.com; s=zohoarc; b=bEMr8X8Sf1dGgq748cpo7hQTU5x/qDAMyCeVNIDmWHxNZFxOXaR0N8vBkvwrFi/g+czZPgN+YaJ4Tu3pUI3mKi4501hBzft/lfBZWCkpD3Vjkca1I7RjXRQj3dNGuPylaS+wCjCVtmboNAskM+DrAMCxNwjYQ7mBeIRknZMAYyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387323; 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=kZLqhAsEGWHmz0lV8qaz7KK9CmcVhtj8aflYqjYEp+c=; b=CyCWRj7LA2Xx8uMzdZtjYcid+EsNCkOWNwQ2dBja2kLgxzl4QyoAMtz8xD3MTl3QKMwMf55UvYDcwe+C8g7je9ES1sgvDyBTVmXoT3PSLK/QZ9xtNwfA3yu++1FGtfhnrrHC2zVYBaqvaD7FabtcsL/+0X8vwMJWyM9amp9nWQM= 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 1781387323134981.9887133230199; Sat, 13 Jun 2026 14:48:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337561.1598905 (Exim 4.92) (envelope-from ) id 1wYWDE-0003Gw-La; Sat, 13 Jun 2026 21:48:20 +0000 Received: by outflank-mailman (output) from mailman id 1337561.1598905; Sat, 13 Jun 2026 21:48:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDE-0003G2-GZ; Sat, 13 Jun 2026 21:48:20 +0000 Received: by outflank-mailman (input) for mailman id 1337561; Sat, 13 Jun 2026 21:48:19 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDC-0002vD-RJ for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:18 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDC-006VOz-8B for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:18 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcfe1-e002-0a2a0a5209dd-0a2a4509edf2-6 for ; Sat, 13 Jun 2026 23:48:18 +0200 Received: from [209.85.128.43] (helo=mail-wm1-f43.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd022-2497-0a2a45090019-d155802bbd49-3 for ; Sat, 13 Jun 2026 23:48:18 +0200 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-490b12270b3so12637205e9.1 for ; Sat, 13 Jun 2026 14:48: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 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387298; x=1781992098; 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=kZLqhAsEGWHmz0lV8qaz7KK9CmcVhtj8aflYqjYEp+c=; b=mnxIRCsyer12mBvOHgDifaR5ohSDWRcJFb1LaNV0OmKOWDjNxgVED6IxI7SrJFKVnZ B8vY9kV4R5rXiB/i/SlpH4QDsvZDCwfawNJgDed3l0L99ryQPshLiqQehN+5z+lhoYPN HShjjW9MOtoGrlUBxe5Jrf12DoIGkkCf5mJokoiqx6Q7d0ZY7DhFwMgUzD1QuG+/NgEm ohHTiDxLGavqEHGmdkow0ERunE83ovWLEXWOXHTCAXMfepJshtNBfN5alYHjWeTq8wOa Ge80jz31rzZpEN7fIuN9w+6QVQ7ywBR85/rGU0V77aky83FU1VnE+GBAB3ecLqG4rTQS lZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387298; x=1781992098; 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=kZLqhAsEGWHmz0lV8qaz7KK9CmcVhtj8aflYqjYEp+c=; b=j7TVbPCn4LYdfoqfVCPcAL6fyvgebrYqqxnawgMExU6CCC0HB1rg5/uPW05lShEYo8 aYkbrqG5N+M2hX/OGsQPzrIb4W4b4rtu/tb7HCJJYOpB6dETBNFLPxyaBXwRR00DiiM9 G7wW23WE9cxqonqsVRYMO7tehBW1+LYNaVhWNJAbXICI+ixmP8Wsy5nxKjPrSGqzCAea D+wjaeffIq/TAEDkxBK43FR1bxie/hwq2E/3JCJ6Q/CTnuLfRmYkb2QAq3nqgMwSC3+l WnRDp2w053H9deQpQtBXiRN2hQKbuc0QqPRB1YQ1QKXfKviSblJjOxiLXlp0VfpFI/Jn BdrQ== X-Gm-Message-State: AOJu0YysDxBFXL9dAcSYt3hV7o8dbcqaqVgSAvi1drGWLGIkXM0n7uBq H6E+olkZiaYjOI0si+dbFBPelPpdFVCs2Rxrf5lGZdkaElT43OkwUYPnaNhd6ZAb1xA= X-Gm-Gg: Acq92OFTxDtFsyW415ztR7D2Is8jsD5xqhaYxZa/j0sSehea28diCldvDF2jhq74y2k J9IL66m07N6djHuLWmxjKZMkReTjBdFJ6l3Rw16L6QB3Z2nyzWTljA+e8erj3WvTpR2nsq7K+4O 7ERrjkddNvYDVwKTEWDSMTpXDyZHk8UZXi0ab4rRv2czOiQpXWQi9SA5joo7uANeSBM67XIvL5Q Husq+LNRN7gujES//mqDnPCmpmjA8NXQh3LwNALW1M/0sYFNdJfwI0yWkSlx4PTKpjyfvgZtovj 2vb31+mFoV9wBtsTqM/oypanAaLQk0yYioRUI3GWNFBwjB2dlR0TXHLneKJSNfgG+XdG0rz1fl4 EfZkP7CFKd5EW4iKYBL+SOqkDxlD4HpPyiiAq/iInz/IkeKbQBKXd2avvda9xrF5CbxVHQrAuIS TvqET7U64n3IOPJxJovpTzDFc1s8SnnSgAgtPQ7M+7VfpskCMoTYCEu8pN/Ow23IlYVL5sK9JvR C+1jIZ/2YMxyoXhfi5QE6ltgA== X-Received: by 2002:a05:600c:3153:b0:490:e5c1:b897 with SMTP id 5b1f17b1804b1-490ec4fe7c2mr108569145e9.20.1781387297616; Sat, 13 Jun 2026 14:48: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 v5 10/16] libs/guest: add xg_foreignmemory_copy_{from,to} Date: Sat, 13 Jun 2026 22:47:43 +0100 Message-ID: <20260613214749.20620-11-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-bad1c0/1781387298-8A98FA53-81DB1CEF/0/0 X-purgate-type: clean X-purgate-size: 3485 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387324200158500 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 9b2782b5cf..f760b63548 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 b2c441b644..e37f805240 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -553,6 +553,14 @@ static inline bool page_type_has_stream_data(uint32_t = type) } } =20 +int xg_foreignmemory_copy_from(xc_interface *xch, domid_t dom, + size_t nr_pages, void *dest, + const xen_pfn_t source[nr_pages]); + +int xg_foreignmemory_copy_to(xc_interface *xch, domid_t dom, + size_t nr_pages, const xen_pfn_t dest[nr_page= s], + const void *source); + #endif /* * Local variables: --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387335; cv=none; d=zohomail.com; s=zohoarc; b=PK/iifg7RtssFZakYn+vdHsXlQjhJ/AzOPxwlRCcDEyg2ETnN/MCB/8Do5iZA6wgm5bwnl6p+4MD+auG2x04vo3lqAWeTfNa+ILiBPYp28/q2lECEK65ZYRGk/0JOwiELbtg1PH5sPlAC3zgFiXOAL+/gmhmG3xAVBusmiulZls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387335; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nZbBEu1yumZubA+jdFXfLBNW/6vA9c6a3PhaM+0TpSU=; b=ETOKJ77l2gMWrITdaASag3ZmcW04W7u1ILT/OmBrgrSsVQr0RnOEDBqnmIjJu8GdCEJNwlj3BxUUwT3M3STMShdP08QZdMaQYC6CQipNv6/z7klDGCsXBzutcXfOWp5Smju0r/kwptTN9mX5fNNpMNbJY/HyRgaF63dZFoAkpDs= 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 1781387335699782.0135702412247; Sat, 13 Jun 2026 14:48:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337562.1598912 (Exim 4.92) (envelope-from ) id 1wYWDF-0003Nc-6U; Sat, 13 Jun 2026 21:48:21 +0000 Received: by outflank-mailman (output) from mailman id 1337562.1598912; Sat, 13 Jun 2026 21:48: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 1wYWDE-0003MW-Tc; Sat, 13 Jun 2026 21:48:20 +0000 Received: by outflank-mailman (input) for mailman id 1337562; Sat, 13 Jun 2026 21:48:19 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDD-00035f-NU for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:19 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDD-002Ajp-3y for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:19 +0200 Received: from [10.42.69.5] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcfda-bab6-0a2a0a5309dd-0a2a4505b0c0-6 for ; Sat, 13 Jun 2026 23:48:19 +0200 Received: from [209.85.128.47] (helo=mail-wm1-f47.google.com) by tlsNG-c201ff.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd022-aaa8-0a2a45050019-d155802fedbf-3 for ; Sat, 13 Jun 2026 23:48:19 +0200 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-490ac357c55so19282735e9.1 for ; Sat, 13 Jun 2026 14:48: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 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387298; x=1781992098; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nZbBEu1yumZubA+jdFXfLBNW/6vA9c6a3PhaM+0TpSU=; b=DG1wKx5wywRyDi8ltJZbwsQGb/HK8goSFrgxp7B8qTiv2XBicu5LCL87Srj2pQfi3X Ico3ay0rxPrH0PT+9E1frSXSEkipsSMfExwa4FCo3v+IQ26DTaLx8wMMFzdRCQpUOE7Z DNejBxCYlvwJt4K2f4bif2kghXK3WmELXJzkohV3KUShZw0EDl332KdWEDkWpvZDISal 7rFRGtV/MVOHc7+pfIIl4dvfnGG+cb6GkqxxcMfSerTVprLQq1hiVM2VfLOWyODWD4fH gqvqON4HhY7iGy6tdxHrmFCgPx+WzCqDXKUgBnFCOFF1QcAaCWaPC0KiFvTWU4dZ3XH1 NWhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387298; x=1781992098; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nZbBEu1yumZubA+jdFXfLBNW/6vA9c6a3PhaM+0TpSU=; b=ZteSnkiSW93kQ5BuaiFcwjZmS7CtZAubE7JAPHz47ji2+1vU7XngONl9pgfAhfT/fj 890KewlHreyIgwzcR3R+BhD4kQimY9nKUZFaq5kh8hb5mM19WygTIfDa7eDRP3OLRzM9 3QNcF8Q6Mx0bYwintLbid3O4y1G2DZlaz1PhDzxpag1XctAE82RoULSlcF3Qb4gbL1Db Z46L9myxxz0MQ34US3KSB12JJnTQBe29GHi3O7MQmvlf0uUiZjm8M7CvzWQHokIkW2nF 2TdPV40dl9Esh2/ExzxXlNIm0q8AD5xcJ/lnx2VTHSlxlndXmHtaaMjLUs/d7z3P3c3p X3Xw== X-Gm-Message-State: AOJu0YxKvxr9vZEMcg/ihqX9URZR2iId1OkTINvMX9iqkt5S1kNDY4yx ZMjTsDN69gaVFE0ttQ/3LLNAjnAGrej6UBLqm3KGxpI3FCk6eXA1qlOkvsdbksx4HwU= X-Gm-Gg: Acq92OGDRvg+RUxDWrjcvmJLrGX7xtVXI2nAlQJOWsCTJ0Wr1OmyKoRbqR1DSITJKu3 hRRcj4StRE94QOwSiX1U/RNPY6Rk4m4bOOMfBoaxYWJ6o+gyVcN+MpXnQWlx2ItAtofrRtlLcpL ZzC/JJcFienuy5DsQ1gZwAxPHWXzq5zGj9Nmds4wDf0wqpH3AAL+5/yIhW3nV8Y3f+U3KTTUyH4 jh7yw37IWQALbp9pIew13xlGBoXOaBSvcPY7slz1sTtdN9HQkpt7gHE2dOWUrkG7YcOWBKtolAF +8XQyr5gLdxzzRbycWHsz/R4ZP82+mhnidVtwZbaD5uvBWld+sKWX8rO1OkKshkrpdan2RwgIfP YavosMifNKUgi6lz16Om8gA+Rf/aOw33+uzEhEgFVQCiqZB/I2CfwrFbl8cCf4hCU3IB2vPjOO2 eZt5azxOPv/WaMjU/eLqbr/S27EigWBy/gwIS67i1xL1YzOOVJ3Y6BF7UK1glga9qpECIUu/CrA tFchCNhJCXauXfQPzpXiGP0GCP/oDlEfQUB X-Received: by 2002:a05:600c:8716:b0:490:b355:9c70 with SMTP id 5b1f17b1804b1-490ec4c3582mr93913715e9.11.1781387298380; Sat, 13 Jun 2026 14:48:18 -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 v5 11/16] PoC: libs/guest: use foreign copy during migration Date: Sat, 13 Jun 2026 22:47:44 +0100 Message-ID: <20260613214749.20620-12-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-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-c201ff/1781387299-D9D77443-5CED8513/0/0 X-purgate-type: clean X-purgate-size: 8610 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387336117158500 From: Edwin T=C3=B6r=C3=B6k ministat confirms the improvement: ``` x baseline + foreigncopy N Min Max Median Avg Stddev x 20 1.1306997 1.1447931 1.1356569 1.1365742 0.003242175 + 20 0.4311504 0.44180303 0.43616705 0.43600089 0.0031094689 Difference at 95.0% confidence -0.700573 +/- 0.00203311 -61.639% +/- 0.133355% (Student's t, pooled s =3D 0.00317652) ``` The tests pass too, which means that it has correctly migrated all guest memory. Frediano: This PoC was adapted to be included in a final series. Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 43 +++-------------- tools/libs/guest/xg_sr_save.c | 82 +++++++++----------------------- 3 files changed, 31 insertions(+), 95 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index e37f805240..d8d8a0f9f7 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -256,6 +256,7 @@ struct xc_sr_context unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; struct xc_sr_context_save_buffers *buffers; + void *dest_buf; } save; =20 struct /* Restore data. */ diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index fb46142d87..ff27560ff7 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -259,8 +259,8 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)); int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; - void *mapping =3D NULL, *guest_page =3D NULL; unsigned nr_pages; + void *const source =3D page_data; =20 if ( !mfns || !map_errs ) { @@ -295,27 +295,8 @@ static int process_page_data(struct xc_sr_context *ctx= , unsigned int count, if ( nr_pages =3D=3D 0 ) goto done; =20 - mapping =3D guest_page =3D xenforeignmemory_map( - xch->fmem, ctx->domid, PROT_READ | PROT_WRITE, - nr_pages, mfns, map_errs); - if ( !mapping ) - { - rc =3D -1; - PERROR("Unable to map %u mfns for %u pages of data", - nr_pages, count); - goto err; - } - for ( unsigned i =3D 0; i < nr_pages; ++i ) { - if ( map_errs[i] ) - { - rc =3D -1; - ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[i], types[i], map_errs[i]); - goto err; - } - /* Undo page normalisation done by the saver. */ rc =3D ctx->restore.ops.localise_page(ctx, types[i], page_data); if ( rc ) @@ -325,29 +306,19 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - if ( ctx->restore.verify ) - { - /* Verify mode - compare incoming data to what we already have= . */ - if ( memcmp(guest_page, page_data, PAGE_SIZE) ) - ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", - pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); - } - else - { - /* Regular mode - copy incoming data into place. */ - memcpy(guest_page, page_data, PAGE_SIZE); - } - - guest_page +=3D PAGE_SIZE; page_data +=3D PAGE_SIZE; } + if ( !ctx->restore.verify ) + { + rc =3D xg_foreignmemory_copy_to(xch, ctx->domid, nr_pages, mfns, s= ource); + if ( rc < 0 ) + goto err; + } =20 done: rc =3D 0; =20 err: - if ( mapping ) - xenforeignmemory_unmap(xch->fmem, mapping, nr_pages); =20 free(map_errs); free(mfns); diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 8a22267fdf..7a48f6b0a3 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -87,12 +87,10 @@ static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; - void *guest_mapping =3D NULL; void **local_pages; int *errors, rc =3D -1; - unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; + unsigned int i, nr_pages =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; - void *page, *orig_page; uint64_t *rec_pfns; struct iovec *iov; int iovcnt =3D 0; struct { @@ -167,62 +165,18 @@ static int write_batch(struct xc_sr_context *ctx) =20 iovcnt =3D 2; =20 - if ( nr_pages > 0 ) + rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, ctx->save= .dest_buf, mfns); + if ( rc < 0 ) { - guest_mapping =3D xenforeignmemory_map( - xch->fmem, ctx->domid, PROT_READ, nr_pages, mfns, errors); - if ( !guest_mapping ) - { - PERROR("Failed to map guest pages"); - goto err; - } - nr_pages_mapped =3D nr_pages; - - for ( i =3D 0, p =3D 0; i < nr_pfns; ++i ) - { - if ( !page_type_has_stream_data(types[i]) ) - continue; - - if ( errors[p] ) - { - ERROR("Mapping of pfn %#"PRIpfn" (mfn %#"PRIpfn") failed %= d", - ctx->save.batch_pfns[i], mfns[p], errors[p]); - goto err; - } - - orig_page =3D page =3D guest_mapping + (p * PAGE_SIZE); - rc =3D ctx->save.ops.normalise_page(ctx, types[i], &page); - - if ( orig_page !=3D page ) - local_pages[i] =3D page; - - if ( rc ) - { - if ( rc =3D=3D -1 && errno =3D=3D EAGAIN ) - { - set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pa= ges); - ++ctx->save.nr_deferred_pages; - types[i] =3D XEN_DOMCTL_PFINFO_XTAB; - --nr_pages; - } - else - goto err; - } - else if ( iov[iovcnt - 1].iov_base + iov[iovcnt - 1].iov_len != =3D - page ) - { - iov[iovcnt].iov_base =3D page; - iov[iovcnt].iov_len =3D PAGE_SIZE; - iovcnt++; - } - else - { - iov[iovcnt - 1].iov_len +=3D PAGE_SIZE; - } + ERROR("xg_foreignmemory_copy_from failed"); + goto err; + } =20 - rc =3D -1; - ++p; - } + if ( nr_pages ) + { + iov[iovcnt].iov_base =3D ctx->save.dest_buf; + iov[iovcnt].iov_len =3D nr_pages << XC_PAGE_SHIFT; + iovcnt++; } =20 hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -239,8 +193,6 @@ static int write_batch(struct xc_sr_context *ctx) rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: - if ( guest_mapping ) - xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i =3D 0; local_pages && i < nr_pfns; ++i ) { free(local_pages[i]); @@ -765,6 +717,7 @@ static int setup(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; int rc; + const unsigned dest_buf_len =3D MAX_BATCH_SIZE * XC_PAGE_SIZE; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); =20 @@ -776,6 +729,16 @@ static int setup(struct xc_sr_context *ctx) xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); + ctx->save.dest_buf =3D NULL; + + rc =3D posix_memalign(&ctx->save.dest_buf, XC_PAGE_SIZE, dest_buf_len); + if ( rc ) + { + ERROR("Unable to allocate %u bytes of buffer", dest_buf_len); + errno =3D rc; + rc =3D -1; + goto err; + } =20 if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) { @@ -810,6 +773,7 @@ static void cleanup(struct xc_sr_context *ctx) NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); free(ctx->save.buffers); + free(ctx->save.dest_buf); } =20 /* --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387329; cv=none; d=zohomail.com; s=zohoarc; b=QuC5srfj/2QTSabiUNK61Uqc3nCvMULlxkNkt0E5JH10HzSO5SpLq2FYTUpN8qhZKEutFO1OBUskCwfvtT0qsPBxqJ4/y6CmdGfB3qwXSDRjJs42H5AaqB6puSt0AMgFmXvT+ZzhsVwrkkWfA96W+D18UDxGAJWPhxrseQod2/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387329; 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=rC9oMPrikP1DR4bdlCBP5UvN/gvi04b0BUj4Wu7mpg8=; b=eGzMCX7LmHUwp+8uLc/jzoeH0UEMy4OWLfzUAfdof83+ACEKusYXHqWqg9MD8Y3CJtPlyDtpxkFMiOYkmjN7kjtL+7L7R7vmZPrVRb1Kz2Bn+Bq8evto4X6tRtIEbzD5GnWk4s2ja1wCEqjY692SL7/D1gAshtiqha2u8cLWYmY= 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 1781387329159768.808155959015; Sat, 13 Jun 2026 14:48:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337563.1598927 (Exim 4.92) (envelope-from ) id 1wYWDH-0003zy-JV; Sat, 13 Jun 2026 21:48:23 +0000 Received: by outflank-mailman (output) from mailman id 1337563.1598927; Sat, 13 Jun 2026 21:48: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 1wYWDH-0003zf-AH; Sat, 13 Jun 2026 21:48:23 +0000 Received: by outflank-mailman (input) for mailman id 1337563; Sat, 13 Jun 2026 21:48:21 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDF-0003Np-6T for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:21 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDE-008PGn-JF for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:20 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcfd3-5cb7-0a2a0a5109dd-0a2a450cacfa-38 for ; Sat, 13 Jun 2026 23:48:20 +0200 Received: from [209.85.128.51] (helo=mail-wm1-f51.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd024-62f1-0a2a450c0019-d1558033a9e6-3 for ; Sat, 13 Jun 2026 23:48:20 +0200 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-490bc6a7958so25605155e9.1 for ; Sat, 13 Jun 2026 14:48: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 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387300; x=1781992100; 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=rC9oMPrikP1DR4bdlCBP5UvN/gvi04b0BUj4Wu7mpg8=; b=tKMdMzqCYveqQ3enzFBulLHTraTHTnTPrBmMYNqlWTJ7f1LysP5YLAsy52MffSMZ5i 2Zq9DSutOGZy+Z8eGn62WDE1pC2e1NmXc0KzGehubUpCCT5uqUv0bBpAvQU80+S6zU0X /Gb2WokK8Pk5u4/L6t31uRZw+LHi5cHyXET+Mjzk9gZoBrAPWvk+ayAeJnizD+6q+PFz 4cmz8tquQ/+k7SzuUKK+VNYAVVP3izgk0ODcN9T7llL5x5JesleUkc8rJ9PcHB0IGSrA HA/9Vo0DqzHeptzUcsRxI1Rua42/qpDLJ1578Rw5Rt4ORrBCOuynmJVyI/pqLcrXeKhW vdsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387300; x=1781992100; 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=rC9oMPrikP1DR4bdlCBP5UvN/gvi04b0BUj4Wu7mpg8=; b=gKMiDWZvgNft4kXnlmtnyKjQlvqoX1yHrlvXTTyw0xVtC2VUEeXycdvoFln3deecTT mLaRBCI+YxnxtCDHPmcsBJD898eeFc4SJ0K70nxohFfGLAcYFlLwjysYOE8lvRc2Zydj GTnJamYzwJNE2WExCGpxl0x4+aFI4uQYmEPzYcwEC82xIvusIaiwwZQzq0L8QcU7RX0y 4gZi+4HJXsHij7951nhGkXNCT5x2N6cKaC3kC1r7z67Y8NPq9/Gqd7NIeDLoRyKOR1Gy bkBA1hqjgWXt7x4Z5tmNl+id/GOi0IHtffMt0VfYbLW1hd3uDPiYbpblSMjwbxGHWbDr hXJg== X-Gm-Message-State: AOJu0YwQKo3bpMuLt/8Y6t9A+SiOVghMjO/HVbUDHx6HCWAbfXPoFegw N4xSgBIWuvIJnODSDYdaje96tveqDI5fKDmh0LXFq2FIxhzsCtXICPcL4N3xR+cFe8g= X-Gm-Gg: Acq92OGiGillS3NDren0/wEW5MVZyE8WVmQfSKZq6Hkh2q0AQ6TpRsW5jdS86Q0wA1N ZS2t/AG4p5pZs/eC3ykD+HsyWg8P0smrwBxb1F46HpdUC8vpBKiR1Hyg+TRqETKGvOfpWeO0oli 0XMgiOGDK4OsaLAIQIeQoa3dzyntaNMTrz/sTshlZhuDY1hKXZ5QAZnljO6t6XCqsGLDovyEk0r groWX9pXG9xAkvNcrCanOZSpbk7h5acqyFwisgj43CMwyWmb3QQiPyy1SAKSzZIXj1/23tiR6fQ 03AJUh7GS8j53pfHmbVQQWTlz5+jjjfXM5ZKkFFGbnr/cPAF0LHEK7lR51mfblXnHbmAM7UsNXh ngnyJ/pZ84ybGUJIpFx/ME7pYiF3ORq9hpVdTl8dEUtXKnBzVcUb2Bh1+eWpTanpaMVcYIlxS9t MBe08j02xaPP2cduJsQqMxKfk5+xvbYPaQp+CquNjYDPwW8qBkUrJmkwVgfY1D84Xsj3z62/JUw HvSMElUjUl6HB2ExNN9zK1hPg== X-Received: by 2002:a05:600c:138b:b0:490:5000:917 with SMTP id 5b1f17b1804b1-490ec480f21mr92445035e9.1.1781387299825; Sat, 13 Jun 2026 14:48: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 v5 12/16] xen: implement new foreign copy hypercall Date: Sat, 13 Jun 2026 22:47:45 +0100 Message-ID: <20260613214749.20620-13-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1781387300-E0567CF5-A84C957D/0/0 X-purgate-type: clean X-purgate-size: 6580 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387329969158500 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 -- Changes since v4: - Fix typo in comment; - removed from check. --- xen/common/memory.c | 134 ++++++++++++++++++++++++++++++++++++ xen/include/public/memory.h | 40 ++++++++++- 2 files changed, 173 insertions(+), 1 deletion(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 3672bda025..8e6317d3cf 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1545,6 +1545,133 @@ static int acquire_resource( return rc; } =20 +/* + * The "noinline" qualifier avoids the compiler to create a large function + * consuming quite a lot of stack. + */ +static int noinline mem_foreigncopy( + XEN_GUEST_HANDLE_PARAM(xen_foreigncopy_t) arg) +{ + struct domain *d, *const currd =3D current->domain; + xen_foreigncopy_t copy; + int rc, direction; + + if ( copy_from_guest(©, arg, 1) ) + return -EFAULT; + + if ( copy.flags & ~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; + const unsigned long valid_mask =3D +#ifdef CONFIG_X86 + p2m_to_mask(p2m_ram_rw) | p2m_to_mask(p2m_ram_logdirty); +#else + p2m_to_mask(p2m_ram_rw); +#endif + + foreign_page =3D get_page_from_gfn(d, gfn_list[i], &p2mt, P2M_= ALLOC); + + if ( unlikely(p2m_to_mask(p2mt) & valid_mask) && foreign_page ) + { + put_page(foreign_page); + foreign_page =3D NULL; + } + if ( unlikely(!foreign_page) ) + { + gdprintk(XENLOG_WARNING, + "Error accessing foreign gfn %" PRI_gfn "\n", + gfn_list[i]); + rc =3D -EINVAL; + copy.nr_frames -=3D i; + guest_handle_add_offset(copy.frame_list, i); + goto out; + } + + /* 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 %d copying gfn %" PRI_gfn "\n", + -rc, gfn_list[i]); + copy.nr_frames -=3D i; + guest_handle_add_offset(copy.frame_list, i); + goto out; + } + + guest_handle_add_offset(copy.buffer, PAGE_SIZE); + } + + copy.nr_frames -=3D todo; + guest_handle_add_offset(copy.frame_list, todo); + + if ( copy.nr_frames && hypercall_preempt_check() ) + { + rc =3D hypercall_create_continuation( + __HYPERVISOR_memory_op, "lh", XENMEM_foreigncopy, arg); + goto out; + } + } while ( copy.nr_frames ); + + rc =3D 0; + + out: + rcu_unlock_domain(d); + + /* + * Update in all cases, it allows the caller to know how many + * frames were successfully copied and the continuation to + * continue correctly. + */ + if ( __copy_to_guest(arg, ©, 1) ) + rc =3D -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 +2139,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.43.0 From nobody Thu Jul 23 22:26:19 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=1781387338; cv=none; d=zohomail.com; s=zohoarc; b=YJ0AbWWHovytumoaudJ72vdoanyyTn4A0wtthBbdQVq+eucq+FaL7cdZW1S2jrluGDCATgdyXEtWyKpXudVSc3szDyTb5ZkYpreqvyhrKloyIKGg42BviSKIysma2c7uc6Gphs+SKgs+5ARTFzfWdmzLi5p1KWH2k9FJjkX/HkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387338; 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=+xFs89+81xqcLpzv1mSuMxyfcArrfVpcycWVoWyDSCc=; b=CgDOYkj6twmSlG17aRLaBCipxBGkz/ze9u4yX2B9Sw+Tc0UXGwpvSg3HLJxw4FKYZBbhZe/yWL+l5Mya5lYNkFI6Kk05mHxOYSwJj4zwS2nxCkHCHpaPdxP2hb2KDvgf4Bbrmn+gf2DcgXYpaA6RgJ8iSaKN70phJlyaD8pYWWc= 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 1781387338516419.19336183046266; Sat, 13 Jun 2026 14:48:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337564.1598933 (Exim 4.92) (envelope-from ) id 1wYWDJ-0004Dx-12; Sat, 13 Jun 2026 21:48:25 +0000 Received: by outflank-mailman (output) from mailman id 1337564.1598933; Sat, 13 Jun 2026 21:48:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDI-0004Dd-Mt; Sat, 13 Jun 2026 21:48:24 +0000 Received: by outflank-mailman (input) for mailman id 1337564; Sat, 13 Jun 2026 21:48:22 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDG-0003js-E1 for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:22 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDF-008PGn-RB for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:21 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dd008-5cb7-0a2a0a5109dd-0a2a4503cafc-16 for ; Sat, 13 Jun 2026 23:48:21 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd025-672d-0a2a45030019-d1558030bc9b-3 for ; Sat, 13 Jun 2026 23:48:21 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4921eed3fa2so8258805e9.0 for ; Sat, 13 Jun 2026 14:48: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 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387301; x=1781992101; 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=+xFs89+81xqcLpzv1mSuMxyfcArrfVpcycWVoWyDSCc=; b=HLgR1pOt5nxcJAg99jTP851Ax5l9qVPasjv+G0APOysmYnGOtaZXWZWc0kRzNWFG73 Ta5tyIs7Neek8Jj/bCFDwEoIBjy676kF4E0GRR0s/klRGIeQAIk1V0PRjdfI+t8gDSg4 vZqYjj9242+A7pLaMIm5tjFv5YzxMMj1I6cvYeLRV8YB8KfZOtOrdQrJtKjdRFk7lxRd 3AkVqxUZlU7Z9qW8MYh6CGeDctL1Ofqgjb2e9Q83Ikx2BhF6+L5hAogTfAe5e59kdT8F n+ZpYrOslq+wlLYOJNGWneymtnrE+LSizZ95g2NFNZZ2oV3nmdv17Nz328+3+EMFQ+MM bY9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387301; x=1781992101; 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=+xFs89+81xqcLpzv1mSuMxyfcArrfVpcycWVoWyDSCc=; b=f3qnXKt15hZF3rWHwci4+2aX15MNg9AR50avG/56vcO3wtuM5AlUhY95PWyolm8dy9 VISMjO2zGcfzdCP2fEjtCUhpo+FNU5RZmU6eUN8sCZIrDTB9RgtWbFGW1KN8YvOYn8P6 pg7WK7ugQdOczphpvDJJzOTYTmFUPEkhL+xZWPM0CPK6QUj3TkeIW3mZrZBt/hL3RxgQ fbwKXT8tko3Wy9DeJg4dzTQfyhjsf+936uZYmW14U4rdfT3gAzhwazc8oZCV/3cbwqp1 y6aTQvsgUYV/viT5+/VDCthXSKrSIq3GhrZtQnaOKfhjxmcI4tOTVzVZUPxOsOACpv6f M87w== X-Gm-Message-State: AOJu0YxaOpT4g2cejlKOVlWTLMAoHSyeMTPj6BnETjKFolJs82kkh6jV 8DPIYE1TBRqjsiVcmrOPca7gjBDfvilN1hpiZODXk45TJyzxakout0Cg9D8bYrrG77c= X-Gm-Gg: Acq92OF3k1/MT6dBHsNRAje70A5+6BJmNNmcvhNHZTJoDwJRJE9xzp6zDVmE84id51s CccCiOepHFI5SH7Xb9x4V8VObCIF7LQMDJe2DS++AURuboLVid2qbjKrAHJ38fExybKoxN3XUim EBZfVglwD7tRPFa0QY9gKqhpD8j3HjOlzXzaRkdI9YfCLT1+8HIXI9VPxwAVclE1ai2tnVUntHs 7K34O/3cgCWz5j8+0QE06a/qvxomQzKe/JpTWrdLOZa5Nd6IqmoeGVSLyVCh+ouZR3XtFSxri8O 14biUi3GiTOH80gvImVF+ey6VEGaU+CKAiW/frwb0oQq9+bDK7DJ2DKqx+pTTJcFM+YlsBA6N53 ZnqNjSjnt/RhmxyrIHhIaKZoWzGDV4NIbZO5BpYoW9VynwN+ybVyv3SuIPiIonuc9CyqOoefuyt YN9bprmrSZrtkJ4wEcM5dc9EyLhGB2ixAbg5yJt9643Nh7wfopfWEzcsycbfGpjpbOTi+iTkOnB 0JJXiHx9hTALwbjAfcGMrwDI5Pu4OhBIbvC X-Received: by 2002:a05:600c:e556:20b0:490:b9c3:6c58 with SMTP id 5b1f17b1804b1-490ec4fe879mr74128225e9.16.1781387301227; Sat, 13 Jun 2026 14:48:21 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v5 13/16] privcmd: Add definition for new Linux privcmd to access new Xen hypercall Date: Sat, 13 Jun 2026 22:47:46 +0100 Message-ID: <20260613214749.20620-14-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1781387301-36746938-7B93632F/0/0 X-purgate-type: clean X-purgate-size: 1454 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387339940158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Userspace should use new ioctl to access new hypercall. Signed-off-by: Frediano Ziglio -- Changes since v4: - update comment. --- tools/include/xen-sys/Linux/privcmd.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/include/xen-sys/Linux/privcmd.h b/tools/include/xen-sys/= Linux/privcmd.h index 607dfa2287..7a3c41308b 100644 --- a/tools/include/xen-sys/Linux/privcmd.h +++ b/tools/include/xen-sys/Linux/privcmd.h @@ -100,6 +100,14 @@ typedef struct privcmd_pcidev_get_gsi { __u32 gsi; } privcmd_pcidev_get_gsi_t; =20 +typedef struct privcmd_foreigncopy { + domid_t dom; /* Foreign domain. */ + __u16 dir; /* Direction, 0 from, 1 to. */ + __u32 num; /* Number of pages to copy. */ + const xen_pfn_t __user *pfns; /* Array of pfns. */ + void __user *buffer; /* Buffer to copy to/from. */ +} privcmd_foreigncopy_t; + /* * @cmd: IOCTL_PRIVCMD_HYPERCALL * @arg: &privcmd_hypercall_t @@ -121,6 +129,8 @@ typedef struct privcmd_pcidev_get_gsi { _IOC(_IOC_NONE, 'P', 7, sizeof(privcmd_mmap_resource_t)) #define IOCTL_PRIVCMD_PCIDEV_GET_GSI \ _IOC(_IOC_NONE, 'P', 10, sizeof(privcmd_pcidev_get_gsi_t)) +#define IOCTL_PRIVCMD_FOREIGNCOPY \ + _IOWR('P', 11, privcmd_foreigncopy_t) #define IOCTL_PRIVCMD_UNIMPLEMENTED \ _IOC(_IOC_NONE, 'P', 0xFF, 0) =20 --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387333; cv=none; d=zohomail.com; s=zohoarc; b=bjZt6ZlYsgky5hFyvjjnPOuZwPFfbbH3fsWbD4+asmerL0yETr+fKx98ELeZX9gyLPdilfANmPt8pWuUjz7vBtYREh+0Pff7QrFTJenkK3v8dRhhZAta3mHynfFF8PiFYcz8zq5D472e7JEIEDO5ZA17lvGt7RPzbF4Qc96pf3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387333; 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=yUOm7tCutCPMEp2EsZgFN8Gvb7lSqyzyFNxwcVNzws0=; b=Nrh1sW9jg5r+0eK65iti4Wgvbyf7djRMKiiyesMi6gxOqXvEdQl9VIYbQEmKji1aGPrDLhRXQOqrpfqG2JPc9VJfPLNeNoNsPKcEn05I6A2UvJY4hWuU7NJy5OJee1MlZp71Ud3N4rqF78Gx7LumAlYlkjfAx2j5sVd8lCaOoLE= 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 1781387333541352.43114977122707; Sat, 13 Jun 2026 14:48:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337565.1598938 (Exim 4.92) (envelope-from ) id 1wYWDK-0004Kg-1W; Sat, 13 Jun 2026 21:48:26 +0000 Received: by outflank-mailman (output) from mailman id 1337565.1598938; Sat, 13 Jun 2026 21:48: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 1wYWDJ-0004Il-Cw; Sat, 13 Jun 2026 21:48:25 +0000 Received: by outflank-mailman (input) for mailman id 1337565; Sat, 13 Jun 2026 21:48:24 +0000 Received: from mx.expurgate.net ([194.145.224.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDH-00042b-Rr for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:23 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDH-00DVVl-7z for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:23 +0200 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcf9c-2eae-0a2a0a5409dd-0a2a4507e990-40 for ; Sat, 13 Jun 2026 23:48:23 +0200 Received: from [209.85.128.53] (helo=mail-wm1-f53.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd027-229c-0a2a45070019-d1558035e569-3 for ; Sat, 13 Jun 2026 23:48:23 +0200 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-490b4a8e28bso15449405e9.1 for ; Sat, 13 Jun 2026 14:48: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 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387303; x=1781992103; 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=yUOm7tCutCPMEp2EsZgFN8Gvb7lSqyzyFNxwcVNzws0=; b=sLKnqmgmVih/QFsnNKfwgBRTw+wi/29W5drCCGUD5khgg2QeuDQ/v/C8FS7UdojJAq /FNdC22i6Owd5R1qjgJLj4zv0vwTDmz1pdJd6JJCwUJF3NR/KtSIg58jvpPVoa7ILcgJ IyHZWJzR6/weQIpuW5rPvnEq+um/RViurkvCT1pAcPpUPfbvkbYyt8dfvg15fjwUPVck GGWOmUmKbfhogLOkbCrNv8bKGFUjI82srhGtt4kVwSLquakH2Xl9XUH1p5W8JpbX4vAF KvbrPGfY2ElZvLxYBuTHPbnrUk0vWZ2Z7S7bRL9rPKUI8zj7yoEsK7vMyyrc0x+RzQjD T8jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387303; x=1781992103; 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=yUOm7tCutCPMEp2EsZgFN8Gvb7lSqyzyFNxwcVNzws0=; b=Wxr9Si21gSOu1Hvfm+pvVQgVwFexDh2F4MA4FUhb0j2NSv7vjl+KLGla0qPVmsAGcX YCWOxOCsD+Zv306097eezlNliEGSOvWkrOxalq8Cq7xM+SimGdnnSfge+H2LPa97i5HZ 4ITA2z/hFU/07TO2mDwYMtbc1OmRDpUK4Kym5ADKqr/OtyVAm3rLHQ8cQWsRSfAehGUN 99TuraYwDbsuphlG8WVCLtFonAcUnDmgG2aX7bhYSIZ0SyhwIcuVGuXFzjftcNLdXaFi MbsqfgyhCSSHuJf8lr2ZuEwFiHcm3lpnnz4//4hwaSPXMgH9fOxETqW1eVcTIrn1m4oZ xHpg== X-Gm-Message-State: AOJu0YwIpgp9KZ6QrOZrE/XwmDk4g7xVwTVVNU+JQwkCe1pAt7SrSkNZ GjjMy8iTTYFGteupo9HYzBSfa6QCUDqGOjZw7zf0Nh45wHfCxqTRiJRjKHZnUluXJl8= X-Gm-Gg: Acq92OHrIQoA9frNcoLs0PDYVdEzAMnySVsOgVRg5EupYh9HnaLlbwd7yAIbgi7sVyp w5uqlT3L5cq9WTXaWaaepPi9pUvoLBTIqaLaSsfkywzYVPhsRhN214HKC/GvIEF85y5b1MOmssW JySzMXB5tkc4jMam2R7nC8PIMbPjgZrw6DR/Jo3fTm47FlVq99g6c6+LOuNboSbcjg/gr6u9b5W 0N664vy99cG7wiRwkOA2NdpJdh6cgfinS3tDVHEb4+0ikYVs9rmZ9wsuvPDnNP2UHErpjWUefWq uKq0eFwJG8gyPIhtSlsujyCZua8fh+PkuUEXbOHOdzI7U190OcvpaW4uZFBVQ9vMv2YNp5dl1WO d8vwnBX0FsHSpq/AdnOmLIm2r2Ry1UOBNdKRzN1NPSBdEddDOdWqCZuNhdyp7ppRsjzEia7QAo5 /uZFzPYT1aD1vo+wmJE98LHzdkas6Dv+r9Z4jH3DwNmfbDtjXQB+PrB0fSCxfnJnIpcPYRRM2re BRHIVzG1q7N1jErtaC9XVXLrPo5QNRGkqqx X-Received: by 2002:a05:600c:314a:b0:490:bcc1:4edb with SMTP id 5b1f17b1804b1-490ec504eb5mr92109205e9.27.1781387302615; Sat, 13 Jun 2026 14:48:22 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v5 14/16] libs/guest: use new hypercall if available Date: Sat, 13 Jun 2026 22:47:47 +0100 Message-ID: <20260613214749.20620-15-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1781387303-2236CC48-96F20C25/0/0 X-purgate-type: clean X-purgate-size: 3659 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387333946158500 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 -- Changes since v4: - use int8_t instead of char for signed type. --- tools/libs/guest/xg_sr_common.c | 47 ++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index f760b63548..b26633d95f 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -156,11 +156,6 @@ static void __attribute__((unused)) build_assertions(v= oid) BUILD_BUG_ON(sizeof(struct xc_sr_rec_hvm_params) !=3D 8); } =20 -enum { - foreigncopy_from, - foreigncopy_to -}; - static int xg_foreignmemory_copy(xc_interface *xch, domid_t domid, int dir, size_t nr_pages, void *buffer, const xen_pfn_t foreign_pfns[nr_pages]) @@ -174,8 +169,42 @@ static int xg_foreignmemory_copy(xc_interface *xch, do= mid_t domid, return -1; } =20 + /* + * If foreign copy is supported, -1 not initialized, 0 not supported, + * 1 supported. + */ + static int8_t foreign_copy_supported =3D -1; + + if ( foreign_copy_supported ) + { + int rc; + privcmd_foreigncopy_t copy =3D { + .dom =3D domid, + .dir =3D dir, + .num =3D nr_pages, + .buffer =3D buffer, + }; + DECLARE_HYPERCALL_BOUNCE_IN(foreign_pfns, nr_pages * sizeof(xen_pf= n_t)); + + if ( xc_hypercall_bounce_pre(xch, foreign_pfns) ) + return -1; + + copy.pfns =3D foreign_pfns; + + rc =3D ioctl(xencall_fd(xch->xcall), IOCTL_PRIVCMD_FOREIGNCOPY, &c= opy); + if ( foreign_copy_supported < 0 ) + foreign_copy_supported =3D + (!rc || (errno !=3D ENOTTY && errno !=3D ENOSYS)); + + xc_hypercall_bounce_post(xch, foreign_pfns); + + if ( foreign_copy_supported ) + return rc; + } + + /* Fallback, emulate. */ int err[nr_pages]; - const int prot =3D (dir =3D=3D foreigncopy_from) ? PROT_READ : PROT_RE= AD|PROT_WRITE; + const int prot =3D (dir =3D=3D XENMEM_foreigncopy_from) ? PROT_READ : = PROT_READ|PROT_WRITE; =20 void *p =3D xenforeignmemory_map(xch->fmem, domid, prot, nr_pages, for= eign_pfns, err); if ( !p ) @@ -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.43.0 From nobody Thu Jul 23 22:26:19 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=1781387333; cv=none; d=zohomail.com; s=zohoarc; b=WC6vTX3MsYKjVB0rQzBQqFH6NxmbUiQfKydonVL8zhhjzoZHsLxCyCxY6OocIUl29aCYp9YHUk5jdjiI1MlazG8D9/7iVUsl67k6wAx0NfYD43oq3wNiqSkpPg8pDwZkrXvMk5RSfbiFgH2tc2Gty3QO4LergiN7kjABQwkTNF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387333; 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=ZdUdxNw3V024HIpq9dPJr4uS0iPxLBhpEEH+UqHTafI=; b=QRLOAGJrlAYgSuFJENwzJDP8X4hGM5slQyLyaZZPaf9lWFc2KLzn9IU4JUmo8mv+Am5Rl1jIrVbBIEvKtZ5E1nkjeHIec3bW0iDxq2M4rdCBqIIoDY+OH7ixW4W4/bNx/bvRxXw+ENY4KOI+kihiBCD7eE1tlt8QizUEZWPgMuM= 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 1781387333680865.7741323947962; Sat, 13 Jun 2026 14:48:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337569.1598953 (Exim 4.92) (envelope-from ) id 1wYWDM-0004wT-IT; Sat, 13 Jun 2026 21:48:28 +0000 Received: by outflank-mailman (output) from mailman id 1337569.1598953; Sat, 13 Jun 2026 21:48: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 1wYWDM-0004vI-5D; Sat, 13 Jun 2026 21:48:28 +0000 Received: by outflank-mailman (input) for mailman id 1337569; Sat, 13 Jun 2026 21:48:24 +0000 Received: from mx.expurgate.net ([194.145.224.20]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDI-0004Ay-JM for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:24 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDH-006VOz-Vv for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:23 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dcfc8-e002-0a2a0a5209dd-0a2a4502cc2a-20 for ; Sat, 13 Jun 2026 23:48:23 +0200 Received: from [209.85.128.54] (helo=mail-wm1-f54.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd027-af86-0a2a45020019-d1558036a867-3 for ; Sat, 13 Jun 2026 23:48:23 +0200 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490b8ac62baso23531785e9.0 for ; Sat, 13 Jun 2026 14:48: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 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387303; x=1781992103; 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=ZdUdxNw3V024HIpq9dPJr4uS0iPxLBhpEEH+UqHTafI=; b=DOq1NtEo/ze3rMQy/YfqTj5K5+YXbgAXsQfnfee7DnFXe9HbIbgwo/xJr8Yd6Bf1HI CagomYznlmHL6m/jkjQ5MEV2lWNGOIExLtyI0xLzf6YR1RsuoxEzFE3POFGfCu+20wiy 6056/4fAYq1TlgQOdo75zChIB7Mz+NaOjB0hbVzAA96v9doxP6DLx3tXwesNFQ1B4Z1b q16vK5PIXlF8b5nfTI/o4R1mGaxrCJ7MkusabQqOOgEQw8q+2Sb74A+NDftsGSv+IG1O YI9Zu3HAyrTRDyGd9vfFHmj+AjznN0TV91c7DOuJ7dWOqXuc3cKWWYB86T8Cd4U73rBX pduw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387303; x=1781992103; 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=ZdUdxNw3V024HIpq9dPJr4uS0iPxLBhpEEH+UqHTafI=; b=QoHJHC0ueAxaf3TD33YIwoHSqOAid8J0ybmc4BjfSFA7B3xJSqZ9XKSKUQMzNAyDC+ /nqb2AkpDWL1GVwqsjTFjFXfqMOmgTJXvCsHHeTo3NmButG+eizWlCORf7dY7b4h9HDu z68qkDByWoXwGGdDQOMBH78T3TaXE5Du98rv8I5+c7CWe8OjmAlOYKdcotutXj0z9iW0 VcTNRnBVtszTnwaF5gAAxyCWDFUA/YIM1TCWiJYM8fy4N4GEHHBCi50JOuYBRLIvf5zU C7jU3sgpKRZ6OCq4nCOUmWxqPh5vt5IIdIRA6NpSewhcy4MFXrpB21dwu79qOyor91ja gq/A== X-Gm-Message-State: AOJu0YyY5jxbqWqMpOtYUzOBc7Pi5XK13G6fvqNTWunWkSGRFMCUzpCU hphEna4JXHmrOYW4qH5J67Om2z9cYC8feADM7UeWm/fAP4rWALDkYEcCx7uv5FaWF+4= X-Gm-Gg: Acq92OHkiUZTNA00LWjBlU9av9H8sM7vbSQ9QoMp1PGt2CMNQJvNYETDCQ8hUqelbPM GtkiAkqIUnvBYC0bIEGRf5YbdOsM5SY85fzdRd59gKQl04svW7HpBsqLDhDc7vTfdsn5WwkZ1sN 0Qu6jyznWFeiCAqXINlTpTb9hfyHRfz/x16/J7FXUNfhdcqQ5zDnH9vY5SoaPOK5tgFhdWJWPqb wRUp6qPJmcpjcFRABF3Oe3pemIWjYp8QamGnB0FE1Y16EQUF7iDLYgUt9eTWkw/OiYgQXQzb0Jv FZ98mD+fb3g9wf2lGUGL7JoZnRBmb0++x9rZfb/DK3jX2NaiOB9rAWfGH2i9UA6GHnHX4g6T88g 8hI3iqpVDbe7q2MRHfrp39IUrFuVqtmWI9khXfAXEQ5z80uNXsRmPlAuxTJFB0chKbyjhwwRrRX OkeIekkXCduDUETAykI6LY2gr6GT7elQ21Pph7q9ZGcnVhkJOnkI+EWSP7Pwm1KX0G9EtJzo/JZ H6q537oS44JAx2qDnuyUdR0gw== X-Received: by 2002:a05:600c:5290:b0:490:3cf0:8d81 with SMTP id 5b1f17b1804b1-490ec4dfa14mr80878945e9.13.1781387303319; Sat, 13 Jun 2026 14:48:23 -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 v5 15/16] libs/guest: finalize PoC Date: Sat, 13 Jun 2026 22:47:48 +0100 Message-ID: <20260613214749.20620-16-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1781387303-AA56B161-99C0D3E9/0/0 X-purgate-type: clean X-purgate-size: 10593 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387334041158500 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 | 45 +++++++++++++++-- tools/libs/guest/xg_sr_save.c | 83 +++++++++++++++++++++----------- 3 files changed, 98 insertions(+), 34 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index d8d8a0f9f7..cd562f028a 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -217,7 +217,6 @@ struct xc_sr_context_save_buffers void *local_pages[MAX_BATCH_SIZE]; struct iovec iov[MAX_BATCH_SIZE + 2]; /* Headers + data. */ uint64_t rec_pfns[MAX_BATCH_SIZE]; - int errors[MAX_BATCH_SIZE]; }; =20 struct xc_sr_context @@ -255,8 +254,8 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + xc_hypercall_buffer_t dest_buf; struct xc_sr_context_save_buffers *buffers; - void *dest_buf; } save; =20 struct /* Restore data. */ @@ -267,6 +266,7 @@ struct xc_sr_context int send_back_fd; unsigned long p2m_size; xc_hypercall_buffer_t dirty_bitmap_hbuf; + xc_hypercall_buffer_t verify_buf; =20 /* From Image Header. */ uint32_t format_version; diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index ff27560ff7..b2df36c6f6 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -257,16 +257,15 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, { xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)); - int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; unsigned nr_pages; void *const source =3D page_data; =20 - if ( !mfns || !map_errs ) + if ( !mfns ) { rc =3D -1; ERROR("Failed to allocate %zu bytes to process page data", - count * (sizeof(*mfns) + sizeof(*map_errs))); + count * sizeof(*mfns)); goto err; } =20 @@ -314,13 +313,33 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, if ( rc < 0 ) goto err; } + else + { + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, verify_buf, + &ctx->restore.verify_buf); + + rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, verif= y_buf, mfns); + if ( rc < 0 ) + goto err; + + void *guest_page =3D verify_buf; + page_data =3D source; + for ( unsigned i =3D 0; i < nr_pages; ++i ) + { + /* Verify mode - compare incoming data to what we already have= . */ + if ( memcmp(guest_page, page_data, PAGE_SIZE) ) + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + pfns[i], types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + + guest_page +=3D PAGE_SIZE; + page_data +=3D PAGE_SIZE; + } + } =20 done: rc =3D 0; =20 err: - - free(map_errs); free(mfns); =20 return rc; @@ -710,6 +729,18 @@ static int setup(struct xc_sr_context *ctx) int rc; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->restore.dirty_bitmap_hbuf); + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, verify_buf, + &ctx->restore.verify_buf); + + verify_buf =3D xc_hypercall_buffer_alloc_pages( + xch, verify_buf, MAX_BATCH_SIZE); + + if ( !verify_buf ) + { + ERROR("Unable to allocate memory for test buffer"); + rc =3D -1; + goto err; + } =20 if ( ctx->stream_type =3D=3D XC_STREAM_COLO ) { @@ -758,6 +789,8 @@ static void cleanup(struct xc_sr_context *ctx) unsigned int i; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->restore.dirty_bitmap_hbuf); + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, verify_buf, + &ctx->restore.verify_buf); =20 for ( i =3D 0; i < ctx->restore.buffered_rec_num; i++ ) free(ctx->restore.buffered_records[i].data); @@ -766,6 +799,8 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->restore.p2m_size))= ); =20 + xc_hypercall_buffer_free_pages(xch, verify_buf, MAX_BATCH_SIZE); + free(ctx->restore.buffered_records); free(ctx->restore.populated_pfns); =20 diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 7a48f6b0a3..f6ada3152d 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -88,7 +88,7 @@ static int write_batch(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; void **local_pages; - int *errors, rc =3D -1; + int rc =3D -1; unsigned int i, nr_pages =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; uint64_t *rec_pfns; @@ -108,8 +108,6 @@ static int write_batch(struct xc_sr_context *ctx) mfns =3D ctx->save.buffers->mfns; /* Types of the batch pfns. */ types =3D ctx->save.buffers->types; - /* Errors from attempting to map the gfns. */ - errors =3D ctx->save.buffers->errors; /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D ctx->save.buffers->local_pages; memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); @@ -165,18 +163,54 @@ static int write_batch(struct xc_sr_context *ctx) =20 iovcnt =3D 2; =20 - rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, ctx->save= .dest_buf, mfns); - if ( rc < 0 ) - { - ERROR("xg_foreignmemory_copy_from failed"); - goto err; - } - if ( nr_pages ) { - iov[iovcnt].iov_base =3D ctx->save.dest_buf; - iov[iovcnt].iov_len =3D nr_pages << XC_PAGE_SHIFT; - iovcnt++; + int p; + void *page, *orig_page; + + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, dest_buf, + &ctx->save.dest_buf); + + rc =3D xg_foreignmemory_copy_from(xch, ctx->domid, nr_pages, dest_= buf, mfns); + if ( rc < 0 ) + { + ERROR("xg_foreignmemory_copy_from failed"); + goto err; + } + + for ( i =3D 0, p =3D 0; i < nr_pfns; ++i ) + { + if ( !page_type_has_stream_data(types[i]) ) + continue; + + orig_page =3D page =3D dest_buf + (p * PAGE_SIZE); + rc =3D ctx->save.ops.normalise_page(ctx, types[i], &page); + + if ( orig_page !=3D page ) + local_pages[i] =3D page; + + if ( rc ) + { + if ( rc !=3D -1 || errno !=3D EAGAIN ) + goto err; + + set_bit(ctx->save.batch_pfns[i], ctx->save.deferred_pages); + ++ctx->save.nr_deferred_pages; + types[i] =3D XEN_DOMCTL_PFINFO_XTAB; + --nr_pages; + } + else if ( iov[iovcnt-1].iov_base + iov[iovcnt-1].iov_len =3D= =3D page ) + { + iov[iovcnt-1].iov_len +=3D PAGE_SIZE; + } + else + { + iov[iovcnt].iov_base =3D page; + iov[iovcnt].iov_len =3D PAGE_SIZE; + iovcnt++; + } + ++p; + } } =20 hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -187,6 +221,7 @@ static int write_batch(struct xc_sr_context *ctx) if ( writev_exact(ctx->fd, iov, iovcnt) ) { PERROR("Failed to write page data to stream"); + rc =3D -1; goto err; } =20 @@ -717,30 +752,23 @@ static int setup(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; int rc; - const unsigned dest_buf_len =3D MAX_BATCH_SIZE * XC_PAGE_SIZE; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, dest_buf, + &ctx->save.dest_buf); =20 rc =3D ctx->save.ops.setup(ctx); if ( rc ) goto err; =20 + dest_buf =3D xc_hypercall_buffer_alloc_pages( + xch, dest_buf, MAX_BATCH_SIZE); dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); - ctx->save.dest_buf =3D NULL; - - rc =3D posix_memalign(&ctx->save.dest_buf, XC_PAGE_SIZE, dest_buf_len); - if ( rc ) - { - ERROR("Unable to allocate %u bytes of buffer", dest_buf_len); - errno =3D rc; - rc =3D -1; - goto err; - } =20 - if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) + if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers = || !dest_buf ) { ERROR("Unable to allocate memory for dirty bitmaps, deferred pages" " and various batch buffers"); @@ -761,7 +789,8 @@ static void cleanup(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap, &ctx->save.dirty_bitmap_hbuf); - + DECLARE_HYPERCALL_BUFFER_SHADOW(uint8_t, dest_buf, + &ctx->save.dest_buf); =20 xc_shadow_control(xch, ctx->domid, XEN_DOMCTL_SHADOW_OP_OFF, NULL, 0); @@ -771,9 +800,9 @@ static void cleanup(struct xc_sr_context *ctx) =20 xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); + xc_hypercall_buffer_free_pages(xch, dest_buf, MAX_BATCH_SIZE); free(ctx->save.deferred_pages); free(ctx->save.buffers); - free(ctx->save.dest_buf); } =20 /* --=20 2.43.0 From nobody Thu Jul 23 22:26:19 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=1781387337; cv=none; d=zohomail.com; s=zohoarc; b=FMuzBX5ycGLZnX/OJ0C+8+IY6Qab+WioBwSzYOa7n2QCtxVTJZ2/nnvFoO1SRwM7l9T70CvB6l5VBzIy170tADde+OwautPGFsJdZU9jkFZ3t0Y2uXDs2wAEcCVGXM+kUzl0/QticloWb9FNyT4ryvzOrkC/9jr3O8/D6Kr8/E4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781387337; 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=GO+OrmTMVGaC0OpwuAjvGTXKlxzTulJK0lDq0/wgpGg=; b=Z9mY2gUmJKaxuAncBnxzQ/Qa1zN+H1ENP88V3hnwsCwGeWMPpSPYM027YvPWh07onAl1b8T7b2K6wwc3b++bSSDrzoExaBG5txDDpMwGQFFChap1rws2dkIvQmlYJVwQV/deUaTZu66zherU5e5TafSMwFUUXAEpwsYpMorODk0= 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 1781387337468878.4031763928842; Sat, 13 Jun 2026 14:48:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1337574.1598958 (Exim 4.92) (envelope-from ) id 1wYWDN-00055M-AQ; Sat, 13 Jun 2026 21:48:29 +0000 Received: by outflank-mailman (output) from mailman id 1337574.1598958; Sat, 13 Jun 2026 21:48: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 1wYWDM-00052N-O7; Sat, 13 Jun 2026 21:48:28 +0000 Received: by outflank-mailman (input) for mailman id 1337574; Sat, 13 Jun 2026 21:48:25 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wYWDJ-0004IA-Bw for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 21:48:25 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wYWDI-008PGn-Ox for xen-devel@lists.xenproject.org; Sat, 13 Jun 2026 23:48:24 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a2dd008-5cb7-0a2a0a5109dd-0a2a4503cafc-20 for ; Sat, 13 Jun 2026 23:48:24 +0200 Received: from [209.85.128.47] (helo=mail-wm1-f47.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a2dd028-672d-0a2a45030019-d155802fe467-3 for ; Sat, 13 Jun 2026 23:48:24 +0200 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-490be03d47bso21011915e9.0 for ; Sat, 13 Jun 2026 14:48:24 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-492202edf89sm113877065e9.1.2026.06.13.14.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jun 2026 14:48: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=1781387304; x=1781992104; 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=GO+OrmTMVGaC0OpwuAjvGTXKlxzTulJK0lDq0/wgpGg=; b=VPEbClme/eaWceGZUChmMmSgnNFkgAdbwnIrsDOqW9iWjZJARzL397oL83TlSlEcS/ WF/erNkJvk567/4Ka/mYZYPLVXNhRNBDpVcM8SFyAsxFmZr56t0m1jm4c4dv5d4uIWjH Mr76L7wx4pEfvaAh1GcAikFS5PEHIvBtyAw/fVwzJISQPRYOLQHSx9deJ6n3MJyTfcle hLUgB2QgXyuoyd7pXWGf6DKQA6j1/87s/tT6RlNj4NnBHR+i3Z8TA/D2isGv8LZMVVgT ok61ukHWkJgbPwLsejIi6huX62TAIQ66oNWDJGz9gDKmBocP93MM71jrOJ7xu8YjdDMH zIHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781387304; x=1781992104; 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=GO+OrmTMVGaC0OpwuAjvGTXKlxzTulJK0lDq0/wgpGg=; b=Kpv9KqZ7RCK5sDh0K+ooWiv6qAsVU+JLlH+LXfFJ07hLhnKzInZTiS31d+fxZ+k+YR gUVKR03v/u730x+OBLeLQ8mAAx/xbA/zFfHuiw/S5Qm50BxZOIM+L5ABjjJWG5AWQw8w 1TMtGbRwgKXDJCFlT1PO4lrZvnsPjKGAUioL1xGm/sg6d/E/tgDSbMm14WQWtUdXmc8Y XZKv6yCmiMvqkOI4fIRO5d1GRObk95qz2gDwqALPo7PkG6bIJj9uDLrayNQIRkR551y6 L4SkY+2uJGBzNjE0yXE4uCQMu5OYdZfV3y7Tym3Vv7OsJ441u9Yrhv4/8p8gnRoMME9S Gckw== X-Gm-Message-State: AOJu0YwEVh9u69rjveOWdZyhUmtpTycYuMUSyupjtnZpE3hnb/olFcQQ 0ORfV6et6IvMbNPJwHxbar1R1cB5JUKeWhvJI795fYB60DabXH/yAEYLm6vxq+uaKgs= X-Gm-Gg: Acq92OHf6nLR4sQmP0FOvcPaMjAuLWrnY1mzxiDS+2eIEaCf1ntm3Vl3LroebUlcTu4 1JthL/v0Fs49D/G5G6xvC5Fcgw0ixvBzCsQcTqzqLhl8AuhW7/tFeTyROkyzHL3RxWod5BYhBuh /Q/KFVkUurfEHM4xU2s7jpvroDl0GgkKsNgtNwbosvSJ8Upp/RRh0aXlMf3fln0EUf8s2oZUDIK CLhQ6lN/jt3A4ONWz3zcgSksuN/dAByA+fu0mWx1b7DoKhUSydRUc880l17uYHNHNNiAH4lgoqo 8u/WGAOTUele1zjfOGr4eZo8KyVRnXCsLD8dVgVBWy7jqKGUNuWKvpRT6amcePzSe4aDwkptNcE ijBfDFm8Ugm0u0s7mmen272x0K9ZWkWQ0+UQS4QPUzwJnRVKy11RgjJf/jKGziMLBXU4jEtUwBK VE3cXQanTktf1ybF6/yLuh+P5mkKe1s7K+9uRhoWFS9Lxb8rRgaeDrJDxlbOax/zi+XX0iq87HT AqhxoJLzbO36qpIZgJZHYzsrA== X-Received: by 2002:a05:600c:c177:b0:490:c2a3:3303 with SMTP id 5b1f17b1804b1-490ec51f18dmr104287785e9.34.1781387304042; Sat, 13 Jun 2026 14:48: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 Linux v5 16/16] xen/privcmd: Add new ABI to allow copying foreign memory Date: Sat, 13 Jun 2026 22:47:49 +0100 Message-ID: <20260613214749.20620-17-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260613214749.20620-1-frediano.ziglio@cloud.com> References: <20260613214749.20620-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1781387304-38975938-0D1DB09A/0/0 X-purgate-type: clean X-purgate-size: 5391 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1781387337993158500 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 -- Changes since v4: - fix wrong assign; - use set_xen_guest_handle to set handle; - wrap slow hypercall with xen_preemptible_hcall_{begin,end}; - use _IOWR for ioctl code to be more specific; - use __copy_to_user if buffer already checked. --- arch/x86/include/asm/xen/interface.h | 1 + drivers/xen/privcmd.c | 49 ++++++++++++++++++++++++++++ include/uapi/xen/privcmd.h | 10 ++++++ include/xen/interface/memory.h | 37 ++++++++++++++++++++ 4 files changed, 97 insertions(+) diff --git a/arch/x86/include/asm/xen/interface.h b/arch/x86/include/asm/xe= n/interface.h index a078a2b0f032..bac3c3bc60fd 100644 --- a/arch/x86/include/asm/xen/interface.h +++ b/arch/x86/include/asm/xen/interface.h @@ -91,6 +91,7 @@ DEFINE_GUEST_HANDLE(int); DEFINE_GUEST_HANDLE(void); DEFINE_GUEST_HANDLE(uint64_t); DEFINE_GUEST_HANDLE(uint32_t); +DEFINE_GUEST_HANDLE(uint8_t); DEFINE_GUEST_HANDLE(xen_pfn_t); DEFINE_GUEST_HANDLE(xen_ulong_t); #endif diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 725a49a0eee7..4ae9138dd314 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -1522,6 +1522,51 @@ static inline void privcmd_ioeventfd_exit(void) } #endif /* CONFIG_XEN_PRIVCMD_EVENTFD */ =20 +static long privcmd_ioctl_foreigncopy( + struct file *file, void __user *udata) +{ + const struct privcmd_data *const data =3D file->private_data; + long ret; + struct privcmd_foreigncopy copy; + struct xen_foreigncopy xcopy; + + if (copy_from_user(©, udata, sizeof(copy))) + return -EFAULT; + if (copy.dir & ~1u) + return -EINVAL; + if (copy.num >=3D U32_MAX >> PAGE_SHIFT) + return -EINVAL; + if (!access_ok(copy.pfns, copy.num * sizeof(*copy.pfns))) + return -EFAULT; + if (!access_ok(copy.buffer, copy.num << PAGE_SHIFT)) + return -EFAULT; + + /* If restriction is in place, check the domid matches */ + if (data->domid !=3D DOMID_INVALID && data->domid !=3D copy.dom) + return -EPERM; + + xcopy.domid =3D copy.dom; + xcopy.flags =3D copy.dir; + xcopy.nr_frames =3D copy.num; + set_xen_guest_handle(xcopy.frame_list, (__force xen_pfn_t *)copy.pfns); + set_xen_guest_handle(xcopy.buffer, (__force uint8_t *)copy.buffer); + + xen_preemptible_hcall_begin(); + ret =3D HYPERVISOR_memory_op(XENMEM_foreigncopy, &xcopy); + xen_preemptible_hcall_end(); + + /* copy values back in case of error */ + if (ret) { + copy.num =3D xcopy.nr_frames; + copy.pfns =3D xcopy.frame_list; + copy.buffer =3D xcopy.buffer; + if (__copy_to_user(udata, ©, sizeof(copy))) + ret =3D -EFAULT; + } + + return ret; +} + static long privcmd_ioctl(struct file *file, unsigned int cmd, unsigned long data) { @@ -1569,6 +1614,10 @@ static long privcmd_ioctl(struct file *file, ret =3D privcmd_ioctl_pcidev_get_gsi(file, udata); break; =20 + case IOCTL_PRIVCMD_FOREIGNCOPY: + ret =3D privcmd_ioctl_foreigncopy(file, udata); + break; + default: break; } diff --git a/include/uapi/xen/privcmd.h b/include/uapi/xen/privcmd.h index 8e2c8fd44764..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 \ + _IOWR('P', 11, struct privcmd_foreigncopy) =20 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ diff --git a/include/xen/interface/memory.h b/include/xen/interface/memory.h index 1a371a825c55..5981402fccde 100644 --- a/include/xen/interface/memory.h +++ b/include/xen/interface/memory.h @@ -325,4 +325,41 @@ struct xen_mem_acquire_resource { }; DEFINE_GUEST_HANDLE_STRUCT(xen_mem_acquire_resource); =20 +/* + * Copy memory from/to a given domain. + */ +#define XENMEM_foreigncopy 29 +struct xen_foreigncopy { + /* IN - The domain whose resource is to be copied */ + domid_t domid; + + /* IN - Flags */ +#define XENMEM_foreigncopy_from 0 +#define XENMEM_foreigncopy_to 1 +#define XENMEM_foreigncopy_direction 1 + uint16_t flags; + + /* + * IN + * + * As an IN parameter number of frames of the domain to be copied. + */ + uint32_t nr_frames; + + /* + * IN + * + * Frames to be copied. + */ + GUEST_HANDLE(xen_pfn_t) frame_list; + + /* + * IN/OUT + * + * Userspace buffer to read/write from. + */ + GUEST_HANDLE(uint8_t) buffer; +}; +DEFINE_GUEST_HANDLE_STRUCT(xen_foreigncopy); + #endif /* __XEN_PUBLIC_MEMORY_H__ */ --=20 2.54.0