Skip to contentSkip to conversation

How to represent SYSTEM_RAM in kerenel/resouce.c

Question In review KAMEZAWA Hiroyuki 5 participants 8 messages Oct 3, 2007 – Nov 6, 2007 Memory management

lore
Share & tools
lore
#0 lore raw

Hi,

Now, SYSTEM_RAM is registerd to resouce list and a user can see memory map from /proc/iomem, like following.
==
[kamezawa@drpq linux-2.6.23-rc8-mm2]$ grep RAM /proc/iomem 00000000-0009ffff : System RAM
00100000-03ffffff : System RAM
04000000-04f1bfff : System RAM
04f1c000-6b4b9fff : System RAM
6b4ba000-6b797fff : System RAM
6b798000-6b799fff : System RAM
6b79a000-6b79dfff : System RAM
6b79e000-6b79efff : System RAM
6b79f000-6b7fbfff : System RAM
6b7fc000-6c629fff : System RAM
6c62a000-6c800fff : System RAM
6c801000-6c843fff : System RAM
6c844000-6c847fff : System RAM
6c848000-6c849fff : System RAM
6c84a000-6c85dfff : System RAM
6c85e000-6c85efff : System RAM
6c85f000-6cbfbfff : System RAM
6cbfc000-6d349fff : System RAM
6d34a000-6d3fbfff : System RAM
6d3fc000-6d455fff : System RAM
6d4fc000-6d773fff : System RAM
100000000-7ffffffff : System RAM
4080000000-40ffffffff : System RAM
14004000000-147ffffffff : System RAM
==

But there is a confusion.

i386 and x86_64 registers System RAM as IORESOUCE_MEM | IORESOUCE_BUSY. ia64 registers System RAM as IORESOURCE_MEM.

Which is better ?

I ask this because current memory hotplug treat memory as IORESOUCE_MEM. When memory hot-add occurs on x86_64, new memory is added as IORESOUCE_MEM. memory hot-remove (now) can remove only IORESOUCE_MEM.

If ia64 should treat System RAM as IORESOUCE_MEM | IORESOUCE_BUSY, I'll write a fix.

Thanks,
-Kame

#1 lore raw
Quoted 4 lines · KAMEZAWA Hiroyuki

i386 and x86_64 registers System RAM as IORESOUCE_MEM | IORESOUCE_BUSY. ia64 registers System RAM as IORESOURCE_MEM.

Which is better ?

Should probably be BUSY. Non-BUSY regions can have io resources requested underneath them, but you wouldn't want a PCI device to be assigned an address which overlaps with physical memory.

Signature · 4 lines
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#2 lore raw
Quoted 9 lines · On Tue, 2 Oct 2007 19:52:42 -0600 Matthew Wilcox <[email protected]> wrote:
Quoted 4 lines · KAMEZAWA Hiroyuki

i386 and x86_64 registers System RAM as IORESOUCE_MEM | IORESOUCE_BUSY. ia64 registers System RAM as IORESOURCE_MEM.

Which is better ?

Should probably be BUSY. Non-BUSY regions can have io resources requested underneath them, but you wouldn't want a PCI device to be assigned an address which overlaps with physical memory.

Thank you.
It seems that I'll have to try modifing ia64 and memory hotplug in the next -mm.

Regards,
-Kame

#3 lore raw

PATCH 1/1 Add IORESOUCE_BUSY flag for System RAM (Re: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c)

Hello.

I was asked from Kame-san to write this patch.

Please apply.

---------
i386 and x86-64 registers System RAM as IORESOURCE_MEM | IORESOURCE_BUSY.

But ia64 registers it as IORESOURCE_MEM only.
In addition, memory hotplug code registers new memory as IORESOURCE_MEM too.

This patch adds IORESOURCE_BUSY for them to avoid potential overlap mapping by PCI device.

---
 arch/ia64/kernel/efi.c |    6 ++----
 mm/memory_hotplug.c    |    2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

