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

Re: [PATCH 3/8] xen/evtchn: modify evtchn_bind_interdomain to allocate specified port


  • To: Julien Grall <julien@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 5 Jul 2022 17:42:32 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; 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=M5Dthn4IsHHsOh7wOId1n8WrGPsprAUglgudlnB1N6U=; b=AoVQGGb1GoAfDtkvQ0rYA2zEj1udLrVqWDP5I56e2nkcT5b0UqiiPvYj/sUETDmL3bcnYeG6Ke/tbbTFQZZeOJga/z4U47GZiv1TRcl3nwAxS0PX9aYPcocoOrqw71z7o9Ojf80fYK43ckiY2nZ17as7K+kLUfRhTzQjvnQU2hpRfFmrbWWCWBT8w3lfnnZQLSbXf9FfCoWklyBc5Kdx3Zlq4YffVR5gWyxj3VOx7GBFH1NthemcubYQnrz5SfUObmfmGaVAkHr/13qgHAToJaOW0Uya/t0yGeFlswRksNSfvQ+xSBG8GgbYAgAjE9tYyBC7X/Wil5fbWAeE3KaBPw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WkMkvTyxZ7iPYSI9fCxinYW99A5yBi2zBEwzcXMOadcGHL5aWHtjaRfHxQ57ms521Xb2yfosDohTJ0qsPdCArSDapy8tTvoMLs0bPRD+y/kRwrW4Dc5z+WgdSMRto6AgU3eZBD7JCq3nfk1fBZv0IN+jeI6MHSLd6Ms1s0/4Sb+0KQk1d4kLBZbozdcUVHwsAp6CZbNWsyX1iAqWXY5J6wcRSuwL4PnsgpQONpVUSMCtCrhqOMAqdEZ7kNwxkb3jCcjDROfinXvhq41fiGOHCHopWSqtVu1EZICOKLnCnaSCyiuKQTyOGMfVGFIvP9qc+VhL9IimEWlALDzTWbwJIQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: bertrand.marquis@xxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 05 Jul 2022 15:42:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 05.07.2022 17:22, Julien Grall wrote:
> Hi Jan,
> 
> On 05/07/2022 16:11, Jan Beulich wrote:
>> On 22.06.2022 16:38, Rahul Singh wrote:
>>> @@ -387,8 +392,19 @@ int evtchn_bind_interdomain(evtchn_bind_interdomain_t 
>>> *bind)
>>>           spin_lock(&ld->event_lock);
>>>       }
>>>   
>>> -    if ( (lport = get_free_port(ld)) < 0 )
>>> -        ERROR_EXIT(lport);
>>> +    if ( lport != 0 )
>>> +    {
>>> +        if ( (rc = evtchn_allocate_port(ld, lport)) != 0 )
>>> +            ERROR_EXIT_DOM(rc, ld);
>>> +    }
>>> +    else
>>> +    {
>>> +        int alloc_port = get_free_port(ld);
>>> +
>>> +        if ( alloc_port < 0 )
>>> +            ERROR_EXIT_DOM(alloc_port, ld);
>>> +        lport = alloc_port;
>>> +    }
>>
>> This is then the 3rd instance of this pattern. I think the logic
>> wants moving into get_free_port() (perhaps with a name change).
> 
> I think the code below would be suitable. I can send it or Rahul can 
> re-use the commit [1]:

Ah yes; probably makes sense (right now) only in the context of his
series.

> --- a/xen/common/event_channel.c
> +++ b/xen/common/event_channel.c
> @@ -292,6 +292,18 @@ void evtchn_free(struct domain *d, struct evtchn *chn)
>       xsm_evtchn_close_post(chn);
>   }
> 
> +static int evtchn_get_port(struct domain *d, uint32_t port)

Preferably evtchn_port_t.

> +{
> +    int rc;
> +
> +    if ( port != 0 )
> +        rc = evtchn_allocate_port(d, port);
> +    else
> +        rc = get_free_port(d);
> +
> +    return rc != 0 ? rc : port;

We commonly use "rc ?: port" in such cases. At which point I'd be
inclined to make it just

static int evtchn_get_port(struct domain *d, evtchn_port_t port)
{
    return (port ? evtchn_allocate_port(d, port)
                 : get_free_port(d)) ?: port;
}

But I can see you or others having reservations against such ...

Jan



 


Rackspace

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