Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp104894pxb; Thu, 30 Sep 2021 02:04:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq5n/G2RjRNot/vK9Newo6gK2zlTs3KCkUq9Bs8KrXE2PvckTT33P0uDuPPYB6pepBkF/p X-Received: by 2002:a17:902:bd45:b0:13d:b4d1:eb39 with SMTP id b5-20020a170902bd4500b0013db4d1eb39mr3237631plx.53.1632992649306; Thu, 30 Sep 2021 02:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632992649; cv=none; d=google.com; s=arc-20160816; b=oKt3cl3TMxlh5NTMRZs6h1GQbcCe4Fl0q8AXbkAgxZR01vbB7G0/MLfuYvZ40STwrz SBjXlOou4TAFIAEbLtF+uLYJtqR2y3ikEjAx7NrFJ/R95biyxm/PYPOhVB7k61YkeMZA p/D5YBacz9m0sRbANYlK7TwcuoRv05/EBnUD0bqwOE/0K9omSF35NE9qoDXl9hMFsckN jgbpw7Z7dBxgX9Sc0drIqifU+PtxQY9trCe7xa1U623Nre/tcXQyE4OTy2q+qbPCXzZX +Z2soOrGfUkHwx5Af/WJ/ffYWgTAsquOsjpAHJ7n9je2dwGjdVlfpaGTJT654mdmhovO CRGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:mime-version :in-reply-to:subject:cc:to:from; bh=v3tAg+elc8J85XscwFD1gN2GFap9DnFD7Pt8vIMY12Q=; b=VgVw8LEzgNn8s0ioTxI/X9t/u/4NNRlvrdUDvCW5s8ZTpnQBNhljoTqlHG1XliE5rR k6UHMluu+Fn4JH3cSCcVe92bEOvxs7KuaWaO12y2Nsb6i2exfRrr5RVCS2/OPkXOiRUq LE1fZxOtZ5o2z/+/CXk567xyIk5LTGWAAxBTuWowp9cwqNPTapOEDDtTGgF+xN/DCUhG g12ZvzA7u/nYN8IRo51vQJU4wtBf/LKQRqx3EMVyanVc8eviAYObuZELm23cqqkR24CX Yy2JW42/u8hGq/Kc3EkegMGs1RTbgZ9uCHdvxs7MDmdCEsFDxyfdbkp9Im7XUz2/3Mqc yINg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y185si2550014pgd.304.2021.09.30.02.03.51; Thu, 30 Sep 2021 02:04:09 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348217AbhI3JCe (ORCPT + 99 others); Thu, 30 Sep 2021 05:02:34 -0400 Received: from foss.arm.com ([217.140.110.172]:50766 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348335AbhI3JCd (ORCPT ); Thu, 30 Sep 2021 05:02:33 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0AF56D6E; Thu, 30 Sep 2021 02:00:51 -0700 (PDT) Received: from e113632-lin (e113632-lin.cambridge.arm.com [10.1.196.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 084F13F793; Thu, 30 Sep 2021 02:00:47 -0700 (PDT) From: Valentin Schneider To: Thomas Gleixner , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rcu@vger.kernel.org, linux-rt-users@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Daniel Bristot de Oliveira , Sebastian Andrzej Siewior , "Paul E. McKenney" , Frederic Weisbecker , Josh Triplett , Mathieu Desnoyers , Davidlohr Bueso , Lai Jiangshan , Joel Fernandes , Anshuman Khandual , Vincenzo Frascino , Steven Price , Ard Biesheuvel , Boqun Feng , Mike Galbraith Subject: Re: rcu/tree: Protect rcu_rdp_is_offloaded() invocations on RT In-Reply-To: <87pmt163al.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain References: <20210811201354.1976839-1-valentin.schneider@arm.com> <20210811201354.1976839-4-valentin.schneider@arm.com> <874kae6n3g.ffs@tglx> <87pmt163al.ffs@tglx> Date: Thu, 30 Sep 2021 10:00:39 +0100 Message-ID: <87h7e21lqg.mognet@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 21/09/21 23:12, Thomas Gleixner wrote: > Valentin reported warnings about suspicious RCU usage on RT kernels. Those > happen when offloading of RCU callbacks is enabled: > > WARNING: suspicious RCU usage > 5.13.0-rt1 #20 Not tainted > ----------------------------- > kernel/rcu/tree_plugin.h:69 Unsafe read of RCU_NOCB offloaded state! > > rcu_rdp_is_offloaded (kernel/rcu/tree_plugin.h:69 kernel/rcu/tree_plugin.h:58) > rcu_core (kernel/rcu/tree.c:2332 kernel/rcu/tree.c:2398 kernel/rcu/tree.c:2777) > rcu_cpu_kthread (./include/linux/bottom_half.h:32 kernel/rcu/tree.c:2876) > > The reason is that rcu_rdp_is_offloaded() is invoked without one of the > required protections on RT enabled kernels because local_bh_disable() does > not disable preemption on RT. > > Valentin proposed to add a local lock to the code in question, but that's > suboptimal in several aspects: > > 1) local locks add extra code to !RT kernels for no value. > > 2) All possible callsites have to audited and amended when affected > possible at an outer function level due to lock nesting issues. > > 3) As the local lock has to be taken at the outer functions it's required > to release and reacquire them in the inner code sections which might > voluntary schedule, e.g. rcu_do_batch(). > > Both callsites of rcu_rdp_is_offloaded() which trigger this check invoke > rcu_rdp_is_offloaded() in the variable declaration section right at the top > of the functions. But the actual usage of the result is either within a > section which provides the required protections or after such a section. > > So the obvious solution is to move the invocation into the code sections > which provide the proper protections, which solves the problem for RT and > does not have any impact on !RT kernels. > Thanks for taking a look at this! My reasoning for adding protection in the outer functions was to prevent impaired unlocks of rcu_nocb_{un}lock_irqsave(), as that too depends on the offload state. Cf. Frederic's writeup: http://lore.kernel.org/r/20210727230814.GC283787@lothringen Anywho, I see Frederic has sent a fancy new series, let me go stare at it.