History

Merge branch 'acpi-apei'

* acpi-apei: (29 commits) efi: cper: Fix possible out-of-bounds access ACPI: APEI: Fix possible out-of-bounds access to BERT region MAINTAINERS: Add James Morse to the list of APEI reviewers ACPI / APEI: Add support for the SDEI GHES Notification type firmware: arm_sdei: Add ACPI GHES registration helper ACPI / APEI: Use separate fixmap pages for arm64 NMI-like notifications ACPI / APEI: Only use queued estatus entry during in_nmi_queue_one_entry() ACPI / APEI: Split ghes_read_estatus() to allow a peek at the CPER length ACPI / APEI: Make GHES estatus header validation more user friendly ACPI / APEI: Pass ghes and estatus separately to avoid a later copy ACPI / APEI: Let the notification helper specify the fixmap slot ACPI / APEI: Move locking to the notification helper arm64: KVM/mm: Move SEA handling behind a single 'claim' interface KVM: arm/arm64: Add kvm_ras.h to collect kvm specific RAS plumbing ACPI / APEI: Switch NOTIFY_SEA to use the estatus queue ACPI / APEI: Move NOTIFY_SEA between the estatus-queue and NOTIFY_NMI ACPI / APEI: Don't allow ghes_ack_error() to mask earlier errors ACPI / APEI: Generalise the estatus queue's notify code ACPI / APEI: Don't update struct ghes' flags in read/clear estatus ACPI / APEI: Remove spurious GHES_TO_CLEAR check ...

Rafael J. Wysocki committed 7 years ago

Commit dcaed592 parents 511514f 45b14a421 files · +591 −368Browse files

Unified · Split

21 files
  1. MAINTAINERS +1 −0
  2. arch/arm/include/asm/kvm_ras.h +14 −0
  3. arch/arm/include/asm/system_misc.h +0 −5
  4. arch/arm64/include/asm/acpi.h +3 −1
  5. arch/arm64/include/asm/daifflags.h +1 −0
  6. arch/arm64/include/asm/fixmap.h +5 −1
  7. arch/arm64/include/asm/kvm_ras.h +25 −0
  8. arch/arm64/include/asm/system_misc.h +0 −2
  9. arch/arm64/kernel/acpi.c +31 −0
  10. arch/arm64/mm/fault.c +5 −19
  11. drivers/acpi/apei/Kconfig +1 −11
  12. drivers/acpi/apei/bert.c +10 −13
  13. drivers/acpi/apei/einj.c +7 −8
  14. drivers/acpi/apei/erst.c +12 −15
  15. drivers/acpi/apei/ghes.c +371 −284
  16. drivers/acpi/apei/hest.c +15 −1
  17. drivers/firmware/arm_sdei.c +68 −0
  18. drivers/firmware/efi/cper.c +9 −4
  19. include/acpi/ghes.h +2 −2
  20. include/linux/arm_sdei.h +9 −0
  21. virt/kvm/arm/mmu.c +2 −2
MAINTAINERS+1−0
@@ -331,6 +331,7 @@ ACPI APEI · 330 unmodified lines
331M: "Rafael J. Wysocki" <rjw@rjwysocki.net>331M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
332M: Len Brown <lenb@kernel.org>332M: Len Brown <lenb@kernel.org>
333L: linux-acpi@vger.kernel.org333L: linux-acpi@vger.kernel.org
334R: James Morse <james.morse@arm.com>
334R: Tony Luck <tony.luck@intel.com>335R: Tony Luck <tony.luck@intel.com>
335R: Borislav Petkov <bp@alien8.de>336R: Borislav Petkov <bp@alien8.de>
336F: drivers/acpi/apei/337F: drivers/acpi/apei/
arch/arm/include/asm/kvm_ras.h+14−0
@@ -0,0 +1,14 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2018 - Arm Ltd */
3
4#ifndef __ARM_KVM_RAS_H__
5#define __ARM_KVM_RAS_H__
6
7#include <linux/types.h>
8
9static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr)
10{
11 return -1;
12}
13
14#endif /* __ARM_KVM_RAS_H__ */
arch/arm/include/asm/system_misc.h+0−5
@@ -38,11 +38,6 @@ static inline void harden_branch_predictor(void) · 37 unmodified lines
38 38
39extern unsigned int user_debug;39extern unsigned int user_debug;
40 40
41static inline int handle_guest_sea(phys_addr_t addr, unsigned int esr)
42{
43 return -1;
44}
45
46#endif /* !__ASSEMBLY__ */41#endif /* !__ASSEMBLY__ */
47 42
48#endif /* __ASM_ARM_SYSTEM_MISC_H */43#endif /* __ASM_ARM_SYSTEM_MISC_H */
arch/arm64/include/asm/acpi.h+3−1
@@ -18,6 +18,7 @@ · 17 unmodified lines
18 18
19#include <asm/cputype.h>19#include <asm/cputype.h>
20#include <asm/io.h>20#include <asm/io.h>
21#include <asm/ptrace.h>
21#include <asm/smp_plat.h>22#include <asm/smp_plat.h>
22#include <asm/tlbflush.h>23#include <asm/tlbflush.h>
23 24
@@ -110,9 +111,10 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu) · 86 unmodified lines
110 111
111static inline void arch_fix_phys_package_id(int num, u32 slot) { }112static inline void arch_fix_phys_package_id(int num, u32 slot) { }
112void __init acpi_init_cpus(void);113void __init acpi_init_cpus(void);
113 114int apei_claim_sea(struct pt_regs *regs);
114#else115#else
115static inline void acpi_init_cpus(void) { }116static inline void acpi_init_cpus(void) { }
117static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; }
116#endif /* CONFIG_ACPI */118#endif /* CONFIG_ACPI */
117 119
118#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL120#ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
arch/arm64/include/asm/daifflags.h+1−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
20 20
21#define DAIF_PROCCTX 021#define DAIF_PROCCTX 0
22#define DAIF_PROCCTX_NOIRQ PSR_I_BIT22#define DAIF_PROCCTX_NOIRQ PSR_I_BIT
23#define DAIF_ERRCTX (PSR_I_BIT | PSR_A_BIT)
23 24
24/* mask/save/unmask/restore all exceptions, including interrupts. */25/* mask/save/unmask/restore all exceptions, including interrupts. */
25static inline void local_daif_mask(void)26static inline void local_daif_mask(void)
arch/arm64/include/asm/fixmap.h+5−1
@@ -55,7 +55,11 @@ enum fixed_addresses { · 54 unmodified lines
55#ifdef CONFIG_ACPI_APEI_GHES55#ifdef CONFIG_ACPI_APEI_GHES
56 /* Used for GHES mapping from assorted contexts */56 /* Used for GHES mapping from assorted contexts */
57 FIX_APEI_GHES_IRQ,57 FIX_APEI_GHES_IRQ,
58 FIX_APEI_GHES_NMI,58 FIX_APEI_GHES_SEA,
59#ifdef CONFIG_ARM_SDE_INTERFACE
60 FIX_APEI_GHES_SDEI_NORMAL,
61 FIX_APEI_GHES_SDEI_CRITICAL,
62#endif
59#endif /* CONFIG_ACPI_APEI_GHES */63#endif /* CONFIG_ACPI_APEI_GHES */
60 64
61#ifdef CONFIG_UNMAP_KERNEL_AT_EL065#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
arch/arm64/include/asm/kvm_ras.h+25−0
@@ -0,0 +1,25 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (C) 2018 - Arm Ltd */
3
4#ifndef __ARM64_KVM_RAS_H__
5#define __ARM64_KVM_RAS_H__
6
7#include <linux/acpi.h>
8#include <linux/errno.h>
9#include <linux/types.h>
10
11#include <asm/acpi.h>
12
13/*
14 * Was this synchronous external abort a RAS notification?
15 * Returns '0' for errors handled by some RAS subsystem, or -ENOENT.
16 */
17static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr)
18{
19 /* apei_claim_sea(NULL) expects to mask interrupts itself */
20 lockdep_assert_irqs_enabled();
21
22 return apei_claim_sea(NULL);
23}
24
25#endif /* __ARM64_KVM_RAS_H__ */
arch/arm64/include/asm/system_misc.h+0−2
@@ -46,8 +46,6 @@ extern void __show_regs(struct pt_regs *); · 45 unmodified lines
46 46
47extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);47extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
48 48
49int handle_guest_sea(phys_addr_t addr, unsigned int esr);
50
51#endif /* __ASSEMBLY__ */49#endif /* __ASSEMBLY__ */
52 50
53#endif /* __ASM_SYSTEM_MISC_H */51#endif /* __ASM_SYSTEM_MISC_H */
arch/arm64/kernel/acpi.c+31−0
@@ -27,8 +27,10 @@ · 26 unmodified lines
27#include <linux/smp.h>27#include <linux/smp.h>
28#include <linux/serial_core.h>28#include <linux/serial_core.h>
29 29
30#include <acpi/ghes.h>
30#include <asm/cputype.h>31#include <asm/cputype.h>
31#include <asm/cpu_ops.h>32#include <asm/cpu_ops.h>
33#include <asm/daifflags.h>
32#include <asm/pgtable.h>34#include <asm/pgtable.h>
33#include <asm/smp_plat.h>35#include <asm/smp_plat.h>
34 36
@@ -256,3 +258,32 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) · 221 unmodified lines
256 return __pgprot(PROT_NORMAL_NC);258 return __pgprot(PROT_NORMAL_NC);
257 return __pgprot(PROT_DEVICE_nGnRnE);259 return __pgprot(PROT_DEVICE_nGnRnE);
258}260}
261
262/*
263 * Claim Synchronous External Aborts as a firmware first notification.
264 *
265 * Used by KVM and the arch do_sea handler.
266 * @regs may be NULL when called from process context.
267 */
268int apei_claim_sea(struct pt_regs *regs)
269{
270 int err = -ENOENT;
271 unsigned long current_flags;
272
273 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
274 return err;
275
276 current_flags = arch_local_save_flags();
277
278 /*
279 * SEA can interrupt SError, mask it and describe this as an NMI so
280 * that APEI defers the handling.
281 */
282 local_daif_restore(DAIF_ERRCTX);
283 nmi_enter();
284 err = ghes_notify_sea();
285 nmi_exit();
286 local_daif_restore(current_flags);
287
288 return err;
289}
arch/arm64/mm/fault.c+5−19
@@ -18,6 +18,7 @@ · 17 unmodified lines
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */19 */
20 20
21#include <linux/acpi.h>
21#include <linux/extable.h>22#include <linux/extable.h>
22#include <linux/signal.h>23#include <linux/signal.h>
23#include <linux/mm.h>24#include <linux/mm.h>
@@ -33,6 +34,7 @@ · 9 unmodified lines
33#include <linux/preempt.h>34#include <linux/preempt.h>
34#include <linux/hugetlb.h>35#include <linux/hugetlb.h>
35 36
37#include <asm/acpi.h>
36#include <asm/bug.h>38#include <asm/bug.h>
37#include <asm/cmpxchg.h>39#include <asm/cmpxchg.h>
38#include <asm/cpufeature.h>40#include <asm/cpufeature.h>
@@ -47,8 +49,6 @@ · 8 unmodified lines
47#include <asm/tlbflush.h>49#include <asm/tlbflush.h>
48#include <asm/traps.h>50#include <asm/traps.h>
49 51
50#include <acpi/ghes.h>
51
52struct fault_info {52struct fault_info {
53 int (*fn)(unsigned long addr, unsigned int esr,53 int (*fn)(unsigned long addr, unsigned int esr,
54 struct pt_regs *regs);54 struct pt_regs *regs);
@@ -643,19 +643,10 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) · 588 unmodified lines
643 inf = esr_to_fault_info(esr);643 inf = esr_to_fault_info(esr);
644 644
645 /*645 /*
646 * Synchronous aborts may interrupt code which had interrupts masked.646 * Return value ignored as we rely on signal merging.
647 * Before calling out into the wider kernel tell the interested647 * Future patches will make this more robust.
648 * subsystems.
649 */648 */
650 if (IS_ENABLED(CONFIG_ACPI_APEI_SEA)) {649 apei_claim_sea(regs);
651 if (interrupts_enabled(regs))
652 nmi_enter();
653
654 ghes_notify_sea();
655
656 if (interrupts_enabled(regs))
657 nmi_exit();
658 }
659 650
660 if (esr & ESR_ELx_FnV)651 if (esr & ESR_ELx_FnV)
661 siaddr = NULL;652 siaddr = NULL;
@@ -733,11 +724,6 @@ static const struct fault_info fault_info[] = { · 71 unmodified lines
733 { do_bad, SIGKILL, SI_KERNEL, "unknown 63" },724 { do_bad, SIGKILL, SI_KERNEL, "unknown 63" },
734};725};
735 726
736int handle_guest_sea(phys_addr_t addr, unsigned int esr)
737{
738 return ghes_notify_sea();
739}
740
741asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr,727asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr,
742 struct pt_regs *regs)728 struct pt_regs *regs)
743{729{
drivers/acpi/apei/Kconfig+1−11
@@ -41,19 +41,9 @@ config ACPI_APEI_PCIEAER · 40 unmodified lines
41 Turn on this option to enable the corresponding support.41 Turn on this option to enable the corresponding support.
42 42
43config ACPI_APEI_SEA43config ACPI_APEI_SEA
44 bool "APEI Synchronous External Abort logging/recovering support"44 bool
45 depends on ARM64 && ACPI_APEI_GHES45 depends on ARM64 && ACPI_APEI_GHES
46 default y46 default y
47 help
48 This option should be enabled if the system supports
49 firmware first handling of SEA (Synchronous External Abort).
50 SEA happens with certain faults of data abort or instruction
51 abort synchronous exceptions on ARMv8 systems. If a system
52 supports firmware first handling of SEA, the platform analyzes
53 and handles hardware error notifications from SEA, and it may then
54 form a HW error record for the OS to parse and handle. This
55 option allows the OS to look for such hardware error record, and
56 take appropriate action.
57 47
58config ACPI_APEI_MEMORY_FAILURE48config ACPI_APEI_MEMORY_FAILURE
59 bool "APEI memory error recovering support"49 bool "APEI memory error recovering support"
drivers/acpi/apei/bert.c+10−13
@@ -42,15 +42,7 @@ static void __init bert_print_all(struct acpi_bert_region *region, · 41 unmodified lines
42 int remain = region_len;42 int remain = region_len;
43 u32 estatus_len;43 u32 estatus_len;
44 44
45 if (!estatus->block_status)45 while (remain >= sizeof(struct acpi_bert_region)) {
46 return;
47
48 while (remain > sizeof(struct acpi_bert_region)) {
49 if (cper_estatus_check(estatus)) {
50 pr_err(FW_BUG "Invalid error record.\n");
51 return;
52 }
53
54 estatus_len = cper_estatus_len(estatus);46 estatus_len = cper_estatus_len(estatus);
55 if (remain < estatus_len) {47 if (remain < estatus_len) {
56 pr_err(FW_BUG "Truncated status block (length: %u).\n",48 pr_err(FW_BUG "Truncated status block (length: %u).\n",
@@ -58,6 +50,15 @@ static void __init bert_print_all(struct acpi_bert_region *region, · 1 unmodified line
58 return;50 return;
59 }51 }
60 52
53 /* No more error records. */
54 if (!estatus->block_status)
55 return;
56
57 if (cper_estatus_check(estatus)) {
58 pr_err(FW_BUG "Invalid error record.\n");
59 return;
60 }
61
61 pr_info_once("Error records from previous boot:\n");62 pr_info_once("Error records from previous boot:\n");
62 63
63 cper_estatus_print(KERN_INFO HW_ERR, estatus);64 cper_estatus_print(KERN_INFO HW_ERR, estatus);
@@ -70,10 +71,6 @@ static void __init bert_print_all(struct acpi_bert_region *region, · 6 unmodified lines
70 estatus->block_status = 0;71 estatus->block_status = 0;
71 72
72 estatus = (void *)estatus + estatus_len;73 estatus = (void *)estatus + estatus_len;
73 /* No more error records. */
74 if (!estatus->block_status)
75 return;
76
77 remain -= estatus_len;74 remain -= estatus_len;
78 }75 }
79}76}
drivers/acpi/apei/einj.c+7−8
@@ -644,8 +644,8 @@ static int error_type_set(void *data, u64 val) · 643 unmodified lines
644 return 0;644 return 0;
645}645}
646 646
647DEFINE_SIMPLE_ATTRIBUTE(error_type_fops, error_type_get,647DEFINE_DEBUGFS_ATTRIBUTE(error_type_fops, error_type_get, error_type_set,
648 error_type_set, "0x%llx\n");648 "0x%llx\n");
649 649
650static int error_inject_set(void *data, u64 val)650static int error_inject_set(void *data, u64 val)
651{651{
@@ -656,8 +656,7 @@ static int error_inject_set(void *data, u64 val) · 4 unmodified lines
656 error_param3, error_param4);656 error_param3, error_param4);
657}657}
658 658
659DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,659DEFINE_DEBUGFS_ATTRIBUTE(error_inject_fops, NULL, error_inject_set, "%llu\n");
660 error_inject_set, "%llu\n");
661 660
662static int einj_check_table(struct acpi_table_einj *einj_tab)661static int einj_check_table(struct acpi_table_einj *einj_tab)
663{662{
@@ -709,10 +708,10 @@ static int __init einj_init(void) · 45 unmodified lines
709 708
710 debugfs_create_file("available_error_type", S_IRUSR, einj_debug_dir,709 debugfs_create_file("available_error_type", S_IRUSR, einj_debug_dir,
711 NULL, &available_error_type_fops);710 NULL, &available_error_type_fops);
712 debugfs_create_file("error_type", S_IRUSR | S_IWUSR, einj_debug_dir,711 debugfs_create_file_unsafe("error_type", 0600, einj_debug_dir,
713 NULL, &error_type_fops);712 NULL, &error_type_fops);
714 debugfs_create_file("error_inject", S_IWUSR, einj_debug_dir,713 debugfs_create_file_unsafe("error_inject", 0200, einj_debug_dir,
715 NULL, &error_inject_fops);714 NULL, &error_inject_fops);
716 715
717 apei_resources_init(&einj_resources);716 apei_resources_init(&einj_resources);
718 einj_exec_ctx_init(&ctx);717 einj_exec_ctx_init(&ctx);
drivers/acpi/apei/erst.c+12−15
@@ -938,17 +938,17 @@ static struct pstore_info erst_info = { · 937 unmodified lines
938};938};
939 939
940#define CPER_CREATOR_PSTORE \940#define CPER_CREATOR_PSTORE \
941 UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \941 GUID_INIT(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \
942 0x64, 0x90, 0xb8, 0x9d)942 0x64, 0x90, 0xb8, 0x9d)
943#define CPER_SECTION_TYPE_DMESG \943#define CPER_SECTION_TYPE_DMESG \
944 UUID_LE(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \944 GUID_INIT(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \
945 0x94, 0x19, 0xeb, 0x12)945 0x94, 0x19, 0xeb, 0x12)
946#define CPER_SECTION_TYPE_DMESG_Z \946#define CPER_SECTION_TYPE_DMESG_Z \
947 UUID_LE(0x4f118707, 0x04dd, 0x4055, 0xb5, 0xdd, 0x95, 0x6d, \947 GUID_INIT(0x4f118707, 0x04dd, 0x4055, 0xb5, 0xdd, 0x95, 0x6d, \
948 0x34, 0xdd, 0xfa, 0xc6)948 0x34, 0xdd, 0xfa, 0xc6)
949#define CPER_SECTION_TYPE_MCE \949#define CPER_SECTION_TYPE_MCE \
950 UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \950 GUID_INIT(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \
951 0x04, 0x4a, 0x38, 0xfc)951 0x04, 0x4a, 0x38, 0xfc)
952 952
953struct cper_pstore_record {953struct cper_pstore_record {
954 struct cper_record_header hdr;954 struct cper_record_header hdr;
@@ -1012,7 +1012,7 @@ skip: · 57 unmodified lines
1012 rc = -EIO;1012 rc = -EIO;
1013 goto out;1013 goto out;
1014 }1014 }
1015 if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0)1015 if (!guid_equal(&rcd->hdr.creator_id, &CPER_CREATOR_PSTORE))
1016 goto skip;1016 goto skip;
1017 1017
1018 record->buf = kmalloc(len, GFP_KERNEL);1018 record->buf = kmalloc(len, GFP_KERNEL);
@@ -1024,15 +1024,12 @@ skip: · 5 unmodified lines
1024 record->id = record_id;1024 record->id = record_id;
1025 record->compressed = false;1025 record->compressed = false;
1026 record->ecc_notice_size = 0;1026 record->ecc_notice_size = 0;
1027 if (uuid_le_cmp(rcd->sec_hdr.section_type,1027 if (guid_equal(&rcd->sec_hdr.section_type, &CPER_SECTION_TYPE_DMESG_Z)) {
1028 CPER_SECTION_TYPE_DMESG_Z) == 0) {
1029 record->type = PSTORE_TYPE_DMESG;1028 record->type = PSTORE_TYPE_DMESG;
1030 record->compressed = true;1029 record->compressed = true;
1031 } else if (uuid_le_cmp(rcd->sec_hdr.section_type,1030 } else if (guid_equal(&rcd->sec_hdr.section_type, &CPER_SECTION_TYPE_DMESG))
1032 CPER_SECTION_TYPE_DMESG) == 0)
1033 record->type = PSTORE_TYPE_DMESG;1031 record->type = PSTORE_TYPE_DMESG;
1034 else if (uuid_le_cmp(rcd->sec_hdr.section_type,1032 else if (guid_equal(&rcd->sec_hdr.section_type, &CPER_SECTION_TYPE_MCE))
1035 CPER_SECTION_TYPE_MCE) == 0)
1036 record->type = PSTORE_TYPE_MCE;1033 record->type = PSTORE_TYPE_MCE;
1037 else1034 else
1038 record->type = PSTORE_TYPE_MAX;1035 record->type = PSTORE_TYPE_MAX;
drivers/acpi/apei/ghes.c+371−284
@@ -25,6 +25,7 @@ · 24 unmodified lines
25 * GNU General Public License for more details.25 * GNU General Public License for more details.
26 */26 */
27 27
28#include <linux/arm_sdei.h>
28#include <linux/kernel.h>29#include <linux/kernel.h>
29#include <linux/moduleparam.h>30#include <linux/moduleparam.h>
30#include <linux/init.h>31#include <linux/init.h>
@@ -33,7 +34,6 @@ · 2 unmodified lines
33#include <linux/interrupt.h>34#include <linux/interrupt.h>
34#include <linux/timer.h>35#include <linux/timer.h>
35#include <linux/cper.h>36#include <linux/cper.h>
36#include <linux/kdebug.h>
37#include <linux/platform_device.h>37#include <linux/platform_device.h>
38#include <linux/mutex.h>38#include <linux/mutex.h>
39#include <linux/ratelimit.h>39#include <linux/ratelimit.h>
@@ -42,6 +42,7 @@ · 2 unmodified lines
42#include <linux/llist.h>42#include <linux/llist.h>
43#include <linux/genalloc.h>43#include <linux/genalloc.h>
44#include <linux/pci.h>44#include <linux/pci.h>
45#include <linux/pfn.h>
45#include <linux/aer.h>46#include <linux/aer.h>
46#include <linux/nmi.h>47#include <linux/nmi.h>
47#include <linux/sched/clock.h>48#include <linux/sched/clock.h>
@@ -85,6 +86,15 @@ · 37 unmodified lines
85 ((struct acpi_hest_generic_status *) \86 ((struct acpi_hest_generic_status *) \
86 ((struct ghes_estatus_node *)(estatus_node) + 1))87 ((struct ghes_estatus_node *)(estatus_node) + 1))
87 88
89/*
90 * NMI-like notifications vary by architecture, before the compiler can prune
91 * unused static functions it needs a value for these enums.
92 */
93#ifndef CONFIG_ARM_SDE_INTERFACE
94#define FIX_APEI_GHES_SDEI_NORMAL __end_of_fixed_addresses
95#define FIX_APEI_GHES_SDEI_CRITICAL __end_of_fixed_addresses
96#endif
97
88static inline bool is_hest_type_generic_v2(struct ghes *ghes)98static inline bool is_hest_type_generic_v2(struct ghes *ghes)
89{99{
90 return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2;100 return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2;
@@ -115,11 +125,10 @@ static DEFINE_MUTEX(ghes_list_mutex); · 24 unmodified lines
115 * handler, but general ioremap can not be used in atomic context, so125 * handler, but general ioremap can not be used in atomic context, so
116 * the fixmap is used instead.126 * the fixmap is used instead.
117 *127 *
118 * These 2 spinlocks are used to prevent the fixmap entries from being used128 * This spinlock is used to prevent the fixmap entry from being used
119 * simultaneously.129 * simultaneously.
120 */130 */
121static DEFINE_RAW_SPINLOCK(ghes_ioremap_lock_nmi);131static DEFINE_SPINLOCK(ghes_notify_lock_irq);
122static DEFINE_SPINLOCK(ghes_ioremap_lock_irq);
123 132
124static struct gen_pool *ghes_estatus_pool;133static struct gen_pool *ghes_estatus_pool;
125static unsigned long ghes_estatus_pool_size_request;134static unsigned long ghes_estatus_pool_size_request;
@@ -129,82 +138,49 @@ static atomic_t ghes_estatus_cache_alloced; · 3 unmodified lines
129 138
130static int ghes_panic_timeout __read_mostly = 30;139static int ghes_panic_timeout __read_mostly = 30;
131 140
132static void __iomem *ghes_ioremap_pfn_nmi(u64 pfn)141static void __iomem *ghes_map(u64 pfn, enum fixed_addresses fixmap_idx)
133{142{
134 phys_addr_t paddr;143 phys_addr_t paddr;
135 pgprot_t prot;144 pgprot_t prot;
136 145
137 paddr = pfn << PAGE_SHIFT;146 paddr = PFN_PHYS(pfn);
138 prot = arch_apei_get_mem_attribute(paddr);147 prot = arch_apei_get_mem_attribute(paddr);
139 __set_fixmap(FIX_APEI_GHES_NMI, paddr, prot);148 __set_fixmap(fixmap_idx, paddr, prot);
140 149
141 return (void __iomem *) fix_to_virt(FIX_APEI_GHES_NMI);150 return (void __iomem *) __fix_to_virt(fixmap_idx);
142}151}
143 152
144static void __iomem *ghes_ioremap_pfn_irq(u64 pfn)153static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
145{154{
146 phys_addr_t paddr;155 int _idx = virt_to_fix((unsigned long)vaddr);
147 pgprot_t prot;
148
149 paddr = pfn << PAGE_SHIFT;
150 prot = arch_apei_get_mem_attribute(paddr);
151 __set_fixmap(FIX_APEI_GHES_IRQ, paddr, prot);
152
153 return (void __iomem *) fix_to_virt(FIX_APEI_GHES_IRQ);
154}
155 156
156static void ghes_iounmap_nmi(void)157 WARN_ON_ONCE(fixmap_idx != _idx);
157{158 clear_fixmap(fixmap_idx);
158 clear_fixmap(FIX_APEI_GHES_NMI);
159}159}
160 160
161static void ghes_iounmap_irq(void)161int ghes_estatus_pool_init(int num_ghes)
162{162{
163 clear_fixmap(FIX_APEI_GHES_IRQ);163 unsigned long addr, len;
164}
165 164
166static int ghes_estatus_pool_init(void)
167{
168 ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);165 ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
169 if (!ghes_estatus_pool)166 if (!ghes_estatus_pool)
170 return -ENOMEM;167 return -ENOMEM;
171 return 0;
172}
173 168
174static void ghes_estatus_pool_free_chunk_page(struct gen_pool *pool,169 len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX;
175 struct gen_pool_chunk *chunk,170 len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE);
176 void *data)
177{
178 free_page(chunk->start_addr);
179}
180
181static void ghes_estatus_pool_exit(void)
182{
183 gen_pool_for_each_chunk(ghes_estatus_pool,
184 ghes_estatus_pool_free_chunk_page, NULL);
185 gen_pool_destroy(ghes_estatus_pool);
186}
187 171
188static int ghes_estatus_pool_expand(unsigned long len)172 ghes_estatus_pool_size_request = PAGE_ALIGN(len);
189{173 addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
190 unsigned long i, pages, size, addr;174 if (!addr)
191 int ret;175 return -ENOMEM;
192 176
193 ghes_estatus_pool_size_request += PAGE_ALIGN(len);177 /*
194 size = gen_pool_size(ghes_estatus_pool);178 * New allocation must be visible in all pgd before it can be found by
195 if (size >= ghes_estatus_pool_size_request)179 * an NMI allocating from the pool.
196 return 0;180 */
197 pages = (ghes_estatus_pool_size_request - size) / PAGE_SIZE;181 vmalloc_sync_all();
198 for (i = 0; i < pages; i++) {
199 addr = __get_free_page(GFP_KERNEL);
200 if (!addr)
201 return -ENOMEM;
202 ret = gen_pool_add(ghes_estatus_pool, addr, PAGE_SIZE, -1);
203 if (ret)
204 return ret;
205 }
206 182
207 return 0;183 return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
208}184}
209 185
210static int map_gen_v2(struct ghes *ghes)186static int map_gen_v2(struct ghes *ghes)
@@ -217,6 +193,21 @@ static void unmap_gen_v2(struct ghes *ghes) · 6 unmodified lines
217 apei_unmap_generic_address(&ghes->generic_v2->read_ack_register);193 apei_unmap_generic_address(&ghes->generic_v2->read_ack_register);
218}194}
219 195
196static void ghes_ack_error(struct acpi_hest_generic_v2 *gv2)
197{
198 int rc;
199 u64 val = 0;
200
201 rc = apei_read(&val, &gv2->read_ack_register);
202 if (rc)
203 return;
204
205 val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset;
206 val |= gv2->read_ack_write << gv2->read_ack_register.bit_offset;
207
208 apei_write(val, &gv2->read_ack_register);
209}
210
220static struct ghes *ghes_new(struct acpi_hest_generic *generic)211static struct ghes *ghes_new(struct acpi_hest_generic *generic)
221{212{
222 struct ghes *ghes;213 struct ghes *ghes;
@@ -289,23 +280,16 @@ static inline int ghes_severity(int severity) · 66 unmodified lines
289}280}
290 281
291static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len,282static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len,
292 int from_phys)283 int from_phys,
284 enum fixed_addresses fixmap_idx)
293{285{
294 void __iomem *vaddr;286 void __iomem *vaddr;
295 unsigned long flags = 0;
296 int in_nmi = in_nmi();
297 u64 offset;287 u64 offset;
298 u32 trunk;288 u32 trunk;
299 289
300 while (len > 0) {290 while (len > 0) {
301 offset = paddr - (paddr & PAGE_MASK);291 offset = paddr - (paddr & PAGE_MASK);
302 if (in_nmi) {292 vaddr = ghes_map(PHYS_PFN(paddr), fixmap_idx);
303 raw_spin_lock(&ghes_ioremap_lock_nmi);
304 vaddr = ghes_ioremap_pfn_nmi(paddr >> PAGE_SHIFT);
305 } else {
306 spin_lock_irqsave(&ghes_ioremap_lock_irq, flags);
307 vaddr = ghes_ioremap_pfn_irq(paddr >> PAGE_SHIFT);
308 }
309 trunk = PAGE_SIZE - offset;293 trunk = PAGE_SIZE - offset;
310 trunk = min(trunk, len);294 trunk = min(trunk, len);
311 if (from_phys)295 if (from_phys)
@@ -315,72 +299,114 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, · 3 unmodified lines
315 len -= trunk;299 len -= trunk;
316 paddr += trunk;300 paddr += trunk;
317 buffer += trunk;301 buffer += trunk;
318 if (in_nmi) {302 ghes_unmap(vaddr, fixmap_idx);
319 ghes_iounmap_nmi();303 }
320 raw_spin_unlock(&ghes_ioremap_lock_nmi);304}
321 } else {305
322 ghes_iounmap_irq();306/* Check the top-level record header has an appropriate size. */
323 spin_unlock_irqrestore(&ghes_ioremap_lock_irq, flags);307static int __ghes_check_estatus(struct ghes *ghes,
324 }308 struct acpi_hest_generic_status *estatus)
309{
310 u32 len = cper_estatus_len(estatus);
311
312 if (len < sizeof(*estatus)) {
313 pr_warn_ratelimited(FW_WARN GHES_PFX "Truncated error status block!\n");
314 return -EIO;
315 }
316
317 if (len > ghes->generic->error_block_length) {
318 pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid error status block length!\n");
319 return -EIO;
320 }
321
322 if (cper_estatus_check_header(estatus)) {
323 pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid CPER header!\n");
324 return -EIO;
325 }325 }
326
327 return 0;
326}328}
327 329
328static int ghes_read_estatus(struct ghes *ghes, int silent)330/* Read the CPER block, returning its address, and header in estatus. */
331static int __ghes_peek_estatus(struct ghes *ghes,
332 struct acpi_hest_generic_status *estatus,
333 u64 *buf_paddr, enum fixed_addresses fixmap_idx)
329{334{
330 struct acpi_hest_generic *g = ghes->generic;335 struct acpi_hest_generic *g = ghes->generic;
331 u64 buf_paddr;
332 u32 len;
333 int rc;336 int rc;
334 337
335 rc = apei_read(&buf_paddr, &g->error_status_address);338 rc = apei_read(buf_paddr, &g->error_status_address);
336 if (rc) {339 if (rc) {
337 if (!silent && printk_ratelimit())340 *buf_paddr = 0;
338 pr_warning(FW_WARN GHES_PFX341 pr_warn_ratelimited(FW_WARN GHES_PFX
339"Failed to read error status block address for hardware error source: %d.\n",342"Failed to read error status block address for hardware error source: %d.\n",
340 g->header.source_id);343 g->header.source_id);
341 return -EIO;344 return -EIO;
342 }345 }
343 if (!buf_paddr)346 if (!*buf_paddr)
344 return -ENOENT;347 return -ENOENT;
345 348
346 ghes_copy_tofrom_phys(ghes->estatus, buf_paddr,349 ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1,
347 sizeof(*ghes->estatus), 1);350 fixmap_idx);
348 if (!ghes->estatus->block_status)351 if (!estatus->block_status) {
352 *buf_paddr = 0;
349 return -ENOENT;353 return -ENOENT;
354 }
350 355
351 ghes->buffer_paddr = buf_paddr;356 return __ghes_check_estatus(ghes, estatus);
352 ghes->flags |= GHES_TO_CLEAR;357}
353 358
354 rc = -EIO;359static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus,
355 len = cper_estatus_len(ghes->estatus);360 u64 buf_paddr, enum fixed_addresses fixmap_idx,
356 if (len < sizeof(*ghes->estatus))361 size_t buf_len)
357 goto err_read_block;362{
358 if (len > ghes->generic->error_block_length)363 ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx);
359 goto err_read_block;364 if (cper_estatus_check(estatus)) {
360 if (cper_estatus_check_header(ghes->estatus))365 pr_warn_ratelimited(FW_WARN GHES_PFX
361 goto err_read_block;366 "Failed to read error status block!\n");
362 ghes_copy_tofrom_phys(ghes->estatus + 1,367 return -EIO;
363 buf_paddr + sizeof(*ghes->estatus),368 }
364 len - sizeof(*ghes->estatus), 1);369
365 if (cper_estatus_check(ghes->estatus))370 return 0;
366 goto err_read_block;
367 rc = 0;
368
369err_read_block:
370 if (rc && !silent && printk_ratelimit())
371 pr_warning(FW_WARN GHES_PFX
372 "Failed to read error status block!\n");
373 return rc;
374}371}
375 372
376static void ghes_clear_estatus(struct ghes *ghes)373static int ghes_read_estatus(struct ghes *ghes,
374 struct acpi_hest_generic_status *estatus,
375 u64 *buf_paddr, enum fixed_addresses fixmap_idx)
377{376{
378 ghes->estatus->block_status = 0;377 int rc;
379 if (!(ghes->flags & GHES_TO_CLEAR))378
379 rc = __ghes_peek_estatus(ghes, estatus, buf_paddr, fixmap_idx);
380 if (rc)
381 return rc;
382
383 rc = __ghes_check_estatus(ghes, estatus);
384 if (rc)
385 return rc;
386
387 return __ghes_read_estatus(estatus, *buf_paddr, fixmap_idx,
388 cper_estatus_len(estatus));
389}
390
391static void ghes_clear_estatus(struct ghes *ghes,
392 struct acpi_hest_generic_status *estatus,
393 u64 buf_paddr, enum fixed_addresses fixmap_idx)
394{
395 estatus->block_status = 0;
396
397 if (!buf_paddr)
380 return;398 return;
381 ghes_copy_tofrom_phys(ghes->estatus, ghes->buffer_paddr,399
382 sizeof(ghes->estatus->block_status), 0);400 ghes_copy_tofrom_phys(estatus, buf_paddr,
383 ghes->flags &= ~GHES_TO_CLEAR;401 sizeof(estatus->block_status), 0,
402 fixmap_idx);
403
404 /*
405 * GHESv2 type HEST entries introduce support for error acknowledgment,
406 * so only acknowledge the error if this support is present.
407 */
408 if (is_hest_type_generic_v2(ghes))
409 ghes_ack_error(ghes->generic_v2);
384}410}
385 411
386static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev)412static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev)
@@ -672,26 +698,13 @@ static void ghes_estatus_cache_add( · 285 unmodified lines
672 rcu_read_unlock();698 rcu_read_unlock();
673}699}
674 700
675static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2)701static void __ghes_panic(struct ghes *ghes,
702 struct acpi_hest_generic_status *estatus,
703 u64 buf_paddr, enum fixed_addresses fixmap_idx)
676{704{
677 int rc;705 __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus);
678 u64 val = 0;
679 706
680 rc = apei_read(&val, &gv2->read_ack_register);707 ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
681 if (rc)
682 return rc;
683
684 val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset;
685 val |= gv2->read_ack_write << gv2->read_ack_register.bit_offset;
686
687 return apei_write(val, &gv2->read_ack_register);
688}
689
690static void __ghes_panic(struct ghes *ghes)
691{
692 __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus);
693
694 ghes_clear_estatus(ghes);
695 708
696 /* reboot to log the error! */709 /* reboot to log the error! */
697 if (!panic_timeout)710 if (!panic_timeout)
@@ -701,34 +714,25 @@ static void __ghes_panic(struct ghes *ghes) · 3 unmodified lines
701 714
702static int ghes_proc(struct ghes *ghes)715static int ghes_proc(struct ghes *ghes)
703{716{
717 struct acpi_hest_generic_status *estatus = ghes->estatus;
718 u64 buf_paddr;
704 int rc;719 int rc;
705 720
706 rc = ghes_read_estatus(ghes, 0);721 rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ);
707 if (rc)722 if (rc)
708 goto out;723 goto out;
709 724
710 if (ghes_severity(ghes->estatus->error_severity) >= GHES_SEV_PANIC) {725 if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC)
711 __ghes_panic(ghes);726 __ghes_panic(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
712 }
713 727
714 if (!ghes_estatus_cached(ghes->estatus)) {728 if (!ghes_estatus_cached(estatus)) {
715 if (ghes_print_estatus(NULL, ghes->generic, ghes->estatus))729 if (ghes_print_estatus(NULL, ghes->generic, estatus))
716 ghes_estatus_cache_add(ghes->generic, ghes->estatus);730 ghes_estatus_cache_add(ghes->generic, estatus);
717 }731 }
718 ghes_do_proc(ghes, ghes->estatus);732 ghes_do_proc(ghes, estatus);
719 733
720out:734out:
721 ghes_clear_estatus(ghes);735 ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
722
723 if (rc == -ENOENT)
724 return rc;
725
726 /*
727 * GHESv2 type HEST entries introduce support for error acknowledgment,
728 * so only acknowledge the error if this support is present.
729 */
730 if (is_hest_type_generic_v2(ghes))
731 return ghes_ack_error(ghes->generic_v2);
732 736
733 return rc;737 return rc;
734}738}
@@ -751,8 +755,11 @@ static void ghes_add_timer(struct ghes *ghes) · 16 unmodified lines
751static void ghes_poll_func(struct timer_list *t)755static void ghes_poll_func(struct timer_list *t)
752{756{
753 struct ghes *ghes = from_timer(ghes, t, timer);757 struct ghes *ghes = from_timer(ghes, t, timer);
758 unsigned long flags;
754 759
760 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
755 ghes_proc(ghes);761 ghes_proc(ghes);
762 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
756 if (!(ghes->flags & GHES_EXITING))763 if (!(ghes->flags & GHES_EXITING))
757 ghes_add_timer(ghes);764 ghes_add_timer(ghes);
758}765}
@@ -760,9 +767,12 @@ static void ghes_poll_func(struct timer_list *t) · 1 unmodified line
760static irqreturn_t ghes_irq_func(int irq, void *data)767static irqreturn_t ghes_irq_func(int irq, void *data)
761{768{
762 struct ghes *ghes = data;769 struct ghes *ghes = data;
770 unsigned long flags;
763 int rc;771 int rc;
764 772
773 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
765 rc = ghes_proc(ghes);774 rc = ghes_proc(ghes);
775 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
766 if (rc)776 if (rc)
767 return IRQ_NONE;777 return IRQ_NONE;
768 778
@@ -773,14 +783,17 @@ static int ghes_notify_hed(struct notifier_block *this, unsigned long event, · 4 unmodified lines
773 void *data)783 void *data)
774{784{
775 struct ghes *ghes;785 struct ghes *ghes;
786 unsigned long flags;
776 int ret = NOTIFY_DONE;787 int ret = NOTIFY_DONE;
777 788
789 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
778 rcu_read_lock();790 rcu_read_lock();
779 list_for_each_entry_rcu(ghes, &ghes_hed, list) {791 list_for_each_entry_rcu(ghes, &ghes_hed, list) {
780 if (!ghes_proc(ghes))792 if (!ghes_proc(ghes))
781 ret = NOTIFY_OK;793 ret = NOTIFY_OK;
782 }794 }
783 rcu_read_unlock();795 rcu_read_unlock();
796 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
784 797
785 return ret;798 return ret;
786}799}
@@ -789,66 +802,20 @@ static struct notifier_block ghes_notifier_hed = { · 2 unmodified lines
789 .notifier_call = ghes_notify_hed,802 .notifier_call = ghes_notify_hed,
790};803};
791 804
792#ifdef CONFIG_ACPI_APEI_SEA
793static LIST_HEAD(ghes_sea);
794
795/*
796 * Return 0 only if one of the SEA error sources successfully reported an error
797 * record sent from the firmware.
798 */
799int ghes_notify_sea(void)
800{
801 struct ghes *ghes;
802 int ret = -ENOENT;
803
804 rcu_read_lock();
805 list_for_each_entry_rcu(ghes, &ghes_sea, list) {
806 if (!ghes_proc(ghes))
807 ret = 0;
808 }
809 rcu_read_unlock();
810 return ret;
811}
812
813static void ghes_sea_add(struct ghes *ghes)
814{
815 mutex_lock(&ghes_list_mutex);
816 list_add_rcu(&ghes->list, &ghes_sea);
817 mutex_unlock(&ghes_list_mutex);
818}
819
820static void ghes_sea_remove(struct ghes *ghes)
821{
822 mutex_lock(&ghes_list_mutex);
823 list_del_rcu(&ghes->list);
824 mutex_unlock(&ghes_list_mutex);
825 synchronize_rcu();
826}
827#else /* CONFIG_ACPI_APEI_SEA */
828static inline void ghes_sea_add(struct ghes *ghes) { }
829static inline void ghes_sea_remove(struct ghes *ghes) { }
830#endif /* CONFIG_ACPI_APEI_SEA */
831
832#ifdef CONFIG_HAVE_ACPI_APEI_NMI
833/*805/*
834 * printk is not safe in NMI context. So in NMI handler, we allocate806 * Handlers for CPER records may not be NMI safe. For example,
835 * required memory from lock-less memory allocator807 * memory_failure_queue() takes spinlocks and calls schedule_work_on().
836 * (ghes_estatus_pool), save estatus into it, put them into lock-less808 * In any NMI-like handler, memory from ghes_estatus_pool is used to save
837 * list (ghes_estatus_llist), then delay printk into IRQ context via809 * estatus, and added to the ghes_estatus_llist. irq_work_queue() causes
838 * irq_work (ghes_proc_irq_work). ghes_estatus_size_request record810 * ghes_proc_in_irq() to run in IRQ context where each estatus in
839 * required pool size by all NMI error source.811 * ghes_estatus_llist is processed.
812 *
813 * Memory from the ghes_estatus_pool is also used with the ghes_estatus_cache
814 * to suppress frequent messages.
840 */815 */
841static struct llist_head ghes_estatus_llist;816static struct llist_head ghes_estatus_llist;
842static struct irq_work ghes_proc_irq_work;817static struct irq_work ghes_proc_irq_work;
843 818
844/*
845 * NMI may be triggered on any CPU, so ghes_in_nmi is used for
846 * having only one concurrent reader.
847 */
848static atomic_t ghes_in_nmi = ATOMIC_INIT(0);
849
850static LIST_HEAD(ghes_nmi);
851
852static void ghes_proc_in_irq(struct irq_work *irq_work)819static void ghes_proc_in_irq(struct irq_work *irq_work)
853{820{
854 struct llist_node *llnode, *next;821 struct llist_node *llnode, *next;
@@ -905,96 +872,154 @@ static void ghes_print_queued_estatus(void) · 50 unmodified lines
905 }872 }
906}873}
907 874
908/* Save estatus for further processing in IRQ context */875static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
909static void __process_error(struct ghes *ghes)876 enum fixed_addresses fixmap_idx)
910{877{
911#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG878 struct acpi_hest_generic_status *estatus, tmp_header;
912 u32 len, node_len;
913 struct ghes_estatus_node *estatus_node;879 struct ghes_estatus_node *estatus_node;
914 struct acpi_hest_generic_status *estatus;880 u32 len, node_len;
881 u64 buf_paddr;
882 int sev, rc;
915 883
916 if (ghes_estatus_cached(ghes->estatus))884 if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG))
917 return;885 return -EOPNOTSUPP;
918 886
919 len = cper_estatus_len(ghes->estatus);887 rc = __ghes_peek_estatus(ghes, &tmp_header, &buf_paddr, fixmap_idx);
920 node_len = GHES_ESTATUS_NODE_LEN(len);888 if (rc) {
889 ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
890 return rc;
891 }
921 892
893 rc = __ghes_check_estatus(ghes, &tmp_header);
894 if (rc) {
895 ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
896 return rc;
897 }
898
899 len = cper_estatus_len(&tmp_header);
900 node_len = GHES_ESTATUS_NODE_LEN(len);
922 estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len);901 estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len);
923 if (!estatus_node)902 if (!estatus_node)
924 return;903 return -ENOMEM;
925 904
926 estatus_node->ghes = ghes;905 estatus_node->ghes = ghes;
927 estatus_node->generic = ghes->generic;906 estatus_node->generic = ghes->generic;
928 estatus = GHES_ESTATUS_FROM_NODE(estatus_node);907 estatus = GHES_ESTATUS_FROM_NODE(estatus_node);
929 memcpy(estatus, ghes->estatus, len);
930 llist_add(&estatus_node->llnode, &ghes_estatus_llist);
931#endif
932}
933 908
934static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)909 if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) {
935{910 ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
936 struct ghes *ghes;911 rc = -ENOENT;
937 int sev, ret = NMI_DONE;912 goto no_work;
913 }
938 914
939 if (!atomic_add_unless(&ghes_in_nmi, 1, 1))915 sev = ghes_severity(estatus->error_severity);
940 return ret;916 if (sev >= GHES_SEV_PANIC) {
917 ghes_print_queued_estatus();
918 __ghes_panic(ghes, estatus, buf_paddr, fixmap_idx);
919 }
941 920
942 list_for_each_entry_rcu(ghes, &ghes_nmi, list) {921 ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
943 if (ghes_read_estatus(ghes, 1)) {
944 ghes_clear_estatus(ghes);
945 continue;
946 } else {
947 ret = NMI_HANDLED;
948 }
949 922
950 sev = ghes_severity(ghes->estatus->error_severity);923 /* This error has been reported before, don't process it again. */
951 if (sev >= GHES_SEV_PANIC) {924 if (ghes_estatus_cached(estatus))
952 oops_begin();925 goto no_work;
953 ghes_print_queued_estatus();
954 __ghes_panic(ghes);
955 }
956 926
957 if (!(ghes->flags & GHES_TO_CLEAR))927 llist_add(&estatus_node->llnode, &ghes_estatus_llist);
958 continue;928
929 return rc;
930
931no_work:
932 gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node,
933 node_len);
934
935 return rc;
936}
959 937
960 __process_error(ghes);938static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
961 ghes_clear_estatus(ghes);939 enum fixed_addresses fixmap_idx)
940{
941 int ret = -ENOENT;
942 struct ghes *ghes;
943
944 rcu_read_lock();
945 list_for_each_entry_rcu(ghes, rcu_list, list) {
946 if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx))
947 ret = 0;
962 }948 }
949 rcu_read_unlock();
963 950
964#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG951 if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret)
965 if (ret == NMI_HANDLED)
966 irq_work_queue(&ghes_proc_irq_work);952 irq_work_queue(&ghes_proc_irq_work);
967#endif953
968 atomic_dec(&ghes_in_nmi);
969 return ret;954 return ret;
970}955}
971 956
972static unsigned long ghes_esource_prealloc_size(957#ifdef CONFIG_ACPI_APEI_SEA
973 const struct acpi_hest_generic *generic)958static LIST_HEAD(ghes_sea);
959
960/*
961 * Return 0 only if one of the SEA error sources successfully reported an error
962 * record sent from the firmware.
963 */
964int ghes_notify_sea(void)
974{965{
975 unsigned long block_length, prealloc_records, prealloc_size;966 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea);
967 int rv;
976 968
977 block_length = min_t(unsigned long, generic->error_block_length,969 raw_spin_lock(&ghes_notify_lock_sea);
978 GHES_ESTATUS_MAX_SIZE);970 rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA);
979 prealloc_records = max_t(unsigned long,971 raw_spin_unlock(&ghes_notify_lock_sea);
980 generic->records_to_preallocate, 1);
981 prealloc_size = min_t(unsigned long, block_length * prealloc_records,
982 GHES_ESOURCE_PREALLOC_MAX_SIZE);
983 972
984 return prealloc_size;973 return rv;
985}974}
986 975
987static void ghes_estatus_pool_shrink(unsigned long len)976static void ghes_sea_add(struct ghes *ghes)
988{977{
989 ghes_estatus_pool_size_request -= PAGE_ALIGN(len);978 mutex_lock(&ghes_list_mutex);
979 list_add_rcu(&ghes->list, &ghes_sea);
980 mutex_unlock(&ghes_list_mutex);
990}981}
991 982
992static void ghes_nmi_add(struct ghes *ghes)983static void ghes_sea_remove(struct ghes *ghes)
993{984{
994 unsigned long len;985 mutex_lock(&ghes_list_mutex);
986 list_del_rcu(&ghes->list);
987 mutex_unlock(&ghes_list_mutex);
988 synchronize_rcu();
989}
990#else /* CONFIG_ACPI_APEI_SEA */
991static inline void ghes_sea_add(struct ghes *ghes) { }
992static inline void ghes_sea_remove(struct ghes *ghes) { }
993#endif /* CONFIG_ACPI_APEI_SEA */
994
995#ifdef CONFIG_HAVE_ACPI_APEI_NMI
996/*
997 * NMI may be triggered on any CPU, so ghes_in_nmi is used for
998 * having only one concurrent reader.
999 */
1000static atomic_t ghes_in_nmi = ATOMIC_INIT(0);
1001
1002static LIST_HEAD(ghes_nmi);
1003
1004static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
1005{
1006 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi);
1007 int ret = NMI_DONE;
1008
1009 if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
1010 return ret;
1011
1012 raw_spin_lock(&ghes_notify_lock_nmi);
1013 if (!ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI))
1014 ret = NMI_HANDLED;
1015 raw_spin_unlock(&ghes_notify_lock_nmi);
995 1016
996 len = ghes_esource_prealloc_size(ghes->generic);1017 atomic_dec(&ghes_in_nmi);
997 ghes_estatus_pool_expand(len);1018 return ret;
1019}
1020
1021static void ghes_nmi_add(struct ghes *ghes)
1022{
998 mutex_lock(&ghes_list_mutex);1023 mutex_lock(&ghes_list_mutex);
999 if (list_empty(&ghes_nmi))1024 if (list_empty(&ghes_nmi))
1000 register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes");1025 register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes");
@@ -1004,8 +1029,6 @@ static void ghes_nmi_add(struct ghes *ghes) · 3 unmodified lines
1004 1029
1005static void ghes_nmi_remove(struct ghes *ghes)1030static void ghes_nmi_remove(struct ghes *ghes)
1006{1031{
1007 unsigned long len;
1008
1009 mutex_lock(&ghes_list_mutex);1032 mutex_lock(&ghes_list_mutex);
1010 list_del_rcu(&ghes->list);1033 list_del_rcu(&ghes->list);
1011 if (list_empty(&ghes_nmi))1034 if (list_empty(&ghes_nmi))
@@ -1016,24 +1039,79 @@ static void ghes_nmi_remove(struct ghes *ghes) · 4 unmodified lines
1016 * freed after NMI handler finishes.1039 * freed after NMI handler finishes.
1017 */1040 */
1018 synchronize_rcu();1041 synchronize_rcu();
1019 len = ghes_esource_prealloc_size(ghes->generic);
1020 ghes_estatus_pool_shrink(len);
1021}1042}
1043#else /* CONFIG_HAVE_ACPI_APEI_NMI */
1044static inline void ghes_nmi_add(struct ghes *ghes) { }
1045static inline void ghes_nmi_remove(struct ghes *ghes) { }
1046#endif /* CONFIG_HAVE_ACPI_APEI_NMI */
1022 1047
1023static void ghes_nmi_init_cxt(void)1048static void ghes_nmi_init_cxt(void)
1024{1049{
1025 init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq);1050 init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq);
1026}1051}
1027#else /* CONFIG_HAVE_ACPI_APEI_NMI */1052
1028static inline void ghes_nmi_add(struct ghes *ghes) { }1053static int __ghes_sdei_callback(struct ghes *ghes,
1029static inline void ghes_nmi_remove(struct ghes *ghes) { }1054 enum fixed_addresses fixmap_idx)
1030static inline void ghes_nmi_init_cxt(void) { }1055{
1031#endif /* CONFIG_HAVE_ACPI_APEI_NMI */1056 if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) {
1057 irq_work_queue(&ghes_proc_irq_work);
1058
1059 return 0;
1060 }
1061
1062 return -ENOENT;
1063}
1064
1065static int ghes_sdei_normal_callback(u32 event_num, struct pt_regs *regs,
1066 void *arg)
1067{
1068 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_normal);
1069 struct ghes *ghes = arg;
1070 int err;
1071
1072 raw_spin_lock(&ghes_notify_lock_sdei_normal);
1073 err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_NORMAL);
1074 raw_spin_unlock(&ghes_notify_lock_sdei_normal);
1075
1076 return err;
1077}
1078
1079static int ghes_sdei_critical_callback(u32 event_num, struct pt_regs *regs,
1080 void *arg)
1081{
1082 static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_critical);
1083 struct ghes *ghes = arg;
1084 int err;
1085
1086 raw_spin_lock(&ghes_notify_lock_sdei_critical);
1087 err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_CRITICAL);
1088 raw_spin_unlock(&ghes_notify_lock_sdei_critical);
1089
1090 return err;
1091}
1092
1093static int apei_sdei_register_ghes(struct ghes *ghes)
1094{
1095 if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
1096 return -EOPNOTSUPP;
1097
1098 return sdei_register_ghes(ghes, ghes_sdei_normal_callback,
1099 ghes_sdei_critical_callback);
1100}
1101
1102static int apei_sdei_unregister_ghes(struct ghes *ghes)
1103{
1104 if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
1105 return -EOPNOTSUPP;
1106
1107 return sdei_unregister_ghes(ghes);
1108}
1032 1109
1033static int ghes_probe(struct platform_device *ghes_dev)1110static int ghes_probe(struct platform_device *ghes_dev)
1034{1111{
1035 struct acpi_hest_generic *generic;1112 struct acpi_hest_generic *generic;
1036 struct ghes *ghes = NULL;1113 struct ghes *ghes = NULL;
1114 unsigned long flags;
1037 1115
1038 int rc = -EINVAL;1116 int rc = -EINVAL;
1039 1117
@@ -1064,6 +1142,13 @@ static int ghes_probe(struct platform_device *ghes_dev) · 24 unmodified lines
1064 goto err;1142 goto err;
1065 }1143 }
1066 break;1144 break;
1145 case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1146 if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) {
1147 pr_warn(GHES_PFX "Generic hardware error source: %d notified via SDE Interface is not supported!\n",
1148 generic->header.source_id);
1149 goto err;
1150 }
1151 break;
1067 case ACPI_HEST_NOTIFY_LOCAL:1152 case ACPI_HEST_NOTIFY_LOCAL:
1068 pr_warning(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n",1153 pr_warning(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n",
1069 generic->header.source_id);1154 generic->header.source_id);
@@ -1127,6 +1212,11 @@ static int ghes_probe(struct platform_device *ghes_dev) · 57 unmodified lines
1127 case ACPI_HEST_NOTIFY_NMI:1212 case ACPI_HEST_NOTIFY_NMI:
1128 ghes_nmi_add(ghes);1213 ghes_nmi_add(ghes);
1129 break;1214 break;
1215 case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1216 rc = apei_sdei_register_ghes(ghes);
1217 if (rc)
1218 goto err;
1219 break;
1130 default:1220 default:
1131 BUG();1221 BUG();
1132 }1222 }
@@ -1136,7 +1226,9 @@ static int ghes_probe(struct platform_device *ghes_dev) · 3 unmodified lines
1136 ghes_edac_register(ghes, &ghes_dev->dev);1226 ghes_edac_register(ghes, &ghes_dev->dev);
1137 1227
1138 /* Handle any pending errors right away */1228 /* Handle any pending errors right away */
1229 spin_lock_irqsave(&ghes_notify_lock_irq, flags);
1139 ghes_proc(ghes);1230 ghes_proc(ghes);
1231 spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
1140 1232
1141 return 0;1233 return 0;
1142 1234
@@ -1150,6 +1242,7 @@ err: · 7 unmodified lines
1150 1242
1151static int ghes_remove(struct platform_device *ghes_dev)1243static int ghes_remove(struct platform_device *ghes_dev)
1152{1244{
1245 int rc;
1153 struct ghes *ghes;1246 struct ghes *ghes;
1154 struct acpi_hest_generic *generic;1247 struct acpi_hest_generic *generic;
1155 1248
@@ -1182,6 +1275,11 @@ static int ghes_remove(struct platform_device *ghes_dev) · 26 unmodified lines
1182 case ACPI_HEST_NOTIFY_NMI:1275 case ACPI_HEST_NOTIFY_NMI:
1183 ghes_nmi_remove(ghes);1276 ghes_nmi_remove(ghes);
1184 break;1277 break;
1278 case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1279 rc = apei_sdei_unregister_ghes(ghes);
1280 if (rc)
1281 return rc;
1282 break;
1185 default:1283 default:
1186 BUG();1284 BUG();
1187 break;1285 break;
@@ -1230,18 +1328,9 @@ static int __init ghes_init(void) · 42 unmodified lines
1230 1328
1231 ghes_nmi_init_cxt();1329 ghes_nmi_init_cxt();
1232 1330
1233 rc = ghes_estatus_pool_init();
1234 if (rc)
1235 goto err;
1236
1237 rc = ghes_estatus_pool_expand(GHES_ESTATUS_CACHE_AVG_SIZE *
1238 GHES_ESTATUS_CACHE_ALLOCED_MAX);
1239 if (rc)
1240 goto err_pool_exit;
1241
1242 rc = platform_driver_register(&ghes_platform_driver);1331 rc = platform_driver_register(&ghes_platform_driver);
1243 if (rc)1332 if (rc)
1244 goto err_pool_exit;1333 goto err;
1245 1334
1246 rc = apei_osc_setup();1335 rc = apei_osc_setup();
1247 if (rc == 0 && osc_sb_apei_support_acked)1336 if (rc == 0 && osc_sb_apei_support_acked)
@@ -1254,8 +1343,6 @@ static int __init ghes_init(void) · 6 unmodified lines
1254 pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");1343 pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");
1255 1344
1256 return 0;1345 return 0;
1257err_pool_exit:
1258 ghes_estatus_pool_exit();
1259err:1346err:
1260 return rc;1347 return rc;
1261}1348}
drivers/acpi/apei/hest.c+15−1
@@ -32,6 +32,7 @@ · 31 unmodified lines
32#include <linux/io.h>32#include <linux/io.h>
33#include <linux/platform_device.h>33#include <linux/platform_device.h>
34#include <acpi/apei.h>34#include <acpi/apei.h>
35#include <acpi/ghes.h>
35 36
36#include "apei-internal.h"37#include "apei-internal.h"
37 38
@@ -53,6 +54,7 @@ static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { · 15 unmodified lines
53 [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),54 [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
54 [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),55 [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
55 [ACPI_HEST_TYPE_GENERIC_ERROR_V2] = sizeof(struct acpi_hest_generic_v2),56 [ACPI_HEST_TYPE_GENERIC_ERROR_V2] = sizeof(struct acpi_hest_generic_v2),
57 [ACPI_HEST_TYPE_IA32_DEFERRED_CHECK] = -1,
56};58};
57 59
58static int hest_esrc_len(struct acpi_hest_header *hest_hdr)60static int hest_esrc_len(struct acpi_hest_header *hest_hdr)
@@ -75,6 +77,11 @@ static int hest_esrc_len(struct acpi_hest_header *hest_hdr) · 16 unmodified lines
75 mc = (struct acpi_hest_ia_machine_check *)hest_hdr;77 mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
76 len = sizeof(*mc) + mc->num_hardware_banks *78 len = sizeof(*mc) + mc->num_hardware_banks *
77 sizeof(struct acpi_hest_ia_error_bank);79 sizeof(struct acpi_hest_ia_error_bank);
80 } else if (hest_type == ACPI_HEST_TYPE_IA32_DEFERRED_CHECK) {
81 struct acpi_hest_ia_deferred_check *mc;
82 mc = (struct acpi_hest_ia_deferred_check *)hest_hdr;
83 len = sizeof(*mc) + mc->num_hardware_banks *
84 sizeof(struct acpi_hest_ia_error_bank);
78 }85 }
79 BUG_ON(len == -1);86 BUG_ON(len == -1);
80 87
@@ -203,6 +210,11 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count) · 122 unmodified lines
203 rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);210 rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
204 if (rc)211 if (rc)
205 goto err;212 goto err;
213
214 rc = ghes_estatus_pool_init(ghes_count);
215 if (rc)
216 goto err;
217
206out:218out:
207 kfree(ghes_arr.ghes_devs);219 kfree(ghes_arr.ghes_devs);
208 return rc;220 return rc;
@@ -251,7 +263,9 @@ void __init acpi_hest_init(void) · 42 unmodified lines
251 rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);263 rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
252 if (rc)264 if (rc)
253 goto err;265 goto err;
254 rc = hest_ghes_dev_register(ghes_count);266
267 if (ghes_count)
268 rc = hest_ghes_dev_register(ghes_count);
255 if (rc)269 if (rc)
256 goto err;270 goto err;
257 }271 }
drivers/firmware/arm_sdei.c+68−0
@@ -2,6 +2,7 @@ · 1 unmodified line
2// Copyright (C) 2017 Arm Ltd.2// Copyright (C) 2017 Arm Ltd.
3#define pr_fmt(fmt) "sdei: " fmt3#define pr_fmt(fmt) "sdei: " fmt
4 4
5#include <acpi/ghes.h>
5#include <linux/acpi.h>6#include <linux/acpi.h>
6#include <linux/arm_sdei.h>7#include <linux/arm_sdei.h>
7#include <linux/arm-smccc.h>8#include <linux/arm-smccc.h>
@@ -887,6 +888,73 @@ static void sdei_smccc_hvc(unsigned long function_id, · 879 unmodified lines
887 arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res);888 arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res);
888}889}
889 890
891int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb,
892 sdei_event_callback *critical_cb)
893{
894 int err;
895 u64 result;
896 u32 event_num;
897 sdei_event_callback *cb;
898
899 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
900 return -EOPNOTSUPP;
901
902 event_num = ghes->generic->notify.vector;
903 if (event_num == 0) {
904 /*
905 * Event 0 is reserved by the specification for
906 * SDEI_EVENT_SIGNAL.
907 */
908 return -EINVAL;
909 }
910
911 err = sdei_api_event_get_info(event_num, SDEI_EVENT_INFO_EV_PRIORITY,
912 &result);
913 if (err)
914 return err;
915
916 if (result == SDEI_EVENT_PRIORITY_CRITICAL)
917 cb = critical_cb;
918 else
919 cb = normal_cb;
920
921 err = sdei_event_register(event_num, cb, ghes);
922 if (!err)
923 err = sdei_event_enable(event_num);
924
925 return err;
926}
927
928int sdei_unregister_ghes(struct ghes *ghes)
929{
930 int i;
931 int err;
932 u32 event_num = ghes->generic->notify.vector;
933
934 might_sleep();
935
936 if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
937 return -EOPNOTSUPP;
938
939 /*
940 * The event may be running on another CPU. Disable it
941 * to stop new events, then try to unregister a few times.
942 */
943 err = sdei_event_disable(event_num);
944 if (err)
945 return err;
946
947 for (i = 0; i < 3; i++) {
948 err = sdei_event_unregister(event_num);
949 if (err != -EINPROGRESS)
950 break;
951
952 schedule();
953 }
954
955 return err;
956}
957
890static int sdei_get_conduit(struct platform_device *pdev)958static int sdei_get_conduit(struct platform_device *pdev)
891{959{
892 const char *method;960 const char *method;
drivers/firmware/efi/cper.c+9−4
@@ -546,19 +546,24 @@ EXPORT_SYMBOL_GPL(cper_estatus_check_header); · 545 unmodified lines
546int cper_estatus_check(const struct acpi_hest_generic_status *estatus)546int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
547{547{
548 struct acpi_hest_generic_data *gdata;548 struct acpi_hest_generic_data *gdata;
549 unsigned int data_len, gedata_len;549 unsigned int data_len, record_size;
550 int rc;550 int rc;
551 551
552 rc = cper_estatus_check_header(estatus);552 rc = cper_estatus_check_header(estatus);
553 if (rc)553 if (rc)
554 return rc;554 return rc;
555
555 data_len = estatus->data_length;556 data_len = estatus->data_length;
556 557
557 apei_estatus_for_each_section(estatus, gdata) {558 apei_estatus_for_each_section(estatus, gdata) {
558 gedata_len = acpi_hest_get_error_length(gdata);559 if (sizeof(struct acpi_hest_generic_data) > data_len)
559 if (gedata_len > data_len - acpi_hest_get_size(gdata))560 return -EINVAL;
561
562 record_size = acpi_hest_get_record_size(gdata);
563 if (record_size > data_len)
560 return -EINVAL;564 return -EINVAL;
561 data_len -= acpi_hest_get_record_size(gdata);565
566 data_len -= record_size;
562 }567 }
563 if (data_len)568 if (data_len)
564 return -EINVAL;569 return -EINVAL;
include/acpi/ghes.h+2−2
@@ -13,7 +13,6 @@ · 12 unmodified lines
13 * estatus: memory buffer for error status block, allocated during13 * estatus: memory buffer for error status block, allocated during
14 * HEST parsing.14 * HEST parsing.
15 */15 */
16#define GHES_TO_CLEAR 0x0001
17#define GHES_EXITING 0x000216#define GHES_EXITING 0x0002
18 17
19struct ghes {18struct ghes {
@@ -22,7 +21,6 @@ struct ghes { · 2 unmodified lines
22 struct acpi_hest_generic_v2 *generic_v2;21 struct acpi_hest_generic_v2 *generic_v2;
23 };22 };
24 struct acpi_hest_generic_status *estatus;23 struct acpi_hest_generic_status *estatus;
25 u64 buffer_paddr;
26 unsigned long flags;24 unsigned long flags;
27 union {25 union {
28 struct list_head list;26 struct list_head list;
@@ -52,6 +50,8 @@ enum { · 23 unmodified lines
52 GHES_SEV_PANIC = 0x3,50 GHES_SEV_PANIC = 0x3,
53};51};
54 52
53int ghes_estatus_pool_init(int num_ghes);
54
55/* From drivers/edac/ghes_edac.c */55/* From drivers/edac/ghes_edac.c */
56 56
57#ifdef CONFIG_EDAC_GHES57#ifdef CONFIG_EDAC_GHES
include/linux/arm_sdei.h+9−0
@@ -11,7 +11,11 @@ enum sdei_conduit_types { · 10 unmodified lines
11 CONDUIT_HVC,11 CONDUIT_HVC,
12};12};
13 13
14#include <acpi/ghes.h>
15
16#ifdef CONFIG_ARM_SDE_INTERFACE
14#include <asm/sdei.h>17#include <asm/sdei.h>
18#endif
15 19
16/* Arch code should override this to set the entry point from firmware... */20/* Arch code should override this to set the entry point from firmware... */
17#ifndef sdei_arch_get_entry_point21#ifndef sdei_arch_get_entry_point
@@ -39,6 +43,11 @@ int sdei_event_unregister(u32 event_num); · 21 unmodified lines
39int sdei_event_enable(u32 event_num);43int sdei_event_enable(u32 event_num);
40int sdei_event_disable(u32 event_num);44int sdei_event_disable(u32 event_num);
41 45
46/* GHES register/unregister helpers */
47int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb,
48 sdei_event_callback *critical_cb);
49int sdei_unregister_ghes(struct ghes *ghes);
50
42#ifdef CONFIG_ARM_SDE_INTERFACE51#ifdef CONFIG_ARM_SDE_INTERFACE
43/* For use by arch code when CPU hotplug notifiers are not appropriate. */52/* For use by arch code when CPU hotplug notifiers are not appropriate. */
44int sdei_mask_local_cpu(void);53int sdei_mask_local_cpu(void);
virt/kvm/arm/mmu.c+2−2
@@ -27,10 +27,10 @@ · 26 unmodified lines
27#include <asm/kvm_arm.h>27#include <asm/kvm_arm.h>
28#include <asm/kvm_mmu.h>28#include <asm/kvm_mmu.h>
29#include <asm/kvm_mmio.h>29#include <asm/kvm_mmio.h>
30#include <asm/kvm_ras.h>
30#include <asm/kvm_asm.h>31#include <asm/kvm_asm.h>
31#include <asm/kvm_emulate.h>32#include <asm/kvm_emulate.h>
32#include <asm/virt.h>33#include <asm/virt.h>
33#include <asm/system_misc.h>
34 34
35#include "trace.h"35#include "trace.h"
36 36
@@ -1906,7 +1906,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) · 1869 unmodified lines
1906 * For RAS the host kernel may handle this abort.1906 * For RAS the host kernel may handle this abort.
1907 * There is no need to pass the error into the guest.1907 * There is no need to pass the error into the guest.
1908 */1908 */
1909 if (!handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu)))1909 if (!kvm_handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu)))
1910 return 1;1910 return 1;
1911 1911
1912 if (unlikely(!is_iabt)) {1912 if (unlikely(!is_iabt)) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t