Skip to content

Commit 7c567bb

Browse files
mwajdeczdanvet
authored andcommitted
drm/i915/guc: Start protecting access to CTB descriptors
We want to stop using guc.send_mutex while sending CTB messages so we have to start protecting access to CTB send descriptor. For completeness protect also CTB receive descriptor. Add spinlock to struct intel_guc_ct_buffer and start using it. Signed-off-by: Michal Wajdeczko <[email protected]> Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent df12d1c commit 7c567bb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ static void ct_incoming_request_worker_func(struct work_struct *w);
8989
*/
9090
void intel_guc_ct_init_early(struct intel_guc_ct *ct)
9191
{
92+
spin_lock_init(&ct->ctbs.send.lock);
93+
spin_lock_init(&ct->ctbs.recv.lock);
9294
spin_lock_init(&ct->requests.lock);
9395
INIT_LIST_HEAD(&ct->requests.pending);
9496
INIT_LIST_HEAD(&ct->requests.incoming);
@@ -473,17 +475,22 @@ static int ct_send(struct intel_guc_ct *ct,
473475
GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK);
474476
GEM_BUG_ON(!response_buf && response_buf_size);
475477

478+
spin_lock_irqsave(&ct->ctbs.send.lock, flags);
479+
476480
fence = ct_get_next_fence(ct);
477481
request.fence = fence;
478482
request.status = 0;
479483
request.response_len = response_buf_size;
480484
request.response_buf = response_buf;
481485

482-
spin_lock_irqsave(&ct->requests.lock, flags);
486+
spin_lock(&ct->requests.lock);
483487
list_add_tail(&request.link, &ct->requests.pending);
484-
spin_unlock_irqrestore(&ct->requests.lock, flags);
488+
spin_unlock(&ct->requests.lock);
485489

486490
err = ct_write(ct, action, len, fence);
491+
492+
spin_unlock_irqrestore(&ct->ctbs.send.lock, flags);
493+
487494
if (unlikely(err))
488495
goto unlink;
489496

@@ -819,6 +826,7 @@ static int ct_handle_request(struct intel_guc_ct *ct, const u32 *msg)
819826
void intel_guc_ct_event_handler(struct intel_guc_ct *ct)
820827
{
821828
u32 msg[GUC_CT_MSG_LEN_MASK + 1]; /* one extra dw for the header */
829+
unsigned long flags;
822830
int err = 0;
823831

824832
if (unlikely(!ct->enabled)) {
@@ -827,7 +835,9 @@ void intel_guc_ct_event_handler(struct intel_guc_ct *ct)
827835
}
828836

829837
do {
838+
spin_lock_irqsave(&ct->ctbs.recv.lock, flags);
830839
err = ct_read(ct, msg);
840+
spin_unlock_irqrestore(&ct->ctbs.recv.lock, flags);
831841
if (err)
832842
break;
833843

drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ struct intel_guc;
2727
* record (command transport buffer descriptor) and the actual buffer which
2828
* holds the commands.
2929
*
30+
* @lock: protects access to the commands buffer and buffer descriptor
3031
* @desc: pointer to the buffer descriptor
3132
* @cmds: pointer to the commands buffer
3233
* @size: size of the commands buffer
3334
*/
3435
struct intel_guc_ct_buffer {
36+
spinlock_t lock;
3537
struct guc_ct_buffer_desc *desc;
3638
u32 *cmds;
3739
u32 size;

0 commit comments

Comments
 (0)