From patchwork Mon Sep 11 04:38:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946619 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 DA1056035D for ; Mon, 11 Sep 2017 04:42:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE27E27D0C for ; Mon, 11 Sep 2017 04:42:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C30D128429; Mon, 11 Sep 2017 04:42:13 +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 0EEC927D0C for ; Mon, 11 Sep 2017 04:42:13 +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 1drGVx-0003Ki-Se; Mon, 11 Sep 2017 04:40:05 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVv-000367-Uc for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:40:04 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 80/EB-03454-3A316B95; Mon, 11 Sep 2017 04:40:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsXS1tYhortAeFu kwYMeeYslHxezODB6HN39mymAMYo1My8pvyKBNePSzsmsBTOcKq68vcnawLjBqIuRi0NIYDqj RO/fB2xdjJwcEgK8EkeWzWCFsAMk5u7oYgSxhQR6GSWOrg4EsdkE9CVWPD4IViMiIC1x7fNlR pBBzALzmCQmf7nOBJIQFnCXuPbsIJjNIqAqcfPva7AFvAJ2Ev8+H4daIC+xq+0imM0JFD/48h 0zxDJbiQWnF7BOYORdwMiwilGjOLWoLLVI18hcL6koMz2jJDcxM0fX0MBMLze1uDgxPTUnMal YLzk/dxMjMCAYgGAH4+K1gYcYJTmYlER53x3fEinEl5SfUpmRWJwRX1Sak1p8iFGGg0NJgldF aFukkGBRanpqRVpmDjA0YdISHDxKIrxRIGne4oLE3OLMdIjUKUZdjo6bd/8wCbHk5eelSonzy oEUCYAUZZTmwY2AxcklRlkpYV5GoKOEeApSi3IzS1DlXzGKczAqCfNGgEzhycwrgdv0CugIJq AjeC5tATmiJBEhJdXA6F18uPS/mNCrSuG5qo+818+J2JMjuL9o4yH5dKk7R+OuMaYduzQtLvy M3+20RVNOXel8fUH1B8OyyPZ9VUUSVTJ9YXz5lXcmVC5/bLzr8acVYQsPCDWd2GOpdnna9sj6 R5+KGp7fND/8S6V0qfHs9VMXO7SlrLp0cnLtUlsNwXXSW0sT2KQsfJRYijMSDbWYi4oTAYnM/ 5iOAgAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!29 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51496 invoked from network); 11 Sep 2017 04:40:00 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:40:00 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:39:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078587" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:39:57 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:15 +0800 Message-Id: <20170911043820.14617-35-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com> References: <20170911043820.14617-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Wei Liu , Ian Jackson , Jan Beulich , Chao Peng , Dan Williams Subject: [Xen-devel] [RFC XEN PATCH v3 34/39] tools/libacpi: add DM ACPI blacklists 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 Some guest ACPI tables and namespace devices are constructed by Xen, and should not be loaded from device model. This commit adds their table signatures and device names into two blacklists, which will be used to check the collisions between guest ACPI constructed by Xen and guest ACPI passed from device model. Signed-off-by: Haozhong Zhang --- Cc: Jan Beulich Cc: Ian Jackson Cc: Wei Liu --- tools/libacpi/build.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 5 +++ 2 files changed, 98 insertions(+) diff --git a/tools/libacpi/build.c b/tools/libacpi/build.c index f9881c9604..493ca48025 100644 --- a/tools/libacpi/build.c +++ b/tools/libacpi/build.c @@ -56,6 +56,76 @@ struct acpi_info { uint64_t pci_hi_min, pci_hi_len; /* 24, 32 - PCI I/O hole boundaries */ }; +/* ACPI tables of following signatures should not appear in DM ACPI */ +static uint64_t dm_acpi_signature_blacklist[64]; +/* ACPI namespace devices of following names should not appear in DM ACPI */ +static const char *dm_acpi_devname_blacklist[64]; + +static int dm_acpi_blacklist_signature(struct acpi_config *config, uint64_t sig) +{ + unsigned int i, nr = ARRAY_SIZE(dm_acpi_signature_blacklist); + + if ( !(config->table_flags & ACPI_HAS_DM) ) + return 0; + + for ( i = 0; i < nr; i++ ) + { + uint64_t entry = dm_acpi_signature_blacklist[i]; + + if ( entry == sig ) + return 0; + else if ( entry == 0 ) + break; + } + + if ( i >= nr ) + { + config->table_flags &= ~ACPI_HAS_DM; + + printf("ERROR: DM ACPI signature blacklist is full (size %u), " + "disable DM ACPI\n", nr); + + return -ENOSPC; + } + + dm_acpi_signature_blacklist[i] = sig; + + return 0; +} + +static int dm_acpi_blacklist_devname(struct acpi_config *config, + const char *devname) +{ + unsigned int i, nr = ARRAY_SIZE(dm_acpi_devname_blacklist); + + if ( !(config->table_flags & ACPI_HAS_DM) ) + return 0; + + for ( i = 0; i < nr; i++ ) + { + const char *entry = dm_acpi_devname_blacklist[i]; + + if ( !entry ) + break; + if ( !strncmp(entry, devname, 4) ) + return 0; + } + + if ( i >= nr ) + { + config->table_flags &= ~ACPI_HAS_DM; + + printf("ERROR: DM ACPI devname blacklist is full (size %u), " + "disable loading DM ACPI\n", nr); + + return -ENOSPC; + } + + dm_acpi_devname_blacklist[i] = devname; + + return 0; +} + static void set_checksum( void *table, uint32_t checksum_offset, uint32_t length) { @@ -360,6 +430,7 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, madt = construct_madt(ctxt, config, info); if (!madt) return -1; table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, madt); + dm_acpi_blacklist_signature(config, madt->header.signature); } /* HPET. */ @@ -368,6 +439,7 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, hpet = construct_hpet(ctxt, config); if (!hpet) return -1; table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, hpet); + dm_acpi_blacklist_signature(config, hpet->header.signature); } /* WAET. */ @@ -377,6 +449,7 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, if ( !waet ) return -1; table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, waet); + dm_acpi_blacklist_signature(config, waet->header.signature); } if ( config->table_flags & ACPI_HAS_SSDT_PM ) @@ -385,6 +458,9 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, if (!ssdt) return -1; memcpy(ssdt, ssdt_pm, sizeof(ssdt_pm)); table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt); + dm_acpi_blacklist_devname(config, "AC"); + dm_acpi_blacklist_devname(config, "BAT0"); + dm_acpi_blacklist_devname(config, "BAT1"); } if ( config->table_flags & ACPI_HAS_SSDT_S3 ) @@ -450,6 +526,8 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, offsetof(struct acpi_header, checksum), tcpa->header.length); } + dm_acpi_blacklist_signature(config, tcpa->header.signature); + dm_acpi_blacklist_devname(config, "TPM"); } /* SRAT and SLIT */ @@ -459,11 +537,17 @@ static int construct_secondary_tables(struct acpi_ctxt *ctxt, struct acpi_20_slit *slit = construct_slit(ctxt, config); if ( srat ) + { table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, srat); + dm_acpi_blacklist_signature(config, srat->header.signature); + } else printf("Failed to build SRAT, skipping...\n"); if ( slit ) + { table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, slit); + dm_acpi_blacklist_signature(config, slit->header.signature); + } else printf("Failed to build SLIT, skipping...\n"); } @@ -543,6 +627,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) facs = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_facs), 16); if (!facs) goto oom; memcpy(facs, &Facs, sizeof(struct acpi_20_facs)); + dm_acpi_blacklist_signature(config, facs->signature); /* * Alternative DSDTs we get linked against. A cover-all DSDT for up to the @@ -564,6 +649,9 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) if (!dsdt) goto oom; memcpy(dsdt, config->dsdt_anycpu, config->dsdt_anycpu_len); } + dm_acpi_blacklist_signature(config, ((struct acpi_header *)dsdt)->signature); + dm_acpi_blacklist_devname(config, "MEM0"); + dm_acpi_blacklist_devname(config, "PCI0"); /* * N.B. ACPI 1.0 operating systems may not handle FADT with revision 2 @@ -583,6 +671,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) set_checksum(fadt_10, offsetof(struct acpi_header, checksum), sizeof(struct acpi_10_fadt)); + dm_acpi_blacklist_signature(config, fadt_10->header.signature); switch ( config->acpi_revision ) { @@ -634,6 +723,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) fadt->iapc_boot_arch |= ACPI_FADT_NO_CMOS_RTC; } set_checksum(fadt, offsetof(struct acpi_header, checksum), fadt_size); + dm_acpi_blacklist_signature(config, fadt->header.signature); nr_secondaries = construct_secondary_tables(ctxt, secondary_tables, config, acpi_info); @@ -652,6 +742,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) set_checksum(xsdt, offsetof(struct acpi_header, checksum), xsdt->header.length); + dm_acpi_blacklist_signature(config, xsdt->header.signature); rsdt = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_rsdt) + sizeof(uint32_t) * nr_secondaries, @@ -665,6 +756,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) set_checksum(rsdt, offsetof(struct acpi_header, checksum), rsdt->header.length); + dm_acpi_blacklist_signature(config, rsdt->header.signature); /* * Fill in low-memory data structures: acpi_info and RSDP. @@ -680,6 +772,7 @@ int acpi_build_tables(struct acpi_ctxt *ctxt, struct acpi_config *config) set_checksum(rsdp, offsetof(struct acpi_20_rsdp, extended_checksum), sizeof(struct acpi_20_rsdp)); + dm_acpi_blacklist_signature(config, rsdp->signature); if ( !new_vm_gid(ctxt, config, acpi_info) ) goto oom; diff --git a/tools/libacpi/libacpi.h b/tools/libacpi/libacpi.h index ab86a35509..87f311bfab 100644 --- a/tools/libacpi/libacpi.h +++ b/tools/libacpi/libacpi.h @@ -36,6 +36,11 @@ #define ACPI_HAS_8042 (1<<13) #define ACPI_HAS_CMOS_RTC (1<<14) #define ACPI_HAS_SSDT_LAPTOP_SLATE (1<<15) +#define ACPI_HAS_DM (1<<16) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#endif struct xen_vmemrange; struct acpi_numa {