Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -1575,6 +1581,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);
Expand Down Expand Up @@ -1740,7 +1750,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 = {
Expand Down
4 changes: 3 additions & 1 deletion drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions include/uapi/linux/virtio_blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
};
Expand Down
Loading