Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1019660rdd; Wed, 10 Jan 2024 06:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7IfNuVQX7vnJbOfBIRvG/YBQPDa1RCue9tZa9VOABS1qf6MhOuozdNIKDieE5FsduGaQV X-Received: by 2002:a05:6e02:15c8:b0:35f:f7cd:e5a5 with SMTP id q8-20020a056e0215c800b0035ff7cde5a5mr1528167ilu.52.1704896913729; Wed, 10 Jan 2024 06:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704896913; cv=none; d=google.com; s=arc-20160816; b=DJDytwtZ9tSgRput6gpGw5EuF4Hw0UxLbtV8aN5iCB5fh1UQpFCWt6D2PW00Pk+2E0 hu3mWf1BEwwAz83+eETEdI+MKVty3SK0pi1wOplJv/RtJMvq2y2/KEkmdE13S8M/ZKDD jzJHKEDavdefdfKjmmqo2KcxQpF9uN6DO/TPDbFN8NYWqxhknrN2Y595xGen96vHZckA b1Rbxh8H7xnp2qpAhVh0vq9dI/p+ZqEdcAPsd7W816imlxtasH1TI3h5/Ln3nQ349G0w 0xG049EppWTG5rOdZHpqtQz7wc1AbSmb3cFchRc9ACaCX9zbL3DpHmsR5WFTuNSZo5sj y0gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=/dMIStNutlFiVBwZuPV1sf1gnJ2SuNkDDtTHQI8wxuM=; fh=NaTjnaQ8wZzIvXPExUJbrjTYafQan9JlDci4ZjioDZI=; b=fXR/xo/horcXpQ2QpcEvRZM2UTy2lON9WwuXJgd23ZD5n/S6WKjFHZAeJc9SxR/pE6 QDKkLYopKNNG2xilGn3IkiuHnyas8OnMRhTStCci1Nr3l+XPUwChhx4jtfTNfZB6WMLt sFR/cGZolvffulg88FI8JNzxMg/7RyhYgXO3TGCBGXQoqOII1yUi4q286hzmObFjKdjO EkQfoxwkDN39UI7azBJXehkqmr3RvjGZnSISq/vcwbch7qKBv6WwS3nGf1Hv2SXS83oJ iOQda23kPcnbyqXfQ5eXaM9Inmofa3xApfRnYq0wAyJo1xk1xeUJvmhunEu+Pc531Xjr 0M3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IwvPaVQU; spf=pass (google.com: domain of linux-kernel+bounces-22356-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m2-20020a632602000000b005ced65a49e2si3679135pgm.756.2024.01.10.06.28.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 06:28:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22356-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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IwvPaVQU; spf=pass (google.com: domain of linux-kernel+bounces-22356-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ED84E286703 for ; Wed, 10 Jan 2024 14:28:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FF7E4B5A5; Wed, 10 Jan 2024 14:28:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IwvPaVQU" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 3DB3C4A9B7 for ; Wed, 10 Jan 2024 14:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704896903; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/dMIStNutlFiVBwZuPV1sf1gnJ2SuNkDDtTHQI8wxuM=; b=IwvPaVQU7tcuZolCHcQhKf1g1W3BNyJw1gE6DFs8STpyIXDp7eYyUwW5JWOKg2myosBivb EGM8AkvdIwz4xNhIV8COtGQ+7Col43xyq1DOeE2qY82HXPjszWsGU2rXeAkhm/IHx2vf6t 9u2/VKoFWetlEQjBOwjKmWkEE1sc0RQ= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-IT_lNvwvPbSCPyzIlp8ohw-1; Wed, 10 Jan 2024 09:28:18 -0500 X-MC-Unique: IT_lNvwvPbSCPyzIlp8ohw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFCB53C0ED62; Wed, 10 Jan 2024 14:28:17 +0000 (UTC) Received: from [10.22.9.232] (unknown [10.22.9.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83EC53C2E; Wed, 10 Jan 2024 14:28:17 +0000 (UTC) Message-ID: Date: Wed, 10 Jan 2024 09:28:16 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] workqueue: Add rcu lock check after work execute end Content-Language: en-US To: Xuewen Yan , tj@kernel.org Cc: jiangshanlai@gmail.com, ke.wang@unisoc.com, xuewen.yan94@gmail.com, linux-kernel@vger.kernel.org References: <9bed61e4-7c08-4c61-a7e4-bdd39335cec1@redhat.com> <20240110032724.3339-1-xuewen.yan@unisoc.com> From: Waiman Long In-Reply-To: <20240110032724.3339-1-xuewen.yan@unisoc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 On 1/9/24 22:27, Xuewen Yan wrote: > 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(); > } This can be a useful additional sanity test. Reviewed-by: Waiman Long