Skip to content

Commit 7d444f5

Browse files
Jiaqi Yanrafaeljw
authored andcommitted
ACPI: APEI: EINJ: Allow more types of addresses except MMIO
EINJ driver today only allows injection request to go through for two kinds of IORESOURCE_MEM: IORES_DESC_PERSISTENT_MEMORY and IORES_DESC_SOFT_RESERVED. This check prevents user of EINJ to test memory corrupted in many interesting areas: - Legacy persistent memory - Memory claimed to be used by ACPI tables or NV storage - Kernel crash memory and others There is need to test how kernel behaves when something consumes memory errors in these memory regions. For example, if certain ACPI table is corrupted, does kernel crash gracefully to prevent "silent data corruption". For another example, legacy persistent memory, when managed by Device DAX, does support recovering from Machine Check Exception raised by memory failure, hence worth to be tested. However, attempt to inject memory error via EINJ to legacy persistent memory or ACPI owned memory fails with -EINVAL. Allow EINJ to inject at address except it is MMIO. Leave it to the BIOS or firmware to decide what is a legitimate injection target. In addition to the test done in [1], on a machine having the following iomem resources: ... 01000000-08ffffff : Crash kernel 768f0098-768f00a7 : APEI EINJ ... 768f4000-77323fff : ACPI Non-volatile Storage 77324000-777fefff : ACPI Tables 777ff000-777fffff : System RAM 77800000-7fffffff : Reserved 80000000-8fffffff : PCI MMCONFIG 0000 [bus 00-ff] 90040000-957fffff : PCI Bus 0000:00 ... 300000000-3ffffffff : Persistent Memory (legacy) ... I commented __einj_error_inject during the test and just tested when injecting a memory error at each start address shown above: - 0x80000000 and 0x90040000 both failed with EINVAL - request passed through for all other addresses Link: https://lore.kernel.org/linux-acpi/20250825223348.3780279-1-jiaqiyan@google.com [1] Signed-off-by: Jiaqi Yan <jiaqiyan@google.com> Reviewed-by: Hanjun Guo <guohanjun@huawei.com> Link: https://patch.msgid.link/20250910044531.264043-1-jiaqiyan@google.com [ rjw: Adding a link tag for the [1] reference ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e06722a commit 7d444f5

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

drivers/acpi/apei/einj-core.c

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,43 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
656656
return rc;
657657
}
658658

659+
/* Allow almost all types of address except MMIO. */
660+
static bool is_allowed_range(u64 base_addr, u64 size)
661+
{
662+
int i;
663+
/*
664+
* MMIO region is usually claimed with IORESOURCE_MEM + IORES_DESC_NONE.
665+
* However, IORES_DESC_NONE is treated like a wildcard when we check if
666+
* region intersects with known resource. So do an allow list check for
667+
* IORES_DESCs that definitely or most likely not MMIO.
668+
*/
669+
int non_mmio_desc[] = {
670+
IORES_DESC_CRASH_KERNEL,
671+
IORES_DESC_ACPI_TABLES,
672+
IORES_DESC_ACPI_NV_STORAGE,
673+
IORES_DESC_PERSISTENT_MEMORY,
674+
IORES_DESC_PERSISTENT_MEMORY_LEGACY,
675+
/* Treat IORES_DESC_DEVICE_PRIVATE_MEMORY as MMIO. */
676+
IORES_DESC_RESERVED,
677+
IORES_DESC_SOFT_RESERVED,
678+
};
679+
680+
if (region_intersects(base_addr, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE)
681+
== REGION_INTERSECTS)
682+
return true;
683+
684+
for (i = 0; i < ARRAY_SIZE(non_mmio_desc); ++i) {
685+
if (region_intersects(base_addr, size, IORESOURCE_MEM, non_mmio_desc[i])
686+
== REGION_INTERSECTS)
687+
return true;
688+
}
689+
690+
if (arch_is_platform_page(base_addr))
691+
return true;
692+
693+
return false;
694+
}
695+
659696
/* Inject the specified hardware error */
660697
int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, u64 param3,
661698
u64 param4)
@@ -702,19 +739,15 @@ int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, u64 param3,
702739
* Disallow crazy address masks that give BIOS leeway to pick
703740
* injection address almost anywhere. Insist on page or
704741
* better granularity and that target address is normal RAM or
705-
* NVDIMM.
742+
* as long as is not MMIO.
706743
*/
707744
base_addr = param1 & param2;
708745
size = ~param2 + 1;
709746

710-
if (((param2 & PAGE_MASK) != PAGE_MASK) ||
711-
((region_intersects(base_addr, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE)
712-
!= REGION_INTERSECTS) &&
713-
(region_intersects(base_addr, size, IORESOURCE_MEM, IORES_DESC_PERSISTENT_MEMORY)
714-
!= REGION_INTERSECTS) &&
715-
(region_intersects(base_addr, size, IORESOURCE_MEM, IORES_DESC_SOFT_RESERVED)
716-
!= REGION_INTERSECTS) &&
717-
!arch_is_platform_page(base_addr)))
747+
if ((param2 & PAGE_MASK) != PAGE_MASK)
748+
return -EINVAL;
749+
750+
if (!is_allowed_range(base_addr, size))
718751
return -EINVAL;
719752

720753
if (is_zero_pfn(base_addr >> PAGE_SHIFT))

0 commit comments

Comments
 (0)