Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566340lkm; Mon, 20 Sep 2021 18:53:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOAfGP4nVX2o/dykIQg5cAjp3aGEEiuCv4nR6gtc9IupvcBHlBTebCZBsRwo8QmqAXwmdc X-Received: by 2002:a05:6e02:2182:: with SMTP id j2mr20169309ila.212.1632189192058; Mon, 20 Sep 2021 18:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189192; cv=none; d=google.com; s=arc-20160816; b=ZJmXU46EsrsU+tou0kvWp8hsp0/Hfoni9+YbXTohTd64Aick5o1zV+4YkLmrMTogWT 6uoDQPkrL8CcUFEuQv8jIk5bZ0t4GjbZTA7ElQ+0FIMo/ORFPIZURtMqsZurylaBXPtp naNGaEVnQv/lInPYsx1wx+gXwfKnaY3RSdWgT5HOkLmBk9Y3/YcRAMsNqikzIka1IkT+ 0ETKMHSaSpIUdG7MvL4FKM9zE+OGdkdzoWQw7aFPLbo9GOVdyDroIAaLEFx1a210kWY7 /EdtXcVJyI0nSEia09Xv5txXMnvNBU6iDGeVPOJoCoUznNeyBCxhF2ekNkzBKEXjYFUJ WiVg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qvZ+cCnmvLKDG2RUh1zTOZx6MtKF4yxHNdEBUGbLo8Y=; b=yJMuMq1wGNJ+vMyN/NvXvp/or9bU/TsK+6HyEZNgf8YwSqTYnw6nMg1Wz6fB6funwK 0M2b/YqUr4SouDwWlczlVxDUFb8ehsf5Tp2u06xZAN7lcu2PQuFs78vkJtvMCYMZt01O zCqhYzM5UZPNCWguztdKfnrUNthwoqhXM9xvV/DE5aZvF1mfBAeMJNQQLurVKyXklwH5 Fe/sAJS53ev2VXbRB2aENXN39DLJAmKyl4UJdAaT8gkmHn01XJgMlwmbJus/S2efl87y bE2fjZLfj1AbaVdO8QI5G33Ol7nzU4qrQNYAd1IhLUZxqGcYmMhUcIkjHVOYsaDmw3hG 0KqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JJ3QN5OJ; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q9si19008630ilo.171.2021.09.20.18.53.00; Mon, 20 Sep 2021 18:53:12 -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=@linuxfoundation.org header.s=korg header.b=JJ3QN5OJ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376564AbhITSNB (ORCPT + 99 others); Mon, 20 Sep 2021 14:13:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:35750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359044AbhITSJM (ORCPT ); Mon, 20 Sep 2021 14:09:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BAFBA61A50; Mon, 20 Sep 2021 17:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158343; bh=L0uvE418LEtuoJirJEY/yF7uXg0fi/F05OFKbzd6Fvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJ3QN5OJIP3Eb7Lrd32aIx6s6SrSu4/1eevsefcob0EFCmDW/8r3lb3B6WbVbCv12 KCvHBywrPQCNAs5tOLcRhnA8QOC8VC95d4w9LaKMNDP1oVP5YNyuVP+USuh8hVHDpw 9QafBunZtfuaZiLNo3dLOkhCvg1RMN3xCquBH5LM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Desmond Cheong Zhi Xi , Daniel Vetter , Sasha Levin Subject: [PATCH 5.4 085/260] drm: avoid blocking in drm_clients_infos rcu section Date: Mon, 20 Sep 2021 18:41:43 +0200 Message-Id: <20210920163934.036054472@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 00debd02c322..0ba92428ef56 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