From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed2-f35.google.com (mail-ed2-f35.google.com [74.125.228.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC25E4A2623 for ; Mon, 21 Sep 2026 14:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789999240; cv=none; b=r/HR3PJ+1gnkcKNaH6OIVkkFMT+x5RK+xXYCTFvtRUYadNKEqCX/i4DAmNeYqLQbF8R8IeYXlqw6TBv7M7lL1OFqHPubfoz1v9RUO6m90tDCEE62sPJzCUmqJP46FhQWWBDLTJ7Vr944tIE8t+ZTC9y8ul1/KX8/JJRYgMS5fzk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789999240; c=relaxed/simple; bh=OeyvfHgi0AM3S4WMT38BkWK6VSxmsJwFB/n9ks+exd0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=b+4mNXwGoJhMVU3LmgiQBlBDXVRJnCtMENKzfliObenM9xWTvQ8mC3V5/5JBUbDfTcpzwDiAlOonOPo3TId88kqIRj/3ebuIbKxsS7rTVRx545yWm/oB37pc1noxoK8EuOu3XBMAWGPno7x2xyRQhu04PEXNxmaAT/JJ8SaIGQM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fy3lm4mW; arc=none smtp.client-ip=74.125.228.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fy3lm4mW" Received: by mail-ed2-f35.google.com with SMTP id 4fb4d7f45d1cf-6aa22408406so4510060a12.3 for ; Mon, 21 Sep 2026 07:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789999236; x=1790604036; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YF4hTPZsf1CzF+RjsRJpL1NqJMDoLq3jkvr85glNVqI=; b=fy3lm4mWVVfxCbiB/3/idnBoWiGR7Ak2D36Mzxp6PBr2+Q8laVBrWpIRYVMTFrcp/0 jFF0hAEuenju7k/fW2j0/C1Jli1UP8WnHH/Of94Gvk1sgDsM7fWI2uyyOZHUsjkVJJPb 0JtH6BP+SVZlH0HMjkU4m57nlQhEUE2RAVPRXvprm0BKQC1hQgaD4/dvBt4EOAFUDnL8 rpAJY91Fcg/OygM5CEK/CUumLCPykTEC3z5vkEPe3zTfIl3UWEN1JSUp6/FvaR+dRraE jovk046obSWMIph957RrWPJMVfeJ6kFVMrFj0Hqvcqs0jI8QC8TubZvfnFnAJXJHjE1h Ikjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789999236; x=1790604036; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YF4hTPZsf1CzF+RjsRJpL1NqJMDoLq3jkvr85glNVqI=; b=KirxaFgQ8qIorri3bPy/jmWAcErv0uKorz3p9BUVRlbrTyTC3AHrEBt9NhvbDtDN5Y 9PvEDfqajs/wNxLBUNKrEaAuGld+AZt282e4VSathHoCIvYKPXlbkobKfwNw0ZgXChAn Gyaiyud079frvt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a05:6402:210f:b0:6a9:aead:4e98 with SMTP id 4fb4d7f45d1cf-6aa577f5cfdmr8223981a12.1.1789999236010; Mon, 21 Sep 2026 07:00:36 -0700 (PDT) Received: from [10.54.182.141] (82-132-213-26.dab.02.net. [82.132.213.26]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6aa67e1a45esm4427483a12.25.2026.09.21.07.00.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Sep 2026 07:00:35 -0700 (PDT) Message-ID: <14db93d0-b41b-43c6-8934-82d10cc50168@gmail.com> Date: Mon, 21 Sep 2026 15:00:27 +0100 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [Linaro-mm-sig] Re: [PATCH v4 01/14] dma-buf: introduce initial file I/O infrastructure To: Matthew Brost , =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Jens Axboe , Keith Busch , Christoph Hellwig , Sagi Grimberg , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Alexander Viro , Christian Brauner , Andrew Morton , Sumit Semwal , Nitesh Shetty , Kanchan Joshi , Anuj Gupta , Tushar Gohad , William Power , Phil Cayton , Jason Gunthorpe , Damien Le Moal , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Benjamin Marzinski , Vishal Verma , David Sterba , Ilya Dryomov , dm-devel@lists.linux.dev, nvdimm@lists.linux.dev, linux-btrfs@vger.kernel.org, ceph-devel@vger.kernel.org References: <181b08be-04bc-4ae9-bb88-15321a82440f@amd.com> Content-Language: en-US From: Pavel Begunkov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/6/26 02:37, Matthew Brost wrote: > On Wed, Aug 05, 2026 at 10:27:49AM +0200, Christian König wrote: >> On 7/28/26 23:29, Pavel Begunkov wrote: ...>>> + /* >>> + * There are no more requests using the map, we can signal the fence. >>> + * It should be done before taking the resv lock as someone could be >>> + * waiting for the fence while holding the lock. >>> + */ >>> + dma_fence_signal(&fence->base); >> >> Signaling fences has a whole bunch of very strict rules associated with it. E.g. you can't alocate memory for example. >> > > Yes, and the rules around signaling fences from worker threads become > interesting as well. In practice, the entire workqueue (or any work item > scheduled on that workqueue) effectively becomes part of the fence > signaling and reclaim path. > >> Are you sure you actually need and want a dma_fence here? >> >>> + >>> + dma_resv_lock(dmabuf->resv, NULL); > > So this is illegal because code is allowed to hold dma-resv locks while > waiting on dma-fences. See dma_resv_lockdep / __dma_fence_might_wait / > dma_fence_begin_signalling. > >>> + ctx->dev_ops->unmap(ctx, map); >>> + dma_resv_unlock(dmabuf->resv); >>> + >>> + dma_fence_put(&fence->base); >> >> You should probably set map->fence to NULL after that. >> >>> + percpu_ref_exit(&map->refs); >>> + kfree(map); >>> + >>> + if (refcount_dec_and_test(&ctx->refs)) { >>> + /* >>> + * Destruction needs to wait for I/O and dma fences. Defer it to >>> + * simplify locking. >>> + */ >>> + INIT_WORK(&ctx->release_work, dma_buf_io_ctx_destroy_work); >>> + queue_work(system_wq, &ctx->release_work); >>> + } >>> +} >>> + >>> +static void dma_buf_io_map_refs_release(struct percpu_ref *ref) >>> +{ >>> + struct dma_buf_io_map *map = container_of(ref, struct dma_buf_io_map, refs); >>> + >>> + /* might sleep, use a worker */ >>> + INIT_WORK(&map->release_work, dma_buf_io_map_release_work); >>> + queue_work(system_wq, &map->release_work); > > You can't guarantee that a GFP_KERNEL allocation won't be performed from > a system worker thread, so you can't safely signal a fence from one. The > pathological case is when all threads in system_wq are running work > items that perform GFP_KERNEL allocations, enter reclaim, and then wait > on a fence that is signaled by another work item queued on system_wq. > Since all worker threads are occupied, the signaling work item cannot be > scheduled, resulting in a deadlock. We actually hit this exact deadlock > early in Xe. > > So, as Christian says, think carefully about whether you really need a > dma-fence here. If you do, then you need to play by the rules. I started with moving it out of wq, which was a good idea anyway, but as mentioned in another email, in the end I just got rid of fences as I believe Christian was suggesting / hinting on. I cc'ed you on v6 if you'd be curious. -- Pavel Begunkov