Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp429534rdb; Tue, 31 Oct 2023 11:12:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsmWcw8MBgE827NRSgZvZZcn5X3jUu9aVLbVvDwSQpdxxcnsPHbXVFNajFDdrkOBZgp6W1 X-Received: by 2002:a05:6a00:1a8a:b0:690:cae9:714d with SMTP id e10-20020a056a001a8a00b00690cae9714dmr12057398pfv.13.1698775938412; Tue, 31 Oct 2023 11:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698775938; cv=none; d=google.com; s=arc-20160816; b=kCJCZ3K7JR+FbpexKR1gO6KxoSjfA9qqWWiizVwLuQKhCRSbKuf+SV+pdhbAWt08ew UEm+7UXh3GNPspxQVQQCiS5EVISAGw+akYncUbprEoo5iKB16KavVMFG3rPrLY6rLDn6 Z9r0bkAu/Z4HMyl9/P8DuvcoPXr1SRm3Kj7PgHoWpMQVD6elI/l6amkU5+xX5/4QJpIH ASohcn4LZaqFGoxIMp46hHdx8jcWGWTUqRnVZad2yckAlyp/SNO9Gxr8sDk5j96lCs9s P3GjBJiS1LlI2o2LRt663OqZItsZXvY+ps8exf3h2/taZmwOHg53z+eYa5pSWZsc5qs9 qqqg== 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=ToEsUawdI7h60M3UjL5+D8c5IuaVptj7OG2wK3Uwwx4=; fh=Rs16LuufoQtzCKmxxOASBKqYE6s2CLWklA42Op3YiY8=; b=AQVB0MRtb3QiKIyDEqbtV1z5gf9RTjyiu+2OjYuGMn1hcaz0JG7x4SUBL9zE1EX/6y /sKxWDHpksRpPpt2MO5ddKglSdggcxxzjsVTaqYJxkZ/4sgmn3fEBm+oXvpODQLMLX49 5GE48OuUsGzG97WXaN5KMUw/0e+50IQd3DACsJyaKLh/3NoFA0TmDhtYLkzBiKENnIKr VOfSSbcaCSAXv1YZqqQUjf8xDZVADk7js7pqx4r27CS9msA18uu1SMllIEd3xdeg5Lgm jTLs76P7sNxBDSBnpCOChRl/0OT6WvV84fVm0E93Yyt/qk7lyD8f0rEk9sPbeTKvUKB3 IdRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m1gSkGf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id y11-20020a62ce0b000000b0068fc9557cddsi1273636pfg.81.2023.10.31.11.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 11:12:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m1gSkGf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1E4D38030E4C; Tue, 31 Oct 2023 11:12:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376616AbjJaSMH (ORCPT + 99 others); Tue, 31 Oct 2023 14:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjJaSMG (ORCPT ); Tue, 31 Oct 2023 14:12:06 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B441DA2; Tue, 31 Oct 2023 11:12:02 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43F2FC433C8; Tue, 31 Oct 2023 18:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698775922; bh=9Jf3KU3ADv1NIFoN1APkqO365A/HCOvTo+JR2JcocMY=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=m1gSkGf+mN9nCYslCyx8aeuQNeOTNjEp13rhkxSfnXOxiAlTZpNI+17No1M4HTmSr 1VDU1rskOdb2pb/n57E2y4O9KHsS4gLtIjifqOj3cPkRgVljsY0MRgQM0MQmRkClF1 4ohlthrUN+MFeDQH9ZBmwxBzPdsuCaku+dM1CeY4Bk5/wZpsxpFTKWYu5SJdC+2mf5 UP9F/ua0/3jY80iNpM7ImM7kHKoqg2Nwe7yJKJmAf68TAvXcYjavDdSaKw+ykncFLy hEZjc+Klg0lZoDBhTLyzXCHM5g/wyWBPgoudZp0T0AlEAIbgj5SBbMmG7w7dN5E7wO sEPfk7YalbQtQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id C9039CE0B77; Tue, 31 Oct 2023 11:12:01 -0700 (PDT) Date: Tue, 31 Oct 2023 11:12:01 -0700 From: "Paul E. McKenney" To: Peter Zijlstra 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: Reply-To: paulmck@kernel.org References: <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> <20231031095202.GC35651@noisy.programming.kicks-ass.net> <58c82a9d-f796-4585-b392-401b8b9dbc2e@paulmck-laptop> <20231031152033.GC15024@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231031152033.GC15024@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 agentk.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 (agentk.vger.email [0.0.0.0]); Tue, 31 Oct 2023 11:12:16 -0700 (PDT) On Tue, Oct 31, 2023 at 04:20:33PM +0100, Peter Zijlstra wrote: > On Tue, Oct 31, 2023 at 07:24:13AM -0700, Paul E. McKenney wrote: > > > So, at least until GCC catches up to clang's code generation, I take it > > that you don't want WRITE_ONCE() for that ->nvcsw increment. Thoughts on > > ->on_rq? > > I've not done the patch yet, but I suspect those would be fine, those > are straight up stores, hard to get wrong (famous last words). Assuming that the reads are already either marked with READ_ONCE() or are under appropriate locks, my immediate thought would be something like the all-too-lightly tested patch shown below. The ASSERT_EXCLUSIVE_WRITER() causes KCSAN to complain if there is a concurrent store of any kind to the location. Of course, please feel free to ignore. Thoughts? Thanx, Paul ------------------------------------------------------------------------ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 81885748871d..aeace19ad7f5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2124,12 +2124,14 @@ void activate_task(struct rq *rq, struct task_struct *p, int flags) enqueue_task(rq, p, flags); - p->on_rq = TASK_ON_RQ_QUEUED; + WRITE_ONCE(p->on_rq, TASK_ON_RQ_QUEUED); + ASSERT_EXCLUSIVE_WRITER(p->on_rq); } void deactivate_task(struct rq *rq, struct task_struct *p, int flags) { - p->on_rq = (flags & DEQUEUE_SLEEP) ? 0 : TASK_ON_RQ_MIGRATING; + WRITE_ONCE(p->on_rq, (flags & DEQUEUE_SLEEP) ? 0 : TASK_ON_RQ_MIGRATING); + ASSERT_EXCLUSIVE_WRITER(p->on_rq); dequeue_task(rq, p, flags); }