Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Mathias Krause <minipli@grsecurity.net>, intel-gfx@lists.freedesktop.org
Cc: Jonathan Cavitt <jonathan.cavitt@intel.com>
Subject: Re: [Intel-gfx] [PATCH v2 1/2] drm/i915: Register engines early to avoid type confusion
Date: Fri, 29 Sep 2023 11:57:10 +0100	[thread overview]
Message-ID: <8e4d36a3-a36f-0c01-2331-293fc4f0df79@linux.intel.com> (raw)
In-Reply-To: <20230928182019.10256-2-minipli@grsecurity.net>


On 28/09/2023 19:20, Mathias Krause wrote:
> Commit 1ec23ed7126e ("drm/i915: Use uabi engines for the default engine
> map") switched from using for_each_engine() to for_each_uabi_engine() to
> iterate over the user engines. While this seems to be a sensible change,
> it's only safe to do when the engines are actually chained using the
> rb-tree structure which is not the case during early driver
> initialization where it can be either a lock-less list or regular
> double-linked list.
> 
> In fact, the modesetting initialization code may end up calling
> default_engines() through the fb helper code while the engines list
> is still llist_node-based:
> 
>    i915_driver_probe() ->
>      intel_display_driver_probe() ->
>        intel_fbdev_init() ->
>          drm_fb_helper_init() ->
>            drm_client_init() ->
>              drm_client_open() ->
>                drm_file_alloc() ->
>                  i915_driver_open() ->
>                    i915_gem_open() ->
>                      i915_gem_context_open() ->
>                        i915_gem_create_context() ->
>                          default_engines()
> 
> Using for_each_uabi_engine() in default_engines() is therefore wrong, as
> it would try to interpret the llist as rb-tree, making it find no engine
> at all, as the rb_left and rb_right members will still be NULL, as they
> haven't been initialized yet.
> 
> To fix this type confusion register the engines earlier and at the same
> time reduce the amount of code that has to deal with the intermediate
> llist state.
> 
> Reported-by: sanitiy checks in grsecurity

Typo in sanity - can fix up while merging.

> Suggested-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Fixes: 1ec23ed7126e ("drm/i915: Use uabi engines for the default engine map")
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> Cc: Jonathan Cavitt <jonathan.cavitt@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
> Tested on my ADL systems just fine, no rb-tree related type confusion
> any more, as expected.
> 
>   drivers/gpu/drm/i915/i915_gem.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 1f65bb33dd21..a8551ce322de 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1199,6 +1199,13 @@ int i915_gem_init(struct drm_i915_private *dev_priv)
>   			goto err_unlock;
>   	}
>   
> +	/*
> +	 * Register engines early to ensure the engine list is in its final
> +	 * rb-tree form, lowering the amount of code that has to deal with
> +	 * the intermediate llist state.
> +	 */
> +	intel_engines_driver_register(dev_priv);

Comment feels a bit too low level (for this high level component 
interface) and would probably be enough to say this completes the GEM 
initialization by populating the uabi engines, which are needed for GEM 
contexts.

Anyway, it is not that important. Many thanks for working on this and I 
will merge it once it passes our CI.

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko

> +
>   	return 0;
>   
>   	/*
> @@ -1246,8 +1253,6 @@ int i915_gem_init(struct drm_i915_private *dev_priv)
>   void i915_gem_driver_register(struct drm_i915_private *i915)
>   {
>   	i915_gem_driver_register__shrinker(i915);
> -
> -	intel_engines_driver_register(i915);
>   }
>   
>   void i915_gem_driver_unregister(struct drm_i915_private *i915)

  reply	other threads:[~2023-09-29 10:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28 18:20 [Intel-gfx] [PATCH v2 0/2] drm/i915: fix rb-tree/llist/list confusion Mathias Krause
2023-09-28 18:20 ` [Intel-gfx] [PATCH v2 1/2] drm/i915: Register engines early to avoid type confusion Mathias Krause
2023-09-29 10:57   ` Tvrtko Ursulin [this message]
2023-09-28 18:20 ` [Intel-gfx] [PATCH v2 2/2] drm/i915: Clarify type evolution of uabi_node/uabi_engines Mathias Krause
2023-09-29 11:00   ` Tvrtko Ursulin
2023-10-03  7:32     ` Tvrtko Ursulin
2023-10-04  9:52       ` Mathias Krause
2023-10-04 10:44         ` Tvrtko Ursulin
2023-09-28 19:29 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: fix rb-tree/llist/list confusion (rev2) Patchwork
2023-09-28 19:29 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-09-28 19:48 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2023-09-29  7:55 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: fix rb-tree/llist/list confusion (rev3) Patchwork
2023-09-29  7:55 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-09-29  8:07 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-09-29 12:39 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2023-10-02 19:02 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: fix rb-tree/llist/list confusion (rev4) Patchwork
2023-10-02 19:02 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-10-02 19:12 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-10-02 20:42 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8e4d36a3-a36f-0c01-2331-293fc4f0df79@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jonathan.cavitt@intel.com \
    --cc=minipli@grsecurity.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox