Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1294937 > unrolled thread

[PATCH] memory-hotplug: don't BUG() in register_memory_resource()

Started byVitaly Kuznetsov <vkuznets@redhat.com>
First post2015-12-18 16:00 +0100
Last post2015-12-22 23:00 +0100
Articles 6 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] memory-hotplug: don't BUG() in register_memory_resource() Vitaly Kuznetsov <vkuznets@redhat.com> - 2015-12-18 16:00 +0100
    Re: [PATCH] memory-hotplug: don't BUG() in  register_memory_resource() Igor Mammedov <imammedo@redhat.com> - 2015-12-18 17:40 +0100
    Re: [PATCH] memory-hotplug: don't BUG() in  register_memory_resource() Andrew Morton <akpm@linux-foundation.org> - 2015-12-19 00:00 +0100
      Re: [PATCH] memory-hotplug: don't BUG() in register_memory_resource() Vitaly Kuznetsov <vkuznets@redhat.com> - 2015-12-21 11:20 +0100
        Re: [PATCH] memory-hotplug: don't BUG() in  register_memory_resource() Andrew Morton <akpm@linux-foundation.org> - 2015-12-22 00:10 +0100
    Re: [PATCH] memory-hotplug: don't BUG() in  register_memory_resource() David Rientjes <rientjes@google.com> - 2015-12-22 23:00 +0100

#1294937 — [PATCH] memory-hotplug: don't BUG() in register_memory_resource()

FromVitaly Kuznetsov <vkuznets@redhat.com>
Date2015-12-18 16:00 +0100
Subject[PATCH] memory-hotplug: don't BUG() in register_memory_resource()
Message-ID<qH4FI-6Xw-15@gated-at.bofh.it>
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 <akpm@linux-foundation.org>
Cc: Tang Chen <tangchen@cn.fujitsu.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Xishi Qiu <qiuxishi@huawei.com>
Cc: Sheng Yong <shengyong1@huawei.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 mm/memory_hotplug.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 67d488a..9392f01 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -127,11 +127,13 @@ void mem_hotplug_done(void)
 }
 
 /* add this memory to iomem resource */
-static struct resource *register_memory_resource(u64 start, u64 size)
+static int register_memory_resource(u64 start, u64 size,
+				    struct resource **resource)
 {
 	struct resource *res;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
-	BUG_ON(!res);
+	if (!res)
+		return -ENOMEM;
 
 	res->name = "System RAM";
 	res->start = start;
@@ -140,9 +142,10 @@ 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 -EEXIST;
 	}
-	return res;
+	*resource = res;
+	return 0;
 }
 
 static void release_memory_resource(struct resource *res)
@@ -1311,9 +1314,9 @@ int __ref add_memory(int nid, u64 start, u64 size)
 	struct resource *res;
 	int ret;
 
-	res = register_memory_resource(start, size);
-	if (!res)
-		return -EEXIST;
+	ret = register_memory_resource(start, size, &res);
+	if (ret)
+		return ret;
 
 	ret = add_memory_resource(nid, res);
 	if (ret < 0)
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1295013 — Re: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()

FromIgor Mammedov <imammedo@redhat.com>
Date2015-12-18 17:40 +0100
SubjectRe: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()
Message-ID<qH6eu-82w-17@gated-at.bofh.it>
In reply to#1294937
On Fri, 18 Dec 2015 15:50:24 +0100
Vitaly Kuznetsov <vkuznets@redhat.com> wrote:

> 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 <akpm@linux-foundation.org>
> Cc: Tang Chen <tangchen@cn.fujitsu.com>
> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> Cc: Xishi Qiu <qiuxishi@huawei.com>
> Cc: Sheng Yong <shengyong1@huawei.com>
> Cc: David Rientjes <rientjes@google.com>
> Cc: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> Cc: Igor Mammedov <imammedo@redhat.com>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  mm/memory_hotplug.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 67d488a..9392f01 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -127,11 +127,13 @@ void mem_hotplug_done(void)
>  }
>  
>  /* add this memory to iomem resource */
> -static struct resource *register_memory_resource(u64 start, u64 size)
> +static int register_memory_resource(u64 start, u64 size,
> +				    struct resource **resource)
>  {
>  	struct resource *res;
>  	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> -	BUG_ON(!res);
> +	if (!res)
> +		return -ENOMEM;
>  
>  	res->name = "System RAM";
>  	res->start = start;
> @@ -140,9 +142,10 @@ 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 -EEXIST;
>  	}
> -	return res;
> +	*resource = res;
> +	return 0;
>  }
>  
>  static void release_memory_resource(struct resource *res)
> @@ -1311,9 +1314,9 @@ int __ref add_memory(int nid, u64 start, u64 size)
>  	struct resource *res;
>  	int ret;
>  
> -	res = register_memory_resource(start, size);
> -	if (!res)
> -		return -EEXIST;
> +	ret = register_memory_resource(start, size, &res);
> +	if (ret)
> +		return ret;
>  
>  	ret = add_memory_resource(nid, res);
>  	if (ret < 0)

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1295231 — Re: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()

