AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/08/21 10:58 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": [
    "EFI_POISONED_MEMORY",
    "MEMORY_FAILURE",
    "EFI_STUB"
  ],
  "FocusSymbols": [
    "efi_hwpoison_record_pfn",
    "efi_reserve_poisoned_memory",
    "install_poisoned_memory_table",
    "efi_get_ram_top"
  ],
  "KMSANReasoning": "The patch introduces a mechanism to carry hardware-poisoned pages across kexec using an EFI configuration table. The newly introduced structure `linux_efi_poisoned_memory` is allocated in `efi_poison_alloc()` and all its fields, including the flexible `bitmap` array, are explicitly initialized (the fields are assigned and the bitmap is zeroed using `memset`). There is no structure padding that could leak uninitialized memory, and this table is not copied to user space. The changes do not introduce any risk of uninitialized memory reads or info-leaks. Any potential memory corruption, out-of-bounds accesses, or use-after-free bugs related to the bitmap handling would be caught by standard KASAN. Therefore, a dedicated KMSAN fuzzing session is not necessary.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch adds support for carrying hardware-poisoned pages across kexec via an EFI configuration table. It introduces a new EFI config table to store the poisoned memory bitmap, hooks into `memory-failure.c` to record poisoned pages, and hooks into the EFI stub to allocate and install the table. The new logic is reachable during EFI boot and when memory failures are injected (e.g., via madvise MADV_HWPOISON).",
  "WorthFuzzing": true
}

