From patchwork Thu Feb 13 23:18:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11381435 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 289BE139A for ; Thu, 13 Feb 2020 23:18:23 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 068ED2082F for ; Thu, 13 Feb 2020 23:18:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Kf4xlv2t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 068ED2082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A2FA66E34D; Thu, 13 Feb 2020 23:18:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id 444B96E34D for ; Thu, 13 Feb 2020 23:18:19 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id x185so3845922pfc.5 for ; Thu, 13 Feb 2020 15:18:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8bmYzwj8p15X4MRtIBLt/3i1qZawBy0sR5wgfSYkNHg=; b=Kf4xlv2t9foMRNGLiNwubNsnrVsqpS1DttQ/YFBlBC41XU7W+B+yOKz1bc8T45ImEU 3wyMSJqmpO/BotnGiODZQMHDbGEnrbDg9E4kckPWQlksa5o1yC+4LS6s1pGn83AofBx3 edLRxZvxSqjGMbDP4midqiAv5JQB+pm8REYV4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8bmYzwj8p15X4MRtIBLt/3i1qZawBy0sR5wgfSYkNHg=; b=Lu4Z09kiOEWZhNcnsiR4fO7AmVbdxi+2Sy3c5utHqlLYkTyHXSEaH1wTaPpxq4A7yC zbqzBzy+fd24QDu3r97PnbtKo9pYwHo8JNYf/k4vlqp9GnocNGkKGbmmK00QwqKBR7aP LY9C1gZlr3x0NpxX3aZWcGJa9ig7E5AF2PdNFnd9hN2L1xm1Wi1jDg325h3HWPCGO0H5 yfJLYclBx9bZYjm2EcFoufBawDDBvRRUsZontM/Y4pNbMJKvDFKBs4uGaOW5jPjb2BHj 7kU81bH2ZPn/R/PT4d81YhOIQMAI8Q+KTlgS/6yTog7jSq8XwXjlLf7Ig5b748GcFIbZ XDNg== X-Gm-Message-State: APjAAAUivXCs9w4TEKYz70K51ICpWSMZsF/uF7mvTmhYJLFnMs1O80K+ fOCPiBkAUXvAdln0trBqrv2q3ItLuTw= X-Google-Smtp-Source: APXvYqxnsNxjBk8wwQ4/SwWHhGVKYamhTP9Cd0PWo/e7PFZUQofkTylaK7Ey1fPPQbWs9DW6HMqt3w== X-Received: by 2002:aa7:8703:: with SMTP id b3mr193595pfo.67.1581635898568; Thu, 13 Feb 2020 15:18:18 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id w17sm4253495pfi.56.2020.02.13.15.18.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Feb 2020 15:18:18 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/virtio: use consistent names for drm_files Date: Thu, 13 Feb 2020 15:18:01 -0800 Message-Id: <20200213231805.622-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213231805.622-1-gurchetansingh@chromium.org> References: <20200213231805.622-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , kraxel@redhat.com, jbates@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Minor cleanup, change: - file_priv--> file, - drm_file --> file. Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index 467649733d24..b0edf1ca095f 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -34,12 +34,12 @@ #include "virtgpu_drv.h" static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, - struct drm_file *file_priv) + struct drm_file *file) { struct virtio_gpu_device *vgdev = dev->dev_private; struct drm_virtgpu_map *virtio_gpu_map = data; - return virtio_gpu_mode_dumb_mmap(file_priv, vgdev->ddev, + return virtio_gpu_mode_dumb_mmap(file, vgdev->ddev, virtio_gpu_map->handle, &virtio_gpu_map->offset); } @@ -51,11 +51,11 @@ static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, * VIRTIO_GPUReleaseInfo struct (first XXX bytes) */ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, - struct drm_file *drm_file) + struct drm_file *file) { struct drm_virtgpu_execbuffer *exbuf = data; struct virtio_gpu_device *vgdev = dev->dev_private; - struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv; + struct virtio_gpu_fpriv *vfpriv = file->driver_priv; struct virtio_gpu_fence *out_fence; int ret; uint32_t *bo_handles = NULL; @@ -116,7 +116,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, goto out_unused_fd; } - buflist = virtio_gpu_array_from_handles(drm_file, bo_handles, + buflist = virtio_gpu_array_from_handles(file, bo_handles, exbuf->num_bo_handles); if (!buflist) { ret = -ENOENT; @@ -177,7 +177,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, } static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data, - struct drm_file *file_priv) + struct drm_file *file) { struct virtio_gpu_device *vgdev = dev->dev_private; struct drm_virtgpu_getparam *param = data; @@ -200,7 +200,7 @@ static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data, } static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, - struct drm_file *file_priv) + struct drm_file *file) { struct virtio_gpu_device *vgdev = dev->dev_private; struct drm_virtgpu_resource_create *rc = data; @@ -251,7 +251,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, return ret; obj = &qobj->base.base; - ret = drm_gem_handle_create(file_priv, obj, &handle); + ret = drm_gem_handle_create(file, obj, &handle); if (ret) { drm_gem_object_release(obj); return ret; @@ -264,13 +264,13 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, } static int virtio_gpu_resource_info_ioctl(struct drm_device *dev, void *data, - struct drm_file *file_priv) + struct drm_file *file) { struct drm_virtgpu_resource_info *ri = data; struct drm_gem_object *gobj = NULL; struct virtio_gpu_object *qobj = NULL; - gobj = drm_gem_object_lookup(file_priv, ri->bo_handle); + gobj = drm_gem_object_lookup(file, ri->bo_handle); if (gobj == NULL) return -ENOENT; From patchwork Thu Feb 13 23:18:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11381439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D7AF1580 for ; Thu, 13 Feb 2020 23:18:28 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 4C1FD2082F for ; Thu, 13 Feb 2020 23:18:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GI/gCn/u" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C1FD2082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E17C36E027; Thu, 13 Feb 2020 23:18:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by gabe.freedesktop.org (Postfix) with ESMTPS id 635586E425 for ; Thu, 13 Feb 2020 23:18:24 +0000 (UTC) Received: by mail-pg1-x541.google.com with SMTP id 70so3918622pgf.8 for ; Thu, 13 Feb 2020 15:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XQxu+IIoe5xi2um76QACcOIx6minXqqqvbsYqyoO+Q0=; b=GI/gCn/uEGCQ1EF1NZMNjE7tWl6JXS8EWPWBciUD2elsV7ayvNRwoL3hkC0Wj7StVJ 1fHuFUxrfz1N/sELY7rkuv8YyEIg47X2WOPNXaM9EPbz0pB4aYVbeDWJWACMJxaxaeFw zAqvobjcjOJ4WifQzk2JLqQgv1elBeMWMDWAc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XQxu+IIoe5xi2um76QACcOIx6minXqqqvbsYqyoO+Q0=; b=pN/aLOwTmKYiU8tYVJArR8a7HpZ6CU2DSWdYjIQdXh+SJTwHxUxPtxOquANXyeEJQk VVkpYPGeCDMirJisCjh/cePyZD1wpPqlWkB1hPFORH5qeBqvAxIYFRfs2f21MBZ8qNuK XJCt8njAdpLoDWA766I31W0CD1o/qMI3e8SXbkP/sutpd8WSIrKLUT7gCjXxXXLDWCpj 8dsMO+WsoOJC+SOHi/dZpVSVGnbrbtW01yogQdZDSg9MFsCoMLeNrbp4n3d7PXtqAwRh FNV5o8ATzHxw7rKY/1uxM1sDCvRmESxKpY+cozLzp4pZ6QT6Oifz/Pi3DY+1Lf9jNPii 0dKA== X-Gm-Message-State: APjAAAX4JtynDBJPC5liGz14LDv67tIEvRCZt0se57vYIfqtk5uZlooP E/sNFT3KnzTtLk+p6E87wskobNELxQE= X-Google-Smtp-Source: APXvYqxCVz6JZ1qNRBuGU2PB3zT++7rsslJhITm7pC2NFzZor2njVQ6oSf1jr1BeheEd/bLpypNJJw== X-Received: by 2002:a63:e954:: with SMTP id q20mr341095pgj.204.1581635903472; Thu, 13 Feb 2020 15:18:23 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id w17sm4253495pfi.56.2020.02.13.15.18.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Feb 2020 15:18:22 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/virtio: factor out context create hyercall Date: Thu, 13 Feb 2020 15:18:02 -0800 Message-Id: <20200213231805.622-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213231805.622-1-gurchetansingh@chromium.org> References: <20200213231805.622-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , kraxel@redhat.com, jbates@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We currently create an OpenGL context when opening the DRM fd if 3D is available. We may need other context types (VK,..) in the future, and the plan is to have explicit initialization for that. For explicit initialization to work, we need to factor out virtio_gpu_create_context from driver initialization. v2: Move context handle initialization too (@olv) Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 ++ drivers/gpu/drm/virtio/virtgpu_ioctl.c | 16 ++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 25 ++++++------------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 2f6c4ccbfd14..72c1d9b59dfe 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -214,6 +214,8 @@ struct virtio_gpu_fpriv { /* virtio_ioctl.c */ #define DRM_VIRTIO_NUM_IOCTLS 10 extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS]; +void virtio_gpu_create_context(struct drm_device *dev, + struct drm_file *file); /* virtio_kms.c */ int virtio_gpu_init(struct drm_device *dev); diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index b0edf1ca095f..896c3f419a6d 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -33,6 +33,22 @@ #include "virtgpu_drv.h" +void virtio_gpu_create_context(struct drm_device *dev, + struct drm_file *file) +{ + struct virtio_gpu_device *vgdev = dev->dev_private; + struct virtio_gpu_fpriv *vfpriv = file->driver_priv; + char dbgname[TASK_COMM_LEN]; + + /* can't create contexts without 3d renderer */ + if (!vgdev->has_virgl_3d) + return; + + get_task_comm(dbgname, current); + virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, + strlen(dbgname), dbgname); +} + static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 8fd7acef960f..282558576527 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -52,18 +52,6 @@ static void virtio_gpu_config_changed_work_func(struct work_struct *work) events_clear, &events_clear); } -static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev, - uint32_t nlen, const char *name) -{ - int handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL); - - if (handle < 0) - return handle; - handle += 1; - virtio_gpu_cmd_context_create(vgdev, handle, nlen, name); - return handle; -} - static void virtio_gpu_context_destroy(struct virtio_gpu_device *vgdev, uint32_t ctx_id) { @@ -257,8 +245,7 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) { struct virtio_gpu_device *vgdev = dev->dev_private; struct virtio_gpu_fpriv *vfpriv; - int id; - char dbgname[TASK_COMM_LEN]; + int handle; /* can't create contexts without 3d renderer */ if (!vgdev->has_virgl_3d) @@ -269,15 +256,15 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) if (!vfpriv) return -ENOMEM; - get_task_comm(dbgname, current); - id = virtio_gpu_context_create(vgdev, strlen(dbgname), dbgname); - if (id < 0) { + handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL); + if (handle < 0) { kfree(vfpriv); - return id; + return handle; } - vfpriv->ctx_id = id; + vfpriv->ctx_id = handle + 1; file->driver_priv = vfpriv; + virtio_gpu_create_context(dev, file); return 0; } From patchwork Thu Feb 13 23:18:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11381441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7470C1580 for ; Thu, 13 Feb 2020 23:18:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 52D1A2082F for ; Thu, 13 Feb 2020 23:18:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="U3oFkLMz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52D1A2082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3DEC46E425; Thu, 13 Feb 2020 23:18:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by gabe.freedesktop.org (Postfix) with ESMTPS id B1BBD6E429 for ; Thu, 13 Feb 2020 23:18:26 +0000 (UTC) Received: by mail-pj1-x1041.google.com with SMTP id dw13so3033141pjb.4 for ; Thu, 13 Feb 2020 15:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=68RJR195cXG/OJoShqYYXCW3gJOrA7bpW+d05EruekI=; b=U3oFkLMz0HbhdXTDYATDbnK2nY4Lh52DvT+urxHFL7FbwB/O63H+psUcwKZtjXS4au Al6chTDvMHdboZR3DGo4a3nDQc0LAJX+8YEuZBnYdy7ZLzAVrQkJLtqRD8sCnJVUXybp hbgpOak3WfnlMf81gT9YDnK2ZKCeErr2L897Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=68RJR195cXG/OJoShqYYXCW3gJOrA7bpW+d05EruekI=; b=BtHahfZwaOY7b+kPpulHZSK+thPShmcYOc4vJ6AD2lCoJL5xXQ2NR9T2PNeHvxSp0K 4VVS5mG080zoLCYnfqZU/FI1IG+YPCJMBLW98c9osWZkCCOVBThFfkij27KzQyJ62wWb U7/wIqwtRFtpogdFFIbPhEqdo0WIKQQfq2DXXxNQ/Qh5NCqOcDWap7sk8fmAt4qTdTiK MfLVajbxAa2Uy5nppVbKKpURl4plfHWaeR949BTgzli8d6FMDda/rBcLL7yVFUECeiJb Hx7mqZB4eM1GZ60fY/8sCz7JyCnaxrC4teucgolDctUrdTsM/lXXRGLsdlahfGXrp2Ve AsvQ== X-Gm-Message-State: APjAAAVJmf5q8KukDWTAXPMKlxCcb/+LorQVakve7RWyRf+Q07F4/n/p 7QnzWYPC57QymcHYDyjBa3OlUxBEX8Y= X-Google-Smtp-Source: APXvYqxMblNGYwRerEkpwSXsFnLVgnk27GSkqeUKS5/AvyYHfuwONtOpZPHvOiZM1lGkPLwpzd0O+Q== X-Received: by 2002:a17:902:a514:: with SMTP id s20mr295733plq.300.1581635905870; Thu, 13 Feb 2020 15:18:25 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id w17sm4253495pfi.56.2020.02.13.15.18.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Feb 2020 15:18:25 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/virtio: track whether or not a context has been initiated Date: Thu, 13 Feb 2020 15:18:03 -0800 Message-Id: <20200213231805.622-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213231805.622-1-gurchetansingh@chromium.org> References: <20200213231805.622-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , kraxel@redhat.com, jbates@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use an atomic variable to track whether a context has been initiated. v2: Fix possible race (@olv) Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_ioctl.c | 3 +++ drivers/gpu/drm/virtio/virtgpu_kms.c | 1 + 3 files changed, 5 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 72c1d9b59dfe..ca505984f8ab 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -209,6 +209,7 @@ struct virtio_gpu_device { struct virtio_gpu_fpriv { uint32_t ctx_id; + atomic_t context_initiated; }; /* virtio_ioctl.c */ diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index 896c3f419a6d..a98884462944 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -44,6 +44,9 @@ void virtio_gpu_create_context(struct drm_device *dev, if (!vgdev->has_virgl_3d) return; + if (!atomic_add_unless(&vfpriv->context_initiated, 1, 1)) + return; + get_task_comm(dbgname, current); virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, strlen(dbgname), dbgname); diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 282558576527..25248bad3fc4 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -263,6 +263,7 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) } vfpriv->ctx_id = handle + 1; + atomic_set(&vfpriv->context_initiated, 0); file->driver_priv = vfpriv; virtio_gpu_create_context(dev, file); return 0; From patchwork Thu Feb 13 23:18:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11381443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 135E8139A for ; Thu, 13 Feb 2020 23:18:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 E65B22168B for ; Thu, 13 Feb 2020 23:18:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QHCd4st3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E65B22168B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3ED866E42A; Thu, 13 Feb 2020 23:18:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by gabe.freedesktop.org (Postfix) with ESMTPS id 065326E429 for ; Thu, 13 Feb 2020 23:18:32 +0000 (UTC) Received: by mail-pg1-x542.google.com with SMTP id b9so3790841pgk.12 for ; Thu, 13 Feb 2020 15:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mhIUUIeRYJgh3PajhzrPLDYE4S2JY+chXfVcanDuT1M=; b=QHCd4st3dCDAmkSJYJ3+wHm7eVd12/CWYFEw8VRT8oKTtsXJnJET+Wrsl6XGaFqwNP UlrSBHiuRVhvPKkmiRi9L5OhX6XKd81DueJNLapjWXp/bEk9mPKebG0TAZqhMizTW6ii 0W5/S3AsVTSSBsNGkyyJSkH3RvR1vBDanptIU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mhIUUIeRYJgh3PajhzrPLDYE4S2JY+chXfVcanDuT1M=; b=j0NqM6D8MCGuJtYcygxj6AxZVUkSoGtqSVCSt3ES6glSikEdbcLSDVUveGxbi0Xy1e tMRx5Q1ROeRNbmSxILZZQKN43spudsCS0/DuBDNTvpuGxIjf4Ded6zF6CIkXaB2jAKh6 oriG+QWNFWhcs2+slVxj0dO7nvDBwyCO48ZSQA+AdvMof2G+m74gmsIkWbUug0M8Gq4d P0LvL5KtmfnKC7HokkPzmaUdmsAhrjYZSjewnFAr9Sxt35rwwYct17qpO78AjBvUMNsL tbXs08KC2YKSe+IzL1vfy9Ewzq6WXQHMWTiKfBRW8bYDahrv931JQuOsUWuF0K/0HDOD zylQ== X-Gm-Message-State: APjAAAX79kQl000lZzJbl6OBOP3iQOatKXRqCy9bQFzMfs6sIkeJTbA7 ihb9Z6yNdip3KT7Rr/XvcFVU1OvIKyA= X-Google-Smtp-Source: APXvYqwKmxe0DZTVu8c5ETIXBUDk8GKnTupNRmmUoT1iFA7TiHPrm05fNgi364/Uo9t5yXJN31ZCCA== X-Received: by 2002:aa7:9359:: with SMTP id 25mr225751pfn.188.1581635908010; Thu, 13 Feb 2020 15:18:28 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id w17sm4253495pfi.56.2020.02.13.15.18.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Feb 2020 15:18:27 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl Date: Thu, 13 Feb 2020 15:18:04 -0800 Message-Id: <20200213231805.622-5-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213231805.622-1-gurchetansingh@chromium.org> References: <20200213231805.622-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , kraxel@redhat.com, jbates@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For old userspace, initialization will still be implicit. For backwards compatibility, enqueue virtio_gpu_cmd_context_create after the first 3D ioctl. v2: staticify virtio_gpu_create_context Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 -- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 9 +++++++-- drivers/gpu/drm/virtio/virtgpu_kms.c | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index ca505984f8ab..4de0741da454 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -215,8 +215,6 @@ struct virtio_gpu_fpriv { /* virtio_ioctl.c */ #define DRM_VIRTIO_NUM_IOCTLS 10 extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS]; -void virtio_gpu_create_context(struct drm_device *dev, - struct drm_file *file); /* virtio_kms.c */ int virtio_gpu_init(struct drm_device *dev); diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index a98884462944..d2f17778bdc4 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -33,8 +33,8 @@ #include "virtgpu_drv.h" -void virtio_gpu_create_context(struct drm_device *dev, - struct drm_file *file) +static void virtio_gpu_create_context(struct drm_device *dev, + struct drm_file *file) { struct virtio_gpu_device *vgdev = dev->dev_private; struct virtio_gpu_fpriv *vfpriv = file->driver_priv; @@ -93,6 +93,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, exbuf->fence_fd = -1; + virtio_gpu_create_context(dev, file); if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) { struct dma_fence *in_fence; @@ -243,6 +244,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, return -EINVAL; } + virtio_gpu_create_context(dev, file); params.format = rc->format; params.width = rc->width; params.height = rc->height; @@ -316,6 +318,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, if (vgdev->has_virgl_3d == false) return -ENOSYS; + virtio_gpu_create_context(dev, file); objs = virtio_gpu_array_from_handles(file, &args->bo_handle, 1); if (objs == NULL) return -ENOENT; @@ -363,6 +366,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, args->box.w, args->box.h, args->box.x, args->box.y, objs, NULL); } else { + virtio_gpu_create_context(dev, file); ret = virtio_gpu_array_lock_resv(objs); if (ret != 0) goto err_put_free; @@ -463,6 +467,7 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev, spin_unlock(&vgdev->display_info_lock); /* not in cache - need to talk to hw */ + virtio_gpu_create_context(dev, file); virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver, &cache_ent); diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index 25248bad3fc4..f84f2cb7546a 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -265,7 +265,6 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) vfpriv->ctx_id = handle + 1; atomic_set(&vfpriv->context_initiated, 0); file->driver_priv = vfpriv; - virtio_gpu_create_context(dev, file); return 0; } From patchwork Thu Feb 13 23:18:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11381445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 579681580 for ; Thu, 13 Feb 2020 23:18:36 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 361182082F for ; Thu, 13 Feb 2020 23:18:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HGhYY+22" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 361182082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0433A6E42F; Thu, 13 Feb 2020 23:18:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by gabe.freedesktop.org (Postfix) with ESMTPS id 23CEE6E429 for ; Thu, 13 Feb 2020 23:18:33 +0000 (UTC) Received: by mail-pg1-x544.google.com with SMTP id w21so3922131pgl.9 for ; Thu, 13 Feb 2020 15:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a3IqDiSJ16U0AO3K2pvZtPfoQrE3E9ga9QugheOmYSY=; b=HGhYY+221j0kTDh1S6CwlCIlAHAn4vACqqalQBxU3ZNBJjwJr5glBuODyj2m7x2C35 MEYdDn9kLQRzYTCnExBwUAHtX5NRXh+8ST/rPyw7EeIyFwY8O5VCNdN7+SbDgD4wlRgh 2EHAuKE+9mBG38e+qv+WYxaWyr3KX8/aTrwZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a3IqDiSJ16U0AO3K2pvZtPfoQrE3E9ga9QugheOmYSY=; b=udEEkaNU4XFio69++T+7oeS42A5W76H24wwYAdJhz/L3kp23is/+A4LSW0wgXn4dS4 LNGZS5B2QUp0hnQOBUYIgwEGFEEJ8SRUJvGNBLzaA2o4NbsHjoIa90d1M8C/LPc08YJc 3LjlfcZKhYKXcPwjd4+TjqUnATgwXKXGhHa2ERxm5/33/aFfSIQCY4DIR7PA/FGQRwCe gEEaei2zbTKg58WtCRLts/Ip6WEucR1nWou16BWOxOPrklwLEBjkM+NvBHs6Z9vIbJMm jjtTTgDr9pqjT1n5bKkJQFSeWv0HGo2/HTnFGrwZda4auWQ360a2oQe64BRnDCk2qezS nWbA== X-Gm-Message-State: APjAAAXoLbXb8JnT25wa3Ef5nJeqK9Abu6m6KxuAQm6doha4qBMZgXXO 9+Q9sjunMHQ34orq+S6vLkX0nmb2A3Y= X-Google-Smtp-Source: APXvYqzoFR3B41278BoSQG5V1c2SabcpK8BIsHfrtj04RHzKIUcVH5+m3L5eSX2Q9o9EA8NtDd6W1g== X-Received: by 2002:a63:1926:: with SMTP id z38mr268495pgl.303.1581635911869; Thu, 13 Feb 2020 15:18:31 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id w17sm4253495pfi.56.2020.02.13.15.18.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Feb 2020 15:18:31 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/virtio: add virtio_gpu_context_type Date: Thu, 13 Feb 2020 15:18:05 -0800 Message-Id: <20200213231805.622-6-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213231805.622-1-gurchetansingh@chromium.org> References: <20200213231805.622-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gurchetan Singh , kraxel@redhat.com, jbates@chromium.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We'll have to do something like this eventually, and this conveys we want a Virgl context by default. Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index d2f17778bdc4..f3be29d3f103 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -33,8 +33,14 @@ #include "virtgpu_drv.h" +/* TODO: add more context types */ +enum virtio_gpu_context_type { + virtio_gpu_virgl_context, +}; + static void virtio_gpu_create_context(struct drm_device *dev, - struct drm_file *file) + struct drm_file *file, + enum virtio_gpu_context_type type) { struct virtio_gpu_device *vgdev = dev->dev_private; struct virtio_gpu_fpriv *vfpriv = file->driver_priv; @@ -47,6 +53,11 @@ static void virtio_gpu_create_context(struct drm_device *dev, if (!atomic_add_unless(&vfpriv->context_initiated, 1, 1)) return; + if (type != virtio_gpu_virgl_context) { + DRM_ERROR("Unsupported context type: %u\n", type); + return; + } + get_task_comm(dbgname, current); virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, strlen(dbgname), dbgname); @@ -93,7 +104,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, exbuf->fence_fd = -1; - virtio_gpu_create_context(dev, file); + virtio_gpu_create_context(dev, file, virtio_gpu_virgl_context); if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) { struct dma_fence *in_fence; @@ -244,7 +255,7 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data, return -EINVAL; } - virtio_gpu_create_context(dev, file); + virtio_gpu_create_context(dev, file, virtio_gpu_virgl_context); params.format = rc->format; params.width = rc->width; params.height = rc->height; @@ -318,7 +329,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, if (vgdev->has_virgl_3d == false) return -ENOSYS; - virtio_gpu_create_context(dev, file); + virtio_gpu_create_context(dev, file, virtio_gpu_virgl_context); objs = virtio_gpu_array_from_handles(file, &args->bo_handle, 1); if (objs == NULL) return -ENOENT; @@ -366,7 +377,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, args->box.w, args->box.h, args->box.x, args->box.y, objs, NULL); } else { - virtio_gpu_create_context(dev, file); + virtio_gpu_create_context(dev, file, virtio_gpu_virgl_context); ret = virtio_gpu_array_lock_resv(objs); if (ret != 0) goto err_put_free; @@ -467,7 +478,7 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev, spin_unlock(&vgdev->display_info_lock); /* not in cache - need to talk to hw */ - virtio_gpu_create_context(dev, file); + virtio_gpu_create_context(dev, file, virtio_gpu_virgl_context); virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver, &cache_ent);