* [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early
@ 2020-08-21 17:42 Rafael J. Wysocki
2020-08-21 18:28 ` Kenneth R. Crudup
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2020-08-21 17:42 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Mika Westerberg, Krogerus, Heikki, Kenneth R. Crudup
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
After commit 1757659d022b ("ACPI: OSL: Implement deferred unmapping
of ACPI memory") in some cases acpi_release_memory() may return
before the target memory mappings actually go away, because they
are released asynchronously now.
Prevent it from returning prematurely by making it wait for the next
RCU grace period to elapse, for all of the RCU callbacks to complete
and for all of the scheduled work items to be flushed before
returning.
Fixes: 1757659d022b ("ACPI: OSL: Implement deferred unmapping of ACPI memory")
Reported-by: Kenneth R. Crudup <kenny@panix.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/osl.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
Index: linux-pm/drivers/acpi/osl.c
===================================================================
--- linux-pm.orig/drivers/acpi/osl.c
+++ linux-pm/drivers/acpi/osl.c
@@ -1575,11 +1575,26 @@ static acpi_status acpi_deactivate_mem_r
acpi_status acpi_release_memory(acpi_handle handle, struct resource *res,
u32 level)
{
+ acpi_status status;
+
if (!(res->flags & IORESOURCE_MEM))
return AE_TYPE;
- return acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
- acpi_deactivate_mem_region, NULL, res, NULL);
+ status = acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
+ acpi_deactivate_mem_region, NULL,
+ res, NULL);
+ if (ACPI_FAILURE(status))
+ return status;
+
+ /*
+ * Wait for all of the mappings queued up for removal by
+ * acpi_deactivate_mem_region() to actually go away.
+ */
+ synchronize_rcu();
+ rcu_barrier();
+ flush_scheduled_work();
+
+ return AE_OK;
}
EXPORT_SYMBOL_GPL(acpi_release_memory);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early
2020-08-21 17:42 [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early Rafael J. Wysocki
@ 2020-08-21 18:28 ` Kenneth R. Crudup
2020-08-24 8:50 ` Heikki Krogerus
2020-08-24 14:06 ` Mika Westerberg
2 siblings, 0 replies; 4+ messages in thread
From: Kenneth R. Crudup @ 2020-08-21 18:28 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux ACPI, LKML, Mika Westerberg, Krogerus, Heikki
Works here for me:
----
$ l /sys/class/typec
total 0
10012 0 drwxr-xr-x 2 root root 0 Aug 21 11:25 ./
10 0 drwxr-xr-x 67 root root 0 Aug 21 11:25 ../
27771 0 lrwxrwxrwx 1 root root 0 Aug 21 11:25 port0 -> ../../devices/platform/USBC000:00/typec/port0/
35601 0 lrwxrwxrwx 1 root root 0 Aug 21 11:25 port0-partner -> ../../devices/platform/USBC000:00/typec/port0/port0-partner/
36686 0 lrwxrwxrwx 1 root root 0 Aug 21 11:25 port1 -> ../../devices/platform/USBC000:00/typec/port1/
$
----
On Fri, 21 Aug 2020, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> After commit 1757659d022b ("ACPI: OSL: Implement deferred unmapping
> of ACPI memory") in some cases acpi_release_memory() may return
> before the target memory mappings actually go away, because they
> are released asynchronously now.
>
> Prevent it from returning prematurely by making it wait for the next
> RCU grace period to elapse, for all of the RCU callbacks to complete
> and for all of the scheduled work items to be flushed before
> returning.
>
> Fixes: 1757659d022b ("ACPI: OSL: Implement deferred unmapping of ACPI memory")
> Reported-by: Kenneth R. Crudup <kenny@panix.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/acpi/osl.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> Index: linux-pm/drivers/acpi/osl.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/osl.c
> +++ linux-pm/drivers/acpi/osl.c
> @@ -1575,11 +1575,26 @@ static acpi_status acpi_deactivate_mem_r
> acpi_status acpi_release_memory(acpi_handle handle, struct resource *res,
> u32 level)
> {
> + acpi_status status;
> +
> if (!(res->flags & IORESOURCE_MEM))
> return AE_TYPE;
>
> - return acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
> - acpi_deactivate_mem_region, NULL, res, NULL);
> + status = acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
> + acpi_deactivate_mem_region, NULL,
> + res, NULL);
> + if (ACPI_FAILURE(status))
> + return status;
> +
> + /*
> + * Wait for all of the mappings queued up for removal by
> + * acpi_deactivate_mem_region() to actually go away.
> + */
> + synchronize_rcu();
> + rcu_barrier();
> + flush_scheduled_work();
> +
> + return AE_OK;
> }
> EXPORT_SYMBOL_GPL(acpi_release_memory);
>
>
>
>
>
--
Kenneth R. Crudup Sr. SW Engineer, Scott County Consulting, Orange County CA
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early
2020-08-21 17:42 [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early Rafael J. Wysocki
2020-08-21 18:28 ` Kenneth R. Crudup
@ 2020-08-24 8:50 ` Heikki Krogerus
2020-08-24 14:06 ` Mika Westerberg
2 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2020-08-24 8:50 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux ACPI, LKML, Mika Westerberg, Kenneth R. Crudup
On Fri, Aug 21, 2020 at 07:42:55PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> After commit 1757659d022b ("ACPI: OSL: Implement deferred unmapping
> of ACPI memory") in some cases acpi_release_memory() may return
> before the target memory mappings actually go away, because they
> are released asynchronously now.
>
> Prevent it from returning prematurely by making it wait for the next
> RCU grace period to elapse, for all of the RCU callbacks to complete
> and for all of the scheduled work items to be flushed before
> returning.
>
> Fixes: 1757659d022b ("ACPI: OSL: Implement deferred unmapping of ACPI memory")
> Reported-by: Kenneth R. Crudup <kenny@panix.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
FWIW:
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/acpi/osl.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> Index: linux-pm/drivers/acpi/osl.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/osl.c
> +++ linux-pm/drivers/acpi/osl.c
> @@ -1575,11 +1575,26 @@ static acpi_status acpi_deactivate_mem_r
> acpi_status acpi_release_memory(acpi_handle handle, struct resource *res,
> u32 level)
> {
> + acpi_status status;
> +
> if (!(res->flags & IORESOURCE_MEM))
> return AE_TYPE;
>
> - return acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
> - acpi_deactivate_mem_region, NULL, res, NULL);
> + status = acpi_walk_namespace(ACPI_TYPE_REGION, handle, level,
> + acpi_deactivate_mem_region, NULL,
> + res, NULL);
> + if (ACPI_FAILURE(status))
> + return status;
> +
> + /*
> + * Wait for all of the mappings queued up for removal by
> + * acpi_deactivate_mem_region() to actually go away.
> + */
> + synchronize_rcu();
> + rcu_barrier();
> + flush_scheduled_work();
> +
> + return AE_OK;
> }
> EXPORT_SYMBOL_GPL(acpi_release_memory);
thanks,
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early
2020-08-21 17:42 [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early Rafael J. Wysocki
2020-08-21 18:28 ` Kenneth R. Crudup
2020-08-24 8:50 ` Heikki Krogerus
@ 2020-08-24 14:06 ` Mika Westerberg
2 siblings, 0 replies; 4+ messages in thread
From: Mika Westerberg @ 2020-08-24 14:06 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux ACPI, LKML, Krogerus, Heikki, Kenneth R. Crudup
On Fri, Aug 21, 2020 at 07:42:55PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> After commit 1757659d022b ("ACPI: OSL: Implement deferred unmapping
> of ACPI memory") in some cases acpi_release_memory() may return
> before the target memory mappings actually go away, because they
> are released asynchronously now.
>
> Prevent it from returning prematurely by making it wait for the next
> RCU grace period to elapse, for all of the RCU callbacks to complete
> and for all of the scheduled work items to be flushed before
> returning.
>
> Fixes: 1757659d022b ("ACPI: OSL: Implement deferred unmapping of ACPI memory")
> Reported-by: Kenneth R. Crudup <kenny@panix.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-24 14:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-21 17:42 [PATCH] ACPI: OSL: Prevent acpi_release_memory() from returning too early Rafael J. Wysocki
2020-08-21 18:28 ` Kenneth R. Crudup
2020-08-24 8:50 ` Heikki Krogerus
2020-08-24 14:06 ` Mika Westerberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).