From nobody Wed May 1 18:00:30 2024 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 1505105063606173.5956393778689; Sun, 10 Sep 2017 21:44:23 -0700 (PDT) Received: from localhost ([::1]:55355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGa5-00021v-QR for importer@patchew.org; Mon, 11 Sep 2017 00:44:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGY5-0000ry-1o for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGY1-0004VC-3k for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:52456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGY0-0004Si-QQ for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:13 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:07 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079070" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:48 +0800 Message-Id: <20170911044157.15403-2-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 01/10] nvdimm: do not intiailize nvdimm->label_data if label size is zero 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 , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Igor Mammedov , Chao Peng , Dan Williams 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" The memory region of vNVDIMM on Xen is a RAM memory region, so memory_region_get_ram_ptr() cannot be used in nvdimm_realize() to get a pointer to the label data area in that region. To be worse, it may abort QEMU. As Xen currently does not support labels (i.e. label size is 0) and every access in QEMU to labels is led by a label size check, let's not intiailize nvdimm->label_data if the label size is 0. Signed-off-by: Haozhong Zhang --- Cc: Xiao Guangrong Cc: "Michael S. Tsirkin" Cc: Igor Mammedov --- hw/mem/nvdimm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 952fce5ec8..3e58538b99 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -87,7 +87,15 @@ static void nvdimm_realize(PCDIMMDevice *dimm, Error **e= rrp) align =3D memory_region_get_alignment(mr); =20 pmem_size =3D size - nvdimm->label_size; - nvdimm->label_data =3D memory_region_get_ram_ptr(mr) + pmem_size; + /* + * The memory region of vNVDIMM on Xen is not a RAM memory region, + * so memory_region_get_ram_ptr() below will abort QEMU. In + * addition that Xen currently does not support vNVDIMM labels + * (i.e. label_size is zero here), let's not initialize of the + * pointer to label data if the label size is zero. + */ + if (nvdimm->label_size) + nvdimm->label_data =3D memory_region_get_ram_ptr(mr) + pmem_size; pmem_size =3D QEMU_ALIGN_DOWN(pmem_size, align); =20 if (size <=3D nvdimm->label_size || !pmem_size) { --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105063617807.4762794291311; Sun, 10 Sep 2017 21:44:23 -0700 (PDT) Received: from localhost ([::1]:55356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGa6-00022f-BN for importer@patchew.org; Mon, 11 Sep 2017 00:44:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGY5-0000rv-1D for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGY1-0004VO-82 for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGY0-0004UV-Sk for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:13 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:11 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079098" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:49 +0800 Message-Id: <20170911044157.15403-3-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 02/10] hw/xen-hvm: create the hotplug memory region on Xen 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" The guest physical address of vNVDIMM is allocated from the hotplug memory region, which is not created when QEMU is used as Xen device model. In order to use vNVDIMM for Xen HVM domains, this commit reuses the code for pc machine type to create the hotplug memory region for Xen HVM domains. Signed-off-by: Haozhong Zhang --- Cc: Paolo Bonzini Cc: Richard Henderson CC: Eduardo Habkost Cc: "Michael S. Tsirkin" Cc: Stefano Stabellini Cc: Anthony Perard --- hw/i386/pc.c | 86 ++++++++++++++++++++++++++++-------------------= ---- hw/i386/xen/xen-hvm.c | 2 ++ include/hw/i386/pc.h | 1 + 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 21081041d5..5cbdce61a7 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1347,6 +1347,53 @@ void xen_load_linux(PCMachineState *pcms) pcms->fw_cfg =3D fw_cfg; } =20 +void pc_memory_hotplug_init(PCMachineState *pcms, MemoryRegion *system_mem= ory) +{ + MachineState *machine =3D MACHINE(pcms); + PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); + ram_addr_t hotplug_mem_size =3D machine->maxram_size - machine->ram_si= ze; + + if (!pcmc->has_reserved_memory || machine->ram_size >=3D machine->maxr= am_size) + return; + + if (memory_region_size(&pcms->hotplug_memory.mr)) { + error_report("hotplug memory region has been initialized"); + exit(EXIT_FAILURE); + } + + if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { + error_report("unsupported amount of memory slots: %"PRIu64, + machine->ram_slots); + exit(EXIT_FAILURE); + } + + if (QEMU_ALIGN_UP(machine->maxram_size, + TARGET_PAGE_SIZE) !=3D machine->maxram_size) { + error_report("maximum memory size must by aligned to multiple of " + "%d bytes", TARGET_PAGE_SIZE); + exit(EXIT_FAILURE); + } + + pcms->hotplug_memory.base =3D + ROUND_UP(0x100000000ULL + pcms->above_4g_mem_size, 1ULL << 30); + + if (pcmc->enforce_aligned_dimm) { + /* size hotplug region assuming 1G page max alignment per slot */ + hotplug_mem_size +=3D (1ULL << 30) * machine->ram_slots; + } + + if ((pcms->hotplug_memory.base + hotplug_mem_size) < hotplug_mem_size)= { + error_report("unsupported amount of maximum memory: " RAM_ADDR_FMT, + machine->maxram_size); + exit(EXIT_FAILURE); + } + + memory_region_init(&pcms->hotplug_memory.mr, OBJECT(pcms), + "hotplug-memory", hotplug_mem_size); + memory_region_add_subregion(system_memory, pcms->hotplug_memory.base, + &pcms->hotplug_memory.mr); +} + void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, @@ -1398,44 +1445,7 @@ void pc_memory_init(PCMachineState *pcms, } =20 /* initialize hotplug memory address space */ - if (pcmc->has_reserved_memory && - (machine->ram_size < machine->maxram_size)) { - ram_addr_t hotplug_mem_size =3D - machine->maxram_size - machine->ram_size; - - if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { - error_report("unsupported amount of memory slots: %"PRIu64, - machine->ram_slots); - exit(EXIT_FAILURE); - } - - if (QEMU_ALIGN_UP(machine->maxram_size, - TARGET_PAGE_SIZE) !=3D machine->maxram_size) { - error_report("maximum memory size must by aligned to multiple = of " - "%d bytes", TARGET_PAGE_SIZE); - exit(EXIT_FAILURE); - } - - pcms->hotplug_memory.base =3D - ROUND_UP(0x100000000ULL + pcms->above_4g_mem_size, 1ULL << 30); - - if (pcmc->enforce_aligned_dimm) { - /* size hotplug region assuming 1G page max alignment per slot= */ - hotplug_mem_size +=3D (1ULL << 30) * machine->ram_slots; - } - - if ((pcms->hotplug_memory.base + hotplug_mem_size) < - hotplug_mem_size) { - error_report("unsupported amount of maximum memory: " RAM_ADDR= _FMT, - machine->maxram_size); - exit(EXIT_FAILURE); - } - - memory_region_init(&pcms->hotplug_memory.mr, OBJECT(pcms), - "hotplug-memory", hotplug_mem_size); - memory_region_add_subregion(system_memory, pcms->hotplug_memory.ba= se, - &pcms->hotplug_memory.mr); - } + pc_memory_hotplug_init(pcms, system_memory); =20 /* Initialize PC system firmware */ pc_system_firmware_init(rom_memory, !pcmc->pci_enabled); diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index d9ccd5d0d6..90163e1a1b 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -235,6 +235,8 @@ static void xen_ram_init(PCMachineState *pcms, pcms->above_4g_mem_size); memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi); } + + pc_memory_hotplug_init(pcms, sysmem); } =20 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 8226904524..b65c5dd5ec 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -249,6 +249,7 @@ void pc_memory_init(PCMachineState *pcms, MemoryRegion *system_memory, MemoryRegion *rom_memory, MemoryRegion **ram_memory); +void pc_memory_hotplug_init(PCMachineState *pcms, MemoryRegion *system_mem= ory); qemu_irq pc_allocate_cpu_irq(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105063621211.20349170957036; Sun, 10 Sep 2017 21:44:23 -0700 (PDT) Received: from localhost ([::1]:55357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGa5-00022m-DZ for importer@patchew.org; Mon, 11 Sep 2017 00:44:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGY5-0000rx-1b for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGY2-0004W3-FJ for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGY2-0004UV-2W for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:14 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:13 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079110" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:50 +0800 Message-Id: <20170911044157.15403-4-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 03/10] hostmem-xen: add a host memory backend for Xen 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 , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Igor Mammedov , Chao Peng , Dan Williams 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" vNVDIMM requires a host memory backend to allocate its backend resources to the guest. When QEMU is used as Xen device model, the backend resource allocation of vNVDIMM is managed out of QEMU. A new host memory backend 'memory-backend-xen' is introduced to represent the backend resource allocated by Xen. It simply creates a memory region of the specified size as a placeholder in the guest address space, which will be mapped by Xen to the actual backend resource. Following example QEMU options create a vNVDIMM device backed by a 4GB host PMEM region at host physical address 0x100000000: -object memory-backend-xen,id=3Dmem1,host-addr=3D0x100000000,size=3D4G -device nvdimm,id=3Dnvdimm1,memdev=3Dmem1 Signed-off-by: Haozhong Zhang --- Cc: Eduardo Habkost Cc: Igor Mammedov Cc: "Michael S. Tsirkin" --- backends/Makefile.objs | 1 + backends/hostmem-xen.c | 108 +++++++++++++++++++++++++++++++++++++++++++++= ++++ backends/hostmem.c | 9 +++++ hw/mem/pc-dimm.c | 6 ++- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 backends/hostmem-xen.c diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 0400799efd..3096fde21f 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -5,6 +5,7 @@ common-obj-$(CONFIG_TPM) +=3D tpm.o =20 common-obj-y +=3D hostmem.o hostmem-ram.o common-obj-$(CONFIG_LINUX) +=3D hostmem-file.o +common-obj-${CONFIG_XEN_BACKEND} +=3D hostmem-xen.o =20 common-obj-y +=3D cryptodev.o common-obj-y +=3D cryptodev-builtin.o diff --git a/backends/hostmem-xen.c b/backends/hostmem-xen.c new file mode 100644 index 0000000000..99211efd81 --- /dev/null +++ b/backends/hostmem-xen.c @@ -0,0 +1,108 @@ +/* + * QEMU Host Memory Backend for Xen + * + * Copyright(C) 2017 Intel Corporation. + * + * Author: + * Haozhong Zhang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "sysemu/hostmem.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" + +#define TYPE_MEMORY_BACKEND_XEN "memory-backend-xen" + +#define MEMORY_BACKEND_XEN(obj) \ + OBJECT_CHECK(HostMemoryBackendXen, (obj), TYPE_MEMORY_BACKEND_XEN) + +typedef struct HostMemoryBackendXen HostMemoryBackendXen; + +struct HostMemoryBackendXen { + HostMemoryBackend parent_obj; + + uint64_t host_addr; +}; + +static void xen_backend_get_host_addr(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + HostMemoryBackendXen *backend =3D MEMORY_BACKEND_XEN(obj); + uint64_t value =3D backend->host_addr; + + visit_type_size(v, name, &value, errp); +} + +static void xen_backend_set_host_addr(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + HostMemoryBackendXen *xb =3D MEMORY_BACKEND_XEN(obj); + Error *local_err =3D NULL; + uint64_t value; + + if (memory_region_size(&backend->mr)) { + error_setg(&local_err, "cannot change property value"); + goto out; + } + + visit_type_size(v, name, &value, &local_err); + if (local_err) { + goto out; + } + xb->host_addr =3D value; + + out: + error_propagate(errp, local_err); +} + +static void xen_backend_alloc(HostMemoryBackend *backend, Error **errp) +{ + if (!backend->size) { + error_setg(errp, "can't create backend with size 0"); + return; + } + memory_region_init(&backend->mr, OBJECT(backend), "hostmem-xen", + backend->size); + backend->mr.align =3D getpagesize(); +} + +static void xen_backend_class_init(ObjectClass *oc, void *data) +{ + HostMemoryBackendClass *bc =3D MEMORY_BACKEND_CLASS(oc); + + bc->alloc =3D xen_backend_alloc; + + object_class_property_add(oc, "host-addr", "int", + xen_backend_get_host_addr, + xen_backend_set_host_addr, + NULL, NULL, &error_abort); +} + +static const TypeInfo xen_backend_info =3D { + .name =3D TYPE_MEMORY_BACKEND_XEN, + .parent =3D TYPE_MEMORY_BACKEND, + .class_init =3D xen_backend_class_init, + .instance_size =3D sizeof(HostMemoryBackendXen), +}; + +static void register_types(void) +{ + type_register_static(&xen_backend_info); +} + +type_init(register_types); diff --git a/backends/hostmem.c b/backends/hostmem.c index ee2c2d5bfd..ba13a52994 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "sysemu/hostmem.h" #include "hw/boards.h" +#include "hw/xen/xen.h" #include "qapi/error.h" #include "qapi/visitor.h" #include "qapi-types.h" @@ -277,6 +278,14 @@ host_memory_backend_memory_complete(UserCreatable *uc,= Error **errp) goto out; } =20 + /* + * The backend storage of MEMORY_BACKEND_XEN is managed by Xen, + * so no further work in this function is needed. + */ + if (xen_enabled() && !backend->mr.ram_block) { + goto out; + } + ptr =3D memory_region_get_ram_ptr(&backend->mr); sz =3D memory_region_size(&backend->mr); =20 diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index bdf6649083..7e1fe005ee 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -28,6 +28,7 @@ #include "sysemu/kvm.h" #include "trace.h" #include "hw/virtio/vhost.h" +#include "hw/xen/xen.h" =20 typedef struct pc_dimms_capacity { uint64_t size; @@ -108,7 +109,10 @@ void pc_dimm_memory_plug(DeviceState *dev, MemoryHotpl= ugState *hpms, } =20 memory_region_add_subregion(&hpms->mr, addr - hpms->base, mr); - vmstate_register_ram(vmstate_mr, dev); + /* memory-backend-xen is not backed by RAM. */ + if (!xen_enabled()) { + vmstate_register_ram(vmstate_mr, dev); + } numa_set_mem_node_id(addr, memory_region_size(mr), dimm->node); =20 out: --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105211134294.69618696198825; Sun, 10 Sep 2017 21:46:51 -0700 (PDT) Received: from localhost ([::1]:55373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGcU-0004Eb-93 for importer@patchew.org; Mon, 11 Sep 2017 00:46:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGY5-0000s1-T5 for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGY4-0004X7-WF for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGY4-0004UV-Lj for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:16 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:16 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079121" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:51 +0800 Message-Id: <20170911044157.15403-5-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 04/10] nvdimm acpi: do not use fw_cfg on Xen 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 , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Igor Mammedov , Chao Peng , Dan Williams 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" Xen relies on QEMU to build guest ACPI for NVDIMM. However, no fw_cfg is created when QEMU is used as Xen device model, so QEMU should avoid using fw_cfg on Xen. Signed-off-by: Haozhong Zhang --- Cc: Xiao Guangrong Cc: "Michael S. Tsirkin" Cc: Igor Mammedov --- hw/acpi/nvdimm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 6ceea196e7..9121a766c6 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -32,6 +32,7 @@ #include "hw/acpi/bios-linker-loader.h" #include "hw/nvram/fw_cfg.h" #include "hw/mem/nvdimm.h" +#include "hw/xen/xen.h" =20 static int nvdimm_device_list(Object *obj, void *opaque) { @@ -890,8 +891,12 @@ void nvdimm_init_acpi_state(AcpiNVDIMMState *state, Me= moryRegion *io, =20 state->dsm_mem =3D g_array_new(false, true /* clear */, 1); acpi_data_push(state->dsm_mem, sizeof(NvdimmDsmIn)); - fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data, - state->dsm_mem->len); + + /* No fw_cfg is created when QEMU is used as Xen device model. */ + if (!xen_enabled()) { + fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data, + state->dsm_mem->len); + } =20 nvdimm_init_fit_buffer(&state->fit_buf); } --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105344570660.1027031754195; Sun, 10 Sep 2017 21:49:04 -0700 (PDT) Received: from localhost ([::1]:55381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGed-0006CT-Sa for importer@patchew.org; Mon, 11 Sep 2017 00:49:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGY9-0000ub-7f for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGY8-0004YZ-7g for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:21 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGY7-0004UV-Ug for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:20 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:19 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079132" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:52 +0800 Message-Id: <20170911044157.15403-6-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 05/10] hw/xen-hvm: initialize DM ACPI 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" Probe the base address and the length of guest ACPI buffer reserved for copying ACPI from QEMU. Signed-off-by: Haozhong Zhang --- Cc: Stefano Stabellini cc: Anthony Perard Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost --- hw/i386/xen/xen-hvm.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 66 insertions(+) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 90163e1a1b..ae895aaf03 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -18,6 +18,7 @@ #include "hw/xen/xen_backend.h" #include "qmp-commands.h" =20 +#include "qemu/cutils.h" #include "qemu/error-report.h" #include "qemu/range.h" #include "sysemu/xen-mapcache.h" @@ -86,6 +87,18 @@ typedef struct XenPhysmap { QLIST_ENTRY(XenPhysmap) list; } XenPhysmap; =20 +#define HVM_XS_DM_ACPI_ROOT "/hvmloader/dm-acpi" +#define HVM_XS_DM_ACPI_ADDRESS HVM_XS_DM_ACPI_ROOT"/address" +#define HVM_XS_DM_ACPI_LENGTH HVM_XS_DM_ACPI_ROOT"/length" + +typedef struct XenAcpiBuf { + ram_addr_t base; + ram_addr_t length; + ram_addr_t used; +} XenAcpiBuf; + +static XenAcpiBuf *dm_acpi_buf; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page; @@ -110,6 +123,8 @@ typedef struct XenIOState { hwaddr free_phys_offset; const XenPhysmap *log_for_dirtybit; =20 + XenAcpiBuf dm_acpi_buf; + Notifier exit; Notifier suspend; Notifier wakeup; @@ -1234,6 +1249,52 @@ static void xen_wakeup_notifier(Notifier *notifier, = void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } =20 +static int xen_dm_acpi_needed(PCMachineState *pcms) +{ + return 0; +} + +static int dm_acpi_buf_init(XenIOState *state) +{ + char path[80], *value; + unsigned int len; + + dm_acpi_buf =3D &state->dm_acpi_buf; + + snprintf(path, sizeof(path), + "/local/domain/%d"HVM_XS_DM_ACPI_ADDRESS, xen_domid); + value =3D xs_read(state->xenstore, 0, path, &len); + if (!value) { + return -EINVAL; + } + if (qemu_strtoul(value, NULL, 16, &dm_acpi_buf->base)) { + return -EINVAL; + } + + snprintf(path, sizeof(path), + "/local/domain/%d"HVM_XS_DM_ACPI_LENGTH, xen_domid); + value =3D xs_read(state->xenstore, 0, path, &len); + if (!value) { + return -EINVAL; + } + if (qemu_strtoul(value, NULL, 16, &dm_acpi_buf->length)) { + return -EINVAL; + } + + dm_acpi_buf->used =3D 0; + + return 0; +} + +static int xen_dm_acpi_init(PCMachineState *pcms, XenIOState *state) +{ + if (!xen_dm_acpi_needed(pcms)) { + return 0; + } + + return dm_acpi_buf_init(state); +} + void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) { int i, rc; @@ -1385,6 +1446,11 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion= **ram_memory) /* Disable ACPI build because Xen handles it */ pcms->acpi_build_enabled =3D false; =20 + if (xen_dm_acpi_init(pcms, state)) { + error_report("failed to initialize xen ACPI"); + goto err; + } + return; =20 err: --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105343472256.03547102755965; Sun, 10 Sep 2017 21:49:03 -0700 (PDT) Received: from localhost ([::1]:55380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGec-0006Bh-Nt for importer@patchew.org; Mon, 11 Sep 2017 00:49:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGYE-0000xs-Sd for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGYA-0004Ze-U9 for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:26 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGYA-0004UV-KI for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:22 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:22 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079145" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:53 +0800 Message-Id: <20170911044157.15403-7-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 06/10] hw/xen-hvm: add function to copy ACPI into guest 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" Xen relies on QEMU to build guest NFIT and NVDIMM namespace devices, and implements an interface to allow QEMU to copy its ACPI into guest memory. This commit implements the QEMU side support. The location of guest memory that can receive QEMU ACPI can be found from XenStore entries /local/domain/$dom_id/hvmloader/dm-acpi/{address,leng= th}, which have been handled by previous commit. QEMU ACPI copied to guest is organized in blobs. For each blob, QEMU creates following XenStore entries under /local/domain/$dom_id/hvmloader/dm-acpi/$name to indicate its type, location in above guest memory region and size. - type the type of the passed ACPI, which can be the following values. * XEN_DM_ACPI_BLOB_TYPE_TABLE (0) indicates it's a complete ACPI table, and its signature is indicated by $name in the XenStore path. * XEN_DM_ACPI_BLOB_TYPE_NSDEV (1) indicates it's the body of a namespace device, and its device name is indicated by $name in the XenStore path. - offset offset in byte from the beginning of above guest memory region - length size in byte of the copied ACPI Signed-off-by: Haozhong Zhang --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost --- hw/i386/xen/xen-hvm.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/xen/xen.h | 18 ++++++++ stubs/xen-hvm.c | 6 +++ 3 files changed, 137 insertions(+) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index ae895aaf03..b74c4ffb9c 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -1286,6 +1286,20 @@ static int dm_acpi_buf_init(XenIOState *state) return 0; } =20 +static ram_addr_t dm_acpi_buf_alloc(size_t length) +{ + ram_addr_t addr; + + if (dm_acpi_buf->length - dm_acpi_buf->used < length) { + return 0; + } + + addr =3D dm_acpi_buf->base + dm_acpi_buf->used; + dm_acpi_buf->used +=3D length; + + return addr; +} + static int xen_dm_acpi_init(PCMachineState *pcms, XenIOState *state) { if (!xen_dm_acpi_needed(pcms)) { @@ -1295,6 +1309,105 @@ static int xen_dm_acpi_init(PCMachineState *pcms, X= enIOState *state) return dm_acpi_buf_init(state); } =20 +static int xs_write_dm_acpi_blob_entry(const char *name, + const char *entry, const char *valu= e) +{ + XenIOState *state =3D container_of(dm_acpi_buf, XenIOState, dm_acpi_bu= f); + char path[80]; + + snprintf(path, sizeof(path), + "/local/domain/%d"HVM_XS_DM_ACPI_ROOT"/%s/%s", + xen_domid, name, entry); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -EIO; + } + + return 0; +} + +static size_t xen_memcpy_to_guest(ram_addr_t gpa, + const void *buf, size_t length) +{ + size_t copied =3D 0, size; + ram_addr_t s, e, offset, cur =3D gpa; + xen_pfn_t cur_pfn; + void *page; + + 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 (length >=3D TARGET_PAGE_SIZE - offset) ? + TARGET_PAGE_SIZE - offset : length; + + page =3D xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ | PRO= T_WRITE, + 1, &cur_pfn, NULL); + if (!page) { + break; + } + + memcpy(page + offset, buf, size); + xenforeignmemory_unmap(xen_fmem, page, 1); + + copied +=3D size; + buf +=3D size; + cur +=3D size; + length -=3D size; + } + + return copied; +} + +int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, + int type) +{ + char value[21]; + ram_addr_t buf_addr; + int rc; + + if (type !=3D XEN_DM_ACPI_BLOB_TYPE_TABLE && + type !=3D XEN_DM_ACPI_BLOB_TYPE_NSDEV) { + return -EINVAL; + } + + buf_addr =3D dm_acpi_buf_alloc(length); + if (!buf_addr) { + return -ENOMEM; + } + if (xen_memcpy_to_guest(buf_addr, blob, length) !=3D length) { + return -EIO; + } + + snprintf(value, sizeof(value), "%d", type); + rc =3D xs_write_dm_acpi_blob_entry(name, "type", value); + if (rc) { + return rc; + } + + snprintf(value, sizeof(value), "%"PRIu64, buf_addr - dm_acpi_buf->base= ); + rc =3D xs_write_dm_acpi_blob_entry(name, "offset", value); + if (rc) { + return rc; + } + + snprintf(value, sizeof(value), "%"PRIu64, length); + rc =3D xs_write_dm_acpi_blob_entry(name, "length", value); + if (rc) { + return rc; + } + + return 0; +} + void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) { int i, rc; diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index 7efcdaa8fe..38dcd1a7d4 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -48,4 +48,22 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_= t length); =20 void xen_register_framebuffer(struct MemoryRegion *mr); =20 +/* + * Copy an ACPI blob from QEMU to HVM guest. + * + * Parameters: + * name: a unique name of the data blob; for XEN_DM_ACPI_BLOB_TYPE_NSDE= V, + * name should be less then 4 characters + * blob: the ACPI blob to be copied + * length: the length in bytes of the ACPI blob + * type: the type of content in the ACPI blob, one of XEN_DM_ACPI_BLOB_= TYPE_* + * + * Return: + * 0 on success; a non-zero error code on failures. + */ +#define XEN_DM_ACPI_BLOB_TYPE_TABLE 0 /* ACPI table */ +#define XEN_DM_ACPI_BLOB_TYPE_NSDEV 1 /* AML of ACPI namespace device */ +int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, + int type); + #endif /* QEMU_HW_XEN_H */ diff --git a/stubs/xen-hvm.c b/stubs/xen-hvm.c index 3ca6c51b21..58889ae0fb 100644 --- a/stubs/xen-hvm.c +++ b/stubs/xen-hvm.c @@ -61,3 +61,9 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ra= m_memory) void qmp_xen_set_global_dirty_log(bool enable, Error **errp) { } + +int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, + int type) +{ + return -1; +} --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105209943818.9529056011546; Sun, 10 Sep 2017 21:46:49 -0700 (PDT) Received: from localhost ([::1]:55372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGcT-0004Cr-50 for importer@patchew.org; Mon, 11 Sep 2017 00:46:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGYE-0000xu-TZ for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGYD-0004ak-GT for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:26 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGYD-0004UV-7r for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:25 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:24 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079153" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:54 +0800 Message-Id: <20170911044157.15403-8-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 07/10] nvdimm acpi: copy NFIT to Xen guest 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 , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Igor Mammedov , Chao Peng , Dan Williams 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" Xen relies on QEMU to build the guest NFIT. Signed-off-by: Haozhong Zhang --- Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Xiao Guangrong --- hw/acpi/nvdimm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 9121a766c6..d9cdc5a531 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -404,6 +404,12 @@ static void nvdimm_build_nfit(AcpiNVDIMMState *state, = GArray *table_offsets, build_header(linker, table_data, (void *)(table_data->data + header), "NFIT", sizeof(NvdimmNfitHeader) + fit_buf->fit->len, 1, NULL, NU= LL); + + if (xen_enabled()) { + xen_acpi_copy_to_guest("NFIT", table_data->data + header, + sizeof(NvdimmNfitHeader) + fit_buf->fit->le= n, + XEN_DM_ACPI_BLOB_TYPE_TABLE); + } } =20 #define NVDIMM_DSM_MEMORY_SIZE 4096 --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105074150193.8972778846163; Sun, 10 Sep 2017 21:44:34 -0700 (PDT) Received: from localhost ([::1]:55358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGaH-0002DC-Cc for importer@patchew.org; Mon, 11 Sep 2017 00:44:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGYH-000101-6t for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGYG-0004bx-9M for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:29 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGYF-0004UV-Uj for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:28 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:27 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079161" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:55 +0800 Message-Id: <20170911044157.15403-9-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 08/10] nvdimm acpi: copy ACPI namespace device of vNVDIMM to Xen guest 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 , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Igor Mammedov , Chao Peng , Dan Williams 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" Xen relies on QEMU to build the ACPI namespace device of vNVDIMM for Xen guest. Signed-off-by: Haozhong Zhang --- Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Xiao Guangrong --- hw/acpi/nvdimm.c | 55 ++++++++++++++++++++++++++++++++++++++--------------= --- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index d9cdc5a531..bf887512ad 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -1226,22 +1226,8 @@ static void nvdimm_build_nvdimm_devices(Aml *root_de= v, uint32_t ram_slots) } } =20 -static void nvdimm_build_ssdt(GArray *table_offsets, GArray *table_data, - BIOSLinker *linker, GArray *dsm_dma_arrea, - uint32_t ram_slots) +static void nvdimm_build_ssdt_device(Aml *dev, uint32_t ram_slots) { - Aml *ssdt, *sb_scope, *dev; - int mem_addr_offset, nvdimm_ssdt; - - acpi_add_table(table_offsets, table_data); - - ssdt =3D init_aml_allocator(); - acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); - - sb_scope =3D aml_scope("\\_SB"); - - dev =3D aml_device("NVDR"); - /* * ACPI 6.0: 9.20 NVDIMM Devices: * @@ -1262,6 +1248,25 @@ static void nvdimm_build_ssdt(GArray *table_offsets,= GArray *table_data, nvdimm_build_fit(dev); =20 nvdimm_build_nvdimm_devices(dev, ram_slots); +} + +static void nvdimm_build_ssdt(GArray *table_offsets, GArray *table_data, + BIOSLinker *linker, GArray *dsm_dma_arrea, + uint32_t ram_slots) +{ + Aml *ssdt, *sb_scope, *dev; + int mem_addr_offset, nvdimm_ssdt; + + acpi_add_table(table_offsets, table_data); + + ssdt =3D init_aml_allocator(); + acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); + + sb_scope =3D aml_scope("\\_SB"); + + dev =3D aml_device("NVDR"); + + nvdimm_build_ssdt_device(dev, ram_slots); =20 aml_append(sb_scope, dev); aml_append(ssdt, sb_scope); @@ -1285,6 +1290,18 @@ static void nvdimm_build_ssdt(GArray *table_offsets,= GArray *table_data, free_aml_allocator(); } =20 +static void nvdimm_build_xen_ssdt(uint32_t ram_slots) +{ + Aml *dev =3D init_aml_allocator(); + + nvdimm_build_ssdt_device(dev, ram_slots); + build_append_named_dword(dev->buf, NVDIMM_ACPI_MEM_ADDR); + xen_acpi_copy_to_guest("NVDR", dev->buf->data, dev->buf->len, + XEN_DM_ACPI_BLOB_TYPE_NSDEV); + + free_aml_allocator(); +} + void nvdimm_build_acpi(GArray *table_offsets, GArray *table_data, BIOSLinker *linker, AcpiNVDIMMState *state, uint32_t ram_slots) @@ -1296,8 +1313,12 @@ void nvdimm_build_acpi(GArray *table_offsets, GArray= *table_data, return; } =20 - nvdimm_build_ssdt(table_offsets, table_data, linker, state->dsm_mem, - ram_slots); + if (!xen_enabled()) { + nvdimm_build_ssdt(table_offsets, table_data, linker, state->dsm_me= m, + ram_slots); + } else { + nvdimm_build_xen_ssdt(ram_slots); + } =20 device_list =3D nvdimm_get_device_list(); /* no NVDIMM device is plugged. */ --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105433702279.02985189331423; Sun, 10 Sep 2017 21:50:33 -0700 (PDT) Received: from localhost ([::1]:55390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGg4-0007QY-E4 for importer@patchew.org; Mon, 11 Sep 2017 00:50:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGYJ-00011r-Gd for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGYI-0004d0-Nr for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:31 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGYI-0004UV-EH for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:30 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:29 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079171" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:56 +0800 Message-Id: <20170911044157.15403-10-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 09/10] nvdimm acpi: do not build _FIT method on Xen 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 , Xiao Guangrong , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Igor Mammedov , Chao Peng , Dan Williams 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" Xen currently does not support vNVDIMM hotplug and always sets QEMU option "maxmem" to be just enough for RAM and vNVDIMM, so it's not necessary to build _FIT method when QEMU is used as Xen device model. Signed-off-by: Haozhong Zhang --- Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Xiao Guangrong --- hw/acpi/nvdimm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index bf887512ad..61789c3966 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -1245,7 +1245,14 @@ static void nvdimm_build_ssdt_device(Aml *dev, uint3= 2_t ram_slots) =20 /* 0 is reserved for root device. */ nvdimm_build_device_dsm(dev, 0); - nvdimm_build_fit(dev); + /* + * Xen does not support vNVDIMM hotplug, and always sets the QEMU + * option "maxmem" to be just enough for RAM and static plugged + * vNVDIMM, so it's unnecessary to build _FIT method on Xen. + */ + if (!xen_enabled()) { + nvdimm_build_fit(dev); + } =20 nvdimm_build_nvdimm_devices(dev, ram_slots); } --=20 2.11.0 From nobody Wed May 1 18:00:30 2024 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 1505105344374830.6139605502417; Sun, 10 Sep 2017 21:49:04 -0700 (PDT) Received: from localhost ([::1]:55379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGed-0006BJ-Kq for importer@patchew.org; Mon, 11 Sep 2017 00:49:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drGYP-00015S-Rh for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drGYL-0004ds-TT for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:37 -0400 Received: from mga04.intel.com ([192.55.52.120]:23374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1drGYL-0004UV-Jt for qemu-devel@nongnu.org; Mon, 11 Sep 2017 00:42:33 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:42:33 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:42:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,376,1500966000"; d="scan'208";a="1217079183" From: Haozhong Zhang To: qemu-devel@nongnu.org, xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:41:57 +0800 Message-Id: <20170911044157.15403-11-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911044157.15403-1-haozhong.zhang@intel.com> References: <20170911044157.15403-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.120 Subject: [Qemu-devel] [RFC QEMU PATCH v3 10/10] hw/xen-hvm: enable building DM ACPI if vNVDIMM is enabled 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 , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Paolo Bonzini , Igor Mammedov , 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" If the machine option 'nvdimm' is enabled and QEMU is used as Xen device model, construct the guest NFIT and ACPI namespace devices of vNVDIMM and copy them into guest memory. Signed-off-by: Haozhong Zhang --- Cc: "Michael S. Tsirkin" Cc: Igor Mammedov Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Cc: Stefano Stabellini Cc: Anthony Perard --- hw/acpi/aml-build.c | 10 +++++++--- hw/i386/pc.c | 16 ++++++++++------ hw/i386/xen/xen-hvm.c | 25 +++++++++++++++++++++++-- include/hw/xen/xen.h | 7 +++++++ stubs/xen-hvm.c | 4 ++++ 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 36a6cc450e..5f57c1bef3 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -22,6 +22,7 @@ #include "qemu/osdep.h" #include #include "hw/acpi/aml-build.h" +#include "hw/xen/xen.h" #include "qemu/bswap.h" #include "qemu/bitops.h" #include "sysemu/numa.h" @@ -1531,9 +1532,12 @@ build_header(BIOSLinker *linker, GArray *table_data, h->oem_revision =3D cpu_to_le32(1); memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4); h->asl_compiler_revision =3D cpu_to_le32(1); - /* Checksum to be filled in by Guest linker */ - bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE, - tbl_offset, len, checksum_offset); + /* No linker is used when QEMU is used as Xen device model. */ + if (!xen_enabled()) { + /* Checksum to be filled in by Guest linker */ + bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE, + tbl_offset, len, checksum_offset); + } } =20 void *acpi_data_push(GArray *table_data, unsigned size) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5cbdce61a7..7101d380a0 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1252,12 +1252,16 @@ void pc_machine_done(Notifier *notifier, void *data) } } =20 - acpi_setup(); - if (pcms->fw_cfg) { - pc_build_smbios(pcms); - pc_build_feature_control_file(pcms); - /* update FW_CFG_NB_CPUS to account for -device added CPUs */ - fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpus); + if (!xen_enabled()) { + acpi_setup(); + if (pcms->fw_cfg) { + pc_build_smbios(pcms); + pc_build_feature_control_file(pcms); + /* update FW_CFG_NB_CPUS to account for -device added CPUs */ + fw_cfg_modify_i16(pcms->fw_cfg, FW_CFG_NB_CPUS, pcms->boot_cpu= s); + } + } else { + xen_dm_acpi_setup(pcms); } =20 if (pcms->apic_id_limit > 255) { diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index b74c4ffb9c..d81cc7dbbc 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -265,7 +265,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size= , MemoryRegion *mr, /* RAM already populated in Xen */ fprintf(stderr, "%s: do not alloc "RAM_ADDR_FMT " bytes of ram at "RAM_ADDR_FMT" when runstate is INMIGRAT= E\n", - __func__, size, ram_addr);=20 + __func__, size, ram_addr); return; } =20 @@ -1251,7 +1251,7 @@ static void xen_wakeup_notifier(Notifier *notifier, v= oid *data) =20 static int xen_dm_acpi_needed(PCMachineState *pcms) { - return 0; + return pcms->acpi_nvdimm_state.is_enabled; } =20 static int dm_acpi_buf_init(XenIOState *state) @@ -1309,6 +1309,20 @@ static int xen_dm_acpi_init(PCMachineState *pcms, Xe= nIOState *state) return dm_acpi_buf_init(state); } =20 +static void xen_dm_acpi_nvdimm_setup(PCMachineState *pcms) +{ + GArray *table_offsets =3D g_array_new(false, true /* clear */, + sizeof(uint32_t)); + GArray *table_data =3D g_array_new(false, true /* clear */, 1); + + nvdimm_build_acpi(table_offsets, table_data, + NULL, &pcms->acpi_nvdimm_state, + MACHINE(pcms)->ram_slots); + + g_array_free(table_offsets, true); + g_array_free(table_data, true); +} + static int xs_write_dm_acpi_blob_entry(const char *name, const char *entry, const char *valu= e) { @@ -1408,6 +1422,13 @@ int xen_acpi_copy_to_guest(const char *name, const v= oid *blob, size_t length, return 0; } =20 +void xen_dm_acpi_setup(PCMachineState *pcms) +{ + if (pcms->acpi_nvdimm_state.is_enabled) { + xen_dm_acpi_nvdimm_setup(pcms); + } +} + void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) { int i, rc; diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index 38dcd1a7d4..8c48195e12 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -66,4 +66,11 @@ void xen_register_framebuffer(struct MemoryRegion *mr); int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t leng= th, int type); =20 +/* + * Build guest ACPI (i.e. DM ACPI, or ACPI built by device model) and + * copy them into guest memory. Xen hvmloader will load and merge DM + * ACPI with the guest ACPI built by itself. + */ +void xen_dm_acpi_setup(PCMachineState *pcms); + #endif /* QEMU_HW_XEN_H */ diff --git a/stubs/xen-hvm.c b/stubs/xen-hvm.c index 58889ae0fb..c1a6d21efa 100644 --- a/stubs/xen-hvm.c +++ b/stubs/xen-hvm.c @@ -67,3 +67,7 @@ int xen_acpi_copy_to_guest(const char *name, const void *= blob, size_t length, { return -1; } + +void xen_dm_acpi_setup(PCMachineState *pcms) +{ +} --=20 2.11.0