grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* grub causing NVDIMMs to be treated as normal memory
@ 2015-11-24 23:52 Elliott, Robert (Persistent Memory)
  2015-11-25 14:08 ` Andrei Borzenkov
  2015-11-25 18:36 ` Andrei Borzenkov
  0 siblings, 2 replies; 23+ messages in thread
From: Elliott, Robert (Persistent Memory) @ 2015-11-24 23:52 UTC (permalink / raw)
  To: dan.j.williams@intel.com, linux-nvdimm@lists.01.org,
	grub-devel@gnu.org
  Cc: Knippers, Linda, Kani, Toshimitsu

[-- Attachment #1: Type: text/plain, Size: 3922 bytes --]

We've noticed that some combinations of grub and old linux kernels

end up interpreting the UEFI memory map EfiPersistentMemory type 14

(formerly a reserved value) as regular memory in the linux e820

table, causing silent data corruption on the NVDIMMs.  That occurs

even though grub prints this message suggesting everything is safe:

    Unknown memory type 14, considering reserved



In broken versions of grub, the code parsing the UEFI memory map

has a "default" case that falls through to the

GRUB_EFI_BOOT_SERVICES_DATA case, which marks the memory range

as GRUB_MEMORY_AVAILABLE and ends up in e820 as regular memory.



In unbroken versions of grub, that "default" case falls through to

the GRUB_EFI_RESERVED_MEMORY_TYPE case, which marks the memory range

as GRUB_MACHINE_MEMORY_RESERVED and ends up in e820 as reserved.



Each of these kernels behaves differently:

* without EFI boot stub (pre-2011 kernel 3.3)

* with EFI boot stub (May 2015, kernel 4.1)

* with EFI boot stub, with May 2015 patch to understand type 14



Kernels that don't have the EFI boot stub are at the mercy of how

grub translates the memory map.  I'm not sure how the pre-4.1

EFI boot stub kernels worked. New kernels work fine.



Does anyone know how prevalent the use of dangerous combinations

might be?



Might other OS loaders (syslinux, elilo, ?) have issues like this?





Example broken grub code

========================

http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/mmap/efi/mmap.c:



grub_efi_mmap_iterate (grub_memory_hook_t hook, void *hook_data,

                     int avoid_efi_boot_services)

{

...

       case GRUB_EFI_UNUSABLE_MEMORY:

         hook (desc->physical_start, desc->num_pages * 4096,

              GRUB_MEMORY_BADRAM, hook_data);

         break;



       default:

         grub_printf ("Unknown memory type %d, considering reserved\n",

                     desc->type);



       case GRUB_EFI_BOOT_SERVICES_DATA:

         if (!avoid_efi_boot_services)

           {

             hook (desc->physical_start, desc->num_pages * 4096,

                  GRUB_MEMORY_AVAILABLE, hook_data);

             break;

           }

       case GRUB_EFI_RESERVED_MEMORY_TYPE:

       case GRUB_EFI_RUNTIME_SERVICES_DATA:

       case GRUB_EFI_MEMORY_MAPPED_IO:

       case GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE:

       case GRUB_EFI_PAL_CODE:

         hook (desc->physical_start, desc->num_pages * 4096,

              GRUB_MEMORY_RESERVED, hook_data);

         break;



Example unbroken grub code

==========================

https://github.com/jolicloud/grub2/blob/master/mmap/efi/mmap.c:



grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,

                                                grub_uint64_t,

                                                grub_uint32_t))

{

...

       default:

         grub_printf ("Unknown memory type %d, considering reserved\n",

                     desc->type);



       case GRUB_EFI_RESERVED_MEMORY_TYPE:

       case GRUB_EFI_RUNTIME_SERVICES_DATA:

       case GRUB_EFI_UNUSABLE_MEMORY:

       case GRUB_EFI_MEMORY_MAPPED_IO:

       case GRUB_EFI_MEMORY_MAPPED_IO_PORT_SPACE:

       case GRUB_EFI_PAL_CODE:

         hook (desc->physical_start, desc->num_pages * 4096,

              GRUB_MACHINE_MEMORY_RESERVED);

         break;



       case GRUB_EFI_LOADER_CODE:

       case GRUB_EFI_LOADER_DATA:

       case GRUB_EFI_BOOT_SERVICES_CODE:

       case GRUB_EFI_BOOT_SERVICES_DATA:

       case GRUB_EFI_CONVENTIONAL_MEMORY:

         hook (desc->physical_start, desc->num_pages * 4096,

              GRUB_MACHINE_MEMORY_AVAILABLE);

         break;


---
Robert Elliott, HPE Persistent Memory


[-- Attachment #2: Type: text/html, Size: 12391 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2015-12-29 17:17 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-24 23:52 grub causing NVDIMMs to be treated as normal memory Elliott, Robert (Persistent Memory)
2015-11-25 14:08 ` Andrei Borzenkov
2015-11-25 16:51   ` Dan Williams
2015-11-25 17:04   ` Elliott, Robert (Persistent Memory)
2015-11-25 17:07   ` Seth Goldberg
2015-11-25 18:36 ` Andrei Borzenkov
2015-11-26  0:12   ` Elliott, Robert (Persistent Memory)
2015-11-26  3:30     ` Andrei Borzenkov
2015-11-26  6:15       ` Elliott, Robert (Persistent Memory)
2015-11-26 16:55         ` Andrei Borzenkov
2015-11-26 23:24           ` Elliott, Robert (Persistent Memory)
2015-11-27  3:58             ` Andrei Borzenkov
2015-11-27  6:22               ` Elliott, Robert (Persistent Memory)
2015-11-27 11:08                 ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-27 11:48                   ` Andrei Borzenkov
2015-11-27 13:55                     ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-27 17:23                       ` Andrei Borzenkov
2015-11-28  6:41                   ` Elliott, Robert (Persistent Memory)
2015-12-01  0:25                     ` Elliott, Robert (Persistent Memory)
2015-12-03 17:50                     ` Elliott, Robert (Persistent Memory)
2015-12-08 17:15                       ` Andrei Borzenkov
2015-12-09  6:37                         ` Elliott, Robert (Persistent Memory)
2015-12-29 17:17                     ` Vladimir 'φ-coder/phcoder' Serbinenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).