Index: current/arch/ia64/kernel/efi.c
=================================--- current.orig/arch/ia64/kernel/efi.c 2007-11-01 15:24:05.000000000 +0900
+++ current/arch/ia64/kernel/efi.c 2007-11-01 15:24:18.000000000 +0900
@@ -1111,7 +1111,7 @@ efi_initialize_iomem_resources(struct re
if (md->num_pages = 0) /* should not happen */
continue;

- flags = IORESOURCE_MEM;
+ flags = IORESOURCE_MEM | IORESOURCE_BUSY;
switch (md->type) {

case EFI_MEMORY_MAPPED_IO:
@@ -1133,12 +1133,11 @@ efi_initialize_iomem_resources(struct re

case EFI_ACPI_MEMORY_NVS:
name = "ACPI Non-volatile Storage";
- flags |= IORESOURCE_BUSY;
break;

case EFI_UNUSABLE_MEMORY:
name = "reserved";
- flags |= IORESOURCE_BUSY | IORESOURCE_DISABLED;
+ flags |= IORESOURCE_DISABLED;
break;

case EFI_RESERVED_TYPE:
@@ -1147,7 +1146,6 @@ efi_initialize_iomem_resources(struct re
case EFI_ACPI_RECLAIM_MEMORY:
default:
name = "reserved";
- flags |= IORESOURCE_BUSY;
break;
}

Index: current/mm/memory_hotplug.c
=================================--- current.orig/mm/memory_hotplug.c 2007-11-01 15:24:16.000000000 +0900
+++ current/mm/memory_hotplug.c 2007-11-01 15:41:27.000000000 +0900
@@ -39,7 +39,7 @@ static struct resource *register_memory_
res->name = "System RAM";
res->start = start;
res->end = start + size - 1;
- res->flags = IORESOURCE_MEM;
+ res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
if (request_resource(&iomem_resource, res) < 0) {
printk("System RAM resource %llx - %llx cannot be added\n", (unsigned long long)res->start, (unsigned long long)res->end);

Signature · 1 line
Yasunori Goto 
#4 lore raw

Re: [PATCH] Add IORESOUCE_BUSY flag for System RAM (Re: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c)

Quoted 63 lines · Yasunori Goto

Hello.

I was asked from Kame-san to write this patch.

Please apply.

---------
i386 and x86-64 registers System RAM as IORESOURCE_MEM | IORESOURCE_BUSY.

But ia64 registers it as IORESOURCE_MEM only.
In addition, memory hotplug code registers new memory as IORESOURCE_MEM too.

This patch adds IORESOURCE_BUSY for them to avoid potential overlap mapping by PCI device.

---
 arch/ia64/kernel/efi.c |    6 ++----
 mm/memory_hotplug.c    |    2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

Index: current/arch/ia64/kernel/efi.c
===================================================================

arch/ia64/kernel/efi.c +2 -4
@@ -1111,7 +1111,7 @@ efi_initialize_iomem_resources(struct re
 		if (md->num_pages == 0) /* should not happen */
 			continue;
 
-		flags = IORESOURCE_MEM;
+		flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 		switch (md->type) {
 
 			case EFI_MEMORY_MAPPED_IO:
@@ -1133,12 +1133,11 @@ efi_initialize_iomem_resources(struct re
 
 			case EFI_ACPI_MEMORY_NVS:
 				name = "ACPI Non-volatile Storage";
-				flags |= IORESOURCE_BUSY;
 				break;
 
 			case EFI_UNUSABLE_MEMORY:
 				name = "reserved";
-				flags |= IORESOURCE_BUSY | IORESOURCE_DISABLED;
+				flags |= IORESOURCE_DISABLED;
 				break;
 
 			case EFI_RESERVED_TYPE:
@@ -1147,7 +1146,6 @@ efi_initialize_iomem_resources(struct re
 			case EFI_ACPI_RECLAIM_MEMORY:
 			default:
 				name = "reserved";
-				flags |= IORESOURCE_BUSY;
 				break;
 		}
 

Index: current/mm/memory_hotplug.c
===================================================================

mm/memory_hotplug.c static struct resource *register_memory_ · line 45

Quoted 8 lines
mm/memory_hotplug.c +1 -1
@@ -39,7 +39,7 @@ static struct resource *register_memory_
 	res->name = "System RAM";
 	res->start = start;
 	res->end = start + size - 1;
-	res->flags = IORESOURCE_MEM;
+	res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	if (request_resource(&iomem_resource, res) < 0) {
 		printk("System RAM resource %llx - %llx cannot be added\n",
 		(unsigned long long)res->start, (unsigned long long)res->end);

Not quite.. You need following patch on top of this to make hotplug memory remove work on ia64/x86-64.

Thanks,
Badari

Once you mark memory resource BUSY, walk_memory_resource() won't be able to find it.

---
 kernel/resource.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/resource.c +1 -1
Index: linux-2.6.24-rc1/kernel/resource.c
===================================================================
@@ -277,7 +277,7 @@ walk_memory_resource(unsigned long start
 	int ret = -1;
 	res.start = (u64) start_pfn << PAGE_SHIFT;
 	res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
-	res.flags = IORESOURCE_MEM;
+	res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 	orig_end = res.end;
 	while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
 		pfn = (unsigned long)(res.start >> PAGE_SHIFT);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

PATCH 1/1 Add IORESOUCE_BUSY flag for System RAM take 2.

Hello.

I merged Baradi-san's patch and mine. This and Kame-san's following patch is necessary for x86-64 memory unplug.

http://marc.info/?l=linux-mm&m9399026017901&w=2

I heard Kame-san's patch is already included in -mm. So, I'll repost merged patch now.

This patch is tested on 2.6.23-mm1.

Please apply.

---

i386 and x86-64 registers System RAM as IORESOURCE_MEM | IORESOURCE_BUSY.

But ia64 registers it as IORESOURCE_MEM only.
In addition, memory hotplug code registers new memory as IORESOURCE_MEM too.

This difference causes a failure of memory unplug of x86-64. This patch fix it.

This patch adds IORESOURCE_BUSY to avoid potential overlap mapping by PCI device.

---
 arch/ia64/kernel/efi.c |    6 ++----
 kernel/resource.c      |    2 +-
 mm/memory_hotplug.c    |    2 +-
 3 files changed, 4 insertions(+), 6 deletions(-)

Index: current/arch/ia64/kernel/efi.c
=================================--- current.orig/arch/ia64/kernel/efi.c 2007-11-02 17:17:30.000000000 +0900
+++ current/arch/ia64/kernel/efi.c 2007-11-02 17:19:10.000000000 +0900
@@ -1111,7 +1111,7 @@ efi_initialize_iomem_resources(struct re
if (md->num_pages = 0) /* should not happen */
continue;

- flags = IORESOURCE_MEM;
+ flags = IORESOURCE_MEM | IORESOURCE_BUSY;
switch (md->type) {

case EFI_MEMORY_MAPPED_IO:
@@ -1133,12 +1133,11 @@ efi_initialize_iomem_resources(struct re

case EFI_ACPI_MEMORY_NVS:
name = "ACPI Non-volatile Storage";
- flags |= IORESOURCE_BUSY;
break;

case EFI_UNUSABLE_MEMORY:
name = "reserved";
- flags |= IORESOURCE_BUSY | IORESOURCE_DISABLED;
+ flags |= IORESOURCE_DISABLED;
break;

case EFI_RESERVED_TYPE:
@@ -1147,7 +1146,6 @@ efi_initialize_iomem_resources(struct re
case EFI_ACPI_RECLAIM_MEMORY:
default:
name = "reserved";
- flags |= IORESOURCE_BUSY;
break;
}

Index: current/mm/memory_hotplug.c
=================================--- current.orig/mm/memory_hotplug.c 2007-11-02 17:19:09.000000000 +0900
+++ current/mm/memory_hotplug.c 2007-11-02 17:19:10.000000000 +0900
@@ -39,7 +39,7 @@ static struct resource *register_memory_
res->name = "System RAM";
res->start = start;
res->end = start + size - 1;
- res->flags = IORESOURCE_MEM;
+ res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
if (request_resource(&iomem_resource, res) < 0) {
printk("System RAM resource %llx - %llx cannot be added\n", (unsigned long long)res->start, (unsigned long long)res->end);
Index: current/kernel/resource.c
=================================--- current.orig/kernel/resource.c 2007-11-02 17:19:15.000000000 +0900
+++ current/kernel/resource.c 2007-11-02 17:22:39.000000000 +0900
@@ -287,7 +287,7 @@ walk_memory_resource(unsigned long start
int ret = -1;
res.start = (u64) start_pfn << PAGE_SHIFT;
res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
- res.flags = IORESOURCE_MEM;
+ res.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
orig_end = res.end;
while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) {
pfn = (unsigned long)(res.start >> PAGE_SHIFT);

Signature · 1 line
Yasunori Goto 
#6 lore raw
In reply to KAMEZAWA Hiroyuki
Quoted 6 lines · KAMEZAWA Hiroyuki

i386 and x86_64 registers System RAM as IORESOUCE_MEM | IORESOUCE_BUSY.
ia64 registers System RAM as IORESOURCE_MEM.

Which is better ?

I think we should take system ram out of the iomem file, at least.

'struct resource' is a good, cross-platform structure to use for keeping track of which memory we have where. So, we can share that structure to keep track of iomem, or memory hotplug state. But, I'm not sure we should be intermingling system RAM and iomem like we are now in the same instance of the structure.

-- Dave

#7 lore raw
Quoted 1 line · Dave Hansen

I think we should take system ram out of the iomem file, at least.

Rubbish. iomem is a representation of the physical addresses in the system as seen from the CPU's perspective. As I said in my previous mail in this thread, if you attempt to map a device's BAR over the top of physical RAM, things will go poorly for you.

Signature · 4 lines
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."