FromAndrew Morton <akpm@linux-foundation.org>
Date2015-12-19 00:00 +0100
SubjectRe: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()
Message-ID<qHcad-3mw-15@gated-at.bofh.it>
In reply to#1294937
On Fri, 18 Dec 2015 15:50:24 +0100 Vitaly Kuznetsov <vkuznets@redhat.com> wrote:

> 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.
> 
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> +static int register_memory_resource(u64 start, u64 size,
> +				    struct resource **resource)
>  {
>  	struct resource *res;
>  	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> -	BUG_ON(!res);
> +	if (!res)
> +		return -ENOMEM;
>  
>  	res->name = "System RAM";
>  	res->start = start;
> @@ -140,9 +142,10 @@ 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 -EEXIST;
>  	}
> -	return res;
> +	*resource = res;
> +	return 0;
>  }

Was there a reason for overwriting the request_resource() return value?
Ordinarily it should be propagated back to callers.

Please review.

--- a/mm/memory_hotplug.c~memory-hotplug-dont-bug-in-register_memory_resource-fix
+++ a/mm/memory_hotplug.c
@@ -131,7 +131,9 @@ static int register_memory_resource(u64
 				    struct resource **resource)
 {
 	struct resource *res;
+	int ret = 0;
 	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
+
 	if (!res)
 		return -ENOMEM;
 
@@ -139,13 +141,14 @@ static int register_memory_resource(u64
 	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 -EEXIST;
+	} else {
+		*resource = res;
 	}
-	*resource = res;
-	return 0;
+	return ret;
 }
 
 static void release_memory_resource(struct resource *res)
_

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1295883

FromVitaly Kuznetsov <vkuznets@redhat.com>
Date2015-12-21 11:20 +0100
Message-ID<qI5Jn-5ac-3@gated-at.bofh.it>
In reply to#1295231
Andrew Morton <akpm@linux-foundation.org> writes:

> On Fri, 18 Dec 2015 15:50:24 +0100 Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>
>> 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.
>> 
>> --- a/mm/memory_hotplug.c
>> +++ b/mm/memory_hotplug.c
>> +static int register_memory_resource(u64 start, u64 size,
>> +				    struct resource **resource)
>>  {
>>  	struct resource *res;
>>  	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
>> -	BUG_ON(!res);
>> +	if (!res)
>> +		return -ENOMEM;
>>  
>>  	res->name = "System RAM";
>>  	res->start = start;
>> @@ -140,9 +142,10 @@ 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 -EEXIST;
>>  	}
>> -	return res;
>> +	*resource = res;
>> +	return 0;
>>  }
>
> Was there a reason for overwriting the request_resource() return
> value?
> Ordinarily it should be propagated back to callers.
>
> Please review.
>

This is a nice-to-have addition but it will break at least ACPI
memhotplug: request_resource() has the following:

conflict = request_resource_conflict(root, new);
return conflict ? -EBUSY : 0;

so we'll end up returning -EBUSY from register_memory_resource() and
add_memory(), at the same time acpi_memory_enable_device() counts on
-EEXIST:

result = add_memory(node, info->start_addr, info->length);

/*
* If the memory block has been used by the kernel, add_memory()
* returns -EEXIST. If add_memory() returns the other error, it
* means that this memory block is not used by the kernel.
*/
if (result && result != -EEXIST)
continue;

So I see 3 options here:
1) Keep the overwrite
2) Change the request_resource() return value to -EEXIST
3) Adapt all add_memory() call sites to -EBUSY.

Please let me know your preference.

> --- a/mm/memory_hotplug.c~memory-hotplug-dont-bug-in-register_memory_resource-fix
> +++ a/mm/memory_hotplug.c
> @@ -131,7 +131,9 @@ static int register_memory_resource(u64
>  				    struct resource **resource)
>  {
>  	struct resource *res;
> +	int ret = 0;
>  	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> +
>  	if (!res)
>  		return -ENOMEM;
>
> @@ -139,13 +141,14 @@ static int register_memory_resource(u64
>  	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 -EEXIST;
> +	} else {
> +		*resource = res;
>  	}
> -	*resource = res;
> -	return 0;
> +	return ret;
>  }
>
>  static void release_memory_resource(struct resource *res)
> _

