From 8d7823f394f8e40bd44e31f86879f8b8ada259de Mon Sep 17 00:00:00 2001 From: Weilin Tong Date: Fri, 4 Sep 2026 14:49:27 +0800 Subject: [PATCH] anolis: arm64: fix linear map invalidation in memory_failure_cb ANBZ: #8540 memory_failure_cb() currently returns immediately when memory_failure() successfully isolates the corrupted page. As a result, set_memory_np() is only reached when recovery fails, which is the reverse of the intended behavior. Move the arm64 linear-map invalidation into the successful recovery path and only operate on a PFN backed by online memory. Fixes: b517a90bf817 ("anolis: arm64: avoid speculative access after memory failure") Signed-off-by: Weilin Tong --- drivers/acpi/apei/ghes.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index eadc37c30bb3..9841df05b126 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -480,21 +481,19 @@ static void memory_failure_cb(struct callback_head *twork) unsigned long pfn = twcb->pfn; rc = memory_failure(pfn, twcb->flags); +#ifdef CONFIG_ARM64 + /* + * Remove a successfully recovered online page from the arm64 + * linear map to prevent speculative access to corrupted memory. + */ + if (!rc && pfn_to_online_page(pfn)) + set_memory_np((unsigned long)page_to_virt(pfn_to_page(pfn)), 1); +#endif kfree(twcb); if (!rc) return; - /* - * If the pfn reported by ghes can not be recovered, set - * the corresponding page table of linear mapping range - * to be non-present, which avoids the speculative - * access of corrupted memory. - */ -#ifdef CONFIG_ARM64 - set_memory_np((unsigned long)page_to_virt(pfn_to_page(pfn)), 1); -#endif - /* * -EHWPOISON from memory_failure() means that it already sent SIGBUS * to the current process with the proper error info, so no need to -- Gitee