Skip to contentSkip to conversation

Exposing EFI memory map

PATCH In review Sourav Sen 8 participants 22 messages May 6, 2004 – May 13, 2004

lore
Share & tools
lore

Sourav Sen

author
#0 lore raw

PATCH 1/1 Exposing EFI memory map

Hi,

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

Thanks
Sourav

The patch is w.r.t 2.6.6-rc3
----------------------------
===========================================================================

drivers/firmware/efivars.c 2004-05-06 11:43:40.000000000 +0530 renamed from drivers/firmware/efivars.c 2004-05-05 13:55:40.000000000 +0530 +32 -0
@@ -580,10 +580,42 @@ systab_read(struct subsystem *entry, cha
        return str - buf;
 }
 
+/*
+ * Expose the efi memory map as kernel keeps it. Note, it may be a little
+ * different from what gets actually passed in at loader handoff time as a
+ * call to efi_memmap_walk modifies that.
+ */
+
+static ssize_t
+efi_memmap_read(struct subsystem *entry, char * buf)
+{
+       void * efi_map_start, *efi_map_end, *p;
+       efi_memory_desc_t *md;
+       u64 efi_desc_size;
+       char * str = buf;
+
+       if (!entry || !buf)
+               return -EINVAL;
+
+       efi_map_start = __va(ia64_boot_param->efi_memmap);
+       efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
+       efi_desc_size = ia64_boot_param->efi_memdesc_size;
+
+       for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
+               md = (efi_memory_desc_t *)p;
+               str += sprintf(str, "%2u     %-#18lx    %#016lx %#016lx\n",
\
+                       md->type, md->attribute, md->phys_addr, \
+                       md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT));
+       }
+       return (str - buf);
+}
+
 static EFI_ATTR(systab, 0400, systab_read, NULL);
+static EFI_ATTR(memmap, 0400, efi_memmap_read, NULL);
 
 static struct subsys_attribute *efi_subsys_attrs[] = {
        &efi_attr_systab,
+       &efi_attr_memmap,       /* Here comes one */
        NULL,   /* maybe more in the future? */
 };
 
#1 lore raw
Quoted 5 lines · Sourav Sen

Hi,

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

doesn't exactly fit into the one value per file approach, does it?

#2 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Sourav Sen

Hi,

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

doesn't exactly fit into the one value per file approach, does it?

It's not exactly modifiable. I'm not sure what benefit we'd gain from splitting this file into dozens.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#3 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Sourav Sen

Hi,

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

doesn't exactly fit into the one value per file approach, does it?

It's not exactly modifiable.

come on, it's the ideal hotplug memory interface ;) should we try to unify the memory map exports between architectures instead of matching the firmware-of-the-day for each architecture ??

#4 lore raw
Quoted 9 lines · Arjan van de Ven
Quoted 8 lines · Matthew Wilcox
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Sourav Sen

Hi,

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

doesn't exactly fit into the one value per file approach, does it?

It's not exactly modifiable.

come on, it's the ideal hotplug memory interface ;) should we try to unify the memory map exports between architectures instead of matching the firmware-of-the-day for each architecture ??

Well, firmware-du-jour is what /sys/firmware/... is for ;-)

I don't have a clear picture of what a hotplug memory interface would look like; and even if I did, I don't think the EFI memory map is of much help in that matter.

Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
#5 lore raw
Quoted 8 lines · Matthew Wilcox
Quoted 6 lines · Arjan van de Ven
Quoted 1 line · Matthew Wilcox

It's not exactly modifiable.

come on, it's the ideal hotplug memory interface ;) should we try to unify the memory map exports between architectures instead of matching the firmware-of-the-day for each architecture ??

Quoted 5 lines

Well, firmware-du-jour is what /sys/firmware/... is for ;-)

I don't have a clear picture of what a hotplug memory interface would look like; and even if I did, I don't think the EFI memory map is of much help in that matter.

If you _get_ a clear picture, please let me know. I've been looking for one. :)

You're right that the EFI map itself isn't any help to memory hotplug, but things derived from it are. The amount and physical locations of all of the memory in the system are obviously pulled out of this table at some point, and Linux already has a representation of them, otherwise we couldn't allocate memory or do things like virt_to_phys() or page_to_pfn().

I think what Arjan doesn't want is 14 different architectures with 14 different userspace programs reading 14 different things in /proc and /sys for each of their memory hotplug schemes. I guarantee you don't want to know what ppc64 is planning on doing.

BTW, Sourav, what is it that you need from the EFI map? Could you take a quick look through the lhms-devel list archives and see if anything there is similar to what you're trying to do? Here's a place to start:

http://sourceforge.net/mailarchive/forum.php?thread_idA20609&forum_id"3

