From 2e5e831b31c9fd78e1f464a4a8268270990d06a4 Mon Sep 17 00:00:00 2001 From: Alex Reid Date: Wed, 18 Jan 2023 17:26:03 +0000 Subject: [PATCH] Fix tcmulib get next command on aarch64 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 #688. PR #693. Signed-off-by: Xiubo Li --- libtcmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libtcmu.c b/libtcmu.c index 46a6fbcc..cf69a4b6 100644 --- a/libtcmu.c +++ b/libtcmu.c @@ -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 *