linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memblock: use WARN_ONCE when MAX_NUMNODES passed as input parameter
@ 2013-12-20 22:28 Santosh Shilimkar
  2013-12-26 23:45 ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Santosh Shilimkar @ 2013-12-20 22:28 UTC (permalink / raw)
  To: akpm, tj
  Cc: linux-mm, linux-arm-kernel, linux-kernel, Grygorii Strashko,
	Yinghai Lu, Santosh Shilimkar

From: Grygorii Strashko <grygorii.strashko@ti.com>

Check nid parameter and produce warning if it has deprecated MAX_NUMNODES
value. Also re-assign NUMA_NO_NODE value to the nid parameter in this case.

These will help to identify the wrong API usage (the caller) and make code
simpler.

Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
---
Incremental update on the memblock series as suggested by Tejun in
below thread:
	https://lkml.org/lkml/2013/12/14/159

 mm/memblock.c |   21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 71b11d9..6af873a 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -707,11 +707,9 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
 	struct memblock_type *rsv = &memblock.reserved;
 	int mi = *idx & 0xffffffff;
 	int ri = *idx >> 32;
-	bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
 
-	if (nid == MAX_NUMNODES)
-		pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE instead\n",
-			     __func__);
+	if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is deprecated. Use NUMA_NO_NODE instead\n"))
+		nid = NUMA_NO_NODE;
 
 	for ( ; mi < mem->cnt; mi++) {
 		struct memblock_region *m = &mem->regions[mi];
@@ -719,7 +717,7 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
 		phys_addr_t m_end = m->base + m->size;
 
 		/* only memory regions are associated with nodes, check it */
-		if (check_node && nid != memblock_get_region_node(m))
+		if (nid != NUMA_NO_NODE && nid != memblock_get_region_node(m))
 			continue;
 
 		/* scan areas before each reservation for intersection */
@@ -775,11 +773,9 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
 	struct memblock_type *rsv = &memblock.reserved;
 	int mi = *idx & 0xffffffff;
 	int ri = *idx >> 32;
-	bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
 
-	if (nid == MAX_NUMNODES)
-		pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE instead\n",
-			     __func__);
+	if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is deprecated. Use NUMA_NO_NODE instead\n"))
+		nid = NUMA_NO_NODE;
 
 	if (*idx == (u64)ULLONG_MAX) {
 		mi = mem->cnt - 1;
@@ -792,7 +788,7 @@ void __init_memblock __next_free_mem_range_rev(u64 *idx, int nid,
 		phys_addr_t m_end = m->base + m->size;
 
 		/* only memory regions are associated with nodes, check it */
-		if (check_node && nid != memblock_get_region_node(m))
+		if (nid != NUMA_NO_NODE && nid != memblock_get_region_node(m))
 			continue;
 
 		/* scan areas before each reservation for intersection */
@@ -980,9 +976,8 @@ static void * __init memblock_virt_alloc_internal(
 	phys_addr_t alloc;
 	void *ptr;
 
-	if (nid == MAX_NUMNODES)
-		pr_warn("%s: usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE\n",
-			__func__);
+	if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is deprecated. Use NUMA_NO_NODE instead\n"))
+		nid = NUMA_NO_NODE;
 
 	/*
 	 * Detect any accidental use of these APIs after slab is ready, as at
-- 
1.7.9.5

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/memblock: use WARN_ONCE when MAX_NUMNODES passed as input parameter
  2013-12-20 22:28 [PATCH] mm/memblock: use WARN_ONCE when MAX_NUMNODES passed as input parameter Santosh Shilimkar
@ 2013-12-26 23:45 ` David Rientjes
  2013-12-30 12:13   ` Grygorii Strashko
  0 siblings, 1 reply; 4+ messages in thread
From: David Rientjes @ 2013-12-26 23:45 UTC (permalink / raw)
  To: Santosh Shilimkar
  Cc: akpm, tj, linux-mm, linux-arm-kernel, linux-kernel,
	Grygorii Strashko, Yinghai Lu

On Fri, 20 Dec 2013, Santosh Shilimkar wrote:

> diff --git a/mm/memblock.c b/mm/memblock.c
> index 71b11d9..6af873a 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -707,11 +707,9 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
>  	struct memblock_type *rsv = &memblock.reserved;
>  	int mi = *idx & 0xffffffff;
>  	int ri = *idx >> 32;
> -	bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
>  
> -	if (nid == MAX_NUMNODES)
> -		pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE instead\n",
> -			     __func__);
> +	if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is deprecated. Use NUMA_NO_NODE instead\n"))
> +		nid = NUMA_NO_NODE;
>  
>  	for ( ; mi < mem->cnt; mi++) {
>  		struct memblock_region *m = &mem->regions[mi];

Um, why do this at runtime?  This is only used for 
for_each_free_mem_range(), which is used rarely in x86 and memblock-only 
code.  I'm struggling to understand why we can't deterministically fix the 
callers if this condition is possible.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/memblock: use WARN_ONCE when MAX_NUMNODES passed as input parameter
  2013-12-26 23:45 ` David Rientjes
@ 2013-12-30 12:13   ` Grygorii Strashko
  2014-01-02 22:03     ` David Rientjes
  0 siblings, 1 reply; 4+ messages in thread
From: Grygorii Strashko @ 2013-12-30 12:13 UTC (permalink / raw)
  To: David Rientjes, Santosh Shilimkar
  Cc: akpm, tj, linux-mm, linux-arm-kernel, linux-kernel, Yinghai Lu

On 12/27/2013 01:45 AM, David Rientjes wrote:
> On Fri, 20 Dec 2013, Santosh Shilimkar wrote:
>
>> diff --git a/mm/memblock.c b/mm/memblock.c
>> index 71b11d9..6af873a 100644
>> --- a/mm/memblock.c
>> +++ b/mm/memblock.c
>> @@ -707,11 +707,9 @@ void __init_memblock __next_free_mem_range(u64 *idx, int nid,
>>   	struct memblock_type *rsv = &memblock.reserved;
>>   	int mi = *idx & 0xffffffff;
>>   	int ri = *idx >> 32;
>> -	bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
>>
>> -	if (nid == MAX_NUMNODES)
>> -		pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use NUMA_NO_NODE instead\n",
>> -			     __func__);
>> +	if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is deprecated. Use NUMA_NO_NODE instead\n"))
>> +		nid = NUMA_NO_NODE;
>>
>>   	for ( ; mi < mem->cnt; mi++) {
>>   		struct memblock_region *m = &mem->regions[mi];
>
> Um, why do this at runtime?  This is only used for
> for_each_free_mem_range(), which is used rarely in x86 and memblock-only
> code.  I'm struggling to understand why we can't deterministically fix the
> callers if this condition is possible.
>


Unfortunately, It's not so simple as from first look :(
We've modified __next_free_mem_range_x() functions which are part of
Memblock APIs (like memblock_alloc_xxx()) and Nobootmem APIs.
These APIs are used as directly as indirectly (as part of callbacks from 
other MM modules like Sparse), as result, it's not trivial to identify 
all places where MAX_NUMNODES will be used as input parameter.

Same was discussed here in details:
- [PATCH v2 08/23] mm/memblock: Add memblock memory allocation apis
   https://lkml.org/lkml/2013/12/2/1075
- Re: [PATCH 09/24] mm/memblock: Add memblock memory allocation apis
   https://lkml.org/lkml/2013/12/2/907

Regards,
- grygorii

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/memblock: use WARN_ONCE when MAX_NUMNODES passed as input parameter
  2013-12-30 12:13   ` Grygorii Strashko
@ 2014-01-02 22:03     ` David Rientjes
  0 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2014-01-02 22:03 UTC (permalink / raw)
  To: Grygorii Strashko
  Cc: Santosh Shilimkar, akpm, tj, linux-mm, linux-arm-kernel,
	linux-kernel, Yinghai Lu

On Mon, 30 Dec 2013, Grygorii Strashko wrote:

> > > diff --git a/mm/memblock.c b/mm/memblock.c
> > > index 71b11d9..6af873a 100644
> > > --- a/mm/memblock.c
> > > +++ b/mm/memblock.c
> > > @@ -707,11 +707,9 @@ void __init_memblock __next_free_mem_range(u64 *idx,
> > > int nid,
> > >   	struct memblock_type *rsv = &memblock.reserved;
> > >   	int mi = *idx & 0xffffffff;
> > >   	int ri = *idx >> 32;
> > > -	bool check_node = (nid != NUMA_NO_NODE) && (nid != MAX_NUMNODES);
> > > 
> > > -	if (nid == MAX_NUMNODES)
> > > -		pr_warn_once("%s: Usage of MAX_NUMNODES is depricated. Use
> > > NUMA_NO_NODE instead\n",
> > > -			     __func__);
> > > +	if (WARN_ONCE(nid == MAX_NUMNODES, "Usage of MAX_NUMNODES is
> > > deprecated. Use NUMA_NO_NODE instead\n"))
> > > +		nid = NUMA_NO_NODE;
> > > 
> > >   	for ( ; mi < mem->cnt; mi++) {
> > >   		struct memblock_region *m = &mem->regions[mi];
> > 
> > Um, why do this at runtime?  This is only used for
> > for_each_free_mem_range(), which is used rarely in x86 and memblock-only
> > code.  I'm struggling to understand why we can't deterministically fix the
> > callers if this condition is possible.
> > 
> 
> 
> Unfortunately, It's not so simple as from first look :(
> We've modified __next_free_mem_range_x() functions which are part of
> Memblock APIs (like memblock_alloc_xxx()) and Nobootmem APIs.
> These APIs are used as directly as indirectly (as part of callbacks from other
> MM modules like Sparse), as result, it's not trivial to identify all places
> where MAX_NUMNODES will be used as input parameter.
> 

These functions are only used for for_each_free_mem_range() and 
for_each_free_mem_range_reverse().  I can very easily find which callers 
are passing MAX_NUMNODES deterministically.

NACK to doing this at runtime.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-02 22:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 22:28 [PATCH] mm/memblock: use WARN_ONCE when MAX_NUMNODES passed as input parameter Santosh Shilimkar
2013-12-26 23:45 ` David Rientjes
2013-12-30 12:13   ` Grygorii Strashko
2014-01-02 22:03     ` David Rientjes

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).