1/1 2026/08/21 10:58 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit ac3651c68b7ae071f45de77bc9fb4d79044fa09c\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Fri Aug 21 10:58:50 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig\nindex 29e0729299f5b..69c0dc02bc112 100644\n--- a/drivers/firmware/efi/Kconfig\n+++ b/drivers/firmware/efi/Kconfig\n@@ -263,6 +263,16 @@ config EFI_COCO_SECRET\n \t  virt/coco/efi_secret module to access the secrets, which in turn\n \t  allows userspace programs to access the injected secrets.\n \n+config EFI_POISONED_MEMORY\n+\tbool \"Carry hardware-poisoned pages across kexec\"\n+\tdepends on EFI_STUB \u0026\u0026 MEMORY_FAILURE \u0026\u0026 64BIT\n+\thelp\n+\t  Record page frames that are hardware-poisoned while this kernel runs\n+\t  into an EFI configuration table, and honor that table early on the\n+\t  next kernel so a kexec does not hand known-bad RAM back out.\n+\n+\t  If unsure, say N.\n+\n config OVMF_DEBUG_LOG\n \tbool \"Expose OVMF firmware debug log via sysfs\"\n \tdepends on EFI\ndiff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile\nindex 8efbcf699e4ff..05d0a490923e5 100644\n--- a/drivers/firmware/efi/Makefile\n+++ b/drivers/firmware/efi/Makefile\n@@ -43,4 +43,5 @@ obj-$(CONFIG_EFI_EARLYCON)\t\t+= earlycon.o\n obj-$(CONFIG_UEFI_CPER_ARM)\t\t+= cper-arm.o\n obj-$(CONFIG_UEFI_CPER_X86)\t\t+= cper-x86.o\n obj-$(CONFIG_UNACCEPTED_MEMORY)\t\t+= unaccepted_memory.o\n+obj-$(CONFIG_EFI_POISONED_MEMORY)\t+= poison.o\n obj-$(CONFIG_TEE_STMM_EFI)\t\t+= stmm/tee_stmm_efi.o\ndiff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c\nindex 0327a39d31fa5..7474eeebb0add 100644\n--- a/drivers/firmware/efi/efi.c\n+++ b/drivers/firmware/efi/efi.c\n@@ -55,6 +55,9 @@ struct efi __read_mostly efi = {\n #ifdef CONFIG_UNACCEPTED_MEMORY\n \t.unaccepted\t\t= EFI_INVALID_TABLE_ADDR,\n #endif\n+#ifdef CONFIG_EFI_POISONED_MEMORY\n+\t.poisoned_memory\t= EFI_INVALID_TABLE_ADDR,\n+#endif\n };\n EXPORT_SYMBOL(efi);\n \n@@ -646,6 +649,9 @@ static const efi_config_table_type_t common_tables[] __initconst = {\n #ifdef CONFIG_UNACCEPTED_MEMORY\n \t{LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID,\t\u0026efi.unaccepted,\t\"Unaccepted\"\t},\n #endif\n+#ifdef CONFIG_EFI_POISONED_MEMORY\n+\t{LINUX_EFI_POISONED_MEMORY_TABLE_GUID,\t\u0026efi.poisoned_memory,\t\"POISON\"\t},\n+#endif\n #ifdef CONFIG_EFI_GENERIC_STUB\n \t{LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID,\t\u0026primary_display_table\t\t\t},\n #endif\n@@ -806,6 +812,8 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,\n \t\t}\n \t}\n \n+\tefi_reserve_poisoned_memory();\n+\n \tif (rt_prop != EFI_INVALID_TABLE_ADDR) {\n \t\tefi_rt_properties_table_t *tbl;\n \ndiff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c\nindex f27f2e1f00199..7258ecdf1f7c2 100644\n--- a/drivers/firmware/efi/libstub/efi-stub-helper.c\n+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c\n@@ -774,3 +774,92 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,\n \t\t\tefi_warn(\"Failed to remap data region non-executable\\n\");\n \t}\n }\n+\n+#ifdef CONFIG_EFI_POISONED_MEMORY\n+/* Cap on the bitmap; a span too wide to fit gets a coarser unit instead. */\n+#define EFI_POISON_MAX_TABLE_SIZE\tSZ_1M\n+#define EFI_POISON_MAX_UNIT_SIZE\tSZ_1G\n+\n+/*\n+ * Bitmap geometry for a given top of RAM. The bitmap starts at address 0, so\n+ * bit N covers unit N.\n+ * In the following code, a \"unit\" is granule of physical address space that one\n+ * bitmap bit covers.\n+ */\n+static u32 efi_poison_geometry(u64 ram_top, u64 *bitmap_size)\n+{\n+\tu64 nr_units = DIV_ROUND_UP(ram_top, EFI_POISON_UNIT_SIZE);\n+\tu32 unit_size = EFI_POISON_UNIT_SIZE;\n+\n+\twhile (DIV_ROUND_UP(nr_units, BITS_PER_BYTE) \u003e EFI_POISON_MAX_TABLE_SIZE \u0026\u0026\n+\t       unit_size \u003c EFI_POISON_MAX_UNIT_SIZE) {\n+\t\tnr_units = DIV_ROUND_UP(nr_units, 2);\n+\t\tunit_size *= 2;\n+\t}\n+\n+\t*bitmap_size = DIV_ROUND_UP(nr_units, BITS_PER_BYTE);\n+\treturn unit_size;\n+}\n+\n+/* ACPI reclaim memory, so the next kernel does not treat it as free RAM. */\n+static struct linux_efi_poisoned_memory *efi_poison_alloc(u64 bitmap_size,\n+\t\t\t\t\t\t\t  u32 unit_size)\n+{\n+\tstruct linux_efi_poisoned_memory *pm;\n+\tefi_status_t status;\n+\n+\tstatus = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,\n+\t\t\t     sizeof(*pm) + bitmap_size, (void **)\u0026pm);\n+\tif (status != EFI_SUCCESS)\n+\t\treturn NULL;\n+\n+\tpm-\u003eversion = 1;\n+\tpm-\u003eunit_size = unit_size;\n+\tpm-\u003ephys_base = 0;\n+\tpm-\u003esize = bitmap_size;\n+\tmemset(pm-\u003ebitmap, 0, bitmap_size);\n+\n+\treturn pm;\n+}\n+\n+/*\n+ * Allocate and install the poisoned-memory bitmap while boot services are\n+ * available\n+ */\n+void install_poisoned_memory_table(void)\n+{\n+\tefi_guid_t poisoned_memory_table_guid = LINUX_EFI_POISONED_MEMORY_TABLE_GUID;\n+\tstruct linux_efi_poisoned_memory *pm;\n+\tu64 ram_top, bitmap_size;\n+\tefi_status_t status;\n+\tu32 unit_size;\n+\n+\t/* A table installed by an earlier boot rides the system table across kexec. */\n+\tpm = get_efi_config_table(poisoned_memory_table_guid);\n+\tif (pm) {\n+\t\tif (pm-\u003eversion != 1)\n+\t\t\tefi_err(\"Unknown version of poisoned-memory table\\n\");\n+\t\treturn;\n+\t}\n+\n+\tif (efi_get_ram_top(\u0026ram_top) != EFI_SUCCESS) {\n+\t\tefi_err(\"Failed to size the poisoned-memory table!\\n\");\n+\t\treturn;\n+\t}\n+\n+\tunit_size = efi_poison_geometry(ram_top, \u0026bitmap_size);\n+\n+\tpm = efi_poison_alloc(bitmap_size, unit_size);\n+\tif (!pm) {\n+\t\tefi_err(\"Failed to allocate poisoned-memory table!\\n\");\n+\t\treturn;\n+\t}\n+\n+\tstatus = efi_bs_call(install_configuration_table,\n+\t\t\t     \u0026poisoned_memory_table_guid, pm);\n+\tif (status != EFI_SUCCESS) {\n+\t\tefi_bs_call(free_pool, pm);\n+\t\tefi_err(\"Failed to install poisoned-memory config table!\\n\");\n+\t}\n+}\n+#endif\ndiff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c\nindex 42d6073bcd062..008635eb5027a 100644\n--- a/drivers/firmware/efi/libstub/efi-stub.c\n+++ b/drivers/firmware/efi/libstub/efi-stub.c\n@@ -179,6 +179,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,\n \t\t\t EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP);\n \n \tinstall_memreserve_table();\n+\tinstall_poisoned_memory_table();\n \n \tstatus = efi_boot_kernel(handle, image, image_addr, cmdline_ptr);\n \ndiff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h\nindex fd91fc15ec810..b5e19ba50ddae 100644\n--- a/drivers/firmware/efi/libstub/efistub.h\n+++ b/drivers/firmware/efi/libstub/efistub.h\n@@ -1094,6 +1094,8 @@ char *efi_convert_cmdline(efi_loaded_image_t *image);\n efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,\n \t\t\t\tbool install_cfg_tbl);\n \n+efi_status_t efi_get_ram_top(u64 *top);\n+\n efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,\n \t\t\t\tunsigned long max);\n \n@@ -1169,6 +1171,12 @@ efi_enable_reset_attack_mitigation(void) { }\n \n void efi_retrieve_eventlog(void);\n \n+#ifdef CONFIG_EFI_POISONED_MEMORY\n+void install_poisoned_memory_table(void);\n+#else\n+static inline void install_poisoned_memory_table(void) { }\n+#endif\n+\n struct sysfb_display_info *alloc_primary_display(void);\n struct sysfb_display_info *__alloc_primary_display(void);\n void free_primary_display(struct sysfb_display_info *dpy);\ndiff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c\nindex 59f3f83de50c2..777f1f180c66e 100644\n--- a/drivers/firmware/efi/libstub/mem.c\n+++ b/drivers/firmware/efi/libstub/mem.c\n@@ -64,6 +64,59 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,\n \treturn EFI_SUCCESS;\n }\n \n+/**\n+ * efi_get_ram_top() - find the top of usable RAM\n+ * @top:\ton return, the end of the highest memory map entry that becomes\n+ *\t\tusable RAM\n+ *\n+ * Walk the UEFI memory map for the entry types that become usable RAM, the set\n+ * setup_e820() maps to E820_TYPE_RAM, and return the highest address any of\n+ * them reaches. Memory a confidential guest has not accepted yet counts as\n+ * well, since it becomes RAM once accepted. This is what the stub has in place\n+ * of max_pfn, which is only set once the kernel proper is up.\n+ *\n+ * Memory the firmware hot-adds later is not described by the memory map and so\n+ * is not accounted for here.\n+ *\n+ * Return:\tstatus code\n+ */\n+efi_status_t efi_get_ram_top(u64 *top)\n+{\n+\tstruct efi_boot_memmap *map __free(efi_pool) = NULL;\n+\tefi_status_t status;\n+\tu64 ram_top = 0;\n+\tint i, nr_desc;\n+\n+\tstatus = efi_get_memory_map(\u0026map, false);\n+\tif (status != EFI_SUCCESS)\n+\t\treturn status;\n+\n+\tnr_desc = map-\u003emap_size / map-\u003edesc_size;\n+\tfor (i = 0; i \u003c nr_desc; i++) {\n+\t\tefi_memory_desc_t *d;\n+\n+\t\td = efi_memdesc_ptr((unsigned long)map-\u003emap, map-\u003edesc_size, i);\n+\t\tswitch (d-\u003etype) {\n+\t\tcase EFI_LOADER_CODE:\n+\t\tcase EFI_LOADER_DATA:\n+\t\tcase EFI_BOOT_SERVICES_CODE:\n+\t\tcase EFI_BOOT_SERVICES_DATA:\n+\t\tcase EFI_CONVENTIONAL_MEMORY:\n+\t\tcase EFI_UNACCEPTED_MEMORY:\n+\t\t\tram_top = max(ram_top,\n+\t\t\t\t      d-\u003ephys_addr + d-\u003enum_pages * EFI_PAGE_SIZE);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (!ram_top)\n+\t\treturn EFI_NOT_FOUND;\n+\n+\t*top = ram_top;\n+\treturn EFI_SUCCESS;\n+}\n+\n /**\n  * efi_allocate_pages() - Allocate memory pages\n  * @size:\tminimum number of bytes to allocate\ndiff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c\nindex cef32e2c82d8f..f90de11bc8855 100644\n--- a/drivers/firmware/efi/libstub/x86-stub.c\n+++ b/drivers/firmware/efi/libstub/x86-stub.c\n@@ -1023,6 +1023,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle,\n \n \tsetup_unaccepted_memory();\n \n+\tinstall_poisoned_memory_table();\n+\n \tstatus = exit_boot(boot_params, handle);\n \tif (status != EFI_SUCCESS) {\n \t\tefi_err(\"exit_boot() failed!\\n\");\ndiff --git a/drivers/firmware/efi/poison.c b/drivers/firmware/efi/poison.c\nnew file mode 100644\nindex 0000000000000..e418c6b3aab81\n--- /dev/null\n+++ b/drivers/firmware/efi/poison.c\n@@ -0,0 +1,197 @@\n+// SPDX-License-Identifier: GPL-2.0-only\n+/*\n+ * Runtime handling for the LINUX_EFI_POISONED_MEMORY configuration table: a\n+ * bitmap with one bit per EFI_POISON_UNIT_SIZE of physical memory that records\n+ * hardware-poisoned frames so the next kexec kernel can keep them out of its\n+ * allocator. The stub allocates and installs the (empty) bitmap; this kernel\n+ * sets bits at runtime; the next kernel reserves the set units before the\n+ * allocator comes up.\n+ *\n+ * Copyright (c) 2026 Meta Platforms, Inc. and affiliates.\n+ * Copyright (c) 2026 Breno Leitao \u003cleitao@debian.org\u003e\n+ */\n+\n+#define pr_fmt(fmt) \"efi: \" fmt\n+\n+#include \u003clinux/bitmap.h\u003e\n+#include \u003clinux/efi.h\u003e\n+#include \u003clinux/io.h\u003e\n+#include \u003clinux/log2.h\u003e\n+#include \u003clinux/memblock.h\u003e\n+#include \u003clinux/minmax.h\u003e\n+#include \u003clinux/mm.h\u003e\n+#include \u003clinux/overflow.h\u003e\n+\n+static struct linux_efi_poisoned_memory *efi_poison __ro_after_init;\n+\n+/* A non-empty bitmap on a power-of-2 grid that phys_base actually sits on. */\n+static bool __init\n+efi_poison_geometry_valid(const struct linux_efi_poisoned_memory *pm)\n+{\n+\tif (!pm-\u003esize)\n+\t\treturn false;\n+\tif (pm-\u003eunit_size \u003c PAGE_SIZE || !is_power_of_2(pm-\u003eunit_size))\n+\t\treturn false;\n+\n+\treturn IS_ALIGNED(pm-\u003ephys_base, pm-\u003eunit_size);\n+}\n+\n+/* The range the bitmap claims to describe has to fit in a u64. */\n+static bool __init\n+efi_poison_range_valid(const struct linux_efi_poisoned_memory *pm)\n+{\n+\tu64 nbits, span;\n+\n+\tif (check_mul_overflow(pm-\u003esize, (u64)BITS_PER_BYTE, \u0026nbits))\n+\t\treturn false;\n+\tif (check_mul_overflow(nbits, (u64)pm-\u003eunit_size, \u0026span))\n+\t\treturn false;\n+\n+\treturn !check_add_overflow(pm-\u003ephys_base, span, \u0026span);\n+}\n+\n+/*\n+ * The table may have been installed by an earlier kernel in the kexec chain,\n+ * so check its geometry before doing any arithmetic with it.\n+ */\n+static bool __init\n+efi_poison_table_valid(const struct linux_efi_poisoned_memory *pm)\n+{\n+\tif (pm-\u003eversion != 1) {\n+\t\tpr_warn(\"Ignoring poisoned-memory table with version %u\\n\",\n+\t\t\tpm-\u003eversion);\n+\t\treturn false;\n+\t}\n+\n+\tif (!efi_poison_geometry_valid(pm) || !efi_poison_range_valid(pm)) {\n+\t\tpr_warn(\"Ignoring malformed poisoned-memory table\\n\");\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+static int __init efi_poison_init(void)\n+{\n+\tstruct linux_efi_poisoned_memory *pm;\n+\tu64 size;\n+\n+\tif (efi.poisoned_memory == EFI_INVALID_TABLE_ADDR)\n+\t\treturn 0;\n+\n+\t/* Map the header to learn the bitmap size, then map the whole table. */\n+\tpm = memremap(efi.poisoned_memory, sizeof(*pm), MEMREMAP_WB);\n+\tif (WARN_ON_ONCE(!pm))\n+\t\treturn 0;\n+\tif (!efi_poison_table_valid(pm)) {\n+\t\tmemunmap(pm);\n+\t\treturn 0;\n+\t}\n+\tsize = pm-\u003esize;\n+\tmemunmap(pm);\n+\n+\tefi_poison = memremap(efi.poisoned_memory, sizeof(*pm) + size,\n+\t\t\t      MEMREMAP_WB);\n+\tWARN_ON_ONCE(!efi_poison);\n+\treturn 0;\n+}\n+early_initcall(efi_poison_init);\n+\n+/* Bitmap unit covering @pfn, or -1 if the pfn falls outside the table. */\n+static long efi_poison_unit(unsigned long pfn)\n+{\n+\tphys_addr_t addr = PFN_PHYS(pfn);\n+\tu64 unit;\n+\n+\tif (addr \u003c efi_poison-\u003ephys_base)\n+\t\treturn -1;\n+\tunit = (addr - efi_poison-\u003ephys_base) / efi_poison-\u003eunit_size;\n+\tif (unit \u003e= (u64)efi_poison-\u003esize * BITS_PER_BYTE)\n+\t\treturn -1;\n+\treturn unit;\n+}\n+\n+/*\n+ * Record a hardware-poisoned frame so the next kernel keeps its unit out of the\n+ * allocator. memory_failure() has already removed the frame from this kernel.\n+ *\n+ * A bit is never cleared: one bit stands for a whole EFI_POISON_UNIT_SIZE, so\n+ * an unpoison cannot tell whether the unit as a whole is good again.\n+ */\n+void efi_hwpoison_record_pfn(unsigned long pfn)\n+{\n+\tlong unit;\n+\n+\tif (!efi_poison)\n+\t\treturn;\n+\n+\tunit = efi_poison_unit(pfn);\n+\tif (unit \u003c 0)\n+\t\treturn;\n+\n+\tset_bit(unit, efi_poison-\u003ebitmap);\n+}\n+\n+void __init efi_reserve_poisoned_memory(void)\n+{\n+\tu64 ppm = efi.poisoned_memory, phys_base, unit_size, bitmap_size, off;\n+\tstruct linux_efi_poisoned_memory *pm;\n+\tunsigned int nr_units = 0;\n+\n+\tif (ppm == EFI_INVALID_TABLE_ADDR)\n+\t\treturn;\n+\n+\tpm = early_memremap(ppm, sizeof(*pm));\n+\tif (!pm) {\n+\t\tpr_warn(\"Could not map poisoned-memory table\\n\");\n+\t\treturn;\n+\t}\n+\n+\tif (!efi_poison_table_valid(pm)) {\n+\t\t/* Keep the runtime side off a table this pass rejected. */\n+\t\tefi.poisoned_memory = EFI_INVALID_TABLE_ADDR;\n+\t\tearly_memunmap(pm, sizeof(*pm));\n+\t\treturn;\n+\t}\n+\n+\tphys_base = pm-\u003ephys_base;\n+\tunit_size = pm-\u003eunit_size;\n+\tbitmap_size = pm-\u003esize;\n+\n+\tearly_memunmap(pm, sizeof(*pm));\n+\n+\t/* Reserve the table itself so it survives a further kexec. */\n+\tmemblock_reserve(PAGE_ALIGN_DOWN(ppm),\n+\t\t\t PAGE_ALIGN(ppm + sizeof(*pm) + bitmap_size) -\n+\t\t\t PAGE_ALIGN_DOWN(ppm));\n+\n+\t/*\n+\t * Walk the bitmap a page at a time and reserve each poisoned unit.\n+\t * memblock.memory is not populated this early, so memblock_remove()\n+\t * and memblock_mark_nomap() would be no-ops; a reservation is what\n+\t * keeps the units away from the allocator.\n+\t */\n+\tfor (off = 0; off \u003c bitmap_size; off += PAGE_SIZE) {\n+\t\tu64 chunk = min_t(u64, PAGE_SIZE, bitmap_size - off);\n+\t\tunsigned long bit, nbits = chunk * BITS_PER_BYTE;\n+\t\tunsigned long *map;\n+\n+\t\tmap = early_memremap(ppm + offsetof(struct linux_efi_poisoned_memory,\n+\t\t\t\t\t\t    bitmap) + off, chunk);\n+\t\tif (!map) {\n+\t\t\tpr_warn(\"Could not map poisoned-memory bitmap\\n\");\n+\t\t\treturn;\n+\t\t}\n+\t\tfor_each_set_bit(bit, map, nbits) {\n+\t\t\tu64 unit = off * BITS_PER_BYTE + bit;\n+\n+\t\t\tmemblock_reserve(phys_base + unit * unit_size, unit_size);\n+\t\t\tnr_units++;\n+\t\t}\n+\t\tearly_memunmap(map, chunk);\n+\t}\n+\n+\tif (nr_units)\n+\t\tpr_info(\"reserved %u poisoned unit(s) (%lluK each) inherited across kexec\\n\",\n+\t\t\tnr_units, unit_size \u003e\u003e 10);\n+}\ndiff --git a/include/linux/efi.h b/include/linux/efi.h\nindex ccbc35479684a..3cb3f224ac02b 100644\n--- a/include/linux/efi.h\n+++ b/include/linux/efi.h\n@@ -23,6 +23,7 @@\n #include \u003clinux/pstore.h\u003e\n #include \u003clinux/range.h\u003e\n #include \u003clinux/reboot.h\u003e\n+#include \u003clinux/sizes.h\u003e\n #include \u003clinux/uuid.h\u003e\n \n #include \u003casm/page.h\u003e\n@@ -422,6 +423,7 @@ void efi_native_runtime_setup(void);\n #define LINUX_EFI_COCO_SECRET_AREA_GUID\t\tEFI_GUID(0xadf956ad, 0xe98c, 0x484c,  0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47)\n #define LINUX_EFI_BOOT_MEMMAP_GUID\t\tEFI_GUID(0x800f683f, 0xd08b, 0x423a,  0xa2, 0x93, 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)\n #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID\tEFI_GUID(0xd5d1de3c, 0x105c, 0x44f9,  0x9e, 0xa9, 0xbc, 0xef, 0x98, 0x12, 0x00, 0x31)\n+#define LINUX_EFI_POISONED_MEMORY_TABLE_GUID\tEFI_GUID(0x78a5bf07, 0x7d2a, 0x2889,  0x16, 0x31, 0x63, 0xd4, 0x56, 0xf2, 0x83, 0x50)\n \n #define RISCV_EFI_BOOT_PROTOCOL_GUID\t\tEFI_GUID(0xccd15fec, 0x6f73, 0x4eec,  0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)\n \n@@ -650,6 +652,7 @@ extern struct efi {\n \tunsigned long\t\t\tmokvar_table;\t\t/* MOK variable config table */\n \tunsigned long\t\t\tcoco_secret;\t\t/* Confidential computing secret table */\n \tunsigned long\t\t\tunaccepted;\t\t/* Unaccepted memory table */\n+\tunsigned long\t\t\tpoisoned_memory;\t/* Hardware-poisoned memory table */\n \n \tefi_get_time_t\t\t\t*get_time;\n \tefi_set_time_t\t\t\t*set_time;\n@@ -1269,6 +1272,24 @@ struct linux_efi_memreserve {\n #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \\\n \t/ sizeof_field(struct linux_efi_memreserve, entry[0]))\n \n+struct linux_efi_poisoned_memory {\n+\tu32\t\tversion;\n+\tu32\t\tunit_size;\t/* bytes of phys space per bitmap bit */\n+\tu64\t\tphys_base;\t/* phys address covered by bit 0 */\n+\tu64\t\tsize;\t\t/* bitmap size in bytes */\n+\tunsigned long\tbitmap[];\n+};\n+\n+#define EFI_POISON_UNIT_SIZE\tSZ_2M\n+\n+#ifdef CONFIG_EFI_POISONED_MEMORY\n+void efi_reserve_poisoned_memory(void);\n+void efi_hwpoison_record_pfn(unsigned long pfn);\n+#else\n+static inline void efi_reserve_poisoned_memory(void) { }\n+static inline void efi_hwpoison_record_pfn(unsigned long pfn) { }\n+#endif\n+\n void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size);\n \n /*\ndiff --git a/mm/memory-failure.c b/mm/memory-failure.c\nindex a8b03e2920ba8..1cc4e92e98748 100644\n--- a/mm/memory-failure.c\n+++ b/mm/memory-failure.c\n@@ -43,6 +43,7 @@\n #include \u003clinux/sched/signal.h\u003e\n #include \u003clinux/sched/task.h\u003e\n #include \u003clinux/dax.h\u003e\n+#include \u003clinux/efi.h\u003e\n #include \u003clinux/ksm.h\u003e\n #include \u003clinux/rmap.h\u003e\n #include \u003clinux/export.h\u003e\n@@ -1286,6 +1287,8 @@ static int action_result(unsigned long pfn, enum mf_action_page_type type,\n \tif (type != MF_MSG_ALREADY_POISONED \u0026\u0026 type != MF_MSG_PFN_MAP) {\n \t\tnum_poisoned_pages_inc(pfn);\n \t\tupdate_per_node_mf_stats(pfn, result);\n+\t\t/* Only hard offlines are carried over to the next kernel. */\n+\t\tefi_hwpoison_record_pfn(pfn);\n \t}\n \n \tpr_err(\"%#lx: recovery action for %s: %s\\n\",\n"
}

