diff mbox series

[RFC,v3,3/5] mm/memory_hotplug: Check for IORESOURCE_SYSRAM in release_mem_region_adjustable

Message ID 20181002150029.23461-4-osalvador@techadventures.net (mailing list archive)
State New, archived
Headers show
Series Do not touch pages/zones during hot-remove path | expand

Commit Message

Oscar Salvador Oct. 2, 2018, 3 p.m. UTC
From: Oscar Salvador <osalvador@suse.de>

This is a preparation for the next patch.

Currently, we only call release_mem_region_adjustable() in __remove_pages
if the zone is not ZONE_DEVICE, because resources that belong to
HMM/devm are being released by themselves with devm_release_mem_region.

Since we do not want to touch any zone/page stuff during the removing
of the memory (but during the offlining), we do not want to check for
the zone here.
So we need another way to tell release_mem_region_adjustable() to not realease
the resource in case it belongs to HMM/devm.

HMM/devm acquires/releases a resource through

These resources have the flag IORESOURCE_MEM, while resources acquired by
hot-add memory path (register_memory_resource()) contain

So, we can check for this flag in release_mem_region_adjustable, and if the
resource does not contain such flag, we know that we are dealing with a HMM/devm
resource, so we can back off.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
 kernel/resource.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series


diff --git a/kernel/resource.c b/kernel/resource.c
index 81937830a42f..6956ce3a4730 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -1272,6 +1272,21 @@  int release_mem_region_adjustable(struct resource *parent,
+		/*
+		 * All memory regions added from memory-hotplug path
+		 * have the flag IORESOURCE_SYSTEM_RAM.
+		 * If the resource does not have this flag, we know that
+		 * we are dealing with a resource coming from HMM/devm.
+		 * HMM/devm use another mechanism to add/release a resource.
+		 * This goes via devm_request_mem_region/devm_release_mem_region.
+		 * HMM/devm take care to release their resources when they want, so
+		 * if we are dealing with them, let us just back off here.
+		 */
+		if (!(res->flags & IORESOURCE_SYSRAM)) {
+			ret = 0;
+			break;
+		}
 		if (!(res->flags & IORESOURCE_MEM))