Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADF50C433E6 for ; Fri, 29 Jan 2021 15:37:59 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2771564E05 for ; Fri, 29 Jan 2021 15:37:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2771564E05 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=antioche.eu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.78248.142272 (Exim 4.92) (envelope-from ) id 1l5VqD-0001a8-M0; Fri, 29 Jan 2021 15:37:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 78248.142272; Fri, 29 Jan 2021 15:37:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5VqD-0001a1-Iu; Fri, 29 Jan 2021 15:37:45 +0000 Received: by outflank-mailman (input) for mailman id 78248; Fri, 29 Jan 2021 15:37:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5VqC-0001Zw-Cd for xen-devel@lists.xenproject.org; Fri, 29 Jan 2021 15:37:44 +0000 Received: from isis.lip6.fr (unknown [2001:660:3302:283c::2]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b38687c4-395b-4833-8f1d-f7baec6aee38; Fri, 29 Jan 2021 15:37:43 +0000 (UTC) Received: from asim.lip6.fr (asim.lip6.fr [132.227.86.2]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTP id 10TFbZOJ017442; Fri, 29 Jan 2021 16:37:35 +0100 (CET) Received: from armandeche.soc.lip6.fr (armandeche [132.227.63.133]) by asim.lip6.fr (8.15.2/8.14.4) with ESMTP id 10TFbZfp012739; Fri, 29 Jan 2021 16:37:35 +0100 (MET) Received: by armandeche.soc.lip6.fr (Postfix, from userid 20331) id 1DEB77218; Fri, 29 Jan 2021 16:37:34 +0100 (MET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b38687c4-395b-4833-8f1d-f7baec6aee38 Date: Fri, 29 Jan 2021 16:37:34 +0100 From: Manuel Bouyer To: Andrew Cooper Cc: Roger Pau =?iso-8859-1?Q?Monn=E9?= , Xen-devel , Wei Liu , Paul Durrant , Juergen Gross , Ian Jackson , Micha? Leszczy?ski , Hubert Jasudowicz , Tamas K Lengyel Subject: Re: [PATCH v4] tools/foreignmem: Support querying the size of a resource Message-ID: <20210129153734.GB18282@mail.soc.lip6.fr> References: <20210128120152.9908-1-andrew.cooper3@citrix.com> <20210129103843.GC2015@antioche.eu.org> <61ab107e-70e0-0445-bf4a-6c7031cff949@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <61ab107e-70e0-0445-bf4a-6c7031cff949@citrix.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Fri, 29 Jan 2021 16:37:36 +0100 (CET) X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 On Fri, Jan 29, 2021 at 03:09:30PM +0000, Andrew Cooper wrote: > 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(). OK, so that's no a bug. Thanks -- Manuel Bouyer NetBSD: 26 ans d'experience feront toujours la difference --