From nobody Mon Feb 9 18:00:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512642372025352.21889692818013; Thu, 7 Dec 2017 02:26:12 -0800 (PST) Received: from localhost ([::1]:59870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMtNW-0003sE-TN for importer@patchew.org; Thu, 07 Dec 2017 05:26:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMtGP-0005PS-NS for qemu-devel@nongnu.org; Thu, 07 Dec 2017 05:18:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMtGO-0003Qk-Iv for qemu-devel@nongnu.org; Thu, 07 Dec 2017 05:18:45 -0500 Received: from mga06.intel.com ([134.134.136.31]:34562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMtGO-000355-9Y for qemu-devel@nongnu.org; Thu, 07 Dec 2017 05:18:44 -0500 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2017 02:18:44 -0800 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by orsmga007.jf.intel.com with ESMTP; 07 Dec 2017 02:18:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,372,1508828400"; d="scan'208";a="795720" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xenproject.org Date: Thu, 7 Dec 2017 18:18:09 +0800 Message-Id: <20171207101812.23602-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171207101812.23602-1-haozhong.zhang@intel.com> References: <20171207101812.23602-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.31 Subject: [Qemu-devel] [RFC QEMU PATCH v4 07/10] xen-hvm: add functions to copy data from/to HVM memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , Stefano Stabellini , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Paolo Bonzini , Anthony Perard , Chao Peng , Dan Williams , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Haozhong Zhang --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: "Michael S. Tsirkin" --- hw/i386/xen/xen-hvm.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/xen/xen.h | 3 +++ stubs/xen-hvm.c | 10 ++++++++++ 3 files changed, 68 insertions(+) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 3df20ff282..a7e99bd438 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1494,3 +1494,58 @@ void xen_acpi_build(AcpiBuildTables *tables, GArray = *table_offsets, build_rsdt(tables_blob, tables->linker, table_offsets, 0, 0); build_rsdp(tables->rsdp, tables->linker, rsdt); } + +static size_t xen_rw_guest(ram_addr_t gpa, + void *buf, size_t length, bool is_write) +{ + size_t copied =3D 0, size; + ram_addr_t s, e, offset, cur =3D gpa; + xen_pfn_t cur_pfn; + void *page; + int prot =3D is_write ? PROT_WRITE : PROT_READ; + + if (!buf || !length) { + return 0; + } + + s =3D gpa & TARGET_PAGE_MASK; + e =3D gpa + length; + if (e < s) { + return 0; + } + + while (cur < e) { + cur_pfn =3D cur >> TARGET_PAGE_BITS; + offset =3D cur - (cur_pfn << TARGET_PAGE_BITS); + size =3D MIN(length, TARGET_PAGE_SIZE - offset); + + page =3D xenforeignmemory_map(xen_fmem, xen_domid, prot, 1, &cur_p= fn, NULL); + if (!page) { + break; + } + + if (is_write) { + memcpy(page + offset, buf, size); + } else { + memcpy(buf, page + offset, size); + } + xenforeignmemory_unmap(xen_fmem, page, 1); + + copied +=3D size; + buf +=3D size; + cur +=3D size; + length -=3D size; + } + + return copied; +} + +size_t xen_copy_to_guest(ram_addr_t gpa, void *buf, size_t length) +{ + return xen_rw_guest(gpa, buf, length, true); +} + +size_t xen_copy_from_guest(ram_addr_t gpa, void *buf, size_t length) +{ + return xen_rw_guest(gpa, buf, length, false); +} diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index 2785b8fd35..cc40d45aeb 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -52,4 +52,7 @@ void xen_register_framebuffer(struct MemoryRegion *mr); void xen_acpi_build(AcpiBuildTables *tables, GArray *table_offsets, MachineState *machine); =20 +size_t xen_copy_to_guest(ram_addr_t gpa, void *buf, size_t length); +size_t xen_copy_from_guest(ram_addr_t gpa, void *buf, size_t length); + #endif /* QEMU_HW_XEN_H */ diff --git a/stubs/xen-hvm.c b/stubs/xen-hvm.c index 58017c1457..5de02842a3 100644 --- a/stubs/xen-hvm.c +++ b/stubs/xen-hvm.c @@ -66,3 +66,13 @@ void xen_acpi_build(AcpiBuildTables *tables, GArray *tab= le_offsets, MachineState *machine) { } + +size_t xen_copy_to_guest(ram_addr_t gpa, void *buf, size_t length) +{ + return 0; +} + +size_t xen_copy_from_guest(ram_addr_t gpa, void *buf, size_t length) +{ + return 0; +} --=20 2.15.1