From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 AF7E7C433DB for ; Mon, 11 Jan 2021 15:00:55 +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 580AD22795 for ; Mon, 11 Jan 2021 15:00:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 580AD22795 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cam.ac.uk 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.64937.114870 (Exim 4.92) (envelope-from ) id 1kyygU-0001hH-3T; Mon, 11 Jan 2021 15:00:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 64937.114870; Mon, 11 Jan 2021 15:00:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kyygU-0001h8-0P; Mon, 11 Jan 2021 15:00:42 +0000 Received: by outflank-mailman (input) for mailman id 64937; Mon, 11 Jan 2021 15:00:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kyygR-0001g7-6J for xen-devel@lists.xenproject.org; Mon, 11 Jan 2021 15:00:40 +0000 Received: from ppsw-31.csi.cam.ac.uk (unknown [131.111.8.131]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1dad11a8-ffdd-4b11-9c0b-d66498647b71; Mon, 11 Jan 2021 15:00:37 +0000 (UTC) Received: from 88-111-124-141.dynamic.dsl.as9105.com ([88.111.124.141]:36330 helo=[192.168.1.219]) by ppsw-31.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.157]:465) with esmtpsa (PLAIN:amc96) (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1kyygL-000R4V-Jg (Exim 4.92.3) (return-path ); Mon, 11 Jan 2021 15:00:33 +0000 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: 1dad11a8-ffdd-4b11-9c0b-d66498647b71 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cam.ac.uk; s=20180806.ppsw; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KgJp4p3kEMjVNvESe4JFEFFydJ10FSWl/zJdaQ6Y3w4=; b=PZyqVAsks2gjMh9YXZ+V5Dd+v/ Mf2v8zFd031AafZvIXYynf89yxK4Fh3UDczVuWz4rYKzldISD/5ndjUiupq6GngvECWfxSDCtEt7S IN9Tp+DyDQpazqfibSNareSXRGt+EFphjXErQ18q14DtCewbXEznNM7fRmw/j/tl6sv8=; X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://help.uis.cam.ac.uk/email-scanner-virus Subject: Re: [PATCH v2 05/11] tools/foreignmem: Support querying the size of a resource To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: Xen-devel , Ian Jackson , =?UTF-8?Q?Micha=c5=82_Leszczy=c5=84ski?= , Hubert Jasudowicz , Tamas K Lengyel , Andrew Cooper References: <20200922182444.12350-1-andrew.cooper3@citrix.com> <20200922182444.12350-6-andrew.cooper3@citrix.com> <22be067c-1e6f-c87d-f910-ced27091a87a@cam.ac.uk> <20210111105001.xioy763vaior5udg@Air-de-Roger> From: Andrew Cooper Autocrypt: addr=amc96@cam.ac.uk; keydata= mQINBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i446JOa2vpCI9GcjCzi3oHV e00bzYiHMIl0FICrNJU0Kjho8pdo0m2uxkn6SYEpogAy9pnatUlO+erL4LqFUO7GXSdBRbw5 gNt25XTLdSFuZtMxkY3tq8MFss5QnjhehCVPEpE6y9ZjI4XB8ad1G4oBHVGK5LMsvg22PfMJ ISWFSHoF/B5+lHkCKWkFxZ0gZn33ju5n6/FOdEx4B8cMJ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Hwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSod5bD8kMSCYsTqtTf T6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs6+ahAA== Message-ID: <5d536d73-84ef-bd48-e8b7-4037bdfafe18@cam.ac.uk> Date: Mon, 11 Jan 2021 15:00:32 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210111105001.xioy763vaior5udg@Air-de-Roger> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-GB On 11/01/2021 10:50, Roger Pau Monné wrote: > On Fri, Jan 08, 2021 at 05:52:36PM +0000, Andrew Cooper wrote: >> On 22/09/2020 19:24, Andrew Cooper wrote: >>> diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/linux.c >>> index fe73d5ab72..eec089e232 100644 >>> --- a/tools/libs/foreignmemory/linux.c >>> +++ b/tools/libs/foreignmemory/linux.c >>> @@ -339,6 +342,39 @@ int osdep_xenforeignmemory_map_resource( >>> return 0; >>> } >>> >>> +int osdep_xenforeignmemory_resource_size( >>> + xenforeignmemory_handle *fmem, domid_t domid, unsigned int type, >>> + unsigned int id, unsigned long *nr_frames) >>> +{ >>> + int rc; >>> + struct xen_mem_acquire_resource *xmar = >>> + xencall_alloc_buffer(fmem->xcall, sizeof(*xmar)); >>> + >>> + if ( !xmar ) >>> + { >>> + PERROR("Could not bounce memory for acquire_resource hypercall"); >>> + return -1; >>> + } >>> + >>> + *xmar = (struct xen_mem_acquire_resource){ >>> + .domid = domid, >>> + .type = type, >>> + .id = id, >>> + }; >>> + >>> + rc = xencall2(fmem->xcall, __HYPERVISOR_memory_op, >>> + XENMEM_acquire_resource, (uintptr_t)xmar); >>> + if ( rc ) >>> + goto out; >>> + >>> + *nr_frames = xmar->nr_frames; >>> + >>> + out: >>> + xencall_free_buffer(fmem->xcall, xmar); >>> + >>> + return rc; >>> +} >> Having talked this through with Roger, it's broken. >> >> In the meantime, foreignmem has gained acquire_resource on FreeBSD. >> Nothing in this osdep function is linux-specific, so it oughtn't to be >> osdep. >> >> However, its also not permitted to make hypercalls like this in >> restricted mode, and that isn't something we should be breaking.  >> Amongst other things, it will prevent us from supporting >128 cpus, as >> Qemu needs updating to use this interface in due course. >> >> The only solution (which keeps restricted mode working) is to fix >> Linux's ioctl() to be able to understand size requests.  This also >> avoids foreignmem needing to open a xencall handle which was fugly in >> the first place. > I think the following patch should allow you to fetch the resource > size from Linux privcmd driver by doing an ioctl with addr = 0 and num > = 0. I've just build tested it, but I haven't tried exercising the > code. > > Roger. > ---8<--- > From 5d717c7b9ad3561ed0b17e7c5cf76b7c9fb536db Mon Sep 17 00:00:00 2001 > From: Roger Pau Monne > Date: Mon, 11 Jan 2021 10:38:59 +0100 > Subject: [PATCH] xen/privcmd: allow fetching resource sizes > MIME-Version: 1.0 > Content-Type: text/plain; charset=UTF-8 > Content-Transfer-Encoding: 8bit > > Allow issuing an IOCTL_PRIVCMD_MMAP_RESOURCE ioctl with num = 0 and > addr = 0 in order to fetch the size of a specific resource. > > Add a shortcut to the default map resource path, since fetching the > size requires no address to be passed in, and thus no VMA to setup. > > Signed-off-by: Roger Pau Monné Tested-by: Andrew Cooper > --- > NB: fetching the size of a resource shouldn't trigger an hypercall > preemption, and hence I've dropped the preempt indications. Yeah - that's fine.  Querying the size isn't ever going to turn into a long running operation from the guest's point of view. I'll submit the matching patch for libxenforeignmem. ~Andrew