* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support
@ 2019-11-16 0:58 gengdongjiu
0 siblings, 0 replies; 14+ messages in thread
From: gengdongjiu @ 2019-11-16 0:58 UTC (permalink / raw)
To: Igor Mammedov
Cc: zhengxiang (A),
pbonzini, mst, shannon.zhaosl, peter.maydell, lersek,
james.morse, mtosatti, rth, ehabkost, Jonathan Cameron, xuwei (O),
kvm, qemu-devel, qemu-arm, Linuxarm, Wanghaibin (D)
> On Fri, 15 Nov 2019 14:32:47 +0000
> gengdongjiu <gengdongjiu@huawei.com> wrote:
>
> > > > + */
> > > > +static void acpi_ghes_build_notify(GArray *table, const uint8_t
> > > > +type)
> > >
> > > typically format should be build_WHAT(), so
> > > build_ghes_hw_error_notification()
> > >
> > > And I'd move this out into its own patch.
> > > this applies to other trivial in-depended sub-tables, that take all data needed to construct them from supplied arguments.
> >
> > I very used your suggested method in previous series[1], but other
> > maintainer suggested to move this function to this file, because he
> > think only GHES used it
>
> Using this file is ok, what I've meant for you to split function from this patch into a separate smaller patch.
>
> With the way code split now I have to review 2 big complex patches at the same which makes reviewing hard and I have a hard time
> convincing myself that code it correct.
>
> Moving small self-contained chunks of code in to separate smaller patches makes review easier.
Ok, got it. Thanks very much for the explanations
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support @ 2019-11-15 14:32 gengdongjiu 2019-11-15 14:55 ` Igor Mammedov 0 siblings, 1 reply; 14+ messages in thread From: gengdongjiu @ 2019-11-15 14:32 UTC (permalink / raw) To: Igor Mammedov, zhengxiang (A) Cc: pbonzini, mst, shannon.zhaosl, peter.maydell, lersek, james.morse, mtosatti, rth, ehabkost, Jonathan Cameron, xuwei (O), kvm, qemu-devel, qemu-arm, Linuxarm, Wanghaibin (D) > > + */ > > +static void acpi_ghes_build_notify(GArray *table, const uint8_t type) > > typically format should be build_WHAT(), so > build_ghes_hw_error_notification() > > And I'd move this out into its own patch. > this applies to other trivial in-depended sub-tables, that take all data needed to construct them from supplied arguments. I very used your suggested method in previous series[1], but other maintainer suggested to move this function to this file, because he think only GHES used it [1]: https://patchwork.ozlabs.org/cover/1099428/ > > > +{ > > + /* Type */ > > + build_append_int_noprefix(table, type, 1); > > + /* > > + * Length: > > + * Total length of the structure in bytes > > + */ > > + build_append_int_noprefix(table, 28, 1); > > + /* Configuration Write Enable */ > > + build_append_int_noprefix(table, 0, 2); > > + /* Poll Interval */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Vector */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Switch To Polling Threshold Value */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Switch To Polling Threshold Window */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Error Threshold Value */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Error Threshold Window */ > > + build_append_int_noprefix(table, 0, 4); } > > + > > /* > Initialize "etc/hardware_errors" and "etc/hardware_errors_addr" fwcfg blobs. > See docs/specs/acpi_hest_ghes.rst for blobs format */ > > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker > > +*linker) > build_ghes_error_table() > > also I'd move this function into its own patch along with other related code that initializes and wires it into virt board. I ever use your suggested method[1], but other maintainer, it seems Michael, suggested to move these functions to this file that used it, because he think only GHES used it. [1]: https://patchwork.ozlabs.org/patch/1099424/ https://patchwork.ozlabs.org/patch/1099425/ https://patchwork.ozlabs.org/patch/1099430/ ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-15 14:32 gengdongjiu @ 2019-11-15 14:55 ` Igor Mammedov 0 siblings, 0 replies; 14+ messages in thread From: Igor Mammedov @ 2019-11-15 14:55 UTC (permalink / raw) To: gengdongjiu Cc: zhengxiang (A), pbonzini, mst, shannon.zhaosl, peter.maydell, lersek, james.morse, mtosatti, rth, ehabkost, Jonathan Cameron, xuwei (O), kvm, qemu-devel, qemu-arm, Linuxarm, Wanghaibin (D) On Fri, 15 Nov 2019 14:32:47 +0000 gengdongjiu <gengdongjiu@huawei.com> wrote: > > > + */ > > > +static void acpi_ghes_build_notify(GArray *table, const uint8_t type) > > > > typically format should be build_WHAT(), so > > build_ghes_hw_error_notification() > > > > And I'd move this out into its own patch. > > this applies to other trivial in-depended sub-tables, that take all data needed to construct them from supplied arguments. > > I very used your suggested method in previous series[1], but other maintainer suggested to move this function to this file, because he think only GHES used it Using this file is ok, what I've meant for you to split function from this patch into a separate smaller patch. With the way code split now I have to review 2 big complex patches at the same which makes reviewing hard and I have a hard time convincing myself that code it correct. Moving small self-contained chunks of code in to separate smaller patches makes review easier. > > [1]: > https://patchwork.ozlabs.org/cover/1099428/ > > > > > > +{ > > > + /* Type */ > > > + build_append_int_noprefix(table, type, 1); > > > + /* > > > + * Length: > > > + * Total length of the structure in bytes > > > + */ > > > + build_append_int_noprefix(table, 28, 1); > > > + /* Configuration Write Enable */ > > > + build_append_int_noprefix(table, 0, 2); > > > + /* Poll Interval */ > > > + build_append_int_noprefix(table, 0, 4); > > > + /* Vector */ > > > + build_append_int_noprefix(table, 0, 4); > > > + /* Switch To Polling Threshold Value */ > > > + build_append_int_noprefix(table, 0, 4); > > > + /* Switch To Polling Threshold Window */ > > > + build_append_int_noprefix(table, 0, 4); > > > + /* Error Threshold Value */ > > > + build_append_int_noprefix(table, 0, 4); > > > + /* Error Threshold Window */ > > > + build_append_int_noprefix(table, 0, 4); } > > > + > > > > /* > > Initialize "etc/hardware_errors" and "etc/hardware_errors_addr" fwcfg blobs. > > See docs/specs/acpi_hest_ghes.rst for blobs format */ > > > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker > > > +*linker) > > build_ghes_error_table() > > > > also I'd move this function into its own patch along with other related code that initializes and wires it into virt board. > > I ever use your suggested method[1], but other maintainer, it seems Michael, suggested to move these functions to this file that used it, because he think only GHES used it. > > [1]: > https://patchwork.ozlabs.org/patch/1099424/ > https://patchwork.ozlabs.org/patch/1099425/ > https://patchwork.ozlabs.org/patch/1099430/ > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* [RESEND PATCH v21 0/6] Add ARMv8 RAS virtualization support in QEMU @ 2019-11-11 1:40 Xiang Zheng 2019-11-11 1:40 ` [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support Xiang Zheng 0 siblings, 1 reply; 14+ messages in thread From: Xiang Zheng @ 2019-11-11 1:40 UTC (permalink / raw) To: pbonzini, mst, imammedo, shannon.zhaosl, peter.maydell, lersek, james.morse, gengdongjiu, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm Cc: zhengxiang9, wanghaibin.wang In the ARMv8 platform, the CPU error types are synchronous external abort(SEA) and SError Interrupt (SEI). If exception happens in guest, sometimes it's better for guest to perform the recovery, because host does not know the detailed information of guest. For example, if an exception happens in a user-space application within guest, host does not know which application encounters errors. For the ARMv8 SEA/SEI, KVM or host kernel delivers SIGBUS to notify userspace. After user space gets the notification, it will record the CPER into guest GHES buffer and inject an exception or IRQ into guest. In the current implementation, if the type of SIGBUS is BUS_MCEERR_AR, we will treat it as a synchronous exception, and notify guest with ARMv8 SEA notification type after recording CPER into guest. This series of patches are based on Qemu 4.1, which include two parts: 1. Generate APEI/GHES table. 2. Handle the SIGBUS signal, record the CPER in runtime and fill it into guest memory, then notify guest according to the type of SIGBUS. The whole solution was suggested by James(james.morse@arm.com); The solution of APEI section was suggested by Laszlo(lersek@redhat.com). Show some discussions in [1]. This series of patches have already been tested on ARM64 platform with RAS feature enabled: Show the APEI part verification result in [2]. Show the BUS_MCEERR_AR SIGBUS handling verification result in [3]. --- Change since v20: 1. Move some implementation details from acpi_ghes.h to acpi_ghes.c 2. Add the reviewers for the ACPI/APEI/GHES part Change since v19: 1. Fix clang compile error 2. Fix sphinx build error Change since v18: 1. Fix some code-style and typo/grammar problems. 2. Remove no_ras in the VirtMachineClass struct. 3. Convert documentation to rst format. 4. Simplize the code and add comments for some magic value. 5. Move kvm_inject_arm_sea() function into the patch where it's used. 6. Register the reset handler(kvm_unpoison_all()) in the kvm_init() function. Change since v17: 1. Improve some commit messages and comments. 2. Fix some code-style problems. 3. Add a *ras* machine option. 4. Move HEST/GHES related structures and macros into "hw/acpi/acpi_ghes.*". 5. Move HWPoison page functions into "include/sysemu/kvm_int.h". 6. Fix some bugs. 7. Improve the design document. Change since v16: 1. check whether ACPI table is enabled when handling the memory error in the SIGBUS handler. Change since v15: 1. Add a doc-comment in the proper format for 'include/exec/ram_addr.h' 2. Remove write_part_cpustate_to_list() because there is another bug fix patch has been merged "arm: Allow system registers for KVM guests to be changed by QEMU code" 3. Add some comments for kvm_inject_arm_sea() in 'target/arm/kvm64.c' 4. Compare the arm_current_el() return value to 0,1,2,3, not to PSTATE_MODE_* constants. 5. Change the RAS support wasn't introduced before 4.1 QEMU version. 6. Move the no_ras flag patch to begin in this series Change since v14: 1. Remove the BUS_MCEERR_AO handling logic because this asynchronous signal was masked by main thread 2. Address some Igor Mammedov's comments(ACPI part) 1) change the comments for the enum AcpiHestNotifyType definition and remove ditto in patch 1 2) change some patch commit messages and separate "APEI GHES table generation" patch to more patches. 3. Address some peter's comments(arm64 Synchronous External Abort injection) 1) change some code notes 2) using arm_current_el() for current EL 2) use the helper functions for those (syn_data_abort_*). Change since v13: 1. Move the patches that set guest ESR and inject virtual SError out of this series 2. Clean and optimize the APEI part patches 3. Update the commit messages and add some comments for the code Change since v12: 1. Address Paolo's comments to move HWPoisonPage definition to accel/kvm/kvm-all.c 2. Only call kvm_cpu_synchronize_state() when get the BUS_MCEERR_AR signal 3. Only add and enable GPIO-Signal and ARMv8 SEA two hardware error sources 4. Address Michael's comments to not sync SPDX from Linux kernel header file Change since v11: Address James's comments(james.morse@arm.com) 1. Check whether KVM has the capability to to set ESR instead of detecting host CPU RAS capability 2. For SIGBUS_MCEERR_AR SIGBUS, use Synchronous-External-Abort(SEA) notification type for SIGBUS_MCEERR_AO SIGBUS, use GPIO-Signal notification Address Shannon's comments(for ACPI part): 1. Unify hest_ghes.c and hest_ghes.h license declaration 2. Remove unnecessary including "qmp-commands.h" in hest_ghes.c 3. Unconditionally add guest APEI table based on James's comments(james.morse@arm.com) 4. Add a option to virt machine for migration compatibility. On new virt machine it's on by default while off for old ones, we enabled it since 2.12 5. Refer to the ACPI spec version which introduces Hardware Error Notification first time 6. Add ACPI_HEST_NOTIFY_RESERVED notification type Address Igor's comments(for ACPI part): 1. Add doc patch first which will describe how it's supposed to work between QEMU/firmware/guest OS with expected flows. 2. Move APEI diagrams into doc/spec patch 3. Remove redundant g_malloc in ghes_record_cper() 4. Use build_append_int_noprefix() API to compose whole error status block and whole APEI table, and try to get rid of most structures in patch 1, as they will be left unused after that 5. Reuse something like https://github.com/imammedo/qemu/commit/3d2fd6d13a3ea298d2ee814835495ce6241d085c to build GAS 6. Remove much offsetof() in the function 7. Build independent tables first and only then build dependent tables passing to it pointers to previously build table if necessary. 8. Redefine macro GHES_ACPI_HEST_NOTIFY_RESERVED to ACPI_HEST_ERROR_SOURCE_COUNT to avoid confusion Address Peter Maydell's comments 1. linux-headers is done as a patch of their own created using scripts/update-linux-headers.sh run against a mainline kernel tree 2. Tested whether this patchset builds OK on aarch32 3. Abstract Hwpoison page adding code out properly into a cpu-independent source file from target/i386/kvm.c, such as kvm-all.c 4. Add doc-comment formatted documentation comment for new globally-visible function prototype in a header --- [1]: https://lkml.org/lkml/2017/2/27/246 https://patchwork.kernel.org/patch/9633105/ https://patchwork.kernel.org/patch/9925227/ [2]: Note: the UEFI(QEMU_EFI.fd) is needed if guest want to use ACPI table. After guest boot up, dump the APEI table, then can see the initialized table (1) # iasl -p ./HEST -d /sys/firmware/acpi/tables/HEST (2) # cat HEST.dsl /* * Intel ACPI Component Architecture * AML/ASL+ Disassembler version 20170728 (64-bit version) * Copyright (c) 2000 - 2017 Intel Corporation * * Disassembly of /sys/firmware/acpi/tables/HEST, Mon Sep 5 07:59:17 2016 * * ACPI Data Table [HEST] * * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue */ .................................................................................. [308h 0776 2] Subtable Type : 000A [Generic Hardware Error Source V2] [30Ah 0778 2] Source Id : 0001 [30Ch 0780 2] Related Source Id : FFFF [30Eh 0782 1] Reserved : 00 [30Fh 0783 1] Enabled : 01 [310h 0784 4] Records To Preallocate : 00000001 [314h 0788 4] Max Sections Per Record : 00000001 [318h 0792 4] Max Raw Data Length : 00001000 [31Ch 0796 12] Error Status Address : [Generic Address Structure] [31Ch 0796 1] Space ID : 00 [SystemMemory] [31Dh 0797 1] Bit Width : 40 [31Eh 0798 1] Bit Offset : 00 [31Fh 0799 1] Encoded Access Width : 04 [QWord Access:64] [320h 0800 8] Address : 00000000785D0040 [328h 0808 28] Notify : [Hardware Error Notification Structure] [328h 0808 1] Notify Type : 08 [SEA] [329h 0809 1] Notify Length : 1C [32Ah 0810 2] Configuration Write Enable : 0000 [32Ch 0812 4] PollInterval : 00000000 [330h 0816 4] Vector : 00000000 [334h 0820 4] Polling Threshold Value : 00000000 [338h 0824 4] Polling Threshold Window : 00000000 [33Ch 0828 4] Error Threshold Value : 00000000 [340h 0832 4] Error Threshold Window : 00000000 [344h 0836 4] Error Status Block Length : 00001000 [348h 0840 12] Read Ack Register : [Generic Address Structure] [348h 0840 1] Space ID : 00 [SystemMemory] [349h 0841 1] Bit Width : 40 [34Ah 0842 1] Bit Offset : 00 [34Bh 0843 1] Encoded Access Width : 04 [QWord Access:64] [34Ch 0844 8] Address : 00000000785D0098 [354h 0852 8] Read Ack Preserve : 00000000FFFFFFFE [35Ch 0860 8] Read Ack Write : 0000000000000001 ..................................................................................... (3) After a synchronous external abort(SEA) happen, Qemu receive a SIGBUS and filled the CPER into guest GHES memory. For example, according to above table, the address that contains the physical address of a block of memory that holds the error status data for this abort is 0x00000000785D0040 (4) the address for SEA notification error source is 0x785d80b0 (qemu) xp /1 0x00000000785D0040 00000000785d0040: 0x785d80b0 (5) check the content of generic error status block and generic error data entry (qemu) xp /100x 0x785d80b0 00000000785d80b0: 0x00000001 0x00000000 0x00000000 0x00000098 00000000785d80c0: 0x00000000 0xa5bc1114 0x4ede6f64 0x833e63b8 00000000785d80d0: 0xb1837ced 0x00000000 0x00000300 0x00000050 00000000785d80e0: 0x00000000 0x00000000 0x00000000 0x00000000 00000000785d80f0: 0x00000000 0x00000000 0x00000000 0x00000000 00000000785d8100: 0x00000000 0x00000000 0x00000000 0x00004002 (6) check the OSPM's ACK value(for example SEA) /* Before OSPM acknowledges the error, check the ACK value */ (qemu) xp /1 0x00000000785D0098 00000000785d00f0: 0x00000000 /* After OSPM acknowledges the error, check the ACK value, it change to 1 from 0 */ (qemu) xp /1 0x00000000785D0098 00000000785d00f0: 0x00000001 [3]: KVM deliver "BUS_MCEERR_AR" to Qemu, Qemu record the guest CPER and inject synchronous external abort to notify guest, then guest do the recovery. [ 1552.516170] Synchronous External Abort: synchronous external abort (0x92000410) at 0x000000003751c6b4 [ 1553.074073] {1}[Hardware Error]: Hardware error from APEI Generic Hardware Error Source: 8 [ 1553.081654] {1}[Hardware Error]: event severity: recoverable [ 1554.034191] {1}[Hardware Error]: Error 0, type: recoverable [ 1554.037934] {1}[Hardware Error]: section_type: memory error [ 1554.513261] {1}[Hardware Error]: physical_address: 0x0000000040fa6000 [ 1554.513944] {1}[Hardware Error]: error_type: 0, unknown [ 1555.041451] Memory failure: 0x40fa6: Killing mca-recover:1296 due to hardware memory corruption [ 1555.373116] Memory failure: 0x40fa6: recovery action for dirty LRU page: Recovered Dongjiu Geng (6): hw/arm/virt: Introduce a RAS machine option docs: APEI GHES generation and CPER record description ACPI: Add APEI GHES table generation support KVM: Move hwpoison page related functions into kvm-all.c target-arm: kvm64: handle SIGBUS signal from kernel or KVM MAINTAINERS: Add APCI/APEI/GHES entries MAINTAINERS | 9 + accel/kvm/kvm-all.c | 36 ++ default-configs/arm-softmmu.mak | 1 + docs/specs/acpi_hest_ghes.rst | 95 ++++++ docs/specs/index.rst | 1 + hw/acpi/Kconfig | 4 + hw/acpi/Makefile.objs | 1 + hw/acpi/acpi_ghes.c | 564 ++++++++++++++++++++++++++++++++ hw/acpi/aml-build.c | 2 + hw/arm/virt-acpi-build.c | 12 + hw/arm/virt.c | 23 ++ include/hw/acpi/acpi_ghes.h | 60 ++++ include/hw/acpi/aml-build.h | 1 + include/hw/arm/virt.h | 1 + include/sysemu/kvm.h | 3 +- include/sysemu/kvm_int.h | 12 + target/arm/cpu.h | 4 + target/arm/helper.c | 2 +- target/arm/internals.h | 5 +- target/arm/kvm64.c | 64 ++++ target/arm/tlb_helper.c | 2 +- target/i386/cpu.h | 2 + target/i386/kvm.c | 36 -- 23 files changed, 898 insertions(+), 42 deletions(-) create mode 100644 docs/specs/acpi_hest_ghes.rst create mode 100644 hw/acpi/acpi_ghes.c create mode 100644 include/hw/acpi/acpi_ghes.h -- 2.19.1 ^ permalink raw reply [flat|nested] 14+ messages in thread
* [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-11 1:40 [RESEND PATCH v21 0/6] Add ARMv8 RAS virtualization support in QEMU Xiang Zheng @ 2019-11-11 1:40 ` Xiang Zheng 2019-11-15 9:38 ` Igor Mammedov 2019-11-22 15:42 ` Beata Michalska 0 siblings, 2 replies; 14+ messages in thread From: Xiang Zheng @ 2019-11-11 1:40 UTC (permalink / raw) To: pbonzini, mst, imammedo, shannon.zhaosl, peter.maydell, lersek, james.morse, gengdongjiu, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm Cc: zhengxiang9, wanghaibin.wang From: Dongjiu Geng <gengdongjiu@huawei.com> This patch implements APEI GHES Table generation via fw_cfg blobs. Now it only supports ARMv8 SEA, a type of GHESv2 error source. Afterwards, we can extend the supported types if needed. For the CPER section, currently it is memory section because kernel mainly wants userspace to handle the memory errors. This patch follows the spec ACPI 6.2 to build the Hardware Error Source table. For more detailed information, please refer to document: docs/specs/acpi_hest_ghes.rst Suggested-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com> Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> --- default-configs/arm-softmmu.mak | 1 + hw/acpi/Kconfig | 4 + hw/acpi/Makefile.objs | 1 + hw/acpi/acpi_ghes.c | 267 ++++++++++++++++++++++++++++++++ hw/acpi/aml-build.c | 2 + hw/arm/virt-acpi-build.c | 12 ++ include/hw/acpi/acpi_ghes.h | 56 +++++++ include/hw/acpi/aml-build.h | 1 + 8 files changed, 344 insertions(+) create mode 100644 hw/acpi/acpi_ghes.c create mode 100644 include/hw/acpi/acpi_ghes.h diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 1f2e0e7fde..5722f3130e 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -40,3 +40,4 @@ CONFIG_FSL_IMX25=y CONFIG_FSL_IMX7=y CONFIG_FSL_IMX6UL=y CONFIG_SEMIHOSTING=y +CONFIG_ACPI_APEI=y diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig index 12e3f1e86e..ed8c34d238 100644 --- a/hw/acpi/Kconfig +++ b/hw/acpi/Kconfig @@ -23,6 +23,10 @@ config ACPI_NVDIMM bool depends on ACPI +config ACPI_APEI + bool + depends on ACPI + config ACPI_PCI bool depends on ACPI && PCI diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 655a9c1973..84474b0ca8 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o +common-obj-$(CONFIG_ACPI_APEI) += acpi_ghes.o common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o diff --git a/hw/acpi/acpi_ghes.c b/hw/acpi/acpi_ghes.c new file mode 100644 index 0000000000..42c00ff3d3 --- /dev/null +++ b/hw/acpi/acpi_ghes.c @@ -0,0 +1,267 @@ +/* + * Support for generating APEI tables and recording CPER for Guests + * + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. + * + * Author: Dongjiu Geng <gengdongjiu@huawei.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "qemu/osdep.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/acpi_ghes.h" +#include "hw/nvram/fw_cfg.h" +#include "sysemu/sysemu.h" +#include "qemu/error-report.h" + +#define ACPI_GHES_ERRORS_FW_CFG_FILE "etc/hardware_errors" +#define ACPI_GHES_DATA_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" + +/* + * The size of Address field in Generic Address Structure. + * ACPI 2.0/3.0: 5.2.3.1 Generic Address Structure. + */ +#define ACPI_GHES_ADDRESS_SIZE 8 + +/* The max size in bytes for one error block */ +#define ACPI_GHES_MAX_RAW_DATA_LENGTH 0x1000 + +/* + * Now only support ARMv8 SEA notification type error source + */ +#define ACPI_GHES_ERROR_SOURCE_COUNT 1 + +/* + * Generic Hardware Error Source version 2 + */ +#define ACPI_GHES_SOURCE_GENERIC_ERROR_V2 10 + +/* + * | +--------------------------+ 0 + * | | Header | + * | +--------------------------+ 40---+- + * | | ................. | | + * | | error_status_address-----+ 60 | + * | | ................. | | + * | | read_ack_register--------+ 104 92 + * | | read_ack_preserve | | + * | | read_ack_write | | + * + +--------------------------+ 132--+- + * + * From above GHES definition, the error status address offset is 60; + * the Read Ack Register offset is 104, the whole size of GHESv2 is 92 + */ + +/* The error status address offset in GHES */ +#define ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(start_addr, n) (start_addr + \ + 60 + offsetof(struct AcpiGenericAddress, address) + n * 92) + +/* The Read Ack Register offset in GHES */ +#define ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(start_addr, n) (start_addr +\ + 104 + offsetof(struct AcpiGenericAddress, address) + n * 92) + +typedef struct AcpiGhesState { + uint64_t ghes_addr_le; +} AcpiGhesState; + +/* + * Hardware Error Notification + * ACPI 4.0: 17.3.2.7 Hardware Error Notification + */ +static void acpi_ghes_build_notify(GArray *table, const uint8_t type) +{ + /* Type */ + build_append_int_noprefix(table, type, 1); + /* + * Length: + * Total length of the structure in bytes + */ + build_append_int_noprefix(table, 28, 1); + /* Configuration Write Enable */ + build_append_int_noprefix(table, 0, 2); + /* Poll Interval */ + build_append_int_noprefix(table, 0, 4); + /* Vector */ + build_append_int_noprefix(table, 0, 4); + /* Switch To Polling Threshold Value */ + build_append_int_noprefix(table, 0, 4); + /* Switch To Polling Threshold Window */ + build_append_int_noprefix(table, 0, 4); + /* Error Threshold Value */ + build_append_int_noprefix(table, 0, 4); + /* Error Threshold Window */ + build_append_int_noprefix(table, 0, 4); +} + +/* Build table for the hardware error fw_cfg blob */ +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker) +{ + int i, error_status_block_offset; + + /* + * | +--------------------------+ + * | | error_block_address | + * | | .......... | + * | +--------------------------+ + * | | read_ack_register | + * | | ........... | + * | +--------------------------+ + * | | Error Status Data Block | + * | | ........ | + * | +--------------------------+ + */ + + /* Build error_block_address */ + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { + build_append_int_noprefix(hardware_errors, 0, ACPI_GHES_ADDRESS_SIZE); + } + + /* Build read_ack_register */ + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { + /* + * Initialize the value of read_ack_register to 1, so GHES can be + * writeable in the first time. + * ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 + * (GHESv2 - Type 10) + */ + build_append_int_noprefix(hardware_errors, 1, ACPI_GHES_ADDRESS_SIZE); + } + + /* Generic Error Status Block offset in the hardware error fw_cfg blob */ + error_status_block_offset = hardware_errors->len; + + /* Build Error Status Data Block */ + build_append_int_noprefix(hardware_errors, 0, + ACPI_GHES_MAX_RAW_DATA_LENGTH * ACPI_GHES_ERROR_SOURCE_COUNT); + + /* Allocate guest memory for the hardware error fw_cfg blob */ + bios_linker_loader_alloc(linker, ACPI_GHES_ERRORS_FW_CFG_FILE, + hardware_errors, 1, false); + + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { + /* + * Patch the address of Error Status Data Block into + * the error_block_address of hardware_errors fw_cfg blob + */ + bios_linker_loader_add_pointer(linker, + ACPI_GHES_ERRORS_FW_CFG_FILE, ACPI_GHES_ADDRESS_SIZE * i, + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, + error_status_block_offset + i * ACPI_GHES_MAX_RAW_DATA_LENGTH); + } + + /* + * Write the address of hardware_errors fw_cfg blob into the + * hardware_errors_addr fw_cfg blob. + */ + bios_linker_loader_write_pointer(linker, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, + 0, ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, 0); +} + +/* Build Hardware Error Source Table */ +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_errors, + BIOSLinker *linker) +{ + uint32_t hest_start = table_data->len; + uint32_t source_id = 0; + + /* Hardware Error Source Table header*/ + acpi_data_push(table_data, sizeof(AcpiTableHeader)); + + /* Error Source Count */ + build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4); + + /* + * Type: + * Generic Hardware Error Source version 2(GHESv2 - Type 10) + */ + build_append_int_noprefix(table_data, ACPI_GHES_SOURCE_GENERIC_ERROR_V2, 2); + /* + * Source Id + * Once we support more than one hardware error sources, we need to + * increase the value of this field. + */ + build_append_int_noprefix(table_data, source_id, 2); + /* Related Source Id */ + build_append_int_noprefix(table_data, 0xffff, 2); + /* Flags */ + build_append_int_noprefix(table_data, 0, 1); + /* Enabled */ + build_append_int_noprefix(table_data, 1, 1); + + /* Number of Records To Pre-allocate */ + build_append_int_noprefix(table_data, 1, 4); + /* Max Sections Per Record */ + build_append_int_noprefix(table_data, 1, 4); + /* Max Raw Data Length */ + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); + + /* Error Status Address */ + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, + 4 /* QWord access */, 0); + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, + source_id * ACPI_GHES_ADDRESS_SIZE); + + /* + * Notification Structure + * Now only enable ARMv8 SEA notification type + */ + acpi_ghes_build_notify(table_data, ACPI_GHES_NOTIFY_SEA); + + /* Error Status Block Length */ + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); + + /* + * Read Ack Register + * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source + * version 2 (GHESv2 - Type 10) + */ + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, + 4 /* QWord access */, 0); + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, + ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(hest_start, 0), + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, + (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) * ACPI_GHES_ADDRESS_SIZE); + + /* + * Read Ack Preserve + * We only provide the first bit in Read Ack Register to OSPM to write + * while the other bits are preserved. + */ + build_append_int_noprefix(table_data, ~0x1ULL, 8); + /* Read Ack Write */ + build_append_int_noprefix(table_data, 0x1, 8); + + build_header(linker, table_data, (void *)(table_data->data + hest_start), + "HEST", table_data->len - hest_start, 1, NULL, "GHES"); +} + +static AcpiGhesState ges; +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_error) +{ + + size_t size = 2 * ACPI_GHES_ADDRESS_SIZE + ACPI_GHES_MAX_RAW_DATA_LENGTH; + size_t request_block_size = ACPI_GHES_ERROR_SOURCE_COUNT * size; + + /* Create a read-only fw_cfg file for GHES */ + fw_cfg_add_file(s, ACPI_GHES_ERRORS_FW_CFG_FILE, hardware_error->data, + request_block_size); + + /* Create a read-write fw_cfg file for Address */ + fw_cfg_add_file_callback(s, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, NULL, NULL, + NULL, &ges.ghes_addr_le, sizeof(ges.ghes_addr_le), false); +} diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 2c3702b882..3681ec6e3d 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1578,6 +1578,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) tables->table_data = g_array_new(false, true /* clear */, 1); tables->tcpalog = g_array_new(false, true /* clear */, 1); tables->vmgenid = g_array_new(false, true /* clear */, 1); + tables->hardware_errors = g_array_new(false, true /* clear */, 1); tables->linker = bios_linker_loader_init(); } @@ -1588,6 +1589,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) g_array_free(tables->table_data, true); g_array_free(tables->tcpalog, mfre); g_array_free(tables->vmgenid, mfre); + g_array_free(tables->hardware_errors, mfre); } /* diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 4cd50175e0..1b1fd273e4 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -48,6 +48,7 @@ #include "sysemu/reset.h" #include "kvm_arm.h" #include "migration/vmstate.h" +#include "hw/acpi/acpi_ghes.h" #define ARM_SPI_BASE 32 @@ -825,6 +826,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) acpi_add_table(table_offsets, tables_blob); build_spcr(tables_blob, tables->linker, vms); + if (vms->ras) { + acpi_add_table(table_offsets, tables_blob); + acpi_ghes_build_error_table(tables->hardware_errors, tables->linker); + acpi_ghes_build_hest(tables_blob, tables->hardware_errors, + tables->linker); + } + if (ms->numa_state->num_nodes > 0) { acpi_add_table(table_offsets, tables_blob); build_srat(tables_blob, tables->linker, vms); @@ -942,6 +950,10 @@ void virt_acpi_setup(VirtMachineState *vms) fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog)); + if (vms->ras) { + acpi_ghes_add_fw_cfg(vms->fw_cfg, tables.hardware_errors); + } + build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, build_state, tables.rsdp, ACPI_BUILD_RSDP_FILE, 0); diff --git a/include/hw/acpi/acpi_ghes.h b/include/hw/acpi/acpi_ghes.h new file mode 100644 index 0000000000..cb62ec9c7b --- /dev/null +++ b/include/hw/acpi/acpi_ghes.h @@ -0,0 +1,56 @@ +/* + * Support for generating APEI tables and recording CPER for Guests + * + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. + * + * Author: Dongjiu Geng <gengdongjiu@huawei.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ACPI_GHES_H +#define ACPI_GHES_H + +#include "hw/acpi/bios-linker-loader.h" + +/* + * Values for Hardware Error Notification Type field + */ +enum AcpiGhesNotifyType { + ACPI_GHES_NOTIFY_POLLED = 0, /* Polled */ + ACPI_GHES_NOTIFY_EXTERNAL = 1, /* External Interrupt */ + ACPI_GHES_NOTIFY_LOCAL = 2, /* Local Interrupt */ + ACPI_GHES_NOTIFY_SCI = 3, /* SCI */ + ACPI_GHES_NOTIFY_NMI = 4, /* NMI */ + ACPI_GHES_NOTIFY_CMCI = 5, /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ + ACPI_GHES_NOTIFY_MCE = 6, /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ + /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ + ACPI_GHES_NOTIFY_GPIO = 7, + /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ + ACPI_GHES_NOTIFY_SEA = 8, + /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ + ACPI_GHES_NOTIFY_SEI = 9, + /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ + ACPI_GHES_NOTIFY_GSIV = 10, + /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ + ACPI_GHES_NOTIFY_SDEI = 11, + ACPI_GHES_NOTIFY_RESERVED = 12 /* 12 and greater are reserved */ +}; + +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_error, + BIOSLinker *linker); + +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker); +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_errors); +#endif diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index de4a406568..8f13620701 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -220,6 +220,7 @@ struct AcpiBuildTables { GArray *rsdp; GArray *tcpalog; GArray *vmgenid; + GArray *hardware_errors; BIOSLinker *linker; } AcpiBuildTables; -- 2.19.1 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-11 1:40 ` [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support Xiang Zheng @ 2019-11-15 9:38 ` Igor Mammedov 2019-11-18 12:49 ` gengdongjiu 2019-11-22 15:42 ` Beata Michalska 1 sibling, 1 reply; 14+ messages in thread From: Igor Mammedov @ 2019-11-15 9:38 UTC (permalink / raw) To: Xiang Zheng Cc: pbonzini, mst, shannon.zhaosl, peter.maydell, lersek, james.morse, gengdongjiu, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang On Mon, 11 Nov 2019 09:40:45 +0800 Xiang Zheng <zhengxiang9@huawei.com> wrote: > From: Dongjiu Geng <gengdongjiu@huawei.com> > > This patch implements APEI GHES Table generation via fw_cfg blobs. Now > it only supports ARMv8 SEA, a type of GHESv2 error source. Afterwards, > we can extend the supported types if needed. For the CPER section, > currently it is memory section because kernel mainly wants userspace to > handle the memory errors. > > This patch follows the spec ACPI 6.2 to build the Hardware Error Source > table. For more detailed information, please refer to document: > docs/specs/acpi_hest_ghes.rst > > Suggested-by: Laszlo Ersek <lersek@redhat.com> > Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com> > Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com> > --- > default-configs/arm-softmmu.mak | 1 + > hw/acpi/Kconfig | 4 + > hw/acpi/Makefile.objs | 1 + > hw/acpi/acpi_ghes.c | 267 ++++++++++++++++++++++++++++++++ > hw/acpi/aml-build.c | 2 + > hw/arm/virt-acpi-build.c | 12 ++ > include/hw/acpi/acpi_ghes.h | 56 +++++++ > include/hw/acpi/aml-build.h | 1 + > 8 files changed, 344 insertions(+) > create mode 100644 hw/acpi/acpi_ghes.c > create mode 100644 include/hw/acpi/acpi_ghes.h > > diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak > index 1f2e0e7fde..5722f3130e 100644 > --- a/default-configs/arm-softmmu.mak > +++ b/default-configs/arm-softmmu.mak > @@ -40,3 +40,4 @@ CONFIG_FSL_IMX25=y > CONFIG_FSL_IMX7=y > CONFIG_FSL_IMX6UL=y > CONFIG_SEMIHOSTING=y > +CONFIG_ACPI_APEI=y > diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig > index 12e3f1e86e..ed8c34d238 100644 > --- a/hw/acpi/Kconfig > +++ b/hw/acpi/Kconfig > @@ -23,6 +23,10 @@ config ACPI_NVDIMM > bool > depends on ACPI > > +config ACPI_APEI > + bool > + depends on ACPI > + > config ACPI_PCI > bool > depends on ACPI && PCI > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs > index 655a9c1973..84474b0ca8 100644 > --- a/hw/acpi/Makefile.objs > +++ b/hw/acpi/Makefile.objs > @@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o > common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o > common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o > common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o > +common-obj-$(CONFIG_ACPI_APEI) += acpi_ghes.o > common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o > common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o > common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o > diff --git a/hw/acpi/acpi_ghes.c b/hw/acpi/acpi_ghes.c > new file mode 100644 > index 0000000000..42c00ff3d3 > --- /dev/null > +++ b/hw/acpi/acpi_ghes.c > @@ -0,0 +1,267 @@ > +/* > + * Support for generating APEI tables and recording CPER for Guests > + * > + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > + * > + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + > + * 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, see <http://www.gnu.org/licenses/>. > + */ > + > +#include "qemu/osdep.h" > +#include "hw/acpi/acpi.h" > +#include "hw/acpi/aml-build.h" > +#include "hw/acpi/acpi_ghes.h" > +#include "hw/nvram/fw_cfg.h" > +#include "sysemu/sysemu.h" > +#include "qemu/error-report.h" > + > +#define ACPI_GHES_ERRORS_FW_CFG_FILE "etc/hardware_errors" > +#define ACPI_GHES_DATA_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" > + > +/* > + * The size of Address field in Generic Address Structure. > + * ACPI 2.0/3.0: 5.2.3.1 Generic Address Structure. > + */ > +#define ACPI_GHES_ADDRESS_SIZE 8 there is not such thing as GHES_ADDRESS_SIZE. I'd just use sizeof(unit64_t), shorter and obvious value when seen at a call site > + > +/* The max size in bytes for one error block */ > +#define ACPI_GHES_MAX_RAW_DATA_LENGTH 0x1000 > + > +/* > + * Now only support ARMv8 SEA notification type error source > + */ maybe one line comment > +#define ACPI_GHES_ERROR_SOURCE_COUNT 1 > + > +/* > + * Generic Hardware Error Source version 2 > + */ ditto > +#define ACPI_GHES_SOURCE_GENERIC_ERROR_V2 10 > + > +/* > + * | +--------------------------+ 0 > + * | | Header | > + * | +--------------------------+ 40---+- > + * | | ................. | | > + * | | error_status_address-----+ 60 | > + * | | ................. | | > + * | | read_ack_register--------+ 104 92 > + * | | read_ack_preserve | | > + * | | read_ack_write | | > + * + +--------------------------+ 132--+- > + * > + * From above GHES definition, the error status address offset is 60; > + * the Read Ack Register offset is 104, the whole size of GHESv2 is 92 > + */ > + > +/* The error status address offset in GHES */ > +#define ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(start_addr, n) (start_addr + \ > + 60 + offsetof(struct AcpiGenericAddress, address) + n * 92) > + > +/* The Read Ack Register offset in GHES */ > +#define ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(start_addr, n) (start_addr +\ > + 104 + offsetof(struct AcpiGenericAddress, address) + n * 92) drop this hunk, see below why > + > +typedef struct AcpiGhesState { > + uint64_t ghes_addr_le; > +} AcpiGhesState; > + > +/* > + * Hardware Error Notification > + * ACPI 4.0: 17.3.2.7 Hardware Error Notification add/ composes dummy Hardware Error Notification descriptor of specified type > + */ > +static void acpi_ghes_build_notify(GArray *table, const uint8_t type) typically format should be build_WHAT(), so build_ghes_hw_error_notification() And I'd move this out into its own patch. this applies to other trivial in-depended sub-tables, that take all data needed to construct them from supplied arguments. > +{ > + /* Type */ > + build_append_int_noprefix(table, type, 1); > + /* > + * Length: > + * Total length of the structure in bytes > + */ > + build_append_int_noprefix(table, 28, 1); > + /* Configuration Write Enable */ > + build_append_int_noprefix(table, 0, 2); > + /* Poll Interval */ > + build_append_int_noprefix(table, 0, 4); > + /* Vector */ > + build_append_int_noprefix(table, 0, 4); > + /* Switch To Polling Threshold Value */ > + build_append_int_noprefix(table, 0, 4); > + /* Switch To Polling Threshold Window */ > + build_append_int_noprefix(table, 0, 4); > + /* Error Threshold Value */ > + build_append_int_noprefix(table, 0, 4); > + /* Error Threshold Window */ > + build_append_int_noprefix(table, 0, 4); > +} > + /* Initialize "etc/hardware_errors" and "etc/hardware_errors_addr" fwcfg blobs. See docs/specs/acpi_hest_ghes.rst for blobs format */ > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker) build_ghes_error_table() also I'd move this function into its own patch along with other related code that initializes and wires it into virt board. > +{ > + int i, error_status_block_offset; > + > + /* > + * | +--------------------------+ > + * | | error_block_address | > + * | | .......... | > + * | +--------------------------+ > + * | | read_ack_register | > + * | | ........... | > + * | +--------------------------+ > + * | | Error Status Data Block | > + * | | ........ | > + * | +--------------------------+ > + */ I'd drop this comment, acpi_hest_ghes.rst should be sufficient, if it's not then fix spec. For example it's not obvious from spec that "Error Status Data Block" immediately follows 'read_ack_register' > + > + /* Build error_block_address */ > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > + build_append_int_noprefix(hardware_errors, 0, ACPI_GHES_ADDRESS_SIZE); > + } > + > + /* Build read_ack_register */ > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > + /* > + * Initialize the value of read_ack_register to 1, so GHES can be > + * writeable in the first time. s/in the first time/after (re)boot/ > + * ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 > + * (GHESv2 - Type 10) > + */ > + build_append_int_noprefix(hardware_errors, 1, ACPI_GHES_ADDRESS_SIZE); > + } > + > + /* Generic Error Status Block offset in the hardware error fw_cfg blob */ > + error_status_block_offset = hardware_errors->len; > + > + /* Build Error Status Data Block */ /* reserve space for Error Status Data Block */ > + build_append_int_noprefix(hardware_errors, 0, > + ACPI_GHES_MAX_RAW_DATA_LENGTH * ACPI_GHES_ERROR_SOURCE_COUNT); this function is for integers only, if you just need to reserve space you can use acpi_data_push(). > + > + /* Allocate guest memory for the hardware error fw_cfg blob */ /* tell guest firmware to place hardware_errors blob into RAM */ > + bios_linker_loader_alloc(linker, ACPI_GHES_ERRORS_FW_CFG_FILE, > + hardware_errors, 1, false); > + > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > + /* > + * Patch the address of Error Status Data Block into > + * the error_block_address of hardware_errors fw_cfg blob Tell firmware to patch error_block_address entries to point to corresponding "Error Status Data Block" > + */ > + bios_linker_loader_add_pointer(linker, > + ACPI_GHES_ERRORS_FW_CFG_FILE, ACPI_GHES_ADDRESS_SIZE * i, > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > + error_status_block_offset + i * ACPI_GHES_MAX_RAW_DATA_LENGTH); > + } > + > + /* > + * Write the address of hardware_errors blob into the > + * hardware_errors_addr fw_cfg blob. /* tell firmware to write hardware_errors GPA into hardware_errors_addr fw_cfg, once the former has been initialized. */ > + */ > + bios_linker_loader_write_pointer(linker, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, > + 0, ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, 0); > +} > + > +/* Build Hardware Error Source Table */ > +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_errors, > + BIOSLinker *linker) it's not GEST specific table, so build_hest() > +{ > + uint32_t hest_start = table_data->len; > + uint32_t source_id = 0; > + > + /* Hardware Error Source Table header*/ > + acpi_data_push(table_data, sizeof(AcpiTableHeader)); > + > + /* Error Source Count */ > + build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4); > + this is the place where all error source structures will be enumerated. I'd move out GHESv2 specific coed into a separate function so that code here would look like this build_ghes_v2(...); > + /* > + * Type: > + * Generic Hardware Error Source version 2(GHESv2 - Type 10) > + */ > + build_append_int_noprefix(table_data, ACPI_GHES_SOURCE_GENERIC_ERROR_V2, 2); > + /* > + * Source Id > + * Once we support more than one hardware error sources, we need to > + * increase the value of this field. I'm not sure ^^^ is correct, according to spec it's just unique id per distinct error structure, so we just assign arbitrary values to each declared source and that never changes once assigned. For now I'd make source_id an enum with one member enum { ACPI_HEST_SRC_ID_SEA = 0, /* future ids go here */ ACPI_HEST_SRC_ID_RESERVED, } and use that instead of allocating magic 0 at the beginning of the function. build_ghes_v2(ACPI_HEST_GHES_SEA); Also add a comment to declaration that already assigned values are not to be changed > + */ > + build_append_int_noprefix(table_data, source_id, 2); > + /* Related Source Id */ > + build_append_int_noprefix(table_data, 0xffff, 2); > + /* Flags */ > + build_append_int_noprefix(table_data, 0, 1); > + /* Enabled */ > + build_append_int_noprefix(table_data, 1, 1); > + > + /* Number of Records To Pre-allocate */ > + build_append_int_noprefix(table_data, 1, 4); > + /* Max Sections Per Record */ > + build_append_int_noprefix(table_data, 1, 4); > + /* Max Raw Data Length */ > + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > + > + /* Error Status Address */ > + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > + 4 /* QWord access */, 0); > + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), it's fine only if GHESv2 is the only entries in HEST, but once other types are added this macro will silently fall apart and cause table corruption. Instead of offset from hest_start, I suggest to use offset relative to GAS structure, here is an idea #define GAS_ADDR_OFFSET 4 off = table->len build_append_gas() bios_linker_loader_add_pointer(..., off + GAS_ADDR_OFFSET, ... > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > + source_id * ACPI_GHES_ADDRESS_SIZE); > + > + /* > + * Notification Structure > + * Now only enable ARMv8 SEA notification type > + */ > + acpi_ghes_build_notify(table_data, ACPI_GHES_NOTIFY_SEA); > + > + /* Error Status Block Length */ > + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > + > + /* > + * Read Ack Register > + * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source > + * version 2 (GHESv2 - Type 10) > + */ > + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > + 4 /* QWord access */, 0); > + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > + ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(hest_start, 0), ditto > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > + (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) * ACPI_GHES_ADDRESS_SIZE); > + > + /* > + * Read Ack Preserve > + * We only provide the first bit in Read Ack Register to OSPM to write > + * while the other bits are preserved. > + */ > + build_append_int_noprefix(table_data, ~0x1ULL, 8); > + /* Read Ack Write */ > + build_append_int_noprefix(table_data, 0x1, 8); > + > + build_header(linker, table_data, (void *)(table_data->data + hest_start), > + "HEST", table_data->len - hest_start, 1, NULL, "GHES"); hest is not GHEST specific so s/GHES/NULL/ > +} > + > +static AcpiGhesState ges; > +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_error) > +{ > + > + size_t size = 2 * ACPI_GHES_ADDRESS_SIZE + ACPI_GHES_MAX_RAW_DATA_LENGTH; > + size_t request_block_size = ACPI_GHES_ERROR_SOURCE_COUNT * size; > + > + /* Create a read-only fw_cfg file for GHES */ > + fw_cfg_add_file(s, ACPI_GHES_ERRORS_FW_CFG_FILE, hardware_error->data, > + request_block_size); > + > + /* Create a read-write fw_cfg file for Address */ > + fw_cfg_add_file_callback(s, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, NULL, NULL, > + NULL, &ges.ghes_addr_le, sizeof(ges.ghes_addr_le), false); > +} > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index 2c3702b882..3681ec6e3d 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -1578,6 +1578,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) > tables->table_data = g_array_new(false, true /* clear */, 1); > tables->tcpalog = g_array_new(false, true /* clear */, 1); > tables->vmgenid = g_array_new(false, true /* clear */, 1); > + tables->hardware_errors = g_array_new(false, true /* clear */, 1); > tables->linker = bios_linker_loader_init(); > } > > @@ -1588,6 +1589,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) > g_array_free(tables->table_data, true); > g_array_free(tables->tcpalog, mfre); > g_array_free(tables->vmgenid, mfre); > + g_array_free(tables->hardware_errors, mfre); > } > > /* > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > index 4cd50175e0..1b1fd273e4 100644 > --- a/hw/arm/virt-acpi-build.c > +++ b/hw/arm/virt-acpi-build.c > @@ -48,6 +48,7 @@ > #include "sysemu/reset.h" > #include "kvm_arm.h" > #include "migration/vmstate.h" > +#include "hw/acpi/acpi_ghes.h" > > #define ARM_SPI_BASE 32 > > @@ -825,6 +826,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) > acpi_add_table(table_offsets, tables_blob); > build_spcr(tables_blob, tables->linker, vms); > > + if (vms->ras) { > + acpi_add_table(table_offsets, tables_blob); > + acpi_ghes_build_error_table(tables->hardware_errors, tables->linker); > + acpi_ghes_build_hest(tables_blob, tables->hardware_errors, > + tables->linker); > + } > + > if (ms->numa_state->num_nodes > 0) { > acpi_add_table(table_offsets, tables_blob); > build_srat(tables_blob, tables->linker, vms); > @@ -942,6 +950,10 @@ void virt_acpi_setup(VirtMachineState *vms) > fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, > acpi_data_len(tables.tcpalog)); > > + if (vms->ras) { > + acpi_ghes_add_fw_cfg(vms->fw_cfg, tables.hardware_errors); > + } > + > build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, > build_state, tables.rsdp, > ACPI_BUILD_RSDP_FILE, 0); > diff --git a/include/hw/acpi/acpi_ghes.h b/include/hw/acpi/acpi_ghes.h > new file mode 100644 > index 0000000000..cb62ec9c7b > --- /dev/null > +++ b/include/hw/acpi/acpi_ghes.h > @@ -0,0 +1,56 @@ > +/* > + * Support for generating APEI tables and recording CPER for Guests > + * > + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > + * > + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + > + * 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, see <http://www.gnu.org/licenses/>. > + */ > + > +#ifndef ACPI_GHES_H > +#define ACPI_GHES_H > + > +#include "hw/acpi/bios-linker-loader.h" > + > +/* > + * Values for Hardware Error Notification Type field > + */ > +enum AcpiGhesNotifyType { > + ACPI_GHES_NOTIFY_POLLED = 0, /* Polled */ > + ACPI_GHES_NOTIFY_EXTERNAL = 1, /* External Interrupt */ > + ACPI_GHES_NOTIFY_LOCAL = 2, /* Local Interrupt */ > + ACPI_GHES_NOTIFY_SCI = 3, /* SCI */ > + ACPI_GHES_NOTIFY_NMI = 4, /* NMI */ > + ACPI_GHES_NOTIFY_CMCI = 5, /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ > + ACPI_GHES_NOTIFY_MCE = 6, /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ > + /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ > + ACPI_GHES_NOTIFY_GPIO = 7, > + /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ > + ACPI_GHES_NOTIFY_SEA = 8, > + /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ > + ACPI_GHES_NOTIFY_SEI = 9, > + /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ > + ACPI_GHES_NOTIFY_GSIV = 10, > + /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ > + ACPI_GHES_NOTIFY_SDEI = 11, > + ACPI_GHES_NOTIFY_RESERVED = 12 /* 12 and greater are reserved */ > +}; maybe make all comment go on newline, otherwise zoo above look ugly > + > +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_error, > + BIOSLinker *linker); > + > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker); > +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_errors); > +#endif > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index de4a406568..8f13620701 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -220,6 +220,7 @@ struct AcpiBuildTables { > GArray *rsdp; > GArray *tcpalog; > GArray *vmgenid; > + GArray *hardware_errors; > BIOSLinker *linker; > } AcpiBuildTables; > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-15 9:38 ` Igor Mammedov @ 2019-11-18 12:49 ` gengdongjiu 2019-11-18 13:18 ` gengdongjiu 2019-11-22 15:44 ` Beata Michalska 0 siblings, 2 replies; 14+ messages in thread From: gengdongjiu @ 2019-11-18 12:49 UTC (permalink / raw) To: Igor Mammedov, Xiang Zheng Cc: pbonzini, mst, shannon.zhaosl, peter.maydell, lersek, james.morse, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang Hi,Igor, Thanks for you review and time. > >> + /* >> + * Type: >> + * Generic Hardware Error Source version 2(GHESv2 - Type 10) >> + */ >> + build_append_int_noprefix(table_data, ACPI_GHES_SOURCE_GENERIC_ERROR_V2, 2); >> + /* >> + * Source Id > >> + * Once we support more than one hardware error sources, we need to >> + * increase the value of this field. > I'm not sure ^^^ is correct, according to spec it's just unique id per > distinct error structure, so we just assign arbitrary values to each > declared source and that never changes once assigned. The source id is used to distinct the error source, for each source, the ‘source id’ is unique, but different source has different source id. for example, the 'source id' of the error source 0 is 0, the 'source id' of the error source 1 is 1. > > For now I'd make source_id an enum with one member > enum { > ACPI_HEST_SRC_ID_SEA = 0, > /* future ids go here */ > ACPI_HEST_SRC_ID_RESERVED, > } If we only have one error source, we can use enum instead of allocating magic 0. But if we have more error source , such as 10 error source. using enum maybe not a good idea. for example, if there are 10 error sources, I can just using below loop for(i=0; i< 10; i++) build_ghes_v2(source_id++); > > and use that instead of allocating magic 0 at the beginning of the function. > build_ghes_v2(ACPI_HEST_GHES_SEA); > Also add a comment to declaration that already assigned values are not to be changed > >> + */ >> + build_append_int_noprefix(table_data, source_id, 2); >> + /* Related Source Id */ >> + build_append_int_noprefix(table_data, 0xffff, 2); >> + /* Flags */ >> + build_append_int_noprefix(table_data, 0, 1); >> + /* Enabled */ >> + build_append_int_noprefix(table_data, 1, 1); >> + >> + /* Number of Records To Pre-allocate */ >> + build_append_int_noprefix(table_data, 1, 4); >> + /* Max Sections Per Record */ >> + build_append_int_noprefix(table_data, 1, 4); >> + /* Max Raw Data Length */ >> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); >> + >> + /* Error Status Address */ >> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, >> + 4 /* QWord access */, 0); >> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, >> + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > it's fine only if GHESv2 is the only entries in HEST, but once > other types are added this macro will silently fall apart and > cause table corruption. > > Instead of offset from hest_start, I suggest to use offset relative > to GAS structure, here is an idea > > #define GAS_ADDR_OFFSET 4 > > off = table->len > build_append_gas() > bios_linker_loader_add_pointer(..., > off + GAS_ADDR_OFFSET, ... I think your suggestion is good. > >> + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, >> + source_id * ACPI_GHES_ADDRESS_SIZE); >> + >> + /* >> + * Notification Structure >> + * Now only enable ARMv8 SEA notification type >> + */ >> + acpi_ghes_build_notify(table_data, ACPI_GHES_NOTIFY_SEA); >> + >> + /* Error Status Block Length */ >> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); >> + >> + /* >> + * Read Ack Register >> + * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source >> + * version 2 (GHESv2 - Type 10) >> + */ >> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, >> + 4 /* QWord access */, 0); >> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, >> + ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(hest_start, 0), > ditto > >> + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, >> + (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) * ACPI_GHES_ADDRESS_SIZE); >> + >> + /* >> + * Read Ack Preserve >> + * We only provide the first bit in Read Ack Register to OSPM to write >> + * while the other bits are preserved. >> + */ >> + build_append_int_noprefix(table_data, ~0x1ULL, 8); >> + /* Read Ack Write */ >> + build_append_int_noprefix(table_data, 0x1, 8); >> + >> + build_header(linker, table_data, (void *)(table_data->data + hest_start), >> + "HEST", table_data->len - hest_start, 1, NULL, "GHES"); > hest is not GHEST specific so s/GHES/NULL/ > >> +} >> + >> +static AcpiGhesState ges; >> +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_error) >> +{ >> + >> + size_t size = 2 * ACPI_GHES_ADDRESS_SIZE + ACPI_GHES_MAX_RAW_DATA_LENGTH; >> + size_t request_block_size = ACPI_GHES_ERROR_SOURCE_COUNT * size; >> + > >> + /* Create a read-only fw_cfg file for GHES */ >> + fw_cfg_add_file(s, ACPI_GHES_ERRORS_FW_CFG_FILE, hardware_error->data, >> + request_block_size); >> + >> + /* Create a read-write fw_cfg file for Address */ >> + fw_cfg_add_file_callback(s, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, NULL, NULL, >> + NULL, &ges.ghes_addr_le, sizeof(ges.ghes_addr_le), false); >> +} >> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c >> index 2c3702b882..3681ec6e3d 100644 >> --- a/hw/acpi/aml-build.c >> +++ b/hw/acpi/aml-build.c >> @@ -1578,6 +1578,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) >> tables->table_data = g_array_new(false, true /* clear */, 1); >> tables->tcpalog = g_array_new(false, true /* clear */, 1); >> tables->vmgenid = g_array_new(false, true /* clear */, 1); >> + tables->hardware_errors = g_array_new(false, true /* clear */, 1); >> tables->linker = bios_linker_loader_init(); >> } >> >> @@ -1588,6 +1589,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) >> g_array_free(tables->table_data, true); >> g_array_free(tables->tcpalog, mfre); >> g_array_free(tables->vmgenid, mfre); >> + g_array_free(tables->hardware_errors, mfre); >> } >> >> /* >> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c >> index 4cd50175e0..1b1fd273e4 100644 >> --- a/hw/arm/virt-acpi-build.c >> +++ b/hw/arm/virt-acpi-build.c >> @@ -48,6 +48,7 @@ >> #include "sysemu/reset.h" >> #include "kvm_arm.h" >> #include "migration/vmstate.h" >> +#include "hw/acpi/acpi_ghes.h" >> >> #define ARM_SPI_BASE 32 >> >> @@ -825,6 +826,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) >> acpi_add_table(table_offsets, tables_blob); >> build_spcr(tables_blob, tables->linker, vms); >> >> + if (vms->ras) { >> + acpi_add_table(table_offsets, tables_blob); >> + acpi_ghes_build_error_table(tables->hardware_errors, tables->linker); >> + acpi_ghes_build_hest(tables_blob, tables->hardware_errors, >> + tables->linker); >> + } >> + >> if (ms->numa_state->num_nodes > 0) { >> acpi_add_table(table_offsets, tables_blob); >> build_srat(tables_blob, tables->linker, vms); >> @@ -942,6 +950,10 @@ void virt_acpi_setup(VirtMachineState *vms) >> fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, >> acpi_data_len(tables.tcpalog)); >> >> + if (vms->ras) { >> + acpi_ghes_add_fw_cfg(vms->fw_cfg, tables.hardware_errors); >> + } >> + >> build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, >> build_state, tables.rsdp, >> ACPI_BUILD_RSDP_FILE, 0); >> diff --git a/include/hw/acpi/acpi_ghes.h b/include/hw/acpi/acpi_ghes.h >> new file mode 100644 >> index 0000000000..cb62ec9c7b >> --- /dev/null >> +++ b/include/hw/acpi/acpi_ghes.h >> @@ -0,0 +1,56 @@ >> +/* >> + * Support for generating APEI tables and recording CPER for Guests >> + * >> + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. >> + * >> + * Author: Dongjiu Geng <gengdongjiu@huawei.com> >> + * >> + * This program is free software; you can redistribute it and/or modify >> + * it under the terms of the GNU General Public License as published by >> + * the Free Software Foundation; either version 2 of the License, or >> + * (at your option) any later version. >> + >> + * 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, see <http://www.gnu.org/licenses/>. >> + */ >> + >> +#ifndef ACPI_GHES_H >> +#define ACPI_GHES_H >> + >> +#include "hw/acpi/bios-linker-loader.h" >> + >> +/* >> + * Values for Hardware Error Notification Type field >> + */ >> +enum AcpiGhesNotifyType { >> + ACPI_GHES_NOTIFY_POLLED = 0, /* Polled */ >> + ACPI_GHES_NOTIFY_EXTERNAL = 1, /* External Interrupt */ >> + ACPI_GHES_NOTIFY_LOCAL = 2, /* Local Interrupt */ >> + ACPI_GHES_NOTIFY_SCI = 3, /* SCI */ >> + ACPI_GHES_NOTIFY_NMI = 4, /* NMI */ >> + ACPI_GHES_NOTIFY_CMCI = 5, /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ >> + ACPI_GHES_NOTIFY_MCE = 6, /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ >> + /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ >> + ACPI_GHES_NOTIFY_GPIO = 7, >> + /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ >> + ACPI_GHES_NOTIFY_SEA = 8, >> + /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ >> + ACPI_GHES_NOTIFY_SEI = 9, >> + /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ >> + ACPI_GHES_NOTIFY_GSIV = 10, >> + /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ >> + ACPI_GHES_NOTIFY_SDEI = 11, >> + ACPI_GHES_NOTIFY_RESERVED = 12 /* 12 and greater are reserved */ >> +}; > maybe make all comment go on newline, otherwise zoo above look ugly sure. > >> + >> +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_error, >> + BIOSLinker *linker); >> + >> +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker); >> +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_errors); >> +#endif >> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h >> index de4a406568..8f13620701 100644 >> --- a/include/hw/acpi/aml-build.h >> +++ b/include/hw/acpi/aml-build.h >> @@ -220,6 +220,7 @@ struct AcpiBuildTables { >> GArray *rsdp; >> GArray *tcpalog; >> GArray *vmgenid; >> + GArray *hardware_errors; >> BIOSLinker *linker; >> } AcpiBuildTables; >> > > . > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-18 12:49 ` gengdongjiu @ 2019-11-18 13:18 ` gengdongjiu 2019-11-18 13:21 ` Michael S. Tsirkin 2019-11-22 15:44 ` Beata Michalska 1 sibling, 1 reply; 14+ messages in thread From: gengdongjiu @ 2019-11-18 13:18 UTC (permalink / raw) To: Igor Mammedov, Xiang Zheng Cc: pbonzini, mst, shannon.zhaosl, peter.maydell, lersek, james.morse, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang On 2019/11/18 20:49, gengdongjiu wrote: >>> + */ >>> + build_append_int_noprefix(table_data, source_id, 2); >>> + /* Related Source Id */ >>> + build_append_int_noprefix(table_data, 0xffff, 2); >>> + /* Flags */ >>> + build_append_int_noprefix(table_data, 0, 1); >>> + /* Enabled */ >>> + build_append_int_noprefix(table_data, 1, 1); >>> + >>> + /* Number of Records To Pre-allocate */ >>> + build_append_int_noprefix(table_data, 1, 4); >>> + /* Max Sections Per Record */ >>> + build_append_int_noprefix(table_data, 1, 4); >>> + /* Max Raw Data Length */ >>> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); >>> + >>> + /* Error Status Address */ >>> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, >>> + 4 /* QWord access */, 0); >>> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, >>> + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), >> it's fine only if GHESv2 is the only entries in HEST, but once >> other types are added this macro will silently fall apart and >> cause table corruption. why silently fall? I think the acpi_ghes.c only support GHESv2 type, not support other type. >> >> Instead of offset from hest_start, I suggest to use offset relative >> to GAS structure, here is an idea>> >> #define GAS_ADDR_OFFSET 4 >> >> off = table->len >> build_append_gas() >> bios_linker_loader_add_pointer(..., >> off + GAS_ADDR_OFFSET, ... If use offset relative to GAS structure, the code does not easily extend to support more Generic Hardware Error Source. if use offset relative to hest_start, just use a loop, the code can support more error source, for example: for (source_id = 0; i<n; source_id++) { ...... bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, source_id * sizeof(uint64_t)); ....... } My previous series patch support 2 error sources, but now only enable 'SEA' type Error Source ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-18 13:18 ` gengdongjiu @ 2019-11-18 13:21 ` Michael S. Tsirkin 2019-11-18 13:57 ` gengdongjiu 2019-11-25 9:48 ` Igor Mammedov 0 siblings, 2 replies; 14+ messages in thread From: Michael S. Tsirkin @ 2019-11-18 13:21 UTC (permalink / raw) To: gengdongjiu Cc: Igor Mammedov, Xiang Zheng, pbonzini, shannon.zhaosl, peter.maydell, lersek, james.morse, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang On Mon, Nov 18, 2019 at 09:18:01PM +0800, gengdongjiu wrote: > On 2019/11/18 20:49, gengdongjiu wrote: > >>> + */ > >>> + build_append_int_noprefix(table_data, source_id, 2); > >>> + /* Related Source Id */ > >>> + build_append_int_noprefix(table_data, 0xffff, 2); > >>> + /* Flags */ > >>> + build_append_int_noprefix(table_data, 0, 1); > >>> + /* Enabled */ > >>> + build_append_int_noprefix(table_data, 1, 1); > >>> + > >>> + /* Number of Records To Pre-allocate */ > >>> + build_append_int_noprefix(table_data, 1, 4); > >>> + /* Max Sections Per Record */ > >>> + build_append_int_noprefix(table_data, 1, 4); > >>> + /* Max Raw Data Length */ > >>> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > >>> + > >>> + /* Error Status Address */ > >>> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > >>> + 4 /* QWord access */, 0); > >>> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > >>> + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > >> it's fine only if GHESv2 is the only entries in HEST, but once > >> other types are added this macro will silently fall apart and > >> cause table corruption. > why silently fall? > I think the acpi_ghes.c only support GHESv2 type, not support other type. > > >> > >> Instead of offset from hest_start, I suggest to use offset relative > >> to GAS structure, here is an idea>> > >> #define GAS_ADDR_OFFSET 4 > >> > >> off = table->len > >> build_append_gas() > >> bios_linker_loader_add_pointer(..., > >> off + GAS_ADDR_OFFSET, ... > > If use offset relative to GAS structure, the code does not easily extend to support more Generic Hardware Error Source. > if use offset relative to hest_start, just use a loop, the code can support more error source, for example: > for (source_id = 0; i<n; source_id++) > { > ...... > bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, > source_id * sizeof(uint64_t)); > ....... > } > > My previous series patch support 2 error sources, but now only enable 'SEA' type Error Source I'd try to merge this, worry about extending things later. This is at v21 and the simpler you can keep things, the faster it'll go in. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-18 13:21 ` Michael S. Tsirkin @ 2019-11-18 13:57 ` gengdongjiu 2019-11-25 9:48 ` Igor Mammedov 1 sibling, 0 replies; 14+ messages in thread From: gengdongjiu @ 2019-11-18 13:57 UTC (permalink / raw) To: Michael S. Tsirkin Cc: Igor Mammedov, Xiang Zheng, pbonzini, shannon.zhaosl, peter.maydell, lersek, james.morse, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang On 2019/11/18 21:21, Michael S. Tsirkin wrote: >> If use offset relative to GAS structure, the code does not easily extend to support more Generic Hardware Error Source. >> if use offset relative to hest_start, just use a loop, the code can support more error source, for example: >> for (source_id = 0; i<n; source_id++) >> { >> ...... >> bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, >> ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), >> sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, >> source_id * sizeof(uint64_t)); >> ....... >> } >> >> My previous series patch support 2 error sources, but now only enable 'SEA' type Error Source > I'd try to merge this, worry about extending things later. > This is at v21 and the simpler you can keep things, > the faster it'll go in. Thanks a lot for the comments. Yes, I think we can merge the v21 series. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-18 13:21 ` Michael S. Tsirkin 2019-11-18 13:57 ` gengdongjiu @ 2019-11-25 9:48 ` Igor Mammedov 2019-11-27 11:16 ` gengdongjiu 1 sibling, 1 reply; 14+ messages in thread From: Igor Mammedov @ 2019-11-25 9:48 UTC (permalink / raw) To: Michael S. Tsirkin Cc: gengdongjiu, peter.maydell, ehabkost, kvm, wanghaibin.wang, mtosatti, qemu-devel, linuxarm, shannon.zhaosl, Xiang Zheng, qemu-arm, james.morse, jonathan.cameron, pbonzini, xuwei5, lersek, rth On Mon, 18 Nov 2019 08:21:18 -0500 "Michael S. Tsirkin" <mst@redhat.com> wrote: > On Mon, Nov 18, 2019 at 09:18:01PM +0800, gengdongjiu wrote: > > On 2019/11/18 20:49, gengdongjiu wrote: > > >>> + */ > > >>> + build_append_int_noprefix(table_data, source_id, 2); > > >>> + /* Related Source Id */ > > >>> + build_append_int_noprefix(table_data, 0xffff, 2); > > >>> + /* Flags */ > > >>> + build_append_int_noprefix(table_data, 0, 1); > > >>> + /* Enabled */ > > >>> + build_append_int_noprefix(table_data, 1, 1); > > >>> + > > >>> + /* Number of Records To Pre-allocate */ > > >>> + build_append_int_noprefix(table_data, 1, 4); > > >>> + /* Max Sections Per Record */ > > >>> + build_append_int_noprefix(table_data, 1, 4); > > >>> + /* Max Raw Data Length */ > > >>> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > > >>> + > > >>> + /* Error Status Address */ > > >>> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > > >>> + 4 /* QWord access */, 0); > > >>> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > > >>> + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > > >> it's fine only if GHESv2 is the only entries in HEST, but once > > >> other types are added this macro will silently fall apart and > > >> cause table corruption. > > why silently fall? > > I think the acpi_ghes.c only support GHESv2 type, not support other type. > > > > >> > > >> Instead of offset from hest_start, I suggest to use offset relative > > >> to GAS structure, here is an idea>> > > >> #define GAS_ADDR_OFFSET 4 > > >> > > >> off = table->len > > >> build_append_gas() > > >> bios_linker_loader_add_pointer(..., > > >> off + GAS_ADDR_OFFSET, ... > > > > If use offset relative to GAS structure, the code does not easily extend to support more Generic Hardware Error Source. > > if use offset relative to hest_start, just use a loop, the code can support more error source, for example: > > for (source_id = 0; i<n; source_id++) > > { > > ...... > > bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > > ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > > sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, > > source_id * sizeof(uint64_t)); > > ....... > > } > > > > My previous series patch support 2 error sources, but now only enable 'SEA' type Error Source > > I'd try to merge this, worry about extending things later. > This is at v21 and the simpler you can keep things, > the faster it'll go in. I don't think the series is ready for merging yet. It has a number of issues (not stylistic ones) that need to be fixed first. As for extending, I think I've suggested to simplify series to account for single error source only in some places so it would be easier on author and reviewers and worry about extending it later. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-25 9:48 ` Igor Mammedov @ 2019-11-27 11:16 ` gengdongjiu 0 siblings, 0 replies; 14+ messages in thread From: gengdongjiu @ 2019-11-27 11:16 UTC (permalink / raw) To: Igor Mammedov, Michael S. Tsirkin Cc: peter.maydell, ehabkost, kvm, wanghaibin.wang, mtosatti, qemu-devel, linuxarm, shannon.zhaosl, Xiang Zheng, qemu-arm, james.morse, jonathan.cameron, pbonzini, xuwei5, lersek, rth On 2019/11/25 17:48, Igor Mammedov wrote: >>> ...... >>> bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, >>> ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), >>> sizeof(uint64_t), ACPI_GHES_ERRORS_FW_CFG_FILE, >>> source_id * sizeof(uint64_t)); >>> ....... >>> } >>> >>> My previous series patch support 2 error sources, but now only enable 'SEA' type Error Source >> I'd try to merge this, worry about extending things later. >> This is at v21 and the simpler you can keep things, >> the faster it'll go in. > I don't think the series is ready for merging yet. > It has a number of issues (not stylistic ones) that need to be fixed first. > > As for extending, I think I've suggested to simplify series > to account for single error source only in some places so it > would be easier on author and reviewers and worry about extending > it later. sure, thanks for the review, we are preparing another series which will fix the issues that you mentioned. > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-18 12:49 ` gengdongjiu 2019-11-18 13:18 ` gengdongjiu @ 2019-11-22 15:44 ` Beata Michalska 1 sibling, 0 replies; 14+ messages in thread From: Beata Michalska @ 2019-11-22 15:44 UTC (permalink / raw) To: gengdongjiu Cc: Igor Mammedov, Xiang Zheng, Peter Maydell, ehabkost, kvm, mst, wanghaibin.wang, mtosatti, qemu-devel, linuxarm, shannon.zhaosl, qemu-arm, james.morse, xuwei5, jonathan.cameron, pbonzini, Laszlo Ersek, rth Hi, On Mon, 18 Nov 2019 at 12:50, gengdongjiu <gengdongjiu@huawei.com> wrote: > > Hi,Igor, > Thanks for you review and time. > > > > >> + /* > >> + * Type: > >> + * Generic Hardware Error Source version 2(GHESv2 - Type 10) > >> + */ > >> + build_append_int_noprefix(table_data, ACPI_GHES_SOURCE_GENERIC_ERROR_V2, 2); > >> + /* > >> + * Source Id > > > >> + * Once we support more than one hardware error sources, we need to > >> + * increase the value of this field. > > I'm not sure ^^^ is correct, according to spec it's just unique id per > > distinct error structure, so we just assign arbitrary values to each > > declared source and that never changes once assigned. > The source id is used to distinct the error source, for each source, the ‘source id’ is unique, > but different source has different source id. for example, the 'source id' of the error source 0 is 0, > the 'source id' of the error source 1 is 1. > I might be wrong but the source id is not a sequence number and it can have any value as long as it is unique and the comment 're 'increasing the number' reads bit wrong. > > > > > For now I'd make source_id an enum with one member > > enum { > > ACPI_HEST_SRC_ID_SEA = 0, > > /* future ids go here */ > > ACPI_HEST_SRC_ID_RESERVED, > > } > If we only have one error source, we can use enum instead of allocating magic 0. > But if we have more error source , such as 10 error source. using enum maybe not a good idea. > > for example, if there are 10 error sources, I can just using below loop > > for(i=0; i< 10; i++) > build_ghes_v2(source_id++); > You can do that but using enum makes it more readable and maintainable. Also you can keep the source id as a sequence number but still represent that with enum, as it has been suggested, and use the 'RESERVED' field for loop control. I think it might be also worth to represent the HES type as enum as well : enum{ ACPI_HES_TYPE_GHESv2 = 10, }; > > > > and use that instead of allocating magic 0 at the beginning of the function. > > build_ghes_v2(ACPI_HEST_GHES_SEA); > > Also add a comment to declaration that already assigned values are not to be changed > > > >> + */ > >> + build_append_int_noprefix(table_data, source_id, 2); > >> + /* Related Source Id */ > >> + build_append_int_noprefix(table_data, 0xffff, 2); > >> + /* Flags */ > >> + build_append_int_noprefix(table_data, 0, 1); > >> + /* Enabled */ > >> + build_append_int_noprefix(table_data, 1, 1); > >> + > >> + /* Number of Records To Pre-allocate */ > >> + build_append_int_noprefix(table_data, 1, 4); > >> + /* Max Sections Per Record */ > >> + build_append_int_noprefix(table_data, 1, 4); > >> + /* Max Raw Data Length */ > >> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > >> + > >> + /* Error Status Address */ > >> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > >> + 4 /* QWord access */, 0); > >> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > >> + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > > it's fine only if GHESv2 is the only entries in HEST, but once > > other types are added this macro will silently fall apart and > > cause table corruption. > > > > Instead of offset from hest_start, I suggest to use offset relative > > to GAS structure, here is an idea > > > > #define GAS_ADDR_OFFSET 4 > > > > off = table->len > > build_append_gas() > > bios_linker_loader_add_pointer(..., > > off + GAS_ADDR_OFFSET, ... > I think your suggestion is good. > > > > >> + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > >> + source_id * ACPI_GHES_ADDRESS_SIZE); > >> + > >> + /* > >> + * Notification Structure > >> + * Now only enable ARMv8 SEA notification type > >> + */ > >> + acpi_ghes_build_notify(table_data, ACPI_GHES_NOTIFY_SEA); > >> + > >> + /* Error Status Block Length */ > >> + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > >> + > >> + /* > >> + * Read Ack Register > >> + * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source > >> + * version 2 (GHESv2 - Type 10) > >> + */ > >> + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > >> + 4 /* QWord access */, 0); > >> + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > >> + ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(hest_start, 0), > > ditto > > > >> + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > >> + (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) * ACPI_GHES_ADDRESS_SIZE); > >> + > >> + /* > >> + * Read Ack Preserve > >> + * We only provide the first bit in Read Ack Register to OSPM to write > >> + * while the other bits are preserved. > >> + */ > >> + build_append_int_noprefix(table_data, ~0x1ULL, 8); > >> + /* Read Ack Write */ > >> + build_append_int_noprefix(table_data, 0x1, 8); > >> + > >> + build_header(linker, table_data, (void *)(table_data->data + hest_start), > >> + "HEST", table_data->len - hest_start, 1, NULL, "GHES"); > > hest is not GHEST specific so s/GHES/NULL/ > > > >> +} > >> + > >> +static AcpiGhesState ges; > >> +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_error) > >> +{ > >> + > >> + size_t size = 2 * ACPI_GHES_ADDRESS_SIZE + ACPI_GHES_MAX_RAW_DATA_LENGTH; > >> + size_t request_block_size = ACPI_GHES_ERROR_SOURCE_COUNT * size; > >> + > > > >> + /* Create a read-only fw_cfg file for GHES */ > >> + fw_cfg_add_file(s, ACPI_GHES_ERRORS_FW_CFG_FILE, hardware_error->data, > >> + request_block_size); > >> + > >> + /* Create a read-write fw_cfg file for Address */ > >> + fw_cfg_add_file_callback(s, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, NULL, NULL, > >> + NULL, &ges.ghes_addr_le, sizeof(ges.ghes_addr_le), false); > >> +} > >> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > >> index 2c3702b882..3681ec6e3d 100644 > >> --- a/hw/acpi/aml-build.c > >> +++ b/hw/acpi/aml-build.c > >> @@ -1578,6 +1578,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) > >> tables->table_data = g_array_new(false, true /* clear */, 1); > >> tables->tcpalog = g_array_new(false, true /* clear */, 1); > >> tables->vmgenid = g_array_new(false, true /* clear */, 1); > >> + tables->hardware_errors = g_array_new(false, true /* clear */, 1); > >> tables->linker = bios_linker_loader_init(); > >> } > >> > >> @@ -1588,6 +1589,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) > >> g_array_free(tables->table_data, true); > >> g_array_free(tables->tcpalog, mfre); > >> g_array_free(tables->vmgenid, mfre); > >> + g_array_free(tables->hardware_errors, mfre); > >> } > >> > >> /* > >> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > >> index 4cd50175e0..1b1fd273e4 100644 > >> --- a/hw/arm/virt-acpi-build.c > >> +++ b/hw/arm/virt-acpi-build.c > >> @@ -48,6 +48,7 @@ > >> #include "sysemu/reset.h" > >> #include "kvm_arm.h" > >> #include "migration/vmstate.h" > >> +#include "hw/acpi/acpi_ghes.h" > >> > >> #define ARM_SPI_BASE 32 > >> > >> @@ -825,6 +826,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) > >> acpi_add_table(table_offsets, tables_blob); > >> build_spcr(tables_blob, tables->linker, vms); > >> > >> + if (vms->ras) { > >> + acpi_add_table(table_offsets, tables_blob); > >> + acpi_ghes_build_error_table(tables->hardware_errors, tables->linker); > >> + acpi_ghes_build_hest(tables_blob, tables->hardware_errors, > >> + tables->linker); > >> + } > >> + > >> if (ms->numa_state->num_nodes > 0) { > >> acpi_add_table(table_offsets, tables_blob); > >> build_srat(tables_blob, tables->linker, vms); > >> @@ -942,6 +950,10 @@ void virt_acpi_setup(VirtMachineState *vms) > >> fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, > >> acpi_data_len(tables.tcpalog)); > >> > >> + if (vms->ras) { > >> + acpi_ghes_add_fw_cfg(vms->fw_cfg, tables.hardware_errors); > >> + } > >> + > >> build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, > >> build_state, tables.rsdp, > >> ACPI_BUILD_RSDP_FILE, 0); > >> diff --git a/include/hw/acpi/acpi_ghes.h b/include/hw/acpi/acpi_ghes.h > >> new file mode 100644 > >> index 0000000000..cb62ec9c7b > >> --- /dev/null > >> +++ b/include/hw/acpi/acpi_ghes.h > >> @@ -0,0 +1,56 @@ > >> +/* > >> + * Support for generating APEI tables and recording CPER for Guests > >> + * > >> + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > >> + * > >> + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > >> + * > >> + * This program is free software; you can redistribute it and/or modify > >> + * it under the terms of the GNU General Public License as published by > >> + * the Free Software Foundation; either version 2 of the License, or > >> + * (at your option) any later version. > >> + > >> + * 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, see <http://www.gnu.org/licenses/>. > >> + */ > >> + > >> +#ifndef ACPI_GHES_H > >> +#define ACPI_GHES_H > >> + > >> +#include "hw/acpi/bios-linker-loader.h" > >> + > >> +/* > >> + * Values for Hardware Error Notification Type field > >> + */ > >> +enum AcpiGhesNotifyType { > >> + ACPI_GHES_NOTIFY_POLLED = 0, /* Polled */ > >> + ACPI_GHES_NOTIFY_EXTERNAL = 1, /* External Interrupt */ > >> + ACPI_GHES_NOTIFY_LOCAL = 2, /* Local Interrupt */ > >> + ACPI_GHES_NOTIFY_SCI = 3, /* SCI */ > >> + ACPI_GHES_NOTIFY_NMI = 4, /* NMI */ > >> + ACPI_GHES_NOTIFY_CMCI = 5, /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ > >> + ACPI_GHES_NOTIFY_MCE = 6, /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ > >> + /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ > >> + ACPI_GHES_NOTIFY_GPIO = 7, > >> + /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ > >> + ACPI_GHES_NOTIFY_SEA = 8, > >> + /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ > >> + ACPI_GHES_NOTIFY_SEI = 9, > >> + /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ > >> + ACPI_GHES_NOTIFY_GSIV = 10, > >> + /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ > >> + ACPI_GHES_NOTIFY_SDEI = 11, > >> + ACPI_GHES_NOTIFY_RESERVED = 12 /* 12 and greater are reserved */ > >> +}; > > maybe make all comment go on newline, otherwise zoo above look ugly > sure. > > > > >> + > >> +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_error, > >> + BIOSLinker *linker); > >> + > >> +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker); > >> +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_errors); > >> +#endif > >> diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > >> index de4a406568..8f13620701 100644 > >> --- a/include/hw/acpi/aml-build.h > >> +++ b/include/hw/acpi/aml-build.h > >> @@ -220,6 +220,7 @@ struct AcpiBuildTables { > >> GArray *rsdp; > >> GArray *tcpalog; > >> GArray *vmgenid; > >> + GArray *hardware_errors; > >> BIOSLinker *linker; > >> } AcpiBuildTables; > >> > > > > . > > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-11 1:40 ` [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support Xiang Zheng 2019-11-15 9:38 ` Igor Mammedov @ 2019-11-22 15:42 ` Beata Michalska 2019-11-25 9:23 ` Igor Mammedov 1 sibling, 1 reply; 14+ messages in thread From: Beata Michalska @ 2019-11-22 15:42 UTC (permalink / raw) To: Xiang Zheng Cc: pbonzini, mst, imammedo, shannon.zhaosl, Peter Maydell, Laszlo Ersek, james.morse, gengdongjiu, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang Hi Xiang, On Mon, 11 Nov 2019 at 01:48, Xiang Zheng <zhengxiang9@huawei.com> wrote: > > From: Dongjiu Geng <gengdongjiu@huawei.com> > > This patch implements APEI GHES Table generation via fw_cfg blobs. Now > it only supports ARMv8 SEA, a type of GHESv2 error source. Afterwards, > we can extend the supported types if needed. For the CPER section, > currently it is memory section because kernel mainly wants userspace to > handle the memory errors. > > This patch follows the spec ACPI 6.2 to build the Hardware Error Source > table. For more detailed information, please refer to document: > docs/specs/acpi_hest_ghes.rst > > Suggested-by: Laszlo Ersek <lersek@redhat.com> > Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com> > Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com> > --- > default-configs/arm-softmmu.mak | 1 + > hw/acpi/Kconfig | 4 + > hw/acpi/Makefile.objs | 1 + > hw/acpi/acpi_ghes.c | 267 ++++++++++++++++++++++++++++++++ > hw/acpi/aml-build.c | 2 + > hw/arm/virt-acpi-build.c | 12 ++ > include/hw/acpi/acpi_ghes.h | 56 +++++++ > include/hw/acpi/aml-build.h | 1 + > 8 files changed, 344 insertions(+) > create mode 100644 hw/acpi/acpi_ghes.c > create mode 100644 include/hw/acpi/acpi_ghes.h > > diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak > index 1f2e0e7fde..5722f3130e 100644 > --- a/default-configs/arm-softmmu.mak > +++ b/default-configs/arm-softmmu.mak > @@ -40,3 +40,4 @@ CONFIG_FSL_IMX25=y > CONFIG_FSL_IMX7=y > CONFIG_FSL_IMX6UL=y > CONFIG_SEMIHOSTING=y > +CONFIG_ACPI_APEI=y > diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig > index 12e3f1e86e..ed8c34d238 100644 > --- a/hw/acpi/Kconfig > +++ b/hw/acpi/Kconfig > @@ -23,6 +23,10 @@ config ACPI_NVDIMM > bool > depends on ACPI > > +config ACPI_APEI > + bool > + depends on ACPI > + > config ACPI_PCI > bool > depends on ACPI && PCI > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs > index 655a9c1973..84474b0ca8 100644 > --- a/hw/acpi/Makefile.objs > +++ b/hw/acpi/Makefile.objs > @@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o > common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o > common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o > common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o > +common-obj-$(CONFIG_ACPI_APEI) += acpi_ghes.o Minor: The 'acpi' prefix could be dropped - it does not seem to be used for other files (self impliend by the dir name). This also applies to most of the naming within this patch > common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o > common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o > common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o > diff --git a/hw/acpi/acpi_ghes.c b/hw/acpi/acpi_ghes.c > new file mode 100644 > index 0000000000..42c00ff3d3 > --- /dev/null > +++ b/hw/acpi/acpi_ghes.c > @@ -0,0 +1,267 @@ > +/* > + * Support for generating APEI tables and recording CPER for Guests > + * > + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > + * > + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + > + * 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, see <http://www.gnu.org/licenses/>. > + */ > + > +#include "qemu/osdep.h" > +#include "hw/acpi/acpi.h" > +#include "hw/acpi/aml-build.h" > +#include "hw/acpi/acpi_ghes.h" > +#include "hw/nvram/fw_cfg.h" > +#include "sysemu/sysemu.h" > +#include "qemu/error-report.h" > + > +#define ACPI_GHES_ERRORS_FW_CFG_FILE "etc/hardware_errors" > +#define ACPI_GHES_DATA_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" > + > +/* > + * The size of Address field in Generic Address Structure. > + * ACPI 2.0/3.0: 5.2.3.1 Generic Address Structure. > + */ > +#define ACPI_GHES_ADDRESS_SIZE 8 > + As already mentioned, you can safely drop this and use sizeof(unit64_t). > +/* The max size in bytes for one error block */ > +#define ACPI_GHES_MAX_RAW_DATA_LENGTH 0x1000 > + > +/* > + * Now only support ARMv8 SEA notification type error source > + */ > +#define ACPI_GHES_ERROR_SOURCE_COUNT 1 > + > +/* > + * Generic Hardware Error Source version 2 > + */ > +#define ACPI_GHES_SOURCE_GENERIC_ERROR_V2 10 Minor: this is actually a type so would be good if the name would reflect that somehow...... > + > +/* > + * | +--------------------------+ 0 > + * | | Header | > + * | +--------------------------+ 40---+- > + * | | ................. | | > + * | | error_status_address-----+ 60 | > + * | | ................. | | > + * | | read_ack_register--------+ 104 92 > + * | | read_ack_preserve | | > + * | | read_ack_write | | > + * + +--------------------------+ 132--+- > + * > + * From above GHES definition, the error status address offset is 60; > + * the Read Ack Register offset is 104, the whole size of GHESv2 is 92 > + */ > + This could potentially land into the doc instead. Also the GHEST is actually part of HEST so your offsets are for HEST not GHEST itself so the comment might be slightly misleading > +/* The error status address offset in GHES */ > +#define ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(start_addr, n) (start_addr + \ > + 60 + offsetof(struct AcpiGenericAddress, address) + n * 92) > + > +/* The Read Ack Register offset in GHES */ > +#define ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(start_addr, n) (start_addr +\ > + 104 + offsetof(struct AcpiGenericAddress, address) + n * 92) > + > +typedef struct AcpiGhesState { > + uint64_t ghes_addr_le; > +} AcpiGhesState; > + Minor: Why AcpiGhes*State* ? And do we need the struct to track single address? > +/* > + * Hardware Error Notification > + * ACPI 4.0: 17.3.2.7 Hardware Error Notification > + */ You are referencing older spec here. The commit message states 6.2 version. Not to mention that 4.0 did not support ARMv8 SEA source. You should not mention sections that do not correspond to the spec the patch is based on. > +static void acpi_ghes_build_notify(GArray *table, const uint8_t type) As it has already been mentioned - the naming here could follow the existing convention. Also this function is creating Hardware Error Notification table which is not necessarily tightly connected to GHES Similarly this applies to the overall naming used within this patch. > +{ > + /* Type */ > + build_append_int_noprefix(table, type, 1); > + /* > + * Length: > + * Total length of the structure in bytes > + */ > + build_append_int_noprefix(table, 28, 1); > + /* Configuration Write Enable */ > + build_append_int_noprefix(table, 0, 2); > + /* Poll Interval */ > + build_append_int_noprefix(table, 0, 4); > + /* Vector */ > + build_append_int_noprefix(table, 0, 4); > + /* Switch To Polling Threshold Value */ > + build_append_int_noprefix(table, 0, 4); > + /* Switch To Polling Threshold Window */ > + build_append_int_noprefix(table, 0, 4); > + /* Error Threshold Value */ > + build_append_int_noprefix(table, 0, 4); > + /* Error Threshold Window */ > + build_append_int_noprefix(table, 0, 4); Most of those fields are being set to the same single value. Why not covering it all in one go ? > +} > + > +/* Build table for the hardware error fw_cfg blob */ > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker) > +{ > + int i, error_status_block_offset; > + > + /* > + * | +--------------------------+ > + * | | error_block_address | > + * | | .......... | > + * | +--------------------------+ > + * | | read_ack_register | > + * | | ........... | > + * | +--------------------------+ > + * | | Error Status Data Block | > + * | | ........ | > + * | +--------------------------+ > + */ > + > + /* Build error_block_address */ > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > + build_append_int_noprefix(hardware_errors, 0, ACPI_GHES_ADDRESS_SIZE); > + } > + > + /* Build read_ack_register */ > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > + /* > + * Initialize the value of read_ack_register to 1, so GHES can be > + * writeable in the first time. > + * ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 > + * (GHESv2 - Type 10) > + */ > + build_append_int_noprefix(hardware_errors, 1, ACPI_GHES_ADDRESS_SIZE); This is a bit of a simplification (justified to some extent) but this should take into account both Read Ack Preserve and Read Ack Write masks..... or having at least a comment would be good Also the above implies support only for GHESTv2 (the 'Ack' regs are GHESv2 specific) still this is iterating over potentially available/supported hw error sources At this point it is ok but if the support gets extended this will not be valid - managing 'Ack' regs should be properly guarded for GHESv2 .. > + } > + > + /* Generic Error Status Block offset in the hardware error fw_cfg blob */ > + error_status_block_offset = hardware_errors->len; > + > + /* Build Error Status Data Block */ > + build_append_int_noprefix(hardware_errors, 0, > + ACPI_GHES_MAX_RAW_DATA_LENGTH * ACPI_GHES_ERROR_SOURCE_COUNT); > + > + /* Allocate guest memory for the hardware error fw_cfg blob */ > + bios_linker_loader_alloc(linker, ACPI_GHES_ERRORS_FW_CFG_FILE, > + hardware_errors, 1, false); > + > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > + /* > + * Patch the address of Error Status Data Block into > + * the error_block_address of hardware_errors fw_cfg blob > + */ > + bios_linker_loader_add_pointer(linker, > + ACPI_GHES_ERRORS_FW_CFG_FILE, ACPI_GHES_ADDRESS_SIZE * i, > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > + error_status_block_offset + i * ACPI_GHES_MAX_RAW_DATA_LENGTH); > + } > + > + /* > + * Write the address of hardware_errors fw_cfg blob into the > + * hardware_errors_addr fw_cfg blob. > + */ > + bios_linker_loader_write_pointer(linker, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, > + 0, ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, 0); > +} > + > +/* Build Hardware Error Source Table */ > +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_errors, > + BIOSLinker *linker) > +{ > + uint32_t hest_start = table_data->len; > + uint32_t source_id = 0; > + > + /* Hardware Error Source Table header*/ > + acpi_data_push(table_data, sizeof(AcpiTableHeader)); > + > + /* Error Source Count */ > + build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4); > + > + /* > + * Type: > + * Generic Hardware Error Source version 2(GHESv2 - Type 10) > + */ > + build_append_int_noprefix(table_data, ACPI_GHES_SOURCE_GENERIC_ERROR_V2, 2); > + /* > + * Source Id > + * Once we support more than one hardware error sources, we need to > + * increase the value of this field. > + */ > + build_append_int_noprefix(table_data, source_id, 2); > + /* Related Source Id */ > + build_append_int_noprefix(table_data, 0xffff, 2); Would be nice to have a comment on the value used -> 'no alternate sources' > + /* Flags */ > + build_append_int_noprefix(table_data, 0, 1); > + /* Enabled */ > + build_append_int_noprefix(table_data, 1, 1); > + > + /* Number of Records To Pre-allocate */ > + build_append_int_noprefix(table_data, 1, 4); > + /* Max Sections Per Record */ > + build_append_int_noprefix(table_data, 1, 4); > + /* Max Raw Data Length */ > + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > + > + /* Error Status Address */ > + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > + 4 /* QWord access */, 0); > + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > + source_id * ACPI_GHES_ADDRESS_SIZE); > + > + /* > + * Notification Structure > + * Now only enable ARMv8 SEA notification type > + */ > + acpi_ghes_build_notify(table_data, ACPI_GHES_NOTIFY_SEA); > + > + /* Error Status Block Length */ > + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > + > + /* > + * Read Ack Register > + * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source > + * version 2 (GHESv2 - Type 10) > + */ > + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > + 4 /* QWord access */, 0); > + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > + ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(hest_start, 0), > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > + (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) * ACPI_GHES_ADDRESS_SIZE); > + > + /* > + * Read Ack Preserve > + * We only provide the first bit in Read Ack Register to OSPM to write > + * while the other bits are preserved. > + */ > + build_append_int_noprefix(table_data, ~0x1ULL, 8); > + /* Read Ack Write */ > + build_append_int_noprefix(table_data, 0x1, 8); > + > + build_header(linker, table_data, (void *)(table_data->data + hest_start), > + "HEST", table_data->len - hest_start, 1, NULL, "GHES"); > +} > + Already mentioned .... but ... the last few lines are GHESv2 specific but it seems that HES/GHES/GHESv2 are being mixed within this patch. Would be nice if those could be separated to easy future extensions BR Beata > +static AcpiGhesState ges; > +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_error) > +{ > + > + size_t size = 2 * ACPI_GHES_ADDRESS_SIZE + ACPI_GHES_MAX_RAW_DATA_LENGTH; > + size_t request_block_size = ACPI_GHES_ERROR_SOURCE_COUNT * size; > + > + /* Create a read-only fw_cfg file for GHES */ > + fw_cfg_add_file(s, ACPI_GHES_ERRORS_FW_CFG_FILE, hardware_error->data, > + request_block_size); > + > + /* Create a read-write fw_cfg file for Address */ > + fw_cfg_add_file_callback(s, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, NULL, NULL, > + NULL, &ges.ghes_addr_le, sizeof(ges.ghes_addr_le), false); > +} > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > index 2c3702b882..3681ec6e3d 100644 > --- a/hw/acpi/aml-build.c > +++ b/hw/acpi/aml-build.c > @@ -1578,6 +1578,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) > tables->table_data = g_array_new(false, true /* clear */, 1); > tables->tcpalog = g_array_new(false, true /* clear */, 1); > tables->vmgenid = g_array_new(false, true /* clear */, 1); > + tables->hardware_errors = g_array_new(false, true /* clear */, 1); > tables->linker = bios_linker_loader_init(); > } > > @@ -1588,6 +1589,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) > g_array_free(tables->table_data, true); > g_array_free(tables->tcpalog, mfre); > g_array_free(tables->vmgenid, mfre); > + g_array_free(tables->hardware_errors, mfre); > } > > /* > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > index 4cd50175e0..1b1fd273e4 100644 > --- a/hw/arm/virt-acpi-build.c > +++ b/hw/arm/virt-acpi-build.c > @@ -48,6 +48,7 @@ > #include "sysemu/reset.h" > #include "kvm_arm.h" > #include "migration/vmstate.h" > +#include "hw/acpi/acpi_ghes.h" > > #define ARM_SPI_BASE 32 > > @@ -825,6 +826,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) > acpi_add_table(table_offsets, tables_blob); > build_spcr(tables_blob, tables->linker, vms); > > + if (vms->ras) { > + acpi_add_table(table_offsets, tables_blob); > + acpi_ghes_build_error_table(tables->hardware_errors, tables->linker); > + acpi_ghes_build_hest(tables_blob, tables->hardware_errors, > + tables->linker); > + } > + > if (ms->numa_state->num_nodes > 0) { > acpi_add_table(table_offsets, tables_blob); > build_srat(tables_blob, tables->linker, vms); > @@ -942,6 +950,10 @@ void virt_acpi_setup(VirtMachineState *vms) > fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, > acpi_data_len(tables.tcpalog)); > > + if (vms->ras) { > + acpi_ghes_add_fw_cfg(vms->fw_cfg, tables.hardware_errors); > + } > + > build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, > build_state, tables.rsdp, > ACPI_BUILD_RSDP_FILE, 0); > diff --git a/include/hw/acpi/acpi_ghes.h b/include/hw/acpi/acpi_ghes.h > new file mode 100644 > index 0000000000..cb62ec9c7b > --- /dev/null > +++ b/include/hw/acpi/acpi_ghes.h > @@ -0,0 +1,56 @@ > +/* > + * Support for generating APEI tables and recording CPER for Guests > + * > + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > + * > + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + > + * 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, see <http://www.gnu.org/licenses/>. > + */ > + > +#ifndef ACPI_GHES_H > +#define ACPI_GHES_H > + > +#include "hw/acpi/bios-linker-loader.h" > + > +/* > + * Values for Hardware Error Notification Type field > + */ > +enum AcpiGhesNotifyType { > + ACPI_GHES_NOTIFY_POLLED = 0, /* Polled */ > + ACPI_GHES_NOTIFY_EXTERNAL = 1, /* External Interrupt */ > + ACPI_GHES_NOTIFY_LOCAL = 2, /* Local Interrupt */ > + ACPI_GHES_NOTIFY_SCI = 3, /* SCI */ > + ACPI_GHES_NOTIFY_NMI = 4, /* NMI */ > + ACPI_GHES_NOTIFY_CMCI = 5, /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ > + ACPI_GHES_NOTIFY_MCE = 6, /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ > + /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ > + ACPI_GHES_NOTIFY_GPIO = 7, > + /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ > + ACPI_GHES_NOTIFY_SEA = 8, > + /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ > + ACPI_GHES_NOTIFY_SEI = 9, > + /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ > + ACPI_GHES_NOTIFY_GSIV = 10, > + /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ > + ACPI_GHES_NOTIFY_SDEI = 11, > + ACPI_GHES_NOTIFY_RESERVED = 12 /* 12 and greater are reserved */ > +}; > + > +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_error, > + BIOSLinker *linker); > + > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker); > +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_errors); > +#endif > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > index de4a406568..8f13620701 100644 > --- a/include/hw/acpi/aml-build.h > +++ b/include/hw/acpi/aml-build.h > @@ -220,6 +220,7 @@ struct AcpiBuildTables { > GArray *rsdp; > GArray *tcpalog; > GArray *vmgenid; > + GArray *hardware_errors; > BIOSLinker *linker; > } AcpiBuildTables; > > -- > 2.19.1 > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support 2019-11-22 15:42 ` Beata Michalska @ 2019-11-25 9:23 ` Igor Mammedov 0 siblings, 0 replies; 14+ messages in thread From: Igor Mammedov @ 2019-11-25 9:23 UTC (permalink / raw) To: Beata Michalska Cc: Xiang Zheng, pbonzini, mst, shannon.zhaosl, Peter Maydell, Laszlo Ersek, james.morse, gengdongjiu, mtosatti, rth, ehabkost, jonathan.cameron, xuwei5, kvm, qemu-devel, qemu-arm, linuxarm, wanghaibin.wang On Fri, 22 Nov 2019 15:42:52 +0000 Beata Michalska <beata.michalska@linaro.org> wrote: > Hi Xiang, > > On Mon, 11 Nov 2019 at 01:48, Xiang Zheng <zhengxiang9@huawei.com> wrote: > > > > From: Dongjiu Geng <gengdongjiu@huawei.com> > > > > This patch implements APEI GHES Table generation via fw_cfg blobs. Now > > it only supports ARMv8 SEA, a type of GHESv2 error source. Afterwards, > > we can extend the supported types if needed. For the CPER section, > > currently it is memory section because kernel mainly wants userspace to > > handle the memory errors. > > > > This patch follows the spec ACPI 6.2 to build the Hardware Error Source > > table. For more detailed information, please refer to document: > > docs/specs/acpi_hest_ghes.rst > > > > Suggested-by: Laszlo Ersek <lersek@redhat.com> > > Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com> > > Signed-off-by: Xiang Zheng <zhengxiang9@huawei.com> > > Reviewed-by: Michael S. Tsirkin <mst@redhat.com> > > --- > > default-configs/arm-softmmu.mak | 1 + > > hw/acpi/Kconfig | 4 + > > hw/acpi/Makefile.objs | 1 + > > hw/acpi/acpi_ghes.c | 267 ++++++++++++++++++++++++++++++++ > > hw/acpi/aml-build.c | 2 + > > hw/arm/virt-acpi-build.c | 12 ++ > > include/hw/acpi/acpi_ghes.h | 56 +++++++ > > include/hw/acpi/aml-build.h | 1 + > > 8 files changed, 344 insertions(+) > > create mode 100644 hw/acpi/acpi_ghes.c > > create mode 100644 include/hw/acpi/acpi_ghes.h > > > > diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak > > index 1f2e0e7fde..5722f3130e 100644 > > --- a/default-configs/arm-softmmu.mak > > +++ b/default-configs/arm-softmmu.mak > > @@ -40,3 +40,4 @@ CONFIG_FSL_IMX25=y > > CONFIG_FSL_IMX7=y > > CONFIG_FSL_IMX6UL=y > > CONFIG_SEMIHOSTING=y > > +CONFIG_ACPI_APEI=y > > diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig > > index 12e3f1e86e..ed8c34d238 100644 > > --- a/hw/acpi/Kconfig > > +++ b/hw/acpi/Kconfig > > @@ -23,6 +23,10 @@ config ACPI_NVDIMM > > bool > > depends on ACPI > > > > +config ACPI_APEI > > + bool > > + depends on ACPI > > + > > config ACPI_PCI > > bool > > depends on ACPI && PCI > > diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs > > index 655a9c1973..84474b0ca8 100644 > > --- a/hw/acpi/Makefile.objs > > +++ b/hw/acpi/Makefile.objs > > @@ -5,6 +5,7 @@ common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o > > common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o > > common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o > > common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o > > +common-obj-$(CONFIG_ACPI_APEI) += acpi_ghes.o > > Minor: The 'acpi' prefix could be dropped - it does not seem to be used > for other files (self impliend by the dir name). > This also applies to most of the naming within this patch > > > common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o > > common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o > > common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o > > diff --git a/hw/acpi/acpi_ghes.c b/hw/acpi/acpi_ghes.c > > new file mode 100644 > > index 0000000000..42c00ff3d3 > > --- /dev/null > > +++ b/hw/acpi/acpi_ghes.c > > @@ -0,0 +1,267 @@ > > +/* > > + * Support for generating APEI tables and recording CPER for Guests > > + * > > + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > > + * > > + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > > + * > > + * This program is free software; you can redistribute it and/or modify > > + * it under the terms of the GNU General Public License as published by > > + * the Free Software Foundation; either version 2 of the License, or > > + * (at your option) any later version. > > + > > + * 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, see <http://www.gnu.org/licenses/>. > > + */ > > + > > +#include "qemu/osdep.h" > > +#include "hw/acpi/acpi.h" > > +#include "hw/acpi/aml-build.h" > > +#include "hw/acpi/acpi_ghes.h" > > +#include "hw/nvram/fw_cfg.h" > > +#include "sysemu/sysemu.h" > > +#include "qemu/error-report.h" > > + > > +#define ACPI_GHES_ERRORS_FW_CFG_FILE "etc/hardware_errors" > > +#define ACPI_GHES_DATA_ADDR_FW_CFG_FILE "etc/hardware_errors_addr" > > + > > +/* > > + * The size of Address field in Generic Address Structure. > > + * ACPI 2.0/3.0: 5.2.3.1 Generic Address Structure. > > + */ > > +#define ACPI_GHES_ADDRESS_SIZE 8 > > + > As already mentioned, you can safely drop this and use sizeof(unit64_t). > > > +/* The max size in bytes for one error block */ > > +#define ACPI_GHES_MAX_RAW_DATA_LENGTH 0x1000 > > + > > +/* > > + * Now only support ARMv8 SEA notification type error source > > + */ > > +#define ACPI_GHES_ERROR_SOURCE_COUNT 1 > > + > > +/* > > + * Generic Hardware Error Source version 2 > > + */ > > +#define ACPI_GHES_SOURCE_GENERIC_ERROR_V2 10 > > Minor: this is actually a type so would be good if the name would > reflect that somehow...... > > > + > > +/* > > + * | +--------------------------+ 0 > > + * | | Header | > > + * | +--------------------------+ 40---+- > > + * | | ................. | | > > + * | | error_status_address-----+ 60 | > > + * | | ................. | | > > + * | | read_ack_register--------+ 104 92 > > + * | | read_ack_preserve | | > > + * | | read_ack_write | | > > + * + +--------------------------+ 132--+- > > + * > > + * From above GHES definition, the error status address offset is 60; > > + * the Read Ack Register offset is 104, the whole size of GHESv2 is 92 > > + */ > > + > This could potentially land into the doc instead. > Also the GHEST is actually part of HEST so your offsets are for > HEST not GHEST itself so the comment might be slightly misleading > > > +/* The error status address offset in GHES */ > > +#define ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(start_addr, n) (start_addr + \ > > + 60 + offsetof(struct AcpiGenericAddress, address) + n * 92) > > + > > +/* The Read Ack Register offset in GHES */ > > +#define ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(start_addr, n) (start_addr +\ > > + 104 + offsetof(struct AcpiGenericAddress, address) + n * 92) > > + > > +typedef struct AcpiGhesState { > > + uint64_t ghes_addr_le; > > +} AcpiGhesState; > > + > Minor: Why AcpiGhes*State* ? And do we need the struct to track single address? > > > +/* > > + * Hardware Error Notification > > + * ACPI 4.0: 17.3.2.7 Hardware Error Notification > > + */ > You are referencing older spec here. The commit message states > 6.2 version. Not to mention that 4.0 did not support ARMv8 SEA source. > You should not mention sections that do not correspond to the spec > the patch is based on. normally we use the spec where structure appeared first, and use later one only when there is no other choice (i.e. work uses/implement fields that weren't in the original structure revision) > > > +static void acpi_ghes_build_notify(GArray *table, const uint8_t type) > > As it has already been mentioned - the naming here could follow the existing > convention. Also this function is creating Hardware Error Notification table > which is not necessarily tightly connected to GHES > Similarly this applies to the overall naming used within this patch. > > +{ > > + /* Type */ > > + build_append_int_noprefix(table, type, 1); > > + /* > > + * Length: > > + * Total length of the structure in bytes > > + */ > > + build_append_int_noprefix(table, 28, 1); > > + /* Configuration Write Enable */ > > + build_append_int_noprefix(table, 0, 2); > > + /* Poll Interval */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Vector */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Switch To Polling Threshold Value */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Switch To Polling Threshold Window */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Error Threshold Value */ > > + build_append_int_noprefix(table, 0, 4); > > + /* Error Threshold Window */ > > + build_append_int_noprefix(table, 0, 4); > > Most of those fields are being set to the same single value. > Why not covering it all in one go ? that's intentional. yep it takes more lines to code but it also makes comparing code against spec much easier as it practically matches table in the spec line by line. > > +} > > + > > +/* Build table for the hardware error fw_cfg blob */ > > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker) > > +{ > > + int i, error_status_block_offset; > > + > > + /* > > + * | +--------------------------+ > > + * | | error_block_address | > > + * | | .......... | > > + * | +--------------------------+ > > + * | | read_ack_register | > > + * | | ........... | > > + * | +--------------------------+ > > + * | | Error Status Data Block | > > + * | | ........ | > > + * | +--------------------------+ > > + */ > > + > > + /* Build error_block_address */ > > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > > + build_append_int_noprefix(hardware_errors, 0, ACPI_GHES_ADDRESS_SIZE); > > + } > > + > > + /* Build read_ack_register */ > > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > > + /* > > + * Initialize the value of read_ack_register to 1, so GHES can be > > + * writeable in the first time. > > + * ACPI 6.2: 18.3.2.8 Generic Hardware Error Source version 2 > > + * (GHESv2 - Type 10) > > + */ > > + build_append_int_noprefix(hardware_errors, 1, ACPI_GHES_ADDRESS_SIZE); > This is a bit of a simplification (justified to some extent) but this > should take into > account both Read Ack Preserve and Read Ack Write masks..... > or having at least a comment would be good > > Also the above implies support only for GHESTv2 (the 'Ack' regs are GHESv2 > specific) still this is iterating over potentially available/supported > hw error sources > At this point it is ok but if the support gets extended this will not > be valid - managing > 'Ack' regs should be properly guarded for GHESv2 .. It ok for code to be more complicated so it would be able to handle other usecases in the future. But if there aren't actual plans to add other usecases, then it's just over-engineering which might mislead reader later on to trying figure out what's going on here. (modulo the case where we are defining ABI between guest and QEMU) So I'd rather simplify code if there aren't plans to extend it, and let someone else to generalize it when there is an actual need for it. > > > + } > > + > > + /* Generic Error Status Block offset in the hardware error fw_cfg blob */ > > + error_status_block_offset = hardware_errors->len; > > + > > + /* Build Error Status Data Block */ > > + build_append_int_noprefix(hardware_errors, 0, > > + ACPI_GHES_MAX_RAW_DATA_LENGTH * ACPI_GHES_ERROR_SOURCE_COUNT); > > + > > + /* Allocate guest memory for the hardware error fw_cfg blob */ > > + bios_linker_loader_alloc(linker, ACPI_GHES_ERRORS_FW_CFG_FILE, > > + hardware_errors, 1, false); > > + > > + for (i = 0; i < ACPI_GHES_ERROR_SOURCE_COUNT; i++) { > > + /* > > + * Patch the address of Error Status Data Block into > > + * the error_block_address of hardware_errors fw_cfg blob > > + */ > > + bios_linker_loader_add_pointer(linker, > > + ACPI_GHES_ERRORS_FW_CFG_FILE, ACPI_GHES_ADDRESS_SIZE * i, > > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > > + error_status_block_offset + i * ACPI_GHES_MAX_RAW_DATA_LENGTH); > > + } > > + > > + /* > > + * Write the address of hardware_errors fw_cfg blob into the > > + * hardware_errors_addr fw_cfg blob. > > + */ > > + bios_linker_loader_write_pointer(linker, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, > > + 0, ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, 0); > > +} > > + > > +/* Build Hardware Error Source Table */ > > +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_errors, > > + BIOSLinker *linker) > > +{ > > + uint32_t hest_start = table_data->len; > > + uint32_t source_id = 0; > > + > > + /* Hardware Error Source Table header*/ > > + acpi_data_push(table_data, sizeof(AcpiTableHeader)); > > + > > + /* Error Source Count */ > > + build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4); > > + > > + /* > > + * Type: > > + * Generic Hardware Error Source version 2(GHESv2 - Type 10) > > + */ > > + build_append_int_noprefix(table_data, ACPI_GHES_SOURCE_GENERIC_ERROR_V2, 2); > > + /* > > + * Source Id > > + * Once we support more than one hardware error sources, we need to > > + * increase the value of this field. > > + */ > > + build_append_int_noprefix(table_data, source_id, 2); > > + /* Related Source Id */ > > + build_append_int_noprefix(table_data, 0xffff, 2); > > Would be nice to have a comment on the value used -> > 'no alternate sources' usually we use verbaltim field name as in the spec table definition. This way reader could easily find it in the spec and read on the meaning of values. This is done to avoid copying needlessly spec text into QEMU. So if 0xffff is described in the table definition, then typically just field name comment is sufficient. > > + /* Flags */ > > + build_append_int_noprefix(table_data, 0, 1); > > + /* Enabled */ > > + build_append_int_noprefix(table_data, 1, 1); > > + > > + /* Number of Records To Pre-allocate */ > > + build_append_int_noprefix(table_data, 1, 4); > > + /* Max Sections Per Record */ > > + build_append_int_noprefix(table_data, 1, 4); > > + /* Max Raw Data Length */ > > + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > > + > > + /* Error Status Address */ > > + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > > + 4 /* QWord access */, 0); > > + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > > + ACPI_GHES_ERROR_STATUS_ADDRESS_OFFSET(hest_start, source_id), > > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > > + source_id * ACPI_GHES_ADDRESS_SIZE); > > + > > + /* > > + * Notification Structure > > + * Now only enable ARMv8 SEA notification type > > + */ > > + acpi_ghes_build_notify(table_data, ACPI_GHES_NOTIFY_SEA); > > + > > + /* Error Status Block Length */ > > + build_append_int_noprefix(table_data, ACPI_GHES_MAX_RAW_DATA_LENGTH, 4); > > + > > + /* > > + * Read Ack Register > > + * ACPI 6.1: 18.3.2.8 Generic Hardware Error Source > > + * version 2 (GHESv2 - Type 10) > > + */ > > + build_append_gas(table_data, AML_AS_SYSTEM_MEMORY, 0x40, 0, > > + 4 /* QWord access */, 0); > > + bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, > > + ACPI_GHES_READ_ACK_REGISTER_ADDRESS_OFFSET(hest_start, 0), > > + ACPI_GHES_ADDRESS_SIZE, ACPI_GHES_ERRORS_FW_CFG_FILE, > > + (ACPI_GHES_ERROR_SOURCE_COUNT + source_id) * ACPI_GHES_ADDRESS_SIZE); > > + > > + /* > > + * Read Ack Preserve > > + * We only provide the first bit in Read Ack Register to OSPM to write > > + * while the other bits are preserved. > > + */ > > + build_append_int_noprefix(table_data, ~0x1ULL, 8); > > + /* Read Ack Write */ > > + build_append_int_noprefix(table_data, 0x1, 8); > > + > > + build_header(linker, table_data, (void *)(table_data->data + hest_start), > > + "HEST", table_data->len - hest_start, 1, NULL, "GHES"); > > +} > > + > Already mentioned .... but ... > the last few lines are GHESv2 specific but it seems that HES/GHES/GHESv2 > are being mixed within this patch. Would be nice if those could be separated > to easy future extensions > > BR > > Beata > > > +static AcpiGhesState ges; > > +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_error) > > +{ > > + > > + size_t size = 2 * ACPI_GHES_ADDRESS_SIZE + ACPI_GHES_MAX_RAW_DATA_LENGTH; > > + size_t request_block_size = ACPI_GHES_ERROR_SOURCE_COUNT * size; > > + > > + /* Create a read-only fw_cfg file for GHES */ > > + fw_cfg_add_file(s, ACPI_GHES_ERRORS_FW_CFG_FILE, hardware_error->data, > > + request_block_size); > > + > > + /* Create a read-write fw_cfg file for Address */ > > + fw_cfg_add_file_callback(s, ACPI_GHES_DATA_ADDR_FW_CFG_FILE, NULL, NULL, > > + NULL, &ges.ghes_addr_le, sizeof(ges.ghes_addr_le), false); > > +} > > diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c > > index 2c3702b882..3681ec6e3d 100644 > > --- a/hw/acpi/aml-build.c > > +++ b/hw/acpi/aml-build.c > > @@ -1578,6 +1578,7 @@ void acpi_build_tables_init(AcpiBuildTables *tables) > > tables->table_data = g_array_new(false, true /* clear */, 1); > > tables->tcpalog = g_array_new(false, true /* clear */, 1); > > tables->vmgenid = g_array_new(false, true /* clear */, 1); > > + tables->hardware_errors = g_array_new(false, true /* clear */, 1); > > tables->linker = bios_linker_loader_init(); > > } > > > > @@ -1588,6 +1589,7 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) > > g_array_free(tables->table_data, true); > > g_array_free(tables->tcpalog, mfre); > > g_array_free(tables->vmgenid, mfre); > > + g_array_free(tables->hardware_errors, mfre); > > } > > > > /* > > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > > index 4cd50175e0..1b1fd273e4 100644 > > --- a/hw/arm/virt-acpi-build.c > > +++ b/hw/arm/virt-acpi-build.c > > @@ -48,6 +48,7 @@ > > #include "sysemu/reset.h" > > #include "kvm_arm.h" > > #include "migration/vmstate.h" > > +#include "hw/acpi/acpi_ghes.h" > > > > #define ARM_SPI_BASE 32 > > > > @@ -825,6 +826,13 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables) > > acpi_add_table(table_offsets, tables_blob); > > build_spcr(tables_blob, tables->linker, vms); > > > > + if (vms->ras) { > > + acpi_add_table(table_offsets, tables_blob); > > + acpi_ghes_build_error_table(tables->hardware_errors, tables->linker); > > + acpi_ghes_build_hest(tables_blob, tables->hardware_errors, > > + tables->linker); > > + } > > + > > if (ms->numa_state->num_nodes > 0) { > > acpi_add_table(table_offsets, tables_blob); > > build_srat(tables_blob, tables->linker, vms); > > @@ -942,6 +950,10 @@ void virt_acpi_setup(VirtMachineState *vms) > > fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, > > acpi_data_len(tables.tcpalog)); > > > > + if (vms->ras) { > > + acpi_ghes_add_fw_cfg(vms->fw_cfg, tables.hardware_errors); > > + } > > + > > build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, > > build_state, tables.rsdp, > > ACPI_BUILD_RSDP_FILE, 0); > > diff --git a/include/hw/acpi/acpi_ghes.h b/include/hw/acpi/acpi_ghes.h > > new file mode 100644 > > index 0000000000..cb62ec9c7b > > --- /dev/null > > +++ b/include/hw/acpi/acpi_ghes.h > > @@ -0,0 +1,56 @@ > > +/* > > + * Support for generating APEI tables and recording CPER for Guests > > + * > > + * Copyright (c) 2019 HUAWEI TECHNOLOGIES CO., LTD. > > + * > > + * Author: Dongjiu Geng <gengdongjiu@huawei.com> > > + * > > + * This program is free software; you can redistribute it and/or modify > > + * it under the terms of the GNU General Public License as published by > > + * the Free Software Foundation; either version 2 of the License, or > > + * (at your option) any later version. > > + > > + * 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, see <http://www.gnu.org/licenses/>. > > + */ > > + > > +#ifndef ACPI_GHES_H > > +#define ACPI_GHES_H > > + > > +#include "hw/acpi/bios-linker-loader.h" > > + > > +/* > > + * Values for Hardware Error Notification Type field > > + */ > > +enum AcpiGhesNotifyType { > > + ACPI_GHES_NOTIFY_POLLED = 0, /* Polled */ > > + ACPI_GHES_NOTIFY_EXTERNAL = 1, /* External Interrupt */ > > + ACPI_GHES_NOTIFY_LOCAL = 2, /* Local Interrupt */ > > + ACPI_GHES_NOTIFY_SCI = 3, /* SCI */ > > + ACPI_GHES_NOTIFY_NMI = 4, /* NMI */ > > + ACPI_GHES_NOTIFY_CMCI = 5, /* CMCI, ACPI 5.0: 18.3.2.7, Table 18-290 */ > > + ACPI_GHES_NOTIFY_MCE = 6, /* MCE, ACPI 5.0: 18.3.2.7, Table 18-290 */ > > + /* GPIO-Signal, ACPI 6.0: 18.3.2.7, Table 18-332 */ > > + ACPI_GHES_NOTIFY_GPIO = 7, > > + /* ARMv8 SEA, ACPI 6.1: 18.3.2.9, Table 18-345 */ > > + ACPI_GHES_NOTIFY_SEA = 8, > > + /* ARMv8 SEI, ACPI 6.1: 18.3.2.9, Table 18-345 */ > > + ACPI_GHES_NOTIFY_SEI = 9, > > + /* External Interrupt - GSIV, ACPI 6.1: 18.3.2.9, Table 18-345 */ > > + ACPI_GHES_NOTIFY_GSIV = 10, > > + /* Software Delegated Exception, ACPI 6.2: 18.3.2.9, Table 18-383 */ > > + ACPI_GHES_NOTIFY_SDEI = 11, > > + ACPI_GHES_NOTIFY_RESERVED = 12 /* 12 and greater are reserved */ > > +}; > > + > > +void acpi_ghes_build_hest(GArray *table_data, GArray *hardware_error, > > + BIOSLinker *linker); > > + > > +void acpi_ghes_build_error_table(GArray *hardware_errors, BIOSLinker *linker); > > +void acpi_ghes_add_fw_cfg(FWCfgState *s, GArray *hardware_errors); > > +#endif > > diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h > > index de4a406568..8f13620701 100644 > > --- a/include/hw/acpi/aml-build.h > > +++ b/include/hw/acpi/aml-build.h > > @@ -220,6 +220,7 @@ struct AcpiBuildTables { > > GArray *rsdp; > > GArray *tcpalog; > > GArray *vmgenid; > > + GArray *hardware_errors; > > BIOSLinker *linker; > > } AcpiBuildTables; > > > > -- > > 2.19.1 > > > > > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2019-11-27 11:16 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-11-16 0:58 [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support gengdongjiu -- strict thread matches above, loose matches on Subject: below -- 2019-11-15 14:32 gengdongjiu 2019-11-15 14:55 ` Igor Mammedov 2019-11-11 1:40 [RESEND PATCH v21 0/6] Add ARMv8 RAS virtualization support in QEMU Xiang Zheng 2019-11-11 1:40 ` [RESEND PATCH v21 3/6] ACPI: Add APEI GHES table generation support Xiang Zheng 2019-11-15 9:38 ` Igor Mammedov 2019-11-18 12:49 ` gengdongjiu 2019-11-18 13:18 ` gengdongjiu 2019-11-18 13:21 ` Michael S. Tsirkin 2019-11-18 13:57 ` gengdongjiu 2019-11-25 9:48 ` Igor Mammedov 2019-11-27 11:16 ` gengdongjiu 2019-11-22 15:44 ` Beata Michalska 2019-11-22 15:42 ` Beata Michalska 2019-11-25 9:23 ` Igor Mammedov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).