Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1340714pxp; Thu, 10 Mar 2022 03:42:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwO5yB78Q2cWOR3IEnWU+ej4kO4VoMR2dhDKZI7xhUhYOYo9iDtPEYNK/bIDXM5JLKC9Ftp X-Received: by 2002:a17:902:bb10:b0:153:204b:1f1a with SMTP id im16-20020a170902bb1000b00153204b1f1amr2298259plb.16.1646912550221; Thu, 10 Mar 2022 03:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646912550; cv=none; d=google.com; s=arc-20160816; b=eLYmunH/K6HygL2Q1xBDCSUn1jFRzwgVgleGoxcQoZ2QKwxppvymStVKEfTQijqyNJ 2OFnoK7Lr9iuDT6DnYol7afZQBKOoKpCkxGgIDdZiB8XQ11FoIO91NgqO5mCT37X+/mS MhwjNDTg0TT95LEvJLWmzB7vcf1e058Itc+xQxQabdbwomMyBo+42Cxay5LsYDRyoxCI lFLQYbWwy7vTV7SNhP37lwVCLeRYonFoEK/leBHb6Jmw7MvDnLMMYgdHBC5J3g5dPVLH Wbi+t1Vcsg3ggWl/D0pdlpxon7A7w9rIVvyW/0jwOxN27o2MiFWLZhcQW8m9jHa8gtja Ta+A== 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=7CNkExPZGr37ETx08CFw0OJRaskcsi0wkihRq0QBeX8=; b=N90FIf0MFx2N72EdWUCypvn4z92433L32PP+c6UfOps+D5y4YJCxNGZryXG5uMYbHg I9f2DxWzRAeQmerElHLyUWFTE+aO9sKfilIUkRw6UtmH5rG9cBSniavXS4Gr1lqggnqg pdx5ouyWqDMvWov5O53nTiybBRI6cb/0GWe3LgtmyMOCRe9f7nJVx5K6aEhsqnyXYQLn 9nTqmYTIwH0xqqonaMBum3sylto603jHnKvQN5S85/vtsB5S/XF33fP1uxFlq7bRbkeP 56EJEX9SMZMDsji5P9uzDU5dmNLPinNYpm1IMCVPPY0kiFjymQTYSdwdgR8wozVaVZnn 0Mmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eFOdIQsQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a635c05000000b003789365a66fsi4406196pgb.127.2022.03.10.03.42.13; Thu, 10 Mar 2022 03:42:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=eFOdIQsQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240468AbiCJIqh (ORCPT + 99 others); Thu, 10 Mar 2022 03:46:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231738AbiCJIqg (ORCPT ); Thu, 10 Mar 2022 03:46:36 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2892C8189A for ; Thu, 10 Mar 2022 00:45:34 -0800 (PST) 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=7CNkExPZGr37ETx08CFw0OJRaskcsi0wkihRq0QBeX8=; b=eFOdIQsQ4S7hjurF+puepjPscW lpDc504LNqvHSPzx2aDl/wKyQcYqlglZW0P1cMhzBuAQpj3YB74QO0NY6yF6pnJjNuSj5i+VIB645 9hv1FHIn2hu+JbtB5+RK4bGENiIg2Cuxnfx89jJJjcG5MtlEkPIG9UUGObtpOhlh1ifB0zAr2RuMm GgwTT5vKYqGKOP5qrM8tu3nFfunT4nDSvDXsmkUTauwJLpI54OLYGTaIGpTVuYfZ+rjTg0BtVgaYN o2C3JK2yGrpttn7yxUZ6JYjpBmJRffyXq3zADCxkC4w9t0ikhI5RZDPycehdlqP/u3X+LnjillSJ8 BDhu9qAw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSEQC-000Lwu-ID; Thu, 10 Mar 2022 08:45:20 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 3E1403000E6; Thu, 10 Mar 2022 09:45:17 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B7BEF201699FB; Thu, 10 Mar 2022 09:45:17 +0100 (CET) Date: Thu, 10 Mar 2022 09:45:17 +0100 From: Peter Zijlstra To: "Paul E. McKenney" Cc: Marek Szyprowski , Chengming Zhou , mingo@redhat.com, vincent.guittot@linaro.org, bristot@redhat.com, zhaolei@cn.fujitsu.com, tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/3] sched/cpuacct: optimize away RCU read lock Message-ID: References: <20220220051426.5274-1-zhouchengming@bytedance.com> <20220220051426.5274-2-zhouchengming@bytedance.com> <20220308234403.GC4285@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220308234403.GC4285@paulmck-ThinkPad-P17-Gen-1> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 08, 2022 at 03:44:03PM -0800, Paul E. McKenney wrote: > On Wed, Mar 09, 2022 at 12:32:25AM +0100, Peter Zijlstra wrote: > > On Wed, Mar 09, 2022 at 12:20:33AM +0100, Marek Szyprowski wrote: > > > On 20.02.2022 06:14, Chengming Zhou wrote: > > > > Since cpuacct_charge() is called from the scheduler update_curr(), > > > > we must already have rq lock held, then the RCU read lock can > > > > be optimized away. > > > > > > > > And do the same thing in it's wrapper cgroup_account_cputime(), > > > > but we can't use lockdep_assert_rq_held() there, which defined > > > > in kernel/sched/sched.h. > > > > > > > > Suggested-by: Peter Zijlstra (Intel) > > > > Signed-off-by: Chengming Zhou > > > > > > This patch landed recently in linux-next as commit dc6e0818bc9a > > > ("sched/cpuacct: Optimize away RCU read lock"). On my test systems I > > > found that it triggers a following warning in the early boot stage: > > > > > > Calibrating delay loop (skipped), value calculated using timer > > > frequency.. 48.00 BogoMIPS (lpj=240000) > > > pid_max: default: 32768 minimum: 301 > > > Mount-cache hash table entries: 2048 (order: 1, 8192 bytes, linear) > > > Mountpoint-cache hash table entries: 2048 (order: 1, 8192 bytes, linear) > > > CPU: Testing write buffer coherency: ok > > > CPU0: Spectre v2: using BPIALL workaround > > > > > > ============================= > > > WARNING: suspicious RCU usage > > > 5.17.0-rc5-00050-gdc6e0818bc9a #11458 Not tainted > > > ----------------------------- > > > ./include/linux/cgroup.h:481 suspicious rcu_dereference_check() usage! > > > > Arguably, with the flavours folded again, rcu_dereference_check() ought > > to default include rcu_read_lock_sched_held() or its equivalent I > > suppose. > > > > Paul? > > That would reduce the number of warnings, but it also would hide bugs. > > So, are you sure you really want this? I don't understand... Since the flavours got merged regular RCU has it's quescent state held off by preempt_disable. So how can relying on that cause bugs? And if we can rely on that, then surely rcu_dereferenced_check() ought to play by the same rules, otherwise we get silly warnings like these at hand. Specifically, we removed the rcu_read_lock() here because this has rq->lock held, which is a raw_spinlock_t which very much implies preempt disable, on top of that, it's also an IRQ-safe lock and thus IRQs will be disabled. There is no possible way for RCU to make progress.