* [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
@ 2015-03-23 13:46 Robbie VanVossen
2015-03-23 21:53 ` Julien Grall
2015-03-24 11:07 ` Manish Jaggi
0 siblings, 2 replies; 10+ messages in thread
From: Robbie VanVossen @ 2015-03-23 13:46 UTC (permalink / raw)
To: xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
If multiple devices are being passed through to the same domain and they
share a single SMMU, then they only require a single iommu_domain.
In arm_smmu_assign_dev, before a new iommu_domain is created, the
xen_domain->contexts is checked for any iommu_domains that are already
assigned to device that uses the same SMMU as the current device. If one
is found, attach the device to that iommu_domain. If a new one isn't
found, create a new iommu_domain just like before.
The arm_smmu_deassign_dev function assumes that there is a single
device per iommu_domain. This meant that when the first device was
deassigned, the iommu_domain was freed and when another device was
deassigned a crash occured in xen.
To fix this, a reference counter was added to the iommu_domain struct.
When an arm_smmu_xen_device references an iommu_domain, the
iommu_domains ref is incremented. When that reference is removed, the
iommu_domains ref is decremented. The iommu_domain will only be freed
when the ref is 0.
Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
---
Changed since v1:
* Fixed coding style for comments
* Move increment/decrement outside of attach/detach functions
* Expanded xen_domain->lock to protect more of the assign/deassign
functions
* Removed iommu_domain add/remove_device functions
---
xen/drivers/passthrough/arm/smmu.c | 98 +++++++++++++++++++++++++++---------
1 file changed, 74 insertions(+), 24 deletions(-)
diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index a7a7da9..1a3de00 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -223,6 +223,7 @@ struct iommu_domain
/* Runtime SMMU configuration for this iommu_domain */
struct arm_smmu_domain *priv;
+ atomic_t ref;
/* Used to link iommu_domain contexts for a same domain.
* There is at least one per-SMMU to used by the domain.
* */
@@ -2569,7 +2570,9 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
{
struct iommu_domain *domain;
struct arm_smmu_xen_domain *xen_domain;
- int ret;
+ struct arm_smmu_device *smmu;
+ int ret = 0;
+ int existing_ctxt_fnd = 0;
xen_domain = domain_hvm_iommu(d)->arch.priv;
@@ -2585,36 +2588,77 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
return ret;
}
+ spin_lock(&xen_domain->lock);
+
/*
- * TODO: Share the context bank (i.e iommu_domain) when the device is
- * under the same SMMU as another device assigned to this domain.
- * Would it useful for PCI
+ * Check to see if a context bank (iommu_domain) already exists for
+ * this xen domain under the same SMMU
*/
- domain = xzalloc(struct iommu_domain);
- if (!domain)
- return -ENOMEM;
+ if (!list_empty(&xen_domain->contexts)) {
+ smmu = find_smmu_for_device(dev);
+ if (!smmu) {
+ dev_err(dev, "cannot find SMMU\n");
+ ret = -ENXIO;
+ goto out;
+ }
- ret = arm_smmu_domain_init(domain);
- if (ret)
- goto err_dom_init;
+ /*
+ * Loop through the &xen_domain->contexts to locate a context
+ * assigned to this SMMU
+ */
+ list_for_each_entry(domain, &xen_domain->contexts, list) {
+ if(domain->priv->smmu == smmu)
+ {
+ /*
+ * We have found a context already associated with the
+ * same xen domain and SMMU
+ */
+ ret = arm_smmu_attach_dev(domain, dev);
+ if (ret) {
+ dev_err(dev,
+ "cannot attach device to already existing iommu_domain\n");
+ goto out;
+ }
+ atomic_inc(&domain->ref);
+
+ existing_ctxt_fnd = 1;
+ break;
+ }
+ }
+ }
- domain->priv->cfg.domain = d;
+ if(!existing_ctxt_fnd){
- ret = arm_smmu_attach_dev(domain, dev);
- if (ret)
- goto err_attach_dev;
+ domain = xzalloc(struct iommu_domain);
+ if (!domain) {
+ ret = -ENOMEM;
+ goto out;
+ }
- spin_lock(&xen_domain->lock);
- /* Chain the new context to the domain */
- list_add(&domain->list, &xen_domain->contexts);
- spin_unlock(&xen_domain->lock);
+ ret = arm_smmu_domain_init(domain);
+ if (ret)
+ goto err_dom_init;
- return 0;
+ domain->priv->cfg.domain = d;
+
+ ret = arm_smmu_attach_dev(domain, dev);
+ if (ret)
+ goto err_attach_dev;
+ atomic_inc(&domain->ref);
+
+ /* Chain the new context to the domain */
+ list_add(&domain->list, &xen_domain->contexts);
+
+ }
+
+ goto out;
err_attach_dev:
arm_smmu_domain_destroy(domain);
err_dom_init:
xfree(domain);
+out:
+ spin_unlock(&xen_domain->lock);
return ret;
}
@@ -2631,14 +2675,20 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev)
return -ESRCH;
}
+ spin_lock(&xen_domain->lock);
+
arm_smmu_detach_dev(domain, dev);
+ atomic_dec(&domain->ref);
- spin_lock(&xen_domain->lock);
- list_del(&domain->list);
- spin_unlock(&xen_domain->lock);
+ if (domain->ref.counter == 0)
+ {
+ list_del(&domain->list);
- arm_smmu_domain_destroy(domain);
- xfree(domain);
+ arm_smmu_domain_destroy(domain);
+ xfree(domain);
+ }
+
+ spin_unlock(&xen_domain->lock);
return 0;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-23 13:46 [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU Robbie VanVossen
@ 2015-03-23 21:53 ` Julien Grall
2015-03-24 15:07 ` Robert VanVossen
2015-03-24 11:07 ` Manish Jaggi
1 sibling, 1 reply; 10+ messages in thread
From: Julien Grall @ 2015-03-23 21:53 UTC (permalink / raw)
To: Robbie VanVossen, xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
Hello Robert,
On 23/03/2015 13:46, Robbie VanVossen wrote:
> If multiple devices are being passed through to the same domain and they
> share a single SMMU, then they only require a single iommu_domain.
>
> In arm_smmu_assign_dev, before a new iommu_domain is created, the
> xen_domain->contexts is checked for any iommu_domains that are already
> assigned to device that uses the same SMMU as the current device. If one
> is found, attach the device to that iommu_domain. If a new one isn't
> found, create a new iommu_domain just like before.
>
> The arm_smmu_deassign_dev function assumes that there is a single
> device per iommu_domain. This meant that when the first device was
> deassigned, the iommu_domain was freed and when another device was
> deassigned a crash occured in xen.
>
> To fix this, a reference counter was added to the iommu_domain struct.
> When an arm_smmu_xen_device references an iommu_domain, the
> iommu_domains ref is incremented. When that reference is removed, the
> iommu_domains ref is decremented. The iommu_domain will only be freed
> when the ref is 0.
>
> Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
>
> ---
> Changed since v1:
> * Fixed coding style for comments
> * Move increment/decrement outside of attach/detach functions
> * Expanded xen_domain->lock to protect more of the assign/deassign
> functions
> * Removed iommu_domain add/remove_device functions
> ---
> xen/drivers/passthrough/arm/smmu.c | 98 +++++++++++++++++++++++++++---------
> 1 file changed, 74 insertions(+), 24 deletions(-)
>
> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
> index a7a7da9..1a3de00 100644
> --- a/xen/drivers/passthrough/arm/smmu.c
> +++ b/xen/drivers/passthrough/arm/smmu.c
> @@ -223,6 +223,7 @@ struct iommu_domain
> /* Runtime SMMU configuration for this iommu_domain */
> struct arm_smmu_domain *priv;
>
> + atomic_t ref;
> /* Used to link iommu_domain contexts for a same domain.
> * There is at least one per-SMMU to used by the domain.
> * */
> @@ -2569,7 +2570,9 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
> {
> struct iommu_domain *domain;
> struct arm_smmu_xen_domain *xen_domain;
> - int ret;
> + struct arm_smmu_device *smmu;
> + int ret = 0;
> + int existing_ctxt_fnd = 0;
You can use a bool_t here.
>
> xen_domain = domain_hvm_iommu(d)->arch.priv;
>
> @@ -2585,36 +2588,77 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
> return ret;
> }
>
> + spin_lock(&xen_domain->lock);
> +
> /*
> - * TODO: Share the context bank (i.e iommu_domain) when the device is
> - * under the same SMMU as another device assigned to this domain.
> - * Would it useful for PCI
> + * Check to see if a context bank (iommu_domain) already exists for
> + * this xen domain under the same SMMU
> */
> - domain = xzalloc(struct iommu_domain);
> - if (!domain)
> - return -ENOMEM;
> + if (!list_empty(&xen_domain->contexts)) {
> + smmu = find_smmu_for_device(dev);
> + if (!smmu) {
> + dev_err(dev, "cannot find SMMU\n");
> + ret = -ENXIO;
> + goto out;
> + }
>
> - ret = arm_smmu_domain_init(domain);
> - if (ret)
> - goto err_dom_init;
> + /*
> + * Loop through the &xen_domain->contexts to locate a context
> + * assigned to this SMMU
> + */
> + list_for_each_entry(domain, &xen_domain->contexts, list) {
> + if(domain->priv->smmu == smmu)
> + {
Coding style. This should be
if (domain->priv->smmu == smmu) {
> + /*
> + * We have found a context already associated with the
> + * same xen domain and SMMU
> + */
> + ret = arm_smmu_attach_dev(domain, dev);
> + if (ret) {
> + dev_err(dev,
> + "cannot attach device to already existing iommu_domain\n");
We don't print an error message for new domain, I don't think this one
is useful.
> + goto out;
> + }
> + atomic_inc(&domain->ref);
Introducing an helper to get the iommu_domain would simply the workflow.
That would give smth like:
domain = arm_smmu_get_domain(d, dev);
if (!domain)
{
allocate domain
Add to list dev
}
arm_smmu_attach_dev(domain, dev);
atomic_inc(&domain->ref);
out:
if (failed && atomic == 0)
destroy iommu_domain.
The destroy iommu_domain could be shared with the one in deassign_dev.
> +
> + existing_ctxt_fnd = 1;
> + break;
> + }
> + }
> + }
>
> - domain->priv->cfg.domain = d;
> + if(!existing_ctxt_fnd){
>
> - ret = arm_smmu_attach_dev(domain, dev);
> - if (ret)
> - goto err_attach_dev;
> + domain = xzalloc(struct iommu_domain);
> + if (!domain) {
> + ret = -ENOMEM;
> + goto out;
> + }
>
> - spin_lock(&xen_domain->lock);
> - /* Chain the new context to the domain */
> - list_add(&domain->list, &xen_domain->contexts);
> - spin_unlock(&xen_domain->lock);
> + ret = arm_smmu_domain_init(domain);
> + if (ret)
> + goto err_dom_init;
>
> - return 0;
> + domain->priv->cfg.domain = d;
> +
> + ret = arm_smmu_attach_dev(domain, dev);
> + if (ret)
> + goto err_attach_dev;
> + atomic_inc(&domain->ref);
> +
> + /* Chain the new context to the domain */
> + list_add(&domain->list, &xen_domain->contexts);
> +
> + }
> +
> + goto out;
>
> err_attach_dev:
> arm_smmu_domain_destroy(domain);
> err_dom_init:
> xfree(domain);
> +out:
> + spin_unlock(&xen_domain->lock);
>
> return ret;
> }
> @@ -2631,14 +2675,20 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev)
> return -ESRCH;
> }
>
> + spin_lock(&xen_domain->lock);
> +
> arm_smmu_detach_dev(domain, dev);
> + atomic_dec(&domain->ref);
>
> - spin_lock(&xen_domain->lock);
> - list_del(&domain->list);
> - spin_unlock(&xen_domain->lock);
> + if (domain->ref.counter == 0)
> + {
Coding style:
if (...) {
> + list_del(&domain->list);
>
> - arm_smmu_domain_destroy(domain);
> - xfree(domain);
> + arm_smmu_domain_destroy(domain);
> + xfree(domain);
> + }
> +
> + spin_unlock(&xen_domain->lock);
>
> return 0;
> }
>
Regards,
--
Julien Grall
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-23 13:46 [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU Robbie VanVossen
2015-03-23 21:53 ` Julien Grall
@ 2015-03-24 11:07 ` Manish Jaggi
2015-03-24 14:04 ` Robert VanVossen
1 sibling, 1 reply; 10+ messages in thread
From: Manish Jaggi @ 2015-03-24 11:07 UTC (permalink / raw)
To: Robbie VanVossen, xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
On Monday 23 March 2015 07:16 PM, Robbie VanVossen wrote:
> If multiple devices are being passed through to the same domain and they
> share a single SMMU, then they only require a single iommu_domain.
>
> In arm_smmu_assign_dev, before a new iommu_domain is created, the
> xen_domain->contexts is checked for any iommu_domains that are already
> assigned to device that uses the same SMMU as the current device. If one
> is found, attach the device to that iommu_domain. If a new one isn't
> found, create a new iommu_domain just like before.
>
> The arm_smmu_deassign_dev function assumes that there is a single
> device per iommu_domain. This meant that when the first device was
> deassigned, the iommu_domain was freed and when another device was
> deassigned a crash occured in xen.
>
> To fix this, a reference counter was added to the iommu_domain struct.
> When an arm_smmu_xen_device references an iommu_domain, the
> iommu_domains ref is incremented. When that reference is removed, the
> iommu_domains ref is decremented. The iommu_domain will only be freed
> when the ref is 0.
>
> Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
Hi,
Are you adding a PCI passthrough support to Xen ?. I am in process of
sending smmu driver patches based on juliens latest code.
> ---
> Changed since v1:
> * Fixed coding style for comments
> * Move increment/decrement outside of attach/detach functions
> * Expanded xen_domain->lock to protect more of the assign/deassign
> functions
> * Removed iommu_domain add/remove_device functions
> ---
> xen/drivers/passthrough/arm/smmu.c | 98 +++++++++++++++++++++++++++---------
> 1 file changed, 74 insertions(+), 24 deletions(-)
>
> diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
> index a7a7da9..1a3de00 100644
> --- a/xen/drivers/passthrough/arm/smmu.c
> +++ b/xen/drivers/passthrough/arm/smmu.c
> @@ -223,6 +223,7 @@ struct iommu_domain
> /* Runtime SMMU configuration for this iommu_domain */
> struct arm_smmu_domain *priv;
>
> + atomic_t ref;
> /* Used to link iommu_domain contexts for a same domain.
> * There is at least one per-SMMU to used by the domain.
> * */
> @@ -2569,7 +2570,9 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
> {
> struct iommu_domain *domain;
> struct arm_smmu_xen_domain *xen_domain;
> - int ret;
> + struct arm_smmu_device *smmu;
> + int ret = 0;
> + int existing_ctxt_fnd = 0;
>
> xen_domain = domain_hvm_iommu(d)->arch.priv;
>
> @@ -2585,36 +2588,77 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
> return ret;
> }
>
> + spin_lock(&xen_domain->lock);
> +
> /*
> - * TODO: Share the context bank (i.e iommu_domain) when the device is
> - * under the same SMMU as another device assigned to this domain.
> - * Would it useful for PCI
> + * Check to see if a context bank (iommu_domain) already exists for
> + * this xen domain under the same SMMU
> */
> - domain = xzalloc(struct iommu_domain);
> - if (!domain)
> - return -ENOMEM;
> + if (!list_empty(&xen_domain->contexts)) {
> + smmu = find_smmu_for_device(dev);
> + if (!smmu) {
> + dev_err(dev, "cannot find SMMU\n");
> + ret = -ENXIO;
> + goto out;
> + }
>
> - ret = arm_smmu_domain_init(domain);
> - if (ret)
> - goto err_dom_init;
> + /*
> + * Loop through the &xen_domain->contexts to locate a context
> + * assigned to this SMMU
> + */
> + list_for_each_entry(domain, &xen_domain->contexts, list) {
> + if(domain->priv->smmu == smmu)
> + {
> + /*
> + * We have found a context already associated with the
> + * same xen domain and SMMU
> + */
> + ret = arm_smmu_attach_dev(domain, dev);
> + if (ret) {
> + dev_err(dev,
> + "cannot attach device to already existing iommu_domain\n");
> + goto out;
> + }
> + atomic_inc(&domain->ref);
> +
> + existing_ctxt_fnd = 1;
> + break;
> + }
> + }
> + }
>
> - domain->priv->cfg.domain = d;
> + if(!existing_ctxt_fnd){
>
> - ret = arm_smmu_attach_dev(domain, dev);
> - if (ret)
> - goto err_attach_dev;
> + domain = xzalloc(struct iommu_domain);
> + if (!domain) {
> + ret = -ENOMEM;
> + goto out;
> + }
>
> - spin_lock(&xen_domain->lock);
> - /* Chain the new context to the domain */
> - list_add(&domain->list, &xen_domain->contexts);
> - spin_unlock(&xen_domain->lock);
> + ret = arm_smmu_domain_init(domain);
> + if (ret)
> + goto err_dom_init;
>
> - return 0;
> + domain->priv->cfg.domain = d;
> +
> + ret = arm_smmu_attach_dev(domain, dev);
> + if (ret)
> + goto err_attach_dev;
> + atomic_inc(&domain->ref);
> +
> + /* Chain the new context to the domain */
> + list_add(&domain->list, &xen_domain->contexts);
> +
> + }
> +
> + goto out;
>
> err_attach_dev:
> arm_smmu_domain_destroy(domain);
> err_dom_init:
> xfree(domain);
> +out:
> + spin_unlock(&xen_domain->lock);
>
> return ret;
> }
> @@ -2631,14 +2675,20 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev)
> return -ESRCH;
> }
>
> + spin_lock(&xen_domain->lock);
> +
> arm_smmu_detach_dev(domain, dev);
> + atomic_dec(&domain->ref);
>
> - spin_lock(&xen_domain->lock);
> - list_del(&domain->list);
> - spin_unlock(&xen_domain->lock);
> + if (domain->ref.counter == 0)
> + {
> + list_del(&domain->list);
>
> - arm_smmu_domain_destroy(domain);
> - xfree(domain);
> + arm_smmu_domain_destroy(domain);
> + xfree(domain);
> + }
> +
> + spin_unlock(&xen_domain->lock);
>
> return 0;
> }
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-24 11:07 ` Manish Jaggi
@ 2015-03-24 14:04 ` Robert VanVossen
2015-03-25 4:58 ` Manish Jaggi
0 siblings, 1 reply; 10+ messages in thread
From: Robert VanVossen @ 2015-03-24 14:04 UTC (permalink / raw)
To: Manish Jaggi, xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
On 3/24/2015 7:07 AM, Manish Jaggi wrote:
>
> On Monday 23 March 2015 07:16 PM, Robbie VanVossen wrote:
>> If multiple devices are being passed through to the same domain and they
>> share a single SMMU, then they only require a single iommu_domain.
>>
>> In arm_smmu_assign_dev, before a new iommu_domain is created, the
>> xen_domain->contexts is checked for any iommu_domains that are already
>> assigned to device that uses the same SMMU as the current device. If one
>> is found, attach the device to that iommu_domain. If a new one isn't
>> found, create a new iommu_domain just like before.
>>
>> The arm_smmu_deassign_dev function assumes that there is a single
>> device per iommu_domain. This meant that when the first device was
>> deassigned, the iommu_domain was freed and when another device was
>> deassigned a crash occured in xen.
>>
>> To fix this, a reference counter was added to the iommu_domain struct.
>> When an arm_smmu_xen_device references an iommu_domain, the
>> iommu_domains ref is incremented. When that reference is removed, the
>> iommu_domains ref is decremented. The iommu_domain will only be freed
>> when the ref is 0.
>>
>> Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
> Hi,
> Are you adding a PCI passthrough support to Xen ?. I am in process of
> sending smmu driver patches based on juliens latest code.
>
Nope, I am just working on what this patch describes
Thanks,
Robbie VanVossen
DornerWorks
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-23 21:53 ` Julien Grall
@ 2015-03-24 15:07 ` Robert VanVossen
2015-03-24 15:19 ` Julien Grall
0 siblings, 1 reply; 10+ messages in thread
From: Robert VanVossen @ 2015-03-24 15:07 UTC (permalink / raw)
To: Julien Grall, xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
Hello Julien,
On 3/23/2015 5:53 PM, Julien Grall wrote:
> Hello Robert,
>
> On 23/03/2015 13:46, Robbie VanVossen wrote:
>> @@ -2569,7 +2570,9 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
>> {
>> struct iommu_domain *domain;
>> struct arm_smmu_xen_domain *xen_domain;
>> - int ret;
>> + struct arm_smmu_device *smmu;
>> + int ret = 0;
>> + int existing_ctxt_fnd = 0;
>
> You can use a bool_t here.
>
Ok.
>>
>> xen_domain = domain_hvm_iommu(d)->arch.priv;
>>
>> @@ -2585,36 +2588,77 @@ static int arm_smmu_assign_dev(struct domain *d, u8 devfn,
>> return ret;
>> }
>>
>> + spin_lock(&xen_domain->lock);
>> +
>> /*
>> - * TODO: Share the context bank (i.e iommu_domain) when the device is
>> - * under the same SMMU as another device assigned to this domain.
>> - * Would it useful for PCI
>> + * Check to see if a context bank (iommu_domain) already exists for
>> + * this xen domain under the same SMMU
>> */
>> - domain = xzalloc(struct iommu_domain);
>> - if (!domain)
>> - return -ENOMEM;
>> + if (!list_empty(&xen_domain->contexts)) {
>> + smmu = find_smmu_for_device(dev);
>> + if (!smmu) {
>> + dev_err(dev, "cannot find SMMU\n");
>> + ret = -ENXIO;
>> + goto out;
>> + }
>>
>> - ret = arm_smmu_domain_init(domain);
>> - if (ret)
>> - goto err_dom_init;
>> + /*
>> + * Loop through the &xen_domain->contexts to locate a context
>> + * assigned to this SMMU
>> + */
>> + list_for_each_entry(domain, &xen_domain->contexts, list) {
>> + if(domain->priv->smmu == smmu)
>> + {
>
> Coding style. This should be
> if (domain->priv->smmu == smmu) {
>
Will fix.
>> + /*
>> + * We have found a context already associated with the
>> + * same xen domain and SMMU
>> + */
>> + ret = arm_smmu_attach_dev(domain, dev);
>> + if (ret) {
>> + dev_err(dev,
>> + "cannot attach device to already existing iommu_domain\n");
>
> We don't print an error message for new domain, I don't think this one
> is useful.
>
Will remove dev_err.
>> + goto out;
>> + }
>> + atomic_inc(&domain->ref);
>
> Introducing an helper to get the iommu_domain would simply the workflow.
>
> That would give smth like:
>
> domain = arm_smmu_get_domain(d, dev);
> if (!domain)
> {
> allocate domain
> Add to list dev
> }
>
> arm_smmu_attach_dev(domain, dev);
> atomic_inc(&domain->ref);
>
> out:
> if (failed && atomic == 0)
> destroy iommu_domain.
>
> The destroy iommu_domain could be shared with the one in deassign_dev.
>
But don't we need to handle the failure of attach_dev differently based on which
fails? If the attach_dev fails on a new iommu_domain, then the iommu_domain
should be destroyed. If it fails on a preexisting iommu_domain that is already
attached to another device, then you don't want to destroy the iommu_domain.
>> +
>> + existing_ctxt_fnd = 1;
>> + break;
>> + }
>> + }
>> + }
>>
>> - domain->priv->cfg.domain = d;
>> + if(!existing_ctxt_fnd){
>>
>> - ret = arm_smmu_attach_dev(domain, dev);
>> - if (ret)
>> - goto err_attach_dev;
>> + domain = xzalloc(struct iommu_domain);
>> + if (!domain) {
>> + ret = -ENOMEM;
>> + goto out;
>> + }
>>
>> - spin_lock(&xen_domain->lock);
>> - /* Chain the new context to the domain */
>> - list_add(&domain->list, &xen_domain->contexts);
>> - spin_unlock(&xen_domain->lock);
>> + ret = arm_smmu_domain_init(domain);
>> + if (ret)
>> + goto err_dom_init;
>>
>> - return 0;
>> + domain->priv->cfg.domain = d;
>> +
>> + ret = arm_smmu_attach_dev(domain, dev);
>> + if (ret)
>> + goto err_attach_dev;
>> + atomic_inc(&domain->ref);
>> +
>> + /* Chain the new context to the domain */
>> + list_add(&domain->list, &xen_domain->contexts);
>> +
>> + }
>> +
>> + goto out;
>>
>> err_attach_dev:
>> arm_smmu_domain_destroy(domain);
>> err_dom_init:
>> xfree(domain);
>> +out:
>> + spin_unlock(&xen_domain->lock);
>>
>> return ret;
>> }
>> @@ -2631,14 +2675,20 @@ static int arm_smmu_deassign_dev(struct domain *d, struct device *dev)
>> return -ESRCH;
>> }
>>
>> + spin_lock(&xen_domain->lock);
>> +
>> arm_smmu_detach_dev(domain, dev);
>> + atomic_dec(&domain->ref);
>>
>> - spin_lock(&xen_domain->lock);
>> - list_del(&domain->list);
>> - spin_unlock(&xen_domain->lock);
>> + if (domain->ref.counter == 0)
>> + {
>
> Coding style:
>
> if (...) {
>
Will Fix
Thanks,
Robbie VanVossen
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-24 15:07 ` Robert VanVossen
@ 2015-03-24 15:19 ` Julien Grall
0 siblings, 0 replies; 10+ messages in thread
From: Julien Grall @ 2015-03-24 15:19 UTC (permalink / raw)
To: Robert VanVossen, xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
On 24/03/2015 15:07, Robert VanVossen wrote:
> Hello Julien,
Hello Robert,
> On 3/23/2015 5:53 PM, Julien Grall wrote:
> But don't we need to handle the failure of attach_dev differently based on which
> fails? If the attach_dev fails on a new iommu_domain, then the iommu_domain
> should be destroyed. If it fails on a preexisting iommu_domain that is already
> attached to another device, then you don't want to destroy the iommu_domain.
It should be covered by
if (failed && atomic == 0)
destroy iommu_domain.
If you prefer to keep the 2 possible case separate, I would still like
to have a separate helper to get the domain.
Regards,
--
Julien Grall
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-24 14:04 ` Robert VanVossen
@ 2015-03-25 4:58 ` Manish Jaggi
2015-03-25 17:35 ` Stefano Stabellini
0 siblings, 1 reply; 10+ messages in thread
From: Manish Jaggi @ 2015-03-25 4:58 UTC (permalink / raw)
To: Robert VanVossen, xen-devel
Cc: julien.grall, edgar.iglesias, Josh.Whitehead, Ian.Campbell,
Stefano.Stabellini
On Tuesday 24 March 2015 07:34 PM, Robert VanVossen wrote:
>
> On 3/24/2015 7:07 AM, Manish Jaggi wrote:
>> On Monday 23 March 2015 07:16 PM, Robbie VanVossen wrote:
>>> If multiple devices are being passed through to the same domain and they
>>> share a single SMMU, then they only require a single iommu_domain.
>>>
>>> In arm_smmu_assign_dev, before a new iommu_domain is created, the
>>> xen_domain->contexts is checked for any iommu_domains that are already
>>> assigned to device that uses the same SMMU as the current device. If one
>>> is found, attach the device to that iommu_domain. If a new one isn't
>>> found, create a new iommu_domain just like before.
>>>
>>> The arm_smmu_deassign_dev function assumes that there is a single
>>> device per iommu_domain. This meant that when the first device was
>>> deassigned, the iommu_domain was freed and when another device was
>>> deassigned a crash occured in xen.
>>>
>>> To fix this, a reference counter was added to the iommu_domain struct.
>>> When an arm_smmu_xen_device references an iommu_domain, the
>>> iommu_domains ref is incremented. When that reference is removed, the
>>> iommu_domains ref is decremented. The iommu_domain will only be freed
>>> when the ref is 0.
>>>
>>> Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
>> Hi,
>> Are you adding a PCI passthrough support to Xen ?. I am in process of
>> sending smmu driver patches based on juliens latest code.
>>
> Nope, I am just working on what this patch describes
Your patch is doing similar thing what am working on. As per the Xen 4.6
release I took smmu for pci-passthorugh. I didnt send smmu patches so
far as there are other dependency patches I need to send first like
pci_host_bridge register hypercall patch.
Julien/Ian could you please hold the merge of this patch.
> Thanks,
> Robbie VanVossen
> DornerWorks
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-25 4:58 ` Manish Jaggi
@ 2015-03-25 17:35 ` Stefano Stabellini
2015-03-30 11:04 ` Manish Jaggi
0 siblings, 1 reply; 10+ messages in thread
From: Stefano Stabellini @ 2015-03-25 17:35 UTC (permalink / raw)
To: Manish Jaggi
Cc: edgar.iglesias, Ian.Campbell, Stefano.Stabellini,
Robert VanVossen, julien.grall, Josh.Whitehead, xen-devel
On Wed, 25 Mar 2015, Manish Jaggi wrote:
> On Tuesday 24 March 2015 07:34 PM, Robert VanVossen wrote:
> >
> > On 3/24/2015 7:07 AM, Manish Jaggi wrote:
> > > On Monday 23 March 2015 07:16 PM, Robbie VanVossen wrote:
> > > > If multiple devices are being passed through to the same domain and they
> > > > share a single SMMU, then they only require a single iommu_domain.
> > > >
> > > > In arm_smmu_assign_dev, before a new iommu_domain is created, the
> > > > xen_domain->contexts is checked for any iommu_domains that are already
> > > > assigned to device that uses the same SMMU as the current device. If one
> > > > is found, attach the device to that iommu_domain. If a new one isn't
> > > > found, create a new iommu_domain just like before.
> > > >
> > > > The arm_smmu_deassign_dev function assumes that there is a single
> > > > device per iommu_domain. This meant that when the first device was
> > > > deassigned, the iommu_domain was freed and when another device was
> > > > deassigned a crash occured in xen.
> > > >
> > > > To fix this, a reference counter was added to the iommu_domain struct.
> > > > When an arm_smmu_xen_device references an iommu_domain, the
> > > > iommu_domains ref is incremented. When that reference is removed, the
> > > > iommu_domains ref is decremented. The iommu_domain will only be freed
> > > > when the ref is 0.
> > > >
> > > > Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
> > > Hi,
> > > Are you adding a PCI passthrough support to Xen ?. I am in process of
> > > sending smmu driver patches based on juliens latest code.
> > >
> > Nope, I am just working on what this patch describes
> Your patch is doing similar thing what am working on. As per the Xen 4.6
> release I took smmu for pci-passthorugh. I didnt send smmu patches so far as
> there are other dependency patches I need to send first like pci_host_bridge
> register hypercall patch.
>
> Julien/Ian could you please hold the merge of this patch.
Sorry Manish, but the Xen community works on a first come first served
basis: if/when this patch is considered in good condition and ready to
be merged, is likely to be merged.
Unless you have a specific concern about the code of course.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-25 17:35 ` Stefano Stabellini
@ 2015-03-30 11:04 ` Manish Jaggi
2015-03-30 11:40 ` Julien Grall
0 siblings, 1 reply; 10+ messages in thread
From: Manish Jaggi @ 2015-03-30 11:04 UTC (permalink / raw)
To: Stefano Stabellini
Cc: edgar.iglesias, Ian.Campbell, Robert VanVossen, julien.grall,
Josh.Whitehead, xen-devel
On Wednesday 25 March 2015 11:05 PM, Stefano Stabellini wrote:
> On Wed, 25 Mar 2015, Manish Jaggi wrote:
>> On Tuesday 24 March 2015 07:34 PM, Robert VanVossen wrote:
>>> On 3/24/2015 7:07 AM, Manish Jaggi wrote:
>>>> On Monday 23 March 2015 07:16 PM, Robbie VanVossen wrote:
>>>>> If multiple devices are being passed through to the same domain and they
>>>>> share a single SMMU, then they only require a single iommu_domain.
>>>>>
>>>>> In arm_smmu_assign_dev, before a new iommu_domain is created, the
>>>>> xen_domain->contexts is checked for any iommu_domains that are already
>>>>> assigned to device that uses the same SMMU as the current device. If one
>>>>> is found, attach the device to that iommu_domain. If a new one isn't
>>>>> found, create a new iommu_domain just like before.
>>>>>
>>>>> The arm_smmu_deassign_dev function assumes that there is a single
>>>>> device per iommu_domain. This meant that when the first device was
>>>>> deassigned, the iommu_domain was freed and when another device was
>>>>> deassigned a crash occured in xen.
>>>>>
>>>>> To fix this, a reference counter was added to the iommu_domain struct.
>>>>> When an arm_smmu_xen_device references an iommu_domain, the
>>>>> iommu_domains ref is incremented. When that reference is removed, the
>>>>> iommu_domains ref is decremented. The iommu_domain will only be freed
>>>>> when the ref is 0.
>>>>>
>>>>> Signed-off-by: Robbie VanVossen <robert.vanvossen@dornerworks.com>
>>>> Hi,
>>>> Are you adding a PCI passthrough support to Xen ?. I am in process of
>>>> sending smmu driver patches based on juliens latest code.
>>>>
>>> Nope, I am just working on what this patch describes
>> Your patch is doing similar thing what am working on. As per the Xen 4.6
>> release I took smmu for pci-passthorugh. I didnt send smmu patches so far as
>> there are other dependency patches I need to send first like pci_host_bridge
>> register hypercall patch.
>>
>> Julien/Ian could you please hold the merge of this patch.
> Sorry Manish, but the Xen community works on a first come first served
> basis: if/when this patch is considered in good condition and ready to
> be merged, is likely to be merged.
> Unless you have a specific concern about the code of course.
Ok. I will incorporate robert's patch in my patch set.
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU
2015-03-30 11:04 ` Manish Jaggi
@ 2015-03-30 11:40 ` Julien Grall
0 siblings, 0 replies; 10+ messages in thread
From: Julien Grall @ 2015-03-30 11:40 UTC (permalink / raw)
To: Manish Jaggi, Stefano Stabellini
Cc: edgar.iglesias, xen-devel, Josh.Whitehead, Ian.Campbell,
Robert VanVossen
Hello,
On 30/03/15 12:04, Manish Jaggi wrote:
>>> Julien/Ian could you please hold the merge of this patch.
>> Sorry Manish, but the Xen community works on a first come first served
>> basis: if/when this patch is considered in good condition and ready to
>> be merged, is likely to be merged.
>> Unless you have a specific concern about the code of course.
> Ok. I will incorporate robert's patch in my patch set.
Why we should wait you to sent your PCI SMMU changes? It will likely
take another couple of months before your series will be merged.
Robert's patch is a standalone patch which is useful for non-PCI case
(for instance 2 networks cards under the same SMMU).
He sent the v4 last week and the patch is ready to go in Xen tree.
Regards,
--
Julien Grall
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-03-30 11:41 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-23 13:46 [PATCH v2] xen/passthrough: Support a single iommu_domain per xen domain per SMMU Robbie VanVossen
2015-03-23 21:53 ` Julien Grall
2015-03-24 15:07 ` Robert VanVossen
2015-03-24 15:19 ` Julien Grall
2015-03-24 11:07 ` Manish Jaggi
2015-03-24 14:04 ` Robert VanVossen
2015-03-25 4:58 ` Manish Jaggi
2015-03-25 17:35 ` Stefano Stabellini
2015-03-30 11:04 ` Manish Jaggi
2015-03-30 11:40 ` Julien Grall
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.