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 0394DC433E0 for ; Fri, 29 Jan 2021 10:39:11 +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 5616F64E10 for ; Fri, 29 Jan 2021 10:39:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5616F64E10 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.77939.141537 (Exim 4.92) (envelope-from ) id 1l5RB9-0007Rk-1X; Fri, 29 Jan 2021 10:39:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 77939.141537; Fri, 29 Jan 2021 10:39:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5RB8-0007Rc-SY; Fri, 29 Jan 2021 10:39:02 +0000 Received: by outflank-mailman (input) for mailman id 77939; Fri, 29 Jan 2021 10:39:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l5RB8-0007Qj-5Z for xen-devel@lists.xenproject.org; Fri, 29 Jan 2021 10:39:02 +0000 Received: from chassiron.antioche.eu.org (unknown [2001:41d0:fe9d:1101::1]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d0af308d-fae7-4161-bb7a-66b385d4958c; Fri, 29 Jan 2021 10:39:00 +0000 (UTC) Received: from rochebonne.antioche.eu.org (rochebonne [IPv6:2001:41d0:fe9d:1100:221:70ff:fe0c:9885]) by chassiron.antioche.eu.org (8.15.2/8.15.2) with ESMTP id 10TAchpQ008588; Fri, 29 Jan 2021 11:38:43 +0100 (MET) Received: by rochebonne.antioche.eu.org (Postfix, from userid 1210) id BA3E8281D; Fri, 29 Jan 2021 11:38:43 +0100 (CET) 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: d0af308d-fae7-4161-bb7a-66b385d4958c Date: Fri, 29 Jan 2021 11:38:43 +0100 From: Manuel Bouyer To: Andrew Cooper Cc: Xen-devel , Wei Liu , Paul Durrant , Roger Pau =?iso-8859-1?Q?Monn=E9?= , 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: <20210129103843.GC2015@antioche.eu.org> References: <20210128120152.9908-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210128120152.9908-1-andrew.cooper3@citrix.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (chassiron.antioche.eu.org [IPv6:2001:41d0:fe9d:1100:a00:20ff:fe1c:276e]); Fri, 29 Jan 2021 11:38:44 +0100 (MET) 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 ? Is it supposed to happen ? Should we assert that fres->addr is NULL when nr_frames is 0 ? Or force fres->addr to NULL when nr_frames is 0 ? -- Manuel Bouyer NetBSD: 26 ans d'experience feront toujours la difference --