Blame SOURCES/0297-mm-Document-GRUB-internal-memory-management-structur.patch

b35c50
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b35c50
From: Daniel Axtens <dja@axtens.net>
b35c50
Date: Thu, 25 Nov 2021 02:22:45 +1100
b35c50
Subject: [PATCH] mm: Document GRUB internal memory management structures
b35c50
b35c50
I spent more than a trivial quantity of time figuring out pre_size and
b35c50
whether a memory region's size contains the header cell or not.
b35c50
b35c50
Document the meanings of all the properties. Hopefully now no-one else
b35c50
has to figure it out!
b35c50
b35c50
Signed-off-by: Daniel Axtens <dja@axtens.net>
b35c50
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
b35c50
(cherry picked from commit a6c5c52ccffd2674d43db25fb4baa9c528526aa0)
b35c50
---
b35c50
 include/grub/mm_private.h | 28 ++++++++++++++++++++++++++++
b35c50
 1 file changed, 28 insertions(+)
b35c50
b35c50
diff --git a/include/grub/mm_private.h b/include/grub/mm_private.h
b35c50
index c2c4cb1511..203533cc3d 100644
b35c50
--- a/include/grub/mm_private.h
b35c50
+++ b/include/grub/mm_private.h
b35c50
@@ -21,15 +21,27 @@
b35c50
 
b35c50
 #include <grub/mm.h>
b35c50
 
b35c50
+/* For context, see kern/mm.c */
b35c50
+
b35c50
 /* Magic words.  */
b35c50
 #define GRUB_MM_FREE_MAGIC	0x2d3c2808
b35c50
 #define GRUB_MM_ALLOC_MAGIC	0x6db08fa4
b35c50
 
b35c50
+/* A header describing a block of memory - either allocated or free */
b35c50
 typedef struct grub_mm_header
b35c50
 {
b35c50
+  /*
b35c50
+   * The 'next' free block in this region's circular free list.
b35c50
+   * Only meaningful if the block is free.
b35c50
+   */
b35c50
   struct grub_mm_header *next;
b35c50
+  /* The block size, not in bytes but the number of cells of
b35c50
+   * GRUB_MM_ALIGN bytes. Includes the header cell.
b35c50
+   */
b35c50
   grub_size_t size;
b35c50
+  /* either free or alloc magic, depending on the block type. */
b35c50
   grub_size_t magic;
b35c50
+  /* pad to cell size: see the top of kern/mm.c. */
b35c50
 #if GRUB_CPU_SIZEOF_VOID_P == 4
b35c50
   char padding[4];
b35c50
 #elif GRUB_CPU_SIZEOF_VOID_P == 8
b35c50
@@ -48,11 +60,27 @@ typedef struct grub_mm_header
b35c50
 
b35c50
 #define GRUB_MM_ALIGN	(1 << GRUB_MM_ALIGN_LOG2)
b35c50
 
b35c50
+/* A region from which we can make allocations. */
b35c50
 typedef struct grub_mm_region
b35c50
 {
b35c50
+  /* The first free block in this region. */
b35c50
   struct grub_mm_header *first;
b35c50
+
b35c50
+  /*
b35c50
+   * The next region in the linked list of regions. Regions are initially
b35c50
+   * sorted in order of increasing size, but can grow, in which case the
b35c50
+   * ordering may not be preserved.
b35c50
+   */
b35c50
   struct grub_mm_region *next;
b35c50
+
b35c50
+  /*
b35c50
+   * A grub_mm_region will always be aligned to cell size. The pre-size is
b35c50
+   * the number of bytes we were given but had to skip in order to get that
b35c50
+   * alignment.
b35c50
+   */
b35c50
   grub_size_t pre_size;
b35c50
+
b35c50
+  /* How many bytes are in this region? (free and allocated) */
b35c50
   grub_size_t size;
b35c50
 }
b35c50
 *grub_mm_region_t;