From patchwork Tue Jun 21 07:18:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Grunau X-Patchwork-Id: 12888732 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 70A7CCCA473 for ; Tue, 21 Jun 2022 07:20: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=/w1rq5tTIRIMRmY/yX85rODPaS/9zI4Gxh7Ka7dIzdA=; b=q1qFrXbBZYSeYx e3mRX+iIh8Vx9GZtU5jIJPEceSLecAnWkj+E+vsWfSkGLlP0y2m2G1CCpuobjkkvWwAIfuGmi8Att H7UqmAyvlPQACPZ3UblMyg+504x2Dqh/KxEUeceCF7SbhP7CbEe0XyTAhdIPZlXxGjyDOz7Cyvxxo SaigYCk9e5TunGX0UqQgyft7O0bk4uv7Zp7aG13DwtAk728wakbjwwSS5c9U/Zk2fT/6+cj52yUAz SEQsdKkYmAM3xheD2INw7Y660vhk9N4llZC3XtQKNvmoFQRz/6WFP0nR1oWTrfOozfyaSzPXR9FNx 47NsEwu3F7FRn66xOYSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3YAE-0040aD-Uy; Tue, 21 Jun 2022 07:19:07 +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 1o3YAA-0040TN-6K for linux-arm-kernel@lists.infradead.org; Tue, 21 Jun 2022 07:19:03 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220621_001902_426996_D1778A76 X-CRM114-Status: GOOD ( 13.26 ) 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 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); }