Skip to contentSkip to conversation

PS3: Fix memory hotplug

PATCH In review Geoff Levand 4 participants 13 messages May 13, 2008 – May 21, 2008

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

A change was made to walk_memory_resource() in commit 4b119e21d0c66c22e8ca03df05d9de623d0eb50f that added a check of find_lmb(). Add the corresponding lmb_add() call to ps3_mm_add_memory() so that that check will succeed.

This fixes the condition where the PS3 boots up with just the 128 MiB of boot memory.

---

Paul,

Please send this one upstream at your earliest convenience.

-Geoff

 arch/powerpc/platforms/ps3/mm.c |    2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/ps3/mm.c +2 -0
@@ -317,6 +317,8 @@ static int __init ps3_mm_add_memory(void
 		return result;
 	}
 
+	lmb_add(start_addr, map.r1.size);
+
 	result = online_pages(start_pfn, nr_pages);
 
 	if (result)
#1 lore raw
Quoted 11 lines · Geoff Levand

A change was made to walk_memory_resource() in commit 4b119e21d0c66c22e8ca03df05d9de623d0eb50f that added a check of find_lmb(). Add the corresponding lmb_add() call to ps3_mm_add_memory() so that that check will succeed.

This fixes the condition where the PS3 boots up with just the 128 MiB of boot memory.

---

When you do an lmb_add you should probably also do an lmb_analyze to update the total memory count etc...

That leads to some interesting issues such as the LMB stuff wasn't really meant to be dynamically modified after boot, and thus the kernel has no locks in there. That can be an issue...

Paul, any thoughts here ? Should we add a lock ? That would mean being careful as the LMB stuff can be called very early, and spinlock wants things like PACA and possibly lockdep to be around..

Ben.

Quoted 25 lines

Paul,

Please send this one upstream at your earliest convenience.

(quoted diff) +0 -1
-Geoff
 
 arch/powerpc/platforms/ps3/mm.c |    2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/ps3/mm.c +2 -0
@@ -317,6 +317,8 @@ static int __init ps3_mm_add_memory(void
 		return result;
 	}
 
+	lmb_add(start_addr, map.r1.size);
+
 	result = online_pages(start_pfn, nr_pages);
 
 	if (result)

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#2 lore raw
Quoted 4 lines

Paul, any thoughts here ? Should we add a lock ? That would mean being careful as the LMB stuff can be called very early, and spinlock wants things like PACA and possibly lockdep to be around..

Actually, we call early_init_devtree(), which populates the LMB, after we initialize the PACA and lockdep, so it -should- be safe to add a spinlock.

Dave ? Any objection to adding a spinlock to the LMB code ?

Cheers,
Ben.

#3 lore raw

From: Benjamin Herrenschmidt <[email protected]>
Date: Wed, 14 May 2008 23:51:29 -0700

Quoted 10 lines
Quoted 4 lines

Paul, any thoughts here ? Should we add a lock ? That would mean being careful as the LMB stuff can be called very early, and spinlock wants things like PACA and possibly lockdep to be around..

Actually, we call early_init_devtree(), which populates the LMB, after we initialize the PACA and lockdep, so it -should- be safe to add a spinlock.

Dave ? Any objection to adding a spinlock to the LMB code ?

No objections, just don't add any bugs. :-)

#4 lore raw

RFC PATCH 1/1 LMB: Add basic spin locking to lmb

Add a spinlock to struct lmb to enforce concurrency in lmb_add(), lmb_remove(), lmb_analyze(), and lmb_dump_all().

This locking is needed for SMP systems that access the lmb structure during hot memory add and remove operations after secondary cpus have been started.

---

This patch just adds locks for the few lmb routines that would be used for hot memory adding and removing.

-Geoff

 include/linux/lmb.h |    1 
 lib/lmb.c           |   54 +++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 42 insertions(+), 13 deletions(-)
