grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* lsefimmap patches for persistent memory
@ 2015-12-17  2:01 Elliott, Robert (Persistent Memory)
  2015-12-17  5:42 ` Andrei Borzenkov
  0 siblings, 1 reply; 2+ messages in thread
From: Elliott, Robert (Persistent Memory) @ 2015-12-17  2:01 UTC (permalink / raw)
  To: The development of GNU GRUB

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

I found another grub cli command that needs patches to
decode persistent memory: lsefimmap.

This patch series also enhances it to support TB-scale
sizes (which will not be uncommon for some persistent
memory technologies), not silently round the sizes, and
use proper IEC binary units.


Robert Elliott (5):
  lsefimmap: decode larger sizes
  lsefimmap: don't round sizes
  lsefimmap: add support for EfiPersistentMemory type
  lsefimmap: Decode EFI memory attributes new in UEFI 2.5
  lsefimmap: Use binary units

 grub-core/commands/efi/lsefimmap.c | 47 +++++++++++++++++++++++++-------------
 include/grub/efi/api.h             |  3 +++
 2 files changed, 34 insertions(+), 16 deletions(-)

-- 
2.4.3

---
Robert Elliott, HPE Persistent Memory



[-- Attachment #2: 0001-lsefimmap-decode-larger-sizes.patch --]
[-- Type: application/octet-stream, Size: 1528 bytes --]

From e6e7b07bc6e6deb9e939417b1581d05e1933adcc Mon Sep 17 00:00:00 2001
From: Robert Elliott <elliott@hpe.com>
Date: Wed, 16 Dec 2015 13:57:33 -0600
Subject: [PATCH 1/5] lsefimmap: decode larger sizes

The lsmmap command only decodes memory ranges sizes up to GiB scale
units.  Persistent memory ranges will reach into the TiB scale.

Since 64-bit size field supports TiB, PiB, and EiB, decode all of
them for completeness.
---
 grub-core/commands/efi/lsefimmap.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c
index 215b45b..f92d3b7 100644
--- a/grub-core/commands/efi/lsefimmap.c
+++ b/grub-core/commands/efi/lsefimmap.c
@@ -99,7 +99,25 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
 	  else
 	    {
 	      size /= 1024;
-	      grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size);
+	      if (size < 1024)
+	        grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size);
+	      else
+	        {
+	          size /= 1024;
+	          if (size < 1024)
+	            grub_printf (" %4" PRIuGRUB_UINT64_T "TB", size);
+	          else
+	            {
+	              size /= 1024;
+	              if (size < 1024)
+	                grub_printf (" %4" PRIuGRUB_UINT64_T "PB", size);
+	              else
+	                {
+	                  size /= 1024;
+	                  grub_printf (" %4" PRIuGRUB_UINT64_T "EB", size);
+	                }
+	            }
+	        }
 	    }
 	}
 
-- 
2.4.3


[-- Attachment #3: 0002-lsefimmap-don-t-round-sizes.patch --]
[-- Type: application/octet-stream, Size: 6012 bytes --]

From f838f56408a2c33f24216910fb465e52f222bf8d Mon Sep 17 00:00:00 2001
From: Robert Elliott <elliott@hpe.com>
Date: Wed, 16 Dec 2015 20:13:02 -0600
Subject: [PATCH 2/5] lsefimmap: don't round sizes

In the lsefimmap command, rewrite the print statements to
* avoid rounding
* avoid a big nested if/else tree.

For example: In the sixth entry, the value of 309MB implies 316416KB
but is really reporting 316436KB.

Widen the size column to 6 digits to accommodate typical cases.
The worst case value would require 14 digits; if that happens,
let the columns get out of sync.

Old format:
Type      Physical start  - end             #Pages     Size Attributes
conv-mem  0000000000000000-0000000000092fff 00000093  588KB UC WC WT WB
reserved  0000000000093000-0000000000093fff 00000001    4KB UC WC WT WB
conv-mem  0000000000094000-000000000009ffff 0000000c   48KB UC WC WT WB
conv-mem  0000000000100000-000000000fffffff 0000ff00  255MB UC WC WT WB
BS-code   0000000010000000-0000000010048fff 00000049  292KB UC WC WT WB
conv-mem  0000000010049000-000000002354dfff 00013505  309MB UC WC WT WB
ldr-data  000000002354e000-000000003ecfffff 0001b7b2  439MB UC WC WT WB
BS-data   000000003ed00000-000000003ed7ffff 00000080  512KB UC WC WT WB
conv-mem  000000003ed80000-000000006af5ffff 0002c1e0  705MB UC WC WT WB
reserved  000000006af60000-000000006b55ffff 00000600    6MB UC WC WT WB
BS-data   000000006b560000-000000006b560fff 00000001    4KB UC WC WT WB
RT-data   000000006b561000-000000006b5e1fff 00000081  516KB RT UC WC WT WB
BS-data   000000006b5e2000-000000006ecfafff 00003719   55MB UC WC WT WB
BS-code   000000006ecfb000-000000006ecfbfff 00000001    4KB UC WC WT WB
conv-mem  000000006ecfc000-00000000711fafff 000024ff   36MB UC WC WT WB
BS-data   00000000711fb000-000000007128dfff 00000093  588KB UC WC WT WB

New format:
Type      Physical start  - end             #Pages       Size Attributes
conv-mem  0000000000000000-0000000000092fff 00000093    588KB UC WC WT WB
reserved  0000000000093000-0000000000093fff 00000001      4KB UC WC WT WB
conv-mem  0000000000094000-000000000009ffff 0000000c     48KB UC WC WT WB
conv-mem  0000000000100000-000000000fffffff 0000ff00    255MB UC WC WT WB
BS-code   0000000010000000-0000000010048fff 00000049    292KB UC WC WT WB
conv-mem  0000000010049000-000000002354dfff 00013505 316436KB UC WC WT WB
ldr-data  000000002354e000-000000003ecfffff 0001b7b2 450248KB UC WC WT WB
BS-data   000000003ed00000-000000003ed7ffff 00000080    512KB UC WC WT WB
conv-mem  000000003ed80000-000000006af5ffff 0002c1e0 722816KB UC WC WT WB
reserved  000000006af60000-000000006b55ffff 00000600      6MB UC WC WT WB
BS-data   000000006b560000-000000006b560fff 00000001      4KB UC WC WT WB
RT-data   000000006b561000-000000006b5e1fff 00000081    516KB RT UC WC WT WB
BS-data   000000006b5e2000-000000006ecfafff 00003719  56420KB UC WC WT WB
BS-code   000000006ecfb000-000000006ecfbfff 00000001      4KB UC WC WT WB
conv-mem  000000006ecfc000-0000000071222fff 00002527  38044KB UC WC WT WB
BS-data   0000000071223000-00000000712ddfff 000000bb    748KB UC WC WT WB
---
 grub-core/commands/efi/lsefimmap.c | 56 ++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 33 deletions(-)

diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c
index f92d3b7..4e5af0c 100644
--- a/grub-core/commands/efi/lsefimmap.c
+++ b/grub-core/commands/efi/lsefimmap.c
@@ -51,7 +51,7 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
 
   grub_printf
     ("Type      Physical start  - end             #Pages   "
-     "  Size Attributes\n");
+     "    Size Attributes\n");
   memory_map_end = ADD_MEMORY_DESCRIPTOR (memory_map, map_size);
   for (desc = memory_map;
        desc < memory_map_end;
@@ -87,39 +87,29 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
 		   desc->physical_start + (desc->num_pages << 12) - 1,
 		   desc->num_pages);
 
-      size = desc->num_pages;
-      size <<= (12 - 10);
-      if (size < 1024)
-	grub_printf (" %4" PRIuGRUB_UINT64_T "KB", size);
+      size = desc->num_pages << 12;	/* 4 KiB page size */
+      /* 
+       * Since size is a multiple of 4 KiB, no need to handle units
+       * of just Bytes (which would use a mask of 0x3ff).
+       *
+       * 14 characters would support the largest possible number of 4 KiB
+       * pages that are not a multiple of larger units (e.g., MiB):
+       * 17592186044415 (0xffffff_fffff000), but that uses a lot of 
+       * whitespace for a rare case.  6 characters usually suffices; 
+       * columns will be off if not, but this is preferable to rounding.
+       */
+      if (size & 0xfffff)
+	grub_printf (" %6" PRIuGRUB_UINT64_T "KB", size >> 10);
+      else if (size & 0x3fffffff)
+	grub_printf (" %6" PRIuGRUB_UINT64_T "MB", size >> 20);
+      else if (size & 0xffffffffff)
+	grub_printf (" %6" PRIuGRUB_UINT64_T "GB", size >> 30);
+      else if (size & 0x3ffffffffffff)
+	grub_printf (" %6" PRIuGRUB_UINT64_T "TB", size >> 40);
+      else if (size & 0xfffffffffffffff)
+	grub_printf (" %6" PRIuGRUB_UINT64_T "PB", size >> 50);
       else
-	{
-	  size /= 1024;
-	  if (size < 1024)
-	    grub_printf (" %4" PRIuGRUB_UINT64_T "MB", size);
-	  else
-	    {
-	      size /= 1024;
-	      if (size < 1024)
-	        grub_printf (" %4" PRIuGRUB_UINT64_T "GB", size);
-	      else
-	        {
-	          size /= 1024;
-	          if (size < 1024)
-	            grub_printf (" %4" PRIuGRUB_UINT64_T "TB", size);
-	          else
-	            {
-	              size /= 1024;
-	              if (size < 1024)
-	                grub_printf (" %4" PRIuGRUB_UINT64_T "PB", size);
-	              else
-	                {
-	                  size /= 1024;
-	                  grub_printf (" %4" PRIuGRUB_UINT64_T "EB", size);
-	                }
-	            }
-	        }
-	    }
-	}
+	grub_printf (" %6" PRIuGRUB_UINT64_T "EB", size >> 60);
 
       attr = desc->attribute;
       if (attr & GRUB_EFI_MEMORY_RUNTIME)
-- 
2.4.3


[-- Attachment #4: 0003-lsefimmap-add-support-for-EfiPersistentMemory-type.patch --]
[-- Type: application/octet-stream, Size: 981 bytes --]

From 501f81f34cab0560e6e96992429cabd97f677b74 Mon Sep 17 00:00:00 2001
From: Robert Elliott <elliott@hpe.com>
Date: Wed, 16 Dec 2015 16:43:03 -0600
Subject: [PATCH 3/5] lsefimmap: add support for EfiPersistentMemory type

For the lsefimmap command, add a string for the EfiPersistentMemory type 14
that was added in UEFI 2.5.

This should accompany
	76ce1de740 Translate UEFI persistent memory type
---
 grub-core/commands/efi/lsefimmap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c
index 4e5af0c..4439658 100644
--- a/grub-core/commands/efi/lsefimmap.c
+++ b/grub-core/commands/efi/lsefimmap.c
@@ -74,7 +74,8 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
 	  "ACPI-nvs",
 	  "MMIO    ",
 	  "IO-ports",
-	  "PAL-code"
+	  "PAL-code",
+	  "persist ",
 	};
       if (desc->type < ARRAY_SIZE (types_str))
 	grub_printf ("%s ", types_str[desc->type]);
-- 
2.4.3


[-- Attachment #5: 0004-lsefimmap-Decode-EFI-memory-attributes-new-in-UEFI-2.patch --]
[-- Type: application/octet-stream, Size: 1777 bytes --]

From c5bb9b41b2a8d6db050368c3239b7145c99fb01b Mon Sep 17 00:00:00 2001
From: Robert Elliott <elliott@hpe.com>
Date: Wed, 16 Dec 2015 16:46:37 -0600
Subject: [PATCH 4/5] lsefimmap: Decode EFI memory attributes new in UEFI 2.5

For the lsefimmap command, decode the memory attributes that
were added in UEFI 2.5:
* NV (non-volatile)
* MORE_RELIABLE (higher reliable, e.g., mirrored memory in a system
  with partial memory mirroring)
* RO (read-only)
---
 grub-core/commands/efi/lsefimmap.c | 6 ++++++
 include/grub/efi/api.h             | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c
index 4439658..ef072cc 100644
--- a/grub-core/commands/efi/lsefimmap.c
+++ b/grub-core/commands/efi/lsefimmap.c
@@ -131,6 +131,12 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
 	grub_printf (" RP");
       if (attr & GRUB_EFI_MEMORY_XP)
 	grub_printf (" XP");
+      if (attr & GRUB_EFI_MEMORY_NV)
+	grub_printf (" NV");
+      if (attr & GRUB_EFI_MEMORY_MORE_RELIABLE)
+	grub_printf (" MR");
+      if (attr & GRUB_EFI_MEMORY_RO)
+	grub_printf (" RO");
 
       grub_printf ("\n");
     }
diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
index 2bbfe34..c7c9f0e 100644
--- a/include/grub/efi/api.h
+++ b/include/grub/efi/api.h
@@ -49,6 +49,9 @@
 #define GRUB_EFI_MEMORY_WP	0x0000000000001000LL
 #define GRUB_EFI_MEMORY_RP	0x0000000000002000LL
 #define GRUB_EFI_MEMORY_XP	0x0000000000004000LL
+#define GRUB_EFI_MEMORY_NV	0x0000000000008000LL
+#define GRUB_EFI_MEMORY_MORE_RELIABLE	0x0000000000010000LL
+#define GRUB_EFI_MEMORY_RO	0x0000000000020000LL
 #define GRUB_EFI_MEMORY_RUNTIME	0x8000000000000000LL
 
 #define GRUB_EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL	0x00000001
-- 
2.4.3


[-- Attachment #6: 0005-lsefimmap-Use-binary-units.patch --]
[-- Type: application/octet-stream, Size: 2137 bytes --]

From 437beb0951e5de1fe2254d44d844908e9390c75c Mon Sep 17 00:00:00 2001
From: Robert Elliott <elliott@hpe.com>
Date: Wed, 16 Dec 2015 20:14:40 -0600
Subject: [PATCH 5/5] lsefimmap: Use binary units

Use proper IEC binary units (KiB, MiB, etc.) for power-of-two
values rather than misusing SI power-of-ten units (KB, MB, etc.)
---
 grub-core/commands/efi/lsefimmap.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/grub-core/commands/efi/lsefimmap.c b/grub-core/commands/efi/lsefimmap.c
index ef072cc..5de6e45 100644
--- a/grub-core/commands/efi/lsefimmap.c
+++ b/grub-core/commands/efi/lsefimmap.c
@@ -51,7 +51,7 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
 
   grub_printf
     ("Type      Physical start  - end             #Pages   "
-     "    Size Attributes\n");
+     "     Size Attributes\n");
   memory_map_end = ADD_MEMORY_DESCRIPTOR (memory_map, map_size);
   for (desc = memory_map;
        desc < memory_map_end;
@@ -100,17 +100,17 @@ grub_cmd_lsefimmap (grub_command_t cmd __attribute__ ((unused)),
        * columns will be off if not, but this is preferable to rounding.
        */
       if (size & 0xfffff)
-	grub_printf (" %6" PRIuGRUB_UINT64_T "KB", size >> 10);
+	grub_printf (" %6" PRIuGRUB_UINT64_T "KiB", size >> 10);
       else if (size & 0x3fffffff)
-	grub_printf (" %6" PRIuGRUB_UINT64_T "MB", size >> 20);
+	grub_printf (" %6" PRIuGRUB_UINT64_T "MiB", size >> 20);
       else if (size & 0xffffffffff)
-	grub_printf (" %6" PRIuGRUB_UINT64_T "GB", size >> 30);
+	grub_printf (" %6" PRIuGRUB_UINT64_T "GiB", size >> 30);
       else if (size & 0x3ffffffffffff)
-	grub_printf (" %6" PRIuGRUB_UINT64_T "TB", size >> 40);
+	grub_printf (" %6" PRIuGRUB_UINT64_T "TiB", size >> 40);
       else if (size & 0xfffffffffffffff)
-	grub_printf (" %6" PRIuGRUB_UINT64_T "PB", size >> 50);
+	grub_printf (" %6" PRIuGRUB_UINT64_T "PiB", size >> 50);
       else
-	grub_printf (" %6" PRIuGRUB_UINT64_T "EB", size >> 60);
+	grub_printf (" %6" PRIuGRUB_UINT64_T "EiB", size >> 60);
 
       attr = desc->attribute;
       if (attr & GRUB_EFI_MEMORY_RUNTIME)
-- 
2.4.3


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

* Re: lsefimmap patches for persistent memory
  2015-12-17  2:01 lsefimmap patches for persistent memory Elliott, Robert (Persistent Memory)
@ 2015-12-17  5:42 ` Andrei Borzenkov
  0 siblings, 0 replies; 2+ messages in thread
