Skip to contentSkip to conversation

accel/amdxdna: Fix order of canceled mailbox messages

PATCH In review Lizhi Hou 2 participants 3 messages Apr 13 – Apr 14

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Fix order of canceled mailbox messages

Mailbox message IDs are allocated cyclically. When destroying a mailbox channel, pending messages are canceled starting from message ID 0. This results in an incorrect cancellation order when the ID of the last posted message wraps around and is smaller than the ID of the first posted message.

Fix this by canceling pending messages starting from the next available message ID, ensuring the correct ordering across wraparound.

Fixes a37d78470bcc ("accel/amdxdna: Replace idr api with xarray")
---
 drivers/accel/amdxdna/amdxdna_mailbox.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_mailbox.c +3 -1
index 84a7e92562ad..336e5e77f18a 100644
@@ -549,7 +549,9 @@ void xdna_mailbox_stop_channel(struct mailbox_channel *mb_chann)
 	drain_workqueue(mb_chann->work_q);
 
 	/* We can clean up and release resources */
-	xa_for_each(&mb_chann->chan_xa, msg_id, mb_msg)
+	xa_for_each_start(&mb_chann->chan_xa, msg_id, mb_msg, mb_chann->next_msgid)
+		mailbox_release_msg(mb_chann, mb_msg);
+	xa_for_each_range(&mb_chann->chan_xa, msg_id, mb_msg, 0, mb_chann->next_msgid - 1)
 		mailbox_release_msg(mb_chann, mb_msg);
 	xa_destroy(&mb_chann->chan_xa);
 
Signature · 1 line
2.34.1
Reviewed-by Mario Limonciello (AMD) on v1 1/1
#1 lore raw
Quoted 11 lines · Lizhi Hou

Mailbox message IDs are allocated cyclically. When destroying a mailbox channel, pending messages are canceled starting from message ID 0. This results in an incorrect cancellation order when the ID of the last posted message wraps around and is smaller than the ID of the first posted message.

Fix this by canceling pending messages starting from the next available message ID, ensuring the correct ordering across wraparound.

Fixes a37d78470bcc ("accel/amdxdna: Replace idr api with xarray")
Quoted 19 lines
---
  drivers/accel/amdxdna/amdxdna_mailbox.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_mailbox.c +3 -1
index 84a7e92562ad..336e5e77f18a 100644
@@ -549,7 +549,9 @@ void xdna_mailbox_stop_channel(struct mailbox_channel *mb_chann)
  	drain_workqueue(mb_chann->work_q);
 
  	/* We can clean up and release resources */
-	xa_for_each(&mb_chann->chan_xa, msg_id, mb_msg)
+	xa_for_each_start(&mb_chann->chan_xa, msg_id, mb_msg, mb_chann->next_msgid)
+		mailbox_release_msg(mb_chann, mb_msg);
+	xa_for_each_range(&mb_chann->chan_xa, msg_id, mb_msg, 0, mb_chann->next_msgid - 1)
  		mailbox_release_msg(mb_chann, mb_msg);
  	xa_destroy(&mb_chann->chan_xa);
 
author maintainer Applied
#2 lore raw

Applied to drm-misc-next

Quoted 36 lines · Mario Limonciello
Quoted 11 lines · Lizhi Hou

Mailbox message IDs are allocated cyclically. When destroying a mailbox channel, pending messages are canceled starting from message ID 0. This results in an incorrect cancellation order when the ID of the last posted message wraps around and is smaller than the ID of the first posted message.

Fix this by canceling pending messages starting from the next available message ID, ensuring the correct ordering across wraparound.

Fixes a37d78470bcc ("accel/amdxdna: Replace idr api with xarray")
Quoted 20 lines

---
  drivers/accel/amdxdna/amdxdna_mailbox.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_mailbox.c +3 -1
index 84a7e92562ad..336e5e77f18a 100644
@@ -549,7 +549,9 @@ void xdna_mailbox_stop_channel(struct 
 mailbox_channel *mb_chann)
       drain_workqueue(mb_chann->work_q);
         /* We can clean up and release resources */
-    xa_for_each(&mb_chann->chan_xa, msg_id, mb_msg)
+    xa_for_each_start(&mb_chann->chan_xa, msg_id, mb_msg, 
 mb_chann->next_msgid)
+        mailbox_release_msg(mb_chann, mb_msg);
+    xa_for_each_range(&mb_chann->chan_xa, msg_id, mb_msg, 0, 
 mb_chann->next_msgid - 1)
           mailbox_release_msg(mb_chann, mb_msg);

      xa_destroy(&mb_chann->chan_xa);