Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5649143img; Wed, 27 Mar 2019 12:25:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGHLfWh+ZOHwRMiBizrysy3MalJSSax1DWf48KgFV25U/1DWmY2YwTsdpGGjE2kHeOS9iZ X-Received: by 2002:a17:902:3283:: with SMTP id z3mr38442928plb.236.1553714722584; Wed, 27 Mar 2019 12:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714722; cv=none; d=google.com; s=arc-20160816; b=zppPrPsUqAvT60YWk72mfxvJxJhgxDyC0Qy4j35BfxNNnpVwAz9yYzC/p9k4hw0EdH m2mS2sc6KqJ8sGcC3m8aZHd0ZRsEe77EJluW8/HgjFjugqrDFkV467Z9m5At5ItAtTKP vosaoKGxjbV4WIgfh3Dv1uVWczSulK7PehCXU01yidtgZZ8w9S8kgu1W9xSIy0BIJKB/ qYatz0p0Qsq4jZRU9PH99ONpKp1BRPP1/mSHyGojYDYfwuJtZkEERNwOp/kolDbNFBX2 wrKulP0OsUR9/m7kkava4bBzpmhHspy3Cn20caQe50z1L1t4cKwhE6xdeYqvyx2MJYrV 9uAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dmj7urdNM19vaE0L5pQi2Gvhjhi1yUxMYBia8MVHiBo=; b=h7QMOLXpNtdEAuaJSaAfbOHQzpJMr6zGh5XoKmKQt5fcecnsK0XuU4GgIbGaBW3O+9 Ly8KSuNj1xPZPTNxCMSib+eJ1dIfP3fZ/FvGaPbOz4UkVGDdOZx6EaSq1RQKzBrXzJzZ 8PpE5bd0cVEXbdrltIK/PMFSax4SNgjaikiDYG7PXkGcU+DDFuXuNyJJW/R2l8Gl3+nb 5rNl6oldDJ+8ArXsDGrEUPxix1zixxFrIRG5WZbs5KKYcHDBAkhPaT3sHmB4RXAmNKzI JmTSdf6fnLBOwYp85IzO+iUK/pgCxnGiIFFg3rUBcGsxUEotIHa13U/3fP0oKUv1VZn7 r40g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MQ6QjnDl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si19740900ply.232.2019.03.27.12.25.07; Wed, 27 Mar 2019 12:25:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MQ6QjnDl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387983AbfC0TXW (ORCPT + 99 others); Wed, 27 Mar 2019 15:23:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:47620 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387862AbfC0SGH (ORCPT ); Wed, 27 Mar 2019 14:06:07 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 902E021734; Wed, 27 Mar 2019 18:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709966; bh=EpLJ3u0C6+VxruNbP/k5cof3OA9WelL0IhLBMySVgG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQ6QjnDl4vsMtdvKyGKuvuW9Mxq6DNRx/+Z+lf3dRYrdT25/1i9t79qApCE3Gx0DO 8N0MrDpx4lGR9Rc5HsciNlG0Jg71KdJqnP9zJR1/AzTPJXG+/JM4xpMthu/zaMB3YK xiPXJbPaYAdLvikuTz4ZXRBETf54tI8DBtRq0o8Y= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bas Nieuwenhuizen , Alex Deucher , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.0 135/262] drm/sched: Fix entities with 0 rqs. Date: Wed, 27 Mar 2019 13:59:50 -0400 Message-Id: <20190327180158.10245-135-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bas Nieuwenhuizen [ Upstream commit 1decbf6bb0b4dc56c9da6c5e57b994ebfc2be3aa ] Some blocks in amdgpu can have 0 rqs. Job creation already fails with -ENOENT when entity->rq is NULL, so jobs cannot be pushed. Without a rq there is no scheduler to pop jobs, and rq selection already does the right thing with a list of length 0. So the operations we need to fix are: - Creation, do not set rq to rq_list[0] if the list can have length 0. - Do not flush any jobs when there is no rq. - On entity destruction handle the rq = NULL case. - on set_priority, do not try to change the rq if it is NULL. Signed-off-by: Bas Nieuwenhuizen Reviewed-by: Christian König Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/scheduler/sched_entity.c | 39 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index e2942c9a11a7..35ddbec1375a 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -52,12 +52,12 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, { int i; - if (!(entity && rq_list && num_rq_list > 0 && rq_list[0])) + if (!(entity && rq_list && (num_rq_list == 0 || rq_list[0]))) return -EINVAL; memset(entity, 0, sizeof(struct drm_sched_entity)); INIT_LIST_HEAD(&entity->list); - entity->rq = rq_list[0]; + entity->rq = NULL; entity->guilty = guilty; entity->num_rq_list = num_rq_list; entity->rq_list = kcalloc(num_rq_list, sizeof(struct drm_sched_rq *), @@ -67,6 +67,10 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, for (i = 0; i < num_rq_list; ++i) entity->rq_list[i] = rq_list[i]; + + if (num_rq_list) + entity->rq = rq_list[0]; + entity->last_scheduled = NULL; spin_lock_init(&entity->rq_lock); @@ -165,6 +169,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) struct task_struct *last_user; long ret = timeout; + if (!entity->rq) + return 0; + sched = entity->rq->sched; /** * The client will not queue more IBs during this fini, consume existing @@ -264,20 +271,24 @@ static void drm_sched_entity_kill_jobs(struct drm_sched_entity *entity) */ void drm_sched_entity_fini(struct drm_sched_entity *entity) { - struct drm_gpu_scheduler *sched; + struct drm_gpu_scheduler *sched = NULL; - sched = entity->rq->sched; - drm_sched_rq_remove_entity(entity->rq, entity); + if (entity->rq) { + sched = entity->rq->sched; + drm_sched_rq_remove_entity(entity->rq, entity); + } /* Consumption of existing IBs wasn't completed. Forcefully * remove them here. */ if (spsc_queue_peek(&entity->job_queue)) { - /* Park the kernel for a moment to make sure it isn't processing - * our enity. - */ - kthread_park(sched->thread); - kthread_unpark(sched->thread); + if (sched) { + /* Park the kernel for a moment to make sure it isn't processing + * our enity. + */ + kthread_park(sched->thread); + kthread_unpark(sched->thread); + } if (entity->dependency) { dma_fence_remove_callback(entity->dependency, &entity->cb); @@ -362,9 +373,11 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, for (i = 0; i < entity->num_rq_list; ++i) drm_sched_entity_set_rq_priority(&entity->rq_list[i], priority); - drm_sched_rq_remove_entity(entity->rq, entity); - drm_sched_entity_set_rq_priority(&entity->rq, priority); - drm_sched_rq_add_entity(entity->rq, entity); + if (entity->rq) { + drm_sched_rq_remove_entity(entity->rq, entity); + drm_sched_entity_set_rq_priority(&entity->rq, priority); + drm_sched_rq_add_entity(entity->rq, entity); + } spin_unlock(&entity->rq_lock); } -- 2.19.1