diff mbox series

[4/6] iommufd/hw_pagetable: Support allocating nested parent domain

Message ID 20230919092523.39286-5-yi.l.liu@intel.com (mailing list archive)
State New, archived
Headers show
Series iommufd support allocating nested parent domain | expand

Commit Message

Yi Liu Sept. 19, 2023, 9:25 a.m. UTC
This extends IOMMU_HWPT_ALLOC to allocate domains used as parent (stage-2)
in nested translation.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
---
 drivers/iommu/iommufd/hw_pagetable.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Baolu Lu Sept. 20, 2023, 5:05 a.m. UTC | #1
On 9/19/23 5:25 PM, Yi Liu wrote:
> This extends IOMMU_HWPT_ALLOC to allocate domains used as parent (stage-2)
> in nested translation.
> 
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> ---
>   drivers/iommu/iommufd/hw_pagetable.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c
> index 5be7a31cbd9c..26a8a818ffa3 100644
> --- a/drivers/iommu/iommufd/hw_pagetable.c
> +++ b/drivers/iommu/iommufd/hw_pagetable.c
> @@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
>   
>   	lockdep_assert_held(&ioas->mutex);
>   
> +	if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ops->domain_alloc_user)
> +		return ERR_PTR(-EOPNOTSUPP);
> +
>   	hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE);
>   	if (IS_ERR(hwpt))
>   		return hwpt;
> @@ -154,7 +157,7 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
>   	struct iommufd_ioas *ioas;
>   	int rc;
>   
> -	if (cmd->flags || cmd->__reserved)
> +	if (cmd->flags & ~IOMMU_HWPT_ALLOC_NEST_PARENT || cmd->__reserved)
>   		return -EOPNOTSUPP;

Need a parenthesis here, otherwise the compiler will interpret it as a
different condition.

	if ((cmd->flags & ~IOMMU_HWPT_ALLOC_NEST_PARENT) || cmd->__reserved)
		return -EOPNOTSUPP;

Best regards,
baolu
Yi Liu Sept. 25, 2023, 6:39 a.m. UTC | #2
On 2023/9/20 13:05, Baolu Lu wrote:
> On 9/19/23 5:25 PM, Yi Liu wrote:
>> This extends IOMMU_HWPT_ALLOC to allocate domains used as parent (stage-2)
>> in nested translation.
>>
>> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
>> ---
>>   drivers/iommu/iommufd/hw_pagetable.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/iommufd/hw_pagetable.c 
>> b/drivers/iommu/iommufd/hw_pagetable.c
>> index 5be7a31cbd9c..26a8a818ffa3 100644
>> --- a/drivers/iommu/iommufd/hw_pagetable.c
>> +++ b/drivers/iommu/iommufd/hw_pagetable.c
>> @@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, 
>> struct iommufd_ioas *ioas,
>>       lockdep_assert_held(&ioas->mutex);
>> +    if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ops->domain_alloc_user)
>> +        return ERR_PTR(-EOPNOTSUPP);
>> +
>>       hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE);
>>       if (IS_ERR(hwpt))
>>           return hwpt;
>> @@ -154,7 +157,7 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
>>       struct iommufd_ioas *ioas;
>>       int rc;
>> -    if (cmd->flags || cmd->__reserved)
>> +    if (cmd->flags & ~IOMMU_HWPT_ALLOC_NEST_PARENT || cmd->__reserved)
>>           return -EOPNOTSUPP;
> 
> Need a parenthesis here, otherwise the compiler will interpret it as a
> different condition.
> 
>      if ((cmd->flags & ~IOMMU_HWPT_ALLOC_NEST_PARENT) || cmd->__reserved)
>          return -EOPNOTSUPP;

ok.
Tian, Kevin Sept. 26, 2023, 5:32 a.m. UTC | #3
> From: Liu, Yi L <yi.l.liu@intel.com>
> Sent: Tuesday, September 19, 2023 5:25 PM
>
> @@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx,
> struct iommufd_ioas *ioas,
> 
>  	lockdep_assert_held(&ioas->mutex);
> 
> +	if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ops-
> >domain_alloc_user)
> +		return ERR_PTR(-EOPNOTSUPP);
> +

if (flags && !ops->domain_alloc_user)
	return ERR_PTR(-EOPNOTSUPP);

as long as flags is non-zero we'll need the new alloc_user ops.
Yi Liu Sept. 26, 2023, 5:50 a.m. UTC | #4
On 2023/9/26 13:32, Tian, Kevin wrote:
>> From: Liu, Yi L <yi.l.liu@intel.com>
>> Sent: Tuesday, September 19, 2023 5:25 PM
>>
>> @@ -83,6 +83,9 @@ iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx,
>> struct iommufd_ioas *ioas,
>>
>>   	lockdep_assert_held(&ioas->mutex);
>>
>> +	if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ops-
>>> domain_alloc_user)
>> +		return ERR_PTR(-EOPNOTSUPP);
>> +
> 
> if (flags && !ops->domain_alloc_user)
> 	return ERR_PTR(-EOPNOTSUPP);
> 
> as long as flags is non-zero we'll need the new alloc_user ops.

yes.
diff mbox series

Patch

diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c
index 5be7a31cbd9c..26a8a818ffa3 100644
--- a/drivers/iommu/iommufd/hw_pagetable.c
+++ b/drivers/iommu/iommufd/hw_pagetable.c
@@ -83,6 +83,9 @@  iommufd_hw_pagetable_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
 
 	lockdep_assert_held(&ioas->mutex);
 
+	if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) && !ops->domain_alloc_user)
+		return ERR_PTR(-EOPNOTSUPP);
+
 	hwpt = iommufd_object_alloc(ictx, hwpt, IOMMUFD_OBJ_HW_PAGETABLE);
 	if (IS_ERR(hwpt))
 		return hwpt;
@@ -154,7 +157,7 @@  int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
 	struct iommufd_ioas *ioas;
 	int rc;
 
-	if (cmd->flags || cmd->__reserved)
+	if (cmd->flags & ~IOMMU_HWPT_ALLOC_NEST_PARENT || cmd->__reserved)
 		return -EOPNOTSUPP;
 
 	idev = iommufd_get_device(ucmd, cmd->dev_id);