From patchwork Tue May 3 06:22:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Grunau X-Patchwork-Id: 12835043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 722CEC433EF for ; Tue, 3 May 2022 06:24:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DF5l5br9HX6GxpB5lVbAoOrdbkcDQUrjVcN694KH4P4=; b=dNKL4sD1Ctz1lF Qpjfnxc8E6V5koePnlRogLMWdrqbISW/82+rmZ/tdqapVK+1un6oJGfECWwBFnP+8yS2jajId9/U0 VOtr12VVIxR6zFjfTQ5S3IgCnUcE8degyfZAOlH136t1knOHMCDMrZdlVSrltLdPlj7EIUVO8egZ7 Z0JmZms5wrHxFaSIU9WzEVLB39xpaPl0IqdHM03PZqnTfFo6DeO1PyD1yTtfb4UpnqbeHbvtG68j2 j2bOo6o20B8UFGoQx2s48Z7h6tbSh7cij3/NfhCprDvWgopPPA/x4J5qv0oiUb3gLjOh/jFk+rEY6 vBRFmRcU2qmfmC0/EcxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nllwF-003x20-NS; Tue, 03 May 2022 06:23:11 +0000 Received: from soltyk.jannau.net ([144.76.91.90]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nllwB-003wxg-Ph for linux-arm-kernel@lists.infradead.org; Tue, 03 May 2022 06:23:09 +0000 Received: from coburn.home.jannau.net (p579ad988.dip0.t-ipconnect.de [87.154.217.136]) by soltyk.jannau.net (Postfix) with ESMTPSA id E76EF26E9B4; Tue, 3 May 2022 08:23:02 +0200 (CEST) From: Janne Grunau To: iommu@lists.linux-foundation.org Cc: Sven Peter , Alyssa Rosenzweig , Hector Martin , Mark Kettenis , Joerg Roedel , Will Deacon , Rob Herring , Robin Murphy , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 2/4] iommu/io-pgtable: Add DART subpage protection support Date: Tue, 3 May 2022 08:22:59 +0200 Message-Id: <20220503062301.20872-3-j@jannau.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220503062301.20872-1-j@jannau.net> References: <20220503062301.20872-1-j@jannau.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220502_232308_020212_8148C82F X-CRM114-Status: GOOD ( 13.23 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Sven Peter DART allows to only expose a subpage to the device. While this is an optional feature on the M1 DARTs the new ones present on the Pro/Max models require this field in every PTE. Signed-off-by: Sven Peter --- drivers/iommu/io-pgtable-arm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 94ff319ae8ac..71570bbc9096 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "arm-lpae io-pgtable: " fmt #include +#include #include #include #include @@ -133,6 +134,9 @@ #define APPLE_DART_PTE_PROT_NO_WRITE (1<<7) #define APPLE_DART_PTE_PROT_NO_READ (1<<8) +#define APPLE_DART_PTE_SUBPAGE_START GENMASK_ULL(63, 52) +#define APPLE_DART_PTE_SUBPAGE_END GENMASK_ULL(51, 40) + /* IOPTE accessors */ #define iopte_deref(pte,d) __va(iopte_to_paddr(pte, d)) @@ -273,6 +277,12 @@ static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, else pte |= ARM_LPAE_PTE_TYPE_BLOCK; + if (data->iop.fmt == APPLE_DART) { + /* subpage protection: always allow access to the entire page */ + pte |= FIELD_PREP(APPLE_DART_PTE_SUBPAGE_START, 0); + pte |= FIELD_PREP(APPLE_DART_PTE_SUBPAGE_END, 0xfff); + } + for (i = 0; i < num_entries; i++) ptep[i] = pte | paddr_to_iopte(paddr + i * sz, data);