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

Re: [PATCH 09/11] xen/arm: remove shm holes for extended regions


  • To: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Fri, 22 Mar 2024 20:11:00 +0000
  • Accept-language: en-GB, 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=9ZJwd0/0OVccJ9HQLwWiNeqWWYJyfEsKSnk0duZQupk=; b=E0cqXFQ8paHQ8cUmQt6JGdXmom8xHnxd1uXXTB93v40BqX00RRuGBPxJElSi1urguqqgRnzDW6exF7hop32JDfX7WZuUwqSX28HxlVCMDw8KxQwiEdutz4A18qlLih17E9pozWHByqjodWAvB5U4ScGF249lgg/JhtbmtO5CSYZ9YcpzQkGc1y/zcsuXmhuItZVUN1KGPUIdTQ+jFOUTWh9XRgRKbl18bBQEHHCpjNPT1UeluGEB1ADjro0rM/WIHRTKd1iVBqhtWpeO12gfohKmDhjqrL6A9OMfgSJkFRy5iFTRLjFEv5eIIF6LUn+c1aj3wR5iwqjRP00sxeVP9Q==
  • 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=9ZJwd0/0OVccJ9HQLwWiNeqWWYJyfEsKSnk0duZQupk=; b=X4N/H42+KZrmIPVp2IRiOemv4MhE3YkjUOqf3zQ1tcNhMp+iu1f6607bc7XW3YE/eT2AydMC/zuOptZ1gf9AjE3vpRM7LhB53Phwv1+cOfTh8nq1+Uy8HEfRzbXHsyv1vdUzCq4FiRXhhwBNNo/Mk45IvCv+QsDfx8iXcC+vzbgXvUIRJk5wH4pztF+EZ6yJuVlmK5EfjiK4rTX//Cl7Y/B+n2aNV/BsdtQm8XzkBO7RL+1ALUWLr9oSxSyXlXja9B9FlwVorQdLhQzfepqUAYyvKbCh+ToblImUEpaHuZ6JqdJpOSswlVUjp3FkEsY1V5dtSpsceSn3u8LijVg//g==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=GQcfoJrE1Jo4K3HvB9FaKp/nZwdjX9tuw9elym0C0p5B5JejwaHoKG/znUe1dKvrdld3jQ7NaFs7hS+GnGd7+62xhVPE/A267gqV4OzHvyughPGGekAeCp+w9XwicT9Ai2A/wMFZV087yhz7q6mGw0QD7yQ4INRyTlQBsajOBfnna/4w+2Qkp7RkYRN04YQDe2kv3dnJcOmHKS/NFyQCuNbNOU3uT/SM6BR4gJXyyX6bqTznPt1iK5PD/SAT1kSyefpIvJs4zoYmvugVAtbi2dHlG3yJ3lIXrl34B0t0JGTB6RB6GSg5TfCK+R4lWHf7ZPqN9uqqnEkmaxrjuNhTWA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dWtm2vx67guu1L76nP7a6ZGJJCKuV3/Qo2zsOe2xf++GRjHYdCTBbi4QOAJyWtLTNfrIWCNK4BNtzBJ9CqJA96tmrxWYOgNQdqX+WgGAwANILEZa9voGf9tbekKGccseuMdkELMt3Q3A4/qrJass+hdg01C4Or/1fhYoV1WCpZKfggodWfXbzLXRqn1TvL0lMTMMcQL/Uc8ClIJ0MNFNHhjA6et0A4w6j/Zqm/B/otnF4sIGJO5BI8KIuTdsJ1OV2hEpDYffo0FGuzEZzkYOmAxAuJbSrGaFGDv6Atfm2TqGUqExSxmjuzy8qkyMBc1BoXCdY4HOrIf7DmPx9Bixgw==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 22 Mar 2024 20:11:31 +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: AQHadH3uaMFqvhbywkGpOv3rQeVHMLFD7N8AgABUNYA=
  • Thread-topic: [PATCH 09/11] xen/arm: remove shm holes for extended regions


