From: "Jan Beulich" Subject: [PATCH RFC] VT-d: honor firmware-first mode in XSA-59 workaround code Date: Wed, 21 May 2014 17:09:22 +0100 Message-ID: <537CEBD20200007800014A29@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2A1808A2.2__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wn955-0007dC-Md for xen-devel@lists.xenproject.org; Wed, 21 May 2014 16:09:28 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper , Malcolm Crossley Cc: Yang Z Zhang , xen-devel , Kevin Tian , Donald D Dugger List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part2A1808A2.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline When firmware-first mode is being indicated by firmware, we shouldn't be modifying AER registers - these ar considered to be owned by firmware in that case. Violating this is being reported to result in SMI (or was it SCI?) storms. While circumventing the workaround means re-exposing affected hosts to the XSA-59 issues, this in any event seems better than not booting at all. Respective messages are being issued to the log, so the situation can be diagnosed. The basic building blocks were taken from Linux 3.15-rc. Reported-by: Andrew Cooper Reported-by: Malcolm Crossley Signed-off-by: Jan Beulich --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -785,6 +785,8 @@ int __init acpi_boot_init(void) =20 erst_init(); =20 + acpi_hest_init(); + acpi_table_parse(ACPI_SIG_BGRT, acpi_invalidate_bgrt); =20 return 0; --- a/xen/drivers/acpi/apei/Makefile +++ b/xen/drivers/acpi/apei/Makefile @@ -1,3 +1,4 @@ obj-y +=3D erst.o +obj-y +=3D hest.o obj-y +=3D apei-base.o obj-y +=3D apei-io.o --- /dev/null +++ b/xen/drivers/acpi/apei/hest.c @@ -0,0 +1,200 @@ +/* + * APEI Hardware Error Souce Table support + * + * HEST describes error sources in detail; communicates operational + * parameters (i.e. severity levels, masking bits, and threshold + * values) to Linux as necessary. It also allows the BIOS to report + * non-standard error sources to Linux (for example, chipset-specific + * error registers). + * + * For more information about HEST, please refer to ACPI Specification + * version 4.0, section 17.3.2. + * + * Copyright 2009 Intel Corp. + * Author: Huang Ying + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version + * 2 as published by the Free Software Foundation; + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "apei-internal.h" + +#define HEST_PFX "HEST: " + +static bool_t hest_disable; +boolean_param("hest_disable", hest_disable); + +/* HEST table parsing */ + +static struct acpi_table_hest *__read_mostly hest_tab; + +static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] =3D { + [ACPI_HEST_TYPE_IA32_CHECK] =3D -1, /* need further calculation= */ + [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] =3D -1, + [ACPI_HEST_TYPE_IA32_NMI] =3D sizeof(struct acpi_hest_ia_nmi), + [ACPI_HEST_TYPE_AER_ROOT_PORT] =3D sizeof(struct acpi_hest_aer_root= ), + [ACPI_HEST_TYPE_AER_ENDPOINT] =3D sizeof(struct acpi_hest_aer), + [ACPI_HEST_TYPE_AER_BRIDGE] =3D sizeof(struct acpi_hest_aer_bridge)= , + [ACPI_HEST_TYPE_GENERIC_ERROR] =3D sizeof(struct acpi_hest_generic)= , +}; + +static int hest_esrc_len(const struct acpi_hest_header *hest_hdr) +{ + u16 hest_type =3D hest_hdr->type; + int len; + + if (hest_type >=3D ACPI_HEST_TYPE_RESERVED) + return 0; + + len =3D hest_esrc_len_tab[hest_type]; + + if (hest_type =3D=3D ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) { + const struct acpi_hest_ia_corrected *cmc =3D + container_of(hest_hdr, + const struct acpi_hest_ia_corrected, + header); + + len =3D sizeof(*cmc) + cmc->num_hardware_banks * + sizeof(struct acpi_hest_ia_error_bank); + } else if (hest_type =3D=3D ACPI_HEST_TYPE_IA32_CHECK) { + const struct acpi_hest_ia_machine_check *mc =3D + container_of(hest_hdr, + const struct acpi_hest_ia_machine_chec= k, + header); + + len =3D sizeof(*mc) + mc->num_hardware_banks * + sizeof(struct acpi_hest_ia_error_bank); + } + BUG_ON(len =3D=3D -1); + + return len; +}; + +int apei_hest_parse(apei_hest_func_t func, void *data) +{ + struct acpi_hest_header *hest_hdr; + int i, rc, len; + + if (hest_disable || !hest_tab) + return -EINVAL; + + hest_hdr =3D (struct acpi_hest_header *)(hest_tab + 1); + for (i =3D 0; i < hest_tab->error_source_count; i++) { + len =3D hest_esrc_len(hest_hdr); + if (!len) { + printk(XENLOG_WARNING HEST_PFX + "Unknown or unused hardware error source " + "type: %d for hardware error source: %d\n", + hest_hdr->type, hest_hdr->source_id); + return -EINVAL; + } + if ((void *)hest_hdr + len > + (void *)hest_tab + hest_tab->header.length) { + printk(XENLOG_WARNING HEST_PFX + "Table contents overflow for hardware error = source: %d\n", + hest_hdr->source_id); + return -EINVAL; + } + + rc =3D func(hest_hdr, data); + if (rc) + return rc; + + hest_hdr =3D (void *)hest_hdr + len; + } + + return 0; +} + +/* + * Check if firmware advertises firmware first mode. We need FF bit to be = set + * along with a set of MC banks which work in FF mode. + */ +static int __init hest_parse_cmc(const struct acpi_hest_header *hest_hdr, + void *data) +{ +#ifdef CONFIG_X86_MCE + unsigned int i; + const struct acpi_hest_ia_corrected *cmc; + const struct acpi_hest_ia_error_bank *mc_bank; + + if (hest_hdr->type !=3D ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) + return 0; + + cmc =3D container_of(hest_hdr, const struct acpi_hest_ia_corrected,= header); + if (!cmc->enabled) + return 0; + + /* + * We expect HEST to provide a list of MC banks that report errors + * in firmware first mode. Otherwise, return non-zero value to + * indicate that we are done parsing HEST. + */ + if (!(cmc->flags & ACPI_HEST_FIRMWARE_FIRST) || !cmc->num_hardware_= banks) + return 1; + + printk(XENLOG_INFO HEST_PFX "Enabling Firmware First mode for = corrected errors.\n"); + + mc_bank =3D (const struct acpi_hest_ia_error_bank *)(cmc + 1); + for (i =3D 0; i < cmc->num_hardware_banks; i++, mc_bank++) + mce_disable_bank(mc_bank->bank_number); +#else +# define acpi_disable_cmcff 1 +#endif + + return 1; +} + +void __init acpi_hest_init(void) +{ + acpi_status status; + acpi_physical_address hest_addr; + acpi_native_uint hest_len; + + if (acpi_disabled) + return; + + if (hest_disable) { + printk(XENLOG_INFO HEST_PFX "Table parsing disabled.\n"); + return; + } + + status =3D acpi_get_table_phys(ACPI_SIG_HEST, 0, &hest_addr, = &hest_len); + if (status =3D=3D AE_NOT_FOUND) + goto err; + if (ACPI_FAILURE(status)) { + printk(XENLOG_ERR HEST_PFX "Failed to get table, %s\n", + acpi_format_exception(status)); + goto err; + } + map_pages_to_xen((unsigned long)__va(hest_addr), PFN_DOWN(hest_addr= ), + PFN_UP(hest_addr + hest_len) - PFN_DOWN(hest_addr)= , + PAGE_HYPERVISOR); + hest_tab =3D __va(hest_addr); + + if (!acpi_disable_cmcff) + apei_hest_parse(hest_parse_cmc, NULL); + + printk(XENLOG_INFO HEST_PFX "Table parsing has been initialized\n")= ; + return; +err: + hest_disable =3D 1; +} --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1066,6 +1066,105 @@ void __hwdom_init setup_hwdom_pci_device spin_unlock(&pcidevs_lock); } =20 +#ifdef CONFIG_ACPI +#include +#include + +static int hest_match_pci(const struct acpi_hest_aer_common *p, + const struct pci_dev *pdev) +{ + return ACPI_HEST_SEGMENT(p->bus) =3D=3D pdev->seg && + ACPI_HEST_BUS(p->bus) =3D=3D pdev->bus && + p->device =3D=3D PCI_SLOT(pdev->devfn) && + p->function =3D=3D PCI_FUNC(pdev->devfn); +} + +static bool_t hest_match_type(const struct acpi_hest_header *hest_hdr, + const struct pci_dev *pdev) +{ + unsigned int pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, + PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), + PCI_CAP_ID_EXP); + u8 pcie =3D (pci_conf_read16(pdev->seg, pdev->bus, PCI_SLOT(pdev->devf= n), + PCI_FUNC(pdev->devfn), pos + PCI_EXP_FLAGS)= & + PCI_EXP_FLAGS_TYPE) / + (PCI_EXP_FLAGS_TYPE & -PCI_EXP_FLAGS_TYPE); + + switch ( hest_hdr->type ) + { + case ACPI_HEST_TYPE_AER_ROOT_PORT: + return pcie =3D=3D PCI_EXP_TYPE_ROOT_PORT; + case ACPI_HEST_TYPE_AER_ENDPOINT: + return pcie =3D=3D PCI_EXP_TYPE_ENDPOINT; + case ACPI_HEST_TYPE_AER_BRIDGE: + return pci_conf_read16(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn)= , + PCI_FUNC(pdev->devfn), PCI_CLASS_DEVICE) = =3D=3D + PCI_CLASS_BRIDGE_PCI; + } + + return 0; +} + +struct aer_hest_parse_info { + const struct pci_dev *pdev; + bool_t firmware_first; +}; + +static bool_t hest_source_is_pcie_aer(const struct acpi_hest_header = *hest_hdr) +{ + if ( hest_hdr->type =3D=3D ACPI_HEST_TYPE_AER_ROOT_PORT || + hest_hdr->type =3D=3D ACPI_HEST_TYPE_AER_ENDPOINT || + hest_hdr->type =3D=3D ACPI_HEST_TYPE_AER_BRIDGE ) + return 1; + return 0; +} + +static int aer_hest_parse(const struct acpi_hest_header *hest_hdr, void = *data) +{ + struct aer_hest_parse_info *info =3D data; + const struct acpi_hest_aer_common *p; + bool_t ff; + + if ( !hest_source_is_pcie_aer(hest_hdr) ) + return 0; + + p =3D (const struct acpi_hest_aer_common *)(hest_hdr + 1); + ff =3D !!(p->flags & ACPI_HEST_FIRMWARE_FIRST); + + /* + * If no specific device is supplied, determine whether + * FIRMWARE_FIRST is set for *any* PCIe device. + */ + if ( !info->pdev ) + { + info->firmware_first |=3D ff; + return 0; + } + + /* Otherwise, check the specific device */ + if ( p->flags & ACPI_HEST_GLOBAL ? + hest_match_type(hest_hdr, info->pdev) : + hest_match_pci(p, info->pdev) ) + { + info->firmware_first =3D ff; + return 1; + } + + return 0; +} + +bool_t pcie_aer_get_firmware_first(const struct pci_dev *pdev) +{ + struct aer_hest_parse_info info =3D { .pdev =3D pdev }; + + return pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn)= , + PCI_FUNC(pdev->devfn), PCI_CAP_ID_EXP) && + apei_hest_parse(aer_hest_parse, &info) >=3D 0 && + info.firmware_first; +} +#endif + static int _dump_pci_devices(struct pci_seg *pseg, void *arg) { struct pci_dev *pdev; --- a/xen/drivers/passthrough/vtd/quirks.c +++ b/xen/drivers/passthrough/vtd/quirks.c @@ -386,9 +386,10 @@ void pci_vtd_quirk(const struct pci_dev=20 int dev =3D PCI_SLOT(pdev->devfn); int func =3D PCI_FUNC(pdev->devfn); int pos; - u32 val; + u32 val, val2; u64 bar; paddr_t pa; + const char *action; =20 if ( pci_conf_read16(seg, bus, dev, func, PCI_VENDOR_ID) !=3D PCI_VENDOR_ID_INTEL ) @@ -447,18 +448,26 @@ void pci_vtd_quirk(const struct pci_dev=20 } =20 val =3D pci_conf_read32(seg, bus, dev, func, pos + PCI_ERR_UNCOR_M= ASK); - pci_conf_write32(seg, bus, dev, func, pos + PCI_ERR_UNCOR_MASK, - val | PCI_ERR_UNC_UNSUP); - val =3D pci_conf_read32(seg, bus, dev, func, pos + PCI_ERR_COR_MAS= K); - pci_conf_write32(seg, bus, dev, func, pos + PCI_ERR_COR_MASK, - val | PCI_ERR_COR_ADV_NFAT); + val2 =3D pci_conf_read32(seg, bus, dev, func, pos + PCI_ERR_COR_MA= SK); + if ( (val & PCI_ERR_UNC_UNSUP) && (val2 & PCI_ERR_COR_ADV_NFAT) ) + action =3D "Found masked"; + else if ( !pcie_aer_get_firmware_first(pdev) ) + { + pci_conf_write32(seg, bus, dev, func, pos + PCI_ERR_UNCOR_MASK= , + val | PCI_ERR_UNC_UNSUP); + pci_conf_write32(seg, bus, dev, func, pos + PCI_ERR_COR_MASK, + val2 | PCI_ERR_COR_ADV_NFAT); + action =3D "Masked"; + } + else + action =3D "Cannot mask"; =20 /* XPUNCERRMSK Send Completion with Unsupported Request */ val =3D pci_conf_read32(seg, bus, dev, func, 0x20c); pci_conf_write32(seg, bus, dev, func, 0x20c, val | (1 << 4)); =20 - printk(XENLOG_INFO "Masked UR signaling on %04x:%02x:%02x.%u\n", - seg, bus, dev, func); + printk(XENLOG_INFO "%s UR signaling on %04x:%02x:%02x.%u\n", + action, seg, bus, dev, func); break; =20 case 0x100: case 0x104: case 0x108: /* Sandybridge */ --- a/xen/include/acpi/actbl1.h +++ b/xen/include/acpi/actbl1.h @@ -445,6 +445,14 @@ struct acpi_hest_aer_common { #define ACPI_HEST_FIRMWARE_FIRST (1) #define ACPI_HEST_GLOBAL (1<<1) =20 +/* + * Macros to access the bus/segment numbers in Bus field above: + * Bus number is encoded in bits 7:0 + * Segment number is encoded in bits 23:8 + */ +#define ACPI_HEST_BUS(bus) ((bus) & 0xFF) +#define ACPI_HEST_SEGMENT(bus) (((bus) >> 8) & 0xFFFF) + /* Hardware Error Notification */ =20 struct acpi_hest_notify { --- a/xen/include/acpi/apei.h +++ b/xen/include/acpi/apei.h @@ -12,6 +12,9 @@ =20 #define FIX_APEI_RANGE_MAX 64 =20 +typedef int (*apei_hest_func_t)(const struct acpi_hest_header *, void *); +int apei_hest_parse(apei_hest_func_t, void *); + int erst_write(const struct cper_record_header *record); ssize_t erst_get_record_count(void); int erst_get_next_record_id(u64 *record_id); --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -61,6 +61,7 @@ int acpi_boot_init (void); int acpi_boot_table_init (void); int acpi_numa_init (void); int erst_init(void); +void acpi_hest_init(void); =20 int acpi_table_init (void); int acpi_table_parse(char *id, acpi_table_handler handler); --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -144,6 +144,8 @@ int pci_find_next_ext_capability(int seg const char *parse_pci(const char *, unsigned int *seg, unsigned int *bus, unsigned int *dev, unsigned int *func); =20 +bool_t pcie_aer_get_firmware_first(const struct pci_dev *); + struct pirq; int msixtbl_pt_register(struct domain *, struct pirq *, uint64_t gtable); void msixtbl_pt_unregister(struct domain *, struct pirq *); --=__Part2A1808A2.2__= Content-Type: text/plain; name="VT-d-mask-UR-honor-firmware-first.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="VT-d-mask-UR-honor-firmware-first.patch" VT-d: honor firmware-first mode in XSA-59 workaround code=0A=0AWhen = firmware-first mode is being indicated by firmware, we shouldn't=0Abe = modifying AER registers - these ar considered to be owned by=0Afirmware in = that case. Violating this is being reported to result in=0ASMI (or was it = SCI?) storms. While circumventing the workaround means=0Are-exposing = affected hosts to the XSA-59 issues, this in any event=0Aseems better than = not booting at all. Respective messages are being=0Aissued to the log, so = the situation can be diagnosed.=0A=0AThe basic building blocks were taken = from Linux 3.15-rc.=0A=0AReported-by: Andrew Cooper =0AReported-by: Malcolm Crossley =0ASigned= -off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/acpi/boot.= c=0A+++ b/xen/arch/x86/acpi/boot.c=0A@@ -785,6 +785,8 @@ int __init = acpi_boot_init(void)=0A =0A erst_init();=0A =0A+ acpi_hest_init();= =0A+=0A acpi_table_parse(ACPI_SIG_BGRT, acpi_invalidate_bgrt);=0A = =0A return 0;=0A--- a/xen/drivers/acpi/apei/Makefile=0A+++ b/xen/driver= s/acpi/apei/Makefile=0A@@ -1,3 +1,4 @@=0A obj-y +=3D erst.o=0A+obj-y +=3D = hest.o=0A obj-y +=3D apei-base.o=0A obj-y +=3D apei-io.o=0A--- /dev/null=0A= +++ b/xen/drivers/acpi/apei/hest.c=0A@@ -0,0 +1,200 @@=0A+/*=0A+ * APEI = Hardware Error Souce Table support=0A+ *=0A+ * HEST describes error = sources in detail; communicates operational=0A+ * parameters (i.e. = severity levels, masking bits, and threshold=0A+ * values) to Linux as = necessary. It also allows the BIOS to report=0A+ * non-standard error = sources to Linux (for example, chipset-specific=0A+ * error registers).=0A+= *=0A+ * For more information about HEST, please refer to ACPI Specificatio= n=0A+ * version 4.0, section 17.3.2.=0A+ *=0A+ * Copyright 2009 Intel = Corp.=0A+ * Author: Huang Ying =0A+ *=0A+ * This = program is free software; you can redistribute it and/or=0A+ * modify it = under the terms of the GNU General Public License version=0A+ * 2 as = published by the Free Software Foundation;=0A+ *=0A+ * This program is = distributed in the hope that it will be useful,=0A+ * but WITHOUT ANY = WARRANTY; without even the implied warranty of=0A+ * MERCHANTABILITY or = FITNESS FOR A PARTICULAR PURPOSE. See the=0A+ * GNU General Public = License for more details.=0A+ *=0A+ * You should have received a copy of = the GNU General Public License=0A+ * along with this program; if not, = write to the Free Software=0A+ * Foundation, Inc., 59 Temple Place, Suite = 330, Boston, MA 02111-1307 USA=0A+ */=0A+=0A+#include =0A+#i= nclude =0A+#include =0A+#include =0A+#i= nclude =0A+#include =0A+#include =0A+= =0A+#include "apei-internal.h"=0A+=0A+#define HEST_PFX "HEST: "=0A+=0A+stat= ic bool_t hest_disable;=0A+boolean_param("hest_disable", hest_disable);=0A+= =0A+/* HEST table parsing */=0A+=0A+static struct acpi_table_hest = *__read_mostly hest_tab;=0A+=0A+static const int hest_esrc_len_tab[ACPI_HES= T_TYPE_RESERVED] =3D {=0A+ [ACPI_HEST_TYPE_IA32_CHECK] =3D -1, /* = need further calculation */=0A+ [ACPI_HEST_TYPE_IA32_CORRECTED_CHECK] =3D = -1,=0A+ [ACPI_HEST_TYPE_IA32_NMI] =3D sizeof(struct acpi_hest_ia_nmi),=0A+ = [ACPI_HEST_TYPE_AER_ROOT_PORT] =3D sizeof(struct acpi_hest_aer_root),=0A+ = [ACPI_HEST_TYPE_AER_ENDPOINT] =3D sizeof(struct acpi_hest_aer),=0A+ = [ACPI_HEST_TYPE_AER_BRIDGE] =3D sizeof(struct acpi_hest_aer_bridge),=0A+ = [ACPI_HEST_TYPE_GENERIC_ERROR] =3D sizeof(struct acpi_hest_generic),=0A+};= =0A+=0A+static int hest_esrc_len(const struct acpi_hest_header *hest_hdr)= =0A+{=0A+ u16 hest_type =3D hest_hdr->type;=0A+ int len;=0A+=0A+ = if (hest_type >=3D ACPI_HEST_TYPE_RESERVED)=0A+ return 0;=0A+=0A+ = len =3D hest_esrc_len_tab[hest_type];=0A+=0A+ if (hest_type =3D=3D = ACPI_HEST_TYPE_IA32_CORRECTED_CHECK) {=0A+ const struct = acpi_hest_ia_corrected *cmc =3D=0A+ container_of(hest_h= dr,=0A+ const struct acpi_hest_ia_corrected,= =0A+ header);=0A+=0A+ len =3D = sizeof(*cmc) + cmc->num_hardware_banks *=0A+ sizeof(struct= acpi_hest_ia_error_bank);=0A+ } else if (hest_type =3D=3D ACPI_HEST_TYPE_= IA32_CHECK) {=0A+ const struct acpi_hest_ia_machine_check = *mc =3D=0A+ container_of(hest_hdr,=0A+ = const struct acpi_hest_ia_machine_check,=0A+ = header);=0A+=0A+ len =3D sizeof(*mc) + mc->num_hardw= are_banks *=0A+ sizeof(struct acpi_hest_ia_error_bank);=0A+ = }=0A+ BUG_ON(len =3D=3D -1);=0A+=0A+ return len;=0A+};=0A+=0A+int = apei_hest_parse(apei_hest_func_t func, void *data)=0A+{=0A+ struct = acpi_hest_header *hest_hdr;=0A+ int i, rc, len;=0A+=0A+ if (hest_disable = || !hest_tab)=0A+ return -EINVAL;=0A+=0A+ hest_hdr =3D = (struct acpi_hest_header *)(hest_tab + 1);=0A+ for (i =3D 0; i < = hest_tab->error_source_count; i++) {=0A+ len =3D hest_esrc_l= en(hest_hdr);=0A+ if (!len) {=0A+ printk(XENL= OG_WARNING HEST_PFX=0A+ "Unknown or unused hardware = error source "=0A+ "type: %d for hardware = error source: %d\n",=0A+ hest_hdr->type, = hest_hdr->source_id);=0A+ return -EINVAL;=0A+ = }=0A+ if ((void *)hest_hdr + len >=0A+ (void = *)hest_tab + hest_tab->header.length) {=0A+ printk(XENL= OG_WARNING HEST_PFX=0A+ "Table contents overflow = for hardware error source: %d\n",=0A+ hest_hdr->so= urce_id);=0A+ return -EINVAL;=0A+ }=0A+=0A+ = rc =3D func(hest_hdr, data);=0A+ if (rc)=0A+ = return rc;=0A+=0A+ hest_hdr =3D (void *)hest_hdr + = len;=0A+ }=0A+=0A+ return 0;=0A+}=0A+=0A+/*=0A+ * Check if = firmware advertises firmware first mode. We need FF bit to be set=0A+ * = along with a set of MC banks which work in FF mode.=0A+ */=0A+static int = __init hest_parse_cmc(const struct acpi_hest_header *hest_hdr,=0A+ = void *data)=0A+{=0A+#ifdef CONFIG_X86_MCE=0A+ unsigned = int i;=0A+ const struct acpi_hest_ia_corrected *cmc;=0A+ const = struct acpi_hest_ia_error_bank *mc_bank;=0A+=0A+ if (hest_hdr->type = !=3D ACPI_HEST_TYPE_IA32_CORRECTED_CHECK)=0A+ return 0;=0A+=0A+ = cmc =3D container_of(hest_hdr, const struct acpi_hest_ia_corrected, = header);=0A+ if (!cmc->enabled)=0A+ return 0;=0A+=0A+ = /*=0A+ * We expect HEST to provide a list of MC banks that report = errors=0A+ * in firmware first mode. Otherwise, return non-zero = value to=0A+ * indicate that we are done parsing HEST.=0A+ */=0A+ if = (!(cmc->flags & ACPI_HEST_FIRMWARE_FIRST) || !cmc->num_hardware_banks)=0A+ = return 1;=0A+=0A+ printk(XENLOG_INFO HEST_PFX "Enabling = Firmware First mode for corrected errors.\n");=0A+=0A+ mc_bank =3D (const = struct acpi_hest_ia_error_bank *)(cmc + 1);=0A+ for (i =3D 0; i < = cmc->num_hardware_banks; i++, mc_bank++)=0A+ mce_disable_bank(mc= _bank->bank_number);=0A+#else=0A+# define acpi_disable_cmcff 1=0A+#endif=0A= +=0A+ return 1;=0A+}=0A+=0A+void __init acpi_hest_init(void)=0A+{=0A+ = acpi_status status;=0A+ acpi_physical_address hest_addr;=0A+ acpi_native= _uint hest_len;=0A+=0A+ if (acpi_disabled)=0A+ return;=0A+=0A+ if = (hest_disable) {=0A+ printk(XENLOG_INFO HEST_PFX "Table parsing = disabled.\n");=0A+ return;=0A+ }=0A+=0A+ status =3D = acpi_get_table_phys(ACPI_SIG_HEST, 0, &hest_addr, &hest_len);=0A+ if = (status =3D=3D AE_NOT_FOUND)=0A+ goto err;=0A+ if = (ACPI_FAILURE(status)) {=0A+ printk(XENLOG_ERR HEST_PFX "Failed = to get table, %s\n",=0A+ acpi_format_exception(status= ));=0A+ goto err;=0A+ }=0A+ map_pages_to_xen((unsigned = long)__va(hest_addr), PFN_DOWN(hest_addr),=0A+ PFN_UP(hes= t_addr + hest_len) - PFN_DOWN(hest_addr),=0A+ PAGE_HYPER= VISOR);=0A+ hest_tab =3D __va(hest_addr);=0A+=0A+ if (!acpi_disable_c= mcff)=0A+ apei_hest_parse(hest_parse_cmc, NULL);=0A+=0A+ = printk(XENLOG_INFO HEST_PFX "Table parsing has been initialized\n");=0A+ = return;=0A+err:=0A+ hest_disable =3D 1;=0A+}=0A--- a/xen/drivers/passth= rough/pci.c=0A+++ b/xen/drivers/passthrough/pci.c=0A@@ -1066,6 +1066,105 = @@ void __hwdom_init setup_hwdom_pci_device=0A spin_unlock(&pcidevs_loc= k);=0A }=0A =0A+#ifdef CONFIG_ACPI=0A+#include =0A+#include = =0A+=0A+static int hest_match_pci(const struct acpi_hest_aer_c= ommon *p,=0A+ const struct pci_dev *pdev)=0A+{=0A+= return ACPI_HEST_SEGMENT(p->bus) =3D=3D pdev->seg &&=0A+ = ACPI_HEST_BUS(p->bus) =3D=3D pdev->bus &&=0A+ p->device = =3D=3D PCI_SLOT(pdev->devfn) &&=0A+ p->function = =3D=3D PCI_FUNC(pdev->devfn);=0A+}=0A+=0A+static bool_t hest_match_= type(const struct acpi_hest_header *hest_hdr,=0A+ = const struct pci_dev *pdev)=0A+{=0A+ unsigned int pos =3D pci_find_c= ap_offset(pdev->seg, pdev->bus,=0A+ = PCI_SLOT(pdev->devfn),=0A+ = PCI_FUNC(pdev->devfn),=0A+ = PCI_CAP_ID_EXP);=0A+ u8 pcie =3D (pci_conf_read16(pdev->seg, pdev->bus, = PCI_SLOT(pdev->devfn),=0A+ PCI_FUNC(pdev->dev= fn), pos + PCI_EXP_FLAGS) &=0A+ PCI_EXP_FLAGS_TYPE) /=0A+ = (PCI_EXP_FLAGS_TYPE & -PCI_EXP_FLAGS_TYPE);=0A+=0A+ switch ( = hest_hdr->type )=0A+ {=0A+ case ACPI_HEST_TYPE_AER_ROOT_PORT:=0A+ = return pcie =3D=3D PCI_EXP_TYPE_ROOT_PORT;=0A+ case ACPI_HEST_TYPE_A= ER_ENDPOINT:=0A+ return pcie =3D=3D PCI_EXP_TYPE_ENDPOINT;=0A+ = case ACPI_HEST_TYPE_AER_BRIDGE:=0A+ return pci_conf_read16(pdev->seg= , pdev->bus, PCI_SLOT(pdev->devfn),=0A+ = PCI_FUNC(pdev->devfn), PCI_CLASS_DEVICE) =3D=3D=0A+ = PCI_CLASS_BRIDGE_PCI;=0A+ }=0A+=0A+ return 0;=0A+}=0A+=0A+struct = aer_hest_parse_info {=0A+ const struct pci_dev *pdev;=0A+ bool_t = firmware_first;=0A+};=0A+=0A+static bool_t hest_source_is_pcie_aer(const = struct acpi_hest_header *hest_hdr)=0A+{=0A+ if ( hest_hdr->type =3D=3D = ACPI_HEST_TYPE_AER_ROOT_PORT ||=0A+ hest_hdr->type =3D=3D = ACPI_HEST_TYPE_AER_ENDPOINT ||=0A+ hest_hdr->type =3D=3D ACPI_HEST_= TYPE_AER_BRIDGE )=0A+ return 1;=0A+ return 0;=0A+}=0A+=0A+static = int aer_hest_parse(const struct acpi_hest_header *hest_hdr, void *data)=0A+= {=0A+ struct aer_hest_parse_info *info =3D data;=0A+ const struct = acpi_hest_aer_common *p;=0A+ bool_t ff;=0A+=0A+ if ( !hest_source_is_= pcie_aer(hest_hdr) )=0A+ return 0;=0A+=0A+ p =3D (const struct = acpi_hest_aer_common *)(hest_hdr + 1);=0A+ ff =3D !!(p->flags & = ACPI_HEST_FIRMWARE_FIRST);=0A+=0A+ /*=0A+ * If no specific device = is supplied, determine whether=0A+ * FIRMWARE_FIRST is set for *any* = PCIe device.=0A+ */=0A+ if ( !info->pdev )=0A+ {=0A+ = info->firmware_first |=3D ff;=0A+ return 0;=0A+ }=0A+=0A+ /* = Otherwise, check the specific device */=0A+ if ( p->flags & ACPI_HEST_GL= OBAL ?=0A+ hest_match_type(hest_hdr, info->pdev) :=0A+ = hest_match_pci(p, info->pdev) )=0A+ {=0A+ info->firmware_first = =3D ff;=0A+ return 1;=0A+ }=0A+=0A+ return 0;=0A+}=0A+=0A+bool= _t pcie_aer_get_firmware_first(const struct pci_dev *pdev)=0A+{=0A+ = struct aer_hest_parse_info info =3D { .pdev =3D pdev };=0A+=0A+ return = pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),=0A+ = PCI_FUNC(pdev->devfn), PCI_CAP_ID_EXP) &&=0A+ = apei_hest_parse(aer_hest_parse, &info) >=3D 0 &&=0A+ = info.firmware_first;=0A+}=0A+#endif=0A+=0A static int _dump_pci_devices(str= uct pci_seg *pseg, void *arg)=0A {=0A struct pci_dev *pdev;=0A--- = a/xen/drivers/passthrough/vtd/quirks.c=0A+++ b/xen/drivers/passthrough/vtd/= quirks.c=0A@@ -386,9 +386,10 @@ void pci_vtd_quirk(const struct pci_dev = =0A int dev =3D PCI_SLOT(pdev->devfn);=0A int func =3D PCI_FUNC(pde= v->devfn);=0A int pos;=0A- u32 val;=0A+ u32 val, val2;=0A = u64 bar;=0A paddr_t pa;=0A+ const char *action;=0A =0A if ( = pci_conf_read16(seg, bus, dev, func, PCI_VENDOR_ID) !=3D=0A = PCI_VENDOR_ID_INTEL )=0A@@ -447,18 +448,26 @@ void pci_vtd_quirk(const = struct pci_dev =0A }=0A =0A val =3D pci_conf_read32(seg, = bus, dev, func, pos + PCI_ERR_UNCOR_MASK);=0A- pci_conf_write32(seg,= bus, dev, func, pos + PCI_ERR_UNCOR_MASK,=0A- val = | PCI_ERR_UNC_UNSUP);=0A- val =3D pci_conf_read32(seg, bus, dev, = func, pos + PCI_ERR_COR_MASK);=0A- pci_conf_write32(seg, bus, dev, = func, pos + PCI_ERR_COR_MASK,=0A- val | PCI_ERR_COR= _ADV_NFAT);=0A+ val2 =3D pci_conf_read32(seg, bus, dev, func, pos + = PCI_ERR_COR_MASK);=0A+ if ( (val & PCI_ERR_UNC_UNSUP) && (val2 & = PCI_ERR_COR_ADV_NFAT) )=0A+ action =3D "Found masked";=0A+ = else if ( !pcie_aer_get_firmware_first(pdev) )=0A+ {=0A+ = pci_conf_write32(seg, bus, dev, func, pos + PCI_ERR_UNCOR_MASK,=0A+ = val | PCI_ERR_UNC_UNSUP);=0A+ pci_conf_wr= ite32(seg, bus, dev, func, pos + PCI_ERR_COR_MASK,=0A+ = val2 | PCI_ERR_COR_ADV_NFAT);=0A+ action =3D = "Masked";=0A+ }=0A+ else=0A+ action =3D "Cannot = mask";=0A =0A /* XPUNCERRMSK Send Completion with Unsupported = Request */=0A val =3D pci_conf_read32(seg, bus, dev, func, = 0x20c);=0A pci_conf_write32(seg, bus, dev, func, 0x20c, val | (1 = << 4));=0A =0A- printk(XENLOG_INFO "Masked UR signaling on = %04x:%02x:%02x.%u\n",=0A- seg, bus, dev, func);=0A+ = printk(XENLOG_INFO "%s UR signaling on %04x:%02x:%02x.%u\n",=0A+ = action, seg, bus, dev, func);=0A break;=0A =0A case 0x100: = case 0x104: case 0x108: /* Sandybridge */=0A--- a/xen/include/acpi/actbl1.h= =0A+++ b/xen/include/acpi/actbl1.h=0A@@ -445,6 +445,14 @@ struct acpi_hest_= aer_common {=0A #define ACPI_HEST_FIRMWARE_FIRST (1)=0A #define = ACPI_HEST_GLOBAL (1<<1)=0A =0A+/*=0A+ * Macros to access = the bus/segment numbers in Bus field above:=0A+ * Bus number is encoded = in bits 7:0=0A+ * Segment number is encoded in bits 23:8=0A+ */=0A+#define= ACPI_HEST_BUS(bus) ((bus) & 0xFF)=0A+#define ACPI_HEST_SEGMEN= T(bus) (((bus) >> 8) & 0xFFFF)=0A+=0A /* Hardware Error Notificati= on */=0A =0A struct acpi_hest_notify {=0A--- a/xen/include/acpi/apei.h=0A++= + b/xen/include/acpi/apei.h=0A@@ -12,6 +12,9 @@=0A =0A #define FIX_APEI_RAN= GE_MAX 64=0A =0A+typedef int (*apei_hest_func_t)(const struct acpi_hest_hea= der *, void *);=0A+int apei_hest_parse(apei_hest_func_t, void *);=0A+=0A = int erst_write(const struct cper_record_header *record);=0A ssize_t = erst_get_record_count(void);=0A int erst_get_next_record_id(u64 *record_id)= ;=0A--- a/xen/include/xen/acpi.h=0A+++ b/xen/include/xen/acpi.h=0A@@ -61,6 = +61,7 @@ int acpi_boot_init (void);=0A int acpi_boot_table_init (void);=0A = int acpi_numa_init (void);=0A int erst_init(void);=0A+void acpi_hest_init(v= oid);=0A =0A int acpi_table_init (void);=0A int acpi_table_parse(char *id, = acpi_table_handler handler);=0A--- a/xen/include/xen/pci.h=0A+++ b/xen/incl= ude/xen/pci.h=0A@@ -144,6 +144,8 @@ int pci_find_next_ext_capability(int = seg=0A const char *parse_pci(const char *, unsigned int *seg, unsigned int = *bus,=0A unsigned int *dev, unsigned int *func);=0A = =0A+bool_t pcie_aer_get_firmware_first(const struct pci_dev *);=0A+=0A = struct pirq;=0A int msixtbl_pt_register(struct domain *, struct pirq *, = uint64_t gtable);=0A void msixtbl_pt_unregister(struct domain *, struct = pirq *);=0A --=__Part2A1808A2.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part2A1808A2.2__=--