virtio_blk: add FUA write support
Subsystems (3)
cover virtio_blk: add FUA write support
virtio-blk FUA write support has been added to the virtio spec [1]. This series implements that by adding the new request flag uapi definitions and corresponding virtio-blk support. It also enables vdpa_sim_blk to handle fua writes.
[1] https://lore.kernel.org/virtio-comment/[email protected]/
Alberto Faria (2):
virtio_blk: add fua write support
vdpa_sim_blk: add support for FUA writes
drivers/block/virtio_blk.c | 15 +++++++++++++-- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 4 +++- include/uapi/linux/virtio_blk.h | 13 +++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-)
Signature · 1 line
2.56.0
PATCH 1/2 virtio_blk: add fua write support
Add the new virtio-blk request FUA flag uapi definitions and corresponding virtio-blk support.
--- drivers/block/virtio_blk.c | 15 +++++++++++++-- include/uapi/linux/virtio_blk.h | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-)
drivers/block/virtio_blk.c +13 -2
@@ -248,7 +248,10 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,return BLK_STS_NOTSUPP ;/* Set fields for all request types */ - vbr->out_hdr.ioprio =cpu_to_virtio32 (vdev,req_get_ioprio (req)); +if (virtio_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS )) + vbr->out_hdr.flags =0 ; +else + vbr->out_hdr.ioprio =cpu_to_virtio32 (vdev,req_get_ioprio (req));switch (req_op (req)) {case REQ_OP_READ :
@@ -258,6 +261,9 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,case REQ_OP_WRITE : type =VIRTIO_BLK_T_OUT ; sector =blk_rq_pos (req); +if (req->cmd_flags &REQ_FUA ) + vbr->out_hdr.flags |=cpu_to_virtio32 (vdev, +BIT (VIRTIO_BLK_REQ_FLAG_OUT_FUA ));break ;case REQ_OP_FLUSH : type =VIRTIO_BLK_T_FLUSH ;
@@ -1508,6 +1514,10 @@ static int virtblk_probe(struct virtio_device *vdev)if (virtblk_get_cache_mode (vdev)) lim.features |=BLK_FEAT_WRITE_CACHE ; +if (virtio_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS ) && +virtio_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA )) + lim.features |=BLK_FEAT_FUA ; + vblk->disk =blk_mq_alloc_disk (&vblk->tag_set, &lim, vblk);if (IS_ERR (vblk->disk)) { err =PTR_ERR (vblk->disk);
@@ -1672,7 +1682,8 @@ static unsigned int features[] = {VIRTIO_BLK_F_RO ,VIRTIO_BLK_F_BLK_SIZE ,VIRTIO_BLK_F_FLUSH ,VIRTIO_BLK_F_TOPOLOGY ,VIRTIO_BLK_F_CONFIG_WCE ,VIRTIO_BLK_F_MQ ,VIRTIO_BLK_F_DISCARD ,VIRTIO_BLK_F_WRITE_ZEROES , - VIRTIO_BLK_F_SECURE_ERASE, VIRTIO_BLK_F_ZONED, +VIRTIO_BLK_F_SECURE_ERASE ,VIRTIO_BLK_F_ZONED ,VIRTIO_BLK_F_REQ_FLAGS , + VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA, }; static struct virtio_driver virtio_blk = {
include/uapi/linux/virtio_blk.h +11 -2
@@ -42,6 +42,8 @@#define VIRTIO_BLK_F_WRITE_ZEROES 14/* WRITE ZEROES is supported */ #define VIRTIO_BLK_F_SECURE_ERASE 16/* Secure Erase is supported */ #define VIRTIO_BLK_F_ZONED 17/* Zoned block device */ +#define VIRTIO_BLK_F_REQ_FLAGS 18/* Request flags supported */ +#define VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA 19/* FUA flag supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY
@@ -211,6 +213,9 @@ struct virtio_blk_config {#define VIRTIO_BLK_T_BARRIER 0x80000000#endif /* !VIRTIO_BLK_NO_LEGACY */ +/* Request flag bits */ +#define VIRTIO_BLK_REQ_FLAG_OUT_FUA 0 +/* * This comes first in the read scatter-gather list. * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated,
@@ -219,8 +224,12 @@ struct virtio_blk_config {struct virtio_blk_outhdr {/* VIRTIO_BLK_T* */ __virtio32 type; -/* io priority. */ -__virtio32 ioprio; +union { +/* io priority. */ +__virtio32 ioprio; +/* Request flags. */ +__virtio32 flags; + };/* Sector (ie. 512 byte offset) */ __virtio64 sector; };
Signature · 1 line
2.56.0
Stefan Hajnoczi
reviewerRe: [PATCH 1/2] virtio_blk: add fua write support
Quoted 26 lines · Alberto Faria
Add the new virtio-blk request FUA flag uapi definitions and corresponding virtio-blk support.
Signed-off-by Alberto Faria <[email protected]>--- drivers/block/virtio_blk.c | 15 +++++++++++++-- include/uapi/linux/virtio_blk.h | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-)drivers/block/virtio_blk.c +4
-1@@ -248,7 +248,10 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,return BLK_STS_NOTSUPP ;/* Set fields for all request types */ - vbr->out_hdr.ioprio =cpu_to_virtio32 (vdev,req_get_ioprio (req)); +if (virtio_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS )) + vbr->out_hdr.flags =0 ; +else + vbr->out_hdr.ioprio =cpu_to_virtio32 (vdev,req_get_ioprio (req));switch (req_op (req)) {case REQ_OP_READ :
drivers/block/virtio_blk.c static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev, · line 264
Quoted 4 lines
drivers/block/virtio_blk.c +1
-0@@ -258,6 +261,9 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev,case REQ_OP_WRITE : type =VIRTIO_BLK_T_OUT ; sector =blk_rq_pos (req); +if (req->cmd_flags &REQ_FUA )
This does not check virtio_has_feature(vdev, VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA). I'm not confident that REQ_FUA only reaches here when supported. For example, dm-mpath might send it when some paths do support FUA but the virtio_blk path does not.
drivers/block/virtio_blk.c static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev, · line 269
Quoted 5 lines
drivers/block/virtio_blk.c +2
-0+ vbr->out_hdr.flags |=cpu_to_virtio32 (vdev, +BIT (VIRTIO_BLK_REQ_FLAG_OUT_FUA ));break ;case REQ_OP_FLUSH : type =VIRTIO_BLK_T_FLUSH ;
Please check the situation with REQ_OP_ZONE_APPEND. We ignore the REQ_FUA bit and that would be dangerous. Perhaps don't report FUA support on zoned devices?
drivers/block/virtio_blk.c static int virtblk_probe(struct virtio_device *vdev) · line 1515
Quoted 3 lines
drivers/block/virtio_blk.c +0
-0@@ -1508,6 +1514,10 @@ static int virtblk_probe(struct virtio_device *vdev)if (virtblk_get_cache_mode (vdev)) lim.features |=BLK_FEAT_WRITE_CACHE ;
Speaking of cache mode, cache_type_store() -> queue_limits_commit_update_frozen() -> queue_limits_commit_update() -> blk_validate_limits() can clear BLK_FEAT_FUA:
if (!(lim->features & BLK_FEAT_WRITE_CACHE))
lim->features &= ~BLK_FEAT_FUA;So cache_type_store() needs to restore BLK_FEAT_FUA when BLK_FEAT_WRITE_CACHE is enabled again (provided the device supports FUA).
Quoted 59 lines
drivers/block/virtio_blk.c +6
-1+if (virtio_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS ) && +virtio_has_feature (vdev,VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA )) + lim.features |=BLK_FEAT_FUA ; + vblk->disk =blk_mq_alloc_disk (&vblk->tag_set, &lim, vblk);if (IS_ERR (vblk->disk)) { err =PTR_ERR (vblk->disk);@@ -1672,7 +1682,8 @@ static unsigned int features[] = {VIRTIO_BLK_F_RO ,VIRTIO_BLK_F_BLK_SIZE ,VIRTIO_BLK_F_FLUSH ,VIRTIO_BLK_F_TOPOLOGY ,VIRTIO_BLK_F_CONFIG_WCE ,VIRTIO_BLK_F_MQ ,VIRTIO_BLK_F_DISCARD ,VIRTIO_BLK_F_WRITE_ZEROES , - VIRTIO_BLK_F_SECURE_ERASE, VIRTIO_BLK_F_ZONED, +VIRTIO_BLK_F_SECURE_ERASE ,VIRTIO_BLK_F_ZONED ,VIRTIO_BLK_F_REQ_FLAGS , + VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA, }; static struct virtio_driver virtio_blk = {include/uapi/linux/virtio_blk.h +11
-2@@ -42,6 +42,8 @@#define VIRTIO_BLK_F_WRITE_ZEROES 14/* WRITE ZEROES is supported */ #define VIRTIO_BLK_F_SECURE_ERASE 16/* Secure Erase is supported */ #define VIRTIO_BLK_F_ZONED 17/* Zoned block device */ +#define VIRTIO_BLK_F_REQ_FLAGS 18/* Request flags supported */ +#define VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA 19/* FUA flag supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -211,6 +213,9 @@ struct virtio_blk_config {#define VIRTIO_BLK_T_BARRIER 0x80000000#endif /* !VIRTIO_BLK_NO_LEGACY */ +/* Request flag bits */ +#define VIRTIO_BLK_REQ_FLAG_OUT_FUA 0 +/* * This comes first in the read scatter-gather list. * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, @@ -219,8 +224,12 @@ struct virtio_blk_config {struct virtio_blk_outhdr {/* VIRTIO_BLK_T* */ __virtio32 type; -/* io priority. */ -__virtio32 ioprio; +union { +/* io priority. */ +__virtio32 ioprio; +/* Request flags. */ +__virtio32 flags; + };/* Sector (ie. 512 byte offset) */ __virtio64 sector; };Signature · 1 line
2.56.0
PATCH 2/2 vdpa_sim_blk: add support for FUA writes
In reply to Alberto FariaExpose VIRTIO_BLK_F_REQ_FLAGS and VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA to drivers. The simulator is a ramdisk, so it handles FUA and non-FUA writes in the same way.
--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +3 -1
@@ -31,7 +31,9 @@ (1ULL << VIRTIO_BLK_F_TOPOLOGY) | \ (1ULL << VIRTIO_BLK_F_MQ) | \ (1ULL << VIRTIO_BLK_F_DISCARD) | \ - (1ULL << VIRTIO_BLK_F_WRITE_ZEROES)) + (1ULL << VIRTIO_BLK_F_WRITE_ZEROES) | \ + (1ULL << VIRTIO_BLK_F_REQ_FLAGS) | \ + (1ULL << VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA))#define VDPASIM_BLK_CAPACITY 0x40000#define VDPASIM_BLK_SIZE_MAX 0x1000
Signature · 1 line
2.56.0
Stefan Hajnoczi
reviewerRe: [PATCH 2/2] vdpa_sim_blk: add support for FUA writes
Quoted 14 lines · Alberto Faria
Expose
VIRTIO_BLK_F_REQ_FLAGSandVIRTIO_BLK_F_REQ_FLAGS_OUT_FUAto drivers. The simulator is a ramdisk, so it handles FUA and non-FUA writes in the same way.Signed-off-by Alberto Faria <[email protected]>--- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +0
-0
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c line 39
Quoted 10 lines
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +3
-1@@ -31,7 +31,9 @@ (1ULL << VIRTIO_BLK_F_TOPOLOGY) | \ (1ULL << VIRTIO_BLK_F_MQ) | \ (1ULL << VIRTIO_BLK_F_DISCARD) | \ - (1ULL << VIRTIO_BLK_F_WRITE_ZEROES)) + (1ULL << VIRTIO_BLK_F_WRITE_ZEROES) | \ + (1ULL << VIRTIO_BLK_F_REQ_FLAGS) | \ + (1ULL << VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA))#define VDPASIM_BLK_CAPACITY 0x40000#define VDPASIM_BLK_SIZE_MAX 0x1000
This allows VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA to be negotiated without VIRTIO_BLK_F_REQ_FLAGS. Please check if there is a way to prevent this since the spec requires it.
Thanks,
Stefan
Stefan Hajnoczi
reviewerQuoted 7 lines · Alberto Faria
virtio-blk FUA write support has been added to the virtio spec [1]. This series implements that by adding the new request flag uapi definitions and corresponding virtio-blk support. It also enables
vdpa_sim_blkto handle fua writes.[1] https://lore.kernel.org/virtio-comment/[email protected]/
Quoted 11 lines
Alberto Faria (2):
virtio_blk: add fua write support
vdpa_sim_blk: add support for FUA writesdrivers/block/virtio_blk.c | 15 +++++++++++++-- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 4 +++- include/uapi/linux/virtio_blk.h | 13 +++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-)Signature · 1 line
2.56.0
CCing maintainers according to scripts/get_maintainers.pl -f drivers/block/virtio_blk.c and Kevin Wolf (QEMU).
If this patch series is just now coming to your attention and you want to take a quick look:
https://lore.kernel.org/linux-block/[email protected]/