[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator


  • To: Julien Grall <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Henry Wang <Henry.Wang@xxxxxxx>
  • Date: Tue, 6 Sep 2022 11:11:02 +0000
  • Accept-language: zh-CN, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rIaVykuJDgreJnWqjs2cBJkNRw+ZlF/GYZztbXTqFXY=; b=NE1QSnX1hjzVA7R+rk0E1g2lF1MotWpAcfrmKJPIqtyfjpti8u0tT3eKlVVJXpp9wMJC7MBVekcH+KtnEnW/KZEaO18cq00fzrcxplJ/CqUC3ojFznXNmjtFCqT55PbjOT1/KFVT9HCSzW30ifmh+fvYzn0VjLedQU9EsfefqYTYC+9r+mkQPreH+aWfryII62M5vup9RN6NoPZnLHJCz8uYuGTFr2JFlwTMZ2qfg1Uff7icspHq7gBPlUu8fqTsSnlieOlNAXce0F9DMCckKfk7L/A4doCWW2x6xmDfWSlWf3vOcGxccOoovvgoDT6rJttadh7E2ZvzXUynAirXSA==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rIaVykuJDgreJnWqjs2cBJkNRw+ZlF/GYZztbXTqFXY=; b=cABDTfWLx8RUHcF8eHGzHVXjZTl9o+1ylGEMkK4XpGstXFhmtJnOUbxk2kd1IZ27vzv5qfSiugWwlc2R8BcLevud+9mvFOwgLhRM9IuiwoB99hho/z5hOYKD9TgFT8eYBMiSeb2wpnrPACmmp6BoleS+AbkPnolhVBsZoUFtRs9fQC86Rpw/+PjM3LIP5fJNCeA/O5Rf0TimTCVw4VEkYQBNz+9YWCX15Lasnv6H5rnF/pS1Klk7bFnDxc21RQuoKyG969Mlt2zVmjT2z4wuxxFTAzUeCrGPuMZ0Lh+bx2B0248iOxZLTM96/iQMLxdQuhQBHgMHslvHmbjqONjWVw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=L43wEP77iEry592Vdss9ekcZFdHFKzjLge9/cxvUqN3Gb7xflPYHoxgGPtmQGhtCcn+K8Ga5KDLT1WKtGbErQfzwN6q1LXFBpdCcBSM3UVh2DpFa3KEjIr1Fhn/KdY5rS5b/iQWIwYfld2wE8uhzy3tlWtzdPkJ8SwW10gmuvjyQEZ2vDzzV+JU5VMvzD7Aho2PWxQHbNQ0ZfNSu6159fbN9aFl87v/XDknGoT4BwbW9MFicXCFZ8k6gKDq7hwUSNQZ5sBCElWySZcPVuunNMq1IoMd+hAqNOm6Kv+b840032OfWE/uSP6INC7OaWH9IaylnZO2Xp1TOIRylqWV4Bg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CnBk6YfNof9baC6HXotUHlnjHZcNj6+ykRxuugJNNx11C6y76kX1WFTbypM1fVltAE0de2g0thTnAF+36DiwO6hEWBilz2XMMlcKd53a6ZdONEwhnG/MAcpXCAdbrvgH1MP39dl0VLVgJpoZ4NkdO2pOqcbTPIjMS3vsq3vuNEl9pKS/zVXxL8zE0to2oY1ZyeL9jyUyDIv/oehA4kvtrJaXD+bLyhHjopf2n6CWowc5P2B2Vv1+Q02mXuf+1YaVEVDyqnca+C6S6VlLvcU1z6Kv9Osylk5iitm+I8t1KpJpbeJ0J8dD9Q67pjWhrD00pUMwIG0B/F9NVz44rvqC7w==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 06 Sep 2022 11:11:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYwPj6dlOKXE+k5kuuj2vKrDnG5K3RJT6AgAB0+PCAAIHpAIAAAbyA
  • Thread-topic: [PATCH v2 3/4] xen/arm: Handle reserved heap pages in boot and heap allocator

Hi Julien,

Thanks for the clarification and your patience. For the
populate_boot_allocator() change, I attached my change in the end,
and personally I would like to hear your opinion before sending v3
since we now have limited time.

> -----Original Message-----
> From: Julien Grall <julien@xxxxxxx>
> >>> +        {
> >>> +            bank_start = bootinfo.reserved_mem.bank[i].start;
> >>> +            bank_size = bootinfo.reserved_mem.bank[i].size;
> >>> +            bank_end = bank_start + bank_size;
> >>> +
> >>> +            if ( bank_size < size )
> >>> +                continue;
> >>> +
> >>> +            aligned_end = bank_end & ~(align - 1);
> >>> +            aligned_start = (aligned_end - size) & ~(align - 1);
> >>
> >> I find the logic a bit confusing. AFAIU, aligned_start could be below
> >> the start of the RAM which is not what I would usually expect.
> >
> > Yeah I understand your concern. Here I want to make sure even if
> > the given size is not aligned (although less likely happen in real life
> > given the size calculation logic in setup_mm) the code still work.
> 

Sorry I probably explained in the wrong way in previous mail, but since no
change requested here this is purely for discussion. In the code we
are sure aligned_end calculation will make sure the end address will
satisfy the alignment requirement within the range to a aligned (lower)
address. The aligned_start = (aligned_end - size) & ~(align - 1) will make
sure the start address is following the same alignment requirement, but
the only issue would be in this case the start address will below the region
start, hence the if ( aligned_start > bank_start ) check.

> I don't think I agree on the less likely here. The regions are provided
> by in the Device-Tree. And there are more chance they are incorrect
> because the value will be specific to a software/device stack.
> 
> Related to this discussion, I can't find any alignment requirement in
> the device-tree binding. I think we at least want to require 64KB
> aligned (so the same Device-Tree works if we were going to support 64KB
> page granularity).

I agree we need to require 64KB alignment, and currently we are following
this because we are doing 32MB alignment. I will add a comment in the
function comment to mention we at least want a 64KB alignment so that
future callers will not make mistakes.

> 
> >>
> >>> +
> >>> +            if ( aligned_start > bank_start )
> >>> +                /*
> >>> +                 * Arm32 allocates xenheap from higher address to lower, 
> >>> so if
> >>
> >> This code is also called on arm32. So what are you referring to? Is it
> >> consider_modules()?
> >
> > Yes, I think the current arm32 behavior in consider_modules() is what
> > I am referring to. In fact, I just want to add some comments that explain
> why
> > we need the end = max(end, aligned_end) since technically if there are
> > multiple reserved heap banks and all of them can fit the xenheap region,
> > we can use either of them. But following the current behavior we can only
> use
> > the highest bank to keep the consistency.
> 
> Xenheap is currently allocated the highest possible so there is enough
> low memory available for domain memory. This is in order to allow 32-bit
> DMA device to function.
> 
> I am less certain this makes sense when the heap is reserved. Because an
> admin could decide to define the heap solely above/below 4GB.
> 
> That said, nothing in the document suggests that domain memory would not
> be allocated from the reserved heap. So I would suggest to write the
> following comment:
> 
> "Allocate the xenheap as high as possible to keep low-memory available
> (assuming the admin supplied region below 4GB) for other use (e.g.
> domain memory allocation)."

Sure.

> 
> Also, I think the documentation wants to be updated to clarify whether
> the reserved heap could be used to allocate domain. If it could, then I
> think we need to explain that the region should contain enough memory
> below some 4GB to cater 32-bit DMA.

Ok I will add in v3.

> 
> >>> +    /*
> >>> +     * No reserved heap regions:
> >>>         * For simplicity, add all the free regions in the boot allocator.
> >>>         */
> >>> -    populate_boot_allocator();
> >>> +    else
> >>> +        populate_boot_allocator();
> >>
> >> For arm32, shouldn't we also only add the reserved heap (minus the
> >> xenheap) to the boot allocator? At which point, I would move the change
> >> in populate_boot_allocator().
> >
> > Sorry I am not sure what this comment about...as here the code is for
> arm64.
> 
> Right, I wasn't sure where to comment because you don't touch the call
> to populate_boot_allocator().
> 
> > For the question, yes.
> > For the latter one, do you request some changes? If so, could you please
> kindly
> > elaborate a little bit more? Thanks.
> 
> Yes I am requesting some change because I think the code on arm32 is
> incorrect (the boot allocator will not be populated with the reserved heap).
> 
> I think the code should be moved in populate_boot_allocator():
> 
> if ( bootinfo.reserved_heap )
> {
>      for ( ...; i < bootinfo.reserved_mem.nr_banks; i++ )
>         [....]
>         init_boot_pages_pages()
> }
> 
> Note that to handle arm32, you will also need to exclude the xenheap area.

When I implement the code, I found that the arm32 Xenheap excluding logic
somehow can be reused.

So I think I tried to reuse as much as current code. Would below
populate_boot_allocator() seem ok to you?

static void __init populate_boot_allocator(void)
{
    unsigned int i;
    const struct meminfo *banks = bootinfo.static_heap ?
                                  &bootinfo.reserved_mem : &bootinfo.mem;

    for ( i = 0; i < banks->nr_banks; i++ )
    {
        const struct membank *bank = &banks->bank[i];
        paddr_t bank_end = bank->start + bank->size;
        paddr_t s, e;

        if ( bootinfo.static_heap && bank->type != MEMBANK_STATIC_HEAP )
            continue;

        s = bank->start;
        while ( s < bank_end )
        {
            paddr_t n = bank_end;

            if ( bootinfo.static_heap )
                e = bank_end;
            else
            {
                e = next_module(s, &n);

                if ( e == ~(paddr_t)0 )
                    e = n = bank_end;

                /*
                 * Module in a RAM bank other than the one which we are
                 * not dealing with here.
                 */
                if ( e > bank_end )
                    e = bank_end;
            }

#ifdef CONFIG_ARM_32
            /* Avoid the xenheap */
            if ( s < mfn_to_maddr(directmap_mfn_end) &&
                 mfn_to_maddr(directmap_mfn_start) < e )
            {
                e = mfn_to_maddr(directmap_mfn_start);
                n = mfn_to_maddr(directmap_mfn_end);
            }
#endif

            if ( bootinfo.static_heap )
                init_boot_pages(s, e);
            else
                fw_unreserved_regions(s, e, init_boot_pages, 0);

            s = n;
        }
    }
}

Kind regards,
Henry

> 
> Cheers,
> 
> --
> Julien Grall

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.