Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp440600rdd; Tue, 9 Jan 2024 08:39:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvfvROJEvWUKnYOREEnPJ2s0ItXWDsaBlktdP2Pm4IWCURY6QUd1lb571U3HTdhjhdE9Cf X-Received: by 2002:a05:6a20:394e:b0:191:6d71:cebf with SMTP id r14-20020a056a20394e00b001916d71cebfmr3090505pzg.32.1704818359967; Tue, 09 Jan 2024 08:39:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704818359; cv=none; d=google.com; s=arc-20160816; b=A3CnVMUR7CAS7yXOjBYOPfnaE0UqjAID8UmLNtO/UXSqIGMRobWmsJM0Of8evmKTt3 +/zrGESfbbI0LATAj0HgntSYAdqsWk2L1+CO2xlEq8u2VFHTL+6bpF3IEV2viRxEL0VE wNegt57o9go10xGYEBkBqZmSOpiDSCfpQQjOKa8ZjnsV5JIIibXLD3d1G78l7sY3kaOc WOnYnUMl0Jt2pmIwtliRpBejNTXotVUWF3+tAIy2rzii1qugPqZQGRXA6bEQnMuVMz9w xlqfxzeTL+Sqr15LN3GJLLsGYeleuZIxseVKAq7Gc14QOV60qjahGXH4a3IeR6g8zJqG GPxg== 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=gALjVpnW2FKki+TZoBpk1J20dJjfEldE4c8nd18BouY=; fh=GePsBXtdEA9DSDoiiyzHcgwNG6PZ3TT8w+oSd8WEqKg=; b=LhrTI/CtlNnqFXDEsrbOcP3+SnDTWpCa+EpkP6KFYueY2CJYlxM7O2HVJe+59wTUVB 4zSA4Jh+BhjKIbncEZYf1GwpXsMECh7rV3XRxG2aV4TQq7wD/UVdzg41r/aJO2amwmrx zIZNIp+oq6FBh1syZFOxHKIWy4o88ZHEIz7lETVPYAh0+TF56OUiSsxMLfT05B1xPgZa iw4VTCjrFQC63EzSj13vLs/2nvshKeLYMHPRcaBbACHrMhrsb6NctxvkmJcH5VrCBQae AC9nbuWwko+i45pJXYAbLaYaEfkWzJC7DTDt2WiFIPVjUt1TwrOuHBn5jApapQ3m4Dmj IFxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TezDVAY1; spf=pass (google.com: domain of linux-kernel+bounces-21116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21116-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w16-20020a639350000000b005ce5ee41a8bsi1642391pgm.886.2024.01.09.08.39.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:39:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TezDVAY1; spf=pass (google.com: domain of linux-kernel+bounces-21116-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21116-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 9B50C2865CF for ; Tue, 9 Jan 2024 16:39:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 321613A1D9; Tue, 9 Jan 2024 16:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TezDVAY1" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 AE96D38F9A for ; Tue, 9 Jan 2024 16:39:12 +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=1704818351; 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=gALjVpnW2FKki+TZoBpk1J20dJjfEldE4c8nd18BouY=; b=TezDVAY1qj/rDpPFhc71Zattm/pw5RIwXVXdKrh2PhA//tvDbUaZZVckI+AWtz0p7wqcT7 ca1sCaqrbOzg15QERV2SgbZJWbMgYfxvo+5kng790Z1gOvN6oej5xjqfkI86uHD8zHtktO CCHlRf0UKNh+8yDmN17v5pGT84kcrlQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-9pVJLRnBOb-uYCDMV09uJg-1; Tue, 09 Jan 2024 11:39:05 -0500 X-MC-Unique: 9pVJLRnBOb-uYCDMV09uJg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 AA16583152B; Tue, 9 Jan 2024 16:39:04 +0000 (UTC) Received: from [10.22.9.97] (unknown [10.22.9.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66CC82949; Tue, 9 Jan 2024 16:39:04 +0000 (UTC) Message-ID: <9bed61e4-7c08-4c61-a7e4-bdd39335cec1@redhat.com> Date: Tue, 9 Jan 2024 11:39:03 -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] workqueue: Add rcu lock check after work execute end Content-Language: en-US To: Xuewen Yan , tj@kernel.org, jiangshanlai@gmail.com Cc: linux-kernel@vger.kernel.org, ke.wang@unisoc.com References: <20240109111014.2689-1-xuewen.yan@unisoc.com> From: Waiman Long In-Reply-To: <20240109111014.2689-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.5 On 1/9/24 06:10, 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 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) { The rcu_preempt_depth() check should be within the unlikely() helper. Other than that, it looks good to me. Cheers, Longman > + 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(); > }