From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B90C2288F4; Mon, 2 Jun 2025 15:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748877186; cv=none; b=rf4++g/+gYiIWT2rOZYjyrl4lYK6gfYA3WC4pxtCon2yP3xkH8NMFFVcyKjPbWJnd/6p1j4MsIG3KEbQbEXP7r6a/5X09g19nIwaLA7lFAw4feqZf2pNhFRQAzTvqg4X9tF5fpdWR4upMNh79YivZfrIdfgc3B1a0ekY6NHaBWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748877186; c=relaxed/simple; bh=hqD8W35mI7adY4b3WAL4QDxeB0fWMnRZQKlUmaIeuuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mIE788eeHeQFaMFL4lyIJvPcUswlylUPHT7DSTJk4HwXII7ewNTcCRxL9i/cOptljyZVWQ+QhETDREhGxgFhTRny47XIWvkdujp2bYm5Uyszn4qjYKe9fIcOzNlV8wRUEIoAj/EXDS1uke1/K+id5ajgeKXjpqKJRFQZMRvVrkw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ADQEKRdN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ADQEKRdN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28E9DC4CEEB; Mon, 2 Jun 2025 15:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748877185; bh=hqD8W35mI7adY4b3WAL4QDxeB0fWMnRZQKlUmaIeuuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ADQEKRdNzl5zfichsvtuFevg5ZhqcLSzQm0g1YZV8R7i52WDowCXt8fmh7xeA768w SB+/0w9HRlHF6z4DCa9AtO0Qsfj54xVO1tdp/pUdNxHwbrbPkVGuLgRM8bW2B4tq9a BDi1wGqU3nit2zW+1zLt+KXj/K+wQLDwPwkmCMjM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Frederic Weisbecker , Ankur Arora , "Paul E. McKenney" , Boqun Feng , Sasha Levin Subject: [PATCH 6.1 198/325] rcu: handle unstable rdp in rcu_read_unlock_strict() Date: Mon, 2 Jun 2025 15:47:54 +0200 Message-ID: <20250602134327.842620567@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134319.723650984@linuxfoundation.org> References: <20250602134319.723650984@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ankur Arora [ Upstream commit fcf0e25ad4c8d14d2faab4d9a17040f31efce205 ] rcu_read_unlock_strict() can be called with preemption enabled which can make for an unstable rdp and a racy norm value. Fix this by dropping the preempt-count in __rcu_read_unlock() after the call to rcu_read_unlock_strict(), adjusting the preempt-count check appropriately. Suggested-by: Frederic Weisbecker Signed-off-by: Ankur Arora Reviewed-by: Frederic Weisbecker Signed-off-by: Paul E. McKenney Signed-off-by: Boqun Feng Signed-off-by: Sasha Levin --- include/linux/rcupdate.h | 2 +- kernel/rcu/tree_plugin.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index aef8c7304d45d..d1c35009831b6 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -97,9 +97,9 @@ static inline void __rcu_read_lock(void) static inline void __rcu_read_unlock(void) { - preempt_enable(); if (IS_ENABLED(CONFIG_RCU_STRICT_GRACE_PERIOD)) rcu_read_unlock_strict(); + preempt_enable(); } static inline int rcu_preempt_depth(void) diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 4f45562be7b54..3929ef8148c10 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -821,8 +821,17 @@ void rcu_read_unlock_strict(void) { struct rcu_data *rdp; - if (irqs_disabled() || preempt_count() || !rcu_state.gp_kthread) + if (irqs_disabled() || in_atomic_preempt_off() || !rcu_state.gp_kthread) return; + + /* + * rcu_report_qs_rdp() can only be invoked with a stable rdp and + * from the local CPU. + * + * The in_atomic_preempt_off() check ensures that we come here holding + * the last preempt_count (which will get dropped once we return to + * __rcu_read_unlock(). + */ rdp = this_cpu_ptr(&rcu_data); rdp->cpu_no_qs.b.norm = false; rcu_report_qs_rdp(rdp); -- 2.39.5