On Mon, Dec 13, 2021 at 11:20:22PM +1100, Daniel Axtens wrote: > Daniel Kiper <dki...@net-space.pl> writes: > > > On Thu, Nov 25, 2021 at 02:22:49AM +1100, Daniel Axtens wrote: > >> grub_mm_init_region does some things that seem magical, especially > >> around region merging. Make it a bit clearer. > >> > >> Signed-off-by: Daniel Axtens <d...@axtens.net> > >> --- > >> grub-core/kern/mm.c | 30 +++++++++++++++++++++++++++++- > >> 1 file changed, 29 insertions(+), 1 deletion(-) > >> > >> diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c > >> index bec960c18e2b..ef2025f929de 100644 > >> --- a/grub-core/kern/mm.c > >> +++ b/grub-core/kern/mm.c > >> @@ -128,23 +128,51 @@ grub_mm_init_region (void *addr, grub_size_t size) > >> if (((grub_addr_t) addr + 0x1000) > ~(grub_addr_t) size) > >> size = ((grub_addr_t) -0x1000) - (grub_addr_t) addr; > >> > >> + /* Attempt to merge this region with every existing region */ > >> for (p = &grub_mm_base, q = *p; q; p = &(q->next), q = *p) > >> + /* > >> + * Is the new region immediately below an existing region? That > >> + * is, is the address of the memory we're adding now (addr) + size > >> + * of the memory we're adding (size) + the bytes we couldn't use > >> + * at the start of the region we're considering (q->pre_size) > >> + * equal to the address of q? In other words, does the memory > >> + * looks like this? > >> + * > >> + * addr q > >> + * |----size-----|-q->pre_size-|<q region>| > >> + */ > >> if ((grub_uint8_t *) addr + size + q->pre_size == (grub_uint8_t *) q) > >> { > >> + /* > >> + * Yes, we can merge. r is our new region, it's address is the > >> + * first GRUB_MM_ALIGNed address above addr. > > > > > I think s/above/below/... > > > >> + */ > >> r = (grub_mm_region_t) ALIGN_UP ((grub_addr_t) addr, GRUB_MM_ALIGN); > > We do r = ALIGN_UP(addr, GRUB_MM_ALIGN), so 'above' is actually correct. > > But that probably indicates that I'm not explaining it well. > > How does this sound: > > /* > * Yes, we can merge the memory starting at addr into the > * existing region from below. Align up addr to GRUB_MM_ALIGN > * so that our new region has proper alignment. > */ > > If you want you can change the comment and apply it, otherwise I will > submit a v2.
Now it is better. I will update the patch and apply it together with the other patches which got my RB. Thanks, Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel