Reserving physical memory at boot time
I would like to reserve a particular page of physical memory when the kernel boots. By reserving I mean that no one else gets to read from it or write to it: it is mine. Any suggestions for the best way to go about this with a 2.5 kernel?
Thanks,
Duncan.
Quoted 8 lines · Duncan Sands
I would like to reserve a particular page of physical memory when the kernel boots. By reserving I mean that no one else gets to read from it or write to it: it is mine. Any suggestions for the best way to go about this with a 2.5 kernel?
Thanks,
Duncan.
If you need a certain page reserved at boot-time you are out-of-luck. You can tell the kernel (using mem=xxx on the boot command line) that you have somewhat less memory than you do and then you can write a module that accesses the other memory that the kernel doesn't use.
If you just want to make sure that your module owns a particular page that nobody else uses, just use ioremap() in your module to allocate a particular address. Those page(s) are now owned by your module and will never be paged. You can access those pages from user-space by providing some connectivity in your module (like read()/write()/ioctl()).
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
Quoted 6 lines · Alan Cox
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
short question - is it also possible to mark some "bad addresses" in a quite similar way ? I know RAM is cheep these days but...
Memory with just one bad address or two would be good enough to be able to use them in a desktop pc again if the kernel could make sure that these addresses will never be accessed/used from anyone.
Next step for HA in servers then would be a memory raid ;-) but for sure big blue holds some patents on this :(
Signature · 2 lines
Bjoern A. Zeeb bzeeb at Zabbadoz dot NeT 56 69 73 69 74 http://www.zabbadoz.net/
Quoted 7 lines · Alan Cox
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
If you are refering to the "reserve=" kernel parameter, I don't think it works for memory addresses that are inside existing RAM. I guess if you used the "mem=" parameter to keep the kernel from using that RAM, the combination might work, but I have never tried it.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America
A message that is not in the archive (sent off-list or not yet received): [email protected]
om
Quoted 10 lines · Richard B. Johnson
Quoted 7 lines · Alan Cox
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
Quoted 5 lines
If you are refering to the "reserve=" kernel parameter, I don't think it works for memory addresses that are inside existing RAM. I guess if you used the "mem=" parameter to keep the kernel from using that RAM, the combination might work, but I have never tried it.
reserve= is for IO ports (kernel/resource.c). I think Alan was referring to mem=exactmap.
If Duncan didn't have the pesky requirement that his module work in an unmodified kernel, it would be easy to use __alloc_bootmem() to reserve an address range and expose via /proc. But alas...
-Mike
Quoted 17 lines · Mike Galbraith
Quoted 10 lines · Richard B. Johnson
Quoted 7 lines · Alan Cox
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
Quoted 5 lines
If you are refering to the "reserve=" kernel parameter, I don't think it works for memory addresses that are inside existing RAM. I guess if you used the "mem=" parameter to keep the kernel from using that RAM, the combination might work, but I have never tried it.
Quoted 9 lines
reserve= is for IO ports (
kernel/resource.c). I think Alan was referring to mem=exactmap.If Duncan didn't have the pesky requirement that his module work in an unmodified kernel, it would be easy to use
__alloc_bootmem()to reserve an address range and expose via /proc. But alas...-Mike
Well that parameter is not documented in:
.../linux-2.4.18/Documentation/kernel-parameters.txt.
Perhaps it's a 2.5.++ thing.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Bush : The Fourth Reich of America
On Wed, 4 Dec 2002, Richard B. Johnson wrote:
| On Wed, 4 Dec 2002, Mike Galbraith wrote: | | > At 08:25 AM 12/4/2002 -0500, Richard B. Johnson wrote: | > >On 3 Dec 2002, Alan Cox wrote: | > > | > > > On Tue, 2002-12-03 at 21:11, Richard B. Johnson wrote: | > > > > If you need a certain page reserved at boot-time you are out-of-luck. | > > > | > > > Wrong - you can specify the precise memory map of a box as well as use | > > > mem= to set the top of used memory. Its a painful way of marking a page | > > > and it only works for a page the kernel isnt loaded into. | > > > | > > | > >If you are refering to the "reserve=" kernel parameter, I don't | > >think it works for memory addresses that are inside existing RAM. | > >I guess if you used the "mem=" parameter to keep the kernel from | > >using that RAM, the combination might work, but I have never | > >tried it. | > | > reserve= is for IO ports (kernel/resource.c). I think Alan was referring to | > mem=exactmap. | > | > If Duncan didn't have the pesky requirement that his module work in an | > unmodified kernel, it would be easy to use __alloc_bootmem() to reserve an | > address range and expose via /proc. But alas... | > | | Well that parameter is not documented in: | | .../linux-2.4.18/Documentation/kernel-parameters.txt. | | Perhaps it's a 2.5.++ thing.
Patch for 'mem=exactmap' in 2.4 was submitted several weeks ago and Alan merged it into -ac. It does need to be pushed to Marcelo...
Signature · 1 line
~Randy
Followup to: <[email protected]> By author: "Randy.Dunlap" <[email protected]> In newsgroup: linux.dev.kernel
Quoted 4 lines
Patch for 'mem=exactmap' in 2.4 was submitted several weeks ago and Alan merged it into -ac. It does need to be pushed to Marcelo...
Once again, with feeling...
DON'T CALL IT mem=.
mem= is part of the boot protocol.
Call it memmap= or something, or you'll break boot loaders in weird and subtle ways.
-hpa
Signature · 3 lines
<[email protected]> at work, <[email protected]> in private! "Unix gives you enough rope to shoot yourself in the foot." Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
Quoted 9 lines
Followup to:
<[email protected]> By author:
"Randy.Dunlap" <[email protected]>
In newsgroup: linux.dev.kernelQuoted 4 lines
Patch for 'mem=exactmap' in 2.4 was submitted several weeks ago and Alan merged it into -ac. It does need to be pushed to Marcelo...
Quoted 7 lines
Once again, with feeling...
DON'T CALL IT mem=.
mem= is part of the boot protocol.
Call it memmap= or something, or you'll break boot loaders in weird and subtle ways.
OK, with feeling:
I agree with you since the boot protocol is well-defined.
Just to be clear, my comment was referring to Documentation/kernel-parameters.txt, not to any C code.
And it would really be helpful to catch issues like this soon after they happen...
Thanks,
~Randy
Followup to: <[email protected]> By author: "Randy.Dunlap" <[email protected]> In newsgroup: linux.dev.kernel
Quoted 11 lines
OK, with feeling:
I agree with you since the boot protocol is well-defined.
Just to be clear, my comment was referring to
Documentation/kernel-parameters.txt, not to any C code.And it would really be helpful to catch issues like this soon after they happen...
Unfortunately last time I commented on this the response was roughly "well, the patch already made it into Linus' kernel, it's too late to fix it now." That isn't exactly a very helpful response.
The mem= parameter has the semantic in the i386/PC boot protocol that it specifies the top address of the usable memory region that begins at 0x100000. It's a bit of a wart that the boot loaders have to be aware of this, but it's so and it's been so for a very long time.
-hpa
Signature · 3 lines
<[email protected]> at work, <[email protected]> in private! "Unix gives you enough rope to shoot yourself in the foot." Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64
On 5 Mar 2003 07:04:51 -0800
"H. Peter Anvin" <[email protected]> wrote:
| Followup to: <[email protected]> | By author: "Randy.Dunlap" <[email protected]> | In newsgroup: linux.dev.kernel | > | > OK, with feeling: | > | > I agree with you since the boot protocol is well-defined. | > | > Just to be clear, my comment was referring to | > Documentation/kernel-parameters.txt, not to any C code. | > | > And it would really be helpful to catch issues like this soon | > after they happen... | > | | Unfortunately last time I commented on this the response was roughly | "well, the patch already made it into Linus' kernel, it's too late to | fix it now." That isn't exactly a very helpful response.
I don't see why it's too late. How can it be too late? Ah, because it's already made it into 2.4?
| The mem= parameter has the semantic in the i386/PC boot protocol that | it specifies the top address of the usable memory region that begins | at 0x100000. It's a bit of a wart that the boot loaders have to be | aware of this, but it's so and it's been so for a very long time.
So it's the top of the 0x100000-mem physical linear memory region (i.e., no gaps)?
--
~Randy
Quoted 7 lines · Randy.Dunlap
| | Unfortunately last time I commented on this the response was roughly | "well, the patch already made it into Linus' kernel, it's too late to | fix it now." That isn't exactly a very helpful response.I don't see why it's too late. How can it be too late? Ah, because it's already made it into 2.4?
More because people don't want to fix their mistakes, I suspect :(
I don't know who originally started adding stuff to "mem=", but I still feel it needs to be backed out and renamed.
Quoted 7 lines
| The mem= parameter has the semantic in the i386/PC boot protocol that | it specifies the top address of the usable memory region that begins | at 0x100000. It's a bit of a wart that the boot loaders have to be | aware of this, but it's so and it's been so for a very long time.So it's the top of the 0x100000-mem physical linear memory region (i.e., no gaps)?
Correct.
Hi!
Quoted 11 lines
Quoted 10 lines
OK, with feeling:
I agree with you since the boot protocol is well-defined.
Just to be clear, my comment was referring to
Documentation/kernel-parameters.txt, not to any C code.And it would really be helpful to catch issues like this soon after they happen...
Quoted 8 lines
Unfortunately last time I commented on this the response was roughly "well, the patch already made it into Linus' kernel, it's too late to fix it now." That isn't exactly a very helpful response.
The mem= parameter has the semantic in the i386/PC boot protocol that it specifies the top address of the usable memory region that begins at
0x100000. It's a bit of a wart that the boot loaders have to be aware of this, but it's so and it's been so for a very long time.
Really? So user has to know where ACPI tables are and specify less than that on mem= command line? That seems very counter-intuitive. [Ahha, its probaly okay because e820 saves you.]
What do you pass on 4GB machine as mem= parameter? AFAIK those beasts have hole at 3.75G. [Hopefully bigmem machines have working e820 tables?]
Pavel
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Quoted 9 lines · Pavel Machek
Really? So user has to know where ACPI tables are and specify less than that on mem= command line? That seems very counter-intuitive. [Ahha, its probaly okay because e820 saves you.]
What do you pass on 4GB machine as mem= parameter? AFAIK those beasts have hole at 3.75G. [Hopefully bigmem machines have working e820 tables?]
If you pass mem= you have to pass mem=3840M. Yes, it sucks, but if you genuinely have a machine which is so fucked up that you can't rely on the memory map the BIOS presents to you, you have problems to begin with.
Oh yes, this is why GRUB passing the mem= parameter gratuitously was beyond total and complete brainfuckage.
-hpa
Hi!
Quoted 9 lines
Quoted 8 lines
Really? So user has to know where ACPI tables are and specify less than that on mem= command line? That seems very counter-intuitive. [Ahha, its probaly okay because e820 saves you.]
What do you pass on 4GB machine as mem= parameter? AFAIK those beasts have hole at 3.75G. [Hopefully bigmem machines have working e820 tables?]
Quoted 6 lines
If you pass mem= you have to pass mem=3840M. Yes, it sucks, but if you genuinely have a machine which is so fucked up that you can't rely on the memory map the BIOS presents to you, you have problems to begin with.
Oh yes, this is why GRUB passing the mem= parameter gratuitously was beyond total and complete brainfuckage.
Okay; which mem= options you want killed?
What about this?
Pavel
arch/i386/kernel/setup.c +23 -3
@@ -527,6 +527,9 @@* to <mem>, overriding the bios size. * "mem=XXX[KkmM]@XXX[KkmM]" defines a memory region from * <start> to <start>+<mem>, overriding the bios size. +* +* HPA tells me bootloaders need to parse mem=, so no new +* option should be mem= */ if (c ==' ' && !memcmp (from,"mem=" ,4 )) {if (to != command_line)
@@ -535,8 +538,24 @@ from +=9 +4 ;clear_bit (X86_FEATURE_PSE , boot_cpu_data.x86_capability); disable_pse =1 ; - }else if (!memcmp (from+4 ,"exactmap" ,8 )) { - from +=8 +4 ; + }else { +/* If the user specifies memory size, we +* limit the BIOS-provided memory map to +* that size. exactmap can be used to specify +* the exact map. mem=number can be used to +* trim the existing memory map. +*/ +unsigned long long start_at, mem_size; + + mem_size =memparse (from+4 , &from); + } + } + +if (c ==' ' && !memcmp (from,"memmap=" ,7 )) { +if (to != command_line) + to--; +if (!memcmp (from+7 ,"exactmap" ,8 )) { + from +=8 +7 ; e820.nr_map =0 ; userdef =1 ; }else {
@@ -548,7 +567,7 @@*/ unsigned long long start_at, mem_size; - mem_size =memparse (from+4 , &from); + mem_size =memparse (from+7 , &from);if (*from =='@' ) { start_at =memparse (from+1 , &from);add_memory_region (start_at, mem_size,E820_RAM );
@@ -565,6 +584,7 @@ } } +/* "acpi=off" disables both ACPI table parsing and interpreter init */ if (c ==' ' && !memcmp (from,"acpi=off" ,8 )) acpi_disabled =1 ;
Signature · 2 lines
When do you have a heart between your knees? [Johanka's followup: and *two* hearts?]
Quoted 3 lines · Pavel Machek
Okay; which mem= options you want killed?
Anything that doesn't match the regexp (in Perl syntax):
/^mem=(0[0-7]*|[1-9][0-9]*|0x[0-9a-f]+)[kmg]$/i
Quoted 1 line
What about this?
Looks good to me.
Quoted 60 lines
Pavel
arch/i386/kernel/setup.c +23
-3@@ -527,6 +527,9 @@* to <mem>, overriding the bios size. * "mem=XXX[KkmM]@XXX[KkmM]" defines a memory region from * <start> to <start>+<mem>, overriding the bios size. +* +* HPA tells me bootloaders need to parse mem=, so no new +* option should be mem= */ if (c ==' ' && !memcmp (from,"mem=" ,4 )) {if (to != command_line)@@ -535,8 +538,24 @@ from +=9 +4 ;clear_bit (X86_FEATURE_PSE , boot_cpu_data.x86_capability); disable_pse =1 ; - }else if (!memcmp (from+4 ,"exactmap" ,8 )) { - from +=8 +4 ; + }else { +/* If the user specifies memory size, we +* limit the BIOS-provided memory map to +* that size. exactmap can be used to specify +* the exact map. mem=number can be used to +* trim the existing memory map. +*/ +unsigned long long start_at, mem_size; + + mem_size =memparse (from+4 , &from); + } + } + +if (c ==' ' && !memcmp (from,"memmap=" ,7 )) { +if (to != command_line) + to--; +if (!memcmp (from+7 ,"exactmap" ,8 )) { + from +=8 +7 ; e820.nr_map =0 ; userdef =1 ; }else {@@ -548,7 +567,7 @@*/ unsigned long long start_at, mem_size; - mem_size =memparse (from+4 , &from); + mem_size =memparse (from+7 , &from);if (*from =='@' ) { start_at =memparse (from+1 , &from);add_memory_region (start_at, mem_size,E820_RAM );@@ -565,6 +584,7 @@ } } +/* "acpi=off" disables both ACPI table parsing and interpreter init */ if (c ==' ' && !memcmp (from,"acpi=off" ,8 )) acpi_disabled =1 ;
Quoted 5 lines
Quoted 3 lines · Pavel Machek
Okay; which mem= options you want killed?
Quoted 7 lines
Anything that doesn't match the regexp (in Perl syntax):
/^mem=(0[0-7]*|[1-9][0-9]*|0x[0-9a-f]+)[kmg]$/i
Quoted 1 line
What about this?
Looks good to me.
Thanks, Pavel. You beat me to it.
~Randy
Quoted 15 lines · Mike Galbraith
Quoted 8 lines · Richard B. Johnson
Quoted 6 lines · Alan Cox
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
Quoted 5 lines
If you are refering to the "reserve=" kernel parameter, I don't think it works for memory addresses that are inside existing RAM. I guess if you used the "mem=" parameter to keep the kernel from using that RAM, the combination might work, but I have never tried it.
Quoted 6 lines
reserve= is for IO ports (
kernel/resource.c). I think Alan was referring to mem=exactmap.If Duncan didn't have the pesky requirement that his module work in an unmodified kernel, it would be easy to use
__alloc_bootmem()to reserve an address range and expose via /proc. But alas...
I actually said I was happy to modify the kernel! As for __alloc_bootmem(), based on my quick reading of the implementation in 2.5.50, I don't see how you can be sure it will give you a particular physical page. I would like to either get the page I want, or fail.
Thanks for your help,
Duncan.
Quoted 19 lines · Duncan Sands
Quoted 18 lines · Mike Galbraith
Quoted 8 lines · Richard B. Johnson
Quoted 6 lines · Alan Cox
Quoted 1 line · Richard B. Johnson
If you need a certain page reserved at boot-time you are out-of-luck.
Wrong - you can specify the precise memory map of a box as well as use mem= to set the top of used memory. Its a painful way of marking a page and it only works for a page the kernel isnt loaded into.
Quoted 5 lines
If you are refering to the "reserve=" kernel parameter, I don't think it works for memory addresses that are inside existing RAM. I guess if you used the "mem=" parameter to keep the kernel from using that RAM, the combination might work, but I have never tried it.
reserve= is for IO ports (
kernel/resource.c). I think Alan was referring to mem=exactmap.
Quoted 8 lines
Quoted 3 lines
If Duncan didn't have the pesky requirement that his module work in an unmodified kernel, it would be easy to use
__alloc_bootmem()to reserve an address range and expose via /proc. But alas...I actually said I was happy to modify the kernel! As for
__alloc_bootmem(), based on my quick reading of the implementation in 2.5.50, I don't see how you can be sure it will give you a particular physical page. I would like to either get the page I want, or fail.
Sorry, mixed you up with someone else. Seems to me you could just create a new __setup("reservepage=", gimme_page) where gimme_page() allocates with goal set, and frees/aborts if what it gets back isn't exactly what you asked for.
-Mike
Quoted 1 line
If you need a certain page reserved at boot-time you are out-of-luck.
I don't mind modifying the kernel.
Duncan.
Quoted 3 lines · Duncan Sands
Quoted 1 line
If you need a certain page reserved at boot-time you are out-of-luck.
I don't mind modifying the kernel.
Makes it easier to mark pages - look at how the e820 code works and mark the page in question reserved as it does.
Quoted 4 lines · Duncan Sands
I would like to reserve a particular page of physical memory when the kernel boots. By reserving I mean that no one else gets to read from it or write to it: it is mine. Any suggestions for the best way to go about this with a 2.5 kernel?
try having a look for the linux badmem patches i belive they might do the same sort of thing.
James
On 3 Dec 2002, James Stevenson wrote:
| On Tue, 2002-12-03 at 12:03, Duncan Sands wrote: | > I would like to reserve a particular page of physical memory when | > the kernel boots. By reserving I mean that no one else gets to read | > from it or write to it: it is mine. Any suggestions for the best way | > to go about this with a 2.5 kernel? | | try having a look for the linux badmem patches i belive they might do | the same sort of thing.
see http://badmem.sourceforge.net/
Signature · 1 line
~Randy