From: Lu Baolu <baolu.lu@linux.intel.com>
To: "Prakhya, Sai Praneeth" <sai.praneeth.prakhya@intel.com>,
"iommu@lists.linux-foundation.org"
<iommu@lists.linux-foundation.org>
Cc: "Raj, Ashok" <ashok.raj@intel.com>,
Will Deacon <will.deacon@arm.com>,
Robin Murphy <robin.murphy@arm.com>,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH V2 3/5] iommu: Add support to change default domain of an iommu_group
Date: Mon, 24 Feb 2020 16:12:45 +0800 [thread overview]
Message-ID: <17eae788-1ed7-a24b-339e-4800496f9542@linux.intel.com> (raw)
In-Reply-To: <FFF73D592F13FD46B8700F0A279B802F5721AB7A@ORSMSX114.amr.corp.intel.com>
On 2020/2/24 15:57, Prakhya, Sai Praneeth wrote:
>> On 2020/2/24 15:03, Prakhya, Sai Praneeth wrote:
>>>> On 2020/2/24 11:20, Prakhya, Sai Praneeth wrote:
>>>>>>> + list_for_each_entry_safe(grp_dev, temp, &group->devices, list) {
>>>>>>> + struct device *dev;
>>>>>>> +
>>>>>>> + dev = grp_dev->dev;
>>>>>>> + iommu_release_device(dev);
>>>>>>> +
>>>>>>> + ret = iommu_group_add_device(group, dev);
>>>>>>> + if (ret)
>>>>>>> + dev_err(dev, "Failed to add to iommu group %d: %d\n",
>>>>>>> + group->id, ret);
>>>>>> Need to handle this error case.
>>>>> I wasn't sure on how to handle the error ☹
>>>> Just roll back to the state before calling this function and return
>>>> an appropriate error value.
>>>>
>>>> The likely behavior is detaching the new domains from all devices (if
>>>> it has already attached), attaching the old domains to all devices in
>>>> the group,
>>> And while handling this error case, there is a possibility that attaching to old
>> domain could fail.. so, we might need to handle that error case as well. If we
>> plan to handle error case, since we have removed devices from group above,
>> adding them back could fail too.. that would lead into handling error case for an
>> error case.
>>
>> We can assume that the old domain should always be attached back.
>> Otherwise, there must be some bugs in the vendor iommu driver.
>>
>> It must be able to role back, otherwise users have to reboot the system in order
>> to use the devices in the group. This is not acceptable in the production kernel.
> I agree that we should be able to roll back but I am afraid that the error handling code could become complex than the usual code that gets to run. For example, assume there are 'n' devices in the group, 'k' of them are successfully processed (i.e. default domain type has been changed) and if k+1 fails while changing default domain type, to roll back state of k devices, we need to maintain a list of processed devices so that we now roll back state for devices in this list. The present code does not have any list because it's processing sequentially, it takes a device from the group, changes it domain and moves to other device and hence does not require a list.
>
> All said, I could give this a try and see how complex the code could turn out to be. I hope I am wrong (i.e. turns out implementing error handling is simple).
>
I think something like below should work.
static int iommu_group_do_attach_device(struct device *dev, void *data)
{
struct iommu_domain *domain = data;
return __iommu_attach_device(domain, dev);
}
static int __iommu_attach_group(struct iommu_domain *domain,
struct iommu_group *group)
{
int ret;
if (group->default_domain && group->domain !=
group->default_domain)
return -EBUSY;
ret = __iommu_group_for_each_dev(group, domain,
iommu_group_do_attach_device);
if (ret == 0)
group->domain = domain;
return ret;
}
The vendor iommu driver should always deprecate the old domain if it
exists. Add a comment there.
Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-02-24 8:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-16 21:57 [PATCH V2 0/5] iommu: Add support to change default domain of a group Sai Praneeth Prakhya
2020-02-16 21:57 ` [PATCH V2 1/5] iommu: Add dev_def_domain_type() call back function to iommu_ops Sai Praneeth Prakhya
2020-02-22 23:37 ` Lu Baolu
2020-02-22 23:39 ` Prakhya, Sai Praneeth
2020-02-16 21:57 ` [PATCH V2 2/5] iommu/vt-d: Rename device_def_domain_type() to intel_iommu_dev_def_domain_type() Sai Praneeth Prakhya
2020-02-22 23:42 ` Lu Baolu
2020-02-22 23:59 ` Prakhya, Sai Praneeth
2020-02-23 1:50 ` Lu Baolu
2020-02-24 3:23 ` Prakhya, Sai Praneeth
2020-02-16 21:57 ` [PATCH V2 3/5] iommu: Add support to change default domain of an iommu_group Sai Praneeth Prakhya
2020-02-23 1:20 ` Lu Baolu
2020-02-24 3:20 ` Prakhya, Sai Praneeth
2020-02-24 5:46 ` Lu Baolu
2020-02-24 7:03 ` Prakhya, Sai Praneeth
2020-02-24 7:39 ` Lu Baolu
2020-02-24 7:57 ` Prakhya, Sai Praneeth
2020-02-24 8:12 ` Lu Baolu [this message]
2020-02-24 8:39 ` Lu Baolu
2020-02-24 8:44 ` Prakhya, Sai Praneeth
2020-03-02 15:08 ` Joerg Roedel
2020-03-03 6:47 ` Lu Baolu
2020-03-03 13:13 ` Joerg Roedel
2020-03-04 12:17 ` Lu Baolu
2020-02-16 21:57 ` [PATCH V2 4/5] iommu: Take lock before reading iommu_group default domain type Sai Praneeth Prakhya
2020-02-16 21:57 ` [PATCH V2 5/5] iommu: Document usage of "/sys/kernel/iommu_groups/<grp_id>/type" file Sai Praneeth Prakhya
2020-02-23 1:38 ` Lu Baolu
2020-02-24 2:18 ` Prakhya, Sai Praneeth
2020-02-22 23:40 ` [PATCH V2 0/5] iommu: Add support to change default domain of a group Prakhya, Sai Praneeth
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=17eae788-1ed7-a24b-339e-4800496f9542@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=robin.murphy@arm.com \
--cc=sai.praneeth.prakhya@intel.com \
--cc=will.deacon@arm.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