Re: [PATCH 2/7] drm/gem-shmem: Export VM ops functions

From: Christian König
Date: Wed Mar 19 2025 - 03:55:41 EST


Am 18.03.25 um 20:22 schrieb Daniel Almeida:
> From: Asahi Lina <lina@xxxxxxxxxxxxx>
>
> There doesn't seem to be a way for the Rust bindings to get a
> compile-time constant reference to drm_gem_shmem_vm_ops, so we need to
> duplicate that structure in Rust... this isn't nice...

Well "isn't nice" is an understatement. We can have that as a short term hack, but I don't think that this is a doable long term solution.

For this particular case here it most likely doesn't matter, but operation pointer structures are often used to identify a certain class of object.

So exporting the functions and then re-creating the constant operation pointer structure in Rust doesn't work in some cases.

Regards,
Christian.

>
> Signed-off-by: Asahi Lina <lina@xxxxxxxxxxxxx>
> Signed-off-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/drm_gem_shmem_helper.c | 9 ++++++---
> include/drm/drm_gem_shmem_helper.h | 3 +++
> 2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index ec89e9499f5f02a2a35713669bf649dd2abb9938..be310db5863871604f3502ad1f419937d4c20a84 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -535,7 +535,7 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
> }
> EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
>
> -static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf)
> +vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf)
> {
> struct vm_area_struct *vma = vmf->vma;
> struct drm_gem_object *obj = vma->vm_private_data;
> @@ -564,8 +564,9 @@ static vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf)
>
> return ret;
> }
> +EXPORT_SYMBOL_GPL(drm_gem_shmem_fault);
>
> -static void drm_gem_shmem_vm_open(struct vm_area_struct *vma)
> +void drm_gem_shmem_vm_open(struct vm_area_struct *vma)
> {
> struct drm_gem_object *obj = vma->vm_private_data;
> struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
> @@ -586,8 +587,9 @@ static void drm_gem_shmem_vm_open(struct vm_area_struct *vma)
>
> drm_gem_vm_open(vma);
> }
> +EXPORT_SYMBOL_GPL(drm_gem_shmem_vm_open);
>
> -static void drm_gem_shmem_vm_close(struct vm_area_struct *vma)
> +void drm_gem_shmem_vm_close(struct vm_area_struct *vma)
> {
> struct drm_gem_object *obj = vma->vm_private_data;
> struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
> @@ -598,6 +600,7 @@ static void drm_gem_shmem_vm_close(struct vm_area_struct *vma)
>
> drm_gem_vm_close(vma);
> }
> +EXPORT_SYMBOL_GPL(drm_gem_shmem_vm_close);
>
> const struct vm_operations_struct drm_gem_shmem_vm_ops = {
> .fault = drm_gem_shmem_fault,
> diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h
> index d22e3fb53631ab655748d7f6c628ffdb402f6324..b70d3cc35bd194e7cd718bee220408b5dda568bf 100644
> --- a/include/drm/drm_gem_shmem_helper.h
> +++ b/include/drm/drm_gem_shmem_helper.h
> @@ -132,6 +132,9 @@ void drm_gem_shmem_print_info(const struct drm_gem_shmem_object *shmem,
> struct drm_printer *p, unsigned int indent);
>
> extern const struct vm_operations_struct drm_gem_shmem_vm_ops;
> +vm_fault_t drm_gem_shmem_fault(struct vm_fault *vmf);
> +void drm_gem_shmem_vm_open(struct vm_area_struct *vma);
> +void drm_gem_shmem_vm_close(struct vm_area_struct *vma);
>
> /*
> * GEM object functions
>