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

Re: [PATCH v2 6/8] xen/arm: remove shm holes for extended regions


  • To: Penny Zheng <Penny.Zheng@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • Date: Thu, 13 Apr 2023 15:56:07 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=arm.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • 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=iXg/prYLx5EALCUgzFznssa0CZnjCJteDGfMgsf99ZQ=; b=ORGV0J4x6cWye8nLtorjcK4G9eEAIntvY9tMg2MeVU2pzkgmvtXFygRUCsWWdZgKJjNSKhR5GWvZdd2pg4iRnbsD2euq/igAgBn601l2+btAUauSFqyo1gdZO+pU6Bt/7OeUGMZpKNVMdg5BmdQYk3vOi0tVSne6CpkdHdwkiKAwPL23DR+Cvus+kih+E6pteZQkULCMzeLM8Sl0dbFzDfW1RgFk6n6H4rARQTlbPdSFI2sl+qrCIGgPWFIepvSPdhh6Nz+2fGtBkY94DWx/hgmkPIOBn+hhrWihjFnojTwGa1NMRX5bbHkaGAPAAiH0okJ43RiPC5NcJlqGIqA1Iw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YKvKgSveCPYfmptBtizcv0+TImHvFUaC3+4DNvXAJHMAOlcJkIOtZq+moW0RcPDIJXW42cMd/2c/bHI+zTmv63NpsVrhmYLyYRQ403iZV80aF+1DNKlPtZgUAsCVhuXLppziDZogOyzy/JNn9UMLWBOR8PP6XSy1/DMb/bRta7nNdAlh7XGs6TkOGcsIfnSGIb4QK41dZe//my3OsOaevxdSXJ4K3QSEBRICcON+jKnl+9ro43T/b44iQsdNeP2nid9R+DKZYAbFwOTXFL20F3oYFC5lJaFs+ruoJIDtu8OCrFnyHqt2ZhzybS376zjuCzb5XBGo9moSrO9ab8JONA==
  • Cc: <wei.chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 13 Apr 2023 19:56:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Penny

