From patchwork Wed Feb 19 02:02:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11390215 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 B2EDE1395 for ; Wed, 19 Feb 2020 02:03:14 +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 908E4206DB for ; Wed, 19 Feb 2020 02:03:14 +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="EYfxftx9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 908E4206DB 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 52DE46EAF9; Wed, 19 Feb 2020 02:03:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id C74D46EAF9 for ; Wed, 19 Feb 2020 02:03:07 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id u12so11539242pgb.10 for ; Tue, 18 Feb 2020 18:03:07 -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:mime-version :content-transfer-encoding; bh=nRm5pCWJ5SqgcYDjnqqphKFQ5kdEr3Yh1XennvVMnrY=; b=EYfxftx9V92dgWcGwIKgyh2pgx0dSNf+paT7+JSGm9TRSybHo7WF1BrBG62UH+xNkO biV4Z//O0JwqUxfldQmuLmchIoHUzRuQFh7VFVY7AQaTNJCRMy2arC+J+iVhBIyJSEi3 KCQ1pk0ERFdiKAU8KhzBct9kPIlmVx/pPalo8= 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:mime-version :content-transfer-encoding; bh=nRm5pCWJ5SqgcYDjnqqphKFQ5kdEr3Yh1XennvVMnrY=; b=a8/qTfGUSKggvNdKzxCxSE5Jx5tpcuVfWxXPKMVJ6GO9ccFiFv99fmQrBEV3AnDOBj 7sX1MHXLmphJpbWPTbWXrMHuAV8B0vA78oGeVO21p6pcGKhHSnkjNuE6FbvcfPfQWE6B LQkG52Ptr5Kxnse5TRdt8fqe75AQkeyAa5RKLXU9EA9rLhPw0JaQt5Q4wLfKg2S4oRcT b4DmxAnes8pi1idKCIzbUC+OgpxDtiWdH270VIT8IOJvJ2A+hd/JW+COIZUXg3hrcXH9 B/1oPVjWL7qP4NMNTavHIzlL5WNdyfo+yzoRWNCaZpomhc7gBFrnmgnhNVmsr0KWmE5j iYFQ== X-Gm-Message-State: APjAAAWKRc0e4x3tP8qSA6KXvc3y3hv+AeJa6cupdUWT2JaU7OFtMMnK 6ioy3wKLz+080I/mQd+AjXaZUWgbiWE= X-Google-Smtp-Source: APXvYqwIPNgp5CgkGbAkWhvmm2mNSIgEMIoTpUjrPjhupyUybyKLNpPdfL/vF+SQjqLglLV6tMp4FQ== X-Received: by 2002:aa7:95a9:: with SMTP id a9mr23995796pfk.15.1582077786990; Tue, 18 Feb 2020 18:03:06 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id 3sm216430pjg.27.2020.02.18.18.03.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Feb 2020 18:03:06 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5 v3] drm/virtio: use consistent names for drm_files Date: Tue, 18 Feb 2020 18:02:57 -0800 Message-Id: <20200219020301.1424-1-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 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 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 bbc31aef51f1..baad7e1c9505 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; @@ -178,7 +178,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; @@ -201,7 +201,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; @@ -252,7 +252,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; @@ -265,13 +265,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 Wed Feb 19 02:02:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11390217 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 EE9AE930 for ; Wed, 19 Feb 2020 02:03:17 +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 CD4AF206DB for ; Wed, 19 Feb 2020 02:03:17 +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="U0SyoHYI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD4AF206DB 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 A480E6EAFA; Wed, 19 Feb 2020 02:03:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by gabe.freedesktop.org (Postfix) with ESMTPS id BAEA76EAFA for ; Wed, 19 Feb 2020 02:03:09 +0000 (UTC) Received: by mail-pg1-x543.google.com with SMTP id 6so11914653pgk.0 for ; Tue, 18 Feb 2020 18:03:09 -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=YdtSg4I83FV4TfRtEYBqKUl/YbqEjTde4tXPeXzE12E=; b=U0SyoHYIVdNKB59W01s1RrmJHk6A+CleIAdt9bLIIA6/rLqRpBugDAV31Ba8DpHN3G Osj2DqkvPm+Ij8np/wyMsGF0IOGq17VyWWo6zk9bTOC4YoUGgNCRHBSOETN7Sn0le4Gu maZ4cdbmGtTFBzf+cfj1i5O1ZicJBNt5bCGvw= 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=YdtSg4I83FV4TfRtEYBqKUl/YbqEjTde4tXPeXzE12E=; b=oNTggrxD8labu32W1Vjb88IqCAbblcArBIHWMy4U7G3D2TFM4C4I2QP0TG/eFDPyER 04KHHnCkebTCtvA3N03/WTkWi0Obsmzd/F2ot4ih0EP9vZbEDsaVIEhwR7TX+rC1LFlJ D2v+JwoHm/e7N8qWTm5thKNMFlTQ96Gayccw66iwqr3MModOHljby8AJywqjXeXL/6jU ey9RqINnUYn7mhG8xuMmtyH2S433UKKq1XyVhYVdxF4nA/xvJ6n3yuHd1Bf17EiY3ln0 VEMSUQ4CiElOwM1k97C9stM8Acrd0f4zmbngDLFTrgoNBvXNn5jLx/MXaoW1hscxFs3K ICQQ== X-Gm-Message-State: APjAAAUREXmsTLiq+EXyNxbSCj1flwDydmGp8Jh9WKRSW+EG3qlHemdb hmBmdMBMzGbOVvQYNci6pXGPbQRqXw4= X-Google-Smtp-Source: APXvYqxfW1AAaXLgP/Owhe7+RgXYD6dlXmrzI83CseaiKTQ94dtgZENTK/H9xpHtWpRz9lpu/73r0w== X-Received: by 2002:a63:1a50:: with SMTP id a16mr25184578pgm.389.1582077788973; Tue, 18 Feb 2020 18:03:08 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id 3sm216430pjg.27.2020.02.18.18.03.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Feb 2020 18:03:08 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5 v3] drm/virtio: factor out context create hyercall Date: Tue, 18 Feb 2020 18:02:58 -0800 Message-Id: <20200219020301.1424-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200219020301.1424-1-gurchetansingh@chromium.org> References: <20200219020301.1424-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 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 | 17 +++++++++++++++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 26 ++++++-------------------- 3 files changed, 25 insertions(+), 20 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 baad7e1c9505..de04f80f737d 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -33,6 +33,23 @@ #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); + virtio_gpu_notify(vgdev); +} + 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 ad3b673f5796..f7e3712502ca 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -52,19 +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); - virtio_gpu_notify(vgdev); - return handle; -} - static void virtio_gpu_context_destroy(struct virtio_gpu_device *vgdev, uint32_t ctx_id) { @@ -260,8 +247,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) @@ -272,15 +258,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 Wed Feb 19 02:02:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11390219 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 6A8C51395 for ; Wed, 19 Feb 2020 02:03:20 +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 48F24206DB for ; Wed, 19 Feb 2020 02:03:20 +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="EvIhNvt+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48F24206DB 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 DBD736EAFB; Wed, 19 Feb 2020 02:03:13 +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 665666EAFA for ; Wed, 19 Feb 2020 02:03:11 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id y5so11651275pfb.11 for ; Tue, 18 Feb 2020 18:03:11 -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=0c4EZlTw5QpZUw23jKFl/TjKgaMoAwFQY+84nYAo5Qw=; b=EvIhNvt+qZlNLgUuv5kuqGJlwWAnRwC+zBLrlnf+1whdN5k4souqtU20l6W1xAd90y XuJH4IeFeWQjKJlVzOEXu8Kjs+UH+7aoUCelmA8xG5zVKCi5SOrj0GU229HSV9PwNNxY 5550tXY05ysh/9CVLtrq/bnKs1Be0kGj1AAfU= 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=0c4EZlTw5QpZUw23jKFl/TjKgaMoAwFQY+84nYAo5Qw=; b=MNCHrfANiPYK0rW1CqX1hcKgyE/wwokOC36vMiY+21ho46e3Eq0OKP28rhBSv12FSo Dj0e2kiYZAAJTafkR+WzF3qpn0Mu3Mg5AiaZH+PQAH6aOlWnPL69FWj2ntbI2bkJ6Tf8 CHHOLiN8Ua42Eage7oXjlw7GyYfYhZdAtDUFGBbcMgIfzMiqLc5WfjXMdybe1fGko9Oy 8z4We9+1LtzFe3IuaWIA9cicd3QTNbk6rO+khJcjLuHP26qfsbeZGM+JANkE8TpzJ3nY AthS4jbg7GDGceP4V6cgJT87xBUrDW05ms6749H5l/N6T5dyKxxhiHsPjMTnK90b6v/b L4Sg== X-Gm-Message-State: APjAAAXkGXR+zUYIYAY3ksXhz9bqrZTZkSFUR5V+kLRuWVf6KTo106oz YUQ4ciRVY3e99inZ6leYWKbRnHyl9Qg= X-Google-Smtp-Source: APXvYqyGpoHHI+Uvg/V2W3eMH7qmP6lIjsRSeYhUjVBX//0tEMzrcSZwGFdCrOKgUEAgkXpcY12gxg== X-Received: by 2002:a62:188:: with SMTP id 130mr24761218pfb.249.1582077790722; Tue, 18 Feb 2020 18:03:10 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id 3sm216430pjg.27.2020.02.18.18.03.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Feb 2020 18:03:10 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5 v3] drm/virtio: track whether or not a context has been initiated Date: Tue, 18 Feb 2020 18:02:59 -0800 Message-Id: <20200219020301.1424-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200219020301.1424-1-gurchetansingh@chromium.org> References: <20200219020301.1424-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 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use an atomic variable to track whether a context has been initiated. v3: Fix possible race via spinlock (@olv) Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 ++ drivers/gpu/drm/virtio/virtgpu_ioctl.c | 8 ++++++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 72c1d9b59dfe..99d94a87c28b 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -209,6 +209,8 @@ struct virtio_gpu_device { struct virtio_gpu_fpriv { uint32_t ctx_id; + bool context_initiated; + spinlock_t context_lock; }; /* virtio_ioctl.c */ diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index de04f80f737d..82312664f2e4 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -44,10 +44,18 @@ void virtio_gpu_create_context(struct drm_device *dev, if (!vgdev->has_virgl_3d) return; + spin_lock(&vfpriv->context_lock); + if (vfpriv->context_initiated) + goto out_unlock; + get_task_comm(dbgname, current); virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, strlen(dbgname), dbgname); virtio_gpu_notify(vgdev); + vfpriv->context_initiated = true; + +out_unlock: + spin_unlock(&vfpriv->context_lock); } static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data, diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index f7e3712502ca..f4a9aa0048d2 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -258,6 +258,8 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) if (!vfpriv) return -ENOMEM; + spin_lock_init(&vfpriv->context_lock); + handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL); if (handle < 0) { kfree(vfpriv); From patchwork Wed Feb 19 02:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11390221 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 55C521395 for ; Wed, 19 Feb 2020 02:03:22 +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 34CE6206DB for ; Wed, 19 Feb 2020 02:03:22 +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="E/7hn6jm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34CE6206DB 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 2559B6EAFD; Wed, 19 Feb 2020 02:03:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by gabe.freedesktop.org (Postfix) with ESMTPS id 72A056EAFB for ; Wed, 19 Feb 2020 02:03:13 +0000 (UTC) Received: by mail-pl1-x641.google.com with SMTP id e8so8869983plt.9 for ; Tue, 18 Feb 2020 18:03:13 -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=ahdVAUkVUgHixqa71A6SxY9pTnBs4SJbiLDM/LQMDSQ=; b=E/7hn6jmD1VwY+K0TQKwqrT087hqEx43qetazFFIKxJtCquG7ohtFsjiaL4L6Sm0q3 kZDDwvUbOgpq5MYVDdrpoJ1Uj3+CDQQrxCMxAfUQ50hu84gdjITwzL7PFrBzHsKhzf9X 0ckcILvz48HYQFP7ioAIZX0H4bI37vS68ujl0= 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=ahdVAUkVUgHixqa71A6SxY9pTnBs4SJbiLDM/LQMDSQ=; b=Kg9kg/sTqromVlQgLtulc+iQSkGjI7c3ijQBqAo6bzKIxBKhOR4xRFWBPIzfo/NA9Y E3WsuVmJ/4wt/I4RFVdvXvGTJJnbBeGt5i/g39hIeLk1s+VT3tGJhJ6ZnhT4EbTLopsA kAcfd0Ntv3+VkUvqirZ4hxNOZNUxNVQ75YLl3OK56IbCSP1iUfAgHPE+3hJssZjZNBFW 5xVyr1nrt0k/uojxjX92YLw1Wa5SVTjYSk43WGfr4Sx22QMiXoqBrzPOX9Kl4JOjk1Wr UaEoHd/yp+u611NrA6xFu0cgCAGSvbUOiS5r+s3O0ekDj6+zDqWni91Z0m8cDPhVQin9 vWDw== X-Gm-Message-State: APjAAAU0Bk+yzeJ0sLN2AhwHJNdiIXBNpfGQGpz/HvbgOB+fa3vyfCaq TNTW1VllRLS8zA0qs3rdclVB1kCmHT8= X-Google-Smtp-Source: APXvYqzyX4si7/lruqgkJZJgbWUO5QizFZI4kZ+PJbWf9L2PWxqpjksk1z30Vcm+w+pCTbEcFM17jg== X-Received: by 2002:a17:90a:d986:: with SMTP id d6mr6261816pjv.78.1582077792747; Tue, 18 Feb 2020 18:03:12 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id 3sm216430pjg.27.2020.02.18.18.03.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Feb 2020 18:03:12 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5 v3] drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl Date: Tue, 18 Feb 2020 18:03:00 -0800 Message-Id: <20200219020301.1424-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200219020301.1424-1-gurchetansingh@chromium.org> References: <20200219020301.1424-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 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. v3: staticify virtio_gpu_create_context remove notify to batch vm-exit Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 -- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 10 +++++++--- drivers/gpu/drm/virtio/virtgpu_kms.c | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 99d94a87c28b..b68ce046490f 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -216,8 +216,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 82312664f2e4..835628e65f13 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; @@ -51,7 +51,6 @@ void virtio_gpu_create_context(struct drm_device *dev, get_task_comm(dbgname, current); virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, strlen(dbgname), dbgname); - virtio_gpu_notify(vgdev); vfpriv->context_initiated = true; out_unlock: @@ -99,6 +98,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; @@ -250,6 +250,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; @@ -323,6 +324,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; @@ -371,6 +373,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; @@ -471,6 +474,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); virtio_gpu_notify(vgdev); diff --git a/drivers/gpu/drm/virtio/virtgpu_kms.c b/drivers/gpu/drm/virtio/virtgpu_kms.c index f4a9aa0048d2..5b0e7d973336 100644 --- a/drivers/gpu/drm/virtio/virtgpu_kms.c +++ b/drivers/gpu/drm/virtio/virtgpu_kms.c @@ -268,7 +268,6 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file) vfpriv->ctx_id = handle + 1; file->driver_priv = vfpriv; - virtio_gpu_create_context(dev, file); return 0; } From patchwork Wed Feb 19 02:03: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: 11390223 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 E9509930 for ; Wed, 19 Feb 2020 02:03: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 C7E6A206DB for ; Wed, 19 Feb 2020 02:03: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="OB/pEjXZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7E6A206DB 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 BBF256EAFE; Wed, 19 Feb 2020 02:03:17 +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 2CE266EAFE for ; Wed, 19 Feb 2020 02:03:15 +0000 (UTC) Received: by mail-pg1-x542.google.com with SMTP id d6so11895687pgn.5 for ; Tue, 18 Feb 2020 18:03:15 -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=wSWqrgqifGCRXfEGhicuI9XmC1gYdm2jvgb2HFx1KW0=; b=OB/pEjXZ1W27PJDwhvFfC2bLKboFt8Viyv+MHBw9aGJayREriliFRNlK8mXLIT9pzF HiwexuZP8vWC1YHrRVqUAbkjJwQO/ct5EcCBLn1Tk9vss5UkSjerNZqFdH1fmUuJWnFS FBCTx/wZ0H7kIw4CjJyFExlkshxKO+h/T+VLo= 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=wSWqrgqifGCRXfEGhicuI9XmC1gYdm2jvgb2HFx1KW0=; b=pBf0wDYYw7fq36CW+/3Se1DJ1D2JytVagdSAotuG6tm59jOtABQaDpzHRU3Z0/sF17 33hl9kuh8D8oGbxJXWbXKtRAe7G2l/IPTJo/5nD5FU727Bom2i1a8l4ZURjtp8/DiIdA RwUVwLamQvY+oBppqHnKjilmMJg92oAcWuyAlVg7lXGfk02lsL4McvNtsO+oSm4HFKpP u5O3gbGen554XkY72gnmzb6VCWbN7mmsLorFjq+SNi9m1Bn5HgWx0Nk0LquhiYLW7iaT eLeZhq4K4LH/CaXxoMOEVVHDCh362ixPUzAjcdkCvueAkkpkHFn7t5944+NPRsoqlmPx S7sA== X-Gm-Message-State: APjAAAW5y+1SiQIyws8YLjUoLSDEnyppVtzSENtjvgpTW0aAhNr9YHzM WTsK4GWT4ciIv240ux+U/t7yJzBKrY4= X-Google-Smtp-Source: APXvYqwvyRb1Qd9gmJ4jr1OuZNe9yguLvyX6q9uT5eL3eEu1TnhW6IAqbtpffLa5h0LbfKc5EYBpRA== X-Received: by 2002:aa7:979a:: with SMTP id o26mr24591686pfp.257.1582077794446; Tue, 18 Feb 2020 18:03:14 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id 3sm216430pjg.27.2020.02.18.18.03.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Feb 2020 18:03:13 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5 v3] drm/virtio: add virtio_gpu_context_type Date: Tue, 18 Feb 2020 18:03:01 -0800 Message-Id: <20200219020301.1424-5-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200219020301.1424-1-gurchetansingh@chromium.org> References: <20200219020301.1424-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 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 835628e65f13..30e87654dc7b 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; @@ -44,6 +50,11 @@ static void virtio_gpu_create_context(struct drm_device *dev, if (!vgdev->has_virgl_3d) return; + if (type != virtio_gpu_virgl_context) { + DRM_ERROR("Unsupported context type: %u\n", type); + return; + } + spin_lock(&vfpriv->context_lock); if (vfpriv->context_initiated) goto out_unlock; @@ -98,7 +109,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; @@ -250,7 +261,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; @@ -324,7 +335,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; @@ -373,7 +384,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; @@ -474,7 +485,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); virtio_gpu_notify(vgdev);