Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp71872pxb; Tue, 21 Sep 2021 19:05:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxPGCHlNzbgaI67hmX/BdqLwIazhCKfcTQmE3JUKv8fbxZ6uW+UtfDvG0FnT+QYSV57b/Q X-Received: by 2002:a05:6e02:1a03:: with SMTP id s3mr24010132ild.156.1632276355535; Tue, 21 Sep 2021 19:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632276355; cv=none; d=google.com; s=arc-20160816; b=w1DRXZIZSkpRbMNUYPi4YEzOV+v3ypbQ6+Bo1xG/MCrQ4cflKcPz59ABUgLGkL8iMJ A4HUY+42d5WF2MB4FqM6Ydj8IvkzJKydB3WF/6/XTF0yJwj/VqRfM/sFLcC+1vi9jG0M RVeK7uo2WsodDFHGVdyU5xetPqUSzPz8c/Ft5cteM3E644Fwo7bHFB4gm7v804q++Tyc ey6SxWOEW5FgV2j3vTjeS4PJvZ07hj6W4s8xQRomyjSFhyXgz7hbSuRtT10MOhfjDu/5 RVSyIu9kqOKE386PMe3DBIy3oIx2jcmSTLnnFEFSjk+K/bEFJSZvQPjkYBbqya4PBXE8 FbXA== 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=S4MTVEoSSsbOjeQ1VlR8XV4rmUvF+oelzsRGNZiTV1s=; b=t4AF4rPQYt5Ec0Z/XKeHuy7sPQwAor5ZpRm4csymwoM6JG0Xfk9leAb4kQ05ikPIOJ UP03N0EUbkDzet/KCaGFW8hjfVYpDsDGuXMLEJ76v06dKP2M6oJjbBxSZR1cGZpTyEh4 x9inPks0f43cXPJtE+uAwljUi1FkRMWBpOhRKI9kJd8dPEev5VIabo1NEPt2z3/+LyrE v48UKOMzsJpm86cD0AfrAeiAQJVfxinyGTXxjXWC19CaQn68CVQoTJ3EYj8NDHxtpATB kmvlx+pS05ufI9Kwov7WOU+5yMKXkT4oXFDXllGSppLlt7OgpXbb1pgpVdaCv2vOwoq1 YjhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LFrEbKVQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 13si895795jan.43.2021.09.21.19.05.44; Tue, 21 Sep 2021 19:05:55 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LFrEbKVQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230478AbhIUXqu (ORCPT + 99 others); Tue, 21 Sep 2021 19:46:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:40514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229824AbhIUXqu (ORCPT ); Tue, 21 Sep 2021 19:46:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 73FB460F6D; Tue, 21 Sep 2021 23:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632267921; bh=4Bdk7t7Ff4sxxY+JAbnfv4+PRj6aM+D+XVagYS8TOp0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LFrEbKVQKJl47R1ka/rgx6b6MDMPN0zdxTWT50HGMGD8V7B3FQ4iZBqvyz7SAIy0E YfoXQNGfQvipOuROtu5wwEUgve5Wk0HLb7JBYekEFGpHA/tdnkdXKEyzGLNF51lwQ3 g9zdycLNbYgwUJZFgxzGv3wKDCwWZrS8iFnQgogx2238RiAfXz3azwCHiBfLgpKyZU P94utw1KHIZW3stUoWYDe/uJBX3l/VG5yf9X1TKiFqJDZcDLyytABkapFcypcUtPV1 x45rwCx7gP1Qs/+v75EXbl0HkS2RqnsdpbJ9+ziQnM2NE4JIlHZCcZ9ep4MAqkC3TV rR2zwqmzebsEw== Date: Wed, 22 Sep 2021 01:45:18 +0200 From: Frederic Weisbecker To: Thomas Gleixner Cc: Valentin Schneider , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rcu@vger.kernel.org, linux-rt-users@vger.kernel.org, Catalin Marinas , Will Deacon , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Daniel Bristot de Oliveira , Sebastian Andrzej Siewior , "Paul E. McKenney" , 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 Message-ID: <20210921234518.GB100318@lothringen> References: <20210811201354.1976839-1-valentin.schneider@arm.com> <20210811201354.1976839-4-valentin.schneider@arm.com> <874kae6n3g.ffs@tglx> <87pmt163al.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87pmt163al.ffs@tglx> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 21, 2021 at 11:12:50PM +0200, 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. Also while at it, I'm asking again: traditionally softirqs could assume that manipulating a local state was safe against !irq_count() code fiddling with the same state on the same CPU. Now with preemptible softirqs, that assumption can be broken anytime. RCU was fortunate enough to have a warning for that. But who knows how many issues like this are lurking? Thanks.