diff mbox

powerpc/mm: fix a hardcode on memory boundary checking

Message ID 20170112090906.17864-1-rui.teng@linux.vnet.ibm.com (mailing list archive)
State Accepted
Commit 23493c121912a39f0262e0dbeb236e1d39efa4d5
Headers show

Commit Message

Rui Teng Jan. 12, 2017, 9:09 a.m. UTC
The offset of hugepage block will not be 16G, if the expected
page is more than one. Calculate the totol size instead of the
hardcode value.

Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
---
 arch/powerpc/mm/hash_utils_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Michael Ellerman Jan. 31, 2017, 9:11 a.m. UTC | #1
Rui Teng <rui.teng@linux.vnet.ibm.com> writes:

> The offset of hugepage block will not be 16G, if the expected
> page is more than one. Calculate the totol size instead of the
> hardcode value.

I assume you found this by code inspection and not by triggering an
actual bug?

cheers

> diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
> index 8033493..b829f8e 100644
> --- a/arch/powerpc/mm/hash_utils_64.c
> +++ b/arch/powerpc/mm/hash_utils_64.c
> @@ -506,7 +506,7 @@ static int __init htab_dt_scan_hugepage_blocks(unsigned long node,
>  	printk(KERN_INFO "Huge page(16GB) memory: "
>  			"addr = 0x%lX size = 0x%lX pages = %d\n",
>  			phys_addr, block_size, expected_pages);
> -	if (phys_addr + (16 * GB) <= memblock_end_of_DRAM()) {
> +	if (phys_addr + block_size * expected_pages <= memblock_end_of_DRAM()) {
>  		memblock_reserve(phys_addr, block_size * expected_pages);
>  		add_gpage(phys_addr, block_size, expected_pages);
>  	}
> -- 
> 2.9.0
Rui Teng Feb. 6, 2017, 2:50 a.m. UTC | #2
On 31/01/2017 5:11 PM, Michael Ellerman wrote:
> Rui Teng <rui.teng@linux.vnet.ibm.com> writes:
>
>> The offset of hugepage block will not be 16G, if the expected
>> page is more than one. Calculate the totol size instead of the
>> hardcode value.
>
> I assume you found this by code inspection and not by triggering an
> actual bug?

Yes, I found this problem only by code inspection. We were finding the
ways to enable 16G huge page besides changing the device tree. For 
example, provide a new interface to set these size and pages parameters.
So that I think it may cause problem here.

>
> cheers
>
>> diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
>> index 8033493..b829f8e 100644
>> --- a/arch/powerpc/mm/hash_utils_64.c
>> +++ b/arch/powerpc/mm/hash_utils_64.c
>> @@ -506,7 +506,7 @@ static int __init htab_dt_scan_hugepage_blocks(unsigned long node,
>>  	printk(KERN_INFO "Huge page(16GB) memory: "
>>  			"addr = 0x%lX size = 0x%lX pages = %d\n",
>>  			phys_addr, block_size, expected_pages);
>> -	if (phys_addr + (16 * GB) <= memblock_end_of_DRAM()) {
>> +	if (phys_addr + block_size * expected_pages <= memblock_end_of_DRAM()) {
>>  		memblock_reserve(phys_addr, block_size * expected_pages);
>>  		add_gpage(phys_addr, block_size, expected_pages);
>>  	}
>> --
>> 2.9.0
>
Anshuman Khandual July 5, 2017, 4:45 a.m. UTC | #3
On 01/12/2017 02:39 PM, Rui Teng wrote:
> The offset of hugepage block will not be 16G, if the expected
> page is more than one. Calculate the totol size instead of the
> hardcode value.
> 
> Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>

I have a redundant patch, this one is the original.

Tested-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Michael Ellerman Aug. 7, 2017, 10:41 a.m. UTC | #4
On Thu, 2017-01-12 at 09:09:06 UTC, Rui Teng wrote:
> The offset of hugepage block will not be 16G, if the expected
> page is more than one. Calculate the totol size instead of the
> hardcode value.
> 
> Signed-off-by: Rui Teng <rui.teng@linux.vnet.ibm.com>
> Tested-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/23493c121912a39f0262e0dbeb236e

cheers
diff mbox

Patch

diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 8033493..b829f8e 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -506,7 +506,7 @@  static int __init htab_dt_scan_hugepage_blocks(unsigned long node,
 	printk(KERN_INFO "Huge page(16GB) memory: "
 			"addr = 0x%lX size = 0x%lX pages = %d\n",
 			phys_addr, block_size, expected_pages);
-	if (phys_addr + (16 * GB) <= memblock_end_of_DRAM()) {
+	if (phys_addr + block_size * expected_pages <= memblock_end_of_DRAM()) {
 		memblock_reserve(phys_addr, block_size * expected_pages);
 		add_gpage(phys_addr, block_size, expected_pages);
 	}