Skip to contentSkip to conversation

memory-hotplug: cleanup register_memory_resource()

PATCH In review Vitaly Kuznetsov 3 participants 7 messages Jan 4, 2016 – Jan 13, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover memory-hotplug: cleanup register_memory_resource()

This series is a successor for the previously sent "[PATCH] memory-hotplug:
don't BUG() in register_memory_resource()". Changes since it are:
- Use ERR_PTR/PTR_ERR/IS_ERR() [David Rientjes]
- Add "memory-hotplug: keep the request_resource() error code" patch [Andrew Morton]

Cc Andrew Morton <[email protected]>
Cc David Rientjes <[email protected]>
Cc Tang Chen <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Sheng Yong <[email protected]>
Cc Zhu Guihua <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Vrabel <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>

Vitaly Kuznetsov (2):
memory-hotplug: don't BUG() in register_memory_resource()
memory-hotplug: keep the request_resource() error code

 drivers/acpi/acpi_memhotplug.c |  4 ++--
 mm/memory_hotplug.c            | 13 ++++++++-----
 2 files changed, 10 insertions(+), 7 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/2 memory-hotplug: don't BUG() in register_memory_resource()

Out of memory condition is not a bug and while we can't add new memory in such case crashing the system seems wrong. Propagating the return value from register_memory_resource() requires interface change.

Cc Andrew Morton <[email protected]>
Cc David Rientjes <[email protected]>
Cc Tang Chen <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Sheng Yong <[email protected]>
Cc Zhu Guihua <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Vrabel <[email protected]>
Cc Igor Mammedov <[email protected]>

---
Changes since v1:
- Use ERR_PTR/PTR_ERR/IS_ERR() [David Rientjes]

---
 mm/memory_hotplug.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
mm/memory_hotplug.c +5 -4
index a042a9d..92f9595 100644
@@ -131,7 +131,8 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 {
 	struct resource *res;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
-	BUG_ON(!res);
+	if (!res)
+		return ERR_PTR(-ENOMEM);
 
 	res->name = "System RAM";
 	res->start = start;
@@ -140,7 +141,7 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 	if (request_resource(&iomem_resource, res) < 0) {
 		pr_debug("System RAM resource %pR cannot be added\n", res);
 		kfree(res);
-		res = NULL;
+		return ERR_PTR(-EEXIST);
 	}
 	return res;
 }
@@ -1312,8 +1313,8 @@ int __ref add_memory(int nid, u64 start, u64 size)
 	int ret;
 
 	res = register_memory_resource(start, size);
-	if (!res)
-		return -EEXIST;
+	if (IS_ERR(res))
+		return PTR_ERR(res);
 
 	ret = add_memory_resource(nid, res);
 	if (ret < 0)
Signature · 7 lines
2.4.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] memory-hotplug: don't BUG() in register_memory_resource()

Quoted 4 lines · Vitaly Kuznetsov

Out of memory condition is not a bug and while we can't add new memory in such case crashing the system seems wrong. Propagating the return value from register_memory_resource() requires interface change.

Quoted 11 lines
Cc Andrew Morton <[email protected]>
Cc David Rientjes <[email protected]>
Cc Tang Chen <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Xishi Qiu <[email protected]>
Cc Sheng Yong <[email protected]>
Cc Zhu Guihua <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Vrabel <[email protected]>
Cc Igor Mammedov <[email protected]>
#3 lore raw

PATCH v2 2/2 memory-hotplug: keep the request_resource() error code

In reply to Vitaly Kuznetsov

Don't overwrite the request_resource() return value with -EEXIST in register_memory_resource(), just propagate the return value. As we return -EBUSY instead of -EEXIST when the desired resource is already occupied now we need to adapt acpi_memory_enable_device(). -EBUSY is currently the only possible error returned by request_resource() so this is just a cleanup, no functional changes intended.

Cc Andrew Morton <[email protected]>
Cc David Rientjes <[email protected]>
Cc Tang Chen <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Vrabel <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/acpi/acpi_memhotplug.c | 4 ++--
 mm/memory_hotplug.c            | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/acpi/acpi_memhotplug.c +2 -2