2/1 2026/08/21 10:58 agent patch-evaluator
1m Model:
best-expensive

Args:
null

Results:
{
  "EnableConfigs": [
    "EFI_POISONED_MEMORY",
    "MEMORY_FAILURE",
    "EFI_STUB"
  ],
  "FocusSymbols": [
    "efi_hwpoison_record_pfn",
    "efi_reserve_poisoned_memory",
    "install_poisoned_memory_table",
    "efi_get_ram_top"
  ],
  "Reasoning": "The patch adds support for carrying hardware-poisoned pages across kexec via an EFI configuration table. It introduces a new EFI config table to store the poisoned memory bitmap, hooks into `memory-failure.c` to record poisoned pages, and hooks into the EFI stub to allocate and install the table. The new logic is reachable during EFI boot and when memory failures are injected (e.g., via madvise MADV_HWPOISON).",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer.
Your job is to review a provided patch series and determine
if it makes functional changes to the kernel that should be fuzzed.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively
use your code access tools to examine the actual source code and confirm any assumptions.

Return WorthFuzzing=false if the patch only contains:
- Modifications to Documentation/, Kconfig files, or code comments.
- Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints.
- Changes to numeric constants or macros that do not functionally alter execution flow.
- Code paths that are impossible to reach in virtualized environments like GCE or QEMU,
  even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim).
- Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed,
  ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU.
- Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove)
  that are executed only during PCI hot-unplug or sysfs driver unbind operations.

If it modifies reachable core kernel logic, drivers, or architectures, use your code search
tools to verify the code can be executed, then return WorthFuzzing=true.

When returning WorthFuzzing=true, you MUST ALSO:
1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols.
   Avoid listing generic hot-path functions to prevent skewed test distributions.
   Prefer non-static, non-inlined API entrypoint functions over internal static helper functions
   (which are inlined by the compiler and do not have distinct symbol addresses).
2. Identify any specific CONFIG_ options required to properly test this new/modified feature.
   Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions.
   Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs
   needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs
   output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit ac3651c68b7ae071f45de77bc9fb4d79044fa09c
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Aug 21 10:58:50 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 29e0729299f5b..69c0dc02bc112 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -263,6 +263,16 @@ config EFI_COCO_SECRET
 	  virt/coco/efi_secret module to access the secrets, which in turn
 	  allows userspace programs to access the injected secrets.
 
+config EFI_POISONED_MEMORY
+	bool "Carry hardware-poisoned pages across kexec"
+	depends on EFI_STUB && MEMORY_FAILURE && 64BIT
+	help
+	  Record page frames that are hardware-poisoned while this kernel runs
+	  into an EFI configuration table, and honor that table early on the
+	  next kernel so a kexec does not hand known-bad RAM back out.
+
+	  If unsure, say N.
+
 config OVMF_DEBUG_LOG
 	bool "Expose OVMF firmware debug log via sysfs"
 	depends on EFI
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index 8efbcf699e4ff..05d0a490923e5 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -43,4 +43,5 @@ obj-$(CONFIG_EFI_EARLYCON)		+= earlycon.o
 obj-$(CONFIG_UEFI_CPER_ARM)		+= cper-arm.o
 obj-$(CONFIG_UEFI_CPER_X86)		+= cper-x86.o
 obj-$(CONFIG_UNACCEPTED_MEMORY)		+= unaccepted_memory.o
+obj-$(CONFIG_EFI_POISONED_MEMORY)	+= poison.o
 obj-$(CONFIG_TEE_STMM_EFI)		+= stmm/tee_stmm_efi.o
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 0327a39d31fa5..7474eeebb0add 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -55,6 +55,9 @@ struct efi __read_mostly efi = {
 #ifdef CONFIG_UNACCEPTED_MEMORY
 	.unaccepted		= EFI_INVALID_TABLE_ADDR,
 #endif
+#ifdef CONFIG_EFI_POISONED_MEMORY
+	.poisoned_memory	= EFI_INVALID_TABLE_ADDR,
+#endif
 };
 EXPORT_SYMBOL(efi);
 
@@ -646,6 +649,9 @@ static const efi_config_table_type_t common_tables[] __initconst = {
 #ifdef CONFIG_UNACCEPTED_MEMORY
 	{LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID,	&efi.unaccepted,	"Unaccepted"	},
 #endif
+#ifdef CONFIG_EFI_POISONED_MEMORY
+	{LINUX_EFI_POISONED_MEMORY_TABLE_GUID,	&efi.poisoned_memory,	"POISON"	},
+#endif
 #ifdef CONFIG_EFI_GENERIC_STUB
 	{LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID,	&primary_display_table			},
 #endif
@@ -806,6 +812,8 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,
 		}
 	}
 
+	efi_reserve_poisoned_memory();
+
 	if (rt_prop != EFI_INVALID_TABLE_ADDR) {
 		efi_rt_properties_table_t *tbl;
 
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index f27f2e1f00199..7258ecdf1f7c2 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -774,3 +774,92 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
 			efi_warn("Failed to remap data region non-executable\n");
 	}
 }
+
+#ifdef CONFIG_EFI_POISONED_MEMORY
+/* Cap on the bitmap; a span too wide to fit gets a coarser unit instead. */
+#define EFI_POISON_MAX_TABLE_SIZE	SZ_1M
+#define EFI_POISON_MAX_UNIT_SIZE	SZ_1G
+
+/*
+ * Bitmap geometry for a given top of RAM. The bitmap starts at address 0, so
+ * bit N covers unit N.
+ * In the following code, a "unit" is granule of physical address space that one
+ * bitmap bit covers.
+ */
+static u32 efi_poison_geometry(u64 ram_top, u64 *bitmap_size)
+{
+	u64 nr_units = DIV_ROUND_UP(ram_top, EFI_POISON_UNIT_SIZE);
+	u32 unit_size = EFI_POISON_UNIT_SIZE;
+
+	while (DIV_ROUND_UP(nr_units, BITS_PER_BYTE) > EFI_POISON_MAX_TABLE_SIZE &&
+	       unit_size < EFI_POISON_MAX_UNIT_SIZE) {
+		nr_units = DIV_ROUND_UP(nr_units, 2);
+		unit_size *= 2;
+	}
+
+	*bitmap_size = DIV_ROUND_UP(nr_units, BITS_PER_BYTE);
+	return unit_size;
+}
+
+/* ACPI reclaim memory, so the next kernel does not treat it as free RAM. */
+static struct linux_efi_poisoned_memory *efi_poison_alloc(u64 bitmap_size,
+							  u32 unit_size)
+{
+	struct linux_efi_poisoned_memory *pm;
+	efi_status_t status;
+
+	status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
+			     sizeof(*pm) + bitmap_size, (void **)&pm);
+	if (status != EFI_SUCCESS)
+		return NULL;
+
+	pm->version = 1;
+	pm->unit_size = unit_size;
+	pm->phys_base = 0;
+	pm->size = bitmap_size;
+	memset(pm->bitmap, 0, bitmap_size);
+
+	return pm;
+}
+
+/*
+ * Allocate and install the poisoned-memory bitmap while boot services are
+ * available
+ */
+void install_poisoned_memory_table(void)
+{
+	efi_guid_t poisoned_memory_table_guid = LINUX_EFI_POISONED_MEMORY_TABLE_GUID;
+	struct linux_efi_poisoned_memory *pm;
+	u64 ram_top, bitmap_size;
+	efi_status_t status;
+	u32 unit_size;
+
+	/* A table installed by an earlier boot rides the system table across kexec. */
+	pm = get_efi_config_table(poisoned_memory_table_guid);
+	if (pm) {
+		if (pm->version != 1)
+			efi_err("Unknown version of poisoned-memory table\n");
+		return;
+	}
+
+	if (efi_get_ram_top(&ram_top) != EFI_SUCCESS) {
+		efi_err("Failed to size the poisoned-memory table!\n");
+		return;
+	}
+
+	unit_size = efi_poison_geometry(ram_top, &bitmap_size);
+
+	pm = efi_poison_alloc(bitmap_size, unit_size);
+	if (!pm) {
+		efi_err("Failed to allocate poisoned-memory table!\n");
+		return;
+	}
+
+	status = efi_bs_call(install_configuration_table,
+			     &poisoned_memory_table_guid, pm);
+	if (status != EFI_SUCCESS) {
+		efi_bs_call(free_pool, pm);
+		efi_err("Failed to install poisoned-memory config table!\n");
+	}
+}
+#endif
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index 42d6073bcd062..008635eb5027a 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -179,6 +179,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
 			 EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP);
 
 	install_memreserve_table();
+	install_poisoned_memory_table();
 
 	status = efi_boot_kernel(handle, image, image_addr, cmdline_ptr);
 
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index fd91fc15ec810..b5e19ba50ddae 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1094,6 +1094,8 @@ char *efi_convert_cmdline(efi_loaded_image_t *image);
 efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
 				bool install_cfg_tbl);
 
+efi_status_t efi_get_ram_top(u64 *top);
+
 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
 				unsigned long max);
 
@@ -1169,6 +1171,12 @@ efi_enable_reset_attack_mitigation(void) { }
 
 void efi_retrieve_eventlog(void);
 
+#ifdef CONFIG_EFI_POISONED_MEMORY
+void install_poisoned_memory_table(void);
+#else
+static inline void install_poisoned_memory_table(void) { }
+#endif
+
 struct sysfb_display_info *alloc_primary_display(void);
 struct sysfb_display_info *__alloc_primary_display(void);
 void free_primary_display(struct sysfb_display_info *dpy);
diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c
index 59f3f83de50c2..777f1f180c66e 100644
--- a/drivers/firmware/efi/libstub/mem.c
+++ b/drivers/firmware/efi/libstub/mem.c
@@ -64,6 +64,59 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
 	return EFI_SUCCESS;
 }
 