-- Dave

#6 lore raw
Quoted 3 lines · Dave Hansen

I think what Arjan doesn't want is 14 different architectures with 14 different userspace programs reading 14 different things in /proc and /sys for each of their memory hotplug schemes.

*exactly*

well 14 architecture and 28 programs because firmware got rev'ed ;)

#7 lore raw
In reply to Matthew Wilcox
Quoted 2 lines · Matthew Wilcox

It's not exactly modifiable. I'm not sure what benefit we'd gain from splitting this file into dozens.

a consistant interface. If we support gazillion random formats in sysfs it's no gain at all over the old procfs mess.

#8 lore raw
In reply to Sourav Sen
Quoted 3 lines · Sourav Sen

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

I'm not generally opposed, but have a couple questions.

1) Why does userspace / humans need to know this? For debugging firmware?

2) Can the memory map output ever be larger than PAGE_SIZE (lower limit is 4KB on x86)? If not, what guarantees that? If so, you need your own read mechanism rather than the generic sysfs one.

The one-value-per-file rule has an exception for an array of values of the same type per Documentation/filesystems/sysfs.txt, which this looks to adhere to.

Thanks,
Matt

Signature · 4 lines
Matt Domsch
Sr. Software Engineer, Lead Engineer
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com
author
#9 lore raw

Hi Matt,

+ -----Original Message-----
+ From: Matt Domsch [mailto:[email protected]]
+ On Thu, May 06, 2004 at 02:22:46PM +0530, Sourav Sen wrote:
+ > The following simple patch creates a read-only file
+ > "memmap" under <mount point>/firmware/efi/ in sysfs
+ > and exposes the efi memory map thru it.
+
+ I'm not generally opposed, but have a couple questions. +
+ 1) Why does userspace / humans need to know this? For
+ debugging firmware?

Maybe. But the point I had in mind is, say for example
memory diagnostics applications/exercisers which reads (Blind reads, without caring about contents) memory
to uncover errors (single bit errors) can use
this to know the usable ranges and map them thru /dev/mem and read those ranges.

+
+ 2) Can the memory map output ever be larger than PAGE_SIZE (lower
+ limit is 4KB on x86)? If not, what guarantees that? If so, you need
+ your own read mechanism rather than the generic sysfs one. +

I don't have an answer right now. I'll investigate. Tony Luck also
expressed similar concerns and suggested seq*() interfaces. I'll see how I can do that.

+ The one-value-per-file rule has an exception for an array of values of
+ the same type per Documentation/filesystems/sysfs.txt, which this
+ looks to adhere to.
+
+ Thanks,
+ Matt
+
+ --
+ Matt Domsch
+ Sr. Software Engineer, Lead Engineer
+ Dell Linux Solutions linux.dell.com & www.dell.com/linux
+ Linux on Dell mailing lists @ http://lists.us.dell.com
+

Thanks
Sourav

#10 lore raw
Quoted 9 lines · Sourav Sen

+ 1) Why does userspace / humans need to know this? For
+ debugging firmware?

Maybe. But the point I had in mind is, say for example
memory diagnostics applications/exercisers which reads (Blind reads, without caring about contents) memory
to uncover errors (single bit errors) can use
this to know the usable ranges and map them thru /dev/mem and read those ranges.

For this application, the EFI memory map isn't what you want. It's a pretty good approximation today, but the day when we'll be able to hot-add memory is fast approaching, and the EFI map won't mention anything added after boot. We'll discover all that via ACPI (on ia64).

author
#11 lore raw

+ -----Original Message-----
+ From: Bjorn Helgaas [mailto:[email protected]]
+ Sent: Thursday, May 06, 2004 8:39 PM
+ To: Sourav Sen
+ Cc: 'Matt Domsch'; [email protected];
+ [email protected]; [email protected];
+ [email protected]
+ Subject: Re: [2.6.6 PATCH] Exposing EFI memory map
+
+
+ On Thursday 06 May 2004 7:20 am, Sourav Sen wrote:
+ > + 1) Why does userspace / humans need to know this? For
+ > + debugging firmware?
+ >
+ > Maybe. But the point I had in mind is, say for example
+ > memory diagnostics applications/exercisers which reads (Blind
+ > reads, without caring about contents) memory
+ > to uncover errors (single bit errors) can use
+ > this to know the usable ranges and map them thru /dev/mem and
+ > read those ranges.
+
+ For this application, the EFI memory map isn't what you want.
+ It's a pretty good approximation today, but the day when we'll
+ be able to hot-add memory is fast approaching, and the EFI map
+ won't mention anything added after boot. We'll discover all
+ that via ACPI (on ia64).
+

