diff mbox series

[8/8] vfio: Split VFIO_GROUP_GET_STATUS into a function

Message ID 8-v1-11d8272dc65a+4bd-vfio_ioctl_split_jgg@nvidia.com (mailing list archive)
State New, archived
Headers show
Series Break up ioctl dispatch functions to one function per ioctl | expand

Commit Message

Jason Gunthorpe Aug. 17, 2022, 4:07 p.m. UTC
This is the last sizable implementation in vfio_group_fops_unl_ioctl(),
move it to a function so vfio_group_fops_unl_ioctl() is emptied out.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_main.c | 55 ++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

Comments

Jason Gunthorpe Aug. 26, 2022, 11:43 p.m. UTC | #1
On Wed, Aug 17, 2022 at 01:07:25PM -0300, Jason Gunthorpe wrote:
> This is the last sizable implementation in vfio_group_fops_unl_ioctl(),
> move it to a function so vfio_group_fops_unl_ioctl() is emptied out.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/vfio_main.c | 55 ++++++++++++++++++++--------------------
>  1 file changed, 27 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 78957f45c37a34..6f96e6d07a5e98 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1227,6 +1227,32 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
>  	vfio_device_put(device);
>  	return ret;
>  }
> +static int vfio_group_ioctl_get_status(struct vfio_group *group,
> +				       struct vfio_group_status __user *arg)

There is a missing blank line after the } here

Jason
Tian, Kevin Aug. 29, 2022, 12:43 a.m. UTC | #2
> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Thursday, August 18, 2022 12:07 AM
> 
> This is the last sizable implementation in vfio_group_fops_unl_ioctl(),
> move it to a function so vfio_group_fops_unl_ioctl() is emptied out.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Alex Williamson Aug. 30, 2022, 4:43 p.m. UTC | #3
On Fri, 26 Aug 2022 20:43:07 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:

> On Wed, Aug 17, 2022 at 01:07:25PM -0300, Jason Gunthorpe wrote:
> > This is the last sizable implementation in vfio_group_fops_unl_ioctl(),
> > move it to a function so vfio_group_fops_unl_ioctl() is emptied out.
> > 
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  drivers/vfio/vfio_main.c | 55 ++++++++++++++++++++--------------------
> >  1 file changed, 27 insertions(+), 28 deletions(-)
> > 
> > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> > index 78957f45c37a34..6f96e6d07a5e98 100644
> > --- a/drivers/vfio/vfio_main.c
> > +++ b/drivers/vfio/vfio_main.c
> > @@ -1227,6 +1227,32 @@ static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
> >  	vfio_device_put(device);
> >  	return ret;
> >  }
> > +static int vfio_group_ioctl_get_status(struct vfio_group *group,
> > +				       struct vfio_group_status __user *arg)  
> 
> There is a missing blank line after the } here

Fixed locally if there's no other need for a respin.  Thanks,

Alex
diff mbox series

Patch

diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 78957f45c37a34..6f96e6d07a5e98 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -1227,6 +1227,32 @@  static int vfio_group_ioctl_get_device_fd(struct vfio_group *group,
 	vfio_device_put(device);
 	return ret;
 }
+static int vfio_group_ioctl_get_status(struct vfio_group *group,
+				       struct vfio_group_status __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_group_status, flags);
+	struct vfio_group_status status;
+
+	if (copy_from_user(&status, arg, minsz))
+		return -EFAULT;
+
+	if (status.argsz < minsz)
+		return -EINVAL;
+
+	status.flags = 0;
+
+	down_read(&group->group_rwsem);
+	if (group->container)
+		status.flags |= VFIO_GROUP_FLAGS_CONTAINER_SET |
+				VFIO_GROUP_FLAGS_VIABLE;
+	else if (!iommu_group_dma_owner_claimed(group->iommu_group))
+		status.flags |= VFIO_GROUP_FLAGS_VIABLE;
+	up_read(&group->group_rwsem);
+
+	if (copy_to_user(arg, &status, minsz))
+		return -EFAULT;
+	return 0;
+}
 
 static long vfio_group_fops_unl_ioctl(struct file *filep,
 				      unsigned int cmd, unsigned long arg)
@@ -1239,34 +1265,7 @@  static long vfio_group_fops_unl_ioctl(struct file *filep,
 	case VFIO_GROUP_GET_DEVICE_FD:
 		return vfio_group_ioctl_get_device_fd(group, uarg);
 	case VFIO_GROUP_GET_STATUS:
-	{
-		struct vfio_group_status status;
-		unsigned long minsz;
-
-		minsz = offsetofend(struct vfio_group_status, flags);
-
-		if (copy_from_user(&status, (void __user *)arg, minsz))
-			return -EFAULT;
-
-		if (status.argsz < minsz)
-			return -EINVAL;
-
-		status.flags = 0;
-
-		down_read(&group->group_rwsem);
-		if (group->container)
-			status.flags |= VFIO_GROUP_FLAGS_CONTAINER_SET |
-					VFIO_GROUP_FLAGS_VIABLE;
-		else if (!iommu_group_dma_owner_claimed(group->iommu_group))
-			status.flags |= VFIO_GROUP_FLAGS_VIABLE;
-		up_read(&group->group_rwsem);
-
-		if (copy_to_user((void __user *)arg, &status, minsz))
-			return -EFAULT;
-
-		ret = 0;
-		break;
-	}
+		return vfio_group_ioctl_get_status(group, uarg);
 	case VFIO_GROUP_SET_CONTAINER:
 		return  vfio_group_ioctl_set_container(group, uarg);
 	case VFIO_GROUP_UNSET_CONTAINER: