@@ -52,6 +52,8 @@ struct xe_eu_stall_data_stream {
5252
5353 struct xe_gt * gt ;
5454 struct xe_bo * bo ;
55+ /* Lock to protect data buffer pointers */
56+ struct mutex xecore_buf_lock ;
5557 struct per_xecore_buf * xecore_buf ;
5658 struct {
5759 bool reported_to_user ;
@@ -208,6 +210,9 @@ int xe_eu_stall_init(struct xe_gt *gt)
208210 struct xe_device * xe = gt_to_xe (gt );
209211 int ret ;
210212
213+ if (!xe_eu_stall_supported_on_platform (xe ))
214+ return 0 ;
215+
211216 gt -> eu_stall = kzalloc (sizeof (* gt -> eu_stall ), GFP_KERNEL );
212217 if (!gt -> eu_stall ) {
213218 ret = - ENOMEM ;
@@ -378,7 +383,7 @@ static bool eu_stall_data_buf_poll(struct xe_eu_stall_data_stream *stream)
378383 u16 group , instance ;
379384 unsigned int xecore ;
380385
381- mutex_lock (& gt -> eu_stall -> stream_lock );
386+ mutex_lock (& stream -> xecore_buf_lock );
382387 for_each_dss_steering (xecore , gt , group , instance ) {
383388 xecore_buf = & stream -> xecore_buf [xecore ];
384389 read_ptr = xecore_buf -> read ;
@@ -396,7 +401,7 @@ static bool eu_stall_data_buf_poll(struct xe_eu_stall_data_stream *stream)
396401 set_bit (xecore , stream -> data_drop .mask );
397402 xecore_buf -> write = write_ptr ;
398403 }
399- mutex_unlock (& gt -> eu_stall -> stream_lock );
404+ mutex_unlock (& stream -> xecore_buf_lock );
400405
401406 return min_data_present ;
402407}
@@ -511,11 +516,13 @@ static ssize_t xe_eu_stall_stream_read_locked(struct xe_eu_stall_data_stream *st
511516 unsigned int xecore ;
512517 int ret = 0 ;
513518
519+ mutex_lock (& stream -> xecore_buf_lock );
514520 if (bitmap_weight (stream -> data_drop .mask , XE_MAX_DSS_FUSE_BITS )) {
515521 if (!stream -> data_drop .reported_to_user ) {
516522 stream -> data_drop .reported_to_user = true;
517523 xe_gt_dbg (gt , "EU stall data dropped in XeCores: %*pb\n" ,
518524 XE_MAX_DSS_FUSE_BITS , stream -> data_drop .mask );
525+ mutex_unlock (& stream -> xecore_buf_lock );
519526 return - EIO ;
520527 }
521528 stream -> data_drop .reported_to_user = false;
@@ -527,6 +534,7 @@ static ssize_t xe_eu_stall_stream_read_locked(struct xe_eu_stall_data_stream *st
527534 if (ret || count == total_size )
528535 break ;
529536 }
537+ mutex_unlock (& stream -> xecore_buf_lock );
530538 return total_size ?: (ret ?: - EAGAIN );
531539}
532540
@@ -583,6 +591,7 @@ static void xe_eu_stall_stream_free(struct xe_eu_stall_data_stream *stream)
583591{
584592 struct xe_gt * gt = stream -> gt ;
585593
594+ mutex_destroy (& stream -> xecore_buf_lock );
586595 gt -> eu_stall -> stream = NULL ;
587596 kfree (stream );
588597}
@@ -718,6 +727,7 @@ static int xe_eu_stall_stream_init(struct xe_eu_stall_data_stream *stream,
718727 }
719728
720729 init_waitqueue_head (& stream -> poll_wq );
730+ mutex_init (& stream -> xecore_buf_lock );
721731 INIT_DELAYED_WORK (& stream -> buf_poll_work , eu_stall_data_buf_poll_work_fn );
722732 stream -> per_xecore_buf_size = per_xecore_buf_size ;
723733 stream -> sampling_rate_mult = props -> sampling_rate_mult ;
0 commit comments