From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: thomas.hellstrom@linux.intel.com, dakr@kernel.org,
ecourtney@nvidia.com, matthew.brost@intel.com,
nat@pixelcluster.dev, dri-devel@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org
Subject: [PATCH 10/10] dma-buf: Inline dma_resv_init and remove allocated flag
Date: Thu, 27 Aug 2026 14:38:58 +0200 [thread overview]
Message-ID: <20260827124910.2245-11-christian.koenig@amd.com> (raw)
In-Reply-To: <20260827124910.2245-1-christian.koenig@amd.com>
Now that all users have migrated to dma_resv_alloc(), inline the
initialization code directly into dma_resv_alloc() and remove the
dma_resv_init() function entirely.
Additionally, remove the 'allocated' flag from struct dma_resv since
all dma_resv objects are now dynamically allocated. This simplifies
the reference counting logic - dma_resv_release() now always frees
the object unconditionally.
The last remaining use of dma_resv_init() in dma_resv_lockdep() has
been converted to use dma_resv_alloc() instead.
Signed-off-by: Christian König <christian.koenig@amd.com>
Assisted-by: Claude:Sonnet 4
---
drivers/dma-buf/dma-resv.c | 41 ++++++++++++++++----------------------
include/linux/dma-resv.h | 10 ----------
2 files changed, 17 insertions(+), 34 deletions(-)
diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index 48798cec6ce7..a3586e79c2eb 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -132,26 +132,13 @@ static void dma_resv_list_free(struct dma_resv_list *list)
kfree_rcu(list, rcu);
}
-/**
- * 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);
-
/*
* dma_resv_release - release function for kref
* @kref: the kref inside the dma_resv object
*
* This is called when the last reference to a dma_resv object is released.
- * Cleans up the object and frees it if it was allocated by dma_resv_alloc().
+ * All dma_resv objects are now dynamically allocated, so this always frees
+ * the object after cleanup.
*/
static void dma_resv_release(struct kref *kref)
{
@@ -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);
}
/**
@@ -181,8 +167,9 @@ struct dma_resv *dma_resv_alloc(void)
if (!obj)
return NULL;
- dma_resv_init(obj);
- obj->allocated = true;
+ kref_init(&obj->refcount);
+ ww_mutex_init(&obj->lock, &reservation_ww_class);
+ RCU_INIT_POINTER(obj->fences, NULL);
return obj;
}
@@ -838,23 +825,28 @@ static int __init dma_resv_lockdep(void)
{
struct mm_struct *mm = mm_alloc();
struct ww_acquire_ctx ctx;
- struct dma_resv obj;
+ struct dma_resv *obj;
struct address_space mapping;
int ret;
if (!mm)
return -ENOMEM;
- dma_resv_init(&obj);
+ obj = dma_resv_alloc();
+ if (!obj) {
+ mmput(mm);
+ return -ENOMEM;
+ }
+
address_space_init_once(&mapping);
mmap_read_lock(mm);
ww_acquire_init(&ctx, &reservation_ww_class);
- ret = dma_resv_lock(&obj, &ctx);
+ ret = dma_resv_lock(obj, &ctx);
if (ret) {
/* Only EDEADLK from the error injection is possible here */
WARN_ON(ret != -EDEADLK);
- dma_resv_lock_slow(&obj, &ctx);
+ dma_resv_lock_slow(obj, &ctx);
}
fs_reclaim_acquire(GFP_KERNEL);
/* for unmap_mapping_range on trylocked buffer objects in shrinkers */
@@ -868,10 +860,11 @@ static int __init dma_resv_lockdep(void)
__dma_fence_might_wait();
#endif
fs_reclaim_release(GFP_KERNEL);
- ww_mutex_unlock(&obj.lock);
+ ww_mutex_unlock(&obj->lock);
ww_acquire_fini(&ctx);
mmap_read_unlock(mm);
+ dma_resv_put(obj);
mmput(mm);
return 0;
diff --git a/include/linux/dma-resv.h b/include/linux/dma-resv.h
index 4d12519df34e..cf689d3d4ba6 100644
--- a/include/linux/dma-resv.h
+++ b/include/linux/dma-resv.h
@@ -162,15 +162,6 @@ struct dma_resv {
*/
struct kref refcount;
- /**
- * @allocated:
- *
- * True if this object was allocated by dma_resv_alloc(), false if
- * embedded in another structure. Used to determine whether to free
- * the object memory in the release function.
- */
- bool allocated;
-
/**
* @lock:
*
@@ -482,7 +473,6 @@ static inline void dma_resv_unlock(struct dma_resv *obj)
ww_mutex_unlock(&obj->lock);
}
-void dma_resv_init(struct dma_resv *obj);
struct dma_resv *dma_resv_alloc(void);
struct dma_resv *dma_resv_get(struct dma_resv *obj);
void dma_resv_put(struct dma_resv *obj);
--
2.43.0
next prev parent reply other threads:[~2026-08-27 12:49 UTC|newest]
Thread overview: 24+ 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-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-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 ` Christian König [this message]
2026-08-27 13:31 ` [PATCH 10/10] dma-buf: Inline dma_resv_init and remove allocated flag sashiko-bot
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=20260827124910.2245-11-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=ecourtney@nvidia.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.brost@intel.com \
--cc=nat@pixelcluster.dev \
--cc=thomas.hellstrom@linux.intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox