On Sat, Oct 12, 2024 at 10:50 PM KobaK <kobak@xxxxxxxxxx> wrote: > > From: Koba Ko <kobak@xxxxxxxxxx> > > 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: > > Find a block with specific type to fix this. > 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 prompted > 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. > > [1] https://uefi.org/sites/default/files/resources/UEFI_Spec_2_10_Aug29.pdf > Fixes: cefc7ca46235 ("ACPI: PRM: implement OperationRegion handler for the PlatformRtMechanism subtype") > cc: stable@xxxxxxxxxxxxxxx > Signed-off-by: Koba Ko <kobak@xxxxxxxxxx> > Reviewed-by: Matthew R. Ochs <mochs@xxxxxxxxxx> > Reviewed-by: Zhang Rui <rui.zhang@xxxxxxxxx> > Reviewed-by: Ard Biesheuvel <ardb@xxxxxxxxxx> > --- > V2: > 1. format the changelog and add more about error handling. > 2. replace goto > V3: Warn if parts of handler are missed during va-pa translating. > V4: Fix the 0day > V5: Fix typo and pr_warn warning > V6: use EFI_MOMOERY_RUNTIME to find block and split goto refactor as a single > patch > V7: > 1. refine the codes and commit description as per comments > 2. drop goto refacotr > V8: Fix 0day and cc to stable > V9: Describe 0day fix > cast PA as (void *) in pr_warn > V10: use 0x%llx instead for PA in pr_warn Applied (under a new subject and with edits in the changelog) as 6.12-rc material. Thanks! > --- > drivers/acpi/prmt.c | 27 ++++++++++++++++++++++----- > 1 file changed, 22 insertions(+), 5 deletions(-) > > diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c > index 1cfaa5957ac4..d59307a76ca3 100644 > --- a/drivers/acpi/prmt.c > +++ b/drivers/acpi/prmt.c > @@ -72,17 +72,21 @@ struct prm_module_info { > struct prm_handler_info handlers[] __counted_by(handler_count); > }; > > -static u64 efi_pa_va_lookup(u64 pa) > +static u64 efi_pa_va_lookup(efi_guid_t *guid, u64 pa) > { > efi_memory_desc_t *md; > u64 pa_offset = pa & ~PAGE_MASK; > u64 page = pa & PAGE_MASK; > > for_each_efi_memory_desc(md) { > - if (md->phys_addr < pa && pa < md->phys_addr + PAGE_SIZE * md->num_pages) > + if ((md->attribute & EFI_MEMORY_RUNTIME) && > + (md->phys_addr < pa && pa < md->phys_addr + PAGE_SIZE * md->num_pages)) { > return pa_offset + md->virt_addr + page - md->phys_addr; > + } > } > > + pr_warn("Failed to find VA for GUID: %pUL, PA: 0x%llx", guid, pa); > + > return 0; > } > > @@ -148,9 +152,15 @@ acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end) > th = &tm->handlers[cur_handler]; > > guid_copy(&th->guid, (guid_t *)handler_info->handler_guid); > - th->handler_addr = (void *)efi_pa_va_lookup(handler_info->handler_address); > - th->static_data_buffer_addr = efi_pa_va_lookup(handler_info->static_data_buffer_address); > - th->acpi_param_buffer_addr = efi_pa_va_lookup(handler_info->acpi_param_buffer_address); > + th->handler_addr = > + (void *)efi_pa_va_lookup(&th->guid, handler_info->handler_address); > + > + th->static_data_buffer_addr = > + efi_pa_va_lookup(&th->guid, handler_info->static_data_buffer_address); > + > + th->acpi_param_buffer_addr = > + efi_pa_va_lookup(&th->guid, handler_info->acpi_param_buffer_address); > + > } while (++cur_handler < tm->handler_count && (handler_info = get_next_handler(handler_info))); > > return 0; > @@ -277,6 +287,13 @@ static acpi_status acpi_platformrt_space_handler(u32 function, > if (!handler || !module) > goto invalid_guid; > > + if (!handler->handler_addr || > + !handler->static_data_buffer_addr || > + !handler->acpi_param_buffer_addr) { > + buffer->prm_status = PRM_HANDLER_ERROR; > + return AE_OK; > + } > + > ACPI_COPY_NAMESEG(context.signature, "PRMC"); > context.revision = 0x0; > context.reserved = 0x0; > -- > 2.43.0 > >