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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E43EBC43334 for ; Tue, 21 Jun 2022 07:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346768AbiFUHZj (ORCPT ); Tue, 21 Jun 2022 03:25:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346265AbiFUHZa (ORCPT ); Tue, 21 Jun 2022 03:25:30 -0400 Received: from soltyk.jannau.net (soltyk.jannau.net [144.76.91.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9294F22B00 for ; Tue, 21 Jun 2022 00:25:29 -0700 (PDT) Received: from coburn.home.jannau.net (p579ad988.dip0.t-ipconnect.de [87.154.217.136]) by soltyk.jannau.net (Postfix) with ESMTPSA id 7E63126ED18; Tue, 21 Jun 2022 09:18:50 +0200 (CEST) From: Janne Grunau To: iommu@lists.linux-foundation.org Cc: Konrad Dybcio , asahi@lists.linux.dev, Sven Peter , Alyssa Rosenzweig , Hector Martin , Joerg Roedel , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] iommu/io-pgtable: Add DART subpage protection support Date: Tue, 21 Jun 2022 09:18:46 +0200 Message-Id: <20220621071848.14834-4-j@jannau.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220621071848.14834-1-j@jannau.net> References: <20220621071848.14834-1-j@jannau.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 Signed-off-by: Janne Grunau --- Changes in v3: - apply change to io-pgtable-dart.c drivers/iommu/io-pgtable-dart.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/iommu/io-pgtable-dart.c b/drivers/iommu/io-pgtable-dart.c index 0c5222942c65..fa8025c03bb5 100644 --- a/drivers/iommu/io-pgtable-dart.c +++ b/drivers/iommu/io-pgtable-dart.c @@ -14,6 +14,7 @@ #define pr_fmt(fmt) "dart io-pgtable: " fmt #include +#include #include #include #include @@ -63,6 +64,9 @@ /* Calculate the block/page mapping size at level l for pagetable in d. */ #define DART_BLOCK_SIZE(l, d) (1ULL << DART_LVL_SHIFT(l, d)) +#define APPLE_DART_PTE_SUBPAGE_START GENMASK_ULL(63, 52) +#define APPLE_DART_PTE_SUBPAGE_END GENMASK_ULL(51, 40) + #define APPLE_DART1_PADDR_MASK GENMASK_ULL(35, 12) /* Apple DART1 protection bits */ @@ -140,6 +144,10 @@ static void __dart_init_pte(struct dart_io_pgtable *data, pte |= APPLE_DART_PTE_VALID; + /* 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); } -- 2.35.1