From patchwork Sat Feb 22 02:42:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11397797 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 92F8414E3 for ; Sat, 22 Feb 2020 02:43:21 +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 7147E206D7 for ; Sat, 22 Feb 2020 02:43:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rQhBDedb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7147E206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 1CE136F5BD; Sat, 22 Feb 2020 02:43:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6CC946F5BC; Sat, 22 Feb 2020 02:43:19 +0000 (UTC) Received: by mail-pl1-x636.google.com with SMTP id t14so1661426plr.8; Fri, 21 Feb 2020 18:43:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3U1IC2Bl/UEMV+oLQmV3uNw3C939JxbUINaVIeDLDNQ=; b=rQhBDedbrOzT0cgipChJyyR/MxNWkwqoJ6gQ7VoSmSWpB7bLpHx/DzcL5dg7d4Pj3E i5TfyeY9vXJHPDpe5vghaEMXfbyH+UOr7Yb2ZWKuxbYIxNcu0hdr70XK9wWyGhTQT/+t f8Tlp6voxJu0Sxwdou69wd0T2yMJAaqqeyDAEZXHNDOi4C1QZzaxbf54LevuEzeaZJ7f jbnL2mc2NScRBF361itdRKi/Sky/+/lVGr9T5KRjFcQY4e7nxRdpP7qeIS+v+mHfTm/h LK02EqcAmJypgE2phkAUcuYEZirDXpqzvdL5AU93Uk2gnpPvA7W9BuX/9/uc/JOxkuKs REiw== 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; bh=3U1IC2Bl/UEMV+oLQmV3uNw3C939JxbUINaVIeDLDNQ=; b=QdnrxGgY5yBuO09w5uHdf9wXtxSmli2V7kxiy9hd63yUKQSK/vk1bVIDyzNYHhkZfG /vYa12nWh5pLgYw246bFdNUVddsoREi4sdxRJLk6X7bWPbUBxBaiyK5he2DtxJkh7N48 pdNuDc7COwZzbGpxsSHjtW470gsMq8Ti/ZsVIRM/J5dTx4o9/BLUwMp/wDryhsSD1rqd ZoJKlL2JBPHW1osW7SXD6wYKx2UHqCKb8x86/0eLF5NHpH8cLEpHcqNoTSoafflvmQZA IWYMkcYUX1+aqQmVBHY6HybqTjKR37f1jUGRhgSf3zO1YY4h6izMDbeXQtNK7BzvZ3nq LnSQ== X-Gm-Message-State: APjAAAVLAaw55tskoV4tMqbob7d63BbCRICAJ1dgUgfH9UR2K8bddNqx UN3wiENe9plTLQQhdowyryZRdrQbRrl8YQ== X-Google-Smtp-Source: APXvYqxNM5qCTESDav5Xk2PWTAnHpQ9gfkwwclrwc9m3JNKxIiyHmW8jd2qRBSF8WVf9E5l0dar5fQ== X-Received: by 2002:a17:902:6bc3:: with SMTP id m3mr40066110plt.27.1582339398714; Fri, 21 Feb 2020 18:43:18 -0800 (PST) Received: from localhost.localdomain ([103.219.195.110]) by smtp.gmail.com with ESMTPSA id u13sm3797317pjn.29.2020.02.21.18.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 18:43:18 -0800 (PST) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/lima: save process info for debug usage Date: Sat, 22 Feb 2020 10:42:06 +0800 Message-Id: <20200222024210.18697-2-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200222024210.18697-1-yuq825@gmail.com> References: <20200222024210.18697-1-yuq825@gmail.com> 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: lima@lists.freedesktop.org, David Airlie , Vasily Khoruzhick , Andreas Baierl , Qiang Yu , Icenowy Zheng , Erico Nunes MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" When task fail, we can find its process with this information. Signed-off-by: Qiang Yu --- drivers/gpu/drm/lima/lima_ctx.c | 3 +++ drivers/gpu/drm/lima/lima_ctx.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/drivers/gpu/drm/lima/lima_ctx.c b/drivers/gpu/drm/lima/lima_ctx.c index 22fff6caa961..891d5cd5019a 100644 --- a/drivers/gpu/drm/lima/lima_ctx.c +++ b/drivers/gpu/drm/lima/lima_ctx.c @@ -27,6 +27,9 @@ int lima_ctx_create(struct lima_device *dev, struct lima_ctx_mgr *mgr, u32 *id) if (err < 0) goto err_out0; + ctx->pid = task_pid_nr(current); + get_task_comm(ctx->pname, current); + return 0; err_out0: diff --git a/drivers/gpu/drm/lima/lima_ctx.h b/drivers/gpu/drm/lima/lima_ctx.h index 6154e5c9bfe4..74e2be09090f 100644 --- a/drivers/gpu/drm/lima/lima_ctx.h +++ b/drivers/gpu/drm/lima/lima_ctx.h @@ -5,6 +5,7 @@ #define __LIMA_CTX_H__ #include +#include #include "lima_device.h" @@ -13,6 +14,10 @@ struct lima_ctx { struct lima_device *dev; struct lima_sched_context context[lima_pipe_num]; atomic_t guilty; + + /* debug info */ + char pname[TASK_COMM_LEN]; + pid_t pid; }; struct lima_ctx_mgr { From patchwork Sat Feb 22 02:42:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11397799 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 337021395 for ; Sat, 22 Feb 2020 02:43:25 +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 1228120722 for ; Sat, 22 Feb 2020 02:43:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lHn4NegE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1228120722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 BA0706F5BE; Sat, 22 Feb 2020 02:43:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by gabe.freedesktop.org (Postfix) with ESMTPS id 699416F5BE; Sat, 22 Feb 2020 02:43:22 +0000 (UTC) Received: by mail-pl1-x642.google.com with SMTP id y1so1663850plp.7; Fri, 21 Feb 2020 18:43:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2ggSthKmC1MgdMMM1+O34Z6L8ZA/PTSMhU3U2kSKKwY=; b=lHn4NegEo2eEgJ6OI436CMlKDD3rBXP0fARZnV9i9joRGZ/1CyLAqS6WBMnGqnY7AJ hdtjhUNx4OlV32O0Ctl76p+P1dy7to8tG+3nmfDUzOA4ufAAJ1oYzAaKyDcHgd8HLSTy LFWQmDccLxyxIa/6e0jBxPGpR7IxAORdq40llMwf5pCdhkWtro9m+WQtw97OJWh3o/Gg GO5y6Z44bkprujrvZW2LRfsmWuwYNj77P3OQPk2IpCLBdfiMkQLodtbKxMj92SzCfYmX nQn8X+apQC31T7KKRtvvZfNWXxZKBnM2fi7a3WzMVS061IYrC224we3SExnNf0NQH55q yXHA== 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; bh=2ggSthKmC1MgdMMM1+O34Z6L8ZA/PTSMhU3U2kSKKwY=; b=KFI6yvjLvDZ5h+eAd0BArVk9Gjw9kjH7C55twgtdcVrw/VZQd4QIH2wmw+8TPTt3YU P0BLlC/uDPPqwzvo0gKFt6AezambbXpV3pktCABa2r0Xq73ZyQGw3Gh2UrOwU8HS6bU6 eXYVfBwgcYgglbpHjUKDOqTLIRqtscnCimSU+mzBMH3lo8hFjiMLCg291wGUoU7n/jOZ mJVN86NLK+ArLsMXiejeL5uq5hIbKcEBxl4OZbMoM4PHZ3TYb4KVazyK95rsBTbkPPEf bDX1xxN79Ck+MtOftxLe+1XnbzB/ItXx+Uah6r564RnkgTLPe3Z1PFrb6qlCfVdsVgn8 8B7g== X-Gm-Message-State: APjAAAWGwhJTS4dFOvTLVAM3r+JfeQo/tbi5YbLuu6wcbrAlTMQJMbr7 XB0dOoQwSbke4155ML67u/HC8EDZ7X5I7g== X-Google-Smtp-Source: APXvYqzgOA7O17pD73bS9Il54ctd3p07KxaEZk6NhUZTpRj21ANJA3/vxmrFlO+2Cb6Er7rc8ObyRQ== X-Received: by 2002:a17:902:8609:: with SMTP id f9mr37547620plo.203.1582339401786; Fri, 21 Feb 2020 18:43:21 -0800 (PST) Received: from localhost.localdomain ([103.219.195.110]) by smtp.gmail.com with ESMTPSA id u13sm3797317pjn.29.2020.02.21.18.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 18:43:21 -0800 (PST) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/5] drm/lima: add max_error_tasks module parameter Date: Sat, 22 Feb 2020 10:42:07 +0800 Message-Id: <20200222024210.18697-3-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200222024210.18697-1-yuq825@gmail.com> References: <20200222024210.18697-1-yuq825@gmail.com> 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: lima@lists.freedesktop.org, David Airlie , Vasily Khoruzhick , Andreas Baierl , Qiang Yu , Icenowy Zheng , Erico Nunes MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Limit error tasks to save. Signed-off-by: Qiang Yu --- drivers/gpu/drm/lima/lima_drv.c | 4 ++++ drivers/gpu/drm/lima/lima_drv.h | 1 + 2 files changed, 5 insertions(+) diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index 2daac64d8955..e235d4545b6c 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -16,6 +16,7 @@ int lima_sched_timeout_ms; uint lima_heap_init_nr_pages = 8; +uint lima_max_error_tasks; MODULE_PARM_DESC(sched_timeout_ms, "task run timeout in ms"); module_param_named(sched_timeout_ms, lima_sched_timeout_ms, int, 0444); @@ -23,6 +24,9 @@ module_param_named(sched_timeout_ms, lima_sched_timeout_ms, int, 0444); MODULE_PARM_DESC(heap_init_nr_pages, "heap buffer init number of pages"); module_param_named(heap_init_nr_pages, lima_heap_init_nr_pages, uint, 0444); +MODULE_PARM_DESC(max_error_tasks, "max number of error tasks to save"); +module_param_named(max_error_tasks, lima_max_error_tasks, uint, 0644); + static int lima_ioctl_get_param(struct drm_device *dev, void *data, struct drm_file *file) { struct drm_lima_get_param *args = data; diff --git a/drivers/gpu/drm/lima/lima_drv.h b/drivers/gpu/drm/lima/lima_drv.h index f492ecc6a5d9..fdbd4077c768 100644 --- a/drivers/gpu/drm/lima/lima_drv.h +++ b/drivers/gpu/drm/lima/lima_drv.h @@ -10,6 +10,7 @@ extern int lima_sched_timeout_ms; extern uint lima_heap_init_nr_pages; +extern uint lima_max_error_tasks; struct lima_vm; struct lima_bo; From patchwork Sat Feb 22 02:42:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11397801 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 3C77F14E3 for ; Sat, 22 Feb 2020 02:43:29 +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 1AC1A20722 for ; Sat, 22 Feb 2020 02:43:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mdd9wFHD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1AC1A20722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 048356F5C0; Sat, 22 Feb 2020 02:43:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by gabe.freedesktop.org (Postfix) with ESMTPS id 52C1C6F5BF; Sat, 22 Feb 2020 02:43:26 +0000 (UTC) Received: by mail-pl1-x643.google.com with SMTP id y1so1663881plp.7; Fri, 21 Feb 2020 18:43:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3u2kcKfGrQWFWcvu77bOrRz/04l5BrVjo4/eFlU4ALc=; b=mdd9wFHDP5f+qYBnOTP8piiZZdTrZu/ef6TsFWKz3WoLsbLmumSqGEQEVlMuYYWDQT +QTnkGoQilI0zEnpX3R7z8n7gE3lVUzGhWHcsjW6p3qXEnc+wUAPX2SU7pDbx+TI7xYc sve2d/oOV+Y8dHVPjoFOx4ta61UKDMEi6Cb2U0VE3kzOVi59Cmsw9saJlVefszH15Ix8 JCLkkWIAqJitADjb96vzyOSWne+SNIC3L7WyTKeIZGMAmQl2spZe+gzZfoomRkkuW3NJ gRLjpfKwO3U8xcM3ccrwxKq/6ksR8R2O+bAqxy1+s80H5DGVqrpIppw0MNGe1WqJHeY1 dwLg== 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; bh=3u2kcKfGrQWFWcvu77bOrRz/04l5BrVjo4/eFlU4ALc=; b=H6va9btJgmyss/0c6Ywt6V30f7jZ/oC3glGCCtODKa5Ouy90Q+2ANBgAnyelzFnNzb cXcrKiKdJdLxRz9/OscxOtx8+pjVrvKN3wP7iU0KxuBAgc7GU6KRPgbm9X76ehW7WLAY ylrXhR/pOImX9GbtJTkyAzilTdBClynYxj1TOYUwOQ8loIudXTnorHiQtNBE+MIoz5M2 OJH++Jnlx0TXpD9XwIQftImyytOLfzdxzrvcBTgWCAtYEWEUKZ9pfoMFr3mvfFT6E8ky lhEwD5EXeKoiE9bey4DXI75nMzTR/b5Y2wGJkWdYnHiky0/Mi9L71GLymxXYtilUqEEO cDDw== X-Gm-Message-State: APjAAAUGu+gqxnUAFzjK0meJNTCVsAHTSSMHM1Z3sIlkWW/UG8/5DxgA Wld9BybTd00UuaapzRMzvCzJ9JNryhzNTw== X-Google-Smtp-Source: APXvYqzUNKaRc56QuEN1cr2a/IeISFYTT2uGkLmL76T+aWB8ckEAJPiPV+FZongUy3NUskWe+5OoZA== X-Received: by 2002:a17:902:9a42:: with SMTP id x2mr41368359plv.194.1582339405423; Fri, 21 Feb 2020 18:43:25 -0800 (PST) Received: from localhost.localdomain ([103.219.195.110]) by smtp.gmail.com with ESMTPSA id u13sm3797317pjn.29.2020.02.21.18.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 18:43:24 -0800 (PST) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/5] drm/lima: save task info dump when task fail Date: Sat, 22 Feb 2020 10:42:08 +0800 Message-Id: <20200222024210.18697-4-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200222024210.18697-1-yuq825@gmail.com> References: <20200222024210.18697-1-yuq825@gmail.com> 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: lima@lists.freedesktop.org, David Airlie , Vasily Khoruzhick , Andreas Baierl , Qiang Yu , Icenowy Zheng , Erico Nunes MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Save all information to start a task which can be exported to user for debug usage. Dump file data format is specified in lima_dump.h Signed-off-by: Qiang Yu Reported-by: kbuild test robot --- drivers/gpu/drm/lima/lima_device.c | 13 +++ drivers/gpu/drm/lima/lima_device.h | 8 ++ drivers/gpu/drm/lima/lima_dump.h | 77 +++++++++++++++++ drivers/gpu/drm/lima/lima_sched.c | 128 +++++++++++++++++++++++++++++ drivers/gpu/drm/lima/lima_sched.h | 7 ++ 5 files changed, 233 insertions(+) create mode 100644 drivers/gpu/drm/lima/lima_dump.h diff --git a/drivers/gpu/drm/lima/lima_device.c b/drivers/gpu/drm/lima/lima_device.c index 19829b543024..42a00171fea5 100644 --- a/drivers/gpu/drm/lima/lima_device.c +++ b/drivers/gpu/drm/lima/lima_device.c @@ -344,6 +344,12 @@ int lima_device_init(struct lima_device *ldev) if (err) goto err_out5; + ldev->dump.magic = LIMA_DUMP_MAGIC; + ldev->dump.version_major = LIMA_DUMP_MAJOR; + ldev->dump.version_minor = LIMA_DUMP_MINOR; + INIT_LIST_HEAD(&ldev->error_task_list); + mutex_init(&ldev->error_task_list_lock); + dev_info(ldev->dev, "bus rate = %lu\n", clk_get_rate(ldev->clk_bus)); dev_info(ldev->dev, "mod rate = %lu", clk_get_rate(ldev->clk_gpu)); @@ -370,6 +376,13 @@ int lima_device_init(struct lima_device *ldev) void lima_device_fini(struct lima_device *ldev) { int i; + struct lima_sched_error_task *et, *tmp; + + list_for_each_entry_safe(et, tmp, &ldev->error_task_list, list) { + list_del(&et->list); + kvfree(et); + } + mutex_destroy(&ldev->error_task_list_lock); lima_fini_pp_pipe(ldev); lima_fini_gp_pipe(ldev); diff --git a/drivers/gpu/drm/lima/lima_device.h b/drivers/gpu/drm/lima/lima_device.h index 31158d86271c..f17173f47f26 100644 --- a/drivers/gpu/drm/lima/lima_device.h +++ b/drivers/gpu/drm/lima/lima_device.h @@ -6,8 +6,11 @@ #include #include +#include +#include #include "lima_sched.h" +#include "lima_dump.h" enum lima_gpu_id { lima_gpu_mali400 = 0, @@ -94,6 +97,11 @@ struct lima_device { u32 *dlbu_cpu; dma_addr_t dlbu_dma; + + /* debug info */ + struct lima_dump_head dump; + struct list_head error_task_list; + struct mutex error_task_list_lock; }; static inline struct lima_device * diff --git a/drivers/gpu/drm/lima/lima_dump.h b/drivers/gpu/drm/lima/lima_dump.h new file mode 100644 index 000000000000..ca243d99c51b --- /dev/null +++ b/drivers/gpu/drm/lima/lima_dump.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2020 Qiang Yu */ + +#ifndef __LIMA_DUMP_H__ +#define __LIMA_DUMP_H__ + +#include + +/** + * dump file format for all the information to start a lima task + * + * top level format + * | magic code "LIMA" | format version | num tasks | data size | + * | reserved | reserved | reserved | reserved | + * | task 1 ID | task 1 size | num chunks | reserved | task 1 data | + * | task 2 ID | task 2 size | num chunks | reserved | task 2 data | + * ... + * + * task data format + * | chunk 1 ID | chunk 1 size | reserved | reserved | chunk 1 data | + * | chunk 2 ID | chunk 2 size | reserved | reserved | chunk 2 data | + * ... + * + */ + +#define LIMA_DUMP_MAJOR 1 +#define LIMA_DUMP_MINOR 0 + +#define LIMA_DUMP_MAGIC 0x414d494c + +struct lima_dump_head { + __u32 magic; + __u16 version_major; + __u16 version_minor; + __u32 num_tasks; + __u32 size; + __u32 reserved[4]; +}; + +#define LIMA_DUMP_TASK_GP 0 +#define LIMA_DUMP_TASK_PP 1 +#define LIMA_DUMP_TASK_NUM 2 + +struct lima_dump_task { + __u32 id; + __u32 size; + __u32 num_chunks; + __u32 reserved; +}; + +#define LIMA_DUMP_CHUNK_FRAME 0 +#define LIMA_DUMP_CHUNK_BUFFER 1 +#define LIMA_DUMP_CHUNK_PROCESS_NAME 2 +#define LIMA_DUMP_CHUNK_PROCESS_ID 3 +#define LIMA_DUMP_CHUNK_NUM 4 + +struct lima_dump_chunk { + __u32 id; + __u32 size; + __u32 reserved[2]; +}; + +struct lima_dump_chunk_buffer { + __u32 id; + __u32 size; + __u32 va; + __u32 reserved; +}; + +struct lima_dump_chunk_pid { + __u32 id; + __u32 size; + __u32 pid; + __u32 reserved; +}; + +#endif diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lima_sched.c index 3886999b4533..cd1bf3ad9bb5 100644 --- a/drivers/gpu/drm/lima/lima_sched.c +++ b/drivers/gpu/drm/lima/lima_sched.c @@ -256,6 +256,132 @@ static struct dma_fence *lima_sched_run_job(struct drm_sched_job *job) return task->fence; } +static void lima_sched_build_error_task_list(struct lima_sched_task *task) +{ + struct lima_sched_error_task *et; + struct lima_sched_pipe *pipe = to_lima_pipe(task->base.sched); + struct lima_ip *ip = pipe->processor[0]; + int pipe_id = ip->id == lima_ip_gp ? lima_pipe_gp : lima_pipe_pp; + struct lima_device *dev = ip->dev; + struct lima_sched_context *sched_ctx = + container_of(task->base.entity, struct lima_sched_context, base); + struct lima_ctx *ctx = + container_of(sched_ctx, struct lima_ctx, context[pipe_id]); + struct lima_dump_task *dt; + struct lima_dump_chunk *chunk; + struct lima_dump_chunk_pid *pid_chunk; + struct lima_dump_chunk_buffer *buffer_chunk; + uint32_t size, task_size, mem_size; + int i; + + mutex_lock(&dev->error_task_list_lock); + + if (dev->dump.num_tasks >= lima_max_error_tasks) { + dev_info(dev->dev, "fail to save task state: error task list is full\n"); + goto out; + } + + /* frame chunk */ + size = sizeof(struct lima_dump_chunk) + pipe->frame_size; + /* process name chunk */ + size += sizeof(struct lima_dump_chunk) + sizeof(ctx->pname); + /* pid chunk */ + size += sizeof(struct lima_dump_chunk); + /* buffer chunks */ + for (i = 0; i < task->num_bos; i++) { + struct lima_bo *bo = task->bos[i]; + + size += sizeof(struct lima_dump_chunk); + size += bo->heap_size ? bo->heap_size : lima_bo_size(bo); + } + + task_size = size + sizeof(struct lima_dump_task); + mem_size = task_size + sizeof(*et); + et = kvmalloc(mem_size, GFP_KERNEL); + if (!et) { + dev_err(dev->dev, "fail to alloc task dump buffer of size %x\n", + mem_size); + goto out; + } + + et->data = et + 1; + et->size = task_size; + + dt = et->data; + memset(dt, 0, sizeof(*dt)); + dt->id = pipe_id; + dt->size = size; + + chunk = (struct lima_dump_chunk *)(dt + 1); + memset(chunk, 0, sizeof(*chunk)); + chunk->id = LIMA_DUMP_CHUNK_FRAME; + chunk->size = pipe->frame_size; + memcpy(chunk + 1, task->frame, pipe->frame_size); + dt->num_chunks++; + + chunk = (void *)(chunk + 1) + chunk->size; + memset(chunk, 0, sizeof(*chunk)); + chunk->id = LIMA_DUMP_CHUNK_PROCESS_NAME; + chunk->size = sizeof(ctx->pname); + memcpy(chunk + 1, ctx->pname, sizeof(ctx->pname)); + dt->num_chunks++; + + pid_chunk = (void *)(chunk + 1) + chunk->size; + memset(pid_chunk, 0, sizeof(*pid_chunk)); + pid_chunk->id = LIMA_DUMP_CHUNK_PROCESS_ID; + pid_chunk->pid = ctx->pid; + dt->num_chunks++; + + buffer_chunk = (void *)(pid_chunk + 1) + pid_chunk->size; + for (i = 0; i < task->num_bos; i++) { + struct lima_bo *bo = task->bos[i]; + void *data; + + memset(buffer_chunk, 0, sizeof(*buffer_chunk)); + buffer_chunk->id = LIMA_DUMP_CHUNK_BUFFER; + buffer_chunk->va = lima_vm_get_va(task->vm, bo); + + if (bo->heap_size) { + buffer_chunk->size = bo->heap_size; + + data = vmap(bo->base.pages, bo->heap_size >> PAGE_SHIFT, + VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + if (!data) { + kvfree(et); + goto out; + } + + memcpy(buffer_chunk + 1, data, buffer_chunk->size); + + vunmap(data); + } else { + buffer_chunk->size = lima_bo_size(bo); + + data = drm_gem_shmem_vmap(&bo->base.base); + if (IS_ERR_OR_NULL(data)) { + kvfree(et); + goto out; + } + + memcpy(buffer_chunk + 1, data, buffer_chunk->size); + + drm_gem_shmem_vunmap(&bo->base.base, data); + } + + buffer_chunk = (void *)(buffer_chunk + 1) + buffer_chunk->size; + dt->num_chunks++; + } + + list_add(&et->list, &dev->error_task_list); + dev->dump.size += et->size; + dev->dump.num_tasks++; + + dev_info(dev->dev, "save error task state success\n"); + +out: + mutex_unlock(&dev->error_task_list_lock); +} + static void lima_sched_timedout_job(struct drm_sched_job *job) { struct lima_sched_pipe *pipe = to_lima_pipe(job->sched); @@ -268,6 +394,8 @@ static void lima_sched_timedout_job(struct drm_sched_job *job) drm_sched_increase_karma(&task->base); + lima_sched_build_error_task_list(task); + pipe->task_error(pipe); if (pipe->bcast_mmu) diff --git a/drivers/gpu/drm/lima/lima_sched.h b/drivers/gpu/drm/lima/lima_sched.h index d64393fb50a9..e29f5e3b675b 100644 --- a/drivers/gpu/drm/lima/lima_sched.h +++ b/drivers/gpu/drm/lima/lima_sched.h @@ -5,9 +5,16 @@ #define __LIMA_SCHED_H__ #include +#include struct lima_vm; +struct lima_sched_error_task { + struct list_head list; + void *data; + uint32_t size; +}; + struct lima_sched_task { struct drm_sched_job base; From patchwork Sat Feb 22 02:42:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11397803 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 4710E14E3 for ; Sat, 22 Feb 2020 02:43:32 +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 25AB020722 for ; Sat, 22 Feb 2020 02:43:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q4fTzOb5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25AB020722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 428946F5C2; Sat, 22 Feb 2020 02:43:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9B34E6F5BC; Sat, 22 Feb 2020 02:43:29 +0000 (UTC) Received: by mail-pf1-x42c.google.com with SMTP id b185so2253311pfb.7; Fri, 21 Feb 2020 18:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ull6T6F5hMcv/eMftiDtP/jzb7nzEx6T9MrULGR8Md0=; b=q4fTzOb5myY8NKXwr7Szd1XciCWBxkkp+hLjr8Wf551btH2uE/z7IlYQTr02eP8XwC 66JezRBK4yJE9rbn61J05VvBbVZAg8sV53F7U/JYydcKFlJ7SjmBujSaR7O+rkqyy7NX UpDw074yhMKiVKvfKBafOQ67kgF8ewpxrbqxhprY0i8ya9oboYR/OXQsmnoo9o8iNunr 1Qg/sL2lbE0jWI1K7mZCLzgZyRhg3BYAr4EG02ObLF3rxS8fT0K6OhxmBh+IY5nXTlmM 36k1u6qS0iDTKKmbNF4v4DWFy3wKfnCNw0jxODg+/TLf6lUvmKBzEYKwXwuOYJAAaY1d +G4w== 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; bh=ull6T6F5hMcv/eMftiDtP/jzb7nzEx6T9MrULGR8Md0=; b=dsh/P5fzXJeMDWnlhSc4RbwDmjdTgHDQe2pYgSCyF3PTpqf2jfz6/4A9XD+ZAtstJd rDCqLZ3Oh1ywWxjyXhXOMnJtqzENQQfMMhnzZlcMVOsJ6tNFmt5ZQgaZB2QA/AukEscs gd9EXfhA+giK8RlovpGyFBb41dTdIZ0ven0sAplvckQKhPRkjr7cLVRgCcCvv8jYMbge eKS3NlhYYS0tqE42MQYjnvCuNyDbAeIoVr5SA/Y/yJ9bvw4uKbdXUSuNHrm+bUmMUvHU MFhU7DCxv8gJMjXR0++MglYtAEx9OrjJeVnTmPVJ1Z4nB/dHUIxN+zT7EtcvmiLMQLHU AbBA== X-Gm-Message-State: APjAAAU1fEcj7UGkH/vYFHiiRVxug1WCalssYpp+wvCzOwHSjjapWgTC kDqbGKg2j2sACC9DktYm4+i74WH5TVSE4g== X-Google-Smtp-Source: APXvYqwFiQ2pZKbuX22NLexd25tTDsgsAcBgXdHjEn8QmzhXjxLRspHNAUj2eiKfKTAgNwC7IXg51g== X-Received: by 2002:aa7:9359:: with SMTP id 25mr40704570pfn.188.1582339408774; Fri, 21 Feb 2020 18:43:28 -0800 (PST) Received: from localhost.localdomain ([103.219.195.110]) by smtp.gmail.com with ESMTPSA id u13sm3797317pjn.29.2020.02.21.18.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 18:43:28 -0800 (PST) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] drm/lima: add error sysfs to export error task dump Date: Sat, 22 Feb 2020 10:42:09 +0800 Message-Id: <20200222024210.18697-5-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200222024210.18697-1-yuq825@gmail.com> References: <20200222024210.18697-1-yuq825@gmail.com> 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: lima@lists.freedesktop.org, David Airlie , Vasily Khoruzhick , Andreas Baierl , Qiang Yu , Icenowy Zheng , Erico Nunes MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Export /sys/class/drm/cardX/device/error sysfs for user read out error task dump file. Signed-off-by: Qiang Yu --- drivers/gpu/drm/lima/lima_drv.c | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index e235d4545b6c..8c5adc025902 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -276,6 +276,92 @@ static struct drm_driver lima_drm_driver = { .gem_prime_mmap = drm_gem_prime_mmap, }; +struct lima_block_reader { + void *dst; + size_t base; + size_t count; + size_t off; + ssize_t read; +}; + +static bool lima_read_block(struct lima_block_reader *reader, void *src, size_t src_size) +{ + size_t max_off = reader->base + src_size; + + if (reader->off < max_off) { + size_t size = min_t(size_t, max_off - reader->off, reader->count); + + memcpy(reader->dst, src + (reader->off - reader->base), size); + + reader->dst += size; + reader->off += size; + reader->read += size; + reader->count -= size; + } + + reader->base = max_off; + + return !!reader->count; +} + +static ssize_t lima_error_state_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t off, size_t count) +{ + + struct device *dev = kobj_to_dev(kobj); + struct lima_device *ldev = dev_get_drvdata(dev); + struct lima_sched_error_task *et; + struct lima_block_reader reader = { + .dst = buf, + .count = count, + .off = off, + }; + + mutex_lock(&ldev->error_task_list_lock); + + if (lima_read_block(&reader, &ldev->dump, sizeof(ldev->dump))) { + list_for_each_entry(et, &ldev->error_task_list, list) { + if (!lima_read_block(&reader, et->data, et->size)) + break; + } + } + + mutex_unlock(&ldev->error_task_list_lock); + return reader.read; +} + +static ssize_t lima_error_state_write(struct file *file, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t off, size_t count) +{ + struct device *dev = kobj_to_dev(kobj); + struct lima_device *ldev = dev_get_drvdata(dev); + struct lima_sched_error_task *et, *tmp; + + mutex_lock(&ldev->error_task_list_lock); + + list_for_each_entry_safe(et, tmp, &ldev->error_task_list, list) { + list_del(&et->list); + kvfree(et); + } + + ldev->dump.size = 0; + ldev->dump.num_tasks = 0; + + mutex_unlock(&ldev->error_task_list_lock); + + return count; +} + +static const struct bin_attribute lima_error_state_attr = { + .attr.name = "error", + .attr.mode = S_IRUSR | S_IWUSR, + .size = 0, + .read = lima_error_state_read, + .write = lima_error_state_write, +}; + static int lima_pdev_probe(struct platform_device *pdev) { struct lima_device *ldev; @@ -318,6 +404,11 @@ static int lima_pdev_probe(struct platform_device *pdev) if (err < 0) goto err_out2; + platform_set_drvdata(pdev, ldev); + + if (sysfs_create_bin_file(&ldev->dev->kobj, &lima_error_state_attr)) + dev_warn(ldev->dev, "fail to create error state sysfs\n"); + return 0; err_out2: @@ -334,6 +425,8 @@ static int lima_pdev_remove(struct platform_device *pdev) struct lima_device *ldev = platform_get_drvdata(pdev); struct drm_device *ddev = ldev->ddev; + sysfs_remove_bin_file(&ldev->dev->kobj, &lima_error_state_attr); + platform_set_drvdata(pdev, NULL); drm_dev_unregister(ddev); lima_device_fini(ldev); drm_dev_put(ddev); From patchwork Sat Feb 22 02:42:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11397805 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 AB9901395 for ; Sat, 22 Feb 2020 02:43:37 +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 88DCB20722 for ; Sat, 22 Feb 2020 02:43:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CyObTePI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88DCB20722 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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 B7A676F5BC; Sat, 22 Feb 2020 02:43:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2FC626F5C4; Sat, 22 Feb 2020 02:43:33 +0000 (UTC) Received: by mail-pf1-x443.google.com with SMTP id b185so2253361pfb.7; Fri, 21 Feb 2020 18:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zmu9+9eRFyNY15h9Ek3Z+76nUFKQGmj+zanQeEr6WEg=; b=CyObTePIC42njRlTMpIZ5jbV07vgmVzwQlIiClf8yxmuRae7p5rmPK3RHoGWUE6mkk UzllkCHvhzvt7xJeIXgotAX4N0urh0fusNlyXvE7soJ3jqUTaD2H3TvbAM0MRJq7UDUK AaNJLBmXC2yJo03J1uSp6YEyYbywQiMhQzFK79fByFG5hWbs376E1Wy3Qr0oQizMIxph R7MjdGqFOb3hoejatRsG9B+ZrhD5tsUWUOzAWgFoNNgROmPyzO6RSdqRf+R51mRMg2+Q 7CG+ZMuNBgUyKNliZ2Z6qM/WB8h6d4zd5yyCRoQtealQsMcxy3ERJkGSa+XzXACOw1bW HiqA== 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; bh=zmu9+9eRFyNY15h9Ek3Z+76nUFKQGmj+zanQeEr6WEg=; b=SfIr8M5GIeETLcx/eWSJyGbZ97nYp9ucP4ZU6+QDVR67yOJvyK9xQ19orX0oLL4JzM sJu1kScGzfwMEmcKreQfO9W/M48PzEGuQbf4jPMFFslFKsxJYHYU0g8vJvCfmSFRc+uI CyBxeIgtwDfIMm8YFcqe16BwuPHqYZf3UNxPPOLJEd36t6VkBMRMjedSvCrzo3Z9vGgI /enU6NAeoiBdJGaRIV996k7frtHuIHCQYmhuQMl2c6kSfq/8YJDuwhQF5JyBKPpmsbun enEzl2SHAxR4US54RlWxvFJkoJqW3i6VoRHc7NhqjAscitShyKvjM3MkMZj85mC4DOXg +Uew== X-Gm-Message-State: APjAAAVeIOlNq5GJmxoyR4KHXrichrK35qwKJM0c31ZKqdCZpidHIHv2 Fs9QJulvy/h7w2ta39NPizPVh8dbDyMxTA== X-Google-Smtp-Source: APXvYqwdgtryziiyB3qwd3ITAq/0Lqdj/vlMbD6j/DyX5dGHIYAmpNW5eZYvU/00f14I634rGNHvOw== X-Received: by 2002:aa7:957c:: with SMTP id x28mr40685571pfq.157.1582339412254; Fri, 21 Feb 2020 18:43:32 -0800 (PST) Received: from localhost.localdomain ([103.219.195.110]) by smtp.gmail.com with ESMTPSA id u13sm3797317pjn.29.2020.02.21.18.43.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 18:43:31 -0800 (PST) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/lima: add LIMA_BO_FLAG_FORCE_VA Date: Sat, 22 Feb 2020 10:42:10 +0800 Message-Id: <20200222024210.18697-6-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200222024210.18697-1-yuq825@gmail.com> References: <20200222024210.18697-1-yuq825@gmail.com> 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: lima@lists.freedesktop.org, David Airlie , Vasily Khoruzhick , Andreas Baierl , Qiang Yu , Icenowy Zheng , Erico Nunes MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" User can force created buffer to be mapped to GPU VM at a user specified address. This is used for debug tools in user space to replay some task. Signed-off-by: Qiang Yu --- drivers/gpu/drm/lima/lima_drv.c | 26 +++++++++++++++++++------- drivers/gpu/drm/lima/lima_gem.c | 7 +++++-- drivers/gpu/drm/lima/lima_gem.h | 4 +++- drivers/gpu/drm/lima/lima_vm.c | 13 ++++++++++++- include/uapi/drm/lima_drm.h | 9 +++++++-- 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index 8c5adc025902..f65021ea9598 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -73,16 +73,27 @@ static int lima_ioctl_gem_create(struct drm_device *dev, void *data, struct drm_ { struct drm_lima_gem_create *args = data; - if (args->pad) - return -EINVAL; - - if (args->flags & ~(LIMA_BO_FLAG_HEAP)) + if (args->flags & ~(LIMA_BO_FLAG_HEAP | LIMA_BO_FLAG_FORCE_VA)) return -EINVAL; if (args->size == 0) return -EINVAL; - return lima_gem_create_handle(dev, file, args->size, args->flags, &args->handle); + if (args->flags & LIMA_BO_FLAG_FORCE_VA) { + u64 max = (u64)args->va + (u64)args->size; + + if (max > LIMA_VA_RESERVE_START) + return -EINVAL; + + if (!IS_ALIGNED(args->va, PAGE_SIZE)) + return -EINVAL; + } else { + if (args->va) + return -EINVAL; + } + + return lima_gem_create_handle(dev, file, args->size, args->flags, + &args->handle, args->va); } static int lima_ioctl_gem_info(struct drm_device *dev, void *data, struct drm_file *file) @@ -253,6 +264,7 @@ DEFINE_DRM_GEM_FOPS(lima_drm_driver_fops); * Changelog: * * - 1.1.0 - add heap buffer support + * - 1.2.0 - add force va support */ static struct drm_driver lima_drm_driver = { @@ -264,9 +276,9 @@ static struct drm_driver lima_drm_driver = { .fops = &lima_drm_driver_fops, .name = "lima", .desc = "lima DRM", - .date = "20191231", + .date = "20200215", .major = 1, - .minor = 1, + .minor = 2, .patchlevel = 0, .gem_create_object = lima_gem_create_object, diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c index 5404e0d668db..c28d90756584 100644 --- a/drivers/gpu/drm/lima/lima_gem.c +++ b/drivers/gpu/drm/lima/lima_gem.c @@ -95,7 +95,7 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm) } int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, - u32 size, u32 flags, u32 *handle) + u32 size, u32 flags, u32 *handle, u32 va) { int err; gfp_t mask; @@ -116,8 +116,11 @@ int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, mask |= __GFP_DMA32; mapping_set_gfp_mask(obj->filp->f_mapping, mask); + bo = to_lima_bo(obj); + bo->flags = flags; + bo->force_va = va; + if (is_heap) { - bo = to_lima_bo(obj); err = lima_heap_alloc(bo, NULL); if (err) goto out; diff --git a/drivers/gpu/drm/lima/lima_gem.h b/drivers/gpu/drm/lima/lima_gem.h index ccea06142f4b..2a6db0c0be89 100644 --- a/drivers/gpu/drm/lima/lima_gem.h +++ b/drivers/gpu/drm/lima/lima_gem.h @@ -15,6 +15,8 @@ struct lima_bo { struct mutex lock; struct list_head va; + u32 flags; + u32 force_va; size_t heap_size; }; @@ -37,7 +39,7 @@ static inline struct dma_resv *lima_bo_resv(struct lima_bo *bo) int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm); struct drm_gem_object *lima_gem_create_object(struct drm_device *dev, size_t size); int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file, - u32 size, u32 flags, u32 *handle); + u32 size, u32 flags, u32 *handle, u32 va); int lima_gem_get_info(struct drm_file *file, u32 handle, u32 *va, u64 *offset); int lima_gem_submit(struct drm_file *file, struct lima_submit *submit); int lima_gem_wait(struct drm_file *file, u32 handle, u32 op, s64 timeout_ns); diff --git a/drivers/gpu/drm/lima/lima_vm.c b/drivers/gpu/drm/lima/lima_vm.c index 5b92fb82674a..be0510032538 100644 --- a/drivers/gpu/drm/lima/lima_vm.c +++ b/drivers/gpu/drm/lima/lima_vm.c @@ -3,6 +3,7 @@ #include #include +#include #include "lima_device.h" #include "lima_vm.h" @@ -93,6 +94,7 @@ int lima_vm_bo_add(struct lima_vm *vm, struct lima_bo *bo, bool create) struct lima_bo_va *bo_va; struct sg_dma_page_iter sg_iter; int offset = 0, err; + u64 start, end; mutex_lock(&bo->lock); @@ -120,7 +122,16 @@ int lima_vm_bo_add(struct lima_vm *vm, struct lima_bo *bo, bool create) mutex_lock(&vm->lock); - err = drm_mm_insert_node(&vm->mm, &bo_va->node, lima_bo_size(bo)); + if (bo->flags & LIMA_BO_FLAG_FORCE_VA) { + start = bo->force_va; + end = start + lima_bo_size(bo); + } else { + start = 0; + end = U64_MAX; + } + + err = drm_mm_insert_node_in_range(&vm->mm, &bo_va->node, lima_bo_size(bo), + 0, 0, start, end, 0); if (err) goto err_out1; diff --git a/include/uapi/drm/lima_drm.h b/include/uapi/drm/lima_drm.h index 1ec58d652a5a..3e699bb78394 100644 --- a/include/uapi/drm/lima_drm.h +++ b/include/uapi/drm/lima_drm.h @@ -37,7 +37,12 @@ struct drm_lima_get_param { * due to lack of heap memory. size field of heap buffer is an up bound of * the backup memory which can be set to a fairly large value. */ -#define LIMA_BO_FLAG_HEAP (1 << 0) +#define LIMA_BO_FLAG_HEAP (1 << 0) +/* + * force buffer GPU virtual address to be drm_lima_gem_create.va, this is + * used to replay some task with fixed GPU virtual address + */ +#define LIMA_BO_FLAG_FORCE_VA (1 << 1) /** * create a buffer for used by GPU @@ -46,7 +51,7 @@ struct drm_lima_gem_create { __u32 size; /* in, buffer size */ __u32 flags; /* in, buffer flags */ __u32 handle; /* out, GEM buffer handle */ - __u32 pad; /* pad, must be zero */ + __u32 va; /* in, buffer va */ }; /**