LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Sven Peter" <sven@svenpeter.dev>
To: "Robin Murphy" <robin.murphy@arm.com>,
"Sven Peter" <iommu@lists.linux-foundation.org>
Cc: "Arnd Bergmann" <arnd@kernel.org>,
"Will Deacon" <will@kernel.org>,
"Hector Martin" <marcan@marcan.st>,
linux-kernel@vger.kernel.org, "Alexander Graf" <graf@amazon.com>,
"Mohamed Mediouni" <mohamed.mediouni@caramail.com>
Subject: Re: [RFC PATCH 2/3] iommu/dma-iommu: Support iovad->granule > PAGE_SIZE
Date: Sat, 07 Aug 2021 13:47:21 +0200 [thread overview]
Message-ID: <dadbd8b0-171a-4008-8a2e-f68abfed9285@www.fastmail.com> (raw)
In-Reply-To: <d289a555-9e3b-b948-1883-2ee4c915da4c@arm.com>
On Fri, Aug 6, 2021, at 20:04, Robin Murphy wrote:
> On 2021-08-06 16:55, Sven Peter via iommu wrote:
> > @@ -1006,6 +1019,31 @@ static int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
> > if (dev_is_untrusted(dev))
> > return iommu_dma_map_sg_swiotlb(dev, sg, nents, dir, attrs);
> >
> > + /*
> > + * If the IOMMU pagesize is larger than the CPU pagesize we will
> > + * very likely run into sgs with a physical address that is not aligned
> > + * to an IOMMU page boundary. Fall back to just mapping every entry
> > + * independently with __iommu_dma_map then.
>
> Scatterlist segments often don't have nicely aligned ends, which is why
> we already align things to IOVA granules in main loop here. I think in
> principle we'd just need to move the non-IOVA-aligned part of the
> address from sg->page to sg->offset in the temporary transformation for
> the rest of the assumptions to hold. I don't blame you for being timid
> about touching that, though - it took me 3 tries to get right when I
> first wrote it...
>
I've spent some time with that code now and I think we cannot use it
but have to fall back to iommu_dma_map_sg_swiotlb (even though that swiotlb
part is a lie then):
When we have sg_phys(s) = 0x802e65000 with s->offset = 0 the paddr
is aligned to PAGE_SIZE but has an offset of 0x1000 from something
the IOMMU can map.
Now this would result in s->offset = -0x1000 which is already weird
enough.
Offset is unsigned (and 32bit) so this will actually look like
s->offset = 0xfffff000 then, which isn't much better.
And then sg_phys(s) = 0x902e64000 (instead of 0x802e64000) and
we'll map some random memory in iommu_map_sg_atomic and a little bit later
everything explodes.
Now I could probably adjust the phys addr backwards and make sure offset is
always positive (and possibly larger than PAGE_SIZE) and later restore it
in __finalise_sg then but I feel like that's pushing this a little bit too far.
Sven
next prev parent reply other threads:[~2021-08-07 11:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 15:55 [RFC PATCH 0/3] iommu/dma-iommu: Support IOMMU page size larger than the CPU page size Sven Peter
2021-08-06 15:55 ` [RFC PATCH 1/3] iommu: Move IOMMU pagesize check to attach_device Sven Peter
2021-08-06 15:55 ` [RFC PATCH 2/3] iommu/dma-iommu: Support iovad->granule > PAGE_SIZE Sven Peter
2021-08-06 18:04 ` Robin Murphy
2021-08-07 8:41 ` Sven Peter
2021-08-09 18:37 ` Robin Murphy
2021-08-09 19:57 ` Sven Peter
2021-08-07 11:47 ` Sven Peter [this message]
2021-08-09 17:41 ` Robin Murphy
2021-08-09 20:45 ` Sven Peter
2021-08-10 9:51 ` Robin Murphy
2021-08-11 20:18 ` Sven Peter
2021-08-12 12:43 ` Robin Murphy
2021-08-06 15:55 ` [RFC PATCH 3/3] iommu: Introduce __IOMMU_DOMAIN_LARGE_PAGES Sven Peter
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=dadbd8b0-171a-4008-8a2e-f68abfed9285@www.fastmail.com \
--to=sven@svenpeter.dev \
--cc=arnd@kernel.org \
--cc=graf@amazon.com \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=mohamed.mediouni@caramail.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
--subject='Re: [RFC PATCH 2/3] iommu/dma-iommu: Support iovad->granule > PAGE_SIZE' \
/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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).