+/**
+ * efi_get_ram_top() - find the top of usable RAM
+ * @top:	on return, the end of the highest memory map entry that becomes
+ *		usable RAM
+ *
+ * Walk the UEFI memory map for the entry types that become usable RAM, the set
+ * setup_e820() maps to E820_TYPE_RAM, and return the highest address any of
+ * them reaches. Memory a confidential guest has not accepted yet counts as
+ * well, since it becomes RAM once accepted. This is what the stub has in place
+ * of max_pfn, which is only set once the kernel proper is up.
+ *
+ * Memory the firmware hot-adds later is not described by the memory map and so
+ * is not accounted for here.
+ *
+ * Return:	status code
+ */
+efi_status_t efi_get_ram_top(u64 *top)
+{
+	struct efi_boot_memmap *map __free(efi_pool) = NULL;
+	efi_status_t status;
+	u64 ram_top = 0;
+	int i, nr_desc;
+
+	status = efi_get_memory_map(&map, false);
+	if (status != EFI_SUCCESS)
+		return status;
+
+	nr_desc = map->map_size / map->desc_size;
+	for (i = 0; i < nr_desc; i++) {
+		efi_memory_desc_t *d;
+
+		d = efi_memdesc_ptr((unsigned long)map->map, map->desc_size, i);
+		switch (d->type) {
+		case EFI_LOADER_CODE:
+		case EFI_LOADER_DATA:
+		case EFI_BOOT_SERVICES_CODE:
+		case EFI_BOOT_SERVICES_DATA:
+		case EFI_CONVENTIONAL_MEMORY:
+		case EFI_UNACCEPTED_MEMORY:
+			ram_top = max(ram_top,
+				      d->phys_addr + d->num_pages * EFI_PAGE_SIZE);
+			break;
+		default:
+			break;
+		}
+	}
+	if (!ram_top)
+		return EFI_NOT_FOUND;
+
+	*top = ram_top;
+	return EFI_SUCCESS;
+}
+
 /**
  * efi_allocate_pages() - Allocate memory pages
  * @size:	minimum number of bytes to allocate
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index cef32e2c82d8f..f90de11bc8855 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -1023,6 +1023,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
 
 	setup_unaccepted_memory();
 
+	install_poisoned_memory_table();
+
 	status = exit_boot(boot_params, handle);
 	if (status != EFI_SUCCESS) {
 		efi_err("exit_boot() failed!\n");
diff --git a/drivers/firmware/efi/poison.c b/drivers/firmware/efi/poison.c
new file mode 100644
index 0000000000000..e418c6b3aab81
--- /dev/null
+++ b/drivers/firmware/efi/poison.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Runtime handling for the LINUX_EFI_POISONED_MEMORY configuration table: a
+ * bitmap with one bit per EFI_POISON_UNIT_SIZE of physical memory that records
+ * hardware-poisoned frames so the next kexec kernel can keep them out of its
+ * allocator. The stub allocates and installs the (empty) bitmap; this kernel
+ * sets bits at runtime; the next kernel reserves the set units before the
+ * allocator comes up.
+ *
+ * Copyright (c) 2026 Meta Platforms, Inc. and affiliates.
+ * Copyright (c) 2026 Breno Leitao <leitao@debian.org>
+ */
+
+#define pr_fmt(fmt) "efi: " fmt
+
+#include <linux/bitmap.h>
+#include <linux/efi.h>
+#include <linux/io.h>
+#include <linux/log2.h>
+#include <linux/memblock.h>
+#include <linux/minmax.h>
+#include <linux/mm.h>
+#include <linux/overflow.h>
+
+static struct linux_efi_poisoned_memory *efi_poison __ro_after_init;
+
+/* A non-empty bitmap on a power-of-2 grid that phys_base actually sits on. */
+static bool __init
+efi_poison_geometry_valid(const struct linux_efi_poisoned_memory *pm)
+{
+	if (!pm->size)
+		return false;
+	if (pm->unit_size < PAGE_SIZE || !is_power_of_2(pm->unit_size))
+		return false;
+
+	return IS_ALIGNED(pm->phys_base, pm->unit_size);
+}
+
+/* The range the bitmap claims to describe has to fit in a u64. */
+static bool __init
+efi_poison_range_valid(const struct linux_efi_poisoned_memory *pm)
+{
+	u64 nbits, span;
+
+	if (check_mul_overflow(pm->size, (u64)BITS_PER_BYTE, &nbits))
+		return false;
+	if (check_mul_overflow(nbits, (u64)pm->unit_size, &span))
+		return false;
+
+	return !check_add_overflow(pm->phys_base, span, &span);
+}
+
+/*
+ * The table may have been installed by an earlier kernel in the kexec chain,
+ * so check its geometry before doing any arithmetic with it.
+ */
+static bool __init
+efi_poison_table_valid(const struct linux_efi_poisoned_memory *pm)
+{
+	if (pm->version != 1) {
+		pr_warn("Ignoring poisoned-memory table with version %u\n",
+			pm->version);
+		return false;
+	}
+
+	if (!efi_poison_geometry_valid(pm) || !efi_poison_range_valid(pm)) {
+		pr_warn("Ignoring malformed poisoned-memory table\n");
+		return false;
+	}
+
+	return true;
+}
+
+static int __init efi_poison_init(void)
+{
+	struct linux_efi_poisoned_memory *pm;
+	u64 size;
+
+	if (efi.poisoned_memory == EFI_INVALID_TABLE_ADDR)
+		return 0;
+
+	/* Map the header to learn the bitmap size, then map the whole table. */
+	pm = memremap(efi.poisoned_memory, sizeof(*pm), MEMREMAP_WB);
+	if (WARN_ON_ONCE(!pm))
+		return 0;
+	if (!efi_poison_table_valid(pm)) {
+		memunmap(pm);
+		return 0;
+	}
+	size = pm->size;
+	memunmap(pm);
+
+	efi_poison = memremap(efi.poisoned_memory, sizeof(*pm) + size,
+			      MEMREMAP_WB);
+	WARN_ON_ONCE(!efi_poison);
+	return 0;
+}
+early_initcall(efi_poison_init);
+
+/* Bitmap unit covering @pfn, or -1 if the pfn falls outside the table. */
+static long efi_poison_unit(unsigned long pfn)
+{
+	phys_addr_t addr = PFN_PHYS(pfn);
+	u64 unit;
+
+	if (addr < efi_poison->phys_base)
+		return -1;
+	unit = (addr - efi_poison->phys_base) / efi_poison->unit_size;
+	if (unit >= (u64)efi_poison->size * BITS_PER_BYTE)
+		return -1;
+	return unit;
+}
+
+/*
+ * Record a hardware-poisoned frame so the next kernel keeps its unit out of the
+ * allocator. memory_failure() has already removed the frame from this kernel.
+ *
+ * A bit is never cleared: one bit stands for a whole EFI_POISON_UNIT_SIZE, so
+ * an unpoison cannot tell whether the unit as a whole is good again.
+ */
+void efi_hwpoison_record_pfn(unsigned long pfn)
+{
+	long unit;
+
+	if (!efi_poison)
+		return;
+
+	unit = efi_poison_unit(pfn);
+	if (unit < 0)
+		return;
+
+	set_bit(unit, efi_poison->bitmap);
+}
+
+void __init efi_reserve_poisoned_memory(void)
+{
+	u64 ppm = efi.poisoned_memory, phys_base, unit_size, bitmap_size, off;
+	struct linux_efi_poisoned_memory *pm;
+	unsigned int nr_units = 0;
+
+	if (ppm == EFI_INVALID_TABLE_ADDR)
+		return;
+
+	pm = early_memremap(ppm, sizeof(*pm));
+	if (!pm) {
+		pr_warn("Could not map poisoned-memory table\n");
+		return;
+	}
+
+	if (!efi_poison_table_valid(pm)) {
+		/* Keep the runtime side off a table this pass rejected. */
+		efi.poisoned_memory = EFI_INVALID_TABLE_ADDR;
+		early_memunmap(pm, sizeof(*pm));
+		return;
+	}
+
+	phys_base = pm->phys_base;
+	unit_size = pm->unit_size;
+	bitmap_size = pm->size;
+
+	early_memunmap(pm, sizeof(*pm));
+
+	/* Reserve the table itself so it survives a further kexec. */
+	memblock_reserve(PAGE_ALIGN_DOWN(ppm),
+			 PAGE_ALIGN(ppm + sizeof(*pm) + bitmap_size) -
+			 PAGE_ALIGN_DOWN(ppm));
+
+	/*
+	 * Walk the bitmap a page at a time and reserve each poisoned unit.
+	 * memblock.memory is not populated this early, so memblock_remove()
+	 * and memblock_mark_nomap() would be no-ops; a reservation is what
+	 * keeps the units away from the allocator.
+	 */
+	for (off = 0; off < bitmap_size; off += PAGE_SIZE) {
+		u64 chunk = min_t(u64, PAGE_SIZE, bitmap_size - off);
+		unsigned long bit, nbits = chunk * BITS_PER_BYTE;
+		unsigned long *map;
+
+		map = early_memremap(ppm + offsetof(struct linux_efi_poisoned_memory,
+						    bitmap) + off, chunk);
+		if (!map) {
+			pr_warn("Could not map poisoned-memory bitmap\n");
+			return;
+		}
+		for_each_set_bit(bit, map, nbits) {
+			u64 unit = off * BITS_PER_BYTE + bit;
+
+			memblock_reserve(phys_base + unit * unit_size, unit_size);
+			nr_units++;
+		}
+		early_memunmap(map, chunk);
+	}
+
+	if (nr_units)
+		pr_info("reserved %u poisoned unit(s) (%lluK each) inherited across kexec\n",
+			nr_units, unit_size >> 10);
+}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index ccbc35479684a..3cb3f224ac02b 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -23,6 +23,7 @@
 #include <linux/pstore.h>
 #include <linux/range.h>
 #include <linux/reboot.h>
+#include <linux/sizes.h>
 #include <linux/uuid.h>
 
 #include <asm/page.h>
@@ -422,6 +423,7 @@ void efi_native_runtime_setup(void);
 #define LINUX_EFI_COCO_SECRET_AREA_GUID		EFI_GUID(0xadf956ad, 0xe98c, 0x484c,  0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47)
 #define LINUX_EFI_BOOT_MEMMAP_GUID		EFI_GUID(0x800f683f, 0xd08b, 0x423a,  0xa2, 0x93, 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
 #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID	EFI_GUID(0xd5d1de3c, 0x105c, 0x44f9,  0x9e, 0xa9, 0xbc, 0xef, 0x98, 0x12, 0x00, 0x31)
+#define LINUX_EFI_POISONED_MEMORY_TABLE_GUID	EFI_GUID(0x78a5bf07, 0x7d2a, 0x2889,  0x16, 0x31, 0x63, 0xd4, 0x56, 0xf2, 0x83, 0x50)
 
 #define RISCV_EFI_BOOT_PROTOCOL_GUID		EFI_GUID(0xccd15fec, 0x6f73, 0x4eec,  0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
 
@@ -650,6 +652,7 @@ extern struct efi {
 	unsigned long			mokvar_table;		/* MOK variable config table */
 	unsigned long			coco_secret;		/* Confidential computing secret table */
 	unsigned long			unaccepted;		/* Unaccepted memory table */
+	unsigned long			poisoned_memory;	/* Hardware-poisoned memory table */
 
 	efi_get_time_t			*get_time;
 	efi_set_time_t			*set_time;
@@ -1269,6 +1272,24 @@ struct linux_efi_memreserve {
 #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
 	/ sizeof_field(struct linux_efi_memreserve, entry[0]))
 
+struct linux_efi_poisoned_memory {
+	u32		version;
+	u32		unit_size;	/* bytes of phys space per bitmap bit */
+	u64		phys_base;	/* phys address covered by bit 0 */
+	u64		size;		/* bitmap size in bytes */
+	unsigned long	bitmap[];
+};
+
+#define EFI_POISON_UNIT_SIZE	SZ_2M
+
+#ifdef CONFIG_EFI_POISONED_MEMORY
+void efi_reserve_poisoned_memory(void);
+void efi_hwpoison_record_pfn(unsigned long pfn);
+#else
+static inline void efi_reserve_poisoned_memory(void) { }
+static inline void efi_hwpoison_record_pfn(unsigned long pfn) { }
+#endif
+
 void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size);
 
 /*
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index a8b03e2920ba8..1cc4e92e98748 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -43,6 +43,7 @@
 #include <linux/sched/signal.h>
 #include <linux/sched/task.h>
 #include <linux/dax.h>
+#include <linux/efi.h>
 #include <linux/ksm.h>
 #include <linux/rmap.h>
 #include <linux/export.h>
@@ -1286,6 +1287,8 @@ static int action_result(unsigned long pfn, enum mf_action_page_type type,
 	if (type != MF_MSG_ALREADY_POISONED && type != MF_MSG_PFN_MAP) {
 		num_poisoned_pages_inc(pfn);
 		update_per_node_mf_stats(pfn, result);
+		/* Only hard offlines are carried over to the next kernel. */
+		efi_hwpoison_record_pfn(pfn);
 	}
 
 	pr_err("%#lx: recovery action for %s: %s\n",

3/2 2026/08/21 10:58 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 9154
							output: 23
							thoughts: 354
						

Thoughts:
**My Assessment of the Hardware Poisoned Page Kexec Patch**

Okay, so we have a patch that's attempting to propagate hardware-poisoned memory pages across a kexec reboot using an EFI configuration table. Interesting approach, I'll need to dig into the nuances of this to see if it's adding any value and if there are any risks. It looks like the core of the implementation is in `drivers/firmware/efi/poison.c`, which is good; separating the logic from the core EFI stub is sound. The `Kconfig` change and the hook into `mm/memory-failure.c` are also expected. Specifically calling `efi_hwpoison_record_pfn(pfn)` seems like the crucial step when a page is flagged as poisoned. Then the EFI stub is being modified to install this poisoned memory table.

Alright, let's think about reachability. I can trigger `mm/memory-failure.c` with injected memory failures through `madvise` or sysfs, that should be straightforward. And, since it’s EFI based, we need to boot the kernel via EFI, which is the standard way of doing things. The real question is: is `efi_reserve_poisoned_memory` called correctly during the boot sequence, and whether the other bits and pieces are correctly implemented?

Is fuzzing this worthwhile? Absolutely. It touches new code paths in both memory failure handling and EFI boot. The new functions are: `efi_hwpoison_record_pfn`, `efi_reserve_poisoned_memory`, `efi_poison_init`, `install_poisoned_memory_table`, and `efi_get_ram_top`. These are all potential targets.

Before I go too far, I should check the dependencies. So, it's not just `CONFIG_EFI_POISONED_MEMORY` that’s needed, it depends on `EFI_STUB && MEMORY_FAILURE && 64BIT`. So we have to make sure we enable those configs too.

Now, a quick grep for `efi_hwpoison_record_pfn` across the codebase should quickly reveal the call sites and any dependencies I might have missed. That'll be my next step before a deep dive.



4/2 2026/08/21 10:58 tool grepper
0m Args:
{
  "Expression": "efi_hwpoison_record_pfn"
}

Results:
{
  "Output": "drivers/firmware/efi/poison.c=101=static long efi_poison_unit(unsigned long pfn)\n--\ndrivers/firmware/efi/poison.c-120- */\ndrivers/firmware/efi/poison.c:121:void efi_hwpoison_record_pfn(unsigned long pfn)\ndrivers/firmware/efi/poison.c-122-{\n--\ninclude/linux/efi.h=1286=void efi_reserve_poisoned_memory(void);\ninclude/linux/efi.h:1287:void efi_hwpoison_record_pfn(unsigned long pfn);\ninclude/linux/efi.h-1288-#else\ninclude/linux/efi.h=1289=static inline void efi_reserve_poisoned_memory(void) { }\ninclude/linux/efi.h:1290:static inline void efi_hwpoison_record_pfn(unsigned long pfn) { }\ninclude/linux/efi.h-1291-#endif\n--\nmm/memory-failure.c=1282=static int action_result(unsigned long pfn, enum mf_action_page_type type,\n--\nmm/memory-failure.c-1290-\t\t/* Only hard offlines are carried over to the next kernel. */\nmm/memory-failure.c:1291:\t\tefi_hwpoison_record_pfn(pfn);\nmm/memory-failure.c-1292-\t}\n"
}

5/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 10386
							output: 22
							thoughts: 71
						

Thoughts:
**My Focus: EFI Memory Poisoning Functions**

Okay, so I need to get my head around this EFI memory poisoning functionality. Right now, I'm thinking I should really concentrate on a few key functions to understand the architecture: `efi_hwpoison_record_pfn`, `efi_reserve_poisoned_memory`, `install_poisoned_memory_table`, and `efi_get_ram_top`. These are probably the core building blocks of how this whole memory poisoning system works. Before I dig too deep though, I should first determine whether `install_poisoned_memory_table` is static or not, as this will influence its scope and where it might be called from. That's my next quick check.



6/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "install_poisoned_memory_table"
}

