From: Alberto Faria <afaria@redhat.com>
To: linux-block@vger.kernel.org
Cc: Alberto Faria <afaria@redhat.com>
Subject: [PATCH 1/2] virtio_blk: add fua write support
Date: Wed, 21 Oct 2026 06:52:33 +0100 [thread overview]
Message-ID: <20261021055235.648957-2-afaria@redhat.com> (raw)
In-Reply-To: <20261021055235.648957-1-afaria@redhat.com>
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 | 15 +++++++++++++--
include/uapi/linux/virtio_blk.h | 13 +++++++++++--
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c8bfbf8435ac7..f2ef0fdba181d 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,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 = {
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.0
next prev parent reply other threads:[~2026-10-21 5:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 5:52 [PATCH 0/2] virtio_blk: add FUA write support Alberto Faria
2026-10-21 5:52 ` Alberto Faria [this message]
2026-10-21 5:52 ` [PATCH 2/2] vdpa_sim_blk: add support for FUA writes Alberto Faria
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261021055235.648957-2-afaria@redhat.com \
--to=afaria@redhat.com \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox