qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

ACPI: Build related register address fields via hardware error fw_cfg blob

This patch builds error_block_address and read_ack_register fields
in hardware errors table , the error_block_address points to Generic
Error Status Block(GESB) via bios_linker. The max size for one GESB
is 1kb, For more detailed information, please refer to
document: docs/specs/acpi_hest_ghes.rst

Now we only support one Error source, if necessary, we can extend to
support more.

Suggested-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-id: 20200512030609.19593-5-gengdongjiu@huawei.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

authored by

Dongjiu Geng and committed by
Peter Maydell
aa16508f 5fb004a2

+131
+1
default-configs/arm-softmmu.mak
··· 42 42 CONFIG_FSL_IMX6UL=y 43 43 CONFIG_SEMIHOSTING=y 44 44 CONFIG_ALLWINNER_H3=y 45 + CONFIG_ACPI_APEI=y
+4
hw/acpi/Kconfig
··· 28 28 bool 29 29 depends on ACPI 30 30 31 + config ACPI_APEI 32 + bool 33 + depends on ACPI 34 + 31 35 config ACPI_PCI 32 36 bool 33 37 depends on ACPI && PCI
+1
hw/acpi/Makefile.objs
··· 8 8 common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o 9 9 common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o 10 10 common-obj-$(CONFIG_ACPI_HMAT) += hmat.o 11 + common-obj-$(CONFIG_ACPI_APEI) += ghes.o 11 12 common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o 12 13 common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o 13 14
+2
hw/acpi/aml-build.c
··· 1578 1578 tables->table_data = g_array_new(false, true /* clear */, 1); 1579 1579 tables->tcpalog = g_array_new(false, true /* clear */, 1); 1580 1580 tables->vmgenid = g_array_new(false, true /* clear */, 1); 1581 + tables->hardware_errors = g_array_new(false, true /* clear */, 1); 1581 1582 tables->linker = bios_linker_loader_init(); 1582 1583 } 1583 1584 ··· 1588 1589 g_array_free(tables->table_data, true); 1589 1590 g_array_free(tables->tcpalog, mfre); 1590 1591 g_array_free(tables->vmgenid, mfre); 1592 + g_array_free(tables->hardware_errors, mfre); 1591 1593 } 1592 1594 1593 1595 /*
+89
hw/acpi/ghes.c
··· 1 + /* 2 + * Support for generating APEI tables and recording CPER for Guests 3 + * 4 + * Copyright (c) 2020 HUAWEI TECHNOLOGIES CO., LTD. 5 + * 6 + * Author: Dongjiu Geng <gengdongjiu@huawei.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + 18 + * You should have received a copy of the GNU General Public License along 19 + * with this program; if not, see <http://www.gnu.org/licenses/>. 20 + */ 21 + 22 + #include "qemu/osdep.h" 23 + #include "qemu/units.h" 24 + #include "hw/acpi/ghes.h" 25 + #include "hw/acpi/aml-build.h" 26 + 27 + #define ACPI_GHES_ERRORS_FW_CFG_FILE "etc/hardware_errors" 28 + #define ACPI_GHES_DATA_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" 29 + 30 + /* The max size in bytes for one error block */ 31 + #define ACPI_GHES_MAX_RAW_DATA_LENGTH (1 * KiB) 32 + 33 + /* Now only support ARMv8 SEA notification type error source */ 34 + #define ACPI_GHES_ERROR_SOURCE_COUNT 1 35 + 36 + /* 37 + * Build table for the hardware error fw_cfg blob. 38 + * Initialize "etc/hardware_errors" and "etc/hardware_errors_addr" fw_cfg blobs. 39 + * See docs/specs/acpi_hest_ghes.rst for blobs format. 40 + */ 41 + void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker) 42 + { 43 + int i, error_status_block_offset; 44 + 45 + /* Build error_block_address */ 46 + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { 47 + build_append_int_noprefix(hardware_errors, 0, sizeof(uint64_t)); 48 + } 49 + 50 + /* Build read_ack_register */ 51 + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { 52 + /* 53 + * Initialize the value of read_ack_register to 1, so GHES can be 54 + * writeable after (re)boot. 55 + * ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 56 + * (GHESv2 - Type 10) 57 + */ 58 + build_append_int_noprefix(hardware_errors, 1, sizeof(uint64_t)); 59 + } 60 + 61 + /* Generic Error Status Block offset in the hardware error fw_cfg blob */ 62 + error_status_block_offset = hardware_errors->len; 63 + 64 + /* Reserve space for Error Status Data Block */ 65 + acpi_data_push(hardware_errors, 66 + ACPI_GHES_MAX_RAW_DATA_LENGTH * ACPI_GHES_ERROR_SOURCE_COUNT); 67 + 68 + /* Tell guest firmware to place hardware_errors blob into RAM */ 69 + bios_linker_loader_alloc(linker, ACPI_GHES_ERRORS_FW_CFG_FILE, 70 + hardware_errors, sizeof(uint64_t), false); 71 + 72 + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { 73 + /* 74 + * Tell firmware to patch error_block_address entries to point to 75 + * corresponding "Generic Error Status Block" 76 + */ 77 + bios_linker_loader_add_pointer(linker, 78 + ACPI_GHES_ERRORS_FW_CFG_FILE, sizeof(uint64_t) * i, 79 + sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, 80 + error_status_block_offset + i * ACPI_GHES_MAX_RAW_DATA_LENGTH); 81 + } 82 + 83 + /* 84 + * tell firmware to write hardware_errors GPA into 85 + * hardware_errors_addr fw_cfg, once the former has been initialized. 86 + */ 87 + bios_linker_loader_write_pointer(linker, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, 88 + 0, sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, 0); 89 + }
+5
hw/arm/virt-acpi-build.c
··· 49 49 #include "sysemu/reset.h" 50 50 #include "kvm_arm.h" 51 51 #include "migration/vmstate.h" 52 + #include "hw/acpi/ghes.h" 52 53 53 54 #define ARM_SPI_BASE 32 54 55 ··· 817 818 818 819 acpi_add_table(table_offsets, tables_blob); 819 820 build_spcr(tables_blob, tables->linker, vms); 821 + 822 + if (vms->ras) { 823 + build_ghes_error_table(tables->hardware_errors, tables->linker); 824 + } 820 825 821 826 if (ms->numa_state->num_nodes > 0) { 822 827 acpi_add_table(table_offsets, tables_blob);
+1
include/hw/acpi/aml-build.h
··· 220 220 GArray *rsdp; 221 221 GArray *tcpalog; 222 222 GArray *vmgenid; 223 + GArray *hardware_errors; 223 224 BIOSLinker *linker; 224 225 } AcpiBuildTables; 225 226
+28
include/hw/acpi/ghes.h
··· 1 + /* 2 + * Support for generating APEI tables and recording CPER for Guests 3 + * 4 + * Copyright (c) 2020 HUAWEI TECHNOLOGIES CO., LTD. 5 + * 6 + * Author: Dongjiu Geng <gengdongjiu@huawei.com> 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + 13 + * This program is distributed in the hope that it will be useful, 14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + * GNU General Public License for more details. 17 + 18 + * You should have received a copy of the GNU General Public License along 19 + * with this program; if not, see <http://www.gnu.org/licenses/>. 20 + */ 21 + 22 + #ifndef ACPI_GHES_H 23 + #define ACPI_GHES_H 24 + 25 + #include "hw/acpi/bios-linker-loader.h" 26 + 27 + void build_ghes_error_table(GArray *hardware_errors, BIOSLinker *linker); 28 + #endif