2007-10-03 01:29:47

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c

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











2007-10-03 01:52:54

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c

On Wed, Oct 03, 2007 at 10:31:36AM +0900, KAMEZAWA Hiroyuki wrote:
> 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.

--
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."

2007-10-03 04:55:46

by Kamezawa Hiroyuki

[permalink] [raw]
Subject: Re: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c

On Tue, 2 Oct 2007 19:52:42 -0600
Matthew Wilcox <[email protected]> wrote:

> On Wed, Oct 03, 2007 at 10:31:36AM +0900, KAMEZAWA Hiroyuki wrote:
> > 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

2007-10-03 16:37:29

by Dave Hansen

[permalink] [raw]
Subject: Re: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c

On Wed, 2007-10-03 at 10:31 +0900, KAMEZAWA Hiroyuki wrote:
>
> 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

2007-10-03 16:43:23

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [Question] How to represent SYSTEM_RAM in kerenel/resouce.c

On Wed, Oct 03, 2007 at 09:37:13AM -0700, Dave Hansen wrote:
> 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.

--
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."

2007-11-01 09:23:18

by Yasunori Goto

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Yasunori Goto <[email protected]>

---
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);

--
Yasunori Goto


2007-11-01 15:25:09

by Badari Pulavarty

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

On Thu, 2007-11-01 at 18:21 +0900, Yasunori Goto wrote:
> 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.
>
> Signed-off-by: Yasunori Goto <[email protected]>
>
> ---
> 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);
>


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.

Signed-off-by: Badari Pulavarty <[email protected]>
---
kernel/resource.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6.24-rc1/kernel/resource.c
===================================================================
--- linux-2.6.24-rc1.orig/kernel/resource.c 2007-10-23 20:50:57.000000000 -0700
+++ linux-2.6.24-rc1/kernel/resource.c 2007-11-01 08:19:59.000000000 -0700
@@ -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);


2007-11-06 02:24:43

by Yasunori Goto

[permalink] [raw]
Subject: [PATCH] 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&m=119399026017901&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.


Signed-off-by: Yasunori Goto <[email protected]>
Signed-off-by: Badari Pulavarty <[email protected]>

---
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);

--
Yasunori Goto