From patchwork Mon May 10 16:36:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 12248689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ECC1C433B4 for ; Mon, 10 May 2021 16:37: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 34758611AB for ; Mon, 10 May 2021 16:37:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 34758611AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.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 7350D6E8C8; Mon, 10 May 2021 16:37:10 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2086.outbound.protection.outlook.com [40.107.94.86]) by gabe.freedesktop.org (Postfix) with ESMTPS id 27DDE6E8BE; Mon, 10 May 2021 16:37:09 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BYMfnsN52o4+zaE7HpWvmwHiYfycXD5b56nyw/U3HNkIzwOcXQxzpXJ4PbIcEML3fyx6I1YTGFIvA9g7KSUE48/I+s13h5FrfPK8lFH/r0f9cDxwezW2cg0o7THnmagioV+tqdShBMX6VfA7tBCHjSNE/zanqhymLS+jw78FA/b9IMQl4ANdg8YQcHt7ZeKAwX5SnBzLuGRk7oW6MhM2YodgzevlAuoLwPWjUwatFjp/oeOpjValBSOoH2ZtAD75S+uVkp01ga/x1wte7BzUGBQFG5qTvYwVF8ehG+EhvnfA5t79g10s4O4A1ZIPLVyL7PqtqSkHQlNKFlk464HX4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H/uPjWV0fg0dVVvp8px//s3OoPIuYbV9UKVinTXXgyM=; b=S4U2Qo66i9XLZtjXmXqoLiC7yNacRv2/sEHls891C4BLkqUn5f79Tgdhj2wzk8GjZ1xz0zy9RYA0dzdrava5rUPLB5BwxZAvLkN3iZ38wV4Nt3Eg6wliuWDmJOdywVS6JbiEVThjHPBH4QaArQhvaqoO8szxmDnUeocKpUkVC4q36p68qOT9B//aPzpJELJSMdUZzsBmmRLhX5GNpMMAUFHmAGXoxJm+D5aYSOrg04PTQp/2g4YMzd3maxlpjxPrpQ0IzllvsPNoIjdJtjVFLJ4NJZ8YrVKYSktAntXkJfsCQJczkOO6sDaymUrAWg6rimjv0N9TVGXHnTm1DLFmaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H/uPjWV0fg0dVVvp8px//s3OoPIuYbV9UKVinTXXgyM=; b=MxKUWsIKIIaK/ZXfaerPAxNtzoeGAN8orCb4LGwFZ8lJ7VwMlVi+7H4e13NA+FS+9stRUZdgydvioheOHwxrXIPQnaPjmL1yQ4b7Z8f3TseaGrAXrMZZcEzTI+lxMbHjeLGibiWDrxgA20CHTI7B4bn7sFTAFDpqBhhdhFTrb/Y= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none; lists.freedesktop.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) by SN6PR12MB4717.namprd12.prod.outlook.com (2603:10b6:805:e2::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.24; Mon, 10 May 2021 16:37:07 +0000 Received: from SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::ad51:8c49:b171:856c]) by SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::ad51:8c49:b171:856c%7]) with mapi id 15.20.4108.031; Mon, 10 May 2021 16:37:07 +0000 From: Andrey Grodzovsky To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-pci@vger.kernel.org, ckoenig.leichtzumerken@gmail.com, daniel.vetter@ffwll.ch, Harry.Wentland@amd.com Subject: [PATCH v6 14/16] drm/scheduler: Fix hang when sched_entity released Date: Mon, 10 May 2021 12:36:23 -0400 Message-Id: <20210510163625.407105-15-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210510163625.407105-1-andrey.grodzovsky@amd.com> References: <20210510163625.407105-1-andrey.grodzovsky@amd.com> X-Originating-IP: [2607:fea8:3edf:49b0:6a5:47b8:e610:f6a3] X-ClientProxiedBy: YT2PR01CA0020.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::25) To SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from agrodzovsky-All-Series.hitronhub.home (2607:fea8:3edf:49b0:6a5:47b8:e610:f6a3) by YT2PR01CA0020.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.31 via Frontend Transport; Mon, 10 May 2021 16:37:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 27eed853-578c-4555-9117-08d913d1da04 X-MS-TrafficTypeDiagnostic: SN6PR12MB4717: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:663; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cj65LdDYZi6Q/yMXUb0SwW15TOKbBTNgSCXO6DmjPbUpdFPwjgQtNVmgFr3EoRuwWCfXV1/pK/4zQ/bUsbzLtXkBu3yje+RmGB29z1LyIjkrJPF1kZjGQHn/I642Z+RkdpHrDhlwB27Bn5IpnzvXVij1hUR4b3oFbaRF2INdCng+KRtGi1TGncHHScebBr9y/FVqEGwKyrCifqxsc1kR7MGR2X4LysTL4lF5XDrp2SOxiNUeNXhm1lLsFvu1GH7Qw4CRfhnx18kszOD+foyBhq6kpQB0QJqlyXPvAzzpOjnaN8uT9UGbZ78pYwxo+uUwjynMKtwGUT70OLzo1hl1nQOqC7VGi98ZzfeLvMdje5jaoZx1+rvA2HN0WTJX5COUbcJvUUwQaO/xELXrgjQt57tGLVhvFEcZ9XADZqbUMVOxJGatc6BUqiA4vvnIYI8AS15b7bSYNLi8jbUkmrnhHSDCnL6rq49+HCrWz7TTtTXPzkAUdKU85v8YHmLuJ0G3CUP04q4Ih1OMnnjXzvtYFl6e7LP167DngEHkeACpoh3uuDki0/YAV9SAOL9SGa4+l4h1S8xoe/uVLHpjHSH6ocHyLb0RPW+7mkyT2JZs/G8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB4623.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(376002)(346002)(396003)(136003)(366004)(6486002)(44832011)(83380400001)(5660300002)(66574015)(2616005)(8676002)(1076003)(86362001)(6506007)(478600001)(186003)(16526019)(8936002)(6512007)(6666004)(38100700002)(36756003)(52116002)(2906002)(316002)(4326008)(54906003)(66946007)(6636002)(66476007)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?un9Ia759PO/+RBzPGUNzP7OL8uwjis?= =?utf-8?q?TxM7GpPMGfKK90E9KvSMUmsMVasBNdXnByPMg7PYSbZmCsL0dUpvAzEPFUsFeEO/2?= =?utf-8?q?7QGU2ANerL0XyE7DpNbO2XR5fnIphuFcbVPBw5ViWxB8KvDyEubFhgHshPF5dwMq+?= =?utf-8?q?Zo5zqEFoplQATUexV1q42m1ZgjO5RKzURplCkv0R/sX2TouKWkh6Q2xf76XeQGYWQ?= =?utf-8?q?zChW48i5ASUxfcm5sgnB7DR9jG36ANhdhWt2wrCNPobV+qX4BDSKwO9fUkAxJhBtu?= =?utf-8?q?9wbH3zSG4g9XTrGmxngF6VhzxeeZbjCs0rKDt3sK8C0H4bFNEpeV8Pc6PAeuZX/bX?= =?utf-8?q?d3R1FtC1lSUp18843utVk4Y9fDv2OgxwGTWkZC+jQaVXjw3ZabnVBPxhNZQbk1auY?= =?utf-8?q?xbmh3cUFiY74Qxi3j1vWwflBmyY4eeSu2Yw8hjRVa8pulLVRLxwIhS7ckM7h854VC?= =?utf-8?q?u50r5LMaMo4YkwMbbA+Hwi5a/+GBXZ67FMxNk4JCLdpCAFdBfVErHvc5Er1La49NH?= =?utf-8?q?CZLy9ZGj/APVeEjLptNi7HXUSRViQU4Ic/w2R4BfbiPkLpr+YsxIUcIRoO8xDAsyH?= =?utf-8?q?IRoKCaljTQqyuj2tJuXZXLNLzrEQsIeub0yU/zKLbuUpwPcGlLckWgZuDZO44vc9B?= =?utf-8?q?f6mo4ubFrl+Y5cX8aku9YQUx5hyEVhak8iN8X3E81jv6qfU+Xz+eU/hpkb+epSucq?= =?utf-8?q?gA8+Gd0mBMsj3MO5tnDJaE0VsDf2lYasuV4dH3ZMTqg4zO1uHxbmc0QiqU3mJ0HZw?= =?utf-8?q?eeufSV9rag+BmDI9YwibamKwZBoyw4q8ZzwykSFyH1V20naLXPG9n/khuNuR/FK5P?= =?utf-8?q?og/Arcb9owCjFQIo/4LqQ2HUTF4/HPh9GK6ruCFPhviF8g8o6KFW/FjiMzqHsIR/L?= =?utf-8?q?Y7U7E+jgvhQI7QOqYiwPkXhiRI3yrXmL6UgARB03fOcloJ/zgB6dtbP/o07DGL2JO?= =?utf-8?q?QkYw2N+H1Y9n3alxn5isgIrxDnKuFWqXINmdq9UNqo9iq9PkFtgyZq/8ZsYHodzAF?= =?utf-8?q?Nhz8oBuDEHFxi1CBHuHELNRsRX4uax0MRw9NmKBPyCULMbIdCYOkV9kAl/NVpwuCz?= =?utf-8?q?eL44S0wMElA5IRXnEMQWl2j8cnB9tgFi8g7DqJO8VBaZUChkDqR1QQlnQmj/hI+7I?= =?utf-8?q?UqCt5HJkDGuON34ho89gJs9FMeqPBOgXcloEWH8gLYjciRPY7UtNBCG5x7YDnyYZX?= =?utf-8?q?ohZf4zfU6u99Z7qogFyowtkU6PkMtS5mTFSi7gqAMtEefOYg2nmQSi32/9zSPhrX8?= =?utf-8?q?DmxMd5NtAiv/50pujF31RVTlgC2i/PGGuakHzu0BGgnJefe2X2RuyA7KJK1rL3n2J?= =?utf-8?q?2CpOs3AbBkiCD?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27eed853-578c-4555-9117-08d913d1da04 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB4623.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2021 16:37:07.7780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C9+m+liBrIy8ToO8d38g3LfgnXZbJBwV1Jds+wbhPOzg8hV03pkZJ3jPCSLcYsK8r8kXoyp+i2JMygXRqUM+6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB4717 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: gregkh@linuxfoundation.org, Felix.Kuehling@amd.com, helgaas@kernel.org, Alexander.Deucher@amd.com, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Problem: If scheduler is already stopped by the time sched_entity is released and entity's job_queue not empty I encountred a hang in drm_sched_entity_flush. This is because drm_sched_entity_is_idle never becomes false. Fix: In drm_sched_fini detach all sched_entities from the scheduler's run queues. This will satisfy drm_sched_entity_is_idle. Also wakeup all those processes stuck in sched_entity flushing as the scheduler main thread which wakes them up is stopped by now. v2: Reverse order of drm_sched_rq_remove_entity and marking s_entity as stopped to prevent reinserion back to rq due to race. v3: Drop drm_sched_rq_remove_entity, only modify entity->stopped and check for it in drm_sched_entity_is_idle Signed-off-by: Andrey Grodzovsky Reviewed-by: Christian König --- drivers/gpu/drm/scheduler/sched_entity.c | 3 ++- drivers/gpu/drm/scheduler/sched_main.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 0249c7450188..2e93e881b65f 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -116,7 +116,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) rmb(); /* for list_empty to work without lock */ if (list_empty(&entity->list) || - spsc_queue_count(&entity->job_queue) == 0) + spsc_queue_count(&entity->job_queue) == 0 || + entity->stopped) return true; return false; diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index 8d1211e87101..a2a953693b45 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -898,9 +898,33 @@ EXPORT_SYMBOL(drm_sched_init); */ void drm_sched_fini(struct drm_gpu_scheduler *sched) { + struct drm_sched_entity *s_entity; + int i; + if (sched->thread) kthread_stop(sched->thread); + for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) { + struct drm_sched_rq *rq = &sched->sched_rq[i]; + + if (!rq) + continue; + + spin_lock(&rq->lock); + list_for_each_entry(s_entity, &rq->entities, list) + /* + * Prevents reinsertion and marks job_queue as idle, + * it will removed from rq in drm_sched_entity_fini + * eventually + */ + s_entity->stopped = true; + spin_unlock(&rq->lock); + + } + + /* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ + wake_up_all(&sched->job_scheduled); + /* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync(&sched->work_tdr);