Received: by 10.213.65.68 with SMTP id h4csp484671imn; Fri, 6 Apr 2018 03:55:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/oemGfdMGJxpvketo/l35s6h3mVOClfddc6g91xBsEtuD62zTqX0vOZ0T+LPppF/n4DwFa X-Received: by 10.101.78.142 with SMTP id b14mr12813123pgs.406.1523012158028; Fri, 06 Apr 2018 03:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523012157; cv=none; d=google.com; s=arc-20160816; b=g5dAcE115wMY+ePFDSG6GLu4EYui1r+NWs+p1ISsrDAEq27Q2yAPkaQw8i3u99CzoY csXviwX6jd/VGm+hgOr/CRf6tmwyKnHmAq9Q70nIe6EDYijWhgRaxpY0Vnhd0r4Qw5y5 5gvB0vcvocSot8v7LM+JNwYgAWLNaEVXyofWux3zxrEsqs7xqzMxCdXxh6d1aL02fMFV 5AuLu7v+a2dJ5VtQ6BW9mHCo5kjuCeYFWAmDRK6le/flU4GIwHl/kgl5oyz1ml/hl4uj FK6/f4W9pZbL14QV1b+Opy3i+5qtIMHhGESUaoHv6zudMED7vew/FCEQVCPT/PjYv0Al RwoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=fbjkT5PBoAzc9lyd3tYzAFTGMWLUlKKEngrnSKn6qrY=; b=HlhV0wFsR0O45N8VjiiGpUkctX+Tv1/J2QqCvKJqZO5b7nYI3yKKtohjvmrmYam9Sd HomgwdFUyux3qHbSlMcsX52EAFt1hOIce9Bl15DSJ9lz9rR7o/ReT3G1gusjAM5VcLEZ dGcvw/6y/vzG1kSLv+L8Gz54gE/6bREfrUPGO5cV0M48KfxJKOiyP1BWLgQcabMVSl8w YzgSLQuMb7LeoZwiiH5fBLn34msBZr7pI98609pi/Re4m5ng/01y9qURDZjukCWL6HnZ TDwm2MC/+XcRw52HPGqciyZtJIh4Feq7LxDaVWYbMpdjmFrCQc9XrdLXvRDyg7ZZ0nHs wIKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si4307751pgs.233.2018.04.06.03.55.43; Fri, 06 Apr 2018 03:55:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752129AbeDFKyb (ORCPT + 99 others); Fri, 6 Apr 2018 06:54:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51822 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751434AbeDFKy3 (ORCPT ); Fri, 6 Apr 2018 06:54:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E677F7CBBA; Fri, 6 Apr 2018 10:54:28 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 53A9A2024CA4; Fri, 6 Apr 2018 10:54:23 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A15423200F; Fri, 6 Apr 2018 12:54:22 +0200 (CEST) Date: Fri, 6 Apr 2018 12:54:22 +0200 From: Gerd Hoffmann To: Daniel Stone Cc: dri-devel , Tomeu Vizoso , David Airlie , open list , qemu-devel@nongnu.org, "moderated list:DMA BUFFER SHARING FRAMEWORK" , "open list:DMA BUFFER SHARING FRAMEWORK" Subject: Re: [RfC PATCH] Add udmabuf misc device Message-ID: <20180406105422.6tewkkciwerud3tm@sirius.home.kraxel.org> References: <20180313154826.20436-1-kraxel@redhat.com> <20180313161035.GL4788@phenom.ffwll.local> <20180314080301.366zycak3whqvvqx@sirius.home.kraxel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180323 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 06 Apr 2018 10:54:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 06 Apr 2018 10:54:29 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 06, 2018 at 10:52:21AM +0100, Daniel Stone wrote: > Hi Gerd, > > On 14 March 2018 at 08:03, Gerd Hoffmann wrote: > >> Either mlock account (because it's mlocked defacto), and get_user_pages > >> won't do that for you. > >> > >> Or you write the full-blown userptr implementation, including mmu_notifier > >> support (see i915 or amdgpu), but that also requires Christian K?nigs > >> latest ->invalidate_mapping RFC for dma-buf (since atm exporting userptr > >> buffers is a no-go). > > > > I guess I'll look at mlock accounting for starters then. Easier for > > now, and leaves the door open to switch to userptr later as this should > > be transparent to userspace. > > Out of interest, do you have usecases for full userptr support? Maybe > another way would be to allow creation of dmabufs from memfds. I have two things in mind. One is vga emulation. I have virtual pci memory bar for the virtual vga. qemu backs vga memory with anonymous pages right now, switching that to shmem should be easy though if that makes things easier. Guest places the framebuffer somewhere in the pci bar, and I want export the chunk which represents the framebuffer as dma-buf to display it on the host without copying around data. Framebuffer is linear in guest physical memory, so a single block only. That is the simpler case. The more difficuilt one is virtio-gpu ressources. virtio-gpu resources live in host memory (guest has no direct access). The guest can optionally specify guest memory pages as backing storage for the resource. Guest backing storage is allowed to be scattered. Commands exist to copy both ways between host storage and guest backing. With virgl (opengl acceleration) enabled the guest will send rendering commands to fill the framebuffer ressource, so there is no need to copy content to the framebuffer ressource. The guest may fill other resources such as textures used for rendering with copy commands. Without acceleration the guest does software-rendering to the backing storage, then sends a command to copy the framebuffer content from guest backing storage to host ressource. Now it would be useful to allow a shared mapping, so no copying between guest backing storage and host resource is needed, especially for the software rendering case (i.e. dumb gem buffers). Being able to export guest dumb buffers to other host processes would be useful too, for example to display guest windows seamlessly on the host wayland server. So getting a dma-buf for the guest backing storage via udmabuf looked like a useful approach. We can export the guest gem buffers to other host processes that way. qemu itself could map it too, to get a linear representation of the scattered guest backing storage. The other obvious approach would be to do it the other way around and allow the guest map the host resource somehow. On the host side qemu could use vgem to allocate resource memory, so it'll be a gem object already. Mapping that into the guest isn't that straight-forward though. The guest manages its physical address space, so the guest would need to find a free spot and ask the host to place the resource there. Then the guest needs page structs covering the mapped resource, so it can work with it. Didn't investigate how difficuilt that is. Use memory hotplug maybe? Can we easily unmap the resource then? Also I think updating the guests physical memory layout (which we would need to do on every resource map/unmap) isn't an exactly cheap operation ... cheers, Gerd