From: Robin Murphy <robin.murphy@arm.com>
To: Zhang Zekun <zhangzekun11@huawei.com>, joro@8bytes.org, will@kernel.org
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
baolu.lu@linux.intel.com, robh@kernel.org, nicolinc@nvidia.com,
john.g.garry@oracle.com, kevin.tian@intel.com
Subject: Re: [RESEND PATCH 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches
Date: Fri, 11 Aug 2023 14:32:38 +0100 [thread overview]
Message-ID: <9582503d-6d48-e5e8-6eb0-a170eb0c1150@arm.com> (raw)
In-Reply-To: <20230811130246.42719-2-zhangzekun11@huawei.com>
On 2023-08-11 14:02, Zhang Zekun wrote:
> free_iova_rcaches() needs to check if cpu_rcache->loaded and
> cpu_rcache->prev is NULL before freeing them.
Why? iova_magazine_free() is just kfree(), and kfree(NULL) is perfectly
valid, specifically to avoid having to make cleanup paths all fiddly and
overcomplicated like this.
Thanks,
Robin.
> Because
> iova_domain_init_rcaches() may fail to alloc magazine for
> cpu_rcache->loaded and cpu_rcache->prev, but they will be freed
> for all cpus.
>
> Fixes: 32e92d9f6f87 ("iommu/iova: Separate out rcache init")
> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
> ---
> drivers/iommu/iova.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
> index 10b964600948..3c784a28e9ed 100644
> --- a/drivers/iommu/iova.c
> +++ b/drivers/iommu/iova.c
> @@ -746,8 +746,12 @@ int iova_domain_init_rcaches(struct iova_domain *iovad)
>
> spin_lock_init(&cpu_rcache->lock);
> cpu_rcache->loaded = iova_magazine_alloc(GFP_KERNEL);
> + if (!cpu_rcache->loaded) {
> + ret = -ENOMEM;
> + goto out_err;
> + }
> cpu_rcache->prev = iova_magazine_alloc(GFP_KERNEL);
> - if (!cpu_rcache->loaded || !cpu_rcache->prev) {
> + if (!cpu_rcache->prev) {
> ret = -ENOMEM;
> goto out_err;
> }
> @@ -903,7 +907,11 @@ static void free_iova_rcaches(struct iova_domain *iovad)
> break;
> for_each_possible_cpu(cpu) {
> cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu);
> + if (!cpu_rcache->loaded)
> + break;
> iova_magazine_free(cpu_rcache->loaded);
> + if (!cpu_rcache->prev)
> + break;
> iova_magazine_free(cpu_rcache->prev);
> }
> free_percpu(rcache->cpu_rcaches);
next prev parent reply other threads:[~2023-08-11 13:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 13:02 [RESEND PATCH 0/2] iommu/iova: optimize the iova rcache Zhang Zekun
2023-08-11 13:02 ` [RESEND PATCH 1/2] iommu/iova: Add check for cpu_rcache in free_iova_rcaches Zhang Zekun
2023-08-11 13:32 ` Robin Murphy [this message]
2023-08-12 2:21 ` zhangzekun (A)
2023-08-11 13:02 ` [RESEND PATCH 2/2] iommu/iova: allocate iova_rcache->depot dynamicly Zhang Zekun
2023-08-11 14:14 ` John Garry
2023-08-12 7:18 ` zhangzekun (A)
2023-08-15 15:15 ` John Garry
2023-08-16 3:40 ` zhangzekun (A)
2023-08-11 13:25 ` [RESEND PATCH 0/2] iommu/iova: optimize the iova rcache Robin Murphy
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=9582503d-6d48-e5e8-6eb0-a170eb0c1150@arm.com \
--to=robin.murphy@arm.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=john.g.garry@oracle.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=robh@kernel.org \
--cc=will@kernel.org \
--cc=zhangzekun11@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®