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

Re: [PATCH v2 6/7] xen/arm: Implement the logic for static shared memory from Xen heap


  • To: Michal Orzel <michal.orzel@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Mon, 20 May 2024 12:44:26 +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=arm.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=FUVo4RFHYXH7qAZMy3ECxtKeGZ0y4iTDJ3FSuBnpHuo=; b=CT0oZYBxYlWmIVkBD7ytwGUnesexO5uWwG7xO+uCSAgDFISKM9vYBx7zWKx8nYpH99/Uola3TfMgjyU78PyQRPZTT14CIDuIsQ9BrXaW1YSdLtfzlNx/bs043ErT9hYEgaIyIWkhSxM5eBOKEfiGDdVizKdKmsHgmpD3FWztzCKgtKyiDYreW8aQLVuQzlgwfKtqgZ8bOibwHoUB40G8nNuJxZqTsUsUmOnIdbizq+1o5LnEfAda8uxbADz2sUdXyAmbC1MHIJnn4995XUMRe4Fy0V8oGseu26XnecBhK8HlreJe5JdpF2uVdPE8hpklsaf2F+jeZ9m5LFSCbVCOpA==
  • 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=FUVo4RFHYXH7qAZMy3ECxtKeGZ0y4iTDJ3FSuBnpHuo=; b=RdiY2XmCBRqpFmCl9gSqQjfLyyvceYmEnHG3N/KnPQSObDEBdSjvh9t7LYnVol0KreA89CkLZYupR8+mnu/Jt5gMHsiLTTzeYDQBYVMtpWaQk403i7FMyW3kmCCmeDd1L8bJA7JI2moWPWZhZkwxiAbW1lS8O9Zju8ftp13GP7awYprh35zyc3q2O2InSpg292OEtNrpq/8ZEfpCrXB6OhCjRF7wJbxn9yBZ7UgWdtlZY+pbERpn9uNTRkAs+3LNLmGw/e3yoQm7HccpIfuAvY9KL2H/c1HHKknsLlJ1DP02eMoXgs4HnvfPDOrAa+xnWrkb/CjUMeq+ezVlB7auTA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=a6y8fbZYiCOUvXhxbXdWr1XVlQsPIDmrzv97k9EiEYFrxJe0J4Fgj/KpwmA0YKEegBFb8O6fDaVpuwjMi5FTxGXJXk8or4Gx4/J9e6rx3PWRvr4GOxhf++hm/SNnn1zpHdsB4/aGS6bIQCA7juMTOdzBMmV1ZiS5ICP/porkRBosTJm48OLjbt0eHk4uC5wxozXZ/2DRiidSYzx5zNZ99EK4hCEundIROs0506wF05EuzUpk6KikvjnxkFG/9nECZB27WsJhHA6sHYYOVkeCTC4ZgIM7m3JVWlFo/f0Bh/JWm1aRDSUMSgnkygcyEwidFvJowXQ8fK2q/XCBp34hLQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SPYUyasNMx5xecrhXXHvhvnIbU4ahWX+rqQ/PE3NnkswH1PKc5O6ezmEhN6K07Bx9gs38HwOgrYnij0oTt+2AliOnzvDhR2LGfvGYlrogstcfTMN3ZgVNwrbo3WmitD1gB4RXysGaj+G4Q1rX8spaJn/cyU5cl42ON3dytnwFNb1fFmI0F/vRftAT5x2njHK8pKX7XTczBkzit9lAsl2qKskaUSRfdz2C1ixGf9azGwb0GZfONKMZQmeuMqIn3eLvs2Qk7FafOfjpYCVba6fO4A6iXrKQ/BCDXBrUssthBtU99jv6T0JIMkO0tiUBYPukK6KjSRLKYgyGcmJjkK7bQ==
  • 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>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 20 May 2024 12:45:02 +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: AQHaptP4l1WkDlPwC0KOp+ZDl+nOHbGgALAAgAAYgIA=
  • Thread-topic: [PATCH v2 6/7] xen/arm: Implement the logic for static shared memory from Xen heap

Hi Michal,

> On 20 May 2024, at 12:16, Michal Orzel <michal.orzel@xxxxxxx> wrote:
> 
> Hi Luca,
> 
> On 15/05/2024 16:26, Luca Fancellu wrote:
>> 
>> 
>> This commit implements the logic to have the static shared memory banks
>> from the Xen heap instead of having the host physical address passed from
>> the user.
>> 
>> When the host physical address is not supplied, the physical memory is
>> taken from the Xen heap using allocate_domheap_memory, the allocation
>> needs to occur at the first handled DT node and the allocated banks
>> need to be saved somewhere, so introduce the 'shm_heap_banks' static
>> global variable of type 'struct meminfo' that will hold the banks
>> allocated from the heap, its field .shmem_extra will be used to point
>> to the bootinfo shared memory banks .shmem_extra space, so that there
>> is not further allocation of memory and every bank in shm_heap_banks
>> can be safely identified by the shm_id to reconstruct its traceability
>> and if it was allocated or not.
> NIT for the future: it's better to split 10 lines long sentence into multiple 
> ones.
> Otherwise it reads difficult.

I’ll do,