include/linux/lmb.h +1 -0
@@ -30,6 +30,7 @@ struct lmb_region {
 };
 
 struct lmb {
+	spinlock_t lock;
 	unsigned long debug;
 	u64 rmo_size;
 	struct lmb_region memory;
lib/lmb.c +41 -13

140 lines not on this page · raw message

#5 lore raw

PATCH v2 1/1 LMB: Add basic spin locking to lmb

Add a spinlock to struct lmb to enforce concurrency in lmb_add(), lmb_remove(), lmb_analyze(), lmb_find(), and lmb_dump_all().

This locking is needed for SMP systems that access the lmb structure during hot memory add and remove operations after secondary cpus have been started.

---

v2: o Add locking to lmb_find().

 include/linux/lmb.h |    1 
 lib/lmb.c           |   62 ++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 49 insertions(+), 14 deletions(-)
include/linux/lmb.h +1 -0
@@ -30,6 +30,7 @@ struct lmb_region {
 };
 
 struct lmb {
+	spinlock_t lock;
 	unsigned long debug;
 	u64 rmo_size;
 	struct lmb_region memory;
lib/lmb.c +48 -14

167 lines not on this page · raw message

#6 lore raw

Re: [patch v2] LMB: Add basic spin locking to lmb

From: Geoff Levand <[email protected]>
Date: Mon, 19 May 2008 17:55:45 -0700

Quoted 4 lines

Add a spinlock to struct lmb to enforce concurrency in lmb_add(), lmb_remove(), lmb_analyze(), lmb_find(), and lmb_dump_all().

Quoted 8 lines

This locking is needed for SMP systems that access the lmb structure during hot memory add and remove operations after secondary cpus have been started.

---

v2: o Add locking to lmb_find().

I'm not against this patch, but I'm pretty sure it's not necessary. Isn't memory hotplug already synchronized at a higher level?

If not, it should be.

#7 lore raw

Re: [patch v2] LMB: Add basic spin locking to lmb

Quoted 14 lines · David Miller

From: Geoff Levand <[email protected]>
Date: Mon, 19 May 2008 17:55:45 -0700

Quoted 11 lines

Add a spinlock to struct lmb to enforce concurrency in lmb_add(), lmb_remove(), lmb_analyze(), lmb_find(), and lmb_dump_all().

This locking is needed for SMP systems that access the lmb structure during hot memory add and remove operations after secondary cpus have been started.

---

Quoted 7 lines
Quoted 1 line

v2: o Add locking to lmb_find().

I'm not against this patch, but I'm pretty sure it's not necessary. Isn't memory hotplug already synchronized at a higher level?

If not, it should be.

I think the core memory hotplug is... However, we used to not change the LMB when doing so (afaik, I'm travelling and not looking at the code right now). However, things like PS3 memory hotplug tries to keep LMB is sync for the sake of /dev/mem or similar and that happens before the memory is added to the core.

Ben.

#8 lore raw

Re: [patch v2] LMB: Add basic spin locking to lmb

From: Benjamin Herrenschmidt <[email protected]>
Date: Mon, 19 May 2008 22:32:58 -0400

Quoted 5 lines

I think the core memory hotplug is... However, we used to not change the LMB when doing so (afaik, I'm travelling and not looking at the code right now). However, things like PS3 memory hotplug tries to keep LMB is sync for the sake of /dev/mem or similar and that happens before the memory is added to the core.

But if the memory hotplug is synchronized, so are changes to the LMB tables.

And if there are LMB read side access concernes outside of the hotplug event, ideally we should use the synchronization mechanism that hotplug uses instead of adding a new one.

#9 lore raw
In reply to Benjamin Herrenschmidt
Quoted 10 lines · Benjamin Herrenschmidt

When you do an lmb_add you should probably also do an lmb_analyze to update the total memory count etc...

That leads to some interesting issues such as the LMB stuff wasn't really meant to be dynamically modified after boot, and thus the kernel has no locks in there. That can be an issue...

Paul, any thoughts here ? Should we add a lock ? That would mean being careful as the LMB stuff can be called very early, and spinlock wants things like PACA and possibly lockdep to be around..

Either that, or we give in and use iomem_resource to track where system RAM is, as well as the other things in the physical address space, like other architectures do...

Paul.

#10 lore raw
Quoted 9 lines · Paul Mackerras
Quoted 7 lines · Benjamin Herrenschmidt

When you do an lmb_add you should probably also do an lmb_analyze to update the total memory count etc...

That leads to some interesting issues such as the LMB stuff wasn't really meant to be dynamically modified after boot, and thus the kernel has no locks in there. That can be an issue...

Quoted 7 lines
Quoted 3 lines

Paul, any thoughts here ? Should we add a lock ? That would mean being careful as the LMB stuff can be called very early, and spinlock wants things like PACA and possibly lockdep to be around..

Either that, or we give in and use iomem_resource to track where system RAM is, as well as the other things in the physical address space, like other architectures do...

The generic hot plug routines already use iomem_resource (mm/memory_hotplug.c). Both __add_pages() and add_memory() add the new mem to iomem_resource, and so it seems there is no need for the powerpc specific walk_memory_resource(), since the generic one does its check with iomem_resource.

I need to look a little closer at how the pSeries does its memory hot plug, but I think removing the powerpc specific walk_memory_resource() won't effect pSeries since it seems to have its own hot plug routines that do their own thing entirely with lmb.

It doesn't seem that it would be difficult to make the pSeries hot plug code to use iomem_resource, but some of the generic hot plug routines cannot be called until fairly late in the startup.

The other thing to do then would be to change the other powerpc startup code to use iomem_resource instead of lmb.

-Geoff

#11 lore raw

PATCH v2 1/1 PS3: Fix memory hotplug

In reply to Geoff Levand

A change was made to walk_memory_resource() in commit 4b119e21d0c66c22e8ca03df05d9de623d0eb50f that added a check of find_lmb(). Add the coresponding lmb_add() call to ps3_mm_add_memory() so that that check will succeed.

This fixes the condition where the PS3 boots up with only the 128 MiB of boot memory.

---

v2: Add call to lmb_analyze().

 arch/powerpc/platforms/ps3/mm.c |    3 +++
 1 file changed, 3 insertions(+)
arch/powerpc/platforms/ps3/mm.c +3 -0
@@ -317,6 +317,9 @@ static int __init ps3_mm_add_memory(void
 		return result;
 	}
 
+	lmb_add(start_addr, map.r1.size);
+	lmb_analyze();
+
 	result = online_pages(start_pfn, nr_pages);
 
 	if (result)
#12 lore raw
Quoted 21 lines · Geoff Levand

A change was made to walk_memory_resource() in commit 4b119e21d0c66c22e8ca03df05d9de623d0eb50f that added a check of find_lmb(). Add the coresponding lmb_add() call to ps3_mm_add_memory() so that that check will succeed.

This fixes the condition where the PS3 boots up with only the 128 MiB of boot memory.

---

v2: Add call to lmb_analyze().

 arch/powerpc/platforms/ps3/mm.c |    3 +++
 1 file changed, 3 insertions(+)

arch/powerpc/platforms/ps3/mm.c static int __init ps3_mm_add_memory(void · line 325

Quoted 9 lines
arch/powerpc/platforms/ps3/mm.c +3 -0
@@ -317,6 +317,9 @@ static int __init ps3_mm_add_memory(void
 		return result;
 	}
 
+	lmb_add(start_addr, map.r1.size);
+	lmb_analyze();
+
 	result = online_pages(start_pfn, nr_pages);
 
 	if (result)

Hi Paul,

Could you please merge this one in for 2.6.26. Without it the system boots with just 128 of the total 256 MiB of memory.

There is the concurrency problem as Ben commented on, but I think not having the 128 MiB of memory is worse than having the potential race, which we can work on as a separate fix.

-Geoff