Results:
{
  "Output": "drivers/firmware/efi/libstub/efi-stub-helper.c=805=static struct linux_efi_poisoned_memory *efi_poison_alloc(u64 bitmap_size,\n--\ndrivers/firmware/efi/libstub/efi-stub-helper.c-828- */\ndrivers/firmware/efi/libstub/efi-stub-helper.c:829:void install_poisoned_memory_table(void)\ndrivers/firmware/efi/libstub/efi-stub-helper.c-830-{\n--\ndrivers/firmware/efi/libstub/efi-stub.c=153=efi_status_t efi_stub_common(efi_handle_t handle,\n--\ndrivers/firmware/efi/libstub/efi-stub.c-181-\tinstall_memreserve_table();\ndrivers/firmware/efi/libstub/efi-stub.c:182:\tinstall_poisoned_memory_table();\ndrivers/firmware/efi/libstub/efi-stub.c-183-\n--\ndrivers/firmware/efi/libstub/efistub.h=1172=void efi_retrieve_eventlog(void);\n--\ndrivers/firmware/efi/libstub/efistub.h-1174-#ifdef CONFIG_EFI_POISONED_MEMORY\ndrivers/firmware/efi/libstub/efistub.h:1175:void install_poisoned_memory_table(void);\ndrivers/firmware/efi/libstub/efistub.h-1176-#else\ndrivers/firmware/efi/libstub/efistub.h:1177:static inline void install_poisoned_memory_table(void) { }\ndrivers/firmware/efi/libstub/efistub.h-1178-#endif\n--\ndrivers/firmware/efi/libstub/x86-stub.c=912=void __noreturn efi_stub_entry(efi_handle_t handle,\n--\ndrivers/firmware/efi/libstub/x86-stub.c-1025-\ndrivers/firmware/efi/libstub/x86-stub.c:1026:\tinstall_poisoned_memory_table();\ndrivers/firmware/efi/libstub/x86-stub.c-1027-\n"
}

7/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 11216
							output: 19
							thoughts: 125
						

Thoughts:
**Analyzing EFI Memory Poisoning Functions**

Okay, so I'm looking at some EFI-related kernel code. I'm seeing a few functions related to memory poisoning, and I want to get a better understanding of how they fit together. First, I've got `install_poisoned_memory_table`, which seems to be involved in the installation process and is defined in `drivers/firmware/efi/libstub/efi-stub-helper.c`. Then, I have `efi_get_ram_top` in `drivers/firmware/efi/libstub/mem.c`, which is probably for determining the top of usable RAM. That makes sense, as memory poisoning needs to know the boundaries of the memory it can play with.  And finally, I've got `efi_reserve_poisoned_memory` and `efi_hwpoison_record_pfn` in `drivers/firmware/efi/poison.c`. Those seem like the core of the poisoning mechanism itself.  It looks like I need to delve into `poison.c` and figure out how these functions work together to achieve memory poisoning. But before I dive too deep, I want to make sure I understand the scope of `efi_poison_init`. Let's confirm whether that function is declared static to gauge its reach.



8/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "efi_poison_init"
}

Results:
{
  "Output": "drivers/firmware/efi/poison.c=58=efi_poison_table_valid(const struct linux_efi_poisoned_memory *pm)\n--\ndrivers/firmware/efi/poison.c-73-\ndrivers/firmware/efi/poison.c:74:static int __init efi_poison_init(void)\ndrivers/firmware/efi/poison.c-75-{\n--\ndrivers/firmware/efi/poison.c-97-}\ndrivers/firmware/efi/poison.c:98:early_initcall(efi_poison_init);\ndrivers/firmware/efi/poison.c-99-\n"
}

9/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 11805
							output: 19
							thoughts: 20
						

Thoughts:
**Checking the Static Nature of a Function**

Okay, here's what I'm thinking. This situation feels...fixed. Stagnant. I need to figure out why. Ah, a possible lead! Let me check something: is this `efi_poison_alloc` function declared as static? That might explain the observed behavior, if it's got restricted scope. I need to verify that declaration to understand what's happening.



10/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "efi_poison_alloc"
}

Results:
{
  "Output": "drivers/firmware/efi/libstub/efi-stub-helper.c=789=static u32 efi_poison_geometry(u64 ram_top, u64 *bitmap_size)\n--\ndrivers/firmware/efi/libstub/efi-stub-helper.c-804-/* ACPI reclaim memory, so the next kernel does not treat it as free RAM. */\ndrivers/firmware/efi/libstub/efi-stub-helper.c:805:static struct linux_efi_poisoned_memory *efi_poison_alloc(u64 bitmap_size,\ndrivers/firmware/efi/libstub/efi-stub-helper.c-806-\t\t\t\t\t\t\t  u32 unit_size)\n--\ndrivers/firmware/efi/libstub/efi-stub-helper.c=829=void install_poisoned_memory_table(void)\n--\ndrivers/firmware/efi/libstub/efi-stub-helper.c-851-\ndrivers/firmware/efi/libstub/efi-stub-helper.c:852:\tpm = efi_poison_alloc(bitmap_size, unit_size);\ndrivers/firmware/efi/libstub/efi-stub-helper.c-853-\tif (!pm) {\n"
}

11/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 12252
							output: 22
							thoughts: 511
						

Thoughts:
**My Analysis of EFI Poisoned Memory for Fuzzing**

Okay, so I've got a new target: EFI poisoned memory. It looks like the core logic revolves around these functions: `efi_hwpoison_record_pfn`, `efi_reserve_poisoned_memory`, `install_poisoned_memory_table`, and `efi_get_ram_top`.

I see that `install_poisoned_memory_table` and `efi_get_ram_top` are part of the EFI stub, which is a bit of a tricky area. Syzkaller can run the EFI stub if we boot via EFI, but it's generally not the direct target of fuzzing. Instead, we're likely fuzzing the kernel's interaction with the EFI tables, and that's where `efi_reserve_poisoned_memory` and `efi_poison_init` come into play. `efi_hwpoison_record_pfn` specifically deals with memory failures, getting called from `action_result` in `mm/memory-failure.c`.

Let's quickly confirm what configs are needed, and make sure that we can be comprehensive. It looks like `EFI_POISONED_MEMORY` alone should be sufficient, as it depends on `EFI_STUB`, `MEMORY_FAILURE`, and `64BIT`, so we don't have to specify all of those. I should double-check that `MEMORY_FAILURE` and `EFI_STUB` are enabled, but `EFI_POISONED_MEMORY` is the critical one.

I've confirmed that `EFI_POISONED_MEMORY` is indeed the main one.

Given that `efi_hwpoison_record_pfn` handles an `unsigned long pfn`, that's an interesting interface to target. It's definitely worth fuzzing; it adds new logic around memory-failure and EFI boot.

**So the key configurations are `EFI_POISONED_MEMORY` and the main focus symbols should be:**

*   `efi_hwpoison_record_pfn`
*   `efi_reserve_poisoned_memory`
*   `install_poisoned_memory_table`
*   `efi_get_ram_top`



12/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "config EFI_POISONED_MEMORY"
}

Results:
{
  "Output": "drivers/firmware/efi/Kconfig=251=config EFI_COCO_SECRET\n--\ndrivers/firmware/efi/Kconfig-265-\ndrivers/firmware/efi/Kconfig:266:config EFI_POISONED_MEMORY\ndrivers/firmware/efi/Kconfig-267-\tbool \"Carry hardware-poisoned pages across kexec\"\n"
}

13/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 13370
							output: 17
							thoughts: 31
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Adding EFI_POISONED_MEMORY and Verification of Action_Result's Static Nature**

Alright, I'm going to add `EFI_POISONED_MEMORY` to the `EnableConfigs`. This seems like a straightforward step, but it's crucial for the intended functionality. Before I proceed any further, I need to confirm something critical about `action_result`. I *really* need to be sure that `action_result` is, in fact, a static variable. The potential implications of it being otherwise are not something I want to think about right now. I have to go back and verify that immediately, and I have my tools ready to go. I just need to make sure I am on the right track before committing any changes.



14/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "action_result"
}

Results:
{
  "Output": "include/trace/events/oom.h=183=TRACE_EVENT(compact_retry,\n--\ninclude/trace/events/oom.h-211-\ninclude/trace/events/oom.h:212:\tTP_printk(\"order=%d priority=%s compaction_result=%s retries=%d max_retries=%d should_retry=%d\",\ninclude/trace/events/oom.h-213-\t\t\t__entry-\u003eorder,\n--\nmm/memory-failure.c=1269=static bool panic_on_unrecoverable_mf(enum mf_action_page_type type,\n--\nmm/memory-failure.c-1281- */\nmm/memory-failure.c:1282:static int action_result(unsigned long pfn, enum mf_action_page_type type,\nmm/memory-failure.c-1283-\t\t\t enum mf_result result)\n--\nmm/memory-failure.c=1303=static int page_action(struct page_state *ps, struct page *p,\n--\nmm/memory-failure.c-1315-\nmm/memory-failure.c:1316:\treturn action_result(pfn, ps-\u003etype, result);\nmm/memory-failure.c-1317-}\n--\nmm/memory-failure.c=2084=static int try_memory_failure_hugetlb(unsigned long pfn, int flags)\n--\nmm/memory-failure.c-2101-\t\t}\nmm/memory-failure.c:2102:\t\treturn action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);\nmm/memory-failure.c-2103-\tcase MF_HUGETLB_FOLIO_PRE_POISONED:\n--\nmm/memory-failure.c-2108-\t\tif (res == MF_HUGETLB_PAGE_PRE_POISONED)\nmm/memory-failure.c:2109:\t\t\taction_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);\nmm/memory-failure.c-2110-\t\telse\nmm/memory-failure.c:2111:\t\t\taction_result(pfn, MF_MSG_HUGE, MF_FAILED);\nmm/memory-failure.c-2112-\t\treturn rv;\n--\nmm/memory-failure.c-2142-\t\t}\nmm/memory-failure.c:2143:\t\treturn action_result(pfn, MF_MSG_FREE_HUGE, res);\nmm/memory-failure.c-2144-\t}\n--\nmm/memory-failure.c-2149-\t\tfolio_unlock(folio);\nmm/memory-failure.c:2150:\t\treturn action_result(pfn, MF_MSG_UNMAP_FAILED, MF_FAILED);\nmm/memory-failure.c-2151-\t}\n--\nmm/memory-failure.c=2177=static int memory_failure_dev_pagemap(unsigned long pfn, int flags,\n--\nmm/memory-failure.c-2204-\tif (rc != -EOPNOTSUPP)\nmm/memory-failure.c:2205:\t\taction_result(pfn, MF_MSG_DAX, rc ? MF_FAILED : MF_RECOVERED);\nmm/memory-failure.c-2206-\treturn rc;\n--\nmm/memory-failure.c=2323=static int memory_failure_pfn(unsigned long pfn, int flags)\n--\nmm/memory-failure.c-2347-\t\tif (!mf_handled)\nmm/memory-failure.c:2348:\t\t\treturn action_result(pfn, MF_MSG_PFN_MAP, MF_IGNORED);\nmm/memory-failure.c-2349-\t}\n--\nmm/memory-failure.c-2360-\nmm/memory-failure.c:2361:\treturn action_result(pfn, MF_MSG_PFN_MAP, MF_RECOVERED);\nmm/memory-failure.c-2362-}\n--\nmm/memory-failure.c=2389=int memory_failure(unsigned long pfn, int flags)\n--\nmm/memory-failure.c-2447-\t\t\tput_page(p);\nmm/memory-failure.c:2448:\t\taction_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED);\nmm/memory-failure.c-2449-\t\tgoto unlock_mutex;\n--\nmm/memory-failure.c-2478-\t\t\t}\nmm/memory-failure.c:2479:\t\t\tres = action_result(pfn, MF_MSG_BUDDY, res);\nmm/memory-failure.c-2480-\t\t} else {\nmm/memory-failure.c:2481:\t\t\tres = action_result(pfn, MF_MSG_KERNEL_HIGH_ORDER, MF_IGNORED);\nmm/memory-failure.c-2482-\t\t}\n--\nmm/memory-failure.c-2492-\t\t */\nmm/memory-failure.c:2493:\t\tres = action_result(pfn, MF_MSG_KERNEL, MF_IGNORED);\nmm/memory-failure.c-2494-\t\tgoto unlock_mutex;\n--\nmm/memory-failure.c-2496-\t\t/* Transient lifecycle race with the page allocator. */\nmm/memory-failure.c:2497:\t\tres = action_result(pfn, MF_MSG_GET_HWPOISON, MF_IGNORED);\nmm/memory-failure.c-2498-\t\tgoto unlock_mutex;\n--\nmm/memory-failure.c-2544-\t\t\tput_page(p);\nmm/memory-failure.c:2545:\t\t\taction_result(pfn, MF_MSG_UNSPLIT_THP, MF_FAILED);\nmm/memory-failure.c-2546-\t\t\tgoto unlock_mutex;\n--\nmm/memory-failure.c-2598-\tif (!hwpoison_user_mappings(folio, p, pfn, flags)) {\nmm/memory-failure.c:2599:\t\tres = action_result(pfn, MF_MSG_UNMAP_FAILED, MF_FAILED);\nmm/memory-failure.c-2600-\t\tgoto unlock_page;\n--\nmm/memory-failure.c-2607-\t    folio-\u003emapping == NULL) {\nmm/memory-failure.c:2608:\t\tres = action_result(pfn, MF_MSG_TRUNCATED_LRU, MF_IGNORED);\nmm/memory-failure.c-2609-\t\tgoto unlock_page;\n"
}

15/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 15273
							output: 22
							thoughts: 70
						

Thoughts:
**My Current Focus: UEFI Poisoned Memory Functions**

Okay, so I'm digging into this UEFI memory poisoning implementation. My attention is drawn to a specific set of functions: `efi_hwpoison_record_pfn`, `efi_reserve_poisoned_memory`, `install_poisoned_memory_table`, and `efi_get_ram_top`. These appear to be the core building blocks for marking and handling memory regions that are, for some reason, considered "poisoned" – likely signifying some sort of hardware issue or a region that needs special handling.

My immediate question, as I delve deeper, is about the scope and lifecycle of these memory reservations. Specifically, I need to know if `efi_reserve_poisoned_memory` is a static function. Knowing this is crucial because it informs how the poisoned memory is declared and subsequently handled by the system. If it is static, then my concerns regarding the scope of the variable are alleviated. I will begin by verifying the declaration of that function.



16/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "efi_reserve_poisoned_memory"
}

Results:
{
  "Output": "drivers/firmware/efi/efi.c=715=int __init efi_config_parse_tables(const efi_config_table_t *config_tables,\n--\ndrivers/firmware/efi/efi.c-814-\ndrivers/firmware/efi/efi.c:815:\tefi_reserve_poisoned_memory();\ndrivers/firmware/efi/efi.c-816-\n--\ndrivers/firmware/efi/poison.c=121=void efi_hwpoison_record_pfn(unsigned long pfn)\n--\ndrivers/firmware/efi/poison.c-134-\ndrivers/firmware/efi/poison.c:135:void __init efi_reserve_poisoned_memory(void)\ndrivers/firmware/efi/poison.c-136-{\n--\ninclude/linux/efi.h=1275=struct linux_efi_poisoned_memory {\n--\ninclude/linux/efi.h-1285-#ifdef CONFIG_EFI_POISONED_MEMORY\ninclude/linux/efi.h:1286:void efi_reserve_poisoned_memory(void);\ninclude/linux/efi.h-1287-void efi_hwpoison_record_pfn(unsigned long pfn);\ninclude/linux/efi.h-1288-#else\ninclude/linux/efi.h:1289:static inline void efi_reserve_poisoned_memory(void) { }\ninclude/linux/efi.h-1290-static inline void efi_hwpoison_record_pfn(unsigned long pfn) { }\n"
}

17/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 15982
							output: 19
							thoughts: 357
						

Thoughts:
**My Analysis of EFI Poisoned Memory Configuration**

Okay, so I've been digging into the EFI poisoned memory implementation, and it's becoming clear how to enable it properly. First, I confirmed that `efi_reserve_poisoned_memory`, `efi_hwpoison_record_pfn`, `install_poisoned_memory_table`, and `efi_get_ram_top` are *not* static, so those are definitely the functions of interest. I'll need to focus on those. I double-checked to be sure, but the static functions, like `efi_poison_init`, `efi_poison_table_valid`, `efi_poison_geometry_valid`, `efi_poison_range_valid`, `efi_poison_unit`, `efi_poison_geometry`, and `efi_poison_alloc` aren't part of this configuration issue.

Now, let's look at the configuration dependencies. It looks like `EFI_POISONED_MEMORY` depends on `EFI_STUB`, `MEMORY_FAILURE`, and `64BIT`. That makes sense; if `MEMORY_FAILURE` isn't enabled, `EFI_POISONED_MEMORY` won't be either, and vice versa. I should include `MEMORY_FAILURE` and `EFI_STUB` just to be safe. I should double check `EFI_STUB`'s location in `drivers/firmware/efi/Kconfig`, just to be certain.



18/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "config EFI_STUB"
}

Results:
{
  "Output": "arch/arm/Kconfig=1592=config AUTO_ZRELADDR\n--\narch/arm/Kconfig-1602-\narch/arm/Kconfig:1603:config EFI_STUB\narch/arm/Kconfig-1604-\tbool\n--\narch/arm64/Kconfig=2465=endchoice\narch/arm64/Kconfig-2466-\narch/arm64/Kconfig:2467:config EFI_STUB\narch/arm64/Kconfig-2468-\tbool\n--\narch/loongarch/Kconfig=498=config EFI\n--\narch/loongarch/Kconfig-505-\narch/loongarch/Kconfig:506:config EFI_STUB\narch/loongarch/Kconfig-507-\tbool \"EFI boot stub support\"\n--\narch/riscv/Kconfig=1249=endchoice\narch/riscv/Kconfig-1250-\narch/riscv/Kconfig:1251:config EFI_STUB\narch/riscv/Kconfig-1252-\tbool\n--\narch/x86/Kconfig=1881=config EFI\n--\narch/x86/Kconfig-1898-\narch/x86/Kconfig:1899:config EFI_STUB\narch/x86/Kconfig-1900-\tbool \"EFI stub support\"\n"
}

19/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 17043
							output: 19
							thoughts: 37
						

Thoughts:
Okay, here's my interpretation of those thoughts, presented as a personal thought process, as requested:

**Navigating Kernel Configuration**

Alright, so I'm thinking about kernel configurations. Specifically, I've got `EFI_STUB` and `MEMORY_FAILURE` on my mind. I know both are configuration options, but I need to understand them better in context. `EFI_STUB` is a pretty standard option.

My instinct is to dive into the kernel source, and I figure the place to start with `MEMORY_FAILURE` is the memory management area. So, let's head over to `mm/Kconfig` and see what's defined there. That's usually the best place to find the detailed description and dependencies for any memory related config options. I'm sure I'll find the information I need to understand what `MEMORY_FAILURE` is all about, and how it fits into the broader kernel design.



20/2 2026/08/21 10:59 tool grepper
0m Args:
{
  "Expression": "config MEMORY_FAILURE"
}

Results:
{
  "Output": "mm/Kconfig=762=config ARCH_SUPPORTS_MEMORY_FAILURE\n--\nmm/Kconfig-764-\nmm/Kconfig:765:config MEMORY_FAILURE\nmm/Kconfig-766-\tdepends on MMU\n"
}

21/2 2026/08/21 10:59 llm patch-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 17371
							output: 186
							thoughts: 265
						

Thoughts:
**My Assessment of the EFI Memory Poisoning Patch**

Okay, so I'm looking at this patch and mentally organizing the key configurations. We're dealing with `EFI_POISONED_MEMORY`, `MEMORY_FAILURE`, and `EFI_STUB`. Hang on... `EFI_STUB` and `MEMORY_FAILURE` are booleans, that's important to note. Right, I need to add all three to the `EnableConfigs` list. Makes sense.

Now, let's recap the rationale here. The core of this patch centers on handling hardware-poisoned memory across kexec using an EFI configuration table. We're introducing a new EFI table to store the bitmap of poisoned memory, and there are hooks within `memory-failure.c` to record the poisoned pages. There are also hooks into the EFI stub for table allocation and installation. The critical thing is, this logic is triggered both during EFI boot *and* when memory failures are explicitly injected, for example, via `madvise(MADV_HWPOISON)`. Clever.

This looks like a solid contribution. The `WorthFuzzing` flag is set to true, which is good. That's a strong indication that this area is likely to have security implications. I see that the `FocusSymbols` are: `efi_hwpoison_record_pfn`, `efi_reserve_poisoned_memory`, `install_poisoned_memory_table`, and `efi_get_ram_top`. These are all logical and expected choices, targeting the core functions.

Alright, that's enough for my initial review. Time to record the results of my assessment.



22/2 2026/08/21 10:59 tool set-results
0m Args:
{
  "EnableConfigs": [
    "EFI_POISONED_MEMORY",
    "MEMORY_FAILURE",
    "EFI_STUB"
  ],
  "FocusSymbols": [
    "efi_hwpoison_record_pfn",
    "efi_reserve_poisoned_memory",
    "install_poisoned_memory_table",
    "efi_get_ram_top"
  ],
  "Reasoning": "The patch adds support for carrying hardware-poisoned pages across kexec via an EFI configuration table. It introduces a new EFI config table to store the poisoned memory bitmap, hooks into `memory-failure.c` to record poisoned pages, and hooks into the EFI stub to allocate and install the table. The new logic is reachable during EFI boot and when memory failures are injected (e.g., via madvise MADV_HWPOISON).",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "EFI_POISONED_MEMORY",
    "MEMORY_FAILURE",
    "EFI_STUB"
  ],
  "FocusSymbols": [
    "efi_hwpoison_record_pfn",
    "efi_reserve_poisoned_memory",
    "install_poisoned_memory_table",
    "efi_get_ram_top"
  ],
  "Reasoning": "The patch adds support for carrying hardware-poisoned pages across kexec via an EFI configuration table. It introduces a new EFI config table to store the poisoned memory bitmap, hooks into `memory-failure.c` to record poisoned pages, and hooks into the EFI stub to allocate and install the table. The new logic is reachable during EFI boot and when memory failures are injected (e.g., via madvise MADV_HWPOISON).",
  "WorthFuzzing": true
}

23/1 2026/08/21 10:59 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

24/2 2026/08/21 10:59 agent kmsan-evaluator
0m Model:
best-expensive

Args:
null

Results:
{
  "KMSANReasoning": "The patch introduces a mechanism to carry hardware-poisoned pages across kexec using an EFI configuration table. The newly introduced structure `linux_efi_poisoned_memory` is allocated in `efi_poison_alloc()` and all its fields, including the flexible `bitmap` array, are explicitly initialized (the fields are assigned and the bitmap is zeroed using `memset`). There is no structure padding that could leak uninitialized memory, and this table is not copied to user space. The changes do not introduce any risk of uninitialized memory reads or info-leaks. Any potential memory corruption, out-of-bounds accesses, or use-after-free bugs related to the bitmap handling would be caught by standard KASAN. Therefore, a dedicated KMSAN fuzzing session is not necessary.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
For your convenience, here is the diff of the changes:
commit ac3651c68b7ae071f45de77bc9fb4d79044fa09c
Author: syz-cluster <triage@syzkaller.com>
Date:   Fri Aug 21 10:58:50 2026 +0000

    syz-cluster: applied patch under review

diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 29e0729299f5b..69c0dc02bc112 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -263,6 +263,16 @@ config EFI_COCO_SECRET
 	  virt/coco/efi_secret module to access the secrets, which in turn
 	  allows userspace programs to access the injected secrets.
 
+config EFI_POISONED_MEMORY
+	bool "Carry hardware-poisoned pages across kexec"
+	depends on EFI_STUB && MEMORY_FAILURE && 64BIT
+	help
+	  Record page frames that are hardware-poisoned while this kernel runs
+	  into an EFI configuration table, and honor that table early on the
+	  next kernel so a kexec does not hand known-bad RAM back out.
+
+	  If unsure, say N.
+
 config OVMF_DEBUG_LOG
 	bool "Expose OVMF firmware debug log via sysfs"
 	depends on EFI
diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile
index 8efbcf699e4ff..05d0a490923e5 100644
--- a/drivers/firmware/efi/Makefile
+++ b/drivers/firmware/efi/Makefile
@@ -43,4 +43,5 @@ obj-$(CONFIG_EFI_EARLYCON)		+= earlycon.o
 obj-$(CONFIG_UEFI_CPER_ARM)		+= cper-arm.o
 obj-$(CONFIG_UEFI_CPER_X86)		+= cper-x86.o
 obj-$(CONFIG_UNACCEPTED_MEMORY)		+= unaccepted_memory.o
+obj-$(CONFIG_EFI_POISONED_MEMORY)	+= poison.o
 obj-$(CONFIG_TEE_STMM_EFI)		+= stmm/tee_stmm_efi.o
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 0327a39d31fa5..7474eeebb0add 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -55,6 +55,9 @@ struct efi __read_mostly efi = {
 #ifdef CONFIG_UNACCEPTED_MEMORY
 	.unaccepted		= EFI_INVALID_TABLE_ADDR,
 #endif
+#ifdef CONFIG_EFI_POISONED_MEMORY
+	.poisoned_memory	= EFI_INVALID_TABLE_ADDR,
+#endif
 };
 EXPORT_SYMBOL(efi);
 
@@ -646,6 +649,9 @@ static const efi_config_table_type_t common_tables[] __initconst = {
 #ifdef CONFIG_UNACCEPTED_MEMORY
 	{LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID,	&efi.unaccepted,	"Unaccepted"	},
 #endif
+#ifdef CONFIG_EFI_POISONED_MEMORY
+	{LINUX_EFI_POISONED_MEMORY_TABLE_GUID,	&efi.poisoned_memory,	"POISON"	},
+#endif
 #ifdef CONFIG_EFI_GENERIC_STUB
 	{LINUX_EFI_PRIMARY_DISPLAY_TABLE_GUID,	&primary_display_table			},
 #endif
@@ -806,6 +812,8 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables,
 		}
 	}
 
+	efi_reserve_poisoned_memory();
+
 	if (rt_prop != EFI_INVALID_TABLE_ADDR) {
 		efi_rt_properties_table_t *tbl;
 
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index f27f2e1f00199..7258ecdf1f7c2 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -774,3 +774,92 @@ void efi_remap_image(unsigned long image_base, unsigned alloc_size,
 			efi_warn("Failed to remap data region non-executable\n");
 	}
 }
+
+#ifdef CONFIG_EFI_POISONED_MEMORY
+/* Cap on the bitmap; a span too wide to fit gets a coarser unit instead. */
+#define EFI_POISON_MAX_TABLE_SIZE	SZ_1M
+#define EFI_POISON_MAX_UNIT_SIZE	SZ_1G
+
+/*
+ * Bitmap geometry for a given top of RAM. The bitmap starts at address 0, so
+ * bit N covers unit N.
+ * In the following code, a "unit" is granule of physical address space that one
+ * bitmap bit covers.
+ */
+static u32 efi_poison_geometry(u64 ram_top, u64 *bitmap_size)
+{
+	u64 nr_units = DIV_ROUND_UP(ram_top, EFI_POISON_UNIT_SIZE);
+	u32 unit_size = EFI_POISON_UNIT_SIZE;
+
+	while (DIV_ROUND_UP(nr_units, BITS_PER_BYTE) > EFI_POISON_MAX_TABLE_SIZE &&
+	       unit_size < EFI_POISON_MAX_UNIT_SIZE) {
+		nr_units = DIV_ROUND_UP(nr_units, 2);
+		unit_size *= 2;
+	}
+
+	*bitmap_size = DIV_ROUND_UP(nr_units, BITS_PER_BYTE);
+	return unit_size;
+}
+
+/* ACPI reclaim memory, so the next kernel does not treat it as free RAM. */
+static struct linux_efi_poisoned_memory *efi_poison_alloc(u64 bitmap_size,
+							  u32 unit_size)
+{
+	struct linux_efi_poisoned_memory *pm;
+	efi_status_t status;
+
+	status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
+			     sizeof(*pm) + bitmap_size, (void **)&pm);
+	if (status != EFI_SUCCESS)
+		return NULL;
+
+	pm->version = 1;
+	pm->unit_size = unit_size;
+	pm->phys_base = 0;
+	pm->size = bitmap_size;
+	memset(pm->bitmap, 0, bitmap_size);
+
+	return pm;
+}
+
+/*
+ * Allocate and install the poisoned-memory bitmap while boot services are
+ * available
+ */
+void install_poisoned_memory_table(void)
+{
+	efi_guid_t poisoned_memory_table_guid = LINUX_EFI_POISONED_MEMORY_TABLE_GUID;
+	struct linux_efi_poisoned_memory *pm;
+	u64 ram_top, bitmap_size;
+	efi_status_t status;
+	u32 unit_size;
+
+	/* A table installed by an earlier boot rides the system table across kexec. */
+	pm = get_efi_config_table(poisoned_memory_table_guid);
+	if (pm) {
+		if (pm->version != 1)
+			efi_err("Unknown version of poisoned-memory table\n");
+		return;
+	}
+
+	if (efi_get_ram_top(&ram_top) != EFI_SUCCESS) {
+		efi_err("Failed to size the poisoned-memory table!\n");
+		return;
+	}
+
+	unit_size = efi_poison_geometry(ram_top, &bitmap_size);
+
+	pm = efi_poison_alloc(bitmap_size, unit_size);
+	if (!pm) {
+		efi_err("Failed to allocate poisoned-memory table!\n");
+		return;
+	}
+
+	status = efi_bs_call(install_configuration_table,
+			     &poisoned_memory_table_guid, pm);
+	if (status != EFI_SUCCESS) {
+		efi_bs_call(free_pool, pm);
+		efi_err("Failed to install poisoned-memory config table!\n");
+	}
+}
+#endif
diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
index 42d6073bcd062..008635eb5027a 100644
--- a/drivers/firmware/efi/libstub/efi-stub.c
+++ b/drivers/firmware/efi/libstub/efi-stub.c
@@ -179,6 +179,7 @@ efi_status_t efi_stub_common(efi_handle_t handle,
 			 EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP);
 
 	install_memreserve_table();
+	install_poisoned_memory_table();
 
 	status = efi_boot_kernel(handle, image, image_addr, cmdline_ptr);
 
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index fd91fc15ec810..b5e19ba50ddae 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -1094,6 +1094,8 @@ char *efi_convert_cmdline(efi_loaded_image_t *image);
 efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
 				bool install_cfg_tbl);
 
+efi_status_t efi_get_ram_top(u64 *top);
+
 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
 				unsigned long max);
 
@@ -1169,6 +1171,12 @@ efi_enable_reset_attack_mitigation(void) { }
 
 void efi_retrieve_eventlog(void);
 
+#ifdef CONFIG_EFI_POISONED_MEMORY
+void install_poisoned_memory_table(void);
+#else
+static inline void install_poisoned_memory_table(void) { }
+#endif
+
 struct sysfb_display_info *alloc_primary_display(void);
 struct sysfb_display_info *__alloc_primary_display(void);
 void free_primary_display(struct sysfb_display_info *dpy);
diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c
index 59f3f83de50c2..777f1f180c66e 100644
--- a/drivers/firmware/efi/libstub/mem.c
+++ b/drivers/firmware/efi/libstub/mem.c
@@ -64,6 +64,59 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
 	return EFI_SUCCESS;
 }
 
+/**
+ * efi_get_ram_top() - find the top of usable RAM
+ * @top:	on return, the end of the highest memory map entry that becomes
+ *		usable RAM
+ *
+ * Walk the UEFI memory map for the entry types that become usable RAM, the set
+ * setup_e820() maps to E820_TYPE_RAM, and return the highest address any of
+ * them reaches. Memory a confidential guest has not accepted yet counts as
+ * well, since it becomes RAM once accepted. This is what the stub has in place
+ * of max_pfn, which is only set once the kernel proper is up.
+ *
+ * Memory the firmware hot-adds later is not described by the memory map and so
+ * is not accounted for here.
+ *
+ * Return:	status code
+ */
+efi_status_t efi_get_ram_top(u64 *top)
+{
+	struct efi_boot_memmap *map __free(efi_pool) = NULL;
+	efi_status_t status;
+	u64 ram_top = 0;
+	int i, nr_desc;
+
+	status = efi_get_memory_map(&map, false);
+	if (status != EFI_SUCCESS)
+		return status;
+
+	nr_desc = map->map_size / map->desc_size;
+	for (i = 0; i < nr_desc; i++) {
+		efi_memory_desc_t *d;
+
+		d = efi_memdesc_ptr((unsigned long)map->map, map->desc_size, i);
+		switch (d->type) {
+		case EFI_LOADER_CODE:
+		case EFI_LOADER_DATA:
+		case EFI_BOOT_SERVICES_CODE:
+		case EFI_BOOT_SERVICES_DATA:
+		case EFI_CONVENTIONAL_MEMORY:
+		case EFI_UNACCEPTED_MEMORY:
+			ram_top = max(ram_top,
+				      d->phys_addr + d->num_pages * EFI_PAGE_SIZE);
+			break;
+		default:
+			break;
+		}
+	}
+	if (!ram_top)
+		return EFI_NOT_FOUND;
+
+	*top = ram_top;
+	return EFI_SUCCESS;
+}
+
 /**
  * efi_allocate_pages() - Allocate memory pages
  * @size:	minimum number of bytes to allocate
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index cef32e2c82d8f..f90de11bc8855 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -1023,6 +1023,8 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
 
 	setup_unaccepted_memory();
 
+	install_poisoned_memory_table();
+
 	status = exit_boot(boot_params, handle);
 	if (status != EFI_SUCCESS) {
 		efi_err("exit_boot() failed!\n");
diff --git a/drivers/firmware/efi/poison.c b/drivers/firmware/efi/poison.c
new file mode 100644
index 0000000000000..e418c6b3aab81
--- /dev/null
+++ b/drivers/firmware/efi/poison.c
@@ -0,0 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Runtime handling for the LINUX_EFI_POISONED_MEMORY configuration table: a
+ * bitmap with one bit per EFI_POISON_UNIT_SIZE of physical memory that records
+ * hardware-poisoned frames so the next kexec kernel can keep them out of its
+ * allocator. The stub allocates and installs the (empty) bitmap; this kernel
+ * sets bits at runtime; the next kernel reserves the set units before the
+ * allocator comes up.
+ *
+ * Copyright (c) 2026 Meta Platforms, Inc. and affiliates.
+ * Copyright (c) 2026 Breno Leitao <leitao@debian.org>
+ */
+
+#define pr_fmt(fmt) "efi: " fmt
+
+#include <linux/bitmap.h>
+#include <linux/efi.h>
+#include <linux/io.h>
+#include <linux/log2.h>
+#include <linux/memblock.h>
+#include <linux/minmax.h>
+#include <linux/mm.h>
+#include <linux/overflow.h>
+
+static struct linux_efi_poisoned_memory *efi_poison __ro_after_init;
+
+/* A non-empty bitmap on a power-of-2 grid that phys_base actually sits on. */
+static bool __init
+efi_poison_geometry_valid(const struct linux_efi_poisoned_memory *pm)
+{
+	if (!pm->size)
+		return false;
+	if (pm->unit_size < PAGE_SIZE || !is_power_of_2(pm->unit_size))
+		return false;
+
+	return IS_ALIGNED(pm->phys_base, pm->unit_size);
+}
+
+/* The range the bitmap claims to describe has to fit in a u64. */
+static bool __init
+efi_poison_range_valid(const struct linux_efi_poisoned_memory *pm)
+{
+	u64 nbits, span;
+
+	if (check_mul_overflow(pm->size, (u64)BITS_PER_BYTE, &nbits))
+		return false;
+	if (check_mul_overflow(nbits, (u64)pm->unit_size, &span))
+		return false;
+
+	return !check_add_overflow(pm->phys_base, span, &span);
+}
+
+/*
+ * The table may have been installed by an earlier kernel in the kexec chain,
+ * so check its geometry before doing any arithmetic with it.
+ */
+static bool __init
+efi_poison_table_valid(const struct linux_efi_poisoned_memory *pm)
+{
+	if (pm->version != 1) {
+		pr_warn("Ignoring poisoned-memory table with version %u\n",
+			pm->version);
+		return false;
+	}
+
+	if (!efi_poison_geometry_valid(pm) || !efi_poison_range_valid(pm)) {
+		pr_warn("Ignoring malformed poisoned-memory table\n");
+		return false;
+	}
+
+	return true;
+}
+
+static int __init efi_poison_init(void)
+{
+	struct linux_efi_poisoned_memory *pm;
+	u64 size;
+
+	if (efi.poisoned_memory == EFI_INVALID_TABLE_ADDR)
+		return 0;
+
+	/* Map the header to learn the bitmap size, then map the whole table. */
+	pm = memremap(efi.poisoned_memory, sizeof(*pm), MEMREMAP_WB);
+	if (WARN_ON_ONCE(!pm))
+		return 0;
+	if (!efi_poison_table_valid(pm)) {
+		memunmap(pm);
+		return 0;
+	}
+	size = pm->size;
+	memunmap(pm);
+
+	efi_poison = memremap(efi.poisoned_memory, sizeof(*pm) + size,
+			      MEMREMAP_WB);
+	WARN_ON_ONCE(!efi_poison);
+	return 0;
+}
+early_initcall(efi_poison_init);
+
+/* Bitmap unit covering @pfn, or -1 if the pfn falls outside the table. */
+static long efi_poison_unit(unsigned long pfn)
+{
+	phys_addr_t addr = PFN_PHYS(pfn);
+	u64 unit;
+
+	if (addr < efi_poison->phys_base)
+		return -1;
+	unit = (addr - efi_poison->phys_base) / efi_poison->unit_size;
+	if (unit >= (u64)efi_poison->size * BITS_PER_BYTE)
+		return -1;
+	return unit;
+}
+
+/*
+ * Record a hardware-poisoned frame so the next kernel keeps its unit out of the
+ * allocator. memory_failure() has already removed the frame from this kernel.
+ *
+ * A bit is never cleared: one bit stands for a whole EFI_POISON_UNIT_SIZE, so
+ * an unpoison cannot tell whether the unit as a whole is good again.
+ */
+void efi_hwpoison_record_pfn(unsigned long pfn)
+{
+	long unit;
+
+	if (!efi_poison)
+		return;
+
+	unit = efi_poison_unit(pfn);
+	if (unit < 0)
+		return;
+
+	set_bit(unit, efi_poison->bitmap);
+}
+
+void __init efi_reserve_poisoned_memory(void)
+{
+	u64 ppm = efi.poisoned_memory, phys_base, unit_size, bitmap_size, off;
+	struct linux_efi_poisoned_memory *pm;
+	unsigned int nr_units = 0;
+
+	if (ppm == EFI_INVALID_TABLE_ADDR)
+		return;
+
+	pm = early_memremap(ppm, sizeof(*pm));
+	if (!pm) {
+		pr_warn("Could not map poisoned-memory table\n");
+		return;
+	}
+
+	if (!efi_poison_table_valid(pm)) {
+		/* Keep the runtime side off a table this pass rejected. */
+		efi.poisoned_memory = EFI_INVALID_TABLE_ADDR;
+		early_memunmap(pm, sizeof(*pm));
+		return;
+	}
+
+	phys_base = pm->phys_base;
+	unit_size = pm->unit_size;
+	bitmap_size = pm->size;
+
+	early_memunmap(pm, sizeof(*pm));
+
+	/* Reserve the table itself so it survives a further kexec. */
+	memblock_reserve(PAGE_ALIGN_DOWN(ppm),
+			 PAGE_ALIGN(ppm + sizeof(*pm) + bitmap_size) -
+			 PAGE_ALIGN_DOWN(ppm));
+
+	/*
+	 * Walk the bitmap a page at a time and reserve each poisoned unit.
+	 * memblock.memory is not populated this early, so memblock_remove()
+	 * and memblock_mark_nomap() would be no-ops; a reservation is what
+	 * keeps the units away from the allocator.
+	 */
+	for (off = 0; off < bitmap_size; off += PAGE_SIZE) {
+		u64 chunk = min_t(u64, PAGE_SIZE, bitmap_size - off);
+		unsigned long bit, nbits = chunk * BITS_PER_BYTE;
+		unsigned long *map;
+
+		map = early_memremap(ppm + offsetof(struct linux_efi_poisoned_memory,
+						    bitmap) + off, chunk);
+		if (!map) {
+			pr_warn("Could not map poisoned-memory bitmap\n");
+			return;
+		}
+		for_each_set_bit(bit, map, nbits) {
+			u64 unit = off * BITS_PER_BYTE + bit;
+
+			memblock_reserve(phys_base + unit * unit_size, unit_size);
+			nr_units++;
+		}
+		early_memunmap(map, chunk);
+	}
+
+	if (nr_units)
+		pr_info("reserved %u poisoned unit(s) (%lluK each) inherited across kexec\n",
+			nr_units, unit_size >> 10);
+}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index ccbc35479684a..3cb3f224ac02b 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -23,6 +23,7 @@
 #include <linux/pstore.h>
 #include <linux/range.h>
 #include <linux/reboot.h>
+#include <linux/sizes.h>
 #include <linux/uuid.h>
 
 #include <asm/page.h>
@@ -422,6 +423,7 @@ void efi_native_runtime_setup(void);
 #define LINUX_EFI_COCO_SECRET_AREA_GUID		EFI_GUID(0xadf956ad, 0xe98c, 0x484c,  0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47)
 #define LINUX_EFI_BOOT_MEMMAP_GUID		EFI_GUID(0x800f683f, 0xd08b, 0x423a,  0xa2, 0x93, 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
 #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID	EFI_GUID(0xd5d1de3c, 0x105c, 0x44f9,  0x9e, 0xa9, 0xbc, 0xef, 0x98, 0x12, 0x00, 0x31)
+#define LINUX_EFI_POISONED_MEMORY_TABLE_GUID	EFI_GUID(0x78a5bf07, 0x7d2a, 0x2889,  0x16, 0x31, 0x63, 0xd4, 0x56, 0xf2, 0x83, 0x50)
 
 #define RISCV_EFI_BOOT_PROTOCOL_GUID		EFI_GUID(0xccd15fec, 0x6f73, 0x4eec,  0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
 
@@ -650,6 +652,7 @@ extern struct efi {
 	unsigned long			mokvar_table;		/* MOK variable config table */
 	unsigned long			coco_secret;		/* Confidential computing secret table */
 	unsigned long			unaccepted;		/* Unaccepted memory table */
+	unsigned long			poisoned_memory;	/* Hardware-poisoned memory table */
 
 	efi_get_time_t			*get_time;
 	efi_set_time_t			*set_time;
@@ -1269,6 +1272,24 @@ struct linux_efi_memreserve {
 #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
 	/ sizeof_field(struct linux_efi_memreserve, entry[0]))
 
+struct linux_efi_poisoned_memory {
+	u32		version;
+	u32		unit_size;	/* bytes of phys space per bitmap bit */
+	u64		phys_base;	/* phys address covered by bit 0 */
+	u64		size;		/* bitmap size in bytes */
+	unsigned long	bitmap[];
+};
+
+#define EFI_POISON_UNIT_SIZE	SZ_2M
+
+#ifdef CONFIG_EFI_POISONED_MEMORY
+void efi_reserve_poisoned_memory(void);
+void efi_hwpoison_record_pfn(unsigned long pfn);
+#else
+static inline void efi_reserve_poisoned_memory(void) { }
+static inline void efi_hwpoison_record_pfn(unsigned long pfn) { }
+#endif
+
 void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size);
 
 /*
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index a8b03e2920ba8..1cc4e92e98748 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -43,6 +43,7 @@
 #include <linux/sched/signal.h>
 #include <linux/sched/task.h>
 #include <linux/dax.h>
+#include <linux/efi.h>
 #include <linux/ksm.h>
 #include <linux/rmap.h>
 #include <linux/export.h>
@@ -1286,6 +1287,8 @@ static int action_result(unsigned long pfn, enum mf_action_page_type type,
 	if (type != MF_MSG_ALREADY_POISONED && type != MF_MSG_PFN_MAP) {
 		num_poisoned_pages_inc(pfn);
 		update_per_node_mf_stats(pfn, result);
+		/* Only hard offlines are carried over to the next kernel. */
+		efi_hwpoison_record_pfn(pfn);
 	}
 
 	pr_err("%#lx: recovery action for %s: %s\n",

25/3 2026/08/21 10:59 llm kmsan-evaluator
0m Model:
gemini-3.1-pro-preview

Args:
null

Results:
null

Tokens:
							input: 9151
							output: 188
							thoughts: 865
						

Thoughts:
**Analyzing the EFI Poisoned Memory Patch**

Okay, so this patch is introducing `CONFIG_EFI_POISONED_MEMORY` to handle hardware-poisoned pages across kexec. I see they're adding a new EFI configuration table, `LINUX_EFI_POISONED_MEMORY_TABLE_GUID`. This is the core of it, a new table to track the poisoned memory.

I'm focusing on potential uninitialized memory reads or information leaks. The code allocates and initializes the table in `efi_poison_alloc()`. Let's break it down: They're using `efi_bs_call(allocate_pool, ...)` for the memory allocation, which is standard EFI stuff. Crucially, they're *fully* initializing the allocated memory. The `pm` struct's fields (`version`, `unit_size`, `phys_base`, `size`) are set, and, critically, the `bitmap` is zeroed out using `memset`. I'm verifying this initialization carefully because that's where uninitialized memory often surfaces.

Looking at the struct itself, it looks clean: `version`, `unit_size`, `phys_base`, `size`, and a flexible array `bitmap`. I'm confident that the `memset` covers the entire `bitmap` area, so there's no dangling memory. There's no unexpected padding in the struct that could leave something uninitialized.

The patch includes `efi_poison_init()` which maps the table using `memremap()`. Then, `efi_reserve_poisoned_memory()` reads the table and reserves the memory with `memblock_reserve()`, and `efi_hwpoison_record_pfn()` sets bits in the bitmap. I can see how this works. The table gets passed to the next kernel via the EFI configuration tables, which is internal and not exposed to user space. It sounds like a solid approach, not leaking any information to user space.

I'm double-checking the allocation in `efi_poison_alloc()`. The allocation size looks correct: `sizeof(*pm) + bitmap_size`. The struct itself is straightforward. *Everything* allocated here is explicitly initialized.

I also checked `efi_get_ram_top()` which calls `efi_get_memory_map()` but this appears to be existing code, not something new to this patch, so I'm not concerned.

Given what I've seen, there are no obvious uninitialized memory usage or info-leaks here. They're being very careful with the initialization. KASAN seems sufficient for catching any out-of-bounds or use-after-free bugs in this area, so KMSAN isn't needed here. I'm reasonably confident in this analysis.



26/3 2026/08/21 11:00 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch introduces a mechanism to carry hardware-poisoned pages across kexec using an EFI configuration table. The newly introduced structure `linux_efi_poisoned_memory` is allocated in `efi_poison_alloc()` and all its fields, including the flexible `bitmap` array, are explicitly initialized (the fields are assigned and the bitmap is zeroed using `memset`). There is no structure padding that could leak uninitialized memory, and this table is not copied to user space. The changes do not introduce any risk of uninitialized memory reads or info-leaks. Any potential memory corruption, out-of-bounds accesses, or use-after-free bugs related to the bitmap handling would be caught by standard KASAN. Therefore, a dedicated KMSAN fuzzing session is not necessary.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch introduces a mechanism to carry hardware-poisoned pages across kexec using an EFI configuration table. The newly introduced structure `linux_efi_poisoned_memory` is allocated in `efi_poison_alloc()` and all its fields, including the flexible `bitmap` array, are explicitly initialized (the fields are assigned and the bitmap is zeroed using `memset`). There is no structure padding that could leak uninitialized memory, and this table is not copied to user space. The changes do not introduce any risk of uninitialized memory reads or info-leaks. Any potential memory corruption, out-of-bounds accesses, or use-after-free bugs related to the bitmap handling would be caught by standard KASAN. Therefore, a dedicated KMSAN fuzzing session is not necessary.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)