]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
vDPA: report virtio-block topology info to user space
authorZhu Lingshan <lingshan.zhu@intel.com>
Sun, 18 Feb 2024 18:56:02 +0000 (02:56 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 19 Mar 2024 06:45:51 +0000 (02:45 -0400)
This commit allows vDPA reporting topology information of
virtio-blk devices to user space, includes:
1) the number of logical blocks per physical block
2) offset of first aligned logical block
3) suggested minimum I/O size in blocks
4) optimal (suggested maximum) I/O size in blocks

Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
Message-Id: <20240218185606.13509-7-lingshan.zhu@intel.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vdpa/vdpa.c
include/uapi/linux/vdpa.h

index 4c348da1f2f72ea9b7593b3e572fb2762dac6f84..76b2e31d6229a75f3d39148f308a1cd191982e53 100644 (file)
@@ -1012,6 +1012,35 @@ static int vdpa_dev_blk_mq_config_fill(struct sk_buff *msg, u64 features,
        return nla_put_u16(msg, VDPA_ATTR_DEV_BLK_CFG_NUM_QUEUES, val_u16);
 }
 
+static int vdpa_dev_blk_topology_config_fill(struct sk_buff *msg, u64 features,
+                                      const struct virtio_blk_config *config)
+{
+       u16 min_io_size;
+       u32 opt_io_size;
+
+       if ((features & BIT_ULL(VIRTIO_BLK_F_TOPOLOGY)) == 0)
+               return 0;
+
+       min_io_size = __virtio16_to_cpu(true, config->min_io_size);
+       opt_io_size = __virtio32_to_cpu(true, config->opt_io_size);
+
+       if (nla_put_u8(msg, VDPA_ATTR_DEV_BLK_CFG_PHY_BLK_EXP,
+           config->physical_block_exp))
+               return -EMSGSIZE;
+
+       if (nla_put_u8(msg, VDPA_ATTR_DEV_BLK_CFG_ALIGN_OFFSET,
+           config->alignment_offset))
+               return -EMSGSIZE;
+
+       if (nla_put_u16(msg, VDPA_ATTR_DEV_BLK_CFG_MIN_IO_SIZE, min_io_size))
+               return -EMSGSIZE;
+
+       if (nla_put_u32(msg, VDPA_ATTR_DEV_BLK_CFG_OPT_IO_SIZE, opt_io_size))
+               return -EMSGSIZE;
+
+       return 0;
+}
+
 static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
                                    struct sk_buff *msg)
 {
@@ -1041,6 +1070,9 @@ static int vdpa_dev_blk_config_fill(struct vdpa_device *vdev,
        if (vdpa_dev_blk_mq_config_fill(msg, features_device, &config))
                return -EMSGSIZE;
 
+       if (vdpa_dev_blk_topology_config_fill(msg, features_device, &config))
+               return -EMSGSIZE;
+
        return 0;
 }
 
index 3c8e3c87a864edb6d11305625ead6811f1a2db95..5cc70614c97a624fb2af17b35462c26e8150f435 100644 (file)
@@ -61,6 +61,10 @@ enum vdpa_attr {
        VDPA_ATTR_DEV_BLK_CFG_BLK_SIZE,         /* u32 */
        VDPA_ATTR_DEV_BLK_CFG_SEG_MAX,          /* u32 */
        VDPA_ATTR_DEV_BLK_CFG_NUM_QUEUES,       /* u16 */
+       VDPA_ATTR_DEV_BLK_CFG_PHY_BLK_EXP,      /* u8 */
+       VDPA_ATTR_DEV_BLK_CFG_ALIGN_OFFSET,     /* u8 */
+       VDPA_ATTR_DEV_BLK_CFG_MIN_IO_SIZE,      /* u16 */
+       VDPA_ATTR_DEV_BLK_CFG_OPT_IO_SIZE,      /* u32 */
 
        /* new attributes must be added above here */
        VDPA_ATTR_MAX,