lib/intel_batchbuffer: prefetch fixes
cover lib/intel_batchbuffer: prefetch fixes
Two patches fixing batchbuffer prefetch handling.
---
Andrzej Hajda (2):
lib/intel_batchbuffer: assert on accessing prefetch area tests/intel/xe_exec_store: increase batchbuffer size
lib/intel_batchbuffer.c | 3 ++- lib/intel_batchbuffer.h | 7 ++++--- tests/intel/xe_exec_store.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-)
---
base-commit: 636a3d128f10348488b47da605c49b775911fd89
change-id: 20260521-ibb_fixes2-0856a6d4746e
Best regards,
Signature · 1 line
Andrzej Hajda <[email protected]>
PATCH 1/2 lib/intel_batchbuffer: assert on accessing prefetch area
On batchbuffer allocation library adds 4k padding to the buffer to avoid prefetch errors. To avoid batchbuffer overflow existing asserts should compare against requested buffer size (usable_size), instead of allocated buffer size. Otherwise we risk prefetch errors.
--- lib/intel_batchbuffer.c | 3 ++- lib/intel_batchbuffer.h | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
lib/intel_batchbuffer.c +2 -1
@@ -917,6 +917,7 @@ __intel_bb_create(int fd, uint32_t ctx, uint32_t vm, const intel_ctx_cfg_t *cfg, ibb->devid =intel_get_drm_devid (fd); ibb->gen =intel_gen (ibb->devid); ibb->ctx = ctx; + ibb->usable_size = size; ibb->fd = fd; ibb->driver = is_i915_device(fd) ? INTEL_DRIVER_I915 :
@@ -2931,7 +2932,7 @@ uint32_t intel_bb_copy_data(struct intel_bb *ibb,intel_bb_ptr_align (ibb, align); offset =intel_bb_offset (ibb); -igt_assert_lt (offset + bytes, ibb->size); +igt_assert_lte (offset + bytes, ibb->usable_size); subdata =intel_bb_ptr (ibb);memcpy (subdata, data, bytes);
lib/intel_batchbuffer.h +4 -3
@@ -255,6 +255,7 @@ struct intel_bb {bool enforce_relocs;uint32_t devid;uint32_t handle; +uint32_t usable_size;uint32_t size;uint32_t *batch;uint32_t *ptr;
@@ -363,7 +364,7 @@ static inline uint32_t intel_bb_offset(struct intel_bb *ibb)static inline void *intel_bb_ptr_get (struct intel_bb *ibb,uint32_t offset) { -igt_assert (offset < ibb->size); +igt_assert (offset <= ibb->usable_size);return ((uint8_t *) ibb->batch + offset); }
@@ -372,7 +373,7 @@ static inline void intel_bb_ptr_set(struct intel_bb *ibb, uint32_t offset) { ibb->ptr = (void *) ((uint8_t *) ibb->batch + offset); -igt_assert (intel_bb_offset (ibb) <= ibb->size); +igt_assert (intel_bb_offset (ibb) <= ibb->usable_size); }static inline void intel_bb_ptr_add (struct intel_bb *ibb,uint32_t offset)
@@ -407,7 +408,7 @@ static inline void intel_bb_out(struct intel_bb *ibb, uint32_t dword) *ibb->ptr = dword; ibb->ptr++; -igt_assert (intel_bb_offset (ibb) <= ibb->size); +igt_assert (intel_bb_offset (ibb) <= ibb->usable_size); } void intel_bb_set_pxp(struct intel_bb *ibb, bool new_state,
Signature · 1 line
2.54.0
Re: [PATCH 1/2] lib/intel_batchbuffer: assert on accessing prefetch area
Hi Andrzej,
Quoted 45 lines · Andrzej Hajda
On batchbuffer allocation library adds 4k padding to the buffer to avoid prefetch errors. To avoid batchbuffer overflow existing asserts should compare against requested buffer size (
usable_size), instead of allocated buffer size. Otherwise we risk prefetch errors.Signed-off-by Andrzej Hajda <[email protected]>--- lib/intel_batchbuffer.c | 3 ++- lib/intel_batchbuffer.h | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)lib/intel_batchbuffer.c +2
-1@@ -917,6 +917,7 @@ __intel_bb_create(int fd, uint32_t ctx, uint32_t vm, const intel_ctx_cfg_t *cfg, ibb->devid =intel_get_drm_devid (fd); ibb->gen =intel_gen (ibb->devid); ibb->ctx = ctx; + ibb->usable_size = size; ibb->fd = fd; ibb->driver = is_i915_device(fd) ? INTEL_DRIVER_I915 :@@ -2931,7 +2932,7 @@ uint32_t intel_bb_copy_data(struct intel_bb *ibb,intel_bb_ptr_align (ibb, align); offset =intel_bb_offset (ibb); -igt_assert_lt (offset + bytes, ibb->size); +igt_assert_lte (offset + bytes, ibb->usable_size); subdata =intel_bb_ptr (ibb);memcpy (subdata, data, bytes);lib/intel_batchbuffer.h +1
-0@@ -255,6 +255,7 @@ struct intel_bb {bool enforce_relocs;uint32_t devid;uint32_t handle; +uint32_t usable_size;uint32_t size;uint32_t *batch;uint32_t *ptr;
lib/intel_batchbuffer.h static inline uint32_t intel_bb_offset(struct intel_bb *ibb) · line 367
Quoted 5 lines
lib/intel_batchbuffer.h +1
-1@@ -363,7 +364,7 @@ static inline uint32_t intel_bb_offset(struct intel_bb *ibb)static inline void *intel_bb_ptr_get (struct intel_bb *ibb,uint32_t offset) { -igt_assert (offset < ibb->size); +igt_assert (offset <= ibb->usable_size);
Can you use here igt_assert_lte?
lib/intel_batchbuffer.h static inline void intel_bb_ptr_set(struct intel_bb *ibb, uint32_t offset) · line 376
Quoted 9 lines
lib/intel_batchbuffer.h +1
-1return ((uint8_t *) ibb->batch + offset); }@@ -372,7 +373,7 @@ static inline void intel_bb_ptr_set(struct intel_bb *ibb, uint32_t offset) { ibb->ptr = (void *) ((uint8_t *) ibb->batch + offset); -igt_assert (intel_bb_offset (ibb) <= ibb->size); +igt_assert (intel_bb_offset (ibb) <= ibb->usable_size);
Same here.
lib/intel_batchbuffer.h static inline void intel_bb_out(struct intel_bb *ibb, uint32_t dword) · line 411
Quoted 9 lines
lib/intel_batchbuffer.h +1
-1}static inline void intel_bb_ptr_add (struct intel_bb *ibb,uint32_t offset)@@ -407,7 +408,7 @@ static inline void intel_bb_out(struct intel_bb *ibb, uint32_t dword) *ibb->ptr = dword; ibb->ptr++; -igt_assert (intel_bb_offset (ibb) <= ibb->size); +igt_assert (intel_bb_offset (ibb) <= ibb->usable_size);
Same here.
With above fixed
Regards,
Kamil
Quoted 7 lines
lib/intel_batchbuffer.h +0
-0} void intel_bb_set_pxp(struct intel_bb *ibb, bool new_state,Signature · 2 lines
-- 2.54.0
PATCH 2/2 tests/intel/xe_exec_store: increase batchbuffer size
In reply to Andrzej HajdaIn case of some platforms 32K is too small for the shader.
--- tests/intel/xe_exec_store.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/intel/xe_exec_store.c +1 -1
@@ -352,7 +352,7 @@ static void long_shader(int fd, struct drm_xe_engine_class_instance *hwe, {const uint64_t target_offset =0x1a000000 ;const uint64_t bb_offset =0x1b000000 ; -const size_t bb_size =32768 ; +const size_t bb_size =65536 ;uint32_t vm_id;uint32_t exec_queue;const unsigned int instruction_count =128 ;
Signature · 1 line
2.54.0
Re: [PATCH 2/2] tests/intel/xe_exec_store: increase batchbuffer size
Hi Andrzej,
Quoted 12 lines · Andrzej Hajda
In case of some platforms 32K is too small for the shader.
Signed-off-by Andrzej Hajda <[email protected]>--- tests/intel/xe_exec_store.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/intel/xe_exec_store.c +0
-0
tests/intel/xe_exec_store.c static void long_shader(int fd, struct drm_xe_engine_class_instance *hwe, · line 355
Quoted 5 lines
tests/intel/xe_exec_store.c +1
-1@@ -352,7 +352,7 @@ static void long_shader(int fd, struct drm_xe_engine_class_instance *hwe, {const uint64_t target_offset =0x1a000000 ;const uint64_t bb_offset =0x1b000000 ; -const size_t bb_size =32768 ; +const size_t bb_size =65536 ;
LGTM
Regards,
Kamil
Quoted 7 lines
tests/intel/xe_exec_store.c +0
-0uint32_t vm_id;uint32_t exec_queue;const unsigned int instruction_count =128 ;Signature · 2 lines
-- 2.54.0
Re: [PATCH 2/2] tests/intel/xe_exec_store: increase batchbuffer size
In reply to Andrzej HajdaQuoted 12 lines · Andrzej Hajda
In case of some platforms 32K is too small for the shader.
Signed-off-by Andrzej Hajda <[email protected]>--- tests/intel/xe_exec_store.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/intel/xe_exec_store.c +0
-0
tests/intel/xe_exec_store.c static void long_shader(int fd, struct drm_xe_engine_class_instance *hwe, · line 355
Quoted 5 lines
tests/intel/xe_exec_store.c +1
-1@@ -352,7 +352,7 @@ static void long_shader(int fd, struct drm_xe_engine_class_instance *hwe, {const uint64_t target_offset =0x1a000000 ;const uint64_t bb_offset =0x1b000000 ; -const size_t bb_size =32768 ; +const size_t bb_size =65536 ;
I think we can now use SZ_64K.
But that's minor and may stay as it is.
--
Zbigniew
Quoted 7 lines
tests/intel/xe_exec_store.c +0
-0uint32_t vm_id;uint32_t exec_queue;const unsigned int instruction_count =128 ;Signature · 2 lines
-- 2.54.0