[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/arm: smmuv1: remove iommu group when deassign a device


  • To: Mykyta Poturai <mykyta.poturai@xxxxxxxxx>
  • From: Rahul Singh <Rahul.Singh@xxxxxxx>
  • Date: Thu, 21 Jul 2022 15:53:30 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T7qqhMz9u9+zPwSI1CNZsMaoieAopSHk2OeZj4UUXT0=; b=g0b23Swn0i8dMqmkP1OARmr6RhPIzthNZle+cb1Mkhs3xKNM8SUa/spE8nypLvuXj2jUQ2y23lw2h0Jw6gN0oF9Z7DJ7CLWuenObo/iJfGmeUMKO9A5NYZs9im+bLe5HXf3DolEYe4q0fc4gTLnCCAifLM05dKS91Xw+Q7SCvVQpB6arLm27ZvBnkK8JKCqSmdfEAR3Y/3phewTTpoUaF5DtbQly6c3FXa6eO4ajn810dD/LlLFBd14nxxfm4udnqeULMpkclyb5Wh1zN0o9IPF+kwBPKBM4S5C/kk4HuowkcpoJnizq4kDhiqvF/3zGd/CHMmjY7OTIUNpM1ExmsA==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T7qqhMz9u9+zPwSI1CNZsMaoieAopSHk2OeZj4UUXT0=; b=ibLErslqnjdeXrHvi9S1p3HhQHwEYfFvHjeavsOJWaSH9XT9eHLd09GfXaF9tklhOyxzSRThqEHE95vNNLdCGRmRWrD4c9Fx2fygo6/MjqCaOS0vJfRPKlkZZ52N0xthG9YbGKkJGKT4klOsoGIiAkAzTDzMr1J3BaO07cghakFI26SWthMAoCNaE9bo+IXUAeI/MVIU9+N9IhHZCooB3xoyhUtAa8h24ZiGgCBxivsFGHDb5iIIrhnTMRUolA/4/juz8qmcLjl/3S7+py3w8IMSK0WqX/j4l9pSHzxYxeiupdoZLzhluQLLWLvLhrXtLxvCSTyfNYJE1mX4nOFpiQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=O2tWMdBFZJwfmo3KKwTxFOwbbTqiiiKTIr1QMBIqV3F4uUSlJ7TTAM2tuFC3nKoRrHPdycqUkIDuZIHS3pH0Tud3ed2Mo/c9nJSEP5ZikQ8DEE8PhwlrMj5fJj3gXNVdXZrGn5NLE5QvCZAjyNXGI3tHsT9uqNk1LzemdYbwrN4mvVRXahCRIfWNUBYA4u8Bs5osikxjeAgjvSQ/cTh8dz8j2OuZVGL5DTEimuw6mz0WrU9rCGF6CZ4K8EZXi2sTvHYeX01uACPINTDROWmttZPBvOpPtiNS7MhJcMUtNCrcfDFn5TJjx5xma1F9dca99+6fYwvqaena9KnNMC1pdQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0sE+/yKwmObztipMkEMN4N08DGevzrzoJo2WxEb9JYkVD3jSGy3AFohPWuiP/xe4wSvyghFXAsUpI5YB8VFOz5DQgVGBxscySOXoNM26CB4bg96JDA2bpX2B6FjOFNb0inMw1Hmrt/fwcI99bc9xT9V8VEgJ0eJPKudxpXd1xEkOZ4KbVv/5lUaEQfpbvlzXBDqoD50EYXdFdxPA8l8WKWKYO9iDjEpKqk++AFTz2FR6xiK5IigInx7umsIUX7W9pD6hGkLSFyolFvVzfry/LDwpK+Ow6UAVukfDqvWoYkOYUXywrZ/P/9EzJg7BcxFk8dfd3l5uGoLM8aYJoLrbQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, "Volodymyr_Babchuk@xxxxxxxx" <Volodymyr_Babchuk@xxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 21 Jul 2022 15:54:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYWlIekEFYa4Z+ZkOKg6prrRxnv60EB7eAgALvxoCABl1EgIBEoW2AgAA0fACAAZfdAIAEm8YAgAGSSQCAAEbogIALO3kAgCQMb4A=
  • Thread-topic: [PATCH] xen/arm: smmuv1: remove iommu group when deassign a device

Hi ,

> On 28 Jun 2022, at 6:23 pm, Mykyta Poturai <mykyta.poturai@xxxxxxxxx> wrote:
> 
>> Hi Mykyta,
>> 
>>> On 21 Jun 2022, at 10:38 am, Mykyta Poturai <mykyta.poturai@xxxxxxxxx> 
>>> wrote:
>>> 
>>>> Thanks for testing the patch.
>>>>> But not fixed the "Unexpected Global fault" that occasionally happens 
>>>>> when destroying
>>>>> the domain with an actively working GPU. Although, I am not sure if this 
>>>>> issue
>>>>> is relevant here.
>>>> 
>>>> Can you please if possible share the more details and logs so that I can 
>>>> look if this issue is relevant here ?
>>> 
>>> So in my setup I have a board with IMX8 chip and 2 core Vivante GPU. GPU is 
>>> split between domains.
>>> One core goes to Dom0 and one to DomU.
>>> 
>>> Steps to trigger this issue:
>>> 1. Start DomU
>>> 2. Start wayland and glmark2-es2-wayland inside DomU
>>> 3. Destroy DomU
>>> 
>>> Sometimes it destroys fine but roughly 1 of 8 times I get logs like this:
>>> 
>>> root@dom0:~# xl dest DomU
>>> [12725.412940] xenbr0: port 1(vif8.0) entered disabled state
>>> [12725.671033] xenbr0: port 1(vif8.0) entered disabled state
>>> [12725.689923] device vif8.0 left promiscuous mode
>>> [12725.696736] xenbr0: port 1(vif8.0) entered disabled state
>>> [12725.696989] audit: type=1700 audit(1616594240.068:39): dev=vif8.0 prom=0 
>>> old_prom=256 auid=4294967295 uid=0 gid=0 ses=4294967295
>>> (XEN) smmu: /iommu@51400000: Unexpected global fault, this could be serious
>>> (XEN) smmu: /iommu@51400000:    GFSR 0x00000001, GFSYNR0 0x00000004, 
>>> GFSYNR1 0x00001055, GFSYNR2 0x00000000
>>> 
>>> My guess is that this happens because GPU continues to access memory when 
>>> the context is already invalidated,
>>> and therefore triggers the "Invalid context fault".
>> 
>> Yes you are right in this case GPU trying to do DMA operation after Xen 
>> destroyed the guest and configures
>> the S2CR type value to fault. Solution to this issue is the patch that I 
>> shared earlier.
>> 
>> You can try this patch and confirm.This patch will solve both the issues.
>> 
>> diff --git a/xen/drivers/passthrough/arm/smmu.c 
>> b/xen/drivers/passthrough/arm/smmu.c
>> index 5cacb2dd99..ff1b73d3d8 100644
>> --- a/xen/drivers/passthrough/arm/smmu.c
>> +++ b/xen/drivers/passthrough/arm/smmu.c
>> @@ -1680,6 +1680,10 @@ static int arm_smmu_attach_dev(struct iommu_domain 
>> *domain, struct device *dev)
>> if (!cfg)
>> return -ENODEV;
>> 
>> + ret = arm_smmu_master_alloc_smes(dev);
>> + if (ret)
>> + return ret;
>> +
>> return arm_smmu_domain_add_master(smmu_domain, cfg);
>> }
>> 
>> @@ -2075,7 +2079,7 @@ static int arm_smmu_add_device(struct device *dev)
>> iommu_group_add_device(group, dev);
>> iommu_group_put(group);
>> 
>> - return arm_smmu_master_alloc_smes(dev);
>> + return 0;
>> }
>> 
>> 
>> Regards,
>> Rahul
> 
> Hi Rahul,
> 
> With this patch I get the same results, here is the error message:
> 
> (XEN) smmu: /iommu@51400000: Unexpected global fault, this could be serious
> (XEN) smmu: /iommu@51400000:    GFSR 0x00000001, GFSYNR0 0x00000004, GFSYNR1 
> 0x00001055, GFSYNR2 0x00000000
> 

