diff mbox

[v8,3/4] VFIO: Introduce helper vfio_pci_container_ioctl()

Message ID 1401951221-32613-4-git-send-email-gwshan@linux.vnet.ibm.com
State New
Headers show

Commit Message

Gavin Shan June 5, 2014, 6:53 a.m. UTC
The patch introduces helper function vfio_pci_container_ioctl() to
pass ioctl commands to the specified VFIO container that is identified
by IOMMU group id. On sPAPR platform, each container only has one
IOMMU group.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 hw/misc/vfio.c         | 31 +++++++++++++++++++++++++++++++
 include/hw/misc/vfio.h |  2 ++
 2 files changed, 33 insertions(+)

Comments

Alexander Graf June 5, 2014, 12:11 p.m. UTC | #1
On 05.06.14 08:53, Gavin Shan wrote:
> The patch introduces helper function vfio_pci_container_ioctl() to
> pass ioctl commands to the specified VFIO container that is identified
> by IOMMU group id. On sPAPR platform, each container only has one
> IOMMU group.
>
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
> ---
>   hw/misc/vfio.c         | 31 +++++++++++++++++++++++++++++++
>   include/hw/misc/vfio.h |  2 ++
>   2 files changed, 33 insertions(+)
>
> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
> index 0796abf..999d97d 100644
> --- a/hw/misc/vfio.c
> +++ b/hw/misc/vfio.c
> @@ -4310,3 +4310,34 @@ put_group_exit:
>   
>       return n;
>   }
> +
> +int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt)
> +{
> +    VFIOGroup *group;
> +    int ret, fd = 0;
> +
> +    /* Search container's fd */
> +    QLIST_FOREACH(group, &group_list, next) {
> +        if (group->groupid == iommu_group_id) {
> +            fd = group->container ? group->container->fd : 0;
> +            break;
> +        }
> +    }
> +
> +    if (fd <= 0) {

fd 0 is a valid file descriptor.


Alex
Alex Williamson June 5, 2014, 6:27 p.m. UTC | #2
On Thu, 2014-06-05 at 16:53 +1000, Gavin Shan wrote:
> The patch introduces helper function vfio_pci_container_ioctl() to
> pass ioctl commands to the specified VFIO container that is identified
> by IOMMU group id. On sPAPR platform, each container only has one
> IOMMU group.
> 
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
> ---
>  hw/misc/vfio.c         | 31 +++++++++++++++++++++++++++++++
>  include/hw/misc/vfio.h |  2 ++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
> index 0796abf..999d97d 100644
> --- a/hw/misc/vfio.c
> +++ b/hw/misc/vfio.c
> @@ -4310,3 +4310,34 @@ put_group_exit:
>  
>      return n;
>  }
> +
> +int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt)
> +{
> +    VFIOGroup *group;
> +    int ret, fd = 0;
> +
> +    /* Search container's fd */
> +    QLIST_FOREACH(group, &group_list, next) {
> +        if (group->groupid == iommu_group_id) {
> +            fd = group->container ? group->container->fd : 0;
> +            break;
> +        }
> +    }
> +
> +    if (fd <= 0) {
> +        return -ENOENT;
> +    }
> +
> +    switch (req) {
> +    case VFIO_EEH_PE_OP: {
> +	struct vfio_eeh_pe_op op = { .argsz = sizeof(op), .op = opt };
> +
> +        ret = ioctl(fd, req, &op);
> +        break;

In addition to fd 0 being valid, there's some white space issues here.

Passing an integer option is not very extensible, maybe a void* that
gets cast to an int* for VFIO_EEH_PE_OP would be better.  It's a qemu
internal API though, so I'm not going to sweat saving that problem for
the next user.  Thanks,

Alex

> +    }
> +    default:
> +        ret = -EINVAL;
> +    }
> +
> +    return ret;
> +}
> diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
> index 53ec665..dc92fae 100644
> --- a/include/hw/misc/vfio.h
> +++ b/include/hw/misc/vfio.h
> @@ -30,4 +30,6 @@ static inline long vfio_kvm_notify(Notifier *n, unsigned request, void *data)
>      return p.ret;
>  }
>  
> +extern int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt);
> +
>  #endif
Gavin Shan June 6, 2014, 1 a.m. UTC | #3
On Thu, Jun 05, 2014 at 02:11:21PM +0200, Alexander Graf wrote:
>
>On 05.06.14 08:53, Gavin Shan wrote:
>>The patch introduces helper function vfio_pci_container_ioctl() to
>>pass ioctl commands to the specified VFIO container that is identified
>>by IOMMU group id. On sPAPR platform, each container only has one
>>IOMMU group.
>>
>>Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
>>---
>>  hw/misc/vfio.c         | 31 +++++++++++++++++++++++++++++++
>>  include/hw/misc/vfio.h |  2 ++
>>  2 files changed, 33 insertions(+)
>>
>>diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
>>index 0796abf..999d97d 100644
>>--- a/hw/misc/vfio.c
>>+++ b/hw/misc/vfio.c
>>@@ -4310,3 +4310,34 @@ put_group_exit:
>>      return n;
>>  }
>>+
>>+int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt)
>>+{
>>+    VFIOGroup *group;
>>+    int ret, fd = 0;
>>+
>>+    /* Search container's fd */
>>+    QLIST_FOREACH(group, &group_list, next) {
>>+        if (group->groupid == iommu_group_id) {
>>+            fd = group->container ? group->container->fd : 0;
>>+            break;
>>+        }
>>+    }
>>+
>>+    if (fd <= 0) {
>
>fd 0 is a valid file descriptor.
>

Yep, I'll fix :)

Thanks,
Gavin

>
>Alex
>
Gavin Shan June 6, 2014, 1:05 a.m. UTC | #4
On Thu, Jun 05, 2014 at 12:27:23PM -0600, Alex Williamson wrote:
>On Thu, 2014-06-05 at 16:53 +1000, Gavin Shan wrote:
>> The patch introduces helper function vfio_pci_container_ioctl() to
>> pass ioctl commands to the specified VFIO container that is identified
>> by IOMMU group id. On sPAPR platform, each container only has one
>> IOMMU group.
>> 
>> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
>> ---
>>  hw/misc/vfio.c         | 31 +++++++++++++++++++++++++++++++
>>  include/hw/misc/vfio.h |  2 ++
>>  2 files changed, 33 insertions(+)
>> 
>> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
>> index 0796abf..999d97d 100644
>> --- a/hw/misc/vfio.c
>> +++ b/hw/misc/vfio.c
>> @@ -4310,3 +4310,34 @@ put_group_exit:
>>  
>>      return n;
>>  }
>> +
>> +int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt)
>> +{
>> +    VFIOGroup *group;
>> +    int ret, fd = 0;
>> +
>> +    /* Search container's fd */
>> +    QLIST_FOREACH(group, &group_list, next) {
>> +        if (group->groupid == iommu_group_id) {
>> +            fd = group->container ? group->container->fd : 0;
>> +            break;
>> +        }
>> +    }
>> +
>> +    if (fd <= 0) {
>> +        return -ENOENT;
>> +    }
>> +
>> +    switch (req) {
>> +    case VFIO_EEH_PE_OP: {
>> +	struct vfio_eeh_pe_op op = { .argsz = sizeof(op), .op = opt };
>> +
>> +        ret = ioctl(fd, req, &op);
>> +        break;
>
>In addition to fd 0 being valid, there's some white space issues here.
>

Thanks and I'll fix :-)

>Passing an integer option is not very extensible, maybe a void* that
>gets cast to an int* for VFIO_EEH_PE_OP would be better.  It's a qemu
>internal API though, so I'm not going to sweat saving that problem for
>the next user.  Thanks,
>

yep, I'll change accordingly.

Thanks,
Gavin

>Alex
>
>> +    }
>> +    default:
>> +        ret = -EINVAL;
>> +    }
>> +
>> +    return ret;
>> +}
>> diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
>> index 53ec665..dc92fae 100644
>> --- a/include/hw/misc/vfio.h
>> +++ b/include/hw/misc/vfio.h
>> @@ -30,4 +30,6 @@ static inline long vfio_kvm_notify(Notifier *n, unsigned request, void *data)
>>      return p.ret;
>>  }
>>  
>> +extern int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt);
>> +
>>  #endif
>
>
>
diff mbox

Patch

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 0796abf..999d97d 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -4310,3 +4310,34 @@  put_group_exit:
 
     return n;
 }
+
+int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt)
+{
+    VFIOGroup *group;
+    int ret, fd = 0;
+
+    /* Search container's fd */
+    QLIST_FOREACH(group, &group_list, next) {
+        if (group->groupid == iommu_group_id) {
+            fd = group->container ? group->container->fd : 0;
+            break;
+        }
+    }
+
+    if (fd <= 0) {
+        return -ENOENT;
+    }
+
+    switch (req) {
+    case VFIO_EEH_PE_OP: {
+	struct vfio_eeh_pe_op op = { .argsz = sizeof(op), .op = opt };
+
+        ret = ioctl(fd, req, &op);
+        break;
+    }
+    default:
+        ret = -EINVAL;
+    }
+
+    return ret;
+}
diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h
index 53ec665..dc92fae 100644
--- a/include/hw/misc/vfio.h
+++ b/include/hw/misc/vfio.h
@@ -30,4 +30,6 @@  static inline long vfio_kvm_notify(Notifier *n, unsigned request, void *data)
     return p.ret;
 }
 
+extern int vfio_pci_container_ioctl(int iommu_group_id, int req, int opt);
+
 #endif