badram filtering
PATCH 1/1 badram filtering
Hi,
This patch implements badram filtering in GRUB. It's the same idea as in
http://rick.vanrein.org/linux/badram/ but applied to GRUB.
The badram module sits between loaders (or other users like lsmmap) and filters the mmap entries, but only when user previously set the "badram" variable (whose syntax is the same as the one in badram patch for Linux).
NOTE this won't affect loadees that get the memory map from BIOS instead of from GRUB. This means it currently works for Multiboot and for the new/experimental Linux loader.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
2009-02-27 Robert Millan <[email protected]>
* conf/i386-pc.rmk (pkglib_MODULES): Add `badram.mod'. (badram_mod_SOURCES, badram_mod_CFLAGS) (badram_mod_LDFLAGS): New variables.
* conf/i386-coreboot.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* lib/badram.c: New file.
* include/grub/badram.h: New file.
* commands/lsmmap.c (grub_cmd_lsmmap): Replace grub_machine_mmap_iterate() with grub_badram_mmap_iterate ().
* loader/i386/linux.c (find_mmap_size, allocate_pages) (grub_linux32_boot): Likewise.
* loader/i386/pc/multiboot.c (grub_get_multiboot_mmap_len) (grub_fill_multiboot_mmap): Likewise.
i386-pc.rmk +5 -0
@@ -370,6 +370,11 @@ lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += badram.mod +badram_mod_SOURCES = lib/badram.c +badram_mod_CFLAGS = $(COMMON_CFLAGS) +badram_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For ata_pthru.mod. ata_pthru_mod_SOURCES = disk/ata_pthru.c ata_pthru_mod_CFLAGS = $(COMMON_CFLAGS)
i386-coreboot.rmk +5 -0
@@ -211,5 +211,10 @@ lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += badram.mod +badram_mod_SOURCES = lib/badram.c +badram_mod_CFLAGS = $(COMMON_CFLAGS) +badram_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk
powerpc-ieee1275.rmk +5 -0
@@ -181,5 +181,10 @@ lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += badram.mod +badram_mod_SOURCES = lib/badram.c +badram_mod_CFLAGS = $(COMMON_CFLAGS) +badram_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/common.mk
i386-ieee1275.rmk +5 -0
@@ -210,5 +210,10 @@ lsmmap_mod_SOURCES = commands/lsmmap.c lsmmap_mod_CFLAGS = $(COMMON_CFLAGS) lsmmap_mod_LDFLAGS = $(COMMON_LDFLAGS) +pkglib_MODULES += badram.mod +badram_mod_SOURCES = lib/badram.c +badram_mod_CFLAGS = $(COMMON_CFLAGS) +badram_mod_LDFLAGS = $(COMMON_LDFLAGS) + include $(srcdir)/conf/i386.mk include $(srcdir)/conf/common.mk
badram.c +127 -0
127 lines not on this page · raw message
grub/badram.h +29 -0
@@ -0,0 +1,29 @@ +/* +* GRUB -- GRand Unified Bootloader +* Copyright (C) 2009 Free Software Foundation, Inc. +* +* GRUB is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* GRUB is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with GRUB. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GRUB_BADRAM_HEADER +#define GRUB_BADRAM_HEADER 1 + +#include <grub/symbol.h> +#include <grub/types.h> +#include <grub/err.h> + +grub_err_t EXPORT_FUNC (grub_badram_mmap_iterate ) + (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t)); + +#endif
lsmmap.c +3 -3
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2008 Free Software Foundation, Inc. +* Copyright (C) 2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@* along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ -#include <grub/machine/memory.h> +#include <grub/badram.h> #include <grub/normal.h> #include <grub/dl.h> #include <grub/arg.h>
@@ -34,7 +34,7 @@ grub_cmd_lsmmap (struct grub_arg_list *s addr, size, type);return 0 ; } -grub_machine_mmap_iterate (hook); +grub_badram_mmap_iterate (hook);return 0 ; }
i386/linux.c +5 -4
@@ -1,6 +1,6 @@/* * GRUB -- GRand Unified Bootloader -* Copyright (C) 2006,2007,2008 Free Software Foundation, Inc. +* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@#include <grub/machine/machine.h> #include <grub/machine/memory.h> #include <grub/machine/loader.h> +#include <grub/badram.h> #include <grub/file.h> #include <grub/disk.h> #include <grub/err.h>
@@ -102,7 +103,7 @@ find_mmap_size (void)return 0 ; } -grub_machine_mmap_iterate (hook); +grub_badram_mmap_iterate (hook); mmap_size = count *sizeof (struct grub_e820_mmap );
@@ -173,7 +174,7 @@ allocate_pages (grub_size_t prot_size)return 0 ; } -grub_machine_mmap_iterate (hook); +grub_badram_mmap_iterate (hook);if (! real_mode_mem) {grub_error (GRUB_ERR_OUT_OF_MEMORY ,"cannot allocate real mode pages" );
@@ -258,7 +259,7 @@ grub_linux32_boot (void) } e820_num =0 ; -grub_machine_mmap_iterate (hook); +grub_badram_mmap_iterate (hook); params->mmap_size = e820_num;/* Hardware interrupts are not safe any longer. */
i386/pc/multiboot.c +3 -2
@@ -32,6 +32,7 @@#include <grub/multiboot.h> #include <grub/machine/init.h> #include <grub/machine/memory.h> +#include <grub/badram.h> #include <grub/elf.h> #include <grub/aout.h> #include <grub/file.h>
@@ -98,7 +99,7 @@ grub_get_multiboot_mmap_len (void)return 0 ; } -grub_machine_mmap_iterate (hook); +grub_badram_mmap_iterate (hook);return count *sizeof (struct grub_multiboot_mmap_entry ); }
@@ -121,7 +122,7 @@ grub_fill_multiboot_mmap (struct grub_mureturn 0 ; } -grub_machine_mmap_iterate (hook); +grub_badram_mmap_iterate (hook); }/* Check if BUFFER contains ELF32. */
Very interesting. I have following suggestions:
1) define platform independent way to enumerate memory map. This function wouldn't mark types with GRUB_MACHINE_* but with one of the following types:GRUB_MMAP_HOLE - means that at this position there is no RAM at all. Should this be iterated at all?GRUB_MMAP_IO - usable only by I/O driversGRUB_MMAP_FREE - usable by ACPI and firmware-unaware OS. But may be unusable by grub itself. memory allocator should be used for requesting memory in grubGRUB_MMAP_ACPI - usable by ACPI-aware OS after loading tables
GRUB_MMAP_PLATFORM_FIRST...GRUB_MMAP_PLATFORM_LAST - platform specific types which can't be used except by firmware-aware code and OS
2) when badram variable is set corresponding memory chunks should be removed from memory manager
3) add a method to specify badram in init.c so that grub2 itself has no risk of using any of this memory. I propose to embed initial environment in core.img. Then prefix and root can be changed to use this mechanism. It would also be able to override this initial environment through multiboot command line when grub2 is loaded by multiboot loader
Quoted 21 lines · Robert Millan
Hi,
This patch implements badram filtering in GRUB. It's the same idea as in
http://rick.vanrein.org/linux/badram/ but applied to GRUB.The badram module sits between loaders (or other users like lsmmap) and filters the mmap entries, but only when user previously set the "badram" variable (whose syntax is the same as the one in badram patch for Linux).
NOTE this won't affect loadees that get the memory map from BIOS instead of from GRUB. This means it currently works for Multiboot and for the new/experimental Linux loader.
------------------------------------------------------------------------
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
I've looked in depth in memory map and have seen that (1) is already done so except for EFI systems. And except that memory types are defined on per-machine basis. IMO generic memory types should be shared at the output of grub_machine_memory_iterate but it's not critical. I will code a similar function for EFI and adapt multiboot loader for EFI systems
Quoted 35 lines · phcoder
Very interesting. I have following suggestions:
1) define platform independent way to enumerate memory map. This function wouldn't mark types with GRUB_MACHINE_* but with one of the following types:GRUB_MMAP_HOLE- means that at this position there is no RAM at all. Should this be iterated at all?GRUB_MMAP_IO- usable only by I/O driversGRUB_MMAP_FREE- usable by ACPI and firmware-unaware OS. But may be unusable by grub itself. memory allocator should be used for requesting memory in grubGRUB_MMAP_ACPI- usable by ACPI-aware OS after loading tables
GRUB_MMAP_PLATFORM_FIRST...GRUB_MMAP_PLATFORM_LAST - platform specific types which can't be used except by firmware-aware code and OS
2) when badram variable is set corresponding memory chunks should be removed from memory manager
3) add a method to specify badram ininit.cso that grub2 itself has no risk of using any of this memory. I propose to embed initial environment in core.img. Then prefix and root can be changed to use this mechanism. It would also be able to override this initial environment through multiboot command line when grub2 is loaded by multiboot loaderQuoted 21 lines · Robert Millan
Hi,
This patch implements badram filtering in GRUB. It's the same idea as in
http://rick.vanrein.org/linux/badram/ but applied to GRUB.The badram module sits between loaders (or other users like lsmmap) and filters the mmap entries, but only when user previously set the "badram" variable (whose syntax is the same as the one in badram patch for Linux).
NOTE this won't affect loadees that get the memory map from BIOS instead of from GRUB. This means it currently works for Multiboot and for the new/experimental Linux loader.
------------------------------------------------------------------------
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko
Hello. I'm now writing the code to make multiboot and bsd work on EFI based on my grub_machine_memory_iterate for EFI. MY code will be the same for all i386 branches. It's quite complete except that I had no time yet to test it. I'l submit once it works
I was thinking and found another utility for badram: BIOS hooks. They are actually allocating take some memory and then removing it from mmap. If bios mmap hook and kernels get their mmap from the same source we can ensure that bios hooks won't be overwritten by the kernel independently how it acquired memory map. So I think badram patch should be extended to allow arbitrary additions to mmap. P.S. sorry if this e-mail isn't clear enough I've just had a long day of studies
Quoted 30 lines · phcoder
Quoted 28 lines
2) when badram variable is set corresponding memory chunks should be removed from memory manager
3) add a method to specify badram ininit.cso that grub2 itself has no risk of using any of this memory. I propose to embed initial environment in core.img. Then prefix and root can be changed to use this mechanism. It would also be able to override this initial environment through multiboot command line when grub2 is loaded by multiboot loaderQuoted 21 lines · Robert Millan
Hi,
This patch implements badram filtering in GRUB. It's the same idea as in
http://rick.vanrein.org/linux/badram/ but applied to GRUB.The badram module sits between loaders (or other users like lsmmap) and filters the mmap entries, but only when user previously set the "badram" variable (whose syntax is the same as the one in badram patch for Linux).
NOTE this won't affect loadees that get the memory map from BIOS instead of from GRUB. This means it currently works for Multiboot and for the new/experimental Linux loader.
------------------------------------------------------------------------
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'phcoder' Serbinenko