index 6b0d3ef..e367e4b 100644
@@ -232,10 +232,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 
 		/*
 		 * If the memory block has been used by the kernel, add_memory()
-		 * returns -EEXIST. If add_memory() returns the other error, it
+		 * returns -EBUSY. If add_memory() returns the other error, it
 		 * means that this memory block is not used by the kernel.
 		 */
-		if (result && result != -EEXIST)
+		if (result && result != -EBUSY)
 			continue;
 
 		result = acpi_bind_memory_blocks(info, mem_device->device);
mm/memory_hotplug.c +4 -2
index 92f9595..07eab2c 100644
@@ -130,6 +130,7 @@ void mem_hotplug_done(void)
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
 	struct resource *res;
+	int ret;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
 	if (!res)
 		return ERR_PTR(-ENOMEM);
@@ -138,10 +139,11 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 	res->start = start;
 	res->end = start + size - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-	if (request_resource(&iomem_resource, res) < 0) {
+	ret = request_resource(&iomem_resource, res);
+	if (ret < 0) {
 		pr_debug("System RAM resource %pR cannot be added\n", res);
 		kfree(res);
-		return ERR_PTR(-EEXIST);
+		return ERR_PTR(ret);
 	}
 	return res;
 }
Signature · 1 line
2.4.3
Acked-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] memory-hotplug: keep the request_resource() error code

Quoted 7 lines · Vitaly Kuznetsov

Don't overwrite the request_resource() return value with -EEXIST in register_memory_resource(), just propagate the return value. As we return -EBUSY instead of -EEXIST when the desired resource is already occupied now we need to adapt acpi_memory_enable_device(). -EBUSY is currently the only possible error returned by request_resource() so this is just a cleanup, no functional changes intended.

Quoted 11 lines
Cc Andrew Morton <[email protected]>
Cc David Rientjes <[email protected]>
Cc Tang Chen <[email protected]>
Cc Naoya Horiguchi <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Vrabel <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>

for the ACPI part and I'm assumig that this will go in through the mm tree.

Quoted 49 lines
---
 drivers/acpi/acpi_memhotplug.c | 4 ++--
 mm/memory_hotplug.c            | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/acpi/acpi_memhotplug.c +2 -2
index 6b0d3ef..e367e4b 100644
@@ -232,10 +232,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 
 		/*
 		 * If the memory block has been used by the kernel, add_memory()
-		 * returns -EEXIST. If add_memory() returns the other error, it
+		 * returns -EBUSY. If add_memory() returns the other error, it
 		 * means that this memory block is not used by the kernel.
 		 */
-		if (result && result != -EEXIST)
+		if (result && result != -EBUSY)
 			continue;
 
 		result = acpi_bind_memory_blocks(info, mem_device->device);
mm/memory_hotplug.c +4 -2
index 92f9595..07eab2c 100644
@@ -130,6 +130,7 @@ void mem_hotplug_done(void)
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
 	struct resource *res;
+	int ret;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
 	if (!res)
 		return ERR_PTR(-ENOMEM);
@@ -138,10 +139,11 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 	res->start = start;
 	res->end = start + size - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-	if (request_resource(&iomem_resource, res) < 0) {
+	ret = request_resource(&iomem_resource, res);
+	if (ret < 0) {
 		pr_debug("System RAM resource %pR cannot be added\n", res);
 		kfree(res);
-		return ERR_PTR(-EEXIST);
+		return ERR_PTR(ret);
 	}
 	return res;
 }
Signature · 8 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

Re: [PATCH v2 2/2] memory-hotplug: keep the request_resource() error code

In reply to Vitaly Kuznetsov
Quoted 33 lines · Vitaly Kuznetsov
drivers/acpi/acpi_memhotplug.c +2 -2
index 6b0d3ef..e367e4b 100644
@@ -232,10 +232,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 
 		/*
 		 * If the memory block has been used by the kernel, add_memory()
-		 * returns -EEXIST. If add_memory() returns the other error, it
+		 * returns -EBUSY. If add_memory() returns the other error, it
 		 * means that this memory block is not used by the kernel.
 		 */
