All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Julien Grall <julien.grall@arm.com>
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	andrii_anisov@epam.com, xen-devel@lists.xen.org
Subject: Re: [PATCH v2 02/21] xen/arm: make allocate_memory work for non 1:1 mapped guests
Date: Mon, 9 Jul 2018 16:02:21 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.10.1807091520560.8023@sstabellini-ThinkPad-X260> (raw)
In-Reply-To: <ffe46d6d-368f-6237-ce43-dc446560a641@arm.com>

On Mon, 9 Jul 2018, Julien Grall wrote:
> Hi Stefano,
> 
> On 07/07/18 00:11, Stefano Stabellini wrote:
> > Extend allocate_memory to work for non 1:1 mapped domUs. Specifically,
> > memory allocated for domU will be mapped into the domU pseudo-physical
> > address space at the appropriate addresses according to the guest memory
> > map: GUEST_RAM0_BASE and GUEST_RAM1_BASE.
> > 
> > To do that, insert_11_bank has been extended to deal with non-dom0
> > mappings starting from GUEST_RAM0_BASE. insert_11_bank has been renamed
> > to insert_bank.
> > 
> > Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> > 
> > ---
> > Changes in v2:
> > - new patch
> > ---
> >   xen/arch/arm/domain_build.c | 57
> > ++++++++++++++++++++++++++++++++++-----------
> >   1 file changed, 44 insertions(+), 13 deletions(-)
> > 
> > diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> > index 182e3d5..2a6619a 100644
> > --- a/xen/arch/arm/domain_build.c
> > +++ b/xen/arch/arm/domain_build.c
> > @@ -97,27 +97,51 @@ static unsigned int get_allocation_size(paddr_t size)
> >    * Returns false if the memory would be below bank 0 or we have run
> >    * out of banks. In this case it will free the pages.
> >    */
> > -static bool insert_11_bank(struct domain *d,
> > -                           struct kernel_info *kinfo,
> > -                           struct page_info *pg,
> > -                           unsigned int order)
> > +static bool insert_bank(struct domain *d,
> > +                        struct kernel_info *kinfo,
> > +                        struct page_info *pg,
> > +                        unsigned int order,
> > +                        bool map_11)
> >   {
> > -    int res, i;
> > +    int res, i, nr_mem_banks = map_11 ? NR_MEM_BANKS : 2;
> 
> nr_mem_banks should be unsigned. I also would drop "mem_" to shorten a bit the
> name.

OK


> >       mfn_t smfn;
> >       paddr_t start, size;
> > +    struct membank *bank;
> >         smfn = page_to_mfn(pg);
> >       start = mfn_to_maddr(smfn);
> 
> The new code is pretty horrible to read. Can you please add some comments to
> help understanding it?
> 
> Here is already an example where you set start to MFN. But then override after
> with none comment to understand why.
> 
> Also, this code as always assumed MFN == GFN so start was making sense. Now,
> you re-purpose it to just the guest-physical address. So more likely you want
> to rework the code a bit.

I'll add more comments in the code. Next time the patch will be clearer.
This is a snippet to give you an idea, but it might be best for you to
just wait for the next version before reading this again.

    /*
     * smfn: the address of the set of pages to map
     * start: the address in guest pseudo-physical memory where to map
     *        the pages
     */
    smfn = page_to_mfn(pg);
    start = mfn_to_maddr(smfn);
    size = pfn_to_paddr(1UL << order);
    if ( !is_hardware_domain(d) )
    {
        /*
         * Dom0 is 1:1 mapped, so start is the same as (smfn <<
         * PAGE_SHIFT).
         *
         * Instead, DomU memory is provided in two banks:
         *   GUEST_RAM0_BASE - GUEST_RAM0_BASE + GUEST_RAM0_SIZE
         *   GUEST_RAM1_BASE - GUEST_RAM1_BASE + GUEST_RAM1_SIZE
         * 
         * Find the right start address for DomUs accordingly.
         */
  


> >       size = pfn_to_paddr(1UL << order);
> > +    if ( !map_11 )
> 
> I am not sure why map_11 would mean DomU? I don't see any reason to not allow
> that for Dom0. Note that I am not asking to do it, just having clearer name.

Good point. I think I should just drop the option, which is just
confusing, and keep using is_hardware_domain(d) checks like in
allocate_memory. Otherwise let me know if you have a better idea.


> > +    {
> > +        start = GUEST_RAM0_BASE;
> > +        if ( kinfo->mem.nr_banks > 0 )
> > +        {
> > +            for( i = 0; i < kinfo->mem.nr_banks; i++ )
> > +            {
> > +                bank = &kinfo->mem.bank[i];
> > +                start = bank->start + bank->size;
> > +            }
> > +            if ( bank->start == GUEST_RAM0_BASE &&
> > +                    start + size > (GUEST_RAM0_BASE + GUEST_RAM0_SIZE) )
> 
> The indentation looks wrong.

OK


> > +                start = GUEST_RAM1_BASE;
> > +            if ( bank->start == GUEST_RAM1_BASE &&
> > +                    start + size > (GUEST_RAM1_BASE + GUEST_RAM1_SIZE) )
> > +            {
> > +                D11PRINT("Allocation of domain memory exceeds max
> > amount\n");
> 
> This looks quite strange to use D11PRINT here as this related to direct-domain
> mapped.
 
You are right, but I didn't feel like replacing all D11PRINT
occurrences. Should I do that? Or should I change just this instance? I
could also just drop this D11PRINT, given that the printk is not even
enabled by default. Let me know.


> > +                goto fail;
> > +            }
> > +        }
> > +    }
> >   -    D11PRINT("Allocated %#"PRIpaddr"-%#"PRIpaddr" (%ldMB/%ldMB, order
> > %d)\n",
> > +    D11PRINT("Allocated %#"PRIpaddr"-%#"PRIpaddr":%#"PRIpaddr"-%#"PRIpaddr"
> > (%ldMB/%ldMB, order %d)\n",
> > +             mfn_to_maddr(smfn), mfn_to_maddr(smfn) + size,
> >                start, start + size,
> >                1UL << (order + PAGE_SHIFT - 20),
> >                /* Don't want format this as PRIpaddr (16 digit hex) */
> >                (unsigned long)(kinfo->unassigned_mem >> 20),
> >                order);
> >   -    if ( kinfo->mem.nr_banks > 0 &&
> > +    if ( map_11 && kinfo->mem.nr_banks > 0 &&
> 
> Why do you drop that check? It should be harmless for non-direct mapped
> domain.

You are right. I'll remove this change.


> >            size < MB(128) && >            start + size <
> > kinfo->mem.bank[0].start )
> >       {
> > @@ -125,7 +149,7 @@ static bool insert_11_bank(struct domain *d,
> >           goto fail;
> >       }
> >   -    res = guest_physmap_add_page(d, _gfn(mfn_x(smfn)), smfn, order);
> > +    res = guest_physmap_add_page(d, gaddr_to_gfn(start), smfn, order);
> >       if ( res )
> >           panic("Failed map pages to DOM0: %d", res);
> >   @@ -141,7 +165,7 @@ static bool insert_11_bank(struct domain *d,
> >         for( i = 0; i < kinfo->mem.nr_banks; i++ )
> >       {
> > -        struct membank *bank = &kinfo->mem.bank[i];
> > +        bank = &kinfo->mem.bank[i];
> >             /* If possible merge new memory into the start of the bank */
> >           if ( bank->start == start+size )
> > @@ -164,7 +188,7 @@ static bool insert_11_bank(struct domain *d,
> >            * could have inserted the memory into/before we would already
> >            * have done so, so this must be the right place.
> >            */
> > -        if ( start + size < bank->start && kinfo->mem.nr_banks <
> > NR_MEM_BANKS )
> > +        if ( start + size < bank->start && kinfo->mem.nr_banks <
> > nr_mem_banks )
> >           {
> >               memmove(bank + 1, bank,
> >                       sizeof(*bank) * (kinfo->mem.nr_banks - i));
> > @@ -175,7 +199,7 @@ static bool insert_11_bank(struct domain *d,
> >           }
> >       }
> >   -    if ( i == kinfo->mem.nr_banks && kinfo->mem.nr_banks < NR_MEM_BANKS )
> > +    if ( i == kinfo->mem.nr_banks && kinfo->mem.nr_banks < nr_mem_banks )
> >       {
> >           struct membank *bank = &kinfo->mem.bank[kinfo->mem.nr_banks];
> >   @@ -253,6 +277,7 @@ static void allocate_memory(struct domain *d, struct
> > kernel_info *kinfo)
> >       struct page_info *pg;
> >       unsigned int order = get_allocation_size(kinfo->unassigned_mem);
> >       int i;
> > +    bool hwdom = d->domain_id == 0;
> 
> You should use is_hardware_domain(...).

Yes, I'll do that here and elsewhere in this patch


> >         bool lowmem = true;
> >       unsigned int bits;
> > @@ -263,6 +288,12 @@ static void allocate_memory(struct domain *d, struct
> > kernel_info *kinfo)
> >         kinfo->mem.nr_banks = 0;
> >   +    if ( !hwdom )
> > +    {
> > +        lowmem = false;
> > +        goto got_bank0;
> > +    }
> 
> Can you explain why you need this?

Yes, I'll add a comment. The first part of allocate_memory tries to
allocate memory as low as possible, which is fine for dom0 but it is
unnecessary for DomUs, given that they are not 1:1 mapped. So, this
check is meant to go straight to the regular allocation for DomUs,
skipping the special below-4G allocation loop.


> > +
> >       /*
> >        * First try and allocate the largest thing we can as low as
> >        * possible to be bank 0.
> > @@ -274,7 +305,7 @@ static void allocate_memory(struct domain *d, struct
> > kernel_info *kinfo)
> >               pg = alloc_domheap_pages(d, order, MEMF_bits(bits));
> >               if ( pg != NULL )
> >               {
> > -                if ( !insert_11_bank(d, kinfo, pg, order) )
> > +                if ( !insert_bank(d, kinfo, pg, order, hwdom) )
> >                       BUG(); /* Cannot fail for first bank */
> >                     goto got_bank0;
> > @@ -319,7 +350,7 @@ static void allocate_memory(struct domain *d, struct
> > kernel_info *kinfo)
> >               break;
> >           }
> >   -        if ( !insert_11_bank(d, kinfo, pg, order) )
> > +        if ( !insert_bank(d, kinfo, pg, order, hwdom) )
> >           {
> >               if ( kinfo->mem.nr_banks == NR_MEM_BANKS )
> >                   /* Nothing more we can do. */
> > 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-07-09 23:02 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06 23:11 [PATCH v2 00/21] dom0less step1: boot multiple domains from device tree Stefano Stabellini
2018-07-06 23:11 ` [PATCH v2 01/21] xen/arm: rename get_11_allocation_size to get_allocation_size Stefano Stabellini
2018-07-09 12:55   ` Julien Grall
2018-07-11 20:09     ` Stefano Stabellini
2018-07-06 23:11 ` [PATCH v2 02/21] xen/arm: make allocate_memory work for non 1:1 mapped guests Stefano Stabellini
2018-07-09 13:43   ` Julien Grall
2018-07-09 23:02     ` Stefano Stabellini [this message]
2018-07-10 17:57       ` Julien Grall
2018-07-11 21:42         ` Stefano Stabellini
2018-07-09 13:58   ` Julien Grall
2018-07-09 23:10     ` Stefano Stabellini
2018-07-23 18:01   ` Andrii Anisov
2018-07-23 18:32     ` Stefano Stabellini
2018-07-24 12:09       ` Andrii Anisov
2018-07-06 23:11 ` [PATCH v2 03/21] xen: allow console_io hypercalls from certain DomUs Stefano Stabellini
2018-07-09 13:48   ` Julien Grall
2018-07-17 20:05     ` Stefano Stabellini
2018-07-17 20:26       ` Julien Grall
2018-07-18 17:10         ` Stefano Stabellini
2018-07-19  9:19           ` Julien Grall
2018-08-17 19:41             ` Daniel De Graaf
2018-07-06 23:11 ` [PATCH v2 04/21] xen/arm: move a few DT related defines to public/device_tree_defs.h Stefano Stabellini
2018-07-09 13:59   ` Julien Grall
2018-07-06 23:12 ` [PATCH v2 05/21] xen/arm: extend device tree based multiboot protocol Stefano Stabellini
2018-07-09 14:07   ` Julien Grall
2018-07-13 22:41     ` Stefano Stabellini
2018-07-16 14:14       ` Julien Grall
2018-07-16 22:02         ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 06/21] xen/arm: do not pass dt_host to make_memory_node and make_hypervisor_node Stefano Stabellini
2018-07-09 14:11   ` Julien Grall
2018-07-09 21:51     ` Stefano Stabellini
2018-07-10 17:28       ` Julien Grall
2018-07-11 20:33         ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 07/21] xen/arm: rename acpi_make_chosen_node to make_chosen_node Stefano Stabellini
2018-07-09 14:12   ` Julien Grall
2018-07-06 23:12 ` [PATCH v2 08/21] xen/arm: increase MAX_MODULES Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 09/21] xen/arm: move cmdline out of boot_modules Stefano Stabellini
2018-07-09 14:53   ` Julien Grall
2018-07-10  0:00     ` Stefano Stabellini
2018-07-10 21:11       ` Julien Grall
2018-07-13  0:04         ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 10/21] xen/arm: don't add duplicate boot modules Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 11/21] xen/arm: probe domU kernels and initrds Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 12/21] xen/arm: refactor construct_dom0 Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 13/21] xen/arm: introduce construct_domU Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 14/21] xen/arm: generate a simple device tree for domUs Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 15/21] xen/arm: generate vpl011 node on device tree for domU Stefano Stabellini
2018-07-12 18:14   ` Julien Grall
2018-07-13 21:24     ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 16/21] xen/arm: introduce a union in vpl011 Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 17/21] xen/arm: refactor vpl011_data_avail Stefano Stabellini
2018-07-24  9:58   ` Julien Grall
2018-07-27 22:37     ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 18/21] xen/arm: Allow vpl011 to be used by DomU Stefano Stabellini
2018-07-24 11:00   ` Julien Grall
2018-07-27  0:10     ` Stefano Stabellini
2018-07-27 11:00       ` Julien Grall
2018-07-27 21:42         ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 19/21] xen/arm: introduce create_domUs Stefano Stabellini
2018-07-16 16:10   ` Jan Beulich
2018-07-16 21:44     ` Stefano Stabellini
2018-07-24 13:53   ` Julien Grall
2018-07-28  2:42     ` Stefano Stabellini
2018-07-30 10:26       ` Julien Grall
2018-07-30 18:15         ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 20/21] xen: support console_switching between Dom0 and DomUs on ARM Stefano Stabellini
2018-07-16 16:19   ` Jan Beulich
2018-07-16 21:55     ` Stefano Stabellini
2018-07-17  6:37       ` Jan Beulich
2018-07-17 16:43         ` Stefano Stabellini
2018-07-18  6:41           ` Jan Beulich
2018-07-18 16:51             ` Stefano Stabellini
2018-07-17  8:40       ` Jan Beulich
2018-07-17 16:33         ` Stefano Stabellini
2018-07-17 20:29   ` Julien Grall
2018-07-18  7:12     ` Jan Beulich
2018-07-18 16:59       ` Julien Grall
2018-07-19  6:10         ` Jan Beulich
2018-07-19 17:18           ` Stefano Stabellini
2018-07-18 17:01       ` Stefano Stabellini
2018-07-18 20:37         ` George Dunlap
2018-07-17 20:34   ` Julien Grall
2018-07-18 17:31     ` Stefano Stabellini
2018-07-06 23:12 ` [PATCH v2 21/21] xen/arm: split domain_build.c Stefano Stabellini
2018-07-12 18:18 ` [PATCH v2 00/21] dom0less step1: boot multiple domains from device tree Julien Grall
2018-07-13 20:54   ` Stefano Stabellini
2018-07-18 16:48     ` Julien Grall
2018-07-18 17:48       ` Stefano Stabellini
2018-07-23 17:13         ` Julien Grall
2018-07-23 17:52           ` Stefano Stabellini
2018-07-23 17:14 ` Andrii Anisov
2018-07-23 17:55   ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.10.1807091520560.8023@sstabellini-ThinkPad-X260 \
    --to=sstabellini@kernel.org \
    --cc=andrii_anisov@epam.com \
    --cc=julien.grall@arm.com \
    --cc=stefanos@xilinx.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.