All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Rahul Singh <Rahul.Singh@arm.com>
Cc: Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>,
	 "xen-devel@lists.xenproject.org"
	<xen-devel@lists.xenproject.org>,
	 Bertrand Marquis <Bertrand.Marquis@arm.com>,
	 Andrew Cooper <andrew.cooper3@citrix.com>,
	 George Dunlap <george.dunlap@citrix.com>,
	Ian Jackson <iwj@xenproject.org>,
	 Jan Beulich <jbeulich@suse.com>, Wei Liu <wl@xen.org>,
	 Paul Durrant <paul@xen.org>,
	 Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH v5 10/10] xen/arm: smmuv3: Add support for SMMUv3 driver
Date: Thu, 21 Jan 2021 13:20:08 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.21.2101211310220.30512@sstabellini-ThinkPad-T480s> (raw)
In-Reply-To: <47E677DA-007E-445D-A72E-599676202CB7@arm.com>

[-- Attachment #1: Type: text/plain, Size: 3241 bytes --]

On Thu, 21 Jan 2021, Rahul Singh wrote:
> > On 21 Jan 2021, at 6:43 pm, Julien Grall <julien@xen.org> wrote:
> > On 21/01/2021 17:10, Rahul Singh wrote:
> >>> On 20 Jan 2021, at 8:31 pm, Stefano Stabellini <sstabellini@kernel.org> 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.

Basically there are two places where l2ptr should be freed:

1) the error out path (err_free_master) in arm_smmu_add_device
2) arm_smmu_remove_device

However, arm_smmu_remove_device is not actually implementedi at all. In
regards to 1), it would be redundant because the memory allocation of
l2ptr is the last operation that could return an error in
arm_smmu_add_device. In other words, if it fails then the memory is not
allocated.

To avoid future memory-leaks in case we add function calls that could
fail after the arm_smmu_init_l2_strtab() call in arm_smmu_add_device, I
think it would be good to have an xfree(l2ptr) under err_free_master.
But given that it is not necessary today I am OK either way.

  reply	other threads:[~2021-01-21 21:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 14:52 [PATCH v5 00/10] xen/arm: Add support for SMMUv3 driver Rahul Singh
2021-01-20 14:52 ` [PATCH v5 01/10] xen/arm: smmuv3: Import the SMMUv3 driver from Linux Rahul Singh
2021-01-20 14:52 ` [PATCH v5 02/10] xen/arm: Revert atomic operation related command-queue insertion patch Rahul Singh
2021-01-20 14:52 ` [PATCH v5 03/10] xen/arm: smmuv3: Revert patch related to XArray Rahul Singh
2021-01-20 14:52 ` [PATCH v5 04/10] xen/arm: smmuv3: Remove support for Stage-1 translation on SMMUv3 Rahul Singh
2021-01-20 14:52 ` [PATCH v5 05/10] xen/arm: smmuv3: Remove Linux specific code that is not usable in XEN Rahul Singh
2021-01-20 14:52 ` [PATCH v5 06/10] xen/device-tree: Add dt_property_match_string helper Rahul Singh
2021-01-20 14:52 ` [PATCH v5 07/10] xen/compiler: import 'fallthrough' keyword from linux Rahul Singh
2021-01-20 14:52 ` [PATCH v5 08/10] xen/arm: smmuv3: Use fallthrough pseudo-keyword Rahul Singh
2021-01-20 15:36   ` Bertrand Marquis
2021-01-20 19:56   ` Stefano Stabellini
2021-01-20 14:52 ` [PATCH v5 09/10] xen/arm: smmuv3: Replace linux functions with xen functions Rahul Singh
2021-01-20 14:52 ` [PATCH v5 10/10] xen/arm: smmuv3: Add support for SMMUv3 driver Rahul Singh
2021-01-20 15:35   ` Bertrand Marquis
2021-01-20 20:31   ` Stefano Stabellini
2021-01-21 17:10     ` Rahul Singh
2021-01-21 18:43       ` Julien Grall
2021-01-21 20:28         ` Rahul Singh
2021-01-21 21:20           ` Stefano Stabellini [this message]
2021-01-20 21:33   ` Oleksandr
2021-01-21 17:18     ` Rahul Singh
2021-01-21 18:31       ` Julien Grall
2021-01-21 18:50         ` Rahul Singh
2021-01-21 20:19           ` Julien Grall

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=alpine.DEB.2.21.2101211310220.30512@sstabellini-ThinkPad-T480s \
    --to=sstabellini@kernel.org \
    --cc=Bertrand.Marquis@arm.com \
    --cc=Rahul.Singh@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=paul@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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 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.