Skip to content

Commit 8fcc4ae

Browse files
James Morserafaeljw
authored andcommitted
arm64: acpi: Make apei_claim_sea() synchronise with APEI's irq work
APEI is unable to do all of its error handling work in nmi-context, so it defers non-fatal work onto the irq_work queue. arch_irq_work_raise() sends an IPI to the calling cpu, but this is not guaranteed to be taken before returning to user-space. Unless the exception interrupted a context with irqs-masked, irq_work_run() can run immediately. Otherwise return -EINPROGRESS to indicate ghes_notify_sea() found some work to do, but it hasn't finished yet. With this apei_claim_sea() returning '0' means this external-abort was also notification of a firmware-first RAS error, and that APEI has processed the CPER records. Signed-off-by: James Morse <[email protected]> Tested-by: Tyler Baicar <[email protected]> Acked-by: Catalin Marinas <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 7f17b4a commit 8fcc4ae

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

arch/arm64/kernel/acpi.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/init.h>
2020
#include <linux/irq.h>
2121
#include <linux/irqdomain.h>
22+
#include <linux/irq_work.h>
2223
#include <linux/memblock.h>
2324
#include <linux/of_fdt.h>
2425
#include <linux/smp.h>
@@ -269,13 +270,20 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr)
269270
int apei_claim_sea(struct pt_regs *regs)
270271
{
271272
int err = -ENOENT;
273+
bool return_to_irqs_enabled;
272274
unsigned long current_flags;
273275

274276
if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES))
275277
return err;
276278

277279
current_flags = local_daif_save_flags();
278280

281+
/* current_flags isn't useful here as daif doesn't tell us about pNMI */
282+
return_to_irqs_enabled = !irqs_disabled_flags(arch_local_save_flags());
283+
284+
if (regs)
285+
return_to_irqs_enabled = interrupts_enabled(regs);
286+
279287
/*
280288
* SEA can interrupt SError, mask it and describe this as an NMI so
281289
* that APEI defers the handling.
@@ -284,6 +292,23 @@ int apei_claim_sea(struct pt_regs *regs)
284292
nmi_enter();
285293
err = ghes_notify_sea();
286294
nmi_exit();
295+
296+
/*
297+
* APEI NMI-like notifications are deferred to irq_work. Unless
298+
* we interrupted irqs-masked code, we can do that now.
299+
*/
300+
if (!err) {
301+
if (return_to_irqs_enabled) {
302+
local_daif_restore(DAIF_PROCCTX_NOIRQ);
303+
__irq_enter();
304+
irq_work_run();
305+
__irq_exit();
306+
} else {
307+
pr_warn_ratelimited("APEI work queued but not completed");
308+
err = -EINPROGRESS;
309+
}
310+
}
311+
287312
local_daif_restore(current_flags);
288313

289314
return err;

arch/arm64/mm/fault.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,13 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs)
635635

636636
inf = esr_to_fault_info(esr);
637637

638-
/*
639-
* Return value ignored as we rely on signal merging.
640-
* Future patches will make this more robust.
641-
*/
642-
apei_claim_sea(regs);
638+
if (user_mode(regs) && apei_claim_sea(regs) == 0) {
639+
/*
640+
* APEI claimed this as a firmware-first notification.
641+
* Some processing deferred to task_work before ret_to_user().
642+
*/
643+
return 0;
644+
}
643645

644646
if (esr & ESR_ELx_FnV)
645647
siaddr = NULL;

0 commit comments

Comments
 (0)