-- 
  Vitaly
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1296283 — Re: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()

FromAndrew Morton <akpm@linux-foundation.org>
Date2015-12-22 00:10 +0100
SubjectRe: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()
Message-ID<qIhKy-4p5-27@gated-at.bofh.it>
In reply to#1295883
On Mon, 21 Dec 2015 11:13:15 +0100 Vitaly Kuznetsov <vkuznets@redhat.com> wrote:

> Andrew Morton <akpm@linux-foundation.org> writes:
> 
> > On Fri, 18 Dec 2015 15:50:24 +0100 Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
> >
> >> 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.
> >> 
> >> --- a/mm/memory_hotplug.c
> >> +++ b/mm/memory_hotplug.c
> >> +static int register_memory_resource(u64 start, u64 size,
> >> +				    struct resource **resource)
> >>  {
> >>  	struct resource *res;
> >>  	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> >> -	BUG_ON(!res);
> >> +	if (!res)
> >> +		return -ENOMEM;
> >>  
> >>  	res->name = "System RAM";
> >>  	res->start = start;
> >> @@ -140,9 +142,10 @@ 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 -EEXIST;
> >>  	}
> >> -	return res;
> >> +	*resource = res;
> >> +	return 0;
> >>  }
> >
> > Was there a reason for overwriting the request_resource() return
> > value?
> > Ordinarily it should be propagated back to callers.
> >
> > Please review.
> >
> 
> This is a nice-to-have addition but it will break at least ACPI
> memhotplug: request_resource() has the following:
> 
> conflict = request_resource_conflict(root, new);
> return conflict ? -EBUSY : 0;
> 
> so we'll end up returning -EBUSY from register_memory_resource() and
> add_memory(), at the same time acpi_memory_enable_device() counts on
> -EEXIST:
> 
> result = add_memory(node, info->start_addr, info->length);
> 
> /*
> * If the memory block has been used by the kernel, add_memory()
> * returns -EEXIST. If add_memory() returns the other error, it
> * means that this memory block is not used by the kernel.
> */
> if (result && result != -EEXIST)
> continue;
> 
> So I see 3 options here:
> 1) Keep the overwrite
> 2) Change the request_resource() return value to -EEXIST
> 3) Adapt all add_memory() call sites to -EBUSY.
> 
> Please let me know your preference.

urgh, what a mess.  We should standardize on EBUSY or EEXIST, I don't
see that it matter much which is chosen.  And for robustness the
callers should be checking for (err < 0) unless there's a very good
reason otherwise.

But it doesn't seem terribly important.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1297080 — Re: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()

FromDavid Rientjes <rientjes@google.com>
Date2015-12-22 23:00 +0100
SubjectRe: [PATCH] memory-hotplug: don't BUG() in register_memory_resource()
Message-ID<qID8l-TR-1@gated-at.bofh.it>
In reply to#1294937
On Fri, 18 Dec 2015, Vitaly Kuznetsov wrote:

> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 67d488a..9392f01 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -127,11 +127,13 @@ void mem_hotplug_done(void)
>  }
>  
>  /* add this memory to iomem resource */
> -static struct resource *register_memory_resource(u64 start, u64 size)
> +static int register_memory_resource(u64 start, u64 size,
> +				    struct resource **resource)
>  {
>  	struct resource *res;
>  	res = kzalloc(sizeof(struct resource), GFP_KERNEL);
> -	BUG_ON(!res);
> +	if (!res)
> +		return -ENOMEM;
>  
>  	res->name = "System RAM";
>  	res->start = start;
> @@ -140,9 +142,10 @@ 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 -EEXIST;
>  	}
> -	return res;
> +	*resource = res;
> +	return 0;
>  }
>  
>  static void release_memory_resource(struct resource *res)
> @@ -1311,9 +1314,9 @@ int __ref add_memory(int nid, u64 start, u64 size)
>  	struct resource *res;
>  	int ret;
>  
> -	res = register_memory_resource(start, size);
> -	if (!res)
> -		return -EEXIST;
> +	ret = register_memory_resource(start, size, &res);
> +	if (ret)
> +		return ret;
>  
>  	ret = add_memory_resource(nid, res);
>  	if (ret < 0)

Wouldn't it be simpler and cleaner to keep the return type of 
register_memory_resource() the same and return ERR_PTR(-ENOMEM) or 
ERR_PTR(-EEXIST) on error?  add_memory() can check IS_ERR(res) and return 
PTR_ERR(res).
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web