Remove duplication by consolidating these here. This reduces the posibility of a parent driver missing them. While we're at it, fix a bug in vdpa_sim where a valid ASID can be assigned to a group equal to ngroups, causing an out of bound write.
Unified · Split
| @@ -3640,9 +3640,6 @@ static int mlx5_set_group_asid(struct vdpa_device *vdev, u32 group, · 3639 unmodified lines | |||
| 3640 | struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); | 3640 | struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); |
| 3641 | int err = 0; | 3641 | int err = 0; |
| 3642 | 3642 | ||
| 3643 | if (group >= MLX5_VDPA_NUMVQ_GROUPS) | ||
| 3644 | return -EINVAL; | ||
| 3645 | |||
| 3646 | mvdev->mres.group2asid[group] = asid; | 3643 | mvdev->mres.group2asid[group] = asid; |
| 3647 | 3644 | ||
| 3648 | mutex_lock(&mvdev->mres.lock); | 3645 | mutex_lock(&mvdev->mres.lock); |
| @@ -606,12 +606,6 @@ static int vdpasim_set_group_asid(struct vdpa_device *vdpa, unsigned int group, · 605 unmodified lines | |||
| 606 | struct vhost_iotlb *iommu; | 606 | struct vhost_iotlb *iommu; |
| 607 | int i; | 607 | int i; |
| 608 | 608 | ||
| 609 | if (group > vdpasim->dev_attr.ngroups) | ||
| 610 | return -EINVAL; | ||
| 611 | |||
| 612 | if (asid >= vdpasim->dev_attr.nas) | ||
| 613 | return -EINVAL; | ||
| 614 | |||
| 615 | iommu = &vdpasim->iommu[asid]; | 609 | iommu = &vdpasim->iommu[asid]; |
| 616 | 610 | ||
| 617 | mutex_lock(&vdpasim->mutex); | 611 | mutex_lock(&vdpasim->mutex); |
| @@ -680,7 +680,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, · 679 unmodified lines | |||
| 680 | case VHOST_VDPA_SET_GROUP_ASID: | 680 | case VHOST_VDPA_SET_GROUP_ASID: |
| 681 | if (copy_from_user(&s, argp, sizeof(s))) | 681 | if (copy_from_user(&s, argp, sizeof(s))) |
| 682 | return -EFAULT; | 682 | return -EFAULT; |
| 683 | if (s.num >= vdpa->nas) | 683 | if (idx >= vdpa->ngroups || s.num >= vdpa->nas) |
| 684 | return -EINVAL; | 684 | return -EINVAL; |
| 685 | if (!ops->set_group_asid) | 685 | if (!ops->set_group_asid) |
| 686 | return -EOPNOTSUPP; | 686 | return -EOPNOTSUPP; |