From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384231; b=qZQ+uopcfe57oqWruGa4AADqPoZwbmwDZT4Vbm3Cr3R28aupzIxg9rw5+c33/lQ4xHyV aEGIADMM3aoUy3j3zpmG5w5A2Ns8zciuefalzU4zXSLSFjkTsFtyjnNKNUsPlIdhBFyK/ F84tm5/byps4sG6GL4S7242FD25SRuP2oqUV04c3CxgMEFvEqArij190rXB9IRz2uysNk EJocmEwX/QP16rTyLHx7i1ysYPQfx1NBDCa8Ea4uEXvvw9xwpKsDQ69b4wGrU1ypbfwyd bhAihYcqYfZM4E69tnEETipefeDUUas9BjmaWqsD36XlUwlYuwsMIpjy3zzUf1tDQjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384231; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=n+nsVPtr9VDyWEVA2gWS+TRWc7el8gUQ7ulpHULaywE=; b=2sp305HRa4CZ8/j7ZsiyE4oEd13rzaN2eHNjbshTU6g70nPffxRZANZAgXLvpcNdsi+W ZDct2zlf4S1OffPI0DwNFMheeG/xOYaBEO8XqGzMcp22RMVrvZvI8lBZGGoBI8M5GCSDk ypTbvQ+EoRJkMFzD+GI4cKNHoOjbzxwq7MykjvhFO4nFgq0dCFR7hrWhzZlul8ZvYcGRw 1ftf7/oU7iw2nI5fy7+VPMecImAy0NcldhuyScU+GUYU7EEJzJ8uKxL1ytIIWinYdaakG wiEkwWeMDZnltx0lRXDI/iNwtLijfh2Yh6CoT0VMnXwtX9EYpn6cBYnYEjEbnHDbxlQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=t0VfvEYW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DB11606A322; Fri, 4 Dec 2026 11:37:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=t0VfvEYW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E4271F000C2; Fri, 4 Dec 2026 11:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384230; bh=n+nsVPtr9VDyWEVA2gWS+TRWc7el8gUQ7ulpHULaywE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=t0VfvEYWnZqJLnmP0CEYUe8mmwehqO4CQLF4r1xTMSs0xT8eW6DOy4FHXcs8JlhcS w7dn4a3Zl0P3DSCF41a0CSy5kaB3zcwGNxtYsg4rIJHSYkIVrNNHXKNAhhPJNOKhXq ohPUuaYF7b2R2Vpa1fia7HYAVAJENJw5Om0Kj88A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Hellwig , Ming Lei , Nilay Shroff , Martin Wilck , Benjamin Marzinski , Bart Van Assche , Jens Axboe , Dickson Wu , Sasha Levin Subject: [PATCH 6.12 545/555] block: Remove queue freezing from several sysfs store callbacks Date: Fri, 4 Dec 2026 19:09:48 +0900 Message-ID: <20261204100629.360664622@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bart Van Assche commit 935a20d1bebf6236076785fac3ff81e3931834e9 upstream. Freezing the request queue from inside sysfs store callbacks may cause a deadlock in combination with the dm-multipath driver and the queue_if_no_path option. Additionally, freezing the request queue slows down system boot on systems where sysfs attributes are set synchronously. Fix this by removing the blk_mq_freeze_queue() / blk_mq_unfreeze_queue() calls from the store callbacks that do not strictly need these callbacks. Add the __data_racy annotation to request_queue.rq_timeout to suppress KCSAN data race reports about the rq_timeout reads. This patch may cause a small delay in applying the new settings. For all the attributes affected by this patch, I/O will complete correctly whether the old or the new value of the attribute is used. This patch affects the following sysfs attributes: * io_poll_delay * io_timeout * nomerges * read_ahead_kb * rq_affinity Here is an example of a deadlock triggered by running test srp/002 if this patch is not applied: task:multipathd Call Trace: __schedule+0x8c1/0x1bf0 schedule+0xdd/0x270 schedule_preempt_disabled+0x1c/0x30 __mutex_lock+0xb89/0x1650 mutex_lock_nested+0x1f/0x30 dm_table_set_restrictions+0x823/0xdf0 __bind+0x166/0x590 dm_swap_table+0x2a7/0x490 do_resume+0x1b1/0x610 dev_suspend+0x55/0x1a0 ctl_ioctl+0x3a5/0x7e0 dm_ctl_ioctl+0x12/0x20 __x64_sys_ioctl+0x127/0x1a0 x64_sys_call+0xe2b/0x17d0 do_syscall_64+0x96/0x3a0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 task:(udev-worker) Call Trace: __schedule+0x8c1/0x1bf0 schedule+0xdd/0x270 blk_mq_freeze_queue_wait+0xf2/0x140 blk_mq_freeze_queue_nomemsave+0x23/0x30 queue_ra_store+0x14e/0x290 queue_attr_store+0x23e/0x2c0 sysfs_kf_write+0xde/0x140 kernfs_fop_write_iter+0x3b2/0x630 vfs_write+0x4fd/0x1390 ksys_write+0xfd/0x230 __x64_sys_write+0x76/0xc0 x64_sys_call+0x276/0x17d0 do_syscall_64+0x96/0x3a0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 Cc: Christoph Hellwig Cc: Ming Lei Cc: Nilay Shroff Cc: Martin Wilck Cc: Benjamin Marzinski Cc: stable@vger.kernel.org Fixes: af2814149883 ("block: freeze the queue in queue_attr_store") Signed-off-by: Bart Van Assche Reviewed-by: Nilay Shroff Signed-off-by: Jens Axboe [ adapted: skip store freeze, omit 5e40f4452dc9 lock, fold d23977fee1ee ] Signed-off-by: Dickson Wu Signed-off-by: Sasha Levin --- block/blk-settings.c | 2 +- block/blk-sysfs.c | 19 +++++++++++++++++-- include/linux/blkdev.h | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index d72a283401c3a..1a173d4437507 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -21,7 +21,7 @@ void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout) { - q->rq_timeout = timeout; + WRITE_ONCE(q->rq_timeout, timeout); } EXPORT_SYMBOL_GPL(blk_queue_rq_timeout); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index f21de1898ff15..55eff38c19c0b 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -92,7 +92,11 @@ queue_ra_store(struct gendisk *disk, const char *page, size_t count) ret = queue_var_store(&ra_kb, page, count); if (ret < 0) return ret; - disk->bdi->ra_pages = ra_kb >> (PAGE_SHIFT - 10); + /* + * bdi->ra_pages reads are not serialized against bdi->ra_pages writes. + * Use WRITE_ONCE() to write bdi->ra_pages once. + */ + WRITE_ONCE(disk->bdi->ra_pages, ra_kb >> (PAGE_SHIFT - 10)); return ret; } @@ -342,7 +346,8 @@ static ssize_t queue_poll_store(struct gendisk *disk, const char *page, static ssize_t queue_io_timeout_show(struct gendisk *disk, char *page) { - return sysfs_emit(page, "%u\n", jiffies_to_msecs(disk->queue->rq_timeout)); + return sysfs_emit(page, "%u\n", + jiffies_to_msecs(READ_ONCE(disk->queue->rq_timeout))); } static ssize_t queue_io_timeout_store(struct gendisk *disk, const char *page, @@ -701,11 +706,21 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr, } mutex_lock(&q->sysfs_lock); + if (entry == &queue_ra_entry || entry == &queue_nomerges_entry || + entry == &queue_rq_affinity_entry || entry == &queue_poll_entry || + entry == &queue_poll_delay_entry || entry == &queue_io_timeout_entry) { + noio_flag = memalloc_noio_save(); + res = entry->store(disk, page, length); + memalloc_noio_restore(noio_flag); + goto unlock; + } + blk_mq_freeze_queue(q); noio_flag = memalloc_noio_save(); res = entry->store(disk, page, length); memalloc_noio_restore(noio_flag); blk_mq_unfreeze_queue(q); +unlock: mutex_unlock(&q->sysfs_lock); return res; } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 33f5b16c0fd9a..eb60179e3b363 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -460,7 +460,7 @@ struct request_queue { */ unsigned long queue_flags; - unsigned int rq_timeout; + unsigned int __data_racy rq_timeout; unsigned int queue_depth; -- 2.53.0