Why not also update the efi memory table on a hotplug :-)
(Now also it gets modified a little on a call to efi_memmap_walk()). Otherwise clients of efi_memmap_walk() will also get stale information after a hotplug, isn't it (assuming they want to know about available physical ranges)?

Also, kernel may not exactly use all the memory added via
hotplug and there may be some truncation (just as efi_memmap_walk() does today). And it isn't help us if we get to know about those extents. Additionally we get to know about various mmio ranges and other ranges thru that table -- may be useful opportunistically.

--Sourav

#12 lore raw
Quoted 8 lines · Sourav Sen

From: Bjorn Helgaas [mailto:[email protected]]
+ For this application, the EFI memory map isn't what you want.
+ It's a pretty good approximation today, but the day when we'll
+ be able to hot-add memory is fast approaching, and the EFI map
+ won't mention anything added after boot. We'll discover all
+ that via ACPI (on ia64).

Why not also update the efi memory table on a hotplug :-)

That's actually what ppc64 does. But, they do it via /proc (not even from inside the kernel). I'm not very fond of that solution :)

Quoted 4 lines

(Now also it gets modified a little on a call to efi_memmap_walk()). Otherwise clients of efi_memmap_walk() will also get stale information after a hotplug, isn't it (assuming they want to know about available physical ranges)?

We'll probably end up having to lock down hotplug around the time that someone *needs* persistent information about memory layout from userspace. Think crashdump...

Quoted 1 line

Also, kernel may not exactly use all the memory added via hotplug

That's a good point. Some of the happy consumers of this should be things like crashdump and kexec. They might want a choice to either dump only the memory that Linux is currently using, or to know about all of the memory that is present.

Quoted 4 lines

and there may be some truncation (just as efi_memmap_walk()
does today). And it isn't help us if we get to know about those extents. Additionally we get to know about various mmio ranges and other ranges thru that table -- may be useful opportunistically.

There can be some pretty generic (although asynchronous) events given via /sbin/hotplug. I'm currently planning on having the memory hotplug "drivers" get the hot-added memory ready, but keep it offline. It then creates some kobjects, which generate hotplug events, and *then* the decision can be made in the hotplug scripts about what to do with it.

-- Dave

#13 lore raw
In reply to Sourav Sen
Quoted 4 lines · Sourav Sen

The following simple patch creates a read-only file "memmap" under <mount point>/firmware/efi/ in sysfs and exposes the efi memory map thru it.

No, data in this kind of format does not belong in sysfs.

thanks,

greg k-h

author
#14 lore raw

Hi Greg,

+ -----Original Message-----
+ From: Greg KH [mailto:[email protected]]
+ Sent: Thursday, May 06, 2004 10:11 PM
+ To: Sourav Sen
+ Cc: [email protected]; [email protected];
+ [email protected]; [email protected]
+ Subject: Re: [2.6.6 PATCH] Exposing EFI memory map +
+
+ On Thu, May 06, 2004 at 02:22:46PM +0530, Sourav Sen wrote:
+ >
+ > The following simple patch creates a read-only file
+ > "memmap" under <mount point>/firmware/efi/ in sysfs
+ > and exposes the efi memory map thru it.
+
+ No, data in this kind of format does not belong in sysfs.

Please tell me more. In Documentation/filesystems/sysfs.txt
I get:

"Attributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only value per file, so it is socially acceptable to express an array of values of the same type."

Here we have "Array of values of same types". And it does not do much nifty formatting either. Is that not acceptable?

If that is not, how about the following.

1. Create a directory "memmap" under firmware/efi/
2. Create files "map_start", "map_size" and "mapdesc_size" under that exposing ia64_boot_param->efi_memmap,
ia64_boot_param->efi_memmap_size

	   and ia64_boot_param->efi_memdesc_size respectively.

Userland can make meaning out of them by knowing the values and knowing about
"efi_memory_desc_t" which is already there in /usr/include/asm/efi.h

Thanks
Sourav

PS: BTW, Your slides on "Dealing with the Linux Kernel Community" at:
http://www.kroah.com/linux/talks/cgl_talk_2002_10_16/mgp00001.html
is kind of useful to me. This is my first time :-)

#15 lore raw
Quoted 2 lines · Sourav Sen

Here we have "Array of values of same types". And it does not do much nifty formatting either. Is that not acceptable?

But they are not of the same time, as you admitted :)

Also, they could be bigger than a single page, right? That is not possible right now in sysfs.

Quoted 11 lines

If that is not, how about the following.

1. Create a directory "memmap" under firmware/efi/
2. Create files "map_start", "map_size" and "mapdesc_size" under that exposing ia64_boot_param->efi_memmap,
ia64_boot_param->efi_memmap_size

	   and ia64_boot_param->efi_memdesc_size respectively.

Userland can make meaning out of them by knowing the values and knowing about "efi_memory_desc_t" which is already there in /usr/include/asm/efi.h

I think you should address the other issues in this thread before worrying about the sysfs interface (why have this at all, incorrect data for hotplug mem, etc.)

Quoted 3 lines

PS: BTW, Your slides on "Dealing with the Linux Kernel Community" at:
http://www.kroah.com/linux/talks/cgl_talk_2002_10_16/mgp00001.html
is kind of useful to me. This is my first time :-)

If only more people/companies would heed those rules...

thanks,

greg k-h

author
#16 lore raw

+ -----Original Message-----
+ From: Greg KH [mailto:[email protected]]
+ Sent: Saturday, May 08, 2004 3:19 AM
+ To: Sourav Sen
+ Cc: [email protected]; [email protected];
+ [email protected]; [email protected]
+ Subject: Re: [2.6.6 PATCH] Exposing EFI memory map +
+
+ On Fri, May 07, 2004 at 03:15:30PM +0530, Sourav Sen wrote:
+ > Here we have "Array of values of same types". And it does
+ not do much
+ > nifty formatting either. Is that not acceptable? +
+ But they are not of the same time, as you admitted :) +

Right. On similar lines I believe we need to split
firmware/efi/systab as well.

+ Also, they could be bigger than a single page, right? That is not
+ possible right now in sysfs.
+
+ > If that is not, how about the following.
+ >
+ > 1. Create a directory "memmap" under firmware/efi/
+ > 2. Create files "map_start", "map_size" and "mapdesc_size" under
+ > that exposing ia64_boot_param->efi_memmap,
+ > ia64_boot_param->efi_memmap_size
+ > and ia64_boot_param->efi_memdesc_size respectively.
+ >
+ > Userland can make meaning out of them by knowing the values
+ and knowing
+ > about "efi_memory_desc_t" which is already there in
+ > /usr/include/asm/efi.h
+
+ I think you should address the other issues in this thread before
+ worrying about the sysfs interface (why have this at all, incorrect
+ data for hotplug mem, etc.)
+
I did not hear whether the idea of updating efi memory map on a
hotplug is good or bad. In any case, can somebody tell me to how do I get the available physical range map (only the ranges that VM is using at a given point in time) from userland. I believe I outlined a legitimate requirement earlier in this thread :-)

Thanks
Sourav

#17 lore raw
Quoted 9 lines · Sourav Sen

+ I think you should address the other issues in this thread before
+ worrying about the sysfs interface (why have this at all, incorrect
+ data for hotplug mem, etc.)
+
I did not hear whether the idea of updating efi memory map on a
hotplug is good or bad. In any case, can somebody tell me to how do I get the available physical range map (only the ranges that VM is using at a given point in time) from userland. I believe I outlined a legitimate requirement earlier in this thread :-)

Let me paraphrase: exporting generic information in an architecture or firmware-specific way in sysfs is bad.

I apologize, but I think I missed yout legitimate requirements earlier in the thread. Could you briefly remind me?

-- Dave

#19 lore raw
Quoted 6 lines · Sourav Sen

Maybe. But the point I had in mind is, say for example memory diagnostics applications/exercisers which reads (Blind reads, without caring about contents) memory
to uncover errors (single bit errors) can use
this to know the usable ranges and map them thru /dev/mem and read those ranges.

If you expose the EFI memory map, then you'll be able to write memory diagnostics that will work on any EFI-based machine.

If you expose the EFI memory map in an architecture-independent fashion, then you'll be able to write diagnostics that will work on any *Linux* machine, plus all of the EFI machines. Plus, by doing it first, you get to greatly influence how the arch-independent stuff is done to make your life the easiest.

Think /sys/system/devices/memory, not /sys/firmware/efi.

We're planning on doing this anyway for memory hotplug, so some of the work and ideas are already there. I'd be happy to point you to some past discussions and code on the subject.

-- Dave

author
#20 lore raw

+ We're planning on doing this anyway for memory hotplug, so some of the
+ work and ideas are already there. I'd be happy to point you to some
+ past discussions and code on the subject.

Yes, please.

Thanks
Sourav

#21 lore raw
Quoted 3 lines · Sourav Sen

+ We're planning on doing this anyway for memory hotplug, so some of the
+ work and ideas are already there. I'd be happy to point you to some
+ past discussions and code on the subject.

Here was my sample implementation of how to export memory areas:

http://sourceforge.net/mailarchive/forum.php?thread_idA20609&forum_id"3

There was at least one other way to do the same thing on the lhms-devel list. I believe it was some time last month.

-- Dave