public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2
@ 2009-07-22  5:06 KAMEZAWA Hiroyuki
  2009-07-22  5:07 ` [PATCH 1/4] kcore: clean up to use generic list ops KAMEZAWA Hiroyuki
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  5:06 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org; +Cc: akpm@linux-foundation.org

I'm sorry I can't find who should be in CC.

This includes some amounts changes to arch-specici code, 
but very special codes for kcore. Can I test this in -mm if no objections ?

Now, /proc/kcore 's physical memory information is set up at boot
via kclist_add(). But it's not updated at memory hotplug etc and
it can include much memory holes. This patch is for generatinc /proc/kcore
based on memory management information maintained by the kernel.

 For usual archs, /proc/iomem is used
 For ppc, lmb information will be used.

This is v2. bugs/bahavior is fixed. Below is output of
"readelf -l /proc/kcore" before/after the patch. (on my vm host..)


=====[Before]======
Elf file type is CORE (Core file)
Entry point 0x0
There are 6 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  NOTE           0x0000000000000190 0x0000000000000000 0x0000000000000000
                 0x00000000000021a4 0x0000000000000000         0
  LOAD           0x00007fffff603000 0xffffffffff600000 0x0000000000000000
                 0x0000000000800000 0x0000000000800000  RWE    1000
  LOAD           0x00007fffa0003000 0xffffffffa0000000 0x0000000000000000
                 0x000000005f000000 0x000000005f000000  RWE    1000
  LOAD           0x00007fff8100c000 0xffffffff81009000 0x0000000000000000
                 0x000000000111a000 0x000000000111a000  RWE    1000
  LOAD           0x0000490000003000 0xffffc90000000000 0x0000000000000000
                 0x00001fffffffffff 0x00001fffffffffff  RWE    1000
  LOAD           0x0000080000003000 0xffff880000000000 0x0000000000000000
                 0x0000000065400000 0x0000000065400000  RWE    1000

====[After]=====


Elf file type is CORE (Core file)
Entry point 0x0
There are 8 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  NOTE           0x0000000000000200 0x0000000000000000 0x0000000000000000
                 0x00000000000021a4 0x0000000000000000         0
  LOAD           0x0000080065303000 0xffff880065300000 0x0000000000000000
                 0x0000000000100000 0x0000000000100000  RWE    1000
  LOAD           0x0000080000103000 0xffff880000100000 0x0000000000000000
                 0x00000000651f0000 0x00000000651f0000  RWE    1000
  LOAD           0x0000080000013000 0xffff880000010000 0x0000000000000000
                 0x000000000008f000 0x000000000008f000  RWE    1000
  LOAD           0x0000490000003000 0xffffc90000000000 0x0000000000000000
                 0x00001fffffffffff 0x00001fffffffffff  RWE    1000
  LOAD           0x00007fff8100c000 0xffffffff81009000 0x0000000000000000
                 0x000000000111a000 0x000000000111a000  RWE    1000
  LOAD           0x00007fffa0003000 0xffffffffa0000000 0x0000000000000000
                 0x000000005f000000 0x000000005f000000  RWE    1000
  LOAD           0x00007fffff603000 0xffffffffff600000 0x0000000000000000
                 0x0000000000800000 0x0000000000800000  RWE    1000



You can see the section

    LOAD         0x0000080000003000 0xffff880000000000 0x0000000000000000
                 0x0000000065400000 0x0000000065400000  RWE    1000
is divided into

  LOAD           0x0000080065303000 0xffff880065300000 0x0000000000000000
                 0x0000000000100000 0x0000000000100000  RWE    1000
  LOAD           0x0000080000103000 0xffff880000100000 0x0000000000000000
                 0x00000000651f0000 0x00000000651f0000  RWE    1000
  LOAD           0x0000080000013000 0xffff880000010000 0x0000000000000000
                 0x000000000008f000 0x000000000008f000  RWE    1000

This is on physical memory information.

And yes, this host's memory map is following. 
(This is same to /proc/iomem, of course)
[    0.000000] early_node_map[3] active PFN ranges
[    0.000000]     0: 0x00000010 -> 0x0000009f
[    0.000000]     0: 0x00000100 -> 0x000652f0
[    0.000000]     0: 0x00065300 -> 0x00065400


Thanks,
-Kame


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

* [PATCH 1/4] kcore: clean up to use generic list ops
  2009-07-22  5:06 [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 KAMEZAWA Hiroyuki
@ 2009-07-22  5:07 ` KAMEZAWA Hiroyuki
  2009-07-22  5:53   ` Amerigo Wang
  2009-07-22  5:08 ` [PATCH 2/4] kcore: add kclist type KAMEZAWA Hiroyuki
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  5:07 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

/proc/kcore uses its own list handling codes. It's better to use
generic list codes.

And read_kcore() use "m" to specifiy
  - kcore entry
  - vmalloc entry
in different types.
This patch renames "m" to "vms" for vmalloc(), avoiding confusion.

No changes in logic. just clean up.

Changelog v1->v2
 - no changes.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 fs/proc/kcore.c         |   41 ++++++++++++++++++++++-------------------
 include/linux/proc_fs.h |    2 +-
 2 files changed, 23 insertions(+), 20 deletions(-)

Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
@@ -20,6 +20,7 @@
 #include <linux/init.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
+#include <linux/list.h>
 
 #define CORE_STR "CORE"
 
@@ -57,7 +58,7 @@ struct memelfnote
 	void *data;
 };
 
-static struct kcore_list *kclist;
+static LIST_HEAD(kclist_head);
 static DEFINE_RWLOCK(kclist_lock);
 
 void
@@ -67,8 +68,7 @@ kclist_add(struct kcore_list *new, void 
 	new->size = size;
 
 	write_lock(&kclist_lock);
-	new->next = kclist;
-	kclist = new;
+	list_add_tail(&new->list, &kclist_head);
 	write_unlock(&kclist_lock);
 }
 
