Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Concurrent modification and unannotated lockless reads of `gpu->reset_counter` and `ctx->reset_counter` lead to data races and lost increments. --
--- Patch [2]: [PATCH v2 2/2] drm/etnaviv: Add GPU reset counters --- commit 0f536ab6e10b2d00764a49473b750d556dcda8ee Author: Christian Gmeiner <[email protected]> drm/etnaviv: Add GPU reset counters This commit adds per-GPU and per-context reset counters to etnaviv to allow userspace to detect GPU resets and determine if their context was guilty. > --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c [ ... ] > +static int etnaviv_ioctl_reset_query(struct drm_device *dev, void *data, > + struct drm_file *file) > +{ > + struct etnaviv_drm_private *priv = dev->dev_private; > + struct etnaviv_file_private *ctx = file->driver_priv; > + struct drm_etnaviv_reset_query *args = data; > + struct etnaviv_gpu *gpu; > + > + if (args->flags) > + return -EINVAL; > + > + if (args->pipe >= ETNA_MAX_PIPES) > + return -EINVAL; > + > + gpu = priv->gpu[args->pipe]; > + if (!gpu) > + return -ENXIO; > + > + args->global_reset_counter = gpu->reset_counter; > + args->context_reset_counter = ctx->reset_counter; [Severity: Medium] Is it possible for these counters to be updated concurrently while being read here? Since etnaviv_sched_timedout_job() can increment the counters on another CPU, it seems this lockless read might need READ_ONCE() to prevent load tearing and ensure the compiler doesn't optimize the read incorrectly. > + > + return 0; > +} [ ... ] > --- a/drivers/gpu/drm/etnaviv/etnaviv_sched.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_sched.c [ ... ] > @@ -79,6 +79,9 @@ static enum drm_gpu_sched_stat > etnaviv_sched_timedout_job(struct drm_sched_job > if(sched_job) > drm_sched_increase_karma(sched_job); > > + gpu->reset_counter++; > + submit->ctx->reset_counter++; [Severity: Medium] Can a single userspace context submit jobs to multiple GPU pipes that might hang at the same time? If so, could multiple per-GPU scheduler timeout workers execute etnaviv_sched_timedout_job() simultaneously? If they do, both workers would evaluate submit->ctx->reset_counter++ concurrently, which could lead to a multi-writer data race and lost increments. Would it make sense to use atomic_t for the context reset counter, or at least WRITE_ONCE() if exact counts are less critical than preventing data races? > /* get the GPU back into the init state */ > etnaviv_core_dump(submit); -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=2
