All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Orzel <michal.orzel@amd.com>
To: Henry Wang <xin.wang2@amd.com>, <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
	Alec Kwapis <alec.kwapis@medtronic.com>
Subject: Re: [PATCH v2 4/5] xen/arm: Find unallocated spaces for magic pages of direct-mapped domU
Date: Mon, 11 Mar 2024 14:46:38 +0100	[thread overview]
Message-ID: <4821f30b-94a6-4a2a-8c46-81a9d1e288a4@amd.com> (raw)
In-Reply-To: <20240308015435.4044339-5-xin.wang2@amd.com>

Hi Henry,

On 08/03/2024 02:54, Henry Wang wrote:
> For 1:1 direct-mapped dom0less DomUs, the magic pages should not clash
> with any RAM region. To find a proper region for guest magic pages,
> we can reuse the logic of finding domain extended regions.
> 
> Extract the logic of finding domain extended regions to a helper
> function named find_unused_memory() and use it to find unallocated
> spaces for magic pages before make_hypervisor_node(). The result magic
> page region is added to the reserved memory section of the bootinfo so
> that it is carved out from the extended regions.
> 
> Reported-by: Alec Kwapis <alec.kwapis@medtronic.com>
> Signed-off-by: Henry Wang <xin.wang2@amd.com>
> ---
> v2:
> - New patch
> ---
>  xen/arch/arm/dom0less-build.c           | 43 +++++++++++++++++++++++++
>  xen/arch/arm/domain_build.c             | 30 ++++++++++-------
>  xen/arch/arm/include/asm/domain_build.h |  2 ++
>  3 files changed, 64 insertions(+), 11 deletions(-)
> 
> diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c
> index 1e1c8d83ae..99447bfb0c 100644
> --- a/xen/arch/arm/dom0less-build.c
> +++ b/xen/arch/arm/dom0less-build.c
> @@ -682,6 +682,49 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
>  
>      if ( kinfo->dom0less_feature & DOM0LESS_ENHANCED_NO_XS )
>      {
> +        if ( is_domain_direct_mapped(d) )
> +        {
This whole block is dependent on static memory feature that is compiled out by default.
Shouldn't you move it to static-memory.c ?

> +            struct meminfo *avail_magic_regions = xzalloc(struct meminfo);
I can't see corresponding xfree(avail_magic_regions). It's not going to be used after unused memory
regions are retrieved.

> +            struct meminfo *rsrv_mem = &bootinfo.reserved_mem;
> +            struct mem_map_domain *mem_map = &d->arch.mem_map;
> +            uint64_t magic_region_start = INVALID_PADDR;
What's the purpose of this initialization? magic_region_start is going to be re-assigned before making use of this value.

> +            uint64_t magic_region_size = GUEST_MAGIC_SIZE;
Why not paddr_t?

> +            unsigned int i;
> +
> +            if ( !avail_magic_regions )
> +                return -ENOMEM;
What about memory allocated for kinfo->fdt? You should goto err;

> +
> +            ret = find_unused_memory(d, kinfo, avail_magic_regions);
> +            if ( ret )
> +            {
> +                printk(XENLOG_WARNING
> +                       "%pd: failed to find a region for domain magic pages\n",
> +                      d);
> +                goto err;
What about memory allocated for avail_magic_regions? You should free it.

> +            }
> +
> +            magic_region_start = avail_magic_regions->bank[0].start;
> +
> +            /*
> +             * Register the magic region as reserved mem to make sure this
> +             * region will not be counted when allocating extended regions.
Well, this is only true in case find_unallocated_memory() is used to retrieve free regions.
What if our direct mapped domU used partial dtb and IOMMU is in use? In this case,
find_memory_holes() will be used and the behavior will be different.

Also, I'm not sure if it is a good idea to call find_unused_memory twice (with lots of steps inside)
just to retrieve 16MB (btw. add_ext_regions will only return 64MB+ regions) region for magic pages.
I'll let other maintainers share their opinion.

Also, CCing Carlo since he was in a need of retrieving free memory regions as well for cache coloring with dom0.

~Michal


  reply	other threads:[~2024-03-11 13:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  1:54 [PATCH v2 0/5] DOMCTL-based guest magic regions allocation for dom0less Henry Wang
2024-03-08  1:54 ` [PATCH v2 1/5] xen/arm: Rename assign_static_memory_11() for consistency Henry Wang
2024-03-08  8:18   ` Michal Orzel
2024-03-08  8:22     ` Henry Wang
2024-03-08  1:54 ` [PATCH v2 2/5] xen/domain.h: Centrialize is_domain_direct_mapped() Henry Wang
2024-03-08  8:59   ` Michal Orzel
2024-03-08  9:06     ` Henry Wang
2024-03-08  9:41       ` Jan Beulich
2024-03-11 18:02   ` Shawn Anastasio
2024-03-08  1:54 ` [PATCH v2 3/5] xen/domctl, tools: Introduce a new domctl to get guest memory map Henry Wang
2024-03-11  9:10   ` Michal Orzel
2024-03-11  9:46     ` Henry Wang
2024-03-11 16:58   ` Jan Beulich
2024-03-12  3:06     ` Henry Wang
2024-03-08  1:54 ` [PATCH v2 4/5] xen/arm: Find unallocated spaces for magic pages of direct-mapped domU Henry Wang
2024-03-11 13:46   ` Michal Orzel [this message]
2024-03-11 13:50     ` Michal Orzel
2024-03-12  3:25     ` Henry Wang
2024-03-13 11:09       ` Carlo Nonato
2024-03-08  1:54 ` [PATCH v2 5/5] xen/memory, tools: Make init-dom0less consume XEN_DOMCTL_get_mem_map Henry Wang
2024-03-11 17:07   ` Jan Beulich
2024-03-12  3:44     ` Henry Wang
2024-03-12  7:34       ` Jan Beulich
2024-03-12  7:36         ` Henry Wang
2024-03-29  5:11     ` Henry Wang
2024-04-02  7:05       ` Jan Beulich
2024-04-02  8:43         ` Henry Wang
2024-04-02  8:51           ` Jan Beulich
2024-04-02  9:03             ` Henry Wang
2024-03-25 15:35   ` Anthony PERARD
2024-03-26  1:21     ` Henry Wang

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=4821f30b-94a6-4a2a-8c46-81a9d1e288a4@amd.com \
    --to=michal.orzel@amd.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=alec.kwapis@medtronic.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    --cc=xin.wang2@amd.com \
    /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.