vfio/mbochs: Convert mbochs to use vfio_info_add_capability()

This driver open codes the cap chain manipulations. Instead use
vfio_info_add_capability() and the get_region_info_caps() op.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/16-v2-2a9e24d62f1b+e10a-vfio_get_region_info_op_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
This commit is contained in:
Jason Gunthorpe 2025-11-07 13:41:32 -04:00 committed by Alex Williamson
parent 775f726a74
commit 45f9fa1810
1 changed files with 23 additions and 52 deletions

View File

@ -143,11 +143,6 @@ static struct mdev_parent mbochs_parent;
static atomic_t mbochs_avail_mbytes; static atomic_t mbochs_avail_mbytes;
static const struct vfio_device_ops mbochs_dev_ops; static const struct vfio_device_ops mbochs_dev_ops;
struct vfio_region_info_ext {
struct vfio_region_info base;
struct vfio_region_info_cap_type type;
};
struct mbochs_mode { struct mbochs_mode {
u32 drm_format; u32 drm_format;
u32 bytepp; u32 bytepp;
@ -1033,10 +1028,12 @@ static int mbochs_dmabuf_export(struct mbochs_dmabuf *dmabuf)
return 0; return 0;
} }
static int mbochs_get_region_info(struct mdev_state *mdev_state, static int mbochs_ioctl_get_region_info(struct vfio_device *vdev,
struct vfio_region_info_ext *ext) struct vfio_region_info *region_info,
struct vfio_info_cap *caps)
{ {
struct vfio_region_info *region_info = &ext->base; struct mdev_state *mdev_state =
container_of(vdev, struct mdev_state, vdev);
if (region_info->index >= MBOCHS_NUM_REGIONS) if (region_info->index >= MBOCHS_NUM_REGIONS)
return -EINVAL; return -EINVAL;
@ -1061,20 +1058,23 @@ static int mbochs_get_region_info(struct mdev_state *mdev_state,
region_info->flags = (VFIO_REGION_INFO_FLAG_READ | region_info->flags = (VFIO_REGION_INFO_FLAG_READ |
VFIO_REGION_INFO_FLAG_WRITE); VFIO_REGION_INFO_FLAG_WRITE);
break; break;
case MBOCHS_EDID_REGION_INDEX: case MBOCHS_EDID_REGION_INDEX: {
ext->base.argsz = sizeof(*ext); struct vfio_region_info_cap_type cap_type = {
ext->base.offset = MBOCHS_EDID_OFFSET; .header.id = VFIO_REGION_INFO_CAP_TYPE,
ext->base.size = MBOCHS_EDID_SIZE; .header.version = 1,
ext->base.flags = (VFIO_REGION_INFO_FLAG_READ | .type = VFIO_REGION_TYPE_GFX,
VFIO_REGION_INFO_FLAG_WRITE | .subtype = VFIO_REGION_SUBTYPE_GFX_EDID,
VFIO_REGION_INFO_FLAG_CAPS); };
ext->base.cap_offset = offsetof(typeof(*ext), type);
ext->type.header.id = VFIO_REGION_INFO_CAP_TYPE; region_info->offset = MBOCHS_EDID_OFFSET;
ext->type.header.version = 1; region_info->size = MBOCHS_EDID_SIZE;
ext->type.header.next = 0; region_info->flags = (VFIO_REGION_INFO_FLAG_READ |
ext->type.type = VFIO_REGION_TYPE_GFX; VFIO_REGION_INFO_FLAG_WRITE |
ext->type.subtype = VFIO_REGION_SUBTYPE_GFX_EDID; VFIO_REGION_INFO_FLAG_CAPS);
break;
return vfio_info_add_capability(caps, &cap_type.header,
sizeof(cap_type));
}
default: default:
region_info->size = 0; region_info->size = 0;
region_info->offset = 0; region_info->offset = 0;
@ -1185,35 +1185,6 @@ static int mbochs_get_gfx_dmabuf(struct mdev_state *mdev_state, u32 id)
return dma_buf_fd(dmabuf->buf, 0); return dma_buf_fd(dmabuf->buf, 0);
} }
static int mbochs_ioctl_get_region_info(struct vfio_device *vdev,
struct vfio_region_info __user *arg)
{
struct mdev_state *mdev_state =
container_of(vdev, struct mdev_state, vdev);
struct vfio_region_info_ext info;
unsigned long minsz, outsz;
int ret;
minsz = offsetofend(typeof(info), base.offset);
if (copy_from_user(&info, arg, minsz))
return -EFAULT;
outsz = info.base.argsz;
if (outsz < minsz)
return -EINVAL;
if (outsz > sizeof(info))
return -EINVAL;
ret = mbochs_get_region_info(mdev_state, &info);
if (ret)
return ret;
if (copy_to_user(arg, &info, outsz))
return -EFAULT;
return 0;
}
static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
@ -1381,7 +1352,7 @@ static const struct vfio_device_ops mbochs_dev_ops = {
.read = mbochs_read, .read = mbochs_read,
.write = mbochs_write, .write = mbochs_write,
.ioctl = mbochs_ioctl, .ioctl = mbochs_ioctl,
.get_region_info = mbochs_ioctl_get_region_info, .get_region_info_caps = mbochs_ioctl_get_region_info,
.mmap = mbochs_mmap, .mmap = mbochs_mmap,
.bind_iommufd = vfio_iommufd_emulated_bind, .bind_iommufd = vfio_iommufd_emulated_bind,
.unbind_iommufd = vfio_iommufd_emulated_unbind, .unbind_iommufd = vfio_iommufd_emulated_unbind,