-		if (result && result != -EEXIST)
+		if (result && result != -EBUSY)
 			continue;
 
 		result = acpi_bind_memory_blocks(info, mem_device->device);
mm/memory_hotplug.c +1 -0
index 92f9595..07eab2c 100644
@@ -130,6 +130,7 @@ void mem_hotplug_done(void)
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
 	struct resource *res;
+	int ret;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
 	if (!res)
 		return ERR_PTR(-ENOMEM);
@@ -138,10 +139,11 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 	res->start = start;
 	res->end = start + size - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;

mm/memory_hotplug.c static struct resource *register_memory_resource(u64 start, u64 size) · line 149

Quoted 10 lines
mm/memory_hotplug.c +3 -2
-	if (request_resource(&iomem_resource, res) < 0) {
+	ret = request_resource(&iomem_resource, res);
+	if (ret < 0) {
 		pr_debug("System RAM resource %pR cannot be added\n", res);
 		kfree(res);
-		return ERR_PTR(-EEXIST);
+		return ERR_PTR(ret);
 	}
 	return res;
 }

The result of this change is that add_memory() returns -EBUSY instead of -EEXIST for overlapping ranges. This patch breaks hv_mem_hot_add() since it strictly uses a return value of -EEXIST to indicate a non-transient failure, so NACK. It also changes the return value of both the "probe" and "dlpar" (on ppc) userspace triggers, which I could imagine is tested from existing userspace scripts.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [PATCH v2 2/2] memory-hotplug: keep the request_resource() error code

Quoted 42 lines · David Rientjes
Quoted 40 lines · Vitaly Kuznetsov
drivers/acpi/acpi_memhotplug.c +2 -2
index 6b0d3ef..e367e4b 100644
@@ -232,10 +232,10 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
 
 		/*
 		 * If the memory block has been used by the kernel, add_memory()
-		 * returns -EEXIST. If add_memory() returns the other error, it
+		 * returns -EBUSY. If add_memory() returns the other error, it
 		 * means that this memory block is not used by the kernel.
 		 */
-		if (result && result != -EEXIST)
+		if (result && result != -EBUSY)
 			continue;
 
 		result = acpi_bind_memory_blocks(info, mem_device->device);
mm/memory_hotplug.c +4 -2
index 92f9595..07eab2c 100644
@@ -130,6 +130,7 @@ void mem_hotplug_done(void)
 static struct resource *register_memory_resource(u64 start, u64 size)
 {
 	struct resource *res;
+	int ret;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
 	if (!res)
 		return ERR_PTR(-ENOMEM);
@@ -138,10 +139,11 @@ static struct resource *register_memory_resource(u64 start, u64 size)
 	res->start = start;
 	res->end = start + size - 1;
 	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
-	if (request_resource(&iomem_resource, res) < 0) {
+	ret = request_resource(&iomem_resource, res);
+	if (ret < 0) {
 		pr_debug("System RAM resource %pR cannot be added\n", res);
 		kfree(res);
-		return ERR_PTR(-EEXIST);
+		return ERR_PTR(ret);
Quoted 8 lines

mm/memory_hotplug.c static struct resource *register_memory_resource(u64 start, u64 size) · line 149

Quoted 3 lines
mm/memory_hotplug.c +0 -0
 	}
 	return res;
 }

The result of this change is that add_memory() returns -EBUSY instead of -EEXIST for overlapping ranges. This patch breaks hv_mem_hot_add() since it strictly uses a return value of -EEXIST to indicate a non-transient failure, so NACK.

While this is shameful but fixable ...

Quoted 3 lines

It also changes the return value of both the "probe"
and "dlpar" (on ppc) userspace triggers, which I could imagine is tested from existing userspace scripts.

this is probably a show-stopper as we're bound by "we don't break userspace" rule (and it's not worth it anyway). Thanks for pointing this out!

Andrew, please drop this patch from your queue permanently. The patch 1 of the series is worthwhile (and is acked by David).

Thanks,

Signature · 7 lines
  Vitaly

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>