From: Andrei Borzenkov @ 2015-12-17  5:42 UTC (permalink / raw)
  To: grub-devel

17.12.2015 05:01, Elliott, Robert (Persistent Memory) пишет:
> I found another grub cli command that needs patches to
> decode persistent memory: lsefimmap.
> 
> This patch series also enhances it to support TB-scale
> sizes (which will not be uncommon for some persistent
> memory technologies), not silently round the sizes, and
> use proper IEC binary units.
> 
> 
> Robert Elliott (5):
>   lsefimmap: decode larger sizes
>   lsefimmap: don't round sizes
>   lsefimmap: add support for EfiPersistentMemory type
>   lsefimmap: Decode EFI memory attributes new in UEFI 2.5
>   lsefimmap: Use binary units
> 
>  grub-core/commands/efi/lsefimmap.c | 47 +++++++++++++++++++++++++-------------
>  include/grub/efi/api.h             |  3 +++
>  2 files changed, 34 insertions(+), 16 deletions(-)
> 

At least 1, 2 and 5 should be merged, but I do not see why this needs
splitting in separate paches. Could you send combined patch, please?
Thank you.


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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-17  2:01 lsefimmap patches for persistent memory Elliott, Robert (Persistent Memory)
2015-12-17  5:42 ` Andrei Borzenkov

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).