As you mentioned earlier, this fault is observed because GPU continues to 
access memory when the context is
already invalidated, and therefore triggers the "Invalid context fault".  This 
is a different issue and is not related to this patch.

@Julien are you okay if I will send the below patch for official review as this 
issue pending for a long time?

In this patch we don’t need to call arm_smmu_master_free_smes() in 
arm_smmu_detach_dev() but we will implement new
function arm_smmu_domain_remove_master() that will configure the s2cr value to 
type fault in detach function.
arm_smmu_domain_remove_master() will revert the changes done by 
arm_smmu_domain_add_master() in attach function.


diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index 69511683b4..da3adf8e7f 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -1598,21 +1598,6 @@ out_err:
return ret;
}

-static void arm_smmu_master_free_smes(struct arm_smmu_master_cfg *cfg)
-{
- struct arm_smmu_device *smmu = cfg->smmu;
- int i, idx;
- struct iommu_fwspec *fwspec = arm_smmu_get_fwspec(cfg);
-
- spin_lock(&smmu->stream_map_lock);
- for_each_cfg_sme(cfg, i, idx, fwspec->num_ids) {
- if (arm_smmu_free_sme(smmu, idx))
- arm_smmu_write_sme(smmu, idx);
- cfg->smendx[i] = INVALID_SMENDX;
- }
- spin_unlock(&smmu->stream_map_lock);
-}
-
static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,
struct arm_smmu_master_cfg *cfg)
{
@@ -1635,6 +1620,20 @@ static int arm_smmu_domain_add_master(struct 
arm_smmu_domain *smmu_domain,
return 0;
}

+static void arm_smmu_domain_remove_master(struct arm_smmu_domain *smmu_domain,
+ struct arm_smmu_master_cfg *cfg)
+{
+ struct arm_smmu_device *smmu = smmu_domain->smmu;
+ struct arm_smmu_s2cr *s2cr = smmu->s2crs;
+ struct iommu_fwspec *fwspec = arm_smmu_get_fwspec(cfg);
+ int i, idx;
+
+ for_each_cfg_sme(cfg, i, idx, fwspec->num_ids) {
+ s2cr[idx] = s2cr_init_val;
+ arm_smmu_write_s2cr(smmu, idx);
+ }
+}
+
static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
{
int ret;
@@ -1684,10 +1683,11 @@ static int arm_smmu_attach_dev(struct iommu_domain 
*domain, struct device *dev)

static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
{
+ struct arm_smmu_domain *smmu_domain = domain->priv;
struct arm_smmu_master_cfg *cfg = find_smmu_master_cfg(dev);

if (cfg)
- arm_smmu_master_free_smes(cfg);
+ return arm_smmu_domain_remove_master(smmu_domain, cfg);

}


Regards,
Rahul

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.