Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp444399pxb; Thu, 9 Sep 2021 04:44:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzWlczGCqSKzvxygEXDFSzi4hzvsM+1m/eyvDELDsTJSLV76dmn9QhUt8sf9pq5krD3qYC X-Received: by 2002:a5d:974f:: with SMTP id c15mr2215115ioo.190.1631187890864; Thu, 09 Sep 2021 04:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631187890; cv=none; d=google.com; s=arc-20160816; b=b4eOjMEetwMH3pgCSqjX4tdJdpEkjaRzdNyLZ3zbE7VCtN5gSusfWhv33y3NINEVyQ zb3FH/moaPTj128XK8jPH6j3x+384J+CXECh1AZ3j2uWFFfKlH8giI9B9WVfIfPuKO53 a15rgfcfokmxGlNU5rJDfAZT3o5ii1QPiPfCIEaiHm3hR3w0v/oUyAUgwJ9y3YLfr1yA USLRozyLzXL/9iPJsl3fHMe19uCY3v4vh9bdSMvyJEviRXIcloxonwtF3kvDcxGfMK1G 7VdMylQaBDwUOLa1+fcbWnddEtRMhLDifyiXqREi35oEdLQWlbC1H1ctqrFqFSaKzaUq rVUQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6HFuMFf9AMtxNpg7Swg5O1xv3Z9tAHexPeeOB+z4Mts=; b=C762J1DNWhFlhA6mAgA7ttCVXCE7EzGViRf5W+3fkDKUhLowyBTgJzp1xYogmRkD3+ 9JRrgkclGUuh7dFRw6tWdenGYMoJMu6AXfyjrZ4lUjDuxQugUKo3tLm4loKgvgIFnyGy asCoADuZprQ9XFsmhQUkhJeMqKb25hPlic7TKY4Fz6BqocS1reo128rNvSeUyBrV6Ykt CQ4NrNCR4uxz0ER+0F268MplbJRjw29KdAzNMpGXAA8H/rllIqQCk2yAMFfIwtTP3yRm 4/ur/iJLah+I2iBH7KgKUVbMHy26QReCWe3NLDVgLUg5FNT1HdSgFVk/kx/JSqBC+FKp 7yRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ae5XeBdi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id x6si1739082ilu.80.2021.09.09.04.44.39; Thu, 09 Sep 2021 04:44:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ae5XeBdi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236463AbhIILo6 (ORCPT + 99 others); Thu, 9 Sep 2021 07:44:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:46202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237365AbhIILnA (ORCPT ); Thu, 9 Sep 2021 07:43:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0277F61131; Thu, 9 Sep 2021 11:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187710; bh=TUaNbGijjf16dwoOSELXxmYWLOmllXRTFAu0Q8E1m3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ae5XeBdiXzzLUuU7HMnm8h6eyob+jGHvlzPzip8wHMV+wwITZJ7MQRUVYhE1gTFwI +UFJV9Duh8XhNCaaQ1WqBmXot4SsZSDCBECcUz0G9BZwLNQcd9veqQw8YE/KCIgeQL h73fj/MJkcFqEvViythSXRorPb1z/oIp1ZO1ti9RlnGjdPLv8bx0q4aUBz/HktEFaC ykZ07zDWkiDn0UfuW5gBvFpg4fpNEI8u0FDlKycEBi4d0kUDInfEZ82UJ3Crxlv5dX mE6cWQGW5raUr3tC8hiOZC852Iea3vPXuOoLcCy3uD2kCeT6NqBja0zRyl46erw3Eo j566DPS7kdnRQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Desmond Cheong Zhi Xi , Daniel Vetter , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.14 034/252] drm: avoid blocking in drm_clients_info's rcu section Date: Thu, 9 Sep 2021 07:37:28 -0400 Message-Id: <20210909114106.141462-34-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Desmond Cheong Zhi Xi [ Upstream commit 5eff9585de220cdd131237f5665db5e6c6bdf590 ] Inside drm_clients_info, the rcu_read_lock is held to lock pid_task()->comm. However, within this protected section, a call to drm_is_current_master is made, which involves a mutex lock in a future patch. However, this is illegal because the mutex lock might block while in the RCU read-side critical section. Since drm_is_current_master isn't protected by rcu_read_lock, we avoid this by moving it out of the RCU critical section. The following report came from intel-gfx ci's igt@debugfs_test@read_all_entries testcase: ============================= [ BUG: Invalid wait context ] 5.13.0-CI-Patchwork_20515+ #1 Tainted: G W ----------------------------- debugfs_test/1101 is trying to lock: ffff888132d901a8 (&dev->master_mutex){+.+.}-{3:3}, at: drm_is_current_master+0x1e/0x50 other info that might help us debug this: context-{4:4} 3 locks held by debugfs_test/1101: #0: ffff88810fdffc90 (&p->lock){+.+.}-{3:3}, at: seq_read_iter+0x53/0x3b0 #1: ffff888132d90240 (&dev->filelist_mutex){+.+.}-{3:3}, at: drm_clients_info+0x63/0x2a0 #2: ffffffff82734220 (rcu_read_lock){....}-{1:2}, at: drm_clients_info+0x1b1/0x2a0 stack backtrace: CPU: 8 PID: 1101 Comm: debugfs_test Tainted: G W 5.13.0-CI-Patchwork_20515+ #1 Hardware name: Intel Corporation CometLake Client Platform/CometLake S UDIMM (ERB/CRB), BIOS CMLSFWR1.R00.1263.D00.1906260926 06/26/2019 Call Trace: dump_stack+0x7f/0xad __lock_acquire.cold.78+0x2af/0x2ca lock_acquire+0xd3/0x300 ? drm_is_current_master+0x1e/0x50 ? __mutex_lock+0x76/0x970 ? lockdep_hardirqs_on+0xbf/0x130 __mutex_lock+0xab/0x970 ? drm_is_current_master+0x1e/0x50 ? drm_is_current_master+0x1e/0x50 ? drm_is_current_master+0x1e/0x50 drm_is_current_master+0x1e/0x50 drm_clients_info+0x107/0x2a0 seq_read_iter+0x178/0x3b0 seq_read+0x104/0x150 full_proxy_read+0x4e/0x80 vfs_read+0xa5/0x1b0 ksys_read+0x5a/0xd0 do_syscall_64+0x39/0xb0 entry_SYSCALL_64_after_hwframe+0x44/0xae Signed-off-by: Desmond Cheong Zhi Xi Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20210712043508.11584-3-desmondcheongzx@gmail.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/drm_debugfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c index 3d7182001004..b0a826489488 100644 --- a/drivers/gpu/drm/drm_debugfs.c +++ b/drivers/gpu/drm/drm_debugfs.c @@ -91,6 +91,7 @@ static int drm_clients_info(struct seq_file *m, void *data) mutex_lock(&dev->filelist_mutex); list_for_each_entry_reverse(priv, &dev->filelist, lhead) { struct task_struct *task; + bool is_current_master = drm_is_current_master(priv); rcu_read_lock(); /* locks pid_task()->comm */ task = pid_task(priv->pid, PIDTYPE_PID); @@ -99,7 +100,7 @@ static int drm_clients_info(struct seq_file *m, void *data) task ? task->comm : "", pid_vnr(priv->pid), priv->minor->index, - drm_is_current_master(priv) ? 'y' : 'n', + is_current_master ? 'y' : 'n', priv->authenticated ? 'y' : 'n', from_kuid_munged(seq_user_ns(m), uid), priv->magic); -- 2.30.2