From patchwork Tue Jan 9 11:10:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuewen Yan X-Patchwork-Id: 186321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp35841dyi; Tue, 9 Jan 2024 03:11:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSjXRTt22xtstrxLcAhJSdUkmuLyqGsiPZe8Zou3wfCjhVqOzqK7fMRKQLLMoT9RBGVieF X-Received: by 2002:a17:907:9718:b0:a28:e2b7:1b96 with SMTP id jg24-20020a170907971800b00a28e2b71b96mr199637ejc.156.1704798709185; Tue, 09 Jan 2024 03:11:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704798709; cv=none; d=google.com; s=arc-20160816; b=rxsrMe0y83wautp7aQLRbbYjRXkJ2Aa0XG2aYt6hi5D2DOAPPW7d/SztJPT6j992dS sfCBIQyGMt3z+ng2iQny+4hho5tea+uHEQ+bAe/+T4DNG80HnSFuHOFj/a5WyMgaea7f jgOwLhyX0BF4tWwjDXGlUzM74+qLnqoPDyPaKZtB3BdDRQPD8SIIXiSUymGuZw1pzXd3 576ResGvK5LGdIs4FFx4T5DMSPoaNw0qemFQNyYVISwfPOWfqdiv+DWUSTWqBMXklc2V BEFTYBCOKx2mnjTLj6VvwG1a/vk3oHCNQSAB2h3r98d1BCBmAmenY51gc9v/fxy8SnLz /0dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=08ksWIX8R6LNvQb81Gj24n3Yfmss2KOvDLW9YQ+22Ok=; fh=imnwms/oZCry6wxJGDhoHw0PiAoy1Wcq6s0TtGVxaag=; b=FccBOUdF1gEPlIOvVwXwUdUNaO+w1vUg+8h7Yifsgi1X8RTYe+/5F69BKEHjI4h5XP 5Kk1+Vo8bohgSyRVTUK0ZIjJQi5JpF8tSPhAOlsKWoq4zFoVEGqPkOGh6h0gyPC4Z6gt kKiUycDbqAgA4UTS2IdnoEsAdA+mtQOazhxsJnVANG0rtW3hQ2hh1KnB30qDn5STah2P 2m+Q2GzMLd3bUuWmpdtig7KDmefSGKWoNNpuj3piIZQu1HWPldzXl4cJwu4eWe62iRTD d5quuxaKauIhUMPtb/2d33NRBHF60YmsU3w6e4+bbsVaAx9MrO+IP5/Ra3IHMy8OcHIk Z2CQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-20749-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20749-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e7-20020a1709062c0700b00a26a4ab3582si675843ejh.322.2024.01.09.03.11.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:11:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20749-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-20749-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20749-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C241B1F25879 for ; Tue, 9 Jan 2024 11:11:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85843381B9; Tue, 9 Jan 2024 11:10:50 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D9B336AEE for ; Tue, 9 Jan 2024 11:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 409BANLO045364; Tue, 9 Jan 2024 19:10:23 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4T8Shw6jWgz2RS3WG; Tue, 9 Jan 2024 19:03:28 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.73) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 9 Jan 2024 19:10:21 +0800 From: Xuewen Yan To: , CC: , , Subject: [PATCH] workqueue: Add rcu lock check after work execute end Date: Tue, 9 Jan 2024 19:10:14 +0800 Message-ID: <20240109111014.2689-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 409BANLO045364 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787611010817058552 X-GMAIL-MSGID: 1787611010817058552 Now the workqueue just check the atomic and lock after work execute end. However, sometimes, drivers's work may don't unlock rcu after call rcu_read_lock(). And as a result, it would cause rcu stall, but the rcu stall warning can not dump the work func, because the work has finished. In order to quickly discover those works that do not call rcu_read_unlock after rcu_read_lock(). Add the rcu lock check. Use rcu_preempt_depth() to check the work's rcu status, Normally, this value is 0. If this value is bigger than 0, it means that the rcu lock is still held after the work ends. At this time, we print err info and print the work func. Signed-off-by: Xuewen Yan --- kernel/workqueue.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 2989b57e154a..a5a0df824df1 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2634,11 +2634,12 @@ __acquires(&pool->lock) lock_map_release(&lockdep_map); lock_map_release(&pwq->wq->lockdep_map); - if (unlikely(in_atomic() || lockdep_depth(current) > 0)) { - pr_err("BUG: workqueue leaked lock or atomic: %s/0x%08x/%d\n" + if (unlikely(in_atomic() || lockdep_depth(current) > 0) || + rcu_preempt_depth() > 0) { + pr_err("BUG: workqueue leaked lock or atomic: %s/0x%08x/%d/%d\n" " last function: %ps\n", - current->comm, preempt_count(), task_pid_nr(current), - worker->current_func); + current->comm, preempt_count(), rcu_preempt_depth(), + task_pid_nr(current), worker->current_func); debug_show_held_locks(current); dump_stack(); }