Skip to contentSkip to conversation

DRM 'feature' support for DRM drivers

PATCH Superseded Laura Nao 2 participants 4 messages May 5 – May 6

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Laura Nao

author
#0 lore raw

v2 cover DRM 'feature' support for DRM drivers

This is a follow up to [1], which introduces feature support for DRM drivers, as will soon be needed by Tyr and rvkms.

Based on feedback and discussion on the first iteration, render node support has been reworked.

Support for render nodes was initially modeled as an unsafe trait, to require drivers to comply with any safety requirements tied to enabling a given feature. For DRIVER_RENDER specifically, the intent was to force implementors to ensure that any ioctl declared with DRM_RENDER_ALLOW does not call KMS/modesetting APIs or require DRM_MASTER.

However, the C DRM core already enforces render node access control at the ioctl dispatch level: if a client opens a render node, any ioctl without the DRM_RENDER_ALLOW flag will fail. So the C DRM framework already ensures the rules are respected for core ioctls, and the unsafe trait doesn't add any meaningful protection beyond this.

For these reasons and since enabling DRIVER_RENDER doesn't require any particular method to be implemented, there's no real need to model this as a trait, and a boolean flag is sufficient.

This does not prevent other driver features to be modeled differently based on their requirements. Features that require additional ops (e.g. FEAT_MODESET) could instead be modeled as a trait, and some other constant type that can only be constructed when the relevant trait is implemented.

Introducing the RENDER_CAPABILITY bool flag here leaves room for implementing other features differently at a later stage.

Changes since v1:
- Replaced DriverFeatures trait and ZSTs with single
RENDER_CAPABILITY: bool constant
- Squashed changes into a single patch

[1] v1: https://lore.kernel.org/rust-for-linux/[email protected]/

Laura Nao (1):
rust: drm: add RENDER_CAPABILITY flag for render node support

 drivers/gpu/drm/tyr/driver.rs |  1 +
 rust/kernel/drm/device.rs     | 12 +++++++++++-
 rust/kernel/drm/driver.rs     |  5 +++++
 3 files changed, 17 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH v2 1/1 rust: drm: add RENDER_CAPABILITY flag for render node support

Add RENDER_CAPABILITY bool constant to the Driver trait to control render node support. When enabled, the driver exposes /dev/dri/renderDXX render nodes to userspace. The flag defaults to false, drivers can opt in by setting it to true in their Driver implementation.

This is then enabled in the Tyr driver, while it's left disabled for Nova for the time being.

