* don't allow enabling a write back cache on devices that don't support it
@ 2023-07-07 9:42 Christoph Hellwig
2023-07-07 9:42 ` [PATCH 1/2] block: cleanup queue_wc_store Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Christoph Hellwig @ 2023-07-07 9:42 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block
Hi Jens,
this series fixes a case where a user could enable a write back cache
on a device (driver) that doesn't support it all, potentially leading
to flush requests being sent to a driver that doesn't know whast to
do with them.
diffstat:
block/blk-settings.c | 7 +++++--
block/blk-sysfs.c | 21 ++++++++-------------
include/linux/blkdev.h | 1 +
3 files changed, 14 insertions(+), 15 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] block: cleanup queue_wc_store
2023-07-07 9:42 don't allow enabling a write back cache on devices that don't support it Christoph Hellwig
@ 2023-07-07 9:42 ` Christoph Hellwig
2023-07-07 9:42 ` [PATCH 2/2] block: don't allow enabling a cache on devices that don't support it Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2023-07-07 9:42 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block
Get rid of the local queue_wc_store variable and handling setting and
clearing the QUEUE_FLAG_WC flag diretly instead the if / else if.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-sysfs.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index afc797fb0dfc48..0cde6598fb2f4d 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -449,21 +449,13 @@ static ssize_t queue_wc_show(struct request_queue *q, char *page)
static ssize_t queue_wc_store(struct request_queue *q, const char *page,
size_t count)
{
- int set = -1;
-
if (!strncmp(page, "write back", 10))
- set = 1;
+ blk_queue_flag_set(QUEUE_FLAG_WC, q);
else if (!strncmp(page, "write through", 13) ||
!strncmp(page, "none", 4))
- set = 0;
-
- if (set == -1)
- return -EINVAL;
-
- if (set)
- blk_queue_flag_set(QUEUE_FLAG_WC, q);
- else
blk_queue_flag_clear(QUEUE_FLAG_WC, q);
+ else
+ return -EINVAL;
return count;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] block: don't allow enabling a cache on devices that don't support it
2023-07-07 9:42 don't allow enabling a write back cache on devices that don't support it Christoph Hellwig
2023-07-07 9:42 ` [PATCH 1/2] block: cleanup queue_wc_store Christoph Hellwig
@ 2023-07-07 9:42 ` Christoph Hellwig
2023-07-13 13:43 ` don't allow enabling a write back " Christoph Hellwig
2023-07-15 15:52 ` Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2023-07-07 9:42 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block
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>
---
block/blk-settings.c | 7 +++++--
block/blk-sysfs.c | 11 +++++++----
include/linux/blkdev.h | 1 +
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 4dd59059b788eb..0046b447268f91 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -830,10 +830,13 @@ EXPORT_SYMBOL(blk_set_queue_depth);
*/
void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua)
{
- if (wc)
+ if (wc) {
+ blk_queue_flag_set(QUEUE_FLAG_HW_WC, q);
blk_queue_flag_set(QUEUE_FLAG_WC, q);
- else
+ } else {
+ blk_queue_flag_clear(QUEUE_FLAG_HW_WC, q);
blk_queue_flag_clear(QUEUE_FLAG_WC, q);
+ }
if (fua)
blk_queue_flag_set(QUEUE_FLAG_FUA, q);
else
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 0cde6598fb2f4d..63e4812623361d 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -449,13 +449,16 @@ static ssize_t queue_wc_show(struct request_queue *q, char *page)
static ssize_t queue_wc_store(struct request_queue *q, const char *page,
size_t count)
{
- if (!strncmp(page, "write back", 10))
+ if (!strncmp(page, "write back", 10)) {
+ if (!test_bit(QUEUE_FLAG_HW_WC, &q->queue_flags))
+ return -EINVAL;
blk_queue_flag_set(QUEUE_FLAG_WC, q);
- else if (!strncmp(page, "write through", 13) ||
- !strncmp(page, "none", 4))
+ } else if (!strncmp(page, "write through", 13) ||
+ !strncmp(page, "none", 4)) {
blk_queue_flag_clear(QUEUE_FLAG_WC, q);
- else
+ } else {
return -EINVAL;
+ }
return count;
}
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index ed44a997f629f5..2f5371b8482c00 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -538,6 +538,7 @@ struct request_queue {
#define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */
#define QUEUE_FLAG_SYNCHRONOUS 11 /* always completes in submit context */
#define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
+#define QUEUE_FLAG_HW_WC 18 /* Write back caching supported */
#define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */
#define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */
#define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */
--
2.39.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: don't allow enabling a write back cache on devices that don't support it
2023-07-07 9:42 don't allow enabling a write back cache on devices that don't support it Christoph Hellwig
2023-07-07 9:42 ` [PATCH 1/2] block: cleanup queue_wc_store Christoph Hellwig
2023-07-07 9:42 ` [PATCH 2/2] block: don't allow enabling a cache on devices that don't support it Christoph Hellwig
@ 2023-07-13 13:43 ` Christoph Hellwig
2023-07-15 15:50 ` Jens Axboe
2023-07-15 15:52 ` Jens Axboe
3 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2023-07-13 13:43 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block
Jens, does this make sense to you? Without this we can deliver
flush requests to drivers not supporting them, which is a bit nasty
even if it's not exploitable without root-equivalent access.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: don't allow enabling a write back cache on devices that don't support it
2023-07-13 13:43 ` don't allow enabling a write back " Christoph Hellwig
@ 2023-07-15 15:50 ` Jens Axboe
0 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2023-07-15 15:50 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-block
On 7/13/23 7:43?AM, Christoph Hellwig wrote:
> Jens, does this make sense to you? Without this we can deliver
> flush requests to drivers not supporting them, which is a bit nasty
> even if it's not exploitable without root-equivalent access.
Yeah I think so, I'll queue it up for 6.6.
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: don't allow enabling a write back cache on devices that don't support it
2023-07-07 9:42 don't allow enabling a write back cache on devices that don't support it Christoph Hellwig
` (2 preceding siblings ...)
2023-07-13 13:43 ` don't allow enabling a write back " Christoph Hellwig
@ 2023-07-15 15:52 ` Jens Axboe
3 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2023-07-15 15:52 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-block
On Fri, 07 Jul 2023 11:42:37 +0200, Christoph Hellwig wrote:
> this series fixes a case where a user could enable a write back cache
> on a device (driver) that doesn't support it all, potentially leading
> to flush requests being sent to a driver that doesn't know whast to
> do with them.
>
> diffstat:
> block/blk-settings.c | 7 +++++--
> block/blk-sysfs.c | 21 ++++++++-------------
> include/linux/blkdev.h | 1 +
> 3 files changed, 14 insertions(+), 15 deletions(-)
>
> [...]
Applied, thanks!
[1/2] block: cleanup queue_wc_store
commit: ba2b2594c0e15a40b7f42dd8aca1867c57c13145
[2/2] block: don't allow enabling a cache on devices that don't support it
commit: 3e8f23e19c95fb4757f8c77f1473578d2154d7c2
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-15 15:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-07 9:42 don't allow enabling a write back cache on devices that don't support it Christoph Hellwig
2023-07-07 9:42 ` [PATCH 1/2] block: cleanup queue_wc_store Christoph Hellwig
2023-07-07 9:42 ` [PATCH 2/2] block: don't allow enabling a cache on devices that don't support it Christoph Hellwig
2023-07-13 13:43 ` don't allow enabling a write back " Christoph Hellwig
2023-07-15 15:50 ` Jens Axboe
2023-07-15 15:52 ` Jens Axboe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.