Hi Michal,

> On 8 May 2024, at 13:09, Michal Orzel <michal.or...@amd.com> wrote:
> 
> Hi Luca,
> 
> On 23/04/2024 10:25, Luca Fancellu wrote:
>> 
>> 
>> Handle the parsing of the 'xen,shared-mem' property when the host physical
>> address is not provided, this commit is introducing the logic to parse it,
>> but the functionality is still not implemented and will be part of future
>> commits.
>> 
>> Rework the logic inside process_shm_node to check the shm_id before doing
>> the other checks, because it ease the logic itself, add more comment on
>> the logic.
>> Now when the host physical address is not provided, the value
>> INVALID_PADDR is chosen to signal this condition and it is stored as
>> start of the bank, due to that change also early_print_info_shmem and
>> init_sharedmem_pages are changed, to don't handle banks with start equal
>> to INVALID_PADDR.
>> 
>> Another change is done inside meminfo_overlap_check, to skip banks that
>> are starting with the start address INVALID_PADDR, that function is used
>> to check banks from reserved memory and ACPI and it's unlikely for these
> also from shmem
> 
>> bank to have the start address as INVALID_PADDR. The change holds
>> because of this consideration.
> On arm64 and LPAE arm32 we don't have this problem. In theory we could have a 
> bank
> starting at INVALID_PADDR if PA range was 32bit but as the comment above the 
> function states,
> wrapping around is not handled. You might want to use it as a justification 
> to be clear.

Sure, I’ll rephrase it, is it ok something like this:

[...]
Another change is done inside meminfo_overlap_check, to skip banks that
are starting with the start address INVALID_PADDR, that function is used
to check banks from reserved memory, shared memory and ACPI and since
the comment above the function states that wrapping around is not handled,
it’s unlikely for these bank to have the start address as INVALID_PADDR.
The change holds because of this consideration.

>> 
>> diff --git a/xen/arch/arm/static-shmem.c b/xen/arch/arm/static-shmem.c
>> index 24e40495a481..1c03bb7f1882 100644
>> --- a/xen/arch/arm/static-shmem.c
>> +++ b/xen/arch/arm/static-shmem.c
>> @@ -264,6 +264,12 @@ 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);
> The dot at the end is not needed.
Will fix


>> 
>> -    end = paddr + size;
>> -    if ( end <= paddr )
>> -    {
>> -        printk("fdt: static shared memory region %s overflow\n", shm_id);
>> -        return -EINVAL;
>> -    }
>> -
>>     for ( i = 0; i < mem->nr_banks; i++ )
>>     {
>>         /*
>>          * Meet the following check:
>> +         * when host address is provided:
> - when would read better
Ok I’ll use hyphen instead of star, here and below

> 
>>          * 1) The shm ID matches and the region exactly match
>>          * 2) The shm ID doesn't match and the region doesn't overlap
>>          * with an existing one
>> +         * when host address is not provided:
>> +         * 1) The shm ID matches and the region size exactly match
>>          */
>> -        if ( paddr == mem->bank[i].start && size == mem->bank[i].size )
>> +        bool paddr_assigned = INVALID_PADDR == paddr;
> parenthesis around INVALID_PADDR == paddr
Ok

> 
>> +        bool shm_id_match = strncmp(shm_id, shmem_extra[i].shm_id,
>> +                                    MAX_SHM_ID_LENGTH) == 0;
> why not if ( strncmp... given no other use of this variable other than the 
> one below?

Yeah I think in some previous rework I was using multiple times and then I 
forgot to
change here, I’ll fix

> 
>> +        if ( shm_id_match )
>>         {
>> -            if ( strncmp(shm_id, shmem_extra[i].shm_id,
>> -                         MAX_SHM_ID_LENGTH) == 0  )
>> +            /*
>> +             * Regions have same shm_id (cases):
>> +             * 1) physical host address is supplied:
>> +             *    - OK:   paddr is equal and size is equal (same region)
>> +             *    - Fail: paddr doesn't match or size doesn't match (there
>> +             *            cannot exists two shmem regions with same shm_id)
>> +             * 2) physical host address is NOT supplied:
>> +             *    - OK:   size is equal (same region)
>> +             *    - Fail: size is not equal (same shm_id must identify only 
>> one
>> +             *            region, there can't be two different regions with 
>> same
>> +             *            shm_id)
>> +             */
>> +            bool start_match = paddr_assigned ? (paddr == 
>> mem->bank[i].start) :
>> +                                                true;
>> +
>> +            if ( start_match && size == mem->bank[i].size )
>>                 break;
>>             else
>>             {
>> -                printk("fdt: xen,shm-id %s does not match for all the nodes 
>> using the same region.\n",
>> +                printk("fdt: different shared memory region could not share 
>> the same shm ID %s\n",
>>                        shm_id);
>>                 return -EINVAL;
>>             }
>>         }
>> -        else if ( strncmp(shm_id, shmem_extra[i].shm_id,
>> -                          MAX_SHM_ID_LENGTH) != 0 )
>> -            continue;
>>         else
>>         {
> There is no need for this else and entire block given that the block within 
> if either calls break or return

There was a MISRA discussion about else at the end of if ... else if ... 
(R15.7) and I don’t remember
the outcome
>> 
>> @@ -588,13 +637,16 @@ void __init early_print_info_shmem(void)
>> {
>>     const struct membanks *shmem = bootinfo_get_shmem();
>>     unsigned int bank;
>> +    unsigned int printed = 0;
>> 
>>     for ( bank = 0; bank < shmem->nr_banks; bank++ )
>> -    {
>> -        printk(" SHMEM[%u]: %"PRIpaddr" - %"PRIpaddr"\n", bank,
>> -               shmem->bank[bank].start,
>> -               shmem->bank[bank].start + shmem->bank[bank].size - 1);
>> -    }
>> +        if ( shmem->bank[bank].start != INVALID_PADDR )
>> +        {
>> +            printk(" SHMEM[%u]: %"PRIpaddr" - %"PRIpaddr"\n", printed,
>> +                shmem->bank[bank].start,
>> +                shmem->bank[bank].start + shmem->bank[bank].size - 1);
>> +            printed++;
> NIT: you could initialize and increment it as part of the for loop
Sure, I’ll do

Reply via email to