[RFC PATCH 0/9] Rust version of the VGEM driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is my first take on using the DRM Rust abstractions [1] to convert a DRM
driver, written originally in C, to Rust. This patchset consists of a conversion
of the vgem driver to a DRM Rust driver. This new driver has the exactly same
functionalities of the original C driver, but takes advantages of all the Rust
features.

These patches are based primarily on the Rust DRM abstractions [1], sent as a
RFC to the mailing list last week. Also, it depends on some Device abstractions
[2] and on the Timer abstraction [3] developed by Boqun Feng.

This patchset introduces some changes to the DRM abstractions proposed in [1]
and also introduces a new abstraction to DMA reservation. Finally, introduces a
fully functional vgem driver written in Rust.

* Patch #1: Introduces a safe abstraction to the DMA Reservation.
* Patch #2 - #5: Introduces some increments to the DRM abstractions, adding
  methods and exposing attributes.
* Patch #6: Makes an adaptation to the UAPI, in order to be interpreted by bindgen.
* Patch #7 - #8: Introduces the vgem driver.
* Patch #9: Makes it possible to use the kernel::declare_drm_ioctls! macro.

The driver was tested with IGT, using the tests `vgem_basic`, `vgem_slow` and
`dmabuf_sync_file`. Also, I incremented some invalid tests to `vgem_basic` [4]
to assure the proper error handling of the driver.

A branch with all the dependencies and ready for compilation is available at
[5].

Note that patch #8 is necessary to deal with the current
kernel::declare_drm_ioctls! macro. Currently, the macro
kernel::declare_drm_ioctls! considers that the IOCTLs are in the right order and
there are no gaps, which is not true for vgem. The vgem IOCTLs starts at 0x01,
so there is a gap for IOCTL 0x00. To bypass this problem I'm currently using a
dummy IOCTL as IOCTL 0x00, but this solution should be temporary. I would love
to hear suggestions on how to address this problem.

Any suggestions and SAFETY reviews are welcomed!

[1] https://lore.kernel.org/dri-devel/20230307-rust-drm-v1-0-917ff5bc80a8@xxxxxxxxxxxxx/T/
[2] https://github.com/Rust-for-Linux/linux/pull/982
[3] https://github.com/fbq/linux-rust/commit/c31a2a3ce7420b43bda2c6f1b43227baf0d13661
[4] https://patchwork.freedesktop.org/series/114912/
[5] https://github.com/mairacanal/linux/tree/vgem/wip-dma

Best Regards,
- Maíra Canal

Maíra Canal (9):
  rust: dma_resv: add DMA Reservation abstraction
  rust: drm: gem: add method to return DmaResv from GEMObject
  rust: dma_fence: add method to return an indication if the fence is signaled
  rust: dma_fence: expose the fence's seqno publically
  rust: drm: gem: shmem: set map_wc on gem_create_object callback
  drm/vgem: move IOCTLs numbers to enum
  drm/rustgem: implement a Rust version of VGEM
  drm/rustgem: implement timeout to prevent hangs
  drm/rustgem: create dummy IOCTL with number 0x00

 drivers/gpu/drm/Kconfig          |  11 +++
 drivers/gpu/drm/Makefile         |   1 +
 drivers/gpu/drm/rustgem/Makefile |   3 +
 drivers/gpu/drm/rustgem/fence.rs |  83 ++++++++++++++++++
 drivers/gpu/drm/rustgem/file.rs  | 143 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/rustgem/gem.rs   |  31 +++++++
 drivers/gpu/drm/rustgem/vgem.rs  | 105 +++++++++++++++++++++++
 include/uapi/drm/vgem_drm.h      |  11 ++-
 rust/bindings/bindings_helper.h  |   2 +
 rust/helpers.c                   |  25 ++++++
 rust/kernel/dma_fence.rs         |  12 +++
 rust/kernel/dma_resv.rs          |  75 ++++++++++++++++
 rust/kernel/drm/gem/mod.rs       |   7 ++
 rust/kernel/drm/gem/shmem.rs     |   5 ++
 rust/kernel/lib.rs               |   1 +
 15 files changed, 513 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/rustgem/Makefile
 create mode 100644 drivers/gpu/drm/rustgem/fence.rs
 create mode 100644 drivers/gpu/drm/rustgem/file.rs
 create mode 100644 drivers/gpu/drm/rustgem/gem.rs
 create mode 100644 drivers/gpu/drm/rustgem/vgem.rs
 create mode 100644 rust/kernel/dma_resv.rs

-- 
2.39.2




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux