Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH v2 0/2] virtio_blk: add FUA write support
@ 2026-11-25  7:54 Alberto Faria
  2026-11-25  7:54 ` [PATCH v2 1/2] virtio_blk: add fua " Alberto Faria
  2026-11-25  7:54 ` [PATCH v2 2/2] vdpa_sim_blk: add support for FUA writes Alberto Faria
  0 siblings, 2 replies; 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

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/20251112055113.62207-1-afaria@redhat.com/

v2:
- Check for VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA when handling requests with REQ_FUA.
- Don't advertise FUA support on zoned devices.
- Restore BLK_FEAT_FUA in cache_type_store().
- vdpa_sim: Reject VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA without VIRTIO_BLK_F_REQ_FLAGS.

Alberto Faria (2):
  virtio_blk: add fua write support
  vdpa_sim_blk: add support for FUA writes

 drivers/block/virtio_blk.c           | 28 ++++++++++++++++++++++++++--
 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 +++++++++++++-
 include/uapi/linux/virtio_blk.h      | 13 +++++++++++--
 5 files changed, 64 insertions(+), 5 deletions(-)

-- 
2.56.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [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

* Re: [PATCH v2 2/2] vdpa_sim_blk: add support for FUA writes
  2026-11-25  7:54 ` [PATCH v2 2/2] vdpa_sim_blk: add support for FUA writes Alberto Faria
@ 2026-11-25  8:05   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-25  8:05 UTC (permalink / raw)
  To: Alberto Faria; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] vdpa_sim: vdpasim_create() clobbers ret with 0, returning
  NULL on error
--

commit 44caf7459577594a98fabfacf52e1c5c4e5f2cf1
Author: Alberto Faria <afaria@redhat.com>

vdpa_sim_blk: add support for FUA writes

This commit adds a validate_features callback to vdpasim_dev_attr and
exposes VIRTIO_BLK_F_REQ_FLAGS and VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA in
vdpa_sim_blk.

> 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;
>  	}

[Severity: Medium]
Can assigning the return value of dev_attr->validate_features() to ret
cause vdpasim_create() to return NULL instead of an error pointer on later
failures?

ret is initialized to -ENOMEM at the start of vdpasim_create() for the
allocation and dma_set_mask_and_coherent() failure paths that jump to
err_iommu without setting ret.  When validate_features() succeeds, it
overwrites ret with 0, so a later allocation failure frees dev and returns
ERR_PTR(0) (NULL), causing callers such as vdpasim_blk_dev_add() that only
check IS_ERR(simdev) to dereference NULL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125075408.226762-1-afaria@redhat.com?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] virtio_blk: add fua write support
  2026-11-25  7:54 ` [PATCH v2 1/2] virtio_blk: add fua " Alberto Faria
@ 2026-11-25  8:09   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-25  8:09 UTC (permalink / raw)
  To: Alberto Faria; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] virtio_blk: missing VIRTIO_BLK_F_REQ_FLAGS check in
  virtblk_setup_cmd()
--

commit f7bfe54853bedaa1afa630f98325bb99ee3bb7cb
Author: Alberto Faria <afaria@redhat.com>

virtio_blk: add fua write support

This commit adds UAPI definitions for virtio-blk request flags and
VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA, and teaches virtio_blk to advertise and
handle REQ_FUA writes.

> 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;

[Severity: Medium]
Should REQ_OP_WRITE also check VIRTIO_BLK_F_REQ_FLAGS before touching
vbr->out_hdr.flags, or should virtio_blk clear
VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA in a .validate callback when
VIRTIO_BLK_F_REQ_FLAGS is not offered?

Unlike virtblk_probe() and cache_type_store(), which check both features,
virtblk_setup_cmd() only checks VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA here.  If
VIRTIO_BLK_F_REQ_FLAGS is not negotiated (for example, when filtered out
via debugfs_filter_features), virtio_blk accepts
VIRTIO_BLK_F_REQ_FLAGS_OUT_FUA without its prerequisite feature and can
fail feature negotiation with spec-compliant devices, or overwrite
vbr->out_hdr.ioprio in the union if a REQ_FUA write reaches the queue.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125075408.226762-1-afaria@redhat.com?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-25  8:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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  8:09   ` sashiko-bot
2026-11-25  7:54 ` [PATCH v2 2/2] vdpa_sim_blk: add support for FUA writes Alberto Faria
2026-11-25  8:05   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox