Received: by 10.223.185.116 with SMTP id b49csp2388871wrg; Mon, 12 Feb 2018 08:48:03 -0800 (PST) X-Google-Smtp-Source: AH8x224Bx4djkTWkPGvEVVT0fX4i+dqbf73ukDMh4PzCQ3TGJSMQrBMxdCgeXds7m1CiTTjrImCP X-Received: by 2002:a17:902:8a4:: with SMTP id 33-v6mr10959003pll.279.1518454083695; Mon, 12 Feb 2018 08:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518454083; cv=none; d=google.com; s=arc-20160816; b=f2PIkUaxkgBAca04hzmSRQlKaEQ1rLCZqKFeNHw/2llJS/OFhLk5VfcVOUsuOQb1VN GUaxpoh7j5rZguvIRQwpDofkeof6aEbvLhwuwW2xPti3UxbEHestiZgrNAfKWyKC8u+Y IcZSFqDAAc8cNblVAvppY5XX+vprvkjPGr5oZRhUlW1I/w3Cp4Vl22ISg5tkagh3C5SE HRIOOgIBqcw9Mp3aHkhyNmyIlDLIhe5DMYv2lNPEzifFLqxojNbgXsFPZvhNMpgdslci mmx7GLwA4v9iH6MyaCwY6OPqhumeZNztdRNXyWbQ1C5NbwgqHDV72Ml4GXVFhADFvMdA ta5w== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=GbY0VifGYYYrOKI5kQ9XbAMF4kJwrPshXjHFwKQC5uI=; b=W5smOiyo7lIoDtsl1IX0YnjV0MsK64k9q4afLell6zaMH0CFdImiCbhO7+ByNCZRKU VORDARLnm4mDcKksFwxkIiZuj3xsOuCv4hitgKuTuH73fZ5gQ0jjb6aRGAJj0Jgfp2LE OOki3HGmd7OwUlCegMkx+8rA2ezrlHNezU4b32LUB9sQXcLDuPMBHnFzdeCoOeU1mZcR d4CPO8uPLpUEIr9tfNRHj4q6sognVcAp2//jk6IkLCckh+Xvu8D1O5/5NSPQbhsCnEQE e2UwklKABVNH1ct2ivFUzYrDGjJpxpvOf9ru57SIW1rvdWyZFTK8l8+2N4XHUZTha8Wf p95g== 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 i14si5301889pgp.516.2018.02.12.08.47.48; Mon, 12 Feb 2018 08:48:03 -0800 (PST) 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 S934204AbeBLLpo (ORCPT + 99 others); Mon, 12 Feb 2018 06:45:44 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43652 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934059AbeBLLpm (ORCPT ); Mon, 12 Feb 2018 06:45:42 -0500 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 0F97A4040093; Mon, 12 Feb 2018 11:45:42 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 516E22024CA4; Mon, 12 Feb 2018 11:45:41 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 780CA41A87; Mon, 12 Feb 2018 12:45:40 +0100 (CET) Date: Mon, 12 Feb 2018 12:45:40 +0100 From: Gerd Hoffmann To: Tomeu Vizoso Cc: linux-kernel@vger.kernel.org, Zach Reizner , kernel@collabora.com, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, "Michael S. Tsirkin" , David Airlie , Jason Wang , Stefan Hajnoczi Subject: Re: [PATCH v3 1/2] drm/virtio: Add window server support Message-ID: <20180212114540.iygbha554busy4ip@sirius.home.kraxel.org> References: <20180126135803.29781-1-tomeu.vizoso@collabora.com> <20180126135803.29781-2-tomeu.vizoso@collabora.com> <20180201163623.5cs2ysykg5wgulf4@sirius.home.kraxel.org> <49785e0d-936a-c3b4-62dd-aafc7083a942@collabora.com> <20180205122017.4vb5nlpodkq2uhxa@sirius.home.kraxel.org> <20180205160322.sntv5uoqp5o7flnh@sirius.home.kraxel.org> <20180206142302.vdjyqmnoypydci4t@sirius.home.kraxel.org> <04687943-847b-25a7-42ef-a21b4c7ef0cf@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <04687943-847b-25a7-42ef-a21b4c7ef0cf@collabora.com> User-Agent: NeoMutt/20171215 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.5]); Mon, 12 Feb 2018 11:45:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 12 Feb 2018 11:45:42 +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 Hi, > > (a) software rendering: client allocates shared memory buffer, renders > > into it, then passes a file handle for that shmem block together > > with some meta data (size, format, ...) to the wayland server. > > > > (b) gpu rendering: client opens a render node, allocates a buffer, > > asks the cpu to renders into it, exports the buffer as dma-buf > > (DRM_IOCTL_PRIME_HANDLE_TO_FD), passes this to the wayland server > > (again including meta data of course). > > > > Is that correct? > > Both are correct descriptions of typical behaviors. But it isn't spec'ed > anywhere who has to do the buffer allocation. Well, according to Pekka's reply it is spec'ed that way, for the existing buffer types. So for server allocated buffers you need (a) a wayland protocol extension and (b) support for the extension in the clients. > That's to say that if we cannot come up with a zero-copy solution for > unmodified clients, we should at least support zero-copy for cooperative > clients. "cooperative clients" == "client which has support for the wayland protocol extension", correct? > > > Creation of shareable buffer by guest > > > ------------------------------------------------- > > > > > > 1. Client requests virtio driver to create a buffer suitable for sharing > > > with host (DRM_VIRTGPU_RESOURCE_CREATE) > > > > client or guest proxy? > > As per the above, the GUI toolkit could have been modified so the client > directly creates a shareable buffer, and renders directly to it without any > extra copies. > > If clients cannot be modified, then it's the guest proxy what has to create > the shareable buffer and keep it in sync with the client's non-shareable > buffer at the right times, by intercepting wl_surface.commit messages and > copying buffer contents. Ok. > > > 4. QEMU maps that buffer to the guest's address space > > > (KVM_SET_USER_MEMORY_REGION), passes the guest PFN to the virtio driver > > > > That part is problematic. The host can't simply allocate something in > > the physical address space, because most physical address space > > management is done by the guest. All pci bars are mapped by the guest > > firmware for example (or by the guest OS in case of hotplug). > > How can KVM_SET_USER_MEMORY_REGION ever be safely used then? I would have > expected that callers of that ioctl have enough knowledge to be able to > choose a physical address that won't conflict with the guest's kernel. Depends on the kind of region. Guest RAM is allocated and mapped by qemu, guest firmware can query qemu about RAM mappings using a special interface, then create a e820 memory map for the guest os. PCI device bars are mapped according to the pci config space registers, which in turn are initialized by the guest firmware, so it is basically in the guests hand where they show up. > I see that the ivshmem device in QEMU registers the memory region in BAR 2 > of a PCI device instead. Would that be better in your opinion? Yes. > > > 4. QEMU pops data+buffers from the virtqueue, looks up shmem FD for each > > > resource, sends data + FDs to the compositor with SCM_RIGHTS > > > > BTW: Is there a 1:1 relationship between buffers and shmem blocks? Or > > does the wayland protocol allow for offsets in buffer meta data, so you > > can place multiple buffers in a single shmem block? > > The latter: > https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_shm_pool Ah, good, that makes it alot easier. So, yes, using ivshmem would be one option. Tricky part here is the buffer management though. It's just a raw piece of memory. The guest proxy could mmap the pci bar and manage it. But then it is again either unmodified guest + copying the data, or modified client (which requests buffers from guest proxy) for zero-copy. Another idea would be extending stdvga. Basically qemu would have to use shmem as backing storage for vga memory instead of anonymous memory, so it would be very simliar to ivshmem on the host side. But on the guest side we have a drm driver for it (bochs-drm). So clients can allocate dumb drm buffers for software rendering, and the buffer would already be backed by a host shmem segment. Given that wayland already supports drm buffers for 3d rendering that could work without extending the wayland protocol. The client proxy would have to translate the drm buffer into an pci bar offset and pass it to the host side. The host proxy could register the pci bar as wl_shm_pool, then just pass through the offset to reference the individual buffers. Drawback of both approaches would be that software rendering and gpu rendering would use quite different code paths. We also need a solution for the keymap shmem block. I guess the keymap doesn't change all that often, so maybe it is easiest to just copy it over (host proxy -> guest proxy) instead of trying to map the host shmem into the guest? cheers, Gerd