> On 22 Mar 2024, at 15:09, Michal Orzel <michal.orzel@xxxxxxx> wrote:
> 
> Hi Luca,
> 
> NIT: title s/for/from?
> 
> On 12/03/2024 14:03, Luca Fancellu wrote:
>> 
>> 
>> From: Penny Zheng <Penny.Zheng@xxxxxxx>
>> 
>> 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>
>> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
>> ---
>> v1:
>> - Rework of 
>> https://patchwork.kernel.org/project/xen-devel/patch/20231206090623.1932275-8-Penny.Zheng@xxxxxxx/
>> ---
>> xen/arch/arm/domain_build.c             | 16 ++++-
>> xen/arch/arm/include/asm/domain_build.h |  2 +
>> xen/arch/arm/include/asm/static-shmem.h | 18 ++++++
>> xen/arch/arm/static-shmem.c             | 86 +++++++++++++++++++++++++
>> 4 files changed, 119 insertions(+), 3 deletions(-)
>> 
>> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
>> index 9fad9e8b2c40..740c483ea2db 100644
>> --- a/xen/arch/arm/domain_build.c
>> +++ b/xen/arch/arm/domain_build.c
>> @@ -817,8 +817,8 @@ int __init make_memory_node(const struct domain *d,
>>     return res;
>> }
>> 
>> -static int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,
>> -                                  void *data)
>> +int __init add_ext_regions(unsigned long s_gfn, unsigned long e_gfn,
>> +                           void *data)
>> {
>>     struct membanks *ext_regions = data;
>>     paddr_t start, size;
>> @@ -969,6 +969,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,domain-shared-memory-v1"
> I'm not sure if providing a compatible here makes sense. If at all, I would 
> put "xen,shared-mem" which holds the addresses.
> 
>>  */
>> static int __init find_memory_holes(const struct kernel_info *kinfo,
>>                                     struct membanks *ext_regions)
>> @@ -985,6 +987,11 @@ static int __init find_memory_holes(const struct 
>> kernel_info *kinfo,
>>     if ( !mem_holes )
>>         return -ENOMEM;
>> 
>> +    /* Remove static shared memory regions */
>> +    res = remove_shm_from_rangeset(kinfo, mem_holes);
>> +    if ( res )
>> +        goto out;
> How can you remove from a rangeset without first adding to it?
> This should be moved after rangeset_add_range().

You are very right

> Also, usually (and this is the case in this function) we pass frames
> to rangeset and not addresses (argument is of type ul). However...
> 
>> +
>>     /* Start with maximum possible addressable physical memory range */
>>     start = 0;
>>     end = (1ULL << p2m_ipa_bits) - 1;
>> @@ -1089,7 +1096,10 @@ static int __init find_domU_holes(const struct 
>> kernel_info *kinfo,
>>         res = 0;
>>     }
>> 
>> -    return res;
>> +    if ( res )
>> +        return res;
>> +
>> +    return remove_shm_holes_for_domU(kinfo, ext_regions);
>> }
>> 
>> int __init make_hypervisor_node(struct domain *d,
>> diff --git a/xen/arch/arm/include/asm/domain_build.h 
>> b/xen/arch/arm/include/asm/domain_build.h
>> index a6f276cc4263..026d975da28e 100644
>> --- a/xen/arch/arm/include/asm/domain_build.h
>> +++ b/xen/arch/arm/include/asm/domain_build.h
>> @@ -51,6 +51,8 @@ static inline int prepare_acpi(struct domain *d, struct 
>> kernel_info *kinfo)
>> int prepare_acpi(struct domain *d, struct kernel_info *kinfo);
>> #endif
>> 
>> +int add_ext_regions(unsigned long s_gfn, unsigned long e_gfn, void *data);
>> +
>> #endif
>> 
>> /*
>> diff --git a/xen/arch/arm/include/asm/static-shmem.h 
>> b/xen/arch/arm/include/asm/static-shmem.h
>> index c6fac9906656..2f70aed53ac7 100644
>> --- a/xen/arch/arm/include/asm/static-shmem.h
>> +++ b/xen/arch/arm/include/asm/static-shmem.h
>> @@ -29,6 +29,12 @@ void early_print_info_shmem(void);
>> 
>> void init_sharedmem_pages(void);
>> 
>> +int remove_shm_from_rangeset(const struct kernel_info *kinfo,
>> +                             struct rangeset *rangeset);
>> +
>> +int remove_shm_holes_for_domU(const struct kernel_info *kinfo,
>> +                              struct membanks *ext_regions);
>> +
>> #else /* !CONFIG_STATIC_SHM */
>> 
>> static inline int make_resv_memory_node(const struct domain *d,
>> @@ -61,6 +67,18 @@ static inline void early_print_info_shmem(void) {};
>> 
>> static inline void init_sharedmem_pages(void) {};
>> 
>> +static inline int remove_shm_from_rangeset(const struct kernel_info *kinfo,
>> +                                           struct rangeset *rangeset)
>> +{
>> +    return 0;
>> +}
>> +
>> +static inline int remove_shm_holes_for_domU(const struct kernel_info *kinfo,
>> +                                            struct membanks *ext_regions)
>> +{
>> +    return 0;
>> +}
>> +
>> #endif /* CONFIG_STATIC_SHM */
>> 
>> #endif /* __ASM_STATIC_SHMEM_H_ */
>> diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c
>> index 6143f52cb991..b3e2105dd3f2 100644
>> --- a/xen/arch/arm/static-shmem.c
>> +++ b/xen/arch/arm/static-shmem.c
>> @@ -1,6 +1,7 @@
>> /* SPDX-License-Identifier: GPL-2.0-only */
>> 
>> #include <xen/libfdt/libfdt.h>
>> +#include <xen/rangeset.h>
>> #include <xen/sched.h>
>> 
>> #include <asm/domain_build.h>
>> @@ -564,6 +565,91 @@ void __init init_sharedmem_pages(void)
>>         init_staticmem_bank(&shmem->bank[bank]);
>> }
>> 
>> +int __init remove_shm_from_rangeset(const struct kernel_info *kinfo,
>> +                                    struct rangeset *rangeset)
>> +{
>> +    const struct membanks *shm_mem = &kinfo->shm_mem.common;
>> +    unsigned int i;
>> +
>> +    /* Remove static shared memory regions */
>> +    for ( i = 0; i < shm_mem->nr_banks; i++ )
>> +    {
>> +        paddr_t start, end;
> ... here, these hold physical addresses and...
> 
>> +        int res;
>> +
>> +        start = shm_mem->bank[i].start;
>> +        end = shm_mem->bank[i].start + shm_mem->bank[i].size - 1;
>> +        res = rangeset_remove_range(rangeset, start, end);
> you will end up in a mix which won't work. Switch to PFN_DOWN()

Will fix

> 
>> +        if ( res )
> What's the point of res variable if it is not printed below?

I guess this part was copied from find_memory_holes which doesn’t print out res,
anyway you are right, we should print it.

> 
>> +        {
>> +            printk(XENLOG_ERR "Failed to remove: 
>> %#"PRIpaddr"->%#"PRIpaddr"\n",
>> +                   start, end);
>> +            return -EINVAL;
>> +        }
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +int __init remove_shm_holes_for_domU(const struct kernel_info *kinfo,
>> +                                     struct membanks *ext_regions)
>> +{
>> +    const struct membanks *shm_mem = &kinfo->shm_mem.common;
>> +    struct rangeset *guest_holes;
>> +    unsigned int i;
>> +    paddr_t start;
>> +    paddr_t end;
>> +    int res;
>> +
>> +    /* No static shared memory region. */
>> +    if ( shm_mem->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;
>> +
>> +    /* Copy extended regions sets into the rangeset */
>> +    for ( i = 0; i < ext_regions->nr_banks; i++ )
>> +    {
>> +        start = ext_regions->bank[i].start;
>> +        end = start + ext_regions->bank[i].size - 1;
>> +
>> +        res = rangeset_add_range(guest_holes, start, end);
> Ditto, PFN_DOWN().

Thanks for the review, I will fix the issues in the next push, I’ll just wait
for the serie to be fully reviewed, or if you don’t want to check the remaining
two patches before I fix the previous comments, just let me know.

> 
> ~Michal


 


Rackspace

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