From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 DF7853DE44B for ; Tue, 25 Aug 2026 09:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787649778; cv=none; b=eRM7QyNeqimtd3wuua0R/IiBusrxLsOA/nuWYTTziVnl1kyZxdWAE4XO34hJoEaLKJqsZSTFPBTBmxTZJjylm8R9DoCL159HZALH+d96a3MNH4EU1xAwQsuixaGTNvLb/44grqyr00/wyEBO9C5OiLMrQO4sOabdcYXcnBKKcPQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787649778; c=relaxed/simple; bh=HG/mRHDj4OgnG4di+5IVO98ZXpCPtSdJQvsNxE83OJc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pdciVK9x7QgYxoRdIHwVYXAB61Wj4Dtc3fxH7aO0nZRPet8W8a3i8BHYZsyNnjHPe6FE9IRyDv0kXe2YS8fOO9ed5G/wbSdbcTS6pyxmMWnfhyPDLznDZRiLbNYndbMh9YYr05mBP6hgysmVm9a5TbLVQcZFyhsST9w6q/Ory10= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=fsmCc1h6; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fsmCc1h6" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=H3EiQ/OgDZ/+STLySPmuezv8zJCKSk7GJ7ZR6lOpkNg=; b=fsmCc1h6/7OWeGQa+YpDA/e1LX 4VliNlQGAnGlTc15nmbtYrzEwPpMm6oOk6Kd4LGmadWLTQ6Kol4xOT+KkVV8NizAKF+ykgMbwSd83 6bm5NKpQvY9ML5mBHaacWEwln9dGWvrof7VLBbyxCmVFoN5Lxg1eQ5yXpgGTvAvYInCPRmpyx4190 owWH4WjZRXrv2St5hnuKIErWa6B7ml26ztCbVbzg9kFe0lpCOK2kyD/Zk+ynKh3fI/hO6A4PK6Uy3 xnLxnhFn3zTkpdrba3ndogtFg/NPmvj+LUfVL9J2kF7uhnoQnPdZHlgE0ZsvnZV4DBShL6ts31PYz Ei/FW9Rw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.99.2 #2 (Red Hat Linux)) id 1wynMm-00000005qVL-3lBw; Tue, 25 Aug 2026 09:22:49 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 631B73001D0; Tue, 25 Aug 2026 11:22:47 +0200 (CEST) Date: Tue, 25 Aug 2026 11:22:47 +0200 From: Peter Zijlstra To: Yang Zi <2959243019@qq.com> Cc: boqun@kernel.org, longman@redhat.com, mingo@redhat.com, will@kernel.org, linux-kernel@vger.kernel.org, Paul McKenney Subject: Re: [PATCH] locking/mutex: Restore RCU read-side protection for optimistic spinning Message-ID: <20260825092247.GE4120091@noisy.programming.kicks-ass.net> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Aug 25, 2026 at 05:13:30PM +0800, Yang Zi wrote: > The optimistic spinning paths in kernel/locking/mutex.c dereference the > current lock owner's task_struct (via owner_on_cpu() -> owner->on_cpu and > task_cpu(owner)) without any lifetime protection on the owner pointer. > > __mutex_owner() (kernel/locking/mutex.h) returns a bare task_struct > pointer that is read directly from lock->owner. mutex_spin_on_owner() and > mutex_can_spin_on_owner() then dereference it inside "while > (__mutex_owner(lock) == owner)" / immediately after the owner load, while > relying only on preempt_disable(). > > Since commit 6c2787f2a20c ("locking: Remove rcu_read_{,un}lock() for > preempt_{dis,en}able()"), the code has assumed that preempt_disable() is > equivalent to an RCU read-side critical section and therefore that the > owner's task_struct "won't go away during the spinning period". That > assumption does not hold on PREEMPT_LAZY kernels: preempt_disable() there > no longer actually disables preemption, so the RCU callback that frees a > just-exited owner's task_struct (put_task_struct_rcu_user() -> > call_rcu(), run in rcu_do_batch()) can fire and free the object while a > spinner still holds the stale pointer, leading to a slab use-after-free > read of owner->on_cpu. This doesn't make sense, rcu_preempt was subsumed (again) into regular rcu proper (along with rcu_bh). Any preempt disable region will prohibit the GP from advancing.