* [PATCH v2 1/2] virtio_blk: add fua write support
2026-11-25 7:54 [PATCH v2 0/2] virtio_blk: add FUA write support Alberto Faria
@ 2026-11-25 7:54 ` Alberto Faria
2026-11-25 8:09 ` sashiko-bot
2026-11-25 7:54 ` [PATCH v2 2/2] vdpa_sim_blk: add support for FUA writes Alberto Faria
1 sibling, 1 reply; 5+ messages in thread
From: Alberto Faria @ 2026-11-25 7:54 UTC (permalink / raw)
To: linux-block
Cc: virtualization, Xuan Zhuo, Jason Wang, Paolo Bonzini, Jens Axboe,
Eugenio Pérez, Stefan Hajnoczi, Michael S. Tsirkin,
Alberto Faria
Add the new virtio-blk request FUA flag uapi definitions and
corresponding virtio-blk support.
Signed-off-by: Alberto Faria <afaria@redhat.com>
---
drivers/block/virtio_blk.c | 28 ++++++++++++++++++++++++++--
include/uapi/linux/virtio_blk.h | 13 +++++++++++--
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 2b462005cdb68..b91d7dbd25cfd 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -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,10 @@ 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) &&
+ virtio_has_feature(vdev, VIRTIO_BLK_F_REQ_FLAGS_OUT_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;
@@ -1151,10 +1158,17 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
virtio_cwrite8(vdev, offsetof(struct virtio_blk_config, wce), i);
lim = queue_limits_start_update(disk->queue);
+
if (virtblk_get_cache_mode(vdev))
lim.features |= BLK_FEAT_WRITE_CACHE;
else
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_ZONED))
+ lim.features |= BLK_FEAT_FUA;
+
i = queue_limits_commit_update_frozen(disk->queue, &lim);
if (i)
return i;
@@ -1575,6 +1589,15 @@ static int virtblk_probe(struct virtio_device *vdev)
if (virtblk_get_cache_mode(vdev))
lim.features |= BLK_FEAT_WRITE_CACHE;
+ /*
+ * Do not advertise FUA when the device is zoned, since we
+ * would not be able to handle it on REQ_OP_ZONE_APPEND.
+ */
+ 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_ZONED))
+ 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);
@@ -1740,7 +1763,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 = {
diff --git a/include/uapi/linux/virtio_blk.h b/include/uapi/linux/virtio_blk.h
index 3744e4da1b2a7..c5047e6a9a9bc 100644
--- a/include/uapi/linux/virtio_blk.h
+++ b/include/uapi/linux/virtio_blk.h
@@ -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;
};
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/2] vdpa_sim_blk: add support for FUA writes
2026-11-25 7:54 [PATCH v2 0/2] virtio_blk: add FUA write support Alberto Faria
2026-11-25 7:54 ` [PATCH v2 1/2] virtio_blk: add fua " Alberto Faria
@ 2026-11-25 7:54 ` Alberto Faria
2026-11-25 8:05 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Alberto Faria @ 2026-11-25 7:54 UTC (permalink / raw)
To: linux-block
Cc: virtualization, Xuan Zhuo, Jason Wang, Paolo Bonzini, Jens Axboe,
Eugenio Pérez, Stefan Hajnoczi, Michael S. Tsirkin,
Alberto Faria
Expose 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.
Signed-off-by: Alberto Faria <afaria@redhat.com>
---
drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++
drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 +
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 14 +++++++++++++-
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 97d437d89524a..888ea80f6e0af 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -209,6 +209,12 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
if (config->device_features &
~dev_attr->supported_features)
return ERR_PTR(-EINVAL);
+ if (dev_attr->validate_features) {
+ ret = dev_attr->validate_features(
+ config->device_features);
+ if (ret)
+ return ERR_PTR(ret);
+ }
dev_attr->supported_features =
config->device_features;
}
@@ -442,11 +448,18 @@ static u64 vdpasim_get_backend_features(const struct vdpa_device *vdpa)
static int vdpasim_set_driver_features(struct vdpa_device *vdpa, u64 features)
{
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
+ int ret;
/* DMA mapping must be done by driver */
if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
return -EINVAL;
+ if (vdpasim->dev_attr.validate_features) {
+ ret = vdpasim->dev_attr.validate_features(features);
+ if (ret)
+ return ret;
+ }
+
vdpasim->features = features & vdpasim->dev_attr.supported_features;
return 0;
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h
index bb137e4797633..70890974b6e56 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.h
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h
@@ -45,6 +45,7 @@ struct vdpasim_dev_attr {
u32 nas;
void (*work_fn)(struct vdpasim *vdpasim);
+ int (*validate_features)(u64 features);
void (*get_config)(struct vdpasim *vdpasim, void *config);
void (*set_config)(struct vdpasim *vdpasim, const void *config);
int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
index 4d3e36fb59d50..e0ed9eb729cf3 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
@@ -32,7 +32,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
@@ -371,6 +373,15 @@ static void vdpasim_blk_work(struct vdpasim *vdpasim)
vdpasim_schedule_work(vdpasim);
}
+static int vdpasim_blk_validate_features(u64 features)
+{
+ if ((features & BIT_ULL(VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA)) &&
+ !(features & BIT_ULL(VIRTIO_BLK_F_REQ_FLAGS)))
+ return -EINVAL;
+
+ return 0;
+}
+
static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config)
{
struct virtio_blk_config *blk_config = config;
@@ -424,6 +435,7 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
dev_attr.nas = VDPASIM_BLK_AS_NUM;
dev_attr.alloc_size = sizeof(struct vdpasim_blk);
dev_attr.config_size = sizeof(struct virtio_blk_config);
+ dev_attr.validate_features = vdpasim_blk_validate_features;
dev_attr.get_config = vdpasim_blk_get_config;
dev_attr.work_fn = vdpasim_blk_work;
dev_attr.free = vdpasim_blk_free;
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread