* [PATCH V3] acpi/prmt: find block with specific type
@ 2024-09-05 12:49 KobaK
2024-09-07 3:30 ` kernel test robot
2024-09-07 4:42 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: KobaK @ 2024-09-05 12:49 UTC (permalink / raw)
To: Matt Ochs, James Morse, Rafael J . Wysocki, Len Brown, linux-acpi,
linux-kernel, Zhang Rui
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:
__efi_queue_work+0x11c/0x170
efi_call_acpi_prm_handler+0x68/0xd0
acpi_platformrt_space_handler+0x198/0x258
acpi_ev_address_space_dispatch+0x144/0x388
acpi_ex_access_region+0x9c/0x118
acpi_ex_write_serial_bus+0xc4/0x218
acpi_ex_write_data_to_field+0x168/0x218
acpi_ex_store_object_to_node+0x1a8/0x258
acpi_ex_store+0xec/0x330
acpi_ex_opcode_1A_1T_1R+0x15c/0x618
acpi_ds_exec_end_op+0x274/0x548
acpi_ps_parse_loop+0x10c/0x6b8
acpi_ps_parse_aml+0x140/0x3b0
acpi_ps_execute_method+0x12c/0x2a0
acpi_ns_evaluate+0x210/0x310
acpi_evaluate_object+0x178/0x358
acpi_proc_write+0x1a8/0x8a0 [acpi_call]
proc_reg_write+0xcc/0x150
vfs_write+0xd8/0x380
ksys_write+0x70/0x120
__arm64_sys_write+0x24/0x48
invoke_syscall.constprop.0+0x80/0xf8
do_el0_svc+0x50/0x110
el0_svc+0x48/0x1d0
el0t_64_sync_handler+0x15c/0x178
el0t_64_sync+0x1a8/0x1b0
Find a block with specific type to fix this.
prmt find a block with EFI_RUNTIME_SERVICES_DATA for prm handler and
find a block with EFI_RUNTIME_SERVICES_CODE for prm context.
If no suitable block is found, a warning message will be prompted
but the procedue continues to manage the next prm handler.
However, if the prm handler is actullay 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.
[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")
Signed-off-by: KobaK <kobak@nvidia.com>
Reviewed-by: Matthew R. Ochs <mochs@nvidia.com>
---
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.
---
drivers/acpi/prmt.c | 49 +++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/drivers/acpi/prmt.c b/drivers/acpi/prmt.c
index c78453c74ef5..a274636dfe8b 100644
--- a/drivers/acpi/prmt.c
+++ b/drivers/acpi/prmt.c
@@ -72,15 +72,17 @@ 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(u64 pa, u32 type)
{
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->type == type) &&
+ (md->phys_addr < pa && pa < md->phys_addr + PAGE_SIZE * md->num_pages)) {
return pa_offset + md->virt_addr + page - md->phys_addr;
+ }
}
return 0;
@@ -148,9 +150,18 @@ 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(handler_info->handler_address, EFI_RUNTIME_SERVICES_CODE);
+ th->static_data_buffer_addr =
+ efi_pa_va_lookup(handler_info->static_data_buffer_address, EFI_RUNTIME_SERVICES_DATA);
+ th->acpi_param_buffer_addr =
+ efi_pa_va_lookup(handler_info->acpi_param_buffer_address, EFI_RUNTIME_SERVICES_DATA);
+
+ if (!th->handler_addr || !th->static_data_buffer_addr || !th->acpi_param_buffer_addr)
+ pr_warn(
+ "Idx: %d, Parts of handler(GUID: %pUB) are missed, handler_addr %llx, data_addr %llx, param_addr %llx",
+ cur_handler, th->handler_addr,
+ th->static_data_buffer_addr, th->acpi_param_buffer_addr);
} while (++cur_handler < tm->handler_count && (handler_info = get_next_handler(handler_info)));
return 0;
@@ -250,8 +261,16 @@ static acpi_status acpi_platformrt_space_handler(u32 function,
handler = find_prm_handler(&buffer->handler_guid);
module = find_prm_module(&buffer->handler_guid);
- if (!handler || !module)
- goto invalid_guid;
+ if (!handler || !module) {
+ buffer->prm_status = PRM_HANDLER_GUID_NOT_FOUND;
+ return AE_OK;
+ }
+
+ 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;
@@ -274,8 +293,10 @@ static acpi_status acpi_platformrt_space_handler(u32 function,
case PRM_CMD_START_TRANSACTION:
module = find_prm_module(&buffer->handler_guid);
- if (!module)
- goto invalid_guid;
+ if (!module) {
+ buffer->prm_status = PRM_HANDLER_GUID_NOT_FOUND;
+ return AE_OK;
+ }
if (module->updatable)
module->updatable = false;
@@ -286,8 +307,10 @@ static acpi_status acpi_platformrt_space_handler(u32 function,
case PRM_CMD_END_TRANSACTION:
module = find_prm_module(&buffer->handler_guid);
- if (!module)
- goto invalid_guid;
+ if (!module) {
+ buffer->prm_status = PRM_HANDLER_GUID_NOT_FOUND;
+ return AE_OK;
+ }
if (module->updatable)
buffer->prm_status = UPDATE_UNLOCK_WITHOUT_LOCK;
@@ -302,10 +325,6 @@ static acpi_status acpi_platformrt_space_handler(u32 function,
}
return AE_OK;
-
-invalid_guid:
- buffer->prm_status = PRM_HANDLER_GUID_NOT_FOUND;
- return AE_OK;
}
void __init init_prmt(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V3] acpi/prmt: find block with specific type
2024-09-05 12:49 [PATCH V3] acpi/prmt: find block with specific type KobaK
@ 2024-09-07 3:30 ` kernel test robot
2024-09-07 4:42 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2024-09-07 3:30 UTC (permalink / raw)
To: KobaK, Matt Ochs, James Morse, Rafael J . Wysocki, Len Brown,
linux-acpi, linux-kernel, Zhang Rui
Cc: oe-kbuild-all
Hi KobaK,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v6.11-rc6 next-20240906]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/KobaK/acpi-prmt-find-block-with-specific-type/20240905-205316
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20240905124950.512973-1-kobak%40nvidia.com
patch subject: [PATCH V3] acpi/prmt: find block with specific type
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20240907/202409071110.LWdX8txQ-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240907/202409071110.LWdX8txQ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409071110.LWdX8txQ-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from include/linux/kernel.h:31,
from drivers/acpi/prmt.c:17:
drivers/acpi/prmt.c: In function 'acpi_parse_prmt':
>> include/linux/kern_levels.h:5:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:437:25: note: in definition of macro 'printk_index_wrap'
437 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:518:9: note: in expansion of macro 'printk'
518 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:518:16: note: in expansion of macro 'KERN_WARNING'
518 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/acpi/prmt.c:161:25: note: in expansion of macro 'pr_warn'
161 | pr_warn(
| ^~~~~~~
>> include/linux/kern_levels.h:5:25: warning: format '%llx' expects a matching 'long long unsigned int' argument [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:437:25: note: in definition of macro 'printk_index_wrap'
437 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:518:9: note: in expansion of macro 'printk'
518 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:12:25: note: in expansion of macro 'KERN_SOH'
12 | #define KERN_WARNING KERN_SOH "4" /* warning conditions */
| ^~~~~~~~
include/linux/printk.h:518:16: note: in expansion of macro 'KERN_WARNING'
518 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/acpi/prmt.c:161:25: note: in expansion of macro 'pr_warn'
161 | pr_warn(
| ^~~~~~~
vim +5 include/linux/kern_levels.h
314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V3] acpi/prmt: find block with specific type
2024-09-05 12:49 [PATCH V3] acpi/prmt: find block with specific type KobaK
2024-09-07 3:30 ` kernel test robot
@ 2024-09-07 4:42 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2024-09-07 4:42 UTC (permalink / raw)
To: KobaK, Matt Ochs, James Morse, Rafael J . Wysocki, Len Brown,
linux-acpi, linux-kernel, Zhang Rui
Cc: llvm, oe-kbuild-all
Hi KobaK,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v6.11-rc6 next-20240906]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/KobaK/acpi-prmt-find-block-with-specific-type/20240905-205316
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20240905124950.512973-1-kobak%40nvidia.com
patch subject: [PATCH V3] acpi/prmt: find block with specific type
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240907/202409071245.bkGWWtfQ-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240907/202409071245.bkGWWtfQ-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409071245.bkGWWtfQ-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/acpi/prmt.c:163:5: warning: format specifies type 'int' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
162 | "Idx: %d, Parts of handler(GUID: %pUB) are missed, handler_addr %llx, data_addr %llx, param_addr %llx",
| ~~
| %llu
163 | cur_handler, th->handler_addr,
| ^~~~~~~~~~~
include/linux/printk.h:518:37: note: expanded from macro 'pr_warn'
518 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ~~~ ^~~~~~~~~~~
include/linux/printk.h:465:60: note: expanded from macro 'printk'
465 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ~~~ ^~~~~~~~~~~
include/linux/printk.h:437:19: note: expanded from macro 'printk_index_wrap'
437 | _p_func(_fmt, ##__VA_ARGS__); \
| ~~~~ ^~~~~~~~~~~
>> drivers/acpi/prmt.c:162:105: warning: more '%' conversions than data arguments [-Wformat-insufficient-args]
162 | "Idx: %d, Parts of handler(GUID: %pUB) are missed, handler_addr %llx, data_addr %llx, param_addr %llx",
| ~~~^
include/linux/printk.h:518:29: note: expanded from macro 'pr_warn'
518 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
| ^~~
include/linux/printk.h:355:21: note: expanded from macro 'pr_fmt'
355 | #define pr_fmt(fmt) fmt
| ^~~
include/linux/printk.h:465:53: note: expanded from macro 'printk'
465 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
| ^~~
include/linux/printk.h:437:11: note: expanded from macro 'printk_index_wrap'
437 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
2 warnings generated.
vim +163 drivers/acpi/prmt.c
93
94 static int __init
95 acpi_parse_prmt(union acpi_subtable_headers *header, const unsigned long end)
96 {
97 struct acpi_prmt_module_info *module_info;
98 struct acpi_prmt_handler_info *handler_info;
99 struct prm_handler_info *th;
100 struct prm_module_info *tm;
101 u64 *mmio_count;
102 u64 cur_handler = 0;
103 u32 module_info_size = 0;
104 u64 mmio_range_size = 0;
105 void *temp_mmio;
106
107 module_info = (struct acpi_prmt_module_info *) header;
108 module_info_size = struct_size(tm, handlers, module_info->handler_info_count);
109 tm = kmalloc(module_info_size, GFP_KERNEL);
110 if (!tm)
111 goto parse_prmt_out1;
112
113 guid_copy(&tm->guid, (guid_t *) module_info->module_guid);
114 tm->major_rev = module_info->major_rev;
115 tm->minor_rev = module_info->minor_rev;
116 tm->handler_count = module_info->handler_info_count;
117 tm->updatable = true;
118
119 if (module_info->mmio_list_pointer) {
120 /*
121 * Each module is associated with a list of addr
122 * ranges that it can use during the service
123 */
124 mmio_count = (u64 *) memremap(module_info->mmio_list_pointer, 8, MEMREMAP_WB);
125 if (!mmio_count)
126 goto parse_prmt_out2;
127
128 mmio_range_size = struct_size(tm->mmio_info, addr_ranges, *mmio_count);
129 tm->mmio_info = kmalloc(mmio_range_size, GFP_KERNEL);
130 if (!tm->mmio_info)
131 goto parse_prmt_out3;
132
133 temp_mmio = memremap(module_info->mmio_list_pointer, mmio_range_size, MEMREMAP_WB);
134 if (!temp_mmio)
135 goto parse_prmt_out4;
136 memmove(tm->mmio_info, temp_mmio, mmio_range_size);
137 } else {
138 tm->mmio_info = kmalloc(sizeof(*tm->mmio_info), GFP_KERNEL);
139 if (!tm->mmio_info)
140 goto parse_prmt_out2;
141
142 tm->mmio_info->mmio_count = 0;
143 }
144
145 INIT_LIST_HEAD(&tm->module_list);
146 list_add(&tm->module_list, &prm_module_list);
147
148 handler_info = get_first_handler(module_info);
149 do {
150 th = &tm->handlers[cur_handler];
151
152 guid_copy(&th->guid, (guid_t *)handler_info->handler_guid);
153 th->handler_addr =
154 (void *)efi_pa_va_lookup(handler_info->handler_address, EFI_RUNTIME_SERVICES_CODE);
155 th->static_data_buffer_addr =
156 efi_pa_va_lookup(handler_info->static_data_buffer_address, EFI_RUNTIME_SERVICES_DATA);
157 th->acpi_param_buffer_addr =
158 efi_pa_va_lookup(handler_info->acpi_param_buffer_address, EFI_RUNTIME_SERVICES_DATA);
159
160 if (!th->handler_addr || !th->static_data_buffer_addr || !th->acpi_param_buffer_addr)
161 pr_warn(
> 162 "Idx: %d, Parts of handler(GUID: %pUB) are missed, handler_addr %llx, data_addr %llx, param_addr %llx",
> 163 cur_handler, th->handler_addr,
164 th->static_data_buffer_addr, th->acpi_param_buffer_addr);
165 } while (++cur_handler < tm->handler_count && (handler_info = get_next_handler(handler_info)));
166
167 return 0;
168
169 parse_prmt_out4:
170 kfree(tm->mmio_info);
171 parse_prmt_out3:
172 memunmap(mmio_count);
173 parse_prmt_out2:
174 kfree(tm);
175 parse_prmt_out1:
176 return -ENOMEM;
177 }
178
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-07 4:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-05 12:49 [PATCH V3] acpi/prmt: find block with specific type KobaK
2024-09-07 3:30 ` kernel test robot
2024-09-07 4:42 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox