From patchwork Fri Jan 26 13:58:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 10186019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63854601D5 for ; Fri, 26 Jan 2018 14:06:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5609C2582C for ; Fri, 26 Jan 2018 14:06:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A7472901B; Fri, 26 Jan 2018 14:06:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DEE4F2582C for ; Fri, 26 Jan 2018 14:06:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0CBE6E2A8; Fri, 26 Jan 2018 14:06:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5AC1E6E2A8 for ; Fri, 26 Jan 2018 14:06:30 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id f71so1495730wmf.0 for ; Fri, 26 Jan 2018 06:06:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EK/Hg/YN7WzYLMliKDElUmSFxLjQPmm4IiBK5bRf1yk=; b=RzGGTHJ9pFvZ0XZ3P6ZuWFW9HZS4XNtwys95zeMy9iNvVF5Wrw+zSb171EUw6njt8V hIMW8BarMHhtjsHhLpLMtDY4G8SZCbowh3RE9c4bYEIeMY/z/jwMQlVeJsVcicTD2cV9 9wJXoZl3EQWpGSXDuzZXIi4qmG2CkwwIdM3UaCNEf/YwtXpwjHp1UjbVPFcJy59VrcX8 I06wEG8RVIYHfjEJ7kuGHCq3/ZHXRmuSosIPKzjQaLfnbau+ubWgpBNhjzn9eY9dVqm3 Nbyhh+bKAyv1r4LeGcU+L1E/jXLyDwCVkZznWnwdGfo+hsf523CdjbNeFUgIs+r+ffBr Ajaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EK/Hg/YN7WzYLMliKDElUmSFxLjQPmm4IiBK5bRf1yk=; b=tq7FsSlZ9HKDJh3ABEIhmk8Ptb+v6lBmHxhG4MlZ0djdSZU2upSG1HEyz2b7/hloVY oDZw/TUEZN5op+vWyxg0PXcyTm2kp/6vQed1VJPPuJdxvaEVm3CzsXXcx+dhQijbyDxm R90W/gRjLxqUBtWmF0PZIaM4m+fnlwR1lDTFcueCaEYovzxiJCn/fm3xOI+w7kQXXPqT 2wvlv2xbx0cIV7Y9EOiykWNmasUGbG9X+KkvkuuCzFq2Y08uSl3FRB1CaM/ek5xg/zzc y4QalTaIC22RT3WJ2osiINMIps34eiZ/vVMrFbIsQ0UoYxlIgBBK3oFHSBpchC2nlGGp tVJg== X-Gm-Message-State: AKwxyteG/11eDZPP7zWzgLYTpzLaMkBQPDWm4MKiHPJVL7Hu4BxHtKRk +lS/jYkJbGqxzr8GxOBYeyc= X-Google-Smtp-Source: AH8x226hESRLHfH4bVJgZlIOfZfmzEM1z25KxFb7wxeW3Vj9dsrEdUaYMLB+kyQ+B1HwwntO+qbKWQ== X-Received: by 10.28.20.8 with SMTP id 8mr10395743wmu.106.1516975096315; Fri, 26 Jan 2018 05:58:16 -0800 (PST) Received: from cizrna.lan ([109.72.12.188]) by smtp.gmail.com with ESMTPSA id c19sm3674481wmd.5.2018.01.26.05.58.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Jan 2018 05:58:15 -0800 (PST) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] drm/virtio: Handle buffers from the compositor Date: Fri, 26 Jan 2018 14:58:02 +0100 Message-Id: <20180126135803.29781-3-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180126135803.29781-1-tomeu.vizoso@collabora.com> References: <20180126135803.29781-1-tomeu.vizoso@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , David Airlie , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, Gerd Hoffmann , kernel@collabora.com MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP When retrieving queued messages from the compositor in the host for clients in the guest, handle buffers that may be passed. These buffers should have been mapped to the guest's address space, for example via the KVM_SET_USER_MEMORY_REGION ioctl. Signed-off-by: Tomeu Vizoso --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index d4230b1fa91d..57b1ad51d251 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -545,14 +545,58 @@ static unsigned int winsrv_poll(struct file *filp, return mask; } +struct virtio_gpu_winsrv_region { + uint64_t pfn; + size_t size; +}; + +static int winsrv_fd_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct virtio_gpu_winsrv_region *region = filp->private_data; + unsigned long vm_size = vma->vm_end - vma->vm_start; + int ret = 0; + + if (vm_size + + (vma->vm_pgoff << PAGE_SHIFT) > PAGE_ALIGN(region->size)) + return -EINVAL; + + ret = io_remap_pfn_range(vma, vma->vm_start, region->pfn, vm_size, + vma->vm_page_prot); + if (ret) + return ret; + + vma->vm_flags |= VM_PFNMAP | VM_IO | VM_DONTEXPAND | VM_DONTDUMP; + + return ret; +} + +static int winsrv_fd_release(struct inode *inodep, struct file *filp) +{ + struct virtio_gpu_winsrv_region *region = filp->private_data; + + kfree(region); + + return 0; +} + +static const struct file_operations winsrv_fd_fops = { + .mmap = winsrv_fd_mmap, + .release = winsrv_fd_release, +}; + static int winsrv_ioctl_rx(struct virtio_gpu_device *vgdev, struct virtio_gpu_winsrv_conn *conn, struct drm_virtgpu_winsrv *cmd) { struct virtio_gpu_winsrv_rx_qentry *qentry, *tmp; struct virtio_gpu_winsrv_rx *virtio_cmd; + struct virtio_gpu_winsrv_region *region; int available_len = cmd->len; int read_count = 0; + int i; + + for (i = 0; i < VIRTGPU_WINSRV_MAX_ALLOCS; i++) + cmd->fds[i] = -1; list_for_each_entry_safe(qentry, tmp, &conn->cmdq, next) { virtio_cmd = qentry->cmd; @@ -567,6 +611,16 @@ static int winsrv_ioctl_rx(struct virtio_gpu_device *vgdev, return -EFAULT; } + for (i = 0; virtio_cmd->pfns[i]; i++) { + region = kmalloc(sizeof(*region), GFP_KERNEL); + region->pfn = virtio_cmd->pfns[i]; + region->size = virtio_cmd->lens[i]; + cmd->fds[i] = anon_inode_getfd("[winsrv_fd]", + &winsrv_fd_fops, + region, + O_CLOEXEC | O_RDWR); + } + available_len -= virtio_cmd->len; read_count += virtio_cmd->len;