>> 
>> xen/arch/arm/static-shmem.c | 186 ++++++++++++++++++++++++++++++------
>> 1 file changed, 155 insertions(+), 31 deletions(-)
>> 
>> diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c
>> index ddaacbc77740..9c3a83042d8b 100644
>> --- a/xen/arch/arm/static-shmem.c
>> +++ b/xen/arch/arm/static-shmem.c
>> @@ -9,6 +9,22 @@
>> #include <asm/static-memory.h>
>> #include <asm/static-shmem.h>
>> 
>> +typedef struct {
>> +    struct domain *d;
>> +    paddr_t gbase;
>> +    const char *role_str;
> You could swap role_str and gbase to avoid a 4B hole on arm32

Sure I will,

> 
>> +    struct shmem_membank_extra *bank_extra_info;
>> +} alloc_heap_pages_cb_extra;
>> +
>> +static struct meminfo __initdata shm_heap_banks = {
>> +    .common.max_banks = NR_MEM_BANKS
> Do we expect that many banks?

Not really, but I was trying to don’t introduce another type, do you think it’s 
better instead to
introduce a new type only here, with a lower amount of banks?

Because if we take struct shared_meminfo, we would waste mem for its ‘extra’ 
member.

>> 
>> static int __init assign_shared_memory(struct domain *d, paddr_t gbase,
>> +                                       bool bank_from_heap,
>>                                        const struct membank *shm_bank)
>> {
>>     mfn_t smfn;
>> @@ -109,10 +138,7 @@ static int __init assign_shared_memory(struct domain 
>> *d, paddr_t gbase,
>>     psize = shm_bank->size;
>>     nr_borrowers = shm_bank->shmem_extra->nr_shm_borrowers;
>> 
>> -    printk("%pd: allocate static shared memory BANK 
>> %#"PRIpaddr"-%#"PRIpaddr".\n",
>> -           d, pbase, pbase + psize);
>> -
>> -    smfn = acquire_shared_memory_bank(d, pbase, psize);
>> +    smfn = acquire_shared_memory_bank(d, pbase, psize, bank_from_heap);
>>     if ( mfn_eq(smfn, INVALID_MFN) )
>>         return -EINVAL;
>> 
>> @@ -183,6 +209,7 @@ append_shm_bank_to_domain(struct kernel_info *kinfo, 
>> paddr_t start,
>> 
>> static int __init handle_shared_mem_bank(struct domain *d, paddr_t gbase,
>>                                          const char *role_str,
>> +                                         bool bank_from_heap,
>>                                          const struct membank *shm_bank)
>> {
>>     bool owner_dom_io = true;
>> @@ -192,6 +219,9 @@ static int __init handle_shared_mem_bank(struct domain 
>> *d, paddr_t gbase,
>>     pbase = shm_bank->start;
>>     psize = shm_bank->size;
>> 
>> +    printk("%pd: SHMEM map from %s: mphys 0x%"PRIpaddr" -> gphys 
>> 0x%"PRIpaddr", size 0x%"PRIpaddr"\n",
>> +           d, bank_from_heap ? "Xen heap" : "Host", pbase, gbase, psize);
> This looks more like a debug print since I don't expect user to want to see a 
> machine address.

printk(XENLOG_DEBUG ? 


>> 
>> int __init process_shm(struct domain *d, struct kernel_info *kinfo,
>>                        const struct dt_device_node *node)
>> {
>> @@ -265,37 +329,97 @@ int __init process_shm(struct domain *d, struct 
>> kernel_info *kinfo,
>>         pbase = boot_shm_bank->start;
>>         psize = boot_shm_bank->size;
>> 
>> -        if ( INVALID_PADDR == pbase )
>> -        {
>> -            printk("%pd: host physical address must be chosen by users at 
>> the moment", d);
>> -            return -EINVAL;
>> -        }
>> +        /* "role" property is optional */
>> +        dt_property_read_string(shm_node, "role", &role_str);
> This function returns a value but you seem to ignore it

Sure, I’ll handle that

>> 
>> -        ret = handle_shared_mem_bank(d, gbase, role_str, boot_shm_bank);
>> -        if ( ret )
>> -            return ret;
>> +            if ( !alloc_bank )
>> +            {
>> +                alloc_heap_pages_cb_extra cb_arg = { d, gbase, role_str,
>> +                    boot_shm_bank->shmem_extra };
>> +
>> +                /* shm_id identified bank is not yet allocated */
>> +                if ( !allocate_domheap_memory(NULL, psize, 
>> save_map_heap_pages,
>> +                                              &cb_arg) )
>> +                {
>> +                    printk(XENLOG_ERR
>> +                           "Failed to allocate (%"PRIpaddr"MB) pages as 
>> static shared memory from heap\n",
> Why limiting to MB?

I think I used it from domain_build.c, do you think it’s better to limit it on 
KB instead?

>> 
>> +                for ( ; alloc_bank < end_bank; alloc_bank++ )
>> +                {
>> +                    if ( strncmp(shm_id, alloc_bank->shmem_extra->shm_id,
>> +                                 MAX_SHM_ID_LENGTH) != 0 )
> shm_id has been already validated above, hence no need for a safe version of 
> strcmp
> 

I always try to use the safe version, even when redundant, I feel that if 
someone is copying part of the code,
at least it would copy a safe version. Anyway I will change it if it’s not 
desirable.

Cheers,
Luca



 


Rackspace

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