Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Jason Gunthorpe and committed by
Alex Williamson
45f9fa18 775f726a

+23 -52
+23 -52
samples/vfio-mdev/mbochs.c
··· 143 143 static atomic_t mbochs_avail_mbytes; 144 144 static const struct vfio_device_ops mbochs_dev_ops; 145 145 146 - struct vfio_region_info_ext { 147 - struct vfio_region_info base; 148 - struct vfio_region_info_cap_type type; 149 - }; 150 - 151 146 struct mbochs_mode { 152 147 u32 drm_format; 153 148 u32 bytepp; ··· 1028 1033 return 0; 1029 1034 } 1030 1035 1031 - static int mbochs_get_region_info(struct mdev_state *mdev_state, 1032 - struct vfio_region_info_ext *ext) 1036 + static int mbochs_ioctl_get_region_info(struct vfio_device *vdev, 1037 + struct vfio_region_info *region_info, 1038 + struct vfio_info_cap *caps) 1033 1039 { 1034 - struct vfio_region_info *region_info = &ext->base; 1040 + struct mdev_state *mdev_state = 1041 + container_of(vdev, struct mdev_state, vdev); 1035 1042 1036 1043 if (region_info->index >= MBOCHS_NUM_REGIONS) 1037 1044 return -EINVAL; ··· 1058 1061 region_info->flags = (VFIO_REGION_INFO_FLAG_READ | 1059 1062 VFIO_REGION_INFO_FLAG_WRITE); 1060 1063 break; 1061 - case MBOCHS_EDID_REGION_INDEX: 1062 - ext->base.argsz = sizeof(*ext); 1063 - ext->base.offset = MBOCHS_EDID_OFFSET; 1064 - ext->base.size = MBOCHS_EDID_SIZE; 1065 - ext->base.flags = (VFIO_REGION_INFO_FLAG_READ | 1066 - VFIO_REGION_INFO_FLAG_WRITE | 1067 - VFIO_REGION_INFO_FLAG_CAPS); 1068 - ext->base.cap_offset = offsetof(typeof(*ext), type); 1069 - ext->type.header.id = VFIO_REGION_INFO_CAP_TYPE; 1070 - ext->type.header.version = 1; 1071 - ext->type.header.next = 0; 1072 - ext->type.type = VFIO_REGION_TYPE_GFX; 1073 - ext->type.subtype = VFIO_REGION_SUBTYPE_GFX_EDID; 1074 - break; 1064 + case MBOCHS_EDID_REGION_INDEX: { 1065 + struct vfio_region_info_cap_type cap_type = { 1066 + .header.id = VFIO_REGION_INFO_CAP_TYPE, 1067 + .header.version = 1, 1068 + .type = VFIO_REGION_TYPE_GFX, 1069 + .subtype = VFIO_REGION_SUBTYPE_GFX_EDID, 1070 + }; 1071 + 1072 + region_info->offset = MBOCHS_EDID_OFFSET; 1073 + region_info->size = MBOCHS_EDID_SIZE; 1074 + region_info->flags = (VFIO_REGION_INFO_FLAG_READ | 1075 + VFIO_REGION_INFO_FLAG_WRITE | 1076 + VFIO_REGION_INFO_FLAG_CAPS); 1077 + 1078 + return vfio_info_add_capability(caps, &cap_type.header, 1079 + sizeof(cap_type)); 1080 + } 1075 1081 default: 1076 1082 region_info->size = 0; 1077 1083 region_info->offset = 0; ··· 1183 1183 return -EINVAL; 1184 1184 1185 1185 return dma_buf_fd(dmabuf->buf, 0); 1186 - } 1187 - 1188 - static int mbochs_ioctl_get_region_info(struct vfio_device *vdev, 1189 - struct vfio_region_info __user *arg) 1190 - { 1191 - struct mdev_state *mdev_state = 1192 - container_of(vdev, struct mdev_state, vdev); 1193 - struct vfio_region_info_ext info; 1194 - unsigned long minsz, outsz; 1195 - int ret; 1196 - 1197 - minsz = offsetofend(typeof(info), base.offset); 1198 - 1199 - if (copy_from_user(&info, arg, minsz)) 1200 - return -EFAULT; 1201 - 1202 - outsz = info.base.argsz; 1203 - if (outsz < minsz) 1204 - return -EINVAL; 1205 - if (outsz > sizeof(info)) 1206 - return -EINVAL; 1207 - 1208 - ret = mbochs_get_region_info(mdev_state, &info); 1209 - if (ret) 1210 - return ret; 1211 - 1212 - if (copy_to_user(arg, &info, outsz)) 1213 - return -EFAULT; 1214 - return 0; 1215 1186 } 1216 1187 1217 1188 static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd, ··· 1352 1381 .read = mbochs_read, 1353 1382 .write = mbochs_write, 1354 1383 .ioctl = mbochs_ioctl, 1355 - .get_region_info = mbochs_ioctl_get_region_info, 1384 + .get_region_info_caps = mbochs_ioctl_get_region_info, 1356 1385 .mmap = mbochs_mmap, 1357 1386 .bind_iommufd = vfio_iommufd_emulated_bind, 1358 1387 .unbind_iommufd = vfio_iommufd_emulated_unbind,