Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Align engine->uabi_class/instance with i915_drm.h

In our ABI we have defined I915_ENGINE_CLASS_INVALID_NONE and
I915_ENGINE_CLASS_INVALID_VIRTUAL as negative values which creates
implicit coupling with type widths used in, also ABI, struct
i915_engine_class_instance.

One place where we export engine->uabi_class
I915_ENGINE_CLASS_INVALID_VIRTUAL is from our our tracepoints. Because the
type of the former is u8 in contrast to u16 defined in the ABI, 254 will
be returned instead of 65534 which userspace would legitimately expect.

Another place is I915_CONTEXT_PARAM_ENGINES.

Therefore we need to align the type used to store engine ABI class and
instance.

v2:
* Update the commit message mentioning get_engines and cc stable.
(Chris)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Fixes: 6d06779e8672 ("drm/i915: Load balancing across a virtual engine")
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: <stable@vger.kernel.org> # v5.3+
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20200116134508.25211-1-tvrtko.ursulin@linux.intel.com

+8 -8
+6 -6
drivers/gpu/drm/i915/gem/i915_gem_busy.c
··· 9 9 #include "i915_gem_ioctls.h" 10 10 #include "i915_gem_object.h" 11 11 12 - static __always_inline u32 __busy_read_flag(u8 id) 12 + static __always_inline u32 __busy_read_flag(u16 id) 13 13 { 14 - if (id == (u8)I915_ENGINE_CLASS_INVALID) 14 + if (id == (u16)I915_ENGINE_CLASS_INVALID) 15 15 return 0xffff0000u; 16 16 17 17 GEM_BUG_ON(id >= 16); 18 18 return 0x10000u << id; 19 19 } 20 20 21 - static __always_inline u32 __busy_write_id(u8 id) 21 + static __always_inline u32 __busy_write_id(u16 id) 22 22 { 23 23 /* 24 24 * The uABI guarantees an active writer is also amongst the read ··· 29 29 * last_read - hence we always set both read and write busy for 30 30 * last_write. 31 31 */ 32 - if (id == (u8)I915_ENGINE_CLASS_INVALID) 32 + if (id == (u16)I915_ENGINE_CLASS_INVALID) 33 33 return 0xffffffffu; 34 34 35 35 return (id + 1) | __busy_read_flag(id); 36 36 } 37 37 38 38 static __always_inline unsigned int 39 - __busy_set_if_active(const struct dma_fence *fence, u32 (*flag)(u8 id)) 39 + __busy_set_if_active(const struct dma_fence *fence, u32 (*flag)(u16 id)) 40 40 { 41 41 const struct i915_request *rq; 42 42 ··· 57 57 return 0; 58 58 59 59 /* Beware type-expansion follies! */ 60 - BUILD_BUG_ON(!typecheck(u8, rq->engine->uabi_class)); 60 + BUILD_BUG_ON(!typecheck(u16, rq->engine->uabi_class)); 61 61 return flag(rq->engine->uabi_class); 62 62 } 63 63
+2 -2
drivers/gpu/drm/i915/gt/intel_engine_types.h
··· 278 278 u8 class; 279 279 u8 instance; 280 280 281 - u8 uabi_class; 282 - u8 uabi_instance; 281 + u16 uabi_class; 282 + u16 uabi_instance; 283 283 284 284 u32 uabi_capabilities; 285 285 u32 context_size;