* [RFC 0/2] virtio_blk: add fua write support
@ 2025-05-08 0:19 Alberto Faria
2025-05-08 0:19 ` [RFC 1/2] " Alberto Faria
2025-05-08 0:19 ` [RFC 2/2] vdpa_sim_blk: add support for fua write commands Alberto Faria
0 siblings, 2 replies; 5+ messages in thread
From: Alberto Faria @ 2025-05-08 0:19 UTC (permalink / raw)
To: linux-block; +Cc: Alberto Faria
There is a proposal to introduce virtio-blk fua write support to the virtio spec
[1]. This series implements that by adding VIRTIO_BLK_{F,T}_OUT_FUA uapi
definitions and corresponding virtio-blk support. It also enables vdpa_sim_blk
to handle fua writes.
[1] https://lore.kernel.org/virtio-comment/20250507152602.3993258-1-afaria@redhat.com/
Alberto Faria (2):
virtio_blk: add fua write support
vdpa_sim_blk: add support for fua write commands
drivers/block/virtio_blk.c | 10 +++++++---
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 6 ++++--
include/uapi/linux/virtio_blk.h | 4 ++++
3 files changed, 15 insertions(+), 5 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [RFC 1/2] virtio_blk: add fua write support 2025-05-08 0:19 [RFC 0/2] virtio_blk: add fua write support Alberto Faria @ 2025-05-08 0:19 ` Alberto Faria 2025-05-08 20:33 ` Stefan Hajnoczi 2025-05-08 0:19 ` [RFC 2/2] vdpa_sim_blk: add support for fua write commands Alberto Faria 1 sibling, 1 reply; 5+ messages in thread From: Alberto Faria @ 2025-05-08 0:19 UTC (permalink / raw) To: linux-block; +Cc: Alberto Faria Add the proposed VIRTIO_BLK_{F,T}_OUT_FUA uapi definitions and corresponding virtio-blk support. Signed-off-by: Alberto Faria <afaria@redhat.com> --- drivers/block/virtio_blk.c | 10 +++++++--- include/uapi/linux/virtio_blk.h | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 7cffea01d868c..021f05c469c50 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -256,7 +256,8 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev, sector = blk_rq_pos(req); break; case REQ_OP_WRITE: - type = VIRTIO_BLK_T_OUT; + type = req->cmd_flags & REQ_FUA ? + VIRTIO_BLK_T_OUT_FUA : VIRTIO_BLK_T_OUT; sector = blk_rq_pos(req); break; case REQ_OP_FLUSH: @@ -1500,6 +1501,9 @@ static int virtblk_probe(struct virtio_device *vdev) if (virtblk_get_cache_mode(vdev)) lim.features |= BLK_FEAT_WRITE_CACHE; + if (virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_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); @@ -1650,7 +1654,7 @@ static unsigned int features_legacy[] = { 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_SECURE_ERASE, VIRTIO_BLK_F_OUT_FUA, } ; static unsigned int features[] = { @@ -1658,7 +1662,7 @@ 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_OUT_FUA, }; static struct virtio_driver virtio_blk = { diff --git a/include/uapi/linux/virtio_blk.h b/include/uapi/linux/virtio_blk.h index 3744e4da1b2a7..52be7943f6b8d 100644 --- a/include/uapi/linux/virtio_blk.h +++ b/include/uapi/linux/virtio_blk.h @@ -42,6 +42,7 @@ #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_OUT_FUA 18 /* FUA write is supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY @@ -206,6 +207,9 @@ struct virtio_blk_config { /* Reset All zones command */ #define VIRTIO_BLK_T_ZONE_RESET_ALL 26 +/* FUA write command */ +#define VIRTIO_BLK_T_OUT_FUA 27 + #ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000 -- 2.49.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC 1/2] virtio_blk: add fua write support 2025-05-08 0:19 ` [RFC 1/2] " Alberto Faria @ 2025-05-08 20:33 ` Stefan Hajnoczi 0 siblings, 0 replies; 5+ messages in thread From: Stefan Hajnoczi @ 2025-05-08 20:33 UTC (permalink / raw) To: Alberto Faria; +Cc: linux-block [-- Attachment #1: Type: text/plain, Size: 3212 bytes --] On Thu, May 08, 2025 at 01:19:50AM +0100, Alberto Faria wrote: > Add the proposed VIRTIO_BLK_{F,T}_OUT_FUA uapi definitions and > corresponding virtio-blk support. > > Signed-off-by: Alberto Faria <afaria@redhat.com> > --- > drivers/block/virtio_blk.c | 10 +++++++--- > include/uapi/linux/virtio_blk.h | 4 ++++ > 2 files changed, 11 insertions(+), 3 deletions(-) > > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c > index 7cffea01d868c..021f05c469c50 100644 > --- a/drivers/block/virtio_blk.c > +++ b/drivers/block/virtio_blk.c > @@ -256,7 +256,8 @@ static blk_status_t virtblk_setup_cmd(struct virtio_device *vdev, > sector = blk_rq_pos(req); > break; > case REQ_OP_WRITE: > - type = VIRTIO_BLK_T_OUT; > + type = req->cmd_flags & REQ_FUA ? > + VIRTIO_BLK_T_OUT_FUA : VIRTIO_BLK_T_OUT; > sector = blk_rq_pos(req); > break; > case REQ_OP_FLUSH: > @@ -1500,6 +1501,9 @@ static int virtblk_probe(struct virtio_device *vdev) > if (virtblk_get_cache_mode(vdev)) > lim.features |= BLK_FEAT_WRITE_CACHE; > > + if (virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_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); > @@ -1650,7 +1654,7 @@ static unsigned int features_legacy[] = { > 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_SECURE_ERASE, VIRTIO_BLK_F_OUT_FUA, This is a new feature. Legacy VIRTIO devices don't support it. VIRTIO_BLK_F_ZONED was not added to features_legacy[] when it was introduced either. > } > ; > static unsigned int features[] = { > @@ -1658,7 +1662,7 @@ 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_OUT_FUA, > }; > > static struct virtio_driver virtio_blk = { > diff --git a/include/uapi/linux/virtio_blk.h b/include/uapi/linux/virtio_blk.h > index 3744e4da1b2a7..52be7943f6b8d 100644 > --- a/include/uapi/linux/virtio_blk.h > +++ b/include/uapi/linux/virtio_blk.h > @@ -42,6 +42,7 @@ > #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_OUT_FUA 18 /* FUA write is supported */ > > /* Legacy feature bits */ > #ifndef VIRTIO_BLK_NO_LEGACY > @@ -206,6 +207,9 @@ struct virtio_blk_config { > /* Reset All zones command */ > #define VIRTIO_BLK_T_ZONE_RESET_ALL 26 > > +/* FUA write command */ > +#define VIRTIO_BLK_T_OUT_FUA 27 > + > #ifndef VIRTIO_BLK_NO_LEGACY > /* Barrier before this op. */ > #define VIRTIO_BLK_T_BARRIER 0x80000000 > -- > 2.49.0 > [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC 2/2] vdpa_sim_blk: add support for fua write commands 2025-05-08 0:19 [RFC 0/2] virtio_blk: add fua write support Alberto Faria 2025-05-08 0:19 ` [RFC 1/2] " Alberto Faria @ 2025-05-08 0:19 ` Alberto Faria 2025-05-08 20:34 ` Stefan Hajnoczi 1 sibling, 1 reply; 5+ messages in thread From: Alberto Faria @ 2025-05-08 0:19 UTC (permalink / raw) To: linux-block; +Cc: Alberto Faria Expose VIRTIO_BLK_F_OUT_FUA to drivers. The simulator is a ramdisk, so it handles VIRTIO_BLK_T_OUT and VIRTIO_BLK_T_OUT_FUA in the same way. Signed-off-by: Alberto Faria <afaria@redhat.com> --- drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c index b137f36793439..64f293e2931d1 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c @@ -31,7 +31,8 @@ (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_OUT_FUA)) #define VDPASIM_BLK_CAPACITY 0x40000 #define VDPASIM_BLK_SIZE_MAX 0x1000 @@ -158,7 +159,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim, status = VIRTIO_BLK_S_OK; if (type != VIRTIO_BLK_T_IN && type != VIRTIO_BLK_T_OUT && - sector != 0) { + type != VIRTIO_BLK_T_OUT_FUA && sector != 0) { dev_dbg(&vdpasim->vdpa.dev, "sector must be 0 for %u request - sector: 0x%llx\n", type, sector); @@ -191,6 +192,7 @@ static bool vdpasim_blk_handle_req(struct vdpasim *vdpasim, break; case VIRTIO_BLK_T_OUT: + case VIRTIO_BLK_T_OUT_FUA: if (!vdpasim_blk_check_range(vdpasim, sector, to_pull >> SECTOR_SHIFT, VDPASIM_BLK_SIZE_MAX * VDPASIM_BLK_SEG_MAX)) { -- 2.49.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC 2/2] vdpa_sim_blk: add support for fua write commands 2025-05-08 0:19 ` [RFC 2/2] vdpa_sim_blk: add support for fua write commands Alberto Faria @ 2025-05-08 20:34 ` Stefan Hajnoczi 0 siblings, 0 replies; 5+ messages in thread From: Stefan Hajnoczi @ 2025-05-08 20:34 UTC (permalink / raw) To: Alberto Faria; +Cc: linux-block [-- Attachment #1: Type: text/plain, Size: 432 bytes --] On Thu, May 08, 2025 at 01:19:51AM +0100, Alberto Faria wrote: > Expose VIRTIO_BLK_F_OUT_FUA to drivers. The simulator is a ramdisk, so > it handles VIRTIO_BLK_T_OUT and VIRTIO_BLK_T_OUT_FUA in the same way. > > Signed-off-by: Alberto Faria <afaria@redhat.com> > --- > drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-08 20:34 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-08 0:19 [RFC 0/2] virtio_blk: add fua write support Alberto Faria 2025-05-08 0:19 ` [RFC 1/2] " Alberto Faria 2025-05-08 20:33 ` Stefan Hajnoczi 2025-05-08 0:19 ` [RFC 2/2] vdpa_sim_blk: add support for fua write commands Alberto Faria 2025-05-08 20:34 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox