Skip to content

Commit 088984c

Browse files
KobaKoNvidiarafaeljw
authored andcommitted
ACPI: PRM: Find EFI_MEMORY_RUNTIME block for PRM handler and context
PRMT needs to find the correct type of block to translate the PA-VA mapping for EFI runtime services. The issue arises because the PRMT is finding a block of type EFI_CONVENTIONAL_MEMORY, which is not appropriate for runtime services as described in Section 2.2.2 (Runtime Services) of the UEFI Specification [1]. Since the PRM handler is a type of runtime service, this causes an exception when the PRM handler is called. [Firmware Bug]: Unable to handle paging request in EFI runtime service WARNING: CPU: 22 PID: 4330 at drivers/firmware/efi/runtime-wrappers.c:341 __efi_queue_work+0x11c/0x170 Call trace: Let PRMT find a block with EFI_MEMORY_RUNTIME for PRM handler and PRM context. If no suitable block is found, a warning message will be printed, but the procedure continues to manage the next PRM handler. However, if the PRM handler is actually called without proper allocation, it would result in a failure during error handling. By using the correct memory types for runtime services, ensure that the PRM handler and the context are properly mapped in the virtual address space during runtime, preventing the paging request error. The issue is really that only memory that has been remapped for runtime by the firmware can be used by the PRM handler, and so the region needs to have the EFI_MEMORY_RUNTIME attribute. Link: https://uefi.org/sites/default/files/resources/UEFI_Spec_2_10_Aug29.pdf # [1] Fixes: cefc7ca ("ACPI: PRM: implement OperationRegion handler for the PlatformRtMechanism subtype") Cc: All applicable <[email protected]> Signed-off-by: Koba Ko <[email protected]> Reviewed-by: Matthew R. Ochs <[email protected]> Reviewed-by: Zhang Rui <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 42f7652 commit 088984c

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

drivers/acpi/prmt.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,21 @@ struct prm_module_info {
7272
struct prm_handler_info handlers[] __counted_by(handler_count);
7373
};
7474

75-
static u64 efi_pa_va_lookup(u64 pa)
75+
static u64 efi_pa_va_lookup(efi_guid_t *guid, u64 pa)
7676
{
7777
efi_memory_desc_t *md;
7878
u64 pa_offset = pa & ~PAGE_MASK;
7979
u64 page = pa & PAGE_MASK;
8080

8181
for_each_efi_memory_desc(md) {
82-
if (md->phys_addr < pa && pa < md->phys_addr + PAGE_SIZE * md->num_pages)
82+
if ((md->attribute & EFI_MEMORY_RUNTIME) &&
83+
(md->phys_addr < pa && pa < md->phys_addr + PAGE_SIZE * md->num_pages)) {
8384
return pa_offset + md->virt_addr + page - md->phys_addr;
85+
}
8486
}
8587

88+
pr_warn("Failed to find VA for GUID: %pUL, PA: 0x%llx", guid, pa);
89+
8690
return 0;
8791
}
8892

@@ -148,9 +152,15 @@ acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end)
148152
th = &tm->handlers[cur_handler];
149153

150154
guid_copy(&th->guid, (guid_t *)handler_info->handler_guid);
151-
th->handler_addr = (void *)efi_pa_va_lookup(handler_info->handler_address);
152-
th->static_data_buffer_addr = efi_pa_va_lookup(handler_info->static_data_buffer_address);
153-
th->acpi_param_buffer_addr = efi_pa_va_lookup(handler_info->acpi_param_buffer_address);
155+
th->handler_addr =
156+
(void *)efi_pa_va_lookup(&th->guid, handler_info->handler_address);
157+
158+
th->static_data_buffer_addr =
159+
efi_pa_va_lookup(&th->guid, handler_info->static_data_buffer_address);
160+
161+
th->acpi_param_buffer_addr =
162+
efi_pa_va_lookup(&th->guid, handler_info->acpi_param_buffer_address);
163+
154164
} while (++cur_handler < tm->handler_count && (handler_info = get_next_handler(handler_info)));
155165

156166
return 0;
@@ -277,6 +287,13 @@ static acpi_status acpi_platformrt_space_handler(u32 function,
277287
if (!handler || !module)
278288
goto invalid_guid;
279289

290+
if (!handler->handler_addr ||
291+
!handler->static_data_buffer_addr ||
292+
!handler->acpi_param_buffer_addr) {
293+
buffer->prm_status = PRM_HANDLER_ERROR;
294+
return AE_OK;
295+
}
296+
280297
ACPI_COPY_NAMESEG(context.signature, "PRMC");
281298
context.revision = 0x0;
282299
context.reserved = 0x0;

0 commit comments

Comments
 (0)