From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_ALL,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCCB0C11F66 for ; Tue, 29 Jun 2021 12:06:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8693E61D6E for ; Tue, 29 Jun 2021 12:06:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8693E61D6E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:CC:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pSYVJX/WbX0gXZfBRGHcQFHm8hqA9VQq9wtsD2B5wKM=; b=WLJwTOvSuZH9ts FnBRAMc98QyADQ5PIw13i7poUDovvy/gZNZdqCk7V09NPP6iB9Wke39tO49O4oPHsQ6Hsxbbed0Vl Jpn20gEdfJft7343gwPR1LFx7luTp42W0q7B2dDPLhS4VgEhypwFWIZURRX3R2TLmFnNMeNseaL3r d7xM05A1sRG0dB+5ljtT8B8Z5/EkzBPSxuqLDQbmAy2C2i2ZZZvZ5ww2V5b6JHVi2KolFQxOv7u5z WoeOMwETdzCwq3+mpEJyJqBKazYqGTBCak6qRSMejJ8Za8OkMIORkBtISLydqw/bDdHfCI6yTzUip dNfnxqghvS2qWAm/X95g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyCTa-00AlHN-Tt; Tue, 29 Jun 2021 12:04:27 +0000 Received: from smtp-fw-2101.amazon.com ([72.21.196.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyCTW-00AlGY-Jp for linux-arm-kernel@lists.infradead.org; Tue, 29 Jun 2021 12:04:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1624968262; x=1656504262; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=4VTqRt/doBhcHug+DYEpXm+V0vDuSlC/ctdi9x/3mQY=; b=p2dtAKHjBVCSonUUOOLf7HkYDWNQu8qwoEp6cUjZT/mX1v3oZe2LrPad f+5lmoi5hH/OXHoN0etxzlE7g2avpAm8gyWCRRXsWmSAK03aW9lTwnb4C MEF7iXP54ofzB/CJmcO/jySRPpoejHyr/VKUtZhZFYXMgZ1yrp8spKgFW U=; X-IronPort-AV: E=Sophos;i="5.83,308,1616457600"; d="scan'208";a="119057987" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2b-baacba05.us-west-2.amazon.com) ([10.43.8.2]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP; 29 Jun 2021 12:04:10 +0000 Received: from EX13MTAUWC002.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id F07C8A1FD3; Tue, 29 Jun 2021 12:04:08 +0000 (UTC) Received: from EX13D20UWC001.ant.amazon.com (10.43.162.244) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 29 Jun 2021 12:04:08 +0000 Received: from [192.168.9.117] (10.43.161.153) by EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 29 Jun 2021 12:04:05 +0000 Message-ID: <50d48c57-b6f4-aad9-2471-ea3d3066563d@amazon.com> Date: Tue, 29 Jun 2021 14:04:03 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:90.0) Gecko/20100101 Thunderbird/90.0 Subject: Re: [PATCH v4 1/3] iommu: io-pgtable: add DART pagetable format Content-Language: en-US To: Sven Peter , Will Deacon , "Robin Murphy" , Joerg Roedel CC: Arnd Bergmann , , "Hector Martin" , , Marc Zyngier , Mohamed Mediouni , "Stan Skowronek" , , "Mark Kettenis" , Petr Mladek via iommu , Alyssa Rosenzweig , Rob Herring , "Rouven Czerwinski" References: <20210627143405.77298-1-sven@svenpeter.dev> <20210627143405.77298-2-sven@svenpeter.dev> <3a43b2de-6a71-2373-8695-5e96657c8fc2@amazon.com> From: Alexander Graf In-Reply-To: X-Originating-IP: [10.43.161.153] X-ClientProxiedBy: EX13D21UWA004.ant.amazon.com (10.43.160.252) To EX13D20UWC001.ant.amazon.com (10.43.162.244) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210629_050422_834598_62F5C4B5 X-CRM114-Status: GOOD ( 25.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 >>> --- >>> 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 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel