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

Re: [PATCH] xen/arm: smmuv1: Set s2cr to type fault when the devices are deassigned


  • To: Julien Grall <julien@xxxxxxx>
  • From: Rahul Singh <Rahul.Singh@xxxxxxx>
  • Date: Wed, 10 Aug 2022 09:51:06 +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=pUHtNR5I2sUhksranR3Xiofr/HqawJ7BxvPt+dq9Blw=; b=LkyfhBjeMOW98koJjuTCfZdRdBoWcqT/Q9gaZaRKNVUpp5MpSPRiyrw9Osb342q2ovBDC8bL7+6nO3VlX2RvfFjCqNBHnykiSkJc+xZPNUiq6PrPwb8u4Phxo53MrBFrZMv3B1q008SA4hQDYFK7vSXSku6eHz9fHViTiqSnVDhIRkivZzQ7sHLEpYsnc0yBTyY3gVwRGnsswhP8LYzXhbiMe1PoiAdTBTmNQnde+6Cg1op1eSCtORab72pMr/gXBqZrJ8EwGoooESOKLyFtCX9WpiSyyNBMlXQj254cTm5fRvZQ6L1oq5Onrx6AdPPrbs5GWckTRy9ka5Grxyj5cA==
  • 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=pUHtNR5I2sUhksranR3Xiofr/HqawJ7BxvPt+dq9Blw=; b=QtA9Mxuwrxk+E+ZptfHORfj2dzLlPl6fvTI0BnwfGLokGOAaWzsmKx2ufQArfCBOlvt0itiJtL8QNuAse0xVJzEtNyBQa90uEP7PEgvt7ApfXv7KRuVV9h7TeAiWCjWF7Ot+xhzXgy8cCsH/hhQyMn6EfThMoW7fAdEMipTwbIK6prQXluaYao3AnFH/V+2Anu2bO8cOVsYFq6n0jmqLijR3SDCAdB7akYxoF8I3wrWFTrrdFNW1VDGoFEDboqRGjg2IyxOgNlp2TDy+aNZ7dZWVOP74mBwzjxbpn7JIZJJeH4OHKbZ1T0OSy08DGEURu2rX1aIFUzu5fZuTb3SY8w==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=O/uttVfUwJeXVZi4VhWdLAHfe6lnv5oybfpmR2Uuu4oMNWbvFOGb3p+XpHa0mNk/5RBqhCdJCudK/vQGH30xy29G2cyg+H80hY86T1MsJmGAKeZfyyY+64t16Gu2i/sAnE2nlqAcKgDjK9pn/dxFGeehoSSzWo9zEpFCcBfwgOs4NRCe5ThAerLDtgRVNp5mdE/kiC2uaBJVyHac8VDZjUWjNjRdaQOOirYW7PSW93So6pAhCQaGOUWkc9oVHNclOlt/RfxJlUw31GzL6waEsGWTHPE9gRVlo1LzbMrWK1eojyRwfWCi///yEZ+zXZsXYpvImmeLpAqPC0iSBqFvAw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lzD8KJjytDKrdbMhdy1Lrir6Kk2nWxyLB9cblfiKXUjSOUXgcNSOk1en242gJSID2ZNEMkcM2A/iEbPc/BGBh6n1eRqDM0MW7WtoFmr0SGhBaS++YeE41/SX4DCM29OyB2jE7lWZEwgDDTpboEIbJfRYKMkXwmAIi8rwPisDVqRJ3rFcZlD3GNHpiW7pdEtU7S3d9jcACI+XY2WbiyFy27gOLL/iWKeU3loFGW8IezYankjjgUjdQ0uN1SqgJZMH/S3hkUnPRChrsktYF/4Gsr9O0bmTyaCr+ThqJayfsxRz1EQO4nK108Wz7NiO1hJXtvlXhUFvrIjruQoqINze9g==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Wed, 10 Aug 2022 09:51:26 +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: AQHYqOJsqJOnAKwEgEyxPjukHtiB2a2m52IAgAEERAA=
  • Thread-topic: [PATCH] xen/arm: smmuv1: Set s2cr to type fault when the devices are deassigned

Hi Julien,

> On 9 Aug 2022, at 7:19 pm, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Rahul,
> 
> title: The driver is for both smmuv1 and v2. Are you suggesting the issue 
> only occurs on v1?

Issue occurs on both v1 & v2. I will fix this in next version.
> 
> On 05/08/2022 16:43, Rahul Singh wrote:
>> When devices are deassigned/assigned, SMMU global fault is observed
>> because SMEs are freed in detach function and not allocated again when
>> the device is assigned back to the guest.
>> Don't free the SMEs when devices are deassigned, set the s2cr to type
>> fault. This way the SMMU will generate a fault if a DMA access is done
>> by a device not assigned to a guest
>> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
> 
> AFAICT, this is fixing 0435784cc75d ("xen/arm: smmuv1: Intelligent SMR 
> allocation"). If I am correct, can you add a Fixes tag?

Yes, I will add the fixes tag.
> 
>> ---
>>  xen/drivers/passthrough/arm/smmu.c | 32 +++++++++++++++---------------
>>  1 file changed, 16 insertions(+), 16 deletions(-)
>> diff --git a/xen/drivers/passthrough/arm/smmu.c 
>> b/xen/drivers/passthrough/arm/smmu.c
>> index 69511683b4..141948decd 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)
> 
> IIUC, the function needs to be moved because you need to use 
> arm_smmu_write_s2cr(). If so, I would suggest to mention in the commit 
> message because at first it seems unwarranted.

Ack. I will add that in commit msg.
> 
>> -{
>> -    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)
>> +{
>> +    int i, idx;
> 
> NIT: I would suggest to take the opportunity to switch to "unsigned int" and 
> ...

Ack. 
> 
>> +    struct arm_smmu_device *smmu = smmu_domain->smmu;
>> +    struct arm_smmu_s2cr *s2cr = smmu->s2crs;
>> +    struct iommu_fwspec *fwspec = arm_smmu_get_fwspec(cfg);
> 
> ... use const here. "cfg" and "smmu" can't be consistent but "smmu_domain" 
> technically could (thanks to how C works). That said, I quite dislike it as 
> the code ends up to be confusing...

Ack. 
> 
>> +
>> +    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);
> 
> Why are you using adding a 'return' here?

Not required. I will remove “return”.

Regards,
Rahul

 


Rackspace

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