@@ -80,7 +80,7 @@ static size_t get_kcore_size(int *nphdr,
 	*nphdr = 1; /* PT_NOTE */
 	size = 0;
 
-	for (m=kclist; m; m=m->next) {
+	list_for_each_entry(m, &kclist_head, list) {
 		try = kc_vaddr_to_offset((size_t)m->addr + m->size);
 		if (try > size)
 			size = try;
@@ -192,7 +192,7 @@ static void elf_kcore_store_hdr(char *bu
 	nhdr->p_align	= 0;
 
 	/* setup ELF PT_LOAD program header for every area */
-	for (m=kclist; m; m=m->next) {
+	list_for_each_entry(m, &kclist_head, list) {
 		phdr = (struct elf_phdr *) bufp;
 		bufp += sizeof(struct elf_phdr);
 		offset += sizeof(struct elf_phdr);
@@ -317,7 +317,7 @@ read_kcore(struct file *file, char __use
 		struct kcore_list *m;
 
 		read_lock(&kclist_lock);
-		for (m=kclist; m; m=m->next) {
+		list_for_each_entry(m, &kclist_head, list) {
 			if (start >= m->addr && start < (m->addr+m->size))
 				break;
 		}
@@ -328,7 +328,7 @@ read_kcore(struct file *file, char __use
 				return -EFAULT;
 		} else if (is_vmalloc_addr((void *)start)) {
 			char * elf_buf;
-			struct vm_struct *m;
+			struct vm_struct *vms;
 			unsigned long curstart = start;
 			unsigned long cursize = tsz;
 
@@ -337,29 +337,32 @@ read_kcore(struct file *file, char __use
 				return -ENOMEM;
 
 			read_lock(&vmlist_lock);
-			for (m=vmlist; m && cursize; m=m->next) {
+			for (vms = vmlist; vms && cursize; vms = vms->next) {
 				unsigned long vmstart;
 				unsigned long vmsize;
-				unsigned long msize = m->size - PAGE_SIZE;
+				unsigned long msize = vms->size - PAGE_SIZE;
+				unsigned long curend, vmend;
 
-				if (((unsigned long)m->addr + msize) < 
+				if (((unsigned long)vms->addr + msize) < 
 								curstart)
 					continue;
-				if ((unsigned long)m->addr > (curstart + 
+				if ((unsigned long)vms->addr > (curstart + 
 								cursize))
 					break;
-				vmstart = (curstart < (unsigned long)m->addr ? 
-					(unsigned long)m->addr : curstart);
-				if (((unsigned long)m->addr + msize) > 
-							(curstart + cursize))
-					vmsize = curstart + cursize - vmstart;
+				if (curstart < (unsigned long)vms->addr)
+					vmstart = (unsigned long)vms->addr;
 				else
-					vmsize = (unsigned long)m->addr + 
-							msize - vmstart;
+					vmstart = curstart;
+				curend = curstart + cursize;
+				vmend = (unsigned long)vms->addr + msize;
+				if (vmend > curend)
+					vmsize = curend - vmstart;
+				else
+					vmsize = vmend - vmstart;
 				curstart = vmstart + vmsize;
 				cursize -= vmsize;
 				/* don't dump ioremap'd stuff! (TA) */
-				if (m->flags & VM_IOREMAP)
+				if (vms->flags & VM_IOREMAP)
 					continue;
 				memcpy(elf_buf + (vmstart - start),
 					(char *)vmstart, vmsize);
Index: mmotm-2.6.31-Jul16/include/linux/proc_fs.h
===================================================================
--- mmotm-2.6.31-Jul16.orig/include/linux/proc_fs.h
+++ mmotm-2.6.31-Jul16/include/linux/proc_fs.h
@@ -79,7 +79,7 @@ struct proc_dir_entry {
 };
 
 struct kcore_list {
-	struct kcore_list *next;
+	struct list_head list;
 	unsigned long addr;
 	size_t size;
 };


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

* [PATCH 2/4] kcore: add kclist type
  2009-07-22  5:06 [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 KAMEZAWA Hiroyuki
  2009-07-22  5:07 ` [PATCH 1/4] kcore: clean up to use generic list ops KAMEZAWA Hiroyuki
@ 2009-07-22  5:08 ` KAMEZAWA Hiroyuki
  2009-07-22  6:00   ` Amerigo Wang
  2009-07-22  5:10 ` [PATCH 3/4] kcore: build physical memory direct map information in proper way KAMEZAWA Hiroyuki
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  5:08 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Now, kclist_add() only eats start address and size as its arguments.
Considering to make kclist dynamically reconfigulable, it's necessary
to know which kclists are for System RAM and whic is not.

This patch add kclist types as
  KCORE_RAM
  KCORE_VMALLOC
  KCORE_TEXT
  KCORE_OTHER

region for KCORE_RAM will be dynamically updated at memory hotplug.

Chnagelog v1->v2
 - no changes.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 arch/ia64/mm/init.c       |    7 ++++---
 arch/mips/mm/init.c       |    7 ++++---
 arch/powerpc/mm/init_32.c |    4 ++--
 arch/powerpc/mm/init_64.c |    5 +++--
 arch/sh/mm/init.c         |    4 ++--
 arch/x86/mm/init_32.c     |    4 ++--
 arch/x86/mm/init_64.c     |   11 ++++++-----
 fs/proc/kcore.c           |    3 ++-
 include/linux/proc_fs.h   |   13 +++++++++++--
 9 files changed, 36 insertions(+), 22 deletions(-)

Index: mmotm-2.6.31-Jul16/include/linux/proc_fs.h
===================================================================
--- mmotm-2.6.31-Jul16.orig/include/linux/proc_fs.h
+++ mmotm-2.6.31-Jul16/include/linux/proc_fs.h
@@ -78,10 +78,18 @@ struct proc_dir_entry {
 	struct list_head pde_openers;	/* who did ->open, but not ->release */
 };
 
+enum kcore_type {
+	KCORE_TEXT,
+	KCORE_VMALLOC,
+	KCORE_RAM,
+	KCORE_OTHER,
+};
+
 struct kcore_list {
 	struct list_head list;
 	unsigned long addr;
 	size_t size;
+	int type;
 };
 
 struct vmcore {
@@ -233,11 +241,12 @@ static inline void dup_mm_exe_file(struc
 #endif /* CONFIG_PROC_FS */
 
 #if !defined(CONFIG_PROC_KCORE)
-static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
+static inline void
+kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
 {
 }
 #else
-extern void kclist_add(struct kcore_list *, void *, size_t);
+extern void kclist_add(struct kcore_list *, void *, size_t, int type);
 #endif
 
 union proc_op {
Index: mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/ia64/mm/init.c
+++ mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
@@ -639,9 +639,10 @@ mem_init (void)
 
 	high_memory = __va(max_low_pfn * PAGE_SIZE);
 
-	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE);
-	kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
-	kclist_add(&kcore_kernel, _stext, _end - _stext);
+	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE, KCORE_RAM);
+	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
+			VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
+	kclist_add(&kcore_kernel, _stext, _end - _stext, KCORE_TEXT);
 
 	for_each_online_pgdat(pgdat)
 		if (pgdat->bdata->node_bootmem_map)
Index: mmotm-2.6.31-Jul16/arch/mips/mm/init.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/mips/mm/init.c
+++ mmotm-2.6.31-Jul16/arch/mips/mm/init.c
@@ -409,11 +409,12 @@ void __init mem_init(void)
 	if ((unsigned long) &_text > (unsigned long) CKSEG0)
 		/* The -4 is a hack so that user tools don't have to handle
 		   the overflow.  */
-		kclist_add(&kcore_kseg0, (void *) CKSEG0, 0x80000000 - 4);
+		kclist_add(&kcore_kseg0, (void *) CKSEG0,
+				0x80000000 - 4, KCORE_TEXT);
 #endif
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
-		   VMALLOC_END-VMALLOC_START);
+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
 	printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
 	       "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_32.c
+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
@@ -270,11 +270,11 @@ static int __init setup_kcore(void)
 						size);
 		}
 
-		kclist_add(kcore_mem, __va(base), size);
+		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
 	}
 
 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
-		VMALLOC_END-VMALLOC_START);
+		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
 	return 0;
 }
Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_64.c
+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
@@ -128,10 +128,11 @@ static int __init setup_kcore(void)
 		if (!kcore_mem)
 			panic("%s: kmalloc failed\n", __func__);
 
-		kclist_add(kcore_mem, __va(base), size);
+		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
 	}
 
-	kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
+	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
+		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
 	return 0;
 }
Index: mmotm-2.6.31-Jul16/arch/sh/mm/init.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/sh/mm/init.c
+++ mmotm-2.6.31-Jul16/arch/sh/mm/init.c
@@ -218,9 +218,9 @@ void __init mem_init(void)
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
 
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
-		   VMALLOC_END - VMALLOC_START);
+		   VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
 
 	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
 	       "%dk data, %dk init)\n",
Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_32.c
+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
@@ -886,9 +886,9 @@ void __init mem_init(void)
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
 
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
-		   VMALLOC_END-VMALLOC_START);
+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
 	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
 			"%dk reserved, %dk data, %dk init, %ldk highmem)\n",
Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_64.c
+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
@@ -677,13 +677,14 @@ void __init mem_init(void)
 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
 
 	/* Register memory areas for /proc/kcore */
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
-		   VMALLOC_END-VMALLOC_START);
-	kclist_add(&kcore_kernel, &_stext, _end - _stext);
-	kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN);
+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
+	kclist_add(&kcore_kernel, &_stext, _end - _stext, KCORE_TEXT);
+	kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN,
+			KCORE_OTHER);
 	kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
-				 VSYSCALL_END - VSYSCALL_START);
+			 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
 
 	printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
 			 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
@@ -62,10 +62,11 @@ static LIST_HEAD(kclist_head);
 static DEFINE_RWLOCK(kclist_lock);
 
 void
-kclist_add(struct kcore_list *new, void *addr, size_t size)
+kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
 {
 	new->addr = (unsigned long)addr;
 	new->size = size;
+	new->type = type;
 
 	write_lock(&kclist_lock);
 	list_add_tail(&new->list, &kclist_head);


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

* [PATCH 3/4] kcore: build physical memory direct map information in proper way
  2009-07-22  5:06 [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 KAMEZAWA Hiroyuki
  2009-07-22  5:07 ` [PATCH 1/4] kcore: clean up to use generic list ops KAMEZAWA Hiroyuki
  2009-07-22  5:08 ` [PATCH 2/4] kcore: add kclist type KAMEZAWA Hiroyuki
@ 2009-07-22  5:10 ` KAMEZAWA Hiroyuki
  2009-07-22  6:09   ` Amerigo Wang
  2009-07-22  5:12 ` [PATCH 4/4] kcore: remove noise from walk_memory_resource KAMEZAWA Hiroyuki
  2009-07-22  5:52 ` [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 Amerigo Wang
  4 siblings, 1 reply; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  5:10 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

For /proc/kcore, each arch registers its memory range by kclist_add().
In usual,
	- range of physical memory
	- range of vmalloc area
	- text, etc...
are registered but "range of physical memory" has some troubles.
It doesn't updated at memory hotplug and it tend to include
unnecessary memory holes. Now, /proc/iomem (kernel/resource.c)
includes required physical memory range information and it's
properly updated at memory hotplug. Then, it's good to avoid
using its own code(duplicating information) and to rebuild
kclist for physical memory based on /proc/iomem.

Note: walk_memory_resource() works based on lmb inforamtion in PPC
but no problem. It's updated at memory hotplug.

Changelog: v1 -> v2
 - removed -EBUSY at memory hotplug in read_kcore()
   (continue reading is no problem in general.)
 - fixed initial value of kcore_need_update to be 1.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 arch/ia64/mm/init.c            |    1 
 arch/mips/mm/init.c            |    1 
 arch/powerpc/mm/init_32.c      |   24 ------
 arch/powerpc/mm/init_64.c      |   17 ----
 arch/sh/mm/init.c              |    1 
 arch/x86/mm/init_32.c          |    1 
 arch/x86/mm/init_64.c          |    1 
 fs/proc/kcore.c                |  151 ++++++++++++++++++++++++++++++++++++++---
 include/linux/ioport.h         |    8 ++
 include/linux/memory_hotplug.h |    7 -
 kernel/resource.c              |    2 
 11 files changed, 149 insertions(+), 65 deletions(-)

Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
@@ -21,6 +21,9 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <linux/list.h>
+#include <linux/ioport.h>
+#include <linux/memory_hotplug.h>
+#include <linux/memory.h>
 
 #define CORE_STR "CORE"
 
@@ -30,17 +33,6 @@
 
 static struct proc_dir_entry *proc_root_kcore;
 
-static int open_kcore(struct inode * inode, struct file * filp)
-{
-	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
-}
-
-static ssize_t read_kcore(struct file *, char __user *, size_t, loff_t *);
-
-static const struct file_operations proc_kcore_operations = {
-	.read		= read_kcore,
-	.open		= open_kcore,
-};
 
 #ifndef kc_vaddr_to_offset
 #define	kc_vaddr_to_offset(v) ((v) - PAGE_OFFSET)
@@ -60,6 +52,7 @@ struct memelfnote
 
 static LIST_HEAD(kclist_head);
 static DEFINE_RWLOCK(kclist_lock);
+static int kcore_need_update = 1;
 
 void
 kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
@@ -98,6 +91,104 @@ static size_t get_kcore_size(int *nphdr,
 	return size + *elf_buflen;
 }
 
+static void free_kclist_ents(struct list_head *head)
+{
+	struct kcore_list *tmp, *pos;
+
+	list_for_each_entry_safe(pos, tmp, head, list) {
+		list_del(&pos->list);
+		kfree(pos);
+	}
+}
+/*
+ * Replace all KCORE_RAM information with passed list.
+ */
+static void __kcore_update_ram(struct list_head *list)
+{
+	struct kcore_list *tmp, *pos;
+	LIST_HEAD(garbage);
+
+	write_lock(&kclist_lock);
+	if (kcore_need_update) {
+		list_for_each_entry_safe(pos, tmp, &kclist_head, list) {
+			if (pos->type == KCORE_RAM)
+				list_move(&pos->list, &garbage);
+		}
+		list_splice(list, &kclist_head);
+	} else
+		list_splice(list, &garbage);
+	kcore_need_update = 0;
+	write_unlock(&kclist_lock);
+
+	free_kclist_ents(&garbage);
+}
+
+
+#ifdef CONFIG_HIGHMEM
+/*
+ * If no highmem, we can assume [0...max_low_pfn) continuous range of memory
+ * because memory hole is not as big as !HIGHMEM case.
+ * (HIGHMEM is special because part of memory is _invisible_ from the kernel.)
+ */
+static int kcore_update_ram(void)
+{
+	LIST_HEAD(head);
+	struct kcore_list *ent;
+	int ret = 0;
+
+	ent = kmalloc(sizeof(*head), GFP_KERNEL);
+	if (!ent) {
+		ret = -ENOMEM;
+		goto unlock_out;
+	}
+	ent->addr = __va(0);
+	ent->size = max_low_pfn << PAGE_SHIFT;
+	ent->type = SYSTEM_RAM;
+	list_add(&ent->list, &head);
+	__kcore_update_ram(&head);
+	return ret;
+}
+
+#else /* !CONFIG_HIGHMEM */
+
+static int
+kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg)
+{
+	struct list_head *head = (struct list_head *)arg;
+	struct kcore_list *ent;
+
+	ent = kmalloc(sizeof(*ent), GFP_KERNEL);
+	if (!ent)
+		return -ENOMEM;
+	ent->addr = (unsigned long)__va((pfn << PAGE_SHIFT));
+	ent->size = nr_pages << PAGE_SHIFT;
+	ent->type = KCORE_RAM;
+	list_add(&ent->list, head);
+	return 0;
+}
+
+static int kcore_update_ram(void)
+{
+	int nid, ret;
+	unsigned long end_pfn;
+	LIST_HEAD(head);
+
+	/* Not inialized....update now */
+	/* find out "max pfn" */
+	end_pfn = 0;
+	for_each_node_state(nid, N_HIGH_MEMORY)
+		if (end_pfn < node_end_pfn(nid))
+			end_pfn = node_end_pfn(nid);
+	/* scan 0 to max_pfn */
+	ret = walk_memory_resource(0, end_pfn, &head, kclist_add_private);
+	if (ret) {
+		free_kclist_ents(&head);
+		return -ENOMEM;
+	}
+	__kcore_update_ram(&head);
+	return ret;
+}
+#endif /* CONFIG_HIGH_MEM */
 
 /*****************************************************************************/
 /*
@@ -271,6 +362,11 @@ read_kcore(struct file *file, char __use
 		read_unlock(&kclist_lock);
 		return 0;
 	}
+	/* memory hotplug ?? */
+	if (kcore_need_update) {
+		read_unlock(&kclist_lock);
+		return -EBUSY;
+	}
 
 	/* trim buflen to not go beyond EOF */
 	if (buflen > size - *fpos)
@@ -406,9 +502,42 @@ read_kcore(struct file *file, char __use
 	return acc;
 }
 
+static int open_kcore(struct inode * inode, struct file *filp)
+{
+	if (!capable(CAP_SYS_RAWIO))
+		return -EPERM;
+	if (kcore_need_update)
+		kcore_update_ram();
+	return 0;
+}
+
+
+static const struct file_operations proc_kcore_operations = {
+	.read		= read_kcore,
+	.open		= open_kcore,
+};
+
+/* just remember that we have to update kcore */
+static int __meminit kcore_callback(struct notifier_block *self,
+				    unsigned long action, void *arg)
+{
+	switch (action) {
+	case MEM_ONLINE:
+	case MEM_OFFLINE:
+		write_lock(&kclist_lock);
+		kcore_need_update = 1;
+		write_unlock(&kclist_lock);
+	}
+	return NOTIFY_OK;
+}
+
+
 static int __init proc_kcore_init(void)
 {
 	proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
+	kcore_update_ram();
+	hotplug_memory_notifier(kcore_callback, 0);
 	return 0;
 }
 module_init(proc_kcore_init);
+
Index: mmotm-2.6.31-Jul16/include/linux/ioport.h
===================================================================
--- mmotm-2.6.31-Jul16.orig/include/linux/ioport.h
+++ mmotm-2.6.31-Jul16/include/linux/ioport.h
@@ -186,5 +186,13 @@ extern void __devm_release_region(struct
 extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size);
 extern int iomem_is_exclusive(u64 addr);
 
+/*
+ * Walk through all SYSTEM_RAM which is registered as resource.
+ * arg is (start_pfn, nr_pages, private_arg_pointer)
+ */
+extern int walk_memory_resource(unsigned long start_pfn,
+			unsigned long nr_pages, void *arg,
+			int (*func)(unsigned long, unsigned long, void *));
+
 #endif /* __ASSEMBLY__ */
 #endif	/* _LINUX_IOPORT_H */
Index: mmotm-2.6.31-Jul16/include/linux/memory_hotplug.h
===================================================================
--- mmotm-2.6.31-Jul16.orig/include/linux/memory_hotplug.h
+++ mmotm-2.6.31-Jul16/include/linux/memory_hotplug.h
@@ -191,13 +191,6 @@ static inline void register_page_bootmem
 
 #endif /* ! CONFIG_MEMORY_HOTPLUG */
 
-/*
- * Walk through all memory which is registered as resource.
- * arg is (start_pfn, nr_pages, private_arg_pointer)
- */
-extern int walk_memory_resource(unsigned long start_pfn,
-			unsigned long nr_pages, void *arg,
-			int (*func)(unsigned long, unsigned long, void *));
 
 #ifdef CONFIG_MEMORY_HOTREMOVE
 
Index: mmotm-2.6.31-Jul16/kernel/resource.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
+++ mmotm-2.6.31-Jul16/kernel/resource.c
@@ -234,7 +234,7 @@ int release_resource(struct resource *ol
 
 EXPORT_SYMBOL(release_resource);
 
-#if defined(CONFIG_MEMORY_HOTPLUG) && !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
+#if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
 /*
  * Finds the lowest memory reosurce exists within [res->start.res->end)
  * the caller must specify res->start, res->end, res->flags.
Index: mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/ia64/mm/init.c
+++ mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
@@ -639,7 +639,6 @@ mem_init (void)
 
 	high_memory = __va(max_low_pfn * PAGE_SIZE);
 
-	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE, KCORE_RAM);
 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
 			VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 	kclist_add(&kcore_kernel, _stext, _end - _stext, KCORE_TEXT);
Index: mmotm-2.6.31-Jul16/arch/mips/mm/init.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/mips/mm/init.c
+++ mmotm-2.6.31-Jul16/arch/mips/mm/init.c
@@ -412,7 +412,6 @@ void __init mem_init(void)
 		kclist_add(&kcore_kseg0, (void *) CKSEG0,
 				0x80000000 - 4, KCORE_TEXT);
 #endif
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_32.c
+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
@@ -249,30 +249,6 @@ static struct kcore_list kcore_vmem;
 
 static int __init setup_kcore(void)
 {
-	int i;
-
-	for (i = 0; i < lmb.memory.cnt; i++) {
-		unsigned long base;
-		unsigned long size;
-		struct kcore_list *kcore_mem;
-
-		base = lmb.memory.region[i].base;
-		size = lmb.memory.region[i].size;
-
-		kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
-		if (!kcore_mem)
-			panic("%s: kmalloc failed\n", __func__);
-
-		/* must stay under 32 bits */
-		if ( 0xfffffffful - (unsigned long)__va(base) < size) {
-			size = 0xfffffffful - (unsigned long)(__va(base));
-			printk(KERN_DEBUG "setup_kcore: restrict size=%lx\n",
-						size);
-		}
-
-		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
-	}
-
 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
 		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_64.c
+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
@@ -114,23 +114,6 @@ static struct kcore_list kcore_vmem;
 
 static int __init setup_kcore(void)
 {
-	int i;
-
-	for (i=0; i < lmb.memory.cnt; i++) {
-		unsigned long base, size;
-		struct kcore_list *kcore_mem;
-
-		base = lmb.memory.region[i].base;
-		size = lmb.memory.region[i].size;
-
-		/* GFP_ATOMIC to avoid might_sleep warnings during boot */
-		kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
-		if (!kcore_mem)
-			panic("%s: kmalloc failed\n", __func__);
-
-		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
-	}
-
 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
 		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
Index: mmotm-2.6.31-Jul16/arch/sh/mm/init.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/sh/mm/init.c
+++ mmotm-2.6.31-Jul16/arch/sh/mm/init.c
@@ -218,7 +218,6 @@ void __init mem_init(void)
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
 
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
 		   VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
 
Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_32.c
+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
@@ -886,7 +886,6 @@ void __init mem_init(void)
 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
 
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 
Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_64.c
+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
@@ -677,7 +677,6 @@ void __init mem_init(void)
 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
 
 	/* Register memory areas for /proc/kcore */
-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
 	kclist_add(&kcore_kernel, &_stext, _end - _stext, KCORE_TEXT);


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

* [PATCH 4/4] kcore: remove noise from walk_memory_resource
  2009-07-22  5:06 [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 KAMEZAWA Hiroyuki
                   ` (2 preceding siblings ...)
  2009-07-22  5:10 ` [PATCH 3/4] kcore: build physical memory direct map information in proper way KAMEZAWA Hiroyuki
@ 2009-07-22  5:12 ` KAMEZAWA Hiroyuki
  2009-07-22  6:21   ` Amerigo Wang
  2009-07-22  5:52 ` [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 Amerigo Wang
  4 siblings, 1 reply; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  5:12 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Originally, walk_memory_resource() was introduced to traverse all memory
of "System RAM" for detecting memory hotplug/unplug range.
For doing so, flags of IORESOUCE_MEM|IORESOURCE_BUSY was used and this
was enough for memory hotplug because scanning range was controlled properly.

But for using other purpose, /proc/kcore, this may includes some firmware
area marked as IORESOURCE_BUSY | IORESOUCE_MEM. This patch makes the check
strict to find out busy "System RAM".

Note: PPC64 keeps their own walk_memory_resouce(), which walk through
ppc64's lmb informaton. Because old kclist_add() is called per lmb,
this patch makes no difference in behavior, finally.

Changelog v2:
 - new patch from v2.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 kernel/resource.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Index: mmotm-2.6.31-Jul16/kernel/resource.c
===================================================================
--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
+++ mmotm-2.6.31-Jul16/kernel/resource.c
@@ -237,10 +237,10 @@ EXPORT_SYMBOL(release_resource);
 #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
 /*
  * Finds the lowest memory reosurce exists within [res->start.res->end)
- * the caller must specify res->start, res->end, res->flags.
+ * the caller must specify res->start, res->end, res->flags and "name".
  * If found, returns 0, res is overwritten, if not found, returns -1.
  */
-static int find_next_system_ram(struct resource *res)
+static int find_next_system_ram(struct resource *res, char *name)
 {
 	resource_size_t start, end;
 	struct resource *p;
@@ -256,6 +256,8 @@ static int find_next_system_ram(struct r
 		/* system ram is just marked as IORESOURCE_MEM */
 		if (p->flags != res->flags)
 			continue;
+		if (name && strcmp(p->name, name))
+			continue;
 		if (p->start > end) {
 			p = NULL;
 			break;
@@ -273,19 +275,27 @@ static int find_next_system_ram(struct r
 		res->end = p->end;
 	return 0;
 }
+
+/*
+ * This function calls callback against all memory range of "System RAM"
+ * which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
+ * Now, this function is only for "System RAM".
+ */
 int
 walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg,
-			int (*func)(unsigned long, unsigned long, void *))
+		int (*func)(unsigned long, unsigned long, void *))
 {
 	struct resource res;
 	unsigned long pfn, len;
 	u64 orig_end;
 	int ret = -1;
+
 	res.start = (u64) start_pfn << PAGE_SHIFT;
 	res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
 	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	orig_end = res.end;
-	while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
+	while ((res.start < res.end) &&
+		(find_next_system_ram(&res, "System RAM") >= 0)) {
 		pfn = (unsigned long)(res.start >> PAGE_SHIFT);
 		len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT);
 		ret = (*func)(pfn, len, arg);


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

* Re: [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2
  2009-07-22  5:06 [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 KAMEZAWA Hiroyuki
                   ` (3 preceding siblings ...)
  2009-07-22  5:12 ` [PATCH 4/4] kcore: remove noise from walk_memory_resource KAMEZAWA Hiroyuki
@ 2009-07-22  5:52 ` Amerigo Wang
  4 siblings, 0 replies; 14+ messages in thread
From: Amerigo Wang @ 2009-07-22  5:52 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, Jul 22, 2009 at 02:06:13PM +0900, KAMEZAWA Hiroyuki wrote:
>I'm sorry I can't find who should be in CC.
>

Just keep the original CC's, or run scripts/get_maintainer.pl -f fs/proc/kcore.c.
:-)


>This includes some amounts changes to arch-specici code, 
>but very special codes for kcore. Can I test this in -mm if no objections ?
>
>Now, /proc/kcore 's physical memory information is set up at boot
>via kclist_add(). But it's not updated at memory hotplug etc and
>it can include much memory holes. This patch is for generatinc /proc/kcore
>based on memory management information maintained by the kernel.
>
> For usual archs, /proc/iomem is used
> For ppc, lmb information will be used.
>

This is a good idea!

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

* Re: [PATCH 1/4] kcore: clean up to use generic list ops
  2009-07-22  5:07 ` [PATCH 1/4] kcore: clean up to use generic list ops KAMEZAWA Hiroyuki
@ 2009-07-22  5:53   ` Amerigo Wang
  0 siblings, 0 replies; 14+ messages in thread
From: Amerigo Wang @ 2009-07-22  5:53 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, Jul 22, 2009 at 02:07:22PM +0900, KAMEZAWA Hiroyuki wrote:
>From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>
>/proc/kcore uses its own list handling codes. It's better to use
>generic list codes.
>
>And read_kcore() use "m" to specifiy
>  - kcore entry
>  - vmalloc entry
>in different types.
>This patch renames "m" to "vms" for vmalloc(), avoiding confusion.
>
>No changes in logic. just clean up.


Nice cleaning!

Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>


>
>Changelog v1->v2
> - no changes.
>
>Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>---
> fs/proc/kcore.c         |   41 ++++++++++++++++++++++-------------------
> include/linux/proc_fs.h |    2 +-
> 2 files changed, 23 insertions(+), 20 deletions(-)
>
>Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
>+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
>@@ -20,6 +20,7 @@
> #include <linux/init.h>
> #include <asm/uaccess.h>
> #include <asm/io.h>
>+#include <linux/list.h>
> 
> #define CORE_STR "CORE"
> 
>@@ -57,7 +58,7 @@ struct memelfnote
> 	void *data;
> };
> 
>-static struct kcore_list *kclist;
>+static LIST_HEAD(kclist_head);
> static DEFINE_RWLOCK(kclist_lock);
> 
> void
>@@ -67,8 +68,7 @@ kclist_add(struct kcore_list *new, void 
> 	new->size = size;
> 
> 	write_lock(&kclist_lock);
>-	new->next = kclist;
>-	kclist = new;
>+	list_add_tail(&new->list, &kclist_head);
> 	write_unlock(&kclist_lock);
> }
> 
>@@ -80,7 +80,7 @@ static size_t get_kcore_size(int *nphdr,
> 	*nphdr = 1; /* PT_NOTE */
> 	size = 0;
> 
>-	for (m=kclist; m; m=m->next) {
>+	list_for_each_entry(m, &kclist_head, list) {
> 		try = kc_vaddr_to_offset((size_t)m->addr + m->size);
> 		if (try > size)
> 			size = try;
>@@ -192,7 +192,7 @@ static void elf_kcore_store_hdr(char *bu
> 	nhdr->p_align	= 0;
> 
> 	/* setup ELF PT_LOAD program header for every area */
>-	for (m=kclist; m; m=m->next) {
>+	list_for_each_entry(m, &kclist_head, list) {
> 		phdr = (struct elf_phdr *) bufp;
> 		bufp += sizeof(struct elf_phdr);
> 		offset += sizeof(struct elf_phdr);
>@@ -317,7 +317,7 @@ read_kcore(struct file *file, char __use
> 		struct kcore_list *m;
> 
> 		read_lock(&kclist_lock);
>-		for (m=kclist; m; m=m->next) {
>+		list_for_each_entry(m, &kclist_head, list) {
> 			if (start >= m->addr && start < (m->addr+m->size))
> 				break;
> 		}
>@@ -328,7 +328,7 @@ read_kcore(struct file *file, char __use
> 				return -EFAULT;
> 		} else if (is_vmalloc_addr((void *)start)) {
> 			char * elf_buf;
>-			struct vm_struct *m;
>+			struct vm_struct *vms;
> 			unsigned long curstart = start;
> 			unsigned long cursize = tsz;
> 
>@@ -337,29 +337,32 @@ read_kcore(struct file *file, char __use
> 				return -ENOMEM;
> 
> 			read_lock(&vmlist_lock);
>-			for (m=vmlist; m && cursize; m=m->next) {
>+			for (vms = vmlist; vms && cursize; vms = vms->next) {
> 				unsigned long vmstart;
> 				unsigned long vmsize;
>-				unsigned long msize = m->size - PAGE_SIZE;
>+				unsigned long msize = vms->size - PAGE_SIZE;
>+				unsigned long curend, vmend;
> 
>-				if (((unsigned long)m->addr + msize) < 
>+				if (((unsigned long)vms->addr + msize) < 
> 								curstart)
> 					continue;
>-				if ((unsigned long)m->addr > (curstart + 
>+				if ((unsigned long)vms->addr > (curstart + 
> 								cursize))
> 					break;
>-				vmstart = (curstart < (unsigned long)m->addr ? 
>-					(unsigned long)m->addr : curstart);
>-				if (((unsigned long)m->addr + msize) > 
>-							(curstart + cursize))
>-					vmsize = curstart + cursize - vmstart;
>+				if (curstart < (unsigned long)vms->addr)
>+					vmstart = (unsigned long)vms->addr;
> 				else
>-					vmsize = (unsigned long)m->addr + 
>-							msize - vmstart;
>+					vmstart = curstart;
>+				curend = curstart + cursize;
>+				vmend = (unsigned long)vms->addr + msize;
>+				if (vmend > curend)
>+					vmsize = curend - vmstart;
>+				else
>+					vmsize = vmend - vmstart;
> 				curstart = vmstart + vmsize;
> 				cursize -= vmsize;
> 				/* don't dump ioremap'd stuff! (TA) */
>-				if (m->flags & VM_IOREMAP)
>+				if (vms->flags & VM_IOREMAP)
> 					continue;
> 				memcpy(elf_buf + (vmstart - start),
> 					(char *)vmstart, vmsize);
>Index: mmotm-2.6.31-Jul16/include/linux/proc_fs.h
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/include/linux/proc_fs.h
>+++ mmotm-2.6.31-Jul16/include/linux/proc_fs.h
>@@ -79,7 +79,7 @@ struct proc_dir_entry {
> };
> 
> struct kcore_list {
>-	struct kcore_list *next;
>+	struct list_head list;
> 	unsigned long addr;
> 	size_t size;
> };
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH 2/4] kcore: add kclist type
  2009-07-22  5:08 ` [PATCH 2/4] kcore: add kclist type KAMEZAWA Hiroyuki
@ 2009-07-22  6:00   ` Amerigo Wang
  2009-07-22  6:05     ` KAMEZAWA Hiroyuki
  0 siblings, 1 reply; 14+ messages in thread
From: Amerigo Wang @ 2009-07-22  6:00 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, Jul 22, 2009 at 02:08:13PM +0900, KAMEZAWA Hiroyuki wrote:
>From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>
>Now, kclist_add() only eats start address and size as its arguments.
>Considering to make kclist dynamically reconfigulable, it's necessary
>to know which kclists are for System RAM and whic is not.
>
>This patch add kclist types as
>  KCORE_RAM
>  KCORE_VMALLOC
>  KCORE_TEXT
>  KCORE_OTHER
>
>region for KCORE_RAM will be dynamically updated at memory hotplug.


The idea is good, but will it be used in any of your latter patches?
I don't see it, can you point it out?

Thanks.

Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>


>
>Chnagelog v1->v2
> - no changes.
>
>Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>---
> arch/ia64/mm/init.c       |    7 ++++---
> arch/mips/mm/init.c       |    7 ++++---
> arch/powerpc/mm/init_32.c |    4 ++--
> arch/powerpc/mm/init_64.c |    5 +++--
> arch/sh/mm/init.c         |    4 ++--
> arch/x86/mm/init_32.c     |    4 ++--
> arch/x86/mm/init_64.c     |   11 ++++++-----
> fs/proc/kcore.c           |    3 ++-
> include/linux/proc_fs.h   |   13 +++++++++++--
> 9 files changed, 36 insertions(+), 22 deletions(-)
>
>Index: mmotm-2.6.31-Jul16/include/linux/proc_fs.h
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/include/linux/proc_fs.h
>+++ mmotm-2.6.31-Jul16/include/linux/proc_fs.h
>@@ -78,10 +78,18 @@ struct proc_dir_entry {
> 	struct list_head pde_openers;	/* who did ->open, but not ->release */
> };
> 
>+enum kcore_type {
>+	KCORE_TEXT,
>+	KCORE_VMALLOC,
>+	KCORE_RAM,
>+	KCORE_OTHER,
>+};
>+
> struct kcore_list {
> 	struct list_head list;
> 	unsigned long addr;
> 	size_t size;
>+	int type;
> };
> 
> struct vmcore {
>@@ -233,11 +241,12 @@ static inline void dup_mm_exe_file(struc
> #endif /* CONFIG_PROC_FS */
> 
> #if !defined(CONFIG_PROC_KCORE)
>-static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
>+static inline void
>+kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> {
> }
> #else
>-extern void kclist_add(struct kcore_list *, void *, size_t);
>+extern void kclist_add(struct kcore_list *, void *, size_t, int type);
> #endif
> 
> union proc_op {
>Index: mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/ia64/mm/init.c
>+++ mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
>@@ -639,9 +639,10 @@ mem_init (void)
> 
> 	high_memory = __va(max_low_pfn * PAGE_SIZE);
> 
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE);
>-	kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
>-	kclist_add(&kcore_kernel, _stext, _end - _stext);
>+	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE, KCORE_RAM);
>+	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
>+			VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
>+	kclist_add(&kcore_kernel, _stext, _end - _stext, KCORE_TEXT);
> 
> 	for_each_online_pgdat(pgdat)
> 		if (pgdat->bdata->node_bootmem_map)
>Index: mmotm-2.6.31-Jul16/arch/mips/mm/init.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/mips/mm/init.c
>+++ mmotm-2.6.31-Jul16/arch/mips/mm/init.c
>@@ -409,11 +409,12 @@ void __init mem_init(void)
> 	if ((unsigned long) &_text > (unsigned long) CKSEG0)
> 		/* The -4 is a hack so that user tools don't have to handle
> 		   the overflow.  */
>-		kclist_add(&kcore_kseg0, (void *) CKSEG0, 0x80000000 - 4);
>+		kclist_add(&kcore_kseg0, (void *) CKSEG0,
>+				0x80000000 - 4, KCORE_TEXT);
> #endif
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
>+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
>-		   VMALLOC_END-VMALLOC_START);
>+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
> 	printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
> 	       "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
>Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_32.c
>+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
>@@ -270,11 +270,11 @@ static int __init setup_kcore(void)
> 						size);
> 		}
> 
>-		kclist_add(kcore_mem, __va(base), size);
>+		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
> 	}
> 
> 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
>-		VMALLOC_END-VMALLOC_START);
>+		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
> 	return 0;
> }
>Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_64.c
>+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
>@@ -128,10 +128,11 @@ static int __init setup_kcore(void)
> 		if (!kcore_mem)
> 			panic("%s: kmalloc failed\n", __func__);
> 
>-		kclist_add(kcore_mem, __va(base), size);
>+		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
> 	}
> 
>-	kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
>+	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
>+		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
> 	return 0;
> }
>Index: mmotm-2.6.31-Jul16/arch/sh/mm/init.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/sh/mm/init.c
>+++ mmotm-2.6.31-Jul16/arch/sh/mm/init.c
>@@ -218,9 +218,9 @@ void __init mem_init(void)
> 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> 
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
>+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
>-		   VMALLOC_END - VMALLOC_START);
>+		   VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
> 
> 	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
> 	       "%dk data, %dk init)\n",
>Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_32.c
>+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
>@@ -886,9 +886,9 @@ void __init mem_init(void)
> 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> 
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
>+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
>-		   VMALLOC_END-VMALLOC_START);
>+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
> 	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
> 			"%dk reserved, %dk data, %dk init, %ldk highmem)\n",
>Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_64.c
>+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
>@@ -677,13 +677,14 @@ void __init mem_init(void)
> 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> 
> 	/* Register memory areas for /proc/kcore */
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
>+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
>-		   VMALLOC_END-VMALLOC_START);
>-	kclist_add(&kcore_kernel, &_stext, _end - _stext);
>-	kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN);
>+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
>+	kclist_add(&kcore_kernel, &_stext, _end - _stext, KCORE_TEXT);
>+	kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN,
>+			KCORE_OTHER);
> 	kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
>-				 VSYSCALL_END - VSYSCALL_START);
>+			 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
> 
> 	printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
> 			 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
>Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
>+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
>@@ -62,10 +62,11 @@ static LIST_HEAD(kclist_head);
> static DEFINE_RWLOCK(kclist_lock);
> 
> void
>-kclist_add(struct kcore_list *new, void *addr, size_t size)
>+kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> {
> 	new->addr = (unsigned long)addr;
> 	new->size = size;
>+	new->type = type;
> 
> 	write_lock(&kclist_lock);
> 	list_add_tail(&new->list, &kclist_head);
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH 2/4] kcore: add kclist type
  2009-07-22  6:00   ` Amerigo Wang
@ 2009-07-22  6:05     ` KAMEZAWA Hiroyuki
  0 siblings, 0 replies; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  6:05 UTC (permalink / raw)
  To: Amerigo Wang; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, 22 Jul 2009 14:00:47 +0800
Amerigo Wang <xiyou.wangcong@gmail.com> wrote:

> On Wed, Jul 22, 2009 at 02:08:13PM +0900, KAMEZAWA Hiroyuki wrote:
> >From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> >
> >Now, kclist_add() only eats start address and size as its arguments.
> >Considering to make kclist dynamically reconfigulable, it's necessary
> >to know which kclists are for System RAM and whic is not.
> >
> >This patch add kclist types as
> >  KCORE_RAM
> >  KCORE_VMALLOC
> >  KCORE_TEXT
> >  KCORE_OTHER
> >
> >region for KCORE_RAM will be dynamically updated at memory hotplug.
> 
> 
> The idea is good, but will it be used in any of your latter patches?
> I don't see it, can you point it out?
> 
> Thanks.
> 
In patch [3/4], at rebuilding physical memory information, All KCORE_RAM are
removed and new KCORE_RAM based on new kernel's information are added.

I wonder KCORE_RAM shouldn't have "executable" bit but it's just a nitpick ;)

Thanks,
-Kame



> Reviewed-by: WANG Cong <xiyou.wangcong@gmail.com>
> 
> 
> >
> >Chnagelog v1->v2
> > - no changes.
> >
> >Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> >---
> > arch/ia64/mm/init.c       |    7 ++++---
> > arch/mips/mm/init.c       |    7 ++++---
> > arch/powerpc/mm/init_32.c |    4 ++--
> > arch/powerpc/mm/init_64.c |    5 +++--
> > arch/sh/mm/init.c         |    4 ++--
> > arch/x86/mm/init_32.c     |    4 ++--
> > arch/x86/mm/init_64.c     |   11 ++++++-----
> > fs/proc/kcore.c           |    3 ++-
> > include/linux/proc_fs.h   |   13 +++++++++++--
> > 9 files changed, 36 insertions(+), 22 deletions(-)
> >
> >Index: mmotm-2.6.31-Jul16/include/linux/proc_fs.h
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/include/linux/proc_fs.h
> >+++ mmotm-2.6.31-Jul16/include/linux/proc_fs.h
> >@@ -78,10 +78,18 @@ struct proc_dir_entry {
> > 	struct list_head pde_openers;	/* who did ->open, but not ->release */
> > };
> > 
> >+enum kcore_type {
> >+	KCORE_TEXT,
> >+	KCORE_VMALLOC,
> >+	KCORE_RAM,
> >+	KCORE_OTHER,
> >+};
> >+
> > struct kcore_list {
> > 	struct list_head list;
> > 	unsigned long addr;
> > 	size_t size;
> >+	int type;
> > };
> > 
> > struct vmcore {
> >@@ -233,11 +241,12 @@ static inline void dup_mm_exe_file(struc
> > #endif /* CONFIG_PROC_FS */
> > 
> > #if !defined(CONFIG_PROC_KCORE)
> >-static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
> >+static inline void
> >+kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> > {
> > }
> > #else
> >-extern void kclist_add(struct kcore_list *, void *, size_t);
> >+extern void kclist_add(struct kcore_list *, void *, size_t, int type);
> > #endif
> > 
> > union proc_op {
> >Index: mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/ia64/mm/init.c
> >+++ mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
> >@@ -639,9 +639,10 @@ mem_init (void)
> > 
> > 	high_memory = __va(max_low_pfn * PAGE_SIZE);
> > 
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE);
> >-	kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
> >-	kclist_add(&kcore_kernel, _stext, _end - _stext);
> >+	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE, KCORE_RAM);
> >+	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> >+			VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> >+	kclist_add(&kcore_kernel, _stext, _end - _stext, KCORE_TEXT);
> > 
> > 	for_each_online_pgdat(pgdat)
> > 		if (pgdat->bdata->node_bootmem_map)
> >Index: mmotm-2.6.31-Jul16/arch/mips/mm/init.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/mips/mm/init.c
> >+++ mmotm-2.6.31-Jul16/arch/mips/mm/init.c
> >@@ -409,11 +409,12 @@ void __init mem_init(void)
> > 	if ((unsigned long) &_text > (unsigned long) CKSEG0)
> > 		/* The -4 is a hack so that user tools don't have to handle
> > 		   the overflow.  */
> >-		kclist_add(&kcore_kseg0, (void *) CKSEG0, 0x80000000 - 4);
> >+		kclist_add(&kcore_kseg0, (void *) CKSEG0,
> >+				0x80000000 - 4, KCORE_TEXT);
> > #endif
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
> >+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> >-		   VMALLOC_END-VMALLOC_START);
> >+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> > 	printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
> > 	       "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n",
> >Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_32.c
> >+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
> >@@ -270,11 +270,11 @@ static int __init setup_kcore(void)
> > 						size);
> > 		}
> > 
> >-		kclist_add(kcore_mem, __va(base), size);
> >+		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
> > 	}
> > 
> > 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> >-		VMALLOC_END-VMALLOC_START);
> >+		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> > 	return 0;
> > }
> >Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_64.c
> >+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
> >@@ -128,10 +128,11 @@ static int __init setup_kcore(void)
> > 		if (!kcore_mem)
> > 			panic("%s: kmalloc failed\n", __func__);
> > 
> >-		kclist_add(kcore_mem, __va(base), size);
> >+		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
> > 	}
> > 
> >-	kclist_add(&kcore_vmem, (void *)VMALLOC_START, VMALLOC_END-VMALLOC_START);
> >+	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> >+		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> > 	return 0;
> > }
> >Index: mmotm-2.6.31-Jul16/arch/sh/mm/init.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/sh/mm/init.c
> >+++ mmotm-2.6.31-Jul16/arch/sh/mm/init.c
> >@@ -218,9 +218,9 @@ void __init mem_init(void)
> > 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> > 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> > 
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
> >+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> >-		   VMALLOC_END - VMALLOC_START);
> >+		   VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
> > 
> > 	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
> > 	       "%dk data, %dk init)\n",
> >Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_32.c
> >+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
> >@@ -886,9 +886,9 @@ void __init mem_init(void)
> > 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> > 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> > 
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
> >+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> >-		   VMALLOC_END-VMALLOC_START);
> >+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> > 	printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
> > 			"%dk reserved, %dk data, %dk init, %ldk highmem)\n",
> >Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_64.c
> >+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
> >@@ -677,13 +677,14 @@ void __init mem_init(void)
> > 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> > 
> > 	/* Register memory areas for /proc/kcore */
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
> >+	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> >-		   VMALLOC_END-VMALLOC_START);
> >-	kclist_add(&kcore_kernel, &_stext, _end - _stext);
> >-	kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN);
> >+		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> >+	kclist_add(&kcore_kernel, &_stext, _end - _stext, KCORE_TEXT);
> >+	kclist_add(&kcore_modules, (void *)MODULES_VADDR, MODULES_LEN,
> >+			KCORE_OTHER);
> > 	kclist_add(&kcore_vsyscall, (void *)VSYSCALL_START,
> >-				 VSYSCALL_END - VSYSCALL_START);
> >+			 VSYSCALL_END - VSYSCALL_START, KCORE_OTHER);
> > 
> > 	printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, "
> > 			 "%ldk absent, %ldk reserved, %ldk data, %ldk init)\n",
> >Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
> >+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
> >@@ -62,10 +62,11 @@ static LIST_HEAD(kclist_head);
> > static DEFINE_RWLOCK(kclist_lock);
> > 
> > void
> >-kclist_add(struct kcore_list *new, void *addr, size_t size)
> >+kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
> > {
> > 	new->addr = (unsigned long)addr;
> > 	new->size = size;
> >+	new->type = type;
> > 
> > 	write_lock(&kclist_lock);
> > 	list_add_tail(&new->list, &kclist_head);
> >
> >--
> >To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >Please read the FAQ at  http://www.tux.org/lkml/
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


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

* Re: [PATCH 3/4] kcore: build physical memory direct map information in proper way
  2009-07-22  6:09   ` Amerigo Wang
@ 2009-07-22  6:08     ` KAMEZAWA Hiroyuki
  0 siblings, 0 replies; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  6:08 UTC (permalink / raw)
  To: Amerigo Wang; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, 22 Jul 2009 14:09:00 +0800
Amerigo Wang <xiyou.wangcong@gmail.com> wrote:

> >+static int kcore_update_ram(void)
> >+{
> >+	LIST_HEAD(head);
> >+	struct kcore_list *ent;
> >+	int ret = 0;
> >+
> >+	ent = kmalloc(sizeof(*head), GFP_KERNEL);
> 
yes, of course.

> 
> Shouldn't it be sizeof(*ent)? :)
> 
> 
> >+	if (!ent) {
> >+		ret = -ENOMEM;
> >+		goto unlock_out;
> 
> 
> Where is unlock_out? :)
> 
> 

Hmm...garbage from old patch, sorry.


> >+	}
> >+	ent->addr = __va(0);
> >+	ent->size = max_low_pfn << PAGE_SHIFT;
> >+	ent->type = SYSTEM_RAM;
> 
> 
> Huh? SYSTEM_RAM or KCORE_RAM?
> 
> 

KCORE_RAM ... ah, ok. I tested only on x86-64 and this HIGHMEM is wasn't 
compiled. Very sorry.

I"ll post fixed one soon.

Thanks,
-Kame


> >+	list_add(&ent->list, &head);
> >+	__kcore_update_ram(&head);
> >+	return ret;
> >+}
> >+
> >+#else /* !CONFIG_HIGHMEM */
> >+
> >+static int
> >+kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg)
> >+{
> >+	struct list_head *head = (struct list_head *)arg;
> >+	struct kcore_list *ent;
> >+
> >+	ent = kmalloc(sizeof(*ent), GFP_KERNEL);
> >+	if (!ent)
> >+		return -ENOMEM;
> >+	ent->addr = (unsigned long)__va((pfn << PAGE_SHIFT));
> >+	ent->size = nr_pages << PAGE_SHIFT;
> >+	ent->type = KCORE_RAM;
> >+	list_add(&ent->list, head);
> >+	return 0;
> >+}
> >+
> >+static int kcore_update_ram(void)
> >+{
> >+	int nid, ret;
> >+	unsigned long end_pfn;
> >+	LIST_HEAD(head);
> >+
> >+	/* Not inialized....update now */
> >+	/* find out "max pfn" */
> >+	end_pfn = 0;
> >+	for_each_node_state(nid, N_HIGH_MEMORY)
> >+		if (end_pfn < node_end_pfn(nid))
> >+			end_pfn = node_end_pfn(nid);
> >+	/* scan 0 to max_pfn */
> >+	ret = walk_memory_resource(0, end_pfn, &head, kclist_add_private);
> >+	if (ret) {
> >+		free_kclist_ents(&head);
> >+		return -ENOMEM;
> >+	}
> >+	__kcore_update_ram(&head);
> >+	return ret;
> >+}
> >+#endif /* CONFIG_HIGH_MEM */
> > 
> > /*****************************************************************************/
> > /*
> >@@ -271,6 +362,11 @@ read_kcore(struct file *file, char __use
> > 		read_unlock(&kclist_lock);
> > 		return 0;
> > 	}
> >+	/* memory hotplug ?? */
> >+	if (kcore_need_update) {
> >+		read_unlock(&kclist_lock);
> >+		return -EBUSY;
> >+	}
> > 
> > 	/* trim buflen to not go beyond EOF */
> > 	if (buflen > size - *fpos)
> >@@ -406,9 +502,42 @@ read_kcore(struct file *file, char __use
> > 	return acc;
> > }
> > 
> >+static int open_kcore(struct inode * inode, struct file *filp)
> >+{
> >+	if (!capable(CAP_SYS_RAWIO))
> >+		return -EPERM;
> >+	if (kcore_need_update)
> >+		kcore_update_ram();
> >+	return 0;
> >+}
> >+
> >+
> >+static const struct file_operations proc_kcore_operations = {
> >+	.read		= read_kcore,
> >+	.open		= open_kcore,
> >+};
> >+
> >+/* just remember that we have to update kcore */
> >+static int __meminit kcore_callback(struct notifier_block *self,
> >+				    unsigned long action, void *arg)
> >+{
> >+	switch (action) {
> >+	case MEM_ONLINE:
> >+	case MEM_OFFLINE:
> >+		write_lock(&kclist_lock);
> >+		kcore_need_update = 1;
> >+		write_unlock(&kclist_lock);
> >+	}
> >+	return NOTIFY_OK;
> >+}
> >+
> >+
> > static int __init proc_kcore_init(void)
> > {
> > 	proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
> >+	kcore_update_ram();
> >+	hotplug_memory_notifier(kcore_callback, 0);
> > 	return 0;
> > }
> > module_init(proc_kcore_init);
> >+
> >Index: mmotm-2.6.31-Jul16/include/linux/ioport.h
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/include/linux/ioport.h
> >+++ mmotm-2.6.31-Jul16/include/linux/ioport.h
> >@@ -186,5 +186,13 @@ extern void __devm_release_region(struct
> > extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size);
> > extern int iomem_is_exclusive(u64 addr);
> > 
> >+/*
> >+ * Walk through all SYSTEM_RAM which is registered as resource.
> >+ * arg is (start_pfn, nr_pages, private_arg_pointer)
> >+ */
> >+extern int walk_memory_resource(unsigned long start_pfn,
> >+			unsigned long nr_pages, void *arg,
> >+			int (*func)(unsigned long, unsigned long, void *));
> >+
> > #endif /* __ASSEMBLY__ */
> > #endif	/* _LINUX_IOPORT_H */
> >Index: mmotm-2.6.31-Jul16/include/linux/memory_hotplug.h
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/include/linux/memory_hotplug.h
> >+++ mmotm-2.6.31-Jul16/include/linux/memory_hotplug.h
> >@@ -191,13 +191,6 @@ static inline void register_page_bootmem
> > 
> > #endif /* ! CONFIG_MEMORY_HOTPLUG */
> > 
> >-/*
> >- * Walk through all memory which is registered as resource.
> >- * arg is (start_pfn, nr_pages, private_arg_pointer)
> >- */
> >-extern int walk_memory_resource(unsigned long start_pfn,
> >-			unsigned long nr_pages, void *arg,
> >-			int (*func)(unsigned long, unsigned long, void *));
> > 
> > #ifdef CONFIG_MEMORY_HOTREMOVE
> > 
> >Index: mmotm-2.6.31-Jul16/kernel/resource.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
> >+++ mmotm-2.6.31-Jul16/kernel/resource.c
> >@@ -234,7 +234,7 @@ int release_resource(struct resource *ol
> > 
> > EXPORT_SYMBOL(release_resource);
> > 
> >-#if defined(CONFIG_MEMORY_HOTPLUG) && !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
> >+#if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
> > /*
> >  * Finds the lowest memory reosurce exists within [res->start.res->end)
> >  * the caller must specify res->start, res->end, res->flags.
> >Index: mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/ia64/mm/init.c
> >+++ mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
> >@@ -639,7 +639,6 @@ mem_init (void)
> > 
> > 	high_memory = __va(max_low_pfn * PAGE_SIZE);
> > 
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE, KCORE_RAM);
> > 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> > 			VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 	kclist_add(&kcore_kernel, _stext, _end - _stext, KCORE_TEXT);
> >Index: mmotm-2.6.31-Jul16/arch/mips/mm/init.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/mips/mm/init.c
> >+++ mmotm-2.6.31-Jul16/arch/mips/mm/init.c
> >@@ -412,7 +412,6 @@ void __init mem_init(void)
> > 		kclist_add(&kcore_kseg0, (void *) CKSEG0,
> > 				0x80000000 - 4, KCORE_TEXT);
> > #endif
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> > 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> >Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_32.c
> >+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
> >@@ -249,30 +249,6 @@ static struct kcore_list kcore_vmem;
> > 
> > static int __init setup_kcore(void)
> > {
> >-	int i;
> >-
> >-	for (i = 0; i < lmb.memory.cnt; i++) {
> >-		unsigned long base;
> >-		unsigned long size;
> >-		struct kcore_list *kcore_mem;
> >-
> >-		base = lmb.memory.region[i].base;
> >-		size = lmb.memory.region[i].size;
> >-
> >-		kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
> >-		if (!kcore_mem)
> >-			panic("%s: kmalloc failed\n", __func__);
> >-
> >-		/* must stay under 32 bits */
> >-		if ( 0xfffffffful - (unsigned long)__va(base) < size) {
> >-			size = 0xfffffffful - (unsigned long)(__va(base));
> >-			printk(KERN_DEBUG "setup_kcore: restrict size=%lx\n",
> >-						size);
> >-		}
> >-
> >-		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
> >-	}
> >-
> > 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> > 		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> >Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_64.c
> >+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
> >@@ -114,23 +114,6 @@ static struct kcore_list kcore_vmem;
> > 
> > static int __init setup_kcore(void)
> > {
> >-	int i;
> >-
> >-	for (i=0; i < lmb.memory.cnt; i++) {
> >-		unsigned long base, size;
> >-		struct kcore_list *kcore_mem;
> >-
> >-		base = lmb.memory.region[i].base;
> >-		size = lmb.memory.region[i].size;
> >-
> >-		/* GFP_ATOMIC to avoid might_sleep warnings during boot */
> >-		kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
> >-		if (!kcore_mem)
> >-			panic("%s: kmalloc failed\n", __func__);
> >-
> >-		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
> >-	}
> >-
> > 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> > 		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> >Index: mmotm-2.6.31-Jul16/arch/sh/mm/init.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/sh/mm/init.c
> >+++ mmotm-2.6.31-Jul16/arch/sh/mm/init.c
> >@@ -218,7 +218,6 @@ void __init mem_init(void)
> > 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> > 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> > 
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> > 		   VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
> > 
> >Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_32.c
> >+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
> >@@ -886,7 +886,6 @@ void __init mem_init(void)
> > 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> > 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> > 
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> > 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 
> >Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_64.c
> >+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
> >@@ -677,7 +677,6 @@ void __init mem_init(void)
> > 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> > 
> > 	/* Register memory areas for /proc/kcore */
> >-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> > 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> > 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> > 	kclist_add(&kcore_kernel, &_stext, _end - _stext, KCORE_TEXT);
> >
> >--
> >To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >Please read the FAQ at  http://www.tux.org/lkml/
> 


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

* Re: [PATCH 3/4] kcore: build physical memory direct map information in proper way
  2009-07-22  5:10 ` [PATCH 3/4] kcore: build physical memory direct map information in proper way KAMEZAWA Hiroyuki
@ 2009-07-22  6:09   ` Amerigo Wang
  2009-07-22  6:08     ` KAMEZAWA Hiroyuki
  0 siblings, 1 reply; 14+ messages in thread
From: Amerigo Wang @ 2009-07-22  6:09 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, Jul 22, 2009 at 02:10:24PM +0900, KAMEZAWA Hiroyuki wrote:
>From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>
>For /proc/kcore, each arch registers its memory range by kclist_add().
>In usual,
>	- range of physical memory
>	- range of vmalloc area
>	- text, etc...
>are registered but "range of physical memory" has some troubles.
>It doesn't updated at memory hotplug and it tend to include
>unnecessary memory holes. Now, /proc/iomem (kernel/resource.c)
>includes required physical memory range information and it's
>properly updated at memory hotplug. Then, it's good to avoid
>using its own code(duplicating information) and to rebuild
>kclist for physical memory based on /proc/iomem.
>


Please see my comments below.


>Note: walk_memory_resource() works based on lmb inforamtion in PPC
>but no problem. It's updated at memory hotplug.
>
>Changelog: v1 -> v2
> - removed -EBUSY at memory hotplug in read_kcore()
>   (continue reading is no problem in general.)
> - fixed initial value of kcore_need_update to be 1.
>
>Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>---
> arch/ia64/mm/init.c            |    1 
> arch/mips/mm/init.c            |    1 
> arch/powerpc/mm/init_32.c      |   24 ------
> arch/powerpc/mm/init_64.c      |   17 ----
> arch/sh/mm/init.c              |    1 
> arch/x86/mm/init_32.c          |    1 
> arch/x86/mm/init_64.c          |    1 
> fs/proc/kcore.c                |  151 ++++++++++++++++++++++++++++++++++++++---
> include/linux/ioport.h         |    8 ++
> include/linux/memory_hotplug.h |    7 -
> kernel/resource.c              |    2 
> 11 files changed, 149 insertions(+), 65 deletions(-)
>
>Index: mmotm-2.6.31-Jul16/fs/proc/kcore.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/fs/proc/kcore.c
>+++ mmotm-2.6.31-Jul16/fs/proc/kcore.c
>@@ -21,6 +21,9 @@
> #include <asm/uaccess.h>
> #include <asm/io.h>
> #include <linux/list.h>
>+#include <linux/ioport.h>
>+#include <linux/memory_hotplug.h>
>+#include <linux/memory.h>
> 
> #define CORE_STR "CORE"
> 
>@@ -30,17 +33,6 @@
> 
> static struct proc_dir_entry *proc_root_kcore;
> 
>-static int open_kcore(struct inode * inode, struct file * filp)
>-{
>-	return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
>-}
>-
>-static ssize_t read_kcore(struct file *, char __user *, size_t, loff_t *);
>-
>-static const struct file_operations proc_kcore_operations = {
>-	.read		= read_kcore,
>-	.open		= open_kcore,
>-};
> 
> #ifndef kc_vaddr_to_offset
> #define	kc_vaddr_to_offset(v) ((v) - PAGE_OFFSET)
>@@ -60,6 +52,7 @@ struct memelfnote
> 
> static LIST_HEAD(kclist_head);
> static DEFINE_RWLOCK(kclist_lock);
>+static int kcore_need_update = 1;
> 
> void
> kclist_add(struct kcore_list *new, void *addr, size_t size, int type)
>@@ -98,6 +91,104 @@ static size_t get_kcore_size(int *nphdr,
> 	return size + *elf_buflen;
> }
> 
>+static void free_kclist_ents(struct list_head *head)
>+{
>+	struct kcore_list *tmp, *pos;
>+
>+	list_for_each_entry_safe(pos, tmp, head, list) {
>+		list_del(&pos->list);
>+		kfree(pos);
>+	}
>+}
>+/*
>+ * Replace all KCORE_RAM information with passed list.
>+ */
>+static void __kcore_update_ram(struct list_head *list)
>+{
>+	struct kcore_list *tmp, *pos;
>+	LIST_HEAD(garbage);
>+
>+	write_lock(&kclist_lock);
>+	if (kcore_need_update) {
>+		list_for_each_entry_safe(pos, tmp, &kclist_head, list) {
>+			if (pos->type == KCORE_RAM)
>+				list_move(&pos->list, &garbage);
>+		}
>+		list_splice(list, &kclist_head);
>+	} else
>+		list_splice(list, &garbage);
>+	kcore_need_update = 0;
>+	write_unlock(&kclist_lock);
>+
>+	free_kclist_ents(&garbage);
>+}
>+
>+
>+#ifdef CONFIG_HIGHMEM
>+/*
>+ * If no highmem, we can assume [0...max_low_pfn) continuous range of memory
>+ * because memory hole is not as big as !HIGHMEM case.
>+ * (HIGHMEM is special because part of memory is _invisible_ from the kernel.)
>+ */
>+static int kcore_update_ram(void)
>+{
>+	LIST_HEAD(head);
>+	struct kcore_list *ent;
>+	int ret = 0;
>+
>+	ent = kmalloc(sizeof(*head), GFP_KERNEL);


Shouldn't it be sizeof(*ent)? :)


>+	if (!ent) {
>+		ret = -ENOMEM;
>+		goto unlock_out;


Where is unlock_out? :)


>+	}
>+	ent->addr = __va(0);
>+	ent->size = max_low_pfn << PAGE_SHIFT;
>+	ent->type = SYSTEM_RAM;


Huh? SYSTEM_RAM or KCORE_RAM?


>+	list_add(&ent->list, &head);
>+	__kcore_update_ram(&head);
>+	return ret;
>+}
>+
>+#else /* !CONFIG_HIGHMEM */
>+
>+static int
>+kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg)
>+{
>+	struct list_head *head = (struct list_head *)arg;
>+	struct kcore_list *ent;
>+
>+	ent = kmalloc(sizeof(*ent), GFP_KERNEL);
>+	if (!ent)
>+		return -ENOMEM;
>+	ent->addr = (unsigned long)__va((pfn << PAGE_SHIFT));
>+	ent->size = nr_pages << PAGE_SHIFT;
>+	ent->type = KCORE_RAM;
>+	list_add(&ent->list, head);
>+	return 0;
>+}
>+
>+static int kcore_update_ram(void)
>+{
>+	int nid, ret;
>+	unsigned long end_pfn;
>+	LIST_HEAD(head);
>+
>+	/* Not inialized....update now */
>+	/* find out "max pfn" */
>+	end_pfn = 0;
>+	for_each_node_state(nid, N_HIGH_MEMORY)
>+		if (end_pfn < node_end_pfn(nid))
>+			end_pfn = node_end_pfn(nid);
>+	/* scan 0 to max_pfn */
>+	ret = walk_memory_resource(0, end_pfn, &head, kclist_add_private);
>+	if (ret) {
>+		free_kclist_ents(&head);
>+		return -ENOMEM;
>+	}
>+	__kcore_update_ram(&head);
>+	return ret;
>+}
>+#endif /* CONFIG_HIGH_MEM */
> 
> /*****************************************************************************/
> /*
>@@ -271,6 +362,11 @@ read_kcore(struct file *file, char __use
> 		read_unlock(&kclist_lock);
> 		return 0;
> 	}
>+	/* memory hotplug ?? */
>+	if (kcore_need_update) {
>+		read_unlock(&kclist_lock);
>+		return -EBUSY;
>+	}
> 
> 	/* trim buflen to not go beyond EOF */
> 	if (buflen > size - *fpos)
>@@ -406,9 +502,42 @@ read_kcore(struct file *file, char __use
> 	return acc;
> }
> 
>+static int open_kcore(struct inode * inode, struct file *filp)
>+{
>+	if (!capable(CAP_SYS_RAWIO))
>+		return -EPERM;
>+	if (kcore_need_update)
>+		kcore_update_ram();
>+	return 0;
>+}
>+
>+
>+static const struct file_operations proc_kcore_operations = {
>+	.read		= read_kcore,
>+	.open		= open_kcore,
>+};
>+
>+/* just remember that we have to update kcore */
>+static int __meminit kcore_callback(struct notifier_block *self,
>+				    unsigned long action, void *arg)
>+{
>+	switch (action) {
>+	case MEM_ONLINE:
>+	case MEM_OFFLINE:
>+		write_lock(&kclist_lock);
>+		kcore_need_update = 1;
>+		write_unlock(&kclist_lock);
>+	}
>+	return NOTIFY_OK;
>+}
>+
>+
> static int __init proc_kcore_init(void)
> {
> 	proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
>+	kcore_update_ram();
>+	hotplug_memory_notifier(kcore_callback, 0);
> 	return 0;
> }
> module_init(proc_kcore_init);
>+
>Index: mmotm-2.6.31-Jul16/include/linux/ioport.h
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/include/linux/ioport.h
>+++ mmotm-2.6.31-Jul16/include/linux/ioport.h
>@@ -186,5 +186,13 @@ extern void __devm_release_region(struct
> extern int iomem_map_sanity_check(resource_size_t addr, unsigned long size);
> extern int iomem_is_exclusive(u64 addr);
> 
>+/*
>+ * Walk through all SYSTEM_RAM which is registered as resource.
>+ * arg is (start_pfn, nr_pages, private_arg_pointer)
>+ */
>+extern int walk_memory_resource(unsigned long start_pfn,
>+			unsigned long nr_pages, void *arg,
>+			int (*func)(unsigned long, unsigned long, void *));
>+
> #endif /* __ASSEMBLY__ */
> #endif	/* _LINUX_IOPORT_H */
>Index: mmotm-2.6.31-Jul16/include/linux/memory_hotplug.h
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/include/linux/memory_hotplug.h
>+++ mmotm-2.6.31-Jul16/include/linux/memory_hotplug.h
>@@ -191,13 +191,6 @@ static inline void register_page_bootmem
> 
> #endif /* ! CONFIG_MEMORY_HOTPLUG */
> 
>-/*
>- * Walk through all memory which is registered as resource.
>- * arg is (start_pfn, nr_pages, private_arg_pointer)
>- */
>-extern int walk_memory_resource(unsigned long start_pfn,
>-			unsigned long nr_pages, void *arg,
>-			int (*func)(unsigned long, unsigned long, void *));
> 
> #ifdef CONFIG_MEMORY_HOTREMOVE
> 
>Index: mmotm-2.6.31-Jul16/kernel/resource.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
>+++ mmotm-2.6.31-Jul16/kernel/resource.c
>@@ -234,7 +234,7 @@ int release_resource(struct resource *ol
> 
> EXPORT_SYMBOL(release_resource);
> 
>-#if defined(CONFIG_MEMORY_HOTPLUG) && !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
>+#if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
> /*
>  * Finds the lowest memory reosurce exists within [res->start.res->end)
>  * the caller must specify res->start, res->end, res->flags.
>Index: mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/ia64/mm/init.c
>+++ mmotm-2.6.31-Jul16/arch/ia64/mm/init.c
>@@ -639,7 +639,6 @@ mem_init (void)
> 
> 	high_memory = __va(max_low_pfn * PAGE_SIZE);
> 
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn * PAGE_SIZE, KCORE_RAM);
> 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> 			VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 	kclist_add(&kcore_kernel, _stext, _end - _stext, KCORE_TEXT);
>Index: mmotm-2.6.31-Jul16/arch/mips/mm/init.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/mips/mm/init.c
>+++ mmotm-2.6.31-Jul16/arch/mips/mm/init.c
>@@ -412,7 +412,6 @@ void __init mem_init(void)
> 		kclist_add(&kcore_kseg0, (void *) CKSEG0,
> 				0x80000000 - 4, KCORE_TEXT);
> #endif
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
>Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_32.c
>+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_32.c
>@@ -249,30 +249,6 @@ static struct kcore_list kcore_vmem;
> 
> static int __init setup_kcore(void)
> {
>-	int i;
>-
>-	for (i = 0; i < lmb.memory.cnt; i++) {
>-		unsigned long base;
>-		unsigned long size;
>-		struct kcore_list *kcore_mem;
>-
>-		base = lmb.memory.region[i].base;
>-		size = lmb.memory.region[i].size;
>-
>-		kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
>-		if (!kcore_mem)
>-			panic("%s: kmalloc failed\n", __func__);
>-
>-		/* must stay under 32 bits */
>-		if ( 0xfffffffful - (unsigned long)__va(base) < size) {
>-			size = 0xfffffffful - (unsigned long)(__va(base));
>-			printk(KERN_DEBUG "setup_kcore: restrict size=%lx\n",
>-						size);
>-		}
>-
>-		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
>-	}
>-
> 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> 		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
>Index: mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/powerpc/mm/init_64.c
>+++ mmotm-2.6.31-Jul16/arch/powerpc/mm/init_64.c
>@@ -114,23 +114,6 @@ static struct kcore_list kcore_vmem;
> 
> static int __init setup_kcore(void)
> {
>-	int i;
>-
>-	for (i=0; i < lmb.memory.cnt; i++) {
>-		unsigned long base, size;
>-		struct kcore_list *kcore_mem;
>-
>-		base = lmb.memory.region[i].base;
>-		size = lmb.memory.region[i].size;
>-
>-		/* GFP_ATOMIC to avoid might_sleep warnings during boot */
>-		kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
>-		if (!kcore_mem)
>-			panic("%s: kmalloc failed\n", __func__);
>-
>-		kclist_add(kcore_mem, __va(base), size, KCORE_RAM);
>-	}
>-
> 	kclist_add(&kcore_vmem, (void *)VMALLOC_START,
> 		VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
>Index: mmotm-2.6.31-Jul16/arch/sh/mm/init.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/sh/mm/init.c
>+++ mmotm-2.6.31-Jul16/arch/sh/mm/init.c
>@@ -218,7 +218,6 @@ void __init mem_init(void)
> 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> 
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> 		   VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
> 
>Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_32.c
>+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_32.c
>@@ -886,7 +886,6 @@ void __init mem_init(void)
> 	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
> 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> 
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 
>Index: mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/arch/x86/mm/init_64.c
>+++ mmotm-2.6.31-Jul16/arch/x86/mm/init_64.c
>@@ -677,7 +677,6 @@ void __init mem_init(void)
> 	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
> 
> 	/* Register memory areas for /proc/kcore */
>-	kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT, KCORE_RAM);
> 	kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
> 		   VMALLOC_END-VMALLOC_START, KCORE_VMALLOC);
> 	kclist_add(&kcore_kernel, &_stext, _end - _stext, KCORE_TEXT);
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH 4/4] kcore: remove noise from walk_memory_resource
  2009-07-22  5:12 ` [PATCH 4/4] kcore: remove noise from walk_memory_resource KAMEZAWA Hiroyuki
@ 2009-07-22  6:21   ` Amerigo Wang
  2009-07-22  6:22     ` KAMEZAWA Hiroyuki
  0 siblings, 1 reply; 14+ messages in thread
From: Amerigo Wang @ 2009-07-22  6:21 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, Jul 22, 2009 at 02:12:27PM +0900, KAMEZAWA Hiroyuki wrote:
>From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>
>Originally, walk_memory_resource() was introduced to traverse all memory
>of "System RAM" for detecting memory hotplug/unplug range.
>For doing so, flags of IORESOUCE_MEM|IORESOURCE_BUSY was used and this
>was enough for memory hotplug because scanning range was controlled properly.
>
>But for using other purpose, /proc/kcore, this may includes some firmware
>area marked as IORESOURCE_BUSY | IORESOUCE_MEM. This patch makes the check
>strict to find out busy "System RAM".
>
>Note: PPC64 keeps their own walk_memory_resouce(), which walk through
>ppc64's lmb informaton. Because old kclist_add() is called per lmb,
>this patch makes no difference in behavior, finally.
>
>Changelog v2:
> - new patch from v2.
>
>Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>---
> kernel/resource.c |   18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
>
>Index: mmotm-2.6.31-Jul16/kernel/resource.c
>===================================================================
>--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
>+++ mmotm-2.6.31-Jul16/kernel/resource.c
>@@ -237,10 +237,10 @@ EXPORT_SYMBOL(release_resource);
> #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
> /*
>  * Finds the lowest memory reosurce exists within [res->start.res->end)
>- * the caller must specify res->start, res->end, res->flags.
>+ * the caller must specify res->start, res->end, res->flags and "name".
>  * If found, returns 0, res is overwritten, if not found, returns -1.
>  */
>-static int find_next_system_ram(struct resource *res)
>+static int find_next_system_ram(struct resource *res, char *name)
> {
> 	resource_size_t start, end;
> 	struct resource *p;
>@@ -256,6 +256,8 @@ static int find_next_system_ram(struct r
> 		/* system ram is just marked as IORESOURCE_MEM */
> 		if (p->flags != res->flags)
> 			continue;
>+		if (name && strcmp(p->name, name))
>+			continue;
> 		if (p->start > end) {
> 			p = NULL;
> 			break;
>@@ -273,19 +275,27 @@ static int find_next_system_ram(struct r
> 		res->end = p->end;
> 	return 0;
> }
>+
>+/*
>+ * This function calls callback against all memory range of "System RAM"
>+ * which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
>+ * Now, this function is only for "System RAM".


Then we should change its name, shouldn't we? :)

>+ */
> int
> walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg,
>-			int (*func)(unsigned long, unsigned long, void *))
>+		int (*func)(unsigned long, unsigned long, void *))


This line is a trivial change, I don't want to see it mixed with
the rest...


> {
> 	struct resource res;
> 	unsigned long pfn, len;
> 	u64 orig_end;
> 	int ret = -1;
>+
> 	res.start = (u64) start_pfn << PAGE_SHIFT;
> 	res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
> 	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
> 	orig_end = res.end;
>-	while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
>+	while ((res.start < res.end) &&
>+		(find_next_system_ram(&res, "System RAM") >= 0)) {
> 		pfn = (unsigned long)(res.start >> PAGE_SHIFT);
> 		len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT);
> 		ret = (*func)(pfn, len, arg);
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH 4/4] kcore: remove noise from walk_memory_resource
  2009-07-22  6:21   ` Amerigo Wang
@ 2009-07-22  6:22     ` KAMEZAWA Hiroyuki
  2009-07-22  6:29       ` Amerigo Wang
  0 siblings, 1 reply; 14+ messages in thread
From: KAMEZAWA Hiroyuki @ 2009-07-22  6:22 UTC (permalink / raw)
  To: Amerigo Wang; +Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org

On Wed, 22 Jul 2009 14:21:03 +0800
Amerigo Wang <xiyou.wangcong@gmail.com> wrote:

> On Wed, Jul 22, 2009 at 02:12:27PM +0900, KAMEZAWA Hiroyuki wrote:
> >From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> >
> >Originally, walk_memory_resource() was introduced to traverse all memory
> >of "System RAM" for detecting memory hotplug/unplug range.
> >For doing so, flags of IORESOUCE_MEM|IORESOURCE_BUSY was used and this
> >was enough for memory hotplug because scanning range was controlled properly.
> >
> >But for using other purpose, /proc/kcore, this may includes some firmware
> >area marked as IORESOURCE_BUSY | IORESOUCE_MEM. This patch makes the check
> >strict to find out busy "System RAM".
> >
> >Note: PPC64 keeps their own walk_memory_resouce(), which walk through
> >ppc64's lmb informaton. Because old kclist_add() is called per lmb,
> >this patch makes no difference in behavior, finally.
> >
> >Changelog v2:
> > - new patch from v2.
> >
> >Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> >---
> > kernel/resource.c |   18 ++++++++++++++----
> > 1 file changed, 14 insertions(+), 4 deletions(-)
> >
> >Index: mmotm-2.6.31-Jul16/kernel/resource.c
> >===================================================================
> >--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
> >+++ mmotm-2.6.31-Jul16/kernel/resource.c
> >@@ -237,10 +237,10 @@ EXPORT_SYMBOL(release_resource);
> > #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
> > /*
> >  * Finds the lowest memory reosurce exists within [res->start.res->end)
> >- * the caller must specify res->start, res->end, res->flags.
> >+ * the caller must specify res->start, res->end, res->flags and "name".
> >  * If found, returns 0, res is overwritten, if not found, returns -1.
> >  */
> >-static int find_next_system_ram(struct resource *res)
> >+static int find_next_system_ram(struct resource *res, char *name)
> > {
> > 	resource_size_t start, end;
> > 	struct resource *p;
> >@@ -256,6 +256,8 @@ static int find_next_system_ram(struct r
> > 		/* system ram is just marked as IORESOURCE_MEM */
> > 		if (p->flags != res->flags)
> > 			continue;
> >+		if (name && strcmp(p->name, name))
> >+			continue;
> > 		if (p->start > end) {
> > 			p = NULL;
> > 			break;
> >@@ -273,19 +275,27 @@ static int find_next_system_ram(struct r
> > 		res->end = p->end;
> > 	return 0;
> > }
> >+
> >+/*
> >+ * This function calls callback against all memory range of "System RAM"
> >+ * which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
> >+ * Now, this function is only for "System RAM".
> 
> 
> Then we should change its name, shouldn't we? :)
> 
I tried, but not changed in this version bacause the usage/purpose is not changed.

Hmm, How about walk_system_ram_range() ?


> >+ */
> > int
> > walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg,
> >-			int (*func)(unsigned long, unsigned long, void *))
> >+		int (*func)(unsigned long, unsigned long, void *))
> 
> 
> This line is a trivial change, I don't want to see it mixed with
> the rest...
Sorry, this was from a trial I tried to change the name ;) I'll remove this.

I'll post v3 but wait for a day to hear other comments.

Thank you for review.

Regards,
-Kame

> 
> 
> > {
> > 	struct resource res;
> > 	unsigned long pfn, len;
> > 	u64 orig_end;
> > 	int ret = -1;
> >+
> > 	res.start = (u64) start_pfn << PAGE_SHIFT;
> > 	res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
> > 	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
> > 	orig_end = res.end;
> >-	while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
> >+	while ((res.start < res.end) &&
> >+		(find_next_system_ram(&res, "System RAM") >= 0)) {
> > 		pfn = (unsigned long)(res.start >> PAGE_SHIFT);
> > 		len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT);
> > 		ret = (*func)(pfn, len, arg);
> >
> >--
> >To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >Please read the FAQ at  http://www.tux.org/lkml/
> 


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

* Re: [PATCH 4/4] kcore: remove noise from walk_memory_resource
  2009-07-22  6:22     ` KAMEZAWA Hiroyuki
@ 2009-07-22  6:29       ` Amerigo Wang
  0 siblings, 0 replies; 14+ messages in thread
From: Amerigo Wang @ 2009-07-22  6:29 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki
  Cc: Amerigo Wang, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org

On Wed, Jul 22, 2009 at 03:22:38PM +0900, KAMEZAWA Hiroyuki wrote:
>On Wed, 22 Jul 2009 14:21:03 +0800
>Amerigo Wang <xiyou.wangcong@gmail.com> wrote:
>
>> On Wed, Jul 22, 2009 at 02:12:27PM +0900, KAMEZAWA Hiroyuki wrote:
>> >From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>> >
>> >Originally, walk_memory_resource() was introduced to traverse all memory
>> >of "System RAM" for detecting memory hotplug/unplug range.
>> >For doing so, flags of IORESOUCE_MEM|IORESOURCE_BUSY was used and this
>> >was enough for memory hotplug because scanning range was controlled properly.
>> >
>> >But for using other purpose, /proc/kcore, this may includes some firmware
>> >area marked as IORESOURCE_BUSY | IORESOUCE_MEM. This patch makes the check
>> >strict to find out busy "System RAM".
>> >
>> >Note: PPC64 keeps their own walk_memory_resouce(), which walk through
>> >ppc64's lmb informaton. Because old kclist_add() is called per lmb,
>> >this patch makes no difference in behavior, finally.
>> >
>> >Changelog v2:
>> > - new patch from v2.
>> >
>> >Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
>> >---
>> > kernel/resource.c |   18 ++++++++++++++----
>> > 1 file changed, 14 insertions(+), 4 deletions(-)
>> >
>> >Index: mmotm-2.6.31-Jul16/kernel/resource.c
>> >===================================================================
>> >--- mmotm-2.6.31-Jul16.orig/kernel/resource.c
>> >+++ mmotm-2.6.31-Jul16/kernel/resource.c
>> >@@ -237,10 +237,10 @@ EXPORT_SYMBOL(release_resource);
>> > #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY)
>> > /*
>> >  * Finds the lowest memory reosurce exists within [res->start.res->end)
>> >- * the caller must specify res->start, res->end, res->flags.
>> >+ * the caller must specify res->start, res->end, res->flags and "name".
>> >  * If found, returns 0, res is overwritten, if not found, returns -1.
>> >  */
>> >-static int find_next_system_ram(struct resource *res)
>> >+static int find_next_system_ram(struct resource *res, char *name)
>> > {
>> > 	resource_size_t start, end;
>> > 	struct resource *p;
>> >@@ -256,6 +256,8 @@ static int find_next_system_ram(struct r
>> > 		/* system ram is just marked as IORESOURCE_MEM */
>> > 		if (p->flags != res->flags)
>> > 			continue;
>> >+		if (name && strcmp(p->name, name))
>> >+			continue;
>> > 		if (p->start > end) {
>> > 			p = NULL;
>> > 			break;
>> >@@ -273,19 +275,27 @@ static int find_next_system_ram(struct r
>> > 		res->end = p->end;
>> > 	return 0;
>> > }
>> >+
>> >+/*
>> >+ * This function calls callback against all memory range of "System RAM"
>> >+ * which are marked as IORESOURCE_MEM and IORESOUCE_BUSY.
>> >+ * Now, this function is only for "System RAM".
>> 
>> 
>> Then we should change its name, shouldn't we? :)
>> 
>I tried, but not changed in this version bacause the usage/purpose is not changed.
>
>Hmm, How about walk_system_ram_range() ?


Fine for me.

Thank you.

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

end of thread, other threads:[~2009-07-22  6:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-22  5:06 [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 KAMEZAWA Hiroyuki
2009-07-22  5:07 ` [PATCH 1/4] kcore: clean up to use generic list ops KAMEZAWA Hiroyuki
2009-07-22  5:53   ` Amerigo Wang
2009-07-22  5:08 ` [PATCH 2/4] kcore: add kclist type KAMEZAWA Hiroyuki
2009-07-22  6:00   ` Amerigo Wang
2009-07-22  6:05     ` KAMEZAWA Hiroyuki
2009-07-22  5:10 ` [PATCH 3/4] kcore: build physical memory direct map information in proper way KAMEZAWA Hiroyuki
2009-07-22  6:09   ` Amerigo Wang
2009-07-22  6:08     ` KAMEZAWA Hiroyuki
2009-07-22  5:12 ` [PATCH 4/4] kcore: remove noise from walk_memory_resource KAMEZAWA Hiroyuki
2009-07-22  6:21   ` Amerigo Wang
2009-07-22  6:22     ` KAMEZAWA Hiroyuki
2009-07-22  6:29       ` Amerigo Wang
2009-07-22  5:52 ` [PATCH 0/4] kcore: cleanup and fix bahavior to find physcal memory range v2 Amerigo Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox