Skip to content

Commit

Permalink
Fix tcmulib get next command on aarch64
Browse files Browse the repository at this point in the history
Use the appropriate atomic load instruction to ensure we synchronize
the read of the command ring head index with any previous stores. Not
doing this causes command ring corruption on aarch64:

[Tue Oct  4 15:45:50 2022] cmd_id 0 not found, ring is broken
[Tue Oct  4 15:45:50 2022] ring broken, not handling completions

See issue open-iscsi#688. PR open-iscsi#693.

Signed-off-by: Xiubo Li <[email protected]>
  • Loading branch information
Alex Reid committed Feb 20, 2023
1 parent 82a2e3e commit 2e5e831
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion libtcmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,13 @@ device_cmd_head(struct tcmu_device *dev)
{
struct tcmu_mailbox *mb = dev->map;

return (struct tcmu_cmd_entry *) ((char *) mb + mb->cmdr_off + mb->cmd_head);
/*
* We must load the mb_head index using an atomic load or we'll crash
* on aarch64. See https://github.com/open-iscsi/tcmu-runner/issues/688
*/
uint32_t mb_head = __atomic_load_n(&mb->cmd_head, __ATOMIC_ACQUIRE);
struct tcmu_cmd_entry* e = (struct tcmu_cmd_entry *) ((char *) mb + mb->cmdr_off + mb_head);
return e;
}

static inline struct tcmu_cmd_entry *
Expand Down

0 comments on commit 2e5e831

Please sign in to comment.