Skip to contentSkip to conversation

kdump : add support for ibm, dynamic-reconfiguration-memory for kexec/kdump

PATCH Superseded Chandru 6 participants 11 messages Jul 7, 2008 – Jul 25, 2008

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chandru

author
#0 lore raw

PATCH 1/4 kdump : add support for ibm, dynamic-reconfiguration-memory for kexec/kdump

kexec-tools adds crash, rtas, and tce memory regions as linux,usable-memory properties in device-tree. Following changes are made in the kernel to recognize these special properties in case of ibm,dynamic-reconfiguration-memory node of device-tree.

---

diff -Naurp linux-2.6.26-rc9-orig/arch/powerpc/kernel/prom.c linux-2.6.26-rc9/arch/powerpc/kernel/prom.c
--- linux-2.6.26-rc9-orig/arch/powerpc/kernel/prom.c 2008-07-06
04:23:22.000000000 +0530
+++ linux-2.6.26-rc9/arch/powerpc/kernel/prom.c 2008-07-07 17:23:58.000000000
+0530
@@ -884,9 +884,10 @@ static u64 __init dt_mem_next_cell(int s
*/
static int __init early_init_dt_scan_drconf_memory(unsigned long node) {
- cell_t *dm, *ls;
+ cell_t *dm, *ls, *endp, *usm;
unsigned long l, n, flags;
u64 base, size, lmb_size;
+ char buf[32], t[8];

ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l); if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
@@ -917,7 +918,33 @@ static int __init early_init_dt_scan_drc
if ((base + size) > 0x80000000ul)
size = 0x80000000ul - base;
}
- lmb_add(base, size);
+ strcpy(buf, "linux,usable-memory");
+ sprintf(t, "%d", (int)n);
+ strcat(buf, t);
+ usm = (cell_t *)of_get_flat_dt_prop(node,
+ (const char *)buf, &l);
+ if (usm != NULL) {
+ endp = usm + (l / sizeof(cell_t));
+ while ((endp - usm) >= (dt_root_addr_cells +
+ dt_root_size_cells)) {
+ base = dt_mem_next_cell(dt_root_addr_cells,
+ &usm);
+ size = dt_mem_next_cell(dt_root_size_cells,
+ &usm);
+ if (size == 0)
+ continue;
+ if (iommu_is_off) {
+ if ((base + size) > 0x80000000ul)
+ size = 0x80000000ul - base;
+ }
+ lmb_add(base, size);
+ }
+
+ /* Continue with next lmb entry */
+ continue;
+ } else {
+ lmb_add(base, size);
+ }
}
lmb_dump_all();
return 0;
diff -Naurp linux-2.6.26-rc9-orig/arch/powerpc/mm/numa.c linux-2.6.26-rc9/arch/powerpc/mm/numa.c
--- linux-2.6.26-rc9-orig/arch/powerpc/mm/numa.c 2008-07-06 04:23:22.000000000
+0530
+++ linux-2.6.26-rc9/arch/powerpc/mm/numa.c 2008-07-07 17:50:35.000000000
+0530
@@ -349,18 +349,33 @@ static unsigned long __init numa_enforce
return lmb_end_of_DRAM() - start;
}

