Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp126799rdb; Tue, 31 Oct 2023 02:54:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHwqs36X+0bfbbBq3Wj69HTAFDnZ6g6YRkozfwG0Uzg6dJSUrkhtSgk5PIukOYUInwDQ5ml X-Received: by 2002:a17:90a:7c06:b0:271:7cd6:165d with SMTP id v6-20020a17090a7c0600b002717cd6165dmr9239970pjf.26.1698746051325; Tue, 31 Oct 2023 02:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698746051; cv=none; d=google.com; s=arc-20160816; b=JgWKssCEPy8qCtYu0I6GHDyYhbHbUbg3w3J/0lZukfv7Be0RABA4FG0iHh4F2NCuK3 X9Q9AevyIWeWKa9b1B6FKy6sGkaVVmXK7zvrwCeqgpPcth3oTMKyogYHFXE278CBa7QH 06ibFUpidb6t22rgXcjEz8VYbwUmeLgn4MmQ87RhHkJ7ZzuKfT3bRnCbKjSVrzgjTm2M e60o6GAyEGS95VHAUZ0ZR+WRfjBbDcnMX2DpIYRBxc6bRY4CdVUwkGxdfyiEjX2w6r9f WzbQb7lkb4DRPo2kzRzYwRRQ/Teqo9AvZhdgKdaTnL4oHWE2/fdhODMiEITYlMgQQq0i xgJA== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=SMnW6LLGoJq+fLU8MEPf/OmYOwMGfrA7QSf+sFamhaQ=; fh=ZUgu6LhcX34GyGXnd2mEA4J/V9jNCNf27fY36hzyG3w=; b=JYQYoaPry6MKz2EV1QR7EqUsK6oiw+SaD1mRdePnvpDBddVmQakV18qfa8cIuZCDdO baCAPgWnT4nJFa478RfDSvGlMsGgisHgTeyFkYhtbQbIUIjtPny0gGz0y1QQiURDUqNd JnFXhwEGsb9zAQo3wDYm2xv5So0pSDabK2+duEYUcjCxeW9iRIjXMnyR88p1dFjfZPXM QYRdN3SPzpkHpNQrhMnUDw3hfbd7f8ZsD55tAeTVKWb3yTDpUmxlD8OezHBNlzoJIUOe SvQbk3E1tJFvYVO6xnkoGTGogf27GbrnHmx/1wCtqhcRIEjWu0E7+Ouo3AXY+NxQRwWW EqXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LKnHCAJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s22-20020a17090aa11600b0027b15e572c2si737759pjp.21.2023.10.31.02.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 02:54:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=LKnHCAJN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E98B98032A21; Tue, 31 Oct 2023 02:54:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235339AbjJaJxw (ORCPT + 99 others); Tue, 31 Oct 2023 05:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235897AbjJaJxh (ORCPT ); Tue, 31 Oct 2023 05:53:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C43410DC; Tue, 31 Oct 2023 02:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SMnW6LLGoJq+fLU8MEPf/OmYOwMGfrA7QSf+sFamhaQ=; b=LKnHCAJNLH6E9QwOtbTVjIEISx /7BJUA9U4ChcN5ti/l+2DOxKwPyt199/w0Pq1t9pCzpvpvCFMWowUgUMlGEcgGoPGqG6hYwUb5BiL Q/brDqVQW13U8kgfFTdmdoPK8JwwJAKiVKJ3JqKdK0HAGD+fvW58Zeg+/0UDmR1q7TO+RAQI74acc 1PQnRYn3ObNHTNj8EJr6S9N0JEoh/x5VPkGOpIL+RFPj2eyFDoYM/xqOhclM1EmRDUDpJiYgJ35DT xchJEI0LQWkNJRLPG672DGTRu5LLnnpMG+mbmOsNDkV833ZaDmJXo5B+iS/8PwQrdRFfiPJrHkeB6 0xpalEVQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qxlPm-009SnL-Gt; Tue, 31 Oct 2023 09:52:02 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 2CB82300473; Tue, 31 Oct 2023 10:52:02 +0100 (CET) Date: Tue, 31 Oct 2023 10:52:02 +0100 From: Peter Zijlstra To: "Paul E. McKenney" Cc: Frederic Weisbecker , LKML , Boqun Feng , Joel Fernandes , Josh Triplett , Mathieu Desnoyers , Neeraj Upadhyay , Steven Rostedt , Uladzislau Rezki , rcu , Zqiang , "Liam R . Howlett" , matz@suse.de, ubizjak@gmail.com Subject: Re: [PATCH 2/4] rcu/tasks: Handle new PF_IDLE semantics Message-ID: <20231031095202.GC35651@noisy.programming.kicks-ass.net> References: <20231027144050.110601-1-frederic@kernel.org> <20231027144050.110601-3-frederic@kernel.org> <20231027192026.GG26550@noisy.programming.kicks-ass.net> <2a0d52a5-5c28-498a-8df7-789f020e36ed@paulmck-laptop> <20231027224628.GI26550@noisy.programming.kicks-ass.net> <200c57ce-90a7-418b-9527-602dbf64231f@paulmck-laptop> <20231030082138.GJ26550@noisy.programming.kicks-ass.net> <622438a5-4d20-4bc9-86b9-f3de55ca6cda@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <622438a5-4d20-4bc9-86b9-f3de55ca6cda@paulmck-laptop> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 31 Oct 2023 02:54:09 -0700 (PDT) On Mon, Oct 30, 2023 at 01:11:41PM -0700, Paul E. McKenney wrote: > On Mon, Oct 30, 2023 at 09:21:38AM +0100, Peter Zijlstra wrote: > > On Fri, Oct 27, 2023 at 04:41:30PM -0700, Paul E. McKenney wrote: > > > On Sat, Oct 28, 2023 at 12:46:28AM +0200, Peter Zijlstra wrote: > > > > > > Nah, this is more or less what I feared. I just worry people will come > > > > around and put WRITE_ONCE() on the other end. I don't think that'll buy > > > > us much. Nor do I think the current READ_ONCE()s actually matter. > > > > > > My friend, you trust compilers more than I ever will. ;-) > > > > Well, we only use the values {0,1,2}, that's contained in the first > > byte. Are we saying compiler will not only byte-split but also > > bit-split the loads? > > > > But again, lacking the WRITE_ONCE() counterpart, this READ_ONCE() isn't > > getting you anything, and if you really worried about it, shouldn't you > > have proposed a patch making it all WRITE_ONCE() back when you did this > > tasks-rcu stuff? > > There are not all that many of them. If such a WRITE_ONCE() patch would > be welcome, I would be happy to put it together. > > > > > But perhaps put a comment there, that we don't care for the races and > > > > only need to observe a 0 once or something. > > > > > > There are these two passagers in the big lock comment preceding the > > > RCU Tasks code: > > > > > // rcu_tasks_pregp_step(): > > > // Invokes synchronize_rcu() in order to wait for all in-flight > > > // t->on_rq and t->nvcsw transitions to complete. This works because > > > // all such transitions are carried out with interrupts disabled. > > > > > Does that suffice, or should we add more? > > > > Probably sufficient. If one were to have used the search option :-) > > > > Anyway, this brings me to nvcsw, exact same problem there, except > > possibly worse, because now we actually do care about the full word. > > > > No WRITE_ONCE() write side, so the READ_ONCE() don't help against > > store-tearing (however unlikely that actually is in this case). > > Again, if such a WRITE_ONCE() patch would be welcome, I would be happy > to put it together. Welcome is not the right word. What bugs me most is that this was never raised when this code was written :/ Mostly my problem is that GCC generates such utter shite when you mention volatile. See, the below patch changes the perfectly fine and non-broken: 0148 1d8: 49 83 06 01 addq $0x1,(%r14) into: 0148 1d8: 49 8b 06 mov (%r14),%rax 014b 1db: 48 83 c0 01 add $0x1,%rax 014f 1df: 49 89 06 mov %rax,(%r14) For absolutely no reason :-( At least clang doesn't do this, it stays: 0403 413: 49 ff 45 00 incq 0x0(%r13) irrespective of the volatile. --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 802551e0009b..d616211b9151 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6575,8 +6575,8 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf) */ static void __sched notrace __schedule(unsigned int sched_mode) { struct task_struct *prev, *next; - unsigned long *switch_count; + volatile unsigned long *switch_count; unsigned long prev_state; struct rq_flags rf; struct rq *rq;