Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1024567pxb; Wed, 29 Sep 2021 15:11:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoJUyDjmGFDraayZVzpDEjn/hoMXCwBTemNTDyJeiZq13B3yjDBXbedbF2wBQrbhNXpWQN X-Received: by 2002:a17:902:a50d:b0:13d:8d71:aa91 with SMTP id s13-20020a170902a50d00b0013d8d71aa91mr824323plq.24.1632953510013; Wed, 29 Sep 2021 15:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632953510; cv=none; d=google.com; s=arc-20160816; b=Han7b4kSBruBLTquLDXcGxu8ufxy25X0csbO+tUcnGsqat271YJFSC2Ql6xAJEtozq sQftnzOjIaRHGjLPuSBRz0Z32fscR2QVjNVRAQpGe8fR2n6bGy6y4YR4107aqpylfEAD yLn+nr3eginEneUvdGh0M1iolF6QI7Y73Pv9s6d1jWt+HVb2cgBIW/6E2nDafwscWQvY z3m72YWPBJ1SzTzPRsEqSyFBH3eWgQOxD8+gbjo4pt4iZLFyReqkxrIV0HbV7zrKqChP OnG6FqFwjaBrByaiylkf5tosDnxO3Y28ZWfHEU3LAkdzjdpmCaID5VwBcA1XusT3d+9J 9BPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=knq064uAEt3wRQNb8ypSAPKiZpig5gyIT0X51XMkOGk=; b=LcZT4hhOfZyUCOBIAvfJ0/713pU4DGjL7O4o1ZC3ly4AgoZJq5WW+tVKWBIO0873U+ /j1HfTCvVDrUF0319hBXWNTIhwl4sXBwQ+3SGUjUMkgTzHoqv0flroIP1Jy0eumAGO6o Hiwww5Z0ilADrOfdjzqAa/QyVBnFMVMAGIkGMb1uWilObvmwXHfV3RwSKQhtNDbVnQpz aeINNWEu7fiv6j+Hx4JZKIZYkqHpASqq+p0siejOfsciQyNVralL1qmg79s1DEklBpWH LHvv2J8A0fPARqFDWowAdK4DnUhSm54zLdPInvGcprYmSoWgvX2GKb9qxAgCa81YcOQJ UnSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DQwaSQvn; 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 n25si1326724pgb.414.2021.09.29.15.11.35; Wed, 29 Sep 2021 15:11:50 -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=DQwaSQvn; 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 S1347097AbhI2WMC (ORCPT + 99 others); Wed, 29 Sep 2021 18:12:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:60430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345332AbhI2WMC (ORCPT ); Wed, 29 Sep 2021 18:12:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6325461423; Wed, 29 Sep 2021 22:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632953420; bh=tWGx8AK8+DXnZ3HGoe4uLYBFj6XGvOZmZrpZv1xbMQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DQwaSQvn2b6wnBM2WY+7cFIPZ2uy9glAfzgxrZ9HY5X4TLzkc0dcG+DQWDIKaT5eU nNmX7FugxV+8ruPZCuJXn89jHLT5is1rTJku6SsadG9Odj1HPStKObd1OMTvffogPw wyhVTWTZ51ohv9GeCDa6e7mMmyMzzha74Tj41UJpBU+6G0Zo5J/K75dSA37FKXqqy2 sKPwO8PmSEprPk0EwHPQpf8Glrj4PJhf0IkUB4Q8FF8/WpBWIm57NadOX273T+ucS4 DEEWdHFaJj5m+sMy8sZdxs733tvKkkEzdAMzS+gbZpxoeFCnZK8jWF5Pdje+3Z/X5p uYYHWAXTzaTpQ== From: Frederic Weisbecker To: "Paul E . McKenney" Cc: LKML , Frederic Weisbecker , Sebastian Andrzej Siewior , Peter Zijlstra , Uladzislau Rezki , Valentin Schneider , Thomas Gleixner , Boqun Feng , Neeraj Upadhyay , Josh Triplett , Joel Fernandes , rcu@vger.kernel.org Subject: [PATCH 01/11] rcu/nocb: Make local rcu_nocb_lock_irqsave() safe against concurrent deoffloading Date: Thu, 30 Sep 2021 00:10:02 +0200 Message-Id: <20210929221012.228270-2-frederic@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210929221012.228270-1-frederic@kernel.org> References: <20210929221012.228270-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org rcu_nocb_lock_irqsave() can be preempted between the call to rcu_segcblist_is_offloaded() and the actual locking. This matters now that rcu_core() is preemptible on PREEMPT_RT and the (de-)offloading process can interrupt the softirq or the rcuc kthread. As a result we may locklessly call into code that requires nocb locking. In practice this is a problem while we accelerate callbacks on rcu_core(). Simply disabling interrupts before (instead of after) checking the NOCB offload state fixes the issue. Reported-by: Valentin Schneider Signed-off-by: Frederic Weisbecker Cc: Valentin Schneider Cc: Peter Zijlstra Cc: Sebastian Andrzej Siewior Cc: Josh Triplett Cc: Joel Fernandes Cc: Boqun Feng Cc: Neeraj Upadhyay Cc: Uladzislau Rezki Cc: Thomas Gleixner --- kernel/rcu/tree.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index 70188cb42473..deeaf2fee714 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h @@ -439,12 +439,16 @@ static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp, static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp); #ifdef CONFIG_RCU_NOCB_CPU static void __init rcu_organize_nocb_kthreads(void); -#define rcu_nocb_lock_irqsave(rdp, flags) \ -do { \ - if (!rcu_segcblist_is_offloaded(&(rdp)->cblist)) \ - local_irq_save(flags); \ - else \ - raw_spin_lock_irqsave(&(rdp)->nocb_lock, (flags)); \ + +/* + * Disable IRQs before checking offloaded state so that local + * locking is safe against concurrent de-offloading. + */ +#define rcu_nocb_lock_irqsave(rdp, flags) \ +do { \ + local_irq_save(flags); \ + if (rcu_segcblist_is_offloaded(&(rdp)->cblist)) \ + raw_spin_lock(&(rdp)->nocb_lock); \ } while (0) #else /* #ifdef CONFIG_RCU_NOCB_CPU */ #define rcu_nocb_lock_irqsave(rdp, flags) local_irq_save(flags) -- 2.25.1