---
 drivers/gpu/drm/tyr/driver.rs |  1 +
 rust/kernel/drm/device.rs     | 12 +++++++++++-
 rust/kernel/drm/driver.rs     |  5 +++++
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/tyr/driver.rs +1 -0
index e20a5978eed6..b7ae37ce3a1b 100644
@@ -186,6 +186,7 @@ impl drm::Driver for TyrDrmDriver {
     type Object = drm::gem::shmem::Object<BoData>;
 
     const INFO: drm::DriverInfo = INFO;
+    const RENDER_CAPABILITY: bool = true;
 
     kernel::declare_drm_ioctls! {
         (PANTHOR_DEV_QUERY, drm_panthor_dev_query, ioctl::RENDER_ALLOW, TyrDrmFileData::dev_query),
rust/kernel/drm/device.rs +11 -1
index adbafe8db54d..e121303d88f0 100644
@@ -80,6 +80,16 @@ pub struct Device<T: drm::Driver> {
 }
 
 impl<T: drm::Driver> Device<T> {
+    const fn compute_features() -> u32 {
+        let mut features = drm::driver::FEAT_GEM;
+
+        if T::RENDER_CAPABILITY {
+            features |= drm::driver::FEAT_RENDER;
+        }
+
+        features
+    }
+
     const VTABLE: bindings::drm_driver = drm_legacy_fields! {
         load: None,
         open: Some(drm::File::<T::File>::open_callback),
@@ -105,7 +115,7 @@ impl<T: drm::Driver> Device<T> {
         name: crate::str::as_char_ptr_in_const_context(T::INFO.name).cast_mut(),
         desc: crate::str::as_char_ptr_in_const_context(T::INFO.desc).cast_mut(),
 
-        driver_features: drm::driver::FEAT_GEM,
+        driver_features: Self::compute_features(),
         ioctls: T::IOCTLS.as_ptr(),
         num_ioctls: T::IOCTLS.len() as i32,
         fops: &Self::GEM_FOPS,
rust/kernel/drm/driver.rs +5 -0
index 5233bdebc9fc..92cbc26ce11f 100644
@@ -16,6 +16,8 @@
 
 /// Driver use the GEM memory manager. This should be set for all modern drivers.
 pub(crate) const FEAT_GEM: u32 = bindings::drm_driver_feature_DRIVER_GEM;
+/// Driver supports render nodes, i.e.: /dev/dri/renderDXX devices.
+pub(crate) const FEAT_RENDER: u32 = bindings::drm_driver_feature_DRIVER_RENDER;
 
 /// Information data for a DRM Driver.
 pub struct DriverInfo {
@@ -115,6 +117,9 @@ pub trait Driver {
 
     /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`.
     const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor];
+
+    /// Sets the `DRIVER_RENDER` feature for this driver.
+    const RENDER_CAPABILITY: bool = false;
 }
 
 /// The registration type of a `drm::Device`.
Signature · 1 line
2.39.5
maintainer Reviewed-by on v2 1/1
#2 lore raw

Re: [PATCH v2 1/1] rust: drm: add RENDER_CAPABILITY flag for render node support

Quoted 11 lines · Laura Nao

Add RENDER_CAPABILITY bool constant to the Driver trait to control render node support. When enabled, the driver exposes /dev/dri/renderDXX render nodes to userspace. The flag defaults to false, drivers can opt in by setting it to true in their Driver implementation.

This is then enabled in the Tyr driver, while it's left disabled for Nova for the time being.

Overall looks good to me!

Quoted 61 lines
 drivers/gpu/drm/tyr/driver.rs |  1 +
 rust/kernel/drm/device.rs     | 12 +++++++++++-
 rust/kernel/drm/driver.rs     |  5 +++++
 3 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/tyr/driver.rs +1 -0
index e20a5978eed6..b7ae37ce3a1b 100644
@@ -186,6 +186,7 @@ impl drm::Driver for TyrDrmDriver {
     type Object = drm::gem::shmem::Object<BoData>;
 
     const INFO: drm::DriverInfo = INFO;
+    const RENDER_CAPABILITY: bool = true;
 
     kernel::declare_drm_ioctls! {
         (PANTHOR_DEV_QUERY, drm_panthor_dev_query, ioctl::RENDER_ALLOW, TyrDrmFileData::dev_query),
rust/kernel/drm/device.rs +11 -1
index adbafe8db54d..e121303d88f0 100644
@@ -80,6 +80,16 @@ pub struct Device<T: drm::Driver> {
 }
 
 impl<T: drm::Driver> Device<T> {
+    const fn compute_features() -> u32 {
+        let mut features = drm::driver::FEAT_GEM;
+
+        if T::RENDER_CAPABILITY {
+            features |= drm::driver::FEAT_RENDER;
+        }
+
+        features
+    }
+
     const VTABLE: bindings::drm_driver = drm_legacy_fields! {
         load: None,
         open: Some(drm::File::<T::File>::open_callback),
@@ -105,7 +115,7 @@ impl<T: drm::Driver> Device<T> {
         name: crate::str::as_char_ptr_in_const_context(T::INFO.name).cast_mut(),
         desc: crate::str::as_char_ptr_in_const_context(T::INFO.desc).cast_mut(),
 
-        driver_features: drm::driver::FEAT_GEM,
+        driver_features: Self::compute_features(),
         ioctls: T::IOCTLS.as_ptr(),
         num_ioctls: T::IOCTLS.len() as i32,
         fops: &Self::GEM_FOPS,
rust/kernel/drm/driver.rs +2 -0
index 5233bdebc9fc..92cbc26ce11f 100644
@@ -16,6 +16,8 @@
 
 /// Driver use the GEM memory manager. This should be set for all modern drivers.
 pub(crate) const FEAT_GEM: u32 = bindings::drm_driver_feature_DRIVER_GEM;
+/// Driver supports render nodes, i.e.: /dev/dri/renderDXX devices.
+pub(crate) const FEAT_RENDER: u32 = bindings::drm_driver_feature_DRIVER_RENDER;
 
 /// Information data for a DRM Driver.
 pub struct DriverInfo {

rust/kernel/drm/driver.rs pub trait Driver { · line 122

Quoted 6 lines
rust/kernel/drm/driver.rs +3 -0
@@ -115,6 +117,9 @@ pub trait Driver {
 
     /// IOCTL list. See `kernel::drm::ioctl::declare_drm_ioctls!{}`.
     const IOCTLS: &'static [drm::ioctl::DrmIoctlDescriptor];
+
+    /// Sets the `DRIVER_RENDER` feature for this driver.
+    const RENDER_CAPABILITY: bool = false;

I think it would be nice for this documentation to elaborate more on what this feature actually does. After all, it clearly took us a while to understand it, so probably others are confused too.

Something along these lines:

/// Sets the DRIVER_RENDER feature for this driver.
///
/// When enabled, the driver exposes /dev/dri/renderDXX render nodes to /// userspace. The render node is an alternate low-priviledge way to access /// the driver, which is enforced on a per-ioctl level. Userspace processes /// that open the render node can only invoke ioctls explicitly listed as /// usable from the render node, whereas userspace processes using the /// master node can invoke any ioctl.
const RENDER_CAPABILITY: bool = false;

Also, I'd probably call this const FEAT_RENDER for consistency / to make it show up in grep.

Alice

author
#3 lore raw

Re: [PATCH v2 1/1] rust: drm: add RENDER_CAPABILITY flag for render node support

Hi Alice,

Quoted 7 lines · Alice Ryhl

I think it would be nice for this documentation to elaborate more on what this feature actually does. After all, it clearly took us a while to understand it, so probably others are confused too.

Something along these lines:

Quoted 10 lines

/// Sets the DRIVER_RENDER feature for this driver.
///
/// When enabled, the driver exposes /dev/dri/renderDXX render nodes to /// userspace. The render node is an alternate low-priviledge way to access /// the driver, which is enforced on a per-ioctl level. Userspace processes /// that open the render node can only invoke ioctls explicitly listed as /// usable from the render node, whereas userspace processes using the /// master node can invoke any ioctl.
const RENDER_CAPABILITY: bool = false;

Agreed, the extra documentation will definitely help clarify the flag purpose. Thanks for the feedback!

Quoted 3 lines

Also, I'd probably call this const FEAT_RENDER for consistency / to make it show up in grep.

Right, using FEAT_RENDER in the Driver trait as well sounds good to me. I'll submit a new revision with these changes.

Best,

Laura