From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793269421; b=nnlsqqqgOgw9RnGfx2rD4/0TpEFeN8N6o5yzVDsTD0O1+qSF6Chruw2kwvzUtx/fw6xf IUFGqD1srm+BNUMG8j6TorXf6VXPhrOYJGi2ZfIAsId3zyFave8ENarS5Gjm/fYtgD2xb U8xfVnOm7QcRDCOqSOmWM8iatJxzLf9LyzIs4rG9Zlw9DecQnoQjx9MXvOG9kjnE0/I/z NGwA7+10g7igo2tIKLW9c7WgCrXYlHJKIQ/eqUhGGgmTUcmQkwhw0FYrtFNpX0Xtj3neK ghWKiVzGJYcgZIOs9g4dhC9b3OdnQeITjecfZ7nwhvPUZlJJbgbmKmFYfk6kMgTMg2g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793269421; h=DMARC-Filter:Received:DKIM-Signature:Message-ID:Subject:From:To:Cc: Date:In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version; bh=h/NTq1WLBMPSLF6XFZgbhvzXQ8oYuf+0ZqChn7K5Lhk=; b=oVQ7nlxXUPKmaMBLTzMQsx2rH43Zo7+vA3zI+mkmwloTA8ZYn3GeaE/xPpyfrvv5nVlX 7+GvmheEi+Tr+pR73Xlrzk+3fsFB1zqtqe1Op4FNu+UQu7CJ195l7olw6O3SbC2BSvGGJ YcxrCIo5E9X8t0vDx0JRSdxFdOTHE1tfL6ozDJ3vhpHLAI5N7Lhkldbre7iKlQq2DI7b6 utYM3mDyRly2Rh5pqIXSQhtaWvdU5wqTgYfFMrx8nZ+0dFPSj9wIPCDTAFvAWbskgBJ4f lfJpU8quEBM5eUTY2o91wqqzwIhZB4mqhrdGLa6wYkU9stI9nDQIq9YSdy2YPIMoxpg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=Ql2h6Chx; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DBD6606A320; Thu, 29 Oct 2026 10:23:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7DBD6606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=Ql2h6Chx Received: from [IPv6:::1] (ptz.office.stw.pengutronix.de [IPv6:2a0a:edc0:0:900:1d::77]) (Authenticated sender: lst@pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 9E169200AD7; Thu, 29 Oct 2026 11:23:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1793269416; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h/NTq1WLBMPSLF6XFZgbhvzXQ8oYuf+0ZqChn7K5Lhk=; b=Ql2h6ChxMtOcGZatguhKGOuEC+rmEILtn+if2SqEYCCbxsuZJ6Ru1gYHv8VOZp6Mh4UHgD nqC+Abc2a38Cwsw0drk11FIo/o24C4d78/xhRP3/VTW8wljjZU8itJ+/kl8dIca91QxHTe zvq2X5SIBOfNysNtdZi59WpQkG7l62333eKKoo1mxhb7lKFl0mbo4G2Zx6icW/xkO4bTTE YLTxcS/jNobwPebe1QvNnKjEU9FWzz23p1+A9z4qKfS4d3UnGFoteuJK8i4EG/TbM+kgZm 36EtXeEIB1VKZmg46ZE6J8JvC49oxRtIkz9PpvGhCuexji4WQBw+w9KH7UeaQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1793269416; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h/NTq1WLBMPSLF6XFZgbhvzXQ8oYuf+0ZqChn7K5Lhk=; b=GGV5mVLTXHW8P1GM8MYEEw2sQLTe4MwdizvhP5Gb/W/2fDooOaBhx/Sa6fBxsgpigJrLiU igwFXfs2zGARcG6oRLe3YbfOnTu/2cJUh7LRJrnnkQS9jz/1Y3UBwkh5VQ/POkNwIuxIT0 KQqycJPkCqfr8Rb3w+LWfxdHK9tZOIFSmALUHySLhH2nMw1ohIN5PV6epE7MfW9GnTgZiP aB1o7tlQphCTr3i/eUUYsp9+VzsQAbIi7aed/Fs9CWQwqWGP3mh0SmpkOiff1MJ5KuNFqQ /B16Le4NHB27ysqZuAH84XpNo3HERRJf+Gjr9xim0+G/tMzPUQcCR7egGl6w6w== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=lst@pengutronix.de smtp.mailfrom=l.stach@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1793269416; a=rsa-sha256; cv=none; b=WpN8WUnDHqz9Mc+CuO1qqQ2s1JkX/YAqSIeMD64lYoC6u7e/Mf6zaDQORC81p8qVmhEOlB Qyk2Tu3F5ZFoPi+6o3G5P8XatkbqSpZqIMxTmNYjN7iZ9PyGZF+UJ9ECFfr5xTsdvve48U DwjbkCL6Gqu4fpyQEmvvgJ4MB8/2UNwQB3y97Tn6pks8uSBKkJNnVRBHkLNA79FYLoF/UQ /Fka7A7sY843ZzZCE560WkHfHGLJkmQ0WFB126J4qtxaMZHhGGerIFlt07dEmX36MJuoaj +Fi5x3cZiGZ8NviUZwVGZyTDLNtqw6kmMNQeZKWIuGV0RSo3ygqYDO8hsPjmKA== Message-ID: Subject: Re: [RFC PATCH 0/6] dma-buf: Phase out is_signaled() race From: Lucas Stach To: Philipp Stanner , Min Ma , Lizhi Hou , Oded Gabbay , "Rob Herring (Arm)" , Tomeu Vizoso , Karol Wachowski , Andrzej Kacprowski , Sumit Semwal , Christian =?ISO-8859-1?Q?K=F6nig?= , Felix Kuehling , Alex Deucher , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Russell King , Christian Gmeiner , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Alessio Belle , Luigi Santivetti , Qiang Yu , Rob Clark , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , Lyude Paul , Danilo Krummrich , Boris Brezillon , Steven Price , =?ISO-8859-1?Q?Adri=E1n?= Larumbe , Liviu Dudau , Dave Airlie , Gerd Hoffmann , Matthew Brost , Natalie Vock , Arun Pravin , Matthew Auld , Thomas =?ISO-8859-1?Q?Hellstr=F6m?= , Melissa Wen , =?ISO-8859-1?Q?Ma=EDra?= Canal , Dave Stevenson , Raspberry Pi Kernel Maintenance , Dmitry Osipenko , Gurchetan Singh , Chia-I Wu , Zack Rusin , Broadcom internal kernel review list , Thierry Reding , Mikko Perttunen , Jonathan Cameron , David Lechner , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , Greg Kroah-Hartman , Sunil Khatri , Kees Cook , Jesse Zhang , Timur =?ISO-8859-1?Q?Krist=F3f?= , Srinivasan Shanmugam , Kexin Sun , Prike Liang , David Rosca , Krzysztof Karas , Marco Crivellari , Shixiong Ou , Jouni =?ISO-8859-1?Q?H=F6gander?= , Thadeu Lima de Souza Cascardo , Pierre-Eric Pelloux-Prayer , Joel Fernandes , Al Viro , Neill Kapron , Michael Bommarito , Sam Day , Gabriel Prostitis Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, amd-gfx@lists.freedesktop.org, etnaviv@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, imagination@lists.freedesktop.org, lima@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, nouveau@lists.freedesktop.org, virtualization@lists.linux.dev, spice-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-iio@vger.kernel.org, linux-usb@vger.kernel.org Date: Thu, 29 Oct 2026 11:23:34 +0100 In-Reply-To: <20261029095542.1526750-3-phasta@kernel.org> References: <20261029095542.1526750-3-phasta@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-2.fc44) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Hi Philipp, hi Christian, Am Donnerstag, dem 29.10.2026 um 10:55 +0100 schrieb Philipp Stanner: > dma_fence_is_signaled() can return true *while* the fence is signaling. > This has caused explosions before and I guess we can agree that it's > just not ideal. >=20 > The fundamental issue is that the fence-signaled-bit is set under lock > protection but read without it. >=20 > So ideally, we would read it with the lock. This would not change the > relative order, i.e. the bit would still be true in the fence callbacks. >=20 > Christian informs us that taking the lock causes people to complain > about performance regressions because the lock-taking shoots down copied > cache-lines. (which is weird since it would mean that someone is > repeatedly polling on fences instead of just registering a callback to > notify himself once it signals) >=20 I think we would all be interested in the actual use-case that's sensitive to this kind of latency. However, I wonder if this is even an issue anymore with the lock inlined into the fence structure. With the deprecated external lock you would potentially get two cacheline bounces/remote invalidations for the exclusive access: once for the lock and one for the test_and_set_bit atomic op on the flags field. Now with the inlined lock, the lock operation will bring the cacheline into exclusive state on the local CPU and the flag check would then operate on that same cacheline, so there should be only a very minimal penalty compared to the sole atomic op. Regards, Lucas > Let's accept the potential for regressions as true for now. > Nevertheless, I think I can propose a path towards removing the race: >=20 > This series suggests taking the lock in dma_fence_is_signaled() *unless* > the driver explicitly asks for a check with a race-condition. >=20 > As a preparation, I allow drivers to set flags when initializing fences. > Then, we add a flag with which the driver can switch locking off for > that particular function. >=20 > By default, we let all drivers take the lock. >=20 > Should we then, in the kernel release process get reports about > regressions, we can set the race-flag for the affected driver and > restore the old behavior. >=20 > Should there be no reports, we could phase the flag out again after a > few releases, always taking the lock. >=20 > New users would always see the lock. >=20 > I put all potentially affected parties on Cc. Please point out if you > can already foresee your driver being negatively affected by this. >=20 > P. >=20 >=20 > Philipp Stanner (6): > dma-buf: dma-fence: Add flags parameter to dma_fence_init() > dma-buf: dma-fence: Add flag for using 64-bit seqnos > dma-buf: Port users of dma_fence_init64() > dma-buf: dma-fence: remove dma_fence_init64() > dma-buf: dma-fence: Close race in dma_fence_is_signaled() by default > drm/nouveau: Remove hacky fence check >=20 > drivers/accel/amdxdna/amdxdna_ctx.c | 2 +- > drivers/accel/ethosu/ethosu_job.c | 2 +- > drivers/accel/ivpu/ivpu_job.c | 2 +- > drivers/accel/rocket/rocket_job.c | 2 +- > drivers/dma-buf/dma-fence-array.c | 2 +- > drivers/dma-buf/dma-fence-chain.c | 4 +- > drivers/dma-buf/dma-fence.c | 44 +++++------------ > drivers/dma-buf/st-dma-fence-chain.c | 2 +- > drivers/dma-buf/st-dma-fence-unwrap.c | 2 +- > drivers/dma-buf/st-dma-fence.c | 2 +- > drivers/dma-buf/st-dma-resv.c | 2 +- > drivers/dma-buf/sw_sync.c | 2 +- > .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- > .../drm/amd/amdgpu/amdgpu_eviction_fence.c | 7 +-- > drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 2 +- > .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 5 +- > .../gpu/drm/amd/amdgpu/amdgpu_vm_tlb_fence.c | 5 +- > drivers/gpu/drm/drm_crtc.c | 2 +- > drivers/gpu/drm/drm_writeback.c | 2 +- > drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 2 +- > drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c | 2 +- > drivers/gpu/drm/i915/i915_request.c | 2 +- > drivers/gpu/drm/i915/i915_sw_fence_work.c | 2 +- > drivers/gpu/drm/i915/i915_vma_resource.c | 2 +- > .../gpu/drm/i915/selftests/i915_sw_fence.c | 2 +- > drivers/gpu/drm/imagination/pvr_ccb.c | 2 +- > drivers/gpu/drm/imagination/pvr_queue.c | 2 +- > drivers/gpu/drm/lima/lima_sched.c | 2 +- > drivers/gpu/drm/msm/msm_fence.c | 2 +- > drivers/gpu/drm/nouveau/nouveau_drm.c | 13 ----- > drivers/gpu/drm/nouveau/nouveau_fence.c | 4 +- > drivers/gpu/drm/panfrost/panfrost_job.c | 2 +- > drivers/gpu/drm/panthor/panthor_sched.c | 2 +- > drivers/gpu/drm/qxl/qxl_release.c | 2 +- > drivers/gpu/drm/radeon/radeon_fence.c | 2 +- > drivers/gpu/drm/scheduler/sched_fence.c | 4 +- > .../gpu/drm/scheduler/tests/mock_scheduler.c | 2 +- > drivers/gpu/drm/ttm/tests/ttm_bo_test.c | 2 +- > .../gpu/drm/ttm/tests/ttm_bo_validate_test.c | 2 +- > drivers/gpu/drm/v3d/v3d_fence.c | 2 +- > drivers/gpu/drm/vc4/vc4_gem.c | 2 +- > drivers/gpu/drm/vgem/vgem_fence.c | 2 +- > drivers/gpu/drm/virtio/virtgpu_fence.c | 2 +- > drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 2 +- > drivers/gpu/drm/xe/xe_hw_fence.c | 2 +- > drivers/gpu/drm/xe/xe_oa.c | 2 +- > drivers/gpu/drm/xe/xe_preempt_fence.c | 2 +- > drivers/gpu/drm/xe/xe_tlb_inval.c | 2 +- > drivers/gpu/host1x/fence.c | 2 +- > drivers/iio/industrialio-buffer.c | 2 +- > drivers/usb/gadget/function/f_fs.c | 2 +- > include/linux/dma-fence.h | 48 +++++++++++++++++-- > 52 files changed, 115 insertions(+), 105 deletions(-)