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

Re: [PATCH v4] tools/foreignmem: Support querying the size of a resource


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Manuel Bouyer <bouyer@xxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Fri, 29 Jan 2021 15:09:30 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.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-SenderADCheck; bh=xO1cC5UEnPKjemPeyqdDt6wCHnHrCs9VqH2wl+jbuOg=; b=QTT+ARbCakOlypyCjOoGXJSV00bNepoHdsv/2Wxw7bJJx4EgxF2BWSOPE9/1DoUXo5ir9kcqG2DC0TcCe8Z806r2lpqTOIpLKkKR2USQT3pUXvsPG3k6znfiDivm38VBCfvk8k0edIFdA8NObKEYv+FPrUkeRrOEwcafRLcOMwLCSuSbkBtuhKoPDs25NDMtGkvi7qXOnHPXshKKZWXsFTS0eEbsD/zus1NvrCGUSBIXyRQ8ZKvcu7koxh/4pTa8uokH4E8i3Y/+nwaICgS/AkIaIC6P9dxqyDyDFElpTu061l/mJ3+KOc991wEBuuIHNawMvzcFMuq03sf5v6LDcQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lBsFR498jLROs+DpT+Q6eH70ar9HNrw5+jdOvcV/q99p8e5rGZ2FVIllf+VXgSDb7wUf+r+PyKHaTdpmOOWsQ3Wtz6GeHIrOtugYcoYjzb6NHuWpSxPK3cwtYrux/Ayrte2wCRHM5aJwAFPubRgVkC49jPXA65nijsTCjw9WyWDSpqQbFWqijkYKi1s2GkK7Klx2zMcbCWYWxvRjUaqHCAC2BT1tyuCfK+w2KYRRIyZXzeSx2ArTg0+NMFgrKk3KoSm2Wju4Ia2SQo7gADOPMsPbaxWMm97OxlWIDhfwnkCaqR2LAJ63mE5yUSttqTMh1ZPMbEDBziuqC4jmQTDTQQ==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Paul Durrant <paul@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Micha? Leszczy?ski <michal.leszczynski@xxxxxxx>, Hubert Jasudowicz <hubert.jasudowicz@xxxxxxx>, Tamas K Lengyel <tamas@xxxxxxxxxxxxx>
  • Delivery-date: Fri, 29 Jan 2021 15:09:47 +0000
  • Ironport-sdr: ltInfohRekBYcDTzpVhjnlAPEOefnF5EVhOLoT05upoxp2mDcn3f89S9Mgb1WI8qU+VtCdUJdF pEhn3FwKyE493XLi2lyWTOL/uO+lOCs3m3BN7orq2IkR09boDOmOLPDoiRyQvwcs7smUgT46kc FrwqiyC4HtBUGmcrpTo7kLrjudJNAInqssukeVO3xjFYvfFW6pKDiMax4q6VoU2VT+vsou1fsY R+cUGJXjNwNt9AsdaczYjA+Vi7PaiDzIzSmujawFH9HNdmHByp70rRRsyr50SAJzlpC29deDxZ 5ro=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 29/01/2021 14:59, Roger Pau Monné wrote:
> On Fri, Jan 29, 2021 at 11:38:43AM +0100, Manuel Bouyer wrote:
>> On Thu, Jan 28, 2021 at 12:01:52PM +0000, Andrew Cooper wrote:
>>> With the Xen side of this interface (soon to be) fixed to return real sizes,
>>> userspace needs to be able to make the query.
>>>
>>> Introduce xenforeignmemory_resource_size() for the purpose, bumping the
>>> library minor version.
>>>
>>> Update both all osdep_xenforeignmemory_map_resource() implementations to
>>> understand size requests, skip the mmap() operation, and copy back the
>>> nr_frames field.
>>>
>>> For NetBSD, also fix up the ioctl() error path to issue an unmap(), which 
>>> was
>>> overlooked by c/s 4a64e2bb39 "libs/foreignmemory: Implement on NetBSD".
>>> [....]
>>> diff --git a/tools/libs/foreignmemory/netbsd.c 
>>> b/tools/libs/foreignmemory/netbsd.c
>>> index d26566f601..4ae60aafdd 100644
>>> --- a/tools/libs/foreignmemory/netbsd.c
>>> +++ b/tools/libs/foreignmemory/netbsd.c
>>> @@ -132,6 +132,10 @@ int osdep_xenforeignmemory_map_resource(
>>>      };
>>>      int rc;
>>>  
>>> +    if ( !fres->addr && !fres->nr_frames )
>>> +        /* Request for resource size.  Skip mmap(). */
>>> +        goto skip_mmap;
>>> +
>>>      fres->addr = mmap(fres->addr, fres->nr_frames << PAGE_SHIFT,
>>>                        fres->prot, fres->flags | MAP_ANON | MAP_SHARED, -1, 
>>> 0);
>> What happens if fres->addr is not NULL and nr_frames is 0 ?
> mmap would return MAP_FAILED and errno == EINVAL in that case AFAICT
> on Linux and FreeBSD. NetBSD mmap man page doesn't seem to mention
> what happens in that case, so the comments below apply to Linux and
> FreeBSD. Maybe we need to handle this differently for NetBSD?
>
>> Is it supposed to happen ?
> I think that's fine. Calling osdep_xenforeignmemory_map_resource with
> nr_frames == 0 is pointing to a bug in the caller, so returning error
> should be fine.
>
>> Should we assert that fres->addr is NULL when
>> nr_frames is 0 ? Or force fres->addr to NULL when nr_frames is 0 ?
> Doesn't really matter, mmap will return EINVAL if nr_frames == 0
> regardless of the value of addr.

mmap() of 0 is an unconditional failure.  So sayeth POSIX.

For the size request, we don't mmap(), and a pointer of 0 is the signal
to Xen.

For the regular mapping, we support both NULL (let the kernel choose),
and non-NULL (I want my mapping here please), just like regular mmap().

~Andrew



 


Rackspace

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