+static void set_nodeinfo(int nid, unsigned long start, unsigned long size) +{
+ fake_numa_create_new_node(((start + size) >> PAGE_SHIFT),
+ &nid);
+ node_set_online(nid);
+
+ size = numa_enforce_memory_limit(start, size);
+ if (!size)
+ return;
+ add_active_range(nid, start >> PAGE_SHIFT,
+ (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
+ return;
+}
+
/*
* Extract NUMA information from the ibm,dynamic-reconfiguration-memory
* node. This assumes n_mem_{addr,size}_cells have been set. */
static void __init parse_drconf_memory(struct device_node *memory) {
- const unsigned int *lm, *dm, *aa;
+ const unsigned int *lm, *dm, *aa, *usm;
unsigned int ls, ld, la;
unsigned int n, aam, aalen;
unsigned long lmb_size, size, start;
int nid, default_nid = 0;
- unsigned int ai, flags;
+ unsigned int ai, flags, len, ranges;
+ char buf[32], t[8];

lm = of_get_property(memory, "ibm,lmb-size", &ls); dm = of_get_property(memory, "ibm,dynamic-memory", &ld);
@@ -396,16 +411,27 @@ static void __init parse_drconf_memory(s
nid = default_nid;
}

- fake_numa_create_new_node(((start + lmb_size) >> PAGE_SHIFT),
- &nid);
- node_set_online(nid);
+ strcpy(buf, "linux,usable-memory");
+ sprintf(t, "%d", (int)n);
+ strcat(buf, t);
+ usm = of_get_property(memory, (const char *)buf, &len);
+ if (usm != NULL) {
+ ranges = (len >> 2) / (n_mem_addr_cells +
+ n_mem_size_cells);
+
+dr_new_range: start = read_n_cells(n_mem_addr_cells, &usm);
+ size = read_n_cells(n_mem_size_cells, &usm);
+ if (size == 0)
+ continue;

- size = numa_enforce_memory_limit(start, lmb_size);
- if (!size)
- continue;
+ set_nodeinfo(nid, start, size);
+ if (--ranges)
+ goto dr_new_range;

- add_active_range(nid, start >> PAGE_SHIFT,
- (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
+ continue;
+ } else {
+ set_nodeinfo(nid, start, lmb_size);
+ }
}
}

#1 lore raw

Hi Chandru,

Review static int __init early_init_dt_scan_drc · line 923

Quoted 9 lines · On Tue, 8 Jul 2008 00:14:24 +0530 Chandru <[email protected]> wrote:
(quoted diff) +3 -1
@@ -917,7 +918,33 @@ static int __init early_init_dt_scan_drc
 			if ((base + size) > 0x80000000ul)
 				size = 0x80000000ul - base;
 		}
-		lmb_add(base, size);
+		strcpy(buf, "linux,usable-memory");
+		sprintf(t, "%d", (int)n);
+		strcat(buf, t);

Why don't you use

		snprintf(buf, sizeof(buf), "linux,usable-memory%ld", n);

instead?

Review static int __init early_init_dt_scan_drc · line 925

Quoted 2 lines
(quoted diff) +2 -0
+		usm = (cell_t *)of_get_flat_dt_prop(node,
+						 (const char *)buf, &l);
		      ^^^^^^^^^^		 ^^^^^^^^^^^^^^

unnecessary casts.

Review static int __init early_init_dt_scan_drc · line 931

Quoted 6 lines
(quoted diff) +3 -0
 static void __init parse_drconf_memory(struct device_node *memory)
 {
 
+		strcpy(buf, "linux,usable-memory");
+		sprintf(t, "%d", (int)n);
+		strcat(buf, t);

See snprint comment above.

Review static int __init early_init_dt_scan_drc · line 932

Quoted 1 line
(quoted diff) +1 -0
+		usm = of_get_property(memory, (const char *)buf, &len);
                                              ^^^^^^^^^^^^^^

unnecessary cast.

Review static int __init early_init_dt_scan_drc · line 934

Quoted 2 lines
(quoted diff) +2 -0
+		if (usm != NULL) {
+			ranges = (len >> 2) / (n_mem_addr_cells +
                                 ^^^^^^^^^^

len / sizeof(u32) ?

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
author
#2 lore raw

Thanks for the review comments. I will change to 'snprintf' at all the places and remove the unnecessary casts.

Quoted 8 lines · On Tuesday 08 July 2008 07:06:46 Stephen Rothwell wrote:

Hi Chandru,

Review

Quoted 2 lines · On Tue, 8 Jul 2008 00:14:24 +0530 Chandru <[email protected]> wrote:
(quoted diff) +2 -0
+		if (usm != NULL) {
+			ranges = (len >> 2) / (n_mem_addr_cells +
                                 ^^^^^^^^^^

len / sizeof(u32) ?

ranges is made to count the number of linux,usable-memory properties in the device tree. It's acting as a counter here. So the expression in the patch is fine.

Thanks,
Chandru

#3 lore raw

In reply to Chandru
Quoted 3 lines

[PATCH 1/4] kdump : add support for ibm, dynamic-reconfiguration-memory for kexec/kdump

Please change the name of the individual patches

BTW this patch doesn't apply against the powerpc-next tree. Please use that tree, not Linus tree.

Quoted 5 lines · In message <[email protected]> you wrote:

kexec-tools adds crash, rtas, and tce memory regions as linux,usable-memory properties in device-tree. Following changes are made in the kernel to recognize these special properties in case of ibm,dynamic-reconfiguration-memory node of device-tree.

Quoted 8 lines

---

diff -Naurp linux-2.6.26-rc9-orig/arch/powerpc/kernel/prom.c linux-2.6.26-rc9/arch/powerpc/kernel/prom.c
--- linux-2.6.26-rc9-orig/arch/powerpc/kernel/prom.c 2008-07-06
04:23:22.000000000 +0530
+++ linux-2.6.26-rc9/arch/powerpc/kernel/prom.c 2008-07-07 17:23:58.000

000000

Quoted 14 lines

+0530

(quoted diff) +2 -1
@@ -884,9 +884,10 @@ static u64 __init dt_mem_next_cell(int s
  */
 static int __init early_init_dt_scan_drconf_memory(unsigned long node)
 {
-	cell_t *dm, *ls;
+	cell_t *dm, *ls, *endp, *usm;
 	unsigned long l, n, flags;
 	u64 base, size, lmb_size;
+	char buf[32], t[8];
 
 	ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
 	if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))

Review static int __init early_init_dt_scan_drc · line 920

Quoted 3 lines
(quoted diff) +0 -0
@@ -917,7 +918,33 @@ static int __init early_init_dt_scan_drc
 			if ((base + size) > 0x80000000ul)
 				size = 0x80000000ul - base;
 		}

Please document what you are trying to achieve here

Review static int __init early_init_dt_scan_drc · line 923

Quoted 4 lines
(quoted diff) +3 -1
-		lmb_add(base, size);
+		strcpy(buf, "linux,usable-memory");
+		sprintf(t, "%d", (int)n);
+		strcat(buf, t);

sprintf(buf, "linux,usable-memory%d", (int)n);
??

Quoted 5 lines
(quoted diff) +5 -0
+		usm = (cell_t *)of_get_flat_dt_prop(node,
+						 (const char *)buf, &l);
+		if (usm != NULL) {
+			endp = usm + (l / sizeof(cell_t));
+			while ((endp - usm) >= (dt_root_addr_cells +

Review static int __init early_init_dt_scan_drc · line 938

Quoted 10 lines
(quoted diff) +10 -0
+						 dt_root_size_cells)) {
+				base = dt_mem_next_cell(dt_root_addr_cells,
+								 &usm);
+				size = dt_mem_next_cell(dt_root_size_cells,
+								 &usm);
+				if (size == 0)
+					continue;
+				if (iommu_is_off) {
+					if ((base + size) > 0x80000000ul)
+						size = 0x80000000ul - base;

There is similar code to this above. Can this be merged? Why 0x80000000ul anyway?

Review static int __init early_init_dt_scan_drc · line 944

Quoted 6 lines
(quoted diff) +6 -0
+				}
+				lmb_add(base, size);
+			}
+
+			/* Continue with next lmb entry */
+			continue;

Is this "continue" needed?

Also, this comment is useless. We know what a continue does :-)

Quoted 9 lines
(quoted diff) +3 -0
+		} else {
+			lmb_add(base, size);
+		}
 	}
 	lmb_dump_all();
 	return 0;

diff -Naurp linux-2.6.26-rc9-orig/arch/powerpc/mm/numa.c linux-2.6.26-rc9/arch/powerpc/mm/numa.c
--- linux-2.6.26-rc9-orig/arch/powerpc/mm/numa.c 2008-07-06 04:23:22.000

000000

Quoted 40 lines

+0530
+++ linux-2.6.26-rc9/arch/powerpc/mm/numa.c 2008-07-07 17:50:35.000000000
+0530

(quoted diff) +17 -2
@@ -349,18 +349,33 @@ static unsigned long __init numa_enforce
 	return lmb_end_of_DRAM() - start;
 }
 
+static void set_nodeinfo(int nid, unsigned long start, unsigned long size)
+{
+	fake_numa_create_new_node(((start + size) >> PAGE_SHIFT),
+					&nid);
+	node_set_online(nid);
+
+	size = numa_enforce_memory_limit(start, size);
+	if (!size)
+		return;
+	add_active_range(nid, start >> PAGE_SHIFT,
+			(start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
+	return;
+}
+
 /*
  * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
  * node.  This assumes n_mem_{addr,size}_cells have been set.
  */
 static void __init parse_drconf_memory(struct device_node *memory)
 {
-	const unsigned int *lm, *dm, *aa;
+	const unsigned int *lm, *dm, *aa, *usm;
 	unsigned int ls, ld, la;
 	unsigned int n, aam, aalen;
 	unsigned long lmb_size, size, start;
 	int nid, default_nid = 0;
-	unsigned int ai, flags;
+	unsigned int ai, flags, len, ranges;
+	char buf[32], t[8];
 
 	lm = of_get_property(memory, "ibm,lmb-size", &ls);
 	dm = of_get_property(memory, "ibm,dynamic-memory", &ld);

Review static void __init parse_drconf_memory(s · line 416

Quoted 9 lines
(quoted diff) +3 -3
@@ -396,16 +411,27 @@ static void __init parse_drconf_memory(s
 				nid = default_nid;
 		}
 
-		fake_numa_create_new_node(((start + lmb_size) >> PAGE_SHIFT),
-						&nid);
-		node_set_online(nid);
+		strcpy(buf, "linux,usable-memory");
+		sprintf(t, "%d", (int)n);
+		strcat(buf, t);

Again, we can do this in a single sprintf, like above...

Quoted 6 lines
(quoted diff) +6 -0
+		usm = of_get_property(memory, (const char *)buf, &len);
+		if (usm != NULL) {
+			ranges = (len >> 2) / (n_mem_addr_cells +
+						 n_mem_size_cells);
+
+dr_new_range:		start = read_n_cells(n_mem_addr_cells, &usm);

Review static void __init parse_drconf_memory(s · line 429

Quoted 10 lines
(quoted diff) +6 -3
+			size = read_n_cells(n_mem_size_cells, &usm);
+			if (size == 0)
+				continue;
 
-		size = numa_enforce_memory_limit(start, lmb_size);
-		if (!size)
-			continue;
+			set_nodeinfo(nid, start, size);
+			if (--ranges)
+				goto dr_new_range;

Can you please use a while or for loop rather than a goto.

Quoted 16 lines
(quoted diff) +4 -2
-		add_active_range(nid, start >> PAGE_SHIFT,
-				 (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
+			continue;
+		} else {
+			set_nodeinfo(nid, start, lmb_size);
+		}
 	}
 }
 
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw
In reply to Chandru

Hello Chandru,

Quoted 33 lines

static int __init early_init_dt_scan_drconf_memory(unsigned long node) {

(quoted diff) +20 -2
-	cell_t *dm, *ls;
+	cell_t *dm, *ls, *endp, *usm;
 	unsigned long l, n, flags;
 	u64 base, size, lmb_size;
+	char buf[32], t[8];
 
 	ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
 	if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
@@ -917,7 +918,33 @@ static int __init early_init_dt_scan_drc
 			if ((base + size) > 0x80000000ul)
 				size = 0x80000000ul - base;
 		}
-		lmb_add(base, size);
+		strcpy(buf, "linux,usable-memory");
+		sprintf(t, "%d", (int)n);
+		strcat(buf, t);
+		usm = (cell_t *)of_get_flat_dt_prop(node,
+						 (const char *)buf, &l);
+		if (usm != NULL) {
+			endp = usm + (l / sizeof(cell_t));
+			while ((endp - usm) >= (dt_root_addr_cells +
+						 dt_root_size_cells)) {
+				base = dt_mem_next_cell(dt_root_addr_cells,
+								 &usm);
+				size = dt_mem_next_cell(dt_root_size_cells,
+								 &usm);
+				if (size == 0)
+					continue;
+				if (iommu_is_off) {
+					if ((base + size) > 0x80000000ul)
+						size = 0x80000000ul - base;

Review static int __init early_init_dt_scan_drc · line 948

Quoted 10 lines
(quoted diff) +9 -0
+				}
+				lmb_add(base, size);
+			}
+
+			/* Continue with next lmb entry */
+			continue;
+		} else {
+			lmb_add(base, size);
+		}
 	}

I am still digging through the kexec tools but I don't think you want the processing of the linux,usable-memory property inside of the for (; n!= 0; --n) loop. This should be moved up so that it looks for the linux,usable-memory property and parses it, then if it is not found look for the ibm,dynamic-reconfiguration-memory property and parse it.

There is no need to look for the linux-usable-memory property every time a piece of the ibm,dynamic-reconfiguration-memory property is parsed.

-Nathan

author
#5 lore raw
Quoted 52 lines · On Friday 11 July 2008 03:57:53 Nathan Fontenot wrote:

Hello Chandru,

Quoted 33 lines

static int __init early_init_dt_scan_drconf_memory(unsigned long node) {

(quoted diff) +20 -2
-	cell_t *dm, *ls;
+	cell_t *dm, *ls, *endp, *usm;
 	unsigned long l, n, flags;
 	u64 base, size, lmb_size;
+	char buf[32], t[8];
 
 	ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
 	if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
@@ -917,7 +918,33 @@ static int __init early_init_dt_scan_drc
 			if ((base + size) > 0x80000000ul)
 				size = 0x80000000ul - base;
 		}
-		lmb_add(base, size);
+		strcpy(buf, "linux,usable-memory");
+		sprintf(t, "%d", (int)n);
+		strcat(buf, t);
+		usm = (cell_t *)of_get_flat_dt_prop(node,
+						 (const char *)buf, &l);
+		if (usm != NULL) {
+			endp = usm + (l / sizeof(cell_t));
+			while ((endp - usm) >= (dt_root_addr_cells +
+						 dt_root_size_cells)) {
+				base = dt_mem_next_cell(dt_root_addr_cells,
+								 &usm);
+				size = dt_mem_next_cell(dt_root_size_cells,
+								 &usm);
+				if (size == 0)
+					continue;
+				if (iommu_is_off) {
+					if ((base + size) > 0x80000000ul)
+						size = 0x80000000ul - base;

Review static int __init early_init_dt_scan_drc · line 948

Quoted 10 lines
(quoted diff) +9 -0
+				}
+				lmb_add(base, size);
+			}
+
+			/* Continue with next lmb entry */
+			continue;
+		} else {
+			lmb_add(base, size);
+		}
 	}

I am still digging through the kexec tools but I don't think you want the processing of the linux,usable-memory property inside of the for (; n!= 0; --n) loop. This should be moved up so that it looks for the linux,usable-memory property and parses it, then if it is not found look for the ibm,dynamic-reconfiguration-memory property and parse it.

Quoted 4 lines

There is no need to look for the linux-usable-memory property every time a piece of the ibm,dynamic-reconfiguration-memory property is parsed.

-Nathan

Hello Nathan,

Thanks for the review. kexec-tools adds a 'linux,usable-memory' property for each memory range listed in the device tree. If the regions are not crashkernel or rtas or tce regions, then it sets base and size to zero but still adds them as linux,usable-memory property. If we look at the code above, in a kdump kernel we don't add an lmb through lmb_add() if the regions are not one of the mentioned above. We check for (size == 0) and continue with next lmb if it is so. We still have the complete device tree which kexec-tools passes in as the buffer that we are scanning here and linux,usable-memory properties aid in making kdump kernel to see only those memory regions that it is suppose to use. I just worked on another version of this patch based on comments from Michael Neuling and Stephen Rothwell. I will post it shortly.

Thanks,
Chandru

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#6 lore raw

PATCH v2 1/4 powerpc : add support for linux, usable-memory properties for drconf memory

Scan for linux,usable-memory properties in case of dynamic reconfiguration memory. Support for kexec/kdump.

---

Patch applies on linux-next tree (patch-v2.6.26-rc9-next-20080711.gz)

 arch/powerpc/kernel/prom.c |   40 +++++++++++++++++++++++------
 arch/powerpc/mm/numa.c     |   48 ++++++++++++++++++++++++-----------
 2 files changed, 65 insertions(+), 23 deletions(-)

diff -Naurp linux-2.6.26-rc9-orig/arch/powerpc/kernel/prom.c linux-2.6.26-rc9/arch/powerpc/kernel/prom.c
--- linux-2.6.26-rc9-orig/arch/powerpc/kernel/prom.c 2008-07-11
14:44:55.000000000 +0530
+++ linux-2.6.26-rc9/arch/powerpc/kernel/prom.c 2008-07-11 14:58:26.000000000
+0530
@@ -888,9 +888,10 @@ static u64 __init dt_mem_next_cell(int s
*/
static int __init early_init_dt_scan_drconf_memory(unsigned long node) {
- cell_t *dm, *ls;
- unsigned long l, n, flags;
+ cell_t *dm, *ls, *usm;
+ unsigned long l, n, flags, ranges;
u64 base, size, lmb_size;
+ char buf[32];

ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l); if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
@@ -914,14 +915,37 @@ static int __init early_init_dt_scan_drc
or if the block is not assigned to this partition (0x8) */
if ((flags & 0x80) || !(flags & 0x8))
continue;
- size = lmb_size;
- if (iommu_is_off) {
+ if (iommu_is_off)
if (base >= 0x80000000ul)
continue;
- if ((base + size) > 0x80000000ul)
- size = 0x80000000ul - base;
- }
- lmb_add(base, size);
+ size = lmb_size;
+
+ /*
+ * Append 'n' to 'linux,usable-memory' to get special
+ * properties passed in by tools like kexec-tools. Relevant
+ * only if this is a kexec/kdump kernel.
+ */
+ sprintf(buf, "linux,usable-memory%d", (int)n);
+ usm = of_get_flat_dt_prop(node, buf, &l);
+ ranges = 1;
+ if (usm != NULL)
+ ranges = (l >> 2)/(dt_root_addr_cells
+ + dt_root_size_cells);
+ do {
+ if (usm != NULL) {
+ base = dt_mem_next_cell(dt_root_addr_cells,
+ &usm);
+ size = dt_mem_next_cell(dt_root_size_cells,
+ &usm);
+ if (size == 0)
+ break;
+ }
+ if (iommu_is_off)
+ if ((base + size) > 0x80000000ul)
+ size = 0x80000000ul - base;
+
+ lmb_add(base, size);
+ } while (--ranges);
}
lmb_dump_all();
return 0;
diff -Naurp linux-2.6.26-rc9-orig/arch/powerpc/mm/numa.c linux-2.6.26-rc9/arch/powerpc/mm/numa.c
--- linux-2.6.26-rc9-orig/arch/powerpc/mm/numa.c 2008-07-11 14:44:55.000000000
+0530
+++ linux-2.6.26-rc9/arch/powerpc/mm/numa.c 2008-07-11 15:01:56.000000000
+0530
@@ -493,11 +493,13 @@ static unsigned long __init numa_enforce
*/
static void __init parse_drconf_memory(struct device_node *memory) {
- const u32 *dm;
- unsigned int n, rc;
- unsigned long lmb_size, size;
+ const u32 *dm, *usm;
+ unsigned int n, rc, len, ranges;
+ unsigned long lmb_size, size, sz;
int nid;
struct assoc_arrays aa;
+ char buf[32];
+ u64 base;

n = of_get_drconf_memory(memory, &dm);
if (!n)
@@ -524,19 +526,35 @@ static void __init parse_drconf_memory(s

nid = of_drconf_to_nid_single(&drmem, &aa);

- fake_numa_create_new_node(
- ((drmem.base_addr + lmb_size) >> PAGE_SHIFT),
- &nid);
-
- node_set_online(nid);
-
- size = numa_enforce_memory_limit(drmem.base_addr, lmb_size);
- if (!size)
- continue;
+ /*
+ * Append 'n' to 'linux,usable-memory' to get special
+ * properties passed in by tools like kexec-tools. Relevant
+ * only if this is a kexec/kdump kernel.
+ */
+ sprintf(buf, "linux,usable-memory%d", (int)n);
+ usm = of_get_property(memory, buf, &len);
+ ranges = 1;
+ if (usm != NULL)
+ ranges = (len >> 2) /
+ (n_mem_addr_cells + n_mem_size_cells);
+
+ base = drmem.base_addr;
+ size = lmb_size;
+ do {
+ if (usm != NULL) {
+ base = read_n_cells(n_mem_addr_cells, &usm);
+ size = read_n_cells(n_mem_size_cells, &usm);
+ }

- add_active_range(nid, drmem.base_addr >> PAGE_SHIFT,
- (drmem.base_addr >> PAGE_SHIFT)
- + (size >> PAGE_SHIFT));
+ fake_numa_create_new_node(((base + size) >> PAGE_SHIFT),
+ &nid);
+ node_set_online(nid);
+ sz = numa_enforce_memory_limit(base, size);
+ if (sz)
+ add_active_range(nid, base >> PAGE_SHIFT,
+ (base >> PAGE_SHIFT)
+ + (sz >> PAGE_SHIFT));
+ } while (--ranges);
}
}

author
#7 lore raw

Re: [PATCH 1/4][V2] powerpc : add support for linux, usable-memory properties for drconf memory

Scan for linux,usable-memory properties in case of dynamic reconfiguration memory . Support for kexec/kdump.

---

Patch applies on powerpc tree. Patch was reviewed by Nathan Fontenot, Stephen Rothwell, Michael Neuling.

 arch/powerpc/kernel/prom.c |   40 +++++++++++++++++++++++------
 arch/powerpc/mm/numa.c     |   48 ++++++++++++++++++++++++-----------
 2 files changed, 65 insertions(+), 23 deletions(-)

diff -Naurp powerpc-orig/arch/powerpc/kernel/prom.c powerpc/arch/powerpc/kernel/prom.c
--- powerpc-orig/arch/powerpc/kernel/prom.c 2008-07-22 14:11:53.000000000
+0530
+++ powerpc/arch/powerpc/kernel/prom.c 2008-07-22 14:12:17.000000000 +0530
@@ -888,9 +888,10 @@ static u64 __init dt_mem_next_cell(int s
*/
static int __init early_init_dt_scan_drconf_memory(unsigned long node) {
- cell_t *dm, *ls;
- unsigned long l, n, flags;
+ cell_t *dm, *ls, *usm;
+ unsigned long l, n, flags, ranges;
u64 base, size, lmb_size;
+ char buf[32];

ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l); if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
@@ -914,14 +915,37 @@ static int __init early_init_dt_scan_drc
or if the block is not assigned to this partition (0x8) */
if ((flags & 0x80) || !(flags & 0x8))
continue;
- size = lmb_size;
- if (iommu_is_off) {
+ if (iommu_is_off)
if (base >= 0x80000000ul)
continue;
- if ((base + size) > 0x80000000ul)
- size = 0x80000000ul - base;
- }
- lmb_add(base, size);
+ size = lmb_size;
+
+ /*
+ * Append 'n' to 'linux,usable-memory' to get special
+ * properties passed in by tools like kexec-tools. Relevant
+ * only if this is a kexec/kdump kernel.
+ */
+ sprintf(buf, "linux,usable-memory%d", (int)n);
+ usm = of_get_flat_dt_prop(node, buf, &l);
+ ranges = 1;
+ if (usm != NULL)
+ ranges = (l >> 2)/(dt_root_addr_cells
+ + dt_root_size_cells);
+ do {
+ if (usm != NULL) {
+ base = dt_mem_next_cell(dt_root_addr_cells,
+ &usm);
+ size = dt_mem_next_cell(dt_root_size_cells,
+ &usm);
+ if (size == 0)
+ break;
+ }
+ if (iommu_is_off)
+ if ((base + size) > 0x80000000ul)
+ size = 0x80000000ul - base;
+
+ lmb_add(base, size);
+ } while (--ranges);
}
lmb_dump_all();
return 0;

arch/powerpc/mm/numa.c +33 -15
diff -Naurp powerpc-orig/arch/powerpc/mm/numa.c powerpc/arch/powerpc/mm/numa.c
@@ -493,11 +493,13 @@ static unsigned long __init numa_enforce
  */
 static void __init parse_drconf_memory(struct device_node *memory)
 {
-	const u32 *dm;
-	unsigned int n, rc;
-	unsigned long lmb_size, size;
+	const u32 *dm, *usm;
+	unsigned int n, rc, len, ranges;
+	unsigned long lmb_size, size, sz;
 	int nid;
 	struct assoc_arrays aa;
+	char buf[32];
+	u64 base;
 
 	n = of_get_drconf_memory(memory, &dm);
 	if (!n)
@@ -524,19 +526,35 @@ static void __init parse_drconf_memory(s
 
 		nid = of_drconf_to_nid_single(&drmem, &aa);
 
-		fake_numa_create_new_node(
-				((drmem.base_addr + lmb_size) >> PAGE_SHIFT),
-					   &nid);
-
-		node_set_online(nid);
-
-		size = numa_enforce_memory_limit(drmem.base_addr, lmb_size);
-		if (!size)
-			continue;
+		/*
+		 * Append 'n' to 'linux,usable-memory' to get special
+		 * properties passed in by tools like kexec-tools. Relevant
+		 * only if this is a kexec/kdump kernel.
+		 */
+		sprintf(buf, "linux,usable-memory%d", (int)n);
+		usm = of_get_property(memory, buf, &len);
+		ranges = 1;
+		if (usm != NULL)
+			ranges = (len >> 2) /
+					 (n_mem_addr_cells + n_mem_size_cells);
+
+		base = drmem.base_addr;
+		size = lmb_size;
+		do {
+			if (usm != NULL) {
+				base = read_n_cells(n_mem_addr_cells, &usm);
+				size = read_n_cells(n_mem_size_cells, &usm);
+			}
 
-		add_active_range(nid, drmem.base_addr >> PAGE_SHIFT,
-				 (drmem.base_addr >> PAGE_SHIFT)
-				 + (size >> PAGE_SHIFT));
+			fake_numa_create_new_node(((base + size) >> PAGE_SHIFT),
+							 &nid);
+			node_set_online(nid);
+			sz = numa_enforce_memory_limit(base, size);
+			if (sz)
+				add_active_range(nid, base >> PAGE_SHIFT,
+						 (base >> PAGE_SHIFT)
+						+ (sz >> PAGE_SHIFT));
+		} while (--ranges);
 	}
 }
#8 lore raw

Re: [PATCH 1/4][V2] powerpc : add support for linux, usable-memory properties for drconf memory

Quoted 4 lines · Chandru

Scan for linux,usable-memory properties in case of dynamic reconfiguration memory . Support for kexec/kdump.

Could we *please* have a more comprehensive patch description that that? Something which will help people coming along in two (or five or ten) years time to understand what problem exists in the code, how this patch solves it, and why this approach was chosen over any alternative approaches?

Thanks,
Paul.

author
#9 lore raw

Re: [PATCH 1/4][V2] powerpc : add support for linux, usable-memory properties for drconf memory

Quoted 7 lines · On Tuesday 22 July 2008 14:46:20 Paul Mackerras wrote:
Quoted 4 lines · Chandru

Scan for linux,usable-memory properties in case of dynamic reconfiguration memory . Support for kexec/kdump.

Quoted 9 lines

Could we *please* have a more comprehensive patch description that that? Something which will help people coming along in two (or five or ten) years time to understand what problem exists in the code, how this patch solves it, and why this approach was chosen over any alternative approaches?

Thanks,
Paul.

Another alternate approach could be to create one 'linux,usable-drconf-memory' property and add all the usable memory regions into it, in a similar fashion to ibm,dynamic-memory property. For a given lmb in ibm,dynamic-memory , a corresponding usable-memory entry could be created which will contain 1 or more of (base,size) duple. For each entry in this new 'linux,usable-drconf-memory' property, a counter within it will tell us how many (base,size) duple are available in it. Some part of the current code may get duplicated. Let me go back and check if I can work on a patch for this approach .

thx,
Chandru

#10 lore raw

Re: [PATCH 1/4][V2] powerpc : add support for linux, usable-memory properties for drconf memory

In reply to Chandru
Quoted 8 lines · Chandru

Scan for linux,usable-memory properties in case of dynamic reconfiguration memory . Support for kexec/kdump.

---

Patch applies on powerpc tree. Patch was reviewed by Nathan Fontenot, Stephen Rothwell, Michael Neuling.

Any reason why there's no acks there then ? I don't have an objection to the patch per-se and I was planning to review it this week too, but if you had positive reviews and you addressed whatever comments the people had, there should be Acked-by: lines in your patch (ie, don't invent them, only put them there if you actually got that from the reviewers).

Cheers,
Ben.

Quoted 133 lines
 arch/powerpc/kernel/prom.c |   40 +++++++++++++++++++++++------
 arch/powerpc/mm/numa.c     |   48 ++++++++++++++++++++++++-----------
 2 files changed, 65 insertions(+), 23 deletions(-)

diff -Naurp powerpc-orig/arch/powerpc/kernel/prom.c powerpc/arch/powerpc/kernel/prom.c
--- powerpc-orig/arch/powerpc/kernel/prom.c 2008-07-22 14:11:53.000000000
+0530
+++ powerpc/arch/powerpc/kernel/prom.c 2008-07-22 14:12:17.000000000 +0530

(quoted diff) +32 -8
@@ -888,9 +888,10 @@ static u64 __init dt_mem_next_cell(int s
  */
 static int __init early_init_dt_scan_drconf_memory(unsigned long node)
 {
-	cell_t *dm, *ls;
-	unsigned long l, n, flags;
+	cell_t *dm, *ls, *usm;
+	unsigned long l, n, flags, ranges;
 	u64 base, size, lmb_size;
+	char buf[32];
 
 	ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
 	if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
@@ -914,14 +915,37 @@ static int __init early_init_dt_scan_drc
 		   or if the block is not assigned to this partition (0x8) */
 		if ((flags & 0x80) || !(flags & 0x8))
 			continue;
-		size = lmb_size;
-		if (iommu_is_off) {
+		if (iommu_is_off)
 			if (base >= 0x80000000ul)
 				continue;
-			if ((base + size) > 0x80000000ul)
-				size = 0x80000000ul - base;
-		}
-		lmb_add(base, size);
+		size = lmb_size;
+
+		/*
+		 * Append 'n' to 'linux,usable-memory' to get special
+		 * properties passed in by tools like kexec-tools. Relevant
+		 * only if this is a kexec/kdump kernel.
+		 */
+		sprintf(buf, "linux,usable-memory%d", (int)n);
+		usm = of_get_flat_dt_prop(node, buf, &l);
+		ranges = 1;
+		if (usm != NULL)
+			ranges = (l >> 2)/(dt_root_addr_cells
+						+ dt_root_size_cells);
+		do {
+			if (usm != NULL) {
+				base = dt_mem_next_cell(dt_root_addr_cells,
+							 &usm);
+				size = dt_mem_next_cell(dt_root_size_cells,
+							 &usm);
+				if (size == 0)
+					break;
+			}
+			if (iommu_is_off)
+				if ((base + size) > 0x80000000ul)
+					size = 0x80000000ul - base;
+
+			lmb_add(base, size);
+		} while (--ranges);
 	}
 	lmb_dump_all();
 	return 0;

diff -Naurp powerpc-orig/arch/powerpc/mm/numa.c powerpc/arch/powerpc/mm/numa.c

arch/powerpc/mm/numa.c +33 -15
@@ -493,11 +493,13 @@ static unsigned long __init numa_enforce
  */
 static void __init parse_drconf_memory(struct device_node *memory)
 {
-	const u32 *dm;
-	unsigned int n, rc;
-	unsigned long lmb_size, size;
+	const u32 *dm, *usm;
+	unsigned int n, rc, len, ranges;
+	unsigned long lmb_size, size, sz;
 	int nid;
 	struct assoc_arrays aa;
+	char buf[32];
+	u64 base;
 
 	n = of_get_drconf_memory(memory, &dm);
 	if (!n)
@@ -524,19 +526,35 @@ static void __init parse_drconf_memory(s
 
 		nid = of_drconf_to_nid_single(&drmem, &aa);
 
-		fake_numa_create_new_node(
-				((drmem.base_addr + lmb_size) >> PAGE_SHIFT),
-					   &nid);
-
-		node_set_online(nid);
-
-		size = numa_enforce_memory_limit(drmem.base_addr, lmb_size);
-		if (!size)
-			continue;
+		/*
+		 * Append 'n' to 'linux,usable-memory' to get special
+		 * properties passed in by tools like kexec-tools. Relevant
+		 * only if this is a kexec/kdump kernel.
+		 */
+		sprintf(buf, "linux,usable-memory%d", (int)n);
+		usm = of_get_property(memory, buf, &len);
+		ranges = 1;
+		if (usm != NULL)
+			ranges = (len >> 2) /
+					 (n_mem_addr_cells + n_mem_size_cells);
+
+		base = drmem.base_addr;
+		size = lmb_size;
+		do {
+			if (usm != NULL) {
+				base = read_n_cells(n_mem_addr_cells, &usm);
+				size = read_n_cells(n_mem_size_cells, &usm);
+			}
 
-		add_active_range(nid, drmem.base_addr >> PAGE_SHIFT,
-				 (drmem.base_addr >> PAGE_SHIFT)
-				 + (size >> PAGE_SHIFT));
+			fake_numa_create_new_node(((base + size) >> PAGE_SHIFT),
+							 &nid);
+			node_set_online(nid);
+			sz = numa_enforce_memory_limit(base, size);
+			if (sz)
+				add_active_range(nid, base >> PAGE_SHIFT,
+						 (base >> PAGE_SHIFT)
+						+ (sz >> PAGE_SHIFT));
+		} while (--ranges);
 	}
 }