Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1532556pxb; Thu, 16 Sep 2021 09:21:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi4wSmiT15QtqF6dcANyn3+nurcht7NE1GzIxwr6eLxZheoq26Ne0FGaqhe5PQNOGAP9U5 X-Received: by 2002:a17:906:1484:: with SMTP id x4mr7050547ejc.72.1631809316620; Thu, 16 Sep 2021 09:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809316; cv=none; d=google.com; s=arc-20160816; b=ieF9dzyuT+fgZDQOQCh89E6PJUvanTJmm/DVBSQTATgqi/wu84pa6NH63JwdB8pfFw p1kHwEEd+iD2mCI/fc8Ni0zGB5QQWUHzQIAtfuk8yHGCzi9v5+ivlAvSZIegdQaxPACa PUJbf6ExqlS68XjhrjkJho/rCSHJKv9QXYT2pMu27lFRAYEspL6Y6QH12ihWKDpSZpcQ Xzpez8LwSFusybnjWPXXXHj+1MX7sEDWRqJTGScZieaIgnI3wddalfKFA1c7DTrXdHSQ yXrloDduMJhVVzbW1h9JjZzvRswAKAUsBIZq9zhaWZuUfAEgbISiJNpRTdFKUr7EHJVZ tSqA== 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=6HFuMFf9AMtxNpg7Swg5O1xv3Z9tAHexPeeOB+z4Mts=; b=OQT2KWocb4S15mpVgpUti3qYl52k9x9POdcbA0PiID1RhqxeX1ztk+C+RTplldMFy3 b6nZ0IaaV/8AcBFbXLWDULZ9VINjWuKicPBuObZoR7+t/0Gq2C3Qst7rkXIMQe5Dwafh CIm9UcXcgv0c5/mAgUyhP51gBlF9yOF+SyziHumlnpoicS5EtlTHYEM7HsY9fjQ72O/i XcMdFGoOoKeCBYTtN7N2WwRi4jZzFCZa5ON+5VpnEFfTTf5UhOzoWM3QXspXbyGaGiyF I2KsklP/HJwQOWn2Tm/1FSFpYY9fMOQpDuBi74uOjUN/rfy/BRTGFQtiY9pZJmYx2Thm K6qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fp7RfQKA; 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 i14si3911578eje.121.2021.09.16.09.21.32; Thu, 16 Sep 2021 09:21:56 -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=fp7RfQKA; 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 S240592AbhIPQUb (ORCPT + 99 others); Thu, 16 Sep 2021 12:20:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:48798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbhIPQLj (ORCPT ); Thu, 16 Sep 2021 12:11:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9745B61355; Thu, 16 Sep 2021 16:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808536; bh=TUaNbGijjf16dwoOSELXxmYWLOmllXRTFAu0Q8E1m3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fp7RfQKA//T0CbjquNW3wrTsVPwU5JHZYU9SWqHQmPO3avEk44mI1vXEvma4xOz1P I6gqkdadLlMwAfauCHogz+MSC0QAMXNlmadiiKjVaIqhNh1+gTkv8hS5JYcrZgUKkk l0hz/UWCXvUTqUCciKe8JTmY8ZRR2zf9fble+CWo= 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.10 127/306] drm: avoid blocking in drm_clients_infos rcu section Date: Thu, 16 Sep 2021 17:57:52 +0200 Message-Id: <20210916155758.397286104@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 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