[1/2] Ensure that DRM device uses the i915 driver

Submitted by Mark Thompson on Jan. 23, 2018, 10:52 p.m.

Details

Message ID c8c2cc2d-66e7-57d9-f258-a8e1fd70b33c@jkqxz.net
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Mark Thompson Jan. 23, 2018, 10:52 p.m.
This avoids calling random ioctl()s and returning nonsensical errors for
unsupported devices.  In particular, loading is much cleaner on setups
where the driver needs to iterate over multiple devices to find the correct
one because the Intel graphics device is not the first DRM device.
---
Fixes this sort of spam from every OpenCL-using application:

$ clinfo 
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
Number of platforms                               1
  Platform Name                                   Intel Gen OCL Driver
  Platform Vendor                                 Intel
  Platform Version                                OpenCL 2.0 beignet 1.4 (git-d1b99a1d)
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_3d_image_writes cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_spir cl_khr_icd cl_intel_accelerator cl_intel_subgroups cl_intel_subgroups_short cl_intel_media_block_io cl_intel_planar_yuv cl_khr_gl_sharing
  Platform Extensions function suffix             Intel
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0

  Platform Name                                   Intel Gen OCL Driver
Number of devices                                 1
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument
Assuming 131072kB available aperture size.
May lead to reduced performance or incorrect rendering.
get chip id failed: -1 [2]
param: 4, val: 0
...


 src/intel/intel_driver.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
index 45719785..10fe3cc8 100644
--- a/src/intel/intel_driver.c
+++ b/src/intel/intel_driver.c
@@ -312,6 +312,26 @@  return ret;
 }
 #endif
 
+static int
+intel_driver_check_device(int dev_fd)
+{
+  // Ensure that this is actually an i915 DRM device.
+  drmVersion *version;
+  int ret;
+  version = drmGetVersion(dev_fd);
+  if (!version) {
+    fprintf(stderr, "drmGetVersion(%d) failed: %s\n", dev_fd, strerror(errno));
+    close(dev_fd);
+    return 0;
+  }
+  ret = !strcmp(version->name, "i915");
+  drmFreeVersion(version);
+  // Don't print an error here if this device is using a different driver,
+  // because we might be iterating over multiple devices looking for a
+  // compatible one.
+  return ret;
+}
+
 LOCAL int
 intel_driver_init_master(intel_driver_t *driver, const char* dev_name)
 {
@@ -326,6 +346,11 @@  if (dev_fd == -1) {
   return 0;
 }
 
+if (!intel_driver_check_device(dev_fd)) {
+  close(dev_fd);
+  return 0;
+}
+
 // Check that we're authenticated
 memset(&client, 0, sizeof(drm_client_t));
 ret = ioctl(dev_fd, DRM_IOCTL_GET_CLIENT, &client);
@@ -356,6 +381,11 @@  dev_fd = open(dev_name, O_RDWR);
 if (dev_fd == -1)
   return 0;
 
+if (!intel_driver_check_device(dev_fd)) {
+  close(dev_fd);
+  return 0;
+}
+
 ret = intel_driver_init(driver, dev_fd);
 driver->need_close = 1;
 

Comments

This patch LGTM, thanks.

> -----Original Message-----

> From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf Of

> Mark Thompson

> Sent: Wednesday, January 24, 2018 6:52 AM

> To: beignet@lists.freedesktop.org

> Subject: [Beignet] [PATCH 1/2] Ensure that DRM device uses the i915 driver

> 

> This avoids calling random ioctl()s and returning nonsensical errors for

> unsupported devices.  In particular, loading is much cleaner on setups where the

> driver needs to iterate over multiple devices to find the correct one because the

> Intel graphics device is not the first DRM device.

> ---

> Fixes this sort of spam from every OpenCL-using application:

> 

> $ clinfo

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> Number of platforms                               1

>   Platform Name                                   Intel Gen OCL Driver

>   Platform Vendor                                 Intel

>   Platform Version                                OpenCL 2.0 beignet 1.4 (git-d1b99a1d)

>   Platform Profile                                FULL_PROFILE

>   Platform Extensions                             cl_khr_global_int32_base_atomics

> cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics

> cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store

> cl_khr_3d_image_writes cl_khr_image2d_from_buffer cl_khr_depth_images

> cl_khr_spir cl_khr_icd cl_intel_accelerator cl_intel_subgroups

> cl_intel_subgroups_short cl_intel_media_block_io cl_intel_planar_yuv

> cl_khr_gl_sharing

>   Platform Extensions function suffix             Intel

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> 

>   Platform Name                                   Intel Gen OCL Driver

> Number of devices                                 1

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> DRM_IOCTL_I915_GEM_APERTURE failed: Invalid argument Assuming 131072kB

> available aperture size.

> May lead to reduced performance or incorrect rendering.

> get chip id failed: -1 [2]

> param: 4, val: 0

> ...

> 

> 

>  src/intel/intel_driver.c | 30 ++++++++++++++++++++++++++++++

>  1 file changed, 30 insertions(+)

> 

> diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c index

> 45719785..10fe3cc8 100644

> --- a/src/intel/intel_driver.c

> +++ b/src/intel/intel_driver.c

> @@ -312,6 +312,26 @@ return ret;

>  }

>  #endif

> 

> +static int

> +intel_driver_check_device(int dev_fd)

> +{

> +  // Ensure that this is actually an i915 DRM device.

> +  drmVersion *version;

> +  int ret;

> +  version = drmGetVersion(dev_fd);

> +  if (!version) {

> +    fprintf(stderr, "drmGetVersion(%d) failed: %s\n", dev_fd, strerror(errno));

> +    close(dev_fd);

> +    return 0;

> +  }

> +  ret = !strcmp(version->name, "i915");

> +  drmFreeVersion(version);

> +  // Don't print an error here if this device is using a different

> +driver,

> +  // because we might be iterating over multiple devices looking for a

> +  // compatible one.

> +  return ret;

> +}

> +

>  LOCAL int

>  intel_driver_init_master(intel_driver_t *driver, const char* dev_name)  { @@ -

> 326,6 +346,11 @@ if (dev_fd == -1) {

>    return 0;

>  }

> 

> +if (!intel_driver_check_device(dev_fd)) {

> +  close(dev_fd);

> +  return 0;

> +}

> +

>  // Check that we're authenticated

>  memset(&client, 0, sizeof(drm_client_t));  ret = ioctl(dev_fd,

> DRM_IOCTL_GET_CLIENT, &client); @@ -356,6 +381,11 @@ dev_fd =

> open(dev_name, O_RDWR);  if (dev_fd == -1)

>    return 0;

> 

> +if (!intel_driver_check_device(dev_fd)) {

> +  close(dev_fd);

> +  return 0;

> +}

> +

>  ret = intel_driver_init(driver, dev_fd);  driver->need_close = 1;

> 

> --

> 2.11.0

> _______________________________________________

> Beignet mailing list

> Beignet@lists.freedesktop.org

> https://lists.freedesktop.org/mailman/listinfo/beignet