Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2760153pxb; Tue, 21 Sep 2021 07:07:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZW3sda/P9APgs/ZLZXaqHqqIVLWuFWkW1NHTSVITqRd10SFlVqrziK6hJwwK3iSW6kKL7 X-Received: by 2002:a17:906:4544:: with SMTP id s4mr34948778ejq.102.1632233258206; Tue, 21 Sep 2021 07:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632233258; cv=none; d=google.com; s=arc-20160816; b=ObFxTFtMi13Lk2CCTkgtXuj+7Ynip5dHVrP1n7VgSyBq8/lfG3qIcDcvMaJJ549s4C biX3keLEjAUw/8YxzH/p8CZZBX8Poq40naTHY5Z6wP+JBQ8ULiBdH0kE2XSmUjYEiyDg RPW8sFfbnFsc0lM/C/EMkNQPAF3KIm0nLerZ2VZENWp1sNoxzBoujagcky32Rf3Wl09d VGRriQQtSIWaCN5/IXp/zjCsJmWV0T0T/nxcDHVE8F6WbKyqMznphQycEahbbM20tSAw 77WRl81nQczhOYoHvsTIIEqPdKvcnrWvIkGqJx6trRC/34I0+UpznTHop2G0AfUzVlZm uYVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=iRZkhuB3q8eWn+Q+IH85cvsi1BXsI2A4fpszlFgTJUU=; b=YmYfhk73h6K5tilihX6K21bZXfguYGC/pBZ0LqNpZRGs6c/Wxr3zBh0YQ2Aa7AilJ2 uIEKPYLWDveYEGlMjJFKL0dpE8Pgadxe+kRu+GuiRXSf/JeSJkwVbTm8+Ndh/WO1y2XY qw4qTD5KrMpLfiCXmyxTHdkUubRu1ctOyeJqVKvn7GWKrI4Rufjenz3U2JTvuzAgxigN QTR+psl7/GiKLLCi5iV4b8hG/s2ZX916TSCtbbnp09iGSsUNfyYbcdok0yJ9JTQ+CGrN XDYRckgzG54nSjDlqZNyQ/KlwvopAjhyWFrZGGc0hhSlnUGBzdIynOQA3zJ0WtUik+bo RZBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fNNNVdBG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w18si20496300ejv.669.2021.09.21.07.07.09; Tue, 21 Sep 2021 07:07:38 -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=@linutronix.de header.s=2020 header.b=fNNNVdBG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233480AbhIUOGi (ORCPT + 99 others); Tue, 21 Sep 2021 10:06:38 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:48892 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233448AbhIUOGh (ORCPT ); Tue, 21 Sep 2021 10:06:37 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1632233107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iRZkhuB3q8eWn+Q+IH85cvsi1BXsI2A4fpszlFgTJUU=; b=fNNNVdBGg+ZulgR/yTyHw3OPyblYrJkTcS+WFxAIGwuHX+/NhHihA1O68bezkykOCH6+rP aj+KRbIMVXK9+xwWRlXdETmYdGguenGbIWi31gR4OhHxo2zW+2VEp/jQgT8VyWV58ThUGY si7riMahz8V4dyLV6FikLL9e5gU0JO/7nPfRKywDNfUYHNmY8BkYgTmFmZXM9V6pPpAT+Y Qm6ZDXbTrrKF4vLUdhquYJWlJEX7F+p6Frt7rEKWjvw8eh0QXWIY3OTObCyZTihXAz1tyv RQwBUaTe8Qiw5Wy3Hf1RylvujyscQHgWKWfIXwSOOj92v2GGSG5taAmDGHqtRg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1632233107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iRZkhuB3q8eWn+Q+IH85cvsi1BXsI2A4fpszlFgTJUU=; b=/92k433iTx4+5yQA3qLenYPKHol2U3cD80NQ9hfx8ufaAt0X5/KFSHo2ByKulagfN2n12I p3DTEu1QJXtWH+BQ== To: Valentin Schneider , 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: [PATCH v3 3/4] rcu/nocb: Protect NOCB state via local_lock() under PREEMPT_RT In-Reply-To: <20210811201354.1976839-4-valentin.schneider@arm.com> References: <20210811201354.1976839-1-valentin.schneider@arm.com> <20210811201354.1976839-4-valentin.schneider@arm.com> Date: Tue, 21 Sep 2021 16:05:07 +0200 Message-ID: <874kae6n3g.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Valentin, On Wed, Aug 11 2021 at 21:13, Valentin Schneider wrote: > Running v5.13-rt1 on my arm64 Juno board triggers: > > [ 0.156302] ============================= > [ 0.160416] WARNING: suspicious RCU usage > [ 0.172409] kernel/rcu/tree_plugin.h:69 Unsafe read of RCU_NOCB offloaded state! > [ 0.260328] rcu_rdp_is_offloaded (kernel/rcu/tree_plugin.h:69 kernel/rcu/tree_plugin.h:58) > [ 0.264537] rcu_core (kernel/rcu/tree.c:2332 kernel/rcu/tree.c:2398 kernel/rcu/tree.c:2777) > [ 0.267786] rcu_cpu_kthread (./include/linux/bottom_half.h:32 kernel/rcu/tree.c:2876) > > In this case, this is the RCU core kthread accessing the local CPU's > rdp. Before that, rcu_cpu_kthread() invokes local_bh_disable(). > > Under !CONFIG_PREEMPT_RT (and rcutree.use_softirq=0), this ends up > incrementing the preempt_count, which satisfies the "local non-preemptible > read" of rcu_rdp_is_offloaded(). > > Under CONFIG_PREEMPT_RT however, this becomes > > local_lock(&softirq_ctrl.lock) > > which, under the same config, is migrate_disable() + rt_spin_lock(). As > pointed out by Frederic, this is not sufficient to safely access an rdp's > offload state, as the RCU core kthread can be preempted by a kworker > executing rcu_nocb_rdp_offload() [1]. > > Introduce a local_lock to serialize an rdp's offload state while the rdp's > associated core kthread is executing rcu_core(). Yes, sure. But I don't think that local_lock is required at all. The point is that the two places where this actually matters invoke rcu_rdp_is_offloaded() just at the top of the function outside of the anyway existing protection sections. Moving it into the sections which already provide the required protections makes it just work for both RT and !RT. Thanks, tglx --- --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2278,13 +2278,13 @@ rcu_report_qs_rdp(struct rcu_data *rdp) { unsigned long flags; unsigned long mask; - bool needwake = false; - const bool offloaded = rcu_rdp_is_offloaded(rdp); + bool offloaded, needwake = false; struct rcu_node *rnp; WARN_ON_ONCE(rdp->cpu != smp_processor_id()); rnp = rdp->mynode; raw_spin_lock_irqsave_rcu_node(rnp, flags); + offloaded = rcu_rdp_is_offloaded(rdp); if (rdp->cpu_no_qs.b.norm || rdp->gp_seq != rnp->gp_seq || rdp->gpwrap) { @@ -2446,7 +2446,7 @@ static void rcu_do_batch(struct rcu_data int div; bool __maybe_unused empty; unsigned long flags; - const bool offloaded = rcu_rdp_is_offloaded(rdp); + bool offloaded; struct rcu_head *rhp; struct rcu_cblist rcl = RCU_CBLIST_INITIALIZER(rcl); long bl, count = 0; @@ -2472,6 +2472,7 @@ static void rcu_do_batch(struct rcu_data rcu_nocb_lock(rdp); WARN_ON_ONCE(cpu_is_offline(smp_processor_id())); pending = rcu_segcblist_n_cbs(&rdp->cblist); + offloaded = rcu_rdp_is_offloaded(rdp); div = READ_ONCE(rcu_divisor); div = div < 0 ? 7 : div > sizeof(long) * 8 - 2 ? sizeof(long) * 8 - 2 : div; bl = max(rdp->blimit, pending >> div);