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 <[email protected]>

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/[email protected]?part=1

Reply via email to