nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0300-mm-Debug-support-for-region-operations.patch

b35c50
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b35c50
From: Daniel Axtens <dja@axtens.net>
b35c50
Date: Thu, 21 Apr 2022 15:24:16 +1000
b35c50
Subject: [PATCH] mm: Debug support for region operations
b35c50
b35c50
This is handy for debugging. Enable with "set debug=regions".
b35c50
b35c50
Signed-off-by: Daniel Axtens <dja@axtens.net>
b35c50
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
b35c50
Tested-by: Patrick Steinhardt <ps@pks.im>
b35c50
(cherry picked from commit 8afa5ef45b797ba5d8147ceee85ac2c59dcc7f09)
b35c50
---
b35c50
 grub-core/kern/mm.c | 19 ++++++++++++++++---
b35c50
 1 file changed, 16 insertions(+), 3 deletions(-)
b35c50
b35c50
diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c
b35c50
index 7be33e23bf..38bfb01df9 100644
b35c50
--- a/grub-core/kern/mm.c
b35c50
+++ b/grub-core/kern/mm.c
b35c50
@@ -115,9 +115,8 @@ grub_mm_init_region (void *addr, grub_size_t size)
b35c50
   grub_mm_header_t h;
b35c50
   grub_mm_region_t r, *p, q;
b35c50
 
b35c50
-#if 0
b35c50
-  grub_printf ("Using memory for heap: start=%p, end=%p\n", addr, addr + (unsigned int) size);
b35c50
-#endif
b35c50
+  grub_dprintf ("regions", "Using memory for heap: start=%p, end=%p\n",
b35c50
+                addr, (char *) addr + (unsigned int) size);
b35c50
 
b35c50
   /* Exclude last 4K to avoid overflows. */
b35c50
   /* If addr + 0x1000 overflows then whole region is in excluded zone.  */
b35c50
@@ -142,8 +141,14 @@ grub_mm_init_region (void *addr, grub_size_t size)
b35c50
        * addr                          q
b35c50
        *   |----size-----|-q->pre_size-|<q region>|
b35c50
        */
b35c50
+      grub_dprintf ("regions", "Can we extend into region above?"
b35c50
+		    " %p + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " ?=? %p\n",
b35c50
+		    (grub_uint8_t *) addr, size, q->pre_size, (grub_uint8_t *) q);
b35c50
       if ((grub_uint8_t *) addr + size + q->pre_size == (grub_uint8_t *) q)
b35c50
         {
b35c50
+	  grub_dprintf ("regions", "Yes: extending a region: (%p -> %p) -> (%p -> %p)\n",
b35c50
+			q, (grub_uint8_t *) q + sizeof (*q) + q->size,
b35c50
+			addr, (grub_uint8_t *) q + sizeof (*q) + q->size);
b35c50
           /*
b35c50
            * Yes, we can merge the memory starting at addr into the
b35c50
            * existing region from below. Align up addr to GRUB_MM_ALIGN
b35c50
@@ -185,9 +190,15 @@ grub_mm_init_region (void *addr, grub_size_t size)
b35c50
        *   q                       addr
b35c50
        *   |<q region>|-q->post_size-|----size-----|
b35c50
        */
b35c50
+      grub_dprintf ("regions", "Can we extend into region below?"
b35c50
+                    " %p + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " + %" PRIxGRUB_SIZE " ?=? %p\n",
b35c50
+                    (grub_uint8_t *) q, sizeof(*q), q->size, q->post_size, (grub_uint8_t *) addr);
b35c50
       if ((grub_uint8_t *) q + sizeof (*q) + q->size + q->post_size ==
b35c50
 	  (grub_uint8_t *) addr)
b35c50
 	{
b35c50
+	  grub_dprintf ("regions", "Yes: extending a region: (%p -> %p) -> (%p -> %p)\n",
b35c50
+			q, (grub_uint8_t *) q + sizeof (*q) + q->size,
b35c50
+			q, (grub_uint8_t *) addr + size);
b35c50
 	  /*
b35c50
 	   * Yes! Follow a similar pattern to above, but simpler.
b35c50
 	   * Our header starts at address - post_size, which should align us
b35c50
@@ -213,6 +224,8 @@ grub_mm_init_region (void *addr, grub_size_t size)
b35c50
 	}
b35c50
     }
b35c50
 
b35c50
+  grub_dprintf ("regions", "No: considering a new region at %p of size %" PRIxGRUB_SIZE "\n",
b35c50
+		addr, size);
b35c50
   /* Allocate a region from the head.  */
b35c50
   r = (grub_mm_region_t) ALIGN_UP ((grub_addr_t) addr, GRUB_MM_ALIGN);
b35c50