Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp730963rdd; Tue, 9 Jan 2024 19:28:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV5ClOJ1uQA6+6o9/6o5xr/u/rDZaTBrmVzZfmLR/oFm8adpMBWIbQeN0kjDF7UOpwhXBW X-Received: by 2002:a05:6808:120c:b0:3bb:c2da:1967 with SMTP id a12-20020a056808120c00b003bbc2da1967mr489364oil.107.1704857309470; Tue, 09 Jan 2024 19:28:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704857309; cv=none; d=google.com; s=arc-20160816; b=OWnspXOp05FZFmeo5TgtuLyNkVJvWElFnwk59Km8zIAUucGDbgP0UEkjnOqUIKZpQs O2t56UtjsG+kWJXxve1HB+8XBVw+FSiGwgVTiz7udGqtcPkDjcJRBB50jkvZFygdtqoC NK+F7bXL6XWnKf0JzkXBLH213/SEUK2h87NCK+D9b4lJ+dzcrru+CZXHieHHuoxG6N2g 7bxtUeewaCwa/s0QdNrZHgSrv5c3EHY8tB4wN1ypPGpWnZzeHYj/xPkgSwCvYwDk9s8z CIPenwsukHET2SdKBDoc5/3k3NVpwZfMrHryPR8hQXyAcAwAEIFY926r9DMEvLydln64 5Q+w== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=3XNv44Msfj47ACJixtraTWRYDtVZO397u4TT3msGGrg=; fh=jZRYkfcR557wdwi8PRnOLMjhyFMka7WhEMItN8mHyXA=; b=EM9kM8zMW99qITBVHxVYCvTX73ctvQ8TdHuDACfwczUpZ34Oz0bMEzpFNrQn0XmbpP Q4eR9nLf2YY4upYuJjzLKXYShdSjVcmhcmKLBdh6idltK4M/rVB/mHgFc0kCu2JfteC3 ZXrt9s32H5MI8gZBZiWSwMK7hkvyDqv7moH55e6eapx7VMwKXtWmU2xNFaxnwBxG9Zlo QhAmsvo5p+pof70O8x+myOUhX+IJ+mho3BYEJ51bdl82jZxJAg3ebvJo1q2n2k3ht/7I b2VNgpxBPqZ8bTP4JX3s3TAdIcdFzQEwv+LeBwYqvhkMX4+mYHPxfvKPct9MokFcRVqZ uaNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-21687-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21687-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d5-20020aa78685000000b006d9f6956fdfsi2671659pfo.7.2024.01.09.19.28.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 19:28:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21687-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-21687-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21687-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2311A2867B3 for ; Wed, 10 Jan 2024 03:28:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F6B763DF; Wed, 10 Jan 2024 03:28:11 +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 57B7E63A7 for ; Wed, 10 Jan 2024 03:28:07 +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 40A3Rdb8060328; Wed, 10 Jan 2024 11:27:39 +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 4T8tNW3c4Wz2QNS93; Wed, 10 Jan 2024 11:20:43 +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; Wed, 10 Jan 2024 11:27:37 +0800 From: Xuewen Yan To: , CC: , , , Subject: [PATCH v2] workqueue: Add rcu lock check after work execute end Date: Wed, 10 Jan 2024 11:27:24 +0800 Message-ID: <20240110032724.3339-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <9bed61e4-7c08-4c61-a7e4-bdd39335cec1@redhat.com> References: <9bed61e4-7c08-4c61-a7e4-bdd39335cec1@redhat.com> 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 40A3Rdb8060328 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 the work are still holding rcu lock. At this time, we print err info and print the work func. Signed-off-by: Xuewen Yan --- V2: - move check to unlikely() helper (Longman) --- kernel/workqueue.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 2989b57e154a..c2a73364f5ad 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