From: Robin Murphy <robin.murphy@arm.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: joro@8bytes.org, will.deacon@arm.com,
iommu@lists.linux-foundation.org, devicetree@vger.kernel.org,
lorenzo.pieralisi@arm.com, jean-philippe.brucker@arm.com,
punit.agrawal@arm.com, thunder.leizhen@huawei.com,
eric.auger@redhat.com, Jason Cooper <jason@lakedaemon.net>,
Marc Zyngier <marc.zyngier@arm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 19/19] iommu/dma: Add support for mapping MSIs
Date: Wed, 24 Aug 2016 11:06:59 +0100 [thread overview]
Message-ID: <21fcb927-f0e9-6409-38d8-ddebed7522df@arm.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1608240950500.5714@nanos>
On 24/08/16 09:16, Thomas Gleixner wrote:
> On Tue, 23 Aug 2016, Robin Murphy wrote:
>> + cookie = domain->iova_cookie;
>> + iovad = &cookie->iovad;
>> +
>> + spin_lock(&cookie->msi_lock);
>> + list_for_each_entry(msi_page, &cookie->msi_page_list, list)
>> + if (msi_page->phys_hi == msg->address_hi &&
>> + msi_page->phys_lo - msg->address_lo < iovad->granule)
>> + goto unlock;
>> +
>> + ret = __iommu_dma_map_msi_page(dev, msg, domain, &msi_page);
>> +unlock:
>> + spin_unlock(&cookie->msi_lock);
>> +
>> + if (!ret) {
>> + msg->address_hi = upper_32_bits(msi_page->iova);
>> + msg->address_lo &= iova_mask(iovad);
>> + msg->address_lo += lower_32_bits(msi_page->iova);
>> + } else {
>> + /*
>> + * We're called from a void callback, so the best we can do is
>> + * 'fail' by filling the message with obviously bogus values.
>> + * Since we got this far due to an IOMMU being present, it's
>> + * not like the existing address would have worked anyway...
>> + */
>> + msg->address_hi = ~0U;
>> + msg->address_lo = ~0U;
>> + msg->data = ~0U;
>> + }
>
> The above is really horrible to parse. I had to read it five times to
> understand the logic.
Yeah, on reflection it is needlessly hideous. I think we should take
this as a clear lesson that whenever you find yourself thinking "Man, I
wish I had Python's for...else construct here", you're doing it wrong ;)
> static struct iommu_dma_msi_page *
> find_or_map_msi_page(struct iommu_dma_cookie *cookie, struct msi_msg *msg)
> {
> struct iova_domain *iovad = &cookie->iovad;
> struct iommu_dma_msi_page *page;
>
> list_for_each_entry(*page, &cookie->msi_page_list, list) {
> if (page->phys_hi == msg->address_hi &&
> page->phys_lo - msg->address_lo < iovad->granule)
> return page;
> }
>
> /*
> * FIXME: __iommu_dma_map_msi_page() should return a page or NULL.
> * The integer return value is pretty pointless. If seperate error
> * codes are required that's what ERR_PTR() is for ....
> */
> ret = __iommu_dma_map_msi_page(dev, msg, domain, &page);
> return ret ? ERR_PTR(ret) : page;
> }
>
> So now the code in iommu_dma_map_msi_msg() becomes:
>
> spin_lock(&cookie->msi_lock);
> msi_page = find_or_map_msi_page(cookie, msg);
> spin_unlock(&cookie->msi_lock);
>
> if (!IS_ERR_OR_NULL(msi_page)) {
> msg->address_hi = upper_32_bits(msi_page->iova);
> msg->address_lo &= iova_mask(iovad);
> msg->address_lo += lower_32_bits(msi_page->iova);
> } else {
> /*
> * We're called from a void callback, so the best we can do is
> * 'fail' by filling the message with obviously bogus values.
> * Since we got this far due to an IOMMU being present, it's
> * not like the existing address would have worked anyway...
> */
> msg->address_hi = ~0U;
> msg->address_lo = ~0U;
> msg->data = ~0U;
> }
>
> Hmm?
OK, I've turned map_msi_page into get_msi_page (returning a page) and
just hoisted the list lookup into that, which leads to knock-on
simplifications throughout and is _much_ nicer. I now can't imagine why
I didn't get that far in the first place - thanks for the reality check!
Robin.
>
> Thanks,
>
> tglx
>
next prev parent reply other threads:[~2016-08-24 10:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1471975357.git.robin.murphy@arm.com>
2016-08-23 19:05 ` Robin Murphy
2016-08-24 8:16 ` Thomas Gleixner
2016-08-24 10:06 ` Robin Murphy [this message]
2016-08-25 22:25 ` Auger Eric
2016-08-26 1:17 ` Robin Murphy
2016-08-31 20:51 ` Auger Eric
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=21fcb927-f0e9-6409-38d8-ddebed7522df@arm.com \
--to=robin.murphy@arm.com \
--cc=devicetree@vger.kernel.org \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jason@lakedaemon.net \
--cc=jean-philippe.brucker@arm.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=marc.zyngier@arm.com \
--cc=punit.agrawal@arm.com \
--cc=tglx@linutronix.de \
--cc=thunder.leizhen@huawei.com \
--cc=will.deacon@arm.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®