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/gvt: Convert to get_region_info_caps

Remove the duplicate code and change info to a pointer.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/17-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
93165757 45f9fa18

+42 -71
+42 -71
drivers/gpu/drm/i915/gvt/kvmgt.c
··· 1141 1141 } 1142 1142 1143 1143 static int intel_vgpu_ioctl_get_region_info(struct vfio_device *vfio_dev, 1144 - struct vfio_region_info __user *arg) 1144 + struct vfio_region_info *info, 1145 + struct vfio_info_cap *caps) 1145 1146 { 1146 - struct vfio_info_cap caps = { .buf = NULL, .size = 0 }; 1147 1147 struct vfio_region_info_cap_sparse_mmap *sparse = NULL; 1148 1148 struct intel_vgpu *vgpu = vfio_dev_to_vgpu(vfio_dev); 1149 - struct vfio_region_info info; 1150 - unsigned long minsz; 1151 1149 int nr_areas = 1; 1152 1150 int cap_type_id; 1153 1151 unsigned int i; 1154 1152 int ret; 1155 1153 1156 - minsz = offsetofend(struct vfio_region_info, offset); 1157 - 1158 - if (copy_from_user(&info, arg, minsz)) 1159 - return -EFAULT; 1160 - 1161 - if (info.argsz < minsz) 1162 - return -EINVAL; 1163 - 1164 - switch (info.index) { 1154 + switch (info->index) { 1165 1155 case VFIO_PCI_CONFIG_REGION_INDEX: 1166 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1167 - info.size = vgpu->gvt->device_info.cfg_space_size; 1168 - info.flags = VFIO_REGION_INFO_FLAG_READ | 1169 - VFIO_REGION_INFO_FLAG_WRITE; 1156 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1157 + info->size = vgpu->gvt->device_info.cfg_space_size; 1158 + info->flags = VFIO_REGION_INFO_FLAG_READ | 1159 + VFIO_REGION_INFO_FLAG_WRITE; 1170 1160 break; 1171 1161 case VFIO_PCI_BAR0_REGION_INDEX: 1172 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1173 - info.size = vgpu->cfg_space.bar[info.index].size; 1174 - if (!info.size) { 1175 - info.flags = 0; 1162 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1163 + info->size = vgpu->cfg_space.bar[info->index].size; 1164 + if (!info->size) { 1165 + info->flags = 0; 1176 1166 break; 1177 1167 } 1178 1168 1179 - info.flags = VFIO_REGION_INFO_FLAG_READ | 1180 - VFIO_REGION_INFO_FLAG_WRITE; 1169 + info->flags = VFIO_REGION_INFO_FLAG_READ | 1170 + VFIO_REGION_INFO_FLAG_WRITE; 1181 1171 break; 1182 1172 case VFIO_PCI_BAR1_REGION_INDEX: 1183 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1184 - info.size = 0; 1185 - info.flags = 0; 1173 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1174 + info->size = 0; 1175 + info->flags = 0; 1186 1176 break; 1187 1177 case VFIO_PCI_BAR2_REGION_INDEX: 1188 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1189 - info.flags = VFIO_REGION_INFO_FLAG_CAPS | 1190 - VFIO_REGION_INFO_FLAG_MMAP | 1191 - VFIO_REGION_INFO_FLAG_READ | 1192 - VFIO_REGION_INFO_FLAG_WRITE; 1193 - info.size = gvt_aperture_sz(vgpu->gvt); 1178 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1179 + info->flags = VFIO_REGION_INFO_FLAG_CAPS | 1180 + VFIO_REGION_INFO_FLAG_MMAP | 1181 + VFIO_REGION_INFO_FLAG_READ | 1182 + VFIO_REGION_INFO_FLAG_WRITE; 1183 + info->size = gvt_aperture_sz(vgpu->gvt); 1194 1184 1195 1185 sparse = kzalloc(struct_size(sparse, areas, nr_areas), 1196 1186 GFP_KERNEL); ··· 1197 1207 break; 1198 1208 1199 1209 case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX: 1200 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1201 - info.size = 0; 1202 - info.flags = 0; 1210 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1211 + info->size = 0; 1212 + info->flags = 0; 1203 1213 1204 - gvt_dbg_core("get region info bar:%d\n", info.index); 1214 + gvt_dbg_core("get region info bar:%d\n", info->index); 1205 1215 break; 1206 1216 1207 1217 case VFIO_PCI_ROM_REGION_INDEX: 1208 1218 case VFIO_PCI_VGA_REGION_INDEX: 1209 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1210 - info.size = 0; 1211 - info.flags = 0; 1219 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1220 + info->size = 0; 1221 + info->flags = 0; 1212 1222 1213 - gvt_dbg_core("get region info index:%d\n", info.index); 1223 + gvt_dbg_core("get region info index:%d\n", info->index); 1214 1224 break; 1215 1225 default: { 1216 1226 struct vfio_region_info_cap_type cap_type = { ··· 1218 1228 .header.version = 1 1219 1229 }; 1220 1230 1221 - if (info.index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions) 1231 + if (info->index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions) 1222 1232 return -EINVAL; 1223 - info.index = array_index_nospec( 1224 - info.index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions); 1233 + info->index = array_index_nospec( 1234 + info->index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions); 1225 1235 1226 - i = info.index - VFIO_PCI_NUM_REGIONS; 1236 + i = info->index - VFIO_PCI_NUM_REGIONS; 1227 1237 1228 - info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index); 1229 - info.size = vgpu->region[i].size; 1230 - info.flags = vgpu->region[i].flags; 1238 + info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index); 1239 + info->size = vgpu->region[i].size; 1240 + info->flags = vgpu->region[i].flags; 1231 1241 1232 1242 cap_type.type = vgpu->region[i].type; 1233 1243 cap_type.subtype = vgpu->region[i].subtype; 1234 1244 1235 - ret = vfio_info_add_capability(&caps, &cap_type.header, 1245 + ret = vfio_info_add_capability(caps, &cap_type.header, 1236 1246 sizeof(cap_type)); 1237 1247 if (ret) 1238 1248 return ret; 1239 1249 } 1240 1250 } 1241 1251 1242 - if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) { 1252 + if ((info->flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) { 1243 1253 switch (cap_type_id) { 1244 1254 case VFIO_REGION_INFO_CAP_SPARSE_MMAP: 1245 1255 ret = vfio_info_add_capability( 1246 - &caps, &sparse->header, 1256 + caps, &sparse->header, 1247 1257 struct_size(sparse, areas, sparse->nr_areas)); 1248 1258 if (ret) { 1249 1259 kfree(sparse); ··· 1256 1266 } 1257 1267 } 1258 1268 1259 - if (caps.size) { 1260 - info.flags |= VFIO_REGION_INFO_FLAG_CAPS; 1261 - if (info.argsz < sizeof(info) + caps.size) { 1262 - info.argsz = sizeof(info) + caps.size; 1263 - info.cap_offset = 0; 1264 - } else { 1265 - vfio_info_cap_shift(&caps, sizeof(info)); 1266 - if (copy_to_user((void __user *)arg + sizeof(info), 1267 - caps.buf, caps.size)) { 1268 - kfree(caps.buf); 1269 - kfree(sparse); 1270 - return -EFAULT; 1271 - } 1272 - info.cap_offset = sizeof(info); 1273 - } 1274 - 1275 - kfree(caps.buf); 1276 - } 1277 - 1278 1269 kfree(sparse); 1279 - return copy_to_user(arg, &info, minsz) ? -EFAULT : 0; 1270 + return 0; 1280 1271 } 1281 1272 1282 1273 static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd, ··· 1444 1473 .write = intel_vgpu_write, 1445 1474 .mmap = intel_vgpu_mmap, 1446 1475 .ioctl = intel_vgpu_ioctl, 1447 - .get_region_info = intel_vgpu_ioctl_get_region_info, 1476 + .get_region_info_caps = intel_vgpu_ioctl_get_region_info, 1448 1477 .dma_unmap = intel_vgpu_dma_unmap, 1449 1478 .bind_iommufd = vfio_iommufd_emulated_bind, 1450 1479 .unbind_iommufd = vfio_iommufd_emulated_unbind,