Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp176837rdb; Thu, 8 Feb 2024 02:43:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV6leyYeUVJgLnP/ABloyaXMszQNxrtYFYEOzYiNbs+Bo6FCJx3MGLDFw1fpw4zqG0Evl+GVmTuEMoeGp8w6xePwuRL6JQbYVGkom/Q+A== X-Google-Smtp-Source: AGHT+IHspDsoS7fPqJXHF+/9+3uA5LNApld9SOQipZCycA1AeepJ60Af/OQRysGoNWBkrIk2NnFA X-Received: by 2002:a2e:a725:0:b0:2d0:9fb2:2c79 with SMTP id s37-20020a2ea725000000b002d09fb22c79mr6390527lje.3.1707389003905; Thu, 08 Feb 2024 02:43:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707389003; cv=pass; d=google.com; s=arc-20160816; b=S2yKV7pDl7msEVt1utHANnuzIYiN7ejIgYQDlzj44Ez187eSk8bagn2+F2I5AYSbVQ xTbIyNzLpma7tKgTHCNPE2HaaVZ662vJbC8Zv11XWP8Ra7YPiiHIPg10TlDM2SRcaXWB YQ+kcm3GLiDiI3orZaMtHZeFKFvwlTz13U358vpceSpvxKGpkCIRAI8A6oToSx0U/JY5 fDKw2R5nSm/nP9iaPEbGeyEZ0O4ruf7xVbl8a/aoJsLY0CFEMaXNd8jKZIU5lKJFie/C rhy1Es8SQXt6q92qPDEM+YH4euyt2NWqxxio/jwMHF8ddaby4NGRsEv6GkJmV1tF1GV/ rKrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=AT63yAUmWQECqV/2J9PPg6kqSXv44Mdmz159NdQZx4M=; fh=n7M+986tA5DpTQGp5mO2bDlpQ+/NBtGm9vgndZuVRvo=; b=S/feq8XzkISxWW8Bjt4/sUrE/Y2GJjjTe8kgKMt8t1/UMpGwFe11hAeSPzmhWPGXB1 lpA3GCxcBBMA8njP2MIphT1Yv+rIV/gSEtpDEyjxrcu0aI1WljbOUPS1ZujfWGQcB3ub epBm4MRg8sNclkTjBEQWfBOPp5fMJFY8EhJ+si2whGI37/BEkSTWGjnC1kW9eHV0Rem8 h8UHuEv5peIr46aQeAKLO6hcbqDjhM6GRf+uBOMUTVuHCZiyc+fKX6rsea0+60gi6yjz K5qlx5zEbG1MTwHHUzXybGEYNgDyRu/gl09j3uK6VM8TcoCtCVnZAo0f9PfT7etmVELV OEow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GvWQ4xVs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57877-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXuem4EVMi7D6h/K/r1gQaBhf9vFrO2fN+GtwS+nnngnfPnehbTCaRrh26o2HMTCAds3vQri7VXGh+K6s9eD4zOw+2+Ehh0BH1x1502XQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ha6-20020a170906a88600b00a3816526e56si1884781ejb.984.2024.02.08.02.43.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 02:43:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GvWQ4xVs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57877-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57877-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 67B6B1F25C30 for ; Thu, 8 Feb 2024 10:43:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C94CF6A352; Thu, 8 Feb 2024 10:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GvWQ4xVs" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E48821DFF2; Thu, 8 Feb 2024 10:43:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707388994; cv=none; b=cHKo9pE/RfHHX8cUULhrGSOk2eugeqBDlS7ldtSrPcSrRSewrV3pxLXD8ycZpfM/+tZqfVCR5+vdIa8V7vHJhVQXtENH4lSmNjryqNIqNO+Yq4h703Ey85LatBRcjFjFIsnYUU4Y4pzyqScDrqiONWDENIPGgSFK76W/sIAVf20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707388994; c=relaxed/simple; bh=iOCEBde5YbT1K2IfyXz3DE1Ta6qmjsnHDk4nzvRYcvQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Tkd2ENWHFv8SK7iALgexbmR12cDcdyuPZOzPu+HEwWRwGbkD3U1UKHOzNBZbNrb/6wus69gAjmOxdXZev6dQXmCvIhJNfJWlQGG0qanZ/sBuYWvJcXXYlxm2VIwERB+KAynEp8iW4XxKx7Z4sQO0BTCnjF4o80IxuURTh11nLBI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GvWQ4xVs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4696C433C7; Thu, 8 Feb 2024 10:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707388993; bh=iOCEBde5YbT1K2IfyXz3DE1Ta6qmjsnHDk4nzvRYcvQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GvWQ4xVs30uQsyDRhy2StCPlc2GlE2b9LvsVXJuAqA8gD6xKbB/oZUQ8qhwMpsVUo Jlt9yShDwNJV0jhJ9i8tQmxFf3mmVOiVwukNgruEJicqQvXsI4+wr0Ob6bG6mpdtbD C0r/EzPqneVD4JLYc3Fd1u/Tfh3pRuQEt4Py+eh0tWi7MkD8ZStqYoRQ4DeNNYwytE T3pjpUxzsVoNGAQG/uE1htxE3OPnrUzMy6jbNJIEv/vrVsBZ847teXZRtbuonjupae KPZzCECiOJuyWIq7w6xYQko9u6lntV7OYWCSVvUM5mzmhUj7c0ghexxGEBfsQT3krR QYw83XHNUCm4w== Date: Thu, 8 Feb 2024 11:43:10 +0100 From: Frederic Weisbecker To: "Paul E. McKenney" Cc: Boqun Feng , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, linux-doc@vger.kernel.org, Chen Zhongjin , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Kent Overstreet , Andrew Morton , Heiko Carstens , Arnd Bergmann , Oleg Nesterov , Christian Brauner , Suren Baghdasaryan , Mike Christie , "Michael S. Tsirkin" , Mateusz Guzik , Nicholas Piggin , Peng Zhang Subject: Re: [PATCH 2/2] rcu-tasks: Eliminate deadlocks involving do_exit() and RCU tasks Message-ID: References: <20240129225730.3168681-1-boqun.feng@gmail.com> <20240129225730.3168681-3-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Feb 08, 2024 at 01:56:10AM -0800, Paul E. McKenney wrote: > On Thu, Feb 08, 2024 at 03:10:32AM +0100, Frederic Weisbecker wrote: > This ordering is not needed. The lock orders addition to this > list against removal from tasklist. If we hold this lock, either > the task is already on this list or our holding this lock prevents > it from removing itself from the tasklist. > > We have already scanned the task list, and we have already done > whatever update we are worried about. > > So, if the task was on the tasklist when we scanned, well and > good. If the task was created after we scanned the tasklist, > then it cannot possibly access whatever we removed. > > But please double-check!!! Heh, right, another new pattern for me to discover :-/ C r-LOCK { } P0(spinlock_t *LOCK, int *X, int *Y) { int r1; int r2; r1 = READ_ONCE(*X); spin_lock(LOCK); r2 = READ_ONCE(*Y); spin_unlock(LOCK); } P1(spinlock_t *LOCK, int *X, int *Y) { spin_lock(LOCK); WRITE_ONCE(*Y, 1); spin_unlock(LOCK); WRITE_ONCE(*X, 1); } exists (0:r1=1 /\ 0:r2=0) (* never *) > > > > synchronize_rcu_tasks() do_exit() > > > ---------------------- --------- > > > //for_each_process_thread() > > > READ tasklist WRITE rtpcp->rtp_exit_list > > > LOCK rtpcp->lock UNLOCK rtpcp->lock > > > smp_mb__after_unlock_lock() WRITE tasklist //unhash_process() > > > READ rtpcp->rtp_exit_list > > > > > > Does this work? Hmm, I'll play with litmus once I have a fresh brain... > > First, thank you very much for the review!!! > > > ie: does smp_mb__after_unlock_lock() order only what precedes the UNLOCK with > > the UNLOCK itself? (but then the UNLOCK itself can be reordered with anything > > that follows)? Or does it also order what follows the UNLOCK with the UNLOCK > > itself? If both, then it looks ok, otherwise... > > If you have this: > > earlier_accesses(); > spin_lock(...); > ill_considered_memory_accesses(); > smp_mb__after_unlock_lock(); > later_accesses(); > > Then earlier_accesses() will be ordered against later_accesses(), but > ill_considered_memory_accesses() won't necessarily be ordered. Also, > any accesses before any prior release of that same lock will be ordered > against later_accesses(). > > (In real life, ill_considered_memory_accesses() will be fully ordered > against either spin_lock() on the one hand or smp_mb__after_unlock_lock() > on the other, with x86 doing the first and PowerPC doing the second. > So please try to avoid any ill_considered_memory_accesses().) Thanks a lot for that explanation! > > > Also on the other end, does LOCK/smp_mb__after_unlock_lock() order against what > > precedes the LOCK? That also is necessary for the above to work. > > It looks like an smp_mb__after_spinlock() would also be needed, for > example, on ARMv8. > > > Of course by the time I'm writing this email, litmus would have told me > > already... > > ;-) ;-) ;-) > > But I believe that simple locking covers this case. Famous last words... Indeed, looks right! Thanks! > Thanx, Paul