Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2381753pxb; Sat, 25 Sep 2021 05:52:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybGbD3Nb/VvlusghhDhdA4DiW8/ZYiRnftkL8ofcG2iXFLmzEF2f9ueC8xug3sXnh6JVSn X-Received: by 2002:a05:6402:694:: with SMTP id f20mr11205248edy.100.1632574361330; Sat, 25 Sep 2021 05:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632574361; cv=none; d=google.com; s=arc-20160816; b=tM6fBz3ix2kaADTvdU+WxAtwhlnw9o/S1JF30smpqPWYOfeu7YTS/5qDiLYUaWz4wN GbHCUsTReV0ZCJN0NCkG3cHJA1//2fhDfpYSeM38EJw1/UaCcDursDJN9XdioLlHAZfG feNG3LaSrqiljBdZJH6FKH+FmjhevJ0O5OJUWNZorbR40WynQpMSf+3drvqcXT3zwKWY WmXPcfAESmcrfQUVhWOW0X34iGGefyI7sUHEMI6xpKe7CEvjttSSecjaDx6DPbkxEzUl CMR4+5J8kbofvrfchJeiAQPg5G787c++1GuN23QZucXxOsqwdEe8Z1S3baBAtRSvV24l wIzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Ua4BJcg2u0344LVjrwHCaiFB5UhE6JK98a8tF/OrK7k=; b=NyOSJIddXHtOV6b1jKHQ0F0SjaeixMEZdFMNJa/o0uq3Byekj1UpU0rghvBN/SiGhX F0vtXuJVvzTPNGCkRd/mk1g6xr5MwaiXD2sl5bREBDqCiWaW+RizB7ifqnQNirf/fxCl US2I4M7pm8BihSQBCnYOi3o2FUmL3KNv7//H97Qhsq8myl1vJIKPa5s3Fcb5qT/y/CzC SKA9vtx7JmlmynICcXkTlYqmtkvt0iSN0xq4ExJ157nPWO38fVmbkCLxX9dXxtNN6UyI CSznaacQ/mYi5vyWYAvVz9cfIILSxiJMrwTLuxCeONTMWbcWZAvVoBN2MnxHOhJDTu4b hwyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qka+leYv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si4252986edj.71.2021.09.25.05.52.18; Sat, 25 Sep 2021 05:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qka+leYv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245170AbhIYMwB (ORCPT + 99 others); Sat, 25 Sep 2021 08:52:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:58930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244795AbhIYMwA (ORCPT ); Sat, 25 Sep 2021 08:52:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C97D61268; Sat, 25 Sep 2021 12:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632574225; bh=ZbuAn2sQrDTft13W7eIt0oMpLbDcS63ttfV2RR/iY/w=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=qka+leYvAu2WtWeoBHkiKT6ei9g6kV18gY9svg8yQHkFGFYbb2XOUANnv0MhN1Kmy pL7t8fVScyzuvqyP4/JD0vU0VHdG0XEpZ4frwYKwrrVmYMTj64CNbCAO/51KbEFTme SXgFBJxA3P/C4sVbOnyKue2V43J4AmGEpt6vkkeYUZFxXi9x8eQrcoOVzwCf0AZAQQ XmKDuwULYkejqlqDIhOJq4g4DIdHoJZMbX+FIsgwdZ3dM0IaW1/BNbOe2gosVGbQE1 IYsW/17pOVVKrX/0UEcTpETd+yWecxJrHbn6IE6yPZhIlE4DV3G+Fq9+1oeO6gYmRq qJWuTBJ49/How== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 33DD85C08E8; Sat, 25 Sep 2021 05:50:25 -0700 (PDT) Date: Sat, 25 Sep 2021 05:50:25 -0700 From: "Paul E. McKenney" To: Boqun Feng Cc: Waiman Long , peterz@infradead.org, mingo@redhat.com, will@kernel.org, linux-kernel@vger.kernel.org, richard@nod.at Subject: Re: Confusing lockdep splat Message-ID: <20210925125025.GO880162@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20210924210247.GA3877322@paulmck-ThinkPad-P17-Gen-1> <20210924224337.GL880162@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 25, 2021 at 10:38:28AM +0800, Boqun Feng wrote: > On Fri, Sep 24, 2021 at 03:43:37PM -0700, Paul E. McKenney wrote: > > On Fri, Sep 24, 2021 at 05:41:17PM -0400, Waiman Long wrote: > > > On 9/24/21 5:02 PM, Paul E. McKenney wrote: > > > > Hello! > > > > > > > > I got the lockdep splat below from an SRCU-T rcutorture run, which uses > > > > a !SMP !PREEMPT kernel. This is a random event, and about half the time > > > > it happens within an hour or two. My reproducer (on current -rcu "dev" > > > > branch for a 16-CPU system) is: > > > > > > > > tools/testing/selftests/rcutorture/bin/kvm.sh --cpus 16 --configs "16*SRCU-T" --duration 7200 > > > > > > > > My points of confusion are as follows: > > > > > > > > 1. The locks involved in this deadlock cycle are irq-disabled > > > > raw spinlocks. The claimed deadlock cycle uses two CPUs. > > > > There is only one CPU. There is no possibility of preemption > > > > or interrupts. So how can this deadlock actually happen? > > > > > > > > 2. If there was more than one CPU, then yes, there would be > > > > a deadlock. The PI lock is acquired by the wakeup code after > > > > acquiring the workqueue lock, and rcutorture tests the new ability > > > > of the scheduler to hold the PI lock across rcu_read_unlock(), > > > > and while it is at it, across the rest of the unlock primitives. > > > > > > > > But if there was more than one CPU, Tree SRCU would be used > > > > instead of Tiny SRCU, and there would be no wakeup invoked from > > > > srcu_read_unlock(). > > > > > > > > Given only one CPU, there is no way to complete the deadlock > > > > cycle. > > > > > > > > For now, I am working around this by preventing rcutorture from holding > > > > the PI lock across Tiny srcu_read_unlock(). > > > > > > > > Am I missing something subtle here? > > > > > > I would say that the lockdep code just doesn't have enough intelligence to > > > identify that deadlock is not possible in this special case. There are > > > certainly false positives, and it can be hard to get rid of them. > > > > Would it make sense for lockdep to filter out reports involving more > > than one CPU unless there is at least one sleeplock in the cycle? > > I think SRCU is special here, because it has different implementations > in SMP and UP. For other code, if the implemenation in SMP and UP is the > same, we want lockdep to detect the deadlock even if it's not in UP. Ah, fair point! There are a few others, for example, kernel/up.c, but it seems to just disable interrupts as its "big UP kernel lock". > We can provide an annotation similar to data_race() for SRCU to mark > UP-only code > > #define LOCKDEP_UP_ONLY(expr) ({ \ > BUILD_BUG_ON(IS_ENABLED(CONFIG_SMP)); \ > > > <...> v = expr; > > v > }) > > and in __srcu_read_unlock(): > > LOCKDEP_UP_ONLY(swake_up_one(...)); > > Thoughts? With the workaround I have now, all is well unless someone needs to hold a PI lock across an rcu_read_unlock(), which seems unlikely. If such a case does arise, lockdep will let us know. In which case what you are suggesting might be a good way to go. Alternatively, I could use the trick that RCU Tasks Trace uses, with the swake_up_one() deferred to an irq_work_queue() handler. It does appear that !SMP kernels are nowhere near as important to the community as they were 20 years ago. ;-) Thanx, Paul