All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
	dri-devel@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/4] drm/sched: Disallow initializing entities with un-initialized schedulers
Date: Tue, 17 Nov 2026 10:46:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-218670@kernel.org> (raw)
In-Reply-To: <20261117100654.8593-2-tvrtko.ursulin@igalia.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/sched: drm_sched_entity_init() breaks v3d_open() on V3D 3.3
- [Medium] drm/sched: uninitialized SR-IOV VCN0 scheduler in
  vcn_v3_0_limit_sched()
--

commit 5a80b965f793708bcd7eab260f9a3099009c1c8c
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

drm/sched: Disallow initializing entities with un-initialized schedulers

This commit rejects uninitialized schedulers (where sched_rq is NULL) in
drm_sched_entity_init() with -EINVAL and in drm_sched_entity_modify_sched()
with a WARN_ON() and early return.

> diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
> index 03e68b4102d50..2844049d4c665 100644
> --- a/drivers/gpu/drm/scheduler/sched_entity.c
> +++ b/drivers/gpu/drm/scheduler/sched_entity.c
> @@ -119,9 +119,16 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
>  			  unsigned int num_sched_list,
>  			  atomic_t *guilty)
>  {
> -	if (!entity || !sched_list || !num_sched_list || !sched_list[0])
> +	unsigned int i;
> +
> +	if (!entity || !sched_list || !num_sched_list)
>  		return -EINVAL;
>  
> +	for (i = 0; i < num_sched_list; i++) {
> +		if (!sched_list[i] || !sched_list[i]->sched_rq)
> +			return -EINVAL;
> +	}

[Severity: High]
Does returning -EINVAL here break v3d_open() on V3D 3.3 hardware?

On V3D 3.3, v3d_has_csd(v3d) is false, so v3d_sched_init() skips
v3d_queue_sched_init() for V3D_CSD and V3D_CACHE_CLEAN, leaving their
sched_rq pointers NULL:

drivers/gpu/drm/v3d/v3d_sched.c:v3d_sched_init() {
    ...
	if (v3d_has_csd(v3d)) {
		ret = v3d_queue_sched_init(v3d, &v3d_csd_sched_ops, V3D_CSD,
					   "v3d_csd");
		if (ret)
			goto fail;

		ret = v3d_queue_sched_init(v3d, &v3d_cache_clean_sched_ops,
					   V3D_CACHE_CLEAN, "v3d_cache_clean");
    ...
}

v3d_open() unconditionally calls drm_sched_entity_init() for all
V3D_MAX_QUEUES and aborts if it returns an error:

drivers/gpu/drm/v3d/v3d_drv.c:v3d_open() {
    ...
	for (i = 0; i < V3D_MAX_QUEUES; i++) {
		...
		sched = &v3d->queue[i].sched;
		ret = drm_sched_entity_init(&v3d_priv->sched_entity[i],
					    DRM_SCHED_PRIORITY_NORMAL, &sched,
					    1, NULL);
		if (ret)
			goto err_sched;
	}
    ...
}

Previously drm_sched_entity_init() logged a warning and returned 0; with
this regression, every open() of the DRM device node on V3D 3.3 fails with
-EINVAL.

[ ... ]

> @@ -192,7 +192,15 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
>  				    struct drm_gpu_scheduler **sched_list,
>  				    unsigned int num_sched_list)
>  {
> -	WARN_ON(!num_sched_list || !sched_list);
> +	unsigned int i;
> +
> +	if (WARN_ON(!num_sched_list || !sched_list))
> +		return;
> +
> +	for (i = 0; i < num_sched_list; i++) {
> +		if (WARN_ON(!sched_list[i] || !sched_list[i]->sched_rq))
> +			return;
> +	}

[Severity: Medium]
Can vcn_v3_0_limit_sched() hit this WARN_ON() when VCN0 decode is disabled
by the hypervisor under SR-IOV?

During vcn_v3_0_sw_init(), amdgpu_ring_init() places &inst[0].ring_dec.sched
into adev->gpu_sched[AMDGPU_HW_IP_VCN_DEC][AMDGPU_RING_PRIO_DEFAULT].sched[0].
Later, vcn_v3_0_hw_init() sets ring->no_scheduler = true when the hypervisor
has disabled VCN0 decode, which causes amdgpu_device_init_schedulers() to
skip drm_sched_init() and leave sched[0]->sched_rq NULL:

drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c:vcn_v3_0_hw_init() {
    ...
			if (amdgpu_vcn_is_disabled_vcn(adev, VCN_DECODE_RING, i)) {
				ring->sched.ready = false;
				ring->no_scheduler = true;
				dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
			}
    ...
}

Because vcn_v3_0_early_init() sets adev->vcn.harvest_config = 0 on SR-IOV,
an AV1 decode submission on VCN1 reaches vcn_v3_0_limit_sched(), passes the
AMDGPU_VCN_HARVEST_VCN0 check, and passes that uninitialized sched[0] to
drm_sched_entity_modify_sched():

drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c:vcn_v3_0_limit_sched() {
	struct drm_gpu_scheduler **scheds;

	/* The create msg must be in the first IB submitted */
	if (atomic_read(&job->base.entity->fence_seq))
		return -EINVAL;

	/* if VCN0 is harvested, we can't support AV1 */
	if (p->adev->vcn.harvest_config & AMDGPU_VCN_HARVEST_VCN0)
		return -EINVAL;

	scheds = p->adev->gpu_sched[AMDGPU_HW_IP_VCN_DEC]
		[AMDGPU_RING_PRIO_DEFAULT].sched;
	drm_sched_entity_modify_sched(job->base.entity, scheds, 1);
	return 0;
}

An unprivileged guest user submitting an AV1 decode job can trigger the
WARN_ON(), and the early return leaves the unsupported AV1 job scheduled on
VCN1.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117100654.8593-1-tvrtko.ursulin@igalia.com?part=1

  reply	other threads:[~2026-11-17 10:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 10:06 [PATCH 0/4] drm/sched: Entity handling cleanups Tvrtko Ursulin
2026-11-17 10:06 ` [PATCH 1/4] drm/sched: Disallow initializing entities with un-initialized schedulers Tvrtko Ursulin
2026-11-17 10:46   ` sashiko-bot [this message]
2026-11-17 12:11     ` Tvrtko Ursulin
2026-11-17 12:00   ` Philipp Stanner
2026-11-17 12:17     ` Tvrtko Ursulin
2026-11-17 10:06 ` [PATCH 2/4] drm/sched: Ignore stopped entity attempt to change its run-queue Tvrtko Ursulin
2026-11-17 11:53   ` Philipp Stanner
2026-11-17 13:04     ` Tvrtko Ursulin
2026-11-17 10:06 ` [PATCH 3/4] drm/sched: Remove the single scheduler special case Tvrtko Ursulin
2026-11-17 10:25   ` sashiko-bot
2026-11-17 10:06 ` [PATCH 4/4] drm/sched: Address the fence_seq fixme Tvrtko Ursulin

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=sashiko-outbox-218670@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tvrtko.ursulin@igalia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.