Skip to contentSkip to conversation

x86: arch_add_memory round up address

PATCH In review Shaohua Li 3 participants 10 messages Oct 9, 2008 – Oct 14, 2008

Subsystems (2)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 1/1 x86: arch_add_memory round up address

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/init_64.c +2 -1
Index: linux/arch/x86/mm/init_64.c
===================================================================
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start, 
 	unsigned long nr_pages = size >> PAGE_SHIFT;
 	int ret;
 
-	last_mapped_pfn = init_memory_mapping(start, start + size-1);
+	last_mapped_pfn = init_memory_mapping(start,
+		round_up(start + size-1, PAGE_SIZE));
 	if (last_mapped_pfn > max_pfn_mapped)
 		max_pfn_mapped = last_mapped_pfn;
 
#1 lore raw
Quoted 12 lines · Shaohua Li

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

last_mapped_pfn = init_memory_mapping(start, start + size);

YH

author
#2 lore raw
Quoted 24 lines · Yinghai Lu
Quoted 12 lines · Shaohua Li

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

#3 lore raw
Quoted 25 lines · Shaohua Li
Quoted 24 lines · Yinghai Lu
Quoted 12 lines · Shaohua Li

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

YH

author
#4 lore raw
Quoted 26 lines · Yinghai Lu
Quoted 25 lines · Shaohua Li
Quoted 24 lines · Yinghai Lu
Quoted 12 lines · Shaohua Li

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

It's memory hotplug. Doing a round up is always ok and safe even it might be already aligned.

#5 lore raw
Quoted 27 lines · Shaohua Li
Quoted 26 lines · Yinghai Lu
Quoted 25 lines · Shaohua Li
Quoted 24 lines · Yinghai Lu
Quoted 12 lines · Shaohua Li

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

It's memory hotplug. Doing a round up is always ok and safe even it might be already aligned.

it seems rounding up in that case is wrong...

if the caller call that funtion with extra half page, you don't need map that half page, because you can not use it.

YH

author
#6 lore raw
Quoted 34 lines · Yinghai Lu
Quoted 33 lines · Shaohua Li
Quoted 32 lines · Yinghai Lu
Quoted 25 lines · Shaohua Li
Quoted 24 lines · Yinghai Lu
Quoted 12 lines · Shaohua Li

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

Quoted 7 lines
Quoted 2 lines

It's memory hotplug. Doing a round up is always ok and safe even it might be already aligned.

it seems rounding up in that case is wrong...

if the caller call that funtion with extra half page, you don't need map that half page, because you can not use it.

shouldn't we mark such page as reserved and so it will not be used? This is the way we handle hole.

#7 lore raw
Quoted 35 lines · Yinghai Lu
Quoted 34 lines · Shaohua Li
Quoted 33 lines · Yinghai Lu
Quoted 32 lines · Shaohua Li
Quoted 25 lines · Yinghai Lu
Quoted 24 lines · Shaohua Li
Quoted 12 lines

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

It's memory hotplug. Doing a round up is always ok and safe even it might be already aligned.

it seems rounding up in that case is wrong...

if the caller call that funtion with extra half page, you don't need map that half page, because you can not use it.

shouldn't we mark such page as reserved and so it will not be used? This is the way we handle hole.

Just curious,
have you ever seen a real machine which needs this patch?

If this patch is needed, there is the firmware which specifies half page size for new memory's size...

Bye.

Signature · 1 line
Yasunori Goto 
author
#8 lore raw
Quoted 38 lines · Yasunori Goto
Quoted 38 lines · Yinghai Lu
Quoted 37 lines · Shaohua Li
Quoted 35 lines · Yinghai Lu
Quoted 26 lines · Shaohua Li
Quoted 25 lines · Yinghai Lu
Quoted 24 lines · Shaohua Li
Quoted 12 lines

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

It's memory hotplug. Doing a round up is always ok and safe even it might be already aligned.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

it seems rounding up in that case is wrong...

if the caller call that funtion with extra half page, you don't need map that half page, because you can not use it.

shouldn't we mark such page as reserved and so it will not be used? This is the way we handle hole.

Just curious,
have you ever seen a real machine which needs this patch?

No, I just did some experiments on a desktop for memory hotplug and this bug
triggered a crash in my test.
Yinghai's suggestion also fixed the bug. I just want to have safer method. Anyway, either approach is ok to me.

Thanks,
Shaohua

#9 lore raw
Quoted 43 lines · Shaohua Li
Quoted 42 lines · Yasunori Goto
Quoted 42 lines · Yinghai Lu
Quoted 41 lines · Shaohua Li
Quoted 27 lines · Yinghai Lu
Quoted 26 lines · Shaohua Li
Quoted 25 lines · Yinghai Lu
Quoted 24 lines · Shaohua Li
Quoted 12 lines

Round up address to a page, otherwise the last page isn't mapped.

---
 arch/x86/mm/init_64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/arch/x86/mm/init_64.c
===================================================================

arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 int arch_add_memory(int nid, u64 start, · line 727

Quoted 8 lines
arch/x86/mm/init_64.c 2008-10-09 11:43:22.000000000 +0800 renamed from arch/x86/mm/init_64.c 2008-10-09 11:42:33.000000000 +0800 +2 -1
@@ -721,7 +721,8 @@ int arch_add_memory(int nid, u64 start,
       unsigned long nr_pages = size >> PAGE_SHIFT;
       int ret;
 
-       last_mapped_pfn = init_memory_mapping(start, start + size-1);
+       last_mapped_pfn = init_memory_mapping(start,
+               round_up(start + size-1, PAGE_SIZE));
       if (last_mapped_pfn > max_pfn_mapped)
               max_pfn_mapped = last_mapped_pfn;

should use

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

last_mapped_pfn = init_memory_mapping(start, start + size);

No, this still can't guarantee page aligned, though this works in my test

who will call arch_add_memory? that should be start and size already be page aligned.

It's memory hotplug. Doing a round up is always ok and safe even it might be already aligned.

it seems rounding up in that case is wrong...

if the caller call that funtion with extra half page, you don't need map that half page, because you can not use it.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

shouldn't we mark such page as reserved and so it will not be used? This is the way we handle hole.

Just curious,
have you ever seen a real machine which needs this patch?

No, I just did some experiments on a desktop for memory hotplug and this bug
triggered a crash in my test.
Yinghai's suggestion also fixed the bug. I just want to have safer method. Anyway, either approach is ok to me.

good, please resubmit updated one with

last_mapped_pfn = init_memory_mapping(start, start + size);

Thanks

YH