Message ID | 20221123001303.533968-1-dmitry.osipenko@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2512867wrr; Tue, 22 Nov 2022 16:30:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf41p20/YevH+yG+tyGIZv2N2PCfpHNeNbbbMMFRTN3mIVjsTVwaqFiBUd7DXJk8gqvPYY/1 X-Received: by 2002:a17:906:32ce:b0:78d:9022:f146 with SMTP id k14-20020a17090632ce00b0078d9022f146mr5558579ejk.656.1669163426370; Tue, 22 Nov 2022 16:30:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669163426; cv=none; d=google.com; s=arc-20160816; b=bK1N3Vf5NpfiQBFiLcuhavhmtYHh8PfpLYp6i9iV3VVrTLuLxwlI7JKW6TCfkc+NbT tPq+EQ3jBbJNQiKXvgVgDXcExnZtkRRvu80UtnZdBLTHNV3KTgaT7OKJqlnUIhaRXhNx 8zTwvxBfoty+6vRZTn32nN3AVC8TaR1NbgyBNrAogGklM0EPW4B3rou+MorSjryPPmGm hosiUUw/b0r1btcJ3BLSldfg0fZ9wOQpzPm4zfNmsOL9tNoy0nV1R7ua17rX3EATfPtr F6nctnROB7aw7EtkCqq6AIVyOUMwum4/ejtZz/hAnvKIb74aFcQZ/OiOaw17o/ktSHIi as7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yQof6qi5ZpM/tiIoXRvT+Byo7/kBCVNoGP7IUjYR93E=; b=TvlfxvrUOKug0btukeAHCUgZ/opFMhsYm8FqLwj6vZ9p4V4pQ2KvN1w3Q7m+69zotL eBKryItmMJ2/Lc4U5m6kCHwxmVjepBqE+FE5MIkRrjLKMTLFOQ83eQTvpgU8N/YZ6kWN 2Z5YJOt5drolOKoeW9iS31i3S6IiuXnkJcIppyct/bb3XhGNlftPFymD3Pjh+FB2EUix nuufwj533/me/b+7zpxH2W5jWy2MHn+Zxtvxjy9e2vJiaQ2K35bs8Y+R77tQ0mCXrDgh VnNNWvlMHBcDEQTmDHR8Wtq9snbOB/Jyj1aJLsu5T57TpB8e72uxJe2OdYcrDU7Duy31 3ixQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bhGlGP4Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js16-20020a17090797d000b0078e1d1d6005si1045709ejc.23.2022.11.22.16.30.00; Tue, 22 Nov 2022 16:30:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bhGlGP4Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235164AbiKWAOS (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 19:14:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234681AbiKWAOQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 19:14:16 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C291AD328D for <linux-kernel@vger.kernel.org>; Tue, 22 Nov 2022 16:14:15 -0800 (PST) Received: from dimapc.. (109-252-117-140.nat.spd-mgts.ru [109.252.117.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1F6476602A9F; Wed, 23 Nov 2022 00:14:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1669162453; bh=CjfoupBANitx/AKoGxyh1s9D/gZeN1CU4qbRETlE+4k=; h=From:To:Cc:Subject:Date:From; b=bhGlGP4QmVJocJpVlT6d0e2EYlzQqO/gsofScbdgqWtPDF2iNG4Uixj2pqveUT30I JzwkZS6f/BDgfPUpCTh7G/MuMvUwjkZOyjmBgCl3sn1vlM3xc7MkvHB1SgPB4AFXNU 4h4Zl3+2BsaLdnxuG3UGBiFcm0Czjd2DIyeSqLCQz1BrQYQ3+IwxtSz4fT3WD2Jqi5 VdaEhEEZz16wMZkkuiNySwo9KmSByjNzSg8DyJJZpLBXwY1UEO+UDDMAPcLKydSqxa vjGNj9lkh5YdzNydlQloq5Ti3ho3Kh5uqh3hU/vEauyhDm5wGYEAIxgKnoVe6HSyv5 VEGTqZnRH7Kkg== From: Dmitry Osipenko <dmitry.osipenko@collabora.com> To: Luben Tuikov <luben.tuikov@amd.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch> Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] drm/scheduler: Fix lockup in drm_sched_entity_kill() Date: Wed, 23 Nov 2022 03:13:03 +0300 Message-Id: <20221123001303.533968-1-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750244709110093942?= X-GMAIL-MSGID: =?utf-8?q?1750244709110093942?= |
Series |
[v1] drm/scheduler: Fix lockup in drm_sched_entity_kill()
|
|
Commit Message
Dmitry Osipenko
Nov. 23, 2022, 12:13 a.m. UTC
The drm_sched_entity_kill() is invoked twice by drm_sched_entity_destroy()
while userspace process is exiting or being killed. First time it's invoked
when sched entity is flushed and second time when entity is released. This
causes a lockup within wait_for_completion(entity_idle) due to how completion
API works.
Calling wait_for_completion() more times than complete() was invoked is a
error condition that causes lockup because completion internally uses
counter for complete/wait calls. The complete_all() must be used instead
in such cases.
This patch fixes lockup of Panfrost driver that is reproducible by killing
any application in a middle of 3d drawing operation.
Fixes: 2fdb8a8f07c2 ("drm/scheduler: rework entity flush, kill and fini")
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
drivers/gpu/drm/scheduler/sched_entity.c | 2 +-
drivers/gpu/drm/scheduler/sched_main.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
Comments
Am 23.11.22 um 01:13 schrieb Dmitry Osipenko: > The drm_sched_entity_kill() is invoked twice by drm_sched_entity_destroy() > while userspace process is exiting or being killed. First time it's invoked > when sched entity is flushed and second time when entity is released. This > causes a lockup within wait_for_completion(entity_idle) due to how completion > API works. > > Calling wait_for_completion() more times than complete() was invoked is a > error condition that causes lockup because completion internally uses > counter for complete/wait calls. The complete_all() must be used instead > in such cases. > > This patch fixes lockup of Panfrost driver that is reproducible by killing > any application in a middle of 3d drawing operation. > > Fixes: 2fdb8a8f07c2 ("drm/scheduler: rework entity flush, kill and fini") > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Oh, good point. Reviewed-by: Christian König <christian.koenig@amd.com> > --- > drivers/gpu/drm/scheduler/sched_entity.c | 2 +- > drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c > index fe09e5be79bd..15d04a0ec623 100644 > --- a/drivers/gpu/drm/scheduler/sched_entity.c > +++ b/drivers/gpu/drm/scheduler/sched_entity.c > @@ -81,7 +81,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, > init_completion(&entity->entity_idle); > > /* We start in an idle state. */ > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > > spin_lock_init(&entity->rq_lock); > spsc_queue_init(&entity->job_queue); > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c > index 6ce04c2e90c0..857ec20be9e8 100644 > --- a/drivers/gpu/drm/scheduler/sched_main.c > +++ b/drivers/gpu/drm/scheduler/sched_main.c > @@ -1026,7 +1026,7 @@ static int drm_sched_main(void *param) > sched_job = drm_sched_entity_pop_job(entity); > > if (!sched_job) { > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > continue; > } > > @@ -1037,7 +1037,7 @@ static int drm_sched_main(void *param) > > trace_drm_run_job(sched_job, entity); > fence = sched->ops->run_job(sched_job); > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > drm_sched_fence_scheduled(s_fence); > > if (!IS_ERR_OR_NULL(fence)) {
On 11/23/22 03:13, Dmitry Osipenko wrote: > The drm_sched_entity_kill() is invoked twice by drm_sched_entity_destroy() > while userspace process is exiting or being killed. First time it's invoked > when sched entity is flushed and second time when entity is released. This > causes a lockup within wait_for_completion(entity_idle) due to how completion > API works. > > Calling wait_for_completion() more times than complete() was invoked is a > error condition that causes lockup because completion internally uses > counter for complete/wait calls. The complete_all() must be used instead > in such cases. > > This patch fixes lockup of Panfrost driver that is reproducible by killing > any application in a middle of 3d drawing operation. > > Fixes: 2fdb8a8f07c2 ("drm/scheduler: rework entity flush, kill and fini") > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > --- > drivers/gpu/drm/scheduler/sched_entity.c | 2 +- > drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c > index fe09e5be79bd..15d04a0ec623 100644 > --- a/drivers/gpu/drm/scheduler/sched_entity.c > +++ b/drivers/gpu/drm/scheduler/sched_entity.c > @@ -81,7 +81,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, > init_completion(&entity->entity_idle); > > /* We start in an idle state. */ > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > > spin_lock_init(&entity->rq_lock); > spsc_queue_init(&entity->job_queue); > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c > index 6ce04c2e90c0..857ec20be9e8 100644 > --- a/drivers/gpu/drm/scheduler/sched_main.c > +++ b/drivers/gpu/drm/scheduler/sched_main.c > @@ -1026,7 +1026,7 @@ static int drm_sched_main(void *param) > sched_job = drm_sched_entity_pop_job(entity); > > if (!sched_job) { > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > continue; > } > > @@ -1037,7 +1037,7 @@ static int drm_sched_main(void *param) > > trace_drm_run_job(sched_job, entity); > fence = sched->ops->run_job(sched_job); > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > drm_sched_fence_scheduled(s_fence); > > if (!IS_ERR_OR_NULL(fence)) { Applied to drm-misc-next
Hi Dmitry / Christian, thanks for the fix!
(And thanks Melissa for pointing that, saving me lots of time in
research heh)
Is this fix planned to be released on 6.2-rc cycle? I've just tested it
on Steam Deck, and it resolved a lockup observed (since v6.2-rc1) -
exactly the same thing mentioned in the commit message.
FWIW:
Tested-By: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck
Cheers,
Guilherme
Hi, On 12/27/22 22:28, Guilherme G. Piccoli wrote: > Hi Dmitry / Christian, thanks for the fix! > > (And thanks Melissa for pointing that, saving me lots of time in > research heh) > > Is this fix planned to be released on 6.2-rc cycle? I've just tested it > on Steam Deck, and it resolved a lockup observed (since v6.2-rc1) - > exactly the same thing mentioned in the commit message. > > FWIW: > Tested-By: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck I'll push the patch to misc-fixes as soon as it will be rebased on 6.2-rc. Thanks! Best regards, Dmitry
On 29/12/2022 07:15, Dmitry Osipenko wrote: > [...] > I'll push the patch to misc-fixes as soon as it will be rebased on > 6.2-rc. Thanks! > > Best regards, > Dmitry > Thank you Dmitry, much appreciated! Cheers, Guilherme
On 11/23/22 03:13, Dmitry Osipenko wrote: > The drm_sched_entity_kill() is invoked twice by drm_sched_entity_destroy() > while userspace process is exiting or being killed. First time it's invoked > when sched entity is flushed and second time when entity is released. This > causes a lockup within wait_for_completion(entity_idle) due to how completion > API works. > > Calling wait_for_completion() more times than complete() was invoked is a > error condition that causes lockup because completion internally uses > counter for complete/wait calls. The complete_all() must be used instead > in such cases. > > This patch fixes lockup of Panfrost driver that is reproducible by killing > any application in a middle of 3d drawing operation. > > Fixes: 2fdb8a8f07c2 ("drm/scheduler: rework entity flush, kill and fini") > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> > --- > drivers/gpu/drm/scheduler/sched_entity.c | 2 +- > drivers/gpu/drm/scheduler/sched_main.c | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c > index fe09e5be79bd..15d04a0ec623 100644 > --- a/drivers/gpu/drm/scheduler/sched_entity.c > +++ b/drivers/gpu/drm/scheduler/sched_entity.c > @@ -81,7 +81,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, > init_completion(&entity->entity_idle); > > /* We start in an idle state. */ > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > > spin_lock_init(&entity->rq_lock); > spsc_queue_init(&entity->job_queue); > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c > index 6ce04c2e90c0..857ec20be9e8 100644 > --- a/drivers/gpu/drm/scheduler/sched_main.c > +++ b/drivers/gpu/drm/scheduler/sched_main.c > @@ -1026,7 +1026,7 @@ static int drm_sched_main(void *param) > sched_job = drm_sched_entity_pop_job(entity); > > if (!sched_job) { > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > continue; > } > > @@ -1037,7 +1037,7 @@ static int drm_sched_main(void *param) > > trace_drm_run_job(sched_job, entity); > fence = sched->ops->run_job(sched_job); > - complete(&entity->entity_idle); > + complete_all(&entity->entity_idle); > drm_sched_fence_scheduled(s_fence); > > if (!IS_ERR_OR_NULL(fence)) { Applied to drm-misc-next-fixes
diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index fe09e5be79bd..15d04a0ec623 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -81,7 +81,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, init_completion(&entity->entity_idle); /* We start in an idle state. */ - complete(&entity->entity_idle); + complete_all(&entity->entity_idle); spin_lock_init(&entity->rq_lock); spsc_queue_init(&entity->job_queue); diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index 6ce04c2e90c0..857ec20be9e8 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -1026,7 +1026,7 @@ static int drm_sched_main(void *param) sched_job = drm_sched_entity_pop_job(entity); if (!sched_job) { - complete(&entity->entity_idle); + complete_all(&entity->entity_idle); continue; } @@ -1037,7 +1037,7 @@ static int drm_sched_main(void *param) trace_drm_run_job(sched_job, entity); fence = sched->ops->run_job(sched_job); - complete(&entity->entity_idle); + complete_all(&entity->entity_idle); drm_sched_fence_scheduled(s_fence); if (!IS_ERR_OR_NULL(fence)) {