block: don't allow enabling a cache on devices that don't support it
authorChristoph Hellwig <hch@lst.de>
Fri, 7 Jul 2023 09:42:39 +0000 (11:42 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:42:40 +0000 (09:42 +0200)
commit00c0b2825bb5df26c339cef1d32db6a8755de203
tree21140bad2e5750ca402982dcf665ee6e74a4bc67
parente5e0ec8ff16089a0801cd6a1748003697b6b901f
block: don't allow enabling a cache on devices that don't support it

[ Upstream commit 43c9835b144c7ce29efe142d662529662a9eb376 ]

Currently the write_cache attribute allows enabling the QUEUE_FLAG_WC
flag on devices that never claimed the capability.

Fix that by adding a QUEUE_FLAG_HW_WC flag that is set by
blk_queue_write_cache and guards re-enabling the cache through sysfs.

Note that any rescan that calls blk_queue_write_cache will still
re-enable the write cache as in the current code.

Fixes: 93e9d8e836cb ("block: add ability to flag write back caching on a device")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230707094239.107968-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
block/blk-settings.c
block/blk-sysfs.c
include/linux/blkdev.h