From patchwork Mon Sep 11 04:41:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4DFC06035D for ; Mon, 11 Sep 2017 04:44:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43F8128ABB for ; Mon, 11 Sep 2017 04:44:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38D8128AD7; Mon, 11 Sep 2017 04:44:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E1B828ABB for ; Mon, 11 Sep 2017 04:44:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGYO-0006Xj-D1; Mon, 11 Sep 2017 04:42:36 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGYN-0006VA-JN for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:42:35 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 7C/78-01812-A3416B95; Mon, 11 Sep 2017 04:42:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPLMWRWlGSWpSXmKPExsXS1tYhr2slsi3 SYOF3foslHxezODB6HN39mymAMYo1My8pvyKBNePhnIdMBXN1KtZ2bWBpYGxV7mLk5BASqJSY /+MyE4gtIcArcWTZDFYIO0Di7fl5jF2MXEA1vYwSD8+tZwNJsAnoS6x4fBCoiINDRMBYou2mM 0gNs8B5ZoltH++BDRIWiJHYP72DHaSGRUBV4ue3CpAwr4CdxNZvn6B2yUvsarsItosTKN7X8p 4Z4h5bibUrH7BMYORdwMiwilGjOLWoLLVI18hML6koMz2jJDcxM0fX0MBYLze1uDgxPTUnMal YLzk/dxMjMBjqGRgYdzA27PU7xCjJwaQkyvvu+JZIIb6k/JTKjMTijPii0pzU4kOMMhwcShK8 d4W2RQoJFqWmp1akZeYAwxImLcHBoyTCGwWS5i0uSMwtzkyHSJ1iNOY4tunyHyaOjpt3/zAJs eTl56VKifNOBykVACnNKM2DGwSLl0uMslLCvIwMDAxCPAWpRbmZJajyrxjFORiVhHkvgkzhyc wrgdv3CugUJqBTeC5tATmlJBEhJdXAGMP52Mw2QWy76dsZD69veMkS/lzPMTA228jL/u9kj9q mS2VbzBL55yzrUM7bJMV/sahPWnzVtQvy29h1dwSemb9lklqKL8+hLl/LP/PUlE/uZUtq/r1Z K31rWW9O2QweSX3FpbP+zhAxv80lKmLk+O7rv54lcwReRYfs2tp5beVjZRXmzOVxSizFGYmGW sxFxYkAOPyuAJICAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1505104925!114186094!11 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34197 invoked from network); 11 Sep 2017 04:42:33 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-8.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:42:33 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 10 Sep 2017 21:42:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217079183" 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 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> Cc: Haozhong Zhang , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Paolo Bonzini , Igor Mammedov , Anthony Perard , Chao Peng , Dan Williams , Richard Henderson Subject: [Xen-devel] [RFC QEMU PATCH v3 10/10] hw/xen-hvm: enable building DM ACPI if vNVDIMM is enabled X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = cpu_to_le32(1); memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4); h->asl_compiler_revision = 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); + } } 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) } } - 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_cpus); + } + } else { + xen_dm_acpi_setup(pcms); } 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 INMIGRATE\n", - __func__, size, ram_addr); + __func__, size, ram_addr); return; } @@ -1251,7 +1251,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data) static int xen_dm_acpi_needed(PCMachineState *pcms) { - return 0; + return pcms->acpi_nvdimm_state.is_enabled; } static int dm_acpi_buf_init(XenIOState *state) @@ -1309,6 +1309,20 @@ static int xen_dm_acpi_init(PCMachineState *pcms, XenIOState *state) return dm_acpi_buf_init(state); } +static void xen_dm_acpi_nvdimm_setup(PCMachineState *pcms) +{ + GArray *table_offsets = g_array_new(false, true /* clear */, + sizeof(uint32_t)); + GArray *table_data = 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 *value) { @@ -1408,6 +1422,13 @@ int xen_acpi_copy_to_guest(const char *name, const void *blob, size_t length, return 0; } +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 length, int type); +/* + * 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) +{ +}