Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp254285rdd; Tue, 9 Jan 2024 03:12:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlS1qox4iADtQoFpw4/4P01rGAa2Y4w9h0a/la2Qo/yyeP9/rnf1Gm4Zo6eXRBYB/THkNk X-Received: by 2002:a17:902:e801:b0:1d4:1956:80d4 with SMTP id u1-20020a170902e80100b001d4195680d4mr3199185plg.47.1704798741256; Tue, 09 Jan 2024 03:12:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704798741; cv=none; d=google.com; s=arc-20160816; b=avLshH1+Zl/hTr2OVFlO8YCYV1B3mP/L+4lM9t6gi+A9IsSy6Gg39fGJk//3BVxtFq t1De73VkGxtsGlWyFygphBHcjL+YHgrgqcObSQ6eG+0d02KZ2xIdLhIVBDfLWMJnkUcH mDk2atFm+EqAMHdnfTz5JSO4RSkvFzD6rsnDg7Uk2+JC26z7bBOS2wokFKJWu/j3kA5q MAJtTGwEJMCcmglTZqMvxHonBycm+mm8mKJd/ud2ned9eDVH+YqcAEVMgbg6b79wuMF6 Ox6D6G1tG3XUmiHskZnOMdPYa8N3ZTL7vmYS8IFc3Pne6Nv4ZdGnP467IjQpws1d1XJN Ulxg== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20749-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n12-20020a170902d2cc00b001d0176127a9si1325631plc.307.2024.01.09.03.12.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 03:12:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-20749-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-20749-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-20749-linux.lists.archive=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B9415B2473F for ; Tue, 9 Jan 2024 11:11:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CC04374FB; Tue, 9 Jan 2024 11:10:49 +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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL:SHSQR01.spreadtrum.com 409BANLO045364 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(); } -- 2.25.1