xen/blkfront: Only check REQ_FUA for writes
Subsystems (3)
PATCH 1/1 xen/blkfront: Only check REQ_FUA for writes
The existing code silently converts read operations with the REQ_FUA bit set into write-barrier operations. This results in data loss as the backend scribbles zeroes over the data instead of returning it.
While the REQ_FUA bit doesn't make sense on a read operation, at least one well-known out-of-tree kernel module does set it and since it results in data loss, let's be safe here and only look at REQ_FUA for writes.
--- drivers/block/xen-blkfront.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/xen-blkfront.c +2 -1
@@ -780,7 +780,8 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri ring_req->u.rw.handle = info->handle; ring_req->operation =rq_data_dir (req) ?BLKIF_OP_WRITE :BLKIF_OP_READ ; -if (req_op (req) ==REQ_OP_FLUSH || req->cmd_flags &REQ_FUA ) { +if (req_op (req) ==REQ_OP_FLUSH || + (req_op (req) ==REQ_OP_WRITE && (req->cmd_flags &REQ_FUA ))) {/* * Ideally we can do an unordered flush-to-disk. * In case the backend onlysupports barriers, use that.
Signature · 1 line
2.31.1
Quoted 11 lines · Ross Lagerwall
The existing code silently converts read operations with the
REQ_FUAbit set into write-barrier operations. This results in data loss as the backend scribbles zeroes over the data instead of returning it.While the
REQ_FUAbit doesn't make sense on a read operation, at least one well-known out-of-tree kernel module does set it and since it results in data loss, let's be safe here and only look atREQ_FUAfor writes.Signed-off-by Ross Lagerwall <[email protected]>
Juergen
Quoted 9 lines · Ross Lagerwall
The existing code silently converts read operations with the
REQ_FUAbit set into write-barrier operations. This results in data loss as the backend scribbles zeroes over the data instead of returning it.While the
REQ_FUAbit doesn't make sense on a read operation, at least one well-known out-of-tree kernel module does set it and since it results in data loss, let's be safe here and only look atREQ_FUAfor writes.
Do we know what's the intention of the out-of-tree kernel module with it's usage of FUA for reads?
Should this maybe be translated to a pair of flush cache and read requests?
Quoted 10 lines
Signed-off-by Ross Lagerwall <[email protected]>--- drivers/block/xen-blkfront.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/block/xen-blkfront.c +0
-0
drivers/block/xen-blkfront.c static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri · line 784
Quoted 6 lines
drivers/block/xen-blkfront.c +2
-1@@ -780,7 +780,8 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri ring_req->u.rw.handle = info->handle; ring_req->operation =rq_data_dir (req) ?BLKIF_OP_WRITE :BLKIF_OP_READ ; -if (req_op (req) ==REQ_OP_FLUSH || req->cmd_flags &REQ_FUA ) { +if (req_op (req) ==REQ_OP_FLUSH || + (req_op (req) ==REQ_OP_WRITE && (req->cmd_flags &REQ_FUA ))) {
Should we print some kind of warning maybe once that we have received a READ request with the FUA flag set, and the FUA flag will have no effect?
Thanks, Roger.
Quoted 12 lines
From: Roger Pau Monne <[email protected]>
Sent: Tuesday, May 2, 2023 4:57 PM
To: Ross Lagerwall <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] xen/blkfront: Only checkREQ_FUAfor writesQuoted 5 lines · Ross Lagerwall
The existing code silently converts read operations with the
REQ_FUAbit set into write-barrier operations. This results in data loss as the backend scribbles zeroes over the data instead of returning it.
Quoted 7 lines
Quoted 4 lines
While the
REQ_FUAbit doesn't make sense on a read operation, at least one well-known out-of-tree kernel module does set it and since it results in data loss, let's be safe here and only look atREQ_FUAfor writes.Do we know what's the intention of the out-of-tree kernel module with it's usage of FUA for reads?
It was just a plain bug that has now been fixed:
https://github.com/veeam/blksnap/commit/e3b3e7369642b59e01c647934789e5e20b380c62
I think this patch is still worthwile since reads becoming writes is asking for data corruption.
Quoted 9 lines
Should this maybe be translated to a pair of flush cache and read requests?
Quoted 5 lines
Signed-off-by Ross Lagerwall <[email protected]>---
drivers/block/xen-blkfront.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 11 lines
drivers/block/xen-blkfront.c +0
-0@@ -780,7 +780,8 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri ring_req->u.rw.handle = info->handle;
ring_req->operation=rq_data_dir(req)?BLKIF_OP_WRITE:BLKIF_OP_READ;- if (req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA) { + if (req_op(req) == REQ_OP_FLUSH ||+ (
req_op(req)==REQ_OP_WRITE&& (req->cmd_flags&REQ_FUA))) {Should we print some kind of warning maybe once that we have received a READ request with the FUA flag set, and the FUA flag will have no effect?
I thought of adding something like this but I couldn't find any other block layer code doing a similar check (also it seems more appropriate in the core block layer).
WARN_ONCE(req_op(req) != REQ_OP_WRITE && (req->cmd_flags & REQ_FUA));
I can add it if the maintainers want it.
Thanks,
Ross
Roger Pau Monné
Reviewed-byQuoted 20 lines · Ross Lagerwall
Quoted 12 lines
From: Roger Pau Monne <[email protected]>
Sent: Tuesday, May 2, 2023 4:57 PM
To: Ross Lagerwall <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] xen/blkfront: Only checkREQ_FUAfor writesQuoted 5 lines · Ross Lagerwall
The existing code silently converts read operations with the
REQ_FUAbit set into write-barrier operations. This results in data loss as the backend scribbles zeroes over the data instead of returning it.Quoted 7 lines
Quoted 4 lines
While the
REQ_FUAbit doesn't make sense on a read operation, at least one well-known out-of-tree kernel module does set it and since it results in data loss, let's be safe here and only look atREQ_FUAfor writes.Do we know what's the intention of the out-of-tree kernel module with it's usage of FUA for reads?
Quoted 6 lines
It was just a plain bug that has now been fixed:
https://github.com/veeam/blksnap/commit/e3b3e7369642b59e01c647934789e5e20b380c62
I think this patch is still worthwile since reads becoming writes is asking for data corruption.
Right, can you add to the commit message that this was a bug in the driver? It wasn't clear to me whether that was the case or it was legit for FUA to be used with requests != write.
Quoted 26 lines
Quoted 9 lines
Should this maybe be translated to a pair of flush cache and read requests?
Quoted 5 lines
Signed-off-by Ross Lagerwall <[email protected]>---
drivers/block/xen-blkfront.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)Quoted 16 lines
Quoted 11 lines
drivers/block/xen-blkfront.c +0
-0@@ -780,7 +780,8 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri ring_req->u.rw.handle = info->handle;
ring_req->operation=rq_data_dir(req)?BLKIF_OP_WRITE:BLKIF_OP_READ;- if (req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA) { + if (req_op(req) == REQ_OP_FLUSH ||+ (
req_op(req)==REQ_OP_WRITE&& (req->cmd_flags&REQ_FUA))) {Should we print some kind of warning maybe once that we have received a READ request with the FUA flag set, and the FUA flag will have no effect?
Quoted 7 lines
I thought of adding something like this but I couldn't find any other block layer code doing a similar check (also it seems more appropriate in the core block layer).
WARN_ONCE(req_op(req) != REQ_OP_WRITE && (req->cmd_flags & REQ_FUA));I can add it if the maintainers want it.
Hm, yes, it would be better placed in some generic blk code rather than (possibly) at every driver, otherwise people might complain that xen-blkfront trows warnings for requests other drivers handle fine.
Would you be up for sending such a patch to generic blk layer?
For the code here:
With the commit message slightly adjusted to make it clear read + fua was a bug in the module?
Thanks, Roger.