From: Alexander Graf via iommu <iommu@lists.linux-foundation.org>
To: Sven Peter <sven@svenpeter.dev>, Will Deacon <will@kernel.org>,
"Robin Murphy" <robin.murphy@arm.com>,
Joerg Roedel <joro@8bytes.org>
Cc: Arnd Bergmann <arnd@kernel.org>,
Rouven Czerwinski <r.czerwinski@pengutronix.de>,
devicetree@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
Hector Martin <marcan@marcan.st>,
linux-kernel@vger.kernel.org,
Petr Mladek via iommu <iommu@lists.linux-foundation.org>,
Rob Herring <robh+dt@kernel.org>,
Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>,
Mohamed Mediouni <mohamed.mediouni@caramail.com>,
Mark Kettenis <mark.kettenis@xs4all.nl>,
linux-arm-kernel@lists.infradead.org,
Stan Skowronek <stan@corellium.com>
Subject: Re: [PATCH v4 1/3] iommu: io-pgtable: add DART pagetable format
Date: Tue, 29 Jun 2021 14:04:03 +0200 [thread overview]
Message-ID: <50d48c57-b6f4-aad9-2471-ea3d3066563d@amazon.com> (raw)
In-Reply-To: <fedb8d5a-a0f1-4216-bb46-1af31b716309@www.fastmail.com>
On 29.06.21 09:37, Sven Peter wrote:
>
> On Mon, Jun 28, 2021, at 12:54, Alexander Graf wrote:
>>
>>
>> On 27.06.21 16:34, Sven Peter wrote:
>>>
>>> Apple's DART iommu uses a pagetable format that shares some
>>> similarities with the ones already implemented by io-pgtable.c.
>>> Add a new format variant to support the required differences
>>> so that we don't have to duplicate the pagetable handling code.
>>>
>>> Signed-off-by: Sven Peter <sven@svenpeter.dev>
>>> ---
>>> drivers/iommu/io-pgtable-arm.c | 62 ++++++++++++++++++++++++++++++++++
>>> drivers/iommu/io-pgtable.c | 1 +
>>> include/linux/io-pgtable.h | 7 ++++
>>> 3 files changed, 70 insertions(+)
>>>
>>> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
>>> index 87def58e79b5..1dd5c45b4b5b 100644
>>> --- a/drivers/iommu/io-pgtable-arm.c
>>> +++ b/drivers/iommu/io-pgtable-arm.c
>>> @@ -127,6 +127,9 @@
>>> #define ARM_MALI_LPAE_MEMATTR_IMP_DEF 0x88ULL
>>> #define ARM_MALI_LPAE_MEMATTR_WRITE_ALLOC 0x8DULL
>>>
>>> +#define APPLE_DART_PTE_PROT_NO_WRITE (1<<7)
>>> +#define APPLE_DART_PTE_PROT_NO_READ (1<<8)
>>> +
>>> /* IOPTE accessors */
>>> #define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d))
>>>
>>> @@ -381,6 +384,15 @@ static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data,
>>> {
>>> arm_lpae_iopte pte;
>>>
>>> + if (data->iop.fmt == ARM_APPLE_DART) {
>>> + pte = 0;
>>> + if (!(prot & IOMMU_WRITE))
>>> + pte |= APPLE_DART_PTE_PROT_NO_WRITE;
>>> + if (!(prot & IOMMU_READ))
>>> + pte |= APPLE_DART_PTE_PROT_NO_READ;
>>> + return pte;
>>
>> What about the other bits, such as sharability, XN, etc? Do they not
>> exist on DART? Or have they not been reverse engineered and 0s happen to
>> "just work"?
>
> I'm fairly certain they don't exist (or are at least not used by XNU).
>
> The co-processors that can run code also either use an entire separate iommu
> (e.g. the GPU) or only use DART as a "second stage" and have their own
> MMU which e.g. handles XN (e.g. the SEP or AOP).
Ok :).
>
>>
>>> + }
>>> +
>>> if (data->iop.fmt == ARM_64_LPAE_S1 ||
>>> data->iop.fmt == ARM_32_LPAE_S1) {
>>> pte = ARM_LPAE_PTE_nG;
>>> @@ -1043,6 +1055,51 @@ arm_mali_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
>>> return NULL;
>>> }
>>>
>>> +static struct io_pgtable *
>>> +apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
>>> +{
>>> + struct arm_lpae_io_pgtable *data;
>>> + int i;
>>> +
>>> + if (cfg->oas > 36)
>>> + return NULL;
>>> +
>>> + data = arm_lpae_alloc_pgtable(cfg);
>>> + if (!data)
>>> + return NULL;
>>> +
>>> + /*
>>> + * Apple's DART always requires three levels with the first level being
>>> + * stored in four MMIO registers. We always concatenate the first and
>>> + * second level so that we only have to setup the MMIO registers once.
>>> + * This results in an effective two level pagetable.
>>> + */
>>> + if (data->start_level < 1)
>>> + return NULL;
>>> + if (data->start_level == 1 && data->pgd_bits > 2)
>>> + return NULL;
>>> + if (data->start_level > 1)
>>> + data->pgd_bits = 0;
>>> + data->start_level = 2;
>>> + cfg->apple_dart_cfg.n_ttbrs = 1 << data->pgd_bits;
>>
>> Maybe add a BUG_ON if n_ttbrs > ARRAY_SIZE(ttbr)? Or alternatively, do a
>> normal runtime check and bail out then.
>
> n_ttbrs can't actually be larger than 4 at this point already due to the
> previous checks.
> I can add a BUG_ON though just to make it explicit and be safe in case those
> checks or the array size ever change.
Ah, now I see it too. No worries then - I agree that you have all cases
covered.
Reviewed-by: Alexander Graf <graf@amazon.com>
Alex
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2021-06-29 12:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-27 14:34 [PATCH v4 0/3] Apple M1 DART IOMMU driver Sven Peter via iommu
2021-06-27 14:34 ` [PATCH v4 1/3] iommu: io-pgtable: add DART pagetable format Sven Peter via iommu
2021-06-28 10:54 ` Alexander Graf via iommu
2021-06-29 7:37 ` Sven Peter via iommu
2021-06-29 12:04 ` Alexander Graf via iommu [this message]
2021-06-30 13:53 ` Alyssa Rosenzweig
2021-07-13 19:17 ` Robin Murphy
2021-07-14 17:39 ` Sven Peter via iommu
2021-06-27 14:34 ` [PATCH v4 2/3] dt-bindings: iommu: add DART iommu bindings Sven Peter via iommu
2021-06-30 13:54 ` Alyssa Rosenzweig
2021-06-27 14:34 ` [PATCH v4 3/3] iommu: dart: Add DART iommu driver Sven Peter via iommu
2021-06-30 13:49 ` Alyssa Rosenzweig
2021-07-12 11:02 ` Sven Peter via iommu
2021-07-12 13:53 ` Alyssa Rosenzweig
2021-07-13 23:23 ` Robin Murphy
2021-07-15 16:41 ` Sven Peter via iommu
2021-07-19 18:15 ` Robin Murphy
2021-07-25 12:40 ` Sven Peter via iommu
2021-07-26 13:19 ` Alyssa Rosenzweig
2021-07-14 18:19 ` [PATCH v4 0/3] Apple M1 DART IOMMU driver Robin Murphy
2021-07-14 20:51 ` Arnd Bergmann
2021-07-15 6:52 ` Joerg Roedel
2021-07-16 6:24 ` Christoph Hellwig
2021-07-16 15:32 ` 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=50d48c57-b6f4-aad9-2471-ea3d3066563d@amazon.com \
--to=iommu@lists.linux-foundation.org \
--cc=alyssa.rosenzweig@collabora.com \
--cc=arnd@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=graf@amazon.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcan@marcan.st \
--cc=mark.kettenis@xs4all.nl \
--cc=maz@kernel.org \
--cc=mohamed.mediouni@caramail.com \
--cc=r.czerwinski@pengutronix.de \
--cc=robh+dt@kernel.org \
--cc=robin.murphy@arm.com \
--cc=stan@corellium.com \
--cc=sven@svenpeter.dev \
--cc=will@kernel.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 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).