Linux IOMMU Development
 help / color / mirror / Atom feed
From: Vasant Hegde <vasant.hegde@amd.com>
To: Baolu Lu <baolu.lu@linux.intel.com>,
	iommu@lists.linux.dev, joro@8bytes.org
Cc: suravee.suthikulpanit@amd.com,
	Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Subject: Re: [PATCH iommu/next] iommu: Fix default domain setup
Date: Mon, 19 Jun 2023 12:19:01 +0530	[thread overview]
Message-ID: <358def2d-163d-ea57-c0c7-6d4affc68d0d@amd.com> (raw)
In-Reply-To: <851e7760-94e2-9691-f059-e48aac9d51ca@linux.intel.com>

Hi Baolu,


On 6/14/2023 11:57 AM, Baolu Lu wrote:
> On 6/14/23 1:56 PM, Vasant Hegde wrote:
>> Commit 1000dccd5d13 ("iommu: Allow IOMMU_RESV_DIRECT to work on ARM")
>> accidently restored "group->domain" to "old_domain" while keeping
>> "group->default_domain" to new domain. Also freed new domain.
>>
>> This works fine during boot as 'old_domain' is NULL. But if we try
>> change domain via sysfs using below command then kernel crashes with
>> "kernel NULL pointer dereference".
>>
>> Change domain command :
>>    - Assumed we have single device in the IOMMU group
> 
> Nit: The requirement for singleton group has been removed.

Yeah. I have seen those changes but forgot while writing commit message. Will
fix it.


> 
>>    - unbind device driver
>>    - echo "<dom type>" > /sys/kernel/iommu_groups/<group id>/type
>>
>> Fix above described issue by handling error path properly.
>>
>> Reported-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
>> Fixes: 1000dccd5d13 ("iommu: Allow IOMMU_RESV_DIRECT to work on ARM")
>> Tested-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
>> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
>> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
>> ---
>> Hi Joerg,
>>    This patch is on top of iommu/next branch.
>>
>> -Vasant
>>
>>   drivers/iommu/iommu.c | 14 ++++++++------
>>   1 file changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index 9e0228ef612b..d21d0a217bdf 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -2880,7 +2880,6 @@ static int iommu_setup_default_domain(struct iommu_group
>> *group,
>>       }
>>         /* We must set default_domain early for __iommu_device_set_domain */
> 
> Is the above comment still relevant? If yes, this fix seems to be
> problematic. Or no?

I think we should keep below change.


> 
>> -    group->default_domain = dom;
>>       if (!group->domain) {
>>           /*
>>            * Drivers are not allowed to fail the first domain attach.
>> @@ -2896,7 +2895,6 @@ static int iommu_setup_default_domain(struct iommu_group
>> *group,
>>           ret = __iommu_group_set_domain(group, dom);
>>           if (ret) {
>>               iommu_domain_free(dom);
>> -            group->default_domain = old_dom;
>>               return ret;
>>           }
>>       }
>> @@ -2915,16 +2913,20 @@ static int iommu_setup_default_domain(struct
>> iommu_group *group,
>>           }
>>       }
>>   +out_free:
>> +    group->default_domain = dom;
>> +
>> +    if (old_dom) {
>> +        iommu_domain_free(old_dom);
>> +        old_dom = NULL;
>> +    }
>> +
>>   err_restore:
>>       if (old_dom) {
>>           __iommu_group_set_domain_internal(
>>               group, old_dom, IOMMU_SET_DOMAIN_MUST_SUCCEED);
>>           iommu_domain_free(dom);
>> -        old_dom = NULL;
>>       }
>> -out_free:
>> -    if (old_dom)
>> -        iommu_domain_free(old_dom);
>>       return ret;
>>   }
>>   
> 
> It's better to split the error path from the successful one.

Sure. Will fix it.

Thanks
-Vasant



  reply	other threads:[~2023-06-19  6:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-14  5:56 [PATCH iommu/next] iommu: Fix default domain setup Vasant Hegde
2023-06-14  6:27 ` Baolu Lu
2023-06-19  6:49   ` Vasant Hegde [this message]
2023-06-20  5:12     ` Baolu Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=358def2d-163d-ea57-c0c7-6d4affc68d0d@amd.com \
    --to=vasant.hegde@amd.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=dheerajkumar.srivastava@amd.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=suravee.suthikulpanit@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox