From: Alberto Faria <afaria@redhat.com>
To: linux-block@vger.kernel.org
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jens Axboe" <axboe@kernel.dk>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Alberto Faria" <afaria@redhat.com>
Subject: [PATCH v3 2/2] vdpa_sim_blk: add support for FUA writes
Date: Wed, 25 Nov 2026 08:39:47 +0000 [thread overview]
Message-ID: <20261125083947.263216-3-afaria@redhat.com> (raw)
In-Reply-To: <20261125083947.263216-1-afaria@redhat.com>
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 | 15 ++++++++++++++-
drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 +
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 14 +++++++++++++-
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 97d437d89524a..bec348d3dd7d1 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -198,7 +198,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
struct vdpa_device *vdpa;
struct vdpasim *vdpasim;
struct device *dev;
- int i, ret = -ENOMEM;
+ int i, ret = -ENOMEM, ret2;
if (!dev_attr->alloc_size)
return ERR_PTR(-EINVAL);
@@ -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) {
+ ret2 = dev_attr->validate_features(
+ config->device_features);
+ if (ret2)
+ return ERR_PTR(ret2);
+ }
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
next prev parent reply other threads:[~2026-11-25 8:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 8:39 [PATCH v3 0/2] virtio_blk: add FUA write support Alberto Faria
2026-11-25 8:39 ` [PATCH v3 1/2] virtio_blk: add fua " Alberto Faria
2026-11-25 9:07 ` Johannes Thumshirn
2026-11-25 9:16 ` Alberto Faria
2026-11-25 9:09 ` Damien Le Moal
2026-11-25 8:39 ` Alberto Faria [this message]
2026-11-25 8:48 ` [PATCH v3 0/2] virtio_blk: add FUA " sashiko-bot
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=20261125083947.263216-3-afaria@redhat.com \
--to=afaria@redhat.com \
--cc=axboe@kernel.dk \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=linux-block@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/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