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
331331 M: "Rafael J. Wysocki" <rjw@rjwysocki.net>
332332 M: Len Brown <lenb@kernel.org>
333333 L: linux-acpi@vger.kernel.org
334+R: James Morse <james.morse@arm.com>
334335 R: Tony Luck <tony.luck@intel.com>
335336 R: Borislav Petkov <bp@alien8.de>
336337 F: 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+
9+static 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
3838
3939 extern unsigned int user_debug;
4040
41−static inline int handle_guest_sea(phys_addr_t addr, unsigned int esr)
42−{
43− return -1;
44−}
45−
4641 #endif /* !__ASSEMBLY__ */
4742
4843 #endif /* __ASM_ARM_SYSTEM_MISC_H */
arch/arm64/include/asm/acpi.h+3−1
@@ -18,6 +18,7 @@ · 17 unmodified lines
1818
1919 #include <asm/cputype.h>
2020 #include <asm/io.h>
21+#include <asm/ptrace.h>
2122 #include <asm/smp_plat.h>
2223 #include <asm/tlbflush.h>
2324
@@ -110,9 +111,10 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu) · 86 unmodified lines
110111
111112 static inline void arch_fix_phys_package_id(int num, u32 slot) { }
112113 void __init acpi_init_cpus(void);
113−
114+int apei_claim_sea(struct pt_regs *regs);
114115 #else
115116 static inline void acpi_init_cpus(void) { }
117+static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; }
116118 #endif /* CONFIG_ACPI */
117119
118120 #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
arch/arm64/include/asm/daifflags.h+1−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020
2121 #define DAIF_PROCCTX 0
2222 #define DAIF_PROCCTX_NOIRQ PSR_I_BIT
23+#define DAIF_ERRCTX (PSR_I_BIT | PSR_A_BIT)
2324
2425 /* mask/save/unmask/restore all exceptions, including interrupts. */
2526 static inline void local_daif_mask(void)
arch/arm64/include/asm/fixmap.h+5−1
@@ -55,7 +55,11 @@ enum fixed_addresses { · 54 unmodified lines
5555 #ifdef CONFIG_ACPI_APEI_GHES
5656 /* Used for GHES mapping from assorted contexts */
5757 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
5963 #endif /* CONFIG_ACPI_APEI_GHES */
6064
6165 #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+ */
17+static 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
4646
4747 extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
4848
49−int handle_guest_sea(phys_addr_t addr, unsigned int esr);
50−
5149 #endif /* __ASSEMBLY__ */
5250
5351 #endif /* __ASM_SYSTEM_MISC_H */
arch/arm64/kernel/acpi.c+31−0
@@ -27,8 +27,10 @@ · 26 unmodified lines
2727 #include <linux/smp.h>
2828 #include <linux/serial_core.h>
2929
30+#include <acpi/ghes.h>
3031 #include <asm/cputype.h>
3132 #include <asm/cpu_ops.h>
33+#include <asm/daifflags.h>
3234 #include <asm/pgtable.h>
3335 #include <asm/smp_plat.h>
3436
@@ -256,3 +258,32 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) · 221 unmodified lines
256258 return __pgprot(PROT_NORMAL_NC);
257259 return __pgprot(PROT_DEVICE_nGnRnE);
258260 }
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+ */
268+int 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
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1919 */
2020
21+#include <linux/acpi.h>
2122 #include <linux/extable.h>
2223 #include <linux/signal.h>
2324 #include <linux/mm.h>
@@ -33,6 +34,7 @@ · 9 unmodified lines
3334 #include <linux/preempt.h>
3435 #include <linux/hugetlb.h>
3536
37+#include <asm/acpi.h>
3638 #include <asm/bug.h>
3739 #include <asm/cmpxchg.h>
3840 #include <asm/cpufeature.h>
@@ -47,8 +49,6 @@ · 8 unmodified lines
4749 #include <asm/tlbflush.h>
4850 #include <asm/traps.h>
4951
50−#include <acpi/ghes.h>
51−
5252 struct fault_info {
5353 int (*fn)(unsigned long addr, unsigned int esr,
5454 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
643643 inf = esr_to_fault_info(esr);
644644
645645 /*
646− * Synchronous aborts may interrupt code which had interrupts masked.
647− * Before calling out into the wider kernel tell the interested
648− * subsystems.
646+ * Return value ignored as we rely on signal merging.
647+ * Future patches will make this more robust.
649648 */
650− if (IS_ENABLED(CONFIG_ACPI_APEI_SEA)) {
651− if (interrupts_enabled(regs))
652− nmi_enter();
653−
654− ghes_notify_sea();
655−
656− if (interrupts_enabled(regs))
657− nmi_exit();
658− }
649+ apei_claim_sea(regs);
659650
660651 if (esr & ESR_ELx_FnV)
661652 siaddr = NULL;
@@ -733,11 +724,6 @@ static const struct fault_info fault_info[] = { · 71 unmodified lines
733724 { do_bad, SIGKILL, SI_KERNEL, "unknown 63" },
734725 };
735726
736−int handle_guest_sea(phys_addr_t addr, unsigned int esr)
737−{
738− return ghes_notify_sea();
739−}
740−
741727 asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr,
742728 struct pt_regs *regs)
743729 {
drivers/acpi/apei/Kconfig+1−11
@@ -41,19 +41,9 @@ config ACPI_APEI_PCIEAER · 40 unmodified lines
4141 Turn on this option to enable the corresponding support.
4242
4343 config ACPI_APEI_SEA
44− bool "APEI Synchronous External Abort logging/recovering support"
44+ bool
4545 depends on ARM64 && ACPI_APEI_GHES
4646 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.
5747
5848 config ACPI_APEI_MEMORY_FAILURE
5949 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
4242 int remain = region_len;
4343 u32 estatus_len;
4444
45− if (!estatus->block_status)
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−
45+ while (remain >= sizeof(struct acpi_bert_region)) {
5446 estatus_len = cper_estatus_len(estatus);
5547 if (remain < estatus_len) {
5648 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
5850 return;
5951 }
6052
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+
6162 pr_info_once("Error records from previous boot:\n");
6263
6364 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
7071 estatus->block_status = 0;
7172
7273 estatus = (void *)estatus + estatus_len;
73− /* No more error records. */
74− if (!estatus->block_status)
75− return;
76−
7774 remain -= estatus_len;
7875 }
7976 }
drivers/acpi/apei/einj.c+7−8
@@ -644,8 +644,8 @@ static int error_type_set(void *data, u64 val) · 643 unmodified lines
644644 return 0;
645645 }
646646
647−DEFINE_SIMPLE_ATTRIBUTE(error_type_fops, error_type_get,
648− error_type_set, "0x%llx\n");
647+DEFINE_DEBUGFS_ATTRIBUTE(error_type_fops, error_type_get, error_type_set,
648+ "0x%llx\n");
649649
650650 static int error_inject_set(void *data, u64 val)
651651 {
@@ -656,8 +656,7 @@ static int error_inject_set(void *data, u64 val) · 4 unmodified lines
656656 error_param3, error_param4);
657657 }
658658
659−DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,
660− error_inject_set, "%llu\n");
659+DEFINE_DEBUGFS_ATTRIBUTE(error_inject_fops, NULL, error_inject_set, "%llu\n");
661660
662661 static int einj_check_table(struct acpi_table_einj *einj_tab)
663662 {
@@ -709,10 +708,10 @@ static int __init einj_init(void) · 45 unmodified lines
709708
710709 debugfs_create_file("available_error_type", S_IRUSR, einj_debug_dir,
711710 NULL, &available_error_type_fops);
712− debugfs_create_file("error_type", S_IRUSR | S_IWUSR, einj_debug_dir,
713− NULL, &error_type_fops);
714− debugfs_create_file("error_inject", S_IWUSR, einj_debug_dir,
715− NULL, &error_inject_fops);
711+ debugfs_create_file_unsafe("error_type", 0600, einj_debug_dir,
712+ NULL, &error_type_fops);
713+ debugfs_create_file_unsafe("error_inject", 0200, einj_debug_dir,
714+ NULL, &error_inject_fops);
716715
717716 apei_resources_init(&einj_resources);
718717 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
938938 };
939939
940940 #define CPER_CREATOR_PSTORE \
941− UUID_LE(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \
942− 0x64, 0x90, 0xb8, 0x9d)
941+ GUID_INIT(0x75a574e3, 0x5052, 0x4b29, 0x8a, 0x8e, 0xbe, 0x2c, \
942+ 0x64, 0x90, 0xb8, 0x9d)
943943 #define CPER_SECTION_TYPE_DMESG \
944− UUID_LE(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \
945− 0x94, 0x19, 0xeb, 0x12)
944+ GUID_INIT(0xc197e04e, 0xd545, 0x4a70, 0x9c, 0x17, 0xa5, 0x54, \
945+ 0x94, 0x19, 0xeb, 0x12)
946946 #define CPER_SECTION_TYPE_DMESG_Z \
947− UUID_LE(0x4f118707, 0x04dd, 0x4055, 0xb5, 0xdd, 0x95, 0x6d, \
948− 0x34, 0xdd, 0xfa, 0xc6)
947+ GUID_INIT(0x4f118707, 0x04dd, 0x4055, 0xb5, 0xdd, 0x95, 0x6d, \
948+ 0x34, 0xdd, 0xfa, 0xc6)
949949 #define CPER_SECTION_TYPE_MCE \
950− UUID_LE(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \
951− 0x04, 0x4a, 0x38, 0xfc)
950+ GUID_INIT(0xfe08ffbe, 0x95e4, 0x4be7, 0xbc, 0x73, 0x40, 0x96, \
951+ 0x04, 0x4a, 0x38, 0xfc)
952952
953953 struct cper_pstore_record {
954954 struct cper_record_header hdr;
@@ -1012,7 +1012,7 @@ skip: · 57 unmodified lines
10121012 rc = -EIO;
10131013 goto out;
10141014 }
1015− if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0)
1015+ if (!guid_equal(&rcd->hdr.creator_id, &CPER_CREATOR_PSTORE))
10161016 goto skip;
10171017
10181018 record->buf = kmalloc(len, GFP_KERNEL);
@@ -1024,15 +1024,12 @@ skip: · 5 unmodified lines
10241024 record->id = record_id;
10251025 record->compressed = false;
10261026 record->ecc_notice_size = 0;
1027− if (uuid_le_cmp(rcd->sec_hdr.section_type,
1028− CPER_SECTION_TYPE_DMESG_Z) == 0) {
1027+ if (guid_equal(&rcd->sec_hdr.section_type, &CPER_SECTION_TYPE_DMESG_Z)) {
10291028 record->type = PSTORE_TYPE_DMESG;
10301029 record->compressed = true;
1031− } else if (uuid_le_cmp(rcd->sec_hdr.section_type,
1032− CPER_SECTION_TYPE_DMESG) == 0)
1030+ } else if (guid_equal(&rcd->sec_hdr.section_type, &CPER_SECTION_TYPE_DMESG))
10331031 record->type = PSTORE_TYPE_DMESG;
1034− else if (uuid_le_cmp(rcd->sec_hdr.section_type,
1035− CPER_SECTION_TYPE_MCE) == 0)
1032+ else if (guid_equal(&rcd->sec_hdr.section_type, &CPER_SECTION_TYPE_MCE))
10361033 record->type = PSTORE_TYPE_MCE;
10371034 else
10381035 record->type = PSTORE_TYPE_MAX;
drivers/acpi/apei/ghes.c+371−284
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 * GNU General Public License for more details.
2626 */
2727
28+#include <linux/arm_sdei.h>
2829 #include <linux/kernel.h>
2930 #include <linux/moduleparam.h>
3031 #include <linux/init.h>
@@ -33,7 +34,6 @@ · 2 unmodified lines
3334 #include <linux/interrupt.h>
3435 #include <linux/timer.h>
3536 #include <linux/cper.h>
36−#include <linux/kdebug.h>
3737 #include <linux/platform_device.h>
3838 #include <linux/mutex.h>
3939 #include <linux/ratelimit.h>
@@ -42,6 +42,7 @@ · 2 unmodified lines
4242 #include <linux/llist.h>
4343 #include <linux/genalloc.h>
4444 #include <linux/pci.h>
45+#include <linux/pfn.h>
4546 #include <linux/aer.h>
4647 #include <linux/nmi.h>
4748 #include <linux/sched/clock.h>
@@ -85,6 +86,15 @@ · 37 unmodified lines
8586 ((struct acpi_hest_generic_status *) \
8687 ((struct ghes_estatus_node *)(estatus_node) + 1))
8788
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+
8898 static inline bool is_hest_type_generic_v2(struct ghes *ghes)
8999 {
90100 return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2;
@@ -115,11 +125,10 @@ static DEFINE_MUTEX(ghes_list_mutex); · 24 unmodified lines
115125 * handler, but general ioremap can not be used in atomic context, so
116126 * the fixmap is used instead.
117127 *
118− * These 2 spinlocks are used to prevent the fixmap entries from being used
128+ * This spinlock is used to prevent the fixmap entry from being used
119129 * simultaneously.
120130 */
121−static DEFINE_RAW_SPINLOCK(ghes_ioremap_lock_nmi);
122−static DEFINE_SPINLOCK(ghes_ioremap_lock_irq);
131+static DEFINE_SPINLOCK(ghes_notify_lock_irq);
123132
124133 static struct gen_pool *ghes_estatus_pool;
125134 static unsigned long ghes_estatus_pool_size_request;
@@ -129,82 +138,49 @@ static atomic_t ghes_estatus_cache_alloced; · 3 unmodified lines
129138
130139 static int ghes_panic_timeout __read_mostly = 30;
131140
132−static void __iomem *ghes_ioremap_pfn_nmi(u64 pfn)
141+static void __iomem *ghes_map(u64 pfn, enum fixed_addresses fixmap_idx)
133142 {
134143 phys_addr_t paddr;
135144 pgprot_t prot;
136145
137− paddr = pfn << PAGE_SHIFT;
146+ paddr = PFN_PHYS(pfn);
138147 prot = arch_apei_get_mem_attribute(paddr);
139− __set_fixmap(FIX_APEI_GHES_NMI, paddr, prot);
148+ __set_fixmap(fixmap_idx, paddr, prot);
140149
141− return (void __iomem *) fix_to_virt(FIX_APEI_GHES_NMI);
150+ return (void __iomem *) __fix_to_virt(fixmap_idx);
142151 }
143152
144−static void __iomem *ghes_ioremap_pfn_irq(u64 pfn)
153+static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx)
145154 {
146− phys_addr_t paddr;
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+ int _idx = virt_to_fix((unsigned long)vaddr);
155156
156−static void ghes_iounmap_nmi(void)
157−{
158− clear_fixmap(FIX_APEI_GHES_NMI);
157+ WARN_ON_ONCE(fixmap_idx != _idx);
158+ clear_fixmap(fixmap_idx);
159159 }
160160
161−static void ghes_iounmap_irq(void)
161+int ghes_estatus_pool_init(int num_ghes)
162162 {
163− clear_fixmap(FIX_APEI_GHES_IRQ);
164−}
163+ unsigned long addr, len;
165164
166−static int ghes_estatus_pool_init(void)
167−{
168165 ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1);
169166 if (!ghes_estatus_pool)
170167 return -ENOMEM;
171− return 0;
172−}
173168
174−static void ghes_estatus_pool_free_chunk_page(struct gen_pool *pool,
175− struct gen_pool_chunk *chunk,
176− void *data)
177−{
178− free_page(chunk->start_addr);
179−}
180−
181−static 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−}
169+ len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX;
170+ len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE);
187171
188−static int ghes_estatus_pool_expand(unsigned long len)
189−{
190− unsigned long i, pages, size, addr;
191− int ret;
172+ ghes_estatus_pool_size_request = PAGE_ALIGN(len);
173+ addr = (unsigned long)vmalloc(PAGE_ALIGN(len));
174+ if (!addr)
175+ return -ENOMEM;
192176
193− ghes_estatus_pool_size_request += PAGE_ALIGN(len);
194− size = gen_pool_size(ghes_estatus_pool);
195− if (size >= ghes_estatus_pool_size_request)
196− return 0;
197− pages = (ghes_estatus_pool_size_request - size) / PAGE_SIZE;
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− }
177+ /*
178+ * New allocation must be visible in all pgd before it can be found by
179+ * an NMI allocating from the pool.
180+ */
181+ vmalloc_sync_all();
206182
207− return 0;
183+ return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1);
208184 }
209185
210186 static int map_gen_v2(struct ghes *ghes)
@@ -217,6 +193,21 @@ static void unmap_gen_v2(struct ghes *ghes) · 6 unmodified lines
217193 apei_unmap_generic_address(&ghes->generic_v2->read_ack_register);
218194 }
219195
196+static 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+
220211 static struct ghes *ghes_new(struct acpi_hest_generic *generic)
221212 {
222213 struct ghes *ghes;
@@ -289,23 +280,16 @@ static inline int ghes_severity(int severity) · 66 unmodified lines
289280 }
290281
291282 static 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)
293285 {
294286 void __iomem *vaddr;
295− unsigned long flags = 0;
296− int in_nmi = in_nmi();
297287 u64 offset;
298288 u32 trunk;
299289
300290 while (len > 0) {
301291 offset = paddr - (paddr & PAGE_MASK);
302− if (in_nmi) {
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− }
292+ vaddr = ghes_map(PHYS_PFN(paddr), fixmap_idx);
309293 trunk = PAGE_SIZE - offset;
310294 trunk = min(trunk, len);
311295 if (from_phys)
@@ -315,72 +299,114 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, · 3 unmodified lines
315299 len -= trunk;
316300 paddr += trunk;
317301 buffer += trunk;
318− if (in_nmi) {
319− ghes_iounmap_nmi();
320− raw_spin_unlock(&ghes_ioremap_lock_nmi);
321− } else {
322− ghes_iounmap_irq();
323− spin_unlock_irqrestore(&ghes_ioremap_lock_irq, flags);
324− }
302+ ghes_unmap(vaddr, fixmap_idx);
303+ }
304+}
305+
306+/* Check the top-level record header has an appropriate size. */
307+static int __ghes_check_estatus(struct ghes *ghes,
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;
325325 }
326+
327+ return 0;
326328 }
327329
328−static int ghes_read_estatus(struct ghes *ghes, int silent)
330+/* Read the CPER block, returning its address, and header in estatus. */
331+static int __ghes_peek_estatus(struct ghes *ghes,
332+ struct acpi_hest_generic_status *estatus,
333+ u64 *buf_paddr, enum fixed_addresses fixmap_idx)
329334 {
330335 struct acpi_hest_generic *g = ghes->generic;
331− u64 buf_paddr;
332− u32 len;
333336 int rc;
334337
335− rc = apei_read(&buf_paddr, &g->error_status_address);
338+ rc = apei_read(buf_paddr, &g->error_status_address);
336339 if (rc) {
337− if (!silent && printk_ratelimit())
338− pr_warning(FW_WARN GHES_PFX
340+ *buf_paddr = 0;
341+ pr_warn_ratelimited(FW_WARN GHES_PFX
339342 "Failed to read error status block address for hardware error source: %d.\n",
340343 g->header.source_id);
341344 return -EIO;
342345 }
343− if (!buf_paddr)
346+ if (!*buf_paddr)
344347 return -ENOENT;
345348
346− ghes_copy_tofrom_phys(ghes->estatus, buf_paddr,
347− sizeof(*ghes->estatus), 1);
348− if (!ghes->estatus->block_status)
349+ ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1,
350+ fixmap_idx);
351+ if (!estatus->block_status) {
352+ *buf_paddr = 0;
349353 return -ENOENT;
354+ }
350355
351− ghes->buffer_paddr = buf_paddr;
352− ghes->flags |= GHES_TO_CLEAR;
356+ return __ghes_check_estatus(ghes, estatus);
357+}
353358
354− rc = -EIO;
355− len = cper_estatus_len(ghes->estatus);
356− if (len < sizeof(*ghes->estatus))
357− goto err_read_block;
358− if (len > ghes->generic->error_block_length)
359− goto err_read_block;
360− if (cper_estatus_check_header(ghes->estatus))
361− goto err_read_block;
362− ghes_copy_tofrom_phys(ghes->estatus + 1,
363− buf_paddr + sizeof(*ghes->estatus),
364− len - sizeof(*ghes->estatus), 1);
365− if (cper_estatus_check(ghes->estatus))
366− goto err_read_block;
367− rc = 0;
368−
369−err_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;
359+static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus,
360+ u64 buf_paddr, enum fixed_addresses fixmap_idx,
361+ size_t buf_len)
362+{
363+ ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx);
364+ if (cper_estatus_check(estatus)) {
365+ pr_warn_ratelimited(FW_WARN GHES_PFX
366+ "Failed to read error status block!\n");
367+ return -EIO;
368+ }
369+
370+ return 0;
374371 }
375372
376−static void ghes_clear_estatus(struct ghes *ghes)
373+static int ghes_read_estatus(struct ghes *ghes,
374+ struct acpi_hest_generic_status *estatus,
375+ u64 *buf_paddr, enum fixed_addresses fixmap_idx)
377376 {
378− ghes->estatus->block_status = 0;
379− if (!(ghes->flags & GHES_TO_CLEAR))
377+ int rc;
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+
391+static 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)
380398 return;
381− ghes_copy_tofrom_phys(ghes->estatus, ghes->buffer_paddr,
382− sizeof(ghes->estatus->block_status), 0);
383− ghes->flags &= ~GHES_TO_CLEAR;
399+
400+ ghes_copy_tofrom_phys(estatus, buf_paddr,
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);
384410 }
385411
386412 static 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
672698 rcu_read_unlock();
673699 }
674700
675−static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2)
701+static void __ghes_panic(struct ghes *ghes,
702+ struct acpi_hest_generic_status *estatus,
703+ u64 buf_paddr, enum fixed_addresses fixmap_idx)
676704 {
677− int rc;
678− u64 val = 0;
705+ __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus);
679706
680− rc = apei_read(&val, &gv2->read_ack_register);
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−
690−static void __ghes_panic(struct ghes *ghes)
691−{
692− __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus);
693−
694− ghes_clear_estatus(ghes);
707+ ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
695708
696709 /* reboot to log the error! */
697710 if (!panic_timeout)
@@ -701,34 +714,25 @@ static void __ghes_panic(struct ghes *ghes) · 3 unmodified lines
701714
702715 static int ghes_proc(struct ghes *ghes)
703716 {
717+ struct acpi_hest_generic_status *estatus = ghes->estatus;
718+ u64 buf_paddr;
704719 int rc;
705720
706− rc = ghes_read_estatus(ghes, 0);
721+ rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ);
707722 if (rc)
708723 goto out;
709724
710− if (ghes_severity(ghes->estatus->error_severity) >= GHES_SEV_PANIC) {
711− __ghes_panic(ghes);
712− }
725+ if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC)
726+ __ghes_panic(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
713727
714− if (!ghes_estatus_cached(ghes->estatus)) {
715− if (ghes_print_estatus(NULL, ghes->generic, ghes->estatus))
716− ghes_estatus_cache_add(ghes->generic, ghes->estatus);
728+ if (!ghes_estatus_cached(estatus)) {
729+ if (ghes_print_estatus(NULL, ghes->generic, estatus))
730+ ghes_estatus_cache_add(ghes->generic, estatus);
717731 }
718− ghes_do_proc(ghes, ghes->estatus);
732+ ghes_do_proc(ghes, estatus);
719733
720734 out:
721− ghes_clear_estatus(ghes);
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);
735+ ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ);
732736
733737 return rc;
734738 }
@@ -751,8 +755,11 @@ static void ghes_add_timer(struct ghes *ghes) · 16 unmodified lines
751755 static void ghes_poll_func(struct timer_list *t)
752756 {
753757 struct ghes *ghes = from_timer(ghes, t, timer);
758+ unsigned long flags;
754759
760+ spin_lock_irqsave(&ghes_notify_lock_irq, flags);
755761 ghes_proc(ghes);
762+ spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
756763 if (!(ghes->flags & GHES_EXITING))
757764 ghes_add_timer(ghes);
758765 }
@@ -760,9 +767,12 @@ static void ghes_poll_func(struct timer_list *t) · 1 unmodified line
760767 static irqreturn_t ghes_irq_func(int irq, void *data)
761768 {
762769 struct ghes *ghes = data;
770+ unsigned long flags;
763771 int rc;
764772
773+ spin_lock_irqsave(&ghes_notify_lock_irq, flags);
765774 rc = ghes_proc(ghes);
775+ spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
766776 if (rc)
767777 return IRQ_NONE;
768778
@@ -773,14 +783,17 @@ static int ghes_notify_hed(struct notifier_block *this, unsigned long event, · 4 unmodified lines
773783 void *data)
774784 {
775785 struct ghes *ghes;
786+ unsigned long flags;
776787 int ret = NOTIFY_DONE;
777788
789+ spin_lock_irqsave(&ghes_notify_lock_irq, flags);
778790 rcu_read_lock();
779791 list_for_each_entry_rcu(ghes, &ghes_hed, list) {
780792 if (!ghes_proc(ghes))
781793 ret = NOTIFY_OK;
782794 }
783795 rcu_read_unlock();
796+ spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
784797
785798 return ret;
786799 }
@@ -789,66 +802,20 @@ static struct notifier_block ghes_notifier_hed = { · 2 unmodified lines
789802 .notifier_call = ghes_notify_hed,
790803 };
791804
792−#ifdef CONFIG_ACPI_APEI_SEA
793−static 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− */
799−int 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−
813−static 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−
820−static 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 */
828−static inline void ghes_sea_add(struct ghes *ghes) { }
829−static inline void ghes_sea_remove(struct ghes *ghes) { }
830−#endif /* CONFIG_ACPI_APEI_SEA */
831−
832−#ifdef CONFIG_HAVE_ACPI_APEI_NMI
833805 /*
834− * printk is not safe in NMI context. So in NMI handler, we allocate
835− * required memory from lock-less memory allocator
836− * (ghes_estatus_pool), save estatus into it, put them into lock-less
837− * list (ghes_estatus_llist), then delay printk into IRQ context via
838− * irq_work (ghes_proc_irq_work). ghes_estatus_size_request record
839− * required pool size by all NMI error source.
806+ * Handlers for CPER records may not be NMI safe. For example,
807+ * memory_failure_queue() takes spinlocks and calls schedule_work_on().
808+ * In any NMI-like handler, memory from ghes_estatus_pool is used to save
809+ * estatus, and added to the ghes_estatus_llist. irq_work_queue() causes
810+ * ghes_proc_in_irq() to run in IRQ context where each estatus in
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.
840815 */
841816 static struct llist_head ghes_estatus_llist;
842817 static struct irq_work ghes_proc_irq_work;
843818
844−/*
845− * NMI may be triggered on any CPU, so ghes_in_nmi is used for
846− * having only one concurrent reader.
847− */
848−static atomic_t ghes_in_nmi = ATOMIC_INIT(0);
849−
850−static LIST_HEAD(ghes_nmi);
851−
852819 static void ghes_proc_in_irq(struct irq_work *irq_work)
853820 {
854821 struct llist_node *llnode, *next;
@@ -905,96 +872,154 @@ static void ghes_print_queued_estatus(void) · 50 unmodified lines
905872 }
906873 }
907874
908−/* Save estatus for further processing in IRQ context */
909−static void __process_error(struct ghes *ghes)
875+static int ghes_in_nmi_queue_one_entry(struct ghes *ghes,
876+ enum fixed_addresses fixmap_idx)
910877 {
911−#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
912− u32 len, node_len;
878+ struct acpi_hest_generic_status *estatus, tmp_header;
913879 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;
915883
916− if (ghes_estatus_cached(ghes->estatus))
917− return;
884+ if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG))
885+ return -EOPNOTSUPP;
918886
919− len = cper_estatus_len(ghes->estatus);
920− node_len = GHES_ESTATUS_NODE_LEN(len);
887+ rc = __ghes_peek_estatus(ghes, &tmp_header, &buf_paddr, fixmap_idx);
888+ if (rc) {
889+ ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
890+ return rc;
891+ }
921892
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);
922901 estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len);
923902 if (!estatus_node)
924− return;
903+ return -ENOMEM;
925904
926905 estatus_node->ghes = ghes;
927906 estatus_node->generic = ghes->generic;
928907 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−}
933908
934−static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs)
935−{
936− struct ghes *ghes;
937− int sev, ret = NMI_DONE;
909+ if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) {
910+ ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx);
911+ rc = -ENOENT;
912+ goto no_work;
913+ }
938914
939− if (!atomic_add_unless(&ghes_in_nmi, 1, 1))
940− return ret;
915+ sev = ghes_severity(estatus->error_severity);
916+ if (sev >= GHES_SEV_PANIC) {
917+ ghes_print_queued_estatus();
918+ __ghes_panic(ghes, estatus, buf_paddr, fixmap_idx);
919+ }
941920
942− list_for_each_entry_rcu(ghes, &ghes_nmi, list) {
943− if (ghes_read_estatus(ghes, 1)) {
944− ghes_clear_estatus(ghes);
945− continue;
946− } else {
947− ret = NMI_HANDLED;
948− }
921+ ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx);
949922
950− sev = ghes_severity(ghes->estatus->error_severity);
951− if (sev >= GHES_SEV_PANIC) {
952− oops_begin();
953− ghes_print_queued_estatus();
954− __ghes_panic(ghes);
955− }
923+ /* This error has been reported before, don't process it again. */
924+ if (ghes_estatus_cached(estatus))
925+ goto no_work;
956926
957− if (!(ghes->flags & GHES_TO_CLEAR))
958− continue;
927+ llist_add(&estatus_node->llnode, &ghes_estatus_llist);
928+
929+ return rc;
930+
931+no_work:
932+ gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node,
933+ node_len);
934+
935+ return rc;
936+}
959937
960− __process_error(ghes);
961− ghes_clear_estatus(ghes);
938+static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list,
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;
962948 }
949+ rcu_read_unlock();
963950
964−#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG
965− if (ret == NMI_HANDLED)
951+ if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret)
966952 irq_work_queue(&ghes_proc_irq_work);
967−#endif
968− atomic_dec(&ghes_in_nmi);
953+
969954 return ret;
970955 }
971956
972−static unsigned long ghes_esource_prealloc_size(
973− const struct acpi_hest_generic *generic)
957+#ifdef CONFIG_ACPI_APEI_SEA
958+static 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+ */
964+int ghes_notify_sea(void)
974965 {
975− unsigned long block_length, prealloc_records, prealloc_size;
966+ static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea);
967+ int rv;
976968
977− block_length = min_t(unsigned long, generic->error_block_length,
978− GHES_ESTATUS_MAX_SIZE);
979− prealloc_records = max_t(unsigned long,
980− generic->records_to_preallocate, 1);
981− prealloc_size = min_t(unsigned long, block_length * prealloc_records,
982− GHES_ESOURCE_PREALLOC_MAX_SIZE);
969+ raw_spin_lock(&ghes_notify_lock_sea);
970+ rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA);
971+ raw_spin_unlock(&ghes_notify_lock_sea);
983972
984− return prealloc_size;
973+ return rv;
985974 }
986975
987−static void ghes_estatus_pool_shrink(unsigned long len)
976+static void ghes_sea_add(struct ghes *ghes)
988977 {
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);
990981 }
991982
992−static void ghes_nmi_add(struct ghes *ghes)
983+static void ghes_sea_remove(struct ghes *ghes)
993984 {
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 */
991+static inline void ghes_sea_add(struct ghes *ghes) { }
992+static 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+ */
1000+static atomic_t ghes_in_nmi = ATOMIC_INIT(0);
1001+
1002+static LIST_HEAD(ghes_nmi);
1003+
1004+static 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);
9951016
996− len = ghes_esource_prealloc_size(ghes->generic);
997− ghes_estatus_pool_expand(len);
1017+ atomic_dec(&ghes_in_nmi);
1018+ return ret;
1019+}
1020+
1021+static void ghes_nmi_add(struct ghes *ghes)
1022+{
9981023 mutex_lock(&ghes_list_mutex);
9991024 if (list_empty(&ghes_nmi))
10001025 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
10041029
10051030 static void ghes_nmi_remove(struct ghes *ghes)
10061031 {
1007− unsigned long len;
1008−
10091032 mutex_lock(&ghes_list_mutex);
10101033 list_del_rcu(&ghes->list);
10111034 if (list_empty(&ghes_nmi))
@@ -1016,24 +1039,79 @@ static void ghes_nmi_remove(struct ghes *ghes) · 4 unmodified lines
10161039 * freed after NMI handler finishes.
10171040 */
10181041 synchronize_rcu();
1019− len = ghes_esource_prealloc_size(ghes->generic);
1020− ghes_estatus_pool_shrink(len);
10211042 }
1043+#else /* CONFIG_HAVE_ACPI_APEI_NMI */
1044+static inline void ghes_nmi_add(struct ghes *ghes) { }
1045+static inline void ghes_nmi_remove(struct ghes *ghes) { }
1046+#endif /* CONFIG_HAVE_ACPI_APEI_NMI */
10221047
10231048 static void ghes_nmi_init_cxt(void)
10241049 {
10251050 init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq);
10261051 }
1027−#else /* CONFIG_HAVE_ACPI_APEI_NMI */
1028−static inline void ghes_nmi_add(struct ghes *ghes) { }
1029−static inline void ghes_nmi_remove(struct ghes *ghes) { }
1030−static inline void ghes_nmi_init_cxt(void) { }
1031−#endif /* CONFIG_HAVE_ACPI_APEI_NMI */
1052+
1053+static int __ghes_sdei_callback(struct ghes *ghes,
1054+ enum fixed_addresses fixmap_idx)
1055+{
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+
1065+static 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+
1079+static 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+
1093+static 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+
1102+static 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+}
10321109
10331110 static int ghes_probe(struct platform_device *ghes_dev)
10341111 {
10351112 struct acpi_hest_generic *generic;
10361113 struct ghes *ghes = NULL;
1114+ unsigned long flags;
10371115
10381116 int rc = -EINVAL;
10391117
@@ -1064,6 +1142,13 @@ static int ghes_probe(struct platform_device *ghes_dev) · 24 unmodified lines
10641142 goto err;
10651143 }
10661144 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;
10671152 case ACPI_HEST_NOTIFY_LOCAL:
10681153 pr_warning(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n",
10691154 generic->header.source_id);
@@ -1127,6 +1212,11 @@ static int ghes_probe(struct platform_device *ghes_dev) · 57 unmodified lines
11271212 case ACPI_HEST_NOTIFY_NMI:
11281213 ghes_nmi_add(ghes);
11291214 break;
1215+ case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1216+ rc = apei_sdei_register_ghes(ghes);
1217+ if (rc)
1218+ goto err;
1219+ break;
11301220 default:
11311221 BUG();
11321222 }
@@ -1136,7 +1226,9 @@ static int ghes_probe(struct platform_device *ghes_dev) · 3 unmodified lines
11361226 ghes_edac_register(ghes, &ghes_dev->dev);
11371227
11381228 /* Handle any pending errors right away */
1229+ spin_lock_irqsave(&ghes_notify_lock_irq, flags);
11391230 ghes_proc(ghes);
1231+ spin_unlock_irqrestore(&ghes_notify_lock_irq, flags);
11401232
11411233 return 0;
11421234
@@ -1150,6 +1242,7 @@ err: · 7 unmodified lines
11501242
11511243 static int ghes_remove(struct platform_device *ghes_dev)
11521244 {
1245+ int rc;
11531246 struct ghes *ghes;
11541247 struct acpi_hest_generic *generic;
11551248
@@ -1182,6 +1275,11 @@ static int ghes_remove(struct platform_device *ghes_dev) · 26 unmodified lines
11821275 case ACPI_HEST_NOTIFY_NMI:
11831276 ghes_nmi_remove(ghes);
11841277 break;
1278+ case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED:
1279+ rc = apei_sdei_unregister_ghes(ghes);
1280+ if (rc)
1281+ return rc;
1282+ break;
11851283 default:
11861284 BUG();
11871285 break;
@@ -1230,18 +1328,9 @@ static int __init ghes_init(void) · 42 unmodified lines
12301328
12311329 ghes_nmi_init_cxt();
12321330
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−
12421331 rc = platform_driver_register(&ghes_platform_driver);
12431332 if (rc)
1244− goto err_pool_exit;
1333+ goto err;
12451334
12461335 rc = apei_osc_setup();
12471336 if (rc == 0 && osc_sb_apei_support_acked)
@@ -1254,8 +1343,6 @@ static int __init ghes_init(void) · 6 unmodified lines
12541343 pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n");
12551344
12561345 return 0;
1257−err_pool_exit:
1258− ghes_estatus_pool_exit();
12591346 err:
12601347 return rc;
12611348 }
drivers/acpi/apei/hest.c+15−1
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 #include <linux/io.h>
3333 #include <linux/platform_device.h>
3434 #include <acpi/apei.h>
35+#include <acpi/ghes.h>
3536
3637 #include "apei-internal.h"
3738
@@ -53,6 +54,7 @@ static const int hest_esrc_len_tab[ACPI_HEST_TYPE_RESERVED] = { · 15 unmodified lines
5354 [ACPI_HEST_TYPE_AER_BRIDGE] = sizeof(struct acpi_hest_aer_bridge),
5455 [ACPI_HEST_TYPE_GENERIC_ERROR] = sizeof(struct acpi_hest_generic),
5556 [ACPI_HEST_TYPE_GENERIC_ERROR_V2] = sizeof(struct acpi_hest_generic_v2),
57+ [ACPI_HEST_TYPE_IA32_DEFERRED_CHECK] = -1,
5658 };
5759
5860 static 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
7577 mc = (struct acpi_hest_ia_machine_check *)hest_hdr;
7678 len = sizeof(*mc) + mc->num_hardware_banks *
7779 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);
7885 }
7986 BUG_ON(len == -1);
8087
@@ -203,6 +210,11 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count) · 122 unmodified lines
203210 rc = apei_hest_parse(hest_parse_ghes, &ghes_arr);
204211 if (rc)
205212 goto err;
213+
214+ rc = ghes_estatus_pool_init(ghes_count);
215+ if (rc)
216+ goto err;
217+
206218 out:
207219 kfree(ghes_arr.ghes_devs);
208220 return rc;
@@ -251,7 +263,9 @@ void __init acpi_hest_init(void) · 42 unmodified lines
251263 rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count);
252264 if (rc)
253265 goto err;
254− rc = hest_ghes_dev_register(ghes_count);
266+
267+ if (ghes_count)
268+ rc = hest_ghes_dev_register(ghes_count);
255269 if (rc)
256270 goto err;
257271 }
drivers/firmware/arm_sdei.c+68−0
@@ -2,6 +2,7 @@ · 1 unmodified line
22 // Copyright (C) 2017 Arm Ltd.
33 #define pr_fmt(fmt) "sdei: " fmt
44
5+#include <acpi/ghes.h>
56 #include <linux/acpi.h>
67 #include <linux/arm_sdei.h>
78 #include <linux/arm-smccc.h>
@@ -887,6 +888,73 @@ static void sdei_smccc_hvc(unsigned long function_id, · 879 unmodified lines
887888 arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res);
888889 }
889890
891+int 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+
928+int 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+
890958 static int sdei_get_conduit(struct platform_device *pdev)
891959 {
892960 const char *method;
drivers/firmware/efi/cper.c+9−4
@@ -546,19 +546,24 @@ EXPORT_SYMBOL_GPL(cper_estatus_check_header); · 545 unmodified lines
546546 int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
547547 {
548548 struct acpi_hest_generic_data *gdata;
549− unsigned int data_len, gedata_len;
549+ unsigned int data_len, record_size;
550550 int rc;
551551
552552 rc = cper_estatus_check_header(estatus);
553553 if (rc)
554554 return rc;
555+
555556 data_len = estatus->data_length;
556557
557558 apei_estatus_for_each_section(estatus, gdata) {
558− gedata_len = acpi_hest_get_error_length(gdata);
559− if (gedata_len > data_len - acpi_hest_get_size(gdata))
559+ if (sizeof(struct acpi_hest_generic_data) > data_len)
560+ return -EINVAL;
561+
562+ record_size = acpi_hest_get_record_size(gdata);
563+ if (record_size > data_len)
560564 return -EINVAL;
561− data_len -= acpi_hest_get_record_size(gdata);
565+
566+ data_len -= record_size;
562567 }
563568 if (data_len)
564569 return -EINVAL;
include/acpi/ghes.h+2−2
@@ -13,7 +13,6 @@ · 12 unmodified lines
1313 * estatus: memory buffer for error status block, allocated during
1414 * HEST parsing.
1515 */
16−#define GHES_TO_CLEAR 0x0001
1716 #define GHES_EXITING 0x0002
1817
1918 struct ghes {
@@ -22,7 +21,6 @@ struct ghes { · 2 unmodified lines
2221 struct acpi_hest_generic_v2 *generic_v2;
2322 };
2423 struct acpi_hest_generic_status *estatus;
25− u64 buffer_paddr;
2624 unsigned long flags;
2725 union {
2826 struct list_head list;
@@ -52,6 +50,8 @@ enum { · 23 unmodified lines
5250 GHES_SEV_PANIC = 0x3,
5351 };
5452
53+int ghes_estatus_pool_init(int num_ghes);
54+
5555 /* From drivers/edac/ghes_edac.c */
5656
5757 #ifdef CONFIG_EDAC_GHES
include/linux/arm_sdei.h+9−0
@@ -11,7 +11,11 @@ enum sdei_conduit_types { · 10 unmodified lines
1111 CONDUIT_HVC,
1212 };
1313
14+#include <acpi/ghes.h>
15+
16+#ifdef CONFIG_ARM_SDE_INTERFACE
1417 #include <asm/sdei.h>
18+#endif
1519
1620 /* Arch code should override this to set the entry point from firmware... */
1721 #ifndef sdei_arch_get_entry_point
@@ -39,6 +43,11 @@ int sdei_event_unregister(u32 event_num); · 21 unmodified lines
3943 int sdei_event_enable(u32 event_num);
4044 int sdei_event_disable(u32 event_num);
4145
46+/* GHES register/unregister helpers */
47+int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb,
48+ sdei_event_callback *critical_cb);
49+int sdei_unregister_ghes(struct ghes *ghes);
50+
4251 #ifdef CONFIG_ARM_SDE_INTERFACE
4352 /* For use by arch code when CPU hotplug notifiers are not appropriate. */
4453 int sdei_mask_local_cpu(void);
virt/kvm/arm/mmu.c+2−2
@@ -27,10 +27,10 @@ · 26 unmodified lines
2727 #include <asm/kvm_arm.h>
2828 #include <asm/kvm_mmu.h>
2929 #include <asm/kvm_mmio.h>
30+#include <asm/kvm_ras.h>
3031 #include <asm/kvm_asm.h>
3132 #include <asm/kvm_emulate.h>
3233 #include <asm/virt.h>
33−#include <asm/system_misc.h>
3434
3535 #include "trace.h"
3636
@@ -1906,7 +1906,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) · 1869 unmodified lines
19061906 * For RAS the host kernel may handle this abort.
19071907 * There is no need to pass the error into the guest.
19081908 */
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)))
19101910 return 1;
19111911
19121912 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