Skip to content

Commit ceb9f34

Browse files
itoralPhil Elwell
authored andcommitted
drm/v3d: clean caches at the end of render jobs on request from user space
Extends the user space ioctl for CL submissions so it can include a request to flush the cache once the CL execution has completed. Fixes memory write violation messages reported by the kernel in workloads involving shader memory writes (SSBOs, shader images, scratch, etc) which sometimes also lead to GPU resets during Piglit and CTS workloads. v2: if v3d_job_init() fails we need to kfree() the job instead of v3d_job_put() it (Eric Anholt). v3 (Eric Anholt): - Drop _FLAG suffix from the new flag name. - Add a new param so userspace can tell whether cache flushing is implemented in the kernel. Signed-off-by: Iago Toral Quiroga <itoral@igalia.com>
1 parent ddee93d commit ceb9f34

3 files changed

Lines changed: 53 additions & 10 deletions

File tree

‎drivers/gpu/drm/v3d/v3d_drv.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data,
117117
case DRM_V3D_PARAM_SUPPORTS_CSD:
118118
args->value = v3d_has_csd(v3d);
119119
return 0;
120+
case DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH:
121+
args->value = 1;
122+
return 0;
120123
default:
121124
DRM_DEBUG("Unknown parameter %d\n", args->param);
122125
return -EINVAL;

‎drivers/gpu/drm/v3d/v3d_gem.c‎

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,16 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
649649
struct drm_v3d_submit_cl *args = data;
650650
struct v3d_bin_job *bin = NULL;
651651
struct v3d_render_job *render;
652+
struct v3d_job *clean_job = NULL;
653+
struct v3d_job *last_job;
652654
struct ww_acquire_ctx acquire_ctx;
653655
int ret = 0;
654656

655657
trace_v3d_submit_cl_ioctl(&v3d->drm, args->rcl_start, args->rcl_end);
656658

657-
if (args->pad != 0) {
658-
DRM_INFO("pad must be zero: %d\n", args->pad);
659+
if (args->flags != 0 &&
660+
args->flags != DRM_V3D_SUBMIT_CL_FLUSH_CACHE) {
661+
DRM_INFO("invalid flags: %d\n", args->flags);
659662
return -EINVAL;
660663
}
661664

@@ -695,12 +698,31 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
695698
bin->render = render;
696699
}
697700

698-
ret = v3d_lookup_bos(dev, file_priv, &render->base,
701+
if (args->flags & DRM_V3D_SUBMIT_CL_FLUSH_CACHE) {
702+
clean_job = kcalloc(1, sizeof(*clean_job), GFP_KERNEL);
703+
if (!clean_job) {
704+
ret = -ENOMEM;
705+
goto fail;
706+
}
707+
708+
ret = v3d_job_init(v3d, file_priv, clean_job, v3d_job_free, 0);
709+
if (ret) {
710+
kfree(clean_job);
711+
clean_job = NULL;
712+
goto fail;
713+
}
714+
715+
last_job = clean_job;
716+
} else {
717+
last_job = &render->base;
718+
}
719+
720+
ret = v3d_lookup_bos(dev, file_priv, last_job,
699721
args->bo_handles, args->bo_handle_count);
700722
if (ret)
701723
goto fail;
702724

703-
ret = v3d_lock_bo_reservations(&render->base, &acquire_ctx);
725+
ret = v3d_lock_bo_reservations(last_job, &acquire_ctx);
704726
if (ret)
705727
goto fail;
706728

@@ -712,33 +734,49 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
712734

713735
ret = v3d_add_dep(&render->base,
714736
dma_fence_get(bin->base.done_fence));
737+
if (ret)
738+
goto fail_unreserve;
715739
}
716740

717741
ret = v3d_push_job(v3d_priv, &render->base, V3D_RENDER);
718742
if (ret)
719743
goto fail_unreserve;
744+
745+
if (clean_job) {
746+
ret = v3d_add_dep(clean_job,
747+
dma_fence_get(render->base.done_fence));
748+
if (ret)
749+
goto fail_unreserve;
750+
ret = v3d_push_job(v3d_priv, clean_job, V3D_CACHE_CLEAN);
751+
if (ret)
752+
goto fail_unreserve;
753+
}
720754
mutex_unlock(&v3d->sched_lock);
721755

722756
v3d_attach_fences_and_unlock_reservation(file_priv,
723-
&render->base,
757+
last_job,
724758
&acquire_ctx,
725759
args->out_sync,
726-
render->base.done_fence);
760+
last_job->done_fence);
727761

728762
if (bin)
729763
v3d_job_put(&bin->base);
730764
v3d_job_put(&render->base);
765+
if (clean_job)
766+
v3d_job_put(clean_job);
731767

732768
return 0;
733769

734770
fail_unreserve:
735771
mutex_unlock(&v3d->sched_lock);
736-
v3d_unlock_bo_reservations(render->base.bo,
737-
render->base.bo_count, &acquire_ctx);
772+
v3d_unlock_bo_reservations(last_job->bo,
773+
last_job->bo_count, &acquire_ctx);
738774
fail:
739775
if (bin)
740776
v3d_job_put(&bin->base);
741777
v3d_job_put(&render->base);
778+
if (clean_job)
779+
v3d_job_put(clean_job);
742780

743781
return ret;
744782
}

‎include/uapi/drm/v3d_drm.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ extern "C" {
4848
#define DRM_IOCTL_V3D_SUBMIT_TFU DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_TFU, struct drm_v3d_submit_tfu)
4949
#define DRM_IOCTL_V3D_SUBMIT_CSD DRM_IOW(DRM_COMMAND_BASE + DRM_V3D_SUBMIT_CSD, struct drm_v3d_submit_csd)
5050

51+
#define DRM_V3D_SUBMIT_CL_FLUSH_CACHE 0x01
52+
5153
/**
5254
* struct drm_v3d_submit_cl - ioctl argument for submitting commands to the 3D
5355
* engine.
@@ -124,8 +126,7 @@ struct drm_v3d_submit_cl {
124126
/* Number of BO handles passed in (size is that times 4). */
125127
__u32 bo_handle_count;
126128

127-
/* Pad, must be zero-filled. */
128-
__u32 pad;
129+
__u32 flags;
129130
};
130131

131132
/**
@@ -193,6 +194,7 @@ enum drm_v3d_param {
193194
DRM_V3D_PARAM_V3D_CORE0_IDENT2,
194195
DRM_V3D_PARAM_SUPPORTS_TFU,
195196
DRM_V3D_PARAM_SUPPORTS_CSD,
197+
DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH,
196198
};
197199

198200
struct drm_v3d_get_param {

0 commit comments

Comments
 (0)