From: sashiko-bot@kernel.org
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 10/10] dma-buf: Inline dma_resv_init and remove allocated flag
Date: Thu, 27 Aug 2026 13:31:52 +0000 [thread overview]
Message-ID: <20260827133152.DDA0D1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260827124910.2245-11-christian.koenig@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Synchronous freeing of shared dma_resv objects causes Use-After-Free for concurrent lockless RCU readers.
- [High] Drivers like i915 leak dynamically allocated dma_resv objects when destroying GEM objects because they bypass standard DRM cleanup routines.
--
commit d696682993c0c4cb40a8a895d00e6e7b158307dd
Author: Christian König <ckoenig.leichtzumerken@gmail.com>
dma-buf: Inline dma_resv_init and remove allocated flag
This commit migrates all dma_resv object initializations directly into
dma_resv_alloc() and removes the dma_resv_init() function. It also makes
dma_resv objects strictly dynamically allocated, removing the allocated
flag and simplifying the cleanup in dma_resv_release() to an unconditional
kfree().
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 1251b18e1b540..b553ad9c87445 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
[ ... ]
> -/**
> - * dma_resv_init - initialize a reservation object
> - * @obj: the reservation object
> - */
> -void dma_resv_init(struct dma_resv *obj)
> -{
> - kref_init(&obj->refcount);
> - obj->allocated = false;
> - ww_mutex_init(&obj->lock, &reservation_ww_class);
> -
> - RCU_INIT_POINTER(obj->fences, NULL);
> -}
> -EXPORT_SYMBOL(dma_resv_init);
[Severity: High]
Does replacing the static initialization with dynamic allocation via
dma_resv_alloc() cause memory leaks in drivers that bypass standard DRM
cleanup routines?
Drivers like i915 use custom cleanup logic. For instance,
i915_gem_object_alloc() calls drm_gem_private_object_init(), which
dynamically allocates obj->resv via dma_resv_alloc(). When the object is
freed, i915 uses __i915_gem_free_object(), which bypasses
drm_gem_object_release() and only calls __i915_gem_object_fini().
Since dma_resv_fini() was removed from __i915_gem_object_fini() and not
replaced with a call to dma_resv_put(obj->base.resv), the reference is
never dropped. Could this permanently leak the dma_resv allocation on every
GEM object destruction?
[ ... ]
> @@ -159,8 +146,7 @@ static void dma_resv_release(struct kref *kref)
>
> dma_resv_list_free(rcu_dereference_protected(obj->fences, true));
> ww_mutex_destroy(&obj->lock);
> - if (obj->allocated)
> - kfree(obj);
> + kfree(obj);
> }
[Severity: Critical]
Does this synchronous free cause a use-after-free for concurrent lockless
RCU readers?
In the i915 driver, GEM objects are destroyed using call_rcu() (via
__i915_gem_free_object_rcu). Lockless readers like i915_gem_busy_ioctl()
look up objects under rcu_read_lock() and access obj->base.resv.
If an object shares its resv instance (e.g., via obj->shares_resv_from with
an i915_address_space), __i915_gem_free_object() drops the lock reference
synchronously via i915_vm_resv_put(). If that drops the last reference,
dma_resv_release() synchronously frees the memory here.
However, the GEM object itself remains valid during the RCU grace period.
Can concurrent RCU readers dereference the already freed dma_resv pointer
when calling dma_resv_iter_begin(&cursor, obj->base.resv, ...) in
i915_gem_busy_ioctl()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260827124910.2245-1-christian.koenig@amd.com?part=10
next prev parent reply other threads:[~2026-08-27 13:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 12:38 Refcounting dma_resv v2 Christian König
2026-08-27 12:38 ` [PATCH 01/10] dma-buf: Add reference counting to dma_resv Christian König
2026-08-27 18:39 ` Andi Shyti
2026-08-28 18:21 ` Danilo Krummrich
2026-08-28 19:17 ` Matthew Brost
2026-08-28 19:34 ` Matthew Brost
2026-08-31 7:37 ` Christian König
2026-08-31 21:09 ` Matthew Brost
2026-08-31 7:31 ` Christian König
2026-08-27 12:38 ` [PATCH 02/10] dma-buf/tests: Convert st-dma-resv tests to use dma_resv_alloc Christian König
2026-08-27 13:08 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 03/10] drm/gem: Add helper for drm_gem_object resv assignment Christian König
2026-08-27 13:22 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 04/10] drm/gem: Convert drm_gem_private_object_init to return error code Christian König
2026-08-27 13:19 ` sashiko-bot
2026-08-31 20:59 ` Youssef Samir
2026-08-27 12:38 ` [PATCH 05/10] drm/gem: Use dynamic allocation for GEM object dma_resv Christian König
2026-08-27 13:13 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 06/10] drm/mode_config: Use dma_resv_alloc for lockdep annotation Christian König
2026-08-27 13:02 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 07/10] drm/xe: " Christian König
2026-08-27 13:04 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 08/10] drm/i915/gt: Use dma_resv_alloc for VM reservation objects Christian König
2026-08-27 13:11 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 09/10] drm/ttm/tests: Use dma_resv_alloc in test files Christian König
2026-08-27 13:12 ` sashiko-bot
2026-08-27 12:38 ` [PATCH 10/10] dma-buf: Inline dma_resv_init and remove allocated flag Christian König
2026-08-27 13:31 ` sashiko-bot [this message]
2026-08-27 13:39 ` ✗ Fi.CI.BUILD: failure for series starting with [01/10] dma-buf: Add reference counting to dma_resv Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260827133152.DDA0D1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.