drm/i915: Clarify type evolution of uabi_node/uabi_engines

Chaining user engines happens in multiple passes during driver
initialization, mutating its type along the way. It starts off with a
simple lock-less linked list (struct llist_node/head) populated by
intel_engine_add_user() which later gets sorted and converted to an
intermediate regular list (struct list_head) just to be converted once
more to its final rb-tree structure (struct rb_node/root) in
intel_engines_driver_register().

All of these types overlay the uabi_node/uabi_engines members which is
unfortunate but safe if one takes care about using the rb-tree based
structure only after the conversion has completed. However, mistakes
happen and commit 1ec23ed712 ("drm/i915: Use uabi engines for the
default engine map") violated that assumption, as the multiple type
evolution was all to easy hidden behind casts papering over it.

Make the type evolution of uabi_node/uabi_engines more visible by
putting all members into an anonymous union and use the correctly typed
member in its various users. This allows us to drop quite some ugly
casts and, hopefully, make the evolution of the members better
recognisable to avoid future mistakes.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230928182019.10256-3-minipli@grsecurity.net
This commit is contained in:
Mathias Krause
2023-09-28 20:20:19 +02:00
committed by Tvrtko Ursulin
parent 2b562f032f
commit 9c303439c4
3 changed files with 32 additions and 12 deletions

View File

@@ -222,7 +222,22 @@ struct drm_i915_private {
bool mchbar_need_disable;
} gmch;
struct rb_root uabi_engines;
/*
* Chaining user engines happens in multiple stages, starting with a
* simple lock-less linked list created by intel_engine_add_user(),
* which later gets sorted and converted to an intermediate regular
* list, just to be converted once again to its final rb tree structure
* in intel_engines_driver_register().
*
* Make sure to use the right iterator helper, depending on if the code
* in question runs before or after intel_engines_driver_register() --
* for_each_uabi_engine() can only be used afterwards!
*/
union {
struct llist_head uabi_engines_llist;
struct list_head uabi_engines_list;
struct rb_root uabi_engines;
};
unsigned int engine_uabi_class_count[I915_LAST_UABI_ENGINE_CLASS + 1];
/* protects the irq masks */