diff mbox series

[v4,08/18] iommufd: Add capabilities to IOMMU_GET_HW_INFO

Message ID 20231018202715.69734-9-joao.m.martins@oracle.com (mailing list archive)
State New, archived
Headers show
Series IOMMUFD Dirty Tracking | expand

Commit Message

Joao Martins Oct. 18, 2023, 8:27 p.m. UTC
Extend IOMMUFD_CMD_GET_HW_INFO op to query generic iommu capabilities for a
given device.

Capabilities are IOMMU agnostic and use device_iommu_capable() API passing
one of the IOMMU_CAP_*. Enumerate IOMMU_CAP_DIRTY for now in the
out_capabilities field returned back to userspace.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 drivers/iommu/iommufd/device.c |  4 ++++
 include/uapi/linux/iommufd.h   | 11 +++++++++++
 2 files changed, 15 insertions(+)

Comments

Jason Gunthorpe Oct. 18, 2023, 10:44 p.m. UTC | #1
On Wed, Oct 18, 2023 at 09:27:05PM +0100, Joao Martins wrote:
> Extend IOMMUFD_CMD_GET_HW_INFO op to query generic iommu capabilities for a
> given device.
> 
> Capabilities are IOMMU agnostic and use device_iommu_capable() API passing
> one of the IOMMU_CAP_*. Enumerate IOMMU_CAP_DIRTY for now in the
> out_capabilities field returned back to userspace.
> 
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
>  drivers/iommu/iommufd/device.c |  4 ++++
>  include/uapi/linux/iommufd.h   | 11 +++++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
> index e88fa73a45e6..71ee22dc1a85 100644
> --- a/drivers/iommu/iommufd/device.c
> +++ b/drivers/iommu/iommufd/device.c
> @@ -1185,6 +1185,10 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
>  	 */
>  	cmd->data_len = data_len;
>  
> +	cmd->out_capabilities = 0;
> +	if (device_iommu_capable(idev->dev, IOMMU_CAP_DIRTY))
> +		cmd->out_capabilities |= IOMMU_HW_CAP_DIRTY_TRACKING;
> +
>  	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
>  out_free:
>  	kfree(data);
> diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
> index efeb12c1aaeb..91de0043e73f 100644
> --- a/include/uapi/linux/iommufd.h
> +++ b/include/uapi/linux/iommufd.h
> @@ -419,6 +419,14 @@ enum iommu_hw_info_type {
>  	IOMMU_HW_INFO_TYPE_INTEL_VTD,
>  };
>  
> +/**
> + * enum iommufd_hw_info_capabilities
> + * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
> + */

Lets write more details here, which iommufd APIs does this flag mean
work.

But otherwise

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

Jason
Joao Martins Oct. 19, 2023, 9:55 a.m. UTC | #2
On 18/10/2023 23:44, Jason Gunthorpe wrote:
> On Wed, Oct 18, 2023 at 09:27:05PM +0100, Joao Martins wrote:
>> Extend IOMMUFD_CMD_GET_HW_INFO op to query generic iommu capabilities for a
>> given device.
>>
>> Capabilities are IOMMU agnostic and use device_iommu_capable() API passing
>> one of the IOMMU_CAP_*. Enumerate IOMMU_CAP_DIRTY for now in the
>> out_capabilities field returned back to userspace.
>>
>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>> ---
>>  drivers/iommu/iommufd/device.c |  4 ++++
>>  include/uapi/linux/iommufd.h   | 11 +++++++++++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
>> index e88fa73a45e6..71ee22dc1a85 100644
>> --- a/drivers/iommu/iommufd/device.c
>> +++ b/drivers/iommu/iommufd/device.c
>> @@ -1185,6 +1185,10 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
>>  	 */
>>  	cmd->data_len = data_len;
>>  
>> +	cmd->out_capabilities = 0;
>> +	if (device_iommu_capable(idev->dev, IOMMU_CAP_DIRTY))
>> +		cmd->out_capabilities |= IOMMU_HW_CAP_DIRTY_TRACKING;
>> +
>>  	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
>>  out_free:
>>  	kfree(data);
>> diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
>> index efeb12c1aaeb..91de0043e73f 100644
>> --- a/include/uapi/linux/iommufd.h
>> +++ b/include/uapi/linux/iommufd.h
>> @@ -419,6 +419,14 @@ enum iommu_hw_info_type {
>>  	IOMMU_HW_INFO_TYPE_INTEL_VTD,
>>  };
>>   
>> +/**
>> + * enum iommufd_hw_info_capabilities
>> + * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
>> + */
> 
> Lets write more details here, which iommufd APIs does this flag mean
> work.
> 

I added this below. It is relatively brief as I expect people to read what each
of the API do. Unless I should be expanding in length here?

diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index ef8a1243eb57..43ed2f208503 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -422,6 +422,12 @@ enum iommu_hw_info_type {
 /**
  * enum iommufd_hw_info_capabilities
  * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
+ *                            If available, it means the following APIs
+ *                            are supported:
+ *
+ *                                   IOMMU_HWPT_GET_DIRTY_IOVA
+ *                                   IOMMU_HWPT_SET_DIRTY
+ *
  */
 enum iommufd_hw_capabilities {
        IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0,
Jason Gunthorpe Oct. 19, 2023, 11:56 p.m. UTC | #3
On Thu, Oct 19, 2023 at 10:55:57AM +0100, Joao Martins wrote:

> I added this below. It is relatively brief as I expect people to read what each
> of the API do. Unless I should be expanding in length here?
> 
> diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
> index ef8a1243eb57..43ed2f208503 100644
> --- a/include/uapi/linux/iommufd.h
> +++ b/include/uapi/linux/iommufd.h
> @@ -422,6 +422,12 @@ enum iommu_hw_info_type {
>  /**
>   * enum iommufd_hw_info_capabilities
>   * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
> + *                            If available, it means the following APIs
> + *                            are supported:
> + *
> + *                                   IOMMU_HWPT_GET_DIRTY_IOVA
> + *                                   IOMMU_HWPT_SET_DIRTY
> + *
>   */

That seems fine, thanks

Jason
Tian, Kevin Oct. 20, 2023, 6:46 a.m. UTC | #4
> From: Joao Martins <joao.m.martins@oracle.com>
> Sent: Thursday, October 19, 2023 4:27 AM
> 
> +/**
> + * enum iommufd_hw_info_capabilities
> + * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty
> tracking

@IOMMU_HW_CAP_DIRTY_TRACKING: ...

>  /**
>   * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO)
>   * @size: sizeof(struct iommu_hw_info)
> @@ -430,6 +438,8 @@ enum iommu_hw_info_type {
>   *             the iommu type specific hardware information data
>   * @out_data_type: Output the iommu hardware info type as defined in the
> enum
>   *                 iommu_hw_info_type.
> + * @out_capabilities: Output the iommu capability info type as defined in
> the
> + *                    enum iommu_hw_capabilities.

"Output the 'generic' iommu capability info ..."

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Joao Martins Oct. 20, 2023, 11:52 a.m. UTC | #5
On 20/10/2023 07:46, Tian, Kevin wrote:
>> From: Joao Martins <joao.m.martins@oracle.com>
>> Sent: Thursday, October 19, 2023 4:27 AM
>>
>> +/**
>> + * enum iommufd_hw_info_capabilities
>> + * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty
>> tracking
> 
> @IOMMU_HW_CAP_DIRTY_TRACKING: ...
> 
OK
>>  /**
>>   * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO)
>>   * @size: sizeof(struct iommu_hw_info)
>> @@ -430,6 +438,8 @@ enum iommu_hw_info_type {
>>   *             the iommu type specific hardware information data
>>   * @out_data_type: Output the iommu hardware info type as defined in the
>> enum
>>   *                 iommu_hw_info_type.
>> + * @out_capabilities: Output the iommu capability info type as defined in
>> the
>> + *                    enum iommu_hw_capabilities.
> 
> "Output the 'generic' iommu capability info ..."
>

Yeap, I 'generic' is important here

> Reviewed-by: Kevin Tian <kevin.tian@intel.com>

Thanks
diff mbox series

Patch

diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
index e88fa73a45e6..71ee22dc1a85 100644
--- a/drivers/iommu/iommufd/device.c
+++ b/drivers/iommu/iommufd/device.c
@@ -1185,6 +1185,10 @@  int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)
 	 */
 	cmd->data_len = data_len;
 
+	cmd->out_capabilities = 0;
+	if (device_iommu_capable(idev->dev, IOMMU_CAP_DIRTY))
+		cmd->out_capabilities |= IOMMU_HW_CAP_DIRTY_TRACKING;
+
 	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
 out_free:
 	kfree(data);
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index efeb12c1aaeb..91de0043e73f 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -419,6 +419,14 @@  enum iommu_hw_info_type {
 	IOMMU_HW_INFO_TYPE_INTEL_VTD,
 };
 
+/**
+ * enum iommufd_hw_info_capabilities
+ * @IOMMU_CAP_DIRTY_TRACKING: IOMMU hardware support for dirty tracking
+ */
+enum iommufd_hw_capabilities {
+	IOMMU_HW_CAP_DIRTY_TRACKING = 1 << 0,
+};
+
 /**
  * struct iommu_hw_info - ioctl(IOMMU_GET_HW_INFO)
  * @size: sizeof(struct iommu_hw_info)
@@ -430,6 +438,8 @@  enum iommu_hw_info_type {
  *             the iommu type specific hardware information data
  * @out_data_type: Output the iommu hardware info type as defined in the enum
  *                 iommu_hw_info_type.
+ * @out_capabilities: Output the iommu capability info type as defined in the
+ *                    enum iommu_hw_capabilities.
  * @__reserved: Must be 0
  *
  * Query an iommu type specific hardware information data from an iommu behind
@@ -454,6 +464,7 @@  struct iommu_hw_info {
 	__aligned_u64 data_uptr;
 	__u32 out_data_type;
 	__u32 __reserved;
+	__aligned_u64 out_capabilities;
 };
 #define IOMMU_GET_HW_INFO _IO(IOMMUFD_TYPE, IOMMUFD_CMD_GET_HW_INFO)