On 2/23/23 00:41, Penny Zheng wrote:
> Static shared memory acts as reserved memory in guest, so it shall be
> excluded from extended regions.
> 
> Extended regions are taken care of under three different scenarios:
> normal DomU, direct-map domain with iommu on, and direct-map domain
> with iommu off.
> 
> For normal DomU, we create a new function "remove_shm_holes_for_domU", to
> firstly transfer original outputs into the format of "struct rangeset",
> then use "remove_shm_from_rangeset" to remove static shm from them.
> 
> For direct-map domain with iommu on, after we get guest shm info from "kinfo",
> we use "remove_shm_from_rangeset" to remove static shm.
> 
> For direct-map domain with iommu off, as static shm has already been taken
> care of through reserved memory banks, we do nothing.
> 
> Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
> ---
> v1 -> v2:
> - new commit
> ---
>  xen/arch/arm/domain_build.c | 94 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 93 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 9b4aabaf22..4cd1e3d433 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -1914,6 +1914,32 @@ static int __init handle_pci_range(const struct 
> dt_device_node *dev,
>      return 0;
>  }
> 
> +static int __init remove_shm_from_rangeset(const struct kernel_info *kinfo,
> +                                           struct rangeset *rangeset)
> +{
> +    unsigned int i;
> +
> +    /* Remove static shared memory regions */
> +    for ( i = 0; i < kinfo->shminfo.nr_banks; i++ )
> +    {
> +        struct membank membank = kinfo->shminfo.bank[i].membank;
> +        paddr_t start, end;
> +        int res;
> +
> +        start = membank.start;
> +        end = membank.start + membank.size - 1;
> +        res = rangeset_remove_range(rangeset, start, end);
> +        if ( res )
> +        {
> +            printk(XENLOG_ERR "Failed to remove: 
> %#"PRIpaddr"->%#"PRIpaddr"\n",
> +                   start, end);
> +            return -EINVAL;
> +        }
> +    }
> +
> +    return 0;
> +}
> +
>  /*
>   * Find the holes in the Host DT which can be exposed to Dom0 as extended
>   * regions for the special memory mappings. In order to calculate regions
> @@ -1922,6 +1948,8 @@ static int __init handle_pci_range(const struct 
> dt_device_node *dev,
>   * - MMIO
>   * - Host RAM
>   * - PCI aperture
> + * - Static shared memory regions, which are described by special property
> + *   "xen,static-shm"
>   */
>  static int __init find_memory_holes(const struct kernel_info *kinfo,
>                                      struct meminfo *ext_regions)
> @@ -1997,6 +2025,14 @@ static int __init find_memory_holes(const struct 
> kernel_info *kinfo,
>          }
>      }
> 
> +    /* Remove static shared memory regions */
> +    if ( kinfo->shminfo.nr_banks != 0 )
> +    {
> +        res = remove_shm_from_rangeset(kinfo, mem_holes);
> +        if ( res )
> +            goto out;
> +    }
> +
>      start = 0;
>      end = (1ULL << p2m_ipa_bits) - 1;
>      res = rangeset_report_ranges(mem_holes, start, end,
> @@ -2012,6 +2048,62 @@ out:
>      return res;
>  }
> 
> +static int __init remove_shm_holes_for_domU(const struct kernel_info *kinfo,
> +                                            struct meminfo *orig_ext)
> +{
> +    struct rangeset *guest_holes;
> +    unsigned int i = 0, tail;
> +    int res;
> +    paddr_t start, end;
> +
> +    /* No static shared memory region. */
> +    if ( kinfo->shminfo.nr_banks == 0 )
> +        return 0;
> +
> +    dt_dprintk("Remove static shared memory holes for extended regions of 
> DomU\n");
> +
> +    guest_holes = rangeset_new(NULL, NULL, 0);
> +    if ( !guest_holes )
> +        return -ENOMEM;
> +
> +    for ( ; i < orig_ext->nr_banks; i++ )
> +    {
> +        start = orig_ext->bank[i].start;
> +        end = start + orig_ext->bank[i].size - 1;
> +
> +        res = rangeset_add_range(guest_holes, start, end);
> +        if ( res )
> +        {
> +            printk(XENLOG_ERR "Failed to add: %#"PRIpaddr"->%#"PRIpaddr"\n",
> +                   start, end);
> +            goto out;
> +        }
> +    }
> +
> +    /* Remove static shared memory regions */
> +    res = remove_shm_from_rangeset(kinfo, guest_holes);
> +    if ( res )
> +        goto out;
> +
> +    tail = orig_ext->nr_banks - 1;
> +    start = orig_ext->bank[0].start;
> +    end = orig_ext->bank[tail].start + orig_ext->bank[tail].size - 1;
> +
> +    /* Reset original extended regions to hold new value */
> +    orig_ext->nr_banks = 0;
> +    res = rangeset_report_ranges(guest_holes, start, end,
> +                                 add_ext_regions, orig_ext);
> +    if ( res )
> +        orig_ext->nr_banks = 0;
> +    else if ( !orig_ext->nr_banks )
> +        res = -ENOENT;
> +
> +out:
> +    rangeset_destroy(guest_holes);
> +
> +    return res;
> +}
> +
>  static int __init find_domU_holes(const struct kernel_info *kinfo,
>                                    struct meminfo *ext_regions)
>  {
> @@ -2039,7 +2131,7 @@ static int __init find_domU_holes(const struct 
> kernel_info *kinfo,
>          res = 0;
>      }
> 
> -    return res;
> +    return remove_shm_holes_for_domU(kinfo, ext_regions);

We are no longer using "res" anywhere in this function, so the variable may be 
removed.

arch/arm/domain_build.c: In function ‘find_domU_holes’:

arch/arm/domain_build.c:2114:9: warning: variable ‘res’ set but not used 
[-Wunused-but-set-variable]

 2114 |     int res = -ENOENT;

      |         ^~~

>  }
> 
>  static int __init make_hypervisor_node(struct domain *d,
> --
> 2.25.1
> 
> 



 


Rackspace

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