From patchwork Wed Jun 10 12:21:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 194100 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42506C433E0 for ; Wed, 10 Jun 2020 12:23:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EC4520734 for ; Wed, 10 Jun 2020 12:23:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729064AbgFJMXk (ORCPT ); Wed, 10 Jun 2020 08:23:40 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:48134 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728583AbgFJMXk (ORCPT ); Wed, 10 Jun 2020 08:23:40 -0400 Received: from 89-64-83-71.dynamic.chello.pl (89.64.83.71) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.415) id c86131f5cc9a7435; Wed, 10 Jun 2020 14:23:37 +0200 From: "Rafael J. Wysocki" To: Dan Williams Cc: Erik Kaneda , rafael.j.wysocki@intel.com, Len Brown , Borislav Petkov , Ira Weiny , James Morse , Myron Stowe , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-nvdimm@lists.01.org, Bob Moore Subject: [RFT][PATCH 2/3] ACPICA: Remove unused memory mappings on interpreter exit Date: Wed, 10 Jun 2020 14:21:48 +0200 Message-ID: <3974162.pZLctmZ5Iv@kreacher> In-Reply-To: <318372766.6LKUBsbRXE@kreacher> References: <158889473309.2292982.18007035454673387731.stgit@dwillia2-desk3.amr.corp.intel.com> <318372766.6LKUBsbRXE@kreacher> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: "Rafael J. Wysocki" For transient memory opregions that are created dynamically under the namespace and interpreter mutexes and go away quickly, there still is the problem that removing their memory mappings may take significant time and so doing that while holding the mutexes should be avoided. For example, unmapping a chunk of memory associated with a memory opregion in Linux involves running synchronize_rcu_expedited() which really should not be done with the namespace mutex held. To address that problem, notice that the unused memory mappings left behind by the "dynamic" opregions that went away need not be unmapped right away when the opregion is deactivated. Instead, they may be unmapped when exiting the interpreter, after the namespace and interpreter mutexes have been dropped (there's one more place dealing with opregions in the debug code that can be treated analogously). Accordingly, change acpi_ev_system_memory_region_setup() to put the unused mappings into a global list instead of unmapping them right away and add acpi_ev_system_release_memory_mappings() to be called when leaving the interpreter in order to unmap the unused memory mappings in the global list (which is protected by the namespace mutex). Signed-off-by: Rafael J. Wysocki --- drivers/acpi/acpica/acevents.h | 2 ++ drivers/acpi/acpica/dbtest.c | 3 ++ drivers/acpi/acpica/evrgnini.c | 51 ++++++++++++++++++++++++++++++++-- drivers/acpi/acpica/exutils.c | 3 ++ drivers/acpi/acpica/utxface.c | 23 +++++++++++++++ include/acpi/acpixf.h | 1 + 6 files changed, 80 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/acpica/acevents.h b/drivers/acpi/acpica/acevents.h index 79f292687bd6..463eb9124765 100644 --- a/drivers/acpi/acpica/acevents.h +++ b/drivers/acpi/acpica/acevents.h @@ -197,6 +197,8 @@ acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function); /* * evregini - Region initialization and setup */ +void acpi_ev_system_release_memory_mappings(void); + acpi_status acpi_ev_system_memory_region_setup(acpi_handle handle, u32 function, diff --git a/drivers/acpi/acpica/dbtest.c b/drivers/acpi/acpica/dbtest.c index 6db44a5ac786..7dac6dae5c48 100644 --- a/drivers/acpi/acpica/dbtest.c +++ b/drivers/acpi/acpica/dbtest.c @@ -8,6 +8,7 @@ #include #include "accommon.h" #include "acdebug.h" +#include "acevents.h" #include "acnamesp.h" #include "acpredef.h" #include "acinterp.h" @@ -768,6 +769,8 @@ acpi_db_test_field_unit_type(union acpi_operand_object *obj_desc) acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); + acpi_ev_system_release_memory_mappings(); + bit_length = obj_desc->common_field.bit_length; byte_length = ACPI_ROUND_BITS_UP_TO_BYTES(bit_length); diff --git a/drivers/acpi/acpica/evrgnini.c b/drivers/acpi/acpica/evrgnini.c index 48a5e6eaf9b9..946c4eef054d 100644 --- a/drivers/acpi/acpica/evrgnini.c +++ b/drivers/acpi/acpica/evrgnini.c @@ -16,6 +16,52 @@ #define _COMPONENT ACPI_EVENTS ACPI_MODULE_NAME("evrgnini") +#ifdef ACPI_OS_MAP_MEMORY_FAST_PATH +static struct acpi_mem_mapping *unused_memory_mappings; + +/******************************************************************************* + * + * FUNCTION: acpi_ev_system_release_memory_mappings + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Release all of the unused memory mappings in the queue + * under the interpreter mutex. + * + ******************************************************************************/ +void acpi_ev_system_release_memory_mappings(void) +{ + struct acpi_mem_mapping *mapping; + + ACPI_FUNCTION_TRACE(acpi_ev_system_release_memory_mappings); + + acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); + + while (unused_memory_mappings) { + mapping = unused_memory_mappings; + unused_memory_mappings = mapping->next; + + acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); + + acpi_os_unmap_memory(mapping->logical_address, mapping->length); + ACPI_FREE(mapping); + + acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); + } + + acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); + + return_VOID; +} +#else /* !ACPI_OS_MAP_MEMORY_FAST_PATH */ +void acpi_ev_system_release_memory_mappings(void) +{ + return_VOID; +} +#endif /* !ACPI_OS_MAP_MEMORY_FAST_PATH */ + /******************************************************************************* * * FUNCTION: acpi_ev_system_memory_region_setup @@ -60,9 +106,8 @@ acpi_ev_system_memory_region_setup(acpi_handle handle, while (local_region_context->first_mapping) { mapping = local_region_context->first_mapping; local_region_context->first_mapping = mapping->next; - acpi_os_unmap_memory(mapping->logical_address, - mapping->length); - ACPI_FREE(mapping); + mapping->next = unused_memory_mappings; + unused_memory_mappings = mapping; } #endif } diff --git a/drivers/acpi/acpica/exutils.c b/drivers/acpi/acpica/exutils.c index 8fefa6feac2f..516d67664392 100644 --- a/drivers/acpi/acpica/exutils.c +++ b/drivers/acpi/acpica/exutils.c @@ -25,6 +25,7 @@ #include #include "accommon.h" +#include "acevents.h" #include "acinterp.h" #include "amlcode.h" @@ -106,6 +107,8 @@ void acpi_ex_exit_interpreter(void) "Could not release AML Interpreter mutex")); } + acpi_ev_system_release_memory_mappings(); + return_VOID; } diff --git a/drivers/acpi/acpica/utxface.c b/drivers/acpi/acpica/utxface.c index ca7c9f0144ef..d972696be846 100644 --- a/drivers/acpi/acpica/utxface.c +++ b/drivers/acpi/acpica/utxface.c @@ -11,6 +11,7 @@ #include #include "accommon.h" +#include "acevents.h" #include "acdebug.h" #define _COMPONENT ACPI_UTILITIES @@ -244,6 +245,28 @@ acpi_status acpi_purge_cached_objects(void) ACPI_EXPORT_SYMBOL(acpi_purge_cached_objects) +/***************************************************************************** + * + * FUNCTION: acpi_release_unused_memory_mappings + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Remove memory mappings that are not used any more. + * + ****************************************************************************/ +void acpi_release_unused_memory_mappings(void) +{ + ACPI_FUNCTION_TRACE(acpi_release_unused_memory_mappings); + + acpi_ev_system_release_memory_mappings(); + + return_VOID; +} + +ACPI_EXPORT_SYMBOL(acpi_release_unused_memory_mappings) + /***************************************************************************** * * FUNCTION: acpi_install_interface diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h index 1dc8d262035b..8d2cc02257ed 100644 --- a/include/acpi/acpixf.h +++ b/include/acpi/acpixf.h @@ -449,6 +449,7 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_size length, struct acpi_pld_info **return_buffer)) +ACPI_EXTERNAL_RETURN_VOID(void acpi_release_unused_memory_mappings(void)) /* * ACPI table load/unload interfaces From patchwork Wed Jun 10 12:22:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 194101 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDE48C433E0 for ; Wed, 10 Jun 2020 12:23:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDAB32078C for ; Wed, 10 Jun 2020 12:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728988AbgFJMXj (ORCPT ); Wed, 10 Jun 2020 08:23:39 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:60752 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728571AbgFJMXj (ORCPT ); Wed, 10 Jun 2020 08:23:39 -0400 Received: from 89-64-83-71.dynamic.chello.pl (89.64.83.71) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.415) id 085cf89194671cbf; Wed, 10 Jun 2020 14:23:35 +0200 From: "Rafael J. Wysocki" To: Dan Williams Cc: Erik Kaneda , rafael.j.wysocki@intel.com, Len Brown , Borislav Petkov , Ira Weiny , James Morse , Myron Stowe , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-nvdimm@lists.01.org, Bob Moore Subject: [RFT][PATCH 3/3] ACPI: OSL: Define ACPI_OS_MAP_MEMORY_FAST_PATH() Date: Wed, 10 Jun 2020 14:22:50 +0200 Message-ID: <6458983.dlBdKaB8z0@kreacher> In-Reply-To: <318372766.6LKUBsbRXE@kreacher> References: <158889473309.2292982.18007035454673387731.stgit@dwillia2-desk3.amr.corp.intel.com> <318372766.6LKUBsbRXE@kreacher> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: "Rafael J. Wysocki" Define the ACPI_OS_MAP_MEMORY_FAST_PATH() macro to allow acpi_ex_system_memory_space_handler() to avoid memory unmapping overhead by deferring the unmap operations to the point when the AML interpreter is exited after removing the operation region that held the memory mappings which are not used any more. That macro, when called on a knwon-existing memory mapping, causes the reference counter of that mapping in the OS layer to be incremented and returns a pointer representing the virtual address of the start of the mapped memory area without really mapping it, so the first subsequent unmap operation on it will only decrement the reference counter. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/osl.c | 67 +++++++++++++++++++++++-------- include/acpi/platform/aclinuxex.h | 4 ++ 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 762c5d50b8fe..b75f3a17776f 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -302,21 +302,8 @@ static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr) iounmap(vaddr); } -/** - * acpi_os_map_iomem - Get a virtual address for a given physical address range. - * @phys: Start of the physical address range to map. - * @size: Size of the physical address range to map. - * - * Look up the given physical address range in the list of existing ACPI memory - * mappings. If found, get a reference to it and return a pointer to it (its - * virtual address). If not found, map it, add it to that list and return a - * pointer to it. - * - * During early init (when acpi_permanent_mmap has not been set yet) this - * routine simply calls __acpi_map_table() to get the job done. - */ -void __iomem __ref -*acpi_os_map_iomem(acpi_physical_address phys, acpi_size size) +static void __iomem __ref *__acpi_os_map_iomem(acpi_physical_address phys, + acpi_size size, bool fast_path) { struct acpi_ioremap *map; void __iomem *virt; @@ -328,8 +315,12 @@ void __iomem __ref return NULL; } - if (!acpi_permanent_mmap) + if (!acpi_permanent_mmap) { + if (WARN_ON(fast_path)) + return NULL; + return __acpi_map_table((unsigned long)phys, size); + } mutex_lock(&acpi_ioremap_lock); /* Check if there's a suitable mapping already. */ @@ -339,6 +330,11 @@ void __iomem __ref goto out; } + if (fast_path) { + mutex_unlock(&acpi_ioremap_lock); + return NULL; + } + map = kzalloc(sizeof(*map), GFP_KERNEL); if (!map) { mutex_unlock(&acpi_ioremap_lock); @@ -366,6 +362,25 @@ void __iomem __ref mutex_unlock(&acpi_ioremap_lock); return map->virt + (phys - map->phys); } + +/** + * acpi_os_map_iomem - Get a virtual address for a given physical address range. + * @phys: Start of the physical address range to map. + * @size: Size of the physical address range to map. + * + * Look up the given physical address range in the list of existing ACPI memory + * mappings. If found, get a reference to it and return a pointer representing + * its virtual address. If not found, map it, add it to that list and return a + * pointer representing its virtual address. + * + * During early init (when acpi_permanent_mmap has not been set yet) call + * __acpi_map_table() to obtain the mapping. + */ +void __iomem __ref *acpi_os_map_iomem(acpi_physical_address phys, + acpi_size size) +{ + return __acpi_os_map_iomem(phys, size, false); +} EXPORT_SYMBOL_GPL(acpi_os_map_iomem); void *__ref acpi_os_map_memory(acpi_physical_address phys, acpi_size size) @@ -374,6 +389,24 @@ void *__ref acpi_os_map_memory(acpi_physical_address phys, acpi_size size) } EXPORT_SYMBOL_GPL(acpi_os_map_memory); +/** + * acpi_os_map_memory_fast_path - Fast-path physical-to-virtual address mapping. + * @phys: Start of the physical address range to map. + * @size: Size of the physical address range to map. + * + * Look up the given physical address range in the list of existing ACPI memory + * mappings. If found, get a reference to it and return a pointer representing + * its virtual address. If not found, return NULL. + * + * During early init (when acpi_permanent_mmap has not been set yet) log a + * warning and return NULL. + */ +void __ref *acpi_os_map_memory_fast_path(acpi_physical_address phys, + acpi_size size) +{ + return __acpi_os_map_iomem(phys, size, true); +} + /* Must be called with mutex_lock(&acpi_ioremap_lock) */ static unsigned long acpi_os_drop_map_ref(struct acpi_ioremap *map) { @@ -1571,6 +1604,8 @@ acpi_status acpi_release_memory(acpi_handle handle, struct resource *res, return acpi_walk_namespace(ACPI_TYPE_REGION, handle, level, acpi_deactivate_mem_region, NULL, res, NULL); + + acpi_release_unused_memory_mappings(); } EXPORT_SYMBOL_GPL(acpi_release_memory); diff --git a/include/acpi/platform/aclinuxex.h b/include/acpi/platform/aclinuxex.h index 04f88f2de781..1d8be4ac9ef9 100644 --- a/include/acpi/platform/aclinuxex.h +++ b/include/acpi/platform/aclinuxex.h @@ -139,6 +139,10 @@ static inline void acpi_os_terminate_debugger(void) * OSL interfaces added by Linux */ +void *acpi_os_map_memory_fast_path(acpi_physical_address where, acpi_size length); + +#define ACPI_OS_MAP_MEMORY_FAST_PATH(a, s) acpi_os_map_memory_fast_path(a, s) + #endif /* __KERNEL__ */ #endif /* __ACLINUXEX_H__ */