From: Robin Murphy <robin.murphy@arm.com>
To: John Garry <john.g.garry@oracle.com>, joro@8bytes.org
Cc: will@kernel.org, pasha.tatashin@soleen.com,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, rientjes@google.com, yosryahmed@google.com
Subject: Re: [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure
Date: Tue, 6 Feb 2024 11:25:03 +0000 [thread overview]
Message-ID: <879751d4-486c-4d5e-b9b3-60e8822ff3fb@arm.com> (raw)
In-Reply-To: <6041982e-3c65-497f-b7bf-3ac444fa3623@oracle.com>
On 06/02/2024 11:01 am, John Garry wrote:
> On 05/02/2024 15:32, Robin Murphy wrote:
>> Failure handling in iova_cache_get() is a little messy, and we'd like
>> to add some more to it, so let's tidy up a bit first. By leaving the
>> hotplug handler until last we can take advantage of kmem_cache_destroy()
>> being NULL-safe to have a single cleanup label. We can also improve the
>> error reporting, noting that kmem_cache_create() already screams if it
>> fails, so that one is redundant.
>>
>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
>
> Regardless of a couple of minor comments, below, FWIW:
> Reviewed-by: John Garry <john.g.garry@oracle.com>
Thanks!
>> ---
>> drivers/iommu/iova.c | 33 ++++++++++++++++-----------------
>> 1 file changed, 16 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
>> index d30e453d0fb4..cf95001d85c0 100644
>> --- a/drivers/iommu/iova.c
>> +++ b/drivers/iommu/iova.c
>> @@ -254,26 +254,20 @@ static void free_iova_mem(struct iova *iova)
>> int iova_cache_get(void)
>> {
>> + int err = -ENOMEM;
>> +
>> mutex_lock(&iova_cache_mutex);
>> if (!iova_cache_users) {
>> - int ret;
>> + iova_cache = kmem_cache_create("iommu_iova", sizeof(struct
>> iova), 0,
>> + SLAB_HWCACHE_ALIGN, NULL);
>
> Maybe can use KMEM_CACHE(), but it would mean that the name would change.
Oh, I never came across that before. On reflection, I am inclined to
think that the "iommu_" names are usefully informative to userspace, and
it's not worth churning the structure names themselves just to save a
couple of lines here.
>> + if (!iova_cache)
>> + goto out_err;
>> - ret = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD,
>> "iommu/iova:dead", NULL,
>> - iova_cpuhp_dead);
>> - if (ret) {
>> - mutex_unlock(&iova_cache_mutex);
>> - pr_err("Couldn't register cpuhp handler\n");
>> - return ret;
>> - }
>> -
>> - iova_cache = kmem_cache_create(
>> - "iommu_iova", sizeof(struct iova), 0,
>> - SLAB_HWCACHE_ALIGN, NULL);
>> - if (!iova_cache) {
>> - cpuhp_remove_multi_state(CPUHP_IOMMU_IOVA_DEAD);
>> - mutex_unlock(&iova_cache_mutex);
>> - pr_err("Couldn't create iova cache\n");
>> - return -ENOMEM;
>> + err = cpuhp_setup_state_multi(CPUHP_IOMMU_IOVA_DEAD,
>> "iommu/iova:dead",
>> + NULL, iova_cpuhp_dead);
>> + if (err) {
>> + pr_err("IOVA: Couldn't register cpuhp handler: %pe\n",
>> ERR_PTR(err));
>
> Maybe can use pr_fmt with "iova".
That one I did consider, but since we now have just this one print and
no imminent reason to add more, I figured I'd just stick it inline, and
we can factor out a pr_fmt in future if we ever have cause to.
Cheers,
Robin.
>
>> + goto out_err;
>> }
>> }
>> @@ -281,6 +275,11 @@ int iova_cache_get(void)
>> mutex_unlock(&iova_cache_mutex);
>> return 0;
>> +
>> +out_err:
>> + kmem_cache_destroy(iova_cache);
>> + mutex_unlock(&iova_cache_mutex);
>> + return err;
>> }
>> EXPORT_SYMBOL_GPL(iova_cache_get);
>
next prev parent reply other threads:[~2024-02-06 11:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 15:32 [PATCH v3 0/3] iommu/iova: use named kmem_cache for iova magazines Robin Murphy
2024-02-05 15:32 ` [PATCH v3 1/3] iommu/iova: Tidy up iova_cache_get() failure Robin Murphy
2024-02-05 18:15 ` David Rientjes
2024-02-05 18:51 ` Pasha Tatashin
2024-02-06 11:01 ` John Garry
2024-02-06 11:25 ` Robin Murphy [this message]
2024-02-07 16:38 ` Jerry Snitselaar
2024-02-05 15:32 ` [PATCH v3 2/3] iommu/iova: Reorganise some code Robin Murphy
2024-02-05 18:17 ` David Rientjes
2024-02-05 18:51 ` Pasha Tatashin
2024-02-06 11:05 ` John Garry
2024-02-07 16:41 ` Jerry Snitselaar
2024-02-05 15:32 ` [PATCH v3 3/3] iommu/iova: use named kmem_cache for iova magazines Robin Murphy
2024-02-06 11:24 ` John Garry
2024-02-06 11:32 ` Robin Murphy
2024-02-07 16:43 ` Jerry Snitselaar
2024-02-09 10:46 ` [PATCH v3 0/3] " Joerg Roedel
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=879751d4-486c-4d5e-b9b3-60e8822ff3fb@arm.com \
--to=robin.murphy@arm.com \
--cc=iommu@lists.linux.dev \
--cc=john.g.garry@oracle.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=rientjes@google.com \
--cc=will@kernel.org \
--cc=yosryahmed@google.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