Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp591315pxv; Wed, 14 Jul 2021 10:42:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycgziBwNVK6Qq9qs2p1WpW0SewlThmVRr/+GF3sjX+ALkLjuxiDruOUv4QGs1IbblB/ZwX X-Received: by 2002:a17:907:c1d:: with SMTP id ga29mr13720392ejc.284.1626284551845; Wed, 14 Jul 2021 10:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626284551; cv=none; d=google.com; s=arc-20160816; b=I03ukw3vLgH0iZBsweqvOzijLeH6aOqAUi0irdrVKPznx0vv0P2EI0/xrNgqAYb1qC W65b3aAVLExXs+6uX1VrmwJppi7OBlOsmMrSYbFeLQOQFqqs0d7ak+V/k78aHIkZ3RVw lzCiYHPgaEUBTMCT+i02RQ7UN+kXH6qYV4g84mtO/wsZzVyol9LL+H1cN8m6BqamVMWW uAG8xfkif0BD2t28JWP2AVHJpgROFle7D7g1UTYk161KD2UugdEfmnUMKWqBpHfaGd1a 7DYI4KH87KkzeolzlaS219y12AJ/6SXSY8AxXXfZ4G1bP+0RofbfJKgO8dMhFDEkH1Vi jdgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature:dkim-signature; bh=jCX74UgdqAO5ih1wL2WZjVTsL6wFOXIZazNpVZLX4KM=; b=bKRUwDxjc3l6Heya7U63ySvn0nWyBi50WGUL5q9Mmv5yQMF4lbFv459TITk9EoiVK8 jR8odNrenHmTHJ0JKGjFFq2bliweN0D3k3bc2GFdw2Kom8MG7jZfZD5ODMJLofDODrwB zJQ79btWu6E5wVPPsgaaRgTY/9WY571VRUWu//uJDTpu1FtNKIUAEXE+tdfeOUyC/e2I rq97pVuztJokZHt/8OpfyZRxaD0Le8NfpoQb/xw1uC0HI+5Iz6mmzRCTOlK7lFkq0qYz XctNOoCZmPizQNDm1eTGSlGskf35sc1/vcnoUNJ25Ffx4p94rTICKBXskJT1iBGiWqpp 7dvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=whOY2qX0; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=IEoCu4rU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n5si3210931edd.91.2021.07.14.10.42.08; Wed, 14 Jul 2021 10:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=whOY2qX0; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=IEoCu4rU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239684AbhGNRnI (ORCPT + 99 others); Wed, 14 Jul 2021 13:43:08 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:33995 "EHLO new1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbhGNRnH (ORCPT ); Wed, 14 Jul 2021 13:43:07 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id 59CA2580A6F; Wed, 14 Jul 2021 13:40:15 -0400 (EDT) Received: from imap21 ([10.202.2.71]) by compute1.internal (MEProxy); Wed, 14 Jul 2021 13:40:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=mime-version:message-id:in-reply-to:references:date:from:to :cc:subject:content-type; s=fm1; bh=jCX74UgdqAO5ih1wL2WZjVTsL6wF OXIZazNpVZLX4KM=; b=whOY2qX0MxDBLiN7pHSESTpi1t8ZQd0kBHsYLG3l9QZz aNLJus7YQrbreO4k2GVk1u8i6Y8h1YEcHOT8uHi5TPTM/SUx45HltuOYinZIS405 9Sjc1J09Cq1RI4wbP539EmoN7jXE/hQuKp/Srb/Q+Tub74lCe/zUYoCcAdAT2MzX W4DLanp1oBG90fNdDHIh/WCsBg91vkQCmG+IajdJ9HrHbxKJXbe6HB5Rini9xHs5 aqGzBjfnnt3xIDowJ1ECRr/Wi0N2Tdm9Mmhj0F+vGjPlNS5Zm1Aqf4aVMNg4yrVN YwVVgjUtIl4dIL8AjcIfiqk3L6Y/gziiwheOyzu6/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=jCX74U gdqAO5ih1wL2WZjVTsL6wFOXIZazNpVZLX4KM=; b=IEoCu4rUG+hjgDSjRuLuse aPHzEPjQ8GVwhrIyy5wUGRk/VRFsFtOkU3nHK0AQBaXunMg6xgunTDTLl535AKrb L7t3qDsZnE1+RZi/BdwlUFIPNPKPldNHZ7c1POMmFcr3BrnPLCFMIos7Xc0XAjZ4 o+dynyLw0vak/skyQ33RXKHdV0HLPb2nOpgvupLdipudupBaxhsaDaXHDFyaFeXm OHnwgePlh+E0skJNiM8ZPtcRqgHFrYHHmdUm3UcGFS/mxs2Y5JftcccDh2OSBBXk TkjRBd+ckGM2U9UDHEfqVxdxnP5EDyxa9XYfU60906fqOCZ6G9lHk6OpRnFCwpkQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudekgdduuddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfuvhgv nhcurfgvthgvrhdfuceoshhvvghnsehsvhgvnhhpvghtvghrrdguvghvqeenucggtffrrg htthgvrhhnpefgieegieffuefhtedtjefgteejteefleefgfefgfdvvddtgffhffduhedv feekffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hsvhgvnhesshhvvghnphgvthgvrhdruggvvh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2685851C0060; Wed, 14 Jul 2021 13:40:13 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-533-gf73e617b8a-fm-20210712.002-gf73e617b Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20210627143405.77298-1-sven@svenpeter.dev> <20210627143405.77298-2-sven@svenpeter.dev> Date: Wed, 14 Jul 2021 19:39:48 +0200 From: "Sven Peter" To: "Robin Murphy" , "Will Deacon" , "Joerg Roedel" Cc: "Arnd Bergmann" , devicetree@vger.kernel.org, "Hector Martin" , linux-kernel@vger.kernel.org, "Marc Zyngier" , "Mohamed Mediouni" , "Stan Skowronek" , linux-arm-kernel@lists.infradead.org, "Mark Kettenis" , "Petr Mladek via iommu" , "Alexander Graf" , "Alyssa Rosenzweig" , "Rob Herring" , "Rouven Czerwinski" Subject: Re: [PATCH v4 1/3] iommu: io-pgtable: add DART pagetable format Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Jul 13, 2021, at 21:17, Robin Murphy wrote: > On 2021-06-27 15: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; > > + } > > + > > 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. > > + */ > > Nit: I appreciate the effort to document the weirdness, but this comment > did rather mislead me initially, and now that I (think I) understand how > things work it seems a bit backwards. Could we say something like: > > "The table format itself always uses two levels, but the total VA > space is mapped by four separate tables, making the MMIO registers > an effective "level 1". For simplicity, though, we treat this > equivalently to LPAE stage 2 concatenation at level 2, with the > additional TTBRs each just pointing at consecutive pages." > > ? > Sure, your version is much easier to understand! Thanks. > > + 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; > > + data->pgd_bits += data->bits_per_level; > > + > > + data->pgd = __arm_lpae_alloc_pages(ARM_LPAE_PGD_SIZE(data), GFP_KERNEL, > > + cfg); > > + if (!data->pgd) > > + goto out_free_data; > > + > > + for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) > > + cfg->apple_dart_cfg.ttbr[i] = > > + virt_to_phys(data->pgd + i * ARM_LPAE_GRANULE(data)); > > + > > + return &data->iop; > > + > > +out_free_data: > > + kfree(data); > > + return NULL; > > +} > > + > > struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns = { > > .alloc = arm_64_lpae_alloc_pgtable_s1, > > .free = arm_lpae_free_pgtable, > > @@ -1068,6 +1125,11 @@ struct io_pgtable_init_fns io_pgtable_arm_mali_lpae_init_fns = { > > .free = arm_lpae_free_pgtable, > > }; > > > > +struct io_pgtable_init_fns io_pgtable_apple_dart_init_fns = { > > + .alloc = apple_dart_alloc_pgtable, > > + .free = arm_lpae_free_pgtable, > > +}; > > + > > #ifdef CONFIG_IOMMU_IO_PGTABLE_LPAE_SELFTEST > > > > static struct io_pgtable_cfg *cfg_cookie __initdata; > > diff --git a/drivers/iommu/io-pgtable.c b/drivers/iommu/io-pgtable.c > > index 6e9917ce980f..fd8e6bd6caf9 100644 > > --- a/drivers/iommu/io-pgtable.c > > +++ b/drivers/iommu/io-pgtable.c > > @@ -20,6 +20,7 @@ io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = { > > [ARM_64_LPAE_S1] = &io_pgtable_arm_64_lpae_s1_init_fns, > > [ARM_64_LPAE_S2] = &io_pgtable_arm_64_lpae_s2_init_fns, > > [ARM_MALI_LPAE] = &io_pgtable_arm_mali_lpae_init_fns, > > + [ARM_APPLE_DART] = &io_pgtable_apple_dart_init_fns, > > #endif > > #ifdef CONFIG_IOMMU_IO_PGTABLE_ARMV7S > > [ARM_V7S] = &io_pgtable_arm_v7s_init_fns, > > diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h > > index 4d40dfa75b55..a4bfac7f85f7 100644 > > --- a/include/linux/io-pgtable.h > > +++ b/include/linux/io-pgtable.h > > @@ -16,6 +16,7 @@ enum io_pgtable_fmt { > > ARM_V7S, > > ARM_MALI_LPAE, > > AMD_IOMMU_V1, > > + ARM_APPLE_DART, > > s/ARM_// - this is pure Apple ;) > > With that fixed and hopefully a somewhat clarified comment above, > > Reviewed-by: Robin Murphy True, I'll remove the ARM_ prefix and also change the commit message to match the subsystem style as mentioned in your reply for the third patch. Thanks for the review! > > > IO_PGTABLE_NUM_FMTS, > > }; > > > > @@ -136,6 +137,11 @@ struct io_pgtable_cfg { > > u64 transtab; > > u64 memattr; > > } arm_mali_lpae_cfg; > > + > > + struct { > > + u64 ttbr[4]; > > + u32 n_ttbrs; > > + } apple_dart_cfg; > > }; > > }; > > > > @@ -246,5 +252,6 @@ extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns; > > extern struct io_pgtable_init_fns io_pgtable_arm_v7s_init_fns; > > extern struct io_pgtable_init_fns io_pgtable_arm_mali_lpae_init_fns; > > extern struct io_pgtable_init_fns io_pgtable_amd_iommu_v1_init_fns; > > +extern struct io_pgtable_init_fns io_pgtable_apple_dart_init_fns; > > > > #endif /* __IO_PGTABLE_H */ > > > Sven