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

Re: [PATCH v5 10/10] xen/arm: smmuv3: Add support for SMMUv3 driver


  • To: Julien Grall <julien@xxxxxxx>
  • From: Rahul Singh <Rahul.Singh@xxxxxxx>
  • Date: Thu, 21 Jan 2021 20:28:43 +0000
  • Accept-language: en-US
  • 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=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-SenderADCheck; bh=mVY7U+yqlxESrTAtpup1k4/z60RBjYL7x6NbiWWNohI=; b=XptpCggH3SAo3kKBIxiw75cQhiu4XhWvlU5MlN43TE9y+wHxTF+2UH3XcK5IdaKOnnFAWAonTV43JXUCC9AkOokoIw959omKnrGNXMtYSNKtkRoz0vELMCFS6C3G4Z9kYYTQe86loO5nhpopPBPk+DEwSpcga75vYGKZHMfGQaE/qFTJuIB8Y7rntJnPS0gFpbrpKwnA7gsT6phhlUBVZd0oDy2H9NmUguWcWTAaEaB1mlrijsRajt6S/Pu+YvXbXjXpPIgzUCbB8vi7O9oCa7CTxXVzHIiEny2wXWp8Ti99/fp/SmQ/3Iw/wl3WHLLJLgapLfbm97kaC2OwhHCFew==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h0XR3Ug/fXfAxIbeTf2OLP2V0l2Rk0+K2GZbsVsb6OCMlGsdaTH9B04OLUA4lUa+KuetN6q44yLZ6Oz8eNEEqp6nc9fT8SjqbPTP+vctlgLiNhxvKT0VSIEL507c+tKZ6ehbVB0kecZiCHqRizpOODXoglUzGI9x/BS1EHStCAGFclDCJWhRX8KiN1bMvDvkl40Weg4OeeVSz8mSITjADptBqeITPHT5LGjimdBPvsQfB2dm/+0YXY4Gk94srBT74x1hKz/srtq4evV1fkntXlpNptiZVNPKxVgHNgela/j2EZbyYKaO064nYJQO78t8AKomTgPsyFwKUS+wkzvchw==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>, Paul Durrant <paul@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 21 Jan 2021 20:29:02 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHW7zzXDLVfiB5hzUKpOAlBcRNn7Kow+AwAgAFaLYCAABnVAIAAHX2A
  • Thread-topic: [PATCH v5 10/10] xen/arm: smmuv3: Add support for SMMUv3 driver

Hello Julien,

> On 21 Jan 2021, at 6:43 pm, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Rahul,
> 
> Please try to trim the e-mail when quoting, otherwise it is quite difficult 
> to find the only couple of answer you wrote.
> 
> On 21/01/2021 17:10, Rahul Singh wrote:
>>> On 20 Jan 2021, at 8:31 pm, Stefano Stabellini <sstabellini@xxxxxxxxxx> 
>>> wrote:
>>>> -static void __iomem *arm_smmu_ioremap(struct device *dev, resource_size_t 
>>>> start,
>>>> -                                resource_size_t size)
>>>> +
>>>> +static void arm_smmu_free_structures(struct arm_smmu_device *smmu)
>>>> {
>>>> -  struct resource res = {
>>>> -          .flags = IORESOURCE_MEM,
>>>> -          .start = start,
>>>> -          .end = start + size - 1,
>>>> -  };
>>>> +  if (smmu->cmdq.q.base)
>>>> +          xfree(smmu->cmdq.q.base);
>>>> +
>>>> +  if (smmu->evtq.q.base)
>>>> +          xfree(smmu->evtq.q.base);
>>>> 
>>>> -  return devm_ioremap_resource(dev, &res);
>>>> +  if (smmu->priq.q.base)
>>>> +          xfree(smmu->priq.q.base);
>>>> +
>>>> +  if (smmu->strtab_cfg.strtab)
>>>> +          xfree(smmu->strtab_cfg.strtab);
>>>> +
>>>> +  if (smmu->strtab_cfg.l1_desc)
>>>> +          xfree(smmu->strtab_cfg.l1_desc);
>>> 
>>> From what I can tell we also need to free somewhere
>>> smmu->strtab_cfg->l1_desc->l2ptr allocated by arm_smmu_init_l2_strtab
>> "l1_desc->l2ptr" is a pointer to the Level 1 Stream Table Descriptor if 
>> 2-level Stream Table supported.
>> If the device is protected by IOMMU, SMMUv3 driver will allocate the  
>> "l1_desc->l2ptr” when the device is added to the IOMMU via 
>> arm_smmu_add_device() function and device will be configured in bypass/abort 
>> mode.
>> Once we assign the device to the domain(arm_smmu_assign_dev() ) smmuv3 hw 
>> will be configured correctly to match the StreamID. If there is a failure in 
>> assigning the device, that case also XEN will not remove the device and 
>> master device still be in bypass/abort mode.
> 
> I am a bit confused with this answer. Wouldn't this mean that we are 
> "leaking" memory if we fail to assign the device?

No we are not leaking memory as "l1_desc->l2ptr” is still be valid and is 
required for correct SMMUv3 opeation if we fail to assign the device, as in 
that case device will operate in bypass or abort mode. 

For example if by any chance there is faulty hw behind SMMUv3 then if we fail 
to assign the device we can configure the device in abort mode in that case 
SMMUv3 hw will silently report abort to device, without any event recorded.

We can also configure the device in bypass mode if we fail to assign. Thats why 
I thought not to free the "l1_desc->l2ptr” if we fail to assign the device.

> 
>> As in XEN, there is no function to remove the master device from the IOMMU, 
>> because of that I feel there is no need to free the "l1_desc->l2ptr” in case 
>> of failure also.
> 
> Hmmm... Xen is able to remove device from the IOMMU. The reason this is not 
> implemented yet on Arm is because you can't hot-unplug "platform" device.
> 
> I expect the removal function to be useful for PCI.

Yes I agree for PCI hot plug devices we have to implement the IOMMU remove 
function. If we implement the remove function for PCI hot-plug we can free the 
the "l1_desc->l2ptr” in the remove function for that device. 

Regards,
Rahul
> 
> Cheers,
> 
> -- 
> Julien Grall


 


Rackspace

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