Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/gem/shmem: Extract drm_gem_shmem_release() from drm_gem_shmem_free()

At the moment, the way that we currently free gem shmem objects is not
ideal for rust bindings. drm_gem_shmem_free() releases all of the
associated memory with a gem shmem object with kfree(), which means that
for us to correctly release a gem shmem object in rust we have to manually
drop all of the contents of our gem object structure in-place by hand
before finally calling drm_gem_shmem_free() to release the shmem resources
and the allocation for the gem object.

Since the only reason this is an issue is because of drm_gem_shmem_free()
calling kfree(), we can fix this by splitting drm_gem_shmem_free() out into
itself and drm_gem_shmem_release(), where drm_gem_shmem_release() releases
the various gem shmem resources without freeing the structure itself. With
this, we can safely re-acquire the KBox for the gem object's memory
allocation and let rust handle cleaning up all of the other struct members
automatically.

Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://lore.kernel.org/r/20250911230147.650077-3-lyude@redhat.com

+19 -5
+18 -5
drivers/gpu/drm/drm_gem_shmem_helper.c
··· 175 175 EXPORT_SYMBOL_GPL(drm_gem_shmem_create_with_mnt); 176 176 177 177 /** 178 - * drm_gem_shmem_free - Free resources associated with a shmem GEM object 179 - * @shmem: shmem GEM object to free 178 + * drm_gem_shmem_release - Release resources associated with a shmem GEM object. 179 + * @shmem: shmem GEM object 180 180 * 181 - * This function cleans up the GEM object state and frees the memory used to 182 - * store the object itself. 181 + * This function cleans up the GEM object state, but does not free the memory used to store the 182 + * object itself. This function is meant to be a dedicated helper for the Rust GEM bindings. 183 183 */ 184 - void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) 184 + void drm_gem_shmem_release(struct drm_gem_shmem_object *shmem) 185 185 { 186 186 struct drm_gem_object *obj = &shmem->base; 187 187 ··· 208 208 } 209 209 210 210 drm_gem_object_release(obj); 211 + } 212 + EXPORT_SYMBOL_GPL(drm_gem_shmem_release); 213 + 214 + /** 215 + * drm_gem_shmem_free - Free resources associated with a shmem GEM object 216 + * @shmem: shmem GEM object to free 217 + * 218 + * This function cleans up the GEM object state and frees the memory used to 219 + * store the object itself. 220 + */ 221 + void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem) 222 + { 223 + drm_gem_shmem_release(shmem); 211 224 kfree(shmem); 212 225 } 213 226 EXPORT_SYMBOL_GPL(drm_gem_shmem_free);
+1
include/drm/drm_gem_shmem_helper.h
··· 112 112 struct drm_gem_shmem_object *drm_gem_shmem_create_with_mnt(struct drm_device *dev, 113 113 size_t size, 114 114 struct vfsmount *gemfs); 115 + void drm_gem_shmem_release(struct drm_gem_shmem_object *shmem); 115 116 void drm_gem_shmem_free(struct drm_gem_shmem_object *shmem); 116 117 117 118 void drm_gem_shmem_put_pages_locked(struct drm_gem_shmem_object *shmem);