Skip to contentSkip to conversation

Always use 64 bit addresses for the firmware memory map

PATCH In review Bernhard Walle 3 participants 9 messages Nov 12, 2008 – Nov 13, 2008

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

PATCH 1/1 Always use 64 bit addresses for the firmware memory map

I had a problem that on i386 without PAE enabled the firmware memory map was wrong because a 64 bit address has been truncated:

        0000000000000000-000000000009f400 (System RAM)
        000000000009f400-00000000000a0000 (reserved)
        00000000fec10000-00000000fec11000 (reserved)
        00000000fec20000-00000000fec21000 (reserved)
        00000000fee00000-00000000fee10000 (reserved)
        00000000ff800000-0000000100000000 (reserved)
 --->   0000000000000000-00000000fffff000 (System RAM)  <---
        00000000000f0000-0000000000100000 (reserved)
        0000000000100000-00000000f57fa000 (System RAM)
        00000000f57fa000-00000000f5800000 (ACPI Tables)
        00000000fdc00000-00000000fdc01000 (reserved)
        00000000fdc10000-00000000fdc11000 (reserved)
        00000000fdc20000-00000000fdc21000 (reserved)
        00000000fdc30000-00000000fdc31000 (reserved)
        00000000fec00000-00000000fec01000 (reserved)

Just always using 64 bit is the most sane approach in my opinion.

---
 drivers/firmware/memmap.c    |   17 +++++++----------
 include/linux/firmware-map.h |   12 +++++-------
 2 files changed, 12 insertions(+), 17 deletions(-)
drivers/firmware/memmap.c +7 -10
index 3bf8ee1..010afde 100644
@@ -31,8 +31,8 @@
  * information is necessary as for the resource tree.
  */
 struct firmware_map_entry {
-	resource_size_t		start;	/* start of the memory range */
-	resource_size_t		end;	/* end of the memory range (incl.) */
+	uint64_t		start;	/* start of the memory range */
+	uint64_t		end;	/* end of the memory range (incl.) */
 	const char		*type;	/* type of the memory range */
 	struct list_head	list;	/* entry for the linked list */
 	struct kobject		kobj;   /* kobject for each entry */
@@ -101,7 +101,7 @@ static LIST_HEAD(map_entries);
  * Common implementation of firmware_map_add() and firmware_map_add_early()
  * which expects a pre-allocated struct firmware_map_entry.
  **/
-static int firmware_map_add_entry(resource_size_t start, resource_size_t end,
+static int firmware_map_add_entry(uint64_t start, uint64_t end,
 				  const char *type,
 				  struct firmware_map_entry *entry)
 {
@@ -132,8 +132,7 @@ static int firmware_map_add_entry(resource_size_t start, resource_size_t end,
  *
  * Returns 0 on success, or -ENOMEM if no memory could be allocated.
  **/
-int firmware_map_add(resource_size_t start, resource_size_t end,
-		     const char *type)
+int firmware_map_add(uint64_t start, uint64_t end, const char *type)
 {
 	struct firmware_map_entry *entry;
 
@@ -157,7 +156,7 @@ int firmware_map_add(resource_size_t start, resource_size_t end,
  *
  * Returns 0 on success, or -ENOMEM if no memory could be allocated.
  **/
-int __init firmware_map_add_early(resource_size_t start, resource_size_t end,
+int __init firmware_map_add_early(uint64_t start, uint64_t end,
 				  const char *type)
 {
 	struct firmware_map_entry *entry;
@@ -175,14 +174,12 @@ int __init firmware_map_add_early(resource_size_t start, resource_size_t end,
 
 static ssize_t start_show(struct firmware_map_entry *entry, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
-		(unsigned long long)entry->start);
+	return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->start);
 }
 
 static ssize_t end_show(struct firmware_map_entry *entry, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
-		(unsigned long long)entry->end);
+	return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->end);
 }
 
 static ssize_t type_show(struct firmware_map_entry *entry, char *buf)
include/linux/firmware-map.h +5 -7
index 6e199c8..209a27a 100644
@@ -24,21 +24,19 @@
  */
 #ifdef CONFIG_FIRMWARE_MEMMAP
 
-int firmware_map_add(resource_size_t start, resource_size_t end,
-		     const char *type);
-int firmware_map_add_early(resource_size_t start, resource_size_t end,
-			   const char *type);
+int firmware_map_add(uint64_t start, uint64_t end, const char *type);
+int firmware_map_add_early(uint64_t start, uint64_t end, const char *type);
 
 #else /* CONFIG_FIRMWARE_MEMMAP */
 
-static inline int firmware_map_add(resource_size_t start, resource_size_t end,
+static inline int firmware_map_add(uint64_t start, uint64_t end,
 				   const char *type)
 {
 	return 0;
 }
 
-static inline int firmware_map_add_early(resource_size_t start,
-					 resource_size_t end, const char *type)
+static inline int firmware_map_add_early(uint64_t start, uint64_t end,
+					 const char *type)
 {
 	return 0;
 }
Signature · 7 lines
1.6.0.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw
Quoted 19 lines · Bernhard Walle

I had a problem that on i386 without PAE enabled the firmware memory map was wrong because a 64 bit address has been truncated:

        0000000000000000-000000000009f400 (System RAM)
        000000000009f400-00000000000a0000 (reserved)
        00000000fec10000-00000000fec11000 (reserved)
        00000000fec20000-00000000fec21000 (reserved)
        00000000fee00000-00000000fee10000 (reserved)
        00000000ff800000-0000000100000000 (reserved)
 --->   0000000000000000-00000000fffff000 (System RAM)  <---
        00000000000f0000-0000000000100000 (reserved)
        0000000000100000-00000000f57fa000 (System RAM)
        00000000f57fa000-00000000f5800000 (ACPI Tables)
        00000000fdc00000-00000000fdc01000 (reserved)
        00000000fdc10000-00000000fdc11000 (reserved)
        00000000fdc20000-00000000fdc21000 (reserved)
        00000000fdc30000-00000000fdc31000 (reserved)
        00000000fec00000-00000000fec01000 (reserved)
Quoted 4 lines

Just always using 64 bit is the most sane approach in my opinion.

There are two options: either filter addresses outside the resource_size_t range (since we don't manage that space and therefore don't care about it) or, as you do, enforce 64-bitness.

I want to make sure, though, that we don't just end up pushing the truncation further down in the code.

-hpa

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

#2 lore raw
Quoted 3 lines · H. Peter Anvin

I want to make sure, though, that we don't just end up pushing the truncation further down in the code.

Well, I think that interface should export the BIOS memmap as provided. Since E820 does provide 64 bit addresses, that should get exported.

It should even possible to kexec a PAE kernel from a non PAE kernel ... I didn't test, but it could work. But only if the E820 map is correctly written in the zero page, which is only the case if we get it correctly.

Regards,
Bernhard

Signature · 6 lines
Bernhard Walle, SUSE LINUX Products GmbH, Architecture Development

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw
Quoted 11 lines · Bernhard Walle
Quoted 2 lines · H. Peter Anvin

I want to make sure, though, that we don't just end up pushing the truncation further down in the code.

Well, I think that interface should export the BIOS memmap as provided. Since E820 does provide 64 bit addresses, that should get exported.

It should even possible to kexec a PAE kernel from a non PAE kernel ... I didn't test, but it could work. But only if the E820 map is correctly written in the zero page, which is only the case if we get it correctly.

That's fine, but we do have to check that we don't truncate elsewhere.

-hpa

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

#4 lore raw
Quoted 6 lines · H. Peter Anvin
Quoted 4 lines · Bernhard Walle
Quoted 2 lines · H. Peter Anvin

I want to make sure, though, that we don't just end up pushing the truncation further down in the code.

Quoted 8 lines
Quoted 6 lines

Well, I think that interface should export the BIOS memmap as provided. Since E820 does provide 64 bit addresses, that should get exported.

It should even possible to kexec a PAE kernel from a non PAE kernel ... I didn't test, but it could work. But only if the E820 map is correctly written in the zero page, which is only the case if we get it correctly.

That's fine, but we do have to check that we don't truncate elsewhere.

What do you mean? That my patch doesn't fix all problems that might exist but are not yet fixed or that my patch introduces new problems?

Well, for example in the resource reservation code [e820.c, e820_reserve_resource()] that is handled at line 1285:

		if (end != (resource_size_t)end) {
			res++;
			continue;
		}

My patch only changes the firmware interface, not the architecture specific code. However, I cannot guarantee that it doesn't break something, but what action do you expect from me that the patch is taken?

Regards,
Bernhard

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

#5 lore raw
In reply to Bernhard Walle
Quoted 33 lines · Bernhard Walle

I had a problem that on i386 without PAE enabled the firmware memory map was wrong because a 64 bit address has been truncated:

        0000000000000000-000000000009f400 (System RAM)
        000000000009f400-00000000000a0000 (reserved)
        00000000fec10000-00000000fec11000 (reserved)
        00000000fec20000-00000000fec21000 (reserved)
        00000000fee00000-00000000fee10000 (reserved)
        00000000ff800000-0000000100000000 (reserved)
 --->   0000000000000000-00000000fffff000 (System RAM)  <---
        00000000000f0000-0000000000100000 (reserved)
        0000000000100000-00000000f57fa000 (System RAM)
        00000000f57fa000-00000000f5800000 (ACPI Tables)
        00000000fdc00000-00000000fdc01000 (reserved)
        00000000fdc10000-00000000fdc11000 (reserved)
        00000000fdc20000-00000000fdc21000 (reserved)
        00000000fdc30000-00000000fdc31000 (reserved)
        00000000fec00000-00000000fec01000 (reserved)

Just always using 64 bit is the most sane approach in my opinion.

---
 drivers/firmware/memmap.c    |   17 +++++++----------
 include/linux/firmware-map.h |   12 +++++-------
 2 files changed, 12 insertions(+), 17 deletions(-)
drivers/firmware/memmap.c +0 -0
index 3bf8ee1..010afde 100644

drivers/firmware/memmap.c line 34

Quoted 6 lines
drivers/firmware/memmap.c +0 -2
@@ -31,8 +31,8 @@
  * information is necessary as for the resource tree.
  */
 struct firmware_map_entry {
-	resource_size_t		start;	/* start of the memory range */
-	resource_size_t		end;	/* end of the memory range (incl.) */
 

resource_size_t should always be 64-bit on PAE now.

J

Quoted 82 lines
drivers/firmware/memmap.c +2 -0
+	uint64_t		start;	/* start of the memory range */
+	uint64_t		end;	/* end of the memory range (incl.) */
 	const char		*type;	/* type of the memory range */
 	struct list_head	list;	/* entry for the linked list */
drivers/firmware/memmap.c +5 -8
 	struct kobject		kobj;   /* kobject for each entry */
@@ -101,7 +101,7 @@ static LIST_HEAD(map_entries);
  * Common implementation of firmware_map_add() and firmware_map_add_early()
  * which expects a pre-allocated struct firmware_map_entry.
  **/
-static int firmware_map_add_entry(resource_size_t start, resource_size_t end,
+static int firmware_map_add_entry(uint64_t start, uint64_t end,
 				  const char *type,
 				  struct firmware_map_entry *entry)
 {
@@ -132,8 +132,7 @@ static int firmware_map_add_entry(resource_size_t start, resource_size_t end,
  *
  * Returns 0 on success, or -ENOMEM if no memory could be allocated.
  **/
-int firmware_map_add(resource_size_t start, resource_size_t end,
-		     const char *type)
+int firmware_map_add(uint64_t start, uint64_t end, const char *type)
 {
 	struct firmware_map_entry *entry;
 
@@ -157,7 +156,7 @@ int firmware_map_add(resource_size_t start, resource_size_t end,
  *
  * Returns 0 on success, or -ENOMEM if no memory could be allocated.
  **/
-int __init firmware_map_add_early(resource_size_t start, resource_size_t end,
+int __init firmware_map_add_early(uint64_t start, uint64_t end,
 				  const char *type)
 {
 	struct firmware_map_entry *entry;
@@ -175,14 +174,12 @@ int __init firmware_map_add_early(resource_size_t start, resource_size_t end,
 
 static ssize_t start_show(struct firmware_map_entry *entry, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
-		(unsigned long long)entry->start);
+	return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->start);
 }
 
 static ssize_t end_show(struct firmware_map_entry *entry, char *buf)
 {
-	return snprintf(buf, PAGE_SIZE, "0x%llx\n",
-		(unsigned long long)entry->end);
+	return snprintf(buf, PAGE_SIZE, "0x%llx\n", entry->end);
 }
 
 static ssize_t type_show(struct firmware_map_entry *entry, char *buf)
include/linux/firmware-map.h +5 -7
index 6e199c8..209a27a 100644
@@ -24,21 +24,19 @@
  */
 #ifdef CONFIG_FIRMWARE_MEMMAP
 
-int firmware_map_add(resource_size_t start, resource_size_t end,
-		     const char *type);
-int firmware_map_add_early(resource_size_t start, resource_size_t end,
-			   const char *type);
+int firmware_map_add(uint64_t start, uint64_t end, const char *type);
+int firmware_map_add_early(uint64_t start, uint64_t end, const char *type);
 
 #else /* CONFIG_FIRMWARE_MEMMAP */
 
-static inline int firmware_map_add(resource_size_t start, resource_size_t end,
+static inline int firmware_map_add(uint64_t start, uint64_t end,
 				   const char *type)
 {
 	return 0;
 }
 
-static inline int firmware_map_add_early(resource_size_t start,
-					 resource_size_t end, const char *type)
+static inline int firmware_map_add_early(uint64_t start, uint64_t end,
+					 const char *type)
 {
 	return 0;
 }
#7 lore raw
Quoted 8 lines · H. Peter Anvin
Quoted 3 lines · Jeremy Fitzhardinge

resource_size_t should always be 64-bit on PAE now.

Yes, but this would affect non-PAE kernels too.

Yeah, I overlooked the comment about non-PAE. Should we just make resource_size_t 64 bits all the time? Or ignore inaccessible resources?

J

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

#8 lore raw
Quoted 7 lines · Jeremy Fitzhardinge
Quoted 6 lines · H. Peter Anvin
Quoted 3 lines · Jeremy Fitzhardinge

resource_size_t should always be 64-bit on PAE now.

Quoted 6 lines
Quoted 2 lines

Yes, but this would affect non-PAE kernels too.

Yeah, I overlooked the comment about non-PAE. Should we just make resource_size_t 64 bits all the time? Or ignore inaccessible resources?

Ignore them, presumably (keeping in mind some of them may need to be truncated.) We simply don't manage that space.

-hpa

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