Skip to content

Commit cba836b

Browse files
mairacanalpopcornmix
authored andcommitted
drm/gem: Create a drm_gem_object_init_with_mnt() function
Commit 0992b25 upstream For some applications, such as applications that uses huge pages, we might want to have a different mountpoint, for which we pass mount flags that better match our usecase. Therefore, create a new function `drm_gem_object_init_with_mnt()` that allow us to define the tmpfs mountpoint where the GEM object will be created. If this parameter is NULL, then we fallback to `shmem_file_setup()`. Signed-off-by: Maíra Canal <mcanal@igalia.com> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240923141348.2422499-5-mcanal@igalia.com
1 parent 14df5a6 commit cba836b

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

drivers/gpu/drm/drm_gem.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,55 @@ drm_gem_init(struct drm_device *dev)
114114
}
115115

116116
/**
117-
* drm_gem_object_init - initialize an allocated shmem-backed GEM object
117+
* drm_gem_object_init_with_mnt - initialize an allocated shmem-backed GEM
118+
* object in a given shmfs mountpoint
119+
*
118120
* @dev: drm_device the object should be initialized for
119121
* @obj: drm_gem_object to initialize
120122
* @size: object size
123+
* @gemfs: tmpfs mount where the GEM object will be created. If NULL, use
124+
* the usual tmpfs mountpoint (`shm_mnt`).
121125
*
122126
* Initialize an already allocated GEM object of the specified size with
123127
* shmfs backing store.
124128
*/
125-
int drm_gem_object_init(struct drm_device *dev,
126-
struct drm_gem_object *obj, size_t size)
129+
int drm_gem_object_init_with_mnt(struct drm_device *dev,
130+
struct drm_gem_object *obj, size_t size,
131+
struct vfsmount *gemfs)
127132
{
128133
struct file *filp;
129134

130135
drm_gem_private_object_init(dev, obj, size);
131136

132-
filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
137+
if (gemfs)
138+
filp = shmem_file_setup_with_mnt(gemfs, "drm mm object", size,
139+
VM_NORESERVE);
140+
else
141+
filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
142+
133143
if (IS_ERR(filp))
134144
return PTR_ERR(filp);
135145

136146
obj->filp = filp;
137147

138148
return 0;
139149
}
150+
EXPORT_SYMBOL(drm_gem_object_init_with_mnt);
151+
152+
/**
153+
* drm_gem_object_init - initialize an allocated shmem-backed GEM object
154+
* @dev: drm_device the object should be initialized for
155+
* @obj: drm_gem_object to initialize
156+
* @size: object size
157+
*
158+
* Initialize an already allocated GEM object of the specified size with
159+
* shmfs backing store.
160+
*/
161+
int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj,
162+
size_t size)
163+
{
164+
return drm_gem_object_init_with_mnt(dev, obj, size, NULL);
165+
}
140166
EXPORT_SYMBOL(drm_gem_object_init);
141167

142168
/**

include/drm/drm_gem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ void drm_gem_object_release(struct drm_gem_object *obj);
473473
void drm_gem_object_free(struct kref *kref);
474474
int drm_gem_object_init(struct drm_device *dev,
475475
struct drm_gem_object *obj, size_t size);
476+
int drm_gem_object_init_with_mnt(struct drm_device *dev,
477+
struct drm_gem_object *obj, size_t size,
478+
struct vfsmount *gemfs);
476479
void drm_gem_private_object_init(struct drm_device *dev,
477480
struct drm_gem_object *obj, size_t size);
478481
void drm_gem_private_object_fini(struct drm_gem_object *obj);

0 commit comments

Comments
 (0)