From 2f1ca0223fd27af5cb298e8d6570c6d8a21d0364 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 21 Oct 2026 15:07:29 +0300 Subject: [PATCH] scst_user: Protect the shared debug freeze flag with its mutex DEBUG_TM_IGNORE_ALL workers share a freeze flag without synchronization. Manual review of the volatile warning confirmed that volatile does not protect these concurrent accesses. Store and snapshot the flag under the existing per-device mutex, then unlock before the intentional infinite sleep. The mutex is initialized before worker creation and destroyed after joins. Checkpatch reports VOLATILE: Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst --- usr/fileio/common.c | 7 ++++++- usr/fileio/common.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/usr/fileio/common.c b/usr/fileio/common.c index 2f15b8e5d..e68a3d044 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -812,11 +812,16 @@ void *main_loop(void *arg) while(1) { #ifdef DEBUG_TM_IGNORE_ALL + int ignore_all; + + pthread_mutex_lock(&dev->dev_mutex); if (dev->debug_tm_ignore && (random() % 50000) == 55) { TRACE_MGMT_DBG("%s", "Ignore ALL"); dev->debug_tm_ignore_all = 1; } - if (dev->debug_tm_ignore_all) { + ignore_all = dev->debug_tm_ignore_all; + pthread_mutex_unlock(&dev->dev_mutex); + if (ignore_all) { /* Go Astral */ while(1) { sleep(60); diff --git a/usr/fileio/common.h b/usr/fileio/common.h index e65be3fd2..ddd0958a7 100644 --- a/usr/fileio/common.h +++ b/usr/fileio/common.h @@ -87,7 +87,7 @@ struct vdisk_dev { #if defined(DEBUG_TM_IGNORE) || defined(DEBUG_TM_IGNORE_ALL) unsigned int debug_tm_ignore:1; #if defined(DEBUG_TM_IGNORE_ALL) - volatile int debug_tm_ignore_all; + int debug_tm_ignore_all; #endif #endif