Skip to contentSkip to conversation

kern/ieee1275/init: ppc64: Add support for alignment requirements

PATCH Stefan Berger 2 participants 4 messages Oct 28, 2023 – Oct 31, 2023 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 22 lines · Stefan Berger

Add support for memory alignment requirements and adjust a candidate address to it before checking whether the block is large enough since the alignment adjustment can make a block smaller than what was requested.

Cc Hari Bathini <[email protected]>
Cc Pavithra Prakash <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Carolyn Scherrer <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Sourabh Jain <[email protected]>
---
  grub-core/kern/ieee1275/init.c        | 10 ++++++++++
  include/grub/powerpc/ieee1275/alloc.h |  1 +
  2 files changed, 11 insertions(+)
grub-core/kern/ieee1275/init.c +0 -0
index a0ce9d55e..5414f659c 100644

grub-core/kern/ieee1275/init.c regions_claim (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type, · line 515

Quoted 10 lines
grub-core/kern/ieee1275/init.c +7 -0
@@ -506,6 +506,16 @@ regions_claim (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type,
              }
          }
      }
+
+  /* Honor alignment restrictions on candidate addr */
+  if (rcr->align)
+    {
+      grub_uint64_t align_addr = ALIGN_UP (addr, rcr->align);
+
+      len = len - (align_addr - addr);

In v2 this will look like this:

      grub_uint64_t align_addr = ALIGN_UP (addr, rcr->align); grub_uint64_t d = align_addr - addr;

      if (d > len)
        return 0;

      len -= d;

Quoted 11 lines
grub-core/kern/ieee1275/init.c +3 -0
+      addr = align_addr;
+    }
+
    if (rcr->flags & GRUB_MM_ADD_REGION_CONSECUTIVE && len < rcr->total)
      return 0;
 
include/grub/powerpc/ieee1275/alloc.h +0 -0
index 136e1df0b..b3d14f095 100644

include/grub/powerpc/ieee1275/alloc.h struct regions_claim_request { · line 17

Quoted 7 lines
include/grub/powerpc/ieee1275/alloc.h +1 -0
@@ -11,6 +11,7 @@ struct regions_claim_request {
    bool init_region;       /* whether to init the region */
    grub_uint64_t addr;     /* result address */
    grub_uint64_t len;      /* number of bytes allocated */
+  grub_size_t align;      /* alignment restrictions */
  };
 
  #endif /* GRUB_POWERPC_IEEE1275_ALLOC_HEADER */

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw

Re: [PATCH 0/8] ppc64: Restrict memory allocations for kernel and initrd

In reply to a message not in the archive
Quoted 8 lines · Stefan Berger

This series of patches converts the memory allocator for kernel and initrd to use the ppc64 regions_claim memory allocator that takes into account memory regions that are not allowed to be used, such as the gap between 640MB and 768MB as well as memory regions beyond an upper address in case an fadump is present. Otherwise those two could be loaded into those forbidden memory regions and either cause a crash or corruption of the fadump.

Quoted 8 lines

I adjusted the kernel and initrd load in loader/powerpc/ieee1275 to use the new memory allocator. I am not aware of which other platforms besides PowerVM and PowerKVM, if any, may be using this code and so I did not touch the functions loading 32 bit kernels, which the targeted platform does not typically use.

The last patch is for viewing where the memory allocations are going and is not to be applied, of course.

I am not entirely convinced we need this for the upcoming release. My concern is that this patch set makes a lot of changes. OK, they are mostly limited to the IEEE 1275 stuff but...

Anyway, quick glance through the patches revealed that most of them missing explanation why they are really needed. At least... Please fix these things...

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

Re: [PATCH 0/8] ppc64: Restrict memory allocations for kernel and initrd

Quoted 15 lines · Daniel Kiper
Quoted 14 lines · Stefan Berger

This series of patches converts the memory allocator for kernel and initrd to use the ppc64 regions_claim memory allocator that takes into account memory regions that are not allowed to be used, such as the gap between 640MB and 768MB as well as memory regions beyond an upper address in case an fadump is present. Otherwise those two could be loaded into those forbidden memory regions and either cause a crash or corruption of the fadump.

I adjusted the kernel and initrd load in loader/powerpc/ieee1275 to use the new memory allocator. I am not aware of which other platforms besides PowerVM and PowerKVM, if any, may be using this code and so I did not touch the functions loading 32 bit kernels, which the targeted platform does not typically use.

Quoted 5 lines
Quoted 2 lines

The last patch is for viewing where the memory allocations are going and is not to be applied, of course.

I am not entirely convinced we need this for the upcoming release. My concern is that this patch set makes a lot of changes. OK, they are mostly limited to the IEEE 1275 stuff but...

I will post a v2.

The kernel and initrd loader code is shared with PowerMacs that also had 64bit, so v2 will introduce some flags to identify PowerVM and PowerKVM and use the restricted memory allocator only for them.

Quoted 4 lines

Anyway, quick glance through the patches revealed that most of them missing explanation why they are really needed. At least... Please fix these things...

Ok. The little steps make the memory allocation function more flexible.

   Stefan

Quoted 7 lines

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH 8/8] debug: Display successful memory claims

grub-core/kern/ieee1275/ieee1275.c grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align, · line 589

Quoted 13 lines · Stefan Berger
---
 grub-core/kern/ieee1275/ieee1275.c | 1 +
 1 file changed, 1 insertion(+)
grub-core/kern/ieee1275/ieee1275.c +1 -0
index db870db47..1da54d890 100644
@@ -586,6 +586,7 @@ grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align,
 
   if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
     return -1;
+  grub_printf ("CLAIMED: 0x%x (%d MB)  size: %d MB\n", args.base, args.base>>20, size>>20);

Why not grub_dprintf()?

... and s/MB/MiB/...

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel